Skip to content

Allow users to define EmbeddedAttribute#76523

Merged
333fred merged 13 commits into
dotnet:mainfrom
333fred:allow-user-defined-embedded
Jan 3, 2025
Merged

Allow users to define EmbeddedAttribute#76523
333fred merged 13 commits into
dotnet:mainfrom
333fred:allow-user-defined-embedded

Conversation

@333fred

@333fred 333fred commented Dec 19, 2024

Copy link
Copy Markdown
Member

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.

@ghost ghost 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

333fred commented Dec 19, 2024

Copy link
Copy Markdown
Member Author

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

Comment thread docs/compilers/CSharp/Compiler Breaking Changes - DotNet 10.md
Comment thread src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs Outdated
Comment thread src/Compilers/CSharp/Test/Emit3/Attributes/AttributeTests_Embedded.cs Outdated
Comment thread src/Compilers/CSharp/Test/Emit3/Attributes/AttributeTests_Embedded.cs Outdated
Comment thread src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs Outdated
@AlekseyTs

AlekseyTs commented Dec 20, 2024

Copy link
Copy Markdown
Contributor

Done with review pass (commit 8) #Closed

@333fred

333fred commented Dec 21, 2024

Copy link
Copy Markdown
Member Author

@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
Copy Markdown
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
Copy Markdown
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.

Comment thread docs/compilers/Visual Basic/Compiler Breaking Changes - DotNet 10.md Outdated
Comment thread docs/compilers/Visual Basic/Compiler Breaking Changes - DotNet 10.md Outdated
Comment thread src/Compilers/CSharp/Portable/Symbols/Source/SourceNamedTypeSymbol.cs Outdated
Comment thread src/Compilers/CSharp/Test/Emit3/Attributes/AttributeTests_Embedded.cs Outdated
Comment thread src/Compilers/VisualBasic/Portable/Symbols/Source/SourceNamedTypeSymbol.vb Outdated
Comment thread src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests.vb Outdated
Comment thread src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests.vb
@AlekseyTs

AlekseyTs commented Jan 2, 2025

Copy link
Copy Markdown
Contributor

Done with review pass (commit 11) #Closed

@333fred

333fred commented Jan 2, 2025

Copy link
Copy Markdown
Member Author

@AlekseyTs @cston for another review pass

Comment thread docs/compilers/Visual Basic/Compiler Breaking Changes - DotNet 10.md Outdated
Comment thread src/Compilers/VisualBasic/Test/Emit/Attributes/AttributeTests.vb Outdated

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

Comment thread src/Compilers/CSharp/Portable/CSharpResources.resx Outdated
@333fred 333fred enabled auto-merge (squash) January 3, 2025 21:06
@333fred 333fred merged commit 0396afe into dotnet:main Jan 3, 2025
@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
checkedsums pushed a commit to checkedsums/roslynjourneys that referenced this pull request Jan 5, 2025
* Work on embedded attribute recognition in source

* Add tests

* Additional testing

* Refactoring for simplicity

* Always validate in source, and document breaking change

* Typo

* Update test

* Synthesize an application of EmbeddedAttribute if EmbeddedAttribute itself didn't have one applied to it.

* Add VB validation implementation.

* More PR feedback.

* PR feedback

* Minor typo and feedback
@dibarbet dibarbet modified the milestones: Next, 17.13 P3 Jan 7, 2025
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.

5 participants