dotnet / roslyn

The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs.
https://docs.microsoft.com/dotnet/csharp/roslyn-sdk/
MIT License
18.96k stars 4.02k forks source link

Module cancellation and stack probing instrumentations #71961

Open tmat opened 8 months ago

tmat commented 8 months ago

Background and Motivation

The goal of the stack probing instrumentation is to protect a host process executing user-specified C# code from accidental mistakes that cause unrecoverable stack overflow.

Details: https://github.com/dotnet/roslyn/pull/71896

Proposed API

namespace Microsoft.CodeAnalysis.Emit
{
   public enum InstrumentationKind
    {
        None = 0,
        TestCoverage = 1,

+       /// <summary>
+       /// Instruments all methods, local functions and lambdas in the code with calls to <see cref="RuntimeHelpers.EnsureSufficientExecutionStack"/>,
+       /// to guard against accidental stack overflow.
+       /// </summary>
+       StackOverflowProbing = 2,

+       /// <summary>
+       /// Instruments code with calls to <see cref="CancellationToken.ThrowIfCancellationRequested"/> on a module-level defined 
+       /// <see cref="CancellationToken"/> to enable cancellation of code that hasn't necessarily been written as cancellable.
+       /// </summary>
+       /// <remarks>
+       /// The <see cref="CancellationToken"/> is emitted to a static field <code>&lt;PrivateImplementationDetails&gt;.ModuleCancellationToken</code>.
+       /// </remarks>
+       ModuleCancellation = 3
    }
}
dotnet-issue-labeler[bot] commented 8 months ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

dotnet-issue-labeler[bot] commented 7 months ago

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

chsienki commented 6 months ago

Api review: approved