-
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
Don't wrap fields in ValueTuple definitions #44231
Changes from 26 commits
72dc304
881e92d
21f72af
348daea
4154f07
758a8be
f4b0b9e
df14519
f491231
6400146
2054720
fc85a89
74cfed2
c422d49
c57a02b
c18e709
49199b8
5575125
52dba4d
92cf81d
e40f8c3
ae512eb
612364d
a3706e7
6b52689
9eeeecb
d260464
59933df
465438c
77e86db
ac45f85
1b2eb98
2484dc0
f02ee32
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 |
---|---|---|
|
@@ -409,6 +409,7 @@ Cci.ITypeReference Cci.ITypeDefinition.GetBaseClass(EmitContext context) | |
foreach (var f in AdaptedNamedTypeSymbol.GetFieldsToEmit()) | ||
{ | ||
Debug.Assert((object)(f.TupleUnderlyingField ?? f) == f); | ||
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.
I think we should keep the assert. #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. In fact, I think we should make it even stronger and make sure we don't run into a In reply to: 426203595 [](ancestors = 426203595) 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 doesn't look like the thread is actually addressed and no other response provided. In reply to: 426264743 [](ancestors = 426264743,426203595) |
||
Debug.Assert(!(f is TupleErrorFieldSymbol)); | ||
if (isStruct || f.GetCciAdapter().ShouldInclude(context)) | ||
{ | ||
yield return f.GetCciAdapter(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,12 +275,14 @@ private void ValidateReferencedAssembly(AssemblySymbol assembly, AssemblyReferen | |
AddSymbolLocation(result, member); | ||
break; | ||
case SymbolKind.Field: | ||
// NOTE: Dev11 does not add synthesized backing fields for properties, | ||
// but adds backing fields for events, Roslyn adds both | ||
if (member is TupleErrorFieldSymbol) | ||
{ | ||
var field = (FieldSymbol)member; | ||
AddSymbolLocation(result, field.TupleUnderlyingField ?? field); | ||
break; | ||
} | ||
|
||
// NOTE: Dev11 does not add synthesized backing fields for properties, | ||
// but adds backing fields for events, Roslyn adds both | ||
AddSymbolLocation(result, member); | ||
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 feels like we should skip |
||
break; | ||
|
||
case SymbolKind.Event: | ||
|
@@ -290,7 +292,7 @@ private void ValidateReferencedAssembly(AssemblySymbol assembly, AssemblyReferen | |
FieldSymbol field = ((EventSymbol)member).AssociatedField; | ||
if ((object)field != null) | ||
{ | ||
AddSymbolLocation(result, field.TupleUnderlyingField ?? field); | ||
AddSymbolLocation(result, field); | ||
} | ||
} | ||
break; | ||
|
@@ -1042,7 +1044,9 @@ internal Cci.IFieldReference Translate( | |
bool needDeclaration = false) | ||
{ | ||
Debug.Assert(fieldSymbol.IsDefinitionOrDistinct()); | ||
Debug.Assert(!fieldSymbol.IsVirtualTupleField && (object)(fieldSymbol.TupleUnderlyingField ?? fieldSymbol) == fieldSymbol, "tuple fields should be rewritten to underlying by now"); | ||
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.
I think we should keep this condition, it is still bad to violate it. #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. In fact, I think we should make the assert even stronger and make sure we don't run into a In reply to: 426203778 [](ancestors = 426203778) 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 doesn't look like the thread is actually addressed completely and no other response provided. In reply to: 426264817 [](ancestors = 426264817,426203778) |
||
Debug.Assert(!fieldSymbol.IsVirtualTupleField && | ||
(object)(fieldSymbol.TupleUnderlyingField ?? fieldSymbol) == fieldSymbol && | ||
!(fieldSymbol is TupleErrorFieldSymbol), "tuple fields should be rewritten to underlying by now"); | ||
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.
Nit: consider |
||
|
||
if (!fieldSymbol.IsDefinition) | ||
{ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -401,6 +401,16 @@ public virtual bool IsDefaultTupleElement | |
{ | ||
get | ||
{ | ||
Debug.Assert(!(this is TupleElementFieldSymbol) && !(this is TupleErrorFieldSymbol)); | ||
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.
Consider 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. |
||
return TupleElementIndex >= 0; | ||
} | ||
} | ||
|
||
public virtual bool IsExplicitlyNamedTupleElement | ||
{ | ||
get | ||
{ | ||
Debug.Assert(!(this is TupleElementFieldSymbol) && !(this is TupleErrorFieldSymbol)); | ||
return false; | ||
} | ||
} | ||
|
@@ -414,6 +424,7 @@ public virtual FieldSymbol TupleUnderlyingField | |
{ | ||
get | ||
{ | ||
Debug.Assert(!(this is TupleElementFieldSymbol)); | ||
return ContainingType.IsTupleType ? this : null; | ||
} | ||
} | ||
|
@@ -426,7 +437,8 @@ public virtual FieldSymbol CorrespondingTupleField | |
{ | ||
get | ||
{ | ||
return null; | ||
Debug.Assert(!(this is TupleElementFieldSymbol)); | ||
return TupleElementIndex >= 0 ? this : null; | ||
} | ||
} | ||
|
||
|
@@ -447,6 +459,18 @@ public virtual int TupleElementIndex | |
{ | ||
get | ||
{ | ||
// wrapped tuple fields already have this information and override this property | ||
Debug.Assert(!(this is TupleElementFieldSymbol) && !(this is TupleErrorFieldSymbol)); | ||
|
||
if (ContainingType.IsTupleType) | ||
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 check seems unnecessary. #Closed |
||
{ | ||
var map = ContainingType.TupleFieldDefinitionsToIndexMap; | ||
if (map is object && map.TryGetValue(this.OriginalDefinition, out int index)) | ||
{ | ||
return index; | ||
} | ||
} | ||
|
||
return -1; | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,17 +122,37 @@ public override IEnumerable<string> MemberNames | |
|
||
public override ImmutableArray<Symbol> GetMembers() | ||
{ | ||
return this.RetargetingTranslator.Retarget(_underlyingType.GetMembers()); | ||
var result = this.RetargetingTranslator.Retarget(_underlyingType.GetMembers()); | ||
if (!this.IsTupleType) | ||
{ | ||
return result; | ||
} | ||
|
||
// For ValueTuple definitions, we may have to re-insert tuple error fields | ||
return this.AddOrWrapTupleMembers(result).ToImmutableAndFree(); | ||
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.
Symbols for real fields are going to be cached and reused by RetargetingTranslator. I think we should find a way to reuse symbols for added tuple error fields in a similar fashion. #Closed |
||
} | ||
|
||
internal override ImmutableArray<Symbol> GetMembersUnordered() | ||
{ | ||
return this.RetargetingTranslator.Retarget(_underlyingType.GetMembersUnordered()); | ||
var result = this.RetargetingTranslator.Retarget(_underlyingType.GetMembersUnordered()); | ||
if (!this.IsTupleType) | ||
{ | ||
return result; | ||
} | ||
|
||
// For ValueTuple definitions, we may have to re-insert tuple error fields | ||
return this.AddOrWrapTupleMembers(result).ToImmutableAndFree(); | ||
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.
Similar comment here #Closed |
||
} | ||
|
||
public override ImmutableArray<Symbol> GetMembers(string name) | ||
{ | ||
return this.RetargetingTranslator.Retarget(_underlyingType.GetMembers(name)); | ||
if (!this.IsTupleType) | ||
{ | ||
return this.RetargetingTranslator.Retarget(_underlyingType.GetMembers(name)); | ||
} | ||
|
||
// For ValueTuple definitions, we may have to re-insert tuple error fields | ||
return GetMembers().WhereAsArray(m => m.Name == name); | ||
} | ||
|
||
internal override IEnumerable<FieldSymbol> GetFieldsToEmit() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -805,7 +805,10 @@ public ImmutableArray<Symbol> Retarget(ImmutableArray<Symbol> arr) | |
|
||
foreach (var s in arr) | ||
{ | ||
symbols.Add(Retarget(s)); | ||
if (!(s is TupleErrorFieldSymbol)) | ||
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.
I think that instead of doing filtering here and making changes to compensate for it in RetargetingNamedTypeSymbol.cs we should change an implementation of |
||
{ | ||
symbols.Add(Retarget(s)); | ||
} | ||
} | ||
|
||
return symbols.ToImmutableAndFree(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1282,14 +1282,18 @@ internal override IEnumerable<FieldSymbol> GetFieldsToEmit() | |
switch (m.Kind) | ||
{ | ||
case SymbolKind.Field: | ||
var field = (FieldSymbol)m; | ||
yield return field.TupleUnderlyingField ?? field; | ||
if (m is TupleErrorFieldSymbol) | ||
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.
When do we try to emit with error fields? #Resolved 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 is recognized as a 2-tuple, and thus has In reply to: 425348604 [](ancestors = 425348604) |
||
{ | ||
break; | ||
} | ||
|
||
yield return (FieldSymbol)m; | ||
break; | ||
case SymbolKind.Event: | ||
FieldSymbol? associatedField = ((EventSymbol)m).AssociatedField; | ||
if ((object?)associatedField != null) | ||
{ | ||
yield return associatedField.TupleUnderlyingField ?? associatedField; | ||
yield return associatedField; | ||
} | ||
break; | ||
} | ||
|
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.
It looks like there is an extra empty line above #Closed