Skip to content

Commit 43f1466

Browse files
committed
Sema: Split off resolveOpenedExistentialArchetype() from resolveAttributedType()
1 parent 30c99b5 commit 43f1466

File tree

1 file changed

+31
-15
lines changed

1 file changed

+31
-15
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1924,6 +1924,10 @@ namespace {
19241924
return diags.diagnose(std::forward<ArgTypes>(Args)...);
19251925
}
19261926

1927+
NeverNullType resolveOpenedExistentialArchetype(
1928+
TypeAttributes &attrs, TypeRepr *repr,
1929+
TypeResolutionOptions options);
1930+
19271931
NeverNullType resolveAttributedType(AttributedTypeRepr *repr,
19281932
TypeResolutionOptions options);
19291933
NeverNullType resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
@@ -2307,6 +2311,29 @@ TypeResolver::resolveAttributedType(AttributedTypeRepr *repr,
23072311
return resolveAttributedType(attrs, repr->getTypeRepr(), options);
23082312
}
23092313

2314+
/// In SIL, handle @opened (n), which creates an existential archetype.
2315+
NeverNullType
2316+
TypeResolver::resolveOpenedExistentialArchetype(
2317+
TypeAttributes &attrs, TypeRepr *repr,
2318+
TypeResolutionOptions options) {
2319+
options.setContext(None);
2320+
Type ty = resolveType(repr, options);
2321+
2322+
if (!ty->isExistentialType()) {
2323+
diagnoseInvalid(repr, attrs.getLoc(TAK_opened), diag::opened_non_protocol,
2324+
ty);
2325+
} else {
2326+
ty = GenericEnvironment::mapTypeIntoContext(
2327+
resolution.getGenericSignature().getGenericEnvironment(), ty);
2328+
ty = OpenedArchetypeType::get(ty->getCanonicalType(),
2329+
GenericSignature(),
2330+
attrs.OpenedID);
2331+
}
2332+
attrs.clearAttribute(TAK_opened);
2333+
2334+
return ty;
2335+
}
2336+
23102337
NeverNullType
23112338
TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
23122339
TypeResolutionOptions options) {
@@ -2715,6 +2742,10 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
27152742
attrs.clearAttribute(TAK_unchecked);
27162743
}
27172744

2745+
if (attrs.has(TAK_opened)) {
2746+
ty = resolveOpenedExistentialArchetype(attrs, repr, options);
2747+
}
2748+
27182749
auto instanceOptions = options;
27192750
instanceOptions.setContext(None);
27202751

@@ -2834,21 +2865,6 @@ TypeResolver::resolveAttributedType(TypeAttributes &attrs, TypeRepr *repr,
28342865
attrs.clearAttribute(TAK_noDerivative);
28352866
}
28362867

2837-
// In SIL, handle @opened (n), which creates an existential archetype.
2838-
if (attrs.has(TAK_opened)) {
2839-
if (!ty->isExistentialType()) {
2840-
diagnoseInvalid(repr, attrs.getLoc(TAK_opened), diag::opened_non_protocol,
2841-
ty);
2842-
} else {
2843-
ty = GenericEnvironment::mapTypeIntoContext(
2844-
resolution.getGenericSignature().getGenericEnvironment(), ty);
2845-
ty = OpenedArchetypeType::get(ty->getCanonicalType(),
2846-
resolution.getGenericSignature(),
2847-
attrs.OpenedID);
2848-
}
2849-
attrs.clearAttribute(TAK_opened);
2850-
}
2851-
28522868
// In SIL files *only*, permit @weak and @unowned to apply directly to types.
28532869
if (attrs.hasOwnership()) {
28542870
if (auto SF = getDeclContext()->getParentSourceFile()) {

0 commit comments

Comments
 (0)