Skip to content

Commit 73976b2

Browse files
committed
Sema: Remove TypeChecker::getTypeOfRValue()
1 parent 2b86bed commit 73976b2

File tree

5 files changed

+21
-33
lines changed

5 files changed

+21
-33
lines changed

lib/Sema/CodeSynthesis.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,14 @@ static ParamDecl *buildInOutArgument(SourceLoc loc, DeclContext *DC,
8989
}
9090

9191
static Type getTypeOfStorage(AbstractStorageDecl *storage,
92-
TypeChecker &TC,
9392
bool wantInterfaceType) {
94-
if (auto var = dyn_cast<VarDecl>(storage))
95-
return TC.getTypeOfRValue(var, wantInterfaceType);
93+
if (auto var = dyn_cast<VarDecl>(storage)) {
94+
auto type = (wantInterfaceType
95+
? var->getInterfaceType()
96+
: var->getType());
97+
return type->getReferenceStorageReferent();
98+
}
9699

97-
// None of the transformations done by getTypeOfRValue are
98-
// necessary for subscripts.
99100
auto subscript = cast<SubscriptDecl>(storage);
100101
auto type = subscript->getElementInterfaceType();
101102
if (!wantInterfaceType)
@@ -156,7 +157,7 @@ static FuncDecl *createGetterPrototype(AbstractStorageDecl *storage,
156157
staticLoc = var->getLoc();
157158
}
158159

159-
auto storageInterfaceType = getTypeOfStorage(storage, TC, true);
160+
auto storageInterfaceType = getTypeOfStorage(storage, true);
160161

161162
auto getter = FuncDecl::create(
162163
TC.Context, staticLoc, StaticSpellingKind::None, loc, Identifier(), loc,
@@ -199,8 +200,8 @@ static FuncDecl *createSetterPrototype(AbstractStorageDecl *storage,
199200
}
200201

201202
// Add a "(value : T, indices...)" argument list.
202-
auto storageType = getTypeOfStorage(storage, TC, false);
203-
auto storageInterfaceType = getTypeOfStorage(storage, TC, true);
203+
auto storageType = getTypeOfStorage(storage, false);
204+
auto storageInterfaceType = getTypeOfStorage(storage, true);
204205
valueDecl = buildLetArgument(storage->getLoc(),
205206
storage->getDeclContext(), "value",
206207
storageType,
@@ -615,7 +616,7 @@ static Expr *synthesizeCopyWithZoneCall(Expr *Val, VarDecl *VD,
615616

616617
// We support @NSCopying on class types (which conform to NSCopying),
617618
// protocols which conform, and option types thereof.
618-
Type UnderlyingType = TC.getTypeOfRValue(VD, /*want interface type*/false);
619+
Type UnderlyingType = VD->getType()->getReferenceStorageReferent();
619620

620621
bool isOptional = false;
621622
if (Type optionalEltTy = UnderlyingType->getAnyOptionalObjectType()) {
@@ -1930,8 +1931,10 @@ ConstructorDecl *swift::createImplicitConstructor(TypeChecker &tc,
19301931

19311932
accessLevel = std::min(accessLevel, var->getFormalAccess());
19321933

1933-
auto varType = tc.getTypeOfRValue(var, false);
1934-
auto varInterfaceType = tc.getTypeOfRValue(var, true);
1934+
auto varType = var->getType()
1935+
->getReferenceStorageReferent();
1936+
auto varInterfaceType = var->getInterfaceType()
1937+
->getReferenceStorageReferent();
19351938

19361939
// If var is a lazy property, its value is provided for the underlying
19371940
// storage. We thus take an optional of the properties type. We only

lib/Sema/ConstraintSystem.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,12 @@ Type TypeChecker::getUnopenedTypeOfReference(VarDecl *value, Type baseType,
649649
if (value->isInvalid())
650650
return ErrorType::get(Context);
651651

652-
Type requestedType = getTypeOfRValue(value, wantInterfaceType);
652+
Type requestedType = (wantInterfaceType
653+
? value->getInterfaceType()
654+
: value->getType());
655+
656+
requestedType = requestedType->getLValueOrInOutObjectType()
657+
->getReferenceStorageReferent();
653658

654659
// If we're dealing with contextual types, and we referenced this type from
655660
// a different context, map the type.

lib/Sema/TypeCheckExpr.cpp

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -492,23 +492,6 @@ static Expr *foldSequence(TypeChecker &TC, DeclContext *DC,
492492
return makeBinOp(TC, op1.op, LHS, RHS, op1.precedence, S.empty());
493493
}
494494

495-
Type TypeChecker::getTypeOfRValue(ValueDecl *value, bool wantInterfaceType) {
496-
497-
Type type;
498-
if (wantInterfaceType) {
499-
if (!value->hasInterfaceType())
500-
validateDecl(value);
501-
type = value->getInterfaceType();
502-
} else {
503-
auto *var = cast<VarDecl>(value);
504-
if (!var->hasType())
505-
validateDecl(var);
506-
type = var->getType();
507-
}
508-
509-
return type->getLValueOrInOutObjectType()->getReferenceStorageReferent();
510-
}
511-
512495
bool TypeChecker::requireOptionalIntrinsics(SourceLoc loc) {
513496
if (Context.hasOptionalIntrinsics(this)) return false;
514497

lib/Sema/TypeCheckPattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1108,7 +1108,7 @@ bool TypeChecker::coercePatternToType(Pattern *&P, DeclContext *dc, Type type,
11081108
NP->getDecl()->setLet(false);
11091109
}
11101110
if (var->getAttrs().hasAttribute<OwnershipAttr>())
1111-
type = getTypeOfRValue(var, false);
1111+
type = var->getType()->getReferenceStorageReferent();
11121112
else if (!var->isInvalid())
11131113
type = var->getType();
11141114
P->setType(type);

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1705,9 +1705,6 @@ class TypeChecker final : public LazyResolver {
17051705
const DeclRefExpr *base = nullptr,
17061706
bool wantInterfaceType = false);
17071707

1708-
/// Return the non-lvalue type-of-reference of the given value.
1709-
Type getTypeOfRValue(ValueDecl *value, bool wantInterfaceType = false);
1710-
17111708
/// \brief Retrieve the default type for the given protocol.
17121709
///
17131710
/// Some protocols, particularly those that correspond to literals, have

0 commit comments

Comments
 (0)