Skip to content

Commit fae01d9

Browse files
committed
AST: Remove ModuleDecl parameter from more places
1 parent b7117aa commit fae01d9

File tree

107 files changed

+288
-420
lines changed

Some content is hidden

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

107 files changed

+288
-420
lines changed

include/swift/AST/Type.h

+5-11
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ using LookupConformanceFn = llvm::function_ref<GenericFunction>;
9797
/// Functor class suitable for use as a \c LookupConformanceFn to look up a
9898
/// conformance through a module.
9999
class LookUpConformanceInModule {
100-
ModuleDecl *M;
101100
public:
102-
explicit LookUpConformanceInModule(ModuleDecl *M)
103-
: M(M) {}
101+
explicit LookUpConformanceInModule() {}
104102

105103
ProtocolConformanceRef operator()(CanType dependentType,
106104
Type conformingReplacementType,
@@ -120,16 +118,12 @@ class MakeAbstractConformanceForGenericType {
120118
/// Functor class suitable for use as a \c LookupConformanceFn that fetches
121119
/// conformances from a generic signature.
122120
class LookUpConformanceInSignature {
123-
const GenericSignatureImpl *Sig;
124121
public:
125-
LookUpConformanceInSignature(const GenericSignatureImpl *Sig)
126-
: Sig(Sig) {
127-
assert(Sig && "Cannot lookup conformance in null signature!");
128-
}
122+
LookUpConformanceInSignature(const GenericSignatureImpl *Sig) {}
129123

130-
ProtocolConformanceRef operator()(CanType dependentType,
131-
Type conformingReplacementType,
132-
ProtocolDecl *conformedProtocol) const;
124+
ProtocolConformanceRef operator()(CanType dependentType,
125+
Type conformingReplacementType,
126+
ProtocolDecl *conformedProtocol) const;
133127
};
134128

135129
/// Flags that can be passed when substituting into a type.

include/swift/AST/Types.h

+5-8
Original file line numberDiff line numberDiff line change
@@ -1309,8 +1309,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
13091309
/// \param genericEnv If non-null and the type is nested inside of a
13101310
/// generic function, generic parameters of the outer context are
13111311
/// mapped to context archetypes of this generic environment.
1312-
SubstitutionMap getContextSubstitutionMap(ModuleDecl *module,
1313-
const DeclContext *dc,
1312+
SubstitutionMap getContextSubstitutionMap(const DeclContext *dc,
13141313
GenericEnvironment *genericEnv=nullptr);
13151314

13161315
/// Deprecated version of the above.
@@ -1322,8 +1321,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
13221321
///
13231322
/// \param genericEnv If non-null, generic parameters of the member are
13241323
/// mapped to context archetypes of this generic environment.
1325-
SubstitutionMap getMemberSubstitutionMap(ModuleDecl *module,
1326-
const ValueDecl *member,
1324+
SubstitutionMap getMemberSubstitutionMap(const ValueDecl *member,
13271325
GenericEnvironment *genericEnv=nullptr);
13281326

13291327
/// Deprecated version of the above.
@@ -1340,7 +1338,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
13401338
/// \param member The property whose type we are substituting.
13411339
///
13421340
/// \returns The resulting property type.
1343-
Type getTypeOfMember(ModuleDecl *module, const VarDecl *member);
1341+
Type getTypeOfMember(const VarDecl *member);
13441342

13451343
/// Retrieve the type of the given member as seen through the given base
13461344
/// type, substituting generic arguments where necessary.
@@ -1371,8 +1369,7 @@ class alignas(1 << TypeAlignInBits) TypeBase
13711369
/// method's generic parameters.
13721370
///
13731371
/// \returns The resulting member type.
1374-
Type getTypeOfMember(ModuleDecl *module, const ValueDecl *member,
1375-
Type memberType);
1372+
Type getTypeOfMember(const ValueDecl *member, Type memberType);
13761373

13771374
/// Get the type of a superclass member as seen from the subclass,
13781375
/// substituting generic parameters, dynamic Self return, and the
@@ -7075,7 +7072,7 @@ class DependentMemberType : public TypeBase {
70757072
/// Substitute the base type, looking up our associated type in it if it is
70767073
/// non-dependent. Returns null if the member could not be found in the new
70777074
/// base.
7078-
Type substBaseType(ModuleDecl *M, Type base);
7075+
Type substBaseType(Type base);
70797076

70807077
/// Substitute the base type, looking up our associated type in it if it is
70817078
/// non-dependent. Returns null if the member could not be found in the new

include/swift/SIL/TypeSubstCloner.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ class TypeSubstCloner : public SILClonerWithScopes<ImplClass> {
331331
remappedOrigFnType->getDifferentiabilityResultIndices(),
332332
dfei->getDerivativeFunctionKind(),
333333
getBuilder().getModule().Types,
334-
LookUpConformanceInModule(SwiftMod))
334+
LookUpConformanceInModule())
335335
->getWithoutDifferentiability();
336336
SILType remappedDerivativeFnType = getOpType(dfei->getType());
337337
// If remapped derivative type and derivative remapped type are equal, do

include/swift/SILOptimizer/Analysis/DifferentiableActivityAnalysis.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,7 @@ class DifferentiableActivityInfo {
139139
type->mapTypeOutOfContext());
140140
}
141141
// Look up conformance in the current module.
142-
auto lookupConformance =
143-
LookUpConformanceInModule(getFunction().getModule().getSwiftModule());
142+
auto lookupConformance = LookUpConformanceInModule();
144143
return type->getAutoDiffTangentSpace(lookupConformance).has_value();
145144
}
146145

include/swift/SILOptimizer/OptimizerBridgingImpl.h

+1-2
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,7 @@ void BridgedPassContext::loadFunction(BridgedFunction function, bool loadCallees
416416
BridgedSubstitutionMap BridgedPassContext::getContextSubstitutionMap(BridgedType type) const {
417417
swift::SILType ty = type.unbridged();
418418
auto *ntd = ty.getASTType()->getAnyNominal();
419-
auto *mod = invocation->getPassManager()->getModule()->getSwiftModule();
420-
return ty.getASTType()->getContextSubstitutionMap(mod, ntd);
419+
return ty.getASTType()->getContextSubstitutionMap(ntd);
421420
}
422421

423422
BridgedType BridgedPassContext::getBuiltinIntegerType(SwiftInt bitWidth) const {

lib/AST/ASTContext.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1561,7 +1561,7 @@ ConcreteDeclRef ASTContext::getRegexInitDecl(Type regexType) const {
15611561
results);
15621562
assert(results.size() == 1);
15631563
auto *foundDecl = cast<ConstructorDecl>(results[0]);
1564-
auto subs = regexType->getMemberSubstitutionMap(spModule, foundDecl);
1564+
auto subs = regexType->getMemberSubstitutionMap(foundDecl);
15651565
return ConcreteDeclRef(foundDecl, subs);
15661566
}
15671567

lib/AST/ASTDemangler.cpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ Type ASTBuilder::createTypeAliasType(GenericTypeDecl *decl, Type parent) {
199199
return declaredType;
200200

201201
auto *dc = aliasDecl->getDeclContext();
202-
auto subs = parent->getContextSubstitutionMap(dc->getParentModule(), dc);
202+
auto subs = parent->getContextSubstitutionMap(dc);
203203

204204
return declaredType.subst(subs);
205205
}
@@ -239,7 +239,7 @@ Type ASTBuilder::createBoundGenericType(GenericTypeDecl *decl,
239239
// Build a SubstitutionMap.
240240
auto genericSig = nominalDecl->getGenericSignature();
241241
auto subs = createSubstitutionMapFromGenericArgs(
242-
genericSig, args, LookUpConformanceInModule(decl->getParentModule()));
242+
genericSig, args, LookUpConformanceInModule());
243243
if (!subs)
244244
return Type();
245245
auto origType = nominalDecl->getDeclaredInterfaceType();
@@ -278,7 +278,7 @@ Type ASTBuilder::resolveOpaqueType(NodePointer opaqueDescriptor,
278278

279279
SubstitutionMap subs = createSubstitutionMapFromGenericArgs(
280280
opaqueDecl->getGenericSignature(), allArgs,
281-
LookUpConformanceInModule(parentModule));
281+
LookUpConformanceInModule());
282282
Type interfaceType = opaqueDecl->getOpaqueGenericParams()[ordinal];
283283
return OpaqueTypeArchetypeType::get(opaqueDecl, interfaceType, subs);
284284
}
@@ -318,11 +318,9 @@ Type ASTBuilder::createBoundGenericType(GenericTypeDecl *decl,
318318
substTy;
319319
}
320320

321-
// FIXME: This is the wrong module
322-
auto *moduleDecl = decl->getParentModule();
323321
auto subMap = SubstitutionMap::get(genericSig,
324322
QueryTypeSubstitutionMap{subs},
325-
LookUpConformanceInModule(moduleDecl));
323+
LookUpConformanceInModule());
326324
if (!subMap)
327325
return Type();
328326

lib/AST/ASTMangler.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1969,9 +1969,8 @@ void ASTMangler::appendRetroactiveConformances(SubstitutionMap subMap,
19691969
void ASTMangler::appendRetroactiveConformances(Type type, GenericSignature sig) {
19701970
// Dig out the substitution map to use.
19711971
SubstitutionMap subMap;
1972-
ModuleDecl *module;
1972+
19731973
if (auto typeAlias = dyn_cast<TypeAliasType>(type.getPointer())) {
1974-
module = Mod ? Mod : typeAlias->getDecl()->getModuleContext();
19751974
subMap = typeAlias->getSubstitutionMap();
19761975
} else {
19771976
if (type->hasUnboundGenericType())
@@ -1980,8 +1979,7 @@ void ASTMangler::appendRetroactiveConformances(Type type, GenericSignature sig)
19801979
auto nominal = type->getAnyNominal();
19811980
if (!nominal) return;
19821981

1983-
module = Mod ? Mod : nominal->getModuleContext();
1984-
subMap = type->getContextSubstitutionMap(module, nominal);
1982+
subMap = type->getContextSubstitutionMap(nominal);
19851983
}
19861984

19871985
appendRetroactiveConformances(subMap, sig);

lib/AST/ASTPrinter.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -861,13 +861,12 @@ class PrintAST : public ASTVisitor<PrintAST> {
861861

862862
Type getTransformedType(Type T) {
863863
if (CurrentType && Current && CurrentType->mayHaveMembers()) {
864-
auto *M = Current->getDeclContext()->getParentModule();
865864
SubstitutionMap subMap;
866865

867866
if (auto *NTD = dyn_cast<NominalTypeDecl>(Current))
868-
subMap = CurrentType->getContextSubstitutionMap(M, NTD);
867+
subMap = CurrentType->getContextSubstitutionMap(NTD);
869868
else if (auto *ED = dyn_cast<ExtensionDecl>(Current))
870-
subMap = CurrentType->getContextSubstitutionMap(M, ED);
869+
subMap = CurrentType->getContextSubstitutionMap(ED);
871870
else {
872871
Decl *subTarget = Current;
873872
if (isa<ParamDecl>(Current)) {
@@ -876,7 +875,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
876875
subTarget = FD;
877876
}
878877
subMap = CurrentType->getMemberSubstitutionMap(
879-
M, cast<ValueDecl>(subTarget));
878+
cast<ValueDecl>(subTarget));
880879
}
881880

882881
T = T.subst(subMap, SubstFlags::DesugarMemberTypes);
@@ -1135,7 +1134,7 @@ class PrintAST : public ASTVisitor<PrintAST> {
11351134
if (auto *NTD = dyn_cast<NominalTypeDecl>(D)) {
11361135
assert(Options.CurrentModule);
11371136
auto Subs = CurrentType->getContextSubstitutionMap(
1138-
Options.CurrentModule, NTD->getDeclContext());
1137+
NTD->getDeclContext());
11391138
setCurrentType(NTD->getDeclaredInterfaceType().subst(Subs));
11401139
}
11411140
}
@@ -1836,8 +1835,7 @@ void PrintAST::printSingleDepthOfGenericSignature(
18361835
if (CurrentType && Current) {
18371836
if (!CurrentType->isExistentialType()) {
18381837
auto *DC = Current->getInnermostDeclContext()->getInnermostTypeContext();
1839-
M = DC->getParentModule();
1840-
subMap = CurrentType->getContextSubstitutionMap(M, DC);
1838+
subMap = CurrentType->getContextSubstitutionMap(DC);
18411839
typeContextDepth = subMap.getGenericSignature().getNextDepth();
18421840
}
18431841
}

lib/AST/AutoDiff.cpp

+5-7
Original file line numberDiff line numberDiff line change
@@ -595,9 +595,8 @@ TangentPropertyInfo TangentStoredPropertyRequest::evaluate(
595595
"Expected a stored property or a property-wrapped property");
596596
auto *parentDC = originalField->getDeclContext();
597597
assert(parentDC->isTypeContext());
598-
auto *moduleDecl = originalField->getModuleContext();
599598
auto parentTan =
600-
baseType->getAutoDiffTangentSpace(LookUpConformanceInModule(moduleDecl));
599+
baseType->getAutoDiffTangentSpace(LookUpConformanceInModule());
601600
// Error if parent nominal type does not conform to `Differentiable`.
602601
if (!parentTan) {
603602
return TangentPropertyInfo(
@@ -609,17 +608,16 @@ TangentPropertyInfo TangentStoredPropertyRequest::evaluate(
609608
TangentPropertyInfo::Error::Kind::NoDerivativeOriginalProperty);
610609
}
611610
// Error if original property's type does not conform to `Differentiable`.
612-
auto originalFieldType = baseType->getTypeOfMember(
613-
originalField->getModuleContext(), originalField);
611+
auto originalFieldType = baseType->getTypeOfMember(originalField);
614612
auto originalFieldTan = originalFieldType->getAutoDiffTangentSpace(
615-
LookUpConformanceInModule(moduleDecl));
613+
LookUpConformanceInModule());
616614
if (!originalFieldTan) {
617615
return TangentPropertyInfo(
618616
TangentPropertyInfo::Error::Kind::OriginalPropertyNotDifferentiable);
619617
}
620618
// Get the parent `TangentVector` type.
621619
auto parentTanType =
622-
baseType->getAutoDiffTangentSpace(LookUpConformanceInModule(moduleDecl))
620+
baseType->getAutoDiffTangentSpace(LookUpConformanceInModule())
623621
->getType();
624622
auto *parentTanStruct = parentTanType->getStructOrBoundGenericStruct();
625623
// Error if parent `TangentVector` is not a struct.
@@ -651,7 +649,7 @@ TangentPropertyInfo TangentStoredPropertyRequest::evaluate(
651649
// `TangentVector` type.
652650
auto originalFieldTanType = originalFieldTan->getType();
653651
auto tanFieldType =
654-
parentTanType->getTypeOfMember(tanField->getModuleContext(), tanField);
652+
parentTanType->getTypeOfMember(tanField);
655653
if (!originalFieldTanType->isEqual(tanFieldType)) {
656654
return TangentPropertyInfo(
657655
TangentPropertyInfo::Error::Kind::TangentPropertyWrongType,

lib/AST/Builtins.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1383,10 +1383,10 @@ static ValueDecl *getAutoDiffApplyDerivativeFunction(
13831383
Context, SmallBitVector(diffFnType->getNumParams(), true));
13841384
// Generator for the resultant function type, i.e. the AD derivative function.
13851385
BuiltinFunctionBuilder::LambdaGenerator resultGen{
1386-
[=, &Context](BuiltinFunctionBuilder &builder) -> Type {
1386+
[=](BuiltinFunctionBuilder &builder) -> Type {
13871387
auto derivativeFnTy = diffFnType->getAutoDiffDerivativeFunctionType(
13881388
paramIndices, kind,
1389-
LookUpConformanceInModule(Context.TheBuiltinModule));
1389+
LookUpConformanceInModule());
13901390
return derivativeFnTy->getResult();
13911391
}};
13921392
builder.addParameter(firstArgGen);

lib/AST/ConformanceLookup.cpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,7 @@ static ProtocolConformanceRef getBuiltinTupleTypeConformance(
239239
}
240240

241241
auto *conformance = cast<NormalProtocolConformance>(conformances.front());
242-
auto subMap = type->getContextSubstitutionMap(protocol->getParentModule(),
243-
conformance->getDeclContext());
242+
auto subMap = type->getContextSubstitutionMap(conformance->getDeclContext());
244243

245244
// TODO: labels
246245
auto *specialized = ctx.getSpecializedConformance(type, conformance, subMap);
@@ -728,8 +727,7 @@ LookupConformanceInModuleRequest::evaluate(
728727
conformanceDC = conformanceDC->getSelfNominalTypeDecl();
729728
}
730729

731-
auto subMap = type->getContextSubstitutionMap(protocol->getParentModule(),
732-
conformanceDC);
730+
auto subMap = type->getContextSubstitutionMap(conformanceDC);
733731
return ProtocolConformanceRef(
734732
ctx.getSpecializedConformance(type, normalConf, subMap));
735733
}

lib/AST/ExistentialGeneralization.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,7 @@ class Generalizer : public CanTypeVisitor<Generalizer, Type> {
186186
/// Generalize the generic arguments of the given generic type.s
187187
Type generalizeGenericArguments(NominalTypeDecl *decl, CanType type) {
188188
assert(decl->isGenericContext());
189-
auto origSubs = type->getContextSubstitutionMap(decl->getModuleContext(),
190-
decl);
189+
auto origSubs = type->getContextSubstitutionMap(decl);
191190

192191
// Generalize all of the arguments.
193192
auto origArgs = origSubs.getReplacementTypes();

lib/AST/ProtocolConformance.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -692,8 +692,7 @@ RootProtocolConformance::getWitnessDeclRef(ValueDecl *requirement) const {
692692
// witness's parent. Don't use witness.getSubstitutions(), which
693693
// are written in terms of the witness thunk signature.
694694
auto subs =
695-
getType()->getContextSubstitutionMap(getDeclContext()->getParentModule(),
696-
witnessDecl->getDeclContext());
695+
getType()->getContextSubstitutionMap(witnessDecl->getDeclContext());
697696
return ConcreteDeclRef(witness.getDecl(), subs);
698697
}
699698

@@ -756,20 +755,17 @@ void SpecializedProtocolConformance::computeConditionalRequirements() const {
756755
// Substitute the conditional requirements so that they're phrased in
757756
// terms of the specialized types, not the conformance-declaring decl's
758757
// types.
759-
ModuleDecl *module;
760758
SubstitutionMap subMap;
761759
if (auto nominal = GenericConformance->getType()->getAnyNominal()) {
762-
module = nominal->getModuleContext();
763-
subMap = getType()->getContextSubstitutionMap(module, nominal);
760+
subMap = getType()->getContextSubstitutionMap(nominal);
764761
} else {
765-
module = getProtocol()->getModuleContext();
766762
subMap = getSubstitutionMap();
767763
}
768764

769765
SmallVector<Requirement, 4> newReqs;
770766
for (auto oldReq : *parentCondReqs) {
771767
auto newReq = oldReq.subst(QuerySubstitutionMap{subMap},
772-
LookUpConformanceInModule(module));
768+
LookUpConformanceInModule());
773769
newReqs.push_back(newReq);
774770
}
775771
auto &ctxt = getProtocol()->getASTContext();

lib/AST/Requirement.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ CheckRequirementsResult swift::checkRequirements(
332332
SmallVector<Requirement, 4> substReqs;
333333
for (auto req : requirements) {
334334
substReqs.push_back(req.subst(substitutions,
335-
LookUpConformanceInModule(module), options));
335+
LookUpConformanceInModule(), options));
336336
}
337337

338338
return checkRequirements(substReqs);

lib/AST/RequirementEnvironment.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ RequirementEnvironment::RequirementEnvironment(
125125
ProtocolConformance *specialized = conformance;
126126
if (conformance && conformance->getGenericSignature()) {
127127
auto concreteSubs =
128-
substConcreteType->getContextSubstitutionMap(
129-
conformanceDC->getParentModule(), conformanceDC);
128+
substConcreteType->getContextSubstitutionMap(conformanceDC);
130129
specialized =
131130
ctx.getSpecializedConformance(substConcreteType,
132131
cast<NormalProtocolConformance>(conformance),

lib/AST/RequirementMachine/ConcreteContraction.cpp

+3-5
Original file line numberDiff line numberDiff line change
@@ -280,13 +280,12 @@ ConcreteContraction::substTypeParameterRec(Type type, Position position) const {
280280
// type's conformance to the associated type's protocol.
281281
if (auto *assocType = memberType->getAssocType()) {
282282
auto *proto = assocType->getProtocol();
283-
auto *module = proto->getParentModule();
284283

285284
// The 'Sendable' protocol does not declare any associated types, so the
286285
// 'allowMissing' value here is actually irrelevant.
287286
auto conformance = ((*substBaseType)->isTypeParameter()
288287
? ProtocolConformanceRef(proto)
289-
: module->lookupConformance(
288+
: ModuleDecl::lookupConformance(
290289
*substBaseType, proto,
291290
/*allowMissing=*/false));
292291

@@ -307,7 +306,7 @@ ConcreteContraction::substTypeParameterRec(Type type, Position position) const {
307306

308307
return assocType->getDeclaredInterfaceType()
309308
->castTo<DependentMemberType>()
310-
->substBaseType(module, *substBaseType);
309+
->substBaseType(*substBaseType);
311310
}
312311

313312
// An unresolved DependentMemberType stores an identifier. Handle this
@@ -328,8 +327,7 @@ ConcreteContraction::substTypeParameterRec(Type type, Position position) const {
328327

329328
// Substitute the base type into the member type.
330329
auto *dc = typeDecl->getDeclContext();
331-
auto subMap = (*substBaseType)->getContextSubstitutionMap(
332-
dc->getParentModule(), dc);
330+
auto subMap = (*substBaseType)->getContextSubstitutionMap(dc);
333331
return typeDecl->getDeclaredInterfaceType().subst(subMap);
334332
}
335333

0 commit comments

Comments
 (0)