Skip to content

Commit 641e9e9

Browse files
authored
Merge pull request #16215 from DougGregor/silgen-subscript-fix-4.2
2 parents c66dbaf + a15a0ad commit 641e9e9

File tree

4 files changed

+37
-13
lines changed

4 files changed

+37
-13
lines changed

include/swift/AST/Types.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1617,12 +1617,6 @@ class NameAliasType final
16171617
return getNumSubstitutions();
16181618
}
16191619

1620-
/// Retrieve the set of substitutions to be applied to the declaration to
1621-
/// produce the underlying type.
1622-
SubstitutionList getSubstitutionList() const {
1623-
return {getTrailingObjects<Substitution>(), getNumSubstitutions()};
1624-
}
1625-
16261620
/// Retrieve the generic signature used for substitutions.
16271621
GenericSignature *getGenericSignature() const {
16281622
return getNumSubstitutions() > 0
@@ -1648,6 +1642,12 @@ class NameAliasType final
16481642
: Type();
16491643
}
16501644

1645+
/// Retrieve the set of substitutions to be applied to the declaration to
1646+
/// produce the underlying type.
1647+
SubstitutionList getSubstitutionList() const {
1648+
return {getTrailingObjects<Substitution>(), getNumSubstitutions()};
1649+
}
1650+
16511651
/// Retrieve the substitution map applied to the declaration's underlying
16521652
/// to produce the described type.
16531653
SubstitutionMap getSubstitutionMap() const;

lib/SILGen/SILGenApply.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5073,7 +5073,7 @@ void SILGenFunction::emitSetAccessor(SILLocation loc, SILDeclRef set,
50735073
if (!subscripts.isNull()) {
50745074
// If we have a value and index list, create a new rvalue to represent the
50755075
// both of them together.
5076-
auto inputTupleType = cast<TupleType>(accessType.getInput());
5076+
auto inputTupleType = dyn_cast<TupleType>(accessType.getInput());
50775077

50785078
SmallVector<ArgumentSource, 4> eltSources;
50795079

@@ -5086,18 +5086,25 @@ void SILGenFunction::emitSetAccessor(SILLocation loc, SILDeclRef set,
50865086
// TODO: we should really take an array of RValues.
50875087
if (accessType->getNumParams() != 2) {
50885088
auto subscriptsTupleType = cast<TupleType>(subscripts.getType());
5089-
assert(inputTupleType->getNumElements()
5089+
assert(accessType.getParams().size()
50905090
== 1 + subscriptsTupleType->getNumElements());
50915091
SmallVector<RValue, 8> eltRVs;
50925092
std::move(subscripts).extractElements(eltRVs);
50935093
for (auto &elt : eltRVs)
50945094
eltSources.emplace_back(loc, std::move(elt));
50955095
} else {
5096+
assert(inputTupleType && "Must have an input tuple here");
50965097
subscripts.rewriteType(inputTupleType.getElementType(1));
50975098
eltSources.emplace_back(loc, std::move(subscripts));
50985099
}
50995100

5100-
setValue = ArgumentSource(loc, inputTupleType, eltSources);
5101+
if (eltSources.size() == 1) {
5102+
setValue = std::move(eltSources.front());
5103+
} else {
5104+
assert(inputTupleType);
5105+
setValue = ArgumentSource(loc, inputTupleType, eltSources);
5106+
}
5107+
51015108
} else {
51025109
setValue.rewriteType(accessType.getInput());
51035110
}

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3631,10 +3631,7 @@ void Serializer::writeType(Type ty) {
36313631
addTypeRef(alias->getParent()),
36323632
addTypeRef(alias->getSinglyDesugaredType()));
36333633
// Write the set of substitutions.
3634-
SmallVector<Substitution, 4> flatSubs;
3635-
if (auto genericSig = typeAlias->getGenericSignature())
3636-
genericSig->getSubstitutions(alias->getSubstitutionMap(), flatSubs);
3637-
writeSubstitutions(flatSubs, DeclTypeAbbrCodes);
3634+
writeSubstitutions(alias->getSubstitutionList(), DeclTypeAbbrCodes);
36383635
break;
36393636
}
36403637

test/SILGen/subscript_accessor.swift

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: %target-swift-frontend -enable-sil-ownership -O -emit-sil -primary-file %s | %FileCheck %s
2+
3+
// CHECK-LABEL: sil private [transparent] @$S18subscript_accessor1XVxSgycimytfU_
4+
// CHECK: [[SETTER:%.*]] = function_ref @$S18subscript_accessor1XVxSgycis
5+
// CHECK-NEXT: apply [[SETTER]]<T>
6+
struct X<T> {
7+
subscript () -> T? {
8+
get {
9+
return nil
10+
}
11+
set { }
12+
}
13+
}
14+
15+
// CHECK: sil{{.*}}S18subscript_accessor9testXRead1xxAA1XVyxG_tlF
16+
@_specialize(where T == (Int, Int))
17+
func testXRead<T>(x: X<T>) -> T {
18+
return x[]!
19+
}
20+
// CHECK: $S18subscript_accessor1XVxSgycisTf4dn_n

0 commit comments

Comments
 (0)