Skip to content

[ASTPrinter] Intorduce 'IntroducerKeyword' name kind #38521

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 1 commit into from
Jul 30, 2021

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Jul 20, 2021

For more fine grained annotations. For now, it's handled as the same as Keyword name kind.

Fix an issue where extension wasn't marked as "keyword".

Also, move static priting out of SkipIntroducerKeywords guard because 'static' is not an declaration introducer.

(Preparation for #38453)

@rintaro
Copy link
Member Author

rintaro commented Jul 20, 2021

@swift-ci Please smoke test

Comment on lines 3094 to 3098
if (!Options.SkipIntroducerKeywords) {
if (decl->isExplicitActor()) {
Printer.printKeyword("actor", Options, " ");
} else {
Printer << tok::kw_class << " ";
}
}
if (!Options.SkipIntroducerKeywords)
Printer.printIntroducerKeyword(
decl->isExplicitActor() ? "actor" : "class");
Copy link
Member Author

@rintaro rintaro Jul 20, 2021

Choose a reason for hiding this comment

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

Since actor is not declared as a keyword, not all introducer are "keyword". There's no reason to use tok::kw_* for introducer printing anymore.

@rintaro rintaro requested a review from benlangmuir July 20, 2021 23:05
@@ -217,6 +219,14 @@ class ASTPrinter {
*this << Suffix;
}

void printIntroducerKeyword(StringRef name,
StringRef Suffix = " ") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should keep the default Suffix the same between printKeyword and printIntroducerKeyword, otherwise it's confusing.

@@ -1292,9 +1293,8 @@ void PrintAST::printPattern(const Pattern *pattern) {

case PatternKind::Binding:
if (!Options.SkipIntroducerKeywords)
Printer << (cast<BindingPattern>(pattern)->isLet() ? tok::kw_let
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we move checking SkipIntroducerKeywords into printIntroducerKeyword? That way you cannot forget, and also we could give the method the same signature as printKeyword, which also takes options.

@rintaro rintaro force-pushed the astprinter-introducerkeyword branch 2 times, most recently from 9222db0 to c535893 Compare July 20, 2021 23:54
@rintaro
Copy link
Member Author

rintaro commented Jul 21, 2021

@swift-ci Please smoke test

Printer.printKeyword("__consuming", Options, " ");
}
Printer << tok::kw_func << " ";
printMutabilityModifiersIfNeeded(decl);
Copy link
Contributor

@benlangmuir benlangmuir Jul 21, 2021

Choose a reason for hiding this comment

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

Will these (mutability and __consuming) now get printed in places they didn't used to due to not checking SkipIntroducerKeywords? Not sure if that's desirable or not 🤔

Copy link
Member Author

Choose a reason for hiding this comment

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

Renamed printMutabilityModifiersIfNeeded() to printSelfAccessKindModifiersIfNeeded() and moved __consuming printing into it. Also, added a printing option whether to print mutating/nonmutating/__consuming.

So far SkipIntroducerKeywords is used only in <RelatedName /> printing in SourceKit.

@rintaro rintaro force-pushed the astprinter-introducerkeyword branch 2 times, most recently from d5ae9c9 to c113ba0 Compare July 28, 2021 23:09
@rintaro
Copy link
Member Author

rintaro commented Jul 29, 2021

@swift-ci Please smoke test

For more fine grained annoations. For now, it's handled as the same as
'Keyword' name kind.

Fix an issue where 'extension' wasn't marked as "keyword".

Also, move 'static' priting out of 'SkipIntroducerKeywords' guard
because 'static' is not an declaration introducer.
@rintaro rintaro force-pushed the astprinter-introducerkeyword branch from c113ba0 to 6e69a44 Compare July 29, 2021 19:50
@rintaro
Copy link
Member Author

rintaro commented Jul 29, 2021

@swift-ci Please smoke test

break;
case SelfAccessKind::NonMutating:
if (AD && AD->isExplicitNonMutating() &&
!Options.excludeAttrKind(DAK_NonMutating))
Copy link
Contributor

Choose a reason for hiding this comment

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

This was checking DAK_Mutating before, which seems like a latent bug, but I don't think it's observable since the only place I found that adds DAK_Mutating but not DAK_NonMutating is protocol conformance diagnostics for non-accessors, but this code only prints nonmutating on accessors. Oh well, at least it's correct now 🤷

@rintaro rintaro merged commit d747ee9 into swiftlang:main Jul 30, 2021
@rintaro rintaro deleted the astprinter-introducerkeyword branch July 30, 2021 21:57
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.

2 participants