Skip to content

Commit 4f93125

Browse files
authored
Merge pull request #6312 from jckarter/no-module-in-map-type-context
2 parents b482c7f + 57d9ad0 commit 4f93125

File tree

13 files changed

+48
-47
lines changed

13 files changed

+48
-47
lines changed

include/swift/AST/ArchetypeBuilder.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,7 @@ class ArchetypeBuilder {
315315
static Type mapTypeOutOfContext(const DeclContext *dc, Type type);
316316

317317
/// Map a contextual type to an interface type.
318-
static Type mapTypeOutOfContext(ModuleDecl *M,
319-
GenericEnvironment *genericEnv,
318+
static Type mapTypeOutOfContext(GenericEnvironment *genericEnv,
320319
Type type);
321320

322321
/// \brief Dump all of the requirements, both specified and inferred.

include/swift/AST/GenericEnvironment.h

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

199199
/// Map a contextual type to an interface type.
200-
Type mapTypeOutOfContext(ModuleDecl *M, Type type) const;
200+
Type mapTypeOutOfContext(Type type) const;
201201

202202
/// Map an interface type to a contextual type.
203203
Type mapTypeIntoContext(ModuleDecl *M, Type type) const;

include/swift/AST/Type.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,17 @@ class LookUpConformanceInSubstitutionMap {
105105
ProtocolType *conformedProtocol) const;
106106
};
107107

108+
/// Functor class suitable for use as a \c LookupConformanceFn that provides
109+
/// only abstract conformances for generic types. Asserts that the replacement
110+
/// type is an opaque generic type.
111+
class MakeAbstractConformanceForGenericType {
112+
public:
113+
Optional<ProtocolConformanceRef>
114+
operator()(CanType dependentType,
115+
Type conformingReplacementType,
116+
ProtocolType *conformedProtocol) const;
117+
};
118+
108119
/// Flags that can be passed when substituting into a type.
109120
enum class SubstFlags {
110121
/// If a type cannot be produced because some member type is

lib/AST/ArchetypeBuilder.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,7 @@ auto ArchetypeBuilder::PotentialArchetype::getNestedType(
423423

424424
// Map the type out of its context.
425425
if (auto genericEnv = alias->getGenericEnvironmentOfContext()) {
426-
type = genericEnv->mapTypeOutOfContext(alias->getModuleContext(),
427-
type);
426+
type = genericEnv->mapTypeOutOfContext(type);
428427
}
429428

430429
if (auto existingPA = builder.resolveArchetype(type)) {
@@ -688,8 +687,7 @@ void ArchetypeType::resolveNestedType(
688687
auto &builder = *genericEnv->getArchetypeBuilder();
689688

690689
Type interfaceType =
691-
genericEnv->mapTypeOutOfContext(&builder.getModule(),
692-
const_cast<ArchetypeType *>(this));
690+
genericEnv->mapTypeOutOfContext(const_cast<ArchetypeType *>(this));
693691
auto parentPA = builder.resolveArchetype(interfaceType);
694692
auto memberPA = parentPA->getNestedType(nested.first, builder);
695693
auto result = memberPA->getTypeInContext(builder, genericEnv);
@@ -1975,14 +1973,12 @@ Type ArchetypeBuilder::mapTypeIntoContext(ModuleDecl *M,
19751973

19761974
Type
19771975
ArchetypeBuilder::mapTypeOutOfContext(const DeclContext *dc, Type type) {
1978-
return mapTypeOutOfContext(dc->getParentModule(),
1979-
dc->getGenericEnvironmentOfContext(),
1976+
return mapTypeOutOfContext(dc->getGenericEnvironmentOfContext(),
19801977
type);
19811978
}
19821979

19831980
Type
1984-
ArchetypeBuilder::mapTypeOutOfContext(ModuleDecl *M,
1985-
GenericEnvironment *env,
1981+
ArchetypeBuilder::mapTypeOutOfContext(GenericEnvironment *env,
19861982
Type type) {
19871983
auto canType = type->getCanonicalType();
19881984
assert(!canType->hasTypeParameter() && "already have an interface type");
@@ -1991,7 +1987,7 @@ ArchetypeBuilder::mapTypeOutOfContext(ModuleDecl *M,
19911987

19921988
assert(env && "dependent type in non-generic context");
19931989

1994-
return env->mapTypeOutOfContext(M, type);
1990+
return env->mapTypeOutOfContext(type);
19951991
}
19961992

19971993
void ArchetypeBuilder::addGenericSignature(GenericSignature *sig) {

lib/AST/DeclContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ Type DeclContext::mapTypeIntoContext(Type type) const {
303303

304304
Type DeclContext::mapTypeOutOfContext(Type type) const {
305305
if (auto genericEnv = getGenericEnvironmentOfContext())
306-
return genericEnv->mapTypeOutOfContext(getParentModule(), type);
306+
return genericEnv->mapTypeOutOfContext(type);
307307

308308
return type;
309309
}

lib/AST/GenericEnvironment.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ bool GenericEnvironment::containsPrimaryArchetype(
142142
QueryArchetypeToInterfaceSubstitutions(this)(archetype));
143143
}
144144

145-
Type GenericEnvironment::mapTypeOutOfContext(ModuleDecl *M, Type type) const {
145+
Type GenericEnvironment::mapTypeOutOfContext(Type type) const {
146146
type = type.subst(QueryArchetypeToInterfaceSubstitutions(this),
147-
LookUpConformanceInModule(M),
147+
MakeAbstractConformanceForGenericType(),
148148
SubstFlags::AllowLoweredTypes);
149149
assert(!type->hasArchetype() && "not fully substituted");
150150
return type;

lib/AST/Type.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2892,6 +2892,16 @@ LookUpConformanceInSubstitutionMap::operator()(CanType dependentType,
28922892
return Subs.lookupConformance(dependentType, conformedProtocol->getDecl());
28932893
}
28942894

2895+
Optional<ProtocolConformanceRef>
2896+
MakeAbstractConformanceForGenericType::operator()(CanType dependentType,
2897+
Type conformingReplacementType,
2898+
ProtocolType *conformedProtocol) const {
2899+
assert((conformingReplacementType->is<SubstitutableType>()
2900+
|| conformingReplacementType->is<DependentMemberType>())
2901+
&& "replacement requires looking up a concrete conformance");
2902+
return ProtocolConformanceRef(conformedProtocol->getDecl());
2903+
}
2904+
28952905
Type DependentMemberType::substBaseType(ModuleDecl *module,
28962906
Type substBase,
28972907
LazyResolver *resolver) {

lib/SIL/SILFunction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ SILType GenericEnvironment::mapTypeIntoContext(SILModule &M,
277277
}
278278

279279
Type SILFunction::mapTypeOutOfContext(Type type) const {
280-
return ArchetypeBuilder::mapTypeOutOfContext(getModule().getSwiftModule(),
281-
getGenericEnvironment(),
280+
return ArchetypeBuilder::mapTypeOutOfContext(getGenericEnvironment(),
282281
type);
283282
}
284283

lib/SIL/TypeLowering.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1591,7 +1591,6 @@ static CanAnyFunctionType getDefaultArgGeneratorInterfaceType(
15911591
if (auto genTy = funcInfo.FormalInterfaceType->getAs<GenericFunctionType>()) {
15921592
sig = genTy->getGenericSignature()->getCanonicalSignature();
15931593
resultTy = ArchetypeBuilder::mapTypeOutOfContext(
1594-
TC.M.getSwiftModule(),
15951594
funcInfo.GenericEnv,
15961595
resultTy)->getCanonicalType();
15971596
}

lib/SILGen/SILGenDecl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,12 +1986,10 @@ getOrCreateReabstractionThunk(GenericEnvironment *genericEnv,
19861986

19871987
// Substitute context parameters out of the "from" and "to" types.
19881988
auto fromInterfaceType
1989-
= ArchetypeBuilder::mapTypeOutOfContext(
1990-
M.getSwiftModule(), genericEnv, fromType)
1989+
= ArchetypeBuilder::mapTypeOutOfContext(genericEnv, fromType)
19911990
->getCanonicalType();
19921991
auto toInterfaceType
1993-
= ArchetypeBuilder::mapTypeOutOfContext(
1994-
M.getSwiftModule(), genericEnv, toType)
1992+
= ArchetypeBuilder::mapTypeOutOfContext(genericEnv, toType)
19951993
->getCanonicalType();
19961994

19971995
mangler.mangleType(fromInterfaceType, /*uncurry*/ 0);

0 commit comments

Comments
 (0)