Document ECMA-335 augment III.1.7.7 recognition for UnscopedRefAttribute and RefSafetyRulesAttribute - #12902
Open
jakobbotsch with Copilot wants to merge 5 commits into
Open
Document ECMA-335 augment III.1.7.7 recognition for UnscopedRefAttribute and RefSafetyRulesAttribute#12902jakobbotsch with Copilot wants to merge 5 commits into
jakobbotsch with Copilot wants to merge 5 commits into
Conversation
Copilot created this pull request from a session on behalf of
jakobbotsch
July 24, 2026 12:31
View session
jakobbotsch
marked this pull request as ready for review
July 27, 2026 08:50
Contributor
There was a problem hiding this comment.
Pull request overview
Updates the ECMA XML reference docs to explain that UnscopedRefAttribute and RefSafetyRulesAttribute are specially recognized by the runtime per ECMA-335 augment III.1.7.7, and links to the spec addendum for the full opt-in IL restriction rules.
Changes:
- Expanded
RefSafetyRulesAttributeremarks to describe module-level opt-in semantics and provide a spec addendum link. - Extended
UnscopedRefAttributeremarks with runtime recognition details, an example ofthisescaping for value-type instance methods, and the dependency onRefSafetyRulesAttribute.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| xml/System.Runtime.CompilerServices/RefSafetyRulesAttribute.xml | Replaces placeholder remarks with ECMA-335 augment explanation and link. |
| xml/System.Diagnostics.CodeAnalysis/UnscopedRefAttribute.xml | Adds augment-based runtime-recognition remarks and clarifies interaction with RefSafetyRulesAttribute. |
Comments suppressed due to low confidence (1)
xml/System.Diagnostics.CodeAnalysis/UnscopedRefAttribute.xml:47
- Grammar/linking: "IL that reference" should be "IL that references" (IL is singular), and the final mention of RefSafetyRulesAttribute is in backticks, so it won't link like the earlier xref.
This attribute is specially recognized by the runtime. ECMA-335 augment III.1.7.7 defines restrictions on valid IL that reference this attribute. For example, when this attribute is applied to an instance method of a value type, the `this` argument is allowed to escape the method. When the attribute is absent, an optimizing compiler can rely on `this` not escaping to further optimize certain code patterns, such as eliminating boxing. For more information, see the [ECMA-335 CLI Specification Addendum](https://github.com/dotnet/runtime/blob/main/docs/design/specs/Ecma-335-Augments.md#iii177-opt-in-restrictions), Sec. III.1.7.7 ("Opt-in restrictions").
Because the runtime relies on this attribute, it can't be stripped from an assembly. The restrictions defined by augment III.1.7.7 apply only when the <xref:System.Runtime.CompilerServices.RefSafetyRulesAttribute> is present on the module, so this attribute has its documented effect only in a module that's also annotated with `RefSafetyRulesAttribute`.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
gewarren
approved these changes
Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Documents that
UnscopedRefAttributeandRefSafetyRulesAttributeare specially recognized by the runtime per ECMA-335 augment III.1.7.7 (from dotnet/runtime#130863), and links out to the augment for the full IL restriction rules.Changes
UnscopedRefAttribute— Added remarks explaining the augment: applying it to a value type instance method letsthisescape; when absent, an optimizing compiler can rely onthisnot escaping (e.g., to eliminate boxing). Notes the runtime relies on it (can't be stripped) and that its effect only holds in a module also annotated withRefSafetyRulesAttribute.RefSafetyRulesAttribute— Replaced the placeholder remarks with a description of the module-level opt-in and version value, links to the augment, and notes the runtime can't strip it.Both entries follow repo style (contractions, "might"/"can" over "may") and link to the augment's
#iii177-opt-in-restrictionsanchor. No claim that dynamic IL emitters must apply either attribute, since omitting them is always conservatively correct.Internal previews