-
Notifications
You must be signed in to change notification settings - Fork 21
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 support for const promotion #886
Comments
Some thoughts on this. The mir for const test_slice2::promoted: &[&[i32]; 1] = {
let mut _0: &[&[i32]; 1];
let mut _1: [&[i32]; 1];
let mut _2: &[i32];
let mut _3: &[i32; 3];
let mut _4: &[i32; 3];
let mut _5: [i32; 3];
bb0: {
_5 = [const 1_i32, const 2_i32, const 3_i32];
_4 = &_5;
_3 = &(*_4);
_2 = move _3 as &[i32] (PointerCoercion(Unsize));
_1 = [move _2];
_0 = &_1;
return;
}
}
fn test_slice2() -> () {
let mut _0: ();
let _1: ();
let mut _2: &[&[i32]];
let _3: &[&[i32]; 1];
bb0: {
_3 = const test_slice2::promoted;
_2 = copy _3 as &[&[i32]] (PointerCoercion(Unsize));
_1 = check_slice(move _2) -> [return: bb1, unwind continue];
}
bb1: {
return;
}
} where I see two options to handle this. We could
edit: On second thought. There's not much difference between the two because (1) I don't think the promoted body can be recursive and (2) promoted constants are by definition used only once so we don't gain much by computing the strongest type and saving it. The real issue is whether the promoted body has more than one return path. If there's more than one, we need to find the join with kvars (since it's not recursive it will still be the strongest). edit2: We can think of edit3: Ok, thinking of it as a function makes it clearer. If we have a promoted const of (rust) type |
Per @nilehmann -- that is what will let us check stuff like the below
https://github.com/rust-lang/const-eval/blob/master/promotion.md
The text was updated successfully, but these errors were encountered: