Skip to content

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

Merged
merged 1 commit into from
Aug 9, 2018

Conversation

jrose-apple
Copy link
Contributor

@jrose-apple jrose-apple commented Aug 8, 2018

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

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test

@jrose-apple
Copy link
Contributor Author

@swift-ci Please test source compatibility

param->setDefaultArgumentKind(*defaultArg);
if (!blobData.empty())
param->setDefaultValueStringRepresentation(blobData);
Copy link
Member

@rintaro rintaro Aug 9, 2018

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?

Copy link
Member

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 :)

Copy link
Member

@rintaro rintaro left a 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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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
@jrose-apple jrose-apple force-pushed the san-andreas-default branch from 3ef50c6 to e4902b7 Compare August 9, 2018 16:47
@jrose-apple
Copy link
Contributor Author

@swift-ci Please smoke test

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.

3 participants