Skip to content

Commit 8cf491f

Browse files
committed
AST: Allow non-canonical opaque archetypes
1 parent 0d90b62 commit 8cf491f

File tree

4 files changed

+9
-7
lines changed

4 files changed

+9
-7
lines changed

include/swift/AST/TypeNodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ TYPE(DynamicSelf, Type)
176176
ABSTRACT_TYPE(Substitutable, Type)
177177
ABSTRACT_TYPE(Archetype, SubstitutableType)
178178
ALWAYS_CANONICAL_TYPE(PrimaryArchetype, ArchetypeType)
179-
ALWAYS_CANONICAL_TYPE(OpaqueTypeArchetype, ArchetypeType)
179+
TYPE(OpaqueTypeArchetype, ArchetypeType)
180180
ABSTRACT_TYPE(LocalArchetype, ArchetypeType)
181181
ALWAYS_CANONICAL_TYPE(ExistentialArchetype, LocalArchetypeType)
182182
ALWAYS_CANONICAL_TYPE(ElementArchetype, LocalArchetypeType)

lib/AST/ASTContext.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6027,11 +6027,6 @@ GenericEnvironment *GenericEnvironment::forPrimary(GenericSignature signature) {
60276027
/// outer substitutions.
60286028
GenericEnvironment *GenericEnvironment::forOpaqueType(
60296029
OpaqueTypeDecl *opaque, SubstitutionMap subs) {
6030-
// TODO: We could attempt to preserve type sugar in the substitution map.
6031-
// Currently archetypes are assumed to be always canonical in many places,
6032-
// though, so doing so would require fixing those places.
6033-
subs = subs.getCanonical();
6034-
60356030
auto &ctx = opaque->getASTContext();
60366031

60376032
auto properties = ArchetypeType::archetypeProperties(

lib/AST/GenericEnvironment.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,6 @@ GenericEnvironment::GenericEnvironment(
227227
GenericEnvironment::GenericEnvironment(
228228
GenericSignature sig, OpaqueTypeDecl *opaque, SubstitutionMap subs)
229229
: sig(sig), kind(Kind::Opaque), canonical(subs.isCanonical()) {
230-
ASSERT(canonical);
231230
*getTrailingObjects<SubstitutionMap>() = subs;
232231
new (getTrailingObjects<OpaqueEnvironmentData>())
233232
OpaqueEnvironmentData{opaque};

lib/AST/Type.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,6 +2023,14 @@ CanType TypeBase::computeCanonicalType() {
20232023
Result = ErrorUnionType::get(ctx, newTerms).getPointer();
20242024
break;
20252025
}
2026+
case TypeKind::OpaqueTypeArchetype: {
2027+
auto *AT = cast<OpaqueTypeArchetypeType>(this);
2028+
Result = OpaqueTypeArchetypeType::get(
2029+
AT->getDecl(), AT->getInterfaceType(),
2030+
AT->getSubstitutions().getCanonical())
2031+
->castTo<OpaqueTypeArchetypeType>();
2032+
break;
2033+
}
20262034
case TypeKind::Integer: {
20272035
auto intTy = cast<IntegerType>(this);
20282036
APInt value = intTy->getValue();

0 commit comments

Comments
 (0)