Skip to content

Add -Zjit-mode flag#151009

Open
bjorn3 wants to merge 3 commits intorust-lang:mainfrom
bjorn3:jit_mode
Open

Add -Zjit-mode flag#151009
bjorn3 wants to merge 3 commits intorust-lang:mainfrom
bjorn3:jit_mode

Conversation

@bjorn3
Copy link
Member

@bjorn3 bjorn3 commented Jan 12, 2026

This flag tells the codegen backend to immediately execute the code it builds. This is exactly what miri needs as it is unable to produce real executables. Adding a builtin flag would allow cargo to add native support for this without miri needing to do a bunch of hacks in its cargo wrapper. Furthermore cg_clif also has a jit mode that benefits from it.

@rustbot
Copy link
Collaborator

rustbot commented Jan 12, 2026

The Miri subtree was changed

cc @rust-lang/miri

@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 Jan 12, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 12, 2026

r? @lcnr

rustbot has assigned @lcnr.
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

@Urgau
Copy link
Member

Urgau commented Jan 12, 2026

This is kind-of a nit, but the naming of the flag implies to me that we generate a binary that calls back rustc at runtime to generate the machine code where necessary. What about -Zrun instead? or -Zexecute?

@rust-log-analyzer

This comment has been minimized.

@bjorn3
Copy link
Member Author

bjorn3 commented Jan 12, 2026

What about -Zrun instead? or -Zexecute?

I like those names. I don't have much of a preference which of the two to use.

@JayanAXHF JayanAXHF added A-codegen Area: Code generation A-CLI Area: Command-line interface (CLI) to the compiler labels Jan 12, 2026
}
}
config.program.args.push("-Zui-testing".into());
config.program.args.push("-Zjit-mode".into());
Copy link
Member

Choose a reason for hiding this comment

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

The code for ./miri run in miri-script/src/commands.rs likely also needs to set this new flag.

@RalfJung
Copy link
Member

This seems MCP-worthy.

Also, how do you imagine this to work from cargo? Cargo currently treats output from rustc and the program very different: rustc produces JSON output that is fully consumed by cargo, cached, and then rendered to the terminal. The program just gets direct access to the terminal.

@bjorn3
Copy link
Member Author

bjorn3 commented Jan 18, 2026

Cargo currently treats output from rustc and the program very different: rustc produces JSON output that is fully consumed by cargo, cached, and then rendered to the terminal. The program just gets direct access to the terminal.

Cargo currently does forward all lines output on stdout which don't start with a } to the terminal unchanged. A more principled way would be for rustc to emit a message indicating that jit execution starts. Though that would require miri to somehow change the diagnostic emitter to disable json output and force colors at that point.

@RalfJung
Copy link
Member

RalfJung commented Jan 18, 2026

Cargo currently does forward all lines output on stdout which don't start with a }

I assume you mean {.

That said, last time I checked (which was many years ago), it did so in a buffered way, making it unsuitable for Miri (we need to be able to emit partial lines). Also, it's not acceptable for output from the program Miri interprets to be swallowed just because it looks like JSON.

@rust-bors

This comment has been minimized.

@bjorn3 bjorn3 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-review Status: Awaiting review from the assignee but also interested parties. labels Feb 25, 2026
This flag tells the codegen backend to immediately execute the code it
builds. This is exactly what miri needs as it is unable to produce real
executables. Adding a builtin flag would allow cargo to add native
support for this without miri needing to do a bunch of hacks in its
cargo wrapper. Furthermore cg_clif also has a jit mode that benefits
from it.
@rustbot
Copy link
Collaborator

rustbot commented Mar 3, 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.

bjorn3 added 2 commits March 3, 2026 16:46
If cargo gets native support for -Zjit-mode, this should allow
simplifying cargo-miri a fair bit.
@rust-log-analyzer
Copy link
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
/dev/sda15      105M  6.2M   99M   6% /boot/efi
tmpfs           1.6G   12K  1.6G   1% /run/user/1001
================================================================================

Sufficient disk space available (94917444KB >= 52428800KB). Skipping cleanup.
##[group]Run echo "[CI_PR_NUMBER=$num]"
echo "[CI_PR_NUMBER=$num]"
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}
---
[RUSTC-TIMING] ui test:false 0.082
error[E0432]: unresolved import `rustc_codegen_ssa::CodegenResults`
  --> src/tools/miri/src/bin/miri.rs:56:25
   |
56 | use rustc_codegen_ssa::{CodegenResults, CompiledModules, CrateInfo, TargetConfig};
   |                         ^^^^^^^^^^^^^^ no `CodegenResults` in the root

warning: unused variable: `sess`
   --> src/tools/miri/src/bin/miri.rs:240:26
    |
240 |     fn target_cpu(&self, sess: &Session) -> String {

cmd.args(args);
}

cmd.arg("-Zjit-mode");
Copy link
Member

Choose a reason for hiding this comment

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

If this is something Miri will always want to set, cargo-miri is not a great place as it does not cover ./miri run and ./miri test.

The usual way we add flags we always want is here; does that not work?

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

Labels

A-CLI Area: Command-line interface (CLI) to the compiler A-codegen Area: Code generation S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

7 participants