Skip to content

Use prototype roslyn compiler #3062

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

Closed
Closed
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
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ syntax: glob
.packages
.tools

# nuget packages for custom roslyn
roslynpackages

# User-specific files
*.suo
*.user
Expand Down
2 changes: 1 addition & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<add key="dotnet-libraries-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-libraries-transport/nuget/v3/index.json" />
<add key="dotnet10" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet10/nuget/v3/index.json" />
<add key="dotnet10-transport" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet10-transport/nuget/v3/index.json" />
<add key="async-compiler" value="roslynpackages" />
<add key="general-testing" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/general-testing/nuget/v3/index.json" />
</packageSources>
<auditSources>
<clear />
Expand Down
34 changes: 0 additions & 34 deletions buildroslynnugets.cmd

This file was deleted.

7 changes: 4 additions & 3 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,10 @@
Any tools that contribute to the design-time experience should use the MicrosoftCodeAnalysisVersion_LatestVS property above to ensure
they do not break the local dev experience.
-->
<MicrosoftCodeAnalysisCSharpVersion>4.14.0-async-15</MicrosoftCodeAnalysisCSharpVersion>
<MicrosoftCodeAnalysisVersion>4.14.0-async-15</MicrosoftCodeAnalysisVersion>
<MicrosoftNetCompilersToolsetVersion>4.14.0-async-15</MicrosoftNetCompilersToolsetVersion>

<MicrosoftCodeAnalysisCSharpVersion>4.13.0-3.24611.10</MicrosoftCodeAnalysisCSharpVersion>
<MicrosoftCodeAnalysisVersion>$(MicrosoftCodeAnalysisCSharpVersion)</MicrosoftCodeAnalysisVersion>
<MicrosoftNetCompilersToolsetVersion>$(MicrosoftCodeAnalysisCSharpVersion)</MicrosoftNetCompilersToolsetVersion>
</PropertyGroup>
<!--
For source generator support we need to target multiple versions of Roslyn in order to be able to run on older versions of Roslyn.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Diagnostics;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Threading;
using System.Threading.Tasks;

Expand All @@ -19,6 +20,7 @@ public static partial class AsyncHelpers
// It will not capture/restore any local state that is live across it.
[BypassReadyToRun]
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)]
[RequiresPreviewFeatures]
public static void AwaitAwaiter<TAwaiter>(TAwaiter awaiter) where TAwaiter : INotifyCompletion
{
ref AsyncHelpers.RuntimeAsyncAwaitState state = ref AsyncHelpers.t_runtimeAsyncAwaitState;
Expand All @@ -34,6 +36,7 @@ public static void AwaitAwaiter<TAwaiter>(TAwaiter awaiter) where TAwaiter : INo
// It will not capture/restore any local state that is live across it.
[BypassReadyToRun]
[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.Async)]
[RequiresPreviewFeatures]
public static void UnsafeAwaitAwaiter<TAwaiter>(TAwaiter awaiter) where TAwaiter : ICriticalNotifyCompletion
{
ref AsyncHelpers.RuntimeAsyncAwaitState state = ref AsyncHelpers.t_runtimeAsyncAwaitState;
Expand All @@ -48,6 +51,7 @@ public static void UnsafeAwaitAwaiter<TAwaiter>(TAwaiter awaiter) where TAwaiter
[Intrinsic]
[BypassReadyToRun]
[MethodImpl(MethodImplOptions.Async)]
[RequiresPreviewFeatures]
public static T Await<T>(Task<T> task)
{
TaskAwaiter<T> awaiter = task.GetAwaiter();
Expand All @@ -62,6 +66,7 @@ public static T Await<T>(Task<T> task)
[Intrinsic]
[BypassReadyToRun]
[MethodImpl(MethodImplOptions.Async)]
[RequiresPreviewFeatures]
public static void Await(Task task)
{
TaskAwaiter awaiter = task.GetAwaiter();
Expand All @@ -76,6 +81,7 @@ public static void Await(Task task)
[Intrinsic]
[BypassReadyToRun]
[MethodImpl(MethodImplOptions.Async)]
[RequiresPreviewFeatures]
public static T Await<T>(ValueTask<T> task)
{
ValueTaskAwaiter<T> awaiter = task.GetAwaiter();
Expand All @@ -90,6 +96,7 @@ public static T Await<T>(ValueTask<T> task)
[Intrinsic]
[BypassReadyToRun]
[MethodImpl(MethodImplOptions.Async)]
[RequiresPreviewFeatures]
public static void Await(ValueTask task)
{
ValueTaskAwaiter awaiter = task.GetAwaiter();
Expand All @@ -104,6 +111,7 @@ public static void Await(ValueTask task)
[Intrinsic]
[BypassReadyToRun]
[MethodImpl(MethodImplOptions.Async)]
[RequiresPreviewFeatures]
public static void Await(ConfiguredTaskAwaitable configuredAwaitable)
{
ConfiguredTaskAwaitable.ConfiguredTaskAwaiter awaiter = configuredAwaitable.GetAwaiter();
Expand All @@ -118,6 +126,7 @@ public static void Await(ConfiguredTaskAwaitable configuredAwaitable)
[Intrinsic]
[BypassReadyToRun]
[MethodImpl(MethodImplOptions.Async)]
[RequiresPreviewFeatures]
public static void Await(ConfiguredValueTaskAwaitable configuredAwaitable)
{
ConfiguredValueTaskAwaitable.ConfiguredValueTaskAwaiter awaiter = configuredAwaitable.GetAwaiter();
Expand All @@ -132,6 +141,7 @@ public static void Await(ConfiguredValueTaskAwaitable configuredAwaitable)
[Intrinsic]
[BypassReadyToRun]
[MethodImpl(MethodImplOptions.Async)]
[RequiresPreviewFeatures]
public static T Await<T>(ConfiguredTaskAwaitable<T> configuredAwaitable)
{
ConfiguredTaskAwaitable<T>.ConfiguredTaskAwaiter awaiter = configuredAwaitable.GetAwaiter();
Expand All @@ -146,6 +156,7 @@ public static T Await<T>(ConfiguredTaskAwaitable<T> configuredAwaitable)
[Intrinsic]
[BypassReadyToRun]
[MethodImpl(MethodImplOptions.Async)]
[RequiresPreviewFeatures]
public static T Await<T>(ConfiguredValueTaskAwaitable<T> configuredAwaitable)
{
ConfiguredValueTaskAwaitable<T>.ConfiguredValueTaskAwaiter awaiter = configuredAwaitable.GetAwaiter();
Expand All @@ -157,15 +168,25 @@ public static T Await<T>(ConfiguredValueTaskAwaitable<T> configuredAwaitable)
return awaiter.GetResult();
}
#else
[RequiresPreviewFeatures]
public static void UnsafeAwaitAwaiter<TAwaiter>(TAwaiter awaiter) where TAwaiter : ICriticalNotifyCompletion { throw new NotImplementedException(); }
[RequiresPreviewFeatures]
public static void AwaitAwaiter<TAwaiter>(TAwaiter awaiter) where TAwaiter : INotifyCompletion { throw new NotImplementedException(); }
[RequiresPreviewFeatures]
public static void Await(System.Threading.Tasks.Task task) { throw new NotImplementedException(); }
[RequiresPreviewFeatures]
public static T Await<T>(System.Threading.Tasks.Task<T> task) { throw new NotImplementedException(); }
[RequiresPreviewFeatures]
public static void Await(System.Threading.Tasks.ValueTask task) { throw new NotImplementedException(); }
[RequiresPreviewFeatures]
public static T Await<T>(System.Threading.Tasks.ValueTask<T> task) { throw new NotImplementedException(); }
[RequiresPreviewFeatures]
public static void Await(System.Runtime.CompilerServices.ConfiguredTaskAwaitable configuredAwaitable) { throw new NotImplementedException(); }
[RequiresPreviewFeatures]
public static void Await(System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable configuredAwaitable) { throw new NotImplementedException(); }
[RequiresPreviewFeatures]
public static T Await<T>(System.Runtime.CompilerServices.ConfiguredTaskAwaitable<T> configuredAwaitable) { throw new NotImplementedException(); }
[RequiresPreviewFeatures]
public static T Await<T>(System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable<T> configuredAwaitable) { throw new NotImplementedException(); }
#endif
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@ public static bool IsSupported(string feature)
{
return feature switch
{
PortablePdb or CovariantReturnsOfClasses or ByRefFields or ByRefLikeGenerics or UnmanagedSignatureCallingConvention or DefaultImplementationsOfInterfaces or VirtualStaticsInInterfaces or NumericIntPtr => true,
PortablePdb or
CovariantReturnsOfClasses or
ByRefFields or
ByRefLikeGenerics or
UnmanagedSignatureCallingConvention or
DefaultImplementationsOfInterfaces or
VirtualStaticsInInterfaces or
NumericIntPtr or

nameof(IsDynamicCodeSupported) => IsDynamicCodeSupported,
nameof(IsDynamicCodeCompiled) => IsDynamicCodeCompiled,
_ => false,
Expand Down
10 changes: 10 additions & 0 deletions src/libraries/System.Runtime/ref/System.Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13832,15 +13832,25 @@ public static void RunModuleConstructor(System.ModuleHandle module) { }
[System.Diagnostics.CodeAnalysis.ExperimentalAttribute("SYSLIB5007", UrlFormat = "https://aka.ms/dotnet-warnings/{0}")]
public static partial class AsyncHelpers
{
[System.Runtime.Versioning.RequiresPreviewFeaturesAttribute]
public static void UnsafeAwaitAwaiter<TAwaiter>(TAwaiter awaiter) where TAwaiter : ICriticalNotifyCompletion { }
[System.Runtime.Versioning.RequiresPreviewFeaturesAttribute]
public static void AwaitAwaiter<TAwaiter>(TAwaiter awaiter) where TAwaiter : INotifyCompletion { }
[System.Runtime.Versioning.RequiresPreviewFeaturesAttribute]
public static void Await(System.Threading.Tasks.Task task) { throw null; }
[System.Runtime.Versioning.RequiresPreviewFeaturesAttribute]
public static T Await<T>(System.Threading.Tasks.Task<T> task) { throw null; }
[System.Runtime.Versioning.RequiresPreviewFeaturesAttribute]
public static void Await(System.Threading.Tasks.ValueTask task) { throw null; }
[System.Runtime.Versioning.RequiresPreviewFeaturesAttribute]
public static T Await<T>(System.Threading.Tasks.ValueTask<T> task) { throw null; }
[System.Runtime.Versioning.RequiresPreviewFeaturesAttribute]
public static void Await(System.Runtime.CompilerServices.ConfiguredTaskAwaitable configuredAwaitable) { throw null; }
[System.Runtime.Versioning.RequiresPreviewFeaturesAttribute]
public static void Await(System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable configuredAwaitable) { throw null; }
[System.Runtime.Versioning.RequiresPreviewFeaturesAttribute]
public static T Await<T>(System.Runtime.CompilerServices.ConfiguredTaskAwaitable<T> configuredAwaitable) { throw null; }
[System.Runtime.Versioning.RequiresPreviewFeaturesAttribute]
public static T Await<T>(System.Runtime.CompilerServices.ConfiguredValueTaskAwaitable<T> configuredAwaitable) { throw null; }
}
public sealed partial class RuntimeWrappedException : System.Exception
Expand Down
5 changes: 5 additions & 0 deletions src/tests/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
<Import Project="$(MSBuildThisFileDirectory)\Common\dir.sdkbuild.props" Condition="'$(UsingMicrosoftNETSdk)' == 'true'" />
<Import Project="$(MSBuildThisFileDirectory)\Common\dir.common.props" Condition="'$(UsingMicrosoftNETSdk)' != 'true'" />

<PropertyGroup>
<!-- Override the compiler version with a private build that supports async2 -->
<MicrosoftNetCompilersToolsetVersion>5.0.0-1.25259.6</MicrosoftNetCompilersToolsetVersion>
</PropertyGroup>

<PropertyGroup>
<RunningOnUnix Condition="('$(RunningOnUnix)' == '') And ('$(MSBuildRuntimeType)' == 'Core') And ('$(OS)'!='Windows_NT')">true</RunningOnUnix>
</PropertyGroup>
Expand Down
9 changes: 9 additions & 0 deletions src/tests/async/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Project>
<Import Project="../Directory.Build.props" />
<PropertyGroup>
<Features>$(Features);runtime-async=on</Features>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildThisFileDirectory)RuntimeAsyncMethodGenerationAttribute.cs" />
</ItemGroup>
</Project>
Copy link
Member

Choose a reason for hiding this comment

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

I think switching all tests to experimental compiler is good for runtimelab, but in main repo we might need to limit this to async folder.

I assume this will work in CI, right?

6 changes: 6 additions & 0 deletions src/tests/async/RuntimeAsyncMethodGenerationAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace System.Runtime.CompilerServices;
[AttributeUsage(AttributeTargets.Method)]
public class RuntimeAsyncMethodGenerationAttribute(bool runtimeAsync) : Attribute
{
public bool RuntimeAsync { get; } = runtimeAsync;
}
7 changes: 4 additions & 3 deletions src/tests/async/awaitingnotasync.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Xunit;

Expand All @@ -14,13 +13,15 @@ public static void TestEntryPoint()
AsyncEntryPoint().Wait();
}

[System.Runtime.CompilerServices.RuntimeAsyncMethodGeneration(false)]
private static async Task<T> GetTask<T>(T arg)
{
await Task.Yield();
return arg;
}

// TODO: switch every other scenario to use ValueTask
[System.Runtime.CompilerServices.RuntimeAsyncMethodGeneration(false)]
private static async ValueTask<T> GetValueTask<T>(T arg)
{
await Task.Yield();
Expand All @@ -33,13 +34,13 @@ private static async ValueTask<T> GetValueTask<T>(T arg)

private static T sIdentity<T>(T arg) => arg;

private static async2 Task AsyncEntryPoint()
private static async Task AsyncEntryPoint()
{
// static field
sField = GetTask(5);
Assert.Equal(5, await sField);

// property
// property
Assert.Equal(6, await sProp);

// generic identity
Expand Down
6 changes: 3 additions & 3 deletions src/tests/async/collectible-alc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void TestEntryPoint()
AsyncEntryPoint().Wait();
}

private static async2 Task AsyncEntryPoint()
private static async Task AsyncEntryPoint()
{
WeakReference wr = await CallFooAsyncAndUnload();

Expand All @@ -31,7 +31,7 @@ private static async2 Task AsyncEntryPoint()
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static async2 Task<WeakReference> CallFooAsyncAndUnload()
private static async Task<WeakReference> CallFooAsyncAndUnload()
{
TaskCompletionSource tcs = new();
(Task<string> task, WeakReference wr) = CallFooAsyncInCollectibleALC(tcs.Task);
Expand Down Expand Up @@ -63,7 +63,7 @@ private static (Task<string>, WeakReference) CallFooAsyncInCollectibleALC(Task t
}

// Task[] to work around a compiler bug
private static async2 Task<string> FooAsync(Task[] t)
private static async Task<string> FooAsync(Task[] t)
{
await t[0];
return "done";
Expand Down
1 change: 1 addition & 0 deletions src/tests/async/collectible-alc.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<!-- For collectible ALC -->
<RequiresProcessIsolation>True</RequiresProcessIsolation>
<Optimize>True</Optimize>
<Features>$(Features);runtime-async</Features>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
Expand Down
3 changes: 2 additions & 1 deletion src/tests/async/cse-array-index-byref.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,14 @@ public static void TestEntryPoint()
Assert.Equal(199_990_000, arr[0]);
}

[System.Runtime.CompilerServices.RuntimeAsyncMethodGeneration(false)]
private static async Task AsyncTestEntryPoint(int[] arr, int index)
{
await HoistedByref(arr, index);
}

[MethodImpl(MethodImplOptions.NoInlining)]
private static async2 Task<int> HoistedByref(int[] arr, int index)
private static async Task<int> HoistedByref(int[] arr, int index)
{
for (int i = 0; i < 20000; i++)
{
Expand Down
Loading