Skip to content

SIL: Canonicalize subscript element type with respect to generic signature when lowering accessor type #21519

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
11 changes: 6 additions & 5 deletions lib/SIL/SILFunctionType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -865,15 +865,17 @@ static void destructureYieldsForCoroutine(SILModule &M,
.getReferenceStorageReferentType();

auto storage = accessor->getStorage();
auto valueType = storage->getValueInterfaceType()
->getReferenceStorageReferent();
auto valueType = storage->getValueInterfaceType();
if (reqtSubs) {
valueType = valueType.subst(*reqtSubs);
}

auto canValueType = valueType->getCanonicalType(
accessor->getGenericSignature());

// 'modify' yields an inout of the target type.
if (accessor->getAccessorKind() == AccessorKind::Modify) {
auto loweredValueTy = M.Types.getLoweredType(origType, valueType);
auto loweredValueTy = M.Types.getLoweredType(origType, canValueType);
yields.push_back(SILYieldInfo(loweredValueTy.getASTType(),
ParameterConvention::Indirect_Inout));
return;
Expand All @@ -882,8 +884,7 @@ static void destructureYieldsForCoroutine(SILModule &M,
// 'read' yields a borrowed value of the target type, destructuring
// tuples as necessary.
assert(accessor->getAccessorKind() == AccessorKind::Read);
destructureYieldsForReadAccessor(M, origType, valueType->getCanonicalType(),
yields);
destructureYieldsForReadAccessor(M, origType, canValueType, yields);
}

/// Create the appropriate SIL function type for the given formal type
Expand Down
15 changes: 14 additions & 1 deletion test/SILGen/subscript_accessor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,20 @@ struct X<T> {
}
}

// CHECK: sil{{.*}}s18subscript_accessor9testXRead1xxAA1XVyxG_tlF
// Don't crash dealing with T? in a non-generic context.
// rdar://44762116
struct WillBeConcretelyConstrained<T> {}
extension WillBeConcretelyConstrained where T == Int {
subscript(key: Int) -> T? {
get { return nil }
set {}
}
}

// CHECK-LABEL: sil hidden [transparent] @$s18subscript_accessor27WillBeConcretelyConstrainedVAASiRszlEySiSgSiciM
// CHECK-SAME: $@yield_once @convention(method) (Int, @inout WillBeConcretelyConstrained<Int>) -> @yields @inout Optional<Int>

// CHECK: sil{{.*}}s18subscript_accessor9testXRead1xxAA1XVyxG_tlF
@_specialize(where T == (Int, Int))
func testXRead<T>(x: X<T>) -> T {
return x[]!
Expand Down