Skip to content

Commit

Permalink
Decode parameter attribute early
Browse files Browse the repository at this point in the history
  • Loading branch information
cston committed Jul 21, 2022
1 parent e4f3aeb commit 2751f37
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,20 @@ namespace Microsoft.CodeAnalysis.CSharp.Symbols
/// </summary>
internal sealed class ParameterEarlyWellKnownAttributeData : CommonParameterEarlyWellKnownAttributeData
{
private bool _hasRefEscapesAttribute;
public bool HasRefEscapesAttribute
{
get
{
VerifySealed(expected: true);
return _hasRefEscapesAttribute;
}
set
{
VerifySealed(expected: false);
_hasRefEscapesAttribute = value;
SetDataStored();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,22 +142,6 @@ public bool HasEnumeratorCancellationAttribute
}
}

private bool _hasRefEscapesAttribute;
public bool HasRefEscapesAttribute
{
get
{
VerifySealed(expected: true);
return _hasRefEscapesAttribute;
}
set
{
VerifySealed(expected: false);
_hasRefEscapesAttribute = value;
SetDataStored();
}
}

private ImmutableHashSet<string> _notNullIfParameterNotNull = ImmutableHashSet<string>.Empty;
public ImmutableHashSet<string> NotNullIfParameterNotNull
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ internal bool HasEnumeratorCancellationAttribute
}
}

internal bool HasRefEscapesAttribute => GetDecodedWellKnownAttributeData()?.HasRefEscapesAttribute == true;
internal bool HasRefEscapesAttribute => GetEarlyDecodedWellKnownAttributeData()?.HasRefEscapesAttribute == true;

#nullable enable

Expand Down Expand Up @@ -595,6 +595,10 @@ internal override (CSharpAttributeData?, BoundAttribute?) EarlyDecodeWellKnownAt
{
return EarlyDecodeAttributeForDefaultParameterValue(AttributeDescription.DateTimeConstantAttribute, ref arguments);
}
else if (CSharpAttributeData.IsTargetEarlyAttribute(arguments.AttributeType, arguments.AttributeSyntax, AttributeDescription.RefEscapesAttribute))
{
return arguments.Binder.GetAttribute(arguments.AttributeSyntax, arguments.AttributeType, beforeAttributePartBound: null, afterAttributePartBound: null, out bool _);
}
else if (!IsOnPartialImplementation(arguments.AttributeSyntax))
{
if (CSharpAttributeData.IsTargetEarlyAttribute(arguments.AttributeType, arguments.AttributeSyntax, AttributeDescription.CallerLineNumberAttribute))
Expand Down Expand Up @@ -794,11 +798,6 @@ protected override void DecodeWellKnownAttributeImpl(ref DecodeWellKnownAttribut
{
DecodeInterpolatedStringHandlerArgumentAttribute(ref arguments, diagnostics, index);
}
else if (attribute.IsTargetAttribute(this, AttributeDescription.RefEscapesAttribute))
{
// PROTOTYPE: Should this be an early decoded attribute? Create a test that manifests a difference.
arguments.GetOrCreateData<ParameterWellKnownAttributeData>().HasRefEscapesAttribute = true;
}
}

private static bool? DecodeMaybeNullWhenOrNotNullWhenOrDoesNotReturnIfAttribute(AttributeDescription description, CSharpAttributeData attribute)
Expand Down

0 comments on commit 2751f37

Please sign in to comment.