Skip to content

Commit 420afdc

Browse files
authored
Merge pull request #37344 from ahoppen/pr/no-unresolved-type-variables
[Sema] Remove `TypeCheckExprFlags::AllowUnresolvedTypeVariables`
2 parents 499844e + 4566bf3 commit 420afdc

File tree

4 files changed

+11
-27
lines changed

4 files changed

+11
-27
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,6 @@ TypeChecker::typeCheckExpression(
350350
if (DiagnosticSuppression::isEnabled(Context.Diags))
351351
csOptions |= ConstraintSystemFlags::SuppressDiagnostics;
352352

353-
if (options.contains(TypeCheckExprFlags::AllowUnresolvedTypeVariables))
354-
csOptions |= ConstraintSystemFlags::AllowUnresolvedTypeVariables;
355-
356353
if (options.contains(TypeCheckExprFlags::LeaveClosureBodyUnchecked))
357354
csOptions |= ConstraintSystemFlags::LeaveClosureBodyUnchecked;
358355

@@ -374,8 +371,6 @@ TypeChecker::typeCheckExpression(
374371
// If the client can handle unresolved type variables, leave them in the
375372
// system.
376373
auto allowFreeTypeVariables = FreeTypeVariableBinding::Disallow;
377-
if (options.contains(TypeCheckExprFlags::AllowUnresolvedTypeVariables))
378-
allowFreeTypeVariables = FreeTypeVariableBinding::UnresolvedType;
379374

380375
// Attempt to solve the constraint system.
381376
auto viable = cs.solve(target, allowFreeTypeVariables);
@@ -384,16 +379,6 @@ TypeChecker::typeCheckExpression(
384379
return None;
385380
}
386381

387-
// If the client allows the solution to have unresolved type expressions,
388-
// check for them now. We cannot apply the solution with unresolved TypeVars,
389-
// because they will leak out into arbitrary places in the resultant AST.
390-
if (options.contains(TypeCheckExprFlags::AllowUnresolvedTypeVariables) &&
391-
(viable->size() != 1 ||
392-
(target.getExprConversionType() &&
393-
target.getExprConversionType()->hasUnresolvedType()))) {
394-
return target;
395-
}
396-
397382
// Apply this solution to the constraint system.
398383
// FIXME: This shouldn't be necessary.
399384
auto &solution = (*viable)[0];

lib/Sema/TypeCheckStmt.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,6 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
764764
assert(DiagnosticSuppression::isEnabled(getASTContext().Diags) &&
765765
"Diagnosing and AllowUnresolvedTypeVariables don't seem to mix");
766766
options |= TypeCheckExprFlags::LeaveClosureBodyUnchecked;
767-
options |= TypeCheckExprFlags::AllowUnresolvedTypeVariables;
768767
}
769768

770769
ContextualTypePurpose ctp = CTP_ReturnStmt;

lib/Sema/TypeChecker.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,22 +122,15 @@ enum class TypeCheckExprFlags {
122122
/// disables constraints forcing an lvalue result to be loadable.
123123
IsDiscarded = 0x01,
124124

125-
/// If set, the client wants a best-effort solution to the constraint system,
126-
/// but can tolerate a solution where all of the constraints are solved, but
127-
/// not all type variables have been determined. In this case, the constraint
128-
/// system is not applied to the expression AST, but the ConstraintSystem is
129-
/// left in-tact.
130-
AllowUnresolvedTypeVariables = 0x02,
131-
132125
/// If set, this expression isn't embedded in a larger expression or
133126
/// statement. This should only be used for syntactic restrictions, and should
134127
/// not affect type checking itself.
135-
IsExprStmt = 0x04,
128+
IsExprStmt = 0x02,
136129

137130
/// Don't try to type check closure expression bodies, and leave them
138131
/// unchecked. This is used by source tooling functionalities such as code
139132
/// completion.
140-
LeaveClosureBodyUnchecked = 0x08,
133+
LeaveClosureBodyUnchecked = 0x04,
141134
};
142135

143136
using TypeCheckExprOptions = OptionSet<TypeCheckExprFlags>;

validation-test/IDE/crashers_2_fixed/rdar76686564.swift

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// RUN: %target-swift-ide-test --conforming-methods -code-completion-token=COMPLETE --conforming-methods-expected-types=s:14swift_ide_test10MySequenceP -source-filename %s
1+
// RUN: %target-swift-ide-test --conforming-methods -code-completion-token=COMPLETE_EXPR --conforming-methods-expected-types=s:14swift_ide_test10MySequenceP -source-filename %s
2+
// RUN: %target-swift-ide-test --conforming-methods -code-completion-token=COMPLETE_STMT --conforming-methods-expected-types=s:14swift_ide_test10MySequenceP -source-filename %s
23

34
protocol MySequence {
45
associatedtype Element
@@ -17,5 +18,11 @@ func myFlatMap<SegmentOfResult: MySequence>(_ transform: (ArgumentDefinition) ->
1718
}
1819

1920
func generateArgumentWords() {
20-
_ = myFlatMap { $0.#^COMPLETE^# } as Foo<String>
21+
// Explicitly coerce the type using 'as'. This is type checked as an expression.
22+
_ = myFlatMap { $0.#^COMPLETE_EXPR^# } as Foo<String>
23+
}
24+
25+
func generateArgumentWords() -> Foo<String> {
26+
// Implicitly coerce the type from the return type. This is type checked as a stmt.
27+
return myFlatMap { $0.#^COMPLETE_STMT^# }
2128
}

0 commit comments

Comments
 (0)