Skip to content
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
16 changes: 7 additions & 9 deletions lib/SILOptimizer/SILCombiner/SILCombinerApplyVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -343,14 +343,11 @@ bool SILCombiner::tryOptimizeKeypathOffsetOf(ApplyInst *AI,

KeyPathPattern *pattern = kp->getPattern();
SubstitutionMap patternSubs = kp->getSubstitutions();
CanType rootTy = pattern->getRootType().subst(patternSubs)->getCanonicalType();
SILFunction *f = AI->getFunction();
SILType rootTy = f->getLoweredType(Lowering::AbstractionPattern::getOpaque(),
pattern->getRootType().subst(patternSubs)->getCanonicalType());

// TODO: support lowering of the rootTy if it's not a legal SIL type in the
// first place, e.g. if it contains an AnyFunctionType.
if (!rootTy->isLegalSILType())
return false;

CanType parentTy = rootTy;
SILType parentTy = rootTy;

// First check if _storedInlineOffset would return an offset or nil. Basically
// only stored struct and tuple elements produce an offset. Everything else
Expand Down Expand Up @@ -387,14 +384,15 @@ bool SILCombiner::tryOptimizeKeypathOffsetOf(ApplyInst *AI,
hasOffset = false;
break;
}
parentTy = component.getComponentType();
parentTy = f->getLoweredType(Lowering::AbstractionPattern::getOpaque(),
component.getComponentType());
}

SILLocation loc = AI->getLoc();
SILValue result;

if (hasOffset) {
SILType rootAddrTy = SILType::getPrimitiveAddressType(rootTy);
SILType rootAddrTy = rootTy.getAddressType();
SILValue rootAddr = Builder.createBaseAddrForOffset(loc, rootAddrTy);

auto projector = KeyPathProjector::create(kp, rootAddr, loc, Builder);
Expand Down
5 changes: 4 additions & 1 deletion test/SILOptimizer/keypath_offset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,10 @@ func testTupleOffsets() {
printOffset(TLayout.offset(of: \Tuple<Int, Int>.1))
}

// Just check that we don't crash.
// CHECK-LABEL: sil {{.*}} @$s4test0A16TupleOfFunctionsyyF
// CHECK-NOT: _storedInlineOffset
// CHECK-NOT: class_method
// CHECK: } // end sil function '$s4test0A16TupleOfFunctionsyyF'
@inline(never)
func testTupleOfFunctions() {
printOffset(MemoryLayout<TupleOfFunctions>.offset(of: \.b))
Expand Down