-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Preserve default argument text through serialization #18579
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
@swift-ci Please test |
@swift-ci Please test source compatibility |
param->setDefaultArgumentKind(*defaultArg); | ||
if (!blobData.empty()) | ||
param->setDefaultValueStringRepresentation(blobData); |
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.
Probably I'm missing something. But, where the blobData
come from? Isn't this StringRef
backed by SmallVector<uint64_t, 64> scratch
? Is it safe to store it in AST nodes as a StringRef
?
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.
Ah, I read the source of BitstreamReader
, and I understand it now :)
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.
This is great! Please add this to CHANGELOG
!
// CHECK73-SAME: = [] | ||
// CHECK73-SAME: = [:] | ||
// FIXME: should be <syntaxtype.keyword>nil</syntaxtype.keyword> | ||
// CHECK73-SAME: = nil |
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.
Do you know why this isn't getting the keyword treatment? Is it coming through as a "normal" default argument?
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, any explicitly-written non-magic-literal expression is still "normal". I suppose we could special-case "the single token 'nil'" and see if that works, but it didn't seem too important to me when other default arguments are also not syntax-highlighted.
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.
Huh, so are DefaultArgumentKind::NilLiteral
(and the empty literals too I guess) unused?
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.
They're used by the importer, since synthesizing instructions and type-checking them would have been a pain. It also mattered back before default arguments were inlinable, because you definitely don't want to call a function just to get nil
.
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 experimented with the "see if the expression is a NilLiteralExpr" approach and it fell over in Sema. It's probably still doable, but I think I'm just going to leave it for now.
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.
SGTM
This allows us to dump it in the generated interface, though it's still not syntax-highlighted. This is necessary for textual module interfaces, but it's also just a longstanding request for Xcode's "Generated Interface" / "Jump to Definition" feature. rdar://problem/18675831
3ef50c6
to
e4902b7
Compare
@swift-ci Please smoke test |
This allows us to dump it in the generated interface, though it's still not syntax-highlighted. This is necessary for textual module interfaces, but it's also just a longstanding request for Xcode's "Generated Interface" / "Jump to Definition" feature.
SR-2608 / rdar://problem/18675831