Skip to content

Unsafe evolution: implement compat mode#81701

Merged
jjonescz merged 6 commits into
dotnet:features/UnsafeEvolutionfrom
jjonescz:Unsafe-06-CompatMode
Dec 19, 2025
Merged

Unsafe evolution: implement compat mode#81701
jjonescz merged 6 commits into
dotnet:features/UnsafeEvolutionfrom
jjonescz:Unsafe-06-CompatMode

Conversation

@jjonescz

Copy link
Copy Markdown
Member

Test plan: #81207

Follow up on #81581 (i.e., still only for methods and properties).

Implements this speclet section: https://github.com/dotnet/csharplang/blob/80f7e032a3131f1d9c2c6822b8a03cf56eeda005/proposals/unsafe-evolution.md#compat-mode

@jjonescz jjonescz requested a review from a team as a code owner December 15, 2025 16:26
@jjonescz jjonescz requested review from 333fred and jcouv December 15, 2025 16:26
@jcouv jcouv self-assigned this Dec 15, 2025
@jjonescz jjonescz marked this pull request as draft December 16, 2025 12:34
@jjonescz jjonescz marked this pull request as ready for review December 16, 2025 14:56
Comment thread src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEMethodSymbol.cs Outdated
Comment thread src/Compilers/CSharp/Portable/Symbols/Metadata/PE/PEPropertySymbol.cs Outdated
Comment thread src/Compilers/CSharp/Portable/Binder/Binder_Unsafe.cs Outdated
return IsDeclaredRequiresUnsafe ? CallerUnsafeMode.Explicit : CallerUnsafeMode.None;
}

return this.HasParameterContainingPointerType() || ReturnType.ContainsPointerOrFunctionPointer()

@jcouv jcouv Dec 16, 2025

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.

Can a pointer appear elsewhere in the signature? For instance, where T : I<int*[]>
Comment also applies to PEPropertySymbol: E.extension<T>(T).Property (with constraint like above) or E.extension(int*[]).Property (I saw that second example is already covered) may be scenarios #Closed

@jjonescz jjonescz Dec 17, 2025

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'm not sure that should be considered caller-unsafe in the compat mode, because calling such method wouldn't be considered unsafe previously either. Similarly we were discussing extern unsafe rule (I will add you to the chat.) @333fred thoughts?

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've updated the speclet: dotnet/csharplang#9883
Will add tests for this too depending on what we decide (doesn't have to be a final decision of course).

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.

Feels like we shouldn't do that. If the substituted type has a pointer in it, then it'll get marked as unsafe.

@jjonescz jjonescz Dec 18, 2025

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've updated the speclet: dotnet/csharplang#9883

Turns out the PR was stuck in GitHub UI, I've force-pushed to it and it should now be at the commit I was talking about.

Comment thread src/Compilers/CSharp/Portable/Symbols/Symbol.cs Outdated
Comment thread src/Compilers/CSharp/Portable/Symbols/MethodSymbol.cs

@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 3)

@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 4). Only open question about unsafe constraints remains

@jjonescz jjonescz requested a review from 333fred December 17, 2025 18:01
@jjonescz

Copy link
Copy Markdown
Member Author

@AlekseyTs for a second review if you are available, thanks

@jjonescz jjonescz requested a review from jcouv December 19, 2025 12:59

@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 6)

@jjonescz jjonescz merged commit 5ecd4a9 into dotnet:features/UnsafeEvolution Dec 19, 2025
29 checks passed
@jjonescz jjonescz deleted the Unsafe-06-CompatMode branch December 19, 2025 18:39
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