Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 9 pull requests #132277

Merged
merged 23 commits into from
Oct 29, 2024
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
42fbaf1
Add a new trait `proc_macro::ToTokens`
SpriteOvO Oct 9, 2024
4839d6e
compiler: Add rustc_abi dependence to the compiler
workingjubilee Oct 28, 2024
cb08e08
Lower AST node id only once
adwinwhite Sep 12, 2024
1a39247
Add duplicate lowering check
adwinwhite Sep 15, 2024
e3bf50e
more consistent debug_assertions
adwinwhite Oct 14, 2024
3f73fe7
compiler: Depend on rustc_abi in rustc_lint
workingjubilee Oct 28, 2024
7cfbe23
Unify variant struct fields margins with struct fields
GuillaumeGomez Oct 28, 2024
26b6ccd
Add GUI regression test for variant structfields margins
GuillaumeGomez Oct 28, 2024
4bd84b2
Use a type-safe helper to cast `&str` and `&[u8]` to `*const c_char`
Zalathar Oct 28, 2024
82bfe05
refactor: cleaner check to return None
ChrisCho-H Oct 28, 2024
2cc9d58
Updating Fuchsia platform-support documentation
claywilkinson Oct 28, 2024
88a9edc
compiler: Add `is_uninhabited` and use LayoutS accessors
workingjubilee Oct 28, 2024
641ce06
rustdoc: Use accessors to interrogate type layouts
workingjubilee Oct 28, 2024
5f91811
stable_mir: Directly use types from rustc_abi
workingjubilee Oct 28, 2024
a24b377
Rollup merge of #130259 - adwinwhite:lower-node-id-once, r=cjgillot
workingjubilee Oct 28, 2024
c9347f1
Rollup merge of #131441 - SpriteOvO:proc-macro-to-tokens-trait, r=dto…
workingjubilee Oct 28, 2024
e20026c
Rollup merge of #132247 - workingjubilee:add-rustc-abi-to-smir, r=cel…
workingjubilee Oct 28, 2024
d6be363
Rollup merge of #132249 - workingjubilee:add-rustc-abi, r=compiler-er…
workingjubilee Oct 28, 2024
259ddf9
Rollup merge of #132255 - workingjubilee:layout-is-🏚️, r=compiler-errors
workingjubilee Oct 28, 2024
6ea83ff
Rollup merge of #132258 - GuillaumeGomez:variant-structfields-margins…
workingjubilee Oct 28, 2024
bd43f8e
Rollup merge of #132260 - Zalathar:type-safe-cast, r=compiler-errors
workingjubilee Oct 28, 2024
6fd4a76
Rollup merge of #132261 - ChrisCho-H:refactor/cleaner-check-none, r=c…
workingjubilee Oct 28, 2024
89ac69f
Rollup merge of #132271 - claywilkinson:master, r=tmandry
workingjubilee Oct 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add duplicate lowering check
adwinwhite committed Oct 28, 2024
commit 1a39247d8dce70554964368046abcae9722675b6
9 changes: 0 additions & 9 deletions compiler/rustc_ast_lowering/src/block.rs
Original file line number Diff line number Diff line change
@@ -14,15 +14,6 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.arena.alloc(self.lower_block_noalloc(hir_id, b, targeted_by_break))
}

pub(super) fn lower_block_with_hir_id(
&mut self,
b: &Block,
hir_id: hir::HirId,
targeted_by_break: bool,
) -> &'hir hir::Block<'hir> {
self.arena.alloc(self.lower_block_noalloc(hir_id, b, targeted_by_break))
}

pub(super) fn lower_block_noalloc(
&mut self,
hir_id: hir::HirId,
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/delegation.rs
Original file line number Diff line number Diff line change
@@ -260,7 +260,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
};
self_resolver.visit_block(block);
// Target expr needs to lower `self` path.
this.ident_to_local_id.insert(pat_node_id, param.pat.hir_id.local_id);
this.ident_and_label_to_local_id.insert(pat_node_id, param.pat.hir_id.local_id);
this.lower_target_expr(&block)
} else {
this.generate_arg(param.pat.hir_id, span)
14 changes: 8 additions & 6 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
@@ -261,10 +261,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
// expr node id.
let block_hir_id = self.lower_node_id(blk.id);
let opt_label = self.lower_label(*opt_label, blk.id, block_hir_id);
hir::ExprKind::Block(
self.lower_block_with_hir_id(blk, block_hir_id, opt_label.is_some()),
opt_label,
)
let hir_block = self.arena.alloc(self.lower_block_noalloc(
block_hir_id,
blk,
opt_label.is_some(),
));
hir::ExprKind::Block(hir_block, opt_label)
}
ExprKind::Assign(el, er, span) => self.lower_expr_assign(el, er, *span, e.span),
ExprKind::AssignOp(op, el, er) => hir::ExprKind::AssignOp(
@@ -1486,15 +1488,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
dest_hir_id: hir::HirId,
) -> Option<Label> {
let label = opt_label?;
self.labelled_node_id_to_local_id.insert(dest_id, dest_hir_id.local_id);
self.ident_and_label_to_local_id.insert(dest_id, dest_hir_id.local_id);
Some(Label { ident: self.lower_ident(label.ident) })
}

fn lower_loop_destination(&mut self, destination: Option<(NodeId, Label)>) -> hir::Destination {
let target_id = match destination {
Some((id, _)) => {
if let Some(loop_id) = self.resolver.get_label_res(id) {
let local_id = self.labelled_node_id_to_local_id[&loop_id];
let local_id = self.ident_and_label_to_local_id[&loop_id];
let loop_hir_id = HirId { owner: self.current_hir_id_owner, local_id };
Ok(loop_hir_id)
} else {
12 changes: 4 additions & 8 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
@@ -154,8 +154,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_item(&mut self, i: &Item) -> &'hir hir::Item<'hir> {
let mut ident = i.ident;
let vis_span = self.lower_span(i.vis.span);
let hir_id =
hir::HirId { owner: self.current_hir_id_owner, local_id: hir::ItemLocalId::ZERO };
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
let attrs = self.lower_attrs(hir_id, &i.attrs);
let kind = self.lower_item_kind(i.span, i.id, hir_id, &mut ident, attrs, vis_span, &i.kind);
let item = hir::Item {
@@ -605,8 +604,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_foreign_item(&mut self, i: &ForeignItem) -> &'hir hir::ForeignItem<'hir> {
let hir_id =
hir::HirId { owner: self.current_hir_id_owner, local_id: hir::ItemLocalId::ZERO };
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
let owner_id = hir_id.expect_owner();
self.lower_attrs(hir_id, &i.attrs);
let item = hir::ForeignItem {
@@ -730,8 +728,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}

fn lower_trait_item(&mut self, i: &AssocItem) -> &'hir hir::TraitItem<'hir> {
let hir_id =
hir::HirId { owner: self.current_hir_id_owner, local_id: hir::ItemLocalId::ZERO };
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
self.lower_attrs(hir_id, &i.attrs);
let trait_item_def_id = hir_id.expect_owner();

@@ -861,8 +858,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// Since `default impl` is not yet implemented, this is always true in impls.
let has_value = true;
let (defaultness, _) = self.lower_defaultness(i.kind.defaultness(), has_value);
let hir_id =
hir::HirId { owner: self.current_hir_id_owner, local_id: hir::ItemLocalId::ZERO };
let hir_id = hir::HirId::make_owner(self.current_hir_id_owner.def_id);
self.lower_attrs(hir_id, &i.attrs);

let (generics, kind) = match &i.kind {
35 changes: 23 additions & 12 deletions compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
@@ -138,10 +138,10 @@ struct LoweringContext<'a, 'hir> {
impl_trait_defs: Vec<hir::GenericParam<'hir>>,
impl_trait_bounds: Vec<hir::WherePredicate<'hir>>,

/// NodeIds of labelled nodes that are lowered inside the current HIR owner.
labelled_node_id_to_local_id: NodeMap<hir::ItemLocalId>,
/// NodeIds of identifier that are lowered inside the current HIR owner.
ident_to_local_id: NodeMap<hir::ItemLocalId>,
/// NodeIds of pattern identifiers and labelled nodes that are lowered inside the current HIR owner.
ident_and_label_to_local_id: NodeMap<hir::ItemLocalId>,
/// NodeIds that are lowered inside the current HIR owner. Only used for duplicate lowering check.
node_id_to_local_id: NodeMap<hir::ItemLocalId>,

allow_try_trait: Lrc<[Symbol]>,
allow_gen_future: Lrc<[Symbol]>,
@@ -171,8 +171,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
current_hir_id_owner: hir::CRATE_OWNER_ID,
current_def_id_parent: CRATE_DEF_ID,
item_local_id_counter: hir::ItemLocalId::ZERO,
labelled_node_id_to_local_id: Default::default(),
ident_to_local_id: Default::default(),
ident_and_label_to_local_id: Default::default(),
node_id_to_local_id: Default::default(),
trait_map: Default::default(),

// Lowering state.
@@ -589,9 +589,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

let current_attrs = std::mem::take(&mut self.attrs);
let current_bodies = std::mem::take(&mut self.bodies);
let current_labelled_node_id_to_local_id =
std::mem::take(&mut self.labelled_node_id_to_local_id);
let current_ident_to_local_id = std::mem::take(&mut self.ident_to_local_id);
let current_ident_and_label_to_local_id =
std::mem::take(&mut self.ident_and_label_to_local_id);
let current_node_id_to_local_id = std::mem::take(&mut self.node_id_to_local_id);
let current_trait_map = std::mem::take(&mut self.trait_map);
let current_owner =
std::mem::replace(&mut self.current_hir_id_owner, hir::OwnerId { def_id });
@@ -604,6 +604,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
// we want `f` to be able to refer to the `LocalDefId`s that the caller created.
// and the caller to refer to some of the subdefinitions' nodes' `LocalDefId`s.

// Always allocate the first `HirId` for the owner itself.
let _old = self.node_id_to_local_id.insert(owner, hir::ItemLocalId::ZERO);
debug_assert_eq!(_old, None);

let item = self.with_def_id_parent(def_id, f);
debug_assert_eq!(def_id, item.def_id().def_id);
// `f` should have consumed all the elements in these vectors when constructing `item`.
@@ -613,8 +617,8 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {

self.attrs = current_attrs;
self.bodies = current_bodies;
self.labelled_node_id_to_local_id = current_labelled_node_id_to_local_id;
self.ident_to_local_id = current_ident_to_local_id;
self.ident_and_label_to_local_id = current_ident_and_label_to_local_id;
self.node_id_to_local_id = current_node_id_to_local_id;
self.trait_map = current_trait_map;
self.current_hir_id_owner = current_owner;
self.item_local_id_counter = current_local_counter;
@@ -703,6 +707,13 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
self.trait_map.insert(hir_id.local_id, traits.into_boxed_slice());
}

// Check whether the same `NodeId` is lowered more than once.
#[cfg(debug_assertions)]
{
let old = self.node_id_to_local_id.insert(ast_node_id, local_id);
assert_eq!(old, None);
}

hir_id
}

@@ -720,7 +731,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_res(&mut self, res: Res<NodeId>) -> Res {
let res: Result<Res, ()> = res.apply_id(|id| {
let owner = self.current_hir_id_owner;
let local_id = self.ident_to_local_id.get(&id).copied().ok_or(())?;
let local_id = self.ident_and_label_to_local_id.get(&id).copied().ok_or(())?;
Ok(HirId { owner, local_id })
});
trace!(?res);
4 changes: 2 additions & 2 deletions compiler/rustc_ast_lowering/src/pat.rs
Original file line number Diff line number Diff line change
@@ -270,12 +270,12 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
};
// All identifiers resolves to this canonical identifier share its `HirId`.
let binding_id = if canonical_id == p.id {
self.ident_to_local_id.insert(canonical_id, hir_id.local_id);
self.ident_and_label_to_local_id.insert(canonical_id, hir_id.local_id);
hir_id
} else {
hir::HirId {
owner: self.current_hir_id_owner,
local_id: self.ident_to_local_id[&canonical_id],
local_id: self.ident_and_label_to_local_id[&canonical_id],
}
};
hir::PatKind::Binding(