[AST/Sema] Remove TypeWrapper feature functionality

This commit is contained in:
Pavel Yaskevich
2023-02-08 00:16:00 -08:00
parent 30531c2dd6
commit e2b22d9f62
22 changed files with 6 additions and 2058 deletions

View File

@@ -1690,51 +1690,6 @@ namespace {
return fnTy->castTo<FunctionType>()->getResult();
};
auto isAssignmentDestination = [&](ConstraintLocatorBuilder locator) {
if (auto *anchor = getAsExpr(locator.getAnchor())) {
if (auto *assignment =
getAsExpr<AssignExpr>(cs.getParentExpr(anchor)))
return assignment->getDest() == anchor;
}
return false;
};
// If this is a reference to an immutable type wrapper
// managed property used as an assignment destination
// i.e. `self.<name> = ...` in an initializer context,
// let's rewrite member access from `self` to `_storage`
// injected by the compiler to support type wrapper
// initialization.
//
// Note that this is safe to do only for immutable
// properties because they do no support re-assignment.
if (isa<ConstructorDecl>(cs.DC) && varDecl->isLet() &&
varDecl->isAccessedViaTypeWrapper() &&
isAssignmentDestination(memberLocator)) {
auto *ctor = cast<ConstructorDecl>(cs.DC);
auto *storageVar = ctor->getLocalTypeWrapperStorageVar();
auto *storageVarTy =
storageVar->getInterfaceType()->castTo<TupleType>();
base =
new (context) DeclRefExpr(storageVar, DeclNameLoc(base->getLoc()),
/*implicit=*/true);
base->setType(
LValueType::get(ctor->mapTypeIntoContext(storageVarTy)));
cs.cacheType(base);
Expr *memberRefExpr = new (context) TupleElementExpr(
base, /*DotLoc=*/SourceLoc(),
storageVarTy->getNamedElementId(varDecl->getName()),
memberLoc.getBaseNameLoc(), resultType(refTy));
memberRefExpr->setImplicit();
cs.cacheType(memberRefExpr);
return forceUnwrapIfExpected(memberRefExpr, memberLocator);
}
if (isUnboundInstanceMember) {
assert(memberLocator.getBaseLocator() &&
cs.UnevaluatedRootExprs.count(