Skip to content

Commit 5795f88

Browse files
committed
[Sema] Change OpaqueValueExpr to take a SourceRange instead of just a single SourceLoc
1 parent 1024447 commit 5795f88

File tree

3 files changed

+33
-42
lines changed

3 files changed

+33
-42
lines changed

include/swift/AST/Expr.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3843,11 +3843,12 @@ class DynamicTypeExpr : public Expr {
38433843
/// node (say, an \c OpenExistentialExpr) and can only be used within the
38443844
/// subexpressions of that AST node.
38453845
class OpaqueValueExpr : public Expr {
3846-
SourceLoc Loc;
3846+
SourceRange Range;
38473847

38483848
public:
3849-
explicit OpaqueValueExpr(SourceLoc Loc, Type Ty, bool isPlaceholder = false)
3850-
: Expr(ExprKind::OpaqueValue, /*Implicit=*/true, Ty), Loc(Loc) {
3849+
explicit OpaqueValueExpr(SourceRange Range, Type Ty,
3850+
bool isPlaceholder = false)
3851+
: Expr(ExprKind::OpaqueValue, /*Implicit=*/true, Ty), Range(Range) {
38513852
Bits.OpaqueValueExpr.IsPlaceholder = isPlaceholder;
38523853
}
38533854

@@ -3856,8 +3857,8 @@ class OpaqueValueExpr : public Expr {
38563857
/// value to be specified later.
38573858
bool isPlaceholder() const { return Bits.OpaqueValueExpr.IsPlaceholder; }
38583859

3859-
SourceRange getSourceRange() const { return Loc; }
3860-
3860+
SourceRange getSourceRange() const { return Range; }
3861+
38613862
static bool classof(const Expr *E) {
38623863
return E->getKind() == ExprKind::OpaqueValue;
38633864
}

lib/Sema/CSApply.cpp

Lines changed: 26 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ namespace {
669669

670670
ASTContext &ctx = tc.Context;
671671
auto archetypeVal =
672-
new (ctx) OpaqueValueExpr(base->getStartLoc(), opaqueType);
672+
new (ctx) OpaqueValueExpr(base->getSourceRange(), opaqueType);
673673
cs.cacheType(archetypeVal);
674674

675675
// Record the opened existential.
@@ -2170,8 +2170,8 @@ namespace {
21702170

21712171
// This OpaqueValueExpr represents the result of builderInit above in
21722172
// silgen.
2173-
OpaqueValueExpr *interpolationExpr =
2174-
new (tc.Context) OpaqueValueExpr(expr->getLoc(), interpolationType);
2173+
OpaqueValueExpr *interpolationExpr = new (tc.Context)
2174+
OpaqueValueExpr(expr->getSourceRange(), interpolationType);
21752175
cs.setType(interpolationExpr, interpolationType);
21762176
expr->setInterpolationExpr(interpolationExpr);
21772177

@@ -5044,8 +5044,8 @@ Expr *ExprRewriter::coerceTupleToTuple(Expr *expr,
50445044
SmallVector<OpaqueValueExpr *, 4> destructured;
50455045
for (unsigned i = 0, e = sources.size(); i != e; ++i) {
50465046
auto fromEltType = fromTuple->getElementType(i);
5047-
auto *opaqueElt = new (tc.Context) OpaqueValueExpr(expr->getLoc(),
5048-
fromEltType);
5047+
auto *opaqueElt =
5048+
new (tc.Context) OpaqueValueExpr(expr->getSourceRange(), fromEltType);
50495049
cs.cacheType(opaqueElt);
50505050
destructured.push_back(opaqueElt);
50515051
}
@@ -5139,10 +5139,8 @@ Expr *ExprRewriter::coerceSuperclass(Expr *expr, Type toType,
51395139
// concrete superclass.
51405140
auto fromArchetype = OpenedArchetypeType::getAny(fromType);
51415141

5142-
auto *archetypeVal =
5143-
cs.cacheType(
5144-
new (tc.Context) OpaqueValueExpr(expr->getLoc(),
5145-
fromArchetype));
5142+
auto *archetypeVal = cs.cacheType(new (tc.Context) OpaqueValueExpr(
5143+
expr->getSourceRange(), fromArchetype));
51465144

51475145
auto *result = coerceSuperclass(archetypeVal, toType, locator);
51485146

@@ -5205,12 +5203,10 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType,
52055203
// For existential-to-existential coercions, open the source existential.
52065204
if (fromType->isAnyExistentialType()) {
52075205
fromType = OpenedArchetypeType::getAny(fromType);
5208-
5209-
auto *archetypeVal =
5210-
cs.cacheType(
5211-
new (ctx) OpaqueValueExpr(expr->getLoc(),
5212-
fromType));
5213-
5206+
5207+
auto *archetypeVal = cs.cacheType(
5208+
new (ctx) OpaqueValueExpr(expr->getSourceRange(), fromType));
5209+
52145210
auto *result = cs.cacheType(ErasureExpr::create(ctx, archetypeVal, toType,
52155211
conformances));
52165212
return cs.cacheType(
@@ -5895,10 +5891,8 @@ maybeDiagnoseUnsupportedFunctionConversion(ConstraintSystem &cs, Expr *expr,
58955891

58965892
/// Build the conversion of an element in a collection upcast.
58975893
static Expr *buildElementConversion(ExprRewriter &rewriter,
5898-
SourceLoc srcLoc,
5899-
Type srcType,
5900-
Type destType,
5901-
bool bridged,
5894+
SourceRange srcRange, Type srcType,
5895+
Type destType, bool bridged,
59025896
ConstraintLocatorBuilder locator,
59035897
Expr *element) {
59045898
auto &cs = rewriter.getConstraintSystem();
@@ -5918,12 +5912,9 @@ static Expr *buildElementConversion(ExprRewriter &rewriter,
59185912
}
59195913

59205914
static CollectionUpcastConversionExpr::ConversionPair
5921-
buildOpaqueElementConversion(ExprRewriter &rewriter,
5922-
SourceLoc srcLoc,
5923-
Type srcCollectionType,
5924-
Type destCollectionType,
5925-
bool bridged,
5926-
ConstraintLocatorBuilder locator,
5915+
buildOpaqueElementConversion(ExprRewriter &rewriter, SourceRange srcRange,
5916+
Type srcCollectionType, Type destCollectionType,
5917+
bool bridged, ConstraintLocatorBuilder locator,
59275918
unsigned typeArgIndex) {
59285919
// We don't need this stuff unless we've got generalized casts.
59295920
Type srcType = srcCollectionType->castTo<BoundGenericType>()
@@ -5935,14 +5926,13 @@ buildOpaqueElementConversion(ExprRewriter &rewriter,
59355926
auto &cs = rewriter.getConstraintSystem();
59365927
ASTContext &ctx = cs.getASTContext();
59375928
auto opaque =
5938-
rewriter.cs.cacheType(new (ctx) OpaqueValueExpr(srcLoc, srcType));
5929+
rewriter.cs.cacheType(new (ctx) OpaqueValueExpr(srcRange, srcType));
59395930

5940-
Expr *conversion =
5941-
buildElementConversion(rewriter, srcLoc, srcType, destType, bridged,
5942-
locator.withPathElement(
5943-
ConstraintLocator::PathElement::getGenericArgument(
5944-
typeArgIndex)),
5945-
opaque);
5931+
Expr *conversion = buildElementConversion(
5932+
rewriter, srcRange, srcType, destType, bridged,
5933+
locator.withPathElement(
5934+
ConstraintLocator::PathElement::getGenericArgument(typeArgIndex)),
5935+
opaque);
59465936

59475937
return { opaque, conversion };
59485938
}
@@ -6997,9 +6987,9 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
69976987
bodyFnTy->withExtInfo(bodyFnTy->getExtInfo().withNoEscape()));
69986988
body = coerceToType(body, bodyFnTy, locator);
69996989
assert(body && "can't make nonescaping?!");
7000-
6990+
70016991
auto escapable = new (tc.Context)
7002-
OpaqueValueExpr(apply->getFn()->getLoc(), Type());
6992+
OpaqueValueExpr(apply->getFn()->getSourceRange(), Type());
70036993
cs.setType(escapable, escapableParams[0].getOldType());
70046994

70056995
auto getType = [&](const Expr *E) -> Type {
@@ -7056,8 +7046,8 @@ Expr *ExprRewriter::finishApply(ApplyExpr *apply, Type openedType,
70567046
->getOpenedExistentialType()
70577047
->isEqual(existentialInstanceTy));
70587048

7059-
auto opaqueValue = new (tc.Context)
7060-
OpaqueValueExpr(apply->getLoc(), openedTy);
7049+
auto opaqueValue =
7050+
new (tc.Context) OpaqueValueExpr(apply->getSourceRange(), openedTy);
70617051
cs.setType(opaqueValue, openedTy);
70627052

70637053
auto getType = [&](const Expr *E) -> Type {

lib/Sema/TypeCheckStorage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2446,7 +2446,7 @@ PropertyWrapperBackingPropertyInfoRequest::evaluate(Evaluator &evaluator,
24462446
// Form the initialization of the backing property from a value of the
24472447
// original property's type.
24482448
OpaqueValueExpr *origValue =
2449-
new (ctx) OpaqueValueExpr(var->getLoc(), var->getType(),
2449+
new (ctx) OpaqueValueExpr(var->getSourceRange(), var->getType(),
24502450
/*isPlaceholder=*/true);
24512451
Expr *initializer = buildPropertyWrapperInitialValueCall(
24522452
var, storageType, origValue,

0 commit comments

Comments
 (0)