-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add missing compiler-generated attributes to corelib #87857
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @dotnet/area-system-runtime-compilerservices |
Interesting - we had one test that expected to find runtime/src/libraries/System.Text.Json/tests/Common/UnsupportedTypesTests.cs Lines 173 to 182 in 9fc5fcb
Perhaps that test should fallback to looking in the core assembly for type ??= typeof(object).Assembly.GetType("System.Runtime.CompilerServices.NullableContextAttribute")!; |
@ericstj Either that or conditioning the |
I do want to hold off on this until we have a bit of time investigate on the roslyn-side about the correct ordering we should look for these attributes and making sure that we're not about to introduce a large metadata-breaking change as libraries update to .NET 8. I should have some time for that next week after we get collection literals merged. I don't expect to encounter unsolvable issues, but measure twice cut once. |
I wasn't sure if that test was actually specific to that type, or you just happened to choose it because it had the characteristics you needed to serve as a repro. From your comment in the issue:
So maybe we could add some test type that is guaranteed to have stripped parameter names. I actually don't understand why the JsonSerializer would ever try to serialize an attribute, unless the user passed in a value of that attribute to serialize which seems really unusual. |
I pushed a commit to disable the json test on netcoreapp. There are other failures on mono in release, all related to moq / castle, I'm guessing something to do with trimming. |
The original customer reported issue was trying to serialize that attribute. I tried reproducing the problem with a test type but couldn't. IIRC it had something to do with how the compiler emitted IL for the particular compiler generated attribute. |
I put my investigation notes into dotnet/roslyn#68697 (comment), but the TLDR is that our past selves were smart and thought about this, and we are good to proceed. |
@lewing, suggestions on how to track down why this is failing? Seems likely it's related to trimming, given the mono legs that are failing. |
c0be262
to
9c0668b
Compare
@stephentoub it looks like these failures are caused the bug fixed in castleproject/Core@979eb75. That was previously assuming all arrays in |
Still failing, but most were fixed by picking up the new version of Moq. Everything remaining is failing at this: var constructor = invocation.GetConstructors()[0]; Where |
Is it just a case of the constructors being linked out then an attempt to access them via reflection? AOT and EAT lanes trim the tests |
I'm not certain - looking through this code it seems to me like these types are generated at runtime with ref.emit - so the linker shouldn't be involved. I'm trying to debug what Moq is doing in the non-browser case to try and answer the question about "what types are these". |
Ok, so at least on windows I see these types being used:
That type does have a constructor, when not trimmed: https://github.com/castleproject/Core/blob/dca4ed09df545dd7512c82778127219795668d30/src/Castle.Core/DynamicProxy/Internal/InterfaceMethodWithoutTargetInvocation.cs#L28 So I downloaded the helix payload for the failing test and examined the IL, sure enough that constructor is missing:
That explains the error, but doesn't really explain why this PR would cause that. I see the same test passing in other PRs, so I'm downloading the helix payload from those to see if they differ (retain the constructor). |
I found this --
Which looks like it's preserving metadata on similar types... I wonder if something about the update I made to Moq / Castle.Core caused it to start hitting this codepath that it did not before and we just need to root more types for the linker 🤔. |
I see -- indeed that is the problem. This change started using the type in Castle.Core instead of emitting a type: castleproject/Core@0c8f9d0#diff-4ba914dc0e136772f890d9ffaf385d702f91df37c92f648ff06bb31a39def6c1 That change came down as part of the update to Moq so I'll need to include that type in the ILLink.Descriptors.Castle.xml. |
Ok - I learned how to get a repro in a plain-old console app. |
All remaining issues in PR validation are known failures. |
.. attributes. Prompted by dotnet/runtime#87857 .
Fixes #85612
Cherry-picked @ericstj's commit for adding these and then tweaked it a bit (e.g. added docs and tests).