Skip to content

Commit 451600c

Browse files
authored
Merge pull request #9824 from slavapestov/more-member-reference-simplification
More member reference simplification
2 parents 1bf63c1 + 73976b2 commit 451600c

File tree

7 files changed

+197
-222
lines changed

7 files changed

+197
-222
lines changed

lib/Sema/CSApply.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,8 @@ void Solution::computeSubstitutions(
7272
return;
7373

7474
TypeSubstitutionMap subs;
75-
for (const auto &opened : openedTypes->second) {
76-
subs[opened.first->castTo<GenericTypeParamType>()] =
77-
getFixedType(opened.second);
78-
}
75+
for (const auto &opened : openedTypes->second)
76+
subs[opened.first] = getFixedType(opened.second);
7977

8078
auto &tc = getConstraintSystem().getTypeChecker();
8179

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

0 commit comments

Comments
 (0)