mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/master' into master-llvm-swift5-transition
This commit is contained in:
@@ -37,10 +37,6 @@ function(handle_gyb_source_single dependency_out_var_name)
|
||||
GYB_SINGLE # prefix
|
||||
"${options}" "${single_value_args}" "${multi_value_args}" ${ARGN})
|
||||
|
||||
set(gyb_flags
|
||||
${SWIFT_GYB_FLAGS}
|
||||
${GYB_SINGLE_FLAGS})
|
||||
|
||||
set(gyb_tool "${SWIFT_SOURCE_DIR}/utils/gyb")
|
||||
set(gyb_tool_source "${gyb_tool}" "${gyb_tool}.py")
|
||||
|
||||
@@ -62,11 +58,9 @@ function(handle_gyb_source_single dependency_out_var_name)
|
||||
COMMAND
|
||||
"${CMAKE_COMMAND}" -E make_directory "${dir}"
|
||||
COMMAND
|
||||
"${PYTHON_EXECUTABLE}" "${gyb_tool}" "${gyb_flags}"
|
||||
-o "${GYB_SINGLE_OUTPUT}.tmp" "${GYB_SINGLE_SOURCE}"
|
||||
"${PYTHON_EXECUTABLE}" "${gyb_tool}" ${SWIFT_GYB_FLAGS} ${GYB_SINGLE_FLAGS} -o "${GYB_SINGLE_OUTPUT}.tmp" "${GYB_SINGLE_SOURCE}"
|
||||
COMMAND
|
||||
"${CMAKE_COMMAND}" -E copy_if_different
|
||||
"${GYB_SINGLE_OUTPUT}.tmp" "${GYB_SINGLE_OUTPUT}"
|
||||
"${CMAKE_COMMAND}" -E copy_if_different "${GYB_SINGLE_OUTPUT}.tmp" "${GYB_SINGLE_OUTPUT}"
|
||||
COMMAND
|
||||
"${CMAKE_COMMAND}" -E remove "${GYB_SINGLE_OUTPUT}.tmp"
|
||||
OUTPUT "${GYB_SINGLE_OUTPUT}"
|
||||
|
||||
@@ -91,6 +91,7 @@ KEY(ownership)
|
||||
KEY(superclassUsr)
|
||||
KEY(parentExtensionReqs)
|
||||
KEY(hasDefaultArg)
|
||||
KEY(conformingProtocols)
|
||||
|
||||
KNOWN_TYPE(Optional)
|
||||
KNOWN_TYPE(ImplicitlyUnwrappedOptional)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
set(line_directive "#line" "%(line)d" "\"%(file)s\"")
|
||||
set(SWIFT_GYB_FLAGS
|
||||
--line-directive "'${line_directive}'")
|
||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
|
||||
set(SWIFT_GYB_FLAGS --line-directive "^\"#line %(line)d \\\"%(file)s\\\"^\"")
|
||||
else()
|
||||
set(SWIFT_GYB_FLAGS --line-directive "\'#line" "%(line)d" "\"%(file)s\"\'")
|
||||
endif()
|
||||
|
||||
set(generated_include_sources
|
||||
SyntaxKind.h.gyb
|
||||
|
||||
@@ -1573,6 +1573,9 @@ class ResultPlanner {
|
||||
///
|
||||
/// Valid: reabstraction info, InnerResult, OuterResult.
|
||||
ReabstractDirectToDirect,
|
||||
|
||||
/// Ignore the next direct inner result, since the outer is 'Void'.
|
||||
IgnoreDirectResult,
|
||||
};
|
||||
|
||||
Operation(Kind kind) : TheKind(kind) {}
|
||||
@@ -1717,6 +1720,24 @@ private:
|
||||
SILResultInfo outerResult,
|
||||
SILValue optOuterResultAddr);
|
||||
|
||||
void planIgnoredResult(AbstractionPattern innerOrigType,
|
||||
CanType innerSubstType, PlanData &planData) {
|
||||
if (innerOrigType.isTuple()) {
|
||||
auto innerSubstTuple = cast<TupleType>(innerSubstType);
|
||||
for (unsigned i = 0, n = innerSubstTuple->getNumElements(); i != n; ++i)
|
||||
planIgnoredResult(innerOrigType.getTupleElementType(i),
|
||||
innerSubstTuple.getElementType(i), planData);
|
||||
return;
|
||||
}
|
||||
|
||||
auto innerResult = claimNextInnerResult(planData);
|
||||
if (innerResult.isFormalIndirect() &&
|
||||
SGF.silConv.isSILIndirect(innerResult))
|
||||
(void)addInnerIndirectResultTemporary(planData, innerResult);
|
||||
else
|
||||
addIgnoreDirectResult();
|
||||
}
|
||||
|
||||
/// Claim the next inner result from the plan data.
|
||||
SILResultInfo claimNextInnerResult(PlanData &data) {
|
||||
return claimNext(data.InnerResults);
|
||||
@@ -1866,6 +1887,10 @@ private:
|
||||
op.OuterOrigType = outerOrigType;
|
||||
op.OuterSubstType = outerSubstType;
|
||||
}
|
||||
|
||||
void addIgnoreDirectResult() {
|
||||
(void)addOperation(Operation::IgnoreDirectResult);
|
||||
}
|
||||
};
|
||||
|
||||
} // end anonymous namespace
|
||||
@@ -1876,6 +1901,13 @@ void ResultPlanner::plan(AbstractionPattern innerOrigType,
|
||||
AbstractionPattern outerOrigType,
|
||||
CanType outerSubstType,
|
||||
PlanData &planData) {
|
||||
// Conversion from `() -> T` to `() -> Void` is allowed when
|
||||
// the argument is a closure.
|
||||
if (!innerSubstType->isVoid() && outerSubstType->isVoid()) {
|
||||
planIgnoredResult(innerOrigType, innerSubstType, planData);
|
||||
return;
|
||||
}
|
||||
|
||||
// The substituted types must match up in tuple-ness and arity.
|
||||
assert(
|
||||
isa<TupleType>(innerSubstType) == isa<TupleType>(outerSubstType) ||
|
||||
@@ -2584,6 +2616,10 @@ void ResultPlanner::execute(ArrayRef<SILValue> innerDirectResults,
|
||||
case Operation::InjectOptionalIndirect:
|
||||
SGF.B.createInjectEnumAddr(Loc, op.OuterResultAddr, op.SomeDecl);
|
||||
continue;
|
||||
|
||||
case Operation::IgnoreDirectResult:
|
||||
(void)claimNext(innerDirectResults);
|
||||
continue;
|
||||
}
|
||||
llvm_unreachable("bad operation kind");
|
||||
}
|
||||
|
||||
@@ -1007,14 +1007,32 @@ SolutionCompareResult ConstraintSystem::compareSolutions(
|
||||
// Compare the type variable bindings.
|
||||
auto &tc = cs.getTypeChecker();
|
||||
for (auto &binding : diff.typeBindings) {
|
||||
// If the type variable isn't one for which we should be looking at the
|
||||
// bindings, don't.
|
||||
if (!binding.typeVar->getImpl().prefersSubtypeBinding())
|
||||
continue;
|
||||
|
||||
auto type1 = binding.bindings[idx1];
|
||||
auto type2 = binding.bindings[idx2];
|
||||
|
||||
auto &impl = binding.typeVar->getImpl();
|
||||
|
||||
if (auto *locator = impl.getLocator()) {
|
||||
auto path = locator->getPath();
|
||||
if (!path.empty() &&
|
||||
path.back().getKind() == ConstraintLocator::ClosureResult) {
|
||||
// Since we support `() -> T` to `() -> Void` and
|
||||
// `() -> Never` to `() -> T` conversions, it's always
|
||||
// preferable to pick `T` rather than `Never` with
|
||||
// all else being equal.
|
||||
if (type2->isUninhabited())
|
||||
++score1;
|
||||
|
||||
if (type1->isUninhabited())
|
||||
++score2;
|
||||
}
|
||||
}
|
||||
|
||||
// If the type variable isn't one for which we should be looking at the
|
||||
// bindings, don't.
|
||||
if (!impl.prefersSubtypeBinding())
|
||||
continue;
|
||||
|
||||
// If the types are equivalent, there's nothing more to do.
|
||||
if (type1->isEqual(type2))
|
||||
continue;
|
||||
|
||||
@@ -1212,10 +1212,8 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
|
||||
return result;
|
||||
|
||||
// Result type can be covariant (or equal).
|
||||
return matchTypes(func1->getResult(), func2->getResult(), subKind,
|
||||
subflags,
|
||||
locator.withPathElement(
|
||||
ConstraintLocator::FunctionResult));
|
||||
return matchTypes(func1->getResult(), func2->getResult(), subKind, subflags,
|
||||
locator.withPathElement(ConstraintLocator::FunctionResult));
|
||||
}
|
||||
|
||||
ConstraintSystem::TypeMatchResult
|
||||
@@ -1501,6 +1499,8 @@ ConstraintSystem::TypeMatchResult
|
||||
ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
|
||||
TypeMatchOptions flags,
|
||||
ConstraintLocatorBuilder locator) {
|
||||
auto origType1 = type1;
|
||||
|
||||
bool isArgumentTupleConversion
|
||||
= kind == ConstraintKind::ArgumentTupleConversion ||
|
||||
kind == ConstraintKind::OperatorArgumentTupleConversion;
|
||||
@@ -2243,7 +2243,32 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
|
||||
// Allow '() -> T' to '() -> ()' and '() -> Never' to '() -> T' for closure
|
||||
// literals.
|
||||
if (auto elt = locator.last()) {
|
||||
if (elt->getKind() == ConstraintLocator::ClosureResult) {
|
||||
auto isClosureResult = [&]() {
|
||||
if (elt->getKind() == ConstraintLocator::ClosureResult)
|
||||
return true;
|
||||
|
||||
// If constraint is matching function results where
|
||||
// left-hand side is a 'closure result' we need to allow
|
||||
// certain implicit conversions.
|
||||
if (elt->getKind() != ConstraintLocator::FunctionResult)
|
||||
return false;
|
||||
|
||||
if (auto *typeVar = origType1->getAs<TypeVariableType>()) {
|
||||
auto *locator = typeVar->getImpl().getLocator();
|
||||
if (!locator)
|
||||
return false;
|
||||
|
||||
auto path = locator->getPath();
|
||||
if (path.empty())
|
||||
return false;
|
||||
|
||||
return path.back().getKind() == ConstraintLocator::ClosureResult;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
|
||||
if (isClosureResult()) {
|
||||
if (concrete && kind >= ConstraintKind::Subtype &&
|
||||
(type1->isUninhabited() || type2->isVoid())) {
|
||||
increaseScore(SK_FunctionConversion);
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
set(line_directive "#line" "%(line)d" "\"%(file)s\"")
|
||||
set(SWIFT_GYB_FLAGS
|
||||
--line-directive "'${line_directive}'")
|
||||
if(CMAKE_HOST_SYSTEM_NAME STREQUAL Windows)
|
||||
set(SWIFT_GYB_FLAGS --line-directive "^\"#line %(line)d \\\"%(file)s\\\"^\"")
|
||||
else()
|
||||
set(SWIFT_GYB_FLAGS --line-directive "\'#line" "%(line)d" "\"%(file)s\"\'")
|
||||
endif()
|
||||
|
||||
add_swift_library(swiftSyntax STATIC
|
||||
SyntaxNodes.cpp.gyb
|
||||
|
||||
@@ -630,7 +630,6 @@ func rdar33429010_2() {
|
||||
let iter = I_33429010()
|
||||
var acc: Int = 0 // expected-warning {{}}
|
||||
let _: Int = AnySequence { iter }.rdar33429010(into: acc, { $0 + $1 })
|
||||
// expected-warning@-1 {{result of operator '+' is unused}}
|
||||
let _: Int = AnySequence { iter }.rdar33429010(into: acc, { $0.rdar33429010_incr($1) })
|
||||
}
|
||||
|
||||
@@ -652,3 +651,38 @@ func rdar36054961() {
|
||||
str.replaceSubrange(range, with: str[range].reversed())
|
||||
}])
|
||||
}
|
||||
|
||||
protocol P_37790062 {
|
||||
associatedtype T
|
||||
var elt: T { get }
|
||||
}
|
||||
|
||||
func rdar37790062() {
|
||||
struct S<T> {
|
||||
init(_ a: () -> T, _ b: () -> T) {}
|
||||
}
|
||||
|
||||
class C1 : P_37790062 {
|
||||
typealias T = Int
|
||||
var elt: T { return 42 }
|
||||
}
|
||||
|
||||
class C2 : P_37790062 {
|
||||
typealias T = (String, Int, Void)
|
||||
var elt: T { return ("question", 42, ()) }
|
||||
}
|
||||
|
||||
func foo() -> Int { return 42 }
|
||||
func bar() -> Void {}
|
||||
func baz() -> (String, Int) { return ("question", 42) }
|
||||
func bzz<T>(_ a: T) -> T { return a }
|
||||
func faz<T: P_37790062>(_ a: T) -> T.T { return a.elt }
|
||||
|
||||
_ = S({ foo() }, { bar() }) // Ok, should infer T to be 'Void'
|
||||
_ = S({ baz() }, { bar() }) // Ok, should infer T to be 'Void'
|
||||
_ = S({ bzz(("question", 42)) }, { bar() }) // Ok
|
||||
_ = S({ bzz(String.self) }, { bar() }) // Ok
|
||||
_ = S({ bzz(((), (()))) }, { bar() }) // Ok
|
||||
_ = S({ bzz(C1()) }, { bar() }) // Ok
|
||||
_ = S({ faz(C2()) }, { bar() }) // Ok
|
||||
}
|
||||
|
||||
46
test/Constraints/rdar37790062.swift
Normal file
46
test/Constraints/rdar37790062.swift
Normal file
@@ -0,0 +1,46 @@
|
||||
// RUN: %target-typecheck-verify-swift
|
||||
|
||||
protocol A {
|
||||
associatedtype V
|
||||
associatedtype E: Error
|
||||
|
||||
init(value: V)
|
||||
init(error: E)
|
||||
|
||||
func foo<U>(value: (V) -> U, error: (E) -> U) -> U
|
||||
}
|
||||
|
||||
enum R<T, E: Error> : A {
|
||||
case foo(T)
|
||||
case bar(E)
|
||||
|
||||
init(value: T) { self = .foo(value) }
|
||||
init(error: E) { self = .bar(error) }
|
||||
|
||||
func foo<R>(value: (T) -> R, error: (E) -> R) -> R {
|
||||
fatalError()
|
||||
}
|
||||
}
|
||||
|
||||
protocol P {
|
||||
associatedtype V
|
||||
|
||||
@discardableResult
|
||||
func baz(callback: @escaping (V) -> Void) -> Self
|
||||
}
|
||||
|
||||
class C<V> : P {
|
||||
func baz(callback: @escaping (V) -> Void) -> Self { return self }
|
||||
}
|
||||
class D<T, E: Error> : C<R<T, E>> {
|
||||
init(fn: (_ ret: @escaping (V) -> Void) -> Void) {}
|
||||
}
|
||||
|
||||
extension A where V: P, V.V: A, E == V.V.E {
|
||||
func bar() -> D<V.V.V, V.V.E> {
|
||||
return D { complete in
|
||||
foo(value: { promise in promise.baz { result in } },
|
||||
error: { complete(R(error: $0)) })
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,13 +24,15 @@ public func test(_ dict: NSDictionary) {
|
||||
// popq %rbp ;<== Blocks the handshake from objc_autoreleaseReturnValue
|
||||
// jmp 0x01ec20 ; symbol stub for: objc_retainAutoreleasedReturnValue
|
||||
|
||||
// CHECK-LABEL: define {{.*}}swiftcc void @"$S34objc_retainAutoreleasedReturnValue4testyySo12NSDictionaryCFyADXEfU_"(%TSo12NSDictionaryC*)
|
||||
// CHECK-LABEL: define {{.*}}swiftcc %TSo12NSEnumeratorC* @"$S34objc_retainAutoreleasedReturnValue4testyySo12NSDictionaryCFSo12NSEnumeratorCADXEfU_"(%TSo12NSDictionaryC*)
|
||||
// CHECK: entry:
|
||||
// CHECK: call {{.*}}@objc_msgSend
|
||||
// CHECK: notail call i8* @objc_retainAutoreleasedReturnValue
|
||||
// CHECK: ret void
|
||||
// CHECK: ret %TSo12NSEnumeratorC*
|
||||
|
||||
// OPT-LABEL: define {{.*}}swiftcc void @"$S34objc_retainAutoreleasedReturnValue4testyySo12NSDictionaryCFyADXEfU_"(%TSo12NSDictionaryC*)
|
||||
// CHECK-LABEL: define {{.*}}swiftcc void @"$SSo12NSDictionaryCSo12NSEnumeratorCIgxo_ABIegx_TR"(%TSo12NSDictionaryC*, i8*, %swift.opaque*)
|
||||
|
||||
// OPT-LABEL: define {{.*}}swiftcc void @"$S34objc_retainAutoreleasedReturnValue10useClosureyySo12NSDictionaryC_yADXEtF06$SSo12h44CSo12NSEnumeratorCIgxo_ABIegx_TR049$S34objc_bcD42Value4testyySo12a6CFSo12B8CADXEfU_Tf3npf_nTf1nc_nTf4g_n"(%TSo12NSDictionaryC*)
|
||||
// OPT: entry:
|
||||
// OPT: call {{.*}}@objc_msgSend
|
||||
// OPT: notail call i8* @objc_retainAutoreleasedReturnValue
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
public struct S1 {
|
||||
public protocol P1 {}
|
||||
public protocol P2 {}
|
||||
public struct S1: P1 {
|
||||
public static func foo1() {}
|
||||
mutating public func foo2() {}
|
||||
internal func foo3() {}
|
||||
@@ -7,6 +9,8 @@ public struct S1 {
|
||||
public func foo6() -> Void {}
|
||||
}
|
||||
|
||||
extension S1: P2 {}
|
||||
|
||||
public class C0<T1, T2, T3> {}
|
||||
|
||||
public class C1: C0<S1, S1, S1> {
|
||||
@@ -24,4 +28,8 @@ public extension C0 {
|
||||
}
|
||||
|
||||
public func foo1(_ a: Int = 1, b: S1) {}
|
||||
public func foo2(_ a: Int = #line, b: S1) {}
|
||||
public func foo2(_ a: Int = #line, b: S1) {}
|
||||
|
||||
public enum Number: Int {
|
||||
case one
|
||||
}
|
||||
@@ -3,6 +3,24 @@
|
||||
"name": "TopLevel",
|
||||
"printedName": "TopLevel",
|
||||
"children": [
|
||||
{
|
||||
"kind": "TypeDecl",
|
||||
"name": "P1",
|
||||
"printedName": "P1",
|
||||
"declKind": "Protocol",
|
||||
"usr": "s:4cake2P1P",
|
||||
"location": "",
|
||||
"moduleName": "cake"
|
||||
},
|
||||
{
|
||||
"kind": "TypeDecl",
|
||||
"name": "P2",
|
||||
"printedName": "P2",
|
||||
"declKind": "Protocol",
|
||||
"usr": "s:4cake2P2P",
|
||||
"location": "",
|
||||
"moduleName": "cake"
|
||||
},
|
||||
{
|
||||
"kind": "TypeDecl",
|
||||
"name": "C0",
|
||||
@@ -93,6 +111,10 @@
|
||||
"usr": "s:4cake2S1V",
|
||||
"location": "",
|
||||
"moduleName": "cake",
|
||||
"conformingProtocols": [
|
||||
"P1",
|
||||
"P2"
|
||||
],
|
||||
"children": [
|
||||
{
|
||||
"kind": "Function",
|
||||
@@ -389,6 +411,165 @@
|
||||
"printedName": "S1"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "TypeDecl",
|
||||
"name": "Number",
|
||||
"printedName": "Number",
|
||||
"declKind": "Enum",
|
||||
"usr": "s:4cake6NumberO",
|
||||
"location": "",
|
||||
"moduleName": "cake",
|
||||
"conformingProtocols": [
|
||||
"Equatable",
|
||||
"Hashable",
|
||||
"RawRepresentable"
|
||||
],
|
||||
"children": [
|
||||
{
|
||||
"kind": "Var",
|
||||
"name": "one",
|
||||
"printedName": "one",
|
||||
"declKind": "EnumElement",
|
||||
"usr": "s:4cake6NumberO3oneyA2CmF",
|
||||
"location": "",
|
||||
"moduleName": "cake",
|
||||
"children": [
|
||||
{
|
||||
"kind": "TypeFunc",
|
||||
"name": "Function",
|
||||
"printedName": "(Number.Type) -> Number",
|
||||
"children": [
|
||||
{
|
||||
"kind": "TypeNominal",
|
||||
"name": "Number",
|
||||
"printedName": "Number"
|
||||
},
|
||||
{
|
||||
"kind": "TypeNominal",
|
||||
"name": "Metatype",
|
||||
"printedName": "Number.Type",
|
||||
"children": [
|
||||
{
|
||||
"kind": "TypeNominal",
|
||||
"name": "Number",
|
||||
"printedName": "Number"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "TypeAlias",
|
||||
"name": "RawValue",
|
||||
"printedName": "RawValue",
|
||||
"declKind": "TypeAlias",
|
||||
"usr": "s:4cake6NumberO8RawValuea",
|
||||
"location": "",
|
||||
"moduleName": "cake",
|
||||
"children": [
|
||||
{
|
||||
"kind": "TypeNominal",
|
||||
"name": "Int",
|
||||
"printedName": "Int"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "Var",
|
||||
"name": "hashValue",
|
||||
"printedName": "hashValue",
|
||||
"declKind": "Var",
|
||||
"usr": "s:4cake6NumberO9hashValueSivp",
|
||||
"location": "",
|
||||
"moduleName": "cake",
|
||||
"children": [
|
||||
{
|
||||
"kind": "TypeNominal",
|
||||
"name": "Int",
|
||||
"printedName": "Int"
|
||||
},
|
||||
{
|
||||
"kind": "Getter",
|
||||
"name": "_",
|
||||
"printedName": "_()",
|
||||
"declKind": "Accessor",
|
||||
"usr": "s:4cake6NumberO9hashValueSivg",
|
||||
"location": "",
|
||||
"moduleName": "cake",
|
||||
"children": [
|
||||
{
|
||||
"kind": "TypeNominal",
|
||||
"name": "Int",
|
||||
"printedName": "Int"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "Constructor",
|
||||
"name": "init",
|
||||
"printedName": "init(rawValue:)",
|
||||
"declKind": "Constructor",
|
||||
"usr": "s:4cake6NumberO8rawValueACSgSi_tcfc",
|
||||
"location": "",
|
||||
"moduleName": "cake",
|
||||
"children": [
|
||||
{
|
||||
"kind": "TypeNominal",
|
||||
"name": "Optional",
|
||||
"printedName": "Number?",
|
||||
"children": [
|
||||
{
|
||||
"kind": "TypeNominal",
|
||||
"name": "Number",
|
||||
"printedName": "Number"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "TypeNominal",
|
||||
"name": "Int",
|
||||
"printedName": "Int"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"kind": "Var",
|
||||
"name": "rawValue",
|
||||
"printedName": "rawValue",
|
||||
"declKind": "Var",
|
||||
"usr": "s:4cake6NumberO8rawValueSivp",
|
||||
"location": "",
|
||||
"moduleName": "cake",
|
||||
"children": [
|
||||
{
|
||||
"kind": "TypeNominal",
|
||||
"name": "Int",
|
||||
"printedName": "Int"
|
||||
},
|
||||
{
|
||||
"kind": "Getter",
|
||||
"name": "_",
|
||||
"printedName": "_()",
|
||||
"declKind": "Accessor",
|
||||
"usr": "s:4cake6NumberO8rawValueSivg",
|
||||
"location": "",
|
||||
"moduleName": "cake",
|
||||
"children": [
|
||||
{
|
||||
"kind": "TypeNominal",
|
||||
"name": "Int",
|
||||
"printedName": "Int"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -259,7 +259,6 @@ func rdar19179412() -> (Int) -> Int {
|
||||
func takesVoidFunc(_ f: () -> ()) {}
|
||||
var i: Int = 1
|
||||
|
||||
// expected-warning @+1 {{expression of type 'Int' is unused}}
|
||||
takesVoidFunc({i})
|
||||
// expected-warning @+1 {{expression of type 'Int' is unused}}
|
||||
var f1: () -> () = {i}
|
||||
|
||||
@@ -331,6 +331,7 @@ struct SDKNodeInitInfo {
|
||||
Ownership Ownership = Ownership::Strong;
|
||||
std::vector<SDKDeclAttrKind> DeclAttrs;
|
||||
std::vector<TypeAttrKind> TypeAttrs;
|
||||
std::vector<StringRef> ConformingProtocols;
|
||||
StringRef SuperclassUsr;
|
||||
ParentExtensionInfo *ExtInfo = nullptr;
|
||||
TypeInitInfo TypeInfo;
|
||||
@@ -774,12 +775,14 @@ SDKNodeDecl *SDKNodeType::getClosestParentDecl() const {
|
||||
|
||||
class SDKNodeTypeDecl : public SDKNodeDecl {
|
||||
StringRef SuperclassUsr;
|
||||
std::vector<StringRef> ConformingProtocols;
|
||||
public:
|
||||
SDKNodeTypeDecl(SDKNodeInitInfo Info) : SDKNodeDecl(Info, SDKNodeKind::TypeDecl),
|
||||
SuperclassUsr(Info.SuperclassUsr) {}
|
||||
SuperclassUsr(Info.SuperclassUsr),
|
||||
ConformingProtocols(Info.ConformingProtocols){}
|
||||
static bool classof(const SDKNode *N);
|
||||
StringRef getSuperClassUsr() const { return SuperclassUsr; }
|
||||
|
||||
ArrayRef<StringRef> getAllProtocols() const { return ConformingProtocols; }
|
||||
Optional<SDKNodeTypeDecl*> getSuperclass() const {
|
||||
if (SuperclassUsr.empty())
|
||||
return None;
|
||||
@@ -946,6 +949,13 @@ SDKNode* SDKNode::constructSDKNode(SDKContext &Ctx,
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KeyKind::KK_conformingProtocols: {
|
||||
assert(Info.ConformingProtocols.empty());
|
||||
for (auto &Name : *cast<llvm::yaml::SequenceNode>(Pair.getValue())) {
|
||||
Info.ConformingProtocols.push_back(GetScalarString(&Name));
|
||||
}
|
||||
break;
|
||||
}
|
||||
case KeyKind::KK_printedName:
|
||||
Info.PrintedName = GetScalarString(Pair.getValue());
|
||||
break;
|
||||
@@ -1272,6 +1282,13 @@ SDKNodeInitInfo::SDKNodeInitInfo(SDKContext &Ctx, ValueDecl *VD) : Ctx(Ctx),
|
||||
ExtInfo->Requirements.emplace_back(Ctx.buffer(OS.str()));
|
||||
}
|
||||
}
|
||||
|
||||
// Get all protocol names this type decl conforms to.
|
||||
if (auto *NTD = dyn_cast<NominalTypeDecl>(VD)) {
|
||||
for (auto *P: NTD->getAllProtocols()) {
|
||||
ConformingProtocols.push_back(P->getName().str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SDKNode *SDKNodeInitInfo::createSDKNode(SDKNodeKind Kind) {
|
||||
@@ -1647,6 +1664,12 @@ namespace swift {
|
||||
out.mapRequired(getKeyContent(Ctx, KeyKind::KK_superclassUsr).data(),
|
||||
Super);
|
||||
}
|
||||
auto Pros = TD->getAllProtocols();
|
||||
if (!Pros.empty()) {
|
||||
out.mapRequired(getKeyContent(Ctx,
|
||||
KeyKind::KK_conformingProtocols).data(),
|
||||
Pros);
|
||||
}
|
||||
}
|
||||
if (D->isFromExtension()) {
|
||||
// Even if we don't have any requirements on this parent extension,
|
||||
|
||||
@@ -6,6 +6,7 @@ from __future__ import print_function
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
try:
|
||||
from cStringIO import StringIO
|
||||
except ImportError:
|
||||
@@ -572,6 +573,8 @@ class ExecutionContext(object):
|
||||
# We can only insert the line directive at a line break
|
||||
if len(self.result_text) == 0 \
|
||||
or self.result_text[-1].endswith('\n'):
|
||||
if sys.platform == 'win32':
|
||||
file = file.replace('\\', '/')
|
||||
substitutions = {'file': file, 'line': line + 1}
|
||||
format_str = self.line_directive + '\n'
|
||||
self.result_text.append(format_str % substitutions)
|
||||
|
||||
Reference in New Issue
Block a user