Skip to content

Commit 46cc200

Browse files
committed
Auto merge of #46882 - oli-obk:miri3, r=<try>
Replace all const evaluation with miri * error reporting in constants prints a stacktrace through all called const fns * Trivial constant propagation and folding in MIR (always active, irrelevant of the optimization level) * can now use floating constants in patterns (previously only floating point literals were allowed) * the future compat lint is still produced for both cases * can index into constant arrays during const eval (previously feature gated) * can create a constant union value with field `a` and read from field `b` * can dereference references into constants * can create references inside constants (`const X: &u32 = &22`) * Tuple struct constructors can be used in constants * regression in const eval errors spans (some of these need improvements in mir debug info) * can cast floats to ints and vice versa (in constants, and even nan/inf constants) * Mir dump prints false/true instead of 0u8/1u8 * `1i8 >> [8][0]` does not lint about exceeding bitshifts anymore. * Needs const propagation across projections * `foo[I]` produces a const eval lint if `foo: [T; N]` and `N < I` * Essentially all builtin panics produce lints if they can be statically proven to trigger at runtime. This is on a best effort basis, so there might be some complex cases that don't trigger. (The runtime panic stays there, irrelevant of whether the lint is produced or not) fixes #34997 (stack overflow with many constants) fixes #25574 (deref byte strings in patterns) fixes #27918 (broken mir ICE) fixes #46114 (ICE on struct constructors in patterns) fixes #37448 (`SomeStruct { foo } as SomeStruct`) fixes #43754 (`return` in const fn) fixes #41898 (tuple struct constructors) fixes #31364 (infinite recursion with const fn, fixed by miri's recursion limit) closes #29947 (const indexing stabilization) r? @eddyb
2 parents 3bd4af8 + a1b74bb commit 46cc200

File tree

212 files changed

+5694
-5292
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

212 files changed

+5694
-5292
lines changed

src/Cargo.lock

+3-18
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/doc/rustc-ux-guidelines.md

-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ for details on how to format and write long error codes.
6464
[librustc](https://github.com/rust-lang/rust/blob/master/src/librustc/diagnostics.rs),
6565
[libsyntax](https://github.com/rust-lang/rust/blob/master/src/libsyntax/diagnostics.rs),
6666
[librustc_borrowck](https://github.com/rust-lang/rust/blob/master/src/librustc_borrowck/diagnostics.rs),
67-
[librustc_const_eval](https://github.com/rust-lang/rust/blob/master/src/librustc_const_eval/diagnostics.rs),
6867
[librustc_metadata](https://github.com/rust-lang/rust/blob/master/src/librustc_metadata/diagnostics.rs),
6968
[librustc_mir](https://github.com/rust-lang/rust/blob/master/src/librustc_mir/diagnostics.rs),
7069
[librustc_passes](https://github.com/rust-lang/rust/blob/master/src/librustc_passes/diagnostics.rs),

src/libcore/cmp.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,7 @@ impl<T: Ord> Ord for Reverse<T> {
427427
/// }
428428
/// }
429429
/// ```
430+
#[cfg_attr(not(stage0), lang = "ord")]
430431
#[stable(feature = "rust1", since = "1.0.0")]
431432
pub trait Ord: Eq + PartialOrd<Self> {
432433
/// This method returns an `Ordering` between `self` and `other`.
@@ -596,7 +597,8 @@ impl PartialOrd for Ordering {
596597
/// assert_eq!(x < y, true);
597598
/// assert_eq!(x.lt(&y), true);
598599
/// ```
599-
#[lang = "ord"]
600+
#[cfg_attr(stage0, lang = "ord")]
601+
#[cfg_attr(not(stage0), lang = "partial_ord")]
600602
#[stable(feature = "rust1", since = "1.0.0")]
601603
#[rustc_on_unimplemented = "can't compare `{Self}` with `{Rhs}`"]
602604
pub trait PartialOrd<Rhs: ?Sized = Self>: PartialEq<Rhs> {

src/librustc/dep_graph/dep_node.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,15 @@
6060
//! user of the `DepNode` API of having to know how to compute the expected
6161
//! fingerprint for a given set of node parameters.
6262
63+
use mir::interpret::{GlobalId};
6364
use hir::def_id::{CrateNum, DefId, DefIndex, CRATE_DEF_INDEX};
6465
use hir::map::DefPathHash;
6566
use hir::{HirId, ItemLocalId};
6667

67-
use ich::Fingerprint;
68+
use ich::{Fingerprint, StableHashingContext};
69+
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
6870
use ty::{TyCtxt, Instance, InstanceDef, ParamEnv, ParamEnvAnd, PolyTraitRef, Ty};
6971
use ty::subst::Substs;
70-
use rustc_data_structures::stable_hasher::{StableHasher, HashStable};
71-
use ich::StableHashingContext;
7272
use std::fmt;
7373
use std::hash::Hash;
7474
use syntax_pos::symbol::InternedString;
@@ -515,7 +515,7 @@ define_dep_nodes!( <'tcx>
515515
[] TypeckTables(DefId),
516516
[] UsedTraitImports(DefId),
517517
[] HasTypeckTables(DefId),
518-
[] ConstEval { param_env: ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)> },
518+
[] ConstEval { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
519519
[] CheckMatch(DefId),
520520
[] SymbolName(DefId),
521521
[] InstanceSymbolName { instance: Instance<'tcx> },
@@ -657,7 +657,7 @@ trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
657657
}
658658

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

src/librustc/hir/def_id.rs

-1
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ impl serialize::UseSpecializedDecodable for DefId {}
220220
pub struct LocalDefId(DefIndex);
221221

222222
impl LocalDefId {
223-
224223
#[inline]
225224
pub fn from_def_id(def_id: DefId) -> LocalDefId {
226225
assert!(def_id.is_local());

src/librustc/hir/map/collector.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ struct HirItemLike<T> {
513513
hash_bodies: bool,
514514
}
515515

516-
impl<'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
516+
impl<'a, 'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
517517
where T: HashStable<StableHashingContext<'hir>>
518518
{
519519
fn hash_stable<W: StableHasherResult>(&self,

src/librustc/ich/hcx.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -44,19 +44,19 @@ thread_local!(static IGNORED_ATTR_NAMES: RefCell<FxHashSet<Symbol>> =
4444
/// a reference to the TyCtxt) and it holds a few caches for speeding up various
4545
/// things (e.g. each DefId/DefPath is only hashed once).
4646
#[derive(Clone)]
47-
pub struct StableHashingContext<'gcx> {
48-
sess: &'gcx Session,
49-
definitions: &'gcx Definitions,
50-
cstore: &'gcx CrateStore,
51-
body_resolver: BodyResolver<'gcx>,
47+
pub struct StableHashingContext<'a> {
48+
sess: &'a Session,
49+
definitions: &'a Definitions,
50+
cstore: &'a CrateStore,
51+
body_resolver: BodyResolver<'a>,
5252
hash_spans: bool,
5353
hash_bodies: bool,
5454
node_id_hashing_mode: NodeIdHashingMode,
5555

5656
// Very often, we are hashing something that does not need the
5757
// CachingCodemapView, so we initialize it lazily.
58-
raw_codemap: &'gcx CodeMap,
59-
caching_codemap: Option<CachingCodemapView<'gcx>>,
58+
raw_codemap: &'a CodeMap,
59+
caching_codemap: Option<CachingCodemapView<'a>>,
6060
}
6161

6262
#[derive(PartialEq, Eq, Clone, Copy)]
@@ -79,14 +79,14 @@ impl<'gcx> BodyResolver<'gcx> {
7979
}
8080
}
8181

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

@@ -113,7 +113,7 @@ impl<'gcx> StableHashingContext<'gcx> {
113113
}
114114

115115
#[inline]
116-
pub fn sess(&self) -> &'gcx Session {
116+
pub fn sess(&self) -> &'a Session {
117117
self.sess
118118
}
119119

@@ -172,7 +172,7 @@ impl<'gcx> StableHashingContext<'gcx> {
172172
}
173173

174174
#[inline]
175-
pub fn codemap(&mut self) -> &mut CachingCodemapView<'gcx> {
175+
pub fn codemap(&mut self) -> &mut CachingCodemapView<'a> {
176176
match self.caching_codemap {
177177
Some(ref mut cm) => {
178178
cm
@@ -202,38 +202,38 @@ impl<'gcx> StableHashingContext<'gcx> {
202202
}
203203

204204
impl<'a, 'gcx, 'lcx> StableHashingContextProvider for TyCtxt<'a, 'gcx, 'lcx> {
205-
type ContextType = StableHashingContext<'gcx>;
205+
type ContextType = StableHashingContext<'a>;
206206
fn create_stable_hashing_context(&self) -> Self::ContextType {
207207
(*self).create_stable_hashing_context()
208208
}
209209
}
210210

211211

212-
impl<'gcx> StableHashingContextProvider for StableHashingContext<'gcx> {
213-
type ContextType = StableHashingContext<'gcx>;
212+
impl<'a> StableHashingContextProvider for StableHashingContext<'a> {
213+
type ContextType = StableHashingContext<'a>;
214214
fn create_stable_hashing_context(&self) -> Self::ContextType {
215215
self.clone()
216216
}
217217
}
218218

219-
impl<'gcx> ::dep_graph::DepGraphSafe for StableHashingContext<'gcx> {
219+
impl<'a> ::dep_graph::DepGraphSafe for StableHashingContext<'a> {
220220
}
221221

222222

223-
impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::BodyId {
223+
impl<'a> HashStable<StableHashingContext<'a>> for hir::BodyId {
224224
fn hash_stable<W: StableHasherResult>(&self,
225-
hcx: &mut StableHashingContext<'gcx>,
225+
hcx: &mut StableHashingContext<'a>,
226226
hasher: &mut StableHasher<W>) {
227227
if hcx.hash_bodies() {
228228
hcx.body_resolver.body(*self).hash_stable(hcx, hasher);
229229
}
230230
}
231231
}
232232

233-
impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::HirId {
233+
impl<'a> HashStable<StableHashingContext<'a>> for hir::HirId {
234234
#[inline]
235235
fn hash_stable<W: StableHasherResult>(&self,
236-
hcx: &mut StableHashingContext<'gcx>,
236+
hcx: &mut StableHashingContext<'a>,
237237
hasher: &mut StableHasher<W>) {
238238
match hcx.node_id_hashing_mode {
239239
NodeIdHashingMode::Ignore => {
@@ -252,21 +252,21 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::HirId {
252252
}
253253
}
254254

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

258258
#[inline]
259259
fn to_stable_hash_key(&self,
260-
hcx: &StableHashingContext<'gcx>)
260+
hcx: &StableHashingContext<'a>)
261261
-> (DefPathHash, hir::ItemLocalId) {
262262
let def_path_hash = hcx.local_def_path_hash(self.owner);
263263
(def_path_hash, self.local_id)
264264
}
265265
}
266266

267-
impl<'gcx> HashStable<StableHashingContext<'gcx>> for ast::NodeId {
267+
impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
268268
fn hash_stable<W: StableHasherResult>(&self,
269-
hcx: &mut StableHashingContext<'gcx>,
269+
hcx: &mut StableHashingContext<'a>,
270270
hasher: &mut StableHasher<W>) {
271271
match hcx.node_id_hashing_mode {
272272
NodeIdHashingMode::Ignore => {
@@ -279,18 +279,18 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for ast::NodeId {
279279
}
280280
}
281281

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

285285
#[inline]
286286
fn to_stable_hash_key(&self,
287-
hcx: &StableHashingContext<'gcx>)
287+
hcx: &StableHashingContext<'a>)
288288
-> (DefPathHash, hir::ItemLocalId) {
289289
hcx.definitions.node_to_hir_id(*self).to_stable_hash_key(hcx)
290290
}
291291
}
292292

293-
impl<'gcx> HashStable<StableHashingContext<'gcx>> for Span {
293+
impl<'a> HashStable<StableHashingContext<'a>> for Span {
294294

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

385-
pub fn hash_stable_trait_impls<'gcx, W, R>(
386-
hcx: &mut StableHashingContext<'gcx>,
385+
pub fn hash_stable_trait_impls<'a, 'gcx, W, R>(
386+
hcx: &mut StableHashingContext<'a>,
387387
hasher: &mut StableHasher<W>,
388388
blanket_impls: &Vec<DefId>,
389389
non_blanket_impls: &HashMap<fast_reject::SimplifiedType, Vec<DefId>, R>)

0 commit comments

Comments
 (0)