@@ -343,14 +343,11 @@ bool SILCombiner::tryOptimizeKeypathOffsetOf(ApplyInst *AI,
343
343
344
344
KeyPathPattern *pattern = kp->getPattern ();
345
345
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 ());
347
349
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;
354
351
355
352
// First check if _storedInlineOffset would return an offset or nil. Basically
356
353
// only stored struct and tuple elements produce an offset. Everything else
@@ -387,14 +384,15 @@ bool SILCombiner::tryOptimizeKeypathOffsetOf(ApplyInst *AI,
387
384
hasOffset = false ;
388
385
break ;
389
386
}
390
- parentTy = component.getComponentType ();
387
+ parentTy = f->getLoweredType (Lowering::AbstractionPattern::getOpaque (),
388
+ component.getComponentType ());
391
389
}
392
390
393
391
SILLocation loc = AI->getLoc ();
394
392
SILValue result;
395
393
396
394
if (hasOffset) {
397
- SILType rootAddrTy = SILType::getPrimitiveAddressType ( rootTy);
395
+ SILType rootAddrTy = rootTy. getAddressType ( );
398
396
SILValue rootAddr = Builder.createBaseAddrForOffset (loc, rootAddrTy);
399
397
400
398
auto projector = KeyPathProjector::create (kp, rootAddr, loc, Builder);
0 commit comments