Skip to content

Commit 20efacf

Browse files
committed
Merge remote-tracking branch 'upstream/master' into master-next
2 parents 5c39026 + af0247e commit 20efacf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+703
-500
lines changed

include/swift/AST/ASTTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ SWIFT_TYPEID_NAMED(Optional<PropertyWrapperMutability>, PropertyWrapperMutabilit
2929
SWIFT_TYPEID_NAMED(CustomAttr *, CustomAttr)
3030
SWIFT_TYPEID_NAMED(TypeAliasDecl *, TypeAliasDecl)
3131
SWIFT_TYPEID(AncestryFlags)
32+
SWIFT_TYPEID_NAMED(GenericSignature *, GenericSignature)
33+
SWIFT_TYPEID_NAMED(GenericTypeParamType *, GenericTypeParamType)
34+
SWIFT_TYPEID(Requirement)

include/swift/AST/ASTTypeIDs.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@
2121
namespace swift {
2222

2323
class CustomAttr;
24+
class GenericSignature;
25+
class GenericTypeParamType;
2426
class NominalTypeDecl;
2527
struct PropertyWrapperBackingPropertyInfo;
2628
struct PropertyWrapperTypeInfo;
2729
enum class CtorInitializerKind;
2830
struct PropertyWrapperMutability;
31+
class Requirement;
2932
class Type;
3033
class VarDecl;
3134
class TypeAliasDecl;

include/swift/AST/Attr.h

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -258,11 +258,9 @@ class DeclAttribute : public AttributeBase {
258258
ownership : NumReferenceOwnershipBits
259259
);
260260

261-
SWIFT_INLINE_BITFIELD_FULL(SpecializeAttr, DeclAttribute, 1+1+32,
261+
SWIFT_INLINE_BITFIELD(SpecializeAttr, DeclAttribute, 1+1,
262262
exported : 1,
263-
kind : 1,
264-
: NumPadBits,
265-
numRequirements : 32
263+
kind : 1
266264
);
267265

268266
SWIFT_INLINE_BITFIELD(SynthesizedProtocolAttr, DeclAttribute,
@@ -1236,39 +1234,29 @@ class SpecializeAttr : public DeclAttribute {
12361234

12371235
private:
12381236
TrailingWhereClause *trailingWhereClause;
1239-
1240-
Requirement *getRequirementsData() {
1241-
return reinterpret_cast<Requirement *>(this+1);
1242-
}
1237+
GenericSignature *specializedSignature;
12431238

12441239
SpecializeAttr(SourceLoc atLoc, SourceRange Range,
12451240
TrailingWhereClause *clause, bool exported,
1246-
SpecializationKind kind);
1247-
1248-
SpecializeAttr(SourceLoc atLoc, SourceRange Range,
1249-
ArrayRef<Requirement> requirements,
1250-
bool exported,
1251-
SpecializationKind kind);
1241+
SpecializationKind kind,
1242+
GenericSignature *specializedSignature);
12521243

12531244
public:
12541245
static SpecializeAttr *create(ASTContext &Ctx, SourceLoc atLoc,
12551246
SourceRange Range, TrailingWhereClause *clause,
1256-
bool exported, SpecializationKind kind);
1257-
1258-
static SpecializeAttr *create(ASTContext &Ctx, SourceLoc atLoc,
1259-
SourceRange Range,
1260-
ArrayRef<Requirement> requirement,
1261-
bool exported, SpecializationKind kind);
1247+
bool exported, SpecializationKind kind,
1248+
GenericSignature *specializedSignature
1249+
= nullptr);
12621250

12631251
TrailingWhereClause *getTrailingWhereClause() const;
12641252

1265-
ArrayRef<Requirement> getRequirements() const;
1266-
1267-
MutableArrayRef<Requirement> getRequirements() {
1268-
return { getRequirementsData(), Bits.SpecializeAttr.numRequirements };
1253+
GenericSignature *getSpecializedSgnature() const {
1254+
return specializedSignature;
12691255
}
12701256

1271-
void setRequirements(ASTContext &Ctx, ArrayRef<Requirement> requirements);
1257+
void setSpecializedSignature(GenericSignature *newSig) {
1258+
specializedSignature = newSig;
1259+
}
12721260

12731261
bool isExported() const {
12741262
return Bits.SpecializeAttr.exported;

include/swift/AST/GenericSignature.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ CanGenericSignature::CanGenericSignature(GenericSignature *Signature)
335335
assert(!Signature || Signature->isCanonical());
336336
}
337337

338+
void simple_display(raw_ostream &out, const GenericSignature *sig);
339+
338340
} // end namespace swift
339341

340342
#endif // SWIFT_AST_GENERIC_SIGNATURE_H

include/swift/AST/LayoutConstraint.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "swift/Basic/SourceLoc.h"
2222
#include "llvm/ADT/DenseMap.h"
2323
#include "llvm/ADT/FoldingSet.h"
24+
#include "llvm/ADT/Hashing.h"
2425
#include "llvm/ADT/StringRef.h"
2526
#include "swift/AST/PrintOptions.h"
2627

@@ -290,6 +291,10 @@ class LayoutConstraint {
290291
/// Return the layout constraint as a string, for use in diagnostics only.
291292
std::string getString(const PrintOptions &PO = PrintOptions()) const;
292293

294+
friend llvm::hash_code hash_value(const LayoutConstraint &layout) {
295+
return hash_value(layout.getPointer());
296+
}
297+
293298
bool operator==(LayoutConstraint rhs) const {
294299
if (isNull() && rhs.isNull())
295300
return true;

include/swift/AST/Module.h

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,10 @@ static inline unsigned alignOfFileUnit();
644644
/// FileUnit is an abstract base class; its subclasses represent different
645645
/// sorts of containers that can each provide a set of decls, e.g. a source
646646
/// file. A module can contain several file-units.
647+
#pragma clang diagnostic push
648+
#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
647649
class FileUnit : public DeclContext {
650+
#pragma clang diagnostic pop
648651
virtual void anchor();
649652

650653
// FIXME: Stick this in a PointerIntPair.
@@ -655,8 +658,6 @@ class FileUnit : public DeclContext {
655658
: DeclContext(DeclContextKind::FileUnit, &M), Kind(kind) {
656659
}
657660

658-
virtual ~FileUnit() = default;
659-
660661
public:
661662
FileUnitKind getKind() const {
662663
return Kind;
@@ -874,10 +875,6 @@ class FileUnit : public DeclContext {
874875
return getParentModule()->getName().str();
875876
}
876877

877-
/// If this is a module imported from a parseable interface, return the path
878-
/// to the interface file, otherwise an empty StringRef.
879-
virtual StringRef getParseableInterface() const { return {}; }
880-
881878
/// Traverse the decls within this file.
882879
///
883880
/// \returns true if traversal was aborted, false if it completed
@@ -897,13 +894,7 @@ class FileUnit : public DeclContext {
897894
// Make placement new and vanilla new/delete illegal for FileUnits.
898895
void *operator new(size_t Bytes) throw() = delete;
899896
void *operator new(size_t Bytes, void *Mem) throw() = delete;
900-
901-
protected:
902-
// Unfortunately we can't remove this altogether because the virtual
903-
// destructor requires it to be accessible.
904-
void operator delete(void *Data) throw() {
905-
llvm_unreachable("Don't use operator delete on a SourceFile");
906-
}
897+
void operator delete(void *Data) throw() = delete;
907898

908899
public:
909900
// Only allow allocation of FileUnits using the allocator in ASTContext
@@ -1386,35 +1377,23 @@ class BuiltinUnit final : public FileUnit {
13861377
};
13871378

13881379
/// Represents an externally-loaded file of some kind.
1380+
#pragma clang diagnostic push
1381+
#pragma clang diagnostic ignored "-Wnon-virtual-dtor"
13891382
class LoadedFile : public FileUnit {
1383+
#pragma clang diagnostic pop
13901384
protected:
1391-
~LoadedFile() = default;
13921385
LoadedFile(FileUnitKind Kind, ModuleDecl &M) noexcept
13931386
: FileUnit(Kind, M) {
13941387
assert(classof(this) && "invalid kind");
13951388
}
1396-
1397-
/// A map from private/fileprivate decls to the file they were defined in.
1398-
llvm::DenseMap<const ValueDecl *, Identifier> FilenameForPrivateDecls;
1399-
14001389
public:
1401-
14021390
/// Returns an arbitrary string representing the storage backing this file.
14031391
///
14041392
/// This is usually a filesystem path.
14051393
virtual StringRef getFilename() const;
14061394

1407-
void addFilenameForPrivateDecl(const ValueDecl *decl, Identifier id) {
1408-
assert(!FilenameForPrivateDecls.count(decl) ||
1409-
FilenameForPrivateDecls[decl] == id);
1410-
FilenameForPrivateDecls[decl] = id;
1411-
}
1412-
1413-
StringRef getFilenameForPrivateDecl(const ValueDecl *decl) {
1414-
auto it = FilenameForPrivateDecls.find(decl);
1415-
if (it == FilenameForPrivateDecls.end())
1416-
return StringRef();
1417-
return it->second.str();
1395+
virtual StringRef getFilenameForPrivateDecl(const ValueDecl *decl) const {
1396+
return StringRef();
14181397
}
14191398

14201399
/// Look up an operator declaration.

include/swift/AST/Requirement.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#define SWIFT_AST_REQUIREMENT_H
1919

2020
#include "swift/AST/Type.h"
21+
#include "llvm/ADT/Hashing.h"
2122
#include "llvm/ADT/PointerIntPair.h"
2223
#include "llvm/Support/ErrorHandling.h"
2324

@@ -119,12 +120,60 @@ class Requirement {
119120
return SecondLayout;
120121
}
121122

123+
/// Whether this requirement is in its canonical form.
124+
bool isCanonical() const;
125+
126+
/// Get the canonical form of this requirement.
127+
Requirement getCanonical() const;
128+
122129
void dump() const;
123130
void dump(raw_ostream &out) const;
124131
void print(raw_ostream &os, const PrintOptions &opts) const;
125132
void print(ASTPrinter &printer, const PrintOptions &opts) const;
133+
134+
friend llvm::hash_code hash_value(const Requirement &requirement) {
135+
using llvm::hash_value;
136+
137+
llvm::hash_code first =
138+
hash_value(requirement.FirstTypeAndKind.getOpaqueValue());
139+
llvm::hash_code second;
140+
switch (requirement.getKind()) {
141+
case RequirementKind::Conformance:
142+
case RequirementKind::Superclass:
143+
case RequirementKind::SameType:
144+
second = hash_value(requirement.getSecondType());
145+
break;
146+
147+
case RequirementKind::Layout:
148+
second = hash_value(requirement.getLayoutConstraint());
149+
break;
150+
}
151+
152+
return llvm::hash_combine(first, second);
153+
}
154+
155+
friend bool operator==(const Requirement &lhs, const Requirement &rhs) {
156+
if (lhs.FirstTypeAndKind.getOpaqueValue()
157+
!= rhs.FirstTypeAndKind.getOpaqueValue())
158+
return false;
159+
160+
switch (lhs.getKind()) {
161+
case RequirementKind::Conformance:
162+
case RequirementKind::Superclass:
163+
case RequirementKind::SameType:
164+
return lhs.getSecondType().getPointer() ==
165+
rhs.getSecondType().getPointer();
166+
167+
case RequirementKind::Layout:
168+
return lhs.getLayoutConstraint() == rhs.getLayoutConstraint();
169+
}
170+
}
126171
};
127172

173+
inline void simple_display(llvm::raw_ostream &out, const Requirement &req) {
174+
req.print(out, PrintOptions());
175+
}
176+
128177
} // end namespace swift
129178

130179
#endif

include/swift/AST/SimpleRequest.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,4 +261,11 @@ class SimpleRequest<Derived, Output(Inputs...), Caching> {
261261
};
262262
}
263263

264+
namespace llvm {
265+
template <typename T, unsigned N>
266+
llvm::hash_code hash_value(const SmallVector<T, N> &vec) {
267+
return hash_combine_range(vec.begin(), vec.end());
268+
}
269+
}
270+
264271
#endif // SWIFT_BASIC_SIMPLEREQUEST_H

include/swift/AST/Type.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
#include "llvm/ADT/DenseMap.h"
2121
#include "llvm/ADT/DenseMapInfo.h"
22+
#include "llvm/ADT/Hashing.h"
2223
#include "llvm/ADT/STLExtras.h"
2324
#include "swift/Basic/LLVM.h"
2425
#include "swift/Basic/ArrayRefView.h"
@@ -323,6 +324,11 @@ class Type {
323324
/// Return the name of the type as a string, for use in diagnostics only.
324325
std::string getString(const PrintOptions &PO = PrintOptions()) const;
325326

327+
friend llvm::hash_code hash_value(Type type) {
328+
using llvm::hash_value;
329+
return hash_value(type.getPointer());
330+
}
331+
326332
/// Return the name of the type, adding parens in cases where
327333
/// appending or prepending text to the result would cause that text
328334
/// to be appended to only a portion of the returned type. For

include/swift/AST/TypeCheckRequests.h

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030
namespace swift {
3131

3232
class AbstractStorageDecl;
33+
class AccessorDecl;
34+
enum class AccessorKind;
3335
class GenericParamList;
3436
struct PropertyWrapperBackingPropertyInfo;
3537
struct PropertyWrapperMutability;
@@ -38,8 +40,8 @@ class SpecializeAttr;
3840
class TypeAliasDecl;
3941
struct TypeLoc;
4042
class ValueDecl;
41-
class AbstractStorageDecl;
4243
enum class OpaqueReadOwnership: uint8_t;
44+
class StorageImplInfo;
4345

4446
/// Display a nominal type or extension thereof.
4547
void simple_display(
@@ -1073,6 +1075,35 @@ class ClassAncestryFlagsRequest :
10731075

10741076
void simple_display(llvm::raw_ostream &out, AncestryFlags value);
10751077

1078+
class AbstractGenericSignatureRequest :
1079+
public SimpleRequest<AbstractGenericSignatureRequest,
1080+
GenericSignature *(GenericSignature *,
1081+
SmallVector<GenericTypeParamType *, 2>,
1082+
SmallVector<Requirement, 2>),
1083+
CacheKind::Cached> {
1084+
public:
1085+
using SimpleRequest::SimpleRequest;
1086+
1087+
private:
1088+
friend SimpleRequest;
1089+
1090+
// Evaluation.
1091+
llvm::Expected<GenericSignature *>
1092+
evaluate(Evaluator &evaluator,
1093+
GenericSignature *baseSignature,
1094+
SmallVector<GenericTypeParamType *, 2> addedParameters,
1095+
SmallVector<Requirement, 2> addedRequirements) const;
1096+
1097+
public:
1098+
// Separate caching.
1099+
bool isCached() const;
1100+
1101+
/// Abstract generic signature requests never have source-location info.
1102+
SourceLoc getNearestLoc() const {
1103+
return SourceLoc();
1104+
}
1105+
};
1106+
10761107
// Allow AnyValue to compare two Type values, even though Type doesn't
10771108
// support ==.
10781109
template<>

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,4 @@ SWIFT_TYPEID(SynthesizeAccessorRequest)
5757
SWIFT_TYPEID(EmittedMembersRequest)
5858
SWIFT_TYPEID(IsImplicitlyUnwrappedOptionalRequest)
5959
SWIFT_TYPEID(ClassAncestryFlagsRequest)
60+
SWIFT_TYPEID(AbstractGenericSignatureRequest)

include/swift/Basic/SimpleDisplay.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,20 @@ namespace swift {
121121
}
122122
out << "}";
123123
}
124+
125+
template<typename T>
126+
void simple_display(llvm::raw_ostream &out,
127+
const llvm::SmallVectorImpl<T> &vec) {
128+
out << "{";
129+
bool first = true;
130+
for (const T &value : vec) {
131+
if (first) first = false;
132+
else out << ", ";
133+
134+
simple_display(out, value);
135+
}
136+
out << "}";
137+
}
124138
}
125139

126140
#endif // SWIFT_BASIC_SIMPLE_DISPLAY_H

include/swift/ClangImporter/ClangModule.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ class ClangModuleUnit final : public LoadedFile {
3939
/// The metadata of the underlying Clang module.
4040
clang::ExternalASTSource::ASTSourceDescriptor ASTSourceDescriptor;
4141

42-
~ClangModuleUnit() = default;
43-
4442
public:
4543
/// True if the given Module contains an imported Clang module unit.
4644
static bool hasClangModule(ModuleDecl *M);

0 commit comments

Comments
 (0)