Skip to content

Commit 9c6809f

Browse files
authored
---
yaml --- r: 344159 b: refs/heads/master-rebranch c: b11e8ac h: refs/heads/master i: 344157: c517728 344155: 631ce30 344151: 838adbe 344143: 048b73f 344127: cc97011
1 parent 34a9d4c commit 9c6809f

31 files changed

+326
-299
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1455,7 +1455,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-02-a: ddd2b2976aa9bfde5f20fe37f6bd2
14551455
refs/tags/swift-DEVELOPMENT-SNAPSHOT-2019-08-03-a: 171cc166f2abeb5ca2a4003700a8a78a108bd300
14561456
refs/heads/benlangmuir-patch-1: baaebaf39d52f3bf36710d4fe40cf212e996b212
14571457
refs/heads/i-do-redeclare: 8c4e6d5de5c1e3f0a2cedccf319df713ea22c48e
1458-
refs/heads/master-rebranch: 8f346a0ca8b714de8103b9b05d6020e4645cc0bf
1458+
refs/heads/master-rebranch: b11e8ac95eb50831aafbf3ce4f1ada8370dc1c26
14591459
refs/heads/rdar-53901732: 9bd06af3284e18a109cdbf9aa59d833b24eeca7b
14601460
refs/heads/revert-26776-subst-always-returns-a-type: 1b8e18fdd391903a348970a4c848995d4cdd789c
14611461
refs/heads/tensorflow-merge: 8b854f62f80d4476cb383d43c4aac2001dde3cec

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,8 @@ class ASTContext final {
460460
/// Retrieve the declaration of ObjectiveC.ObjCBool.
461461
StructDecl *getObjCBoolDecl() const;
462462

463+
/// Retrieve the declaration of Foundation.NSCopying.
464+
ProtocolDecl *getNSCopyingDecl() const;
463465
/// Retrieve the declaration of Foundation.NSError.
464466
ClassDecl *getNSErrorDecl() const;
465467
/// Retrieve the declaration of Foundation.NSNumber.

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

Lines changed: 68 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@
1414
#define SWIFT_AST_CAPTURE_INFO_H
1515

1616
#include "swift/Basic/LLVM.h"
17+
#include "swift/Basic/OptionSet.h"
1718
#include "swift/Basic/SourceLoc.h"
1819
#include "swift/AST/TypeAlignments.h"
1920
#include "llvm/ADT/ArrayRef.h"
2021
#include "llvm/ADT/PointerIntPair.h"
2122
#include "llvm/ADT/PointerUnion.h"
23+
#include "llvm/Support/TrailingObjects.h"
2224
#include <vector>
2325

2426
namespace swift {
@@ -114,31 +116,63 @@ class DynamicSelfType;
114116

115117
/// Stores information about captured variables.
116118
class CaptureInfo {
117-
const CapturedValue *Captures;
118-
DynamicSelfType *DynamicSelf;
119-
OpaqueValueExpr *OpaqueValue;
120-
unsigned Count = 0;
121-
bool GenericParamCaptures : 1;
122-
bool Computed : 1;
119+
class CaptureInfoStorage final
120+
: public llvm::TrailingObjects<CaptureInfoStorage, CapturedValue> {
121+
122+
DynamicSelfType *DynamicSelf;
123+
OpaqueValueExpr *OpaqueValue;
124+
unsigned Count;
125+
public:
126+
explicit CaptureInfoStorage(unsigned count, DynamicSelfType *dynamicSelf,
127+
OpaqueValueExpr *opaqueValue)
128+
: DynamicSelf(dynamicSelf), OpaqueValue(opaqueValue), Count(count) { }
129+
130+
ArrayRef<CapturedValue> getCaptures() const {
131+
return llvm::makeArrayRef(this->getTrailingObjects<CapturedValue>(),
132+
Count);
133+
}
134+
135+
DynamicSelfType *getDynamicSelfType() const {
136+
return DynamicSelf;
137+
}
138+
139+
OpaqueValueExpr *getOpaqueValue() const {
140+
return OpaqueValue;
141+
}
142+
};
143+
144+
enum class Flags : unsigned {
145+
HasGenericParamCaptures = 1 << 0
146+
};
147+
148+
llvm::PointerIntPair<const CaptureInfoStorage *, 2, OptionSet<Flags>>
149+
StorageAndFlags;
123150

124151
public:
125-
CaptureInfo()
126-
: Captures(nullptr), DynamicSelf(nullptr), OpaqueValue(nullptr), Count(0),
127-
GenericParamCaptures(0), Computed(0) { }
152+
/// The default-constructed CaptureInfo is "not yet computed".
153+
CaptureInfo() = default;
154+
CaptureInfo(ASTContext &ctx, ArrayRef<CapturedValue> captures,
155+
DynamicSelfType *dynamicSelf, OpaqueValueExpr *opaqueValue,
156+
bool genericParamCaptures);
128157

129-
bool hasBeenComputed() const { return Computed; }
158+
/// A CaptureInfo representing no captures at all.
159+
static CaptureInfo empty();
160+
161+
bool hasBeenComputed() const {
162+
return StorageAndFlags.getPointer();
163+
}
130164

131165
bool isTrivial() const {
132-
return Count == 0 && !GenericParamCaptures && !DynamicSelf && !OpaqueValue;
166+
return getCaptures().empty() && !hasGenericParamCaptures() &&
167+
!hasDynamicSelfCapture() && !hasOpaqueValueCapture();
133168
}
134169

135170
ArrayRef<CapturedValue> getCaptures() const {
136-
return llvm::makeArrayRef(Captures, Count);
137-
}
138-
void setCaptures(ArrayRef<CapturedValue> C) {
139-
Captures = C.data();
140-
Computed = true;
141-
Count = C.size();
171+
// FIXME: Ideally, everywhere that synthesizes a function should include
172+
// its capture info.
173+
if (!hasBeenComputed())
174+
return None;
175+
return StorageAndFlags.getPointer()->getCaptures();
142176
}
143177

144178
/// Return a filtered list of the captures for this function,
@@ -152,37 +186,37 @@ class CaptureInfo {
152186

153187
/// \returns true if the function captures any generic type parameters.
154188
bool hasGenericParamCaptures() const {
155-
return GenericParamCaptures;
156-
}
157-
158-
void setGenericParamCaptures(bool genericParamCaptures) {
159-
GenericParamCaptures = genericParamCaptures;
189+
// FIXME: Ideally, everywhere that synthesizes a function should include
190+
// its capture info.
191+
if (!hasBeenComputed())
192+
return false;
193+
return StorageAndFlags.getInt().contains(Flags::HasGenericParamCaptures);
160194
}
161195

162196
/// \returns true if the function captures the dynamic Self type.
163197
bool hasDynamicSelfCapture() const {
164-
return DynamicSelf != nullptr;
198+
return getDynamicSelfType() != nullptr;
165199
}
166200

167201
/// \returns the captured dynamic Self type, if any.
168202
DynamicSelfType *getDynamicSelfType() const {
169-
return DynamicSelf;
170-
}
171-
172-
void setDynamicSelfType(DynamicSelfType *dynamicSelf) {
173-
DynamicSelf = dynamicSelf;
203+
// FIXME: Ideally, everywhere that synthesizes a function should include
204+
// its capture info.
205+
if (!hasBeenComputed())
206+
return nullptr;
207+
return StorageAndFlags.getPointer()->getDynamicSelfType();
174208
}
175209

176210
bool hasOpaqueValueCapture() const {
177-
return OpaqueValue != nullptr;
211+
return getOpaqueValue() != nullptr;
178212
}
179213

180214
OpaqueValueExpr *getOpaqueValue() const {
181-
return OpaqueValue;
182-
}
183-
184-
void setOpaqueValue(OpaqueValueExpr *OVE) {
185-
OpaqueValue = OVE;
215+
// FIXME: Ideally, everywhere that synthesizes a function should include
216+
// its capture info.
217+
if (!hasBeenComputed())
218+
return nullptr;
219+
return StorageAndFlags.getPointer()->getOpaqueValue();
186220
}
187221

188222
void dump() const;

branches/master-rebranch/include/swift/AST/DiagnosticsSema.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,12 @@ ERROR(cannot_convert_partial_argument_value_protocol,none,
396396
ERROR(cannot_convert_argument_value_nil,none,
397397
"'nil' is not compatible with expected argument type %0", (Type))
398398

399+
ERROR(cannot_convert_condition_value,none,
400+
"cannot convert value of type %0 to expected condition type %1",
401+
(Type, Type))
402+
ERROR(cannot_convert_condition_value_nil,none,
403+
"'nil' is not compatible with expected condition type %0", (Type))
404+
399405
ERROR(cannot_yield_rvalue_by_reference_same_type,none,
400406
"cannot yield immutable value of type %0 as an inout yield", (Type))
401407
ERROR(cannot_yield_rvalue_by_reference,none,

branches/master-rebranch/include/swift/AST/KnownFoundationEntities.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
#endif
2121

2222
FOUNDATION_ENTITY(NSArray)
23-
FOUNDATION_ENTITY(NSCopying)
2423
FOUNDATION_ENTITY(NSDictionary)
2524
FOUNDATION_ENTITY(NSError)
2625
FOUNDATION_ENTITY(NSErrorPointer)

branches/master-rebranch/include/swift/AST/KnownProtocols.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
//===----------------------------------------------------------------------===//
1212
//
1313
// This file defines macros used for macro-metaprogramming with compiler-known
14-
// protocols.
14+
// protocols. Note that this mechanism does not look through an overlay into its
15+
// underlying module, so it typically cannot find Objective-C protocols.
1516
//
1617
//===----------------------------------------------------------------------===//
1718

branches/master-rebranch/lib/AST/ASTContext.cpp

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -100,9 +100,10 @@ using AssociativityCacheType =
100100
Associativity>;
101101

102102
#define FOR_KNOWN_FOUNDATION_TYPES(MACRO) \
103-
MACRO(NSError) \
104-
MACRO(NSNumber) \
105-
MACRO(NSValue)
103+
MACRO(NSCopying, ProtocolDecl) \
104+
MACRO(NSError, ClassDecl) \
105+
MACRO(NSNumber, ClassDecl) \
106+
MACRO(NSValue, ClassDecl)
106107

107108
struct OverrideSignatureKey {
108109
GenericSignature *baseMethodSig;
@@ -219,9 +220,9 @@ struct ASTContext::Implementation {
219220
/// The declaration of ObjectiveC.ObjCBool.
220221
StructDecl *ObjCBoolDecl = nullptr;
221222

222-
#define CACHE_FOUNDATION_DECL(NAME) \
223+
#define CACHE_FOUNDATION_DECL(NAME, DECLTYPE) \
223224
/** The declaration of Foundation.NAME. */ \
224-
ClassDecl *NAME##Decl = nullptr;
225+
DECLTYPE *NAME##Decl = nullptr;
225226
FOR_KNOWN_FOUNDATION_TYPES(CACHE_FOUNDATION_DECL)
226227
#undef CACHE_FOUNDATION_DECL
227228

@@ -850,18 +851,18 @@ StructDecl *ASTContext::getObjCBoolDecl() const {
850851
return getImpl().ObjCBoolDecl;
851852
}
852853

853-
#define GET_FOUNDATION_DECL(NAME) \
854-
ClassDecl *ASTContext::get##NAME##Decl() const { \
854+
#define GET_FOUNDATION_DECL(NAME, DECLTYPE) \
855+
DECLTYPE *ASTContext::get##NAME##Decl() const { \
855856
if (!getImpl().NAME##Decl) { \
856857
if (ModuleDecl *M = getLoadedModule(Id_Foundation)) { \
857858
/* Note: lookupQualified() will search both the Foundation module \
858859
* and the Clang Foundation module it imports. */ \
859860
SmallVector<ValueDecl *, 1> decls; \
860861
M->lookupQualified(M, getIdentifier(#NAME), NL_OnlyTypes, decls); \
861-
if (decls.size() == 1 && isa<ClassDecl>(decls[0])) { \
862-
auto classDecl = cast<ClassDecl>(decls[0]); \
863-
if (classDecl->getGenericParams() == nullptr) { \
864-
getImpl().NAME##Decl = classDecl; \
862+
if (decls.size() == 1 && isa<DECLTYPE>(decls[0])) { \
863+
auto decl = cast<DECLTYPE>(decls[0]); \
864+
if (isa<ProtocolDecl>(decl) || decl->getGenericParams() == nullptr) { \
865+
getImpl().NAME##Decl = decl; \
865866
} \
866867
} \
867868
} \

branches/master-rebranch/lib/AST/CaptureInfo.cpp

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,50 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "swift/AST/CaptureInfo.h"
14+
#include "swift/AST/ASTContext.h"
1415
#include "swift/AST/Decl.h"
1516
#include "llvm/Support/raw_ostream.h"
1617

1718
using namespace swift;
1819

20+
CaptureInfo::CaptureInfo(ASTContext &ctx, ArrayRef<CapturedValue> captures,
21+
DynamicSelfType *dynamicSelf,
22+
OpaqueValueExpr *opaqueValue,
23+
bool genericParamCaptures) {
24+
static_assert(IsTriviallyDestructible<CapturedValue>::value,
25+
"Capture info is alloc'd on the ASTContext and not destroyed");
26+
static_assert(IsTriviallyDestructible<CaptureInfo::CaptureInfoStorage>::value,
27+
"Capture info is alloc'd on the ASTContext and not destroyed");
28+
29+
OptionSet<Flags> flags;
30+
if (genericParamCaptures)
31+
flags |= Flags::HasGenericParamCaptures;
32+
33+
if (captures.empty() && !dynamicSelf && !opaqueValue) {
34+
*this = CaptureInfo::empty();
35+
StorageAndFlags.setInt(flags);
36+
return;
37+
}
38+
39+
size_t storageToAlloc =
40+
CaptureInfoStorage::totalSizeToAlloc<CapturedValue>(captures.size());
41+
void *storageBuf = ctx.Allocate(storageToAlloc, alignof(CaptureInfoStorage));
42+
auto *storage = new (storageBuf) CaptureInfoStorage(captures.size(),
43+
dynamicSelf,
44+
opaqueValue);
45+
StorageAndFlags.setPointerAndInt(storage, flags);
46+
std::uninitialized_copy(captures.begin(), captures.end(),
47+
storage->getTrailingObjects<CapturedValue>());
48+
}
49+
50+
CaptureInfo CaptureInfo::empty() {
51+
static const CaptureInfoStorage empty{0, /*dynamicSelf*/nullptr,
52+
/*opaqueValue*/nullptr};
53+
CaptureInfo result;
54+
result.StorageAndFlags.setPointer(&empty);
55+
return result;
56+
}
57+
1958
bool CaptureInfo::hasLocalCaptures() const {
2059
for (auto capture : getCaptures())
2160
if (capture.getDecl()->getDeclContext()->isLocalContext())
@@ -28,7 +67,7 @@ void CaptureInfo::
2867
getLocalCaptures(SmallVectorImpl<CapturedValue> &Result) const {
2968
if (!hasLocalCaptures()) return;
3069

31-
Result.reserve(Count);
70+
Result.reserve(getCaptures().size());
3271

3372
// Filter out global variables.
3473
for (auto capture : getCaptures()) {

branches/master-rebranch/lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,13 +2634,13 @@ namespace {
26342634
return newtype;
26352635

26362636
if (!SwiftType) {
2637-
// Import typedefs of blocks as their fully-bridged equivalent Swift
2638-
// type. That matches how we want to use them in most cases. All other
2639-
// types should be imported in a non-bridged way.
2637+
// Note that the code below checks to see if the typedef allows
2638+
// bridging, i.e. if the imported typealias should name a bridged type
2639+
// or the original C type.
26402640
clang::QualType ClangType = Decl->getUnderlyingType();
26412641
SwiftType = Impl.importTypeIgnoreIUO(
26422642
ClangType, ImportTypeKind::Typedef, isInSystemModule(DC),
2643-
getTypedefBridgeability(Decl, ClangType), OTK_Optional);
2643+
getTypedefBridgeability(Decl), OTK_Optional);
26442644
}
26452645

26462646
if (!SwiftType)

0 commit comments

Comments
 (0)