Skip to content

Add codeview_annotation intrinsic - #160285

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
gurry:add-codeview-annotation-intrinsic
Oct 17, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
gurry:add-codeview-annotation-intrinsic

Conversation

@gurry

@gurry gurry commented Jul 31, 2026 •

Copy link
Copy Markdown
Contributor

View all comments

This PR adds:

  • A new intrinsic called codeview_annotation, which lowers to llvm.codeview.annotation and allows users to emit arbitrary S_ANNOTATION records into PDB files
  • A std lib API to call this intrinsic

For the underlying motivation and design details see:

Tracking issues:

Implementation details

  • Codgen happens only on LLVM backend and only if the target uses PDBs. It is a no-op in all other cases. A compile error will still be emitted in all cases (even on non-LLVM, non-PDB ones) if CodeViewAnnotationArgs::ARGS fails to const eval.
  • Had to change the feature gate on core::os module to a neutral core_os in order to add the new module core::os::windows. It was earlier gated on darwin_objc, which was not general enough.

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jul 31, 2026
@gurry gurry changed the title Add codeview_annotation intrinsic Add codeview_annotation intrinsic Jul 31, 2026
@rust-bors

This comment has been minimized.

@gurry
gurry force-pushed the add-codeview-annotation-intrinsic branch from 734844e to 0740b67 Compare August 11, 2026 07:10
@rust-bors

This comment has been minimized.

@gurry
gurry force-pushed the add-codeview-annotation-intrinsic branch from 0740b67 to 7161ffd Compare August 19, 2026 07:04
@rust-bors

This comment has been minimized.

@rust-bors

This comment has been minimized.

@gurry
gurry force-pushed the add-codeview-annotation-intrinsic branch 2 times, most recently from d012be4 to 6d91060 Compare October 9, 2026 11:10
@rustbot rustbot added the O-windows Operating system: Windows label Oct 9, 2026
@rust-log-analyzer

This comment has been minimized.

@gurry
gurry force-pushed the add-codeview-annotation-intrinsic branch from 6d91060 to 07eceeb Compare October 9, 2026 13:12
@gurry
gurry marked this pull request as ready for review October 10, 2026 03:29
@rustbot

rustbot commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

⚠️ #[miri::intrinsic_fallback_is_spec] must only be used if the function actively checks for all UB cases,
and explores the possible non-determinism of the intrinsic.

cc @rust-lang/miri

Any special-casing of Miri in the standard library requires review.

cc @rust-lang/miri

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

miri is developed in its own repository. If the Miri part of this change can be broken out, consider making this change to rust-lang/miri instead. However, if Miri needs adjusting for rustc changes, just ignore this message.

cc @rust-lang/miri

rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

cc @bjorn3

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

@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 Oct 10, 2026
@rustbot

rustbot commented Oct 10, 2026

Copy link
Copy Markdown
Collaborator

r? @folkertdev

rustbot has assigned @folkertdev.
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 77 candidates
  • Random selection from 17 candidates

@gurry
gurry force-pushed the add-codeview-annotation-intrinsic branch from 07eceeb to e9d57be Compare October 10, 2026 05:11
@gurry

gurry commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

⚠️ #[miri::intrinsic_fallback_is_spec] must only be used if the function actively checks for all UB cases, and explores the possible non-determinism of the intrinsic.

The function does not caues any UB or non-determinism (it returns () and has no run-time side effects) so the fallback should be fine.

rustc_codegen_gcc is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_gcc instead.

cc @antoyo, @GuillaumeGomez

...
rustc_codegen_cranelift is developed in its own repository. If possible, consider making this change to rust-lang/rustc_codegen_cranelift instead.

I have now removed the changes in rustc_codegen_gcc and rustc_codegen_cranelift. I had earlier added explicit no-op handling for the intrinic in these backends, but I think the fallback function is enough.

@RalfJung RalfJung Oct 10, 2026 •

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.

Please move this into the intrinsics folder.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved

@@ -0,0 +1,17 @@
// Verifies that `codeview_annotation` is a no-op under Miri
// and that Miri does not try to const eval `CodeViewAnnotationArgs::ARGS`

@RalfJung RalfJung Oct 10, 2026 •

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.

Why should Miri not const-eval the args? That seems strange.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My thinking was that Miri should not do anything at all upon encountering this intrinsic including const evaluating the args. That's what I meant by "no-op under Miri" in the comment.

Now I realize that perhaps Miri should actively try to const eval and raise an error if ARGS fails to eval because that's exactly what we're doing for LLVM+PDB targets. So that this particular behaviour will be consistent in all cases.

What are your thoughts?

@RalfJung RalfJung Oct 10, 2026 •

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.

So that this particular behaviour will be consistent in all cases.

Yeah that's what I thought -- and not just Miri but also other codegen backends.

I think you can just put a const { let _ignore = T::ARGS; } into the fallback body to achieve this.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed. Added const block in the fallback body to force const eval, added miri test for when const eval fails (‎src/tools/miri/tests/fail/intrinsics/codeview-annotation.rs) and removed //@ only-msvc from ‎tests/ui/intrinsics/codeview-annotation-bad-args.rs which will now test const eval failure on all environments.

Comment thread library/core/src/os/mod.rs Outdated
@@ -1,12 +1,11 @@
//! OS-specific functionality.

#![unstable(feature = "darwin_objc", issue = "145496")]
#![stable(feature = "core_os", since = "CURRENT_RUSTC_VERSION")]

@RalfJung RalfJung Oct 10, 2026 •

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.

This PR should not stabilize anything. (It would have to go through the full team approval process otherwise as it would represent a permanent commitment we can never take back. And anyway a stabilization PR should never also add new features.) Why can't this be a new unstable feature instead?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it.

If I change the feature gate on core::os to something like core_os, then anyone using items in, say, core::os::windows will require both the features codeview_annotation and core_os. That's acceptable, right?

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.

It's suboptimal but better than a drive-by stabilization.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@gurry
gurry force-pushed the add-codeview-annotation-intrinsic branch from e9d57be to 457ca69 Compare October 10, 2026 11:43
@rust-log-analyzer

This comment has been minimized.

@gurry
gurry force-pushed the add-codeview-annotation-intrinsic branch from 457ca69 to 9b1f38c Compare October 10, 2026 14:15
@rustbot

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@gurry
gurry force-pushed the add-codeview-annotation-intrinsic branch from 9b1f38c to a339f69 Compare October 11, 2026 08:26

@folkertdev folkertdev 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.

Some small things, @RalfJung does the const eval stuff look OK to you otherwise?

View changes since this review

Comment on lines +3510 to +3520
.filter_map(|trait_clause| {
let trait_ref = trait_clause.skip_binder().trait_ref;
tcx.associated_items(trait_ref.def_id)
.in_definition_order()
.find(|item| {
item.tag() == ty::AssocTag::Const
&& tcx.item_name(item.def_id).as_str() == "ARGS"
})
.map(|item| (item.def_id, trait_ref.args))
})
.next()

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.

this can be find_map I think?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Comment on lines +3540 to +3541
mir::ConstValue::Slice { alloc_id, meta } => Some((alloc_id, Size::ZERO, meta)),
mir::ConstValue::Indirect { alloc_id, offset } => read_slice_pointer(tcx, alloc_id, offset)

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.

Why are both branches needed?

@gurry gurry Oct 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like we'll only ever get ConstValue::Indirect in this case so I removed ConstValue::Slice. Thanks.

@rust-bors

This comment has been minimized.

@RalfJung

Copy link
Copy Markdown
Member

On the const-eval / Miri side there's just the fallback body and that seems reasonable to me.

@gurry
gurry force-pushed the add-codeview-annotation-intrinsic branch from a339f69 to 9d8da0d Compare October 14, 2026 09:04
@rustbot

rustbot commented Oct 14, 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.

@folkertdev folkertdev 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.

Looks good, thanks!

@bors r+

View changes since this review

Comment on lines +22 to +23
#[cfg_attr(windows, doc = "```")]
#[cfg_attr(not(windows), doc = "```ignore (needs windows)")]

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.

hmm, we have

```ignore-windows

but sadly not currently

```only-windows

it would be nice if rustdoc could do that

@rust-bors

rust-bors Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 9d8da0d has been approved by folkertdev

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 Oct 16, 2026
@rust-bors

This comment has been minimized.

@rust-bors rust-bors Bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 17, 2026
@rust-bors

rust-bors Bot commented Oct 17, 2026

Copy link
Copy Markdown
Contributor

☀️ Test successful - CI
Approved by: folkertdev
Duration: 2h 58m 8s
Pushing f4d7ecf to main...

@rust-bors
rust-bors Bot merged commit f4d7ecf into rust-lang:main Oct 17, 2026
15 checks passed
@rustbot rustbot added this to the 1.101.0 milestone Oct 17, 2026
@github-actions

Copy link
Copy Markdown
Contributor
What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing 5d8fec0 (parent) -> f4d7ecf (this PR)

Test differences

Show 116 test diffs

Stage 1

  • [codegen] tests/codegen-llvm/intrinsics/codeview-annotation-non-pdb-targets.rs: [missing] -> pass (J2)
  • [codegen] tests/codegen-llvm/intrinsics/codeview-annotation.rs#OPT0: [missing] -> ignore (only executed when the target environment is msvc) (J2)
  • [codegen] tests/codegen-llvm/intrinsics/codeview-annotation.rs#OPT3: [missing] -> ignore (only executed when the target environment is msvc) (J2)
  • [ui] tests/ui/feature-gates/feature-gate-codeview_annotation.rs: [missing] -> ignore (only executed when the operating system is windows) (J4)
  • [ui] tests/ui/intrinsics/codeview-annotation-bad-args.rs: [missing] -> pass (J4)
  • [ui] tests/ui/intrinsics/codeview-annotation.rs: [missing] -> ignore (only executed when the operating system is windows) (J4)
  • [ui (polonius)] tests/ui/feature-gates/feature-gate-codeview_annotation.rs: [missing] -> ignore (only executed when the operating system is windows) (J7)
  • [ui (polonius)] tests/ui/intrinsics/codeview-annotation-bad-args.rs: [missing] -> pass (J7)
  • [ui (polonius)] tests/ui/intrinsics/codeview-annotation.rs: [missing] -> ignore (only executed when the operating system is windows) (J7)

Stage 2

  • [codegen] tests/codegen-llvm/intrinsics/codeview-annotation-non-pdb-targets.rs: [missing] -> pass (J0)
  • [codegen] tests/codegen-llvm/intrinsics/codeview-annotation.rs#OPT0: [missing] -> ignore (only executed when the target environment is msvc) (J0)
  • [codegen] tests/codegen-llvm/intrinsics/codeview-annotation.rs#OPT3: [missing] -> ignore (only executed when the target environment is msvc) (J0)
  • [ui] tests/ui/feature-gates/feature-gate-codeview_annotation.rs: [missing] -> ignore (only executed when the operating system is windows) (J1)
  • [ui] tests/ui/intrinsics/codeview-annotation.rs: [missing] -> ignore (only executed when the operating system is windows) (J1)
  • [ui] tests/ui/feature-gates/feature-gate-codeview_annotation.rs: [missing] -> pass (J3)
  • [ui] tests/ui/intrinsics/codeview-annotation.rs: [missing] -> pass (J3)
  • [codegen] tests/codegen-llvm/intrinsics/codeview-annotation-non-pdb-targets.rs: [missing] -> ignore (ignored when the target environment is msvc) (J5)
  • [codegen] tests/codegen-llvm/intrinsics/codeview-annotation.rs#OPT0: [missing] -> pass (J5)
  • [codegen] tests/codegen-llvm/intrinsics/codeview-annotation.rs#OPT3: [missing] -> pass (J5)
  • [ui] tests/ui/intrinsics/codeview-annotation-bad-args.rs: [missing] -> pass (J6)

Additionally, 96 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard f4d7ecfb0efc8330cef8f8020f192920d8721911 --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-loongarch64-linux: 5h 44m -> 1h 19m (-77.0%)
  2. dist-loongarch64-musl: 5h 40m -> 1h 31m (-73.0%)
  3. test-i686-gnu-nopt-1: 1h 31m -> 2h 24m (+58.5%)
  4. test-x86_64-msvc-ext2: 1h 9m -> 1h 50m (+58.3%)
  5. dist-arm-linux-gnueabi: 1h 4m -> 1h 41m (+57.9%)
  6. test-x86_64-gnu: 1h 42m -> 2h 36m (+53.2%)
  7. dist-s390x-linux: 1h 3m -> 1h 33m (+47.8%)
  8. dist-x86_64-solaris: 1h 10m -> 1h 43m (+47.6%)
  9. dist-powerpc64le-linux-musl: 1h 8m -> 1h 38m (+44.5%)
  10. dist-i686-linux: 1h 20m -> 1h 53m (+42.2%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (f4d7ecf): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (secondary 4.2%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
4.2% [4.2%, 4.2%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Cycles

Results (secondary 2.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
2.0% [2.0%, 2.0%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 490.438s -> 497.38s (1.42%)
Artifact size: 406.97 MiB -> 407.06 MiB (0.02%)

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

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. merged-by-bors This PR was explicitly merged by bors. O-windows Operating system: Windows T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants