Skip to content

Commit d81161a

Browse files
authored
Merge pull request #29851 from DougGregor/remove-performance-hacks
[Constraint solver] Remove performance hacks for pattern type computation
2 parents c7552bf + 72d29cf commit d81161a

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
@@ -2208,62 +2208,26 @@ namespace {
22082208
return getTypeForPattern(cast<VarPattern>(pattern)->getSubPattern(),
22092209
locator);
22102210
case PatternKind::Any: {
2211-
// If we have a type from an initializer expression, and that
2212-
// expression does not produce an InOut type, use it. This
2213-
// will avoid exponential typecheck behavior in the case of
2214-
// tuples, nested arrays, and dictionary literals.
2215-
//
2216-
// Otherwise, create a new type variable.
2217-
if (auto boundExpr = locator.trySimplifyToExpr()) {
2218-
if (!boundExpr->isSemanticallyInOutExpr())
2219-
return CS.getType(boundExpr)->getRValueType();
2220-
}
2221-
22222211
return CS.createTypeVariable(CS.getConstraintLocator(locator),
22232212
TVO_CanBindToNoEscape);
22242213
}
22252214

22262215
case PatternKind::Named: {
22272216
auto var = cast<NamedPattern>(pattern)->getDecl();
22282217

2229-
// If we have a type from an initializer expression, and that
2230-
// expression does not produce an InOut type, use it. This
2231-
// will avoid exponential typecheck behavior in the case of
2232-
// tuples, nested arrays, and dictionary literals.
2233-
//
2234-
// FIXME: This should be handled in the solver, not here.
2235-
//
2236-
// Otherwise, create a new type variable.
2237-
auto ty = Type();
2238-
if (!var->hasNonPatternBindingInit() &&
2239-
!var->hasAttachedPropertyWrapper()) {
2240-
if (auto boundExpr = locator.trySimplifyToExpr()) {
2241-
if (!boundExpr->isSemanticallyInOutExpr())
2242-
ty = CS.getType(boundExpr)->getRValueType();
2243-
}
2244-
}
2218+
Type varType = CS.createTypeVariable(
2219+
CS.getConstraintLocator(locator), TVO_CanBindToNoEscape);
22452220

22462221
auto ROK = ReferenceOwnership::Strong;
22472222
if (auto *OA = var->getAttrs().getAttribute<ReferenceOwnershipAttr>())
22482223
ROK = OA->get();
2249-
22502224
switch (optionalityOf(ROK)) {
22512225
case ReferenceOwnershipOptionality::Required:
2252-
if (ty && ty->getOptionalObjectType())
2253-
return ty; // Already Optional<T>.
2254-
// Create a fresh type variable to handle overloaded expressions.
2255-
if (!ty || ty->is<TypeVariableType>())
2256-
ty = CS.createTypeVariable(CS.getConstraintLocator(locator),
2257-
TVO_CanBindToNoEscape);
2258-
return TypeChecker::getOptionalType(var->getLoc(), ty);
2226+
return TypeChecker::getOptionalType(var->getLoc(), varType);
22592227
case ReferenceOwnershipOptionality::Allowed:
22602228
case ReferenceOwnershipOptionality::Disallowed:
2261-
break;
2229+
return varType;
22622230
}
2263-
if (ty)
2264-
return ty;
2265-
return CS.createTypeVariable(CS.getConstraintLocator(locator),
2266-
TVO_CanBindToNoEscape);
22672231
}
22682232

22692233
case PatternKind::Typed: {

0 commit comments

Comments
 (0)