@@ -343,14 +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 ();
346+ SILFunction *f = AI->getFunction ();
347+ SILType rootTy = f->getLoweredType (Lowering::AbstractionPattern::getOpaque (),
348+ pattern->getRootType ().subst (patternSubs)->getCanonicalType ());
347349
348- // TODO: support lowering of the rootTy if it's not a legal SIL type in the
349- // first place, e.g. if it contains an AnyFunctionType.
350- if (!rootTy->isLegalSILType ())
351- return false ;
352-
353- CanType parentTy = rootTy;
350+ SILType parentTy = rootTy;
354351
355352 // First check if _storedInlineOffset would return an offset or nil. Basically
356353 // only stored struct and tuple elements produce an offset. Everything else
@@ -387,14 +384,15 @@ bool SILCombiner::tryOptimizeKeypathOffsetOf(ApplyInst *AI,
387384 hasOffset = false ;
388385 break ;
389386 }
390- parentTy = component.getComponentType ();
387+ parentTy = f->getLoweredType (Lowering::AbstractionPattern::getOpaque (),
388+ component.getComponentType ());
391389 }
392390
393391 SILLocation loc = AI->getLoc ();
394392 SILValue result;
395393
396394 if (hasOffset) {
397- SILType rootAddrTy = SILType::getPrimitiveAddressType ( rootTy);
395+ SILType rootAddrTy = rootTy. getAddressType ( );
398396 SILValue rootAddr = Builder.createBaseAddrForOffset (loc, rootAddrTy);
399397
400398 auto projector = KeyPathProjector::create (kp, rootAddr, loc, Builder);
0 commit comments