Merge pull request #42146 from xedin/rdar-91145060

[ConstraintSystem] Cache types of `~=` components
This commit is contained in:
Pavel Yaskevich
2022-04-04 10:35:52 -07:00
committed by GitHub
3 changed files with 6 additions and 3 deletions

View File

@@ -8774,7 +8774,7 @@ ExprWalker::rewriteTarget(SolutionApplicationTarget target) {
if (auto *enumElement = dyn_cast<EnumElementPattern>(info.pattern)) {
if (auto target = cs.getSolutionApplicationTarget(enumElement)) {
auto *EP = target->getExprPattern();
auto enumType = solution.simplifyType(EP->getType());
auto enumType = solution.getResolvedType(EP);
auto *matchCall = target->getAsExpr();

View File

@@ -8944,6 +8944,9 @@ static bool inferEnumMemberThroughTildeEqualsOperator(
std::tie(matchVar, matchCall) = *tildeEqualsApplication;
cs.setType(matchVar, enumTy);
cs.setType(EP, enumTy);
// result of ~= operator is always a `Bool`.
auto target = SolutionApplicationTarget::forExprPattern(
matchCall, DC, EP, ctx.getBoolDecl()->getDeclaredInterfaceType());
@@ -8972,7 +8975,6 @@ static bool inferEnumMemberThroughTildeEqualsOperator(
// Store the $match variable and binary expression for solution application.
EP->setMatchVar(matchVar);
EP->setMatchExpr(matchCall);
EP->setType(enumTy);
cs.setSolutionApplicationTarget(pattern, target);

View File

@@ -880,6 +880,8 @@ bool TypeChecker::typeCheckExprPattern(ExprPattern *EP, DeclContext *DC,
std::tie(matchVar, matchCall) = *tildeEqualsApplication;
matchVar->setInterfaceType(rhsType->mapTypeOutOfContext());
// Result of `~=` should always be a boolean.
auto contextualTy = Context.getBoolDecl()->getDeclaredInterfaceType();
auto target = SolutionApplicationTarget::forExprPattern(matchCall, DC, EP,
@@ -908,7 +910,6 @@ TypeChecker::synthesizeTildeEqualsOperatorApplication(ExprPattern *EP,
auto *matchVar =
new (Context) VarDecl(/*IsStatic*/ false, VarDecl::Introducer::Let,
EP->getLoc(), Context.Id_PatternMatchVar, DC);
matchVar->setInterfaceType(enumType->mapTypeOutOfContext());
matchVar->setImplicit();