Skip to content

Commit ebb1198

Browse files
committed
AST: There's no longer any reason to pass SubstitutionMap by const reference
SubstitutionMaps are now just a trivial pointer-sized value, so pass them by value instead. I did have to move a couple of functors from Type.h to SubstitutionMap.h to resolve some issues with forward declarations.
1 parent 8db3368 commit ebb1198

22 files changed

+68
-68
lines changed

include/swift/AST/RequirementEnvironment.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class RequirementEnvironment {
114114

115115
/// Retrieve the substitution map that maps the interface types of the
116116
/// requirement to the interface types of the synthetic environment.
117-
const SubstitutionMap &getRequirementToSyntheticMap() const {
117+
SubstitutionMap getRequirementToSyntheticMap() const {
118118
return reqToSyntheticEnvMap;
119119
}
120120
};

include/swift/AST/SubstitutionMap.h

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ class SubstitutionMap {
164164

165165
/// Apply a substitution to all replacement types in the map. Does not
166166
/// change keys.
167-
SubstitutionMap subst(const SubstitutionMap &subMap) const;
167+
SubstitutionMap subst(SubstitutionMap subMap) const;
168168

169169
/// Apply a substitution to all replacement types in the map. Does not
170170
/// change keys.
@@ -208,8 +208,8 @@ class SubstitutionMap {
208208
///
209209
/// The 'how' parameter determines if we're looking at the depth or index.
210210
static SubstitutionMap
211-
combineSubstitutionMaps(const SubstitutionMap &firstSubMap,
212-
const SubstitutionMap &secondSubMap,
211+
combineSubstitutionMaps(SubstitutionMap firstSubMap,
212+
SubstitutionMap secondSubMap,
213213
CombineSubstitutionMaps how,
214214
unsigned baseDepthOrIndex,
215215
unsigned origDepthOrIndex,
@@ -270,6 +270,28 @@ class SubstitutionMap {
270270
Type lookupSubstitution(CanSubstitutableType type) const;
271271
};
272272

273+
/// A function object suitable for use as a \c TypeSubstitutionFn that
274+
/// queries an underlying \c SubstitutionMap.
275+
struct QuerySubstitutionMap {
276+
SubstitutionMap subMap;
277+
278+
Type operator()(SubstitutableType *type) const;
279+
};
280+
281+
/// Functor class suitable for use as a \c LookupConformanceFn to look up a
282+
/// conformance in a \c SubstitutionMap.
283+
class LookUpConformanceInSubstitutionMap {
284+
SubstitutionMap Subs;
285+
public:
286+
explicit LookUpConformanceInSubstitutionMap(SubstitutionMap Subs)
287+
: Subs(Subs) {}
288+
289+
Optional<ProtocolConformanceRef>
290+
operator()(CanType dependentType,
291+
Type conformingReplacementType,
292+
ProtocolType *conformedProtocol) const;
293+
};
294+
273295
} // end namespace swift
274296

275297
namespace llvm {

include/swift/AST/Type.h

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,6 @@ struct QueryTypeSubstitutionMapOrIdentity {
8888
Type operator()(SubstitutableType *type) const;
8989
};
9090

91-
/// A function object suitable for use as a \c TypeSubstitutionFn that
92-
/// queries an underlying \c SubstitutionMap.
93-
struct QuerySubstitutionMap {
94-
const SubstitutionMap &subMap;
95-
96-
Type operator()(SubstitutableType *type) const;
97-
};
98-
9991
/// Function used to resolve conformances.
10092
using GenericFunction = auto(CanType dependentType,
10193
Type conformingReplacementType,
@@ -117,20 +109,6 @@ class LookUpConformanceInModule {
117109
ProtocolType *conformedProtocol) const;
118110
};
119111

120-
/// Functor class suitable for use as a \c LookupConformanceFn to look up a
121-
/// conformance in a \c SubstitutionMap.
122-
class LookUpConformanceInSubstitutionMap {
123-
const SubstitutionMap &Subs;
124-
public:
125-
explicit LookUpConformanceInSubstitutionMap(const SubstitutionMap &Subs)
126-
: Subs(Subs) {}
127-
128-
Optional<ProtocolConformanceRef>
129-
operator()(CanType dependentType,
130-
Type conformingReplacementType,
131-
ProtocolType *conformedProtocol) const;
132-
};
133-
134112
/// Functor class suitable for use as a \c LookupConformanceFn that provides
135113
/// only abstract conformances for generic types. Asserts that the replacement
136114
/// type is an opaque generic type.
@@ -314,7 +292,7 @@ class Type {
314292
/// \param options Options that affect the substitutions.
315293
///
316294
/// \returns the substituted type, or a null type if an error occurred.
317-
Type subst(const SubstitutionMap &substitutions,
295+
Type subst(SubstitutionMap substitutions,
318296
SubstOptions options = None) const;
319297

320298
/// Replace references to substitutable types with new, concrete types and

include/swift/AST/Types.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,7 @@ class NameAliasType final
16051605
friend TrailingObjects;
16061606

16071607
NameAliasType(TypeAliasDecl *typealias, Type parent,
1608-
const SubstitutionMap &substitutions, Type underlying,
1608+
SubstitutionMap substitutions, Type underlying,
16091609
RecursiveTypeProperties properties);
16101610

16111611
size_t numTrailingObjects(OverloadToken<Type>) const {
@@ -1623,7 +1623,7 @@ class NameAliasType final
16231623

16241624
public:
16251625
static NameAliasType *get(TypeAliasDecl *typealias, Type parent,
1626-
const SubstitutionMap &substitutions,
1626+
SubstitutionMap substitutions,
16271627
Type underlying);
16281628

16291629
/// \brief Returns the declaration that declares this type.
@@ -1660,7 +1660,7 @@ class NameAliasType final
16601660
void Profile(llvm::FoldingSetNodeID &id) const;
16611661

16621662
static void Profile(llvm::FoldingSetNodeID &id, TypeAliasDecl *typealias,
1663-
Type parent, const SubstitutionMap &substitutions,
1663+
Type parent, SubstitutionMap substitutions,
16641664
Type underlying);
16651665

16661666
// Implement isa/cast/dyncast/etc.
@@ -3057,7 +3057,7 @@ class GenericFunctionType final : public AnyFunctionType,
30573057

30583058
/// Substitute the given generic arguments into this generic
30593059
/// function type and return the resulting non-generic type.
3060-
FunctionType *substGenericArgs(const SubstitutionMap &subs);
3060+
FunctionType *substGenericArgs(SubstitutionMap subs);
30613061

30623062
/// Substitute the given generic arguments into this generic
30633063
/// function type using the given substitution and conformance lookup
@@ -4033,7 +4033,7 @@ class SILFunctionType final : public TypeBase, public llvm::FoldingSetNode,
40334033
isABICompatibleWith(CanSILFunctionType other) const;
40344034

40354035
CanSILFunctionType substGenericArgs(SILModule &silModule,
4036-
const SubstitutionMap &subs);
4036+
SubstitutionMap subs);
40374037
CanSILFunctionType substGenericArgs(SILModule &silModule,
40384038
TypeSubstitutionFn subs,
40394039
LookupConformanceFn conformances);

include/swift/SIL/SILType.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ class SILType {
439439
///
440440
/// Only call this with function types!
441441
SILType substGenericArgs(SILModule &M,
442-
const SubstitutionMap &SubMap) const;
442+
SubstitutionMap SubMap) const;
443443

444444
/// If the original type is generic, pass the signature as genericSig.
445445
///
@@ -450,7 +450,7 @@ class SILType {
450450
LookupConformanceFn conformances,
451451
CanGenericSignature genericSig=CanGenericSignature()) const;
452452

453-
SILType subst(SILModule &silModule, const SubstitutionMap &subs) const;
453+
SILType subst(SILModule &silModule, SubstitutionMap subs) const;
454454

455455
/// Return true if this type references a "ref" type that has a single pointer
456456
/// representation. Class existentials do not always qualify.

include/swift/SILOptimizer/Utils/Generics.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ReabstractionInfo {
114114

115115
// Create a new substituted type with the updated signature.
116116
CanSILFunctionType createSubstitutedType(SILFunction *OrigF,
117-
const SubstitutionMap &SubstMap,
117+
SubstitutionMap SubstMap,
118118
bool HasUnboundGenericParams);
119119

120120
void createSubstitutedAndSpecializedTypes();

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2874,7 +2874,7 @@ StringRef ASTContext::getSwiftName(KnownFoundationEntity kind) {
28742874
//===----------------------------------------------------------------------===//
28752875

28762876
NameAliasType::NameAliasType(TypeAliasDecl *typealias, Type parent,
2877-
const SubstitutionMap &substitutions,
2877+
SubstitutionMap substitutions,
28782878
Type underlying,
28792879
RecursiveTypeProperties properties)
28802880
: SugarType(TypeKind::NameAlias, underlying, properties),
@@ -2897,7 +2897,7 @@ NameAliasType::NameAliasType(TypeAliasDecl *typealias, Type parent,
28972897
}
28982898

28992899
NameAliasType *NameAliasType::get(TypeAliasDecl *typealias, Type parent,
2900-
const SubstitutionMap &substitutions,
2900+
SubstitutionMap substitutions,
29012901
Type underlying) {
29022902
// Compute the recursive properties.
29032903
//
@@ -2950,7 +2950,7 @@ void NameAliasType::Profile(llvm::FoldingSetNodeID &id) const {
29502950
void NameAliasType::Profile(
29512951
llvm::FoldingSetNodeID &id,
29522952
TypeAliasDecl *typealias,
2953-
Type parent, const SubstitutionMap &substitutions,
2953+
Type parent, SubstitutionMap substitutions,
29542954
Type underlying) {
29552955
id.AddPointer(typealias);
29562956
id.AddPointer(parent.getPointer());

lib/AST/SubstitutionMap.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ SubstitutionMap SubstitutionMap::mapReplacementTypesOutOfContext() const {
415415
return subst(MapTypeOutOfContext(), MakeAbstractConformanceForGenericType());
416416
}
417417

418-
SubstitutionMap SubstitutionMap::subst(const SubstitutionMap &subMap) const {
418+
SubstitutionMap SubstitutionMap::subst(SubstitutionMap subMap) const {
419419
return subst(QuerySubstitutionMap{subMap},
420420
LookUpConformanceInSubstitutionMap(subMap));
421421
}
@@ -530,8 +530,8 @@ SubstitutionMap::getOverrideSubstitutions(const ClassDecl *baseClass,
530530
}
531531

532532
SubstitutionMap
533-
SubstitutionMap::combineSubstitutionMaps(const SubstitutionMap &firstSubMap,
534-
const SubstitutionMap &secondSubMap,
533+
SubstitutionMap::combineSubstitutionMaps(SubstitutionMap firstSubMap,
534+
SubstitutionMap secondSubMap,
535535
CombineSubstitutionMaps how,
536536
unsigned firstDepthOrIndex,
537537
unsigned secondDepthOrIndex,

lib/AST/Type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2762,7 +2762,7 @@ bool AnyFunctionType::isCanonicalFunctionInputType(Type input) {
27622762
}
27632763

27642764
FunctionType *
2765-
GenericFunctionType::substGenericArgs(const SubstitutionMap &subs) {
2765+
GenericFunctionType::substGenericArgs(SubstitutionMap subs) {
27662766
Type input = getInput().subst(subs);
27672767
Type result = getResult().subst(subs);
27682768
return FunctionType::get(input, result, getExtInfo());
@@ -3116,7 +3116,7 @@ static Type substType(Type derivedType,
31163116
});
31173117
}
31183118

3119-
Type Type::subst(const SubstitutionMap &substitutions,
3119+
Type Type::subst(SubstitutionMap substitutions,
31203120
SubstOptions options) const {
31213121
return substType(*this,
31223122
QuerySubstitutionMap{substitutions},

lib/IRGen/GenProto.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2855,7 +2855,7 @@ llvm::Value *irgen::emitWitnessTableRef(IRGenFunction &IGF,
28552855
}
28562856

28572857
static CanType getSubstSelfType(CanSILFunctionType origFnType,
2858-
const SubstitutionMap &subs) {
2858+
SubstitutionMap subs) {
28592859
// Grab the apparent 'self' type. If there isn't a 'self' type,
28602860
// we're not going to try to access this anyway.
28612861
assert(!origFnType->getParameters().empty());
@@ -2896,11 +2896,11 @@ namespace {
28962896
CanSILFunctionType polyFn)
28972897
: PolymorphicConvention(IGF.IGM, polyFn), IGF(IGF) {}
28982898

2899-
void emit(const SubstitutionMap &subs,
2899+
void emit(SubstitutionMap subs,
29002900
WitnessMetadata *witnessMetadata, Explosion &out);
29012901

29022902
private:
2903-
void emitEarlySources(const SubstitutionMap &subs, Explosion &out) {
2903+
void emitEarlySources(SubstitutionMap subs, Explosion &out) {
29042904
for (auto &source : getSources()) {
29052905
switch (source.getKind()) {
29062906
// Already accounted for in the parameters.
@@ -2929,13 +2929,13 @@ namespace {
29292929
/// Pass all the arguments necessary for the given function.
29302930
void irgen::emitPolymorphicArguments(IRGenFunction &IGF,
29312931
CanSILFunctionType origFnType,
2932-
const SubstitutionMap &subs,
2932+
SubstitutionMap subs,
29332933
WitnessMetadata *witnessMetadata,
29342934
Explosion &out) {
29352935
EmitPolymorphicArguments(IGF, origFnType).emit(subs, witnessMetadata, out);
29362936
}
29372937

2938-
void EmitPolymorphicArguments::emit(const SubstitutionMap &subs,
2938+
void EmitPolymorphicArguments::emit(SubstitutionMap subs,
29392939
WitnessMetadata *witnessMetadata,
29402940
Explosion &out) {
29412941
// Add all the early sources.
@@ -2980,7 +2980,7 @@ void EmitPolymorphicArguments::emit(const SubstitutionMap &subs,
29802980
NecessaryBindings
29812981
NecessaryBindings::forFunctionInvocations(IRGenModule &IGM,
29822982
CanSILFunctionType origType,
2983-
const SubstitutionMap &subs) {
2983+
SubstitutionMap subs) {
29842984
NecessaryBindings bindings;
29852985

29862986
// Bail out early if we don't have polymorphic parameters.
@@ -3066,7 +3066,7 @@ GenericTypeRequirements::GenericTypeRequirements(IRGenModule &IGM,
30663066

30673067
void
30683068
GenericTypeRequirements::enumerateFulfillments(IRGenModule &IGM,
3069-
const SubstitutionMap &subs,
3069+
SubstitutionMap subs,
30703070
FulfillmentCallback callback) {
30713071
if (empty()) return;
30723072

@@ -3084,7 +3084,7 @@ GenericTypeRequirements::enumerateFulfillments(IRGenModule &IGM,
30843084
}
30853085

30863086
void GenericTypeRequirements::emitInitOfBuffer(IRGenFunction &IGF,
3087-
const SubstitutionMap &subs,
3087+
SubstitutionMap subs,
30883088
Address buffer) {
30893089
if (Requirements.empty()) return;
30903090

@@ -3128,7 +3128,7 @@ irgen::emitGenericRequirementFromSubstitutions(IRGenFunction &IGF,
31283128
CanGenericSignature generics,
31293129
ModuleDecl &module,
31303130
GenericRequirement requirement,
3131-
const SubstitutionMap &subs) {
3131+
SubstitutionMap subs) {
31323132
CanType depTy = requirement.TypeParameter;
31333133
CanType argType = depTy.subst(subs)->getCanonicalType();
31343134

0 commit comments

Comments
 (0)