Ref fields feature requires ByRefFields runtime flag#62941
Ref fields feature requires ByRefFields runtime flag#62941jcouv merged 12 commits intodotnet:mainfrom
Conversation
f0dedc9 to
fb5fcda
Compare
| }" | ||
| Dim comp = CreateCSharpCompilation(GetUniqueName(), source, parseOptions:=New CSharp.CSharpParseOptions(CSharp.LanguageVersion.Preview)) | ||
| comp.VerifyDiagnostics() | ||
| comp.VerifyDiagnostics( |
There was a problem hiding this comment.
Please use AssertTheseDiagnostics #Resolved
There was a problem hiding this comment.
Had tried that, but it fails with System.InvalidCastException : Unable to cast object of type 'Microsoft.CodeAnalysis.CSharp.CSharpCompilation' to type 'Microsoft.CodeAnalysis.VisualBasic.VisualBasicCompilation'.
There was a problem hiding this comment.
Also, I'd considered getting ride of the diagnostic, by adding a runtime flag, but the C# test hook can't easily be reached from VB tests.
Another option is to skip the test until we have TargetFramework.Net70
There was a problem hiding this comment.
Then please at least include what these errors are.
|
|
||
| private static string IncludeExpectedOutput(string expectedOutput) => IsNet70OrGreater() ? expectedOutput : null; | ||
|
|
||
| private static MetadataReference MscorlibRefWithoutSharingCachedSymbols |
There was a problem hiding this comment.
There's only two tests that use this. What are you trying to achieve?
There was a problem hiding this comment.
I was mistaken. I thought this was used in more tests, and that all tests could share a common reference.
| }"; | ||
| var comp = CreateCompilation(sourceA, parseOptions: TestOptions.Regular10); | ||
| var mscorlibWithRefFields = MscorlibRefWithoutSharingCachedSymbols; | ||
| var comp = CreateByRefFieldsCompilation(sourceA, references: new[] { mscorlibWithRefFields }, parseOptions: TestOptions.Regular10); |
There was a problem hiding this comment.
CreateByRefFieldsCompilation(sourceA, references: new[] { mscorlibWithRefFields }, parseOptions: TestOptions.Regular10)
Could we hide most of the work in CreateCompilation()?
For instance, add a parameter to CreateCompilation(..., RuntimeFeatures runtimeFeatures, ...) that creates a cloned version of the appropriate corlib with the necessary features enabled, and that cloned version is created at most once and shared with all callers that need the same set of features. #Resolved
| // RuntimeSupportsByRefFields property for it. | ||
| var mscorlibRefWithRefFields = | ||
| ((AssemblyMetadata)((MetadataImageReference)MscorlibRef).GetMetadata()).CopyWithoutSharingCachedSymbols(). | ||
| GetReference(display: "mscorlib.v4_0_30319.dll"); |
There was a problem hiding this comment.
Can we calculate this once and cache the value, perhaps in CSharpTestBase? #Resolved
There was a problem hiding this comment.
Perhaps each caller needs a separate instance in case not all callers set the same runtime features. In that case, consider extracting a helper method in the base class.
|
@333fred for second review. Thanks |
|
@333fred for second review. Thanks |
| => RuntimeSupportsFeature(SpecialMember.System_Runtime_CompilerServices_RuntimeFeature__ByRefFields); | ||
| internal virtual bool RuntimeSupportsByRefFields | ||
| { | ||
| get |
There was a problem hiding this comment.
Nit: please use consistent style between these two one-line methods :). #Resolved
| var comp = CreateCompilation(sourceA, parseOptions: TestOptions.Regular10); | ||
| var mscorlibRefWithRefFields = GetMscorlibRefWithoutSharingCachedSymbols(); | ||
|
|
||
| // Note: we use skipUsesIsNullable and skipExtraValidation so that nobody pulls |
There was a problem hiding this comment.
I'm confused why this is necessary. I wouldn't expect anything to be pulling on the compilation or it's references until the compilation is actually used? Can you clarify why we need to do this for this particular flag, but haven't needed to for any of the other RuntimeSupports bypass flags? #Resolved
There was a problem hiding this comment.
We don't need this for this particular flag, but we need it for certain flags such as numeric IntPtr (pattern that I'm following).
I'll remove but we should have a discussion at some point on a universal test hook, so that we don't have to special-case every new runtime feature flag.
There was a problem hiding this comment.
I opened an issue (#63223) to sit down and design a general/re-usable CreateCompilation API supporting what we need, including a note on skipUsesIsNullable and skipExtraValidation since some features need those but some don't.
|
|
||
| private static string IncludeExpectedOutput(string expectedOutput) => IsNet70OrGreater() ? expectedOutput : null; | ||
|
|
||
| private static IEnumerable<MetadataReference> CopyWithoutSharingCachedSymbols(IEnumerable<MetadataReference> references) |
There was a problem hiding this comment.
Why is this necessary? It wasn't necessary for any previous feature that set override flags. #Resolved
There was a problem hiding this comment.
This is used in two tests that need more than mscorlib. For example, one needs dynamic machinery.
Unless those previous features tests such combinations, they would not run into this situation.
I can't say that I understand CopyWithoutSharingCachedSymbols well enough to say there isn't a better way to do this. I'm happy to open a tracking issue to re-discuss when Aleksey is back.
There was a problem hiding this comment.
Filed #63222 to review usages of CopyWithoutSharingCachedSymbols()
Fixes #62919
Relates to test plan #59194