Skip to content

miri: require (almost) all 1-ZST arguments to be actually passed#156085

Open
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:miri-ignored-args
Open

miri: require (almost) all 1-ZST arguments to be actually passed#156085
RalfJung wants to merge 1 commit into
rust-lang:mainfrom
RalfJung:miri-ignored-args

Conversation

@RalfJung
Copy link
Copy Markdown
Member

@RalfJung RalfJung commented May 2, 2026

View all comments

We can't ignore all of them since the compiler itself relies on non-capturing closure arguments being ignored.

Fixes rust-lang/miri#4993

Cc @folkertdev since it also changes the checks for variadics.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 2, 2026

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred to the CTFE machinery

cc @oli-obk, @lcnr

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

rustbot commented May 2, 2026

r? @nikomatsakis

rustbot has assigned @nikomatsakis.
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, mir
  • compiler, mir expanded to 73 candidates
  • Random selection from 21 candidates

@saethlin
Copy link
Copy Markdown
Member

saethlin commented May 2, 2026

@bors try @rust-timer queue

@rust-timer
Copy link
Copy Markdown
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 2, 2026

⌛ Trying commit 403e9b0 with merge 583ebe0

To cancel the try build, run the command @bors try cancel.

Workflow: https://github.com/rust-lang/rust/actions/runs/25256422338

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 2, 2026
rust-bors Bot pushed a commit that referenced this pull request May 2, 2026
miri: require (almost) all 1-ZST arguments to be actually passed
Comment thread compiler/rustc_const_eval/src/interpret/call.rs Outdated
@RalfJung RalfJung force-pushed the miri-ignored-args branch from 403e9b0 to e7467e2 Compare May 2, 2026 16:30
Comment on lines +271 to +278
/// Determine whether this argument can be safely ignored.
/// We have to ignore closures that didn't capture anything to ensure that their
/// coercion to function pointers is sound. We don't want to ignore anything else
/// since we don't actually guarantee that anything is ever ignored.
fn is_ignored_arg(arg: &ArgAbi<'tcx, Ty<'tcx>>) -> bool {
let can_ignore = matches!(arg.layout.ty.kind(), ty::Closure (_def, closure_args) if {
closure_args.as_closure().upvar_tys().is_empty()
});
Copy link
Copy Markdown
Member

@saethlin saethlin May 2, 2026

Choose a reason for hiding this comment

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

I feel like this should mention that normally ZSTs are ignored. But maybe you disagree and think that's base knowledge for Rust argument passing, which would be fine with me.

The connection to closure coercion is turning my brain into a pretzel. Does this mean that we still ignore the argument in this?

fn func<T>(_: T) {}

func(|| {});

View changes since the review

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I have extended the comment, does that help?

The connection to closure coercion is turning my brain into a pretzel. Does this mean that we still ignore the argument in this?

Yes. That's unfortunate, ideally we'd still report UB if that argument gets ignored. However, I'm not sure it's worth trying to restrict this. It seems non-trivial to figure out whether the callee is actually a closure. But maybe you have a good idea for how to do that?

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.

Conceptually, I think of the closure captures being implicitly passed to closure calls, not literally self. But of course the FnOnce trait takes self so I suspect trying to implement my mental model would be really fiddly, if even possible.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

In MIR closures are just normal functions -- closure conversion already happened at that point. So we can't really treat them as anything else.

The best we could do is check the DefId of the callee and figure out if it is a closure, and then treat the first parameter different.

@RalfJung RalfJung force-pushed the miri-ignored-args branch from e7467e2 to 3427f02 Compare May 2, 2026 16:58
@saethlin
Copy link
Copy Markdown
Member

saethlin commented May 2, 2026

The new explanation is much easier for me to follow. Thanks.

r? saethlin
@bors r+

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 2, 2026

📌 Commit 3427f02 has been approved by saethlin

It is now in the queue for this repository.

@rust-bors rust-bors Bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label May 2, 2026
@rust-bors rust-bors Bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 2, 2026
@saethlin saethlin removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label May 2, 2026
@saethlin
Copy link
Copy Markdown
Member

saethlin commented May 2, 2026

@bors try-

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 2, 2026

Unknown command "try-". Run @bors help to see available commands.

@saethlin
Copy link
Copy Markdown
Member

saethlin commented May 2, 2026

@bors try cancel

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 2, 2026

Try build cancelled. Cancelled workflows:

@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the miri-ignored-args branch from 3427f02 to ec802b2 Compare May 2, 2026 17:44
@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 2, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 2, 2026

⚠️ A new commit ec802b2e72a59eda62cefbb9c0de81695a860de8 was pushed.

This pull request was unapproved.

@rust-bors

This comment has been minimized.

@RalfJung
Copy link
Copy Markdown
Member Author

RalfJung commented May 7, 2026

@saethlin what do you think about the latest version of this?

@RalfJung RalfJung force-pushed the miri-ignored-args branch from 2763bb3 to 5d2de1b Compare May 7, 2026 10:29
@rustbot

This comment has been minimized.

@RalfJung
Copy link
Copy Markdown
Member Author

RalfJung commented May 7, 2026

@theemathas thinking about your example again I think it is in fact covered by our documented ABI guarantees since we say that all 1-ZST are ABI compatible, with both () and the closure environment type are 1-ZST. It just kind of "leaks" the fact that there is actually an argument there that implicitly gets removed by the closure-to-fn-ptr coercion.

@saethlin
Copy link
Copy Markdown
Member

@saethlin what do you think about the latest version of this?

I wish our semantics were easier to implement.

@bors r+ rollup=iffy

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented May 31, 2026

📌 Commit 5d2de1b has been approved by saethlin

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 31, 2026
@RalfJung
Copy link
Copy Markdown
Member Author

I wish our semantics were easier to implement.

💯

We could avoid this complication by having the closure-to-fn-ptr coercion insert a shim that does the ABI adjustment. But that's outside the parts of the compiler I am comfortable in...

jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 1, 2026
…hlin

miri: require (almost) all 1-ZST arguments to be actually passed

We can't ignore *all* of them since the compiler itself relies on non-capturing closure arguments being ignored.

Fixes rust-lang/miri#4993

Cc @folkertdev since it also changes the checks for variadics.
jhpratt added a commit to jhpratt/rust that referenced this pull request Jun 1, 2026
…hlin

miri: require (almost) all 1-ZST arguments to be actually passed

We can't ignore *all* of them since the compiler itself relies on non-capturing closure arguments being ignored.

Fixes rust-lang/miri#4993

Cc @folkertdev since it also changes the checks for variadics.
@jhpratt
Copy link
Copy Markdown
Member

jhpratt commented Jun 1, 2026

@bors r-

#157225 (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 Jun 1, 2026
@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 1, 2026

This pull request was unapproved.

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

View changes since this unapproval

@RalfJung RalfJung force-pushed the miri-ignored-args branch from 5d2de1b to a96cc82 Compare June 1, 2026 06:40
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Jun 1, 2026

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-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 1, 2026

⚠️ A new commit a96cc82f159d32a00e6169074689d2a0f126a206 was pushed.

This PR was contained in a rollup (#157225), which was closed.

@RalfJung
Copy link
Copy Markdown
Member Author

RalfJung commented Jun 1, 2026

@bors r=saethlin

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors Bot commented Jun 1, 2026

📌 Commit a96cc82 has been approved by saethlin

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 1, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 1, 2026
…hlin

miri: require (almost) all 1-ZST arguments to be actually passed

We can't ignore *all* of them since the compiler itself relies on non-capturing closure arguments being ignored.

Fixes rust-lang/miri#4993

Cc @folkertdev since it also changes the checks for variadics.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jun 1, 2026
…hlin

miri: require (almost) all 1-ZST arguments to be actually passed

We can't ignore *all* of them since the compiler itself relies on non-capturing closure arguments being ignored.

Fixes rust-lang/miri#4993

Cc @folkertdev since it also changes the checks for variadics.
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.

Function call ABI check ignores ZSTs

8 participants