-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Adjust printing to take into account special DeclNames #9979
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
Conversation
Please test with following pull request: @swift-ci Please test |
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.
Mostly looking good.
include/swift/AST/Identifier.h
Outdated
@@ -233,6 +233,12 @@ class DeclBaseName { | |||
return !isSpecial() && getIdentifier().isEditorPlaceholder(); | |||
} | |||
|
|||
/// A representation of the name to be displayed to users. May be ambiguous | |||
/// between identifiers and special names |
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.
Nitpick: Missing period.
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.
Good catch!
include/swift/AST/Identifier.h
Outdated
@@ -233,6 +233,12 @@ class DeclBaseName { | |||
return !isSpecial() && getIdentifier().isEditorPlaceholder(); | |||
} | |||
|
|||
/// A representation of the name to be displayed to users. May be ambiguous | |||
/// between identifiers and special names | |||
StringRef userFacingStr() const { |
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.
Nitpick: I feel like the abbreviation of "str" doesn't make sense in a longer name. How about "userFacingName" or "nameForDiagnostics" or something like that?
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.
I'll go with userFacingName
since it's not only used for diagnostics but also for some other stuff like sorting names.
lib/AST/ASTVerifier.cpp
Outdated
@@ -3202,7 +3202,8 @@ bool swift::shouldVerify(const Decl *D, const ASTContext &Context) { | |||
return true; | |||
} | |||
|
|||
size_t Hash = llvm::hash_value(VD->getNameStr()); | |||
size_t Hash = | |||
llvm::DenseMapInfo<DeclBaseName>::getHashValue(VD->getBaseName()); |
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.
Please use a hash that's stable from run to run. (The AST verifier doesn't need to be fast.)
lib/AST/Identifier.cpp
Outdated
// TODO: Handle special names | ||
return OS << I.getIdentifier(); | ||
if (I.empty()) | ||
return OS << "_"; |
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.
I don't think <<
should behave differently from userFacingStr
(or whatever). Either they should both insert the "_" or neither should.
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.
Yeah, makes sense. userFacingStr
now returns "_" for the empty name since we require "_" for <<
for quite a few diagnostics IIRC
@@ -3729,7 +3729,8 @@ class CompletionLookup final : public swift::VisibleDeclConsumer { | |||
for (auto Ex : NTD->getExtensions()) { | |||
handleDeclRange(Ex->getMembers(), Reason); | |||
} | |||
} else if (isNameHit(VD->getNameStr())) { | |||
} else if (!VD->getBaseName().isSpecial() && |
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.
@benlangmuir, is this method ever supposed to produce subscripts?
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.
It probably should. The situation would be something like
x[label: #^COMPLETE_HERE^#]
lib/IDE/SyntaxModel.cpp
Outdated
DRE->getName().getBaseIdentifier().getLength()))) | ||
if (!Fn(CharSourceRange( | ||
DRE->getSourceRange().Start, | ||
DRE->getName().getBaseName().userFacingStr().size()))) |
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.
Note for @nathawes and @bitjammer: this is not a good way to measure the length of an identifier because it won't handle the backtick-escaping syntax. Using the lexer is the right way to do it.
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.
Noted!
2952410
to
ac44647
Compare
@jrose-apple I renamed @swift-ci please test |
ac44647
to
638bf80
Compare
@swift-ci Please test |
Build failed |
Build failed |
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.
Looks good now. Still need to get back to the diagnostic changes.
Print DeclBaseNames using a new userFacingStr() method to prepare for DeclBaseNames that are not backed by Identifiers
638bf80
to
949968a
Compare
@swift-ci Please test |
macOS failure seemed unrelated. Let's try again @swift-ci Please test OS X Platform |
Build failed |
Print DeclBaseNames using a new userFacingStr() method to prepare for
DeclBaseNames that are not backed by Identifiers
This includes the changes from #9975, #9976, #9977, #9978, #9978