-
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// RUN: %empty-directory(%t) | ||
// RUN: %target-swift-frontend -emit-module -o %t/Test~partial.swiftmodule -module-name Test -primary-file %s | ||
// RUN: %target-swift-frontend -merge-modules -emit-module -o %t/Test.swiftmodule %t/Test~partial.swiftmodule | ||
// RUN: %target-swift-ide-test -print-module -module-to-print=Test -source-filename=x -I %t | %FileCheck %s | ||
|
||
// CHECK-LABEL: func testDefaultArguments( | ||
public func testDefaultArguments( | ||
// CHECK-SAME: normal: Int = 0 | ||
normal: Int = 0, | ||
// CHECK-SAME: multiToken: Int = Int.max | ||
multiToken: Int = Int.max, | ||
// CHECK-SAME: special: Int = #line | ||
special: Int = #line | ||
) {} | ||
// CHECK-SAME: ) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -328,8 +328,8 @@ enum E7: String { | |
|
||
// RUN: %sourcekitd-test -req=cursor -pos=31:7 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | %FileCheck -check-prefix=CHECK13 %s | ||
// CHECK13: source.lang.swift.decl.function.free (31:6-31:37) | ||
// CHECK13: <Declaration>func testDefaultParam(arg1: <Type usr="s:Si">Int</Type> = default)</Declaration> | ||
// CHECK13: <decl.function.free><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>testDefaultParam</decl.name>(<decl.var.parameter><decl.var.parameter.argument_label>arg1</decl.var.parameter.argument_label>: <decl.var.parameter.type><ref.struct usr="s:Si">Int</ref.struct></decl.var.parameter.type> = <syntaxtype.keyword>default</syntaxtype.keyword></decl.var.parameter>)</decl.function.free> | ||
// CHECK13: <Declaration>func testDefaultParam(arg1: <Type usr="s:Si">Int</Type> = 0)</Declaration> | ||
// CHECK13: <decl.function.free><syntaxtype.keyword>func</syntaxtype.keyword> <decl.name>testDefaultParam</decl.name>(<decl.var.parameter><decl.var.parameter.argument_label>arg1</decl.var.parameter.argument_label>: <decl.var.parameter.type><ref.struct usr="s:Si">Int</ref.struct></decl.var.parameter.type> = 0</decl.var.parameter>)</decl.function.free> | ||
|
||
// RUN: %sourcekitd-test -req=cursor -pos=34:4 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | %FileCheck -check-prefix=CHECK14 %s | ||
// CHECK14: source.lang.swift.ref.function.free ({{.*}}Foo.framework/Frameworks/FooSub.framework/Headers/FooSub.h:4:5-4:16) | ||
|
@@ -652,13 +652,11 @@ enum E7: String { | |
// CHECK73-SAME: = <syntaxtype.keyword>#file</syntaxtype.keyword> | ||
// CHECK73-SAME: = <syntaxtype.keyword>#line</syntaxtype.keyword> | ||
// CHECK73-SAME: = <syntaxtype.keyword>#column</syntaxtype.keyword> | ||
// FIXME: [] | ||
// CHECK73-SAME: = <syntaxtype.keyword>default</syntaxtype.keyword> | ||
// FIXME: [:] | ||
// CHECK73-SAME: = <syntaxtype.keyword>default</syntaxtype.keyword> | ||
// FIXME: keyword nil | ||
// CHECK73-SAME: = <syntaxtype.keyword>default</syntaxtype.keyword> | ||
// CHECK73-SAME: = <syntaxtype.keyword>default</syntaxtype.keyword> | ||
// 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 commentThe 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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Huh, so are There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. SGTM |
||
// CHECK73-SAME: = 1 | ||
|
||
// RUN: %sourcekitd-test -req=cursor -pos=162:8 %s -- -F %S/../Inputs/libIDE-mock-sdk -I %t.tmp %mcp_opt %s | %FileCheck %s -check-prefix=CHECK74 | ||
// CHECK74: source.lang.swift.decl.function.method.instance (162:8-162:20) | ||
|
Uh oh!
There was an error while loading. Please reload this page.
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 thisStringRef
backed bySmallVector<uint64_t, 64> scratch
? Is it safe to store it in AST nodes as aStringRef
?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 :)