From 872a6da935afa11c9b836d685efd591ca7a64481 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 6 Oct 2022 11:44:42 +0000 Subject: [PATCH 1/6] Remove an unused function --- compiler/rustc_middle/src/ty/generics.rs | 8 -------- 1 file changed, 8 deletions(-) diff --git a/compiler/rustc_middle/src/ty/generics.rs b/compiler/rustc_middle/src/ty/generics.rs index 2e70ac256a7..705adecd3b9 100644 --- a/compiler/rustc_middle/src/ty/generics.rs +++ b/compiler/rustc_middle/src/ty/generics.rs @@ -70,14 +70,6 @@ impl GenericParamDef { } } - pub fn has_default(&self) -> bool { - match self.kind { - GenericParamDefKind::Type { has_default, .. } - | GenericParamDefKind::Const { has_default } => has_default, - GenericParamDefKind::Lifetime => false, - } - } - pub fn is_anonymous_lifetime(&self) -> bool { match self.kind { GenericParamDefKind::Lifetime => { From c787de3bbd307cccbfaeb56421ad7ad898330676 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 11 Oct 2022 19:11:56 +0000 Subject: [PATCH 2/6] Fix some `~const` usage in libcore --- library/core/src/const_closure.rs | 4 ++-- library/core/src/hash/mod.rs | 4 ++-- library/core/src/ops/index.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/library/core/src/const_closure.rs b/library/core/src/const_closure.rs index 151c8e6d898..920c31233c1 100644 --- a/library/core/src/const_closure.rs +++ b/library/core/src/const_closure.rs @@ -51,7 +51,7 @@ macro_rules! impl_fn_mut_tuple { impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const FnOnce for ConstFnMutClosure<($(&'a mut $var),*), Function> where - Function: ~const Fn(($(&mut $var),*), ClosureArguments) -> ClosureReturnValue+ ~const Destruct, + Function: ~const Fn(($(&mut $var),*), ClosureArguments) -> ClosureReturnValue + ~const Destruct, { type Output = ClosureReturnValue; @@ -64,7 +64,7 @@ macro_rules! impl_fn_mut_tuple { impl<'a, $($var,)* ClosureArguments, Function, ClosureReturnValue> const FnMut for ConstFnMutClosure<($(&'a mut $var),*), Function> where - Function: ~const Fn(($(&mut $var),*), ClosureArguments)-> ClosureReturnValue, + Function: ~const Fn(($(&mut $var),*), ClosureArguments)-> ClosureReturnValue + ~const Destruct, { extern "rust-call" fn call_mut(&mut self, args: ClosureArguments) -> Self::Output { #[allow(non_snake_case)] diff --git a/library/core/src/hash/mod.rs b/library/core/src/hash/mod.rs index c755afa39eb..71a0d1825ef 100644 --- a/library/core/src/hash/mod.rs +++ b/library/core/src/hash/mod.rs @@ -199,7 +199,7 @@ pub trait Hash { /// println!("Hash is {:x}!", hasher.finish()); /// ``` #[stable(feature = "rust1", since = "1.0.0")] - fn hash(&self, state: &mut H); + fn hash(&self, state: &mut H); /// Feeds a slice of this type into the given [`Hasher`]. /// @@ -980,7 +980,7 @@ mod impls { #[rustc_const_unstable(feature = "const_hash", issue = "104061")] impl const Hash for &mut T { #[inline] - fn hash(&self, state: &mut H) { + fn hash(&self, state: &mut H) { (**self).hash(state); } } diff --git a/library/core/src/ops/index.rs b/library/core/src/ops/index.rs index 5e3dc48b6ca..228efb0bc0a 100644 --- a/library/core/src/ops/index.rs +++ b/library/core/src/ops/index.rs @@ -165,7 +165,7 @@ see chapter in The Book : Index { +pub trait IndexMut: ~const Index { /// Performs the mutable indexing (`container[index]`) operation. /// /// # Panics From b0ed631ad47a15df6e23f4a34fd2f75162341889 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 10 Nov 2022 08:47:16 +0000 Subject: [PATCH 3/6] Some hir cleanups --- compiler/rustc_middle/src/hir/map/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index 0450abed51b..cf5ebad4032 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -408,7 +408,7 @@ impl<'hir> Map<'hir> { /// item (possibly associated), a closure, or a `hir::AnonConst`. pub fn body_owner(self, BodyId { hir_id }: BodyId) -> HirId { let parent = self.get_parent_node(hir_id); - assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id))); + assert!(self.find(parent).map_or(false, |n| is_body_owner(n, hir_id)), "{hir_id:?}"); parent } @@ -419,7 +419,7 @@ impl<'hir> Map<'hir> { /// Given a `LocalDefId`, returns the `BodyId` associated with it, /// if the node is a body owner, otherwise returns `None`. pub fn maybe_body_owned_by(self, id: LocalDefId) -> Option { - self.get_if_local(id.to_def_id()).map(associated_body).flatten() + self.find_by_def_id(id).and_then(associated_body) } /// Given a body owner's id, returns the `BodyId` associated with it. From b2b859be8ccb2951ffbba7de7461111d9a62883a Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 12 Oct 2022 14:16:31 +0000 Subject: [PATCH 4/6] Some track_caller additions --- compiler/rustc_middle/src/hir/map/mod.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/rustc_middle/src/hir/map/mod.rs b/compiler/rustc_middle/src/hir/map/mod.rs index cf5ebad4032..f5cb89fa624 100644 --- a/compiler/rustc_middle/src/hir/map/mod.rs +++ b/compiler/rustc_middle/src/hir/map/mod.rs @@ -170,6 +170,7 @@ impl<'hir> Map<'hir> { } #[inline] + #[track_caller] pub fn local_def_id(self, hir_id: HirId) -> LocalDefId { self.opt_local_def_id(hir_id).unwrap_or_else(|| { bug!( @@ -310,6 +311,7 @@ impl<'hir> Map<'hir> { } } + #[track_caller] pub fn get_parent_node(self, hir_id: HirId) -> HirId { self.find_parent_node(hir_id) .unwrap_or_else(|| bug!("No parent for node {:?}", self.node_to_string(hir_id))) @@ -334,12 +336,14 @@ impl<'hir> Map<'hir> { } /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found. + #[track_caller] pub fn get(self, id: HirId) -> Node<'hir> { self.find(id).unwrap_or_else(|| bug!("couldn't find hir id {} in the HIR map", id)) } /// Retrieves the `Node` corresponding to `id`, panicking if it cannot be found. #[inline] + #[track_caller] pub fn get_by_def_id(self, id: LocalDefId) -> Node<'hir> { self.find_by_def_id(id).unwrap_or_else(|| bug!("couldn't find {:?} in the HIR map", id)) } @@ -377,6 +381,7 @@ impl<'hir> Map<'hir> { self.tcx.hir_owner_nodes(id.hir_id.owner).unwrap().bodies[&id.hir_id.local_id] } + #[track_caller] pub fn fn_decl_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnDecl<'hir>> { if let Some(node) = self.find(hir_id) { node.fn_decl() @@ -385,6 +390,7 @@ impl<'hir> Map<'hir> { } } + #[track_caller] pub fn fn_sig_by_hir_id(self, hir_id: HirId) -> Option<&'hir FnSig<'hir>> { if let Some(node) = self.find(hir_id) { node.fn_sig() @@ -393,6 +399,7 @@ impl<'hir> Map<'hir> { } } + #[track_caller] pub fn enclosing_body_owner(self, hir_id: HirId) -> LocalDefId { for (_, node) in self.parent_iter(hir_id) { if let Some(body) = associated_body(node) { @@ -423,6 +430,7 @@ impl<'hir> Map<'hir> { } /// Given a body owner's id, returns the `BodyId` associated with it. + #[track_caller] pub fn body_owned_by(self, id: LocalDefId) -> BodyId { self.maybe_body_owned_by(id).unwrap_or_else(|| { let hir_id = self.local_def_id_to_hir_id(id); From fedcc739c6788dbfbb1bfa07cacceaa9fa924382 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Tue, 11 Oct 2022 11:05:41 +0000 Subject: [PATCH 5/6] tracing: make flag checking less noisy --- compiler/rustc_middle/src/ty/visit.rs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/compiler/rustc_middle/src/ty/visit.rs b/compiler/rustc_middle/src/ty/visit.rs index b302572f3ca..d5553f84f75 100644 --- a/compiler/rustc_middle/src/ty/visit.rs +++ b/compiler/rustc_middle/src/ty/visit.rs @@ -88,9 +88,11 @@ pub trait TypeVisitable<'tcx>: fmt::Debug + Clone { self.has_vars_bound_at_or_above(ty::INNERMOST) } - #[instrument(level = "trace", ret)] fn has_type_flags(&self, flags: TypeFlags) -> bool { - self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags) + let res = + self.visit_with(&mut HasTypeFlagsVisitor { flags }).break_value() == Some(FoundFlags); + trace!(?self, ?flags, ?res, "has_type_flags"); + res } fn has_projections(&self) -> bool { self.has_type_flags(TypeFlags::HAS_PROJECTION) @@ -560,10 +562,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { type BreakTy = FoundFlags; #[inline] - #[instrument(skip(self), level = "trace", ret)] fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow { let flags = t.flags(); - trace!(t.flags=?t.flags()); if flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) } else { @@ -572,10 +572,8 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { } #[inline] - #[instrument(skip(self), level = "trace", ret)] fn visit_region(&mut self, r: ty::Region<'tcx>) -> ControlFlow { let flags = r.type_flags(); - trace!(r.flags=?flags); if flags.intersects(self.flags) { ControlFlow::Break(FoundFlags) } else { @@ -584,7 +582,6 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { } #[inline] - #[instrument(level = "trace", ret)] fn visit_const(&mut self, c: ty::Const<'tcx>) -> ControlFlow { let flags = FlagComputation::for_const(c); trace!(r.flags=?flags); @@ -596,14 +593,7 @@ impl<'tcx> TypeVisitor<'tcx> for HasTypeFlagsVisitor { } #[inline] - #[instrument(level = "trace", ret)] fn visit_predicate(&mut self, predicate: ty::Predicate<'tcx>) -> ControlFlow { - debug!( - "HasTypeFlagsVisitor: predicate={:?} predicate.flags={:?} self.flags={:?}", - predicate, - predicate.flags(), - self.flags - ); if predicate.flags().intersects(self.flags) { ControlFlow::Break(FoundFlags) } else { From ed61be60da3b5dd28abd4ec4956df9eb896183c9 Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Wed, 21 Sep 2022 08:14:31 +0000 Subject: [PATCH 6/6] Some ICE debugging aids --- compiler/rustc_middle/src/ty/subst.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index a04b15f8cf1..eeb2afb0349 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -348,7 +348,7 @@ impl<'tcx> InternalSubsts<'tcx> { substs.reserve(defs.params.len()); for param in &defs.params { let kind = mk_kind(param, substs); - assert_eq!(param.index as usize, substs.len()); + assert_eq!(param.index as usize, substs.len(), "{substs:#?}, {defs:#?}"); substs.push(kind); } }