Skip to content

Expose an API for polymorphic drop glue translation#157156

Open
Nadrieril wants to merge 4 commits into
rust-lang:mainfrom
Nadrieril:poly-drop-glue
Open

Expose an API for polymorphic drop glue translation#157156
Nadrieril wants to merge 4 commits into
rust-lang:mainfrom
Nadrieril:poly-drop-glue

Conversation

@Nadrieril
Copy link
Copy Markdown
Member

At my $dayjob I work on a rustc driver called Charon, whose main selling point is its ability to accurately represent polymorphic Rust code. In adding support for drops I ran into an issue: the code that generates drop glue shim expects monomorphized types and ICEs when used in some polymorphic contexts. Example output:

error: internal compiler error: compiler/rustc_middle/src/ty/sty.rs:373:13: cannot find `K/#0` in param-env: ParamEnv {
    caller_bounds: [
        Binder { value: HostEffectPredicate { trait_ref: <T as std::marker::Destruct>, constness: Maybe }, bound_vars: [] },
        Binder { value: TraitPredicate(<T as std::marker::Destruct>, polarity:Positive), bound_vars: [] },
    ],
}

thread 'rustc' panicked at compiler/rustc_middle/src/ty/sty.rs:373:13:

I recall a Zulip discussion about this but cannot find it.

This PR exposes build_drop_shim and gives it a TypingEnv argument, for use in rustc drivers like mine.

Disclosure: I used LLM assistance to make this very complicated PR. This consisted in me repeatedly telling it to do something simpler until I eventually cleaned it up myself. I like the test it wrote tho.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 30, 2026

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@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 May 30, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 30, 2026

r? @JonathanBrouwer

rustbot has assigned @JonathanBrouwer.
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 16 candidates

@rust-log-analyzer

This comment has been minimized.

@Nadrieril
Copy link
Copy Markdown
Member Author

Nadrieril commented May 30, 2026

Wait why on earth would this be backend-dependent 🤔

@Nadrieril
Copy link
Copy Markdown
Member Author

Investigation reveals some rather broken state of affairs: calling tcx.fn_sig on the DefId for the DropGlue lang item is what ICEs, and it looks like some mixup between DefIds. So I've just ignored the gcc backend.

@Kobzol
Copy link
Copy Markdown
Member

Kobzol commented May 30, 2026

I'm not sure if these situations are interesting for cg_gcc maintainers, but just to make sure - CC @rust-lang/wg-gcc-backend

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

Labels

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.

5 participants