Skip to content

Commit e3ff6f0

Browse files
committed
AST: Fiddle with GenericEnvironment::forOpenedExistential() again
1 parent 8299655 commit e3ff6f0

File tree

7 files changed

+33
-15
lines changed

7 files changed

+33
-15
lines changed

include/swift/AST/GenericEnvironment.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,11 +232,21 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
232232
/// Create a new generic environment for an opened existential.
233233
///
234234
/// \param existential The subject existential type
235+
/// \param uuid The unique identifier for this opened existential
236+
static GenericEnvironment *
237+
forOpenedExistential(Type existential, UUID uuid);
238+
239+
/// Create a new generic environment for an opened existential.
240+
///
241+
/// \param signature The opened existential signature
242+
/// \param existential The generalized existential type
235243
/// \param outerSubs The substitution map containing archetypes from the
236244
/// outer generic context
237245
/// \param uuid The unique identifier for this opened existential
238246
static GenericEnvironment *
239-
forOpenedExistential(Type existential, SubstitutionMap outerSubs, UUID uuid);
247+
forOpenedExistential(GenericSignature signature,
248+
Type existential, SubstitutionMap outerSubs,
249+
UUID uuid);
240250

241251
/// Create a new generic environment for an opened element.
242252
///

include/swift/SIL/SILCloner.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ class SILCloner : protected SILInstructionVisitor<ImplClass> {
387387

388388
auto substExistentialTy = getOpASTType(origExistentialTy);
389389
auto *newEnv = GenericEnvironment::forOpenedExistential(
390-
substExistentialTy, subMap, UUID::fromTime());
390+
substExistentialTy, UUID::fromTime());
391391

392392
registerLocalArchetypeRemapping(origEnv, newEnv);
393393
}

lib/AST/ASTContext.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5350,9 +5350,8 @@ CanOpenedArchetypeType OpenedArchetypeType::get(CanType existential,
53505350
if (!knownID)
53515351
knownID = UUID::fromTime();
53525352

5353-
auto *genericEnv =
5354-
GenericEnvironment::forOpenedExistential(
5355-
existential, SubstitutionMap(), *knownID);
5353+
auto *genericEnv = GenericEnvironment::forOpenedExistential(
5354+
existential, *knownID);
53565355

53575356
// Map the interface type into that environment.
53585357
auto result = genericEnv->mapTypeIntoContext(interfaceType)
@@ -5543,10 +5542,19 @@ GenericEnvironment *GenericEnvironment::forOpaqueType(
55435542
return env;
55445543
}
55455544

5545+
/// Create a new generic environment for an opened archetype.
5546+
GenericEnvironment *
5547+
GenericEnvironment::forOpenedExistential(Type existential, UUID uuid) {
5548+
auto &ctx = existential->getASTContext();
5549+
auto signature = ctx.getOpenedExistentialSignature(existential, GenericSignature());
5550+
return forOpenedExistential(signature, existential, SubstitutionMap(), uuid);
5551+
}
5552+
55465553
/// Create a new generic environment for an opened archetype.
55475554
GenericEnvironment *
55485555
GenericEnvironment::forOpenedExistential(
5549-
Type existential, SubstitutionMap subs, UUID uuid) {
5556+
GenericSignature signature, Type existential,
5557+
SubstitutionMap subs, UUID uuid) {
55505558
assert(existential->isExistentialType());
55515559

55525560
// TODO: We could attempt to preserve type sugar in the substitution map.
@@ -5568,15 +5576,13 @@ GenericEnvironment::forOpenedExistential(
55685576
if (found != environments.end()) {
55695577
auto *existingEnv = found->second;
55705578
assert(existingEnv->getOpenedExistentialType()->isEqual(existential));
5579+
assert(existingEnv->getGenericSignature().getPointer() == signature.getPointer());
55715580
assert(existingEnv->getOuterSubstitutions() == subs);
55725581
assert(existingEnv->getOpenedExistentialUUID() == uuid);
55735582

55745583
return existingEnv;
55755584
}
55765585

5577-
auto parentSig = subs.getGenericSignature().getCanonicalSignature();
5578-
auto signature = ctx.getOpenedExistentialSignature(existential, parentSig);
5579-
55805586
// Allocate and construct the new environment.
55815587
unsigned numGenericParams = signature.getGenericParams().size();
55825588
size_t bytes = totalSizeToAlloc<SubstitutionMap,

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2863,7 +2863,7 @@ TypeResolver::resolveOpenedExistentialArchetype(
28632863
// The opened existential type is formed by mapping the interface type
28642864
// into a new opened generic environment.
28652865
auto *env = GenericEnvironment::forOpenedExistential(
2866-
constraintType->getCanonicalType(), SubstitutionMap(),
2866+
constraintType->getCanonicalType(),
28672867
openedAttr->getUUID());
28682868
return env->mapTypeIntoContext(interfaceType);
28692869
}

lib/Serialization/Deserialization.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1660,7 +1660,10 @@ Expected<GenericEnvironment *> ModuleFile::getGenericEnvironmentChecked(
16601660
switch (GenericEnvironmentKind(kind)) {
16611661
case GenericEnvironmentKind::OpenedExistential:
16621662
genericEnv = GenericEnvironment::forOpenedExistential(
1663-
existentialOrShapeTypeOrError.get(), contextSubsOrError.get(), UUID::fromTime());
1663+
genericSigOrError.get(),
1664+
existentialOrShapeTypeOrError.get(),
1665+
contextSubsOrError.get(),
1666+
UUID::fromTime());
16641667
break;
16651668

16661669
case GenericEnvironmentKind::OpenedElement:

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 886; // SIL function thunk kind
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 887; // extravagant opened existentials
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///

lib/Serialization/Serialization.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1667,7 +1667,7 @@ void Serializer::writeASTBlockEntity(const GenericEnvironment *genericEnv) {
16671667
case GenericEnvironment::Kind::OpenedExistential: {
16681668
auto kind = GenericEnvironmentKind::OpenedExistential;
16691669
auto existentialTypeID = addTypeRef(genericEnv->getOpenedExistentialType());
1670-
auto parentSigID = addGenericSignatureRef(GenericSignature());
1670+
auto parentSigID = addGenericSignatureRef(genericEnv->getGenericSignature());
16711671
auto contextSubs = genericEnv->getOuterSubstitutions();
16721672
auto subsID = addSubstitutionMapRef(contextSubs);
16731673

@@ -1681,8 +1681,7 @@ void Serializer::writeASTBlockEntity(const GenericEnvironment *genericEnv) {
16811681
case GenericEnvironment::Kind::OpenedElement: {
16821682
auto kind = GenericEnvironmentKind::OpenedElement;
16831683
auto shapeClassID = addTypeRef(genericEnv->getOpenedElementShapeClass());
1684-
auto parentSig = genericEnv->getGenericSignature();
1685-
auto parentSigID = addGenericSignatureRef(parentSig);
1684+
auto parentSigID = addGenericSignatureRef(genericEnv->getGenericSignature());
16861685
auto contextSubs = genericEnv->getOuterSubstitutions();
16871686
auto subsID = addSubstitutionMapRef(contextSubs);
16881687

0 commit comments

Comments
 (0)