-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Make CTFE able to check for UB... #78407
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
68ff5f0
Stop optimizing promoteds
552f391
Make `encode_optimized_mir` always perform its action and instead req…
dadf937
Remove mir encode calls that didn't actually encode anything
248b4db
Limit trait item mir encoding to items with default bodies
8e4fe66
Require the `encode_promoted_mir` caller to know whether MIR for this…
cccd40f
Keep an unoptimized duplicate of `const fn` around
1f5fb3e
Differentiate between the availability of ctfe MIR and runtime MIR
oli-obk eb4e94b
Simplify the `optimize_mir` query
oli-obk db90150
Polymorphization should look at the runtime MIR of `const fn`
oli-obk 680c402
Comment nit
oli-obk 7202054
Document all the things
oli-obk f6d54aa
Adjust imports
oli-obk caeb3d5
Move MIR body loading to a machine function
oli-obk 9eaec13
Small comment adjustments
oli-obk a76dae4
Fix wording of query description
oli-obk 3af7989
No doc comments on expressions
oli-obk 409195d
Update stderr files after rebase
oli-obk 65ee418
Do not run const prop on the `mir_for_ctfe` of `const fn`
oli-obk 41a732d
Remove a FIXME and explain the decision
oli-obk e90b521
--emit=mir now emits both `mir_for_ctfe` and `optimized_mir` for `con…
oli-obk 53e3a23
Coverage computation needs access to the MIR, too
oli-obk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
--emit=mir now emits both
mir_for_ctfe
and optimized_mir
for `con…
…st fn`
- Loading branch information
commit e90b521a15f12863fced1023e700d02e015931a4
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
-include ../../run-make-fulldeps/tools.mk | ||
|
||
all: | ||
$(RUSTC) main.rs --emit=mir -o "$(TMPDIR)"/dump.mir | ||
|
||
ifdef RUSTC_BLESS_TEST | ||
cp "$(TMPDIR)"/dump.mir dump.mir | ||
else | ||
$(DIFF) dump.mir "$(TMPDIR)"/dump.mir | ||
endif |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// WARNING: This output format is intended for human consumers only | ||
// and is subject to change without notice. Knock yourself out. | ||
fn main() -> () { | ||
let mut _0: (); // return place in scope 0 at main.rs:8:11: 8:11 | ||
let _1: i32; // in scope 0 at main.rs:9:5: 9:10 | ||
|
||
bb0: { | ||
StorageLive(_1); // scope 0 at main.rs:9:5: 9:10 | ||
_1 = foo() -> bb1; // scope 0 at main.rs:9:5: 9:10 | ||
// mir::Constant | ||
// + span: main.rs:9:5: 9:8 | ||
// + literal: Const { ty: fn() -> i32 {foo}, val: Value(Scalar(<ZST>)) } | ||
} | ||
|
||
bb1: { | ||
StorageDead(_1); // scope 0 at main.rs:9:10: 9:11 | ||
_0 = const (); // scope 0 at main.rs:8:11: 10:2 | ||
return; // scope 0 at main.rs:10:2: 10:2 | ||
} | ||
} | ||
|
||
fn foo() -> i32 { | ||
let mut _0: i32; // return place in scope 0 at main.rs:4:19: 4:22 | ||
|
||
bb0: { | ||
_0 = const 11_i32; // scope 0 at main.rs:5:5: 5:10 | ||
return; // scope 0 at main.rs:6:2: 6:2 | ||
} | ||
} | ||
|
||
// MIR FOR CTFE | ||
fn foo() -> i32 { | ||
let mut _0: i32; // return place in scope 0 at main.rs:4:19: 4:22 | ||
let mut _1: (i32, bool); // in scope 0 at main.rs:5:5: 5:10 | ||
|
||
bb0: { | ||
_1 = CheckedAdd(const 5_i32, const 6_i32); // scope 0 at main.rs:5:5: 5:10 | ||
assert(!move (_1.1: bool), "attempt to compute `{} + {}`, which would overflow", const 5_i32, const 6_i32) -> bb1; // scope 0 at main.rs:5:5: 5:10 | ||
} | ||
|
||
bb1: { | ||
_0 = move (_1.0: i32); // scope 0 at main.rs:5:5: 5:10 | ||
return; // scope 0 at main.rs:6:2: 6:2 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// emit-mir | ||
// check-pass | ||
|
||
const fn foo() -> i32 { | ||
5 + 6 | ||
} | ||
|
||
fn main() { | ||
foo(); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The expect_local call here means that write_mir_pretty no longer works for non local def_ids. The ability to print out MIR for non local functions this way is critical for the MIRAI project.
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.
Is the fix as simple as adding
if let Some(local) = def_id.expect_local()
? If so, are you interested in making a PR for that change?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.
I doubt that the fix is that simple. I need a way of actually getting the MIR of non local functions. Perhaps use as_local and keep the old code for the None case?
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.
I think what we can do is to check
is_const_fn_raw
for theconst fn
path, and usetcx.instance_mir(ty::InstanceDef::Item(def_id))
for the other two paths