Skip to content

[TypeChecker] NFC: Remove -experimental-multi-statement-closures flag #42484

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 1 commit into from
Apr 20, 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 @@ -759,10 +759,6 @@ namespace swift {
/// parameters of closures.
bool EnableOneWayClosureParameters = false;

/// Enable experimental support for type inference through multi-statement
/// closures.
bool EnableMultiStatementClosureInference = true;

/// See \ref FrontendOptions.PrintFullConvention
bool PrintFullConvention = false;
};
Expand Down
4 changes: 0 additions & 4 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -900,10 +900,6 @@ def experimental_one_way_closure_params :
Flag<["-"], "experimental-one-way-closure-params">,
HelpText<"Enable experimental support for one-way closure parameters">;

def experimental_multi_statement_closures :
Flag<["-"], "experimental-multi-statement-closures">,
HelpText<"Enable experimental support for type inference in multi-statement closures">;

def prebuilt_module_cache_path :
Separate<["-"], "prebuilt-module-cache-path">,
HelpText<"Directory of prebuilt modules for loading module interfaces">;
Expand Down
3 changes: 0 additions & 3 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1146,9 +1146,6 @@ static bool ParseTypeCheckerArgs(TypeCheckerOptions &Opts, ArgList &Args,
Opts.EnableOneWayClosureParameters |=
Args.hasArg(OPT_experimental_one_way_closure_params);

Opts.EnableMultiStatementClosureInference |=
Args.hasArg(OPT_experimental_multi_statement_closures);

Opts.PrintFullConvention |=
Args.hasArg(OPT_experimental_print_full_convention);

Expand Down
4 changes: 1 addition & 3 deletions lib/Sema/ConstraintSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6639,9 +6639,7 @@ bool ConstraintSystem::participatesInInference(ClosureExpr *closure) const {
if (Options.contains(ConstraintSystemFlags::LeaveClosureBodyUnchecked))
return false;

auto &ctx = closure->getASTContext();
if (closure->hasEmptyBody() ||
!ctx.TypeCheckerOpts.EnableMultiStatementClosureInference)
if (closure->hasEmptyBody())
return false;

// If body is nested in a parent that has a function builder applied,
Expand Down
10 changes: 3 additions & 7 deletions lib/Sema/MiscDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,10 @@ bool BaseDiagnosticWalker::shouldWalkIntoDeclInClosureContext(Decl *D) {
if (closure->isSeparatelyTypeChecked())
return false;

auto &opts = D->getASTContext().TypeCheckerOpts;

// If multi-statement inference is enabled, let's not walk
// into declarations contained in a multi-statement closure
// because they'd be handled via `typeCheckDecl` that runs
// Let's not walk into declarations contained in a multi-statement
// closure because they'd be handled via `typeCheckDecl` that runs
// syntactic diagnostics.
if (opts.EnableMultiStatementClosureInference &&
!closure->hasSingleExpressionBody()) {
if (!closure->hasSingleExpressionBody()) {
// Since pattern bindings get their types through solution application,
// `typeCheckDecl` doesn't touch initializers (because they are already
// fully type-checked), so pattern bindings have to be allowed to be
Expand Down
13 changes: 4 additions & 9 deletions lib/Sema/PreCheckExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1443,12 +1443,10 @@ namespace {
bool walkToDeclPre(Decl *D) override { return isa<PatternBindingDecl>(D); }

std::pair<bool, Pattern *> walkToPatternPre(Pattern *pattern) override {
// With multi-statement closure inference enabled, constraint generation
// is responsible for pattern verification and type-checking in the body
// of the closure, so there is no need to walk into patterns.
bool walkIntoPatterns =
!(isa<ClosureExpr>(DC) &&
Ctx.TypeCheckerOpts.EnableMultiStatementClosureInference);
// Constraint generation is responsible for pattern verification and
// type-checking in the body of the closure, so there is no need to
// walk into patterns.
bool walkIntoPatterns = !isa<ClosureExpr>(DC);
return {walkIntoPatterns, pattern};
}
};
Expand All @@ -1461,9 +1459,6 @@ bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) {
if (!closure->hasSingleExpressionBody()) {
if (LeaveClosureBodiesUnchecked)
return false;

if (!Ctx.TypeCheckerOpts.EnableMultiStatementClosureInference)
return false;
}

// Update the current DeclContext to be the closure we're about to
Expand Down
16 changes: 1 addition & 15 deletions lib/Sema/TypeCheckAvailability.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3136,21 +3136,7 @@ class ExprAvailabilityWalker : public ASTWalker {
}

bool shouldWalkIntoClosure(AbstractClosureExpr *closure) const {
// Multi-statement closures are collected by ExprWalker::rewriteFunction
// and checked by ExprWalker::processDelayed in CSApply.cpp.
// Single-statement closures only have the attributes checked
// by TypeChecker::checkClosureAttributes in that rewriteFunction.
// Multi-statement closures will be checked explicitly later (as the decl
// context in the Where). Single-expression closures will not be
// revisited, and are not automatically set as the context of the 'where'.
// Don't double-check multi-statement closures, but do check
// single-statement closures, setting the closure as the decl context.
//
// Note about SE-0326: When a flag is enabled multi-statement closures
// are type-checked together with enclosing context, so walker behavior
// should match that of single-expression closures.
return closure->hasSingleExpressionBody() ||
Context.TypeCheckerOpts.EnableMultiStatementClosureInference;
return true;
}

/// Walk an abstract closure expression, checking for availability
Expand Down
4 changes: 0 additions & 4 deletions lib/Sema/TypeCheckCodeCompletion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,6 @@ class SanitizeExpr : public ASTWalker {
// If this is a closure, only walk into its children if they
// are type-checked in the context of the enclosing expression.
if (auto closure = dyn_cast<ClosureExpr>(expr)) {
// TODO: This has to be deleted once `EnableMultiStatementClosureInference`
// is enabled by default.
if (!closure->hasSingleExpressionBody())
return { false, expr };
for (auto &Param : *closure->getParameters()) {
Param->setSpecifier(swift::ParamSpecifier::Default);
}
Expand Down
2 changes: 1 addition & 1 deletion test/expr/closure/multi_statement.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -swift-version 5 -experimental-multi-statement-closures -enable-experimental-static-assert
// RUN: %target-typecheck-verify-swift -swift-version 5 -enable-experimental-static-assert

func isInt<T>(_ value: T) -> Bool {
return value is Int
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5 -experimental-multi-statement-closures
// RUN: %target-typecheck-verify-swift -target %target-cpu-apple-macosx10.15 -swift-version 5
// REQUIRES: objc_interop
// REQUIRES: OS=macosx

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %target-typecheck-verify-swift -swift-version 5 -experimental-multi-statement-closures
// RUN: %target-typecheck-verify-swift -swift-version 5

func callClosure(closure: () -> ()) {
closure()
Expand Down