From 2111d6f2768911a8449df93ea5c826801e1dbf79 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Thu, 2 Jul 2020 22:06:14 +0200 Subject: [PATCH 01/25] add const generic tests --- .../auxiliary/type_dependent_lib.rs | 36 ++++++++++++++ .../type-dependent/const-arg-in-const-arg.rs | 26 ++++++++++ .../type-dependent/issue-61936.rs | 47 +++++++++++++++++++ .../type-dependent/issue-63695.rs | 17 +++++++ .../type-dependent/issue-69816.rs | 20 ++++++++ .../type-dependent/issue-70507.rs | 47 +++++++++++++++++++ .../type-dependent/issue-71382.rs | 24 ++++++++++ .../type-dependent/issue-71382.stderr | 17 +++++++ .../type-dependent/non-local.rs | 24 ++++++++++ .../ui/const-generics/type-dependent/qpath.rs | 12 +++++ .../const-generics/type-dependent/simple.rs | 12 +++++ .../type-dependent/type-mismatch.rs | 12 +++++ .../type-dependent/type-mismatch.stderr | 23 +++++++++ src/test/ui/const-generics/unknown_adt.rs | 7 +++ src/test/ui/const-generics/unknown_adt.stderr | 9 ++++ 15 files changed, 333 insertions(+) create mode 100644 src/test/ui/const-generics/type-dependent/auxiliary/type_dependent_lib.rs create mode 100644 src/test/ui/const-generics/type-dependent/const-arg-in-const-arg.rs create mode 100644 src/test/ui/const-generics/type-dependent/issue-61936.rs create mode 100644 src/test/ui/const-generics/type-dependent/issue-63695.rs create mode 100644 src/test/ui/const-generics/type-dependent/issue-69816.rs create mode 100644 src/test/ui/const-generics/type-dependent/issue-70507.rs create mode 100644 src/test/ui/const-generics/type-dependent/issue-71382.rs create mode 100644 src/test/ui/const-generics/type-dependent/issue-71382.stderr create mode 100644 src/test/ui/const-generics/type-dependent/non-local.rs create mode 100644 src/test/ui/const-generics/type-dependent/qpath.rs create mode 100644 src/test/ui/const-generics/type-dependent/simple.rs create mode 100644 src/test/ui/const-generics/type-dependent/type-mismatch.rs create mode 100644 src/test/ui/const-generics/type-dependent/type-mismatch.stderr create mode 100644 src/test/ui/const-generics/unknown_adt.rs create mode 100644 src/test/ui/const-generics/unknown_adt.stderr diff --git a/src/test/ui/const-generics/type-dependent/auxiliary/type_dependent_lib.rs b/src/test/ui/const-generics/type-dependent/auxiliary/type_dependent_lib.rs new file mode 100644 index 0000000000000..c8db91b62b58c --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/auxiliary/type_dependent_lib.rs @@ -0,0 +1,36 @@ +#![feature(const_generics)] +#![allow(incomplete_features)] + +pub struct Struct(()); + +impl Struct { + pub fn new() -> Self { + Struct(()) + } + + pub fn same_ty(&self) -> (usize, usize) { + (N, M) + } + + pub fn different_ty(&self) -> (usize, u8) { + (N, M) + } + + pub fn containing_ty(&self) -> (usize, u8) { + (std::mem::size_of::() + N, M) + } + + pub fn we_have_to_go_deeper(&self) -> Struct { + Struct(()) + } +} + +pub trait Foo { + fn foo(&self) -> usize; +} + +impl Foo for Struct<7> { + fn foo(&self) -> usize { + M + } +} diff --git a/src/test/ui/const-generics/type-dependent/const-arg-in-const-arg.rs b/src/test/ui/const-generics/type-dependent/const-arg-in-const-arg.rs new file mode 100644 index 0000000000000..ae50252facd25 --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/const-arg-in-const-arg.rs @@ -0,0 +1,26 @@ +// run-pass +#![feature(const_generics)] +#![allow(incomplete_features)] +#![feature(const_fn)] + +struct Foo; + +impl Foo { + fn foo(&self) -> usize { + let f = self; + f.bar::<{ + let f = Foo; + f.bar::<7>() + }>() + N + } + + const fn bar(&self) -> usize { + M + } +} + +fn main() { + let f = Foo; + + assert_eq!(f.foo::<13>(), 20) +} diff --git a/src/test/ui/const-generics/type-dependent/issue-61936.rs b/src/test/ui/const-generics/type-dependent/issue-61936.rs new file mode 100644 index 0000000000000..2dd6c0cd24191 --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/issue-61936.rs @@ -0,0 +1,47 @@ +// run-pass +#![feature(const_generics)] +#![allow(incomplete_features)] + +trait SliceExt { + fn array_windows<'a, const N: usize>(&'a self) -> ArrayWindows<'a, T, N>; +} + +impl SliceExt for [T] { + fn array_windows<'a, const N: usize>(&'a self) -> ArrayWindows<'a, T, N> { + ArrayWindows{ idx: 0, slice: &self } + } +} + +struct ArrayWindows<'a, T, const N: usize> { + slice: &'a [T], + idx: usize, +} + +impl <'a, T: Clone, const N: usize> Iterator for ArrayWindows<'a, T, N> { + type Item = [T; N]; + fn next(&mut self) -> Option { + let mut res = unsafe{ std::mem::zeroed() }; + let mut ptr = &mut res as *mut [T; N] as *mut T; + + for i in 0..N { + match self.slice[i..].get(i) { + None => return None, + Some(elem) => unsafe { std::ptr::write_volatile(ptr, elem.clone())}, + }; + ptr = ptr.wrapping_add(1); + self.idx += 1; + } + + Some(res) + } +} + +const FOUR: usize = 4; + +fn main() { + let v: Vec = vec![100; 0usize]; + + for array in v.as_slice().array_windows::() { + assert_eq!(array, [0, 0, 0, 0]) + } +} diff --git a/src/test/ui/const-generics/type-dependent/issue-63695.rs b/src/test/ui/const-generics/type-dependent/issue-63695.rs new file mode 100644 index 0000000000000..f3c2e1775940f --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/issue-63695.rs @@ -0,0 +1,17 @@ +// run-pass +#![feature(const_generics)] +#![allow(incomplete_features)] + +trait T { + fn test(&self) -> i32 { A } +} + +struct S(); + +impl T for S {} + +fn main() { + let foo = S(); + assert_eq!(foo.test::<8i32>(), 8); + assert_eq!(foo.test::<16i32>(), 16); +} diff --git a/src/test/ui/const-generics/type-dependent/issue-69816.rs b/src/test/ui/const-generics/type-dependent/issue-69816.rs new file mode 100644 index 0000000000000..cbe86cef3230f --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/issue-69816.rs @@ -0,0 +1,20 @@ +// run-pass +#![feature(const_generics)] +#![allow(incomplete_features)] + +trait IterExt: Sized + Iterator { + fn default_for_size(self) -> [Self::Item; N] + where + [Self::Item; N]: Default, + { + Default::default() + } +} + +impl IterExt for T {} + +fn main(){ + const N: usize = 10; + let arr = (0u32..10).default_for_size::(); + assert_eq!(arr, [0; 10]); +} diff --git a/src/test/ui/const-generics/type-dependent/issue-70507.rs b/src/test/ui/const-generics/type-dependent/issue-70507.rs new file mode 100644 index 0000000000000..6fcf4116d437c --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/issue-70507.rs @@ -0,0 +1,47 @@ +// run-pass +#![feature(const_generics)] +#![allow(incomplete_features)] + +trait ConstChunksExactTrait { + fn const_chunks_exact(&self) -> ConstChunksExact<'_, T, {N}>; +} + +impl ConstChunksExactTrait for [T] { + fn const_chunks_exact(&self) -> ConstChunksExact<'_, T, {N}> { + assert!(N != 0); + let rem = self.len() % N; + let len = self.len() - rem; + let (fst, _) = self.split_at(len); + ConstChunksExact { v: fst, } + } +} + +struct ConstChunksExact<'a, T: 'a, const N: usize> { + v: &'a [T], +} + +impl <'a, T: std::fmt::Debug, const N: usize> Iterator for ConstChunksExact<'a, T, {N}> { + type Item = &'a [T; N]; + + fn next(&mut self) -> Option { + if self.v.len() < N { + None + } else { + let (fst, snd) = self.v.split_at(N); + + self.v = snd; + let ptr = fst.as_ptr() as *const _; + Some(unsafe { &*ptr}) + } + } +} + +fn main() { + let slice = &[1i32, 2, 3, 4, 5, 6, 7, 8, 9, 10]; + + let mut iter = [[1, 2, 3], [4, 5, 6], [7, 8, 9]].iter(); + + for a in slice.const_chunks_exact::<3>() { + assert_eq!(a, iter.next().unwrap()); + } +} diff --git a/src/test/ui/const-generics/type-dependent/issue-71382.rs b/src/test/ui/const-generics/type-dependent/issue-71382.rs new file mode 100644 index 0000000000000..05abd488816ff --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/issue-71382.rs @@ -0,0 +1,24 @@ +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete + +struct Test; + +fn pass() -> u8 { + 42 +} + +impl Test { + pub fn call_me(&self) -> u8 { + self.test::() + } + + fn test u8>(&self) -> u8 { + //~^ ERROR using function pointers as const generic parameters is forbidden + FN() + } +} + +fn main() { + let x = Test; + assert_eq!(x.call_me(), 42); +} diff --git a/src/test/ui/const-generics/type-dependent/issue-71382.stderr b/src/test/ui/const-generics/type-dependent/issue-71382.stderr new file mode 100644 index 0000000000000..f441b71031ece --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/issue-71382.stderr @@ -0,0 +1,17 @@ +warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/issue-71382.rs:1:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44580 for more information + +error: using function pointers as const generic parameters is forbidden + --> $DIR/issue-71382.rs:15:23 + | +LL | fn test u8>(&self) -> u8 { + | ^^^^^^^^^^ + +error: aborting due to previous error; 1 warning emitted + diff --git a/src/test/ui/const-generics/type-dependent/non-local.rs b/src/test/ui/const-generics/type-dependent/non-local.rs new file mode 100644 index 0000000000000..e6f3eb075f1da --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/non-local.rs @@ -0,0 +1,24 @@ +// aux-build:type_dependent_lib.rs +// run-pass +#![feature(const_generics)] +#![allow(incomplete_features)] + +extern crate type_dependent_lib; + +use type_dependent_lib::*; + +fn main() { + let s = Struct::<42>::new(); + assert_eq!(s.same_ty::<7>(), (42, 7)); + assert_eq!(s.different_ty::<19>(), (42, 19)); + assert_eq!(Struct::<1337>::new().different_ty::<96>(), (1337, 96)); + assert_eq!( + Struct::<18>::new() + .we_have_to_go_deeper::<19>() + .containing_ty::, 3>(), + (27, 3), + ); + + let s = Struct::<7>::new(); + assert_eq!(s.foo::<18>(), 18); +} diff --git a/src/test/ui/const-generics/type-dependent/qpath.rs b/src/test/ui/const-generics/type-dependent/qpath.rs new file mode 100644 index 0000000000000..f3f98e5faf52d --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/qpath.rs @@ -0,0 +1,12 @@ +// run-pass +#![feature(const_generics)] +#![allow(incomplete_features)] + +struct A; +impl A { + fn foo() -> usize { N + 1 } +} + +fn main() { + assert_eq!(A::foo::<7>(), 8); +} diff --git a/src/test/ui/const-generics/type-dependent/simple.rs b/src/test/ui/const-generics/type-dependent/simple.rs new file mode 100644 index 0000000000000..cc7c50d8fd835 --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/simple.rs @@ -0,0 +1,12 @@ +// run-pass +#![feature(const_generics)] +#![allow(incomplete_features)] + +struct R; + +impl R { + fn method(&self) -> u8 { N } +} +fn main() { + assert_eq!(R.method::<1u8>(), 1); +} diff --git a/src/test/ui/const-generics/type-dependent/type-mismatch.rs b/src/test/ui/const-generics/type-dependent/type-mismatch.rs new file mode 100644 index 0000000000000..0c71f338bd262 --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/type-mismatch.rs @@ -0,0 +1,12 @@ +#![feature(const_generics)] +//~^ WARN the feature `const_generics` is incomplete + +struct R; + +impl R { + fn method(&self) -> u8 { N } +} +fn main() { + assert_eq!(R.method::<1u16>(), 1); + //~^ ERROR mismatched types +} diff --git a/src/test/ui/const-generics/type-dependent/type-mismatch.stderr b/src/test/ui/const-generics/type-dependent/type-mismatch.stderr new file mode 100644 index 0000000000000..5bb7c5b0ea9bf --- /dev/null +++ b/src/test/ui/const-generics/type-dependent/type-mismatch.stderr @@ -0,0 +1,23 @@ +warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes + --> $DIR/type-mismatch.rs:1:12 + | +LL | #![feature(const_generics)] + | ^^^^^^^^^^^^^^ + | + = note: `#[warn(incomplete_features)]` on by default + = note: see issue #44580 for more information + +error[E0308]: mismatched types + --> $DIR/type-mismatch.rs:10:27 + | +LL | assert_eq!(R.method::<1u16>(), 1); + | ^^^^ expected `u8`, found `u16` + | +help: change the type of the numeric literal from `u16` to `u8` + | +LL | assert_eq!(R.method::<1u8>(), 1); + | ^^^ + +error: aborting due to previous error; 1 warning emitted + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/const-generics/unknown_adt.rs b/src/test/ui/const-generics/unknown_adt.rs new file mode 100644 index 0000000000000..0ba9945b399ae --- /dev/null +++ b/src/test/ui/const-generics/unknown_adt.rs @@ -0,0 +1,7 @@ +#![feature(const_generics)] +#![allow(incomplete_features)] + +fn main() { + let _: UnknownStruct<7>; + //~^ ERROR cannot find type `UnknownStruct` +} diff --git a/src/test/ui/const-generics/unknown_adt.stderr b/src/test/ui/const-generics/unknown_adt.stderr new file mode 100644 index 0000000000000..b2e287b762c69 --- /dev/null +++ b/src/test/ui/const-generics/unknown_adt.stderr @@ -0,0 +1,9 @@ +error[E0412]: cannot find type `UnknownStruct` in this scope + --> $DIR/unknown_adt.rs:5:12 + | +LL | let _: UnknownStruct<7>; + | ^^^^^^^^^^^^^ not found in this scope + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0412`. From 37a6103e1ad5916d0c2b40f9bda743061a5c45b2 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Thu, 2 Jul 2020 22:35:11 +0200 Subject: [PATCH 02/25] introduce the query `opt_const_param_of` --- src/librustc_middle/query/mod.rs | 19 ++ src/librustc_typeck/collect.rs | 1 + src/librustc_typeck/collect/type_of.rs | 274 ++++++++++++++----------- 3 files changed, 169 insertions(+), 125 deletions(-) diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 0faf389aa385c..d53b8d33262b5 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -89,6 +89,25 @@ rustc_queries! { desc { |tcx| "HIR owner items in `{}`", tcx.def_path_str(key.to_def_id()) } } + /// Computes the `DefId` of the corresponding const parameter in case the `key` is a + /// const argument and returns `None` otherwise. + /// + /// ```rust + /// let a = foo::<7>(); + /// // ^ Calling `opt_const_param_of` for this argument, + /// + /// fn foo() + /// // ^ returns this `DefId`. + /// + /// fn bar() { + /// // ^ While calling `opt_const_param_of` for other bodies returns `None`. + /// } + /// ``` + query opt_const_param_of(key: LocalDefId) -> Option { + desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) } + // FIXME: consider storing this query on disk. + } + /// Records the type of every item. query type_of(key: DefId) -> Ty<'tcx> { desc { |tcx| "computing type of `{}`", tcx.def_path_str(key) } diff --git a/src/librustc_typeck/collect.rs b/src/librustc_typeck/collect.rs index 625b72091a6cc..4354996614b2a 100644 --- a/src/librustc_typeck/collect.rs +++ b/src/librustc_typeck/collect.rs @@ -64,6 +64,7 @@ fn collect_mod_item_types(tcx: TyCtxt<'_>, module_def_id: LocalDefId) { pub fn provide(providers: &mut Providers) { *providers = Providers { + opt_const_param_of: type_of::opt_const_param_of, type_of: type_of::type_of, generics_of, predicates_of, diff --git a/src/librustc_typeck/collect/type_of.rs b/src/librustc_typeck/collect/type_of.rs index 3dd9c9c5c39db..c265fadb82f94 100644 --- a/src/librustc_typeck/collect/type_of.rs +++ b/src/librustc_typeck/collect/type_of.rs @@ -17,29 +17,141 @@ use rustc_trait_selection::traits; use super::ItemCtxt; use super::{bad_placeholder_type, is_suggestable_infer_ty}; +/// Computes the relevant generic parameter for a potential generic const argument. +/// +/// This should be called using the query `tcx.opt_const_param_of`. +pub(super) fn opt_const_param_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option { + use hir::*; + + let hir_id = tcx.hir().as_local_hir_id(def_id); + + if let Node::AnonConst(_) = tcx.hir().get(hir_id) { + let parent_node_id = tcx.hir().get_parent_node(hir_id); + let parent_node = tcx.hir().get(parent_node_id); + + match parent_node { + Node::Expr(&Expr { + kind: + ExprKind::MethodCall(segment, ..) | ExprKind::Path(QPath::TypeRelative(_, segment)), + .. + }) => { + let body_owner = tcx.hir().local_def_id(tcx.hir().enclosing_body_owner(hir_id)); + let tables = tcx.typeck_tables_of(body_owner); + // This may fail in case the method/path does not actually exist. + // As there is no relevant param for `def_id`, we simply return + // `None` here. + let type_dependent_def = tables.type_dependent_def_id(parent_node_id)?; + let idx = segment + .args + .and_then(|args| { + args.args + .iter() + .filter(|arg| arg.is_const()) + .position(|arg| arg.id() == hir_id) + }) + .unwrap_or_else(|| { + bug!("no arg matching AnonConst in segment"); + }); + + tcx.generics_of(type_dependent_def) + .params + .iter() + .filter(|param| matches!(param.kind, ty::GenericParamDefKind::Const)) + .nth(idx) + .map(|param| param.def_id) + } + + Node::Ty(&Ty { kind: TyKind::Path(_), .. }) + | Node::Expr(&Expr { kind: ExprKind::Struct(..), .. }) + | Node::Expr(&Expr { kind: ExprKind::Path(_), .. }) + | Node::TraitRef(..) => { + let path = match parent_node { + Node::Ty(&Ty { kind: TyKind::Path(QPath::Resolved(_, path)), .. }) + | Node::TraitRef(&TraitRef { path, .. }) => &*path, + Node::Expr(&Expr { + kind: + ExprKind::Path(QPath::Resolved(_, path)) + | ExprKind::Struct(&QPath::Resolved(_, path), ..), + .. + }) => { + let body_owner = + tcx.hir().local_def_id(tcx.hir().enclosing_body_owner(hir_id)); + let _tables = tcx.typeck_tables_of(body_owner); + &*path + } + _ => span_bug!(DUMMY_SP, "unexpected const parent path {:?}", parent_node), + }; + + // We've encountered an `AnonConst` in some path, so we need to + // figure out which generic parameter it corresponds to and return + // the relevant type. + + let (arg_index, segment) = path + .segments + .iter() + .filter_map(|seg| seg.args.map(|args| (args.args, seg))) + .find_map(|(args, seg)| { + args.iter() + .filter(|arg| arg.is_const()) + .position(|arg| arg.id() == hir_id) + .map(|index| (index, seg)) + }) + .unwrap_or_else(|| { + bug!("no arg matching AnonConst in path"); + }); + + // Try to use the segment resolution if it is valid, otherwise we + // default to the path resolution. + let res = segment.res.filter(|&r| r != Res::Err).unwrap_or(path.res); + let generics = match res { + Res::Def(DefKind::Ctor(..), def_id) => { + tcx.generics_of(tcx.parent(def_id).unwrap()) + } + Res::Def(_, def_id) => tcx.generics_of(def_id), + Res::Err => { + tcx.sess.delay_span_bug(tcx.def_span(def_id), "anon const with Res::Err"); + return None; + } + _ => span_bug!( + DUMMY_SP, + "unexpected anon const res {:?} in path: {:?}", + res, + path, + ), + }; + + generics + .params + .iter() + .filter(|param| matches!(param.kind, ty::GenericParamDefKind::Const)) + .nth(arg_index) + .map(|param| param.def_id) + } + _ => None, + } + } else { + None + } +} + pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { + let def_id = def_id.expect_local(); use rustc_hir::*; - let hir_id = tcx.hir().as_local_hir_id(def_id.expect_local()); + let hir_id = tcx.hir().as_local_hir_id(def_id); - let icx = ItemCtxt::new(tcx, def_id); + let icx = ItemCtxt::new(tcx, def_id.to_def_id()); match tcx.hir().get(hir_id) { Node::TraitItem(item) => match item.kind { TraitItemKind::Fn(..) => { - let substs = InternalSubsts::identity_for_item(tcx, def_id); - tcx.mk_fn_def(def_id, substs) + let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); + tcx.mk_fn_def(def_id.to_def_id(), substs) } TraitItemKind::Const(ref ty, body_id) => body_id .and_then(|body_id| { if is_suggestable_infer_ty(ty) { - Some(infer_placeholder_type( - tcx, - def_id.expect_local(), - body_id, - ty.span, - item.ident, - )) + Some(infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident)) } else { None } @@ -53,12 +165,12 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { Node::ImplItem(item) => match item.kind { ImplItemKind::Fn(..) => { - let substs = InternalSubsts::identity_for_item(tcx, def_id); - tcx.mk_fn_def(def_id, substs) + let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); + tcx.mk_fn_def(def_id.to_def_id(), substs) } ImplItemKind::Const(ref ty, body_id) => { if is_suggestable_infer_ty(ty) { - infer_placeholder_type(tcx, def_id.expect_local(), body_id, ty.span, item.ident) + infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident) } else { icx.to_ty(ty) } @@ -76,13 +188,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { match item.kind { ItemKind::Static(ref ty, .., body_id) | ItemKind::Const(ref ty, body_id) => { if is_suggestable_infer_ty(ty) { - infer_placeholder_type( - tcx, - def_id.expect_local(), - body_id, - ty.span, - item.ident, - ) + infer_placeholder_type(tcx, def_id, body_id, ty.span, item.ident) } else { icx.to_ty(ty) } @@ -91,26 +197,26 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { icx.to_ty(self_ty) } ItemKind::Fn(..) => { - let substs = InternalSubsts::identity_for_item(tcx, def_id); - tcx.mk_fn_def(def_id, substs) + let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); + tcx.mk_fn_def(def_id.to_def_id(), substs) } ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => { let def = tcx.adt_def(def_id); - let substs = InternalSubsts::identity_for_item(tcx, def_id); + let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); tcx.mk_adt(def, substs) } ItemKind::OpaqueTy(OpaqueTy { origin: hir::OpaqueTyOrigin::Binding, .. }) => { - let_position_impl_trait_type(tcx, def_id.expect_local()) + let_position_impl_trait_type(tcx, def_id) } ItemKind::OpaqueTy(OpaqueTy { impl_trait_fn: None, .. }) => { - find_opaque_ty_constraints(tcx, def_id.expect_local()) + find_opaque_ty_constraints(tcx, def_id) } // Opaque types desugared from `impl Trait`. ItemKind::OpaqueTy(OpaqueTy { impl_trait_fn: Some(owner), .. }) => { let concrete_ty = tcx .mir_borrowck(owner.expect_local()) .concrete_opaque_types - .get(&def_id) + .get(&def_id.to_def_id()) .map(|opaque| opaque.concrete_type) .unwrap_or_else(|| { tcx.sess.delay_span_bug( @@ -132,8 +238,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { // resolves to itself. Return the non-revealed // type, which should result in E0720. tcx.mk_opaque( - def_id, - InternalSubsts::identity_for_item(tcx, def_id), + def_id.to_def_id(), + InternalSubsts::identity_for_item(tcx, def_id.to_def_id()), ) } }); @@ -158,11 +264,11 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { Node::ForeignItem(foreign_item) => match foreign_item.kind { ForeignItemKind::Fn(..) => { - let substs = InternalSubsts::identity_for_item(tcx, def_id); - tcx.mk_fn_def(def_id, substs) + let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); + tcx.mk_fn_def(def_id.to_def_id(), substs) } ForeignItemKind::Static(ref t, _) => icx.to_ty(t), - ForeignItemKind::Type => tcx.mk_foreign(def_id), + ForeignItemKind::Type => tcx.mk_foreign(def_id.to_def_id()), }, Node::Ctor(&ref def) | Node::Variant(Variant { data: ref def, .. }) => match *def { @@ -170,23 +276,29 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { tcx.type_of(tcx.hir().get_parent_did(hir_id).to_def_id()) } VariantData::Tuple(..) => { - let substs = InternalSubsts::identity_for_item(tcx, def_id); - tcx.mk_fn_def(def_id, substs) + let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); + tcx.mk_fn_def(def_id.to_def_id(), substs) } }, Node::Field(field) => icx.to_ty(&field.ty), Node::Expr(&Expr { kind: ExprKind::Closure(.., gen), .. }) => { - let substs = InternalSubsts::identity_for_item(tcx, def_id); + let substs = InternalSubsts::identity_for_item(tcx, def_id.to_def_id()); if let Some(movability) = gen { - tcx.mk_generator(def_id, substs, movability) + tcx.mk_generator(def_id.to_def_id(), substs, movability) } else { - tcx.mk_closure(def_id, substs) + tcx.mk_closure(def_id.to_def_id(), substs) } } Node::AnonConst(_) => { + if let Some(param) = tcx.opt_const_param_of(def_id) { + // We defer to `type_of` of the corresponding parameter + // for generic arguments. + return tcx.type_of(param); + } + let parent_node = tcx.hir().get(tcx.hir().get_parent_node(hir_id)); match parent_node { Node::Ty(&Ty { kind: TyKind::Array(_, ref constant), .. }) @@ -203,94 +315,6 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: DefId) -> Ty<'_> { .discr_type() .to_ty(tcx), - Node::Ty(&Ty { kind: TyKind::Path(_), .. }) - | Node::Expr(&Expr { kind: ExprKind::Struct(..) | ExprKind::Path(_), .. }) - | Node::TraitRef(..) => { - let path = match parent_node { - Node::Ty(&Ty { kind: TyKind::Path(QPath::Resolved(_, path)), .. }) - | Node::Expr(&Expr { - kind: - ExprKind::Path(QPath::Resolved(_, path)) - | ExprKind::Struct(&QPath::Resolved(_, path), ..), - .. - }) - | Node::TraitRef(&TraitRef { path, .. }) => &*path, - _ => { - return tcx.ty_error_with_message( - DUMMY_SP, - &format!("unexpected const parent path {:?}", parent_node), - ); - } - }; - - // We've encountered an `AnonConst` in some path, so we need to - // figure out which generic parameter it corresponds to and return - // the relevant type. - - let (arg_index, segment) = path - .segments - .iter() - .filter_map(|seg| seg.args.as_ref().map(|args| (args.args, seg))) - .find_map(|(args, seg)| { - args.iter() - .filter(|arg| arg.is_const()) - .enumerate() - .filter(|(_, arg)| arg.id() == hir_id) - .map(|(index, _)| (index, seg)) - .next() - }) - .unwrap_or_else(|| { - bug!("no arg matching AnonConst in path"); - }); - - // Try to use the segment resolution if it is valid, otherwise we - // default to the path resolution. - let res = segment.res.filter(|&r| r != Res::Err).unwrap_or(path.res); - let generics = match res { - Res::Def(DefKind::Ctor(..), def_id) => { - tcx.generics_of(tcx.parent(def_id).unwrap()) - } - Res::Def(_, def_id) => tcx.generics_of(def_id), - res => { - return tcx.ty_error_with_message( - DUMMY_SP, - &format!( - "unexpected anon const res {:?} in path: {:?}", - res, path, - ), - ); - } - }; - - let ty = generics - .params - .iter() - .filter(|param| { - if let ty::GenericParamDefKind::Const = param.kind { - true - } else { - false - } - }) - .nth(arg_index) - .map(|param| tcx.type_of(param.def_id)); - - if let Some(ty) = ty { - ty - } else { - // This is no generic parameter associated with the arg. This is - // probably from an extra arg where one is not needed. - tcx.ty_error_with_message( - DUMMY_SP, - &format!( - "missing generic parameter for `AnonConst`, \ - parent: {:?}, res: {:?}", - parent_node, res - ), - ) - } - } - x => tcx.ty_error_with_message( DUMMY_SP, &format!("unexpected const parent in type_of_def_id(): {:?}", x), From 08865d94e5a3c2116eeb6ba3c5fd3c0b4e5a17d8 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Thu, 2 Jul 2020 22:56:28 +0200 Subject: [PATCH 03/25] begin using `WithOptParam` --- src/librustc_middle/ty/mod.rs | 26 +++++++++++++++++++++ src/librustc_middle/ty/sty.rs | 19 ++++++++++----- src/librustc_typeck/astconv.rs | 10 ++++++-- src/librustc_typeck/check/method/confirm.rs | 2 +- src/librustc_typeck/check/mod.rs | 20 +++++++++++++++- 5 files changed, 67 insertions(+), 10 deletions(-) diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index bec1200d7aa0f..f8a205084de88 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1571,6 +1571,32 @@ pub type PlaceholderType = Placeholder; pub type PlaceholderConst = Placeholder; +#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(PartialEq, Eq, PartialOrd, Ord)] +#[derive(Hash, HashStable)] +pub struct WithOptParam { + pub did: T, + pub param_did: Option, +} + +impl WithOptParam { + pub fn dummy(did: T) -> WithOptParam { + WithOptParam { did, param_did: None } + } +} + +impl WithOptParam { + pub fn ty_def_id(self) -> DefId { + if let Some(did) = self.param_did { did } else { self.did.to_def_id() } + } +} + +impl WithOptParam { + pub fn ty_def_id(self) -> DefId { + self.param_did.unwrap_or(self.did) + } +} + /// When type checking, we use the `ParamEnv` to track /// details about the set of where-clauses that are in scope at this /// particular point. diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index c7683cefd82f6..6326068905d3c 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -2210,21 +2210,28 @@ impl<'tcx> Const<'tcx> { /// Literals and const generic parameters are eagerly converted to a constant, everything else /// becomes `Unevaluated`. pub fn from_anon_const(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx Self { - debug!("Const::from_anon_const(id={:?})", def_id); + Self::const_arg_from_anon_const(tcx, ty::WithOptParam::dummy(def_id)) + } + + pub fn const_arg_from_anon_const( + tcx: TyCtxt<'tcx>, + def: ty::WithOptParam, + ) -> &'tcx Self { + debug!("Const::from_anon_const(def={:?})", def); - let hir_id = tcx.hir().local_def_id_to_hir_id(def_id); + let hir_id = tcx.hir().local_def_id_to_hir_id(def.did); let body_id = match tcx.hir().get(hir_id) { hir::Node::AnonConst(ac) => ac.body, _ => span_bug!( - tcx.def_span(def_id.to_def_id()), + tcx.def_span(def.did.to_def_id()), "from_anon_const can only process anonymous constants" ), }; let expr = &tcx.hir().body(body_id).value; - let ty = tcx.type_of(def_id.to_def_id()); + let ty = tcx.type_of(def.ty_def_id()); let lit_input = match expr.kind { hir::ExprKind::Lit(ref lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }), @@ -2271,8 +2278,8 @@ impl<'tcx> Const<'tcx> { ty::ConstKind::Param(ty::ParamConst::new(index, name)) } _ => ty::ConstKind::Unevaluated( - def_id.to_def_id(), - InternalSubsts::identity_for_item(tcx, def_id.to_def_id()), + def.did.to_def_id(), + InternalSubsts::identity_for_item(tcx, def.did.to_def_id()), None, ), }; diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index 616f5d90395e1..eeb14352ca0f3 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -886,8 +886,14 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } } (GenericParamDefKind::Const, GenericArg::Const(ct)) => { - let ct_def_id = tcx.hir().local_def_id(ct.value.hir_id); - ty::Const::from_anon_const(tcx, ct_def_id).into() + ty::Const::const_arg_from_anon_const( + tcx, + ty::WithOptParam { + did: tcx.hir().local_def_id(ct.value.hir_id), + param_did: Some(param.def_id), + }, + ) + .into() } _ => unreachable!(), }, diff --git a/src/librustc_typeck/check/method/confirm.rs b/src/librustc_typeck/check/method/confirm.rs index 1c3d23a3a241f..0ca85b5165ea0 100644 --- a/src/librustc_typeck/check/method/confirm.rs +++ b/src/librustc_typeck/check/method/confirm.rs @@ -325,7 +325,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> { } (GenericParamDefKind::Type { .. }, GenericArg::Type(ty)) => self.to_ty(ty).into(), (GenericParamDefKind::Const, GenericArg::Const(ct)) => { - self.to_const(&ct.value).into() + self.const_arg_to_const(&ct.value, param.def_id).into() } _ => unreachable!(), }, diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index bc01da324b66f..56f751e000ba1 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3542,6 +3542,24 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { c } + pub fn const_arg_to_const( + &self, + ast_c: &hir::AnonConst, + param_def_id: DefId, + ) -> &'tcx ty::Const<'tcx> { + let const_def = ty::WithOptParam { + did: self.tcx.hir().local_def_id(ast_c.hir_id), + param_did: Some(param_def_id), + }; + let c = ty::Const::const_arg_from_anon_const(self.tcx, const_def); + self.register_wf_obligation( + c.into(), + self.tcx.hir().span(ast_c.hir_id), + ObligationCauseCode::MiscObligation, + ); + c + } + // If the type given by the user has free regions, save it for later, since // NLL would like to enforce those. Also pass in types that involve // projections, since those can resolve to `'static` bounds (modulo #54940, @@ -5655,7 +5673,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.to_ty(ty).into() } (GenericParamDefKind::Const, GenericArg::Const(ct)) => { - self.to_const(&ct.value).into() + self.const_arg_to_const(&ct.value, param.def_id).into() } _ => unreachable!(), }, From 58031c7cb2352fb17f2c720a84f541c532ffdf09 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Thu, 2 Jul 2020 23:13:32 +0200 Subject: [PATCH 04/25] ConstKind::Unevaluated --- src/librustc_codegen_ssa/mir/constant.rs | 4 ++-- src/librustc_middle/ty/mod.rs | 12 ++++++++++++ src/librustc_middle/ty/print/pretty.rs | 12 ++++++------ src/librustc_middle/ty/sty.rs | 10 +++++----- src/librustc_mir/borrow_check/type_check/mod.rs | 4 ++-- src/librustc_mir/interpret/operand.rs | 4 ++-- src/librustc_mir/monomorphize/collector.rs | 6 +++--- src/librustc_mir/transform/check_consts/qualifs.rs | 6 +++--- src/librustc_mir/transform/promote_consts.rs | 2 +- src/librustc_mir_build/hair/cx/expr.rs | 8 ++++++-- src/librustc_trait_selection/traits/fulfill.rs | 4 ++-- src/librustc_trait_selection/traits/select/mod.rs | 4 ++-- src/librustc_trait_selection/traits/wf.rs | 6 +++--- src/librustdoc/clean/utils.rs | 8 ++++---- 14 files changed, 53 insertions(+), 37 deletions(-) diff --git a/src/librustc_codegen_ssa/mir/constant.rs b/src/librustc_codegen_ssa/mir/constant.rs index 11ec62f96ed38..007be7a62ae31 100644 --- a/src/librustc_codegen_ssa/mir/constant.rs +++ b/src/librustc_codegen_ssa/mir/constant.rs @@ -25,10 +25,10 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { constant: &mir::Constant<'tcx>, ) -> Result, ErrorHandled> { match self.monomorphize(&constant.literal).val { - ty::ConstKind::Unevaluated(def_id, substs, promoted) => self + ty::ConstKind::Unevaluated(def, substs, promoted) => self .cx .tcx() - .const_eval_resolve(ty::ParamEnv::reveal_all(), def_id, substs, promoted, None) + .const_eval_resolve(ty::ParamEnv::reveal_all(), def.did, substs, promoted, None) .map_err(|err| { if promoted.is_none() { self.cx diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index f8a205084de88..539dfa6e892bc 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1586,12 +1586,24 @@ impl WithOptParam { } impl WithOptParam { + pub fn to_global(self) -> WithOptParam { + WithOptParam { did: self.did.to_def_id(), param_did: self.param_did } + } + pub fn ty_def_id(self) -> DefId { if let Some(did) = self.param_did { did } else { self.did.to_def_id() } } } impl WithOptParam { + pub fn as_local(self) -> Option> { + self.did.as_local().map(|did| WithOptParam { did, param_did: self.param_did }) + } + + pub fn is_local(self) -> bool { + self.did.is_local() + } + pub fn ty_def_id(self) -> DefId { self.param_did.unwrap_or(self.did) } diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index 3809c8d245bbe..1cba593879aa5 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -883,18 +883,18 @@ pub trait PrettyPrinter<'tcx>: } match ct.val { - ty::ConstKind::Unevaluated(did, substs, promoted) => { + ty::ConstKind::Unevaluated(def, substs, promoted) => { if let Some(promoted) = promoted { - p!(print_value_path(did, substs)); + p!(print_value_path(def.did, substs)); p!(write("::{:?}", promoted)); } else { - match self.tcx().def_kind(did) { + match self.tcx().def_kind(def.did) { DefKind::Static | DefKind::Const | DefKind::AssocConst => { - p!(print_value_path(did, substs)) + p!(print_value_path(def.did, substs)) } _ => { - if did.is_local() { - let span = self.tcx().def_span(did); + if def.is_local() { + let span = self.tcx().def_span(def.did); if let Ok(snip) = self.tcx().sess.source_map().span_to_snippet(span) { p!(write("{}", snip)) diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 6326068905d3c..1e7171ea06c5c 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -2278,7 +2278,7 @@ impl<'tcx> Const<'tcx> { ty::ConstKind::Param(ty::ParamConst::new(index, name)) } _ => ty::ConstKind::Unevaluated( - def.did.to_def_id(), + def.to_global(), InternalSubsts::identity_for_item(tcx, def.did.to_def_id()), None, ), @@ -2347,7 +2347,7 @@ impl<'tcx> Const<'tcx> { /// Tries to evaluate the constant if it is `Unevaluated`. If that doesn't succeed, return the /// unevaluated constant. pub fn eval(&self, tcx: TyCtxt<'tcx>, param_env: ParamEnv<'tcx>) -> &Const<'tcx> { - if let ConstKind::Unevaluated(did, substs, promoted) = self.val { + if let ConstKind::Unevaluated(def, substs, promoted) = self.val { use crate::mir::interpret::ErrorHandled; let param_env_and_substs = param_env.with_reveal_all().and(substs); @@ -2363,7 +2363,7 @@ impl<'tcx> Const<'tcx> { // FIXME(eddyb, skinny121) pass `InferCtxt` into here when it's available, so that // we can call `infcx.const_eval_resolve` which handles inference variables. let param_env_and_substs = if param_env_and_substs.needs_infer() { - tcx.param_env(did).and(InternalSubsts::identity_for_item(tcx, did)) + tcx.param_env(def.did).and(InternalSubsts::identity_for_item(tcx, def.did)) } else { param_env_and_substs }; @@ -2373,7 +2373,7 @@ impl<'tcx> Const<'tcx> { let (param_env, substs) = param_env_and_substs.into_parts(); // try to resolve e.g. associated constants to their definition on an impl, and then // evaluate the const. - match tcx.const_eval_resolve(param_env, did, substs, promoted, None) { + match tcx.const_eval_resolve(param_env, def.did, substs, promoted, None) { // NOTE(eddyb) `val` contains no lifetimes/types/consts, // and we use the original type, so nothing from `substs` // (which may be identity substs, see above), @@ -2433,7 +2433,7 @@ pub enum ConstKind<'tcx> { /// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other /// variants when the code is monomorphic enough for that. - Unevaluated(DefId, SubstsRef<'tcx>, Option), + Unevaluated(ty::WithOptParam, SubstsRef<'tcx>, Option), /// Used to hold computed value. Value(ConstValue<'tcx>), diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index 3532b6de003ba..7b84737fa77a4 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -321,7 +321,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { } } else { let tcx = self.tcx(); - if let ty::ConstKind::Unevaluated(def_id, substs, promoted) = constant.literal.val { + if let ty::ConstKind::Unevaluated(def, substs, promoted) = constant.literal.val { if let Some(promoted) = promoted { let check_err = |verifier: &mut TypeVerifier<'a, 'b, 'tcx>, promoted: &Body<'tcx>, @@ -357,7 +357,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { ConstraintCategory::Boring, self.cx.param_env.and(type_op::ascribe_user_type::AscribeUserType::new( constant.literal.ty, - def_id, + def.did, UserSubsts { substs, user_self_ty: None }, )), ) { diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index b02b5219ba1a4..face72d70cea0 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -549,8 +549,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let val_val = match val.val { ty::ConstKind::Param(_) => throw_inval!(TooGeneric), ty::ConstKind::Error(_) => throw_inval!(TypeckError(ErrorReported)), - ty::ConstKind::Unevaluated(def_id, substs, promoted) => { - let instance = self.resolve(def_id, substs)?; + ty::ConstKind::Unevaluated(def, substs, promoted) => { + let instance = self.resolve(def.did, substs)?; // We use `const_eval` here and `const_eval_raw` elsewhere in mir interpretation. // The reason we use `const_eval_raw` everywhere else is to prevent cycles during // validation, because validation automatically reads through any references, thus diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index f9b3c319c1f66..7a649649a42fe 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -622,12 +622,12 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { match substituted_constant.val { ty::ConstKind::Value(val) => collect_const_value(self.tcx, val, self.output), - ty::ConstKind::Unevaluated(def_id, substs, promoted) => { - match self.tcx.const_eval_resolve(param_env, def_id, substs, promoted, None) { + ty::ConstKind::Unevaluated(def, substs, promoted) => { + match self.tcx.const_eval_resolve(param_env, def.did, substs, promoted, None) { Ok(val) => collect_const_value(self.tcx, val, self.output), Err(ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted) => {} Err(ErrorHandled::TooGeneric) => span_bug!( - self.tcx.def_span(def_id), + self.tcx.def_span(def.did), "collection encountered polymorphic constant", ), } diff --git a/src/librustc_mir/transform/check_consts/qualifs.rs b/src/librustc_mir/transform/check_consts/qualifs.rs index 3dddd9c1c1766..705eb5d73233e 100644 --- a/src/librustc_mir/transform/check_consts/qualifs.rs +++ b/src/librustc_mir/transform/check_consts/qualifs.rs @@ -244,11 +244,11 @@ where }; // Check the qualifs of the value of `const` items. - if let ty::ConstKind::Unevaluated(def_id, _, promoted) = constant.literal.val { + if let ty::ConstKind::Unevaluated(def, _, promoted) = constant.literal.val { assert!(promoted.is_none()); // Don't peek inside trait associated constants. - if cx.tcx.trait_of_item(def_id).is_none() { - let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def_id); + if cx.tcx.trait_of_item(def.did).is_none() { + let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def.did); if !Q::in_qualifs(&qualifs) { return false; } diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 5aa67227994d9..a96ba715835f3 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -955,7 +955,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { literal: tcx.mk_const(ty::Const { ty, val: ty::ConstKind::Unevaluated( - def_id, + ty::WithOptParam::dummy(def_id), InternalSubsts::for_item(tcx, def_id, |param, _| { if let ty::GenericParamDefKind::Lifetime = param.kind { tcx.lifetimes.re_erased.into() diff --git a/src/librustc_mir_build/hair/cx/expr.rs b/src/librustc_mir_build/hair/cx/expr.rs index d36990684e03b..025ef1ece4603 100644 --- a/src/librustc_mir_build/hair/cx/expr.rs +++ b/src/librustc_mir_build/hair/cx/expr.rs @@ -600,7 +600,11 @@ fn make_mirror_unadjusted<'a, 'tcx>( // and not the beginning of discriminants (which is always `0`) let substs = InternalSubsts::identity_for_item(cx.tcx(), did); let lhs = mk_const(cx.tcx().mk_const(ty::Const { - val: ty::ConstKind::Unevaluated(did, substs, None), + val: ty::ConstKind::Unevaluated( + ty::WithOptParam::dummy(did), + substs, + None, + ), ty: var_ty, })); let bin = ExprKind::Binary { op: BinOp::Add, lhs, rhs: offset }; @@ -796,7 +800,7 @@ fn convert_path_expr<'a, 'tcx>( debug!("convert_path_expr: (const) user_ty={:?}", user_ty); ExprKind::Literal { literal: cx.tcx.mk_const(ty::Const { - val: ty::ConstKind::Unevaluated(def_id, substs, None), + val: ty::ConstKind::Unevaluated(ty::WithOptParam::dummy(def_id), substs, None), ty: cx.tables().node_type(expr.hir_id), }), user_ty, diff --git a/src/librustc_trait_selection/traits/fulfill.rs b/src/librustc_trait_selection/traits/fulfill.rs index 800aef7284f9e..702dcc2f9e1f4 100644 --- a/src/librustc_trait_selection/traits/fulfill.rs +++ b/src/librustc_trait_selection/traits/fulfill.rs @@ -524,10 +524,10 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { let stalled_on = &mut pending_obligation.stalled_on; let mut evaluate = |c: &'tcx Const<'tcx>| { - if let ty::ConstKind::Unevaluated(def_id, substs, promoted) = c.val { + if let ty::ConstKind::Unevaluated(def, substs, promoted) = c.val { match self.selcx.infcx().const_eval_resolve( obligation.param_env, - def_id, + def.did, substs, promoted, Some(obligation.cause.span), diff --git a/src/librustc_trait_selection/traits/select/mod.rs b/src/librustc_trait_selection/traits/select/mod.rs index ba5e60012da19..77c50973b914b 100644 --- a/src/librustc_trait_selection/traits/select/mod.rs +++ b/src/librustc_trait_selection/traits/select/mod.rs @@ -507,11 +507,11 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { debug!("evaluate_predicate_recursively: equating consts c1={:?} c2={:?}", c1, c2); let evaluate = |c: &'tcx ty::Const<'tcx>| { - if let ty::ConstKind::Unevaluated(def_id, substs, promoted) = c.val { + if let ty::ConstKind::Unevaluated(def, substs, promoted) = c.val { self.infcx .const_eval_resolve( obligation.param_env, - def_id, + def.did, substs, promoted, Some(obligation.cause.span), diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index ebff2dd9b23c1..30ba49ed2d8fe 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -359,13 +359,13 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { GenericArgKind::Const(constant) => { match constant.val { - ty::ConstKind::Unevaluated(def_id, substs, promoted) => { + ty::ConstKind::Unevaluated(def, substs, promoted) => { assert!(promoted.is_none()); - let obligations = self.nominal_obligations(def_id, substs); + let obligations = self.nominal_obligations(def.did, substs); self.out.extend(obligations); - let predicate = ty::PredicateKind::ConstEvaluatable(def_id, substs) + let predicate = ty::PredicateKind::ConstEvaluatable(def.did, substs) .to_predicate(self.tcx()); let cause = self.cause(traits::MiscObligation); self.out.push(traits::Obligation::new( diff --git a/src/librustdoc/clean/utils.rs b/src/librustdoc/clean/utils.rs index 832b2420c2389..52c306688268f 100644 --- a/src/librustdoc/clean/utils.rs +++ b/src/librustdoc/clean/utils.rs @@ -466,12 +466,12 @@ pub fn name_from_pat(p: &hir::Pat<'_>) -> String { pub fn print_const(cx: &DocContext<'_>, n: &'tcx ty::Const<'_>) -> String { match n.val { - ty::ConstKind::Unevaluated(def_id, _, promoted) => { - let mut s = if let Some(def_id) = def_id.as_local() { - let hir_id = cx.tcx.hir().as_local_hir_id(def_id); + ty::ConstKind::Unevaluated(def, _, promoted) => { + let mut s = if let Some(def) = def.as_local() { + let hir_id = cx.tcx.hir().as_local_hir_id(def.did); print_const_expr(cx, cx.tcx.hir().body_owned_by(hir_id)) } else { - inline::print_inlined_const(cx, def_id) + inline::print_inlined_const(cx, def.did) }; if let Some(promoted) = promoted { s.push_str(&format!("::{:?}", promoted)) From 2e6bf0923b113b754c9bda72b78eac354bec61f7 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Thu, 2 Jul 2020 23:56:17 +0200 Subject: [PATCH 05/25] const_eval_resolve --- src/librustc_codegen_ssa/mir/constant.rs | 2 +- src/librustc_infer/infer/mod.rs | 4 +- src/librustc_middle/mir/interpret/queries.rs | 4 +- src/librustc_middle/query/mod.rs | 9 ++++ src/librustc_middle/ty/instance.rs | 11 ++++ src/librustc_middle/ty/mod.rs | 4 +- src/librustc_middle/ty/print/pretty.rs | 4 +- src/librustc_middle/ty/query/keys.rs | 11 ++++ src/librustc_middle/ty/sty.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 2 +- .../traits/fulfill.rs | 2 +- .../traits/select/mod.rs | 2 +- src/librustc_trait_selection/traits/wf.rs | 6 +-- src/librustc_ty/instance.rs | 52 +++++++++++++++---- src/librustc_typeck/check/wfcheck.rs | 7 ++- src/tools/clippy/clippy_lints/src/consts.rs | 2 +- 16 files changed, 96 insertions(+), 28 deletions(-) diff --git a/src/librustc_codegen_ssa/mir/constant.rs b/src/librustc_codegen_ssa/mir/constant.rs index 007be7a62ae31..4943e279c7e05 100644 --- a/src/librustc_codegen_ssa/mir/constant.rs +++ b/src/librustc_codegen_ssa/mir/constant.rs @@ -28,7 +28,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ty::ConstKind::Unevaluated(def, substs, promoted) => self .cx .tcx() - .const_eval_resolve(ty::ParamEnv::reveal_all(), def.did, substs, promoted, None) + .const_eval_resolve(ty::ParamEnv::reveal_all(), def, substs, promoted, None) .map_err(|err| { if promoted.is_none() { self.cx diff --git a/src/librustc_infer/infer/mod.rs b/src/librustc_infer/infer/mod.rs index 27da514a17f4d..85c568cbd6583 100644 --- a/src/librustc_infer/infer/mod.rs +++ b/src/librustc_infer/infer/mod.rs @@ -1536,7 +1536,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn const_eval_resolve( &self, param_env: ty::ParamEnv<'tcx>, - def_id: DefId, + def: ty::WithOptParam, substs: SubstsRef<'tcx>, promoted: Option, span: Option, @@ -1547,7 +1547,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { let (param_env, substs) = canonical.value; // The return value is the evaluated value which doesn't contain any reference to inference // variables, thus we don't need to substitute back the original values. - self.tcx.const_eval_resolve(param_env, def_id, substs, promoted, span) + self.tcx.const_eval_resolve(param_env, def, substs, promoted, span) } /// If `typ` is a type variable of some kind, resolve it one level diff --git a/src/librustc_middle/mir/interpret/queries.rs b/src/librustc_middle/mir/interpret/queries.rs index a7953f0f900fb..bbaead535f6c7 100644 --- a/src/librustc_middle/mir/interpret/queries.rs +++ b/src/librustc_middle/mir/interpret/queries.rs @@ -34,12 +34,12 @@ impl<'tcx> TyCtxt<'tcx> { pub fn const_eval_resolve( self, param_env: ty::ParamEnv<'tcx>, - def_id: DefId, + def: ty::WithOptParam, substs: SubstsRef<'tcx>, promoted: Option, span: Option, ) -> ConstEvalResult<'tcx> { - match ty::Instance::resolve(self, param_env, def_id, substs) { + match ty::Instance::resolve_const_arg(self, param_env, def, substs) { Ok(Some(instance)) => { let cid = GlobalId { instance, promoted }; self.const_eval_global_id(param_env, cid, span) diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index d53b8d33262b5..50625af0adf0f 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -1463,5 +1463,14 @@ rustc_queries! { ) -> Result>, ErrorReported> { desc { "resolving instance `{}`", ty::Instance::new(key.value.0, key.value.1) } } + + query resolve_instance_of_const_arg( + key: ty::ParamEnvAnd<'tcx, (ty::WithOptParam, SubstsRef<'tcx>)> + ) -> Result>, ErrorReported> { + desc { + "resolving instance of the potential const argument `{}`", + ty::Instance::new(key.value.0.did, key.value.1), + } + } } } diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index d628d6783d5b0..fef1f9a51e6b7 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -336,6 +336,17 @@ impl<'tcx> Instance<'tcx> { tcx.resolve_instance(tcx.erase_regions(¶m_env.and((def_id, substs)))) } + // This should be kept up to date with `resolve`. + pub fn resolve_const_arg( + tcx: TyCtxt<'tcx>, + param_env: ty::ParamEnv<'tcx>, + def: ty::WithOptParam, + substs: SubstsRef<'tcx>, + ) -> Result>, ErrorReported> { + let substs = tcx.erase_regions(&substs); + tcx.resolve_instance_of_const_arg(tcx.erase_regions(¶m_env.and((def, substs)))) + } + pub fn resolve_for_fn_ptr( tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 539dfa6e892bc..bc55c1b2fe8c5 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1100,7 +1100,7 @@ pub enum PredicateKind<'tcx> { Subtype(PolySubtypePredicate<'tcx>), /// Constant initializer must evaluate successfully. - ConstEvaluatable(DefId, SubstsRef<'tcx>), + ConstEvaluatable(ty::WithOptParam, SubstsRef<'tcx>), /// Constants must be equal. The first component is the const that is expected. ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>), @@ -1571,7 +1571,7 @@ pub type PlaceholderType = Placeholder; pub type PlaceholderConst = Placeholder; -#[derive(Copy, Clone, Debug, RustcEncodable, RustcDecodable)] +#[derive(Copy, Clone, Debug, TypeFoldable, Lift, RustcEncodable, RustcDecodable)] #[derive(PartialEq, Eq, PartialOrd, Ord)] #[derive(Hash, HashStable)] pub struct WithOptParam { diff --git a/src/librustc_middle/ty/print/pretty.rs b/src/librustc_middle/ty/print/pretty.rs index 1cba593879aa5..b50d2852c1c5c 100644 --- a/src/librustc_middle/ty/print/pretty.rs +++ b/src/librustc_middle/ty/print/pretty.rs @@ -2027,9 +2027,9 @@ define_print_and_forward_display! { print_value_path(closure_def_id, &[]), write("` implements the trait `{}`", kind)) } - &ty::PredicateKind::ConstEvaluatable(def_id, substs) => { + &ty::PredicateKind::ConstEvaluatable(def, substs) => { p!(write("the constant `"), - print_value_path(def_id, substs), + print_value_path(def.did, substs), write("` can be evaluated")) } ty::PredicateKind::ConstEquate(c1, c2) => { diff --git a/src/librustc_middle/ty/query/keys.rs b/src/librustc_middle/ty/query/keys.rs index 4acf766f033d8..5fc9917376157 100644 --- a/src/librustc_middle/ty/query/keys.rs +++ b/src/librustc_middle/ty/query/keys.rs @@ -171,6 +171,17 @@ impl<'tcx> Key for (DefId, SubstsRef<'tcx>) { } } +impl<'tcx> Key for (ty::WithOptParam, SubstsRef<'tcx>) { + type CacheSelector = DefaultCacheSelector; + + fn query_crate(&self) -> CrateNum { + LOCAL_CRATE + } + fn default_span(&self, tcx: TyCtxt<'_>) -> Span { + self.0.did.default_span(tcx) + } +} + impl<'tcx> Key for (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>) { type CacheSelector = DefaultCacheSelector; diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 1e7171ea06c5c..3d16a9f92c98c 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -2373,7 +2373,7 @@ impl<'tcx> Const<'tcx> { let (param_env, substs) = param_env_and_substs.into_parts(); // try to resolve e.g. associated constants to their definition on an impl, and then // evaluate the const. - match tcx.const_eval_resolve(param_env, def.did, substs, promoted, None) { + match tcx.const_eval_resolve(param_env, def, substs, promoted, None) { // NOTE(eddyb) `val` contains no lifetimes/types/consts, // and we use the original type, so nothing from `substs` // (which may be identity substs, see above), diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 7a649649a42fe..a927df02cdcfe 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -623,7 +623,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { match substituted_constant.val { ty::ConstKind::Value(val) => collect_const_value(self.tcx, val, self.output), ty::ConstKind::Unevaluated(def, substs, promoted) => { - match self.tcx.const_eval_resolve(param_env, def.did, substs, promoted, None) { + match self.tcx.const_eval_resolve(param_env, def, substs, promoted, None) { Ok(val) => collect_const_value(self.tcx, val, self.output), Err(ErrorHandled::Reported(ErrorReported) | ErrorHandled::Linted) => {} Err(ErrorHandled::TooGeneric) => span_bug!( diff --git a/src/librustc_trait_selection/traits/fulfill.rs b/src/librustc_trait_selection/traits/fulfill.rs index 702dcc2f9e1f4..c6c76028f857c 100644 --- a/src/librustc_trait_selection/traits/fulfill.rs +++ b/src/librustc_trait_selection/traits/fulfill.rs @@ -527,7 +527,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> { if let ty::ConstKind::Unevaluated(def, substs, promoted) = c.val { match self.selcx.infcx().const_eval_resolve( obligation.param_env, - def.did, + def, substs, promoted, Some(obligation.cause.span), diff --git a/src/librustc_trait_selection/traits/select/mod.rs b/src/librustc_trait_selection/traits/select/mod.rs index 77c50973b914b..5dc5fb797ff6c 100644 --- a/src/librustc_trait_selection/traits/select/mod.rs +++ b/src/librustc_trait_selection/traits/select/mod.rs @@ -511,7 +511,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { self.infcx .const_eval_resolve( obligation.param_env, - def.did, + def, substs, promoted, Some(obligation.cause.span), diff --git a/src/librustc_trait_selection/traits/wf.rs b/src/librustc_trait_selection/traits/wf.rs index 30ba49ed2d8fe..b8446fa0012ab 100644 --- a/src/librustc_trait_selection/traits/wf.rs +++ b/src/librustc_trait_selection/traits/wf.rs @@ -116,8 +116,8 @@ pub fn predicate_obligations<'a, 'tcx>( wf.compute(data.skip_binder().a.into()); // (*) wf.compute(data.skip_binder().b.into()); // (*) } - &ty::PredicateKind::ConstEvaluatable(def_id, substs) => { - let obligations = wf.nominal_obligations(def_id, substs); + &ty::PredicateKind::ConstEvaluatable(def, substs) => { + let obligations = wf.nominal_obligations(def.did, substs); wf.out.extend(obligations); for arg in substs.iter() { @@ -365,7 +365,7 @@ impl<'a, 'tcx> WfPredicates<'a, 'tcx> { let obligations = self.nominal_obligations(def.did, substs); self.out.extend(obligations); - let predicate = ty::PredicateKind::ConstEvaluatable(def.did, substs) + let predicate = ty::PredicateKind::ConstEvaluatable(def, substs) .to_predicate(self.tcx()); let cause = self.cause(traits::MiscObligation); self.out.push(traits::Obligation::new( diff --git a/src/librustc_ty/instance.rs b/src/librustc_ty/instance.rs index 9f5ab7f8e4a02..d5c848817582c 100644 --- a/src/librustc_ty/instance.rs +++ b/src/librustc_ty/instance.rs @@ -14,15 +14,48 @@ fn resolve_instance<'tcx>( tcx: TyCtxt<'tcx>, key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>, ) -> Result>, ErrorReported> { - let (param_env, (def_id, substs)) = key.into_parts(); + let (param_env, (did, substs)) = key.into_parts(); + if let param_did @ Some(_) = did.as_local().and_then(|did| tcx.opt_const_param_of(did)) { + tcx.resolve_instance_of_const_arg( + param_env.and((ty::WithOptParam { did, param_did }, substs)), + ) + } else { + inner_resolve_instance(tcx, param_env.and((ty::WithOptParam::dummy(did), substs))) + } +} + +fn resolve_instance_of_const_arg<'tcx>( + tcx: TyCtxt<'tcx>, + key: ty::ParamEnvAnd<'tcx, (ty::WithOptParam, SubstsRef<'tcx>)>, +) -> Result>, ErrorReported> { + let (param_env, (def, substs)) = key.into_parts(); + if def.param_did.is_none() { + if let Some(did) = def.did.as_local() { + if let param_did @ Some(_) = tcx.opt_const_param_of(did) { + return tcx.resolve_instance_of_const_arg( + param_env.and((ty::WithOptParam { param_did, ..def }, substs)), + ); + } + } + tcx.resolve_instance(param_env.and((def.did, substs))) + } else { + inner_resolve_instance(tcx, param_env.and((def, substs))) + } +} + +fn inner_resolve_instance<'tcx>( + tcx: TyCtxt<'tcx>, + key: ty::ParamEnvAnd<'tcx, (ty::WithOptParam, SubstsRef<'tcx>)>, +) -> Result>, ErrorReported> { + let (param_env, (def, substs)) = key.into_parts(); - debug!("resolve(def_id={:?}, substs={:?})", def_id, substs); - let result = if let Some(trait_def_id) = tcx.trait_of_item(def_id) { + debug!("resolve(def={:?}, substs={:?})", def.did, substs); + let result = if let Some(trait_def_id) = tcx.trait_of_item(def.did) { debug!(" => associated item, attempting to find impl in param_env {:#?}", param_env); - let item = tcx.associated_item(def_id); + let item = tcx.associated_item(def.did); resolve_associated_item(tcx, &item, param_env, trait_def_id, substs) } else { - let ty = tcx.type_of(def_id); + let ty = tcx.type_of(def.ty_def_id()); let item_type = tcx.subst_and_normalize_erasing_regions(substs, param_env, &ty); let def = match item_type.kind { @@ -33,7 +66,7 @@ fn resolve_instance<'tcx>( } => { debug!(" => intrinsic"); - ty::InstanceDef::Intrinsic(def_id) + ty::InstanceDef::Intrinsic(def.did) } ty::FnDef(def_id, substs) if Some(def_id) == tcx.lang_items().drop_in_place_fn() => { let ty = substs.type_at(0); @@ -53,12 +86,12 @@ fn resolve_instance<'tcx>( } _ => { debug!(" => free item"); - ty::InstanceDef::Item(def_id) + ty::InstanceDef::Item(def.did) } }; Ok(Some(Instance { def, substs })) }; - debug!("resolve(def_id={:?}, substs={:?}) = {:?}", def_id, substs, result); + debug!("resolve(def.did={:?}, substs={:?}) = {:?}", def.did, substs, result); result } @@ -244,5 +277,6 @@ fn resolve_associated_item<'tcx>( } pub fn provide(providers: &mut ty::query::Providers) { - *providers = ty::query::Providers { resolve_instance, ..*providers }; + *providers = + ty::query::Providers { resolve_instance, resolve_instance_of_const_arg, ..*providers }; } diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 19c556942afc1..f64dce5132da0 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -423,8 +423,11 @@ fn check_type_defn<'tcx, F>( fcx.register_predicate(traits::Obligation::new( cause, fcx.param_env, - ty::PredicateKind::ConstEvaluatable(discr_def_id.to_def_id(), discr_substs) - .to_predicate(fcx.tcx), + ty::PredicateKind::ConstEvaluatable( + ty::WithOptParam::dummy(discr_def_id.to_def_id()), + discr_substs, + ) + .to_predicate(fcx.tcx), )); } } diff --git a/src/tools/clippy/clippy_lints/src/consts.rs b/src/tools/clippy/clippy_lints/src/consts.rs index 2f963dfcf8b18..6ba4201b2c254 100644 --- a/src/tools/clippy/clippy_lints/src/consts.rs +++ b/src/tools/clippy/clippy_lints/src/consts.rs @@ -332,7 +332,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let result = self .lcx .tcx - .const_eval_resolve(self.param_env, def_id, substs, None, None) + .const_eval_resolve(self.param_env, ty::WithOptParam::dummy(def_id), substs, None, None) .ok() .map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty))?; let result = miri_to_const(&result); From 178c6507f6f8bb8a8713151b12f29dfa650262ed Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Fri, 3 Jul 2020 16:39:02 +0200 Subject: [PATCH 06/25] typeck all the tables --- src/librustc_middle/query/mod.rs | 8 ++++++++ src/librustc_middle/ty/query/keys.rs | 11 +++++++++++ src/librustc_typeck/check/mod.rs | 21 +++++++++++++++++++-- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 50625af0adf0f..18bf2a7beaaae 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -556,6 +556,14 @@ rustc_queries! { desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if { true } } + query typeck_tables_of_const_arg( + key: ty::WithOptParam + ) -> &'tcx ty::TypeckTables<'tcx> { + desc { + |tcx| "type-checking the potential const argument `{}`", + tcx.def_path_str(key.did.to_def_id()), + } + } query diagnostic_only_typeck_tables_of(key: LocalDefId) -> &'tcx ty::TypeckTables<'tcx> { desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if { true } diff --git a/src/librustc_middle/ty/query/keys.rs b/src/librustc_middle/ty/query/keys.rs index 5fc9917376157..ad205e1f83b71 100644 --- a/src/librustc_middle/ty/query/keys.rs +++ b/src/librustc_middle/ty/query/keys.rs @@ -105,6 +105,17 @@ impl Key for DefId { } } +impl Key for ty::WithOptParam { + type CacheSelector = DefaultCacheSelector; + + fn query_crate(&self) -> CrateNum { + self.did.query_crate() + } + fn default_span(&self, tcx: TyCtxt<'_>) -> Span { + self.did.default_span(tcx) + } +} + impl Key for (DefId, DefId) { type CacheSelector = DefaultCacheSelector; diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 56f751e000ba1..4f792a07cc600 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -764,6 +764,7 @@ pub fn provide(providers: &mut Providers) { method::provide(providers); *providers = Providers { typeck_item_bodies, + typeck_tables_of_const_arg, typeck_tables_of, diagnostic_only_typeck_tables_of, has_typeck_tables, @@ -955,9 +956,25 @@ where val.fold_with(&mut FixupFolder { tcx }) } +fn typeck_tables_of_const_arg<'tcx>( + tcx: TyCtxt<'tcx>, + def: ty::WithOptParam, +) -> &ty::TypeckTables<'tcx> { + if let Some(param_did) = def.param_did { + let fallback = move || tcx.type_of(param_did); + typeck_tables_of_with_fallback(tcx, def.did, fallback) + } else { + tcx.typeck_tables_of(def.did) + } +} + fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckTables<'tcx> { - let fallback = move || tcx.type_of(def_id.to_def_id()); - typeck_tables_of_with_fallback(tcx, def_id, fallback) + if let param_did @ Some(_) = tcx.opt_const_param_of(def_id) { + tcx.typeck_tables_of_const_arg(ty::WithOptParam { did: def_id, param_did }) + } else { + let fallback = move || tcx.type_of(def_id.to_def_id()); + typeck_tables_of_with_fallback(tcx, def_id, fallback) + } } /// Used only to get `TypeckTables` for type inference during error recovery. From a8419099d18a3d5bd16ffa5165d6e2e7aefda807 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Fri, 3 Jul 2020 19:13:39 +0200 Subject: [PATCH 07/25] InstanceDef::Item --- .../back/symbol_export.rs | 4 +- src/librustc_middle/mir/mono.rs | 4 +- src/librustc_middle/ty/instance.rs | 41 +++++++++++++------ src/librustc_middle/ty/mod.rs | 2 +- src/librustc_middle/ty/structural_impls.rs | 5 ++- src/librustc_mir/const_eval/eval_queries.rs | 24 +++++------ src/librustc_mir/const_eval/machine.rs | 4 +- src/librustc_mir/interpret/eval_context.rs | 20 +++++---- src/librustc_mir/monomorphize/collector.rs | 4 +- src/librustc_mir/monomorphize/partitioning.rs | 5 ++- .../transform/check_consts/validation.rs | 4 +- src/librustc_mir/transform/mod.rs | 12 +++--- src/librustc_mir/util/pretty.rs | 5 ++- src/librustc_ty/instance.rs | 4 +- 14 files changed, 80 insertions(+), 58 deletions(-) diff --git a/src/librustc_codegen_ssa/back/symbol_export.rs b/src/librustc_codegen_ssa/back/symbol_export.rs index faf6809f35b1c..4f2d592ffc6a6 100644 --- a/src/librustc_codegen_ssa/back/symbol_export.rs +++ b/src/librustc_codegen_ssa/back/symbol_export.rs @@ -249,9 +249,9 @@ fn exported_symbols_provider_local( } match *mono_item { - MonoItem::Fn(Instance { def: InstanceDef::Item(def_id), substs }) => { + MonoItem::Fn(Instance { def: InstanceDef::Item(def), substs }) => { if substs.non_erasable_generics().next().is_some() { - let symbol = ExportedSymbol::Generic(def_id, substs); + let symbol = ExportedSymbol::Generic(def.did, substs); symbols.push((symbol, SymbolExportLevel::Rust)); } } diff --git a/src/librustc_middle/mir/mono.rs b/src/librustc_middle/mir/mono.rs index c9e5a196f9179..b7e3500ede428 100644 --- a/src/librustc_middle/mir/mono.rs +++ b/src/librustc_middle/mir/mono.rs @@ -346,8 +346,8 @@ impl<'tcx> CodegenUnit<'tcx> { // instances into account. The others don't matter for // the codegen tests and can even make item order // unstable. - InstanceDef::Item(def_id) => { - def_id.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) + InstanceDef::Item(def) => { + def.did.as_local().map(|def_id| tcx.hir().as_local_hir_id(def_id)) } InstanceDef::VtableShim(..) | InstanceDef::ReifyShim(..) diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index fef1f9a51e6b7..4c96e1f965f7f 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -29,7 +29,7 @@ pub enum InstanceDef<'tcx> { /// - `fn` items /// - closures /// - generators - Item(DefId), + Item(ty::WithOptParam), /// An intrinsic `fn` item (with `"rust-intrinsic"` or `"platform-intrinsic"` ABI). /// @@ -160,8 +160,8 @@ impl<'tcx> Instance<'tcx> { self.substs.non_erasable_generics().next()?; match self.def { - InstanceDef::Item(def_id) => tcx - .upstream_monomorphizations_for(def_id) + InstanceDef::Item(def) => tcx + .upstream_monomorphizations_for(def.did) .and_then(|monos| monos.get(&self.substs).cloned()), InstanceDef::DropGlue(_, Some(_)) => tcx.upstream_drop_glue_for(self.substs), _ => None, @@ -171,10 +171,10 @@ impl<'tcx> Instance<'tcx> { impl<'tcx> InstanceDef<'tcx> { #[inline] - pub fn def_id(&self) -> DefId { - match *self { - InstanceDef::Item(def_id) - | InstanceDef::VtableShim(def_id) + pub fn def_id(self) -> DefId { + match self { + InstanceDef::Item(def) => def.did, + InstanceDef::VtableShim(def_id) | InstanceDef::ReifyShim(def_id) | InstanceDef::FnPtrShim(def_id, _) | InstanceDef::Virtual(def_id, _) @@ -185,6 +185,21 @@ impl<'tcx> InstanceDef<'tcx> { } } + #[inline] + pub fn with_opt_param(self) -> ty::WithOptParam { + match self { + InstanceDef::Item(def) => def, + InstanceDef::VtableShim(def_id) + | InstanceDef::ReifyShim(def_id) + | InstanceDef::FnPtrShim(def_id, _) + | InstanceDef::Virtual(def_id, _) + | InstanceDef::Intrinsic(def_id) + | InstanceDef::ClosureOnceShim { call_once: def_id } + | InstanceDef::DropGlue(def_id, _) + | InstanceDef::CloneShim(def_id, _) => ty::WithOptParam::dummy(def_id), + } + } + #[inline] pub fn attrs(&self, tcx: TyCtxt<'tcx>) -> ty::Attributes<'tcx> { tcx.get_attrs(self.def_id()) @@ -198,7 +213,7 @@ impl<'tcx> InstanceDef<'tcx> { pub fn requires_inline(&self, tcx: TyCtxt<'tcx>) -> bool { use rustc_hir::definitions::DefPathData; let def_id = match *self { - ty::InstanceDef::Item(def_id) => def_id, + ty::InstanceDef::Item(def) => def.did, ty::InstanceDef::DropGlue(_, Some(_)) => return false, _ => return true, }; @@ -244,8 +259,8 @@ impl<'tcx> InstanceDef<'tcx> { pub fn requires_caller_location(&self, tcx: TyCtxt<'_>) -> bool { match *self { - InstanceDef::Item(def_id) => { - tcx.codegen_fn_attrs(def_id).flags.contains(CodegenFnAttrFlags::TRACK_CALLER) + InstanceDef::Item(def) => { + tcx.codegen_fn_attrs(def.did).flags.contains(CodegenFnAttrFlags::TRACK_CALLER) } _ => false, } @@ -283,7 +298,7 @@ impl<'tcx> Instance<'tcx> { def_id, substs ); - Instance { def: InstanceDef::Item(def_id), substs } + Instance { def: InstanceDef::Item(ty::WithOptParam::dummy(def_id)), substs } } pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> { @@ -356,9 +371,9 @@ impl<'tcx> Instance<'tcx> { debug!("resolve(def_id={:?}, substs={:?})", def_id, substs); Instance::resolve(tcx, param_env, def_id, substs).ok().flatten().map(|mut resolved| { match resolved.def { - InstanceDef::Item(def_id) if resolved.def.requires_caller_location(tcx) => { + InstanceDef::Item(def) if resolved.def.requires_caller_location(tcx) => { debug!(" => fn pointer created for function with #[track_caller]"); - resolved.def = InstanceDef::ReifyShim(def_id); + resolved.def = InstanceDef::ReifyShim(def.did); } InstanceDef::Virtual(def_id, _) => { debug!(" => fn pointer created for virtual call"); diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index bc55c1b2fe8c5..ce76a3bef832f 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -2880,7 +2880,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair. pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> { match instance { - ty::InstanceDef::Item(did) => self.optimized_mir(did), + ty::InstanceDef::Item(def) => self.optimized_mir(def.did), ty::InstanceDef::VtableShim(..) | ty::InstanceDef::ReifyShim(..) | ty::InstanceDef::Intrinsic(..) diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index 159af277d240b..67d0030dea8fc 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -838,7 +838,7 @@ impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> { Self { substs: self.substs.fold_with(folder), def: match self.def { - Item(did) => Item(did.fold_with(folder)), + Item(def) => Item(def.fold_with(folder)), VtableShim(did) => VtableShim(did.fold_with(folder)), ReifyShim(did) => ReifyShim(did.fold_with(folder)), Intrinsic(did) => Intrinsic(did.fold_with(folder)), @@ -857,7 +857,8 @@ impl<'tcx> TypeFoldable<'tcx> for ty::instance::Instance<'tcx> { use crate::ty::InstanceDef::*; self.substs.visit_with(visitor) || match self.def { - Item(did) | VtableShim(did) | ReifyShim(did) | Intrinsic(did) | Virtual(did, _) => { + Item(def) => def.visit_with(visitor), + VtableShim(did) | ReifyShim(did) | Intrinsic(did) | Virtual(did, _) => { did.visit_with(visitor) } FnPtrShim(did, ty) | CloneShim(did, ty) => { diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs index 24a0107ab9689..a8f0de68f22f7 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -288,21 +288,21 @@ pub fn const_eval_raw_provider<'tcx>( } let cid = key.value; - let def_id = cid.instance.def.def_id(); + let def = cid.instance.def.with_opt_param(); - if let Some(def_id) = def_id.as_local() { - if tcx.has_typeck_tables(def_id) { - if let Some(error_reported) = tcx.typeck_tables_of(def_id).tainted_by_errors { + if let Some(def) = def.as_local() { + if tcx.has_typeck_tables(def.did) { + if let Some(error_reported) = tcx.typeck_tables_of_const_arg(def).tainted_by_errors { return Err(ErrorHandled::Reported(error_reported)); } } } - let is_static = tcx.is_static(def_id); + let is_static = tcx.is_static(def.did); let mut ecx = InterpCx::new( tcx, - tcx.def_span(cid.instance.def_id()), + tcx.def_span(def.did), key.param_env, CompileTimeInterpreter::new(tcx.sess.const_eval_limit()), MemoryExtra { can_access_statics: is_static }, @@ -334,9 +334,9 @@ pub fn const_eval_raw_provider<'tcx>( } v - } else if let Some(def_id) = def_id.as_local() { + } else if let Some(def) = def.as_local() { // constant defined in this crate, we can figure out a lint level! - match tcx.def_kind(def_id.to_def_id()) { + match tcx.def_kind(def.did.to_def_id()) { // constants never produce a hard error at the definition site. Anything else is // a backwards compatibility hazard (and will break old versions of winapi for // sure) @@ -346,9 +346,9 @@ pub fn const_eval_raw_provider<'tcx>( // validation thus preventing such a hard error from being a backwards // compatibility hazard DefKind::Const | DefKind::AssocConst => { - let hir_id = tcx.hir().as_local_hir_id(def_id); + let hir_id = tcx.hir().as_local_hir_id(def.did); err.report_as_lint( - tcx.at(tcx.def_span(def_id)), + tcx.at(tcx.def_span(def.did)), "any use of this value will cause an error", hir_id, Some(err.span), @@ -359,7 +359,7 @@ pub fn const_eval_raw_provider<'tcx>( // deny-by-default lint _ => { if let Some(p) = cid.promoted { - let span = tcx.promoted_mir(def_id)[p].span; + let span = tcx.promoted_mir(def.did)[p].span; if let err_inval!(ReferencedConstant) = err.error { err.report_as_error( tcx.at(span), @@ -369,7 +369,7 @@ pub fn const_eval_raw_provider<'tcx>( err.report_as_lint( tcx.at(span), "reaching this expression at runtime will panic or abort", - tcx.hir().as_local_hir_id(def_id), + tcx.hir().as_local_hir_id(def.did), Some(err.span), ) } diff --git a/src/librustc_mir/const_eval/machine.rs b/src/librustc_mir/const_eval/machine.rs index 8be0ab9019fe2..6453630bb92ba 100644 --- a/src/librustc_mir/const_eval/machine.rs +++ b/src/librustc_mir/const_eval/machine.rs @@ -191,11 +191,11 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir, debug!("find_mir_or_eval_fn: {:?}", instance); // Only check non-glue functions - if let ty::InstanceDef::Item(def_id) = instance.def { + if let ty::InstanceDef::Item(def) = instance.def { // Execution might have wandered off into other crates, so we cannot do a stability- // sensitive check here. But we can at least rule out functions that are not const // at all. - if ecx.tcx.is_const_fn_raw(def_id) { + if ecx.tcx.is_const_fn_raw(def.did) { // If this function is a `const fn` then under certain circumstances we // can evaluate call via the query system, thus memoizing all future calls. if ecx.try_eval_const_fn_call(instance, ret, args)? { diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 602876e3de168..641b8cce5e419 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -394,24 +394,26 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { promoted: Option, ) -> InterpResult<'tcx, &'tcx mir::Body<'tcx>> { // do not continue if typeck errors occurred (can only occur in local crate) - let did = instance.def_id(); - if let Some(did) = did.as_local() { - if self.tcx.has_typeck_tables(did) { - if let Some(error_reported) = self.tcx.typeck_tables_of(did).tainted_by_errors { + let def = instance.with_opt_param(); + if let Some(def) = def.as_local() { + if self.tcx.has_typeck_tables(def.did) { + if let Some(error_reported) = + self.tcx.typeck_tables_of_const_arg(def).tainted_by_errors + { throw_inval!(TypeckError(error_reported)) } } } trace!("load mir(instance={:?}, promoted={:?})", instance, promoted); if let Some(promoted) = promoted { - return Ok(&self.tcx.promoted_mir(did)[promoted]); + return Ok(&self.tcx.promoted_mir(def.did)[promoted]); } match instance { - ty::InstanceDef::Item(def_id) => { - if self.tcx.is_mir_available(did) { - Ok(self.tcx.optimized_mir(did)) + ty::InstanceDef::Item(def) => { + if self.tcx.is_mir_available(def.did) { + Ok(self.tcx.optimized_mir(def.did)) } else { - throw_unsup!(NoMirFor(def_id)) + throw_unsup!(NoMirFor(def.did)) } } _ => Ok(self.tcx.instance_mir(instance)), diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index a927df02cdcfe..35fb950ce66b9 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -768,8 +768,8 @@ fn visit_instance_use<'tcx>( // need a mono item. fn should_monomorphize_locally<'tcx>(tcx: TyCtxt<'tcx>, instance: &Instance<'tcx>) -> bool { let def_id = match instance.def { - ty::InstanceDef::Item(def_id) | ty::InstanceDef::DropGlue(def_id, Some(_)) => def_id, - + ty::InstanceDef::Item(def) => def.did, + ty::InstanceDef::DropGlue(def_id, Some(_)) => def_id, ty::InstanceDef::VtableShim(..) | ty::InstanceDef::ReifyShim(..) | ty::InstanceDef::ClosureOnceShim { .. } diff --git a/src/librustc_mir/monomorphize/partitioning.rs b/src/librustc_mir/monomorphize/partitioning.rs index ebea65c8f96f2..208d282058130 100644 --- a/src/librustc_mir/monomorphize/partitioning.rs +++ b/src/librustc_mir/monomorphize/partitioning.rs @@ -314,7 +314,8 @@ fn mono_item_visibility( }; let def_id = match instance.def { - InstanceDef::Item(def_id) | InstanceDef::DropGlue(def_id, Some(_)) => def_id, + InstanceDef::Item(def) => def.did, + InstanceDef::DropGlue(def_id, Some(_)) => def_id, // These are all compiler glue and such, never exported, always hidden. InstanceDef::VtableShim(..) @@ -704,7 +705,7 @@ fn characteristic_def_id_of_mono_item<'tcx>( match mono_item { MonoItem::Fn(instance) => { let def_id = match instance.def { - ty::InstanceDef::Item(def_id) => def_id, + ty::InstanceDef::Item(def) => def.did, ty::InstanceDef::VtableShim(..) | ty::InstanceDef::ReifyShim(..) | ty::InstanceDef::FnPtrShim(..) diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index 5cb161ebcfb5e..f64c72e7b362d 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -520,8 +520,8 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> { let instance = Instance::resolve(self.tcx, self.param_env, def_id, substs); debug!("Resolving ({:?}) -> {:?}", def_id, instance); if let Ok(Some(func)) = instance { - if let InstanceDef::Item(def_id) = func.def { - if is_const_fn(self.tcx, def_id) { + if let InstanceDef::Item(def) = func.def { + if is_const_fn(self.tcx, def.did) { return; } } diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 816cf08a6da48..e5d6ff4a3fb96 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -9,7 +9,7 @@ use rustc_middle::mir::visit::Visitor as _; use rustc_middle::mir::{traversal, Body, ConstQualifs, MirPhase, Promoted}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::steal::Steal; -use rustc_middle::ty::{InstanceDef, TyCtxt, TypeFoldable}; +use rustc_middle::ty::{self, InstanceDef, TyCtxt, TypeFoldable}; use rustc_span::{Span, Symbol}; use std::borrow::Cow; @@ -116,7 +116,7 @@ pub struct MirSource<'tcx> { impl<'tcx> MirSource<'tcx> { pub fn item(def_id: DefId) -> Self { - MirSource { instance: InstanceDef::Item(def_id), promoted: None } + MirSource { instance: InstanceDef::Item(ty::WithOptParam::dummy(def_id)), promoted: None } } #[inline] @@ -249,7 +249,7 @@ fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> Steal> { run_passes( tcx, &mut body, - InstanceDef::Item(def_id.to_def_id()), + InstanceDef::Item(ty::WithOptParam::dummy(def_id.to_def_id())), None, MirPhase::Const, &[&[ @@ -284,7 +284,7 @@ fn mir_validated( run_passes( tcx, &mut body, - InstanceDef::Item(def_id.to_def_id()), + InstanceDef::Item(ty::WithOptParam::dummy(def_id.to_def_id())), None, MirPhase::Validated, &[&[ @@ -350,7 +350,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>( run_passes( tcx, body, - InstanceDef::Item(def_id.to_def_id()), + InstanceDef::Item(ty::WithOptParam::dummy(def_id.to_def_id())), promoted, MirPhase::DropElab, &[post_borrowck_cleanup], @@ -414,7 +414,7 @@ fn run_optimization_passes<'tcx>( run_passes( tcx, body, - InstanceDef::Item(def_id.to_def_id()), + InstanceDef::Item(ty::WithOptParam::dummy(def_id.to_def_id())), promoted, MirPhase::Optimized, &[ diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index db45481e4fd25..9b6dd2dc268a1 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -248,7 +248,10 @@ pub fn write_mir_pretty<'tcx>( for (i, body) in tcx.promoted_mir(def_id).iter_enumerated() { writeln!(w)?; - let src = MirSource { instance: ty::InstanceDef::Item(def_id), promoted: Some(i) }; + let src = MirSource { + instance: ty::InstanceDef::Item(ty::WithOptParam::dummy(def_id)), + promoted: Some(i), + }; write_mir_fn(tcx, src, body, &mut |_, _| Ok(()), w)?; } } diff --git a/src/librustc_ty/instance.rs b/src/librustc_ty/instance.rs index d5c848817582c..7c58963fccc85 100644 --- a/src/librustc_ty/instance.rs +++ b/src/librustc_ty/instance.rs @@ -86,7 +86,7 @@ fn inner_resolve_instance<'tcx>( } _ => { debug!(" => free item"); - ty::InstanceDef::Item(def.did) + ty::InstanceDef::Item(def) } }; Ok(Some(Instance { def, substs })) @@ -215,7 +215,7 @@ fn resolve_associated_item<'tcx>( Some(ty::Instance::new(leaf_def.item.def_id, substs)) } traits::ImplSourceGenerator(generator_data) => Some(Instance { - def: ty::InstanceDef::Item(generator_data.generator_def_id), + def: ty::InstanceDef::Item(ty::WithOptParam::dummy(generator_data.generator_def_id)), substs: generator_data.substs, }), traits::ImplSourceClosure(closure_data) => { From 316128c38a1bb011e3b6a5301ffe47427b06c9aa Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Fri, 3 Jul 2020 20:38:31 +0200 Subject: [PATCH 08/25] optimized_mir --- .../rmeta/decoder/cstore_impl.rs | 2 +- src/librustc_middle/arena.rs | 1 + src/librustc_middle/query/mod.rs | 6 ++- src/librustc_middle/ty/mod.rs | 8 +++- src/librustc_mir/transform/mod.rs | 37 +++++++++++++++---- 5 files changed, 43 insertions(+), 11 deletions(-) diff --git a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs index 201a32d387779..c46229b77a5b0 100644 --- a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs +++ b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs @@ -111,7 +111,7 @@ provide! { <'tcx> tcx, def_id, other, cdata, bug!("coerce_unsized_info: `{:?}` is missing its info", def_id); }) } - optimized_mir => { cdata.get_optimized_mir(tcx, def_id.index) } + optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) } promoted_mir => { cdata.get_promoted_mir(tcx, def_id.index) } mir_const_qualif => { cdata.mir_const_qualif(def_id.index) } fn_sig => { cdata.fn_sig(def_id.index, tcx) } diff --git a/src/librustc_middle/arena.rs b/src/librustc_middle/arena.rs index 4f1889aeb162a..3e5a2cd7825fa 100644 --- a/src/librustc_middle/arena.rs +++ b/src/librustc_middle/arena.rs @@ -14,6 +14,7 @@ macro_rules! arena_types { [] layouts: rustc_target::abi::Layout, rustc_target::abi::Layout; // AdtDef are interned and compared by address [] adt_def: rustc_middle::ty::AdtDef, rustc_middle::ty::AdtDef; + [] mir: rustc_middle::mir::Body<$tcx>, rustc_middle::mir::Body<$tcx>; [decode] tables: rustc_middle::ty::TypeckTables<$tcx>, rustc_middle::ty::TypeckTables<'_x>; [] const_allocs: rustc_middle::mir::interpret::Allocation, rustc_middle::mir::interpret::Allocation; // Required for the incremental on-disk cache diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 18bf2a7beaaae..28cdedca3f74d 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -244,11 +244,13 @@ rustc_queries! { /// MIR after our optimization passes have run. This is MIR that is ready /// for codegen. This is also the only query that can fetch non-local MIR, at present. - query optimized_mir(key: DefId) -> mir::Body<'tcx> { + query optimized_mir(key: DefId) -> &'tcx mir::Body<'tcx> { desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) } - storage(ArenaCacheSelector<'tcx>) cache_on_disk_if { key.is_local() } } + query optimized_mir_of_const_arg(key: ty::WithOptParam) -> &'tcx mir::Body<'tcx> { + desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) } + } /// Returns coverage summary info for a function, after executing the `InstrumentCoverage` /// MIR pass (assuming the -Zinstrument-coverage option is enabled). diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index ce76a3bef832f..2a366c9801efc 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -2880,7 +2880,13 @@ impl<'tcx> TyCtxt<'tcx> { /// Returns the possibly-auto-generated MIR of a `(DefId, Subst)` pair. pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> { match instance { - ty::InstanceDef::Item(def) => self.optimized_mir(def.did), + ty::InstanceDef::Item(def) => { + if let Some(def) = def.as_local() { + self.optimized_mir_of_const_arg(def) + } else { + self.optimized_mir(def.did) + } + } ty::InstanceDef::VtableShim(..) | ty::InstanceDef::ReifyShim(..) | ty::InstanceDef::Intrinsic(..) diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index e5d6ff4a3fb96..4ba9cb9f7720d 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -52,6 +52,7 @@ pub(crate) fn provide(providers: &mut Providers) { mir_validated, mir_drops_elaborated_and_const_checked, optimized_mir, + optimized_mir_of_const_arg, is_mir_available, promoted_mir, ..*providers @@ -424,19 +425,41 @@ fn run_optimization_passes<'tcx>( ); } -fn optimized_mir(tcx: TyCtxt<'_>, def_id: DefId) -> Body<'_> { - if tcx.is_constructor(def_id) { +fn optimized_mir<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx Body<'tcx> { + let did = did.expect_local(); + if let param_did @ Some(_) = tcx.opt_const_param_of(did) { + tcx.optimized_mir_of_const_arg(ty::WithOptParam { did, param_did }) + } else { + tcx.arena.alloc(inner_optimized_mir(tcx, ty::WithOptParam::dummy(did))) + } +} + +fn optimized_mir_of_const_arg<'tcx>( + tcx: TyCtxt<'tcx>, + def: ty::WithOptParam, +) -> &'tcx Body<'tcx> { + if def.param_did.is_none() { + if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + tcx.optimized_mir_of_const_arg(ty::WithOptParam { param_did, ..def }) + } else { + tcx.optimized_mir(def.did) + } + } else { + tcx.arena.alloc(inner_optimized_mir(tcx, def)) + } +} + +fn inner_optimized_mir(tcx: TyCtxt<'_>, def: ty::WithOptParam) -> Body<'_> { + if tcx.is_constructor(def.did.to_def_id()) { // There's no reason to run all of the MIR passes on constructors when // we can just output the MIR we want directly. This also saves const // qualification and borrow checking the trouble of special casing // constructors. - return shim::build_adt_ctor(tcx, def_id); + return shim::build_adt_ctor(tcx, def.did.to_def_id()); } - let def_id = def_id.expect_local(); - - let mut body = tcx.mir_drops_elaborated_and_const_checked(def_id).steal(); - run_optimization_passes(tcx, &mut body, def_id, None); + let mut body = tcx.mir_drops_elaborated_and_const_checked(def.did).steal(); + run_optimization_passes(tcx, &mut body, def.did, None); debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR"); From b615b98f33c73670731c7e681a45a8335049492e Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Fri, 3 Jul 2020 22:15:27 +0200 Subject: [PATCH 09/25] continue mir pipeline --- src/librustc_interface/passes.rs | 3 ++- src/librustc_middle/arena.rs | 19 +++++++++++++ src/librustc_middle/query/mod.rs | 27 ++++++++++--------- src/librustc_middle/ty/context.rs | 8 +++--- src/librustc_mir/borrow_check/mod.rs | 4 +-- src/librustc_mir/interpret/eval_context.rs | 6 ++++- src/librustc_mir/transform/mod.rs | 25 ++++++++++------- src/librustc_mir_build/build/mod.rs | 2 +- ...9-assoc-const-static-recursion-impl.stderr | 5 ++++ ...onst-static-recursion-trait-default.stderr | 5 ++++ ...-assoc-const-static-recursion-trait.stderr | 5 ++++ 11 files changed, 78 insertions(+), 31 deletions(-) diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 6d85c2f182544..5152e62f07201 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -891,7 +891,8 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> { mir::transform::check_unsafety::check_unsafety(tcx, def_id); if tcx.hir().body_const_context(def_id).is_some() { - tcx.ensure().mir_drops_elaborated_and_const_checked(def_id); + tcx.ensure() + .mir_drops_elaborated_and_const_checked(ty::WithOptParam::dummy(def_id)); } } }); diff --git a/src/librustc_middle/arena.rs b/src/librustc_middle/arena.rs index 3e5a2cd7825fa..caf771803c0f4 100644 --- a/src/librustc_middle/arena.rs +++ b/src/librustc_middle/arena.rs @@ -14,8 +14,27 @@ macro_rules! arena_types { [] layouts: rustc_target::abi::Layout, rustc_target::abi::Layout; // AdtDef are interned and compared by address [] adt_def: rustc_middle::ty::AdtDef, rustc_middle::ty::AdtDef; + [] steal_mir: + rustc_middle::ty::steal::Steal>, + rustc_middle::ty::steal::Steal>; [] mir: rustc_middle::mir::Body<$tcx>, rustc_middle::mir::Body<$tcx>; + [] steal_promoted: + rustc_middle::ty::steal::Steal< + rustc_index::vec::IndexVec< + rustc_middle::mir::Promoted, + rustc_middle::mir::Body<$tcx> + > + >, + rustc_middle::ty::steal::Steal< + rustc_index::vec::IndexVec< + rustc_middle::mir::Promoted, + rustc_middle::mir::Body<$tcx> + > + >; [decode] tables: rustc_middle::ty::TypeckTables<$tcx>, rustc_middle::ty::TypeckTables<'_x>; + [decode] borrowck_result: + rustc_middle::mir::BorrowCheckResult<$tcx>, + rustc_middle::mir::BorrowCheckResult<'_x>; [] const_allocs: rustc_middle::mir::interpret::Allocation, rustc_middle::mir::interpret::Allocation; // Required for the incremental on-disk cache [few, decode] mir_keys: rustc_hir::def_id::DefIdSet, rustc_hir::def_id::DefIdSet; diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 28cdedca3f74d..bad2dc648594e 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -211,8 +211,7 @@ rustc_queries! { /// Fetch the MIR for a given `DefId` right after it's built - this includes /// unreachable code. - query mir_built(key: LocalDefId) -> Steal> { - storage(ArenaCacheSelector<'tcx>) + query mir_built(key: LocalDefId) -> &'tcx Steal> { desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.to_def_id()) } } @@ -220,24 +219,23 @@ rustc_queries! { /// ready for const qualification. /// /// See the README for the `mir` module for details. - query mir_const(key: DefId) -> Steal> { - desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key) } - storage(ArenaCacheSelector<'tcx>) + query mir_const(key: DefId) -> &'tcx Steal> { + desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key) } no_hash } - query mir_drops_elaborated_and_const_checked(key: LocalDefId) -> Steal> { - storage(ArenaCacheSelector<'tcx>) + query mir_drops_elaborated_and_const_checked( + key: ty::WithOptParam + ) -> &'tcx Steal> { no_hash - desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.to_def_id()) } + desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) } } query mir_validated(key: LocalDefId) -> ( - Steal>, - Steal>> + &'tcx Steal>, + &'tcx Steal>> ) { - storage(ArenaCacheSelector<'tcx>) no_hash desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) } } @@ -249,7 +247,10 @@ rustc_queries! { cache_on_disk_if { key.is_local() } } query optimized_mir_of_const_arg(key: ty::WithOptParam) -> &'tcx mir::Body<'tcx> { - desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) } + desc { + |tcx| "optimizing MIR for the potential const argument `{}`", + tcx.def_path_str(key.did.to_def_id()) + } } /// Returns coverage summary info for a function, after executing the `InstrumentCoverage` @@ -599,7 +600,7 @@ rustc_queries! { BorrowChecking { /// Borrow-checks the function body. If this is a closure, returns /// additional requirements that the closure's creator must verify. - query mir_borrowck(key: LocalDefId) -> mir::BorrowCheckResult<'tcx> { + query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> { storage(ArenaCacheSelector<'tcx>) desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if(tcx, opt_result) { diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index c4a5bc302227d..d2bad6e90dda2 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -980,15 +980,15 @@ pub struct GlobalCtxt<'tcx> { } impl<'tcx> TyCtxt<'tcx> { - pub fn alloc_steal_mir(self, mir: Body<'tcx>) -> Steal> { - Steal::new(mir) + pub fn alloc_steal_mir(self, mir: Body<'tcx>) -> &'tcx Steal> { + self.arena.alloc(Steal::new(mir)) } pub fn alloc_steal_promoted( self, promoted: IndexVec>, - ) -> Steal>> { - Steal::new(promoted) + ) -> &'tcx Steal>> { + self.arena.alloc(Steal::new(promoted)) } pub fn alloc_adt_def( diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index beb5f1fe924ec..e77dcb63f4667 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -90,7 +90,7 @@ pub fn provide(providers: &mut Providers) { *providers = Providers { mir_borrowck, ..*providers }; } -fn mir_borrowck(tcx: TyCtxt<'_>, def_id: LocalDefId) -> BorrowCheckResult<'_> { +fn mir_borrowck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx BorrowCheckResult<'tcx> { let (input_body, promoted) = tcx.mir_validated(def_id); debug!("run query mir_borrowck: {}", tcx.def_path_str(def_id.to_def_id())); @@ -101,7 +101,7 @@ fn mir_borrowck(tcx: TyCtxt<'_>, def_id: LocalDefId) -> BorrowCheckResult<'_> { }); debug!("mir_borrowck done"); - opt_closure_req + tcx.arena.alloc(opt_closure_req) } fn do_mir_borrowck<'a, 'tcx>( diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 641b8cce5e419..5e1376677a0a7 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -411,7 +411,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { match instance { ty::InstanceDef::Item(def) => { if self.tcx.is_mir_available(def.did) { - Ok(self.tcx.optimized_mir(def.did)) + if let Some(def) = def.as_local() { + Ok(self.tcx.optimized_mir_of_const_arg(def)) + } else { + Ok(self.tcx.optimized_mir(def.did)) + } } else { throw_unsup!(NoMirFor(def.did)) } diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 4ba9cb9f7720d..25973462e4c6e 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -235,7 +235,7 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs { } /// Make MIR ready for const evaluation. This is run on all MIR, not just on consts! -fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> Steal> { +fn mir_const<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Steal> { let def_id = def_id.expect_local(); // Unsafety check uses the raw mir, so make sure it is run. @@ -267,7 +267,7 @@ fn mir_const(tcx: TyCtxt<'_>, def_id: DefId) -> Steal> { fn mir_validated( tcx: TyCtxt<'tcx>, def_id: LocalDefId, -) -> (Steal>, Steal>>) { +) -> (&'tcx Steal>, &'tcx Steal>>) { // Ensure that we compute the `mir_const_qualif` for constants at // this point, before we steal the mir-const result. let _ = tcx.mir_const_qualif(def_id.to_def_id()); @@ -305,17 +305,24 @@ fn mir_validated( fn mir_drops_elaborated_and_const_checked<'tcx>( tcx: TyCtxt<'tcx>, - def_id: LocalDefId, -) -> Steal> { + def: ty::WithOptParam, +) -> &'tcx Steal> { + if def.param_did.is_none() { + if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + return tcx + .mir_drops_elaborated_and_const_checked(ty::WithOptParam { param_did, ..def }); + } + } + // (Mir-)Borrowck uses `mir_validated`, so we have to force it to // execute before we can steal. - tcx.ensure().mir_borrowck(def_id); + tcx.ensure().mir_borrowck(def.did); - let (body, _) = tcx.mir_validated(def_id); + let (body, _) = tcx.mir_validated(def.did); let mut body = body.steal(); - run_post_borrowck_cleanup_passes(tcx, &mut body, def_id, None); - check_consts::post_drop_elaboration::check_live_drops(tcx, def_id, &body); + run_post_borrowck_cleanup_passes(tcx, &mut body, def.did, None); + check_consts::post_drop_elaboration::check_live_drops(tcx, def.did, &body); tcx.alloc_steal_mir(body) } @@ -458,7 +465,7 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, def: ty::WithOptParam) -> Bo return shim::build_adt_ctor(tcx, def.did.to_def_id()); } - let mut body = tcx.mir_drops_elaborated_and_const_checked(def.did).steal(); + let mut body = tcx.mir_drops_elaborated_and_const_checked(def).steal(); run_optimization_passes(tcx, &mut body, def.did, None); debug_assert!(!body.has_free_regions(), "Free regions in optimized MIR"); diff --git a/src/librustc_mir_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index e69f6b30abd5c..07d0f6ab8dd93 100644 --- a/src/librustc_mir_build/build/mod.rs +++ b/src/librustc_mir_build/build/mod.rs @@ -21,7 +21,7 @@ use rustc_target::spec::PanicStrategy; use super::lints; -crate fn mir_built(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::steal::Steal> { +crate fn mir_built<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx ty::steal::Steal> { tcx.alloc_steal_mir(mir_build(tcx, def_id)) } diff --git a/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr b/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr index 1b4326ea56aaa..846e2979f8439 100644 --- a/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr +++ b/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr @@ -30,6 +30,11 @@ note: ...which requires const-evaluating `::BAR`... + --> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5 + | +LL | const BAR: u32 = IMPL_REF_BAR; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires optimizing MIR for `::BAR`... --> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5 | diff --git a/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr b/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr index 8efa56a9a2e63..305d20c05c9a8 100644 --- a/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr +++ b/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr @@ -30,6 +30,11 @@ note: ...which requires const-evaluating `FooDefault::BAR`... | LL | const BAR: u32 = DEFAULT_REF_BAR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires optimizing MIR for the potential const argument `FooDefault::BAR`... + --> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5 + | +LL | const BAR: u32 = DEFAULT_REF_BAR; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires optimizing MIR for `FooDefault::BAR`... --> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5 | diff --git a/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr b/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr index 78ce1a28a3fdc..7a4912aaa73ab 100644 --- a/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr +++ b/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr @@ -30,6 +30,11 @@ note: ...which requires const-evaluating `::BAR`... + --> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5 + | +LL | const BAR: u32 = TRAIT_REF_BAR; + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires optimizing MIR for `::BAR`... --> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5 | From 48bbf49765a2f2dd30d18242145a5e3084b42f94 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Mon, 6 Jul 2020 23:49:53 +0200 Subject: [PATCH 10/25] const generics work! --- .../rmeta/decoder/cstore_impl.rs | 2 +- src/librustc_middle/arena.rs | 10 ++ src/librustc_middle/query/mod.rs | 49 +++++-- src/librustc_middle/ty/mod.rs | 8 ++ src/librustc_middle/ty/relate.rs | 8 +- src/librustc_mir/borrow_check/mod.rs | 60 +++++---- src/librustc_mir/borrow_check/nll.rs | 10 +- .../borrow_check/universal_regions.rs | 49 +++---- src/librustc_mir/const_eval/eval_queries.rs | 2 +- src/librustc_mir/interpret/eval_context.rs | 6 +- .../transform/check_consts/qualifs.rs | 7 +- src/librustc_mir/transform/check_unsafety.rs | 45 +++++-- src/librustc_mir/transform/mod.rs | 120 +++++++++++++----- src/librustc_mir/transform/promote_consts.rs | 17 ++- src/librustc_mir_build/build/mod.rs | 20 ++- src/librustc_mir_build/hair/cx/expr.rs | 8 +- src/librustc_mir_build/hair/cx/mod.rs | 21 +-- 17 files changed, 301 insertions(+), 141 deletions(-) diff --git a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs index c46229b77a5b0..be153758a2a0c 100644 --- a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs +++ b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs @@ -112,7 +112,7 @@ provide! { <'tcx> tcx, def_id, other, cdata, }) } optimized_mir => { tcx.arena.alloc(cdata.get_optimized_mir(tcx, def_id.index)) } - promoted_mir => { cdata.get_promoted_mir(tcx, def_id.index) } + promoted_mir => { tcx.arena.alloc(cdata.get_promoted_mir(tcx, def_id.index)) } mir_const_qualif => { cdata.mir_const_qualif(def_id.index) } fn_sig => { cdata.fn_sig(def_id.index, tcx) } inherent_impls => { cdata.get_inherent_implementations_for_type(tcx, def_id.index) } diff --git a/src/librustc_middle/arena.rs b/src/librustc_middle/arena.rs index caf771803c0f4..b77aca4d6348d 100644 --- a/src/librustc_middle/arena.rs +++ b/src/librustc_middle/arena.rs @@ -31,10 +31,20 @@ macro_rules! arena_types { rustc_middle::mir::Body<$tcx> > >; + [] promoted: + rustc_index::vec::IndexVec< + rustc_middle::mir::Promoted, + rustc_middle::mir::Body<$tcx> + >, + rustc_index::vec::IndexVec< + rustc_middle::mir::Promoted, + rustc_middle::mir::Body<'_x> + >; [decode] tables: rustc_middle::ty::TypeckTables<$tcx>, rustc_middle::ty::TypeckTables<'_x>; [decode] borrowck_result: rustc_middle::mir::BorrowCheckResult<$tcx>, rustc_middle::mir::BorrowCheckResult<'_x>; + [] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult, rustc_middle::mir::UnsafetyCheckResult; [] const_allocs: rustc_middle::mir::interpret::Allocation, rustc_middle::mir::interpret::Allocation; // Required for the incremental on-disk cache [few, decode] mir_keys: rustc_hir::def_id::DefIdSet, rustc_hir::def_id::DefIdSet; diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index bad2dc648594e..f1deb6388af59 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -208,19 +208,27 @@ rustc_queries! { desc { |tcx| "const checking `{}`", tcx.def_path_str(key) } cache_on_disk_if { key.is_local() } } + query mir_const_qualif_const_arg( + key: ty::WithOptParam + ) -> mir::ConstQualifs { + desc { + |tcx| "const checking the potential const argument `{}`", + tcx.def_path_str(key.did.to_def_id()) + } + } /// Fetch the MIR for a given `DefId` right after it's built - this includes /// unreachable code. - query mir_built(key: LocalDefId) -> &'tcx Steal> { - desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.to_def_id()) } + query mir_built(key: ty::WithOptParam) -> &'tcx Steal> { + desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) } } /// Fetch the MIR for a given `DefId` up till the point where it is /// ready for const qualification. /// /// See the README for the `mir` module for details. - query mir_const(key: DefId) -> &'tcx Steal> { - desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key) } + query mir_const(key: ty::WithOptParam) -> &'tcx Steal> { + desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) } no_hash } @@ -231,13 +239,16 @@ rustc_queries! { desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) } } - query mir_validated(key: LocalDefId) -> + query mir_validated(key: ty::WithOptParam) -> ( &'tcx Steal>, &'tcx Steal>> ) { no_hash - desc { |tcx| "processing `{}`", tcx.def_path_str(key.to_def_id()) } + desc { + |tcx| "processing the potential const argument `{}`", + tcx.def_path_str(key.did.to_def_id()) + } } /// MIR after our optimization passes have run. This is MIR that is ready @@ -261,11 +272,18 @@ rustc_queries! { cache_on_disk_if { key.is_local() } } - query promoted_mir(key: DefId) -> IndexVec> { + query promoted_mir(key: DefId) -> &'tcx IndexVec> { desc { |tcx| "optimizing promoted MIR for `{}`", tcx.def_path_str(key) } - storage(ArenaCacheSelector<'tcx>) cache_on_disk_if { key.is_local() } } + query promoted_mir_of_const_arg( + key: ty::WithOptParam + ) -> &'tcx IndexVec> { + desc { + |tcx| "optimizing promoted MIR for the potential const argument `{}`", + tcx.def_path_str(key.did.to_def_id()), + } + } } TypeChecking { @@ -473,11 +491,13 @@ rustc_queries! { } TypeChecking { - /// The result of unsafety-checking this `DefId`. - query unsafety_check_result(key: LocalDefId) -> mir::UnsafetyCheckResult { + /// The result of unsafety-checking this `LocalDefId`. + query unsafety_check_result(key: LocalDefId) -> &'tcx mir::UnsafetyCheckResult { desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if { true } - storage(ArenaCacheSelector<'tcx>) + } + query unsafety_check_result_const_arg(key: ty::WithOptParam) -> &'tcx mir::UnsafetyCheckResult { + desc { |tcx| "unsafety-checking the potential const arg `{}`", tcx.def_path_str(key.did.to_def_id()) } } /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error. @@ -601,13 +621,18 @@ rustc_queries! { /// Borrow-checks the function body. If this is a closure, returns /// additional requirements that the closure's creator must verify. query mir_borrowck(key: LocalDefId) -> &'tcx mir::BorrowCheckResult<'tcx> { - storage(ArenaCacheSelector<'tcx>) desc { |tcx| "borrow-checking `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if(tcx, opt_result) { tcx.is_closure(key.to_def_id()) || opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty()) } } + query mir_borrowck_const_arg(key: ty::WithOptParam) -> &'tcx mir::BorrowCheckResult<'tcx> { + desc { + |tcx| "borrow-checking the potential const argument`{}`", + tcx.def_path_str(key.did.to_def_id()) + } + } } TypeChecking { diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 2a366c9801efc..9ebf1ed60e2ff 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1600,6 +1600,10 @@ impl WithOptParam { self.did.as_local().map(|did| WithOptParam { did, param_did: self.param_did }) } + pub fn expect_local(self) -> WithOptParam { + self.as_local().unwrap() + } + pub fn is_local(self) -> bool { self.did.is_local() } @@ -1607,6 +1611,10 @@ impl WithOptParam { pub fn ty_def_id(self) -> DefId { self.param_did.unwrap_or(self.did) } + + pub fn init_me_bby(tcx: TyCtxt<'_>, did: DefId) -> WithOptParam { + WithOptParam { did, param_did: did.as_local().and_then(|did| tcx.opt_const_param_of(did)) } + } } /// When type checking, we use the `ParamEnv` to track diff --git a/src/librustc_middle/ty/relate.rs b/src/librustc_middle/ty/relate.rs index 7946a27b4d968..ae2820b460fe3 100644 --- a/src/librustc_middle/ty/relate.rs +++ b/src/librustc_middle/ty/relate.rs @@ -578,12 +578,12 @@ pub fn super_relate_consts>( // FIXME(const_generics): this is wrong, as it is a projection ( - ty::ConstKind::Unevaluated(a_def_id, a_substs, a_promoted), - ty::ConstKind::Unevaluated(b_def_id, b_substs, b_promoted), - ) if a_def_id == b_def_id && a_promoted == b_promoted => { + ty::ConstKind::Unevaluated(a_def, a_substs, a_promoted), + ty::ConstKind::Unevaluated(b_def, b_substs, b_promoted), + ) if a_def == b_def && a_promoted == b_promoted => { let substs = relation.relate_with_variance(ty::Variance::Invariant, a_substs, b_substs)?; - Ok(ty::ConstKind::Unevaluated(a_def_id, substs, a_promoted)) + Ok(ty::ConstKind::Unevaluated(a_def, substs, a_promoted)) } _ => Err(TypeError::ConstMismatch(expected_found(relation, a, b))), }; diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index e77dcb63f4667..b4ddda5c03d0c 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -17,7 +17,7 @@ use rustc_middle::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind use rustc_middle::mir::{Field, ProjectionElem, Promoted, Rvalue, Statement, StatementKind}; use rustc_middle::mir::{InlineAsmOperand, Terminator, TerminatorKind}; use rustc_middle::ty::query::Providers; -use rustc_middle::ty::{self, RegionVid, TyCtxt}; +use rustc_middle::ty::{self, InstanceDef, RegionVid, TyCtxt}; use rustc_session::lint::builtin::{MUTABLE_BORROW_RESERVATION_CONFLICT, UNUSED_MUT}; use rustc_span::{Span, Symbol, DUMMY_SP}; @@ -87,17 +87,32 @@ crate struct Upvar { const DEREF_PROJECTION: &[PlaceElem<'_>; 1] = &[ProjectionElem::Deref]; pub fn provide(providers: &mut Providers) { - *providers = Providers { mir_borrowck, ..*providers }; + *providers = Providers { + mir_borrowck: |tcx, did| mir_borrowck(tcx, ty::WithOptParam::dummy(did)), + mir_borrowck_const_arg: |tcx, def| { + if def.param_did.is_none() { tcx.mir_borrowck(def.did) } else { mir_borrowck(tcx, def) } + }, + ..*providers + }; } -fn mir_borrowck<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx BorrowCheckResult<'tcx> { - let (input_body, promoted) = tcx.mir_validated(def_id); - debug!("run query mir_borrowck: {}", tcx.def_path_str(def_id.to_def_id())); +fn mir_borrowck<'tcx>( + tcx: TyCtxt<'tcx>, + def: ty::WithOptParam, +) -> &'tcx BorrowCheckResult<'tcx> { + if def.param_did.is_none() { + if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + return tcx.mir_borrowck_const_arg(ty::WithOptParam { param_did, ..def }); + } + } + + let (input_body, promoted) = tcx.mir_validated(def); + debug!("run query mir_borrowck: {}", tcx.def_path_str(def.did.to_def_id())); let opt_closure_req = tcx.infer_ctxt().enter(|infcx| { let input_body: &Body<'_> = &input_body.borrow(); let promoted: &IndexVec<_, _> = &promoted.borrow(); - do_mir_borrowck(&infcx, input_body, promoted, def_id) + do_mir_borrowck(&infcx, input_body, promoted, def) }); debug!("mir_borrowck done"); @@ -108,13 +123,13 @@ fn do_mir_borrowck<'a, 'tcx>( infcx: &InferCtxt<'a, 'tcx>, input_body: &Body<'tcx>, input_promoted: &IndexVec>, - def_id: LocalDefId, + def: ty::WithOptParam, ) -> BorrowCheckResult<'tcx> { - debug!("do_mir_borrowck(def_id = {:?})", def_id); + debug!("do_mir_borrowck(def = {:?})", def); let tcx = infcx.tcx; - let param_env = tcx.param_env(def_id); - let id = tcx.hir().as_local_hir_id(def_id); + let param_env = tcx.param_env(def.did); + let id = tcx.hir().as_local_hir_id(def.did); let mut local_names = IndexVec::from_elem(None, &input_body.local_decls); for var_debug_info in &input_body.var_debug_info { @@ -135,13 +150,13 @@ fn do_mir_borrowck<'a, 'tcx>( } // Gather the upvars of a closure, if any. - let tables = tcx.typeck_tables_of(def_id); + let tables = tcx.typeck_tables_of_const_arg(def); if let Some(ErrorReported) = tables.tainted_by_errors { infcx.set_tainted_by_errors(); } let upvars: Vec<_> = tables .closure_captures - .get(&def_id.to_def_id()) + .get(&def.did.to_def_id()) .into_iter() .flat_map(|v| v.values()) .map(|upvar_id| { @@ -171,8 +186,7 @@ fn do_mir_borrowck<'a, 'tcx>( // will have a lifetime tied to the inference context. let mut body = input_body.clone(); let mut promoted = input_promoted.clone(); - let free_regions = - nll::replace_regions_in_mir(infcx, def_id, param_env, &mut body, &mut promoted); + let free_regions = nll::replace_regions_in_mir(infcx, def, param_env, &mut body, &mut promoted); let body = &body; // no further changes let location_table = &LocationTable::new(&body); @@ -190,7 +204,7 @@ fn do_mir_borrowck<'a, 'tcx>( let mdpe = MoveDataParamEnv { move_data, param_env }; let mut flow_inits = MaybeInitializedPlaces::new(tcx, &body, &mdpe) - .into_engine(tcx, &body, def_id.to_def_id()) + .into_engine(tcx, &body, def.did.to_def_id()) .iterate_to_fixpoint() .into_results_cursor(&body); @@ -207,7 +221,7 @@ fn do_mir_borrowck<'a, 'tcx>( nll_errors, } = nll::compute_regions( infcx, - def_id, + def.did, free_regions, body, &promoted, @@ -223,7 +237,7 @@ fn do_mir_borrowck<'a, 'tcx>( // write unit-tests, as well as helping with debugging. nll::dump_mir_results( infcx, - MirSource::item(def_id.to_def_id()), + MirSource { instance: InstanceDef::Item(def.to_global()), promoted: None }, &body, ®ioncx, &opt_closure_req, @@ -234,7 +248,7 @@ fn do_mir_borrowck<'a, 'tcx>( nll::dump_annotation( infcx, &body, - def_id.to_def_id(), + def.did.to_def_id(), ®ioncx, &opt_closure_req, &opaque_type_values, @@ -249,13 +263,13 @@ fn do_mir_borrowck<'a, 'tcx>( let regioncx = Rc::new(regioncx); let flow_borrows = Borrows::new(tcx, &body, regioncx.clone(), &borrow_set) - .into_engine(tcx, &body, def_id.to_def_id()) + .into_engine(tcx, &body, def.did.to_def_id()) .iterate_to_fixpoint(); let flow_uninits = MaybeUninitializedPlaces::new(tcx, &body, &mdpe) - .into_engine(tcx, &body, def_id.to_def_id()) + .into_engine(tcx, &body, def.did.to_def_id()) .iterate_to_fixpoint(); let flow_ever_inits = EverInitializedPlaces::new(tcx, &body, &mdpe) - .into_engine(tcx, &body, def_id.to_def_id()) + .into_engine(tcx, &body, def.did.to_def_id()) .iterate_to_fixpoint(); let movable_generator = match tcx.hir().get(id) { @@ -274,7 +288,7 @@ fn do_mir_borrowck<'a, 'tcx>( let mut promoted_mbcx = MirBorrowckCtxt { infcx, body: promoted_body, - mir_def_id: def_id, + mir_def_id: def.did, move_data: &move_data, location_table: &LocationTable::new(promoted_body), movable_generator, @@ -307,7 +321,7 @@ fn do_mir_borrowck<'a, 'tcx>( let mut mbcx = MirBorrowckCtxt { infcx, body, - mir_def_id: def_id, + mir_def_id: def.did, move_data: &mdpe.move_data, location_table, movable_generator, diff --git a/src/librustc_mir/borrow_check/nll.rs b/src/librustc_mir/borrow_check/nll.rs index ea68364be37a3..f1e7f4c26f4b4 100644 --- a/src/librustc_mir/borrow_check/nll.rs +++ b/src/librustc_mir/borrow_check/nll.rs @@ -9,7 +9,7 @@ use rustc_middle::mir::{ BasicBlock, Body, ClosureOutlivesSubject, ClosureRegionRequirements, LocalKind, Location, Promoted, }; -use rustc_middle::ty::{self, RegionKind, RegionVid}; +use rustc_middle::ty::{self, InstanceDef, RegionKind, RegionVid}; use rustc_span::symbol::sym; use std::env; use std::fmt::Debug; @@ -59,20 +59,20 @@ crate struct NllOutput<'tcx> { /// `compute_regions`. pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>( infcx: &InferCtxt<'cx, 'tcx>, - def_id: LocalDefId, + def: ty::WithOptParam, param_env: ty::ParamEnv<'tcx>, body: &mut Body<'tcx>, promoted: &mut IndexVec>, ) -> UniversalRegions<'tcx> { - debug!("replace_regions_in_mir(def_id={:?})", def_id); + debug!("replace_regions_in_mir(def={:?})", def); // Compute named region information. This also renumbers the inputs/outputs. - let universal_regions = UniversalRegions::new(infcx, def_id, param_env); + let universal_regions = UniversalRegions::new(infcx, def, param_env); // Replace all remaining regions with fresh inference variables. renumber::renumber_mir(infcx, body, promoted); - let source = MirSource::item(def_id.to_def_id()); + let source = MirSource { instance: InstanceDef::Item(def.to_global()), promoted: None }; mir_util::dump_mir(infcx.tcx, None, "renumber", &0, source, body, |_, _| Ok(())); universal_regions diff --git a/src/librustc_mir/borrow_check/universal_regions.rs b/src/librustc_mir/borrow_check/universal_regions.rs index 7b292ee71f99d..1e2d94a1df41e 100644 --- a/src/librustc_mir/borrow_check/universal_regions.rs +++ b/src/librustc_mir/borrow_check/universal_regions.rs @@ -227,12 +227,12 @@ impl<'tcx> UniversalRegions<'tcx> { /// known between those regions. pub fn new( infcx: &InferCtxt<'_, 'tcx>, - mir_def_id: LocalDefId, + mir_def: ty::WithOptParam, param_env: ty::ParamEnv<'tcx>, ) -> Self { let tcx = infcx.tcx; - let mir_hir_id = tcx.hir().as_local_hir_id(mir_def_id); - UniversalRegionsBuilder { infcx, mir_def_id, mir_hir_id, param_env }.build() + let mir_hir_id = tcx.hir().as_local_hir_id(mir_def.did); + UniversalRegionsBuilder { infcx, mir_def, mir_hir_id, param_env }.build() } /// Given a reference to a closure type, extracts all the values @@ -388,7 +388,7 @@ impl<'tcx> UniversalRegions<'tcx> { struct UniversalRegionsBuilder<'cx, 'tcx> { infcx: &'cx InferCtxt<'cx, 'tcx>, - mir_def_id: LocalDefId, + mir_def: ty::WithOptParam, mir_hir_id: HirId, param_env: ty::ParamEnv<'tcx>, } @@ -397,7 +397,7 @@ const FR: NLLRegionVariableOrigin = NLLRegionVariableOrigin::FreeRegion; impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { fn build(self) -> UniversalRegions<'tcx> { - debug!("build(mir_def_id={:?})", self.mir_def_id); + debug!("build(mir_def={:?})", self.mir_def); let param_env = self.param_env; debug!("build: param_env={:?}", param_env); @@ -417,7 +417,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let mut indices = self.compute_indices(fr_static, defining_ty); debug!("build: indices={:?}", indices); - let closure_base_def_id = self.infcx.tcx.closure_base_def_id(self.mir_def_id.to_def_id()); + let closure_base_def_id = self.infcx.tcx.closure_base_def_id(self.mir_def.did.to_def_id()); // If this is a closure or generator, then the late-bound regions from the enclosing // function are actually external regions to us. For example, here, 'a is not local @@ -425,8 +425,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { // fn foo<'a>() { // let c = || { let x: &'a u32 = ...; } // } - if self.mir_def_id.to_def_id() != closure_base_def_id { - self.infcx.replace_late_bound_regions_with_nll_infer_vars(self.mir_def_id, &mut indices) + if self.mir_def.did.to_def_id() != closure_base_def_id { + self.infcx + .replace_late_bound_regions_with_nll_infer_vars(self.mir_def.did, &mut indices) } let bound_inputs_and_output = self.compute_inputs_and_output(&indices, defining_ty); @@ -436,15 +437,15 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let first_local_index = self.infcx.num_region_vars(); let inputs_and_output = self.infcx.replace_bound_regions_with_nll_infer_vars( FR, - self.mir_def_id, + self.mir_def.did, &bound_inputs_and_output, &mut indices, ); // Converse of above, if this is a function then the late-bound regions declared on its // signature are local to the fn. - if self.mir_def_id.to_def_id() == closure_base_def_id { + if self.mir_def.did.to_def_id() == closure_base_def_id { self.infcx - .replace_late_bound_regions_with_nll_infer_vars(self.mir_def_id, &mut indices); + .replace_late_bound_regions_with_nll_infer_vars(self.mir_def.did, &mut indices); } let (unnormalized_output_ty, mut unnormalized_input_tys) = @@ -456,7 +457,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { if self.infcx.tcx.fn_sig(def_id).c_variadic() { let va_list_did = self.infcx.tcx.require_lang_item( lang_items::VaListTypeLangItem, - Some(self.infcx.tcx.def_span(self.mir_def_id)), + Some(self.infcx.tcx.def_span(self.mir_def.did)), ); let region = self .infcx @@ -507,14 +508,14 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { /// see `DefiningTy` for details. fn defining_ty(&self) -> DefiningTy<'tcx> { let tcx = self.infcx.tcx; - let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id.to_def_id()); + let closure_base_def_id = tcx.closure_base_def_id(self.mir_def.did.to_def_id()); match tcx.hir().body_owner_kind(self.mir_hir_id) { BodyOwnerKind::Closure | BodyOwnerKind::Fn => { - let defining_ty = if self.mir_def_id.to_def_id() == closure_base_def_id { + let defining_ty = if self.mir_def.did.to_def_id() == closure_base_def_id { tcx.type_of(closure_base_def_id) } else { - let tables = tcx.typeck_tables_of(self.mir_def_id); + let tables = tcx.typeck_tables_of(self.mir_def.did); tables.node_type(self.mir_hir_id) }; @@ -530,20 +531,20 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { } ty::FnDef(def_id, substs) => DefiningTy::FnDef(def_id, substs), _ => span_bug!( - tcx.def_span(self.mir_def_id), + tcx.def_span(self.mir_def.did), "expected defining type for `{:?}`: `{:?}`", - self.mir_def_id, + self.mir_def.did, defining_ty ), } } BodyOwnerKind::Const | BodyOwnerKind::Static(..) => { - assert_eq!(self.mir_def_id.to_def_id(), closure_base_def_id); + assert_eq!(self.mir_def.did.to_def_id(), closure_base_def_id); let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id); let substs = self.infcx.replace_free_regions_with_nll_infer_vars(FR, &identity_substs); - DefiningTy::Const(self.mir_def_id.to_def_id(), substs) + DefiningTy::Const(self.mir_def.did.to_def_id(), substs) } } } @@ -558,7 +559,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { defining_ty: DefiningTy<'tcx>, ) -> UniversalRegionIndices<'tcx> { let tcx = self.infcx.tcx; - let closure_base_def_id = tcx.closure_base_def_id(self.mir_def_id.to_def_id()); + let closure_base_def_id = tcx.closure_base_def_id(self.mir_def.did.to_def_id()); let identity_substs = InternalSubsts::identity_for_item(tcx, closure_base_def_id); let fr_substs = match defining_ty { DefiningTy::Closure(_, ref substs) | DefiningTy::Generator(_, ref substs, _) => { @@ -592,7 +593,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let tcx = self.infcx.tcx; match defining_ty { DefiningTy::Closure(def_id, substs) => { - assert_eq!(self.mir_def_id.to_def_id(), def_id); + assert_eq!(self.mir_def.did.to_def_id(), def_id); let closure_sig = substs.as_closure().sig(); let inputs_and_output = closure_sig.inputs_and_output(); let closure_ty = tcx.closure_env_ty(def_id, substs).unwrap(); @@ -616,7 +617,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { } DefiningTy::Generator(def_id, substs, movability) => { - assert_eq!(self.mir_def_id.to_def_id(), def_id); + assert_eq!(self.mir_def.did.to_def_id(), def_id); let resume_ty = substs.as_generator().resume_ty(); let output = substs.as_generator().return_ty(); let generator_ty = tcx.mk_generator(def_id, substs, movability); @@ -634,8 +635,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { DefiningTy::Const(def_id, _) => { // For a constant body, there are no inputs, and one // "output" (the type of the constant). - assert_eq!(self.mir_def_id.to_def_id(), def_id); - let ty = tcx.type_of(def_id); + assert_eq!(self.mir_def.did.to_def_id(), def_id); + let ty = tcx.type_of(self.mir_def.ty_def_id()); let ty = indices.fold_to_region_vids(tcx, &ty); ty::Binder::dummy(tcx.intern_type_list(&[ty])) } diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs index a8f0de68f22f7..c3f992877ead6 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -359,7 +359,7 @@ pub fn const_eval_raw_provider<'tcx>( // deny-by-default lint _ => { if let Some(p) = cid.promoted { - let span = tcx.promoted_mir(def.did)[p].span; + let span = tcx.promoted_mir_of_const_arg(def)[p].span; if let err_inval!(ReferencedConstant) = err.error { err.report_as_error( tcx.at(span), diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 5e1376677a0a7..bfef9c1b3535a 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -406,7 +406,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } trace!("load mir(instance={:?}, promoted={:?})", instance, promoted); if let Some(promoted) = promoted { - return Ok(&self.tcx.promoted_mir(def.did)[promoted]); + return if let Some(def) = def.as_local() { + Ok(&self.tcx.promoted_mir_of_const_arg(def)[promoted]) + } else { + Ok(&self.tcx.promoted_mir(def.did)[promoted]) + }; } match instance { ty::InstanceDef::Item(def) => { diff --git a/src/librustc_mir/transform/check_consts/qualifs.rs b/src/librustc_mir/transform/check_consts/qualifs.rs index 705eb5d73233e..a03d3fbb68ed9 100644 --- a/src/librustc_mir/transform/check_consts/qualifs.rs +++ b/src/librustc_mir/transform/check_consts/qualifs.rs @@ -248,7 +248,12 @@ where assert!(promoted.is_none()); // Don't peek inside trait associated constants. if cx.tcx.trait_of_item(def.did).is_none() { - let qualifs = cx.tcx.at(constant.span).mir_const_qualif(def.did); + let qualifs = if let Some(def) = def.as_local() { + cx.tcx.at(constant.span).mir_const_qualif_const_arg(def) + } else { + cx.tcx.at(constant.span).mir_const_qualif(def.did) + }; + if !Q::in_qualifs(&qualifs) { return false; } diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index f218dd397c0c8..6d270a9c68428 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -489,7 +489,20 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { } pub(crate) fn provide(providers: &mut Providers) { - *providers = Providers { unsafety_check_result, unsafe_derive_on_repr_packed, ..*providers }; + *providers = Providers { + unsafety_check_result: |tcx, def_id| { + unsafety_check_result(tcx, ty::WithOptParam::dummy(def_id)) + }, + unsafety_check_result_const_arg: |tcx, def| { + if def.param_did.is_none() { + tcx.unsafety_check_result(def.did) + } else { + unsafety_check_result(tcx, def) + } + }, + unsafe_derive_on_repr_packed, + ..*providers + }; } struct UnusedUnsafeVisitor<'a> { @@ -535,32 +548,42 @@ fn check_unused_unsafe( intravisit::Visitor::visit_body(&mut visitor, body); } -fn unsafety_check_result(tcx: TyCtxt<'_>, def_id: LocalDefId) -> UnsafetyCheckResult { - debug!("unsafety_violations({:?})", def_id); +fn unsafety_check_result<'tcx>( + tcx: TyCtxt<'tcx>, + def: ty::WithOptParam, +) -> &'tcx UnsafetyCheckResult { + if def.param_did.is_none() { + if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + return tcx.unsafety_check_result_const_arg(ty::WithOptParam { param_did, ..def }); + } + } + + debug!("unsafety_violations({:?})", def); // N.B., this borrow is valid because all the consumers of // `mir_built` force this. - let body = &tcx.mir_built(def_id).borrow(); + let body = &tcx.mir_built(def).borrow(); - let param_env = tcx.param_env(def_id); + let param_env = tcx.param_env(def.did); - let id = tcx.hir().as_local_hir_id(def_id); + let id = tcx.hir().as_local_hir_id(def.did); let (const_context, min_const_fn) = match tcx.hir().body_owner_kind(id) { hir::BodyOwnerKind::Closure => (false, false), hir::BodyOwnerKind::Fn => { - (tcx.is_const_fn_raw(def_id.to_def_id()), is_min_const_fn(tcx, def_id.to_def_id())) + (tcx.is_const_fn_raw(def.did.to_def_id()), is_min_const_fn(tcx, def.did.to_def_id())) } hir::BodyOwnerKind::Const | hir::BodyOwnerKind::Static(_) => (true, false), }; let mut checker = - UnsafetyChecker::new(const_context, min_const_fn, body, def_id, tcx, param_env); + UnsafetyChecker::new(const_context, min_const_fn, body, def.did, tcx, param_env); checker.visit_body(&body); - check_unused_unsafe(tcx, def_id, &checker.used_unsafe, &mut checker.inherited_blocks); - UnsafetyCheckResult { + check_unused_unsafe(tcx, def.did, &checker.used_unsafe, &mut checker.inherited_blocks); + + tcx.arena.alloc(UnsafetyCheckResult { violations: checker.violations.into(), unsafe_blocks: checker.inherited_blocks.into(), - } + }) } fn unsafe_derive_on_repr_packed(tcx: TyCtxt<'_>, def_id: LocalDefId) { diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 25973462e4c6e..8259e1288bb82 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -48,13 +48,31 @@ pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { mir_keys, mir_const, - mir_const_qualif, + mir_const_qualif: |tcx, did| { + mir_const_qualif(tcx, ty::WithOptParam::dummy(did.expect_local())) + }, + mir_const_qualif_const_arg: |tcx, def| { + if def.param_did.is_none() { + tcx.mir_const_qualif(def.did.to_def_id()) + } else { + mir_const_qualif(tcx, def) + } + }, mir_validated, mir_drops_elaborated_and_const_checked, optimized_mir, optimized_mir_of_const_arg, is_mir_available, - promoted_mir, + promoted_mir: |tcx, def_id| { + promoted_mir(tcx, ty::WithOptParam::dummy(def_id.expect_local())) + }, + promoted_mir_of_const_arg: |tcx, def| { + if def.param_did.is_none() { + tcx.promoted_mir(def.did.to_def_id()) + } else { + promoted_mir(tcx, def) + } + }, ..*providers }; instrument_coverage::provide(providers); @@ -120,6 +138,10 @@ impl<'tcx> MirSource<'tcx> { MirSource { instance: InstanceDef::Item(ty::WithOptParam::dummy(def_id)), promoted: None } } + pub fn with_opt_param(self) -> ty::WithOptParam { + self.instance.with_opt_param() + } + #[inline] pub fn def_id(&self) -> DefId { self.instance.def_id() @@ -203,9 +225,14 @@ pub fn run_passes( } } -fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs { - let def_id = def_id.expect_local(); - let const_kind = tcx.hir().body_const_context(def_id); +fn mir_const_qualif(tcx: TyCtxt<'_>, def: ty::WithOptParam) -> ConstQualifs { + if def.param_did.is_none() { + if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + return tcx.mir_const_qualif_const_arg(ty::WithOptParam { param_did, ..def }); + } + } + + let const_kind = tcx.hir().body_const_context(def.did); // No need to const-check a non-const `fn`. if const_kind.is_none() { @@ -216,15 +243,20 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs { // cannot yet be stolen), because `mir_validated()`, which steals // from `mir_const(), forces this query to execute before // performing the steal. - let body = &tcx.mir_const(def_id.to_def_id()).borrow(); + let body = &tcx.mir_const(def).borrow(); if body.return_ty().references_error() { tcx.sess.delay_span_bug(body.span, "mir_const_qualif: MIR had errors"); return Default::default(); } - let ccx = - check_consts::ConstCx { body, tcx, def_id, const_kind, param_env: tcx.param_env(def_id) }; + let ccx = check_consts::ConstCx { + body, + tcx, + def_id: def.did, + const_kind, + param_env: tcx.param_env(def.did), + }; let mut validator = check_consts::validation::Validator::new(&ccx); validator.check_body(); @@ -235,22 +267,35 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def_id: DefId) -> ConstQualifs { } /// Make MIR ready for const evaluation. This is run on all MIR, not just on consts! -fn mir_const<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Steal> { - let def_id = def_id.expect_local(); +fn mir_const<'tcx>( + tcx: TyCtxt<'tcx>, + def: ty::WithOptParam, +) -> &'tcx Steal> { + if def.param_did.is_none() { + if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + return tcx.mir_const(ty::WithOptParam { param_did, ..def }); + } + } // Unsafety check uses the raw mir, so make sure it is run. - let _ = tcx.unsafety_check_result(def_id); + let _ = tcx.unsafety_check_result_const_arg(def); - let mut body = tcx.mir_built(def_id).steal(); + let mut body = tcx.mir_built(def).steal(); - util::dump_mir(tcx, None, "mir_map", &0, MirSource::item(def_id.to_def_id()), &body, |_, _| { - Ok(()) - }); + util::dump_mir( + tcx, + None, + "mir_map", + &0, + MirSource { instance: InstanceDef::Item(def.to_global()), promoted: None }, + &body, + |_, _| Ok(()), + ); run_passes( tcx, &mut body, - InstanceDef::Item(ty::WithOptParam::dummy(def_id.to_def_id())), + InstanceDef::Item(def.to_global()), None, MirPhase::Const, &[&[ @@ -266,13 +311,19 @@ fn mir_const<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx Steal> fn mir_validated( tcx: TyCtxt<'tcx>, - def_id: LocalDefId, + def: ty::WithOptParam, ) -> (&'tcx Steal>, &'tcx Steal>>) { + if def.param_did.is_none() { + if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + return tcx.mir_validated(ty::WithOptParam { param_did, ..def }); + } + } + // Ensure that we compute the `mir_const_qualif` for constants at // this point, before we steal the mir-const result. - let _ = tcx.mir_const_qualif(def_id.to_def_id()); + let _ = tcx.mir_const_qualif_const_arg(def); - let mut body = tcx.mir_const(def_id.to_def_id()).steal(); + let mut body = tcx.mir_const(def).steal(); let mut required_consts = Vec::new(); let mut required_consts_visitor = RequiredConstsVisitor::new(&mut required_consts); @@ -285,7 +336,7 @@ fn mir_validated( run_passes( tcx, &mut body, - InstanceDef::Item(ty::WithOptParam::dummy(def_id.to_def_id())), + InstanceDef::Item(def.to_global()), None, MirPhase::Validated, &[&[ @@ -316,9 +367,9 @@ fn mir_drops_elaborated_and_const_checked<'tcx>( // (Mir-)Borrowck uses `mir_validated`, so we have to force it to // execute before we can steal. - tcx.ensure().mir_borrowck(def.did); + tcx.ensure().mir_borrowck_const_arg(def); - let (body, _) = tcx.mir_validated(def.did); + let (body, _) = tcx.mir_validated(def); let mut body = body.steal(); run_post_borrowck_cleanup_passes(tcx, &mut body, def.did, None); @@ -473,23 +524,30 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, def: ty::WithOptParam) -> Bo body } -fn promoted_mir(tcx: TyCtxt<'_>, def_id: DefId) -> IndexVec> { - if tcx.is_constructor(def_id) { - return IndexVec::new(); +fn promoted_mir<'tcx>( + tcx: TyCtxt<'tcx>, + def: ty::WithOptParam, +) -> &'tcx IndexVec> { + if def.param_did.is_none() { + if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + return tcx.promoted_mir_of_const_arg(ty::WithOptParam { param_did, ..def }); + } } - let def_id = def_id.expect_local(); + if tcx.is_constructor(def.did.to_def_id()) { + return tcx.arena.alloc(IndexVec::new()); + } - tcx.ensure().mir_borrowck(def_id); - let (_, promoted) = tcx.mir_validated(def_id); + tcx.ensure().mir_borrowck_const_arg(def); + let (_, promoted) = tcx.mir_validated(def); let mut promoted = promoted.steal(); for (p, mut body) in promoted.iter_enumerated_mut() { - run_post_borrowck_cleanup_passes(tcx, &mut body, def_id, Some(p)); - run_optimization_passes(tcx, &mut body, def_id, Some(p)); + run_post_borrowck_cleanup_passes(tcx, &mut body, def.did, Some(p)); + run_optimization_passes(tcx, &mut body, def.did, Some(p)); } debug_assert!(!promoted.has_free_regions(), "Free regions in promoted MIR"); - promoted + tcx.arena.alloc(promoted) } diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index a96ba715835f3..292ff17f4c598 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -60,16 +60,15 @@ impl<'tcx> MirPass<'tcx> for PromoteTemps<'tcx> { return; } - let def_id = src.def_id().expect_local(); + let def = src.with_opt_param().expect_local(); let mut rpo = traversal::reverse_postorder(body); - let ccx = ConstCx::new(tcx, def_id, body); + let ccx = ConstCx::new(tcx, def.did, body); let (temps, all_candidates) = collect_temps_and_candidates(&ccx, &mut rpo); let promotable_candidates = validate_candidates(&ccx, &temps, &all_candidates); - let promoted = - promote_candidates(def_id.to_def_id(), body, tcx, temps, promotable_candidates); + let promoted = promote_candidates(def.to_global(), body, tcx, temps, promotable_candidates); self.promoted_fragments.set(promoted); } } @@ -937,7 +936,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { fn promote_candidate( mut self, - def_id: DefId, + def: ty::WithOptParam, candidate: Candidate, next_promoted_id: usize, ) -> Option> { @@ -955,8 +954,8 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { literal: tcx.mk_const(ty::Const { ty, val: ty::ConstKind::Unevaluated( - ty::WithOptParam::dummy(def_id), - InternalSubsts::for_item(tcx, def_id, |param, _| { + def, + InternalSubsts::for_item(tcx, def.did, |param, _| { if let ty::GenericParamDefKind::Lifetime = param.kind { tcx.lifetimes.re_erased.into() } else { @@ -1100,7 +1099,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> { } pub fn promote_candidates<'tcx>( - def_id: DefId, + def: ty::WithOptParam, body: &mut Body<'tcx>, tcx: TyCtxt<'tcx>, mut temps: IndexVec, @@ -1157,7 +1156,7 @@ pub fn promote_candidates<'tcx>( }; //FIXME(oli-obk): having a `maybe_push()` method on `IndexVec` might be nice - if let Some(promoted) = promoter.promote_candidate(def_id, candidate, promotions.len()) { + if let Some(promoted) = promoter.promote_candidate(def, candidate, promotions.len()) { promotions.push(promoted); } } diff --git a/src/librustc_mir_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index 07d0f6ab8dd93..4aa3e87d41529 100644 --- a/src/librustc_mir_build/build/mod.rs +++ b/src/librustc_mir_build/build/mod.rs @@ -21,13 +21,19 @@ use rustc_target::spec::PanicStrategy; use super::lints; -crate fn mir_built<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx ty::steal::Steal> { - tcx.alloc_steal_mir(mir_build(tcx, def_id)) +crate fn mir_built<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptParam) -> &'tcx ty::steal::Steal> { + if def.param_did.is_none() { + if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + return tcx.mir_built(ty::WithOptParam { param_did, ..def }); + } + } + + tcx.alloc_steal_mir(mir_build(tcx, def)) } /// Construct the MIR for a given `DefId`. -fn mir_build(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Body<'_> { - let id = tcx.hir().as_local_hir_id(def_id); +fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptParam) -> Body<'_> { + let id = tcx.hir().as_local_hir_id(def.did); // Figure out what primary body this item has. let (body_id, return_ty_span) = match tcx.hir().get(id) { @@ -57,11 +63,11 @@ fn mir_build(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Body<'_> { }) => (*body_id, ty.span), Node::AnonConst(hir::AnonConst { body, hir_id, .. }) => (*body, tcx.hir().span(*hir_id)), - _ => span_bug!(tcx.hir().span(id), "can't build MIR for {:?}", def_id), + _ => span_bug!(tcx.hir().span(id), "can't build MIR for {:?}", def.did), }; tcx.infer_ctxt().enter(|infcx| { - let cx = Cx::new(&infcx, id); + let cx = Cx::new(&infcx, def, id); let body = if let Some(ErrorReported) = cx.tables().tainted_by_errors { build::construct_error(cx, body_id) } else if cx.body_owner_kind.is_fn_or_closure() { @@ -181,7 +187,7 @@ fn mir_build(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Body<'_> { build::construct_const(cx, body_id, return_ty, return_ty_span) }; - lints::check(tcx, &body, def_id); + lints::check(tcx, &body, def.did); // The borrow checker will replace all the regions here with its own // inference variables. There's no point having non-erased regions here. diff --git a/src/librustc_mir_build/hair/cx/expr.rs b/src/librustc_mir_build/hair/cx/expr.rs index 025ef1ece4603..e5f9f7328b89c 100644 --- a/src/librustc_mir_build/hair/cx/expr.rs +++ b/src/librustc_mir_build/hair/cx/expr.rs @@ -601,7 +601,7 @@ fn make_mirror_unadjusted<'a, 'tcx>( let substs = InternalSubsts::identity_for_item(cx.tcx(), did); let lhs = mk_const(cx.tcx().mk_const(ty::Const { val: ty::ConstKind::Unevaluated( - ty::WithOptParam::dummy(did), + ty::WithOptParam::init_me_bby(cx.tcx(), did), substs, None, ), @@ -800,7 +800,11 @@ fn convert_path_expr<'a, 'tcx>( debug!("convert_path_expr: (const) user_ty={:?}", user_ty); ExprKind::Literal { literal: cx.tcx.mk_const(ty::Const { - val: ty::ConstKind::Unevaluated(ty::WithOptParam::dummy(def_id), substs, None), + val: ty::ConstKind::Unevaluated( + ty::WithOptParam::init_me_bby(cx.tcx, def_id), + substs, + None, + ), ty: cx.tables().node_type(expr.hir_id), }), user_ty, diff --git a/src/librustc_mir_build/hair/cx/mod.rs b/src/librustc_mir_build/hair/cx/mod.rs index d8b3ac79e6b9c..5505559fc8e55 100644 --- a/src/librustc_mir_build/hair/cx/mod.rs +++ b/src/librustc_mir_build/hair/cx/mod.rs @@ -1,4 +1,4 @@ -//! This module contains the fcuntaiontliy to convert from the wacky tcx data +//! This module contains the functionality to convert from the wacky tcx data //! structures into the HAIR. The `builder` is generally ignorant of the tcx, //! etc., and instead goes through the `Cx` for most of its work. @@ -8,7 +8,7 @@ use crate::hair::*; use rustc_ast::ast; use rustc_ast::attr; use rustc_hir as hir; -use rustc_hir::def_id::DefId; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::Node; use rustc_index::vec::Idx; use rustc_infer::infer::InferCtxt; @@ -50,10 +50,13 @@ crate struct Cx<'a, 'tcx> { } impl<'a, 'tcx> Cx<'a, 'tcx> { - crate fn new(infcx: &'a InferCtxt<'a, 'tcx>, src_id: hir::HirId) -> Cx<'a, 'tcx> { + crate fn new( + infcx: &'a InferCtxt<'a, 'tcx>, + def: ty::WithOptParam, + src_id: hir::HirId, + ) -> Cx<'a, 'tcx> { let tcx = infcx.tcx; - let src_def_id = tcx.hir().local_def_id(src_id); - let tables = tcx.typeck_tables_of(src_def_id); + let tables = tcx.typeck_tables_of_const_arg(def); let body_owner_kind = tcx.hir().body_owner_kind(src_id); let constness = match body_owner_kind { @@ -78,12 +81,12 @@ impl<'a, 'tcx> Cx<'a, 'tcx> { tcx, infcx, root_lint_level: src_id, - param_env: tcx.param_env(src_def_id), - identity_substs: InternalSubsts::identity_for_item(tcx, src_def_id.to_def_id()), - region_scope_tree: tcx.region_scope_tree(src_def_id), + param_env: tcx.param_env(def.did), + identity_substs: InternalSubsts::identity_for_item(tcx, def.did.to_def_id()), + region_scope_tree: tcx.region_scope_tree(def.did), tables, constness, - body_owner: src_def_id.to_def_id(), + body_owner: def.did.to_def_id(), body_owner_kind, check_overflow, } From 4ef1029f5c58ec98a090925df32e298b79176def Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Tue, 7 Jul 2020 00:03:30 +0200 Subject: [PATCH 11/25] mir opt diff --- .../rustc.BAR.PromoteTemps.diff | 4 ++-- .../rustc.FOO.PromoteTemps.diff | 4 ++-- .../64bit/rustc.main.ConstProp.diff | 4 ++-- .../const_prop_fails_gracefully/rustc.main.ConstProp.diff | 4 ++-- .../rustc.hello.ConstProp.diff | 4 ++-- .../const_prop/ref_deref/rustc.main.ConstProp.diff | 4 ++-- .../const_prop/ref_deref/rustc.main.PromoteTemps.diff | 4 ++-- .../ref_deref_project/rustc.main.ConstProp.diff | 4 ++-- .../ref_deref_project/rustc.main.PromoteTemps.diff | 4 ++-- .../const_prop/slice_len/64bit/rustc.main.ConstProp.diff | 4 ++-- .../inline/inline-retag/rustc.bar.Inline.after.mir | 8 ++++---- .../mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff | 8 ++++---- .../issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff | 8 ++++---- .../rustc.full_tested_match.PromoteTemps.after.mir | 4 ++-- .../rustc.main.SimplifyCfg-elaborate-drops.after.mir | 4 ++-- 15 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/test/mir-opt/const-promotion-extern-static/rustc.BAR.PromoteTemps.diff b/src/test/mir-opt/const-promotion-extern-static/rustc.BAR.PromoteTemps.diff index 5c192979a8696..a39ad96739205 100644 --- a/src/test/mir-opt/const-promotion-extern-static/rustc.BAR.PromoteTemps.diff +++ b/src/test/mir-opt/const-promotion-extern-static/rustc.BAR.PromoteTemps.diff @@ -22,7 +22,7 @@ - // + ty: &i32 - // + val: Value(Scalar(alloc0)) + // + ty: &[&i32; 1] -+ // + val: Unevaluated(DefId(0:6 ~ const_promotion_extern_static[317d]::BAR[0]), [], Some(promoted[0])) ++ // + val: Unevaluated(WithOptParam { did: DefId(0:6 ~ const_promotion_extern_static[317d]::BAR[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant - // + span: $DIR/const-promotion-extern-static.rs:9:33: 9:34 - // + literal: Const { ty: &i32, val: Value(Scalar(alloc0)) } @@ -30,7 +30,7 @@ - _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35 - _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35 + // + span: $DIR/const-promotion-extern-static.rs:9:31: 9:35 -+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(DefId(0:6 ~ const_promotion_extern_static[317d]::BAR[0]), [], Some(promoted[0])) } ++ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(WithOptParam { did: DefId(0:6 ~ const_promotion_extern_static[317d]::BAR[0]), param_did: None }, [], Some(promoted[0])) } + _2 = &(*_6); // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35 _1 = move _2 as &[&i32] (Pointer(Unsize)); // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35 _0 = const core::slice::::as_ptr(move _1) -> [return: bb2, unwind: bb1]; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:44 diff --git a/src/test/mir-opt/const-promotion-extern-static/rustc.FOO.PromoteTemps.diff b/src/test/mir-opt/const-promotion-extern-static/rustc.FOO.PromoteTemps.diff index 649cea6493e45..e9ca064129947 100644 --- a/src/test/mir-opt/const-promotion-extern-static/rustc.FOO.PromoteTemps.diff +++ b/src/test/mir-opt/const-promotion-extern-static/rustc.FOO.PromoteTemps.diff @@ -24,7 +24,7 @@ - // + ty: &i32 - // + val: Value(Scalar(alloc2)) + // + ty: &[&i32; 1] -+ // + val: Unevaluated(DefId(0:7 ~ const_promotion_extern_static[317d]::FOO[0]), [], Some(promoted[0])) ++ // + val: Unevaluated(WithOptParam { did: DefId(0:7 ~ const_promotion_extern_static[317d]::FOO[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant - // + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43 - // + literal: Const { ty: &i32, val: Value(Scalar(alloc2)) } @@ -32,7 +32,7 @@ - _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46 - _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46 + // + span: $DIR/const-promotion-extern-static.rs:13:31: 13:46 -+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(DefId(0:7 ~ const_promotion_extern_static[317d]::FOO[0]), [], Some(promoted[0])) } ++ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(WithOptParam { did: DefId(0:7 ~ const_promotion_extern_static[317d]::FOO[0]), param_did: None }, [], Some(promoted[0])) } + _2 = &(*_6); // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46 _1 = move _2 as &[&i32] (Pointer(Unsize)); // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46 _0 = const core::slice::::as_ptr(move _1) -> [return: bb2, unwind: bb1]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:55 diff --git a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff index 3626814fa9770..c7683305da000 100644 --- a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff @@ -28,10 +28,10 @@ _9 = const main::promoted[0]; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 // ty::Const // + ty: &[i32; 3] - // + val: Unevaluated(DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 - // + literal: Const { ty: &[i32; 3], val: Unevaluated(DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &[i32; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } _3 = _9; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 _2 = &raw const (*_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 _1 = move _2 as *const [i32] (Pointer(Unsize)); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 diff --git a/src/test/mir-opt/const_prop/const_prop_fails_gracefully/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/const_prop_fails_gracefully/rustc.main.ConstProp.diff index 6c5fe7454b4ed..b09bbead4105d 100644 --- a/src/test/mir-opt/const_prop/const_prop_fails_gracefully/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/const_prop_fails_gracefully/rustc.main.ConstProp.diff @@ -19,10 +19,10 @@ _3 = const main::FOO; // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 // ty::Const // + ty: &i32 - // + val: Unevaluated(DefId(0:5 ~ const_prop_fails_gracefully[317d]::main[0]::FOO[0]), [], None) + // + val: Unevaluated(WithOptParam { did: DefId(0:5 ~ const_prop_fails_gracefully[317d]::main[0]::FOO[0]), param_did: None }, [], None) // mir::Constant // + span: $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 - // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:5 ~ const_prop_fails_gracefully[317d]::main[0]::FOO[0]), [], None) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:5 ~ const_prop_fails_gracefully[317d]::main[0]::FOO[0]), param_did: None }, [], None) } _2 = &raw const (*_3); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 _1 = move _2 as usize (Misc); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:39 StorageDead(_2); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:38: 7:39 diff --git a/src/test/mir-opt/const_prop/control-flow-simplification/rustc.hello.ConstProp.diff b/src/test/mir-opt/const_prop/control-flow-simplification/rustc.hello.ConstProp.diff index b4d1f087391f3..d8be755632feb 100644 --- a/src/test/mir-opt/const_prop/control-flow-simplification/rustc.hello.ConstProp.diff +++ b/src/test/mir-opt/const_prop/control-flow-simplification/rustc.hello.ConstProp.diff @@ -12,11 +12,11 @@ + _1 = const false; // scope 0 at $DIR/control-flow-simplification.rs:12:8: 12:21 // ty::Const // + ty: bool -- // + val: Unevaluated(DefId(0:4 ~ control_flow_simplification[317d]::NeedsDrop[0]::NEEDS[0]), [bool], None) +- // + val: Unevaluated(WithOptParam { did: DefId(0:4 ~ control_flow_simplification[317d]::NeedsDrop[0]::NEEDS[0]), param_did: None }, [bool], None) + // + val: Value(Scalar(0x00)) // mir::Constant // + span: $DIR/control-flow-simplification.rs:12:8: 12:21 -- // + literal: Const { ty: bool, val: Unevaluated(DefId(0:4 ~ control_flow_simplification[317d]::NeedsDrop[0]::NEEDS[0]), [bool], None) } +- // + literal: Const { ty: bool, val: Unevaluated(WithOptParam { did: DefId(0:4 ~ control_flow_simplification[317d]::NeedsDrop[0]::NEEDS[0]), param_did: None }, [bool], None) } - switchInt(_1) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/control-flow-simplification.rs:12:5: 14:6 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } + switchInt(const false) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/control-flow-simplification.rs:12:5: 14:6 diff --git a/src/test/mir-opt/const_prop/ref_deref/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/ref_deref/rustc.main.ConstProp.diff index 12e3a04d89bf2..0182cb83a967f 100644 --- a/src/test/mir-opt/const_prop/ref_deref/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/ref_deref/rustc.main.ConstProp.diff @@ -14,10 +14,10 @@ _4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 // ty::Const // + ty: &i32 - // + val: Unevaluated(DefId(0:3 ~ ref_deref[317d]::main[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/ref_deref.rs:5:6: 5:10 - // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:3 ~ ref_deref[317d]::main[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } _2 = _4; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 - _1 = (*_2); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 + _1 = const 4_i32; // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 diff --git a/src/test/mir-opt/const_prop/ref_deref/rustc.main.PromoteTemps.diff b/src/test/mir-opt/const_prop/ref_deref/rustc.main.PromoteTemps.diff index d56f07e0f57f5..da915585f82c1 100644 --- a/src/test/mir-opt/const_prop/ref_deref/rustc.main.PromoteTemps.diff +++ b/src/test/mir-opt/const_prop/ref_deref/rustc.main.PromoteTemps.diff @@ -18,13 +18,13 @@ - // + ty: i32 - // + val: Value(Scalar(0x00000004)) + // + ty: &i32 -+ // + val: Unevaluated(DefId(0:3 ~ ref_deref[317d]::main[0]), [], Some(promoted[0])) ++ // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant - // + span: $DIR/ref_deref.rs:5:8: 5:9 - // + literal: Const { ty: i32, val: Value(Scalar(0x00000004)) } - _2 = &_3; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 + // + span: $DIR/ref_deref.rs:5:6: 5:10 -+ // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:3 ~ ref_deref[317d]::main[0]), [], Some(promoted[0])) } ++ // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + _2 = &(*_4); // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 _1 = (*_2); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 - StorageDead(_3); // scope 0 at $DIR/ref_deref.rs:5:10: 5:11 diff --git a/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.ConstProp.diff index dd2f5bd906428..7ce4635eeb588 100644 --- a/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.ConstProp.diff @@ -14,10 +14,10 @@ _4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17 // ty::Const // + ty: &(i32, i32) - // + val: Unevaluated(DefId(0:3 ~ ref_deref_project[317d]::main[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref_project[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/ref_deref_project.rs:5:6: 5:17 - // + literal: Const { ty: &(i32, i32), val: Unevaluated(DefId(0:3 ~ ref_deref_project[317d]::main[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &(i32, i32), val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref_project[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } _2 = &((*_4).1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17 _1 = (*_2); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17 StorageDead(_2); // scope 0 at $DIR/ref_deref_project.rs:5:17: 5:18 diff --git a/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.PromoteTemps.diff b/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.PromoteTemps.diff index 0b9c1caa6bdae..535da0655d5fb 100644 --- a/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.PromoteTemps.diff +++ b/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.PromoteTemps.diff @@ -18,7 +18,7 @@ - // + ty: i32 - // + val: Value(Scalar(0x00000004)) + // + ty: &(i32, i32) -+ // + val: Unevaluated(DefId(0:3 ~ ref_deref_project[317d]::main[0]), [], Some(promoted[0])) ++ // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref_project[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant - // + span: $DIR/ref_deref_project.rs:5:9: 5:10 - // + literal: Const { ty: i32, val: Value(Scalar(0x00000004)) } @@ -30,7 +30,7 @@ - // + literal: Const { ty: i32, val: Value(Scalar(0x00000005)) } - _2 = &(_3.1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17 + // + span: $DIR/ref_deref_project.rs:5:6: 5:17 -+ // + literal: Const { ty: &(i32, i32), val: Unevaluated(DefId(0:3 ~ ref_deref_project[317d]::main[0]), [], Some(promoted[0])) } ++ // + literal: Const { ty: &(i32, i32), val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref_project[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + _2 = &((*_4).1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17 _1 = (*_2); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17 - StorageDead(_3); // scope 0 at $DIR/ref_deref_project.rs:5:17: 5:18 diff --git a/src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff index 885f28124c4b7..676e54598a261 100644 --- a/src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff @@ -21,10 +21,10 @@ _9 = const main::promoted[0]; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 // ty::Const // + ty: &[u32; 3] - // + val: Unevaluated(DefId(0:3 ~ slice_len[317d]::main[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ slice_len[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/slice_len.rs:5:6: 5:19 - // + literal: Const { ty: &[u32; 3], val: Unevaluated(DefId(0:3 ~ slice_len[317d]::main[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &[u32; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ slice_len[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } _4 = _9; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 _3 = _4; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 _2 = move _3 as &[u32] (Pointer(Unsize)); // scope 0 at $DIR/slice_len.rs:5:6: 5:19 diff --git a/src/test/mir-opt/inline/inline-retag/rustc.bar.Inline.after.mir b/src/test/mir-opt/inline/inline-retag/rustc.bar.Inline.after.mir index e83cc92eb43ef..2149200cefb9c 100644 --- a/src/test/mir-opt/inline/inline-retag/rustc.bar.Inline.after.mir +++ b/src/test/mir-opt/inline/inline-retag/rustc.bar.Inline.after.mir @@ -38,10 +38,10 @@ fn bar() -> bool { _10 = const bar::promoted[1]; // scope 1 at $DIR/inline-retag.rs:12:7: 12:9 // ty::Const // + ty: &i32 - // + val: Unevaluated(DefId(0:4 ~ inline_retag[317d]::bar[0]), [], Some(promoted[1])) + // + val: Unevaluated(WithOptParam { did: DefId(0:4 ~ inline_retag[317d]::bar[0]), param_did: None }, [], Some(promoted[1])) // mir::Constant // + span: $DIR/inline-retag.rs:12:7: 12:9 - // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:4 ~ inline_retag[317d]::bar[0]), [], Some(promoted[1])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:4 ~ inline_retag[317d]::bar[0]), param_did: None }, [], Some(promoted[1])) } Retag(_10); // scope 1 at $DIR/inline-retag.rs:12:7: 12:9 _4 = &(*_10); // scope 1 at $DIR/inline-retag.rs:12:7: 12:9 Retag(_4); // scope 1 at $DIR/inline-retag.rs:12:7: 12:9 @@ -52,10 +52,10 @@ fn bar() -> bool { _9 = const bar::promoted[0]; // scope 1 at $DIR/inline-retag.rs:12:11: 12:14 // ty::Const // + ty: &i32 - // + val: Unevaluated(DefId(0:4 ~ inline_retag[317d]::bar[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:4 ~ inline_retag[317d]::bar[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/inline-retag.rs:12:11: 12:14 - // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:4 ~ inline_retag[317d]::bar[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:4 ~ inline_retag[317d]::bar[0]), param_did: None }, [], Some(promoted[0])) } Retag(_9); // scope 1 at $DIR/inline-retag.rs:12:11: 12:14 _7 = &(*_9); // scope 1 at $DIR/inline-retag.rs:12:11: 12:14 Retag(_7); // scope 1 at $DIR/inline-retag.rs:12:11: 12:14 diff --git a/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff b/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff index 59c00e1b96f96..ebbfd5eaedb3e 100644 --- a/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff +++ b/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff @@ -96,10 +96,10 @@ (_5.1: &i32) = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &i32 - // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) } StorageDead(_6); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_7); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL _7 = (_5.0: &i32); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL @@ -140,10 +140,10 @@ _15 = const main::promoted[0] as &[&str] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &[&str; 3] - // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &[&str; 3], val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &[&str; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } StorageLive(_18); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL StorageLive(_19); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL StorageLive(_20); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff b/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff index aa606ed22b6d0..2ebf849c9bf29 100644 --- a/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff @@ -153,10 +153,10 @@ _51 = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &i32 - // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) } _11 = _51; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_9.0: &i32) = move _10; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_9.1: &i32) = move _11; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL @@ -220,10 +220,10 @@ _50 = const main::promoted[0]; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &[&str; 3] - // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &[&str; 3], val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &[&str; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } _25 = _50; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL _24 = _25; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL _23 = move _24 as &[&str] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir b/src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir index 5ff4150d2ac1a..f1f7cb58aadcf 100644 --- a/src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir +++ b/src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir @@ -76,10 +76,10 @@ fn full_tested_match() -> () { _11 = const full_tested_match::promoted[0]; // scope 0 at $DIR/match_false_edges.rs:16:14: 16:15 // ty::Const // + ty: &std::option::Option - // + val: Unevaluated(DefId(0:5 ~ match_false_edges[317d]::full_tested_match[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:5 ~ match_false_edges[317d]::full_tested_match[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/match_false_edges.rs:16:14: 16:15 - // + literal: Const { ty: &std::option::Option, val: Unevaluated(DefId(0:5 ~ match_false_edges[317d]::full_tested_match[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &std::option::Option, val: Unevaluated(WithOptParam { did: DefId(0:5 ~ match_false_edges[317d]::full_tested_match[0]), param_did: None }, [], Some(promoted[0])) } _6 = &(((*_11) as Some).0: i32); // scope 0 at $DIR/match_false_edges.rs:16:14: 16:15 _4 = &shallow _2; // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 StorageLive(_7); // scope 0 at $DIR/match_false_edges.rs:16:20: 16:27 diff --git a/src/test/mir-opt/retag/rustc.main.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/retag/rustc.main.SimplifyCfg-elaborate-drops.after.mir index 14a7f2d500542..a03cabee63267 100644 --- a/src/test/mir-opt/retag/rustc.main.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/retag/rustc.main.SimplifyCfg-elaborate-drops.after.mir @@ -184,10 +184,10 @@ fn main() -> () { _27 = const main::promoted[0]; // scope 7 at $DIR/retag.rs:47:21: 47:23 // ty::Const // + ty: &i32 - // + val: Unevaluated(DefId(0:13 ~ retag[317d]::main[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:13 ~ retag[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/retag.rs:47:21: 47:23 - // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:13 ~ retag[317d]::main[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:13 ~ retag[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } Retag(_27); // scope 7 at $DIR/retag.rs:47:21: 47:23 _23 = &(*_27); // scope 7 at $DIR/retag.rs:47:21: 47:23 Retag(_23); // scope 7 at $DIR/retag.rs:47:21: 47:23 From 050acc02135e4bf2b1d233d3a593f8f846611840 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Tue, 7 Jul 2020 00:03:36 +0200 Subject: [PATCH 12/25] ui test diff --- src/test/ui/impl-trait/auto-trait-leak.stderr | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/test/ui/impl-trait/auto-trait-leak.stderr b/src/test/ui/impl-trait/auto-trait-leak.stderr index 679b26efe5933..a543a31f7dded 100644 --- a/src/test/ui/impl-trait/auto-trait-leak.stderr +++ b/src/test/ui/impl-trait/auto-trait-leak.stderr @@ -9,7 +9,7 @@ note: ...which requires borrow-checking `cycle1`... | LL | fn cycle1() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires processing `cycle1`... +note: ...which requires processing the potential const argument `cycle1`... --> $DIR/auto-trait-leak.rs:12:1 | LL | fn cycle1() -> impl Clone { @@ -19,6 +19,11 @@ note: ...which requires processing MIR for `cycle1`... | LL | fn cycle1() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires unsafety-checking the potential const arg `cycle1`... + --> $DIR/auto-trait-leak.rs:12:1 + | +LL | fn cycle1() -> impl Clone { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires unsafety-checking `cycle1`... --> $DIR/auto-trait-leak.rs:12:1 | @@ -29,6 +34,11 @@ note: ...which requires building MIR for `cycle1`... | LL | fn cycle1() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires type-checking the potential const argument `cycle1`... + --> $DIR/auto-trait-leak.rs:12:1 + | +LL | fn cycle1() -> impl Clone { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires type-checking `cycle1`... --> $DIR/auto-trait-leak.rs:12:1 | @@ -45,7 +55,7 @@ note: ...which requires borrow-checking `cycle2`... | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires processing `cycle2`... +note: ...which requires processing the potential const argument `cycle2`... --> $DIR/auto-trait-leak.rs:20:1 | LL | fn cycle2() -> impl Clone { @@ -55,6 +65,11 @@ note: ...which requires processing MIR for `cycle2`... | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires unsafety-checking the potential const arg `cycle2`... + --> $DIR/auto-trait-leak.rs:20:1 + | +LL | fn cycle2() -> impl Clone { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires unsafety-checking `cycle2`... --> $DIR/auto-trait-leak.rs:20:1 | @@ -65,6 +80,11 @@ note: ...which requires building MIR for `cycle2`... | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ +note: ...which requires type-checking the potential const argument `cycle2`... + --> $DIR/auto-trait-leak.rs:20:1 + | +LL | fn cycle2() -> impl Clone { + | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires type-checking `cycle2`... --> $DIR/auto-trait-leak.rs:20:1 | From aa0269257053c14b9ec6e5d6bc40938e8ef57838 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Tue, 7 Jul 2020 00:34:28 +0200 Subject: [PATCH 13/25] decode stuff --- src/librustc_middle/arena.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc_middle/arena.rs b/src/librustc_middle/arena.rs index b77aca4d6348d..c5b66c1b13be5 100644 --- a/src/librustc_middle/arena.rs +++ b/src/librustc_middle/arena.rs @@ -17,7 +17,7 @@ macro_rules! arena_types { [] steal_mir: rustc_middle::ty::steal::Steal>, rustc_middle::ty::steal::Steal>; - [] mir: rustc_middle::mir::Body<$tcx>, rustc_middle::mir::Body<$tcx>; + [decode] mir: rustc_middle::mir::Body<$tcx>, rustc_middle::mir::Body<'_x>; [] steal_promoted: rustc_middle::ty::steal::Steal< rustc_index::vec::IndexVec< @@ -31,7 +31,7 @@ macro_rules! arena_types { rustc_middle::mir::Body<$tcx> > >; - [] promoted: + [decode] promoted: rustc_index::vec::IndexVec< rustc_middle::mir::Promoted, rustc_middle::mir::Body<$tcx> @@ -44,7 +44,7 @@ macro_rules! arena_types { [decode] borrowck_result: rustc_middle::mir::BorrowCheckResult<$tcx>, rustc_middle::mir::BorrowCheckResult<'_x>; - [] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult, rustc_middle::mir::UnsafetyCheckResult; + [decode] unsafety_check_result: rustc_middle::mir::UnsafetyCheckResult, rustc_middle::mir::UnsafetyCheckResult; [] const_allocs: rustc_middle::mir::interpret::Allocation, rustc_middle::mir::interpret::Allocation; // Required for the incremental on-disk cache [few, decode] mir_keys: rustc_hir::def_id::DefIdSet, rustc_hir::def_id::DefIdSet; From d4cb820528076bdac9f860a849c29993973bcf2d Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Tue, 7 Jul 2020 00:35:06 +0200 Subject: [PATCH 14/25] mir_built is a lie --- .../persist/dirty_clean.rs | 5 +- .../incremental/hashes/call_expressions.rs | 16 +++--- .../incremental/hashes/closure_expressions.rs | 6 +- .../incremental/hashes/enum_constructors.rs | 28 +++++----- .../incremental/hashes/exported_vs_not.rs | 6 +- src/test/incremental/hashes/for_loops.rs | 16 +++--- .../incremental/hashes/function_interfaces.rs | 14 ++--- src/test/incremental/hashes/if_expressions.rs | 12 ++-- src/test/incremental/hashes/inherent_impls.rs | 20 +++---- src/test/incremental/hashes/inline_asm.rs | 12 ++-- .../incremental/hashes/let_expressions.rs | 24 ++++---- .../incremental/hashes/loop_expressions.rs | 10 ++-- .../incremental/hashes/match_expressions.rs | 26 ++++----- src/test/incremental/hashes/panic_exprs.rs | 18 +++--- .../incremental/hashes/struct_constructors.rs | 16 +++--- .../hashes/unary_and_binary_exprs.rs | 56 +++++++++---------- .../incremental/hashes/while_let_loops.rs | 12 ++-- src/test/incremental/hashes/while_loops.rs | 12 ++-- 18 files changed, 154 insertions(+), 155 deletions(-) diff --git a/src/librustc_incremental/persist/dirty_clean.rs b/src/librustc_incremental/persist/dirty_clean.rs index ddc1def6e9367..0f558f59a12c8 100644 --- a/src/librustc_incremental/persist/dirty_clean.rs +++ b/src/librustc_incremental/persist/dirty_clean.rs @@ -64,8 +64,7 @@ const BASE_IMPL: &[&str] = /// DepNodes for mir_built/Optimized, which is relevant in "executable" /// code, i.e., functions+methods -const BASE_MIR: &[&str] = - &[label_strs::optimized_mir, label_strs::promoted_mir, label_strs::mir_built]; +const BASE_MIR: &[&str] = &[label_strs::optimized_mir, label_strs::promoted_mir]; /// Struct, Enum and Union DepNodes /// @@ -376,7 +375,7 @@ impl DirtyCleanVisitor<'tcx> { let def_path_hash = self.tcx.def_path_hash(def_id); labels.iter().map(move |label| match DepNode::from_label_string(label, def_path_hash) { Ok(dep_node) => dep_node, - Err(()) => unreachable!(), + Err(()) => unreachable!("label: {}", label), }) } diff --git a/src/test/incremental/hashes/call_expressions.rs b/src/test/incremental/hashes/call_expressions.rs index 3706ab4a02075..73d5bcf21a2b0 100644 --- a/src/test/incremental/hashes/call_expressions.rs +++ b/src/test/incremental/hashes/call_expressions.rs @@ -25,7 +25,7 @@ pub fn change_callee_function() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_callee_function() { callee2(1, 2) @@ -40,7 +40,7 @@ pub fn change_argument_function() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_argument_function() { callee1(1, 3) @@ -81,7 +81,7 @@ pub fn change_callee_method() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_callee_method() { let s = Struct; @@ -98,7 +98,7 @@ pub fn change_argument_method() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_argument_method() { let s = Struct; @@ -115,7 +115,7 @@ pub fn change_ufcs_callee_method() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_ufcs_callee_method() { let s = Struct; @@ -132,7 +132,7 @@ pub fn change_argument_method_ufcs() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_argument_method_ufcs() { let s = Struct; @@ -149,7 +149,7 @@ pub fn change_to_ufcs() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] // One might think this would be expanded in the hir_owner_nodes/Mir, but it actually // results in slightly different hir_owner/Mir. @@ -171,7 +171,7 @@ pub mod change_ufcs_callee_indirectly { #[cfg(not(cfail1))] use super::Struct2 as Struct; - #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] + #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] diff --git a/src/test/incremental/hashes/closure_expressions.rs b/src/test/incremental/hashes/closure_expressions.rs index b1e9ed678c4c5..a4a3ba779c017 100644 --- a/src/test/incremental/hashes/closure_expressions.rs +++ b/src/test/incremental/hashes/closure_expressions.rs @@ -37,7 +37,7 @@ pub fn add_parameter() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir, typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_parameter() { let x = 0u32; @@ -53,7 +53,7 @@ pub fn change_parameter_pattern() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_parameter_pattern() { let _ = |(x,): (u32,)| x; @@ -101,7 +101,7 @@ pub fn change_parameter_type() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir, typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_parameter_type() { let closure = |x: u16| (x as u64) + 1; diff --git a/src/test/incremental/hashes/enum_constructors.rs b/src/test/incremental/hashes/enum_constructors.rs index 2c07cbcb2054b..398866bef79ae 100644 --- a/src/test/incremental/hashes/enum_constructors.rs +++ b/src/test/incremental/hashes/enum_constructors.rs @@ -34,7 +34,7 @@ pub fn change_field_value_struct_like() -> Enum { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_field_value_struct_like() -> Enum { Enum::Struct { @@ -96,7 +96,7 @@ pub fn change_constructor_path_struct_like() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_constructor_path_struct_like() { let _ = Enum2::Struct { @@ -119,7 +119,7 @@ pub fn change_constructor_variant_struct_like() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_constructor_variant_struct_like() { let _ = Enum2::Struct2 { @@ -139,7 +139,7 @@ pub mod change_constructor_path_indirectly_struct_like { #[rustc_clean( cfg="cfail2", - except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,mir_built,\ + except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\ typeck_tables_of" )] #[rustc_clean(cfg="cfail3")] @@ -161,7 +161,7 @@ pub mod change_constructor_variant_indirectly_struct_like { #[cfg(not(cfail1))] use super::Enum2::Struct2 as Variant; - #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")] + #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn function() -> Enum2 { Variant { @@ -180,7 +180,7 @@ pub fn change_field_value_tuple_like() -> Enum { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_field_value_tuple_like() -> Enum { Enum::Tuple(0, 1, 3) @@ -197,7 +197,7 @@ pub fn change_constructor_path_tuple_like() { #[cfg(not(cfail1))] #[rustc_clean( cfg="cfail2", - except="hir_owner_nodes,optimized_mir,mir_built,typeck_tables_of" + except="hir_owner_nodes,optimized_mir,typeck_tables_of" )] #[rustc_clean(cfg="cfail3")] pub fn change_constructor_path_tuple_like() { @@ -215,7 +215,7 @@ pub fn change_constructor_variant_tuple_like() { #[cfg(not(cfail1))] #[rustc_clean( cfg="cfail2", - except="hir_owner_nodes,optimized_mir,mir_built,typeck_tables_of" + except="hir_owner_nodes,optimized_mir,typeck_tables_of" )] #[rustc_clean(cfg="cfail3")] pub fn change_constructor_variant_tuple_like() { @@ -232,7 +232,7 @@ pub mod change_constructor_path_indirectly_tuple_like { #[rustc_clean( cfg="cfail2", - except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,mir_built,\ + except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\ typeck_tables_of" )] #[rustc_clean(cfg="cfail3")] @@ -251,7 +251,7 @@ pub mod change_constructor_variant_indirectly_tuple_like { #[cfg(not(cfail1))] use super::Enum2::Tuple2 as Variant; - #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built,typeck_tables_of")] + #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn function() -> Enum2 { Variant(0, 1, 2) @@ -278,7 +278,7 @@ pub fn change_constructor_path_c_like() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_constructor_path_c_like() { let _x = Clike2::B; @@ -293,7 +293,7 @@ pub fn change_constructor_variant_c_like() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_constructor_variant_c_like() { let _x = Clike::C; @@ -309,7 +309,7 @@ pub mod change_constructor_path_indirectly_c_like { #[rustc_clean( cfg="cfail2", - except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,mir_built,\ + except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,\ typeck_tables_of" )] #[rustc_clean(cfg="cfail3")] @@ -328,7 +328,7 @@ pub mod change_constructor_variant_indirectly_c_like { #[cfg(not(cfail1))] use super::Clike::B as Variant; - #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")] + #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn function() -> Clike { Variant diff --git a/src/test/incremental/hashes/exported_vs_not.rs b/src/test/incremental/hashes/exported_vs_not.rs index 4ea58705017ee..40b6925bc7276 100644 --- a/src/test/incremental/hashes/exported_vs_not.rs +++ b/src/test/incremental/hashes/exported_vs_not.rs @@ -16,7 +16,7 @@ pub fn body_not_exported_to_metadata() -> u32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn body_not_exported_to_metadata() -> u32 { 2 @@ -35,7 +35,7 @@ pub fn body_exported_to_metadata_because_of_inline() -> u32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] #[inline] pub fn body_exported_to_metadata_because_of_inline() -> u32 { @@ -55,7 +55,7 @@ pub fn body_exported_to_metadata_because_of_generic() -> u32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] #[inline] pub fn body_exported_to_metadata_because_of_generic() -> u32 { diff --git a/src/test/incremental/hashes/for_loops.rs b/src/test/incremental/hashes/for_loops.rs index d3d5a69c171f9..18ba48e7b4be3 100644 --- a/src/test/incremental/hashes/for_loops.rs +++ b/src/test/incremental/hashes/for_loops.rs @@ -25,7 +25,7 @@ pub fn change_loop_body() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_loop_body() { let mut _x = 0; @@ -48,7 +48,7 @@ pub fn change_iteration_variable_name() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_iteration_variable_name() { let mut _x = 0; @@ -71,7 +71,7 @@ pub fn change_iteration_variable_pattern() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir, typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_iteration_variable_pattern() { let mut _x = 0; @@ -94,7 +94,7 @@ pub fn change_iterable() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, promoted_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, promoted_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_iterable() { let mut _x = 0; @@ -116,7 +116,7 @@ pub fn add_break() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir, typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_break() { let mut _x = 0; @@ -187,7 +187,7 @@ pub fn change_break_label() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_break_label() { let mut _x = 0; @@ -237,7 +237,7 @@ pub fn change_continue_label() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_continue_label() { let mut _x = 0; @@ -262,7 +262,7 @@ pub fn change_continue_to_break() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_continue_to_break() { let mut _x = 0; diff --git a/src/test/incremental/hashes/function_interfaces.rs b/src/test/incremental/hashes/function_interfaces.rs index a6b936fcbcf89..2690b0bd6ed3d 100644 --- a/src/test/incremental/hashes/function_interfaces.rs +++ b/src/test/incremental/hashes/function_interfaces.rs @@ -22,7 +22,7 @@ pub fn add_parameter() {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck_tables_of, fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub fn add_parameter(p: i32) {} @@ -45,7 +45,7 @@ pub fn type_of_parameter(p: i32) {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck_tables_of, fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub fn type_of_parameter(p: i64) {} @@ -58,7 +58,7 @@ pub fn type_of_parameter_ref(p: &i32) {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck_tables_of, fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub fn type_of_parameter_ref(p: &mut i32) {} @@ -71,7 +71,7 @@ pub fn order_of_parameters(p1: i32, p2: i64) {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck_tables_of, fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub fn order_of_parameters(p2: i64, p1: i32) {} @@ -84,7 +84,7 @@ pub fn make_unsafe() {} #[cfg(not(cfail1))] #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck_tables_of, fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub unsafe fn make_unsafe() {} @@ -274,7 +274,7 @@ pub mod change_return_type_indirectly { #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck_tables_of, fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub fn indirect_return_type() -> ReturnType { @@ -292,7 +292,7 @@ pub mod change_parameter_type_indirectly { #[rustc_clean( cfg = "cfail2", - except = "hir_owner, hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of, fn_sig" + except = "hir_owner, hir_owner_nodes, optimized_mir, typeck_tables_of, fn_sig" )] #[rustc_clean(cfg = "cfail3")] pub fn indirect_parameter_type(p: ParameterType) {} diff --git a/src/test/incremental/hashes/if_expressions.rs b/src/test/incremental/hashes/if_expressions.rs index 29b3f1f5b1d83..8faa91e465be1 100644 --- a/src/test/incremental/hashes/if_expressions.rs +++ b/src/test/incremental/hashes/if_expressions.rs @@ -25,7 +25,7 @@ pub fn change_condition(x: bool) -> u32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_condition(x: bool) -> u32 { if !x { @@ -46,7 +46,7 @@ pub fn change_then_branch(x: bool) -> u32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_then_branch(x: bool) -> u32 { if x { @@ -69,7 +69,7 @@ pub fn change_else_branch(x: bool) -> u32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_else_branch(x: bool) -> u32 { if x { @@ -120,7 +120,7 @@ pub fn change_condition_if_let(x: Option) -> u32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_condition_if_let(x: Option) -> u32 { if let Some(_) = x { @@ -143,7 +143,7 @@ pub fn change_then_branch_if_let(x: Option) -> u32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_then_branch_if_let(x: Option) -> u32 { if let Some(x) = x { @@ -166,7 +166,7 @@ pub fn change_else_branch_if_let(x: Option) -> u32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_else_branch_if_let(x: Option) -> u32 { if let Some(x) = x { diff --git a/src/test/incremental/hashes/inherent_impls.rs b/src/test/incremental/hashes/inherent_impls.rs index a9c8457f7f260..4244e0c238688 100644 --- a/src/test/incremental/hashes/inherent_impls.rs +++ b/src/test/incremental/hashes/inherent_impls.rs @@ -44,7 +44,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="hir_owner_nodes,optimized_mir,promoted_mir,mir_built,typeck_tables_of" + except="hir_owner_nodes,optimized_mir,promoted_mir,typeck_tables_of" )] #[rustc_clean(cfg="cfail3")] pub fn method_body() { @@ -68,7 +68,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="hir_owner_nodes,optimized_mir,promoted_mir,mir_built,typeck_tables_of" + except="hir_owner_nodes,optimized_mir,promoted_mir,typeck_tables_of" )] #[rustc_clean(cfg="cfail3")] #[inline] @@ -120,7 +120,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="hir_owner,hir_owner_nodes,fn_sig,typeck_tables_of,optimized_mir,mir_built" + except="hir_owner,hir_owner_nodes,fn_sig,typeck_tables_of,optimized_mir" )] #[rustc_clean(cfg="cfail3")] pub fn method_selfmutness(&mut self) { } @@ -160,7 +160,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="hir_owner,hir_owner_nodes,fn_sig,typeck_tables_of,optimized_mir,mir_built" + except="hir_owner,hir_owner_nodes,fn_sig,typeck_tables_of,optimized_mir" )] #[rustc_clean(cfg="cfail3")] pub fn add_method_parameter(&self, _: i32) { } @@ -178,7 +178,7 @@ impl Foo { #[rustc_clean(cfg="cfail2")] #[rustc_clean(cfg="cfail3")] impl Foo { - #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")] + #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_method_parameter_name(&self, b: i64) { } } @@ -197,7 +197,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="hir_owner,hir_owner_nodes,fn_sig,optimized_mir,mir_built,typeck_tables_of")] + except="hir_owner,hir_owner_nodes,fn_sig,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_method_return_type(&self) -> u8 { 0 } } @@ -232,7 +232,7 @@ impl Foo { #[rustc_clean(cfg="cfail2")] #[rustc_clean(cfg="cfail3")] impl Foo { - #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")] + #[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_method_parameter_order(&self, b: i64, a: i64) { } } @@ -251,7 +251,7 @@ impl Foo { impl Foo { #[rustc_clean( cfg="cfail2", - except="hir_owner,hir_owner_nodes,fn_sig,typeck_tables_of,optimized_mir,mir_built" + except="hir_owner,hir_owner_nodes,fn_sig,typeck_tables_of,optimized_mir" )] #[rustc_clean(cfg="cfail3")] pub unsafe fn make_method_unsafe(&self) { } @@ -453,7 +453,7 @@ impl Bar { impl Bar { #[rustc_clean( cfg="cfail2", - except="generics_of,fn_sig,typeck_tables_of,type_of,optimized_mir,mir_built" + except="generics_of,fn_sig,typeck_tables_of,type_of,optimized_mir" )] #[rustc_clean(cfg="cfail3")] pub fn add_type_parameter_to_impl(&self) { } @@ -471,7 +471,7 @@ impl Bar { #[rustc_clean(cfg="cfail2", except="hir_owner,hir_owner_nodes")] #[rustc_clean(cfg="cfail3")] impl Bar { - #[rustc_clean(cfg="cfail2", except="fn_sig,optimized_mir,mir_built,typeck_tables_of")] + #[rustc_clean(cfg="cfail2", except="fn_sig,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_impl_self_type(&self) { } } diff --git a/src/test/incremental/hashes/inline_asm.rs b/src/test/incremental/hashes/inline_asm.rs index 3eaffc440615f..7fd9975bc22a9 100644 --- a/src/test/incremental/hashes/inline_asm.rs +++ b/src/test/incremental/hashes/inline_asm.rs @@ -33,7 +33,7 @@ pub fn change_template(a: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub fn change_template(a: i32) -> i32 { @@ -69,7 +69,7 @@ pub fn change_output(a: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub fn change_output(a: i32) -> i32 { @@ -105,7 +105,7 @@ pub fn change_input(_a: i32, _b: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub fn change_input(_a: i32, _b: i32) -> i32 { @@ -140,7 +140,7 @@ pub fn change_input_constraint(_a: i32, _b: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub fn change_input_constraint(_a: i32, _b: i32) -> i32 { @@ -175,7 +175,7 @@ pub fn change_clobber(_a: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub fn change_clobber(_a: i32) -> i32 { @@ -210,7 +210,7 @@ pub fn change_options(_a: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub fn change_options(_a: i32) -> i32 { diff --git a/src/test/incremental/hashes/let_expressions.rs b/src/test/incremental/hashes/let_expressions.rs index 846bfc6d0e4db..b833e621a91b1 100644 --- a/src/test/incremental/hashes/let_expressions.rs +++ b/src/test/incremental/hashes/let_expressions.rs @@ -22,7 +22,7 @@ pub fn change_name() { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir")] + except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_name() { let _y = 2u64; @@ -38,7 +38,7 @@ pub fn add_type() { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,typeck_tables_of,mir_built")] + except="hir_owner_nodes,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_type() { let _x: u32 = 2u32; @@ -54,7 +54,7 @@ pub fn change_type() { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,typeck_tables_of,mir_built,optimized_mir")] + except="hir_owner_nodes,typeck_tables_of,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_type() { let _x: u8 = 2; @@ -70,7 +70,7 @@ pub fn change_mutability_of_reference_type() { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,typeck_tables_of,mir_built,optimized_mir")] + except="hir_owner_nodes,typeck_tables_of,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_mutability_of_reference_type() { let _x: &mut u64; @@ -86,7 +86,7 @@ pub fn change_mutability_of_slot() { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,typeck_tables_of,mir_built,optimized_mir")] + except="hir_owner_nodes,typeck_tables_of,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_mutability_of_slot() { let _x: u64 = 0; @@ -102,7 +102,7 @@ pub fn change_simple_binding_to_pattern() { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,typeck_tables_of,mir_built,optimized_mir")] + except="hir_owner_nodes,typeck_tables_of,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_simple_binding_to_pattern() { let (_a, _b) = (0u8, 'x'); @@ -118,7 +118,7 @@ pub fn change_name_in_pattern() { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir")] + except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_name_in_pattern() { let (_a, _c) = (1u8, 'y'); @@ -134,7 +134,7 @@ pub fn add_ref_in_pattern() { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,typeck_tables_of,mir_built,optimized_mir")] + except="hir_owner_nodes,typeck_tables_of,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn add_ref_in_pattern() { let (ref _a, _b) = (1u8, 'y'); @@ -150,7 +150,7 @@ pub fn add_amp_in_pattern() { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,typeck_tables_of,mir_built,optimized_mir")] + except="hir_owner_nodes,typeck_tables_of,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn add_amp_in_pattern() { let (&_a, _b) = (&1u8, 'y'); @@ -166,7 +166,7 @@ pub fn change_mutability_of_binding_in_pattern() { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,typeck_tables_of,mir_built,optimized_mir")] + except="hir_owner_nodes,typeck_tables_of,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_mutability_of_binding_in_pattern() { let (mut _a, _b) = (99u8, 'q'); @@ -182,7 +182,7 @@ pub fn add_initializer() { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,typeck_tables_of,mir_built,optimized_mir")] + except="hir_owner_nodes,typeck_tables_of,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn add_initializer() { let _x: i16 = 3i16; @@ -198,7 +198,7 @@ pub fn change_initializer() { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir")] + except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_initializer() { let _x = 5u16; diff --git a/src/test/incremental/hashes/loop_expressions.rs b/src/test/incremental/hashes/loop_expressions.rs index 65db89eb976cf..4196fd68cb096 100644 --- a/src/test/incremental/hashes/loop_expressions.rs +++ b/src/test/incremental/hashes/loop_expressions.rs @@ -25,7 +25,7 @@ pub fn change_loop_body() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_loop_body() { let mut _x = 0; @@ -47,7 +47,7 @@ pub fn add_break() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir, typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_break() { let mut _x = 0; @@ -118,7 +118,7 @@ pub fn change_break_label() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir, typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_break_label() { let mut _x = 0; @@ -168,7 +168,7 @@ pub fn change_continue_label() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_continue_label() { let mut _x = 0; @@ -193,7 +193,7 @@ pub fn change_continue_to_break() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir, typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_continue_to_break() { let mut _x = 0; diff --git a/src/test/incremental/hashes/match_expressions.rs b/src/test/incremental/hashes/match_expressions.rs index 033723a4c7796..1e19401479687 100644 --- a/src/test/incremental/hashes/match_expressions.rs +++ b/src/test/incremental/hashes/match_expressions.rs @@ -26,7 +26,7 @@ pub fn add_arm(x: u32) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] + except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_arm(x: u32) -> u32 { match x { @@ -51,7 +51,7 @@ pub fn change_order_of_arms(x: u32) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir")] + except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_order_of_arms(x: u32) -> u32 { match x { @@ -75,7 +75,7 @@ pub fn add_guard_clause(x: u32, y: bool) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] + except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_guard_clause(x: u32, y: bool) -> u32 { match x { @@ -99,7 +99,7 @@ pub fn change_guard_clause(x: u32, y: bool) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] + except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_guard_clause(x: u32, y: bool) -> u32 { match x { @@ -123,7 +123,7 @@ pub fn add_at_binding(x: u32) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] + except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_at_binding(x: u32) -> u32 { match x { @@ -147,7 +147,7 @@ pub fn change_name_of_at_binding(x: u32) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir")] + except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_name_of_at_binding(x: u32) -> u32 { match x { @@ -170,7 +170,7 @@ pub fn change_simple_name_to_pattern(x: u32) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] + except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_simple_name_to_pattern(x: u32) -> u32 { match (x, x & 1) { @@ -193,7 +193,7 @@ pub fn change_name_in_pattern(x: u32) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir")] + except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_name_in_pattern(x: u32) -> u32 { match (x, x & 1) { @@ -216,7 +216,7 @@ pub fn change_mutability_of_binding_in_pattern(x: u32) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] + except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_mutability_of_binding_in_pattern(x: u32) -> u32 { match (x, x & 1) { @@ -238,7 +238,7 @@ pub fn add_ref_to_binding_in_pattern(x: u32) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] + except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_ref_to_binding_in_pattern(x: u32) -> u32 { match (x, x & 1) { @@ -260,7 +260,7 @@ pub fn add_amp_to_binding_in_pattern(x: u32) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", -except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] +except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_amp_to_binding_in_pattern(x: u32) -> u32 { match (&x, x & 1) { @@ -283,7 +283,7 @@ pub fn change_rhs_of_arm(x: u32) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir")] + except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_rhs_of_arm(x: u32) -> u32 { match x { @@ -307,7 +307,7 @@ pub fn add_alternative_to_arm(x: u32) -> u32 { #[cfg(not(cfail1))] #[rustc_clean(cfg="cfail2", - except="hir_owner_nodes,mir_built,optimized_mir,typeck_tables_of")] + except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_alternative_to_arm(x: u32) -> u32 { match x { diff --git a/src/test/incremental/hashes/panic_exprs.rs b/src/test/incremental/hashes/panic_exprs.rs index 9de2aaa1bfd11..cc0bd45a4b4c1 100644 --- a/src/test/incremental/hashes/panic_exprs.rs +++ b/src/test/incremental/hashes/panic_exprs.rs @@ -18,7 +18,7 @@ // Indexing expression -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn indexing(slice: &[u8]) -> u8 { #[cfg(cfail1)] @@ -33,7 +33,7 @@ pub fn indexing(slice: &[u8]) -> u8 { // Arithmetic overflow plus -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn arithmetic_overflow_plus(val: i32) -> i32 { #[cfg(cfail1)] @@ -48,7 +48,7 @@ pub fn arithmetic_overflow_plus(val: i32) -> i32 { // Arithmetic overflow minus -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn arithmetic_overflow_minus(val: i32) -> i32 { #[cfg(cfail1)] @@ -63,7 +63,7 @@ pub fn arithmetic_overflow_minus(val: i32) -> i32 { // Arithmetic overflow mult -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn arithmetic_overflow_mult(val: i32) -> i32 { #[cfg(cfail1)] @@ -78,7 +78,7 @@ pub fn arithmetic_overflow_mult(val: i32) -> i32 { // Arithmetic overflow negation -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn arithmetic_overflow_negation(val: i32) -> i32 { #[cfg(cfail1)] @@ -93,7 +93,7 @@ pub fn arithmetic_overflow_negation(val: i32) -> i32 { // Division by zero -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn division_by_zero(val: i32) -> i32 { #[cfg(cfail1)] @@ -107,7 +107,7 @@ pub fn division_by_zero(val: i32) -> i32 { } // Division by zero -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn mod_by_zero(val: i32) -> i32 { #[cfg(cfail1)] @@ -122,7 +122,7 @@ pub fn mod_by_zero(val: i32) -> i32 { // shift left -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn shift_left(val: i32, shift: usize) -> i32 { #[cfg(cfail1)] @@ -137,7 +137,7 @@ pub fn shift_left(val: i32, shift: usize) -> i32 { // shift right -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn shift_right(val: i32, shift: usize) -> i32 { #[cfg(cfail1)] diff --git a/src/test/incremental/hashes/struct_constructors.rs b/src/test/incremental/hashes/struct_constructors.rs index 006b712923b99..9e8f5ce77bc64 100644 --- a/src/test/incremental/hashes/struct_constructors.rs +++ b/src/test/incremental/hashes/struct_constructors.rs @@ -31,7 +31,7 @@ pub fn change_field_value_regular_struct() -> RegularStruct { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_field_value_regular_struct() -> RegularStruct { RegularStruct { @@ -82,7 +82,7 @@ pub fn add_field_regular_struct() -> RegularStruct { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_field_regular_struct() -> RegularStruct { let struct1 = RegularStruct { @@ -117,7 +117,7 @@ pub fn change_field_label_regular_struct() -> RegularStruct { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_field_label_regular_struct() -> RegularStruct { let struct1 = RegularStruct { @@ -152,7 +152,7 @@ pub fn change_constructor_path_regular_struct() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_constructor_path_regular_struct() { let _ = RegularStruct2 { @@ -173,7 +173,7 @@ pub mod change_constructor_path_indirectly_regular_struct { #[rustc_clean( cfg="cfail2", - except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,mir_built,typeck_tables_of" + except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,typeck_tables_of" )] #[rustc_clean(cfg="cfail3")] pub fn function() -> Struct { @@ -196,7 +196,7 @@ pub fn change_field_value_tuple_struct() -> TupleStruct { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir,mir_built")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_field_value_tuple_struct() -> TupleStruct { TupleStruct(0, 1, 3) @@ -213,7 +213,7 @@ pub fn change_constructor_path_tuple_struct() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,mir_built,typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes,typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn change_constructor_path_tuple_struct() { let _ = TupleStruct2(0, 1, 2); @@ -230,7 +230,7 @@ pub mod change_constructor_path_indirectly_tuple_struct { #[rustc_clean( cfg="cfail2", - except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,mir_built,typeck_tables_of" + except="fn_sig,hir_owner,hir_owner_nodes,optimized_mir,typeck_tables_of" )] #[rustc_clean(cfg="cfail3")] pub fn function() -> Struct { diff --git a/src/test/incremental/hashes/unary_and_binary_exprs.rs b/src/test/incremental/hashes/unary_and_binary_exprs.rs index c8b53c27b02c8..325dd56b7410f 100644 --- a/src/test/incremental/hashes/unary_and_binary_exprs.rs +++ b/src/test/incremental/hashes/unary_and_binary_exprs.rs @@ -21,7 +21,7 @@ pub fn const_negation() -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn const_negation() -> i32 { -1 @@ -36,7 +36,7 @@ pub fn const_bitwise_not() -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn const_bitwise_not() -> i32 { !99 @@ -51,7 +51,7 @@ pub fn var_negation(x: i32, y: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn var_negation(x: i32, y: i32) -> i32 { -y @@ -66,7 +66,7 @@ pub fn var_bitwise_not(x: i32, y: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn var_bitwise_not(x: i32, y: i32) -> i32 { !y @@ -81,7 +81,7 @@ pub fn var_deref(x: &i32, y: &i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn var_deref(x: &i32, y: &i32) -> i32 { *y @@ -96,7 +96,7 @@ pub fn first_const_add() -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn first_const_add() -> i32 { 2 + 3 @@ -111,7 +111,7 @@ pub fn second_const_add() -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn second_const_add() -> i32 { 1 + 3 @@ -126,7 +126,7 @@ pub fn first_var_add(a: i32, b: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn first_var_add(a: i32, b: i32) -> i32 { b + 2 @@ -141,7 +141,7 @@ pub fn second_var_add(a: i32, b: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn second_var_add(a: i32, b: i32) -> i32 { 1 + b @@ -156,7 +156,7 @@ pub fn plus_to_minus(a: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn plus_to_minus(a: i32) -> i32 { 1 - a @@ -171,7 +171,7 @@ pub fn plus_to_mult(a: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn plus_to_mult(a: i32) -> i32 { 1 * a @@ -186,7 +186,7 @@ pub fn plus_to_div(a: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn plus_to_div(a: i32) -> i32 { 1 / a @@ -201,7 +201,7 @@ pub fn plus_to_mod(a: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn plus_to_mod(a: i32) -> i32 { 1 % a @@ -216,7 +216,7 @@ pub fn and_to_or(a: bool, b: bool) -> bool { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn and_to_or(a: bool, b: bool) -> bool { a || b @@ -231,7 +231,7 @@ pub fn bitwise_and_to_bitwise_or(a: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn bitwise_and_to_bitwise_or(a: i32) -> i32 { 1 | a @@ -246,7 +246,7 @@ pub fn bitwise_and_to_bitwise_xor(a: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn bitwise_and_to_bitwise_xor(a: i32) -> i32 { 1 ^ a @@ -261,7 +261,7 @@ pub fn bitwise_and_to_lshift(a: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn bitwise_and_to_lshift(a: i32) -> i32 { a << 1 @@ -276,7 +276,7 @@ pub fn bitwise_and_to_rshift(a: i32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn bitwise_and_to_rshift(a: i32) -> i32 { a >> 1 @@ -291,7 +291,7 @@ pub fn eq_to_uneq(a: i32) -> bool { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn eq_to_uneq(a: i32) -> bool { a != 1 @@ -306,7 +306,7 @@ pub fn eq_to_lt(a: i32) -> bool { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn eq_to_lt(a: i32) -> bool { a < 1 @@ -321,7 +321,7 @@ pub fn eq_to_gt(a: i32) -> bool { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn eq_to_gt(a: i32) -> bool { a > 1 @@ -336,7 +336,7 @@ pub fn eq_to_le(a: i32) -> bool { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn eq_to_le(a: i32) -> bool { a <= 1 @@ -351,7 +351,7 @@ pub fn eq_to_ge(a: i32) -> bool { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn eq_to_ge(a: i32) -> bool { a >= 1 @@ -368,7 +368,7 @@ pub fn type_cast(a: u8) -> u64 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built,typeck_tables_of", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir,typeck_tables_of", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn type_cast(a: u8) -> u64 { let b = a as u32; @@ -385,7 +385,7 @@ pub fn value_cast(a: u32) -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn value_cast(a: u32) -> i32 { 2 as i32 @@ -403,7 +403,7 @@ pub fn place() -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn place() -> i32 { let mut x = 10; @@ -423,7 +423,7 @@ pub fn rvalue() -> i32 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn rvalue() -> i32 { let mut x = 10; @@ -440,7 +440,7 @@ pub fn index_to_slice(s: &[u8], i: usize, j: usize) -> u8 { } #[cfg(not(cfail1))] -#[rustc_clean(except="hir_owner_nodes,optimized_mir,mir_built", cfg="cfail2")] +#[rustc_clean(except="hir_owner_nodes,optimized_mir", cfg="cfail2")] #[rustc_clean(cfg="cfail3")] pub fn index_to_slice(s: &[u8], i: usize, j: usize) -> u8 { s[j] diff --git a/src/test/incremental/hashes/while_let_loops.rs b/src/test/incremental/hashes/while_let_loops.rs index 36e0fcdbe74d1..6608ad9c41a93 100644 --- a/src/test/incremental/hashes/while_let_loops.rs +++ b/src/test/incremental/hashes/while_let_loops.rs @@ -25,7 +25,7 @@ pub fn change_loop_body() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")] #[rustc_clean(cfg="cfail3")] pub fn change_loop_body() { let mut _x = 0; @@ -48,7 +48,7 @@ pub fn change_loop_condition() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")] #[rustc_clean(cfg="cfail3")] pub fn change_loop_condition() { let mut _x = 0; @@ -70,7 +70,7 @@ pub fn add_break() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_break() { let mut _x = 0; @@ -141,7 +141,7 @@ pub fn change_break_label() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")] #[rustc_clean(cfg="cfail3")] pub fn change_break_label() { let mut _x = 0; @@ -191,7 +191,7 @@ pub fn change_continue_label() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")] #[rustc_clean(cfg="cfail3")] pub fn change_continue_label() { let mut _x = 0; @@ -216,7 +216,7 @@ pub fn change_continue_to_break() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")] #[rustc_clean(cfg="cfail3")] pub fn change_continue_to_break() { let mut _x = 0; diff --git a/src/test/incremental/hashes/while_loops.rs b/src/test/incremental/hashes/while_loops.rs index 83f09bd7be614..0ecb0d79ae67e 100644 --- a/src/test/incremental/hashes/while_loops.rs +++ b/src/test/incremental/hashes/while_loops.rs @@ -25,7 +25,7 @@ pub fn change_loop_body() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_loop_body() { let mut _x = 0; @@ -48,7 +48,7 @@ pub fn change_loop_condition() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_loop_condition() { let mut _x = 0; @@ -70,7 +70,7 @@ pub fn add_break() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir, typeck_tables_of")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir, typeck_tables_of")] #[rustc_clean(cfg="cfail3")] pub fn add_break() { let mut _x = 0; @@ -141,7 +141,7 @@ pub fn change_break_label() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_break_label() { let mut _x = 0; @@ -191,7 +191,7 @@ pub fn change_continue_label() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes")] #[rustc_clean(cfg="cfail3")] pub fn change_continue_label() { let mut _x = 0; @@ -216,7 +216,7 @@ pub fn change_continue_to_break() { } #[cfg(not(cfail1))] -#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, mir_built, optimized_mir")] +#[rustc_clean(cfg="cfail2", except="hir_owner_nodes, optimized_mir")] #[rustc_clean(cfg="cfail3")] pub fn change_continue_to_break() { let mut _x = 0; From 9df03ccf622b96f23bc185019d9be464c308f3fe Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Tue, 7 Jul 2020 10:35:20 +0200 Subject: [PATCH 15/25] mir opt cross compile --- .../32bit/rustc.main.ConstProp.diff | 4 ++-- .../const_prop/slice_len/32bit/rustc.main.ConstProp.diff | 4 ++-- .../mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff | 8 ++++---- .../issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff | 8 ++++---- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff index ee4d4c39f172c..0ad68b9f6c705 100644 --- a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff @@ -28,10 +28,10 @@ _9 = const main::promoted[0]; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 // ty::Const // + ty: &[i32; 3] - // + val: Unevaluated(DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 - // + literal: Const { ty: &[i32; 3], val: Unevaluated(DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &[i32; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } _3 = _9; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 _2 = &raw const (*_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 _1 = move _2 as *const [i32] (Pointer(Unsize)); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 diff --git a/src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff index 70c4156488223..7176428d82a43 100644 --- a/src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff @@ -21,10 +21,10 @@ _9 = const main::promoted[0]; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 // ty::Const // + ty: &[u32; 3] - // + val: Unevaluated(DefId(0:3 ~ slice_len[317d]::main[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ slice_len[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/slice_len.rs:5:6: 5:19 - // + literal: Const { ty: &[u32; 3], val: Unevaluated(DefId(0:3 ~ slice_len[317d]::main[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &[u32; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ slice_len[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } _4 = _9; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 _3 = _4; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 _2 = move _3 as &[u32] (Pointer(Unsize)); // scope 0 at $DIR/slice_len.rs:5:6: 5:19 diff --git a/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff b/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff index 59c00e1b96f96..ebbfd5eaedb3e 100644 --- a/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff +++ b/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff @@ -96,10 +96,10 @@ (_5.1: &i32) = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &i32 - // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) } StorageDead(_6); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_7); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL _7 = (_5.0: &i32); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL @@ -140,10 +140,10 @@ _15 = const main::promoted[0] as &[&str] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &[&str; 3] - // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &[&str; 3], val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &[&str; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } StorageLive(_18); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL StorageLive(_19); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL StorageLive(_20); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff b/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff index 1020fc965fe86..3d9f9b096b649 100644 --- a/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff @@ -153,10 +153,10 @@ _51 = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &i32 - // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &i32, val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[1])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) } _11 = _51; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_9.0: &i32) = move _10; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_9.1: &i32) = move _11; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL @@ -220,10 +220,10 @@ _50 = const main::promoted[0]; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &[&str; 3] - // + val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) + // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &[&str; 3], val: Unevaluated(DefId(0:3 ~ issue_73223[317d]::main[0]), [], Some(promoted[0])) } + // + literal: Const { ty: &[&str; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } _25 = _50; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL _24 = _25; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL _23 = move _24 as &[&str] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL From 29b5844c2d7225936545ead6c25e13fc1e822b63 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Tue, 7 Jul 2020 10:40:36 +0200 Subject: [PATCH 16/25] only call `typeck_tables_of_const_arg` for const args --- src/librustc_middle/query/mod.rs | 4 ++-- src/librustc_middle/ty/context.rs | 11 +++++++++++ src/librustc_typeck/check/mod.rs | 4 ++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index f1deb6388af59..56cd93a509a35 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -579,11 +579,11 @@ rustc_queries! { desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if { true } } - query typeck_tables_of_const_arg( + query _typeck_tables_of_const_arg( key: ty::WithOptParam ) -> &'tcx ty::TypeckTables<'tcx> { desc { - |tcx| "type-checking the potential const argument `{}`", + |tcx| "type-checking the const argument `{}`", tcx.def_path_str(key.did.to_def_id()), } } diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index d2bad6e90dda2..f79297aeac697 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -980,6 +980,17 @@ pub struct GlobalCtxt<'tcx> { } impl<'tcx> TyCtxt<'tcx> { + pub fn typeck_tables_of_const_arg( + self, + def: ty::WithOptParam, + ) -> &'tcx TypeckTables<'tcx> { + if def.param_did.is_some() { + self._typeck_tables_of_const_arg(def) + } else { + self.typeck_tables_of(def.did) + } + } + pub fn alloc_steal_mir(self, mir: Body<'tcx>) -> &'tcx Steal> { self.arena.alloc(Steal::new(mir)) } diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 4f792a07cc600..fdeb01cc6b35a 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -764,7 +764,7 @@ pub fn provide(providers: &mut Providers) { method::provide(providers); *providers = Providers { typeck_item_bodies, - typeck_tables_of_const_arg, + _typeck_tables_of_const_arg: typeck_tables_of_const_arg, typeck_tables_of, diagnostic_only_typeck_tables_of, has_typeck_tables, @@ -964,7 +964,7 @@ fn typeck_tables_of_const_arg<'tcx>( let fallback = move || tcx.type_of(param_did); typeck_tables_of_with_fallback(tcx, def.did, fallback) } else { - tcx.typeck_tables_of(def.did) + bug!("missing param_did") } } From 08394eb12174ad14aeef739a876d1456187b4d66 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Tue, 7 Jul 2020 10:46:24 +0200 Subject: [PATCH 17/25] update test --- .../ui/const-generics/type-dependent/issue-61936.rs | 6 ++++-- src/test/ui/impl-trait/auto-trait-leak.stderr | 10 ---------- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/test/ui/const-generics/type-dependent/issue-61936.rs b/src/test/ui/const-generics/type-dependent/issue-61936.rs index 2dd6c0cd24191..a7a923c6a59b7 100644 --- a/src/test/ui/const-generics/type-dependent/issue-61936.rs +++ b/src/test/ui/const-generics/type-dependent/issue-61936.rs @@ -20,11 +20,13 @@ struct ArrayWindows<'a, T, const N: usize> { impl <'a, T: Clone, const N: usize> Iterator for ArrayWindows<'a, T, N> { type Item = [T; N]; fn next(&mut self) -> Option { + // Note: this is unsound for some `T` and not meant as an example + // on how to implement `ArrayWindows`. let mut res = unsafe{ std::mem::zeroed() }; let mut ptr = &mut res as *mut [T; N] as *mut T; for i in 0..N { - match self.slice[i..].get(i) { + match self.slice[self.idx..].get(i) { None => return None, Some(elem) => unsafe { std::ptr::write_volatile(ptr, elem.clone())}, }; @@ -39,7 +41,7 @@ impl <'a, T: Clone, const N: usize> Iterator for ArrayWindows<'a, T, N> { const FOUR: usize = 4; fn main() { - let v: Vec = vec![100; 0usize]; + let v: Vec = vec![0; 100]; for array in v.as_slice().array_windows::() { assert_eq!(array, [0, 0, 0, 0]) diff --git a/src/test/ui/impl-trait/auto-trait-leak.stderr b/src/test/ui/impl-trait/auto-trait-leak.stderr index a543a31f7dded..146704a623c00 100644 --- a/src/test/ui/impl-trait/auto-trait-leak.stderr +++ b/src/test/ui/impl-trait/auto-trait-leak.stderr @@ -34,11 +34,6 @@ note: ...which requires building MIR for `cycle1`... | LL | fn cycle1() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires type-checking the potential const argument `cycle1`... - --> $DIR/auto-trait-leak.rs:12:1 - | -LL | fn cycle1() -> impl Clone { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires type-checking `cycle1`... --> $DIR/auto-trait-leak.rs:12:1 | @@ -80,11 +75,6 @@ note: ...which requires building MIR for `cycle2`... | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires type-checking the potential const argument `cycle2`... - --> $DIR/auto-trait-leak.rs:20:1 - | -LL | fn cycle2() -> impl Clone { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires type-checking `cycle2`... --> $DIR/auto-trait-leak.rs:20:1 | From ae80d7e012e6b0efcacc7b648690a9257445afd7 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 8 Jul 2020 01:03:19 +0200 Subject: [PATCH 18/25] update const arg queries --- src/librustc_middle/mir/query.rs | 25 +++++++++- src/librustc_middle/query/mod.rs | 36 +++++++------- src/librustc_middle/ty/context.rs | 6 +-- src/librustc_middle/ty/instance.rs | 9 +++- src/librustc_middle/ty/mod.rs | 19 +++++--- src/librustc_middle/ty/query/keys.rs | 15 +++++- src/librustc_middle/ty/structural_impls.rs | 13 +++++ src/librustc_mir/borrow_check/mod.rs | 10 ++-- src/librustc_mir/const_eval/eval_queries.rs | 3 +- src/librustc_mir/interpret/eval_context.rs | 6 +-- .../transform/check_consts/qualifs.rs | 4 +- src/librustc_mir/transform/check_unsafety.rs | 12 ++--- src/librustc_mir/transform/mod.rs | 48 +++++++++---------- src/librustc_mir_build/hair/cx/expr.rs | 8 +--- src/librustc_mir_build/hair/cx/mod.rs | 2 +- src/librustc_ty/instance.rs | 35 ++++++-------- src/librustc_typeck/check/mod.rs | 16 +++---- ...9-assoc-const-static-recursion-impl.stderr | 5 -- ...onst-static-recursion-trait-default.stderr | 5 -- ...-assoc-const-static-recursion-trait.stderr | 5 -- src/test/ui/impl-trait/auto-trait-leak.stderr | 10 ---- 21 files changed, 154 insertions(+), 138 deletions(-) diff --git a/src/librustc_middle/mir/query.rs b/src/librustc_middle/mir/query.rs index 8dddaf40c8264..76b8ac4e80af1 100644 --- a/src/librustc_middle/mir/query.rs +++ b/src/librustc_middle/mir/query.rs @@ -1,10 +1,10 @@ //! Values computed by queries that use MIR. -use crate::ty::{self, Ty}; +use crate::ty::{self, Ty, TyCtxt}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; use rustc_hir as hir; -use rustc_hir::def_id::DefId; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_index::bit_set::BitMatrix; use rustc_index::vec::IndexVec; use rustc_span::{Span, Symbol}; @@ -323,3 +323,24 @@ pub struct CoverageInfo { /// The total number of coverage region counters added to the MIR `Body`. pub num_counters: u32, } + +impl<'tcx> TyCtxt<'tcx> { + pub fn mir_borrowck_opt_const_arg( + self, + def: ty::WithOptParam, + ) -> &'tcx BorrowCheckResult<'tcx> { + if let Some(param_did) = def.param_did { + self.mir_borrowck_const_arg((def.did, param_did)) + } else { + self.mir_borrowck(def.did) + } + } + + pub fn mir_const_qualif_opt_const_arg(self, def: ty::WithOptParam) -> ConstQualifs { + if let Some(param_did) = def.param_did { + self.mir_const_qualif_const_arg((def.did, param_did)) + } else { + self.mir_const_qualif(def.did) + } + } +} diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 56cd93a509a35..76702fab9dc91 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -209,11 +209,11 @@ rustc_queries! { cache_on_disk_if { key.is_local() } } query mir_const_qualif_const_arg( - key: ty::WithOptParam + key: (LocalDefId, DefId) ) -> mir::ConstQualifs { desc { - |tcx| "const checking the potential const argument `{}`", - tcx.def_path_str(key.did.to_def_id()) + |tcx| "const checking the const argument `{}`", + tcx.def_path_str(key.0.to_def_id()) } } @@ -257,10 +257,10 @@ rustc_queries! { desc { |tcx| "optimizing MIR for `{}`", tcx.def_path_str(key) } cache_on_disk_if { key.is_local() } } - query optimized_mir_of_const_arg(key: ty::WithOptParam) -> &'tcx mir::Body<'tcx> { + query optimized_mir_of_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::Body<'tcx> { desc { - |tcx| "optimizing MIR for the potential const argument `{}`", - tcx.def_path_str(key.did.to_def_id()) + |tcx| "optimizing MIR for the const argument `{}`", + tcx.def_path_str(key.0.to_def_id()) } } @@ -280,7 +280,7 @@ rustc_queries! { key: ty::WithOptParam ) -> &'tcx IndexVec> { desc { - |tcx| "optimizing promoted MIR for the potential const argument `{}`", + |tcx| "optimizing promoted MIR for the const argument `{}`", tcx.def_path_str(key.did.to_def_id()), } } @@ -496,8 +496,8 @@ rustc_queries! { desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if { true } } - query unsafety_check_result_const_arg(key: ty::WithOptParam) -> &'tcx mir::UnsafetyCheckResult { - desc { |tcx| "unsafety-checking the potential const arg `{}`", tcx.def_path_str(key.did.to_def_id()) } + query unsafety_check_result_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult { + desc { |tcx| "unsafety-checking the const arg `{}`", tcx.def_path_str(key.0.to_def_id()) } } /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error. @@ -579,12 +579,12 @@ rustc_queries! { desc { |tcx| "type-checking `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if { true } } - query _typeck_tables_of_const_arg( - key: ty::WithOptParam + query typeck_tables_of_const_arg( + key: (LocalDefId, DefId) ) -> &'tcx ty::TypeckTables<'tcx> { desc { |tcx| "type-checking the const argument `{}`", - tcx.def_path_str(key.did.to_def_id()), + tcx.def_path_str(key.0.to_def_id()), } } query diagnostic_only_typeck_tables_of(key: LocalDefId) -> &'tcx ty::TypeckTables<'tcx> { @@ -627,10 +627,10 @@ rustc_queries! { || opt_result.map_or(false, |r| !r.concrete_opaque_types.is_empty()) } } - query mir_borrowck_const_arg(key: ty::WithOptParam) -> &'tcx mir::BorrowCheckResult<'tcx> { + query mir_borrowck_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::BorrowCheckResult<'tcx> { desc { - |tcx| "borrow-checking the potential const argument`{}`", - tcx.def_path_str(key.did.to_def_id()) + |tcx| "borrow-checking the const argument`{}`", + tcx.def_path_str(key.0.to_def_id()) } } } @@ -1501,11 +1501,11 @@ rustc_queries! { } query resolve_instance_of_const_arg( - key: ty::ParamEnvAnd<'tcx, (ty::WithOptParam, SubstsRef<'tcx>)> + key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)> ) -> Result>, ErrorReported> { desc { - "resolving instance of the potential const argument `{}`", - ty::Instance::new(key.value.0.did, key.value.1), + "resolving instance of the const argument `{}`", + ty::Instance::new(key.value.0.to_def_id(), key.value.2), } } } diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index f79297aeac697..fd7be0dbc0b0b 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -980,12 +980,12 @@ pub struct GlobalCtxt<'tcx> { } impl<'tcx> TyCtxt<'tcx> { - pub fn typeck_tables_of_const_arg( + pub fn typeck_tables_of_opt_const_arg( self, def: ty::WithOptParam, ) -> &'tcx TypeckTables<'tcx> { - if def.param_did.is_some() { - self._typeck_tables_of_const_arg(def) + if let Some(param_did) = def.param_did { + self.typeck_tables_of_const_arg((def.did, param_did)) } else { self.typeck_tables_of(def.did) } diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index 4c96e1f965f7f..a00afab95997a 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -359,7 +359,14 @@ impl<'tcx> Instance<'tcx> { substs: SubstsRef<'tcx>, ) -> Result>, ErrorReported> { let substs = tcx.erase_regions(&substs); - tcx.resolve_instance_of_const_arg(tcx.erase_regions(¶m_env.and((def, substs)))) + + if let Some((did, param_did)) = def.as_const_arg() { + tcx.resolve_instance_of_const_arg( + tcx.erase_regions(¶m_env.and((did, param_did, substs))), + ) + } else { + tcx.resolve_instance(tcx.erase_regions(¶m_env.and((def.did, substs)))) + } } pub fn resolve_for_fn_ptr( diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 9ebf1ed60e2ff..92ebe9b2d184c 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1600,6 +1600,16 @@ impl WithOptParam { self.did.as_local().map(|did| WithOptParam { did, param_did: self.param_did }) } + pub fn as_const_arg(self) -> Option<(LocalDefId, DefId)> { + if let Some(param_did) = self.param_did { + if let Some(did) = self.did.as_local() { + return Some((did, param_did)); + } + } + + None + } + pub fn expect_local(self) -> WithOptParam { self.as_local().unwrap() } @@ -1611,10 +1621,6 @@ impl WithOptParam { pub fn ty_def_id(self) -> DefId { self.param_did.unwrap_or(self.did) } - - pub fn init_me_bby(tcx: TyCtxt<'_>, did: DefId) -> WithOptParam { - WithOptParam { did, param_did: did.as_local().and_then(|did| tcx.opt_const_param_of(did)) } - } } /// When type checking, we use the `ParamEnv` to track @@ -2889,8 +2895,9 @@ impl<'tcx> TyCtxt<'tcx> { pub fn instance_mir(self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> { match instance { ty::InstanceDef::Item(def) => { - if let Some(def) = def.as_local() { - self.optimized_mir_of_const_arg(def) + if let Some((did, param_did)) = def.as_const_arg() { + // The `param_did` is only `Some` for local `DefId`s. + self.optimized_mir_of_const_arg((did, param_did)) } else { self.optimized_mir(def.did) } diff --git a/src/librustc_middle/ty/query/keys.rs b/src/librustc_middle/ty/query/keys.rs index ad205e1f83b71..557f64d3c1913 100644 --- a/src/librustc_middle/ty/query/keys.rs +++ b/src/librustc_middle/ty/query/keys.rs @@ -138,6 +138,17 @@ impl Key for (DefId, LocalDefId) { } } +impl Key for (LocalDefId, DefId) { + type CacheSelector = DefaultCacheSelector; + + fn query_crate(&self) -> CrateNum { + LOCAL_CRATE + } + fn default_span(&self, tcx: TyCtxt<'_>) -> Span { + self.0.default_span(tcx) + } +} + impl Key for (CrateNum, DefId) { type CacheSelector = DefaultCacheSelector; @@ -182,14 +193,14 @@ impl<'tcx> Key for (DefId, SubstsRef<'tcx>) { } } -impl<'tcx> Key for (ty::WithOptParam, SubstsRef<'tcx>) { +impl<'tcx> Key for (LocalDefId, DefId, SubstsRef<'tcx>) { type CacheSelector = DefaultCacheSelector; fn query_crate(&self) -> CrateNum { LOCAL_CRATE } fn default_span(&self, tcx: TyCtxt<'_>) -> Span { - self.0.did.default_span(tcx) + self.0.default_span(tcx) } } diff --git a/src/librustc_middle/ty/structural_impls.rs b/src/librustc_middle/ty/structural_impls.rs index 67d0030dea8fc..f04bfe648fb78 100644 --- a/src/librustc_middle/ty/structural_impls.rs +++ b/src/librustc_middle/ty/structural_impls.rs @@ -272,6 +272,7 @@ CloneTypeFoldableAndLiftImpls! { ::rustc_span::symbol::Symbol, ::rustc_hir::def::Res, ::rustc_hir::def_id::DefId, + ::rustc_hir::def_id::LocalDefId, ::rustc_hir::LlvmInlineAsmInner, ::rustc_hir::MatchSource, ::rustc_hir::Mutability, @@ -719,6 +720,18 @@ impl<'tcx, T: TypeFoldable<'tcx>, U: TypeFoldable<'tcx>> TypeFoldable<'tcx> for } } +impl<'tcx, A: TypeFoldable<'tcx>, B: TypeFoldable<'tcx>, C: TypeFoldable<'tcx>> TypeFoldable<'tcx> + for (A, B, C) +{ + fn super_fold_with>(&self, folder: &mut F) -> (A, B, C) { + (self.0.fold_with(folder), self.1.fold_with(folder), self.2.fold_with(folder)) + } + + fn super_visit_with>(&self, visitor: &mut V) -> bool { + self.0.visit_with(visitor) || self.1.visit_with(visitor) || self.2.visit_with(visitor) + } +} + EnumTypeFoldableImpl! { impl<'tcx, T> TypeFoldable<'tcx> for Option { (Some)(a), diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index b4ddda5c03d0c..0ca165ee84717 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -89,8 +89,8 @@ const DEREF_PROJECTION: &[PlaceElem<'_>; 1] = &[ProjectionElem::Deref]; pub fn provide(providers: &mut Providers) { *providers = Providers { mir_borrowck: |tcx, did| mir_borrowck(tcx, ty::WithOptParam::dummy(did)), - mir_borrowck_const_arg: |tcx, def| { - if def.param_did.is_none() { tcx.mir_borrowck(def.did) } else { mir_borrowck(tcx, def) } + mir_borrowck_const_arg: |tcx, (did, param_did)| { + mir_borrowck(tcx, ty::WithOptParam { did, param_did: Some(param_did) }) }, ..*providers }; @@ -101,8 +101,8 @@ fn mir_borrowck<'tcx>( def: ty::WithOptParam, ) -> &'tcx BorrowCheckResult<'tcx> { if def.param_did.is_none() { - if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { - return tcx.mir_borrowck_const_arg(ty::WithOptParam { param_did, ..def }); + if let Some(param_did) = tcx.opt_const_param_of(def.did) { + return tcx.mir_borrowck_const_arg((def.did, param_did)); } } @@ -150,7 +150,7 @@ fn do_mir_borrowck<'a, 'tcx>( } // Gather the upvars of a closure, if any. - let tables = tcx.typeck_tables_of_const_arg(def); + let tables = tcx.typeck_tables_of_opt_const_arg(def); if let Some(ErrorReported) = tables.tainted_by_errors { infcx.set_tainted_by_errors(); } diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs index c3f992877ead6..38894398343d5 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -292,7 +292,8 @@ pub fn const_eval_raw_provider<'tcx>( if let Some(def) = def.as_local() { if tcx.has_typeck_tables(def.did) { - if let Some(error_reported) = tcx.typeck_tables_of_const_arg(def).tainted_by_errors { + if let Some(error_reported) = tcx.typeck_tables_of_opt_const_arg(def).tainted_by_errors + { return Err(ErrorHandled::Reported(error_reported)); } } diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index bfef9c1b3535a..9cbc6d4dcea9b 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -398,7 +398,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { if let Some(def) = def.as_local() { if self.tcx.has_typeck_tables(def.did) { if let Some(error_reported) = - self.tcx.typeck_tables_of_const_arg(def).tainted_by_errors + self.tcx.typeck_tables_of_opt_const_arg(def).tainted_by_errors { throw_inval!(TypeckError(error_reported)) } @@ -415,8 +415,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { match instance { ty::InstanceDef::Item(def) => { if self.tcx.is_mir_available(def.did) { - if let Some(def) = def.as_local() { - Ok(self.tcx.optimized_mir_of_const_arg(def)) + if let Some((did, param_did)) = def.as_const_arg() { + Ok(self.tcx.optimized_mir_of_const_arg((did, param_did))) } else { Ok(self.tcx.optimized_mir(def.did)) } diff --git a/src/librustc_mir/transform/check_consts/qualifs.rs b/src/librustc_mir/transform/check_consts/qualifs.rs index a03d3fbb68ed9..445a0230afd3a 100644 --- a/src/librustc_mir/transform/check_consts/qualifs.rs +++ b/src/librustc_mir/transform/check_consts/qualifs.rs @@ -248,8 +248,8 @@ where assert!(promoted.is_none()); // Don't peek inside trait associated constants. if cx.tcx.trait_of_item(def.did).is_none() { - let qualifs = if let Some(def) = def.as_local() { - cx.tcx.at(constant.span).mir_const_qualif_const_arg(def) + let qualifs = if let Some((did, param_did)) = def.as_const_arg() { + cx.tcx.at(constant.span).mir_const_qualif_const_arg((did, param_did)) } else { cx.tcx.at(constant.span).mir_const_qualif(def.did) }; diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 6d270a9c68428..5ee93dfc446a4 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -493,12 +493,8 @@ pub(crate) fn provide(providers: &mut Providers) { unsafety_check_result: |tcx, def_id| { unsafety_check_result(tcx, ty::WithOptParam::dummy(def_id)) }, - unsafety_check_result_const_arg: |tcx, def| { - if def.param_did.is_none() { - tcx.unsafety_check_result(def.did) - } else { - unsafety_check_result(tcx, def) - } + unsafety_check_result_const_arg: |tcx, (did, param_did)| { + unsafety_check_result(tcx, ty::WithOptParam { did, param_did: Some(param_did) }) }, unsafe_derive_on_repr_packed, ..*providers @@ -553,8 +549,8 @@ fn unsafety_check_result<'tcx>( def: ty::WithOptParam, ) -> &'tcx UnsafetyCheckResult { if def.param_did.is_none() { - if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { - return tcx.unsafety_check_result_const_arg(ty::WithOptParam { param_did, ..def }); + if let Some(param_did) = tcx.opt_const_param_of(def.did) { + return tcx.unsafety_check_result_const_arg((def.did, param_did)); } } diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index 8259e1288bb82..fdcf36a316268 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -51,12 +51,8 @@ pub(crate) fn provide(providers: &mut Providers) { mir_const_qualif: |tcx, did| { mir_const_qualif(tcx, ty::WithOptParam::dummy(did.expect_local())) }, - mir_const_qualif_const_arg: |tcx, def| { - if def.param_did.is_none() { - tcx.mir_const_qualif(def.did.to_def_id()) - } else { - mir_const_qualif(tcx, def) - } + mir_const_qualif_const_arg: |tcx, (did, param_did)| { + mir_const_qualif(tcx, ty::WithOptParam { did, param_did: Some(param_did) }) }, mir_validated, mir_drops_elaborated_and_const_checked, @@ -227,8 +223,8 @@ pub fn run_passes( fn mir_const_qualif(tcx: TyCtxt<'_>, def: ty::WithOptParam) -> ConstQualifs { if def.param_did.is_none() { - if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { - return tcx.mir_const_qualif_const_arg(ty::WithOptParam { param_did, ..def }); + if let Some(param_did) = tcx.opt_const_param_of(def.did) { + return tcx.mir_const_qualif_const_arg((def.did, param_did)); } } @@ -278,7 +274,11 @@ fn mir_const<'tcx>( } // Unsafety check uses the raw mir, so make sure it is run. - let _ = tcx.unsafety_check_result_const_arg(def); + if let Some(param_did) = def.param_did { + tcx.ensure().unsafety_check_result_const_arg((def.did, param_did)); + } else { + tcx.ensure().unsafety_check_result(def.did); + } let mut body = tcx.mir_built(def).steal(); @@ -321,7 +321,7 @@ fn mir_validated( // Ensure that we compute the `mir_const_qualif` for constants at // this point, before we steal the mir-const result. - let _ = tcx.mir_const_qualif_const_arg(def); + let _ = tcx.mir_const_qualif_opt_const_arg(def); let mut body = tcx.mir_const(def).steal(); @@ -367,7 +367,11 @@ fn mir_drops_elaborated_and_const_checked<'tcx>( // (Mir-)Borrowck uses `mir_validated`, so we have to force it to // execute before we can steal. - tcx.ensure().mir_borrowck_const_arg(def); + if let Some(param_did) = def.param_did { + tcx.ensure().mir_borrowck_const_arg((def.did, param_did)); + } else { + tcx.ensure().mir_borrowck(def.did); + } let (body, _) = tcx.mir_validated(def); let mut body = body.steal(); @@ -485,8 +489,8 @@ fn run_optimization_passes<'tcx>( fn optimized_mir<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx Body<'tcx> { let did = did.expect_local(); - if let param_did @ Some(_) = tcx.opt_const_param_of(did) { - tcx.optimized_mir_of_const_arg(ty::WithOptParam { did, param_did }) + if let Some(param_did) = tcx.opt_const_param_of(did) { + tcx.optimized_mir_of_const_arg((did, param_did)) } else { tcx.arena.alloc(inner_optimized_mir(tcx, ty::WithOptParam::dummy(did))) } @@ -494,17 +498,9 @@ fn optimized_mir<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx Body<'tcx> { fn optimized_mir_of_const_arg<'tcx>( tcx: TyCtxt<'tcx>, - def: ty::WithOptParam, + (did, param_did): (LocalDefId, DefId), ) -> &'tcx Body<'tcx> { - if def.param_did.is_none() { - if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { - tcx.optimized_mir_of_const_arg(ty::WithOptParam { param_did, ..def }) - } else { - tcx.optimized_mir(def.did) - } - } else { - tcx.arena.alloc(inner_optimized_mir(tcx, def)) - } + tcx.arena.alloc(inner_optimized_mir(tcx, ty::WithOptParam { did, param_did: Some(param_did) })) } fn inner_optimized_mir(tcx: TyCtxt<'_>, def: ty::WithOptParam) -> Body<'_> { @@ -538,7 +534,11 @@ fn promoted_mir<'tcx>( return tcx.arena.alloc(IndexVec::new()); } - tcx.ensure().mir_borrowck_const_arg(def); + if let Some(param_did) = def.param_did { + tcx.ensure().mir_borrowck_const_arg((def.did, param_did)); + } else { + tcx.ensure().mir_borrowck(def.did); + } let (_, promoted) = tcx.mir_validated(def); let mut promoted = promoted.steal(); diff --git a/src/librustc_mir_build/hair/cx/expr.rs b/src/librustc_mir_build/hair/cx/expr.rs index e5f9f7328b89c..025ef1ece4603 100644 --- a/src/librustc_mir_build/hair/cx/expr.rs +++ b/src/librustc_mir_build/hair/cx/expr.rs @@ -601,7 +601,7 @@ fn make_mirror_unadjusted<'a, 'tcx>( let substs = InternalSubsts::identity_for_item(cx.tcx(), did); let lhs = mk_const(cx.tcx().mk_const(ty::Const { val: ty::ConstKind::Unevaluated( - ty::WithOptParam::init_me_bby(cx.tcx(), did), + ty::WithOptParam::dummy(did), substs, None, ), @@ -800,11 +800,7 @@ fn convert_path_expr<'a, 'tcx>( debug!("convert_path_expr: (const) user_ty={:?}", user_ty); ExprKind::Literal { literal: cx.tcx.mk_const(ty::Const { - val: ty::ConstKind::Unevaluated( - ty::WithOptParam::init_me_bby(cx.tcx, def_id), - substs, - None, - ), + val: ty::ConstKind::Unevaluated(ty::WithOptParam::dummy(def_id), substs, None), ty: cx.tables().node_type(expr.hir_id), }), user_ty, diff --git a/src/librustc_mir_build/hair/cx/mod.rs b/src/librustc_mir_build/hair/cx/mod.rs index 5505559fc8e55..7daf7b629d852 100644 --- a/src/librustc_mir_build/hair/cx/mod.rs +++ b/src/librustc_mir_build/hair/cx/mod.rs @@ -56,7 +56,7 @@ impl<'a, 'tcx> Cx<'a, 'tcx> { src_id: hir::HirId, ) -> Cx<'a, 'tcx> { let tcx = infcx.tcx; - let tables = tcx.typeck_tables_of_const_arg(def); + let tables = tcx.typeck_tables_of_opt_const_arg(def); let body_owner_kind = tcx.hir().body_owner_kind(src_id); let constness = match body_owner_kind { diff --git a/src/librustc_ty/instance.rs b/src/librustc_ty/instance.rs index 7c58963fccc85..0a1d8c1077a0b 100644 --- a/src/librustc_ty/instance.rs +++ b/src/librustc_ty/instance.rs @@ -1,5 +1,5 @@ use rustc_errors::ErrorReported; -use rustc_hir::def_id::DefId; +use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::ty::subst::SubstsRef; use rustc_middle::ty::{self, Instance, TyCtxt, TypeFoldable}; @@ -15,32 +15,25 @@ fn resolve_instance<'tcx>( key: ty::ParamEnvAnd<'tcx, (DefId, SubstsRef<'tcx>)>, ) -> Result>, ErrorReported> { let (param_env, (did, substs)) = key.into_parts(); - if let param_did @ Some(_) = did.as_local().and_then(|did| tcx.opt_const_param_of(did)) { - tcx.resolve_instance_of_const_arg( - param_env.and((ty::WithOptParam { did, param_did }, substs)), - ) - } else { - inner_resolve_instance(tcx, param_env.and((ty::WithOptParam::dummy(did), substs))) + if let Some(did) = did.as_local() { + if let Some(param_did) = tcx.opt_const_param_of(did) { + return tcx.resolve_instance_of_const_arg(param_env.and((did, param_did, substs))); + } } + + inner_resolve_instance(tcx, param_env.and((ty::WithOptParam::dummy(did), substs))) } fn resolve_instance_of_const_arg<'tcx>( tcx: TyCtxt<'tcx>, - key: ty::ParamEnvAnd<'tcx, (ty::WithOptParam, SubstsRef<'tcx>)>, + key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>, ) -> Result>, ErrorReported> { - let (param_env, (def, substs)) = key.into_parts(); - if def.param_did.is_none() { - if let Some(did) = def.did.as_local() { - if let param_did @ Some(_) = tcx.opt_const_param_of(did) { - return tcx.resolve_instance_of_const_arg( - param_env.and((ty::WithOptParam { param_did, ..def }, substs)), - ); - } - } - tcx.resolve_instance(param_env.and((def.did, substs))) - } else { - inner_resolve_instance(tcx, param_env.and((def, substs))) - } + let (param_env, (did, param_did, substs)) = key.into_parts(); + inner_resolve_instance( + tcx, + param_env + .and((ty::WithOptParam { did: did.to_def_id(), param_did: Some(param_did) }, substs)), + ) } fn inner_resolve_instance<'tcx>( diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index fdeb01cc6b35a..fd2a0175cf66c 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -764,7 +764,7 @@ pub fn provide(providers: &mut Providers) { method::provide(providers); *providers = Providers { typeck_item_bodies, - _typeck_tables_of_const_arg: typeck_tables_of_const_arg, + typeck_tables_of_const_arg, typeck_tables_of, diagnostic_only_typeck_tables_of, has_typeck_tables, @@ -958,19 +958,15 @@ where fn typeck_tables_of_const_arg<'tcx>( tcx: TyCtxt<'tcx>, - def: ty::WithOptParam, + (did, param_did): (LocalDefId, DefId), ) -> &ty::TypeckTables<'tcx> { - if let Some(param_did) = def.param_did { - let fallback = move || tcx.type_of(param_did); - typeck_tables_of_with_fallback(tcx, def.did, fallback) - } else { - bug!("missing param_did") - } + let fallback = move || tcx.type_of(param_did); + typeck_tables_of_with_fallback(tcx, did, fallback) } fn typeck_tables_of<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &ty::TypeckTables<'tcx> { - if let param_did @ Some(_) = tcx.opt_const_param_of(def_id) { - tcx.typeck_tables_of_const_arg(ty::WithOptParam { did: def_id, param_did }) + if let Some(param_did) = tcx.opt_const_param_of(def_id) { + tcx.typeck_tables_of_const_arg((def_id, param_did)) } else { let fallback = move || tcx.type_of(def_id.to_def_id()); typeck_tables_of_with_fallback(tcx, def_id, fallback) diff --git a/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr b/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr index 846e2979f8439..1b4326ea56aaa 100644 --- a/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr +++ b/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-impl.stderr @@ -30,11 +30,6 @@ note: ...which requires const-evaluating `::BAR`... - --> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5 - | -LL | const BAR: u32 = IMPL_REF_BAR; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires optimizing MIR for `::BAR`... --> $DIR/issue-24949-assoc-const-static-recursion-impl.rs:12:5 | diff --git a/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr b/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr index 305d20c05c9a8..8efa56a9a2e63 100644 --- a/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr +++ b/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait-default.stderr @@ -30,11 +30,6 @@ note: ...which requires const-evaluating `FooDefault::BAR`... | LL | const BAR: u32 = DEFAULT_REF_BAR; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires optimizing MIR for the potential const argument `FooDefault::BAR`... - --> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5 - | -LL | const BAR: u32 = DEFAULT_REF_BAR; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires optimizing MIR for `FooDefault::BAR`... --> $DIR/issue-24949-assoc-const-static-recursion-trait-default.rs:8:5 | diff --git a/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr b/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr index 7a4912aaa73ab..78ce1a28a3fdc 100644 --- a/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr +++ b/src/test/ui/associated-consts/issue-24949-assoc-const-static-recursion-trait.stderr @@ -30,11 +30,6 @@ note: ...which requires const-evaluating `::BAR`... - --> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5 - | -LL | const BAR: u32 = TRAIT_REF_BAR; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires optimizing MIR for `::BAR`... --> $DIR/issue-24949-assoc-const-static-recursion-trait.rs:12:5 | diff --git a/src/test/ui/impl-trait/auto-trait-leak.stderr b/src/test/ui/impl-trait/auto-trait-leak.stderr index 146704a623c00..cba894bec9d22 100644 --- a/src/test/ui/impl-trait/auto-trait-leak.stderr +++ b/src/test/ui/impl-trait/auto-trait-leak.stderr @@ -19,11 +19,6 @@ note: ...which requires processing MIR for `cycle1`... | LL | fn cycle1() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires unsafety-checking the potential const arg `cycle1`... - --> $DIR/auto-trait-leak.rs:12:1 - | -LL | fn cycle1() -> impl Clone { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires unsafety-checking `cycle1`... --> $DIR/auto-trait-leak.rs:12:1 | @@ -60,11 +55,6 @@ note: ...which requires processing MIR for `cycle2`... | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires unsafety-checking the potential const arg `cycle2`... - --> $DIR/auto-trait-leak.rs:20:1 - | -LL | fn cycle2() -> impl Clone { - | ^^^^^^^^^^^^^^^^^^^^^^^^^ note: ...which requires unsafety-checking `cycle2`... --> $DIR/auto-trait-leak.rs:20:1 | From a7fe4df04a095bad08a4158ce0cabed632a16828 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 8 Jul 2020 10:35:58 +0200 Subject: [PATCH 19/25] update promoted_mir --- src/librustc_middle/mir/query.rs | 12 ++++++++++++ src/librustc_middle/query/mod.rs | 4 ++-- src/librustc_mir/const_eval/eval_queries.rs | 2 +- src/librustc_mir/interpret/eval_context.rs | 6 +----- src/librustc_mir/transform/mod.rs | 12 ++++-------- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/librustc_middle/mir/query.rs b/src/librustc_middle/mir/query.rs index 76b8ac4e80af1..884067347a68d 100644 --- a/src/librustc_middle/mir/query.rs +++ b/src/librustc_middle/mir/query.rs @@ -1,5 +1,6 @@ //! Values computed by queries that use MIR. +use crate::mir::{Body, Promoted}; use crate::ty::{self, Ty, TyCtxt}; use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::Lrc; @@ -343,4 +344,15 @@ impl<'tcx> TyCtxt<'tcx> { self.mir_const_qualif(def.did) } } + + pub fn promoted_mir_of_opt_const_arg( + self, + def: ty::WithOptParam, + ) -> &'tcx IndexVec> { + if let Some((did, param_did)) = def.as_const_arg() { + self.promoted_mir_of_const_arg((did, param_did)) + } else { + self.promoted_mir(def.did) + } + } } diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 76702fab9dc91..8c4b8cd1c8f65 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -277,11 +277,11 @@ rustc_queries! { cache_on_disk_if { key.is_local() } } query promoted_mir_of_const_arg( - key: ty::WithOptParam + key: (LocalDefId, DefId) ) -> &'tcx IndexVec> { desc { |tcx| "optimizing promoted MIR for the const argument `{}`", - tcx.def_path_str(key.did.to_def_id()), + tcx.def_path_str(key.0.to_def_id()), } } } diff --git a/src/librustc_mir/const_eval/eval_queries.rs b/src/librustc_mir/const_eval/eval_queries.rs index 38894398343d5..cec7f1bcb9d9b 100644 --- a/src/librustc_mir/const_eval/eval_queries.rs +++ b/src/librustc_mir/const_eval/eval_queries.rs @@ -360,7 +360,7 @@ pub fn const_eval_raw_provider<'tcx>( // deny-by-default lint _ => { if let Some(p) = cid.promoted { - let span = tcx.promoted_mir_of_const_arg(def)[p].span; + let span = tcx.promoted_mir_of_opt_const_arg(def.to_global())[p].span; if let err_inval!(ReferencedConstant) = err.error { err.report_as_error( tcx.at(span), diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 9cbc6d4dcea9b..c59b7c98e982b 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -406,11 +406,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { } trace!("load mir(instance={:?}, promoted={:?})", instance, promoted); if let Some(promoted) = promoted { - return if let Some(def) = def.as_local() { - Ok(&self.tcx.promoted_mir_of_const_arg(def)[promoted]) - } else { - Ok(&self.tcx.promoted_mir(def.did)[promoted]) - }; + return Ok(&self.tcx.promoted_mir_of_opt_const_arg(def)[promoted]); } match instance { ty::InstanceDef::Item(def) => { diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index fdcf36a316268..f2d6efae0192a 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -62,12 +62,8 @@ pub(crate) fn provide(providers: &mut Providers) { promoted_mir: |tcx, def_id| { promoted_mir(tcx, ty::WithOptParam::dummy(def_id.expect_local())) }, - promoted_mir_of_const_arg: |tcx, def| { - if def.param_did.is_none() { - tcx.promoted_mir(def.did.to_def_id()) - } else { - promoted_mir(tcx, def) - } + promoted_mir_of_const_arg: |tcx, (did, param_did)| { + promoted_mir(tcx, ty::WithOptParam { did, param_did: Some(param_did) }) }, ..*providers }; @@ -525,8 +521,8 @@ fn promoted_mir<'tcx>( def: ty::WithOptParam, ) -> &'tcx IndexVec> { if def.param_did.is_none() { - if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { - return tcx.promoted_mir_of_const_arg(ty::WithOptParam { param_did, ..def }); + if let Some(param_did) = tcx.opt_const_param_of(def.did) { + return tcx.promoted_mir_of_const_arg((def.did, param_did)); } } From 805c44d5d32d23e18d962f14e34869ddcef588fd Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 8 Jul 2020 11:42:59 +0200 Subject: [PATCH 20/25] cleanup --- src/librustc_middle/query/mod.rs | 16 ++++++--- src/librustc_middle/ty/mod.rs | 36 +++++++++++++++++-- src/test/ui/impl-trait/auto-trait-leak.stderr | 4 +-- 3 files changed, 48 insertions(+), 8 deletions(-) diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 8c4b8cd1c8f65..fbd4f4b7f54fc 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -228,7 +228,11 @@ rustc_queries! { /// /// See the README for the `mir` module for details. query mir_const(key: ty::WithOptParam) -> &'tcx Steal> { - desc { |tcx| "processing MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) } + desc { + |tcx| "processing MIR for {}`{}`", + if key.param_did.is_some() { "the const argument " } else { "" }, + tcx.def_path_str(key.did.to_def_id()), + } no_hash } @@ -246,8 +250,9 @@ rustc_queries! { ) { no_hash desc { - |tcx| "processing the potential const argument `{}`", - tcx.def_path_str(key.did.to_def_id()) + |tcx| "processing {}`{}`", + if key.param_did.is_some() { "the const argument " } else { "" }, + tcx.def_path_str(key.did.to_def_id()), } } @@ -497,7 +502,10 @@ rustc_queries! { cache_on_disk_if { true } } query unsafety_check_result_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult { - desc { |tcx| "unsafety-checking the const arg `{}`", tcx.def_path_str(key.0.to_def_id()) } + desc { + |tcx| "unsafety-checking the const argument `{}`", + tcx.def_path_str(key.0.to_def_id()) + } } /// HACK: when evaluated, this reports a "unsafe derive on repr(packed)" error. diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 92ebe9b2d184c..5e2cce42d9320 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1,5 +1,4 @@ // ignore-tidy-filelength - pub use self::fold::{TypeFoldable, TypeVisitor}; pub use self::AssocItemContainer::*; pub use self::BorrowKind::*; @@ -1571,11 +1570,45 @@ pub type PlaceholderType = Placeholder; pub type PlaceholderConst = Placeholder; +/// A `DefId` which is potentially bundled with its corresponding generic parameter +/// in case `did` is a const argument. +/// +/// This is used to prevent cycle errors during typeck +/// as `type_of(const_arg)` depends on `typeck_tables_of(owning_body)` +/// which once again requires the type of its generic arguments. +/// +/// Luckily we only need to deal with const arguments once we +/// know their corresponding parameters. We (ab)use this by +/// calling `type_of(param_did)` for these arguments. +/// +/// ```rust +/// #![feature(const_generics)] +/// +/// struct A; +/// impl A { +/// fn foo(&self) -> usize { N } +/// } +/// struct B; +/// impl B { +/// fn foo(&self) -> usize { 42 } +/// } +/// +/// fn main() { +/// let a = A; +/// a.foo::<7>(); +/// } +/// ``` #[derive(Copy, Clone, Debug, TypeFoldable, Lift, RustcEncodable, RustcDecodable)] #[derive(PartialEq, Eq, PartialOrd, Ord)] #[derive(Hash, HashStable)] pub struct WithOptParam { pub did: T, + /// The `DefId` of the corresponding generic paramter in case `did` is + /// a const argument. + /// + /// Note that even if `did` is a const argument, this may still be `None`. + /// All queries taking `WithOptParam` start by calling `tcx.opt_const_param_of(def.did)` + /// to potentially update `param_did` in case it `None`. pub param_did: Option, } @@ -2896,7 +2929,6 @@ impl<'tcx> TyCtxt<'tcx> { match instance { ty::InstanceDef::Item(def) => { if let Some((did, param_did)) = def.as_const_arg() { - // The `param_did` is only `Some` for local `DefId`s. self.optimized_mir_of_const_arg((did, param_did)) } else { self.optimized_mir(def.did) diff --git a/src/test/ui/impl-trait/auto-trait-leak.stderr b/src/test/ui/impl-trait/auto-trait-leak.stderr index cba894bec9d22..679b26efe5933 100644 --- a/src/test/ui/impl-trait/auto-trait-leak.stderr +++ b/src/test/ui/impl-trait/auto-trait-leak.stderr @@ -9,7 +9,7 @@ note: ...which requires borrow-checking `cycle1`... | LL | fn cycle1() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires processing the potential const argument `cycle1`... +note: ...which requires processing `cycle1`... --> $DIR/auto-trait-leak.rs:12:1 | LL | fn cycle1() -> impl Clone { @@ -45,7 +45,7 @@ note: ...which requires borrow-checking `cycle2`... | LL | fn cycle2() -> impl Clone { | ^^^^^^^^^^^^^^^^^^^^^^^^^ -note: ...which requires processing the potential const argument `cycle2`... +note: ...which requires processing `cycle2`... --> $DIR/auto-trait-leak.rs:20:1 | LL | fn cycle2() -> impl Clone { From a909eb6b653080683b49b2be5e6621ca08cecf01 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 15 Jul 2020 10:50:54 +0200 Subject: [PATCH 21/25] improve naming --- src/librustc_infer/infer/mod.rs | 2 +- src/librustc_interface/passes.rs | 2 +- src/librustc_middle/mir/interpret/queries.rs | 2 +- src/librustc_middle/mir/query.rs | 13 ++-- src/librustc_middle/query/mod.rs | 14 ++-- src/librustc_middle/ty/context.rs | 4 +- src/librustc_middle/ty/instance.rs | 10 +-- src/librustc_middle/ty/mod.rs | 36 +++++----- src/librustc_middle/ty/query/keys.rs | 2 +- src/librustc_middle/ty/sty.rs | 8 +-- src/librustc_mir/borrow_check/mod.rs | 10 +-- src/librustc_mir/borrow_check/nll.rs | 2 +- .../borrow_check/universal_regions.rs | 4 +- src/librustc_mir/transform/check_unsafety.rs | 11 +-- src/librustc_mir/transform/mod.rs | 70 +++++++++++-------- src/librustc_mir/transform/promote_consts.rs | 4 +- src/librustc_mir/util/pretty.rs | 2 +- src/librustc_mir_build/build/mod.rs | 10 +-- src/librustc_mir_build/hair/cx/expr.rs | 8 ++- src/librustc_mir_build/hair/cx/mod.rs | 2 +- src/librustc_ty/instance.rs | 16 +++-- src/librustc_typeck/astconv.rs | 6 +- src/librustc_typeck/check/mod.rs | 6 +- src/librustc_typeck/check/wfcheck.rs | 2 +- .../rustc.BAR.PromoteTemps.diff | 4 +- .../rustc.FOO.PromoteTemps.diff | 4 +- .../32bit/rustc.main.ConstProp.diff | 4 +- .../64bit/rustc.main.ConstProp.diff | 4 +- .../rustc.main.ConstProp.diff | 4 +- .../rustc.hello.ConstProp.diff | 4 +- .../ref_deref/rustc.main.ConstProp.diff | 4 +- .../ref_deref/rustc.main.PromoteTemps.diff | 4 +- .../rustc.main.ConstProp.diff | 4 +- .../rustc.main.PromoteTemps.diff | 4 +- .../slice_len/32bit/rustc.main.ConstProp.diff | 4 +- .../slice_len/64bit/rustc.main.ConstProp.diff | 4 +- .../inline-retag/rustc.bar.Inline.after.mir | 8 +-- .../32bit/rustc.main.PreCodegen.diff | 8 +-- .../32bit/rustc.main.SimplifyArmIdentity.diff | 8 +-- .../64bit/rustc.main.PreCodegen.diff | 8 +-- .../64bit/rustc.main.SimplifyArmIdentity.diff | 8 +-- ...c.full_tested_match.PromoteTemps.after.mir | 4 +- ...main.SimplifyCfg-elaborate-drops.after.mir | 4 +- src/tools/clippy/clippy_lints/src/consts.rs | 2 +- 44 files changed, 184 insertions(+), 160 deletions(-) diff --git a/src/librustc_infer/infer/mod.rs b/src/librustc_infer/infer/mod.rs index 85c568cbd6583..00503a6992875 100644 --- a/src/librustc_infer/infer/mod.rs +++ b/src/librustc_infer/infer/mod.rs @@ -1536,7 +1536,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> { pub fn const_eval_resolve( &self, param_env: ty::ParamEnv<'tcx>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, substs: SubstsRef<'tcx>, promoted: Option, span: Option, diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 5152e62f07201..4357f11776c36 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -892,7 +892,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> { if tcx.hir().body_const_context(def_id).is_some() { tcx.ensure() - .mir_drops_elaborated_and_const_checked(ty::WithOptParam::dummy(def_id)); + .mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::dummy(def_id)); } } }); diff --git a/src/librustc_middle/mir/interpret/queries.rs b/src/librustc_middle/mir/interpret/queries.rs index bbaead535f6c7..0a9c2ac947574 100644 --- a/src/librustc_middle/mir/interpret/queries.rs +++ b/src/librustc_middle/mir/interpret/queries.rs @@ -34,7 +34,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn const_eval_resolve( self, param_env: ty::ParamEnv<'tcx>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, substs: SubstsRef<'tcx>, promoted: Option, span: Option, diff --git a/src/librustc_middle/mir/query.rs b/src/librustc_middle/mir/query.rs index 884067347a68d..560a8421c1797 100644 --- a/src/librustc_middle/mir/query.rs +++ b/src/librustc_middle/mir/query.rs @@ -328,17 +328,20 @@ pub struct CoverageInfo { impl<'tcx> TyCtxt<'tcx> { pub fn mir_borrowck_opt_const_arg( self, - def: ty::WithOptParam, + def: ty::WithOptConstParam, ) -> &'tcx BorrowCheckResult<'tcx> { - if let Some(param_did) = def.param_did { + if let Some(param_did) = def.const_param_did { self.mir_borrowck_const_arg((def.did, param_did)) } else { self.mir_borrowck(def.did) } } - pub fn mir_const_qualif_opt_const_arg(self, def: ty::WithOptParam) -> ConstQualifs { - if let Some(param_did) = def.param_did { + pub fn mir_const_qualif_opt_const_arg( + self, + def: ty::WithOptConstParam, + ) -> ConstQualifs { + if let Some(param_did) = def.const_param_did { self.mir_const_qualif_const_arg((def.did, param_did)) } else { self.mir_const_qualif(def.did) @@ -347,7 +350,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn promoted_mir_of_opt_const_arg( self, - def: ty::WithOptParam, + def: ty::WithOptConstParam, ) -> &'tcx IndexVec> { if let Some((did, param_did)) = def.as_const_arg() { self.promoted_mir_of_const_arg((did, param_did)) diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index fbd4f4b7f54fc..edeefab43421e 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -105,7 +105,7 @@ rustc_queries! { /// ``` query opt_const_param_of(key: LocalDefId) -> Option { desc { |tcx| "computing the optional const parameter of `{}`", tcx.def_path_str(key.to_def_id()) } - // FIXME: consider storing this query on disk. + // FIXME(#74113): consider storing this query on disk. } /// Records the type of every item. @@ -219,7 +219,7 @@ rustc_queries! { /// Fetch the MIR for a given `DefId` right after it's built - this includes /// unreachable code. - query mir_built(key: ty::WithOptParam) -> &'tcx Steal> { + query mir_built(key: ty::WithOptConstParam) -> &'tcx Steal> { desc { |tcx| "building MIR for `{}`", tcx.def_path_str(key.did.to_def_id()) } } @@ -227,23 +227,23 @@ rustc_queries! { /// ready for const qualification. /// /// See the README for the `mir` module for details. - query mir_const(key: ty::WithOptParam) -> &'tcx Steal> { + query mir_const(key: ty::WithOptConstParam) -> &'tcx Steal> { desc { |tcx| "processing MIR for {}`{}`", - if key.param_did.is_some() { "the const argument " } else { "" }, + if key.const_param_did.is_some() { "the const argument " } else { "" }, tcx.def_path_str(key.did.to_def_id()), } no_hash } query mir_drops_elaborated_and_const_checked( - key: ty::WithOptParam + key: ty::WithOptConstParam ) -> &'tcx Steal> { no_hash desc { |tcx| "elaborating drops for `{}`", tcx.def_path_str(key.did.to_def_id()) } } - query mir_validated(key: ty::WithOptParam) -> + query mir_validated(key: ty::WithOptConstParam) -> ( &'tcx Steal>, &'tcx Steal>> @@ -251,7 +251,7 @@ rustc_queries! { no_hash desc { |tcx| "processing {}`{}`", - if key.param_did.is_some() { "the const argument " } else { "" }, + if key.const_param_did.is_some() { "the const argument " } else { "" }, tcx.def_path_str(key.did.to_def_id()), } } diff --git a/src/librustc_middle/ty/context.rs b/src/librustc_middle/ty/context.rs index fd7be0dbc0b0b..bb5dd53a7e669 100644 --- a/src/librustc_middle/ty/context.rs +++ b/src/librustc_middle/ty/context.rs @@ -982,9 +982,9 @@ pub struct GlobalCtxt<'tcx> { impl<'tcx> TyCtxt<'tcx> { pub fn typeck_tables_of_opt_const_arg( self, - def: ty::WithOptParam, + def: ty::WithOptConstParam, ) -> &'tcx TypeckTables<'tcx> { - if let Some(param_did) = def.param_did { + if let Some(param_did) = def.const_param_did { self.typeck_tables_of_const_arg((def.did, param_did)) } else { self.typeck_tables_of(def.did) diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index a00afab95997a..114ce491f2780 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -29,7 +29,7 @@ pub enum InstanceDef<'tcx> { /// - `fn` items /// - closures /// - generators - Item(ty::WithOptParam), + Item(ty::WithOptConstParam), /// An intrinsic `fn` item (with `"rust-intrinsic"` or `"platform-intrinsic"` ABI). /// @@ -186,7 +186,7 @@ impl<'tcx> InstanceDef<'tcx> { } #[inline] - pub fn with_opt_param(self) -> ty::WithOptParam { + pub fn with_opt_param(self) -> ty::WithOptConstParam { match self { InstanceDef::Item(def) => def, InstanceDef::VtableShim(def_id) @@ -196,7 +196,7 @@ impl<'tcx> InstanceDef<'tcx> { | InstanceDef::Intrinsic(def_id) | InstanceDef::ClosureOnceShim { call_once: def_id } | InstanceDef::DropGlue(def_id, _) - | InstanceDef::CloneShim(def_id, _) => ty::WithOptParam::dummy(def_id), + | InstanceDef::CloneShim(def_id, _) => ty::WithOptConstParam::dummy(def_id), } } @@ -298,7 +298,7 @@ impl<'tcx> Instance<'tcx> { def_id, substs ); - Instance { def: InstanceDef::Item(ty::WithOptParam::dummy(def_id)), substs } + Instance { def: InstanceDef::Item(ty::WithOptConstParam::dummy(def_id)), substs } } pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> { @@ -355,7 +355,7 @@ impl<'tcx> Instance<'tcx> { pub fn resolve_const_arg( tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, substs: SubstsRef<'tcx>, ) -> Result>, ErrorReported> { let substs = tcx.erase_regions(&substs); diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 5e2cce42d9320..35b3ad66f0131 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1099,7 +1099,7 @@ pub enum PredicateKind<'tcx> { Subtype(PolySubtypePredicate<'tcx>), /// Constant initializer must evaluate successfully. - ConstEvaluatable(ty::WithOptParam, SubstsRef<'tcx>), + ConstEvaluatable(ty::WithOptConstParam, SubstsRef<'tcx>), /// Constants must be equal. The first component is the const that is expected. ConstEquate(&'tcx Const<'tcx>, &'tcx Const<'tcx>), @@ -1601,40 +1601,42 @@ pub type PlaceholderConst = Placeholder; #[derive(Copy, Clone, Debug, TypeFoldable, Lift, RustcEncodable, RustcDecodable)] #[derive(PartialEq, Eq, PartialOrd, Ord)] #[derive(Hash, HashStable)] -pub struct WithOptParam { +pub struct WithOptConstParam { pub did: T, /// The `DefId` of the corresponding generic paramter in case `did` is /// a const argument. /// /// Note that even if `did` is a const argument, this may still be `None`. - /// All queries taking `WithOptParam` start by calling `tcx.opt_const_param_of(def.did)` + /// All queries taking `WithOptConstParam` start by calling `tcx.opt_const_param_of(def.did)` /// to potentially update `param_did` in case it `None`. - pub param_did: Option, + pub const_param_did: Option, } -impl WithOptParam { - pub fn dummy(did: T) -> WithOptParam { - WithOptParam { did, param_did: None } +impl WithOptConstParam { + pub fn dummy(did: T) -> WithOptConstParam { + WithOptConstParam { did, const_param_did: None } } } -impl WithOptParam { - pub fn to_global(self) -> WithOptParam { - WithOptParam { did: self.did.to_def_id(), param_did: self.param_did } +impl WithOptConstParam { + pub fn to_global(self) -> WithOptConstParam { + WithOptConstParam { did: self.did.to_def_id(), const_param_did: self.const_param_did } } pub fn ty_def_id(self) -> DefId { - if let Some(did) = self.param_did { did } else { self.did.to_def_id() } + if let Some(did) = self.const_param_did { did } else { self.did.to_def_id() } } } -impl WithOptParam { - pub fn as_local(self) -> Option> { - self.did.as_local().map(|did| WithOptParam { did, param_did: self.param_did }) +impl WithOptConstParam { + pub fn as_local(self) -> Option> { + self.did + .as_local() + .map(|did| WithOptConstParam { did, const_param_did: self.const_param_did }) } pub fn as_const_arg(self) -> Option<(LocalDefId, DefId)> { - if let Some(param_did) = self.param_did { + if let Some(param_did) = self.const_param_did { if let Some(did) = self.did.as_local() { return Some((did, param_did)); } @@ -1643,7 +1645,7 @@ impl WithOptParam { None } - pub fn expect_local(self) -> WithOptParam { + pub fn expect_local(self) -> WithOptConstParam { self.as_local().unwrap() } @@ -1652,7 +1654,7 @@ impl WithOptParam { } pub fn ty_def_id(self) -> DefId { - self.param_did.unwrap_or(self.did) + self.const_param_did.unwrap_or(self.did) } } diff --git a/src/librustc_middle/ty/query/keys.rs b/src/librustc_middle/ty/query/keys.rs index 557f64d3c1913..cb2b7a662cb4c 100644 --- a/src/librustc_middle/ty/query/keys.rs +++ b/src/librustc_middle/ty/query/keys.rs @@ -105,7 +105,7 @@ impl Key for DefId { } } -impl Key for ty::WithOptParam { +impl Key for ty::WithOptConstParam { type CacheSelector = DefaultCacheSelector; fn query_crate(&self) -> CrateNum { diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 3d16a9f92c98c..c968e2fbde861 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -2210,12 +2210,12 @@ impl<'tcx> Const<'tcx> { /// Literals and const generic parameters are eagerly converted to a constant, everything else /// becomes `Unevaluated`. pub fn from_anon_const(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx Self { - Self::const_arg_from_anon_const(tcx, ty::WithOptParam::dummy(def_id)) + Self::from_opt_const_arg_anon_const(tcx, ty::WithOptConstParam::dummy(def_id)) } - pub fn const_arg_from_anon_const( + pub fn from_opt_const_arg_anon_const( tcx: TyCtxt<'tcx>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, ) -> &'tcx Self { debug!("Const::from_anon_const(def={:?})", def); @@ -2433,7 +2433,7 @@ pub enum ConstKind<'tcx> { /// Used in the HIR by using `Unevaluated` everywhere and later normalizing to one of the other /// variants when the code is monomorphic enough for that. - Unevaluated(ty::WithOptParam, SubstsRef<'tcx>, Option), + Unevaluated(ty::WithOptConstParam, SubstsRef<'tcx>, Option), /// Used to hold computed value. Value(ConstValue<'tcx>), diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 0ca165ee84717..348c50720beb6 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -88,9 +88,9 @@ const DEREF_PROJECTION: &[PlaceElem<'_>; 1] = &[ProjectionElem::Deref]; pub fn provide(providers: &mut Providers) { *providers = Providers { - mir_borrowck: |tcx, did| mir_borrowck(tcx, ty::WithOptParam::dummy(did)), + mir_borrowck: |tcx, did| mir_borrowck(tcx, ty::WithOptConstParam::dummy(did)), mir_borrowck_const_arg: |tcx, (did, param_did)| { - mir_borrowck(tcx, ty::WithOptParam { did, param_did: Some(param_did) }) + mir_borrowck(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) }, ..*providers }; @@ -98,9 +98,9 @@ pub fn provide(providers: &mut Providers) { fn mir_borrowck<'tcx>( tcx: TyCtxt<'tcx>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, ) -> &'tcx BorrowCheckResult<'tcx> { - if def.param_did.is_none() { + if def.const_param_did.is_none() { if let Some(param_did) = tcx.opt_const_param_of(def.did) { return tcx.mir_borrowck_const_arg((def.did, param_did)); } @@ -123,7 +123,7 @@ fn do_mir_borrowck<'a, 'tcx>( infcx: &InferCtxt<'a, 'tcx>, input_body: &Body<'tcx>, input_promoted: &IndexVec>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, ) -> BorrowCheckResult<'tcx> { debug!("do_mir_borrowck(def = {:?})", def); diff --git a/src/librustc_mir/borrow_check/nll.rs b/src/librustc_mir/borrow_check/nll.rs index f1e7f4c26f4b4..f6b3be59d9576 100644 --- a/src/librustc_mir/borrow_check/nll.rs +++ b/src/librustc_mir/borrow_check/nll.rs @@ -59,7 +59,7 @@ crate struct NllOutput<'tcx> { /// `compute_regions`. pub(in crate::borrow_check) fn replace_regions_in_mir<'cx, 'tcx>( infcx: &InferCtxt<'cx, 'tcx>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, param_env: ty::ParamEnv<'tcx>, body: &mut Body<'tcx>, promoted: &mut IndexVec>, diff --git a/src/librustc_mir/borrow_check/universal_regions.rs b/src/librustc_mir/borrow_check/universal_regions.rs index 1e2d94a1df41e..2faf7fa9022a1 100644 --- a/src/librustc_mir/borrow_check/universal_regions.rs +++ b/src/librustc_mir/borrow_check/universal_regions.rs @@ -227,7 +227,7 @@ impl<'tcx> UniversalRegions<'tcx> { /// known between those regions. pub fn new( infcx: &InferCtxt<'_, 'tcx>, - mir_def: ty::WithOptParam, + mir_def: ty::WithOptConstParam, param_env: ty::ParamEnv<'tcx>, ) -> Self { let tcx = infcx.tcx; @@ -388,7 +388,7 @@ impl<'tcx> UniversalRegions<'tcx> { struct UniversalRegionsBuilder<'cx, 'tcx> { infcx: &'cx InferCtxt<'cx, 'tcx>, - mir_def: ty::WithOptParam, + mir_def: ty::WithOptConstParam, mir_hir_id: HirId, param_env: ty::ParamEnv<'tcx>, } diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 5ee93dfc446a4..42ac4d126a138 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -491,10 +491,13 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { unsafety_check_result: |tcx, def_id| { - unsafety_check_result(tcx, ty::WithOptParam::dummy(def_id)) + unsafety_check_result(tcx, ty::WithOptConstParam::dummy(def_id)) }, unsafety_check_result_const_arg: |tcx, (did, param_did)| { - unsafety_check_result(tcx, ty::WithOptParam { did, param_did: Some(param_did) }) + unsafety_check_result( + tcx, + ty::WithOptConstParam { did, const_param_did: Some(param_did) }, + ) }, unsafe_derive_on_repr_packed, ..*providers @@ -546,9 +549,9 @@ fn check_unused_unsafe( fn unsafety_check_result<'tcx>( tcx: TyCtxt<'tcx>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, ) -> &'tcx UnsafetyCheckResult { - if def.param_did.is_none() { + if def.const_param_did.is_none() { if let Some(param_did) = tcx.opt_const_param_of(def.did) { return tcx.unsafety_check_result_const_arg((def.did, param_did)); } diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index f2d6efae0192a..ce8e71d878b00 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -49,10 +49,10 @@ pub(crate) fn provide(providers: &mut Providers) { mir_keys, mir_const, mir_const_qualif: |tcx, did| { - mir_const_qualif(tcx, ty::WithOptParam::dummy(did.expect_local())) + mir_const_qualif(tcx, ty::WithOptConstParam::dummy(did.expect_local())) }, mir_const_qualif_const_arg: |tcx, (did, param_did)| { - mir_const_qualif(tcx, ty::WithOptParam { did, param_did: Some(param_did) }) + mir_const_qualif(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) }, mir_validated, mir_drops_elaborated_and_const_checked, @@ -60,10 +60,10 @@ pub(crate) fn provide(providers: &mut Providers) { optimized_mir_of_const_arg, is_mir_available, promoted_mir: |tcx, def_id| { - promoted_mir(tcx, ty::WithOptParam::dummy(def_id.expect_local())) + promoted_mir(tcx, ty::WithOptConstParam::dummy(def_id.expect_local())) }, promoted_mir_of_const_arg: |tcx, (did, param_did)| { - promoted_mir(tcx, ty::WithOptParam { did, param_did: Some(param_did) }) + promoted_mir(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) }, ..*providers }; @@ -127,10 +127,13 @@ pub struct MirSource<'tcx> { impl<'tcx> MirSource<'tcx> { pub fn item(def_id: DefId) -> Self { - MirSource { instance: InstanceDef::Item(ty::WithOptParam::dummy(def_id)), promoted: None } + MirSource { + instance: InstanceDef::Item(ty::WithOptConstParam::dummy(def_id)), + promoted: None, + } } - pub fn with_opt_param(self) -> ty::WithOptParam { + pub fn with_opt_param(self) -> ty::WithOptConstParam { self.instance.with_opt_param() } @@ -217,8 +220,8 @@ pub fn run_passes( } } -fn mir_const_qualif(tcx: TyCtxt<'_>, def: ty::WithOptParam) -> ConstQualifs { - if def.param_did.is_none() { +fn mir_const_qualif(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> ConstQualifs { + if def.const_param_did.is_none() { if let Some(param_did) = tcx.opt_const_param_of(def.did) { return tcx.mir_const_qualif_const_arg((def.did, param_did)); } @@ -261,16 +264,16 @@ fn mir_const_qualif(tcx: TyCtxt<'_>, def: ty::WithOptParam) -> Const /// Make MIR ready for const evaluation. This is run on all MIR, not just on consts! fn mir_const<'tcx>( tcx: TyCtxt<'tcx>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, ) -> &'tcx Steal> { - if def.param_did.is_none() { - if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { - return tcx.mir_const(ty::WithOptParam { param_did, ..def }); + if def.const_param_did.is_none() { + if let const_param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + return tcx.mir_const(ty::WithOptConstParam { const_param_did, ..def }); } } // Unsafety check uses the raw mir, so make sure it is run. - if let Some(param_did) = def.param_did { + if let Some(param_did) = def.const_param_did { tcx.ensure().unsafety_check_result_const_arg((def.did, param_did)); } else { tcx.ensure().unsafety_check_result(def.did); @@ -307,11 +310,11 @@ fn mir_const<'tcx>( fn mir_validated( tcx: TyCtxt<'tcx>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, ) -> (&'tcx Steal>, &'tcx Steal>>) { - if def.param_did.is_none() { - if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { - return tcx.mir_validated(ty::WithOptParam { param_did, ..def }); + if def.const_param_did.is_none() { + if let const_param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + return tcx.mir_validated(ty::WithOptConstParam { const_param_did, ..def }); } } @@ -352,18 +355,20 @@ fn mir_validated( fn mir_drops_elaborated_and_const_checked<'tcx>( tcx: TyCtxt<'tcx>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, ) -> &'tcx Steal> { - if def.param_did.is_none() { - if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { - return tcx - .mir_drops_elaborated_and_const_checked(ty::WithOptParam { param_did, ..def }); + if def.const_param_did.is_none() { + if let const_param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + return tcx.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam { + const_param_did, + ..def + }); } } // (Mir-)Borrowck uses `mir_validated`, so we have to force it to // execute before we can steal. - if let Some(param_did) = def.param_did { + if let Some(param_did) = def.const_param_did { tcx.ensure().mir_borrowck_const_arg((def.did, param_did)); } else { tcx.ensure().mir_borrowck(def.did); @@ -409,7 +414,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>( run_passes( tcx, body, - InstanceDef::Item(ty::WithOptParam::dummy(def_id.to_def_id())), + InstanceDef::Item(ty::WithOptConstParam::dummy(def_id.to_def_id())), promoted, MirPhase::DropElab, &[post_borrowck_cleanup], @@ -473,7 +478,7 @@ fn run_optimization_passes<'tcx>( run_passes( tcx, body, - InstanceDef::Item(ty::WithOptParam::dummy(def_id.to_def_id())), + InstanceDef::Item(ty::WithOptConstParam::dummy(def_id.to_def_id())), promoted, MirPhase::Optimized, &[ @@ -488,7 +493,7 @@ fn optimized_mir<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx Body<'tcx> { if let Some(param_did) = tcx.opt_const_param_of(did) { tcx.optimized_mir_of_const_arg((did, param_did)) } else { - tcx.arena.alloc(inner_optimized_mir(tcx, ty::WithOptParam::dummy(did))) + tcx.arena.alloc(inner_optimized_mir(tcx, ty::WithOptConstParam::dummy(did))) } } @@ -496,10 +501,13 @@ fn optimized_mir_of_const_arg<'tcx>( tcx: TyCtxt<'tcx>, (did, param_did): (LocalDefId, DefId), ) -> &'tcx Body<'tcx> { - tcx.arena.alloc(inner_optimized_mir(tcx, ty::WithOptParam { did, param_did: Some(param_did) })) + tcx.arena.alloc(inner_optimized_mir( + tcx, + ty::WithOptConstParam { did, const_param_did: Some(param_did) }, + )) } -fn inner_optimized_mir(tcx: TyCtxt<'_>, def: ty::WithOptParam) -> Body<'_> { +fn inner_optimized_mir(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> Body<'_> { if tcx.is_constructor(def.did.to_def_id()) { // There's no reason to run all of the MIR passes on constructors when // we can just output the MIR we want directly. This also saves const @@ -518,9 +526,9 @@ fn inner_optimized_mir(tcx: TyCtxt<'_>, def: ty::WithOptParam) -> Bo fn promoted_mir<'tcx>( tcx: TyCtxt<'tcx>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, ) -> &'tcx IndexVec> { - if def.param_did.is_none() { + if def.const_param_did.is_none() { if let Some(param_did) = tcx.opt_const_param_of(def.did) { return tcx.promoted_mir_of_const_arg((def.did, param_did)); } @@ -530,7 +538,7 @@ fn promoted_mir<'tcx>( return tcx.arena.alloc(IndexVec::new()); } - if let Some(param_did) = def.param_did { + if let Some(param_did) = def.const_param_did { tcx.ensure().mir_borrowck_const_arg((def.did, param_did)); } else { tcx.ensure().mir_borrowck(def.did); diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index 292ff17f4c598..59a8415ef96f0 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -936,7 +936,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { fn promote_candidate( mut self, - def: ty::WithOptParam, + def: ty::WithOptConstParam, candidate: Candidate, next_promoted_id: usize, ) -> Option> { @@ -1099,7 +1099,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> { } pub fn promote_candidates<'tcx>( - def: ty::WithOptParam, + def: ty::WithOptConstParam, body: &mut Body<'tcx>, tcx: TyCtxt<'tcx>, mut temps: IndexVec, diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 9b6dd2dc268a1..e01badde21794 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -249,7 +249,7 @@ pub fn write_mir_pretty<'tcx>( for (i, body) in tcx.promoted_mir(def_id).iter_enumerated() { writeln!(w)?; let src = MirSource { - instance: ty::InstanceDef::Item(ty::WithOptParam::dummy(def_id)), + instance: ty::InstanceDef::Item(ty::WithOptConstParam::dummy(def_id)), promoted: Some(i), }; write_mir_fn(tcx, src, body, &mut |_, _| Ok(()), w)?; diff --git a/src/librustc_mir_build/build/mod.rs b/src/librustc_mir_build/build/mod.rs index 4aa3e87d41529..21a5ea0aae305 100644 --- a/src/librustc_mir_build/build/mod.rs +++ b/src/librustc_mir_build/build/mod.rs @@ -21,10 +21,10 @@ use rustc_target::spec::PanicStrategy; use super::lints; -crate fn mir_built<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptParam) -> &'tcx ty::steal::Steal> { - if def.param_did.is_none() { - if let param_did @ Some(_) = tcx.opt_const_param_of(def.did) { - return tcx.mir_built(ty::WithOptParam { param_did, ..def }); +crate fn mir_built<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptConstParam) -> &'tcx ty::steal::Steal> { + if def.const_param_did.is_none() { + if let const_param_did @ Some(_) = tcx.opt_const_param_of(def.did) { + return tcx.mir_built(ty::WithOptConstParam { const_param_did, ..def }); } } @@ -32,7 +32,7 @@ crate fn mir_built<'tcx>(tcx: TyCtxt<'tcx>, def: ty::WithOptParam) - } /// Construct the MIR for a given `DefId`. -fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptParam) -> Body<'_> { +fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam) -> Body<'_> { let id = tcx.hir().as_local_hir_id(def.did); // Figure out what primary body this item has. diff --git a/src/librustc_mir_build/hair/cx/expr.rs b/src/librustc_mir_build/hair/cx/expr.rs index 025ef1ece4603..8692363d00635 100644 --- a/src/librustc_mir_build/hair/cx/expr.rs +++ b/src/librustc_mir_build/hair/cx/expr.rs @@ -601,7 +601,7 @@ fn make_mirror_unadjusted<'a, 'tcx>( let substs = InternalSubsts::identity_for_item(cx.tcx(), did); let lhs = mk_const(cx.tcx().mk_const(ty::Const { val: ty::ConstKind::Unevaluated( - ty::WithOptParam::dummy(did), + ty::WithOptConstParam::dummy(did), substs, None, ), @@ -800,7 +800,11 @@ fn convert_path_expr<'a, 'tcx>( debug!("convert_path_expr: (const) user_ty={:?}", user_ty); ExprKind::Literal { literal: cx.tcx.mk_const(ty::Const { - val: ty::ConstKind::Unevaluated(ty::WithOptParam::dummy(def_id), substs, None), + val: ty::ConstKind::Unevaluated( + ty::WithOptConstParam::dummy(def_id), + substs, + None, + ), ty: cx.tables().node_type(expr.hir_id), }), user_ty, diff --git a/src/librustc_mir_build/hair/cx/mod.rs b/src/librustc_mir_build/hair/cx/mod.rs index 7daf7b629d852..12d1c637fb006 100644 --- a/src/librustc_mir_build/hair/cx/mod.rs +++ b/src/librustc_mir_build/hair/cx/mod.rs @@ -52,7 +52,7 @@ crate struct Cx<'a, 'tcx> { impl<'a, 'tcx> Cx<'a, 'tcx> { crate fn new( infcx: &'a InferCtxt<'a, 'tcx>, - def: ty::WithOptParam, + def: ty::WithOptConstParam, src_id: hir::HirId, ) -> Cx<'a, 'tcx> { let tcx = infcx.tcx; diff --git a/src/librustc_ty/instance.rs b/src/librustc_ty/instance.rs index 0a1d8c1077a0b..6de08bd04893d 100644 --- a/src/librustc_ty/instance.rs +++ b/src/librustc_ty/instance.rs @@ -21,24 +21,26 @@ fn resolve_instance<'tcx>( } } - inner_resolve_instance(tcx, param_env.and((ty::WithOptParam::dummy(did), substs))) + inner_resolve_instance(tcx, param_env.and((ty::WithOptConstParam::dummy(did), substs))) } fn resolve_instance_of_const_arg<'tcx>( tcx: TyCtxt<'tcx>, key: ty::ParamEnvAnd<'tcx, (LocalDefId, DefId, SubstsRef<'tcx>)>, ) -> Result>, ErrorReported> { - let (param_env, (did, param_did, substs)) = key.into_parts(); + let (param_env, (did, const_param_did, substs)) = key.into_parts(); inner_resolve_instance( tcx, - param_env - .and((ty::WithOptParam { did: did.to_def_id(), param_did: Some(param_did) }, substs)), + param_env.and(( + ty::WithOptConstParam { did: did.to_def_id(), const_param_did: Some(const_param_did) }, + substs, + )), ) } fn inner_resolve_instance<'tcx>( tcx: TyCtxt<'tcx>, - key: ty::ParamEnvAnd<'tcx, (ty::WithOptParam, SubstsRef<'tcx>)>, + key: ty::ParamEnvAnd<'tcx, (ty::WithOptConstParam, SubstsRef<'tcx>)>, ) -> Result>, ErrorReported> { let (param_env, (def, substs)) = key.into_parts(); @@ -208,7 +210,9 @@ fn resolve_associated_item<'tcx>( Some(ty::Instance::new(leaf_def.item.def_id, substs)) } traits::ImplSourceGenerator(generator_data) => Some(Instance { - def: ty::InstanceDef::Item(ty::WithOptParam::dummy(generator_data.generator_def_id)), + def: ty::InstanceDef::Item(ty::WithOptConstParam::dummy( + generator_data.generator_def_id, + )), substs: generator_data.substs, }), traits::ImplSourceClosure(closure_data) => { diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index eeb14352ca0f3..37f48f82ea674 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -886,11 +886,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { } } (GenericParamDefKind::Const, GenericArg::Const(ct)) => { - ty::Const::const_arg_from_anon_const( + ty::Const::from_opt_const_arg_anon_const( tcx, - ty::WithOptParam { + ty::WithOptConstParam { did: tcx.hir().local_def_id(ct.value.hir_id), - param_did: Some(param.def_id), + const_param_did: Some(param.def_id), }, ) .into() diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index fd2a0175cf66c..9a8d78940ba0d 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -3560,11 +3560,11 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { ast_c: &hir::AnonConst, param_def_id: DefId, ) -> &'tcx ty::Const<'tcx> { - let const_def = ty::WithOptParam { + let const_def = ty::WithOptConstParam { did: self.tcx.hir().local_def_id(ast_c.hir_id), - param_did: Some(param_def_id), + const_param_did: Some(param_def_id), }; - let c = ty::Const::const_arg_from_anon_const(self.tcx, const_def); + let c = ty::Const::from_opt_const_arg_anon_const(self.tcx, const_def); self.register_wf_obligation( c.into(), self.tcx.hir().span(ast_c.hir_id), diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index f64dce5132da0..30aa861e55de4 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -424,7 +424,7 @@ fn check_type_defn<'tcx, F>( cause, fcx.param_env, ty::PredicateKind::ConstEvaluatable( - ty::WithOptParam::dummy(discr_def_id.to_def_id()), + ty::WithOptConstParam::dummy(discr_def_id.to_def_id()), discr_substs, ) .to_predicate(fcx.tcx), diff --git a/src/test/mir-opt/const-promotion-extern-static/rustc.BAR.PromoteTemps.diff b/src/test/mir-opt/const-promotion-extern-static/rustc.BAR.PromoteTemps.diff index a39ad96739205..0e0d8ea906311 100644 --- a/src/test/mir-opt/const-promotion-extern-static/rustc.BAR.PromoteTemps.diff +++ b/src/test/mir-opt/const-promotion-extern-static/rustc.BAR.PromoteTemps.diff @@ -22,7 +22,7 @@ - // + ty: &i32 - // + val: Value(Scalar(alloc0)) + // + ty: &[&i32; 1] -+ // + val: Unevaluated(WithOptParam { did: DefId(0:6 ~ const_promotion_extern_static[317d]::BAR[0]), param_did: None }, [], Some(promoted[0])) ++ // + val: Unevaluated(WithOptConstParam { did: DefId(0:6 ~ const_promotion_extern_static[317d]::BAR[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant - // + span: $DIR/const-promotion-extern-static.rs:9:33: 9:34 - // + literal: Const { ty: &i32, val: Value(Scalar(alloc0)) } @@ -30,7 +30,7 @@ - _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35 - _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35 + // + span: $DIR/const-promotion-extern-static.rs:9:31: 9:35 -+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(WithOptParam { did: DefId(0:6 ~ const_promotion_extern_static[317d]::BAR[0]), param_did: None }, [], Some(promoted[0])) } ++ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(WithOptConstParam { did: DefId(0:6 ~ const_promotion_extern_static[317d]::BAR[0]), const_param_did: None }, [], Some(promoted[0])) } + _2 = &(*_6); // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35 _1 = move _2 as &[&i32] (Pointer(Unsize)); // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:35 _0 = const core::slice::::as_ptr(move _1) -> [return: bb2, unwind: bb1]; // scope 0 at $DIR/const-promotion-extern-static.rs:9:31: 9:44 diff --git a/src/test/mir-opt/const-promotion-extern-static/rustc.FOO.PromoteTemps.diff b/src/test/mir-opt/const-promotion-extern-static/rustc.FOO.PromoteTemps.diff index e9ca064129947..a885b4d3bae1b 100644 --- a/src/test/mir-opt/const-promotion-extern-static/rustc.FOO.PromoteTemps.diff +++ b/src/test/mir-opt/const-promotion-extern-static/rustc.FOO.PromoteTemps.diff @@ -24,7 +24,7 @@ - // + ty: &i32 - // + val: Value(Scalar(alloc2)) + // + ty: &[&i32; 1] -+ // + val: Unevaluated(WithOptParam { did: DefId(0:7 ~ const_promotion_extern_static[317d]::FOO[0]), param_did: None }, [], Some(promoted[0])) ++ // + val: Unevaluated(WithOptConstParam { did: DefId(0:7 ~ const_promotion_extern_static[317d]::FOO[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant - // + span: $DIR/const-promotion-extern-static.rs:13:42: 13:43 - // + literal: Const { ty: &i32, val: Value(Scalar(alloc2)) } @@ -32,7 +32,7 @@ - _3 = [move _4]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46 - _2 = &_3; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46 + // + span: $DIR/const-promotion-extern-static.rs:13:31: 13:46 -+ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(WithOptParam { did: DefId(0:7 ~ const_promotion_extern_static[317d]::FOO[0]), param_did: None }, [], Some(promoted[0])) } ++ // + literal: Const { ty: &[&i32; 1], val: Unevaluated(WithOptConstParam { did: DefId(0:7 ~ const_promotion_extern_static[317d]::FOO[0]), const_param_did: None }, [], Some(promoted[0])) } + _2 = &(*_6); // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46 _1 = move _2 as &[&i32] (Pointer(Unsize)); // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:46 _0 = const core::slice::::as_ptr(move _1) -> [return: bb2, unwind: bb1]; // scope 0 at $DIR/const-promotion-extern-static.rs:13:31: 13:55 diff --git a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff index 0ad68b9f6c705..0f9c81943eda9 100644 --- a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/32bit/rustc.main.ConstProp.diff @@ -28,10 +28,10 @@ _9 = const main::promoted[0]; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 // ty::Const // + ty: &[i32; 3] - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 - // + literal: Const { ty: &[i32; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &[i32; 3], val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } _3 = _9; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 _2 = &raw const (*_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 _1 = move _2 as *const [i32] (Pointer(Unsize)); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 diff --git a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff index c7683305da000..da2c8dffb2411 100644 --- a/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/bad_op_unsafe_oob_for_slices/64bit/rustc.main.ConstProp.diff @@ -28,10 +28,10 @@ _9 = const main::promoted[0]; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 // ty::Const // + ty: &[i32; 3] - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 - // + literal: Const { ty: &[i32; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &[i32; 3], val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ bad_op_unsafe_oob_for_slices[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } _3 = _9; // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 _2 = &raw const (*_3); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 _1 = move _2 as *const [i32] (Pointer(Unsize)); // scope 0 at $DIR/bad_op_unsafe_oob_for_slices.rs:5:25: 5:35 diff --git a/src/test/mir-opt/const_prop/const_prop_fails_gracefully/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/const_prop_fails_gracefully/rustc.main.ConstProp.diff index b09bbead4105d..f3efef387a3b4 100644 --- a/src/test/mir-opt/const_prop/const_prop_fails_gracefully/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/const_prop_fails_gracefully/rustc.main.ConstProp.diff @@ -19,10 +19,10 @@ _3 = const main::FOO; // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 // ty::Const // + ty: &i32 - // + val: Unevaluated(WithOptParam { did: DefId(0:5 ~ const_prop_fails_gracefully[317d]::main[0]::FOO[0]), param_did: None }, [], None) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:5 ~ const_prop_fails_gracefully[317d]::main[0]::FOO[0]), const_param_did: None }, [], None) // mir::Constant // + span: $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 - // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:5 ~ const_prop_fails_gracefully[317d]::main[0]::FOO[0]), param_did: None }, [], None) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:5 ~ const_prop_fails_gracefully[317d]::main[0]::FOO[0]), const_param_did: None }, [], None) } _2 = &raw const (*_3); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:16 _1 = move _2 as usize (Misc); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:13: 7:39 StorageDead(_2); // scope 0 at $DIR/const_prop_fails_gracefully.rs:7:38: 7:39 diff --git a/src/test/mir-opt/const_prop/control-flow-simplification/rustc.hello.ConstProp.diff b/src/test/mir-opt/const_prop/control-flow-simplification/rustc.hello.ConstProp.diff index d8be755632feb..68527a86aeb83 100644 --- a/src/test/mir-opt/const_prop/control-flow-simplification/rustc.hello.ConstProp.diff +++ b/src/test/mir-opt/const_prop/control-flow-simplification/rustc.hello.ConstProp.diff @@ -12,11 +12,11 @@ + _1 = const false; // scope 0 at $DIR/control-flow-simplification.rs:12:8: 12:21 // ty::Const // + ty: bool -- // + val: Unevaluated(WithOptParam { did: DefId(0:4 ~ control_flow_simplification[317d]::NeedsDrop[0]::NEEDS[0]), param_did: None }, [bool], None) +- // + val: Unevaluated(WithOptConstParam { did: DefId(0:4 ~ control_flow_simplification[317d]::NeedsDrop[0]::NEEDS[0]), const_param_did: None }, [bool], None) + // + val: Value(Scalar(0x00)) // mir::Constant // + span: $DIR/control-flow-simplification.rs:12:8: 12:21 -- // + literal: Const { ty: bool, val: Unevaluated(WithOptParam { did: DefId(0:4 ~ control_flow_simplification[317d]::NeedsDrop[0]::NEEDS[0]), param_did: None }, [bool], None) } +- // + literal: Const { ty: bool, val: Unevaluated(WithOptConstParam { did: DefId(0:4 ~ control_flow_simplification[317d]::NeedsDrop[0]::NEEDS[0]), const_param_did: None }, [bool], None) } - switchInt(_1) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/control-flow-simplification.rs:12:5: 14:6 + // + literal: Const { ty: bool, val: Value(Scalar(0x00)) } + switchInt(const false) -> [false: bb1, otherwise: bb2]; // scope 0 at $DIR/control-flow-simplification.rs:12:5: 14:6 diff --git a/src/test/mir-opt/const_prop/ref_deref/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/ref_deref/rustc.main.ConstProp.diff index 0182cb83a967f..ba5ac8d3ddf87 100644 --- a/src/test/mir-opt/const_prop/ref_deref/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/ref_deref/rustc.main.ConstProp.diff @@ -14,10 +14,10 @@ _4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 // ty::Const // + ty: &i32 - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref[317d]::main[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/ref_deref.rs:5:6: 5:10 - // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } _2 = _4; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 - _1 = (*_2); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 + _1 = const 4_i32; // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 diff --git a/src/test/mir-opt/const_prop/ref_deref/rustc.main.PromoteTemps.diff b/src/test/mir-opt/const_prop/ref_deref/rustc.main.PromoteTemps.diff index da915585f82c1..fa68eb348185a 100644 --- a/src/test/mir-opt/const_prop/ref_deref/rustc.main.PromoteTemps.diff +++ b/src/test/mir-opt/const_prop/ref_deref/rustc.main.PromoteTemps.diff @@ -18,13 +18,13 @@ - // + ty: i32 - // + val: Value(Scalar(0x00000004)) + // + ty: &i32 -+ // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref[317d]::main[0]), param_did: None }, [], Some(promoted[0])) ++ // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant - // + span: $DIR/ref_deref.rs:5:8: 5:9 - // + literal: Const { ty: i32, val: Value(Scalar(0x00000004)) } - _2 = &_3; // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 + // + span: $DIR/ref_deref.rs:5:6: 5:10 -+ // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } ++ // + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ ref_deref[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } + _2 = &(*_4); // scope 0 at $DIR/ref_deref.rs:5:6: 5:10 _1 = (*_2); // scope 0 at $DIR/ref_deref.rs:5:5: 5:10 - StorageDead(_3); // scope 0 at $DIR/ref_deref.rs:5:10: 5:11 diff --git a/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.ConstProp.diff index 7ce4635eeb588..483e5f1b9a426 100644 --- a/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.ConstProp.diff @@ -14,10 +14,10 @@ _4 = const main::promoted[0]; // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17 // ty::Const // + ty: &(i32, i32) - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref_project[317d]::main[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/ref_deref_project.rs:5:6: 5:17 - // + literal: Const { ty: &(i32, i32), val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref_project[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &(i32, i32), val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } _2 = &((*_4).1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17 _1 = (*_2); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17 StorageDead(_2); // scope 0 at $DIR/ref_deref_project.rs:5:17: 5:18 diff --git a/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.PromoteTemps.diff b/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.PromoteTemps.diff index 535da0655d5fb..86e6aacab45a7 100644 --- a/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.PromoteTemps.diff +++ b/src/test/mir-opt/const_prop/ref_deref_project/rustc.main.PromoteTemps.diff @@ -18,7 +18,7 @@ - // + ty: i32 - // + val: Value(Scalar(0x00000004)) + // + ty: &(i32, i32) -+ // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref_project[317d]::main[0]), param_did: None }, [], Some(promoted[0])) ++ // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant - // + span: $DIR/ref_deref_project.rs:5:9: 5:10 - // + literal: Const { ty: i32, val: Value(Scalar(0x00000004)) } @@ -30,7 +30,7 @@ - // + literal: Const { ty: i32, val: Value(Scalar(0x00000005)) } - _2 = &(_3.1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17 + // + span: $DIR/ref_deref_project.rs:5:6: 5:17 -+ // + literal: Const { ty: &(i32, i32), val: Unevaluated(WithOptParam { did: DefId(0:3 ~ ref_deref_project[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } ++ // + literal: Const { ty: &(i32, i32), val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ ref_deref_project[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } + _2 = &((*_4).1: i32); // scope 0 at $DIR/ref_deref_project.rs:5:6: 5:17 _1 = (*_2); // scope 0 at $DIR/ref_deref_project.rs:5:5: 5:17 - StorageDead(_3); // scope 0 at $DIR/ref_deref_project.rs:5:17: 5:18 diff --git a/src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff index 7176428d82a43..6eb64f75ef17e 100644 --- a/src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/slice_len/32bit/rustc.main.ConstProp.diff @@ -21,10 +21,10 @@ _9 = const main::promoted[0]; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 // ty::Const // + ty: &[u32; 3] - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ slice_len[317d]::main[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ slice_len[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/slice_len.rs:5:6: 5:19 - // + literal: Const { ty: &[u32; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ slice_len[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &[u32; 3], val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ slice_len[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } _4 = _9; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 _3 = _4; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 _2 = move _3 as &[u32] (Pointer(Unsize)); // scope 0 at $DIR/slice_len.rs:5:6: 5:19 diff --git a/src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff b/src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff index 676e54598a261..2b641bef1d802 100644 --- a/src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff +++ b/src/test/mir-opt/const_prop/slice_len/64bit/rustc.main.ConstProp.diff @@ -21,10 +21,10 @@ _9 = const main::promoted[0]; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 // ty::Const // + ty: &[u32; 3] - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ slice_len[317d]::main[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ slice_len[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/slice_len.rs:5:6: 5:19 - // + literal: Const { ty: &[u32; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ slice_len[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &[u32; 3], val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ slice_len[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } _4 = _9; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 _3 = _4; // scope 0 at $DIR/slice_len.rs:5:6: 5:19 _2 = move _3 as &[u32] (Pointer(Unsize)); // scope 0 at $DIR/slice_len.rs:5:6: 5:19 diff --git a/src/test/mir-opt/inline/inline-retag/rustc.bar.Inline.after.mir b/src/test/mir-opt/inline/inline-retag/rustc.bar.Inline.after.mir index 2149200cefb9c..d6ac1c57a6359 100644 --- a/src/test/mir-opt/inline/inline-retag/rustc.bar.Inline.after.mir +++ b/src/test/mir-opt/inline/inline-retag/rustc.bar.Inline.after.mir @@ -38,10 +38,10 @@ fn bar() -> bool { _10 = const bar::promoted[1]; // scope 1 at $DIR/inline-retag.rs:12:7: 12:9 // ty::Const // + ty: &i32 - // + val: Unevaluated(WithOptParam { did: DefId(0:4 ~ inline_retag[317d]::bar[0]), param_did: None }, [], Some(promoted[1])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:4 ~ inline_retag[317d]::bar[0]), const_param_did: None }, [], Some(promoted[1])) // mir::Constant // + span: $DIR/inline-retag.rs:12:7: 12:9 - // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:4 ~ inline_retag[317d]::bar[0]), param_did: None }, [], Some(promoted[1])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:4 ~ inline_retag[317d]::bar[0]), const_param_did: None }, [], Some(promoted[1])) } Retag(_10); // scope 1 at $DIR/inline-retag.rs:12:7: 12:9 _4 = &(*_10); // scope 1 at $DIR/inline-retag.rs:12:7: 12:9 Retag(_4); // scope 1 at $DIR/inline-retag.rs:12:7: 12:9 @@ -52,10 +52,10 @@ fn bar() -> bool { _9 = const bar::promoted[0]; // scope 1 at $DIR/inline-retag.rs:12:11: 12:14 // ty::Const // + ty: &i32 - // + val: Unevaluated(WithOptParam { did: DefId(0:4 ~ inline_retag[317d]::bar[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:4 ~ inline_retag[317d]::bar[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/inline-retag.rs:12:11: 12:14 - // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:4 ~ inline_retag[317d]::bar[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:4 ~ inline_retag[317d]::bar[0]), const_param_did: None }, [], Some(promoted[0])) } Retag(_9); // scope 1 at $DIR/inline-retag.rs:12:11: 12:14 _7 = &(*_9); // scope 1 at $DIR/inline-retag.rs:12:11: 12:14 Retag(_7); // scope 1 at $DIR/inline-retag.rs:12:11: 12:14 diff --git a/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff b/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff index ebbfd5eaedb3e..cf5d1f3f6c6a4 100644 --- a/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff +++ b/src/test/mir-opt/issue-73223/32bit/rustc.main.PreCodegen.diff @@ -96,10 +96,10 @@ (_5.1: &i32) = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &i32 - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[1])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[1])) } StorageDead(_6); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_7); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL _7 = (_5.0: &i32); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL @@ -140,10 +140,10 @@ _15 = const main::promoted[0] as &[&str] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &[&str; 3] - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &[&str; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &[&str; 3], val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } StorageLive(_18); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL StorageLive(_19); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL StorageLive(_20); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff b/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff index 3d9f9b096b649..91baac8611296 100644 --- a/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/issue-73223/32bit/rustc.main.SimplifyArmIdentity.diff @@ -153,10 +153,10 @@ _51 = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &i32 - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[1])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[1])) } _11 = _51; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_9.0: &i32) = move _10; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_9.1: &i32) = move _11; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL @@ -220,10 +220,10 @@ _50 = const main::promoted[0]; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &[&str; 3] - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &[&str; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &[&str; 3], val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } _25 = _50; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL _24 = _25; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL _23 = move _24 as &[&str] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff b/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff index ebbfd5eaedb3e..cf5d1f3f6c6a4 100644 --- a/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff +++ b/src/test/mir-opt/issue-73223/64bit/rustc.main.PreCodegen.diff @@ -96,10 +96,10 @@ (_5.1: &i32) = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &i32 - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[1])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[1])) } StorageDead(_6); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL StorageLive(_7); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL _7 = (_5.0: &i32); // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL @@ -140,10 +140,10 @@ _15 = const main::promoted[0] as &[&str] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &[&str; 3] - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &[&str; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &[&str; 3], val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } StorageLive(_18); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL StorageLive(_19); // scope 4 at $SRC_DIR/libstd/macros.rs:LL:COL StorageLive(_20); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff b/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff index 2ebf849c9bf29..0da748d79ebdd 100644 --- a/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff +++ b/src/test/mir-opt/issue-73223/64bit/rustc.main.SimplifyArmIdentity.diff @@ -153,10 +153,10 @@ _51 = const main::promoted[1]; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &i32 - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[1])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[1])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[1])) } _11 = _51; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_9.0: &i32) = move _10; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL (_9.1: &i32) = move _11; // scope 3 at $SRC_DIR/libcore/macros/mod.rs:LL:COL @@ -220,10 +220,10 @@ _50 = const main::promoted[0]; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL // ty::Const // + ty: &[&str; 3] - // + val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $SRC_DIR/libcore/macros/mod.rs:LL:COL - // + literal: Const { ty: &[&str; 3], val: Unevaluated(WithOptParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &[&str; 3], val: Unevaluated(WithOptConstParam { did: DefId(0:3 ~ issue_73223[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } _25 = _50; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL _24 = _25; // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL _23 = move _24 as &[&str] (Pointer(Unsize)); // scope 4 at $SRC_DIR/libcore/macros/mod.rs:LL:COL diff --git a/src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir b/src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir index f1f7cb58aadcf..c53c9cf1db7cc 100644 --- a/src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir +++ b/src/test/mir-opt/match_false_edges/rustc.full_tested_match.PromoteTemps.after.mir @@ -76,10 +76,10 @@ fn full_tested_match() -> () { _11 = const full_tested_match::promoted[0]; // scope 0 at $DIR/match_false_edges.rs:16:14: 16:15 // ty::Const // + ty: &std::option::Option - // + val: Unevaluated(WithOptParam { did: DefId(0:5 ~ match_false_edges[317d]::full_tested_match[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:5 ~ match_false_edges[317d]::full_tested_match[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/match_false_edges.rs:16:14: 16:15 - // + literal: Const { ty: &std::option::Option, val: Unevaluated(WithOptParam { did: DefId(0:5 ~ match_false_edges[317d]::full_tested_match[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &std::option::Option, val: Unevaluated(WithOptConstParam { did: DefId(0:5 ~ match_false_edges[317d]::full_tested_match[0]), const_param_did: None }, [], Some(promoted[0])) } _6 = &(((*_11) as Some).0: i32); // scope 0 at $DIR/match_false_edges.rs:16:14: 16:15 _4 = &shallow _2; // scope 0 at $DIR/match_false_edges.rs:15:19: 15:27 StorageLive(_7); // scope 0 at $DIR/match_false_edges.rs:16:20: 16:27 diff --git a/src/test/mir-opt/retag/rustc.main.SimplifyCfg-elaborate-drops.after.mir b/src/test/mir-opt/retag/rustc.main.SimplifyCfg-elaborate-drops.after.mir index a03cabee63267..b61d936837512 100644 --- a/src/test/mir-opt/retag/rustc.main.SimplifyCfg-elaborate-drops.after.mir +++ b/src/test/mir-opt/retag/rustc.main.SimplifyCfg-elaborate-drops.after.mir @@ -184,10 +184,10 @@ fn main() -> () { _27 = const main::promoted[0]; // scope 7 at $DIR/retag.rs:47:21: 47:23 // ty::Const // + ty: &i32 - // + val: Unevaluated(WithOptParam { did: DefId(0:13 ~ retag[317d]::main[0]), param_did: None }, [], Some(promoted[0])) + // + val: Unevaluated(WithOptConstParam { did: DefId(0:13 ~ retag[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) // mir::Constant // + span: $DIR/retag.rs:47:21: 47:23 - // + literal: Const { ty: &i32, val: Unevaluated(WithOptParam { did: DefId(0:13 ~ retag[317d]::main[0]), param_did: None }, [], Some(promoted[0])) } + // + literal: Const { ty: &i32, val: Unevaluated(WithOptConstParam { did: DefId(0:13 ~ retag[317d]::main[0]), const_param_did: None }, [], Some(promoted[0])) } Retag(_27); // scope 7 at $DIR/retag.rs:47:21: 47:23 _23 = &(*_27); // scope 7 at $DIR/retag.rs:47:21: 47:23 Retag(_23); // scope 7 at $DIR/retag.rs:47:21: 47:23 diff --git a/src/tools/clippy/clippy_lints/src/consts.rs b/src/tools/clippy/clippy_lints/src/consts.rs index 6ba4201b2c254..891cb69bb5624 100644 --- a/src/tools/clippy/clippy_lints/src/consts.rs +++ b/src/tools/clippy/clippy_lints/src/consts.rs @@ -332,7 +332,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let result = self .lcx .tcx - .const_eval_resolve(self.param_env, ty::WithOptParam::dummy(def_id), substs, None, None) + .const_eval_resolve(self.param_env, ty::WithOptConstParam::dummy(def_id), substs, None, None) .ok() .map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty))?; let result = miri_to_const(&result); From 8003ccfdcd5731fe00c48f477857bf5ad52c6146 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 15 Jul 2020 10:53:11 +0200 Subject: [PATCH 22/25] ty_def_id -> def_id_for_type_of --- src/librustc_middle/ty/mod.rs | 4 ++-- src/librustc_middle/ty/sty.rs | 2 +- src/librustc_mir/borrow_check/universal_regions.rs | 2 +- src/librustc_ty/instance.rs | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 35b3ad66f0131..26ce8e54a65ca 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1623,7 +1623,7 @@ impl WithOptConstParam { WithOptConstParam { did: self.did.to_def_id(), const_param_did: self.const_param_did } } - pub fn ty_def_id(self) -> DefId { + pub fn def_id_for_type_of(self) -> DefId { if let Some(did) = self.const_param_did { did } else { self.did.to_def_id() } } } @@ -1653,7 +1653,7 @@ impl WithOptConstParam { self.did.is_local() } - pub fn ty_def_id(self) -> DefId { + pub fn def_id_for_type_of(self) -> DefId { self.const_param_did.unwrap_or(self.did) } } diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index c968e2fbde861..8cdfe5e5ac6fd 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -2231,7 +2231,7 @@ impl<'tcx> Const<'tcx> { let expr = &tcx.hir().body(body_id).value; - let ty = tcx.type_of(def.ty_def_id()); + let ty = tcx.type_of(def.def_id_for_type_of()); let lit_input = match expr.kind { hir::ExprKind::Lit(ref lit) => Some(LitToConstInput { lit: &lit.node, ty, neg: false }), diff --git a/src/librustc_mir/borrow_check/universal_regions.rs b/src/librustc_mir/borrow_check/universal_regions.rs index 2faf7fa9022a1..55d817b3f1ce3 100644 --- a/src/librustc_mir/borrow_check/universal_regions.rs +++ b/src/librustc_mir/borrow_check/universal_regions.rs @@ -636,7 +636,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { // For a constant body, there are no inputs, and one // "output" (the type of the constant). assert_eq!(self.mir_def.did.to_def_id(), def_id); - let ty = tcx.type_of(self.mir_def.ty_def_id()); + let ty = tcx.type_of(self.mir_def.def_id_for_type_of()); let ty = indices.fold_to_region_vids(tcx, &ty); ty::Binder::dummy(tcx.intern_type_list(&[ty])) } diff --git a/src/librustc_ty/instance.rs b/src/librustc_ty/instance.rs index 6de08bd04893d..1a3308468bb4c 100644 --- a/src/librustc_ty/instance.rs +++ b/src/librustc_ty/instance.rs @@ -50,7 +50,7 @@ fn inner_resolve_instance<'tcx>( let item = tcx.associated_item(def.did); resolve_associated_item(tcx, &item, param_env, trait_def_id, substs) } else { - let ty = tcx.type_of(def.ty_def_id()); + let ty = tcx.type_of(def.def_id_for_type_of()); let item_type = tcx.subst_and_normalize_erasing_regions(substs, param_env, &ty); let def = match item_type.kind { From aca66bd052cc078edfdaee8500b41d0303e99cf3 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 15 Jul 2020 10:55:41 +0200 Subject: [PATCH 23/25] WithOptConstParam::dummy -> WithOptConstParam::unknown --- src/librustc_interface/passes.rs | 2 +- src/librustc_middle/ty/instance.rs | 4 ++-- src/librustc_middle/ty/mod.rs | 3 ++- src/librustc_middle/ty/sty.rs | 2 +- src/librustc_mir/borrow_check/mod.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 2 +- src/librustc_mir/transform/mod.rs | 12 ++++++------ src/librustc_mir/util/pretty.rs | 2 +- src/librustc_mir_build/hair/cx/expr.rs | 4 ++-- src/librustc_ty/instance.rs | 4 ++-- src/librustc_typeck/check/wfcheck.rs | 2 +- src/tools/clippy/clippy_lints/src/consts.rs | 2 +- 12 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 4357f11776c36..533d0a6d383c4 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -892,7 +892,7 @@ fn analysis(tcx: TyCtxt<'_>, cnum: CrateNum) -> Result<()> { if tcx.hir().body_const_context(def_id).is_some() { tcx.ensure() - .mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::dummy(def_id)); + .mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::unknown(def_id)); } } }); diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index 114ce491f2780..1a5c7fe485984 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -196,7 +196,7 @@ impl<'tcx> InstanceDef<'tcx> { | InstanceDef::Intrinsic(def_id) | InstanceDef::ClosureOnceShim { call_once: def_id } | InstanceDef::DropGlue(def_id, _) - | InstanceDef::CloneShim(def_id, _) => ty::WithOptConstParam::dummy(def_id), + | InstanceDef::CloneShim(def_id, _) => ty::WithOptConstParam::unknown(def_id), } } @@ -298,7 +298,7 @@ impl<'tcx> Instance<'tcx> { def_id, substs ); - Instance { def: InstanceDef::Item(ty::WithOptConstParam::dummy(def_id)), substs } + Instance { def: InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)), substs } } pub fn mono(tcx: TyCtxt<'tcx>, def_id: DefId) -> Instance<'tcx> { diff --git a/src/librustc_middle/ty/mod.rs b/src/librustc_middle/ty/mod.rs index 26ce8e54a65ca..497004b80a5c8 100644 --- a/src/librustc_middle/ty/mod.rs +++ b/src/librustc_middle/ty/mod.rs @@ -1613,7 +1613,8 @@ pub struct WithOptConstParam { } impl WithOptConstParam { - pub fn dummy(did: T) -> WithOptConstParam { + /// Creates a new `WithOptConstParam` setting `const_param_did` to `None`. + pub fn unknown(did: T) -> WithOptConstParam { WithOptConstParam { did, const_param_did: None } } } diff --git a/src/librustc_middle/ty/sty.rs b/src/librustc_middle/ty/sty.rs index 8cdfe5e5ac6fd..3104d2ee36a79 100644 --- a/src/librustc_middle/ty/sty.rs +++ b/src/librustc_middle/ty/sty.rs @@ -2210,7 +2210,7 @@ impl<'tcx> Const<'tcx> { /// Literals and const generic parameters are eagerly converted to a constant, everything else /// becomes `Unevaluated`. pub fn from_anon_const(tcx: TyCtxt<'tcx>, def_id: LocalDefId) -> &'tcx Self { - Self::from_opt_const_arg_anon_const(tcx, ty::WithOptConstParam::dummy(def_id)) + Self::from_opt_const_arg_anon_const(tcx, ty::WithOptConstParam::unknown(def_id)) } pub fn from_opt_const_arg_anon_const( diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 348c50720beb6..d8d988717b824 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -88,7 +88,7 @@ const DEREF_PROJECTION: &[PlaceElem<'_>; 1] = &[ProjectionElem::Deref]; pub fn provide(providers: &mut Providers) { *providers = Providers { - mir_borrowck: |tcx, did| mir_borrowck(tcx, ty::WithOptConstParam::dummy(did)), + mir_borrowck: |tcx, did| mir_borrowck(tcx, ty::WithOptConstParam::unknown(did)), mir_borrowck_const_arg: |tcx, (did, param_did)| { mir_borrowck(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) }, diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 42ac4d126a138..024244582bbf5 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -491,7 +491,7 @@ impl<'a, 'tcx> UnsafetyChecker<'a, 'tcx> { pub(crate) fn provide(providers: &mut Providers) { *providers = Providers { unsafety_check_result: |tcx, def_id| { - unsafety_check_result(tcx, ty::WithOptConstParam::dummy(def_id)) + unsafety_check_result(tcx, ty::WithOptConstParam::unknown(def_id)) }, unsafety_check_result_const_arg: |tcx, (did, param_did)| { unsafety_check_result( diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index ce8e71d878b00..db091b3a0abd9 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -49,7 +49,7 @@ pub(crate) fn provide(providers: &mut Providers) { mir_keys, mir_const, mir_const_qualif: |tcx, did| { - mir_const_qualif(tcx, ty::WithOptConstParam::dummy(did.expect_local())) + mir_const_qualif(tcx, ty::WithOptConstParam::unknown(did.expect_local())) }, mir_const_qualif_const_arg: |tcx, (did, param_did)| { mir_const_qualif(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) @@ -60,7 +60,7 @@ pub(crate) fn provide(providers: &mut Providers) { optimized_mir_of_const_arg, is_mir_available, promoted_mir: |tcx, def_id| { - promoted_mir(tcx, ty::WithOptConstParam::dummy(def_id.expect_local())) + promoted_mir(tcx, ty::WithOptConstParam::unknown(def_id.expect_local())) }, promoted_mir_of_const_arg: |tcx, (did, param_did)| { promoted_mir(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }) @@ -128,7 +128,7 @@ pub struct MirSource<'tcx> { impl<'tcx> MirSource<'tcx> { pub fn item(def_id: DefId) -> Self { MirSource { - instance: InstanceDef::Item(ty::WithOptConstParam::dummy(def_id)), + instance: InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)), promoted: None, } } @@ -414,7 +414,7 @@ fn run_post_borrowck_cleanup_passes<'tcx>( run_passes( tcx, body, - InstanceDef::Item(ty::WithOptConstParam::dummy(def_id.to_def_id())), + InstanceDef::Item(ty::WithOptConstParam::unknown(def_id.to_def_id())), promoted, MirPhase::DropElab, &[post_borrowck_cleanup], @@ -478,7 +478,7 @@ fn run_optimization_passes<'tcx>( run_passes( tcx, body, - InstanceDef::Item(ty::WithOptConstParam::dummy(def_id.to_def_id())), + InstanceDef::Item(ty::WithOptConstParam::unknown(def_id.to_def_id())), promoted, MirPhase::Optimized, &[ @@ -493,7 +493,7 @@ fn optimized_mir<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx Body<'tcx> { if let Some(param_did) = tcx.opt_const_param_of(did) { tcx.optimized_mir_of_const_arg((did, param_did)) } else { - tcx.arena.alloc(inner_optimized_mir(tcx, ty::WithOptConstParam::dummy(did))) + tcx.arena.alloc(inner_optimized_mir(tcx, ty::WithOptConstParam::unknown(did))) } } diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index e01badde21794..990bfc064c2be 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -249,7 +249,7 @@ pub fn write_mir_pretty<'tcx>( for (i, body) in tcx.promoted_mir(def_id).iter_enumerated() { writeln!(w)?; let src = MirSource { - instance: ty::InstanceDef::Item(ty::WithOptConstParam::dummy(def_id)), + instance: ty::InstanceDef::Item(ty::WithOptConstParam::unknown(def_id)), promoted: Some(i), }; write_mir_fn(tcx, src, body, &mut |_, _| Ok(()), w)?; diff --git a/src/librustc_mir_build/hair/cx/expr.rs b/src/librustc_mir_build/hair/cx/expr.rs index 8692363d00635..89ad8a1b3370c 100644 --- a/src/librustc_mir_build/hair/cx/expr.rs +++ b/src/librustc_mir_build/hair/cx/expr.rs @@ -601,7 +601,7 @@ fn make_mirror_unadjusted<'a, 'tcx>( let substs = InternalSubsts::identity_for_item(cx.tcx(), did); let lhs = mk_const(cx.tcx().mk_const(ty::Const { val: ty::ConstKind::Unevaluated( - ty::WithOptConstParam::dummy(did), + ty::WithOptConstParam::unknown(did), substs, None, ), @@ -801,7 +801,7 @@ fn convert_path_expr<'a, 'tcx>( ExprKind::Literal { literal: cx.tcx.mk_const(ty::Const { val: ty::ConstKind::Unevaluated( - ty::WithOptConstParam::dummy(def_id), + ty::WithOptConstParam::unknown(def_id), substs, None, ), diff --git a/src/librustc_ty/instance.rs b/src/librustc_ty/instance.rs index 1a3308468bb4c..0bc6c47097868 100644 --- a/src/librustc_ty/instance.rs +++ b/src/librustc_ty/instance.rs @@ -21,7 +21,7 @@ fn resolve_instance<'tcx>( } } - inner_resolve_instance(tcx, param_env.and((ty::WithOptConstParam::dummy(did), substs))) + inner_resolve_instance(tcx, param_env.and((ty::WithOptConstParam::unknown(did), substs))) } fn resolve_instance_of_const_arg<'tcx>( @@ -210,7 +210,7 @@ fn resolve_associated_item<'tcx>( Some(ty::Instance::new(leaf_def.item.def_id, substs)) } traits::ImplSourceGenerator(generator_data) => Some(Instance { - def: ty::InstanceDef::Item(ty::WithOptConstParam::dummy( + def: ty::InstanceDef::Item(ty::WithOptConstParam::unknown( generator_data.generator_def_id, )), substs: generator_data.substs, diff --git a/src/librustc_typeck/check/wfcheck.rs b/src/librustc_typeck/check/wfcheck.rs index 30aa861e55de4..845a4fcafc224 100644 --- a/src/librustc_typeck/check/wfcheck.rs +++ b/src/librustc_typeck/check/wfcheck.rs @@ -424,7 +424,7 @@ fn check_type_defn<'tcx, F>( cause, fcx.param_env, ty::PredicateKind::ConstEvaluatable( - ty::WithOptConstParam::dummy(discr_def_id.to_def_id()), + ty::WithOptConstParam::unknown(discr_def_id.to_def_id()), discr_substs, ) .to_predicate(fcx.tcx), diff --git a/src/tools/clippy/clippy_lints/src/consts.rs b/src/tools/clippy/clippy_lints/src/consts.rs index 891cb69bb5624..e6ef54f528f4b 100644 --- a/src/tools/clippy/clippy_lints/src/consts.rs +++ b/src/tools/clippy/clippy_lints/src/consts.rs @@ -332,7 +332,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> { let result = self .lcx .tcx - .const_eval_resolve(self.param_env, ty::WithOptConstParam::dummy(def_id), substs, None, None) + .const_eval_resolve(self.param_env, ty::WithOptConstParam::unknown(def_id), substs, None, None) .ok() .map(|val| rustc_middle::ty::Const::from_value(self.lcx.tcx, val, ty))?; let result = miri_to_const(&result); From e070b45e6acb1cb2bbe06485721cb77de1e2469c Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 15 Jul 2020 11:26:26 +0200 Subject: [PATCH 24/25] unsafety_check_result_for_const_arg --- src/librustc_middle/query/mod.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 4 ++-- src/librustc_mir/transform/mod.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index edeefab43421e..0893a0f084470 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -501,7 +501,7 @@ rustc_queries! { desc { |tcx| "unsafety-checking `{}`", tcx.def_path_str(key.to_def_id()) } cache_on_disk_if { true } } - query unsafety_check_result_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult { + query unsafety_check_result_for_const_arg(key: (LocalDefId, DefId)) -> &'tcx mir::UnsafetyCheckResult { desc { |tcx| "unsafety-checking the const argument `{}`", tcx.def_path_str(key.0.to_def_id()) diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 024244582bbf5..2605d45f8101e 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -493,7 +493,7 @@ pub(crate) fn provide(providers: &mut Providers) { unsafety_check_result: |tcx, def_id| { unsafety_check_result(tcx, ty::WithOptConstParam::unknown(def_id)) }, - unsafety_check_result_const_arg: |tcx, (did, param_did)| { + unsafety_check_result_for_const_arg: |tcx, (did, param_did)| { unsafety_check_result( tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) }, @@ -553,7 +553,7 @@ fn unsafety_check_result<'tcx>( ) -> &'tcx UnsafetyCheckResult { if def.const_param_did.is_none() { if let Some(param_did) = tcx.opt_const_param_of(def.did) { - return tcx.unsafety_check_result_const_arg((def.did, param_did)); + return tcx.unsafety_check_result_for_const_arg((def.did, param_did)); } } diff --git a/src/librustc_mir/transform/mod.rs b/src/librustc_mir/transform/mod.rs index db091b3a0abd9..51a9e76e762eb 100644 --- a/src/librustc_mir/transform/mod.rs +++ b/src/librustc_mir/transform/mod.rs @@ -274,7 +274,7 @@ fn mir_const<'tcx>( // Unsafety check uses the raw mir, so make sure it is run. if let Some(param_did) = def.const_param_did { - tcx.ensure().unsafety_check_result_const_arg((def.did, param_did)); + tcx.ensure().unsafety_check_result_for_const_arg((def.did, param_did)); } else { tcx.ensure().unsafety_check_result(def.did); } From 2666aed4989c3bec9cf9f94b2d15beda4e5407f7 Mon Sep 17 00:00:00 2001 From: Bastian Kauschke Date: Wed, 15 Jul 2020 11:45:01 +0200 Subject: [PATCH 25/25] unify Instance::resolve --- src/librustc_middle/mir/interpret/queries.rs | 2 +- src/librustc_middle/ty/instance.rs | 25 +++++++++++--------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/librustc_middle/mir/interpret/queries.rs b/src/librustc_middle/mir/interpret/queries.rs index 0a9c2ac947574..d7c0be058599f 100644 --- a/src/librustc_middle/mir/interpret/queries.rs +++ b/src/librustc_middle/mir/interpret/queries.rs @@ -39,7 +39,7 @@ impl<'tcx> TyCtxt<'tcx> { promoted: Option, span: Option, ) -> ConstEvalResult<'tcx> { - match ty::Instance::resolve_const_arg(self, param_env, def, substs) { + match ty::Instance::resolve_opt_const_arg(self, param_env, def, substs) { Ok(Some(instance)) => { let cid = GlobalId { instance, promoted }; self.const_eval_global_id(param_env, cid, span) diff --git a/src/librustc_middle/ty/instance.rs b/src/librustc_middle/ty/instance.rs index 1a5c7fe485984..f627d05d3e9d2 100644 --- a/src/librustc_middle/ty/instance.rs +++ b/src/librustc_middle/ty/instance.rs @@ -339,27 +339,30 @@ impl<'tcx> Instance<'tcx> { def_id: DefId, substs: SubstsRef<'tcx>, ) -> Result>, ErrorReported> { - // All regions in the result of this query are erased, so it's - // fine to erase all of the input regions. - - // HACK(eddyb) erase regions in `substs` first, so that `param_env.and(...)` - // below is more likely to ignore the bounds in scope (e.g. if the only - // generic parameters mentioned by `substs` were lifetime ones). - let substs = tcx.erase_regions(&substs); - - // FIXME(eddyb) should this always use `param_env.with_reveal_all()`? - tcx.resolve_instance(tcx.erase_regions(¶m_env.and((def_id, substs)))) + Instance::resolve_opt_const_arg( + tcx, + param_env, + ty::WithOptConstParam::unknown(def_id), + substs, + ) } // This should be kept up to date with `resolve`. - pub fn resolve_const_arg( + pub fn resolve_opt_const_arg( tcx: TyCtxt<'tcx>, param_env: ty::ParamEnv<'tcx>, def: ty::WithOptConstParam, substs: SubstsRef<'tcx>, ) -> Result>, ErrorReported> { + // All regions in the result of this query are erased, so it's + // fine to erase all of the input regions. + + // HACK(eddyb) erase regions in `substs` first, so that `param_env.and(...)` + // below is more likely to ignore the bounds in scope (e.g. if the only + // generic parameters mentioned by `substs` were lifetime ones). let substs = tcx.erase_regions(&substs); + // FIXME(eddyb) should this always use `param_env.with_reveal_all()`? if let Some((did, param_did)) = def.as_const_arg() { tcx.resolve_instance_of_const_arg( tcx.erase_regions(¶m_env.and((did, param_did, substs))),