Skip to content

Commit

Permalink
Unrolled build for rust-lang#122719
Browse files Browse the repository at this point in the history
Rollup merge of rust-lang#122719 - oli-obk:nested_static_feed_hir, r=fee1-dead

Ensure nested statics have a HIR node to prevent various queries from ICEing

fixes rust-lang/miri#3389
  • Loading branch information
rust-timer authored Mar 19, 2024
2 parents a385e56 + 3a09680 commit c078f86
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 49 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(super) fn index_hir<'hir>(
OwnerNode::TraitItem(item) => collector.visit_trait_item(item),
OwnerNode::ImplItem(item) => collector.visit_impl_item(item),
OwnerNode::ForeignItem(item) => collector.visit_foreign_item(item),
OwnerNode::AssocOpaqueTy(..) => unreachable!(),
OwnerNode::Synthetic => unreachable!(),
};

for (local_id, node) in collector.nodes.iter_enumerated() {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_const_eval/src/interpret/intern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ fn intern_as_new_static<'tcx>(
feed.generics_of(tcx.generics_of(static_id).clone());
feed.def_ident_span(tcx.def_ident_span(static_id));
feed.explicit_predicates_of(tcx.explicit_predicates_of(static_id));

feed.feed_hir()
}

/// How a constant value should be interned.
Expand Down
22 changes: 9 additions & 13 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2552,11 +2552,6 @@ pub struct OpaqueTy<'hir> {
pub in_trait: bool,
}

#[derive(Copy, Clone, Debug, HashStable_Generic)]
pub struct AssocOpaqueTy {
// Add some data if necessary
}

/// From whence the opaque type came.
#[derive(Copy, Clone, PartialEq, Eq, Debug, HashStable_Generic)]
pub enum OpaqueTyOrigin {
Expand Down Expand Up @@ -3367,7 +3362,7 @@ pub enum OwnerNode<'hir> {
TraitItem(&'hir TraitItem<'hir>),
ImplItem(&'hir ImplItem<'hir>),
Crate(&'hir Mod<'hir>),
AssocOpaqueTy(&'hir AssocOpaqueTy),
Synthetic,
}

impl<'hir> OwnerNode<'hir> {
Expand All @@ -3377,7 +3372,7 @@ impl<'hir> OwnerNode<'hir> {
| OwnerNode::ForeignItem(ForeignItem { ident, .. })
| OwnerNode::ImplItem(ImplItem { ident, .. })
| OwnerNode::TraitItem(TraitItem { ident, .. }) => Some(*ident),
OwnerNode::Crate(..) | OwnerNode::AssocOpaqueTy(..) => None,
OwnerNode::Crate(..) | OwnerNode::Synthetic => None,
}
}

Expand All @@ -3390,7 +3385,7 @@ impl<'hir> OwnerNode<'hir> {
| OwnerNode::ImplItem(ImplItem { span, .. })
| OwnerNode::TraitItem(TraitItem { span, .. }) => span,
OwnerNode::Crate(Mod { spans: ModSpans { inner_span, .. }, .. }) => inner_span,
OwnerNode::AssocOpaqueTy(..) => unreachable!(),
OwnerNode::Synthetic => unreachable!(),
}
}

Expand Down Expand Up @@ -3449,7 +3444,7 @@ impl<'hir> OwnerNode<'hir> {
| OwnerNode::ImplItem(ImplItem { owner_id, .. })
| OwnerNode::ForeignItem(ForeignItem { owner_id, .. }) => *owner_id,
OwnerNode::Crate(..) => crate::CRATE_HIR_ID.owner,
OwnerNode::AssocOpaqueTy(..) => unreachable!(),
OwnerNode::Synthetic => unreachable!(),
}
}

Expand Down Expand Up @@ -3493,7 +3488,7 @@ impl<'hir> Into<Node<'hir>> for OwnerNode<'hir> {
OwnerNode::ImplItem(n) => Node::ImplItem(n),
OwnerNode::TraitItem(n) => Node::TraitItem(n),
OwnerNode::Crate(n) => Node::Crate(n),
OwnerNode::AssocOpaqueTy(n) => Node::AssocOpaqueTy(n),
OwnerNode::Synthetic => Node::Synthetic,
}
}
}
Expand Down Expand Up @@ -3531,7 +3526,8 @@ pub enum Node<'hir> {
WhereBoundPredicate(&'hir WhereBoundPredicate<'hir>),
// FIXME: Merge into `Node::Infer`.
ArrayLenInfer(&'hir InferArg),
AssocOpaqueTy(&'hir AssocOpaqueTy),
// Created by query feeding
Synthetic,
// Span by reference to minimize `Node`'s size
#[allow(rustc::pass_by_value)]
Err(&'hir Span),
Expand Down Expand Up @@ -3582,7 +3578,7 @@ impl<'hir> Node<'hir> {
| Node::Infer(..)
| Node::WhereBoundPredicate(..)
| Node::ArrayLenInfer(..)
| Node::AssocOpaqueTy(..)
| Node::Synthetic
| Node::Err(..) => None,
}
}
Expand Down Expand Up @@ -3695,7 +3691,7 @@ impl<'hir> Node<'hir> {
Node::TraitItem(i) => Some(OwnerNode::TraitItem(i)),
Node::ImplItem(i) => Some(OwnerNode::ImplItem(i)),
Node::Crate(i) => Some(OwnerNode::Crate(i)),
Node::AssocOpaqueTy(i) => Some(OwnerNode::AssocOpaqueTy(i)),
Node::Synthetic => Some(OwnerNode::Synthetic),
_ => None,
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ fn check_well_formed(tcx: TyCtxt<'_>, def_id: hir::OwnerId) -> Result<(), ErrorG
hir::OwnerNode::TraitItem(item) => check_trait_item(tcx, item),
hir::OwnerNode::ImplItem(item) => check_impl_item(tcx, item),
hir::OwnerNode::ForeignItem(item) => check_foreign_item(tcx, item),
hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(),
hir::OwnerNode::Synthetic => unreachable!(),
};

if let Some(generics) = node.generics() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ fn resolve_bound_vars(tcx: TyCtxt<'_>, local_def_id: hir::OwnerId) -> ResolveBou
visitor.visit_impl_item(item)
}
hir::OwnerNode::Crate(_) => {}
hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(),
hir::OwnerNode::Synthetic => unreachable!(),
}

let mut rl = ResolveBoundVars::default();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ impl<'a> State<'a> {
self.print_bounds(":", pred.bounds);
}
Node::ArrayLenInfer(_) => self.word("_"),
Node::AssocOpaqueTy(..) => unreachable!(),
Node::Synthetic => unreachable!(),
Node::Err(_) => self.word("/*ERROR*/"),
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2553,7 +2553,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
hir::OwnerNode::ImplItem(i) => visitor.visit_impl_item(i),
hir::OwnerNode::TraitItem(i) => visitor.visit_trait_item(i),
hir::OwnerNode::Crate(_) => bug!("OwnerNode::Crate doesn't not have generics"),
hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(),
hir::OwnerNode::Synthetic => unreachable!(),
}

let ast_generics = self.tcx.hir().get_generics(lifetime_scope).unwrap();
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fn shallow_lint_levels_on(tcx: TyCtxt<'_>, owner: hir::OwnerId) -> ShallowLintLe
levels.add_id(hir::CRATE_HIR_ID);
levels.visit_mod(mod_, mod_.spans.inner_span, hir::CRATE_HIR_ID)
}
hir::OwnerNode::AssocOpaqueTy(..) => unreachable!(),
hir::OwnerNode::Synthetic => unreachable!(),
},
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_middle/src/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ impl<'hir> Map<'hir> {
Node::Crate(item) => item.spans.inner_span,
Node::WhereBoundPredicate(pred) => pred.span,
Node::ArrayLenInfer(inf) => inf.span,
Node::AssocOpaqueTy(..) => unreachable!(),
Node::Synthetic => unreachable!(),
Node::Err(span) => *span,
}
}
Expand Down Expand Up @@ -1179,7 +1179,7 @@ fn hir_id_to_string(map: Map<'_>, id: HirId) -> String {
Node::Crate(..) => String::from("(root_crate)"),
Node::WhereBoundPredicate(_) => node_str("where bound predicate"),
Node::ArrayLenInfer(_) => node_str("array len infer"),
Node::AssocOpaqueTy(..) => unreachable!(),
Node::Synthetic => unreachable!(),
Node::Err(_) => node_str("error"),
}
}
Expand Down
21 changes: 21 additions & 0 deletions compiler/rustc_middle/src/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,27 @@ impl<'tcx> TyCtxtFeed<'tcx, LocalDefId> {
pub fn feed_owner_id(&self) -> TyCtxtFeed<'tcx, hir::OwnerId> {
TyCtxtFeed { tcx: self.tcx, key: hir::OwnerId { def_id: self.key } }
}

// Fills in all the important parts needed by HIR queries
pub fn feed_hir(&self) {
self.local_def_id_to_hir_id(HirId::make_owner(self.def_id()));

let node = hir::OwnerNode::Synthetic;
let bodies = Default::default();
let attrs = hir::AttributeMap::EMPTY;

let (opt_hash_including_bodies, _) = self.tcx.hash_owner_nodes(node, &bodies, &attrs.map);
let node = node.into();
self.opt_hir_owner_nodes(Some(self.tcx.arena.alloc(hir::OwnerNodes {
opt_hash_including_bodies,
nodes: IndexVec::from_elem_n(
hir::ParentedNode { parent: hir::ItemLocalId::INVALID, node },
1,
),
bodies,
})));
self.feed_owner_id().hir_attrs(attrs);
}
}

/// The central data structure of the compiler. It stores references
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_passes/src/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ impl<'tcx> ReachableContext<'tcx> {
| Node::Field(_)
| Node::Ty(_)
| Node::Crate(_)
| Node::AssocOpaqueTy(..) => {}
| Node::Synthetic => {}
_ => {
bug!(
"found unexpected node kind in worklist: {} ({:?})",
Expand Down
31 changes: 4 additions & 27 deletions compiler/rustc_ty_utils/src/assoc.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use rustc_data_structures::fx::FxIndexSet;
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{self as hir, HirId};
use rustc_index::IndexVec;
use rustc_middle::query::Providers;
use rustc_middle::ty::{self, ImplTraitInTraitData, TyCtxt, TyCtxtFeed};
use rustc_middle::ty::{self, ImplTraitInTraitData, TyCtxt};
use rustc_span::symbol::kw;

pub(crate) fn provide(providers: &mut Providers) {
Expand Down Expand Up @@ -238,28 +237,6 @@ fn associated_types_for_impl_traits_in_associated_fn(
}
}

fn feed_hir(feed: &TyCtxtFeed<'_, LocalDefId>) {
feed.local_def_id_to_hir_id(HirId::make_owner(feed.def_id()));

let node = hir::OwnerNode::AssocOpaqueTy(&hir::AssocOpaqueTy {});
let bodies = Default::default();
let attrs = hir::AttributeMap::EMPTY;

let (opt_hash_including_bodies, _) = feed.tcx.hash_owner_nodes(node, &bodies, &attrs.map);
feed.opt_hir_owner_nodes(Some(feed.tcx.arena.alloc(hir::OwnerNodes {
opt_hash_including_bodies,
nodes: IndexVec::from_elem_n(
hir::ParentedNode {
parent: hir::ItemLocalId::INVALID,
node: hir::Node::AssocOpaqueTy(&hir::AssocOpaqueTy {}),
},
1,
),
bodies,
})));
feed.feed_owner_id().hir_attrs(attrs);
}

/// Given an `opaque_ty_def_id` corresponding to an `impl Trait` in an associated
/// function from a trait, synthesize an associated type for that `impl Trait`
/// that inherits properties that we infer from the method and the opaque type.
Expand All @@ -281,7 +258,7 @@ fn associated_type_for_impl_trait_in_trait(
let local_def_id = trait_assoc_ty.def_id();
let def_id = local_def_id.to_def_id();

feed_hir(&trait_assoc_ty);
trait_assoc_ty.feed_hir();

// Copy span of the opaque.
trait_assoc_ty.def_ident_span(Some(span));
Expand Down Expand Up @@ -335,7 +312,7 @@ fn associated_type_for_impl_trait_in_impl(
let local_def_id = impl_assoc_ty.def_id();
let def_id = local_def_id.to_def_id();

feed_hir(&impl_assoc_ty);
impl_assoc_ty.feed_hir();

// Copy span of the opaque.
impl_assoc_ty.def_ident_span(Some(span));
Expand Down

0 comments on commit c078f86

Please sign in to comment.