Skip to content

Commit bc54bc6

Browse files
authored
Revert "[TypeChecker] SE-0326: Enable multi-statement closure inference by default"
1 parent e7120a6 commit bc54bc6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+247
-480
lines changed

include/swift/Basic/LangOptions.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -688,7 +688,7 @@ namespace swift {
688688

689689
/// Enable experimental support for type inference through multi-statement
690690
/// closures.
691-
bool EnableMultiStatementClosureInference = true;
691+
bool EnableMultiStatementClosureInference = false;
692692

693693
/// See \ref FrontendOptions.PrintFullConvention
694694
bool PrintFullConvention = false;

include/swift/Sema/CSBindings.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -338,14 +338,6 @@ class BindingSet {
338338

339339
TypeVariableType *getTypeVariable() const { return Info.TypeVar; }
340340

341-
/// Check whether this binding set belongs to a type variable
342-
/// that represents a result type of a closure.
343-
bool forClosureResult() const;
344-
345-
/// Check whether this binding set belongs to a type variable
346-
/// that represents a generic parameter.
347-
bool forGenericParameter() const;
348-
349341
bool canBeNil() const;
350342

351343
/// If this type variable doesn't have any viable bindings, or

include/swift/Sema/CSFix.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2305,10 +2305,6 @@ class SpecifyClosureParameterType final : public ConstraintFix {
23052305

23062306
bool diagnose(const Solution &solution, bool asNote = false) const override;
23072307

2308-
bool diagnoseForAmbiguity(CommonFixesArray commonFixes) const override {
2309-
return diagnose(*commonFixes.front().first);
2310-
}
2311-
23122308
static SpecifyClosureParameterType *create(ConstraintSystem &cs,
23132309
ConstraintLocator *locator);
23142310

include/swift/Sema/Constraint.h

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,8 +442,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
442442
ASTNode Element;
443443
/// Contextual information associated with the element (if any).
444444
ContextualTypeInfo Context;
445-
/// Identifies whether result of this node is unused.
446-
bool IsDiscarded;
447445
} ClosureElement;
448446
};
449447

@@ -497,7 +495,7 @@ class Constraint final : public llvm::ilist_node<Constraint>,
497495
SmallPtrSetImpl<TypeVariableType *> &typeVars);
498496

499497
/// Construct a closure body element constraint.
500-
Constraint(ASTNode node, ContextualTypeInfo context, bool isDiscarded,
498+
Constraint(ASTNode node, ContextualTypeInfo context,
501499
ConstraintLocator *locator,
502500
SmallPtrSetImpl<TypeVariableType *> &typeVars);
503501

@@ -587,14 +585,12 @@ class Constraint final : public llvm::ilist_node<Constraint>,
587585

588586
static Constraint *createClosureBodyElement(ConstraintSystem &cs,
589587
ASTNode node,
590-
ConstraintLocator *locator,
591-
bool isDiscarded = false);
588+
ConstraintLocator *locator);
592589

593590
static Constraint *createClosureBodyElement(ConstraintSystem &cs,
594591
ASTNode node,
595592
ContextualTypeInfo context,
596-
ConstraintLocator *locator,
597-
bool isDiscarded = false);
593+
ConstraintLocator *locator);
598594

599595
/// Determine the kind of constraint.
600596
ConstraintKind getKind() const { return Kind; }
@@ -861,11 +857,6 @@ class Constraint final : public llvm::ilist_node<Constraint>,
861857
return ClosureElement.Context;
862858
}
863859

864-
bool isDiscardedElement() const {
865-
assert(Kind == ConstraintKind::ClosureBodyElement);
866-
return ClosureElement.IsDiscarded;
867-
}
868-
869860
/// For an applicable function constraint, retrieve the trailing closure
870861
/// matching rule.
871862
Optional<TrailingClosureMatching> getTrailingClosureMatching() const;

include/swift/Sema/ConstraintSystem.h

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4854,8 +4854,8 @@ class ConstraintSystem {
48544854
/// Simplify a closure body element constraint by generating required
48554855
/// constraints to represent the given element in constraint system.
48564856
SolutionKind simplifyClosureBodyElementConstraint(
4857-
ASTNode element, ContextualTypeInfo context, bool isDiscarded,
4858-
TypeMatchOptions flags, ConstraintLocatorBuilder locator);
4857+
ASTNode element, ContextualTypeInfo context, TypeMatchOptions flags,
4858+
ConstraintLocatorBuilder locator);
48594859

48604860
public: // FIXME: Public for use by static functions.
48614861
/// Simplify a conversion constraint with a fix applied to it.
@@ -5014,8 +5014,7 @@ class ConstraintSystem {
50145014
/// \param replaceInvalidRefsWithErrors Indicates whether it's allowed
50155015
/// to replace any discovered invalid member references with `ErrorExpr`.
50165016
static bool preCheckExpression(Expr *&expr, DeclContext *dc,
5017-
bool replaceInvalidRefsWithErrors,
5018-
bool leaveClosureBodiesUnchecked);
5017+
bool replaceInvalidRefsWithErrors);
50195018

50205019
/// Solve the system of constraints generated from provided target.
50215020
///
@@ -5246,16 +5245,6 @@ class ConstraintSystem {
52465245
/// imported from C/ObjectiveC.
52475246
bool isArgumentOfImportedDecl(ConstraintLocatorBuilder locator);
52485247

5249-
/// Check whether given closure should participate in inference e.g.
5250-
/// if it's a single-expression closure - it always does, but
5251-
/// multi-statement closures require special flags.
5252-
bool participatesInInference(ClosureExpr *closure) const;
5253-
5254-
/// Visit each subexpression that will be part of the constraint system
5255-
/// of the given expression, including those in closure bodies that will be
5256-
/// part of the constraint system.
5257-
void forEachExpr(Expr *expr, llvm::function_ref<Expr *(Expr *)> callback);
5258-
52595248
SWIFT_DEBUG_DUMP;
52605249
SWIFT_DEBUG_DUMPER(dump(Expr *));
52615250

@@ -6080,6 +6069,18 @@ BraceStmt *applyResultBuilderTransform(
60806069
constraints::SolutionApplicationTarget)>
60816070
rewriteTarget);
60826071

6072+
/// Determine whether the given closure expression should be type-checked
6073+
/// within the context of its enclosing expression. Otherwise, it will be
6074+
/// separately type-checked once its enclosing expression has determined all
6075+
/// of the parameter and result types without looking at the body.
6076+
bool shouldTypeCheckInEnclosingExpression(ClosureExpr *expr);
6077+
6078+
/// Visit each subexpression that will be part of the constraint system
6079+
/// of the given expression, including those in closure bodies that will be
6080+
/// part of the constraint system.
6081+
void forEachExprInConstraintSystem(
6082+
Expr *expr, llvm::function_ref<Expr *(Expr *)> callback);
6083+
60836084
/// Whether the given parameter requires an argument.
60846085
bool parameterRequiresArgument(
60856086
ArrayRef<AnyFunctionType::Param> params,

include/swift/Sema/IDETypeChecking.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ namespace swift {
4747
struct PrintOptions;
4848

4949
/// Typecheck binding initializer at \p bindingIndex.
50-
void typeCheckPatternBinding(PatternBindingDecl *PBD, unsigned bindingIndex,
51-
bool leaveClosureBodiesUnchecked);
50+
void typeCheckPatternBinding(PatternBindingDecl *PBD, unsigned bindingIndex);
5251

5352
/// Check if T1 is convertible to T2.
5453
///

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ void swift::ide::typeCheckContextAt(DeclContext *DC, SourceLoc Loc) {
9898
[](VarDecl *VD) { (void)VD->getInterfaceType(); });
9999
if (PBD->getInit(i)) {
100100
if (!PBD->isInitializerChecked(i))
101-
typeCheckPatternBinding(PBD, i,
102-
/*LeaveClosureBodyUnchecked=*/true);
101+
typeCheckPatternBinding(PBD, i);
103102
}
104103
}
105104
} else if (auto *defaultArg = dyn_cast<DefaultArgumentInitializer>(DC)) {

lib/Sema/BuilderTransform.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1932,9 +1932,7 @@ class PreCheckResultBuilderApplication : public ASTWalker {
19321932
DiagnosticTransaction transaction(diagEngine);
19331933

19341934
HasError |= ConstraintSystem::preCheckExpression(
1935-
E, DC, /*replaceInvalidRefsWithErrors=*/true,
1936-
/*leaveClosureBodiesUnchecked=*/false);
1937-
1935+
E, DC, /*replaceInvalidRefsWithErrors=*/true);
19381936
HasError |= transaction.hasErrors();
19391937

19401938
if (!HasError)

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4056,7 +4056,8 @@ namespace {
40564056
if (expr->isLiteralInit()) {
40574057
auto *literalInit = expr->getSubExpr();
40584058
if (auto *call = dyn_cast<CallExpr>(literalInit)) {
4059-
cs.forEachExpr(call->getFn(), [&](Expr *subExpr) -> Expr * {
4059+
forEachExprInConstraintSystem(call->getFn(),
4060+
[&](Expr *subExpr) -> Expr * {
40604061
auto *TE = dyn_cast<TypeExpr>(subExpr);
40614062
if (!TE)
40624063
return subExpr;

lib/Sema/CSBindings.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,6 @@ using namespace swift;
2525
using namespace constraints;
2626
using namespace inference;
2727

28-
bool BindingSet::forClosureResult() const {
29-
return Info.TypeVar->getImpl().isClosureResultType();
30-
}
31-
32-
bool BindingSet::forGenericParameter() const {
33-
return bool(Info.TypeVar->getImpl().getGenericParameter());
34-
}
35-
3628
bool BindingSet::canBeNil() const {
3729
auto &ctx = CS.getASTContext();
3830
return Literals.count(

0 commit comments

Comments
 (0)