Skip to content

Add Microsoft.CodeAnalysis.Contracts source package #76997

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Feb 11, 2025

Conversation

tmat
Copy link
Member

@tmat tmat commented Feb 1, 2025

The package is intended to include a small number of essential contracts and polyfills used across Roslyn code base and in other Roslyn source packages (see #76937).

image

Introduction of this package simplifies the set of file links in Roslyn repository, makes it easier to apply Roslyn coding patterns across other related repositories (e.g. dotnet-watch, Razor, WebTools, Interactive Window, etc) and to use other Roslyn source packages in these repositories.

Moves all non-polyfill types to Microsoft.CodeAnalysis namespace (instead of Roslyn.Utilities). This move makes these core types immediately available in all Roslyn types defined in Microsoft.CodeAnalysis namespace or a subnamespace.

For Contract type, it avoids accidental mix-up with Microsoft.Diagnostics.Contracts.Contract type in non-VS layer, which doesn't benefit since it defines types under Microsoft.VisualStudio namespace.

TODO:

  • Contract type is not currently available in Compiler layer (only Workspace and up). We can use #if !MICROSOFT_CODEANALYSIS_CONTRACTS_NO_CONTRACT to keep it that way if desired.
  • Consider moving ExceptionUtilities.Unreachable and ExceptionUtilities.UnexpectedValue methods to Contract type. These helpers declare code contracts/assertions similar to those expressed by Throw* methods in Contract class.

@tmat tmat requested review from a team as code owners February 1, 2025 16:36
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Feb 1, 2025
@tmat tmat changed the title Adds Microsoft.CodeAnalysis.Contracts source package Add Microsoft.CodeAnalysis.Contracts source package Feb 1, 2025
@tmat
Copy link
Member Author

tmat commented Feb 3, 2025

@dotnet/roslyn-ide @dotnet/roslyn-compiler PTAL

@cston
Copy link
Contributor

cston commented Feb 4, 2025

  • Contract type is not currently available in Compiler layer (only Workspace and up). We can use #if !COMPILERCORE to keep it that way if desired.

That sounds reasonable to me, for consistency with the current state. Then we can discuss separately whether to include the Contract type in the compiler layer.

@tmat tmat force-pushed the ContractsSourcePackage branch 2 times, most recently from 820f4fe to 948d2ea Compare February 5, 2025 22:00
@tmat tmat force-pushed the ContractsSourcePackage branch from 948d2ea to 32af181 Compare February 7, 2025 04:04
<Compile Include="$(MSBuildThisFileDirectory)NullableAttributes.cs" />
<Compile Include="$(MSBuildThisFileDirectory)RequiredMemberAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)SetsRequiredMembersAttribute.cs" />
<Compile Include="$(MSBuildThisFileDirectory)ExceptionUtilities.cs" />
Copy link
Member

@jjonescz jjonescz Feb 11, 2025

Choose a reason for hiding this comment

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

Why not include glob *.cs rather than explicitly including each file?

Copy link
Member Author

Choose a reason for hiding this comment

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

Glob works but next time you edit the project VS screws it up :(.

Copy link
Member Author

@tmat tmat Feb 11, 2025

Choose a reason for hiding this comment

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

@JakeRadMSFT Can we get this fixed please? dotnet/project-system#6010
Working with shared projects in VS is such a PITA.

@tmat tmat merged commit eeff8ea into dotnet:main Feb 11, 2025
28 checks passed
@tmat tmat deleted the ContractsSourcePackage branch February 11, 2025 18:46
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Feb 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead VSCode
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants