Repository navigation
Implement module cancellation and stack probing instrumentations - #71896
Conversation
|
@dotnet/roslyn-compiler PTAL |
I might be misinterpreting this, but doesn't this mean that the application will no longer be able to cancel execution through user provided tokens (since they will be ignored)? Should the tokens be "combined" instead? Do we already have a consumer for this instrumentation? Could you provide some details if that is the case? Are we going to document this capability and how to take advantage of it somewhere? |
|
@tmat It looks like there are some analyzer errors |
We don't expect the user-specified code that is being executed by the host to explicitly handle cancellations in the current scenarios (executing small scripts that have access to the APIs exposed by the host), so I went with the simple implementation. We could definitely combine the tokens. Shouldn't add too much complexity. I can follow up on that. The cancellation instrumentation is very specialized API tailored to very specific scenarios (similarly to EnC APIs). |
|
@jjonescz for second review |
|
Done with review pass (commit 12) |
|
@tmat It looks like there are legitimate test failures |
|
Done with review pass (commit 13). Besides the test failure, I am still tracking the following threads: |
Fixing the test failure. This is addressed - I have added code that makes the check insensitive to whitespace. The parameter is removed. |
|
Done with review pass (commit 14). Still tracking #71896 (review) |
| var isInstrumented = il.Contains("System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack"); | ||
|
|
||
| Assert.False(isInstrumented, | ||
| $"Method '{qualifiedMethodName}' should not be trumented. Actual IL:{Environment.NewLine}{il}"); |
|
@jjonescz Please review the latest revision |
| typeMap1: null, | ||
| parametersWithCancellationToken.AsSpan(0, methodDefinition.Parameters.Length), | ||
| typeMap, | ||
| MemberSignatureComparer.RefKindCompareMode.ConsiderDifferences, |
There was a problem hiding this comment.
I am wondering if any unexpected behavior changes could occur if:
- the original method was a
readonlystruct method and the replacement method was not, for example. - Or, the other way around, the original is non-readonly and the replacement is readonly.
Since it seems like we are not checking the readonly-ness of the this parameter in these checks.
Since this PR is already merged some time ago, I will open a new issue based on this comment.
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.
Similarly, the module-level cancellation instrumentation allows the host to avoid the compiled user code accidentally blocking for long time. The instrumentation:
CancellationTokenstatic writable field to<PrivateImplementationDetails>. The host can set this token via Reflection before executing the compiled code.ThrowIfCancellationRequestedon the host token into each method, loop or goto.CancellationTokenas the last parameter with matching overloads that do and passes it the host token.The instrumentation may change semantics of the user specified code in rare cases, which is the trade-off the host needs to make.
Neither instrumentation provides guarantees that stack overflow will be avoided, or the code won't run indefinitely.
Supports #71268
Public API: #71961