Skip to content

Commit 6f8fd07

Browse files
authored
Merge pull request #67037 from slavapestov/type-array-view
AST: Replace TypeArrayView<GenericTypeParamType> with ArrayRef<GenericTypeParamType *>
2 parents f1039c3 + 8afff61 commit 6f8fd07

27 files changed

+111
-121
lines changed

include/swift/AST/Decl.h

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

13601360
/// Retrieve the innermost generic parameter types.
1361-
TypeArrayView<GenericTypeParamType> getInnermostGenericParamTypes() const;
1361+
ArrayRef<GenericTypeParamType *> getInnermostGenericParamTypes() const;
13621362

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

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

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
@@ -663,17 +663,6 @@ inline CanTypeWrapper<X> dyn_cast_or_null(CanTypeWrapper<P> type) {
663663
return CanTypeWrapper<X>(dyn_cast_or_null<X>(type.getPointer()));
664664
}
665665

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

679668
namespace llvm {

include/swift/AST/Types.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,7 +3786,7 @@ class GenericFunctionType final : public AnyFunctionType,
37863786
}
37873787

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

37913791
/// Retrieve the requirements of this polymorphic function type.
37923792
ArrayRef<Requirement> getRequirements() const;
@@ -6859,7 +6859,7 @@ class PackType final : public TypeBase, public llvm::FoldingSetNode,
68596859
static PackType *getSingletonPackExpansion(Type packParameter);
68606860

68616861
static SmallVector<Type, 2> getExpandedGenericArgs(
6862-
TypeArrayView<GenericTypeParamType> params,
6862+
ArrayRef<GenericTypeParamType *> params,
68636863
ArrayRef<Type> args);
68646864

68656865
public:

lib/AST/ASTContext.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4376,7 +4376,7 @@ GenericTypeParamType *GenericTypeParamType::get(bool isParameterPack,
43764376
return result;
43774377
}
43784378

4379-
TypeArrayView<GenericTypeParamType>
4379+
ArrayRef<GenericTypeParamType *>
43804380
GenericFunctionType::getGenericParams() const {
43814381
return Signature.getGenericParams();
43824382
}
@@ -5071,7 +5071,7 @@ SubstitutionMap::Storage *SubstitutionMap::Storage::get(
50715071
}
50725072

50735073
void GenericSignatureImpl::Profile(llvm::FoldingSetNodeID &ID,
5074-
TypeArrayView<GenericTypeParamType> genericParams,
5074+
ArrayRef<GenericTypeParamType *> genericParams,
50755075
ArrayRef<Requirement> requirements) {
50765076
for (auto p : genericParams)
50775077
ID.AddPointer(p);
@@ -5086,19 +5086,8 @@ void GenericSignatureImpl::Profile(llvm::FoldingSetNodeID &ID,
50865086
}
50875087
}
50885088

5089-
GenericSignature
5090-
GenericSignature::get(ArrayRef<GenericTypeParamType *> params,
5091-
ArrayRef<Requirement> requirements,
5092-
bool isKnownCanonical) {
5093-
SmallVector<Type, 4> paramTypes;
5094-
for (auto param : params)
5095-
paramTypes.push_back(param);
5096-
auto paramsView = TypeArrayView<GenericTypeParamType>(paramTypes);
5097-
return get(paramsView, requirements, isKnownCanonical);
5098-
}
5099-
51005089
GenericSignature
5101-
GenericSignature::get(TypeArrayView<GenericTypeParamType> params,
5090+
GenericSignature::get(ArrayRef<GenericTypeParamType *> params,
51025091
ArrayRef<Requirement> requirements,
51035092
bool isKnownCanonical) {
51045093
assert(!params.empty());
@@ -5128,7 +5117,8 @@ GenericSignature::get(TypeArrayView<GenericTypeParamType> params,
51285117

51295118
// Allocate and construct the new signature.
51305119
size_t bytes =
5131-
GenericSignatureImpl::template totalSizeToAlloc<Type, Requirement>(
5120+
GenericSignatureImpl::template totalSizeToAlloc<
5121+
GenericTypeParamType *, Requirement>(
51325122
params.size(), requirements.size());
51335123
void *mem = ctx.Allocate(bytes, alignof(GenericSignatureImpl));
51345124
auto *newSig =

lib/AST/ASTPrinter.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -910,11 +910,11 @@ class PrintAST : public ASTVisitor<PrintAST> {
910910
printGenericSignature(GenericSignature genericSig, unsigned flags,
911911
llvm::function_ref<bool(const Requirement &)> filter);
912912
void printSingleDepthOfGenericSignature(
913-
TypeArrayView<GenericTypeParamType> genericParams,
913+
ArrayRef<GenericTypeParamType *> genericParams,
914914
ArrayRef<Requirement> requirements, unsigned flags,
915915
llvm::function_ref<bool(const Requirement &)> filter);
916916
void printSingleDepthOfGenericSignature(
917-
TypeArrayView<GenericTypeParamType> genericParams,
917+
ArrayRef<GenericTypeParamType *> genericParams,
918918
ArrayRef<Requirement> requirements, bool &isFirstReq, unsigned flags,
919919
llvm::function_ref<bool(const Requirement &)> filter);
920920
void printRequirement(const Requirement &req);
@@ -1641,7 +1641,7 @@ void PrintAST::printGenericSignature(
16411641
}
16421642

16431643
void PrintAST::printSingleDepthOfGenericSignature(
1644-
TypeArrayView<GenericTypeParamType> genericParams,
1644+
ArrayRef<GenericTypeParamType *> genericParams,
16451645
ArrayRef<Requirement> requirements, unsigned flags,
16461646
llvm::function_ref<bool(const Requirement &)> filter) {
16471647
bool isFirstReq = true;
@@ -1650,7 +1650,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
16501650
}
16511651

16521652
void PrintAST::printSingleDepthOfGenericSignature(
1653-
TypeArrayView<GenericTypeParamType> genericParams,
1653+
ArrayRef<GenericTypeParamType *> genericParams,
16541654
ArrayRef<Requirement> requirements, bool &isFirstReq, unsigned flags,
16551655
llvm::function_ref<bool(const Requirement &)> filter) {
16561656
bool printParams = (flags & PrintParams);
@@ -1692,7 +1692,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
16921692

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

57305730
void printGenericArgs(ASTContext &ctx,
5731-
TypeArrayView<GenericTypeParamType> params,
5731+
ArrayRef<GenericTypeParamType *> params,
57325732
ArrayRef<Type> args) {
57335733
printGenericArgs(PackType::getExpandedGenericArgs(params, args));
57345734
}

lib/AST/Decl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1219,7 +1219,7 @@ GenericContext::GenericContext(DeclContextKind Kind, DeclContext *Parent,
12191219
}
12201220
}
12211221

1222-
TypeArrayView<GenericTypeParamType>
1222+
ArrayRef<GenericTypeParamType *>
12231223
GenericContext::getInnermostGenericParamTypes() const {
12241224
return getGenericSignature().getInnermostGenericParams();
12251225
}

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)