Merge pull request #18594 from fredriss/dev/rdar-43011380-lldb-deployment-target
Force teh deployment target of LLDB to 10.13
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d11afef..c929b26 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,11 @@
Swift 5.0
---------
+* [SR-2608][]
+
+ Default arguments are now printed in SourceKit-generated interfaces for Swift
+ modules, instead of just using a placeholder `default`.
+
* Notable bug fix: unowned and unowned(unsafe) variables now support optional
types.
@@ -7151,3 +7156,4 @@
[SR-2131]: <https://bugs.swift.org/browse/SR-2131>
[SR-2388]: <https://bugs.swift.org/browse/SR-2388>
[SR-2394]: <https://bugs.swift.org/browse/SR-2394>
+[SR-2608]: <https://bugs.swift.org/browse/SR-2608>
diff --git a/include/swift/AST/Decl.h b/include/swift/AST/Decl.h
index 1b9c326..1864d07 100644
--- a/include/swift/AST/Decl.h
+++ b/include/swift/AST/Decl.h
@@ -4704,6 +4704,7 @@
struct StoredDefaultArgument {
Expr *DefaultArg = nullptr;
Initializer *InitContext = nullptr;
+ StringRef StringRepresentation;
};
/// The default value, if any, along with whether this is varargs.
@@ -4767,6 +4768,17 @@
void setDefaultArgumentInitContext(Initializer *initContext);
+ /// Returns a saved string representation of the parameter's default value.
+ ///
+ /// This should only be called if the default value expression is absent or
+ /// doesn't have a valid source range; otherwise, clients should extract the
+ /// source text from that range.
+ ///
+ /// \sa getDefaultValue
+ StringRef getDefaultValueStringRepresentation() const;
+
+ void setDefaultValueStringRepresentation(StringRef stringRepresentation);
+
/// Whether or not this parameter is varargs.
bool isVariadic() const { return DefaultValueAndIsVariadic.getInt(); }
void setVariadic(bool value = true) {DefaultValueAndIsVariadic.setInt(value);}
diff --git a/include/swift/AST/DefaultArgumentKind.h b/include/swift/AST/DefaultArgumentKind.h
index 67ccc95..ad1ba79 100644
--- a/include/swift/AST/DefaultArgumentKind.h
+++ b/include/swift/AST/DefaultArgumentKind.h
@@ -55,10 +55,6 @@
};
enum { NumDefaultArgumentKindBits = 4 };
-/// Retrieve the spelling of this default argument in source code, or
-/// an empty string if it has none.
-llvm::StringRef getDefaultArgumentSpelling(DefaultArgumentKind kind);
-
} // end namespace swift
#endif // LLVM_SWIFT_DEFAULTARGUMENTKIND_H
diff --git a/include/swift/Serialization/ModuleFormat.h b/include/swift/Serialization/ModuleFormat.h
index 8d6d717..5e6755f 100644
--- a/include/swift/Serialization/ModuleFormat.h
+++ b/include/swift/Serialization/ModuleFormat.h
@@ -55,7 +55,7 @@
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
/// Don't worry about adhering to the 80-column limit for this line.
-const uint16_t VERSION_MINOR = 431; // Last change: eliminate PARAMETERLIST_ELT
+const uint16_t VERSION_MINOR = 432; // Last change: default argument text
using DeclIDField = BCFixed<31>;
@@ -1003,13 +1003,14 @@
using ParamLayout = BCRecordLayout<
PARAM_DECL,
- IdentifierIDField, // argument name
- IdentifierIDField, // parameter name
- DeclContextIDField, // context decl
+ IdentifierIDField, // argument name
+ IdentifierIDField, // parameter name
+ DeclContextIDField, // context decl
VarDeclSpecifierField, // specifier
- TypeIDField, // interface type
- BCFixed<1>, // isVariadic?
- DefaultArgumentField // default argument
+ TypeIDField, // interface type
+ BCFixed<1>, // isVariadic?
+ DefaultArgumentField, // default argument kind
+ BCBlob // default argument text
>;
using FuncLayout = BCRecordLayout<
diff --git a/lib/AST/ASTPrinter.cpp b/lib/AST/ASTPrinter.cpp
index 65d9747..738b379 100644
--- a/lib/AST/ASTPrinter.cpp
+++ b/lib/AST/ASTPrinter.cpp
@@ -2327,8 +2327,8 @@
Printer << "...";
if (param->isDefaultArgument()) {
- auto defaultArgStr
- = getDefaultArgumentSpelling(param->getDefaultArgumentKind());
+ StringRef defaultArgStr = param->getDefaultValueStringRepresentation();
+
if (defaultArgStr.empty()) {
if (Options.PrintDefaultParameterPlaceholder)
Printer << " = " << tok::kw_default;
@@ -2341,6 +2341,7 @@
case DefaultArgumentKind::Column:
case DefaultArgumentKind::Function:
case DefaultArgumentKind::DSOHandle:
+ case DefaultArgumentKind::NilLiteral:
Printer.printKeyword(defaultArgStr);
break;
default:
diff --git a/lib/AST/CMakeLists.txt b/lib/AST/CMakeLists.txt
index 72885b8..a961cd8 100644
--- a/lib/AST/CMakeLists.txt
+++ b/lib/AST/CMakeLists.txt
@@ -24,7 +24,6 @@
Decl.cpp
DeclContext.cpp
DeclNameLoc.cpp
- DefaultArgumentKind.cpp
DiagnosticConsumer.cpp
DiagnosticEngine.cpp
DiagnosticList.cpp
diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp
index ffd1d72..4739c4e 100644
--- a/lib/AST/Decl.cpp
+++ b/lib/AST/Decl.cpp
@@ -4880,6 +4880,43 @@
DefaultValueAndIsVariadic.getPointer()->InitContext = initContext;
}
+StringRef ParamDecl::getDefaultValueStringRepresentation() const {
+ switch (getDefaultArgumentKind()) {
+ case DefaultArgumentKind::None:
+ llvm_unreachable("called on a ParamDecl with no default value");
+ case DefaultArgumentKind::Normal:
+ assert(DefaultValueAndIsVariadic.getPointer() &&
+ "default value not provided yet");
+ return DefaultValueAndIsVariadic.getPointer()->StringRepresentation;
+ case DefaultArgumentKind::Inherited:
+ // FIXME: This needs /some/ kind of textual representation, but this isn't
+ // a great one.
+ return "super";
+ case DefaultArgumentKind::File: return "#file";
+ case DefaultArgumentKind::Line: return "#line";
+ case DefaultArgumentKind::Column: return "#column";
+ case DefaultArgumentKind::Function: return "#function";
+ case DefaultArgumentKind::DSOHandle: return "#dsohandle";
+ case DefaultArgumentKind::NilLiteral: return "nil";
+ case DefaultArgumentKind::EmptyArray: return "[]";
+ case DefaultArgumentKind::EmptyDictionary: return "[:]";
+ }
+}
+
+void
+ParamDecl::setDefaultValueStringRepresentation(StringRef stringRepresentation) {
+ assert(getDefaultArgumentKind() == DefaultArgumentKind::Normal);
+ assert(!stringRepresentation.empty());
+
+ if (!DefaultValueAndIsVariadic.getPointer()) {
+ DefaultValueAndIsVariadic.setPointer(
+ getASTContext().Allocate<StoredDefaultArgument>());
+ }
+
+ DefaultValueAndIsVariadic.getPointer()->StringRepresentation =
+ stringRepresentation;
+}
+
void DefaultArgumentInitializer::changeFunction(
DeclContext *parent, ParameterList *paramList) {
if (parent->isLocalContext()) {
diff --git a/lib/AST/DefaultArgumentKind.cpp b/lib/AST/DefaultArgumentKind.cpp
deleted file mode 100644
index 6f65b91..0000000
--- a/lib/AST/DefaultArgumentKind.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-//===--- DefaultArgumentKind.cpp - Default Argument Implementation --------===//
-//
-// This source file is part of the Swift.org open source project
-//
-// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
-// Licensed under Apache License v2.0 with Runtime Library Exception
-//
-// See https://swift.org/LICENSE.txt for license information
-// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
-//
-//===----------------------------------------------------------------------===//
-//
-// This file implements utilities associated with default arguments.
-//
-//===----------------------------------------------------------------------===//
-#include "swift/AST/DefaultArgumentKind.h"
-#include "swift/AST/ASTContext.h"
-#include "swift/AST/Decl.h"
-#include "swift/AST/Expr.h"
-using namespace swift;
-
-StringRef swift::getDefaultArgumentSpelling(DefaultArgumentKind kind) {
- switch (kind) {
- case DefaultArgumentKind::None:
- case DefaultArgumentKind::Normal:
- case DefaultArgumentKind::Inherited:
- return StringRef();
- case DefaultArgumentKind::File: return "#file";
- case DefaultArgumentKind::Line: return "#line";
- case DefaultArgumentKind::Column: return "#column";
- case DefaultArgumentKind::Function: return "#function";
- case DefaultArgumentKind::DSOHandle: return "#dsohandle";
- case DefaultArgumentKind::NilLiteral: return "nil";
- case DefaultArgumentKind::EmptyArray: return "[]";
- case DefaultArgumentKind::EmptyDictionary: return "[:]";
- }
-
- llvm_unreachable("Unhandled DefaultArgumentKind in switch.");
-}
diff --git a/lib/Parse/ParsePattern.cpp b/lib/Parse/ParsePattern.cpp
index 36cfe89..76658ff 100644
--- a/lib/Parse/ParsePattern.cpp
+++ b/lib/Parse/ParsePattern.cpp
@@ -63,11 +63,9 @@
}
}
-static ParserStatus parseDefaultArgument(Parser &P,
- Parser::DefaultArgumentInfo *defaultArgs,
- unsigned argIndex,
- Expr *&init,
- Parser::ParameterContextKind paramContext) {
+static ParserStatus parseDefaultArgument(
+ Parser &P, Parser::DefaultArgumentInfo *defaultArgs, unsigned argIndex,
+ Expr *&init, Parser::ParameterContextKind paramContext) {
SyntaxParsingContext DefaultArgContext(P.SyntaxContext,
SyntaxKind::InitializerClause);
SourceLoc equalLoc = P.consumeToken(tok::equal);
@@ -576,8 +574,17 @@
paramContext == Parser::ParameterContextKind::Initializer ||
paramContext == Parser::ParameterContextKind::EnumElement) &&
"Default arguments are only permitted on the first param clause");
- result->setDefaultArgumentKind(getDefaultArgKind(param.DefaultArg));
+ DefaultArgumentKind kind = getDefaultArgKind(param.DefaultArg);
+ result->setDefaultArgumentKind(kind);
result->setDefaultValue(param.DefaultArg);
+ if (kind == DefaultArgumentKind::Normal) {
+ SourceRange defaultArgRange = param.DefaultArg->getSourceRange();
+ CharSourceRange charRange =
+ Lexer::getCharSourceRangeFromSourceRange(parser.SourceMgr,
+ defaultArgRange);
+ StringRef defaultArgText = parser.SourceMgr.extractText(charRange);
+ result->setDefaultValueStringRepresentation(defaultArgText);
+ }
}
elements.push_back(result);
diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp
index 3c5e2d0..3d75606 100644
--- a/lib/Serialization/Deserialization.cpp
+++ b/lib/Serialization/Deserialization.cpp
@@ -3040,8 +3040,11 @@
// Decode the default argument kind.
// FIXME: Default argument expression, if available.
- if (auto defaultArg = getActualDefaultArgKind(rawDefaultArg))
+ if (auto defaultArg = getActualDefaultArgKind(rawDefaultArg)) {
param->setDefaultArgumentKind(*defaultArg);
+ if (!blobData.empty())
+ param->setDefaultValueStringRepresentation(blobData);
+ }
break;
}
diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp
index 50b33a7..1ac8785 100644
--- a/lib/Serialization/Serialization.cpp
+++ b/lib/Serialization/Serialization.cpp
@@ -3168,6 +3168,12 @@
auto contextID = addDeclContextRef(param->getDeclContext());
Type interfaceType = param->getInterfaceType();
+ // Only save the text for normal default arguments, not any of the special
+ // ones.
+ StringRef defaultArgumentText;
+ if (param->getDefaultArgumentKind() == swift::DefaultArgumentKind::Normal)
+ defaultArgumentText = param->getDefaultValueStringRepresentation();
+
unsigned abbrCode = DeclTypeAbbrCodes[ParamLayout::Code];
ParamLayout::emitRecord(Out, ScratchRecord, abbrCode,
addDeclBaseNameRef(param->getArgumentName()),
@@ -3176,7 +3182,8 @@
getRawStableVarDeclSpecifier(param->getSpecifier()),
addTypeRef(interfaceType),
param->isVariadic(),
- getRawStableDefaultArgumentKind(param->getDefaultArgumentKind()));
+ getRawStableDefaultArgumentKind(param->getDefaultArgumentKind()),
+ defaultArgumentText);
if (interfaceType->hasError()) {
param->getDeclContext()->dumpContext();
diff --git a/test/IDE/print_ast_tc_decls.swift b/test/IDE/print_ast_tc_decls.swift
index 2dac63f..6e1b939 100644
--- a/test/IDE/print_ast_tc_decls.swift
+++ b/test/IDE/print_ast_tc_decls.swift
@@ -130,10 +130,10 @@
// PASS_COMMON-NEXT: {{^}} func instanceFunc3(a: Int, b: Double){{$}}
func instanceFuncWithDefaultArg1(a: Int = 0) {}
-// PASS_COMMON-NEXT: {{^}} func instanceFuncWithDefaultArg1(a: Int = default){{$}}
+// PASS_COMMON-NEXT: {{^}} func instanceFuncWithDefaultArg1(a: Int = 0){{$}}
func instanceFuncWithDefaultArg2(a: Int = 0, b: Double = 0) {}
-// PASS_COMMON-NEXT: {{^}} func instanceFuncWithDefaultArg2(a: Int = default, b: Double = default){{$}}
+// PASS_COMMON-NEXT: {{^}} func instanceFuncWithDefaultArg2(a: Int = 0, b: Double = 0){{$}}
func varargInstanceFunc0(v: Int...) {}
// PASS_COMMON-NEXT: {{^}} func varargInstanceFunc0(v: Int...){{$}}
diff --git a/test/IDE/print_type_interface.swift b/test/IDE/print_type_interface.swift
index a43f207..d61f4af 100644
--- a/test/IDE/print_type_interface.swift
+++ b/test/IDE/print_type_interface.swift
@@ -79,7 +79,7 @@
// RUN: %target-swift-ide-test -print-type-interface -usr=_TtGSaSS_ -module-name print_type_interface -source-filename %s | %FileCheck %s -check-prefix=TYPE5
// TYPE5-DAG: public func prefix(_ maxLength: Int) -> ArraySlice<String>
// TYPE5-DAG: public func suffix(_ maxLength: Int) -> ArraySlice<String>
-// TYPE5-DAG: public func split(separator: String, maxSplits: Int = default, omittingEmptySubsequences: Bool = default) -> [ArraySlice<String>]
+// TYPE5-DAG: public func split(separator: String, maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true) -> [ArraySlice<String>]
// TYPE5-DAG: public func formIndex(_ i: inout Int, offsetBy distance: Int)
// TYPE5-DAG: public func distance(from start: Int, to end: Int) -> Int
-// TYPE5-DAG: public func joined(separator: String = default) -> String
+// TYPE5-DAG: public func joined(separator: String = "") -> String
diff --git a/test/Serialization/function-default-args.swift b/test/Serialization/function-default-args.swift
new file mode 100644
index 0000000..a59e4a5
--- /dev/null
+++ b/test/Serialization/function-default-args.swift
@@ -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: )
\ No newline at end of file
diff --git a/test/SourceKit/CursorInfo/cursor_info.swift b/test/SourceKit/CursorInfo/cursor_info.swift
index 0079f77..1fac1a2 100644
--- a/test/SourceKit/CursorInfo/cursor_info.swift
+++ b/test/SourceKit/CursorInfo/cursor_info.swift
@@ -328,8 +328,8 @@
// 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 @@
// 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
+// 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)