Skip to content

Commit 49eb58c

Browse files
committed
---
yaml --- r: 317183 b: refs/heads/master-rebranch c: b5ec228 h: refs/heads/master i: 317181: f06b51f 317179: 0d2e21d 317175: adcdfb8 317167: 325890e 317151: c4d1126 317119: 6c56bd8 317055: 40c1949 316927: b8f4d48
1 parent f3c7878 commit 49eb58c

File tree

11 files changed

+102
-12
lines changed

11 files changed

+102
-12
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1457,4 +1457,4 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14571457
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14581458
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14591459
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1460-
refs/heads/master-rebranch: 4fda7ca8ef3126a43dde2575e3cb2cc3004f34ea
1460+
refs/heads/master-rebranch: b5ec2284273e1a1bbeabd4f0cfa718a12770f121

branches/master-rebranch/include/swift/ABI/MetadataValues.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -880,7 +880,11 @@ using FunctionTypeFlags = TargetFunctionTypeFlags<size_t>;
880880

881881
template <typename int_type>
882882
class TargetParameterTypeFlags {
883-
enum : int_type { ValueOwnershipMask = 0x7F, VariadicMask = 0x80 };
883+
enum : int_type {
884+
ValueOwnershipMask = 0x7F,
885+
VariadicMask = 0x80,
886+
AutoClosureMask = 0x100,
887+
};
884888
int_type Data;
885889

886890
constexpr TargetParameterTypeFlags(int_type Data) : Data(Data) {}
@@ -900,8 +904,15 @@ class TargetParameterTypeFlags {
900904
(isVariadic ? VariadicMask : 0));
901905
}
902906

907+
constexpr TargetParameterTypeFlags<int_type>
908+
withAutoClosure(bool isAutoClosure) const {
909+
return TargetParameterTypeFlags<int_type>(
910+
(Data & ~AutoClosureMask) | (isAutoClosure ? AutoClosureMask : 0));
911+
}
912+
903913
bool isNone() const { return Data == 0; }
904914
bool isVariadic() const { return Data & VariadicMask; }
915+
bool isAutoClosure() const { return Data & AutoClosureMask; }
905916

906917
ValueOwnership getValueOwnership() const {
907918
return (ValueOwnership)(Data & ValueOwnershipMask);

branches/master-rebranch/include/swift/AST/Types.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,6 +1726,12 @@ class ParameterTypeFlags {
17261726
| ParameterFlags(uint8_t(ownership) << OwnershipShift);
17271727
}
17281728

1729+
ParameterTypeFlags withAutoClosure(bool isAutoClosure) const {
1730+
return ParameterTypeFlags(isAutoClosure
1731+
? value | ParameterTypeFlags::AutoClosure
1732+
: value - ParameterTypeFlags::AutoClosure);
1733+
}
1734+
17291735
bool operator ==(const ParameterTypeFlags &other) const {
17301736
return value.toRaw() == other.value.toRaw();
17311737
}

branches/master-rebranch/include/swift/Demangling/TypeDecoder.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ class FunctionParam {
5656
void setType(BuiltType type) { Type = type; }
5757

5858
void setVariadic() { Flags = Flags.withVariadic(true); }
59+
void setAutoClosure() { Flags = Flags.withAutoClosure(true); }
5960
void setValueOwnership(ValueOwnership ownership) {
6061
Flags = Flags.withValueOwnership(ownership);
6162
}
@@ -253,7 +254,6 @@ class TypeDecoder {
253254
if (Node->getNumChildren() < 2)
254255
return BuiltType();
255256

256-
// FIXME: autoclosure is not represented in function metadata
257257
FunctionTypeFlags flags;
258258
if (Node->getKind() == NodeKind::ObjCBlock) {
259259
flags = flags.withConvention(FunctionMetadataConvention::Block);
@@ -565,6 +565,13 @@ class TypeDecoder {
565565
setOwnership(ValueOwnership::Owned);
566566
break;
567567

568+
case NodeKind::AutoClosureType:
569+
case NodeKind::EscapingAutoClosureType: {
570+
param.setAutoClosure();
571+
hasParamFlags = true;
572+
break;
573+
}
574+
568575
default:
569576
break;
570577
}

branches/master-rebranch/lib/IRGen/MetadataRequest.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -947,8 +947,9 @@ namespace {
947947
// flags.
948948
auto getABIParameterFlags = [](ParameterTypeFlags flags) {
949949
return ParameterFlags()
950-
.withValueOwnership(flags.getValueOwnership())
951-
.withVariadic(flags.isVariadic());
950+
.withValueOwnership(flags.getValueOwnership())
951+
.withVariadic(flags.isVariadic())
952+
.withAutoClosure(flags.isAutoClosure());
952953
};
953954

954955
bool hasFlags = false;

branches/master-rebranch/lib/RemoteAST/RemoteAST.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,8 @@ class RemoteASTTypeBuilder {
365365
auto ownership = flags.getValueOwnership();
366366
auto parameterFlags = ParameterTypeFlags()
367367
.withValueOwnership(ownership)
368-
.withVariadic(flags.isVariadic());
368+
.withVariadic(flags.isVariadic())
369+
.withAutoClosure(flags.isAutoClosure());
369370

370371
funcParams.push_back(AnyFunctionType::Param(type, label, parameterFlags));
371372
}

branches/master-rebranch/lib/Sema/CSDiag.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1289,7 +1289,8 @@ diagnoseUnresolvedDotExprTypeRequirementFailure(ConstraintSystem &cs,
12891289
// If we actually resolved the member to use, use it.
12901290
auto loc = cs.getConstraintLocator(UDE, ConstraintLocator::Member);
12911291
auto *member = cs.findResolvedMemberRef(loc);
1292-
if (!member)
1292+
// If the problem is contextual it's diagnosed elsewhere.
1293+
if (!member || !member->getAsGenericContext())
12931294
return false;
12941295

12951296
auto req = member->getAsGenericContext()

branches/master-rebranch/lib/Sema/CSDiagnostics.h

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,23 @@ class RequirementFailure : public FailureDiagnostic {
160160
const ApplyExpr *Apply = nullptr;
161161

162162
public:
163-
RequirementFailure(Expr *expr, ConstraintSystem &cs,
163+
RequirementFailure(ConstraintSystem &cs, Expr *expr, RequirementKind kind,
164164
ConstraintLocator *locator)
165165
: FailureDiagnostic(expr, cs, locator), AffectedDecl(getDeclRef()) {
166+
assert(locator);
166167
assert(AffectedDecl);
168+
169+
auto path = locator->getPath();
170+
assert(!path.empty());
171+
172+
auto &last = path.back();
173+
assert(last.getKind() == ConstraintLocator::TypeParameterRequirement);
174+
assert(static_cast<RequirementKind>(last.getValue2()) == kind);
175+
176+
// It's possible sometimes not to have no base expression.
177+
if (!expr)
178+
return;
179+
167180
auto *anchor = getAnchor();
168181
expr->forEachChildExpr([&](Expr *subExpr) -> Expr * {
169182
auto *AE = dyn_cast<ApplyExpr>(subExpr);
@@ -246,7 +259,7 @@ class MissingConformanceFailure final : public RequirementFailure {
246259
MissingConformanceFailure(Expr *expr, ConstraintSystem &cs,
247260
ConstraintLocator *locator,
248261
std::pair<Type, ProtocolDecl *> conformance)
249-
: RequirementFailure(expr, cs, locator),
262+
: RequirementFailure(cs, expr, RequirementKind::Conformance, locator),
250263
NonConformingType(conformance.first), Protocol(conformance.second) {}
251264

252265
bool diagnoseAsError() override;
@@ -294,7 +307,8 @@ class SameTypeRequirementFailure final : public RequirementFailure {
294307
public:
295308
SameTypeRequirementFailure(Expr *expr, ConstraintSystem &cs, Type lhs,
296309
Type rhs, ConstraintLocator *locator)
297-
: RequirementFailure(expr, cs, locator), LHS(lhs), RHS(rhs) {}
310+
: RequirementFailure(cs, expr, RequirementKind::SameType, locator),
311+
LHS(lhs), RHS(rhs) {}
298312

299313
Type getLHS() const override { return LHS; }
300314
Type getRHS() const override { return RHS; }
@@ -332,7 +346,8 @@ class SuperclassRequirementFailure final : public RequirementFailure {
332346
public:
333347
SuperclassRequirementFailure(Expr *expr, ConstraintSystem &cs, Type lhs,
334348
Type rhs, ConstraintLocator *locator)
335-
: RequirementFailure(expr, cs, locator), LHS(lhs), RHS(rhs) {}
349+
: RequirementFailure(cs, expr, RequirementKind::Superclass, locator),
350+
LHS(lhs), RHS(rhs) {}
336351

337352
Type getLHS() const override { return LHS; }
338353
Type getRHS() const override { return RHS; }
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -typecheck -verify %s
2+
// REQUIRES: objc_interop
3+
4+
import Foundation
5+
6+
protocol A: RawRepresentable {}
7+
8+
extension A {
9+
static func +(lhs: RawValue, rhs: Self) -> Self {
10+
fatalError()
11+
}
12+
}
13+
14+
class Foo<Bar: NSObject> {
15+
var foobar: Bar {
16+
fatalError()
17+
}
18+
19+
lazy var foo: () -> Void = {
20+
// TODO: improve diagnostic message
21+
_ = self.foobar + nil // expected-error {{'Foo<Bar>' requires that 'Bar' inherit from 'NSObject'}}
22+
}
23+
}

branches/master-rebranch/test/IRGen/dynamic_cast_functions.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,17 @@ let k: (Int, inout Int) -> Void = { _,_ in }
5555
let l: (inout Int, Float, inout String) -> Void = { _,_,_ in }
5656
let m: (__shared Int, String, inout Float, Double) -> Void = { _,_,_,_ in }
5757
let n: () -> Int = { 42 }
58+
let o: (@autoclosure () -> Int) -> Void = { (x: @autoclosure () -> Int) -> Void in }
59+
let p: (@autoclosure @escaping () -> Int) -> Void = { (x: @autoclosure @escaping () -> Int) -> Void in }
5860

5961
let i_any: Any = i
6062
let j_any: Any = j
6163
let k_any: Any = k
6264
let l_any: Any = l
6365
let m_any: Any = m
6466
let n_any: Any = n
67+
let o_any: Any = o
68+
let p_any: Any = p
6569

6670
// CHECK: ok
6771
print((i_any as? (Int) -> Void) != nil ? "fail" : "ok")
@@ -125,3 +129,20 @@ print((n_any as? () -> Int) != nil ? "ok" : "fail")
125129
print((n_any as? () -> Void) != nil ? "fail" : "ok")
126130
// CHECK: ok
127131
print((n_any as? (Int) -> Int) != nil ? "fail" : "ok")
132+
133+
// CHECK: ok
134+
print((o_any as? (() -> Int) -> Void) != nil ? "fail" : "ok")
135+
// CHECK: ok
136+
print((o_any as? (inout () -> Int) -> Void) != nil ? "fail" : "ok")
137+
// CHECK: ok
138+
print((o_any as? (@escaping () -> Int) -> Void) != nil ? "fail" : "ok")
139+
// CHECK: ok
140+
print((o_any as? (@autoclosure () -> Int) -> Void) != nil ? "ok" : "fail")
141+
// CHECK: ok
142+
print((o_any as? (@autoclosure @escaping () -> Int) -> Void) != nil ? "fail" : "ok")
143+
// CHECK: ok
144+
print((p_any as? (@escaping () -> Int) -> Void) != nil ? "fail" : "ok")
145+
// CHECK: ok
146+
print((p_any as? (@autoclosure () -> Int) -> Void) != nil ? "fail" : "ok")
147+
// CHECK: ok
148+
print((p_any as? (@autoclosure @escaping () -> Int) -> Void) == nil ? "fail" : "ok")

branches/master-rebranch/test/IRGen/function_metadata.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ func test_arch() {
5353
arch({(x: inout Int, y: Double, z: String, w: Int8) -> () in })
5454

5555
// CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$syyyccMa"
56-
// CHECK: call %swift.type* @swift_getFunctionTypeMetadata1({{i(32|64)}} 67108865
56+
// CHECK: call %swift.type* @swift_getFunctionTypeMetadata1([[WORD]] 67108865
5757
arch({(x: @escaping () -> ()) -> () in })
58+
59+
// CHECK-LABEL: define{{( protected)?}} linkonce_odr hidden swiftcc %swift.metadata_response @"$sySiyXKcMa"
60+
// CHECK: call %swift.type* @swift_getFunctionTypeMetadata([[WORD]] 100663297
61+
arch({(x: @autoclosure () -> Int) -> Void in })
5862
}

0 commit comments

Comments
 (0)