-
Notifications
You must be signed in to change notification settings - Fork 3
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
[Discussion] how to handleconst-eval
and promoted
in K
#65
Comments
My notes on CTFE CTFECTFE: Compile time function evaluation The CTFE mechanism checks for undefined behaviors during the evaluation (using Miri). In case of a UB, CTFE is terminated with an error. To avoid an optimization changing the undefinedness of a program, CTFE uses unoptimized MIR functions (RFC-3016). Thus, the compiler emits both optimized and unoptimized MIR ( Since constants remain unevaluated in the MIR output, we need "MIR for CTFE" functions for constant evaluation.
|
The two |
Thank you, @bbyalcinkaya for preparing the examples with mir output embeded nicely!
Observation There is something I have noticed in the above example:
|
@virgil-serbanuta Do you mean it is because they are assigned to unused variables? I tried adding print statements, but they are still unevaluated. @yanliu18 Yes, my 3rd question is the same as CTFE. If I understand correctly, CTFE is applied during code generation, after this MIR output is created. That's why we have unevaluated constants. How is |
This is an interesting example: const A: usize = 111 + 222; // 333
const B: usize = A + 444; // 777
fn main() {
let x = A;
let y = B;
let arr = [0 ; B];
println!("{}", x);
println!("{}", y);
} Constant evaluation is lazy. The compiler only evaluates the array length because it is part of the type. Other constants will eventually be evaluated in codegen.
|
I've been learning about the mir optimizations (far from done yet) and options to turn them off. Ive find some answers to the questions in our discussion, thus I am composing an update to this issue.
const fn foo(x: i32, y: i32) -> i32 {
x + y
}
fn main() {
const A: i32 = foo(1, 2 + 34);
assert!(A == 37);
return
}
|
Problem
The MIR file emitted by
rustc
could contain special constructs such aspromoted[0]
,fn main::const_eval()...
in multiple occurence or comments//MIR for CTFE
beforeconst_eval()
. These are all related toconst-eval
in CTFE.Such constructs are silently added at compile time, that there is no appearance at surface syntax. We consider it as compiler time optimization, where there sould be no occurence of such construct for
no-op
MIR file (to be validated). It also seems to be a feature added bymiri
whilerustc
callsmiri
for code checking.However, when it comes to definitions in K, how should we treat CTFE behaviors in kmir (considering its semantics and relation to the semantics of the original rust program)?
[To be investigated]
references
const-eval
const-eval
.Related Issues
promoted
means #58rustc
produces multiple functions with the same signature in some tests #63MIR FOR CTFE
functions #62We will close the above issues and merge the discussion here.
Investigation Todos
testdata/optimizations/CTFE
, it is good to have examples dedicated to the three category of programs enablesconst-eval
no-op
/ skipmiri
step orCTFE
step and after op.The text was updated successfully, but these errors were encountered: