-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Ref fields feature requires ByRefFields runtime flag #62941
Conversation
f0dedc9
to
fb5fcda
Compare
@@ -5283,7 +5283,11 @@ ref struct S<T> | |||
ref readonly T F2; | |||
}" | |||
Dim comp = CreateCSharpCompilation(GetUniqueName(), source, parseOptions:=New CSharp.CSharpParseOptions(CSharp.LanguageVersion.Preview)) | |||
comp.VerifyDiagnostics() | |||
comp.VerifyDiagnostics( |
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.
Please use AssertTheseDiagnostics
#Resolved
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then please at least include what these errors are.
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.
Done review pass (commit 1)
@@ -30,6 +31,26 @@ private static bool IsNet70OrGreater() | |||
|
|||
private static string IncludeExpectedOutput(string expectedOutput) => IsNet70OrGreater() ? expectedOutput : null; | |||
|
|||
private static MetadataReference MscorlibRefWithoutSharingCachedSymbols |
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.
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.
There's only two tests that use this. What are you trying to achieve?
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.
I was mistaken. I thought this was used in more tests, and that all tests could share a common reference.
@@ -90,7 +111,8 @@ void M5(S<T> s5) | |||
M2(ref s5.F1); | |||
} | |||
}"; | |||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we calculate this once and cache the value, perhaps in CSharpTestBase? #Resolved
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.
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 |
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.
Done review pass (commit 9). @jcouv and I need to sync on the approach taken in the tests, as no previous bypass flag has needed this level of modification before.
=> RuntimeSupportsFeature(SpecialMember.System_Runtime_CompilerServices_RuntimeFeature__ByRefFields); | ||
internal virtual bool RuntimeSupportsByRefFields | ||
{ | ||
get |
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
@@ -30,6 +31,14 @@ private static bool IsNet70OrGreater() | |||
|
|||
private static string IncludeExpectedOutput(string expectedOutput) => IsNet70OrGreater() ? expectedOutput : null; | |||
|
|||
private static IEnumerable<MetadataReference> CopyWithoutSharingCachedSymbols(IEnumerable<MetadataReference> references) |
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.
Why is this necessary? It wasn't necessary for any previous feature that set override flags. #Resolved
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.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filed #63222 to review usages of CopyWithoutSharingCachedSymbols()
Fixes #62919
Relates to test plan #59194