Skip to content

Store DefId instead of EiiDecl in EiiImplResolution::Known#158235

Open
cezarbbb wants to merge 1 commit into
rust-lang:mainfrom
cezarbbb:eii-metadata-opt
Open

Store DefId instead of EiiDecl in EiiImplResolution::Known#158235
cezarbbb wants to merge 1 commit into
rust-lang:mainfrom
cezarbbb:eii-metadata-opt

Conversation

@cezarbbb

@cezarbbb cezarbbb commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Fixes the FIXME(eii) about removing the extern target from the encoded decl.

Known(EiiDecl) serialized the same EiiDecl N+1 times per entry (once as the declaration, once per Known impl). Changing to Known(DefId) eliminates that redundancy — the EiiDecl is recoverable via tcx.externally_implementable_items() or a local lookup map, consistent with how Rust metadata uses DefId as a reference elsewhere.

I believe there are benefits in both performance and size(full EiiDecl to single DefId, and O(N) to O(1) lookup).

Also fixes a soundness gap(I think?) in check_attr.rs where the Known branch skipped impl_unsafe checking, and replaces an .expect() in codegen_attrs.rs with a let Some pattern.

tracking issues: #125418

r? @jdonszelmann

@rustbot

rustbot commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_passes/src/check_attr.rs

cc @jdonszelmann, @JonathanBrouwer

Some changes occurred in compiler/rustc_hir/src/attrs

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jun 22, 2026
@rustbot

rustbot commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

jdonszelmann is currently at their maximum review capacity.
They may take a while to respond.

Comment thread compiler/rustc_metadata/src/eii.rs Outdated
tcx.dcx().span_delayed_bug(
i.span,
"EII impl has Known resolution but can't find EiiDeclaration",
);

@bjorn3 bjorn3 Jun 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this possible in error cases? If it also isn't expected to be possible in error cases this should be a bug!().

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can't happen — Known is only produced by compiler-generated default impls where the foreign item path uses self::, so it always resolves to something in the current crate. Changed to bug!().

// (this is ok since we generate codegen fn attrs in the local crate)
// if any of them is *not default* then don't emit the alias.
&& tcx.externally_implementable_items(LOCAL_CRATE).get(&foreign_item).expect("at least one").1.iter().any(|(_, imp)| !imp.is_default)
&& let Some((_, impls)) = tcx.externally_implementable_items(LOCAL_CRATE).get(&foreign_item)

@bjorn3 bjorn3 Jun 22, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a case where it is expected to get None?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it shouldn't return None — the impl we're processing is itself part of that map's entry. Changed to unwrap_or_else(|| bug!(...)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants