Skip to content

[LangOptions] Remove the option to enable/disable implicit existential opening. #59740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions include/swift/Basic/LangOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,6 @@ namespace swift {
/// Enable experimental concurrency model.
bool EnableExperimentalConcurrency = false;

/// Enable support for implicitly opening existential argument types
/// in calls to generic functions.
bool EnableOpenedExistentialTypes = false;

/// Disable experimental ClangImporter diagnostics.
bool DisableExperimentalClangImporterDiagnostics = false;

Expand Down
5 changes: 0 additions & 5 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -450,11 +450,6 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.EnableExperimentalConcurrency |=
Args.hasArg(OPT_enable_experimental_concurrency);

Opts.EnableOpenedExistentialTypes =
Args.hasFlag(OPT_enable_experimental_opened_existential_types,
OPT_disable_experimental_opened_existential_types,
true);

Opts.EnableInferPublicSendable |=
Args.hasFlag(OPT_enable_infer_public_concurrent_value,
OPT_disable_infer_public_concurrent_value,
Expand Down
4 changes: 0 additions & 4 deletions lib/Sema/CSSimplify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1519,10 +1519,6 @@ shouldOpenExistentialCallArgument(
if (isa_and_nonnull<clang::FunctionTemplateDecl>(callee->getClangDecl()))
return None;

ASTContext &ctx = callee->getASTContext();
if (!ctx.LangOpts.EnableOpenedExistentialTypes)
return None;

// The actual parameter type needs to involve a type variable, otherwise
// type inference won't be possible.
if (!paramTy->hasTypeVariable())
Expand Down
9 changes: 7 additions & 2 deletions lib/Sema/TypeCheckCodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
// Build temporary expression to typecheck.
// We allocate these expressions on the stack because we know they can't
// escape and there isn't a better way to allocate scratch Expr nodes.

// Use a placeholder expr for the LHS argument to avoid sending
// a pre-type-checked AST through the constraint system.
OpaqueValueExpr argExpr(LHS->getSourceRange(), LHSTy,
/*isPlaceholder=*/true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense to me! If I understand correctly, code completion doesn't care about the structure of the argument but the fact that the argument has a particular type it could use to infer right-hand side of the operator.

/cc @ahoppen

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we only care about the type. We might even be able to get rid of the ConstraintSystemFlags::ReusePrecheckedType option above. Not entirely sure though.

UnresolvedDeclRefExpr UDRE(DeclNameRef(opName), refKind, DeclNameLoc(Loc));
auto *opExpr = TypeChecker::resolveDeclRefExpr(
&UDRE, DC, /*replaceInvalidRefsWithErrors=*/true);
Expand All @@ -493,7 +498,7 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
// (declref_expr name=<opName>)
// (argument_list
// (<LHS>)))
auto *postfixExpr = PostfixUnaryExpr::create(ctx, opExpr, LHS);
auto *postfixExpr = PostfixUnaryExpr::create(ctx, opExpr, &argExpr);
return getTypeOfCompletionOperatorImpl(DC, postfixExpr, referencedDecl);
}

Expand All @@ -504,7 +509,7 @@ TypeChecker::getTypeOfCompletionOperator(DeclContext *DC, Expr *LHS,
// (<LHS>)
// (code_completion_expr)))
CodeCompletionExpr dummyRHS(Loc);
auto *binaryExpr = BinaryExpr::create(ctx, LHS, opExpr, &dummyRHS,
auto *binaryExpr = BinaryExpr::create(ctx, &argExpr, opExpr, &dummyRHS,
/*implicit*/ true);
return getTypeOfCompletionOperatorImpl(DC, binaryExpr, referencedDecl);
}
Expand Down
1 change: 0 additions & 1 deletion test/Constraints/openExistential.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %target-typecheck-verify-swift
// RUN: %target-typecheck-verify-swift -enable-experimental-opened-existential-types

protocol P { }

Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/opened_existentials.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-opened-existential-types
// RUN: %target-typecheck-verify-swift

protocol Q { }

Expand Down
2 changes: 1 addition & 1 deletion test/Constraints/opened_existentials_suppression.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-frontend -enable-experimental-opened-existential-types -typecheck -dump-ast -parse-as-library %s | %FileCheck %s
// RUN: %target-swift-frontend -typecheck -dump-ast -parse-as-library %s | %FileCheck %s

protocol P { }
extension Optional: P where Wrapped: P { }
Expand Down
1 change: 0 additions & 1 deletion test/Constraints/result_builder_availability.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.50
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.50 -enable-experimental-opened-existential-types

// REQUIRES: OS=macosx

Expand Down
10 changes: 5 additions & 5 deletions test/Generics/existential_restrictions.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -enable-objc-interop -disable-experimental-opened-existential-types
// RUN: %target-typecheck-verify-swift -enable-objc-interop

protocol P { }
@objc protocol OP { }
Expand All @@ -8,14 +8,14 @@ protocol CP : class { }
static func createNewOne() -> SP
}

func fP<T : P>(_ t: T) { }
func fP<T : P>(_ t: T?) { }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the addition of '?' in this file intentional?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I made these parameters optional so the diagnostics stay the same later in the file (instead of disappearing due to opening)

// expected-note@-1 {{required by global function 'fP' where 'T' = 'any P'}}
// expected-note@-2 {{required by global function 'fP' where 'T' = 'any OP & P'}}
func fOP<T : OP>(_ t: T) { }
func fOP<T : OP>(_ t: T?) { }
// expected-note@-1 {{required by global function 'fOP' where 'T' = 'any OP & P'}}
func fOPE(_ t: OP) { }
func fSP<T : SP>(_ t: T) { }
func fAO<T : AnyObject>(_ t: T) { }
func fSP<T : SP>(_ t: T?) { }
func fAO<T : AnyObject>(_ t: T?) { }
// expected-note@-1 {{where 'T' = 'any P'}}
// expected-note@-2 {{where 'T' = 'any CP'}}
// expected-note@-3 {{where 'T' = 'any OP & P'}}
Expand Down
3 changes: 1 addition & 2 deletions test/Interop/Cxx/templates/function-template.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop)
// RUN: %target-run-simple-swift(-I %S/Inputs -Xfrontend -enable-experimental-cxx-interop -Xfrontend -enable-experimental-opened-existential-types)
//

// REQUIRES: executable_test

import FunctionTemplates
Expand Down
2 changes: 1 addition & 1 deletion test/SILGen/opened_existentials.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-swift-emit-silgen -enable-experimental-opened-existential-types %s | %FileCheck %s
// RUN: %target-swift-emit-silgen %s | %FileCheck %s

public protocol P { }

Expand Down