Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
10 changes: 6 additions & 4 deletions src/Compilers/CSharp/Portable/Compilation/CSharpCompilation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,7 @@ internal bool IsNullableAnalysisEnabledAlways
/// Returns true if this method should be processed with runtime async handling instead
/// of compiler async state machine generation.
/// </summary>
#pragma warning disable IDE0060 // Remove unused parameter
internal bool IsRuntimeAsyncEnabledIn(MethodSymbol method)
#pragma warning restore IDE0060 // Remove unused parameter
{
// PROTOTYPE: EE tests fail this assert, handle and test
//Debug.Assert(ReferenceEquals(method.ContainingAssembly, Assembly));
Expand All @@ -327,8 +325,12 @@ internal bool IsRuntimeAsyncEnabledIn(MethodSymbol method)
return false;
}

// PROTOTYPE: Check for attributes that turn on/off the feature member-by-member
return true;
return method switch
{
SourceMethodSymbol { IsRuntimeAsyncEnabledInMethod: ThreeState.True } => true,
SourceMethodSymbol { IsRuntimeAsyncEnabledInMethod: ThreeState.False } => false,
_ => Feature("runtime-async") == "on"
};
Copy link
Member

Choose a reason for hiding this comment

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

Let's update the compiler spec for how those three flags (runtime feature flag, compiler feature flag, method-level attribute) work together

Copy link
Member Author

Choose a reason for hiding this comment

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

Will update in main after this PR.

}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,5 +149,21 @@ public UnmanagedCallersOnlyAttributeData? UnmanagedCallersOnlyAttributeData
SetDataStored();
}
}

private ThreeState _hasRuntimeAsyncMethodGenerationAttribute;
public ThreeState HasRuntimeAsyncMethodGenerationAttribute
{
get
{
VerifySealed(expected: true);
return _hasRuntimeAsyncMethodGenerationAttribute;
}
set
{
VerifySealed(expected: false);
_hasRuntimeAsyncMethodGenerationAttribute = value;
SetDataStored();
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,14 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut
arguments.AttributeSyntaxOpt);
}
}
else if (attribute.IsTargetAttribute(AttributeDescription.RuntimeAsyncMethodGenerationAttribute))
{
// PROTOTYPE: Validate langversion? Validate previewness of the runtime feature flag?
arguments.GetOrCreateData<MethodWellKnownAttributeData>().HasRuntimeAsyncMethodGenerationAttribute =
attribute.CommonConstructorArguments[0].DecodeValue<bool>(SpecialType.System_Boolean)
? ThreeState.True
: ThreeState.False;
}
else
{
var compilation = this.DeclaringCompilation;
Expand All @@ -661,6 +669,15 @@ private void DecodeWellKnownAttributeAppliedToMethod(ref DecodeWellKnownAttribut
}
}

internal ThreeState IsRuntimeAsyncEnabledInMethod
{
get
{
var data = GetDecodedWellKnownAttributeData();
return data?.HasRuntimeAsyncMethodGenerationAttribute ?? ThreeState.Unknown;
}
}

internal override ImmutableArray<string> NotNullMembers =>
GetDecodedWellKnownAttributeData()?.NotNullMembers ?? ImmutableArray<string>.Empty;

Expand Down
Loading