Skip to content

EII: only require implementations for final artifacts to support -C prefer-dynamic#158340

Closed
cezarbbb wants to merge 1 commit into
rust-lang:mainfrom
cezarbbb:eii-prefer-dynamic-support
Closed

EII: only require implementations for final artifacts to support -C prefer-dynamic#158340
cezarbbb wants to merge 1 commit into
rust-lang:mainfrom
cezarbbb:eii-prefer-dynamic-support

Conversation

@cezarbbb

@cezarbbb cezarbbb commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

EII checking currently uses CheckExistence for any crate type that isn't rlib, which means dylib/sdylib/proc-macro crates that declare an EII without an implementation always fail to compile. But these are intermediate products — their EIIs can be resolved by downstream crates, just like rlibs. The linker selects the strong symbol (explicit impl) over the weak one (default impl) at final link time, so intermediate crates don't need to guarantee an implementation exists yet.

This changes get_checking_mode() in rustc_passes/src/eii.rs to only use CheckExistence when the crate produces a final artifact: Executable, Cdylib, or StaticLib. All other crate types (Rlib, Dylib, Sdylib, ProcMacro) only check for duplicate explicit implementations. This matches the existing CrateType::has_metadata() classification in rustc_hir/src/attrs/data_structures.rs — crate types with metadata are intermediate products that downstream crates can depend on, and those without metadata are leaf nodes in the dependency graph where no further resolution is possible.

With this change the behavior for each crate type is:

  • Rlib / Dylib / Sdylib / ProcMacro — no explicit impl is fine, compiles successfully; duplicate explicit impls across dependencies still error
  • Executable / Cdylib / StaticLib — every EII must have at least one implementation (default or explicit), otherwise EiiWithoutImpl error; duplicate explicit impls still error

This modification's result is the -C prefer-dynamic flag works: a dylib intermediate can declare an EII without an implementation, and the final executable provides the explicit impl — the strong alias overrides the weak one at link time.

tracking issues: #125418

r? @jdonszelmann

@rustbot rustbot added 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 24, 2026
@rustbot

rustbot commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

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

@bjorn3

bjorn3 commented Jun 24, 2026

Copy link
Copy Markdown
Member

@cezarbbb

Copy link
Copy Markdown
Contributor Author

I agree with bjorn's reply in zulip. I will close this PR and explore new ways to enable EII support prefer-dynamic.

@cezarbbb cezarbbb closed this Jun 24, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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