Skip to content
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

Remove unnecessary check of trailing trivia for directives. #71185

Merged
merged 8 commits into from
Dec 11, 2023

Conversation

CyrusNajmabadi
Copy link
Member

@CyrusNajmabadi CyrusNajmabadi commented Dec 8, 2023

Directives can only be in leading trivia. So this walk is unnecessary.

@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Dec 8, 2023
@CyrusNajmabadi CyrusNajmabadi changed the title No directives Remove unnecessary check of trailing trivia for directives. Dec 8, 2023
{
foreach (var trivia in node.AsToken().LeadingTrivia)
GetDirectivesInTrivia(trivia, filter, ref directives);
}
Copy link
Member Author

Choose a reason for hiding this comment

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

simplified check and inlined.

@@ -865,40 +868,21 @@ private static void GetDirectives<TDirective>(SyntaxNode node, Func<TDirective,
{
foreach (var trivia in node.DescendantTrivia(node => node.ContainsDirectives, descendIntoTrivia: true))
{
_ = GetDirectivesInTrivia(trivia, filter, ref directives);
GetDirectivesInTrivia(trivia, filter, ref directives);
Copy link
Member Author

Choose a reason for hiding this comment

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

no need for return value.

{
foreach (var tr in trivia)
{
if (!GetDirectivesInTrivia(tr, filter, ref directives) && tr.GetStructure() is SyntaxNode node)
Copy link
Member Author

@CyrusNajmabadi CyrusNajmabadi Dec 8, 2023

Choose a reason for hiding this comment

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

directives can't be inside other structured trivia. THey are teh structured trivia. So just removed this.

@CyrusNajmabadi CyrusNajmabadi marked this pull request as ready for review December 8, 2023 21:18
@CyrusNajmabadi CyrusNajmabadi requested a review from a team as a code owner December 8, 2023 21:18
@CyrusNajmabadi
Copy link
Member Author

@333fred @RikkiGibson ptal.

directives = new List<TDirective>();
}

directives ??= [];
Copy link
Contributor

Choose a reason for hiding this comment

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

@CyrusNajmabadi CyrusNajmabadi merged commit d3520d7 into dotnet:main Dec 11, 2023
@ghost ghost added this to the Next milestone Dec 11, 2023
@CyrusNajmabadi CyrusNajmabadi deleted the noDirectives branch December 11, 2023 21:35
@Cosifne Cosifne modified the milestones: Next, 17.9 P3 Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants