Skip to content

More member reference simplification #9824

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,8 @@ void Solution::computeSubstitutions(
return;

TypeSubstitutionMap subs;
for (const auto &opened : openedTypes->second) {
subs[opened.first->castTo<GenericTypeParamType>()] =
getFixedType(opened.second);
}
for (const auto &opened : openedTypes->second)
subs[opened.first] = getFixedType(opened.second);

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

Expand Down
25 changes: 14 additions & 11 deletions lib/Sema/CodeSynthesis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,13 +89,14 @@ static ParamDecl *buildInOutArgument(SourceLoc loc, DeclContext *DC,
}

static Type getTypeOfStorage(AbstractStorageDecl *storage,
TypeChecker &TC,
bool wantInterfaceType) {
if (auto var = dyn_cast<VarDecl>(storage))
return TC.getTypeOfRValue(var, wantInterfaceType);
if (auto var = dyn_cast<VarDecl>(storage)) {
auto type = (wantInterfaceType
? var->getInterfaceType()
: var->getType());
return type->getReferenceStorageReferent();
}

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

auto storageInterfaceType = getTypeOfStorage(storage, TC, true);
auto storageInterfaceType = getTypeOfStorage(storage, true);

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

// Add a "(value : T, indices...)" argument list.
auto storageType = getTypeOfStorage(storage, TC, false);
auto storageInterfaceType = getTypeOfStorage(storage, TC, true);
auto storageType = getTypeOfStorage(storage, false);
auto storageInterfaceType = getTypeOfStorage(storage, true);
valueDecl = buildLetArgument(storage->getLoc(),
storage->getDeclContext(), "value",
storageType,
Expand Down Expand Up @@ -615,7 +616,7 @@ static Expr *synthesizeCopyWithZoneCall(Expr *Val, VarDecl *VD,

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

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

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

auto varType = tc.getTypeOfRValue(var, false);
auto varInterfaceType = tc.getTypeOfRValue(var, true);
auto varType = var->getType()
->getReferenceStorageReferent();
auto varInterfaceType = var->getInterfaceType()
->getReferenceStorageReferent();

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