Skip to content

Commit c90f682

Browse files
committed
Auto merge of #46882 - oli-obk:miri3, r=eddyb
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) * can use `union`s to implement `transmute` for `Copy` types in constants without a feature gate. With all the greatness and nasal demons that come with this. * can convert integers to `&'static T` in constants (useful for embedded) 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) fixes #45044 (pattern matching repeat expressions) fixes #47971 (ICE on const fn + references) fixes #48081 (ICE on cyclic assoc const error) fixes #48746 (nonhelpful error message with unions) r? @eddyb even though 1k loc are added in tests, this PR reduces the loc in this repository by 700
2 parents cdcca78 + 52dec0e commit c90f682

File tree

251 files changed

+6638
-7166
lines changed

Some content is hidden

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

251 files changed

+6638
-7166
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/doc/unstable-book/src/language-features/const-indexing.md

-19
This file was deleted.

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;
@@ -518,7 +518,7 @@ define_dep_nodes!( <'tcx>
518518
[] TypeckTables(DefId),
519519
[] UsedTraitImports(DefId),
520520
[] HasTypeckTables(DefId),
521-
[] ConstEval { param_env: ParamEnvAnd<'tcx, (DefId, &'tcx Substs<'tcx>)> },
521+
[] ConstEval { param_env: ParamEnvAnd<'tcx, GlobalId<'tcx>> },
522522
[] CheckMatch(DefId),
523523
[] SymbolName(DefId),
524524
[] InstanceSymbolName { instance: Instance<'tcx> },
@@ -661,7 +661,7 @@ trait DepNodeParams<'a, 'gcx: 'tcx + 'a, 'tcx: 'a> : fmt::Debug {
661661
}
662662

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

src/librustc/diagnostics.rs

-13
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,6 @@
1414
// Each message should start and end with a new line, and be wrapped to 80 characters.
1515
// In vim you can `:set tw=80` and use `gq` to wrap paragraphs. Use `:set tw=0` to disable.
1616
register_long_diagnostics! {
17-
E0020: r##"
18-
This error indicates that an attempt was made to divide by zero (or take the
19-
remainder of a zero divisor) in a static or constant expression. Erroneous
20-
code example:
21-
22-
```compile_fail
23-
#[deny(const_err)]
24-
25-
const X: i32 = 42 / 0;
26-
// error: attempt to divide by zero in a constant expression
27-
```
28-
"##,
29-
3017
E0038: r##"
3118
Trait objects like `Box<Trait>` can only be constructed when certain
3219
requirements are satisfied by the trait in question.

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
@@ -529,7 +529,7 @@ struct HirItemLike<T> {
529529
hash_bodies: bool,
530530
}
531531

532-
impl<'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
532+
impl<'a, 'hir, T> HashStable<StableHashingContext<'hir>> for HirItemLike<T>
533533
where T: HashStable<StableHashingContext<'hir>>
534534
{
535535
fn hash_stable<W: StableHasherResult>(&self,

src/librustc/ich/hcx.rs

+32-32
Original file line numberDiff line numberDiff line change
@@ -46,19 +46,19 @@ pub fn compute_ignored_attr_names() -> FxHashSet<Symbol> {
4646
/// a reference to the TyCtxt) and it holds a few caches for speeding up various
4747
/// things (e.g. each DefId/DefPath is only hashed once).
4848
#[derive(Clone)]
49-
pub struct StableHashingContext<'gcx> {
50-
sess: &'gcx Session,
51-
definitions: &'gcx Definitions,
52-
cstore: &'gcx dyn CrateStore,
53-
body_resolver: BodyResolver<'gcx>,
49+
pub struct StableHashingContext<'a> {
50+
sess: &'a Session,
51+
definitions: &'a Definitions,
52+
cstore: &'a dyn CrateStore,
53+
body_resolver: BodyResolver<'a>,
5454
hash_spans: bool,
5555
hash_bodies: bool,
5656
node_id_hashing_mode: NodeIdHashingMode,
5757

5858
// Very often, we are hashing something that does not need the
5959
// CachingCodemapView, so we initialize it lazily.
60-
raw_codemap: &'gcx CodeMap,
61-
caching_codemap: Option<CachingCodemapView<'gcx>>,
60+
raw_codemap: &'a CodeMap,
61+
caching_codemap: Option<CachingCodemapView<'a>>,
6262
}
6363

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

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

@@ -106,7 +106,7 @@ impl<'gcx> StableHashingContext<'gcx> {
106106
}
107107

108108
#[inline]
109-
pub fn sess(&self) -> &'gcx Session {
109+
pub fn sess(&self) -> &'a Session {
110110
self.sess
111111
}
112112

@@ -165,7 +165,7 @@ impl<'gcx> StableHashingContext<'gcx> {
165165
}
166166

167167
#[inline]
168-
pub fn codemap(&mut self) -> &mut CachingCodemapView<'gcx> {
168+
pub fn codemap(&mut self) -> &mut CachingCodemapView<'a> {
169169
match self.caching_codemap {
170170
Some(ref mut cm) => {
171171
cm
@@ -193,38 +193,38 @@ impl<'gcx> StableHashingContext<'gcx> {
193193
}
194194

195195
impl<'a, 'gcx, 'lcx> StableHashingContextProvider for TyCtxt<'a, 'gcx, 'lcx> {
196-
type ContextType = StableHashingContext<'gcx>;
196+
type ContextType = StableHashingContext<'a>;
197197
fn create_stable_hashing_context(&self) -> Self::ContextType {
198198
(*self).create_stable_hashing_context()
199199
}
200200
}
201201

202202

203-
impl<'gcx> StableHashingContextProvider for StableHashingContext<'gcx> {
204-
type ContextType = StableHashingContext<'gcx>;
203+
impl<'a> StableHashingContextProvider for StableHashingContext<'a> {
204+
type ContextType = StableHashingContext<'a>;
205205
fn create_stable_hashing_context(&self) -> Self::ContextType {
206206
self.clone()
207207
}
208208
}
209209

210-
impl<'gcx> ::dep_graph::DepGraphSafe for StableHashingContext<'gcx> {
210+
impl<'a> ::dep_graph::DepGraphSafe for StableHashingContext<'a> {
211211
}
212212

213213

214-
impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::BodyId {
214+
impl<'a> HashStable<StableHashingContext<'a>> for hir::BodyId {
215215
fn hash_stable<W: StableHasherResult>(&self,
216-
hcx: &mut StableHashingContext<'gcx>,
216+
hcx: &mut StableHashingContext<'a>,
217217
hasher: &mut StableHasher<W>) {
218218
if hcx.hash_bodies() {
219219
hcx.body_resolver.body(*self).hash_stable(hcx, hasher);
220220
}
221221
}
222222
}
223223

224-
impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::HirId {
224+
impl<'a> HashStable<StableHashingContext<'a>> for hir::HirId {
225225
#[inline]
226226
fn hash_stable<W: StableHasherResult>(&self,
227-
hcx: &mut StableHashingContext<'gcx>,
227+
hcx: &mut StableHashingContext<'a>,
228228
hasher: &mut StableHasher<W>) {
229229
match hcx.node_id_hashing_mode {
230230
NodeIdHashingMode::Ignore => {
@@ -243,21 +243,21 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for hir::HirId {
243243
}
244244
}
245245

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

249249
#[inline]
250250
fn to_stable_hash_key(&self,
251-
hcx: &StableHashingContext<'gcx>)
251+
hcx: &StableHashingContext<'a>)
252252
-> (DefPathHash, hir::ItemLocalId) {
253253
let def_path_hash = hcx.local_def_path_hash(self.owner);
254254
(def_path_hash, self.local_id)
255255
}
256256
}
257257

258-
impl<'gcx> HashStable<StableHashingContext<'gcx>> for ast::NodeId {
258+
impl<'a> HashStable<StableHashingContext<'a>> for ast::NodeId {
259259
fn hash_stable<W: StableHasherResult>(&self,
260-
hcx: &mut StableHashingContext<'gcx>,
260+
hcx: &mut StableHashingContext<'a>,
261261
hasher: &mut StableHasher<W>) {
262262
match hcx.node_id_hashing_mode {
263263
NodeIdHashingMode::Ignore => {
@@ -270,18 +270,18 @@ impl<'gcx> HashStable<StableHashingContext<'gcx>> for ast::NodeId {
270270
}
271271
}
272272

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

276276
#[inline]
277277
fn to_stable_hash_key(&self,
278-
hcx: &StableHashingContext<'gcx>)
278+
hcx: &StableHashingContext<'a>)
279279
-> (DefPathHash, hir::ItemLocalId) {
280280
hcx.definitions.node_to_hir_id(*self).to_stable_hash_key(hcx)
281281
}
282282
}
283283

284-
impl<'gcx> HashStable<StableHashingContext<'gcx>> for Span {
284+
impl<'a> HashStable<StableHashingContext<'a>> for Span {
285285

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

376-
pub fn hash_stable_trait_impls<'gcx, W, R>(
377-
hcx: &mut StableHashingContext<'gcx>,
376+
pub fn hash_stable_trait_impls<'a, 'gcx, W, R>(
377+
hcx: &mut StableHashingContext<'a>,
378378
hasher: &mut StableHasher<W>,
379379
blanket_impls: &Vec<DefId>,
380380
non_blanket_impls: &HashMap<fast_reject::SimplifiedType, Vec<DefId>, R>)

0 commit comments

Comments
 (0)