Skip to content

Commit 72d29cf

Browse files
committed
[Constraint solver] Remove performance hacks for pattern type computation.
We shouldn't need these.
1 parent 5e28c7c commit 72d29cf

File tree

1 file changed

+4
-40
lines changed

1 file changed

+4
-40
lines changed

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2199,62 +2199,26 @@ namespace {
21992199
return getTypeForPattern(cast<VarPattern>(pattern)->getSubPattern(),
22002200
locator);
22012201
case PatternKind::Any: {
2202-
// If we have a type from an initializer expression, and that
2203-
// expression does not produce an InOut type, use it. This
2204-
// will avoid exponential typecheck behavior in the case of
2205-
// tuples, nested arrays, and dictionary literals.
2206-
//
2207-
// Otherwise, create a new type variable.
2208-
if (auto boundExpr = locator.trySimplifyToExpr()) {
2209-
if (!boundExpr->isSemanticallyInOutExpr())
2210-
return CS.getType(boundExpr)->getRValueType();
2211-
}
2212-
22132202
return CS.createTypeVariable(CS.getConstraintLocator(locator),
22142203
TVO_CanBindToNoEscape);
22152204
}
22162205

22172206
case PatternKind::Named: {
22182207
auto var = cast<NamedPattern>(pattern)->getDecl();
22192208

2220-
// If we have a type from an initializer expression, and that
2221-
// expression does not produce an InOut type, use it. This
2222-
// will avoid exponential typecheck behavior in the case of
2223-
// tuples, nested arrays, and dictionary literals.
2224-
//
2225-
// FIXME: This should be handled in the solver, not here.
2226-
//
2227-
// Otherwise, create a new type variable.
2228-
auto ty = Type();
2229-
if (!var->hasNonPatternBindingInit() &&
2230-
!var->hasAttachedPropertyWrapper()) {
2231-
if (auto boundExpr = locator.trySimplifyToExpr()) {
2232-
if (!boundExpr->isSemanticallyInOutExpr())
2233-
ty = CS.getType(boundExpr)->getRValueType();
2234-
}
2235-
}
2209+
Type varType = CS.createTypeVariable(
2210+
CS.getConstraintLocator(locator), TVO_CanBindToNoEscape);
22362211

22372212
auto ROK = ReferenceOwnership::Strong;
22382213
if (auto *OA = var->getAttrs().getAttribute<ReferenceOwnershipAttr>())
22392214
ROK = OA->get();
2240-
22412215
switch (optionalityOf(ROK)) {
22422216
case ReferenceOwnershipOptionality::Required:
2243-
if (ty && ty->getOptionalObjectType())
2244-
return ty; // Already Optional<T>.
2245-
// Create a fresh type variable to handle overloaded expressions.
2246-
if (!ty || ty->is<TypeVariableType>())
2247-
ty = CS.createTypeVariable(CS.getConstraintLocator(locator),
2248-
TVO_CanBindToNoEscape);
2249-
return TypeChecker::getOptionalType(var->getLoc(), ty);
2217+
return TypeChecker::getOptionalType(var->getLoc(), varType);
22502218
case ReferenceOwnershipOptionality::Allowed:
22512219
case ReferenceOwnershipOptionality::Disallowed:
2252-
break;
2220+
return varType;
22532221
}
2254-
if (ty)
2255-
return ty;
2256-
return CS.createTypeVariable(CS.getConstraintLocator(locator),
2257-
TVO_CanBindToNoEscape);
22582222
}
22592223

22602224
case PatternKind::Typed: {

0 commit comments

Comments
 (0)