Skip to content
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

Allow users to define EmbeddedAttribute #76523

Merged
merged 13 commits into from
Jan 3, 2025

Conversation

333fred
Copy link
Member

@333fred 333fred commented Dec 19, 2024

Alternative approach to #71546. Today, our enforcement of whether to allow users to define Microsoft.CodeAnalysis.EmbeddedAttribute is inconsistent; if we need to generate it, we error if the user defines one. But if the we don't need to generate it (as we increasingly do not since .NET 6), we allow the user to define their own version. This PR standardizes our enforcement, and enables the compiler to use the user-declared attribute instead generating one. We also document the breaking change from the standardized enforcement.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 19, 2024
@333fred 333fred marked this pull request as ready for review December 19, 2024 20:18
@333fred 333fred requested a review from a team as a code owner December 19, 2024 20:18
@333fred
Copy link
Member Author

333fred commented Dec 19, 2024

@dotnet/roslyn-compiler for review. I'll propose a source-generation API to allow authors to create this API easily, but this change can go in separately. For VB, there are existing tests verifying that it respects the EmbeddedAttribute definition, and allows defining in the same assembly. I opted not to enforce any shape on the VB as it doesn't do any form of validation in any scenario for the attribute definition today. We now validate the VB side, because we will synthesize an EmbeddedAttribute application for the type. This has also been documented as a breaking change.

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Dec 20, 2024

Done with review pass (commit 8) #Closed

@333fred
Copy link
Member Author

333fred commented Dec 21, 2024

@AlekseyTs I believe I've address your feedback, thanks!


***Introduced in Visual Studio 2022 version 17.13***

The compiler now validates the shape of `Microsoft.CodeAnalysis.EmbeddedAttribute` when declared in source. Previously, the compiler
Copy link
Member

Choose a reason for hiding this comment

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

Unrelated to the PR: it's not clear to me what the Microsoft.CodeAnalysis.EmbeddedAttribute does. Is that documented somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Not documented afaik, though we will when we add the SG API. It prevents the compiler from resolving the type outside the current compilation. It's how the compiler itself gets around the "type defined in multiple assemblies" issues when it needs to synthesize an attribute.

@333fred
Copy link
Member Author

333fred commented Dec 27, 2024

@AlekseyTs addressed feedback, thanks!

@AlekseyTs
Copy link
Contributor

AlekseyTs commented Jan 2, 2025

Done with review pass (commit 11) #Closed

@333fred
Copy link
Member Author

333fred commented Jan 2, 2025

@AlekseyTs @cston for another review pass

Copy link
Contributor

@AlekseyTs AlekseyTs left a comment

Choose a reason for hiding this comment

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

LGTM (commit 12)

@333fred 333fred enabled auto-merge (squash) January 3, 2025 21:06
@333fred 333fred merged commit 0396afe into dotnet:main Jan 3, 2025
24 checks passed
@dotnet-policy-service dotnet-policy-service bot added this to the Next milestone Jan 3, 2025
@333fred 333fred deleted the allow-user-defined-embedded branch January 3, 2025 22:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants