-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Generate custom attributes from metadata instead of type system #100763
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
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6ed48bc
wip
MichalStrehovsky de5ce9a
Update Transform.CustomAttribute.cs
MichalStrehovsky 2866dac
Fixes
MichalStrehovsky 1892ab3
Update Transform.CustomAttribute.cs
MichalStrehovsky 7d5e6bb
Rename
MichalStrehovsky 14b76b3
Test update
MichalStrehovsky 338a688
UnreachableException
MichalStrehovsky 2bbdc90
Assert -> Throw
MichalStrehovsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Update Transform.CustomAttribute.cs
- Loading branch information
commit 1892ab34cad179a3c3c069c7b48ce936e24ef372
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cts.ThrowHelper.ThrowBadImageFormatExceptionorthrow new UnreachableException()?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cts.ThrowHelper.ThrowBadImageFormatExceptionis not a throw for C#, so it won't work.Any opinion about simply disabling warning CS8509 ILCompiler-project-wide?
We keep having to work around it by adding artificial throws, or worse, by adding
_ =>for something that could be one concrete value (SomeFoo =>), but the right-hand side happens to throw for all the other possibilities, so it's as good as an extra_ => throw new Blah()line.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The compiler is going to add throw for cases that are not covered by the switch. The difference here is whether the code is explicitly handling it with a throw or whether you let the compiler to generate the throw implicitly. Many of the compiler warnings and our own coding conventions rules force you to write more verbose and explicit code, so I see the CS8509 warning as just another one of those.
I think we should throw BIF for invalid input files when we have a choice. If these default switch cases are reachable for invalid input (it is not obvious to me whether it is the case), we may want to add
Cts.ThrowHelper.CreateBadImageFormatExceptionand change them tothrow Cts.ThrowHelper.CreateBadImageFormatException().There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The thing is that I would be fine with the
SwitchExpressionExceptionthe compiler throws. Anything that kills the compilation is fine by me.I agree that our coding standards err on the more verbose side, so
throw new UnrechableExceptionsounds like the best fix.Throwing a Cts.BadImageException wouldn't make a difference here. This spot is non-recoverable; we're in the middle of generating metadata and can't change our mind about it. We already inspected the attribute for dependencies during dependency analysis so at this point we know it doesn't refer to something that doesn't exist (we'd skip it if it does). If it has some other structural issue we didn't detect during dependency analysis, I'm fine with a compiler crash. We try to be resilient for invalid inputs that could be the result of bad assembly version management, but we don't try to be resilient against source-to-IL compiler bugs. Too much resilience makes it difficult to surface our own bugs because this would also paper over those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parsing of custom attribute blobs can hit BadImageFormat exception due to user error. If the custom attribute references enum from a different assembly and the enum underlying type changes due to user error, parsing of the custom attribute blob will get lost and it will likely end up hitting one of these unreachable cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good point but it still needs to go to the other spot that parses it first (at the time we analyze dependencies). #101164 has the fix.