Skip to content

Commit 6f1cf76

Browse files
authored
Merge pull request #67100 from slavapestov/rqm-same-type-same-shape-5.9
RequirementMachine: Same-type requirements imply same-shape requirements [5.9]
2 parents e741091 + f138d5a commit 6f1cf76

34 files changed

+274
-163
lines changed

include/swift/AST/Decl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1357,7 +1357,7 @@ class GenericContext : private _GenericContext, public DeclContext {
13571357
GenericEnvironment *getGenericEnvironment() const;
13581358

13591359
/// Retrieve the innermost generic parameter types.
1360-
TypeArrayView<GenericTypeParamType> getInnermostGenericParamTypes() const;
1360+
ArrayRef<GenericTypeParamType *> getInnermostGenericParamTypes() const;
13611361

13621362
/// Retrieve the generic requirements.
13631363
ArrayRef<Requirement> getGenericRequirements() const;
@@ -3147,7 +3147,7 @@ class OpaqueTypeDecl final :
31473147

31483148
/// Retrieve the generic parameters that represent the opaque types described by this opaque
31493149
/// type declaration.
3150-
TypeArrayView<GenericTypeParamType> getOpaqueGenericParams() const {
3150+
ArrayRef<GenericTypeParamType *> getOpaqueGenericParams() const {
31513151
return OpaqueInterfaceGenericSignature.getInnermostGenericParams();
31523152
}
31533153

include/swift/AST/GenericEnvironment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
177177

178178
Kind getKind() const { return SignatureAndKind.getInt(); }
179179

180-
TypeArrayView<GenericTypeParamType> getGenericParams() const;
180+
ArrayRef<GenericTypeParamType *> getGenericParams() const;
181181

182182
/// Retrieve the existential type for an opened existential environment.
183183
Type getOpenedExistentialType() const;

include/swift/AST/GenericParamKey.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ struct GenericParamKey {
9393

9494
/// Find the index that this key would have into an array of
9595
/// generic type parameters
96-
unsigned findIndexIn(TypeArrayView<GenericTypeParamType> genericParams) const;
96+
unsigned findIndexIn(ArrayRef<GenericTypeParamType *> genericParams) const;
9797
};
9898

9999
} // end namespace swift

include/swift/AST/GenericSignature.h

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class ProtocolConformanceRef;
3434
class ProtocolType;
3535
class SubstitutionMap;
3636
class GenericEnvironment;
37+
class GenericTypeParamType;
3738

3839
namespace rewriting {
3940
class RequirementMachine;
@@ -118,16 +119,13 @@ class GenericSignature {
118119
static GenericSignature get(ArrayRef<GenericTypeParamType *> params,
119120
ArrayRef<Requirement> requirements,
120121
bool isKnownCanonical = false);
121-
static GenericSignature get(TypeArrayView<GenericTypeParamType> params,
122-
ArrayRef<Requirement> requirements,
123-
bool isKnownCanonical = false);
124122

125123
/// Produce a new generic signature which drops all of the marker
126124
/// protocol conformance requirements associated with this one.
127125
GenericSignature withoutMarkerProtocols() const;
128126

129127
public:
130-
static ASTContext &getASTContext(TypeArrayView<GenericTypeParamType> params,
128+
static ASTContext &getASTContext(ArrayRef<GenericTypeParamType *> params,
131129
ArrayRef<Requirement> requirements);
132130

133131
public:
@@ -164,7 +162,7 @@ class GenericSignature {
164162
void Profile(llvm::FoldingSetNodeID &id) const;
165163

166164
static void Profile(llvm::FoldingSetNodeID &ID,
167-
TypeArrayView<GenericTypeParamType> genericParams,
165+
ArrayRef<GenericTypeParamType *> genericParams,
168166
ArrayRef<Requirement> requirements);
169167
public:
170168
using RequiredProtocols = SmallVector<ProtocolDecl *, 2>;
@@ -191,13 +189,13 @@ class GenericSignature {
191189

192190
public:
193191
/// Retrieve the generic parameters.
194-
TypeArrayView<GenericTypeParamType> getGenericParams() const;
192+
ArrayRef<GenericTypeParamType *> getGenericParams() const;
195193

196194
/// Retrieve the innermost generic parameters.
197195
///
198196
/// Given a generic signature for a nested generic type, produce an
199197
/// array of the generic parameters for the innermost generic type.
200-
TypeArrayView<GenericTypeParamType> getInnermostGenericParams() const;
198+
ArrayRef<GenericTypeParamType *> getInnermostGenericParams() const;
201199

202200
/// Retrieve the requirements.
203201
ArrayRef<Requirement> getRequirements() const;
@@ -240,7 +238,7 @@ class CanGenericSignature : public GenericSignature {
240238
/// Create a new generic signature with the given type parameters and
241239
/// requirements, first canonicalizing the types.
242240
static CanGenericSignature
243-
getCanonical(TypeArrayView<GenericTypeParamType> params,
241+
getCanonical(ArrayRef<GenericTypeParamType *> params,
244242
ArrayRef<Requirement> requirements);
245243

246244
public:
@@ -267,7 +265,8 @@ class CanGenericSignature : public GenericSignature {
267265
/// The underlying implementation of generic signatures.
268266
class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
269267
: public llvm::FoldingSetNode,
270-
private llvm::TrailingObjects<GenericSignatureImpl, Type, Requirement> {
268+
private llvm::TrailingObjects<GenericSignatureImpl, GenericTypeParamType *,
269+
Requirement> {
271270
friend class ASTContext;
272271
friend GenericSignature;
273272
friend TrailingObjects;
@@ -286,14 +285,14 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
286285
void *operator new(size_t Bytes) = delete;
287286
void operator delete(void *Data) = delete;
288287

289-
size_t numTrailingObjects(OverloadToken<Type>) const {
288+
size_t numTrailingObjects(OverloadToken<GenericTypeParamType *>) const {
290289
return NumGenericParams;
291290
}
292291
size_t numTrailingObjects(OverloadToken<Requirement>) const {
293292
return NumRequirements;
294293
}
295294

296-
GenericSignatureImpl(TypeArrayView<GenericTypeParamType> params,
295+
GenericSignatureImpl(ArrayRef<GenericTypeParamType *> params,
297296
ArrayRef<Requirement> requirements,
298297
bool isKnownCanonical);
299298

@@ -326,6 +325,9 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
326325
/// concrete.
327326
bool areAllParamsConcrete() const;
328327

328+
/// Check if the generic signature has a parameter pack.
329+
bool hasParameterPack() const;
330+
329331
/// Compute the number of conformance requirements in this signature.
330332
unsigned getNumConformanceRequirements() const {
331333
unsigned result = 0;
@@ -470,7 +472,7 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
470472
Type getDependentUpperBounds(Type type) const;
471473

472474
static void Profile(llvm::FoldingSetNodeID &ID,
473-
TypeArrayView<GenericTypeParamType> genericParams,
475+
ArrayRef<GenericTypeParamType *> genericParams,
474476
ArrayRef<Requirement> requirements);
475477

476478
void print(raw_ostream &OS, PrintOptions Options = PrintOptions()) const;
@@ -483,16 +485,16 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
483485
friend CanGenericSignature;
484486

485487
/// Retrieve the generic parameters.
486-
TypeArrayView<GenericTypeParamType> getGenericParams() const {
487-
return TypeArrayView<GenericTypeParamType>(
488-
{getTrailingObjects<Type>(), NumGenericParams});
488+
ArrayRef<GenericTypeParamType *> getGenericParams() const {
489+
return ArrayRef<GenericTypeParamType *>(
490+
{getTrailingObjects<GenericTypeParamType *>(), NumGenericParams});
489491
}
490492

491493
/// Retrieve the innermost generic parameters.
492494
///
493495
/// Given a generic signature for a nested generic type, produce an
494496
/// array of the generic parameters for the innermost generic type.
495-
TypeArrayView<GenericTypeParamType> getInnermostGenericParams() const;
497+
ArrayRef<GenericTypeParamType *> getInnermostGenericParams() const;
496498

497499
/// Retrieve the requirements.
498500
ArrayRef<Requirement> getRequirements() const {

include/swift/AST/Type.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -661,17 +661,6 @@ inline CanTypeWrapper<X> dyn_cast_or_null(CanTypeWrapper<P> type) {
661661
return CanTypeWrapper<X>(dyn_cast_or_null<X>(type.getPointer()));
662662
}
663663

664-
template <typename T>
665-
inline T *staticCastHelper(const Type &Ty) {
666-
// The constructor of the ArrayRef<Type> must guarantee this invariant.
667-
// XXX -- We use reinterpret_cast instead of static_cast so that files
668-
// can avoid including Types.h if they want to.
669-
return reinterpret_cast<T*>(Ty.getPointer());
670-
}
671-
/// TypeArrayView allows arrays of 'Type' to have a static type.
672-
template <typename T>
673-
using TypeArrayView = ArrayRefView<Type, T*, staticCastHelper,
674-
/*AllowOrigAccess*/true>;
675664
} // end namespace swift
676665

677666
namespace llvm {

include/swift/AST/Types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3792,7 +3792,7 @@ class GenericFunctionType final : public AnyFunctionType,
37923792
}
37933793

37943794
/// Retrieve the generic parameters of this polymorphic function type.
3795-
TypeArrayView<GenericTypeParamType> getGenericParams() const;
3795+
ArrayRef<GenericTypeParamType *> getGenericParams() const;
37963796

37973797
/// Retrieve the requirements of this polymorphic function type.
37983798
ArrayRef<Requirement> getRequirements() const;
@@ -6869,7 +6869,7 @@ class PackType final : public TypeBase, public llvm::FoldingSetNode,
68696869
static PackType *getSingletonPackExpansion(Type packParameter);
68706870

68716871
static SmallVector<Type, 2> getExpandedGenericArgs(
6872-
TypeArrayView<GenericTypeParamType> params,
6872+
ArrayRef<GenericTypeParamType *> params,
68736873
ArrayRef<Type> args);
68746874

68756875
public:

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4366,7 +4366,7 @@ GenericTypeParamType *GenericTypeParamType::get(bool isParameterPack,
43664366
return result;
43674367
}
43684368

4369-
TypeArrayView<GenericTypeParamType>
4369+
ArrayRef<GenericTypeParamType *>
43704370
GenericFunctionType::getGenericParams() const {
43714371
return Signature.getGenericParams();
43724372
}
@@ -5077,7 +5077,7 @@ SubstitutionMap::Storage *SubstitutionMap::Storage::get(
50775077
}
50785078

50795079
void GenericSignatureImpl::Profile(llvm::FoldingSetNodeID &ID,
5080-
TypeArrayView<GenericTypeParamType> genericParams,
5080+
ArrayRef<GenericTypeParamType *> genericParams,
50815081
ArrayRef<Requirement> requirements) {
50825082
for (auto p : genericParams)
50835083
ID.AddPointer(p);
@@ -5092,19 +5092,8 @@ void GenericSignatureImpl::Profile(llvm::FoldingSetNodeID &ID,
50925092
}
50935093
}
50945094

5095-
GenericSignature
5096-
GenericSignature::get(ArrayRef<GenericTypeParamType *> params,
5097-
ArrayRef<Requirement> requirements,
5098-
bool isKnownCanonical) {
5099-
SmallVector<Type, 4> paramTypes;
5100-
for (auto param : params)
5101-
paramTypes.push_back(param);
5102-
auto paramsView = TypeArrayView<GenericTypeParamType>(paramTypes);
5103-
return get(paramsView, requirements, isKnownCanonical);
5104-
}
5105-
51065095
GenericSignature
5107-
GenericSignature::get(TypeArrayView<GenericTypeParamType> params,
5096+
GenericSignature::get(ArrayRef<GenericTypeParamType *> params,
51085097
ArrayRef<Requirement> requirements,
51095098
bool isKnownCanonical) {
51105099
assert(!params.empty());
@@ -5134,7 +5123,8 @@ GenericSignature::get(TypeArrayView<GenericTypeParamType> params,
51345123

51355124
// Allocate and construct the new signature.
51365125
size_t bytes =
5137-
GenericSignatureImpl::template totalSizeToAlloc<Type, Requirement>(
5126+
GenericSignatureImpl::template totalSizeToAlloc<
5127+
GenericTypeParamType *, Requirement>(
51385128
params.size(), requirements.size());
51395129
void *mem = ctx.Allocate(bytes, alignof(GenericSignatureImpl));
51405130
auto *newSig =

lib/AST/ASTPrinter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -911,11 +911,11 @@ class PrintAST : public ASTVisitor<PrintAST> {
911911
printGenericSignature(GenericSignature genericSig, unsigned flags,
912912
llvm::function_ref<bool(const Requirement &)> filter);
913913
void printSingleDepthOfGenericSignature(
914-
TypeArrayView<GenericTypeParamType> genericParams,
914+
ArrayRef<GenericTypeParamType *> genericParams,
915915
ArrayRef<Requirement> requirements, unsigned flags,
916916
llvm::function_ref<bool(const Requirement &)> filter);
917917
void printSingleDepthOfGenericSignature(
918-
TypeArrayView<GenericTypeParamType> genericParams,
918+
ArrayRef<GenericTypeParamType *> genericParams,
919919
ArrayRef<Requirement> requirements, bool &isFirstReq, unsigned flags,
920920
llvm::function_ref<bool(const Requirement &)> filter);
921921
void printRequirement(const Requirement &req);
@@ -1642,7 +1642,7 @@ void PrintAST::printGenericSignature(
16421642
}
16431643

16441644
void PrintAST::printSingleDepthOfGenericSignature(
1645-
TypeArrayView<GenericTypeParamType> genericParams,
1645+
ArrayRef<GenericTypeParamType *> genericParams,
16461646
ArrayRef<Requirement> requirements, unsigned flags,
16471647
llvm::function_ref<bool(const Requirement &)> filter) {
16481648
bool isFirstReq = true;
@@ -1651,7 +1651,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
16511651
}
16521652

16531653
void PrintAST::printSingleDepthOfGenericSignature(
1654-
TypeArrayView<GenericTypeParamType> genericParams,
1654+
ArrayRef<GenericTypeParamType *> genericParams,
16551655
ArrayRef<Requirement> requirements, bool &isFirstReq, unsigned flags,
16561656
llvm::function_ref<bool(const Requirement &)> filter) {
16571657
bool printParams = (flags & PrintParams);
@@ -1693,7 +1693,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
16931693

16941694
/// Separate the explicit generic parameters from the implicit, opaque
16951695
/// generic parameters. We only print the former.
1696-
TypeArrayView<GenericTypeParamType> opaqueGenericParams;
1696+
ArrayRef<GenericTypeParamType *> opaqueGenericParams;
16971697
for (unsigned index : indices(genericParams)) {
16981698
auto gpDecl = genericParams[index]->getDecl();
16991699
if (!gpDecl)
@@ -5696,7 +5696,7 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
56965696
}
56975697

56985698
void printGenericArgs(ASTContext &ctx,
5699-
TypeArrayView<GenericTypeParamType> params,
5699+
ArrayRef<GenericTypeParamType *> params,
57005700
ArrayRef<Type> args) {
57015701
printGenericArgs(PackType::getExpandedGenericArgs(params, args));
57025702
}

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1238,7 +1238,7 @@ GenericContext::GenericContext(DeclContextKind Kind, DeclContext *Parent,
12381238
}
12391239
}
12401240

1241-
TypeArrayView<GenericTypeParamType>
1241+
ArrayRef<GenericTypeParamType *>
12421242
GenericContext::getInnermostGenericParamTypes() const {
12431243
return getGenericSignature().getInnermostGenericParams();
12441244
}

lib/AST/GenericEnvironment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ ArrayRef<Type> GenericEnvironment::getOpenedPackParams() const {
9898
return ArrayRef<Type>(begin, getNumOpenedPackParams());
9999
}
100100

101-
TypeArrayView<GenericTypeParamType>
101+
ArrayRef<GenericTypeParamType *>
102102
GenericEnvironment::getGenericParams() const {
103103
return getGenericSignature().getGenericParams();
104104
}
@@ -152,7 +152,7 @@ namespace {
152152

153153
struct FindOpenedElementParam {
154154
ArrayRef<Type> openedPacks;
155-
TypeArrayView<GenericTypeParamType> packElementParams;
155+
ArrayRef<GenericTypeParamType *> packElementParams;
156156

157157
FindOpenedElementParam(const GenericEnvironment *env,
158158
ArrayRef<Type> openedPacks)

0 commit comments

Comments
 (0)