Skip to content
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

Replace all const evaluation with miri #46882

Merged
merged 110 commits into from
Mar 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
110 commits
Select commit Hold shift + click to select a range
38b5ddd
Add a variant to ConstVal for storing miri results
oli-obk Jan 16, 2018
c0574c0
Add miri errors to the const eval error enum
oli-obk Jan 16, 2018
918b6d7
Produce instead of pointers
oli-obk Jan 16, 2018
e97089d
Move librustc_const_eval to librustc_mir
oli-obk Dec 27, 2017
0b9db57
Resolve variant field access
oli-obk Jan 16, 2018
28572d2
Nuke the entire ctfe from orbit, it's the only way to be sure
oli-obk Jan 16, 2018
4c9b1b1
Initial changes to librustc to support const trait fns.
alexreg Jan 6, 2018
b2b101b
Prepare for using miri in trans
alexreg Jan 2, 2018
b33e4e7
Fully use miri in trans
oli-obk Jan 16, 2018
246d05b
Evaluate 128 lowering lang items manually
oli-obk Jan 14, 2018
f73d4ac
Implement on disk cache for AllocId
oli-obk Jan 14, 2018
0595ff1
Codegen tests
oli-obk Jan 15, 2018
e0045ab
Add tests for fixed issues
oli-obk Jan 16, 2018
7d2d4e3
Add InterpretInterner to StableHashingContext for AllocId serialization
oli-obk Jan 16, 2018
9d9a69d
Print whether the stackframe is for a promoted
oli-obk Jan 22, 2018
4caf6a9
Additional sanity assertion
oli-obk Jan 22, 2018
f14e746
Enable const prop to also evaluate constants, not just literals
oli-obk Jan 23, 2018
d3e2f48
More const eval sanity checks (invalid slice fat pointers)
oli-obk Jan 23, 2018
34772aa
Allow writing mutable statics in miri by adding them to the Machine
oli-obk Jan 25, 2018
1d438f8
Allow tools (e.g. miri) to enable rust logging
oli-obk Jan 25, 2018
37d8b9a
Don't borrow the interpret_interner for anything but a direct functio…
oli-obk Jan 25, 2018
d26ebec
Hide the RefCell inside InterpretInterner
oli-obk Jan 25, 2018
3d8c4d4
Don't read from zero sized fields
oli-obk Jan 25, 2018
4f6c557
Wrap the miri ErrorKind in an Rc to reduce work in queries
oli-obk Jan 25, 2018
cf05661
Add test for attempting to use array indexing for conditional const eval
oli-obk Jan 25, 2018
790d131
Add test for #45044
oli-obk Jan 25, 2018
2f2c90e
Destructure Rc wrapped ErrorKind in miri
oli-obk Jan 25, 2018
3b8d2e0
Rename ConstVal::to_u128 to to_raw_bits
oli-obk Jan 25, 2018
9857eaa
Nuke ConstInt and Const*size
oli-obk Jan 25, 2018
bdda119
Use layout::Integer over manual *size resolving
oli-obk Jan 26, 2018
03ef614
Rename simd shuffle function and adjust comment
oli-obk Jan 26, 2018
8c2db0b
Stop emitting `miri failed` in error messages
oli-obk Jan 26, 2018
c5d2e17
Prefer enum instead of magic numbers
oli-obk Jan 26, 2018
8a93972
Use Mutability enum instead of bool
oli-obk Jan 26, 2018
b75a828
Reduce noise in error reporting
oli-obk Jan 26, 2018
0e2da01
Move compare_const_vals out of `eval`
oli-obk Jan 26, 2018
b38e8af
Remove unused function
oli-obk Jan 26, 2018
57f9e0e
Move lit_to_const to `pattern` and remove the now-empty `eval` module
oli-obk Jan 26, 2018
1543367
The `const_eval` module is no more
oli-obk Jan 26, 2018
bb81f9b
only export the two check* functions from check_match
oli-obk Jan 26, 2018
ef995bd
Move the pattern checking code to hair
oli-obk Jan 26, 2018
4f65261
Remove unused error variants and const eval types
oli-obk Jan 26, 2018
f8602ac
Explain the existance of `is_binop_lang_item`
oli-obk Jan 26, 2018
4fbf119
Accidental paste
oli-obk Jan 26, 2018
5125d58
Simplify code around reading/writing ConstVals
oli-obk Jan 26, 2018
df6b40e
Add regression tests
oli-obk Jan 27, 2018
5b247b9
Report errors in statics during collecting instead of translating
oli-obk Jan 27, 2018
edb2af5
Don't use scary block reorderings
oli-obk Jan 28, 2018
54615ec
Split const prop into its own pass
oli-obk Jan 28, 2018
00c95b2
Revert all changes to the instcombine pass
oli-obk Jan 29, 2018
e549f0b
Simplify const SIMD shuffle in trans
oli-obk Jan 29, 2018
21554b9
Fix ICE in const prop
oli-obk Jan 29, 2018
d57a109
Adjust tests to more aggressive const err linting
oli-obk Jan 29, 2018
ec857e1
Deduplicate code in rustdoc
oli-obk Jan 29, 2018
4667346
Remove the fragile const propagator and just do linting
oli-obk Jan 29, 2018
e093ab0
Adjust tests to changed const err lints
oli-obk Jan 29, 2018
c568807
Remove single field struct by just using the field
oli-obk Jan 29, 2018
0f72f00
Remove redundant warnings in rustc_trans
Jan 29, 2018
8c8a433
Merge const linting pass into const prop
Jan 29, 2018
929a4ce
Use IndexVec instead of FxHashMap
Jan 29, 2018
438139f
rustc_passes::consts -> rvalue_promotion
oli-obk Jan 29, 2018
13c0dc5
Only report bitshift lints on bitshift ops
oli-obk Jan 29, 2018
600fcc7
Report const eval errors at the correct span
oli-obk Jan 29, 2018
45abb1b
Stabilize const_indexing feature
oli-obk Jan 29, 2018
ceb634a
Update tests
oli-obk Jan 29, 2018
16d560f
Remove unused error E0020
oli-obk Jan 30, 2018
0462d09
Figure out const propgatable locals in a single pass
oli-obk Jan 30, 2018
65ed591
Move the resource limits to the session in preparation for attributes…
oli-obk Jan 30, 2018
57ae890
Simplify const prop checks through PlaceContext
oli-obk Jan 30, 2018
411fcf5
Rename OptimizationFinder and don't propagate any borrows
oli-obk Jan 30, 2018
1561b4a
Simplify const propagator by removing unused code paths
oli-obk Jan 30, 2018
05a03d7
Update tests
oli-obk Jan 30, 2018
dde68dc
Can only const prop temporaries
oli-obk Jan 30, 2018
a678044
Add regression test for const prop
oli-obk Jan 30, 2018
64fbf5d
Compute the ParamEnv only once and use it to call tcx.const_eval
oli-obk Jan 31, 2018
d2f363b
Report all errors other than those about insufficient type information
oli-obk Jan 31, 2018
8c53d54
Update tests
oli-obk Jan 31, 2018
bd03371
Add stack traces to miri errors
oli-obk Jan 31, 2018
8500c2f
Const eval error refactoring
oli-obk Jan 31, 2018
3c663d0
Tidy fix
oli-obk Jan 31, 2018
b985399
Reduce code duplication
oli-obk Feb 6, 2018
1f9d846
Add some documentation to pattern/const conversions
oli-obk Feb 6, 2018
f5cc5ca
Remove dead code
oli-obk Feb 6, 2018
421622d
Stage 2 doesn't see suggestion_approximate
oli-obk Feb 6, 2018
5b698a1
Unregress error spans in constant errors
oli-obk Feb 6, 2018
0a1278a
Typo
oli-obk Feb 6, 2018
f68dc01
Add a test for transmuting via unions in constants
oli-obk Feb 6, 2018
f363e08
Update compile-fail tests
oli-obk Feb 6, 2018
1e653aa
Report a best guess span if no stack is available anymore
oli-obk Feb 6, 2018
2f0e077
Report tcx errors with the span of the currently evaluating statement
oli-obk Feb 6, 2018
d98a2b9
Rebase fallout
oli-obk Feb 9, 2018
b63c6bb
Add regression test
oli-obk Feb 19, 2018
0ca4b45
Step limit is now terminator limit
oli-obk Feb 19, 2018
134c291
Const eval will oom together with rustc now
oli-obk Feb 20, 2018
7218836
Fix mozjs crater failure
oli-obk Feb 20, 2018
df283df
Don't use the undefined bytes of PrimVal::Bytes
oli-obk Feb 21, 2018
889a4eb
Deduplicate some code
oli-obk Feb 22, 2018
e8d357f
Decide signdedness on the layout instead of the type
oli-obk Feb 22, 2018
208d764
Adjust test which differs between 32 bit and 64 bit
oli-obk Feb 22, 2018
47913ee
Address review comments
oli-obk Feb 22, 2018
3dc7e93
Generator assertions are unconditionally triggered
oli-obk Feb 23, 2018
2730256
Remove unused error code
oli-obk Feb 23, 2018
eb18d39
Reuse `Integer::from_attr`
oli-obk Feb 23, 2018
6cfda07
Use clearer name for integer bit width helper function
oli-obk Feb 23, 2018
aedd4c6
Regenerate tests
oli-obk Mar 5, 2018
edc5f73
Correct the shift overflow check in miri
oli-obk Mar 6, 2018
b5ace9a
Unify the const folding errors
oli-obk Mar 6, 2018
c0fc6a8
simplify constant value pair field access
oli-obk Mar 6, 2018
47e0bb5
Clean up the binary hex lint
oli-obk Mar 7, 2018
52dec0e
Don't derive traits on packed structs
oli-obk Mar 7, 2018
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
21 changes: 3 additions & 18 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/doc/rustc-ux-guidelines.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ for details on how to format and write long error codes.
[librustc](https://github.com/rust-lang/rust/blob/master/src/librustc/diagnostics.rs),
[libsyntax](https://github.com/rust-lang/rust/blob/master/src/libsyntax/diagnostics.rs),
[librustc_borrowck](https://github.com/rust-lang/rust/blob/master/src/librustc_borrowck/diagnostics.rs),
[librustc_const_eval](https://github.com/rust-lang/rust/blob/master/src/librustc_const_eval/diagnostics.rs),
[librustc_metadata](https://github.com/rust-lang/rust/blob/master/src/librustc_metadata/diagnostics.rs),
[librustc_mir](https://github.com/rust-lang/rust/blob/master/src/librustc_mir/diagnostics.rs),
[librustc_passes](https://github.com/rust-lang/rust/blob/master/src/librustc_passes/diagnostics.rs),
Expand Down
19 changes: 0 additions & 19 deletions src/doc/unstable-book/src/language-features/const-indexing.md

This file was deleted.

4 changes: 3 additions & 1 deletion src/libcore/cmp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ impl<T: Ord> Ord for Reverse<T> {
/// }
/// }
/// ```
#[cfg_attr(not(stage0), lang = "ord")]
#[stable(feature = "rust1", since = "1.0.0")]
pub trait Ord: Eq + PartialOrd<Self> {
/// This method returns an `Ordering` between `self` and `other`.
Expand Down Expand Up @@ -596,7 +597,8 @@ impl PartialOrd for Ordering {
/// assert_eq!(x < y, true);
/// assert_eq!(x.lt(&y), true);
/// ```
#[lang = "ord"]
#[cfg_attr(stage0, lang = "ord")]
#[cfg_attr(not(stage0), lang = "partial_ord")]
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_on_unimplemented = "can't compare `{Self}` with `{Rhs}`"]
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {
Expand Down
10 changes: 5 additions & 5 deletions src/librustc/dep_graph/dep_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@
//! user of the `DepNode` API of having to know how to compute the expected
//! fingerprint for a given set of node parameters.

use mir::interpret::{GlobalId};
use hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
use hir::map::DefPathHash;
use hir::{HirId, ItemLocalId};

use ich::Fingerprint;
use ich::{Fingerprint, StableHashingContext};
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
use ty::{TyCtxt, Instance, InstanceDef, ParamEnv, ParamEnvAnd, PolyTraitRef, Ty};
use ty::subst::Substs;
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
use ich::StableHashingContext;
use std::fmt;
use std::hash::Hash;
use syntax_pos::symbol::InternedString;
Expand Down Expand Up @@ -518,7 +518,7 @@ define_dep_nodes!( <'tcx>
[] TypeckTables(DefId),
[] UsedTraitImports(DefId),
[] HasTypeckTables(DefId),
[] ConstEval { param_env: ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)> },
[] ConstEval { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
[] CheckMatch(DefId),
[] SymbolName(DefId),
[] InstanceSymbolName { instance: Instance<'tcx> },
Expand Down Expand Up @@ -661,7 +661,7 @@ trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
}

impl<'a, 'gcx: 'tcx + 'a, 'tcx: 'a, T> DepNodeParams<'a, 'gcx, 'tcx> for T
where T: HashStable<StableHashingContext<'gcx>> + fmt::Debug
where T: HashStable<StableHashingContext<'a>> + fmt::Debug
{
default const CAN_RECONSTRUCT_QUERY_KEY: bool = false;

Expand Down
13 changes: 0 additions & 13 deletions src/librustc/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@
// Each message should start and end with a new line, and be wrapped to 80 characters.
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
register_long_diagnostics! {
E0020: r##"
This error indicates that an attempt was made to divide by zero (or take the
remainder of a zero divisor) in a static or constant expression. Erroneous
code example:

```compile_fail
#[deny(const_err)]

const X: i32 = 42 / 0;
// error: attempt to divide by zero in a constant expression
```
"##,

E0038: r##"
Trait objects like `Box<Trait>` can only be constructed when certain
requirements are satisfied by the trait in question.
Expand Down
1 change: 0 additions & 1 deletion src/librustc/hir/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,6 @@ impl serialize::UseSpecializedDecodable for DefId {}
pub struct LocalDefId(DefIndex);

impl LocalDefId {

#[inline]
pub fn from_def_id(def_id: DefId) -> LocalDefId {
assert!(def_id.is_local());
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/hir/map/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ struct HirItemLike<T> {
hash_bodies: bool,
}

impl<'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
impl<'a, 'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
where T: HashStable<StableHashingContext<'hir>>
{
fn hash_stable<W: StableHasherResult>(&self,
Expand Down
64 changes: 32 additions & 32 deletions src/librustc/ich/hcx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ pub fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
/// a reference to the TyCtxt) and it holds a few caches for speeding up various
/// things (e.g. each DefId/DefPath is only hashed once).
#[derive(Clone)]
pub struct StableHashingContext<'gcx> {
sess: &'gcx Session,
definitions: &'gcx Definitions,
cstore: &'gcx dyn CrateStore,
body_resolver: BodyResolver<'gcx>,
pub struct StableHashingContext<'a> {
sess: &'a Session,
definitions: &'a Definitions,
cstore: &'a dyn CrateStore,
body_resolver: BodyResolver<'a>,
hash_spans: bool,
hash_bodies: bool,
node_id_hashing_mode: NodeIdHashingMode,

// Very often, we are hashing something that does not need the
// CachingCodemapView, so we initialize it lazily.
raw_codemap: &'gcx CodeMap,
caching_codemap: Option<CachingCodemapView<'gcx>>,
raw_codemap: &'a CodeMap,
caching_codemap: Option<CachingCodemapView<'a>>,
}

#[derive(PartialEq, Eq, Clone, Copy)]
Expand All @@ -81,14 +81,14 @@ impl<'gcx> BodyResolver<'gcx> {
}
}

impl<'gcx> StableHashingContext<'gcx> {
impl<'a> StableHashingContext<'a> {
// The `krate` here is only used for mapping BodyIds to Bodies.
// Don't use it for anything else or you'll run the risk of
// leaking data out of the tracking system.
pub fn new(sess: &'gcx Session,
krate: &'gcx hir::Crate,
definitions: &'gcx Definitions,
cstore: &'gcx dyn CrateStore)
pub fn new(sess: &'a Session,
krate: &'a hir::Crate,
definitions: &'a Definitions,
cstore: &'a dyn CrateStore)
-> Self {
let hash_spans_initial = !sess.opts.debugging_opts.incremental_ignore_spans;

Expand All @@ -106,7 +106,7 @@ impl<'gcx> StableHashingContext<'gcx> {
}

#[inline]
pub fn sess(&self) -> &'gcx Session {
pub fn sess(&self) -> &'a Session {
self.sess
}

Expand Down Expand Up @@ -165,7 +165,7 @@ impl<'gcx> StableHashingContext<'gcx> {
}

#[inline]
pub fn codemap(&mut self) -> &mut CachingCodemapView<'gcx> {
pub fn codemap(&mut self) -> &mut CachingCodemapView<'a> {
match self.caching_codemap {
Some(ref mut cm) => {
cm
Expand Down Expand Up @@ -193,38 +193,38 @@ impl<'gcx> StableHashingContext<'gcx> {
}

impl<'a, 'gcx, 'lcx> StableHashingContextProvider for TyCtxt<'a, 'gcx, 'lcx> {
type ContextType = StableHashingContext<'gcx>;
type ContextType = StableHashingContext<'a>;
fn create_stable_hashing_context(&self) -> Self::ContextType {
(*self).create_stable_hashing_context()
}
}


impl<'gcx> StableHashingContextProvider for StableHashingContext<'gcx> {
type ContextType = StableHashingContext<'gcx>;
impl<'a> StableHashingContextProvider for StableHashingContext<'a> {
type ContextType = StableHashingContext<'a>;
fn create_stable_hashing_context(&self) -> Self::ContextType {
self.clone()
}
}

impl<'gcx> ::dep_graph::DepGraphSafe for StableHashingContext<'gcx> {
impl<'a> ::dep_graph::DepGraphSafe for StableHashingContext<'a> {
}


impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::BodyId {
impl<'a> HashStable<StableHashingContext<'a>> for hir::BodyId {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'gcx>,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
if hcx.hash_bodies() {
hcx.body_resolver.body(*self).hash_stable(hcx, hasher);
}
}
}

impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::HirId {
impl<'a> HashStable<StableHashingContext<'a>> for hir::HirId {
#[inline]
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'gcx>,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
match hcx.node_id_hashing_mode {
NodeIdHashingMode::Ignore => {
Expand All @@ -243,21 +243,21 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::HirId {
}
}

impl<'gcx> ToStableHashKey<StableHashingContext<'gcx>> for hir::HirId {
impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::HirId {
type KeyType = (DefPathHash, hir::ItemLocalId);

#[inline]
fn to_stable_hash_key(&self,
hcx: &StableHashingContext<'gcx>)
hcx: &StableHashingContext<'a>)
-> (DefPathHash, hir::ItemLocalId) {
let def_path_hash = hcx.local_def_path_hash(self.owner);
(def_path_hash, self.local_id)
}
}

impl<'gcx> HashStable<StableHashingContext<'gcx>> for ast::NodeId {
impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'gcx>,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
match hcx.node_id_hashing_mode {
NodeIdHashingMode::Ignore => {
Expand All @@ -270,18 +270,18 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for ast::NodeId {
}
}

impl<'gcx> ToStableHashKey<StableHashingContext<'gcx>> for ast::NodeId {
impl<'a> ToStableHashKey<StableHashingContext<'a>> for ast::NodeId {
type KeyType = (DefPathHash, hir::ItemLocalId);

#[inline]
fn to_stable_hash_key(&self,
hcx: &StableHashingContext<'gcx>)
hcx: &StableHashingContext<'a>)
-> (DefPathHash, hir::ItemLocalId) {
hcx.definitions.node_to_hir_id(*self).to_stable_hash_key(hcx)
}
}

impl<'gcx> HashStable<StableHashingContext<'gcx>> for Span {
impl<'a> HashStable<StableHashingContext<'a>> for Span {

// Hash a span in a stable way. We can't directly hash the span's BytePos
// fields (that would be similar to hashing pointers, since those are just
Expand All @@ -293,7 +293,7 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for Span {
// Also, hashing filenames is expensive so we avoid doing it twice when the
// span starts and ends in the same file, which is almost always the case.
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'gcx>,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
const TAG_VALID_SPAN: u8 = 0;
const TAG_INVALID_SPAN: u8 = 1;
Expand Down Expand Up @@ -373,8 +373,8 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for Span {
}
}

pub fn hash_stable_trait_impls<'gcx, W, R>(
hcx: &mut StableHashingContext<'gcx>,
pub fn hash_stable_trait_impls<'a, 'gcx, W, R>(
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>,
blanket_impls: &Vec<DefId>,
non_blanket_impls: &HashMap<fast_reject::SimplifiedType, Vec<DefId>, R>)
Expand Down
Loading