-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Handle cycles in IsValueType and IsReferenceType binding constraints #47968
Changes from 8 commits
bc5d41e
cbbf3b8
3c76be2
417f48b
9367f0a
d88c2fd
2558034
f9061da
89eeb4c
d1360db
6e1fe38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ internal ImmutableArray<TypeWithAnnotations> TypeArgumentsWithDefinitionUseSiteD | |
|
||
foreach (var typeArgument in result) | ||
{ | ||
typeArgument.Type.OriginalDefinition.AddUseSiteDiagnostics(ref useSiteDiagnostics); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why not simply access DefaultType here? #Closed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would be good to avoid repeating In reply to: 493955260 [](ancestors = 493955260) |
||
typeArgument.AddUseSiteDiagnostics(ref useSiteDiagnostics); | ||
} | ||
|
||
return result; | ||
|
@@ -72,7 +72,7 @@ internal ImmutableArray<TypeWithAnnotations> TypeArgumentsWithDefinitionUseSiteD | |
internal TypeWithAnnotations TypeArgumentWithDefinitionUseSiteDiagnostics(int index, ref HashSet<DiagnosticInfo> useSiteDiagnostics) | ||
{ | ||
var result = TypeArgumentsWithAnnotationsNoUseSiteDiagnostics[index]; | ||
result.Type.OriginalDefinition.AddUseSiteDiagnostics(ref useSiteDiagnostics); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Why not simply access DefaultType here? #Closed |
||
result.AddUseSiteDiagnostics(ref useSiteDiagnostics); | ||
return result; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -251,15 +251,18 @@ private ImmutableArray<TypeParameterSymbol> MakeTypeParameters(DiagnosticBag dia | |
/// <summary> | ||
/// Returns the constraint clause for the given type parameter. | ||
/// </summary> | ||
internal TypeParameterConstraintClause GetTypeParameterConstraintClause(int ordinal) | ||
internal TypeParameterConstraintClause GetTypeParameterConstraintClause(bool canIgnoreNullableContext, int ordinal) | ||
{ | ||
var clauses = _lazyTypeParameterConstraints; | ||
if (clauses.IsDefault) | ||
if (!clauses.HasValue(canIgnoreNullableContext)) | ||
{ | ||
var diagnostics = DiagnosticBag.GetInstance(); | ||
if (ImmutableInterlocked.InterlockedInitialize(ref _lazyTypeParameterConstraints, MakeTypeParameterConstraints(diagnostics))) | ||
if (ImmutableInterlocked.InterlockedCompareExchange(ref _lazyTypeParameterConstraints, MakeTypeParameterConstraints(canIgnoreNullableContext, diagnostics), clauses) == clauses) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is there a possibility of a race here? If a thread with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
{ | ||
this.AddDeclarationDiagnostics(diagnostics); | ||
if (_lazyTypeParameterConstraints.HasValue(canIgnoreNullableContext: false)) | ||
{ | ||
this.AddDeclarationDiagnostics(diagnostics); | ||
} | ||
} | ||
diagnostics.Free(); | ||
clauses = _lazyTypeParameterConstraints; | ||
|
@@ -268,7 +271,7 @@ internal TypeParameterConstraintClause GetTypeParameterConstraintClause(int ordi | |
return (clauses.Length > 0) ? clauses[ordinal] : TypeParameterConstraintClause.Empty; | ||
} | ||
|
||
private ImmutableArray<TypeParameterConstraintClause> MakeTypeParameterConstraints(DiagnosticBag diagnostics) | ||
private ImmutableArray<TypeParameterConstraintClause> MakeTypeParameterConstraints(bool canIgnoreNullableContext, DiagnosticBag diagnostics) | ||
{ | ||
var typeParameters = this.TypeParameters; | ||
var results = ImmutableArray<TypeParameterConstraintClause>.Empty; | ||
|
@@ -317,9 +320,10 @@ private ImmutableArray<TypeParameterConstraintClause> MakeTypeParameterConstrain | |
// Wrap binder from factory in a generic constraints specific binder | ||
// to avoid checking constraints when binding type names. | ||
Debug.Assert(!binder.Flags.Includes(BinderFlags.GenericConstraintsClause)); | ||
binder = binder.WithContainingMemberOrLambda(this).WithAdditionalFlags(BinderFlags.GenericConstraintsClause | BinderFlags.SuppressConstraintChecks); | ||
binder = binder.WithContainingMemberOrLambda(this).WithAdditionalFlags( | ||
BinderFlags.GenericConstraintsClause | BinderFlags.SuppressConstraintChecks | (canIgnoreNullableContext ? BinderFlags.IgnoreNullableContext : 0)); | ||
|
||
constraints = binder.BindTypeParameterConstraintClauses(this, typeParameters, typeParameterList, constraintClauses, ref isValueTypeOverride, diagnostics); | ||
constraints = binder.BindTypeParameterConstraintClauses(this, typeParameters, typeParameterList, constraintClauses, canIgnoreNullableContext, ref isValueTypeOverride, diagnostics); | ||
} | ||
|
||
Debug.Assert(constraints.Length == arity); | ||
|
@@ -438,7 +442,7 @@ private ImmutableArray<TypeParameterConstraintClause> MergeConstraintsForPartial | |
} | ||
|
||
builder[i] = TypeParameterConstraintClause.Create(mergedKind, | ||
mergedConstraintTypes?.ToImmutableAndFree() ?? originalConstraintTypes); | ||
mergedConstraintTypes?.ToImmutableAndFree() ?? originalConstraintTypes, ignoresNullableContext: constraint.IgnoresNullableContext); | ||
} | ||
} | ||
|
||
|
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 not simply access
DefaultType
here? #Closed