Skip to content
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

IOperation Test Porting Pt 3 #51206

Merged
merged 14 commits into from
Feb 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 40 additions & 39 deletions src/Compilers/CSharp/Portable/Binder/Binder_Attributes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ private BoundAttribute BindAttributeCore(AttributeSyntax node, NamedTypeSymbol a
MethodSymbol? attributeConstructor = null;

// Bind attributeType's constructor based on the bound constructor arguments
ImmutableArray<BoundExpression> boundConstructorArguments;
if (!attributeTypeForBinding.IsErrorType())
{
attributeConstructor = BindAttributeConstructor(node,
Expand All @@ -165,8 +166,16 @@ private BoundAttribute BindAttributeCore(AttributeSyntax node, NamedTypeSymbol a
suppressErrors: attributeType.IsErrorType(),
ref argsToParamsOpt,
ref expanded,
ref useSiteInfo);
ref useSiteInfo,
out boundConstructorArguments);
}
else
{
boundConstructorArguments = analyzedArguments.ConstructorArguments.Arguments.SelectAsArray(
static (arg, attributeArgumentBinder) => attributeArgumentBinder.BindToTypeForErrorRecovery(arg),
attributeArgumentBinder);
}
Debug.Assert(boundConstructorArguments.All(a => !a.NeedsToBeConverted()));
diagnostics.Add(node, useSiteInfo);

if (attributeConstructor is object)
Expand All @@ -179,11 +188,11 @@ private BoundAttribute BindAttributeCore(AttributeSyntax node, NamedTypeSymbol a
}
}

var constructorArguments = analyzedArguments.ConstructorArguments;
ImmutableArray<BoundExpression> boundConstructorArguments = constructorArguments.Arguments.ToImmutableAndFree();
ImmutableArray<string> boundConstructorArgumentNamesOpt = constructorArguments.GetNames();
ImmutableArray<BoundExpression> boundNamedArguments = analyzedArguments.NamedArguments;
constructorArguments.Free();
ImmutableArray<string> boundConstructorArgumentNamesOpt = analyzedArguments.ConstructorArguments.GetNames();
ImmutableArray<BoundAssignmentOperator> boundNamedArguments = analyzedArguments.NamedArguments?.ToImmutableAndFree() ?? ImmutableArray<BoundAssignmentOperator>.Empty;
Debug.Assert(boundNamedArguments.All(arg => !arg.Right.NeedsToBeConverted()));

analyzedArguments.ConstructorArguments.Free();

return new BoundAttribute(node, attributeConstructor, boundConstructorArguments, boundConstructorArgumentNamesOpt, argsToParamsOpt, expanded,
boundNamedArguments, resultKind, attributeType, hasErrors: resultKind != LookupResultKind.Viable);
Expand Down Expand Up @@ -293,19 +302,18 @@ protected bool IsAttributeConditionallyOmitted(NamedTypeSymbol attributeType, Sy
}

/// <summary>
/// The result of this method captures some AnalyzedArguments, which must be free'ed by the caller.
/// The caller is responsible for freeing <see cref="AnalyzedAttributeArguments.ConstructorArguments"/> and <see cref="AnalyzedAttributeArguments.NamedArguments"/>.
/// </summary>
private AnalyzedAttributeArguments BindAttributeArguments(
AttributeArgumentListSyntax? attributeArgumentList,
NamedTypeSymbol attributeType,
BindingDiagnosticBag diagnostics)
{
var boundConstructorArguments = AnalyzedArguments.GetInstance();
var boundNamedArguments = ImmutableArray<BoundExpression>.Empty;
ArrayBuilder<BoundAssignmentOperator>? boundNamedArgumentsBuilder = null;

if (attributeArgumentList != null)
{
ArrayBuilder<BoundExpression>? boundNamedArgumentsBuilder = null;
HashSet<string>? boundNamedArgumentsSet = null;

// Only report the first "non-trailing named args required C# 7.2" error,
Expand Down Expand Up @@ -342,7 +350,7 @@ private AnalyzedAttributeArguments BindAttributeArguments(
string argumentName = argument.NameEquals.Name.Identifier.ValueText!;
if (boundNamedArgumentsBuilder == null)
{
boundNamedArgumentsBuilder = ArrayBuilder<BoundExpression>.GetInstance();
boundNamedArgumentsBuilder = ArrayBuilder<BoundAssignmentOperator>.GetInstance();
boundNamedArgumentsSet = new HashSet<string>();
}
else if (boundNamedArgumentsSet!.Contains(argumentName))
Expand All @@ -351,22 +359,17 @@ private AnalyzedAttributeArguments BindAttributeArguments(
Error(diagnostics, ErrorCode.ERR_DuplicateNamedAttributeArgument, argument, argumentName);
}

BoundExpression boundNamedArgument = BindNamedAttributeArgument(argument, attributeType, diagnostics);
BoundAssignmentOperator boundNamedArgument = BindNamedAttributeArgument(argument, attributeType, diagnostics);
boundNamedArgumentsBuilder.Add(boundNamedArgument);
boundNamedArgumentsSet.Add(argumentName);
}
}

if (boundNamedArgumentsBuilder != null)
{
boundNamedArguments = boundNamedArgumentsBuilder.ToImmutableAndFree();
}
}

return new AnalyzedAttributeArguments(boundConstructorArguments, boundNamedArguments);
return new AnalyzedAttributeArguments(boundConstructorArguments, boundNamedArgumentsBuilder);
}

private BoundExpression BindNamedAttributeArgument(AttributeArgumentSyntax namedArgument, NamedTypeSymbol attributeType, BindingDiagnosticBag diagnostics)
private BoundAssignmentOperator BindNamedAttributeArgument(AttributeArgumentSyntax namedArgument, NamedTypeSymbol attributeType, BindingDiagnosticBag diagnostics)
{
bool wasError;
LookupResultKind resultKind;
Expand Down Expand Up @@ -537,7 +540,8 @@ protected MethodSymbol BindAttributeConstructor(
bool suppressErrors,
ref ImmutableArray<int> argsToParamsOpt,
ref bool expanded,
ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo)
ref CompoundUseSiteInfo<AssemblySymbol> useSiteInfo,
out ImmutableArray<BoundExpression> constructorArguments)
{
MemberResolutionResult<MethodSymbol> memberResolutionResult;
ImmutableArray<MethodSymbol> candidateConstructors;
Expand All @@ -556,6 +560,11 @@ protected MethodSymbol BindAttributeConstructor(
memberResolutionResult.IsValid && !IsConstructorAccessible(memberResolutionResult.Member, ref useSiteInfo) ?
LookupResultKind.Inaccessible :
LookupResultKind.OverloadResolutionFailure);
constructorArguments = BuildArgumentsForErrorRecovery(boundConstructorArguments, candidateConstructors);
}
else
{
constructorArguments = boundConstructorArguments.Arguments.ToImmutable();
}
argsToParamsOpt = memberResolutionResult.Result.ArgsToParamsOpt;
expanded = memberResolutionResult.Result.Kind == MemberResolutionKind.ApplicableInExpandedForm;
Expand Down Expand Up @@ -982,7 +991,7 @@ public ImmutableArray<TypedConstant> VisitArguments(ImmutableArray<BoundExpressi
return validatedArguments;
}

public ImmutableArray<KeyValuePair<string, TypedConstant>> VisitNamedArguments(ImmutableArray<BoundExpression> arguments, BindingDiagnosticBag diagnostics, ref bool attrHasErrors)
public ImmutableArray<KeyValuePair<string, TypedConstant>> VisitNamedArguments(ImmutableArray<BoundAssignmentOperator> arguments, BindingDiagnosticBag diagnostics, ref bool attrHasErrors)
{
ArrayBuilder<KeyValuePair<string, TypedConstant>>? builder = null;
foreach (var argument in arguments)
Expand All @@ -1008,28 +1017,20 @@ public ImmutableArray<KeyValuePair<string, TypedConstant>> VisitNamedArguments(I
return builder.ToImmutableAndFree();
}

private KeyValuePair<String, TypedConstant>? VisitNamedArgument(BoundExpression argument, BindingDiagnosticBag diagnostics, ref bool attrHasErrors)
private KeyValuePair<String, TypedConstant>? VisitNamedArgument(BoundAssignmentOperator assignment, BindingDiagnosticBag diagnostics, ref bool attrHasErrors)
{
KeyValuePair<String, TypedConstant>? visitedArgument = null;

switch (argument.Kind)
switch (assignment.Left.Kind)
{
case BoundKind.AssignmentOperator:
var assignment = (BoundAssignmentOperator)argument;

switch (assignment.Left.Kind)
{
case BoundKind.FieldAccess:
var fa = (BoundFieldAccess)assignment.Left;
visitedArgument = new KeyValuePair<String, TypedConstant>(fa.FieldSymbol.Name, VisitExpression(assignment.Right, diagnostics, ref attrHasErrors, argument.HasAnyErrors));
break;

case BoundKind.PropertyAccess:
var pa = (BoundPropertyAccess)assignment.Left;
visitedArgument = new KeyValuePair<String, TypedConstant>(pa.PropertySymbol.Name, VisitExpression(assignment.Right, diagnostics, ref attrHasErrors, argument.HasAnyErrors));
break;
}
case BoundKind.FieldAccess:
var fa = (BoundFieldAccess)assignment.Left;
visitedArgument = new KeyValuePair<String, TypedConstant>(fa.FieldSymbol.Name, VisitExpression(assignment.Right, diagnostics, ref attrHasErrors, assignment.HasAnyErrors));
break;

case BoundKind.PropertyAccess:
var pa = (BoundPropertyAccess)assignment.Left;
visitedArgument = new KeyValuePair<String, TypedConstant>(pa.PropertySymbol.Name, VisitExpression(assignment.Right, diagnostics, ref attrHasErrors, assignment.HasAnyErrors));
break;
}

Expand Down Expand Up @@ -1248,9 +1249,9 @@ private static TypedConstant CreateTypedConstant(BoundExpression node, TypedCons
private struct AnalyzedAttributeArguments
{
internal readonly AnalyzedArguments ConstructorArguments;
internal readonly ImmutableArray<BoundExpression> NamedArguments;
internal readonly ArrayBuilder<BoundAssignmentOperator>? NamedArguments;

internal AnalyzedAttributeArguments(AnalyzedArguments constructorArguments, ImmutableArray<BoundExpression> namedArguments)
internal AnalyzedAttributeArguments(AnalyzedArguments constructorArguments, ArrayBuilder<BoundAssignmentOperator>? namedArguments)
{
this.ConstructorArguments = constructorArguments;
this.NamedArguments = namedArguments;
Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/BoundTree/BoundNodes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@
<Field Name="ConstructorArgumentNamesOpt" Type="ImmutableArray&lt;string&gt;" Null="allow"/>
<Field Name="ConstructorArgumentsToParamsOpt" Type="ImmutableArray&lt;int&gt;" Null="allow"/>
<Field Name="ConstructorExpanded" Type="bool" />
<Field Name="NamedArguments" Type ="ImmutableArray&lt;BoundExpression&gt;"/>
<Field Name="NamedArguments" Type ="ImmutableArray&lt;BoundAssignmentOperator&gt;"/>
<Field Name="ResultKind" PropertyOverrides="true" Type="LookupResultKind"/>
</Node>

Expand Down
2 changes: 1 addition & 1 deletion src/Compilers/CSharp/Portable/BoundTree/Expression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ internal partial class BoundAnonymousObjectCreationExpression

internal partial class BoundAttribute
{
protected override ImmutableArray<BoundNode?> Children => StaticCast<BoundNode?>.From(this.ConstructorArguments.AddRange(this.NamedArguments));
protected override ImmutableArray<BoundNode?> Children => StaticCast<BoundNode?>.From(this.ConstructorArguments.AddRange(StaticCast<BoundExpression>.From(this.NamedArguments)));
}

internal partial class BoundQueryClause
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions src/Compilers/CSharp/Portable/Symbols/TypeWithAnnotations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -942,8 +942,6 @@ private TypeSymbol GetResolvedType()
{
if ((object)_resolved == null)
{
Debug.Assert(_underlying.IsSafeToResolve());
Copy link
Member

@jcouv jcouv Feb 25, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why remove this assertion? #Closed


TryForceResolve(asValueType: _underlying.Type.IsValueType);
}

Expand Down
Loading