Skip to content

Unsafe evolution: warn for using the attribute under legacy rules and some cleanup#82456

Merged
jjonescz merged 13 commits into
dotnet:features/UnsafeEvolutionfrom
jjonescz:Unsafe-16-CleanupPrototypeComments
Feb 24, 2026
Merged

Unsafe evolution: warn for using the attribute under legacy rules and some cleanup#82456
jjonescz merged 13 commits into
dotnet:features/UnsafeEvolutionfrom
jjonescz:Unsafe-16-CleanupPrototypeComments

Conversation

@jjonescz

@jjonescz jjonescz commented Feb 19, 2026

Copy link
Copy Markdown
Member

Test plan: #81207
Related speclet update: dotnet/csharplang#9999

Commits should be mostly self-contained.

@jjonescz jjonescz changed the title Unsafe evolution: warn for using attribute under legacy rules and some cleanup Unsafe evolution: warn for using the attribute under legacy rules and some cleanup Feb 19, 2026
@jjonescz jjonescz marked this pull request as ready for review February 19, 2026 12:46
@jjonescz jjonescz requested a review from a team as a code owner February 19, 2026 12:46
@jjonescz jjonescz requested review from 333fred and jcouv February 19, 2026 12:46
@jcouv jcouv self-assigned this Feb 19, 2026
@333fred 333fred self-assigned this Feb 19, 2026

| Warning ID | Description |
|------------|-------------|
| CS9508 | [RequiresUnsafeAttribute is only valid under the updated memory safety rules](https://github.com/dotnet/csharplang/issues/9704) |

@jcouv jcouv Feb 20, 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.

CS9508

Let's leave a PROTOTYPE since this will need to be adjusted when ErrorCodes are compacted #Closed

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.

Does the prototype checking infrastructure actually look at non-code files?

@jjonescz jjonescz Feb 23, 2026

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.

Yes, it seems to filter out just binaries:

$prototypes = Get-ChildItem -Path src, eng, scripts, docs\compilers -Exclude *.dll,*.exe,*.pdb,*.xlf,todo-check.ps1 -Recurse | Select-String -Pattern 'PROTOTYPE' -CaseSensitive -SimpleMatch

return MessageID.IDS_FeatureUnsafeEvolution.GetFeatureAvailabilityDiagnosticInfo(this.Compilation);
}

// PROTOTYPE: Update the error message to hint that one can enable updated memory safety rules.

@jcouv jcouv Feb 21, 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.

What was the resolution? #Closed

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.

It still makes sense to have unsafe blocks around all pointers even if that's not required by the updated rules, hence it doesn't seem appropriate to hint to enable the updated memory safety rules in the legacy errors.

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.

Agreed. I expect source generators may do just this.

diagnostics.Add(ErrorCode.ERR_PartialMemberReadOnlyDifference, implementation.GetFirstLocation());
}

// PROTOTYPE: Update and test this for unsafe evolution.

@jcouv jcouv Feb 21, 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.

What was the resolution? #Closed

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.

We removed the possibility to mark property accessors as unsafe in a previous PR so this is no longer relevant for this feature.

break;
case ErrorCode.WRN_RequiresUnsafeAttributeLegacyRules:
// These are the warnings introduced with the warning "wave" shipped with dotnet 11 and C# 15.
Assert.Equal(11, ErrorFacts.GetWarningLevel(errorCode));

@jcouv jcouv Feb 21, 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.

nit: not related to this PR, but it may be good to have a comment at the bottom of this test indicating that the warning wave doc should be updated #Closed

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.

There is already a comment to update that doc in GetWarningLevel method (which also needs to be updated). Are you suggesting it would be good to have such comment in both places?

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.

Doc in GetWarningLevel is good enough reminder. Thanks

@jcouv jcouv left a comment

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.

Done with review pass (commit 12). Only minor comments/questions

@jjonescz jjonescz requested a review from jcouv February 23, 2026 11:07

| Warning ID | Description |
|------------|-------------|
| CS9508 | [RequiresUnsafeAttribute is only valid under the updated memory safety rules](https://github.com/dotnet/csharplang/issues/9704) |

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.

Does the prototype checking infrastructure actually look at non-code files?

return MessageID.IDS_FeatureUnsafeEvolution.GetFeatureAvailabilityDiagnosticInfo(this.Compilation);
}

// PROTOTYPE: Update the error message to hint that one can enable updated memory safety rules.

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.

Agreed. I expect source generators may do just this.

@jcouv jcouv left a comment

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.

LGTM Thanks (commit 13)

@jjonescz jjonescz enabled auto-merge (squash) February 24, 2026 09:48
@jjonescz jjonescz merged commit 60a23da into dotnet:features/UnsafeEvolution Feb 24, 2026
23 of 24 checks passed
@jjonescz jjonescz deleted the Unsafe-16-CleanupPrototypeComments branch February 24, 2026 13:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants