未验证 提交 821a927b 编写于 作者: J Julien Couvreur 提交者: GitHub

Add well-known types/members for async iterators, add reference for ValueTask (#27100)

上级 7777c5f5
......@@ -33,7 +33,7 @@
<MicrosoftCodeAnalysisCSharpWorkspacesVersion>1.0.1</MicrosoftCodeAnalysisCSharpWorkspacesVersion>
<MicrosoftCodeAnalysisEditorFeaturesTextVersion>1.0.1</MicrosoftCodeAnalysisEditorFeaturesTextVersion>
<MicrosoftCodeAnalysisElfieVersion>0.10.6</MicrosoftCodeAnalysisElfieVersion>
<MicrosoftCodeAnalysisTestResourcesProprietaryVersion>2.0.7</MicrosoftCodeAnalysisTestResourcesProprietaryVersion>
<MicrosoftCodeAnalysisTestResourcesProprietaryVersion>2.0.9</MicrosoftCodeAnalysisTestResourcesProprietaryVersion>
<MicrosoftCodeAnalysisVisualBasicVersion>1.0.1</MicrosoftCodeAnalysisVisualBasicVersion>
<MicrosoftCodeAnalysisVisualBasicWorkspacesVersion>1.0.1</MicrosoftCodeAnalysisVisualBasicWorkspacesVersion>
<MicrosoftCodeAnalysisWorkspacesCommonVersion>1.0.1</MicrosoftCodeAnalysisWorkspacesCommonVersion>
......
......@@ -975,6 +975,11 @@ protected override bool IsByRefMethod(MethodSymbol method)
return method.RefKind != RefKind.None;
}
protected override bool IsByRefProperty(PropertySymbol property)
{
return property.RefKind != RefKind.None;
}
protected override bool IsGenericMethodTypeParam(TypeSymbol type, int paramPosition)
{
if (type.Kind != SymbolKind.TypeParameter)
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Linq;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests.CodeGen
{
[CompilerTrait(CompilerFeature.AsyncStreams)]
public class CodeGenAsyncIteratorTests : EmitMetadataTestBase
{
// PROTOTYPE(async-streams): Consider moving this common test code to TestSources.cs
private static readonly string s_common = @"
namespace System.Collections.Generic
{
public interface IAsyncEnumerable<out T>
{
IAsyncEnumerator<T> GetAsyncEnumerator();
}
public interface IAsyncEnumerator<out T> : System.IAsyncDisposable
{
System.Threading.Tasks.Task<bool> WaitForNextAsync();
T TryGetNext(out bool success);
}
}
namespace System
{
public interface IAsyncDisposable
{
System.Threading.Tasks.Task DisposeAsync();
}
}
namespace System.Runtime.CompilerServices
{
public interface IStrongBox<T>
{
ref T Value { get; }
}
}
namespace System.Threading.Tasks
{
using System.Runtime.CompilerServices;
using System.Threading.Tasks.Sources;
public struct ManualResetValueTaskSourceLogic<TResult>
{
public ManualResetValueTaskSourceLogic(IStrongBox<ManualResetValueTaskSourceLogic<TResult>> parent)
{
}
public short Version
=> throw null;
public ValueTaskSourceStatus GetStatus(short token)
=> throw null;
public TResult GetResult(short token)
=> throw null;
public void Reset()
=> throw null;
public void OnCompleted(Action<object> continuation, object state, short token, ValueTaskSourceOnCompletedFlags flags)
=> throw null;
public void SetResult(TResult result)
=> throw null;
public void SetException(Exception error)
=> throw null;
}
}
";
[Fact]
public void TestWellKnownMembers()
{
var comp = CreateCompilation(s_common, references: new[] { TestReferences.NetStandard20.TasksExtensionsRef }, targetFramework: Roslyn.Test.Utilities.TargetFramework.NetStandard20);
comp.VerifyDiagnostics();
verifyType(WellKnownType.System_Runtime_CompilerServices_IStrongBox_T,
"System.Runtime.CompilerServices.IStrongBox<T>");
verifyMember(WellKnownMember.System_Runtime_CompilerServices_IStrongBox_T__Value,
"ref T System.Runtime.CompilerServices.IStrongBox<T>.Value { get; }");
verifyMember(WellKnownMember.System_Runtime_CompilerServices_IStrongBox_T__get_Value,
"ref T System.Runtime.CompilerServices.IStrongBox<T>.Value.get");
verifyType(WellKnownType.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T,
"System.Threading.Tasks.ManualResetValueTaskSourceLogic<TResult>");
verifyMember(WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__ctor,
"System.Threading.Tasks.ManualResetValueTaskSourceLogic<TResult>..ctor(System.Runtime.CompilerServices.IStrongBox<System.Threading.Tasks.ManualResetValueTaskSourceLogic<TResult>> parent)");
verifyMember(WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__GetResult,
"TResult System.Threading.Tasks.ManualResetValueTaskSourceLogic<TResult>.GetResult(System.Int16 token)");
verifyMember(WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__GetStatus,
"System.Threading.Tasks.Sources.ValueTaskSourceStatus System.Threading.Tasks.ManualResetValueTaskSourceLogic<TResult>.GetStatus(System.Int16 token)");
verifyMember(WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__OnCompleted,
"void System.Threading.Tasks.ManualResetValueTaskSourceLogic<TResult>.OnCompleted(System.Action<System.Object> continuation, System.Object state, System.Int16 token, System.Threading.Tasks.Sources.ValueTaskSourceOnCompletedFlags flags)");
verifyMember(WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__Reset,
"void System.Threading.Tasks.ManualResetValueTaskSourceLogic<TResult>.Reset()");
verifyMember(WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__SetResult,
"void System.Threading.Tasks.ManualResetValueTaskSourceLogic<TResult>.SetResult(TResult result)");
verifyMember(WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__get_Version,
"System.Int16 System.Threading.Tasks.ManualResetValueTaskSourceLogic<TResult>.Version.get");
verifyType(WellKnownType.System_Threading_Tasks_Sources_ValueTaskSourceStatus,
"System.Threading.Tasks.Sources.ValueTaskSourceStatus");
verifyType(WellKnownType.System_Threading_Tasks_Sources_ValueTaskSourceOnCompletedFlags,
"System.Threading.Tasks.Sources.ValueTaskSourceOnCompletedFlags");
verifyType(WellKnownType.System_Threading_Tasks_Sources_IValueTaskSource_T,
"System.Threading.Tasks.Sources.IValueTaskSource<out TResult>");
verifyMember(WellKnownMember.System_Threading_Tasks_Sources_IValueTaskSource_T__GetResult,
"TResult System.Threading.Tasks.Sources.IValueTaskSource<out TResult>.GetResult(System.Int16 token)");
verifyMember(WellKnownMember.System_Threading_Tasks_Sources_IValueTaskSource_T__GetStatus,
"System.Threading.Tasks.Sources.ValueTaskSourceStatus System.Threading.Tasks.Sources.IValueTaskSource<out TResult>.GetStatus(System.Int16 token)");
verifyMember(WellKnownMember.System_Threading_Tasks_Sources_IValueTaskSource_T__OnCompleted,
"void System.Threading.Tasks.Sources.IValueTaskSource<out TResult>.OnCompleted(System.Action<System.Object> continuation, System.Object state, System.Int16 token, System.Threading.Tasks.Sources.ValueTaskSourceOnCompletedFlags flags)");
verifyType(WellKnownType.System_Threading_Tasks_ValueTask_T,
"System.Threading.Tasks.ValueTask<TResult>");
verifyMember(WellKnownMember.System_Threading_Tasks_ValueTask_T__ctor,
"System.Threading.Tasks.ValueTask<TResult>..ctor(System.Threading.Tasks.Sources.IValueTaskSource<TResult> source, System.Int16 token)");
void verifyType(WellKnownType type, string expected)
{
var symbol = comp.GetWellKnownType(type);
Assert.Equal(expected, symbol.ToTestDisplayString());
}
void verifyMember(WellKnownMember member, string expected)
{
var symbol = comp.GetWellKnownTypeMember(member);
Assert.Equal(expected, symbol.ToTestDisplayString());
}
}
}
}
......@@ -566,6 +566,12 @@ public void AllWellKnownTypes()
case WellKnownType.System_IAsyncDisposable:
case WellKnownType.System_Collections_Generic_IAsyncEnumerable_T:
case WellKnownType.System_Collections_Generic_IAsyncEnumerator_T:
case WellKnownType.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T:
case WellKnownType.System_Runtime_CompilerServices_IStrongBox_T:
case WellKnownType.System_Threading_Tasks_Sources_ValueTaskSourceStatus:
case WellKnownType.System_Threading_Tasks_Sources_ValueTaskSourceOnCompletedFlags:
case WellKnownType.System_Threading_Tasks_Sources_IValueTaskSource_T:
case WellKnownType.System_Threading_Tasks_ValueTask_T:
// Not yet in the platform.
case WellKnownType.Microsoft_CodeAnalysis_Runtime_Instrumentation:
// Not always available.
......@@ -874,6 +880,20 @@ public void AllWellKnownTypeMembers()
case WellKnownMember.System_Collections_Generic_IAsyncEnumerable_T__GetAsyncEnumerator:
case WellKnownMember.System_Collections_Generic_IAsyncEnumerator_T__TryGetNext:
case WellKnownMember.System_Collections_Generic_IAsyncEnumerator_T__WaitForNextAsync:
case WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__ctor:
case WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__get_Version:
case WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__GetResult:
case WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__GetStatus:
case WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__OnCompleted:
case WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__Reset:
case WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__SetResult:
case WellKnownMember.System_Runtime_CompilerServices_IStrongBox_T__Value:
case WellKnownMember.System_Runtime_CompilerServices_IStrongBox_T__get_Value:
case WellKnownMember.System_Threading_Tasks_Sources_IValueTaskSource_T__GetResult:
case WellKnownMember.System_Threading_Tasks_Sources_IValueTaskSource_T__GetStatus:
case WellKnownMember.System_Threading_Tasks_Sources_IValueTaskSource_T__OnCompleted:
case WellKnownMember.System_Threading_Tasks_ValueTask_T__ctor:
// Not yet in the platform.
continue;
case WellKnownMember.Microsoft_CodeAnalysis_Runtime_Instrumentation__CreatePayloadForMethodsSpanningSingleFile:
......
......@@ -53,6 +53,12 @@ public bool MatchPropertySignature(PropertySymbol property, ImmutableArray<byte>
return false;
}
bool isByRef = IsByRef(signature, ref position);
if (IsByRefProperty(property) != isByRef)
{
return false;
}
// get the property type
if (!MatchType(GetPropertyType(property), signature, ref position))
{
......@@ -287,6 +293,7 @@ private static short ReadTypeId(ImmutableArray<byte> signature, ref int position
protected abstract bool IsByRefParam(ParameterSymbol parameter);
protected abstract bool IsByRefMethod(MethodSymbol method);
protected abstract bool IsByRefProperty(PropertySymbol property);
protected abstract TypeSymbol GetFieldType(FieldSymbol field);
}
......
......@@ -447,6 +447,20 @@ internal enum WellKnownMember
System_Collections_Generic_IAsyncEnumerator_T__WaitForNextAsync,
System_Collections_Generic_IAsyncEnumerator_T__TryGetNext,
System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__ctor,
System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__GetResult,
System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__GetStatus,
System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__OnCompleted,
System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__Reset,
System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__SetResult,
System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__get_Version,
System_Runtime_CompilerServices_IStrongBox_T__Value,
System_Runtime_CompilerServices_IStrongBox_T__get_Value,
System_Threading_Tasks_Sources_IValueTaskSource_T__GetResult,
System_Threading_Tasks_Sources_IValueTaskSource_T__GetStatus,
System_Threading_Tasks_Sources_IValueTaskSource_T__OnCompleted,
System_Threading_Tasks_ValueTask_T__ctor,
Count
}
}
......@@ -279,6 +279,12 @@ internal enum WellKnownType
System_IAsyncDisposable,
System_Collections_Generic_IAsyncEnumerable_T,
System_Collections_Generic_IAsyncEnumerator_T,
System_Threading_Tasks_ManualResetValueTaskSourceLogic_T,
System_Runtime_CompilerServices_IStrongBox_T,
System_Threading_Tasks_Sources_ValueTaskSourceStatus,
System_Threading_Tasks_Sources_ValueTaskSourceOnCompletedFlags,
System_Threading_Tasks_Sources_IValueTaskSource_T,
System_Threading_Tasks_ValueTask_T,
NextAvailable,
}
......@@ -553,6 +559,12 @@ internal static class WellKnownTypes
"System.IAsyncDisposable",
"System.Collections.Generic.IAsyncEnumerable`1",
"System.Collections.Generic.IAsyncEnumerator`1",
"System.Threading.Tasks.ManualResetValueTaskSourceLogic`1",
"System.Runtime.CompilerServices.IStrongBox`1",
"System.Threading.Tasks.Sources.ValueTaskSourceStatus",
"System.Threading.Tasks.Sources.ValueTaskSourceOnCompletedFlags",
"System.Threading.Tasks.Sources.IValueTaskSource`1",
"System.Threading.Tasks.ValueTask`1",
};
private readonly static Dictionary<string, WellKnownType> s_nameToTypeIdMap = new Dictionary<string, WellKnownType>((int)Count);
......
......@@ -628,6 +628,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Return method.ReturnsByRef
End Function
Protected Overrides Function IsByRefProperty(ByVal [property] As PropertySymbol) As Boolean
Return [property].ReturnsByRef
End Function
Protected Overrides Function IsGenericMethodTypeParam(type As TypeSymbol, paramPosition As Integer) As Boolean
If type.Kind <> SymbolKind.TypeParameter Then
Return False
......
......@@ -506,7 +506,13 @@ End Namespace
WellKnownType.System_ReadOnlySpan_T,
WellKnownType.System_IAsyncDisposable,
WellKnownType.System_Collections_Generic_IAsyncEnumerable_T,
WellKnownType.System_Collections_Generic_IAsyncEnumerator_T
WellKnownType.System_Collections_Generic_IAsyncEnumerator_T,
WellKnownType.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T,
WellKnownType.System_Runtime_CompilerServices_IStrongBox_T,
WellKnownType.System_Threading_Tasks_Sources_ValueTaskSourceStatus,
WellKnownType.System_Threading_Tasks_Sources_ValueTaskSourceOnCompletedFlags,
WellKnownType.System_Threading_Tasks_Sources_IValueTaskSource_T,
WellKnownType.System_Threading_Tasks_ValueTask_T
' Not available on all platforms.
Continue For
Case WellKnownType.ExtSentinel
......@@ -550,7 +556,13 @@ End Namespace
WellKnownType.System_ReadOnlySpan_T,
WellKnownType.System_IAsyncDisposable,
WellKnownType.System_Collections_Generic_IAsyncEnumerable_T,
WellKnownType.System_Collections_Generic_IAsyncEnumerator_T
WellKnownType.System_Collections_Generic_IAsyncEnumerator_T,
WellKnownType.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T,
WellKnownType.System_Runtime_CompilerServices_IStrongBox_T,
WellKnownType.System_Threading_Tasks_Sources_ValueTaskSourceStatus,
WellKnownType.System_Threading_Tasks_Sources_ValueTaskSourceOnCompletedFlags,
WellKnownType.System_Threading_Tasks_Sources_IValueTaskSource_T,
WellKnownType.System_Threading_Tasks_ValueTask_T
' Not available on all platforms.
Continue For
Case WellKnownType.ExtSentinel
......@@ -604,7 +616,20 @@ End Namespace
WellKnownMember.System_IAsyncDisposable__DisposeAsync,
WellKnownMember.System_Collections_Generic_IAsyncEnumerable_T__GetAsyncEnumerator,
WellKnownMember.System_Collections_Generic_IAsyncEnumerator_T__TryGetNext,
WellKnownMember.System_Collections_Generic_IAsyncEnumerator_T__WaitForNextAsync
WellKnownMember.System_Collections_Generic_IAsyncEnumerator_T__WaitForNextAsync,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__ctor,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__get_Version,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__GetResult,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__GetStatus,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__OnCompleted,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__Reset,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__SetResult,
WellKnownMember.System_Runtime_CompilerServices_IStrongBox_T__Value,
WellKnownMember.System_Runtime_CompilerServices_IStrongBox_T__get_Value,
WellKnownMember.System_Threading_Tasks_Sources_IValueTaskSource_T__GetResult,
WellKnownMember.System_Threading_Tasks_Sources_IValueTaskSource_T__GetStatus,
WellKnownMember.System_Threading_Tasks_Sources_IValueTaskSource_T__OnCompleted,
WellKnownMember.System_Threading_Tasks_ValueTask_T__ctor
' Not available yet, but will be in upcoming release.
Continue For
Case WellKnownMember.Microsoft_CodeAnalysis_Runtime_Instrumentation__CreatePayloadForMethodsSpanningSingleFile,
......@@ -702,7 +727,20 @@ End Namespace
WellKnownMember.System_IAsyncDisposable__DisposeAsync,
WellKnownMember.System_Collections_Generic_IAsyncEnumerable_T__GetAsyncEnumerator,
WellKnownMember.System_Collections_Generic_IAsyncEnumerator_T__TryGetNext,
WellKnownMember.System_Collections_Generic_IAsyncEnumerator_T__WaitForNextAsync
WellKnownMember.System_Collections_Generic_IAsyncEnumerator_T__WaitForNextAsync,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__ctor,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__get_Version,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__GetResult,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__GetStatus,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__OnCompleted,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__Reset,
WellKnownMember.System_Threading_Tasks_ManualResetValueTaskSourceLogic_T__SetResult,
WellKnownMember.System_Runtime_CompilerServices_IStrongBox_T__Value,
WellKnownMember.System_Runtime_CompilerServices_IStrongBox_T__get_Value,
WellKnownMember.System_Threading_Tasks_Sources_IValueTaskSource_T__GetResult,
WellKnownMember.System_Threading_Tasks_Sources_IValueTaskSource_T__GetStatus,
WellKnownMember.System_Threading_Tasks_Sources_IValueTaskSource_T__OnCompleted,
WellKnownMember.System_Threading_Tasks_ValueTask_T__ctor
' Not available yet, but will be in upcoming release.
Continue For
Case WellKnownMember.Microsoft_CodeAnalysis_Runtime_Instrumentation__CreatePayloadForMethodsSpanningSingleFile,
......
......@@ -260,6 +260,11 @@ public static class NetStandard20
() => AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.Microsoft_CSharp).GetReference(display: "Microsoft.CSharp.dll (netstandard 2.0 ref)"),
LazyThreadSafetyMode.PublicationOnly);
public static PortableExecutableReference MicrosoftCSharpRef => s_microsoftCSharp.Value;
private static readonly Lazy<PortableExecutableReference> s_system_Threading_Tasks_Extensions = new Lazy<PortableExecutableReference>(
() => AssemblyMetadata.CreateFromImage(TestResources.NetFX.netstandard20.System_Threading_Tasks_Extensions).GetReference(display: "System.Threading.Tasks.Extensions.dll (netstandard 2.0)"),
LazyThreadSafetyMode.PublicationOnly);
public static PortableExecutableReference TasksExtensionsRef => s_system_Threading_Tasks_Extensions.Value;
}
public static class DiagnosticTests
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册