Skip to content

Implement dataflow-based const validation #64470

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 31 commits into from
Sep 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
717c64e
Silence "skipping const checks" if outside a const context
ecstatic-morse Sep 17, 2019
457c3aa
Add additional `const` tests
ecstatic-morse Sep 17, 2019
e81297d
Add analysis to determine if a local is indirectly mutable
ecstatic-morse Sep 17, 2019
83a3e04
Don't treat locals as mutably borrowed after they're dropped
ecstatic-morse Sep 17, 2019
eec93ca
Copy `Qualif` to start work on new const validator
ecstatic-morse Sep 17, 2019
3a5442a
Remove unnecessary method
ecstatic-morse Sep 17, 2019
c2e121d
Make new qualifs public
ecstatic-morse Sep 17, 2019
48d3843
Add requisite imports and bitset to hold qualifs
ecstatic-morse Sep 17, 2019
3758e38
Remove reference to `Mode::NonConstFn` in qualifs
ecstatic-morse Sep 17, 2019
908dcb8
Control whether a `Qualif` is cleared on move
ecstatic-morse Sep 17, 2019
3698d04
Pass current qualification state in a separate parameter
ecstatic-morse Sep 17, 2019
fc92d3b
Add dataflow-based const validation
ecstatic-morse Sep 17, 2019
c990243
Run new validator in compare mode
ecstatic-morse Sep 17, 2019
670c84d
Fix tests broken by more consistent miri unleashed warnings
ecstatic-morse Sep 17, 2019
27bd849
Correct list of miri-supported operations
ecstatic-morse Sep 20, 2019
f2ff425
Add rationale for `suppress_errors` flag
ecstatic-morse Sep 20, 2019
e296436
Remember to replace ICE with some form of warning
ecstatic-morse Sep 20, 2019
b3e59bb
Move non-const ops into their own module
ecstatic-morse Sep 20, 2019
93ee779
Explain why `visit_terminator` does nothing for `IndirectlyMutableLoc…
ecstatic-morse Sep 20, 2019
bc7928a
Trigger ICE on nightly if validators disagree
ecstatic-morse Sep 24, 2019
406ac2e
Give usage instructions `IndirectlyMutableLocals` docs
ecstatic-morse Sep 25, 2019
2f5ea63
Return a `bool` from `in_any_value_of_ty`
ecstatic-morse Sep 25, 2019
dcecefc
Use conservative, type-based qualifcation for statics
ecstatic-morse Sep 25, 2019
1a14d17
Require `fmt::Debug` to implement `NonConstOp`
ecstatic-morse Sep 25, 2019
713ec15
Share `IndirectlyMutableLocals` results via reference
ecstatic-morse Sep 25, 2019
ff6faab
Add description for every module in `check_consts`
ecstatic-morse Sep 25, 2019
a302055
Mask results from flow-sensitive resolver with `in_any_value_of_ty`
ecstatic-morse Sep 25, 2019
8bfe82b
Correct `IndirectlyMutableLocals` docs
ecstatic-morse Sep 25, 2019
f2e7faf
Revert "Use conservative, type-based qualifcation for statics"
ecstatic-morse Sep 25, 2019
ff4158a
Bless miri unleashed output
ecstatic-morse Sep 25, 2019
0bf1a80
Rename `sty` to `kind`
ecstatic-morse Sep 28, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix tests broken by more consistent miri unleashed warnings
  • Loading branch information
ecstatic-morse committed Sep 28, 2019
commit 670c84dde3ad25f113b00436066a65a0dfb808cd
144 changes: 9 additions & 135 deletions src/test/ui/consts/const-eval/const_fn_ptr.stderr
Original file line number Diff line number Diff line change
@@ -1,146 +1,20 @@
warning: skipping const checks
--> $DIR/const_fn_ptr.rs:25:5
--> $DIR/const_fn_ptr.rs:12:5
|
LL | assert_eq!(Y, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:25:5
|
LL | assert_eq!(Y, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:25:5
|
LL | assert_eq!(Y, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:27:5
|
LL | assert_eq!(y, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:27:5
|
LL | assert_eq!(y, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:27:5
|
LL | assert_eq!(y, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:29:5
|
LL | assert_eq!(y, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:29:5
|
LL | assert_eq!(y, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
LL | X(x)
| ^^^^

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:29:5
|
LL | assert_eq!(y, 4);
| ^^^^^^^^^^^^^^^^^
--> $DIR/const_fn_ptr.rs:16:5
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
LL | X_const(x)
| ^^^^^^^^^^

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:32:5
|
LL | assert_eq!(Z, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:32:5
|
LL | assert_eq!(Z, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:32:5
|
LL | assert_eq!(Z, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:34:5
|
LL | assert_eq!(z, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:34:5
|
LL | assert_eq!(z, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:34:5
|
LL | assert_eq!(z, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:36:5
|
LL | assert_eq!(z, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:36:5
|
LL | assert_eq!(z, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr.rs:36:5
|
LL | assert_eq!(z, 4);
| ^^^^^^^^^^^^^^^^^
--> $DIR/const_fn_ptr.rs:20:5
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
LL | x(y)
| ^^^^

warning: constant `X_const` should have an upper case name
--> $DIR/const_fn_ptr.rs:9:7
Expand Down
1 change: 1 addition & 0 deletions src/test/ui/consts/const-eval/const_fn_ptr_fail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const X: fn(usize) -> usize = double;

const fn bar(x: usize) -> usize {
X(x) // FIXME: this should error someday
//~^ WARN: skipping const checks
}

fn main() {}
6 changes: 6 additions & 0 deletions src/test/ui/consts/const-eval/const_fn_ptr_fail.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
warning: skipping const checks
--> $DIR/const_fn_ptr_fail.rs:10:5
|
LL | X(x) // FIXME: this should error someday
| ^^^^

8 changes: 1 addition & 7 deletions src/test/ui/consts/const-eval/const_fn_ptr_fail2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ fn double(x: usize) -> usize { x * 2 }
const X: fn(usize) -> usize = double;

const fn bar(x: fn(usize) -> usize, y: usize) -> usize {
x(y)
x(y) //~ WARN skipping const checks
}

const Y: usize = bar(X, 2); // FIXME: should fail to typeck someday
Expand All @@ -15,12 +15,6 @@ const Z: usize = bar(double, 2); // FIXME: should fail to typeck someday
fn main() {
assert_eq!(Y, 4);
//~^ ERROR evaluation of constant expression failed
//~^^ WARN skipping const checks
//~^^^ WARN skipping const checks
//~^^^^ WARN skipping const checks
assert_eq!(Z, 4);
//~^ ERROR evaluation of constant expression failed
//~^^ WARN skipping const checks
//~^^^ WARN skipping const checks
//~^^^^ WARN skipping const checks
}
50 changes: 4 additions & 46 deletions src/test/ui/consts/const-eval/const_fn_ptr_fail2.stderr
Original file line number Diff line number Diff line change
@@ -1,50 +1,8 @@
warning: skipping const checks
--> $DIR/const_fn_ptr_fail2.rs:16:5
|
LL | assert_eq!(Y, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr_fail2.rs:16:5
|
LL | assert_eq!(Y, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr_fail2.rs:16:5
|
LL | assert_eq!(Y, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr_fail2.rs:21:5
|
LL | assert_eq!(Z, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr_fail2.rs:21:5
|
LL | assert_eq!(Z, 4);
| ^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/const_fn_ptr_fail2.rs:21:5
|
LL | assert_eq!(Z, 4);
| ^^^^^^^^^^^^^^^^^
--> $DIR/const_fn_ptr_fail2.rs:9:5
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
LL | x(y)
| ^^^^

error[E0080]: evaluation of constant expression failed
--> $DIR/const_fn_ptr_fail2.rs:16:5
Expand All @@ -57,7 +15,7 @@ LL | assert_eq!(Y, 4);
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0080]: evaluation of constant expression failed
--> $DIR/const_fn_ptr_fail2.rs:21:5
--> $DIR/const_fn_ptr_fail2.rs:18:5
|
LL | assert_eq!(Z, 4);
| ^^^^^^^^^^^-^^^^^
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/consts/miri_unleashed/assoc_const.stderr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
warning: skipping const checks
--> $DIR/assoc_const.rs:12:31
--> $DIR/assoc_const.rs:12:20
|
LL | const F: u32 = (U::X, 42).1;
| ^
| ^^^^^^^^^^

error[E0080]: erroneous constant used
--> $DIR/assoc_const.rs:29:13
Expand Down
48 changes: 0 additions & 48 deletions src/test/ui/consts/miri_unleashed/enum_discriminants.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,3 @@ warning: skipping const checks
LL | if let E1::V2 { .. } = (E1::V1 { f: true }) {
| ^^^^^^^^^^^^^

warning: skipping const checks
--> $DIR/enum_discriminants.rs:108:5
|
LL | assert_eq!(OVERFLOW, 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/enum_discriminants.rs:108:5
|
LL | assert_eq!(OVERFLOW, 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/enum_discriminants.rs:108:5
|
LL | assert_eq!(OVERFLOW, 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/enum_discriminants.rs:109:5
|
LL | assert_eq!(MORE_OVERFLOW, 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/enum_discriminants.rs:109:5
|
LL | assert_eq!(MORE_OVERFLOW, 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

warning: skipping const checks
--> $DIR/enum_discriminants.rs:109:5
|
LL | assert_eq!(MORE_OVERFLOW, 0);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this warning originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

1 change: 1 addition & 0 deletions src/test/ui/consts/miri_unleashed/mutable_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use std::cell::UnsafeCell;

// make sure we do not just intern this as mutable
const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
//~^ WARN: skipping const checks

const MUTATING_BEHIND_RAW: () = {
// Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
Expand Down
10 changes: 8 additions & 2 deletions src/test/ui/consts/miri_unleashed/mutable_const.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
warning: skipping const checks
--> $DIR/mutable_const.rs:14:9
--> $DIR/mutable_const.rs:9:38
|
LL | const MUTABLE_BEHIND_RAW: *mut i32 = &UnsafeCell::new(42) as *const _ as *mut _;
| ^^^^^^^^^^^^^^^^^^^^

warning: skipping const checks
--> $DIR/mutable_const.rs:15:9
|
LL | *MUTABLE_BEHIND_RAW = 99
| ^^^^^^^^^^^^^^^^^^^^^^^^

error: any use of this value will cause an error
--> $DIR/mutable_const.rs:14:9
--> $DIR/mutable_const.rs:15:9
|
LL | / const MUTATING_BEHIND_RAW: () = {
LL | | // Test that `MUTABLE_BEHIND_RAW` is actually immutable, by doing this at const time.
Expand Down
6 changes: 6 additions & 0 deletions src/test/ui/consts/miri_unleashed/mutable_references.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ use std::cell::UnsafeCell;
// a test demonstrating what things we could allow with a smarter const qualification

static FOO: &&mut u32 = &&mut 42;
//~^ WARN: skipping const checks
//~| WARN: skipping const checks

static BAR: &mut () = &mut ();
//~^ WARN: skipping const checks

struct Foo<T>(T);

static BOO: &mut Foo<()> = &mut Foo(());
//~^ WARN: skipping const checks

struct Meh {
x: &'static UnsafeCell<i32>,
Expand All @@ -21,9 +25,11 @@ unsafe impl Sync for Meh {}

static MEH: Meh = Meh {
x: &UnsafeCell::new(42),
//~^ WARN: skipping const checks
};

static OH_YES: &mut i32 = &mut 42;
//~^ WARN: skipping const checks

fn main() {
unsafe {
Expand Down
Loading