Skip to content

Make json source generation cancellable#69332

Merged
eiriktsarpalis merged 6 commits intodotnet:mainfrom
CyrusNajmabadi:jsonCancellation
May 17, 2022
Merged

Make json source generation cancellable#69332
eiriktsarpalis merged 6 commits intodotnet:mainfrom
CyrusNajmabadi:jsonCancellation

Conversation

@CyrusNajmabadi
Copy link
Contributor

No description provided.

@ghost
Copy link

ghost commented May 13, 2022

Tagging subscribers to this area: @dotnet/area-system-text-json, @gregsdennis
See info in area-owners.md if you want to be subscribed.

Issue Details

null

Author: CyrusNajmabadi
Assignees: CyrusNajmabadi
Labels:

area-System.Text.Json

Milestone: -

public void Initialize(GeneratorInitializationContext context)
{
context.RegisterForSyntaxNotifications(() => new SyntaxContextReceiver());
context.RegisterForSyntaxNotifications(() => new SyntaxContextReceiver(context.CancellationToken));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@chsienki is ok/correct to use this cancellation token here? is the delegate guaranteed to have a shorter lifetime than the CT for GeneratorInitializationContext ?

Copy link
Member

Choose a reason for hiding this comment

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

No, you can't do this. On the second run through, the initialization isn't called again but the token will be something else, so you'll still be referring to the previously captured token. The lack of a token on the GeneratorSyntaxContext was an oversight.

In both compilers before 4.0 and currently we check the cancellation token before we visit each tree (https://sourceroslyn.io/#Microsoft.CodeAnalysis/SourceGeneration/SyntaxStore.cs,812c07816abb8b9e)

It's obviously not as efficient as doing it per node visit but it will cancel out relatively quickly, at least.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good to know. I'll undo this

@CyrusNajmabadi CyrusNajmabadi requested a review from eerhardt May 13, 2022 21:56
@CyrusNajmabadi CyrusNajmabadi requested a review from chsienki May 14, 2022 02:42
@eiriktsarpalis eiriktsarpalis added this to the 7.0.0 milestone May 16, 2022
Copy link
Member

@eiriktsarpalis eiriktsarpalis left a comment

Choose a reason for hiding this comment

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

Thanks!

@CyrusNajmabadi
Copy link
Contributor Author

@chsienki can you review?

@eiriktsarpalis I'm not sure what your merge requirements are. If tests are passing and there's a signoff, is that sufficient? Thanks!

@eiriktsarpalis
Copy link
Member

I'm not sure what your merge requirements are. If tests are passing and there's a signoff, is that sufficient? Thanks!

Yep, that's it. I'll merge once the current PR builds complete.

@CyrusNajmabadi
Copy link
Contributor Author

@eiriktsarpalis Are the failures expected?

@eiriktsarpalis eiriktsarpalis merged commit 2157b28 into dotnet:main May 17, 2022
@CyrusNajmabadi CyrusNajmabadi deleted the jsonCancellation branch May 17, 2022 15:22
@CyrusNajmabadi
Copy link
Contributor Author

Thanks!

@ghost ghost locked as resolved and limited conversation to collaborators Jun 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants