-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add const_allocate intrinsic #79594
add const_allocate intrinsic #79594
Changes from 1 commit
528355c
b5b811a
a6c4cbd
1b7fe09
899a59e
bc6eb6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#![feature(core_intrinsics)] | ||
#![feature(const_heap)] | ||
#![feature(const_raw_ptr_deref)] | ||
#![feature(const_mut_refs)] | ||
use std::intrinsics; | ||
|
||
const FOO: i32 = foo(); | ||
const fn foo() -> i32 { | ||
unsafe { | ||
let _ = intrinsics::const_allocate(4, 3) as * mut i32; | ||
//~^ error: any use of this value will cause an error [const_err] | ||
} | ||
1 | ||
|
||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
error: any use of this value will cause an error | ||
--> $DIR/alloc_intrinsic_errors.rs:10:17 | ||
| | ||
LL | const FOO: i32 = foo(); | ||
| ----------------------- | ||
... | ||
LL | let _ = intrinsics::const_allocate(4, 3) as * mut i32; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | | ||
| align has to be a power of 2, `3` is not a power of 2 | ||
| inside `foo` at $DIR/alloc_intrinsic_errors.rs:10:17 | ||
| inside `FOO` at $DIR/alloc_intrinsic_errors.rs:7:18 | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -1,11 +1,11 @@ | ||||||||||||
// run-pass | ||||||||||||
#![feature(core_intrinsics)] | ||||||||||||
#![feature(const_heap)] | ||||||||||||
#![feature(const_raw_ptr_deref)] | ||||||||||||
#![feature(const_mut_refs)] | ||||||||||||
use std::intrinsics; | ||||||||||||
|
||||||||||||
const FOO: *const i32 = foo(); | ||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's super curious that this doesn't error with the same error that src/test/ui/consts/const-eval/heap/alloc_intrinsic_untyped.rs emits: "untyped pointer". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh... I think I know why... rust/compiler/rustc_mir/src/const_eval/machine.rs Lines 40 to 44 in 75f1db1
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess we'll need to disable that optimization for function items now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test memoizes function alls to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Basically if you used const fn foo() -> &'static i32 {
const fn bar() -> *mut i32 {
unsafe { intrinsics::const_allocate(4, 4) as *mut i32 }
}
unsafe {
let i = bar();
*i = 20;
...
}
} the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, lol... yeah, |
||||||||||||
//~^ error: untyped pointers are not allowed in constant | ||||||||||||
|
||||||||||||
const fn foo() -> &'static i32 { | ||||||||||||
let t = unsafe { | ||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: untyped pointers are not allowed in constant | ||
--> $DIR/alloc_intrinsic_nontransient.rs:7:1 | ||
| | ||
LL | const FOO: *const i32 = foo(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah sorry, I meant to run this check within
try_eval_const_fn_call
and returnOk(false)
from it if it's not an intrinsicThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand this new code. Don't we have to just entirely remove memoization?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we still memoize calls to
size_of
andalign_of
I thinkThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is that worth it all the code complexity here? Those functions are trivial to evaluate...