Skip to content

Change RazorSyntaxTree.Diagnostics from an IReadOnlyList<RazorDiagnostic> to an ImmutableArray<RazorDiagnostic>#10797

Merged
DustinCampbell merged 15 commits into
dotnet:mainfrom
DustinCampbell:syntax-tree-diagnostics
Sep 4, 2024
Merged

Change RazorSyntaxTree.Diagnostics from an IReadOnlyList<RazorDiagnostic> to an ImmutableArray<RazorDiagnostic>#10797
DustinCampbell merged 15 commits into
dotnet:mainfrom
DustinCampbell:syntax-tree-diagnostics

Conversation

@DustinCampbell

Copy link
Copy Markdown
Member

This pull request represents several changes with the ultimate goal of exposing RazorSyntaxTree.Diagnostics as an ImmutableArray<RazorDiagnostic> rather than an IReadOnlyList<RazorDiagnostic>:

  • Clean up RazorSyntaxTree and get rid of DefaultRazorSyntaxTree.
  • Add (Drain)ToImmutableOrdered* methods to PooledArrayBuilder<T>. Note that this change also includes a refactoring to the various unit tests for ordering to share test data that I've isolated to a single commit.
  • Clean up and improve ErrorSink to no longer greedily create a new List<T> before any errors are encountered.
  • Clean up ParserContext and make it used pooled collections.
  • Use pooled collections when computing and caching the result of RazorSyntaxTree.Diagnostics.

- Use pooled `ImmutableArray<RazorDiagnostic>.Builder` internally
- Don't request pooled builder until first error is added
- Make ErrorSink disposable to return builder to pool
- Add GetErrorsAndClear() method to returns an `ImmutableArray<RazorDiagnostic>` and clears out the sink.
- Add 'ParserContext.PushNewErrorScope(...)` to handle the temporary ErrorSinks used by CSharpCodeParser
This change cleans up ParserContext a bit and uses pooled collections within it.
@DustinCampbell DustinCampbell requested review from a team as code owners August 27, 2024 18:14

@davidwengier davidwengier left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

✅ Tooling

_inlineCount = 0;
}

public readonly ImmutableArray<T> ToImmutableOrdered()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was looking for these methods just yesterday, and I couldn't find them, but knew I'd seem them somewhere. The mystery is solved! :D

@chsienki chsienki left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM. I think every time I saw something I wanted to comment on, you fixed it in the next commit :)

@333fred 333fred left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks as always for the meticulous commit history Dustin, it significantly helps make these reviews easy. Only one small testing comment, otherwise everything LGTM.

It is perfectly legal for a PooledArrayBuilder<T> to be drained via one of the DrainToImmutable* methods and then continue adding items to the builder. However, if the inner ImmutableArray<T>.Builder's capacity was set to 0 during the drain, its capacity will not be reset to any specified value when adding new items. This change fixes that.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants