AST: Remove Expr's LValueAccessKind

This commit is contained in:
Slava Pestov
2018-07-05 22:54:26 -07:00
parent 2ec0842360
commit 381483bd74
11 changed files with 5 additions and 303 deletions

View File

@@ -246,22 +246,6 @@ getImplicitMemberReferenceAccessSemantics(Expr *base, VarDecl *member,
return member->getAccessSemanticsFromContext(DC, isAccessOnSelf);
}
void ConstraintSystem::propagateLValueAccessKind(Expr *E, AccessKind accessKind,
bool isShallow,
bool allowOverwrite) {
// If solver is set up in "shallow" mode we expect that some of the
// sub-expressions are already type-checked which means that they
// already have access kind set.
if (isShallow && E->hasLValueAccessKind() && !allowOverwrite)
return;
E->propagateLValueAccessKind(accessKind,
[&](Expr *E) -> Type {
return getType(E);
},
allowOverwrite);
}
bool ConstraintSystem::isTypeReference(const Expr *E) {
return E->isTypeReference([&](const Expr *E) -> Type { return getType(E); });
}
@@ -425,7 +409,6 @@ namespace {
DeclContext *dc;
const Solution &solution;
bool SuppressDiagnostics;
bool IsShallow;
/// Recognize used conformances from an imported type when we must emit
/// the witness table.
@@ -895,16 +878,6 @@ namespace {
}
}
// If the opaque value has an l-value access kind, then
// the OpenExistentialExpr isn't making a derived l-value, which
// means this is our only chance to propagate the l-value access kind
// down to the original existential value. Otherwise, propagateLVAK
// will handle this.
if (record.OpaqueValue && record.OpaqueValue->hasLValueAccessKind())
cs.propagateLValueAccessKind(record.ExistentialValue,
record.OpaqueValue->getLValueAccessKind(),
IsShallow);
// Form the open-existential expression.
result = new (tc.Context) OpenExistentialExpr(
record.ExistentialValue,
@@ -1854,9 +1827,9 @@ namespace {
public:
ExprRewriter(ConstraintSystem &cs, const Solution &solution,
bool suppressDiagnostics, bool shallow = false)
bool suppressDiagnostics)
: cs(cs), dc(cs.DC), solution(solution),
SuppressDiagnostics(suppressDiagnostics), IsShallow(shallow) {}
SuppressDiagnostics(suppressDiagnostics) {}
ConstraintSystem &getConstraintSystem() const { return cs; }
@@ -3176,13 +3149,6 @@ namespace {
}
Expr *visitInOutExpr(InOutExpr *expr) {
// The default assumption is that inouts are read-write. It's easier
// to do this unconditionally here and then overwrite in the exception
// case (when we turn the inout into an UnsafePointer) than to try to
// discover that we're in that case right now.
if (!cs.getType(expr->getSubExpr())->is<UnresolvedType>())
cs.propagateLValueAccessKind(expr->getSubExpr(), AccessKind::ReadWrite,
IsShallow);
auto objectTy = cs.getType(expr->getSubExpr())->getRValueType();
// The type is simply inout of whatever the lvalue's object type was.
@@ -3875,8 +3841,6 @@ namespace {
auto destTy = cs.computeAssignDestType(expr->getDest(), expr->getLoc());
if (!destTy)
return nullptr;
cs.propagateLValueAccessKind(expr->getDest(), AccessKind::Write,
IsShallow);
// Convert the source to the simplified destination type.
auto locator =
@@ -4197,11 +4161,6 @@ namespace {
return E;
}
if (cs.getType(subExpr)->hasLValueType()) {
// Treat this like a read of the property.
cs.propagateLValueAccessKind(subExpr, AccessKind::Read, IsShallow);
}
// Check that we requested a property getter or setter.
switch (E->getSelectorKind()) {
case ObjCSelectorExpr::Method: {
@@ -6601,7 +6560,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
// Load from the lvalue. If we're loading the result of a force,
// swap the order so that we load first and force the result.
cs.propagateLValueAccessKind(expr, AccessKind::Read, IsShallow);
if (auto *forceExpr = dyn_cast<ForceValueExpr>(expr)) {
fromType = cs.getType(forceExpr->getSubExpr())->getRValueType();
auto *loadExpr = cs.cacheType(
@@ -6708,13 +6666,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
PointerTypeKind pointerKind;
auto toEltType = unwrappedTy->getAnyPointerElementType(pointerKind);
assert(toEltType && "not a pointer type?"); (void) toEltType;
if (pointerKind == PTK_UnsafePointer) {
// Overwrite the l-value access kind to be read-only if we're
// converting to a non-mutable pointer type.
auto *E = cast<InOutExpr>(expr->getValueProvidingExpr())->getSubExpr();
cs.propagateLValueAccessKind(E, AccessKind::Read, IsShallow,
/*overwrite*/ true);
}
tc.requirePointerArgumentIntrinsics(expr->getLoc());
Expr *result =
@@ -6820,7 +6771,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
// In an 'inout' operator like "i += 1", the operand is converted from
// an implicit lvalue to an inout argument.
assert(toIO->getObjectType()->isEqual(fromLValue->getObjectType()));
cs.propagateLValueAccessKind(expr, AccessKind::ReadWrite, IsShallow);
return cs.cacheType(new (tc.Context)
InOutExpr(expr->getStartLoc(), expr,
toIO->getObjectType(),
@@ -6839,7 +6789,6 @@ Expr *ExprRewriter::coerceToType(Expr *expr, Type toType,
if (performLoad) {
// Load from the lvalue.
cs.propagateLValueAccessKind(expr, AccessKind::Read, IsShallow);
expr = cs.cacheType(new (tc.Context)
LoadExpr(expr, fromLValue->getObjectType()));
@@ -7100,7 +7049,6 @@ ExprRewriter::coerceObjectArgumentToType(Expr *expr,
// Use InOutExpr to convert it to an explicit inout argument for the
// receiver.
cs.propagateLValueAccessKind(expr, AccessKind::ReadWrite, IsShallow);
return cs.cacheType(new (ctx) InOutExpr(expr->getStartLoc(), expr,
toInOutTy->getInOutObjectType(),
/*isImplicit*/ true));
@@ -8263,7 +8211,7 @@ Expr *ConstraintSystem::applySolution(Solution &solution, Expr *expr,
Expr *ConstraintSystem::applySolutionShallow(const Solution &solution,
Expr *expr,
bool suppressDiagnostics) {
ExprRewriter rewriter(*this, solution, suppressDiagnostics, true);
ExprRewriter rewriter(*this, solution, suppressDiagnostics);
rewriter.walkToExprPre(expr);
Expr *result = rewriter.walkToExprPost(expr);
if (result)