-
Notifications
You must be signed in to change notification settings - Fork 0
fix: preserve incremental pipeline cancellation/cache stability #117
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
....XunitCancellationShared/ANcpLua.Roslyn.Utilities.Examples.XunitCancellationShared.csproj
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <Project Sdk="Microsoft.NET.Sdk"> | ||
| <PropertyGroup> | ||
| <TargetFramework>netstandard2.0</TargetFramework> | ||
| <LangVersion>latest</LangVersion> | ||
| <Nullable>enable</Nullable> | ||
| <ImplicitUsings>disable</ImplicitUsings> | ||
| <RootNamespace>ANcpLua.Roslyn.Utilities.Examples.XunitCancellationShared</RootNamespace> | ||
| <IsPackable>false</IsPackable> | ||
| <GenerateDocumentationFile>false</GenerateDocumentationFile> | ||
| </PropertyGroup> | ||
|
|
||
| <ItemGroup> | ||
| <PackageReference Include="Microsoft.CodeAnalysis.CSharp" /> | ||
| </ItemGroup> | ||
|
|
||
| <ItemGroup> | ||
| <ProjectReference Include="..\ANcpLua.Roslyn.Utilities\ANcpLua.Roslyn.Utilities.csproj" /> | ||
| </ItemGroup> | ||
| </Project> |
37 changes: 37 additions & 0 deletions
37
...Lua.Roslyn.Utilities.Examples.XunitCancellationShared/MissingCancellationTokenContract.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| using System.Threading; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.CodeAnalysis.CSharp; | ||
| using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
| using Microsoft.CodeAnalysis.Operations; | ||
| using ANcpLua.Roslyn.Utilities; | ||
|
|
||
| namespace ANcpLua.Roslyn.Utilities.Examples.XunitCancellationShared; | ||
|
|
||
| public static class MissingCancellationTokenContract | ||
| { | ||
| public const string DiagnosticId = "ANCP0001"; | ||
| public const string ParameterNameProperty = "ParameterName"; | ||
| public const string ParameterIndexProperty = "ParameterIndex"; | ||
| public const string ReplacementExpression = "TestContext.Current.CancellationToken"; | ||
|
|
||
| public static bool IsDefaultCancellationTokenArgument(IOperation operation, ITypeSymbol cancellationTokenType) | ||
| { | ||
| if (operation is null) | ||
| return false; | ||
|
|
||
| operation = operation.UnwrapAllConversions().UnwrapParenthesized(); | ||
|
|
||
| if (operation.Syntax.IsKind(SyntaxKind.DefaultExpression) | ||
| || operation.Syntax.IsKind(SyntaxKind.DefaultLiteralExpression)) | ||
| return true; | ||
|
|
||
| return operation is IPropertyReferenceOperation | ||
| { | ||
| Property: { Name: nameof(CancellationToken.None), ContainingType: { } containingType } | ||
| } && containingType.IsEqualTo(cancellationTokenType); | ||
| } | ||
|
|
||
| public static ExpressionSyntax CreateReplacementTokenExpression() => | ||
| SyntaxFactory.ParseExpression(ReplacementExpression); | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| // Copyright (c) ANcpLua. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace ANcpLua.Roslyn.Utilities.Models; | ||
|
|
||
| /// <summary> | ||
| /// A value-equatable snapshot of an <see cref="Exception" /> safe to flow through the | ||
| /// incremental generator cache. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// <see cref="Exception" /> instances do not implement value equality, so storing one in | ||
| /// pipeline state forces every cache comparison to reference-equality and breaks | ||
| /// incremental caching across compilations. <see cref="GeneratorErrorInfo" /> captures the | ||
| /// minimum information needed to surface the failure as a diagnostic — type name, message, | ||
| /// and stack trace — as immutable strings, which the record-struct equality contract | ||
| /// compares by value. | ||
| /// </para> | ||
| /// </remarks> | ||
| /// <param name="TypeName">The exception's runtime type name (e.g. <c>System.InvalidOperationException</c>).</param> | ||
| /// <param name="Message">The exception's message, or empty if absent.</param> | ||
| /// <param name="StackTrace">The exception's stack trace, or empty if absent.</param> | ||
| #if ANCPLUA_ROSLYN_PUBLIC | ||
| public | ||
| #else | ||
| internal | ||
| #endif | ||
| readonly record struct GeneratorErrorInfo(string TypeName, string Message, string StackTrace) | ||
| { | ||
| /// <summary> | ||
| /// Captures an <see cref="Exception" /> as a value-equatable <see cref="GeneratorErrorInfo" />. | ||
| /// </summary> | ||
| public static GeneratorErrorInfo From(Exception exception) | ||
| { | ||
| if (exception is null) throw new ArgumentNullException(nameof(exception)); | ||
| return new GeneratorErrorInfo( | ||
| exception.GetType().FullName ?? exception.GetType().Name, | ||
| exception.Message ?? string.Empty, | ||
| exception.StackTrace ?? string.Empty); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Renders the captured error in <c>Type: Message\n StackTrace</c> form, mirroring | ||
| /// <see cref="Exception.ToString" />. | ||
| /// </summary> | ||
| public override string ToString() | ||
| { | ||
| return string.IsNullOrEmpty(StackTrace) | ||
| ? $"{TypeName}: {Message}" | ||
| : $"{TypeName}: {Message}{Environment.NewLine}{StackTrace}"; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This helper now rethrows every
OperationCanceledException, which means selectors that throw OCE for reasons unrelated to the pipeline token (for example, a nested API using its own cancellation token) will abort generation and skip theSRE001diagnostic path. That breaks the method’s “report exceptions and continue” behavior for a real class of failures; it should only propagate when the RoslyncancellationTokenis actually canceled (e.g., catch filter oncancellationToken.IsCancellationRequestedor matching token).Useful? React with 👍 / 👎.