Skip to content

Unsafe evolution: add ISymbol public API - #84674

Merged
jjonescz merged 3 commits into
dotnet:mainfrom
jjonescz:Unsafe-45-SymbolApi
Jul 31, 2026
Merged

Unsafe evolution: add ISymbol public API#84674
jjonescz merged 3 commits into
dotnet:mainfrom
jjonescz:Unsafe-45-SymbolApi

Conversation

@jjonescz

@jjonescz jjonescz commented Jul 29, 2026

Copy link
Copy Markdown
Member

Part of #82791.
Test plan: #81207

@EgorBo FYI

Microsoft Reviewers: Open in CodeFlow

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

Copilot AI 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.

Pull request overview

This PR extends the Microsoft.CodeAnalysis.ISymbol public API surface by adding a new experimental RequiresUnsafe property and wires it through relevant symbol wrappers/implementations across C#, VB, workspace code-generation symbols, and Metadata-as-Source, with compiler tests and reference-API updates to keep tooling in sync.

Changes:

  • Added experimental ISymbol.RequiresUnsafe API and updated public API baselines.
  • Implemented/plumbed RequiresUnsafe through C# public model symbols, VB symbols (default False), Metadata-as-Source wrapper symbols, and code generation symbols.
  • Added C# compiler tests validating RequiresUnsafe values and ensured semantic search reference API lists include the new getter.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/Symbols/CodeGenerationSymbol.cs Adds RequiresUnsafe stub implementation for code-generation symbols.
src/Tools/SemanticSearch/ReferenceAssemblies/Apis/Microsoft.CodeAnalysis.txt Updates reference API list to include ISymbol.get_RequiresUnsafe.
src/Features/Core/Portable/MetadataAsSource/AbstractMetadataAsSourceService.AbstractWrappedSymbol.cs Forwards RequiresUnsafe through Metadata-as-Source wrapped symbols.
src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb Adds default VB implementation of ISymbol.RequiresUnsafe returning False.
src/Compilers/CSharp/Test/CSharp15/UnsafeEvolutionTests.cs Adds/extends tests asserting RequiresUnsafe behavior for public symbols.
src/Compilers/CSharp/Portable/Symbols/Symbol.cs Removes now-obsolete comment about needing a public API for caller-unsafe exposure.
src/Compilers/CSharp/Portable/Symbols/PublicModel/Symbol.cs Implements ISymbol.RequiresUnsafe in the C# public symbol wrapper via caller-unsafe mode.
src/Compilers/CSharp/Portable/Symbols/PublicModel/PreprocessingSymbol.cs Implements RequiresUnsafe as false for preprocessing symbols.
src/Compilers/Core/Portable/Symbols/ISymbol.cs Adds the new experimental RequiresUnsafe property and XML doc.
src/Compilers/Core/Portable/PublicAPI.Unshipped.txt Records the new experimental public API member.

Comment thread src/Compilers/Core/Portable/Symbols/ISymbol.cs Outdated
@jjonescz
jjonescz marked this pull request as ready for review July 29, 2026 13:14
@jjonescz
jjonescz requested review from a team as code owners July 29, 2026 13:14
@jjonescz
jjonescz requested review from 333fred and AlekseyTs July 29, 2026 13:14
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 2 pipeline(s).
There may be pipelines that require an authorized user to comment /azp run to run.

@jjonescz

Copy link
Copy Markdown
Member Author

@333fred @AlekseyTs for reviews, thanks

Comment thread src/Compilers/Core/Portable/Symbols/ISymbol.cs Outdated
@AlekseyTs

AlekseyTs commented Jul 30, 2026

Copy link
Copy Markdown
Contributor
    internal abstract CallerUnsafeMode GetCallerUnsafeMode(ConsList<FieldSymbol> fieldsBeingBound);

Consider aligning the name with the current spec terminology ("requires-unsafe"). Not necessarily in this PR. #Closed


Refers to: src/Compilers/CSharp/Portable/Symbols/Symbol.cs:627 in 835cab0. [](commit_id = 835cab0, deletion_comment = False)

Comment thread src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb Outdated
Comment thread src/Compilers/VisualBasic/Portable/Symbols/Symbol.vb Outdated
@AlekseyTs

Copy link
Copy Markdown
Contributor

Done with review pass (commit 1)

Copilot AI review requested due to automatic review settings July 30, 2026 14:43
@dotnet-policy-service dotnet-policy-service Bot added VSCode Needs API Review Needs to be reviewed by the API review council labels Jul 30, 2026
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

This PR modifies public API files. Please follow the instructions at https://github.com/dotnet/roslyn/blob/main/docs/contributing/API%20Review%20Process.md for ensuring all public APIs are reviewed before merging.

Copilot AI 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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

src/Compilers/Core/Portable/Symbols/ISymbol.cs:165

  • The XML doc for ISymbol.RequiresUnsafe has awkward/incorrect phrasing (“considered requires-unsafe”). Rewording this improves clarity for API consumers without changing meaning.
        /// Whether this symbol is considered requires-<see langword="unsafe"/> under the updated memory safety rules,
        /// i.e., the symbol requires an <see langword="unsafe"/> context at its use site.
        /// This can be either a symbol compiled with the updated memory safety rules which has <see langword="unsafe"/> in its signature,
        /// or a symbol compiled with the legacy memory safety rules which has pointers in its signature.

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

LGTM (commit 2)


Private ReadOnly Property ISymbol_RequiresUnsafe As Boolean Implements ISymbol.RequiresUnsafe
Get
Return False

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.

Consider adding a test

Copilot AI review requested due to automatic review settings July 30, 2026 15:59

Copilot AI 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.

Pull request overview

Copilot reviewed 10 out of 10 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (3)

src/Compilers/Core/Portable/Symbols/ISymbol.cs:166

  • The opening sentence is grammatically awkward ("considered requires-unsafe") and also reads as if legacy-pointer cases are still "under the updated rules". Rewording to directly describe the observable behavior makes the API contract clearer.
        /// Whether this symbol is considered requires-<see langword="unsafe"/> under the updated memory safety rules,
        /// i.e., the symbol requires an <see langword="unsafe"/> context at its use site.
        /// This can be either a symbol compiled with the updated memory safety rules which has <see langword="unsafe"/> in its signature,
        /// or a symbol compiled with the legacy memory safety rules which has pointers in its signature.
        /// </summary>

src/Workspaces/SharedUtilitiesAndExtensions/Workspace/Core/CodeGeneration/Symbols/CodeGenerationSymbol.cs:136

  • The CA1822 suppression can be avoided by implementing RequiresUnsafe as an explicit ISymbol member. That removes the need for a #pragma while still satisfying the interface and keeping behavior the same (always false).
    // CA1822 suppression is needed until all projects using this file are updated to newest Roslyn which has this member on ISymbol.
#pragma warning disable CA1822 // Mark members as static
    public bool RequiresUnsafe => false;
#pragma warning restore CA1822

src/Compilers/CSharp/Portable/Symbols/Symbol.cs:623

  • This comment says we’re only tracking a terminology change, but the XML docs immediately below still describe "caller-unsafe" and the method is still named GetCallerUnsafeMode. Suggest updating the comment to reflect the current purpose (public API exposure) so it doesn’t become misleading/stale.
        // https://github.com/dotnet/roslyn/issues/82546: change terminology from "caller unsafe" to "requires unsafe"

@jjonescz
jjonescz enabled auto-merge (squash) July 31, 2026 07:50
@jjonescz
jjonescz merged commit 496dd9c into dotnet:main Jul 31, 2026
27 of 28 checks passed
@jjonescz
jjonescz deleted the Unsafe-45-SymbolApi branch July 31, 2026 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants