@@ -343,8 +343,11 @@ bool SILCombiner::tryOptimizeKeypathOffsetOf(ApplyInst *AI,
343343
344344 KeyPathPattern *pattern = kp->getPattern ();
345345 SubstitutionMap patternSubs = kp->getSubstitutions ();
346- CanType rootTy = pattern->getRootType ().subst (patternSubs)->getCanonicalType ();
347- CanType parentTy = rootTy;
346+ SILFunction *f = AI->getFunction ();
347+ SILType rootTy = f->getLoweredType (Lowering::AbstractionPattern::getOpaque (),
348+ pattern->getRootType ().subst (patternSubs)->getCanonicalType ());
349+
350+ SILType parentTy = rootTy;
348351
349352 // First check if _storedInlineOffset would return an offset or nil. Basically
350353 // only stored struct and tuple elements produce an offset. Everything else
@@ -381,14 +384,15 @@ bool SILCombiner::tryOptimizeKeypathOffsetOf(ApplyInst *AI,
381384 hasOffset = false ;
382385 break ;
383386 }
384- parentTy = component.getComponentType ();
387+ parentTy = f->getLoweredType (Lowering::AbstractionPattern::getOpaque (),
388+ component.getComponentType ());
385389 }
386390
387391 SILLocation loc = AI->getLoc ();
388392 SILValue result;
389393
390394 if (hasOffset) {
391- SILType rootAddrTy = SILType::getPrimitiveAddressType ( rootTy);
395+ SILType rootAddrTy = rootTy. getAddressType ( );
392396 SILValue rootAddr = Builder.createBaseAddrForOffset (loc, rootAddrTy);
393397
394398 auto projector = KeyPathProjector::create (kp, rootAddr, loc, Builder);
0 commit comments