Skip to content

[SIL] Fix tuple keypath verifier #60737

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 1 commit into from
Aug 26, 2022
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
10 changes: 5 additions & 5 deletions lib/SIL/Verifier/SILVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -418,19 +418,19 @@ void verifyKeyPathComponent(SILModule &M,
break;
}
case KeyPathPatternComponent::Kind::TupleElement: {
require(loweredBaseTy.is<TupleType>(),
require(baseTy->is<TupleType>(),
"invalid baseTy, should have been a TupleType");

auto tupleTy = loweredBaseTy.castTo<TupleType>();
auto tupleTy = baseTy->castTo<TupleType>();
auto eltIdx = component.getTupleIndex();

require(eltIdx < tupleTy->getNumElements(),
"invalid element index, greater than # of tuple elements");

auto eltTy = tupleTy.getElementType(eltIdx)
.getReferenceStorageReferent();
auto eltTy = tupleTy->getElementType(eltIdx)
->getReferenceStorageReferent();

require(eltTy == componentTy,
require(eltTy->isEqual(componentTy),
"tuple element type should match the type of the component");

break;
Expand Down
8 changes: 8 additions & 0 deletions test/SILGen/keypaths.swift
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,14 @@ func tuples(_: T) {
let _: ReferenceWritableKeyPath<T, Int> = \T.c.x.x
// CHECK: keypath $KeyPath<T, String>, (root $T; stored_property #T.c : $(x: C<Int>, y: C<String>); tuple_element #0 : $C<Int>; stored_property #C.y : $String)
let _: KeyPath<T, String> = \T.c.x.y

typealias Thing = (type: Any.Type, fn: () -> ())

// CHECK: keypath $WritableKeyPath<(type: any Any.Type, fn: () -> ()), any Any.Type>, (root $(type: any Any.Type, fn: () -> ()); tuple_element #0 : $any Any.Type)
let _: WritableKeyPath<Thing, Any.Type> = \Thing.type

// CHECK: keypath $WritableKeyPath<(type: any Any.Type, fn: () -> ()), () -> ()>, (root $(type: any Any.Type, fn: () -> ()); tuple_element #1 : $() -> ())
let _: WritableKeyPath<Thing, () -> ()> = \Thing.fn
}

// CHECK-LABEL: sil hidden [ossa] @{{.*}}tuples_generic
Expand Down