Skip to content

Commit

Permalink
Simplify and reduce amount of work performed by SourcePropertySymbolB…
Browse files Browse the repository at this point in the history
…ase constructor. (#49360)

Closes #45489.
  • Loading branch information
AlekseyTs authored Nov 19, 2020
1 parent 881e4bc commit bd92aeb
Show file tree
Hide file tree
Showing 13 changed files with 628 additions and 484 deletions.
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Binder/Binder_Statements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1628,7 +1628,7 @@ private static bool AccessingAutoPropertyFromConstructor(BoundExpression receive
var propertyIsStatic = propertySymbol.IsStatic;

return (object)sourceProperty != null &&
sourceProperty.IsAutoProperty &&
sourceProperty.IsAutoPropertyWithGetAccessor &&
TypeSymbol.Equals(sourceProperty.ContainingType, fromMember.ContainingType, TypeCompareKind.ConsiderEverything2) &&
IsConstructorOrField(fromMember, isStatic: propertyIsStatic) &&
(propertyIsStatic || receiver.Kind == BoundKind.ThisReference);
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/Compiler/MethodCompiler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@ syntaxNode is ConstructorDeclarationSyntax constructorSyntax &&
else
{
var property = sourceMethod.AssociatedSymbol as SourcePropertySymbolBase;
if ((object)property != null && property.IsAutoProperty)
if ((object)property != null && property.IsAutoPropertyWithGetAccessor)
{
return MethodBodySynthesizer.ConstructAutoPropertyAccessorBody(sourceMethod);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private BoundExpression MakePropertyAssignment(
if (setMethod is null)
{
var autoProp = (SourcePropertySymbolBase)property;
Debug.Assert(autoProp.IsAutoProperty,
Debug.Assert(autoProp.IsAutoPropertyWithGetAccessor,
"only autoproperties can be assignable without having setters");

var backingField = autoProp.BackingField;
Expand Down
15 changes: 10 additions & 5 deletions src/Compilers/CSharp/Portable/Symbols/CompletionPart.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,16 @@ internal enum CompletionPart
TypeParameterSymbolAll = Attributes | TypeParameterConstraints,

// For property symbols
StartPropertyParameters = 1 << 4,
FinishPropertyParameters = 1 << 5,
StartPropertyType = 1 << 6,
FinishPropertyType = 1 << 7,
PropertySymbolAll = Attributes | StartPropertyParameters | FinishPropertyParameters | StartPropertyType | FinishPropertyType,
StartPropertyEnsureSignature = 1 << 4,
FinishPropertyEnsureSignature = 1 << 5,
StartPropertyParameters = 1 << 6,
FinishPropertyParameters = 1 << 7,
StartPropertyType = 1 << 8,
FinishPropertyType = 1 << 9,
StartPropertyFinalCompletion = 1 << 10,
FinishPropertyFinalCompletion = 1 << 11,
PropertySymbolAll = Attributes | StartPropertyEnsureSignature | FinishPropertyEnsureSignature | StartPropertyParameters | FinishPropertyParameters |
StartPropertyType | FinishPropertyType | StartPropertyFinalCompletion | FinishPropertyFinalCompletion,

// For alias symbols
AliasTarget = 1 << 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3291,15 +3291,15 @@ ImmutableArray<PropertySymbol> addProperties(ImmutableArray<ParameterSymbol> rec
}
if (existingMember is null)
{
addProperty(new SynthesizedRecordPropertySymbol(this, syntax, param, isOverride: false, diagnostics));
addProperty(new SynthesizedRecordPropertySymbol(this, syntax, param, isOverride: false));
}
else if (existingMember is PropertySymbol { IsStatic: false, GetMethod: { } } prop
&& prop.TypeWithAnnotations.Equals(param.TypeWithAnnotations, TypeCompareKind.AllIgnoreOptions))
{
// There already exists a member corresponding to the candidate synthesized property.
if (isInherited && prop.IsAbstract)
{
addProperty(new SynthesizedRecordPropertySymbol(this, syntax, param, isOverride: true, diagnostics));
addProperty(new SynthesizedRecordPropertySymbol(this, syntax, param, isOverride: true));
}
else
{
Expand All @@ -3320,6 +3320,8 @@ void addProperty(SynthesizedRecordPropertySymbol property)
{
existingOrAddedMembers.Add(property);
members.Add(property);
Debug.Assert(property.GetMethod is object);
Debug.Assert(property.SetMethod is object);
members.Add(property.GetMethod);
members.Add(property.SetMethod);
members.Add(property.BackingField);
Expand Down Expand Up @@ -3393,7 +3395,7 @@ PropertySymbol addEqualityContract()

if (!memberSignatures.TryGetValue(targetProperty, out Symbol? existingEqualityContractProperty))
{
equalityContract = new SynthesizedRecordEqualityContractProperty(this, diagnostics);
equalityContract = new SynthesizedRecordEqualityContractProperty(this);
members.Add(equalityContract);
members.Add(equalityContract.GetMethod);
}
Expand Down
Loading

0 comments on commit bd92aeb

Please sign in to comment.