Skip to content

Support defaults for static EIIs#156583

Open
AsakuraMizu wants to merge 2 commits into
rust-lang:mainfrom
AsakuraMizu:eii-static-default
Open

Support defaults for static EIIs#156583
AsakuraMizu wants to merge 2 commits into
rust-lang:mainfrom
AsakuraMizu:eii-static-default

Conversation

@AsakuraMizu

@AsakuraMizu AsakuraMizu commented May 14, 2026

Copy link
Copy Markdown
Contributor

View all comments

Tracking issue: #125418

#154193 added EII support for statics, but left default implementations for "a followup PR". This PR implements it.

Maybe I should remove no-prefer-dynamic if #156577 is accepted.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 14, 2026
@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label May 14, 2026
@rustbot

rustbot commented May 14, 2026

Copy link
Copy Markdown
Collaborator

r? @mu001999

rustbot has assigned @mu001999.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 73 candidates
  • Random selection from 17 candidates

@mu001999 mu001999 left a comment

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.

LGTM, but I’ll defer to @JonathanBrouwer in case I’ve missed anything.

r? JonathanBrouwer

View changes since this review

@rustbot rustbot assigned JonathanBrouwer and unassigned mu001999 May 15, 2026
@rustbot

rustbot commented May 15, 2026

Copy link
Copy Markdown
Collaborator

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

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

I'm currently on holidays but would like to take a look, might take me a few days to get around to it

@AsakuraMizu AsakuraMizu force-pushed the eii-static-default branch from 81c9617 to d7f16d7 Compare May 15, 2026 19:27

@JonathanBrouwer JonathanBrouwer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@bors r+ rollup
Looks good, thanks!
Wanted to implement this immediately after my PR that implemented static EIIs but forgot :3

View changes since this review

@rust-bors

rust-bors Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit d7f16d7 has been approved by JonathanBrouwer

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 17, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors r=JonathanBrouwer,mu001999

@rust-bors

rust-bors Bot commented May 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit d7f16d7 has been approved by JonathanBrouwer,mu001999

It is now in the queue for this repository.

JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 17, 2026
…JonathanBrouwer,mu001999

Support defaults for static EIIs

Tracking issue: rust-lang#125418

rust-lang#154193 added EII support for statics, but left default implementations for "a followup PR". This PR implements it.

Maybe I should remove `no-prefer-dynamic` if rust-lang#156577 is accepted.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request May 17, 2026
…JonathanBrouwer,mu001999

Support defaults for static EIIs

Tracking issue: rust-lang#125418

rust-lang#154193 added EII support for statics, but left default implementations for "a followup PR". This PR implements it.

Maybe I should remove `no-prefer-dynamic` if rust-lang#156577 is accepted.
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors r-
#156679 (comment)

@rust-bors rust-bors Bot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels May 18, 2026
@rust-bors

rust-bors Bot commented May 18, 2026

Copy link
Copy Markdown
Contributor

This pull request was unapproved.

This PR was contained in a rollup (#156679), which was unapproved.

View changes since this unapproval

@AsakuraMizu

Copy link
Copy Markdown
Contributor Author

After some investigation, I think this is hitting an LLVM issue: llvm/llvm-project#111321

For tests/ui/eii/static/auxiliary/decl_with_default.rs, rustc currently emits the following LLVM IR on aarch64-apple-darwin:

@_RNvNvCshLcOpHkWMCm_17decl_with_default1__5DECL1 =
  constant [8 x i8] c"\05\00\00\00\00\00\00\00", align 8

@_RNvCshLcOpHkWMCm_17decl_with_default5DECL1 =
  linkonce alias i64, ptr @_RNvNvCshLcOpHkWMCm_17decl_with_default1__5DECL1

The second symbol is the EII foreign item symbol. In the generated Mach-O object it becomes non-external:

0000000000000000 (__TEXT,__const) non-external __RNvCshLcOpHkWMCm_17decl_with_default5DECL1
0000000000000000 (__TEXT,__const) external     __RNvNvCshLcOpHkWMCm_17decl_with_default1__5DECL1

Then, when the aux crate is built as a dylib, ld64 fails because the linker’s initial-undefines list requires the EII symbol to be externally resolvable:

Undefined symbols for architecture arm64:
  "__RNvCshLcOpHkWMCm_17decl_with_default5DECL1", referenced from:
      <initial-undefines>

I also checked whether //@ no-prefer-dynamic would be enough. It is not: the aux crate can then be built as an rlib, but the EII alias symbol inside the object is still non-external, so the final executable link fails instead:

Undefined symbols for architecture arm64:
  "__RNv...decl_with_default...DECL1", referenced from:
      default_cross_crate::main

What should I do here?

  1. Temporarily skip the new cross-crate static-default tests on Apple targets and leave a FIXME.
  2. Refactor to avoid weak aliases for static EII default impls: emit the default value directly under the foreign item symbol with weak/linkonce linkage.
  3. Fix the LLVM issue.

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

(I'm at Rustweek this week, I'll take a look at this next week)

@JonathanBrouwer

JonathanBrouwer commented May 29, 2026

Copy link
Copy Markdown
Contributor
  1. If you're a wizard enough to even consider fixing the LLVM issue please take that route, but I don't really know anything about LLVM so I can't help you there
  2. If not, which is perfectly fine as well, disable static EII defaults on MacOS (and then also disable the test, leaving a FIXME), emitting a diagnostic explaining that they're currently broken. Imo only disabling the test is just risking that we forget about this in the future

I'd avoid refactoring to avoid weak aliases, as that would require a lot of code changes and might work less well dynamically linked libraries.

(sorry for the late reply, have been very busy and then a bit ill)
@rustbot author

@rustbot

rustbot commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@AsakuraMizu

Copy link
Copy Markdown
Contributor Author
  1. If you're a wizard enough to even consider fixing the LLVM issue please take that route, but I don't really know anything about LLVM so I can't help you there

Some update from my side: I actually tried patching LLVM locally a few days ago, and with that patch the Rust tests here passed on macOS. When I was about to open an LLVM PR, I found that this collided with llvm/llvm-project#198148. The approach there is basically the same as mine, so I did not open a competing PR. I have not tested that exact patch yet, though.

I am not sure how long the full path usually takes: LLVM review/merge, possible backport, updating https://github.com/rust-lang/llvm-project, then updating the LLVM submodule here. If that goes smoothly, waiting for the upstream LLVM fix would be fine, but I would guess it will not be immediate.

  1. If not, which is perfectly fine as well, disable static EII defaults on MacOS (and then also disable the test, leaving a FIXME), emitting a diagnostic explaining that they're currently broken. Imo only disabling the test is just risking that we forget about this in the future

So I agree with this approach to work around this on the Rust side for now. One question about the diagnostic: should it point users somewhere? Maybe the tracking issue?

@JonathanBrouwer

Copy link
Copy Markdown
Contributor

I actually tried patching LLVM locally a few days ago

Very impressive, good job! Indeed waiting on that to land sounds like the best option then.

One question about the diagnostic: should it point users somewhere? Maybe the tracking issue?

I'd say create a new issue (linked to the tracking issue) for this. Give this issue the F-external-item_impls label, so we don't forget about it in the future if we try to stabilize this or whatever, being optimistic here

@AsakuraMizu AsakuraMizu force-pushed the eii-static-default branch from d7f16d7 to 26766eb Compare June 9, 2026 12:04
@rustbot

rustbot commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@rust-log-analyzer

This comment has been minimized.

@AsakuraMizu AsakuraMizu force-pushed the eii-static-default branch from 26766eb to 80d5676 Compare June 9, 2026 12:24
@AsakuraMizu

Copy link
Copy Markdown
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 9, 2026
Comment thread compiler/rustc_builtin_macros/src/eii.rs
@mu001999

Copy link
Copy Markdown
Member

@bors r=JonathanBrouwer,mu001999

@rust-bors

rust-bors Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

📌 Commit cdb6acc has been approved by JonathanBrouwer,mu001999

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 10, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 10, 2026
…JonathanBrouwer,mu001999

Support defaults for static EIIs

Tracking issue: rust-lang#125418

rust-lang#154193 added EII support for statics, but left default implementations for "a followup PR". This PR implements it.

Maybe I should remove `no-prefer-dynamic` if rust-lang#156577 is accepted.
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 10, 2026
…JonathanBrouwer,mu001999

Support defaults for static EIIs

Tracking issue: rust-lang#125418

rust-lang#154193 added EII support for statics, but left default implementations for "a followup PR". This PR implements it.

Maybe I should remove `no-prefer-dynamic` if rust-lang#156577 is accepted.
rust-bors Bot pushed a commit that referenced this pull request Jun 10, 2026
Rollup of 23 pull requests

Successful merges:

 - #157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty)
 - #157282 (Fix post-monomorphization error note race in the parallel frontend)
 - #157352 (Make the retained dep graph deterministic under the parallel frontend)
 - #157601 (Emit error for unused target expression in glob and list delegations)
 - #157611 (Update `browser-ui-test` version to `0.24.0`)
 - #157620 (Add a strategy FnMut to inject behavior into the flush cycle)
 - #157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded)
 - #157647 (Start using comptime for reflection intrinsics and their wrapper functions)
 - #157719 (resolve: Partially revert "Remove a special case for dummy imports")
 - #156497 (fix-155516: Don't suggest wrong unwrap expect)
 - #156583 (Support defaults for static EIIs)
 - #157013 (Ensure inferred let pattern types are well-formed)
 - #157230 (borrowck: avoid ICE describing fields on generic params)
 - #157288 (platform support: add SNaN erratum to MIPS targets)
 - #157350 (compiletest: ignore SVG `y` offset in by-lines comparison)
 - #157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs)
 - #157384 (Add `#[rustc_dump_generics]` attribute)
 - #157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`)
 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
 - #157691 (Move symbol hiding code to a new file)
 - #157697 (Add more tests that exercise the well-formedness checking of lazy type aliases)
 - #157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N))
 - #157703 (Fix doc link to Instant sub in saturating caveat)

Failed merges:

 - #157699 (Arg splat experiment - hir FnDecl impl)
rust-bors Bot pushed a commit that referenced this pull request Jun 11, 2026
Rollup of 23 pull requests

Successful merges:

 - #157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty)
 - #157282 (Fix post-monomorphization error note race in the parallel frontend)
 - #157352 (Make the retained dep graph deterministic under the parallel frontend)
 - #157601 (Emit error for unused target expression in glob and list delegations)
 - #157611 (Update `browser-ui-test` version to `0.24.0`)
 - #157620 (Add a strategy FnMut to inject behavior into the flush cycle)
 - #157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded)
 - #157647 (Start using comptime for reflection intrinsics and their wrapper functions)
 - #157719 (resolve: Partially revert "Remove a special case for dummy imports")
 - #156497 (fix-155516: Don't suggest wrong unwrap expect)
 - #156583 (Support defaults for static EIIs)
 - #157013 (Ensure inferred let pattern types are well-formed)
 - #157230 (borrowck: avoid ICE describing fields on generic params)
 - #157288 (platform support: add SNaN erratum to MIPS targets)
 - #157350 (compiletest: ignore SVG `y` offset in by-lines comparison)
 - #157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs)
 - #157384 (Add `#[rustc_dump_generics]` attribute)
 - #157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`)
 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
 - #157691 (Move symbol hiding code to a new file)
 - #157697 (Add more tests that exercise the well-formedness checking of lazy type aliases)
 - #157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N))
 - #157703 (Fix doc link to Instant sub in saturating caveat)

Failed merges:

 - #157699 (Arg splat experiment - hir FnDecl impl)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 11, 2026
…JonathanBrouwer,mu001999

Support defaults for static EIIs

Tracking issue: rust-lang#125418

rust-lang#154193 added EII support for statics, but left default implementations for "a followup PR". This PR implements it.

Maybe I should remove `no-prefer-dynamic` if rust-lang#156577 is accepted.
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 11, 2026
…JonathanBrouwer,mu001999

Support defaults for static EIIs

Tracking issue: rust-lang#125418

rust-lang#154193 added EII support for statics, but left default implementations for "a followup PR". This PR implements it.

Maybe I should remove `no-prefer-dynamic` if rust-lang#156577 is accepted.
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 11, 2026
…JonathanBrouwer,mu001999

Support defaults for static EIIs

Tracking issue: rust-lang#125418

rust-lang#154193 added EII support for statics, but left default implementations for "a followup PR". This PR implements it.

Maybe I should remove `no-prefer-dynamic` if rust-lang#156577 is accepted.
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 11, 2026
…JonathanBrouwer,mu001999

Support defaults for static EIIs

Tracking issue: rust-lang#125418

rust-lang#154193 added EII support for statics, but left default implementations for "a followup PR". This PR implements it.

Maybe I should remove `no-prefer-dynamic` if rust-lang#156577 is accepted.
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 11, 2026
…JonathanBrouwer,mu001999

Support defaults for static EIIs

Tracking issue: rust-lang#125418

rust-lang#154193 added EII support for statics, but left default implementations for "a followup PR". This PR implements it.

Maybe I should remove `no-prefer-dynamic` if rust-lang#156577 is accepted.
rust-bors Bot pushed a commit that referenced this pull request Jun 11, 2026
Rollup of 31 pull requests

Successful merges:

 - #141030 (Expand free alias types during variance computation)
 - #154853 (mgca: Register `ConstArgHasType` when normalizing projection consts)
 - #155527 (Replace printables table with `unicode_data.rs` tables)
 - #156629 (Stabilize `core::range::{legacy, RangeFull, RangeTo}`)
 - #157280 (traits: Allow escaping self types in ExistentialTraitRef::with_self_ty)
 - #157282 (Fix post-monomorphization error note race in the parallel frontend)
 - #157352 (Make the retained dep graph deterministic under the parallel frontend)
 - #157601 (Emit error for unused target expression in glob and list delegations)
 - #157611 (Update `browser-ui-test` version to `0.24.0`)
 - #157620 (Add a strategy FnMut to inject behavior into the flush cycle)
 - #157645 (Windows TLS - Only register the `atexit` hook when `cleanup` can be unloaded)
 - #157646 (Keep rename-imported main alive in dead-code analysis under `--test`)
 - #157647 (Start using comptime for reflection intrinsics and their wrapper functions)
 - #157719 (resolve: Partially revert "Remove a special case for dummy imports")
 - #155153 (Ensure Send/Sync is not implemented for std::env::Vars{,Os})
 - #155198 (fix(mgca): Allow specifying generic args (of enum) on enum itself in unit & tuple variant constructions in (direct) const args)
 - #155323 (refactor `TypeRelativePath::AssocItem` to use `AliasTerm`)
 - #156497 (fix-155516: Don't suggest wrong unwrap expect)
 - #156583 (Support defaults for static EIIs)
 - #157013 (Ensure inferred let pattern types are well-formed)
 - #157196 (Only suggest reborrowing a moved value where the reborrow is valid)
 - #157230 (borrowck: avoid ICE describing fields on generic params)
 - #157288 (platform support: add SNaN erratum to MIPS targets)
 - #157330 (remove `IsTypeConst` from `hir::TraitItemKind`)
 - #157350 (compiletest: ignore SVG `y` offset in by-lines comparison)
 - #157355 (Add `or_try_*` variants for `HashMap` and `BTreeMap` Entry APIs)
 - #157577 (Fix parser error recovery treating 'dyn' as a strict keyword in Rust 2015 when used in `dyn + dyn`)
 - #157670 (Rename `errors.rs` file to `diagnostics.rs` (4/N))
 - #157691 (Move symbol hiding code to a new file)
 - #157700 (Rename `errors.rs` file to `diagnostics.rs` (5/N))
 - #157703 (Fix doc link to Instant sub in saturating caveat)

Failed merges:

 - #157699 (Arg splat experiment - hir FnDecl impl)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

5 participants