Skip to content

Commit 05235ed

Browse files
authored
Merge pull request #42011 from DougGregor/do-not-open-self-conforming-existential-arg
Don't open an existential argument that's completely self-conforming.
2 parents f1dde51 + b9f31a8 commit 05235ed

File tree

4 files changed

+23
-7
lines changed

4 files changed

+23
-7
lines changed

include/swift/Option/FrontendOptions.td

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ def enable_experimental_opened_existential_types :
538538
HelpText<"Enable experimental support for implicitly opened existentials">;
539539

540540
def disable_experimental_opened_existential_types :
541-
Flag<["-"], "disble-experimental-opened-existential-types">,
541+
Flag<["-"], "disable-experimental-opened-existential-types">,
542542
HelpText<"Disable experimental support for implicitly opened existentials">;
543543

544544
def enable_deserialization_recovery :

lib/Frontend/CompilerInvocation.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
459459
Opts.EnableExperimentalVariadicGenerics |=
460460
Args.hasArg(OPT_enable_experimental_variadic_generics);
461461

462-
// SwiftOnoneSupport produces different symbols when opening existentials,
463-
// so disable it.
464-
if (FrontendOpts.ModuleName == SWIFT_ONONE_SUPPORT)
465-
Opts.EnableOpenedExistentialTypes = false;
466-
467462
Opts.EnableExperimentalDistributed |=
468463
Args.hasArg(OPT_enable_experimental_distributed);
469464

lib/Sema/CSSimplify.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,25 @@ shouldOpenExistentialCallArgument(
15011501
if (!argTy->isAnyExistentialType())
15021502
return None;
15031503

1504+
if (argTy->isExistentialType()) {
1505+
// If the existential argument type conforms to all of its protocol
1506+
// requirements, don't open the existential.
1507+
auto layout = argTy->getExistentialLayout();
1508+
auto module = cs.DC->getParentModule();
1509+
bool containsNonSelfConformance = false;
1510+
for (auto proto : layout.getProtocols()) {
1511+
auto protoDecl = proto->getDecl();
1512+
auto conformance = module->lookupExistentialConformance(argTy, protoDecl);
1513+
if (conformance.isInvalid()) {
1514+
containsNonSelfConformance = true;
1515+
break;
1516+
}
1517+
}
1518+
1519+
if (!containsNonSelfConformance)
1520+
return None;
1521+
}
1522+
15041523
auto param = getParameterAt(callee, paramIdx);
15051524
if (!param)
15061525
return None;

test/Constraints/opened_existentials_suppression.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ func acceptsBox<T>(_ value: T) { }
66

77
// CHECK: passBox
88
// CHECK-NOT: open_existential_expr
9-
func passBox(p: P) {
9+
func passBox(p: P, obj: AnyObject, err: Error) {
1010
acceptsBox(p as P)
11+
acceptsBox(obj)
12+
acceptsBox(err)
1113
}

0 commit comments

Comments
 (0)