@@ -208,7 +208,9 @@ class GettablePropertyProjector : public ComponentProjector {
208
208
// The callback expects a memory address it can read from,
209
209
// so allocate a buffer.
210
210
auto &function = builder.getFunction ();
211
- SILType type = function.getLoweredType (component.getComponentType ());
211
+ auto substType = component.getComponentType ().subst (keyPath->getSubstitutions (),
212
+ None);
213
+ SILType type = function.getLoweredType (substType);
212
214
auto addr = builder.createAllocStack (loc, type);
213
215
214
216
assertHasNoContext ();
@@ -283,7 +285,9 @@ class SettablePropertyProjector : public GettablePropertyProjector {
283
285
// The callback expects a memory address it can write to,
284
286
// so allocate a writeback buffer.
285
287
auto &function = builder.getFunction ();
286
- SILType type = function.getLoweredType (component.getComponentType ());
288
+ auto substType = component.getComponentType ().subst (keyPath->getSubstitutions (),
289
+ None);
290
+ SILType type = function.getLoweredType (substType);
287
291
auto addr = builder.createAllocStack (loc, type);
288
292
289
293
assertHasNoContext ();
@@ -315,10 +319,12 @@ class SettablePropertyProjector : public GettablePropertyProjector {
315
319
316
320
class OptionalWrapProjector : public ComponentProjector {
317
321
public:
318
- OptionalWrapProjector (const KeyPathPatternComponent &component,
322
+ OptionalWrapProjector (KeyPathInst *kpInst,
323
+ const KeyPathPatternComponent &component,
319
324
std::unique_ptr<KeyPathProjector> parent,
320
325
SILLocation loc, SILBuilder &builder)
321
- : ComponentProjector(component, std::move(parent), loc, builder) {}
326
+ : ComponentProjector(component, std::move(parent), loc, builder),
327
+ keyPath (kpInst) {}
322
328
323
329
void project (AccessType accessType,
324
330
std::function<void (SILValue addr)> callback) override {
@@ -328,7 +334,9 @@ class OptionalWrapProjector : public ComponentProjector {
328
334
329
335
parent->project (AccessType::Get, [&](SILValue parentValue) {
330
336
auto &function = builder.getFunction ();
331
- SILType optType = function.getLoweredType (component.getComponentType ());
337
+ auto substType = component.getComponentType ().subst (keyPath->getSubstitutions (),
338
+ None);
339
+ SILType optType = function.getLoweredType (substType);
332
340
SILType objType = optType.getOptionalObjectType ().getAddressType ();
333
341
334
342
assert (objType && " optional wrap must return an optional" );
@@ -352,6 +360,9 @@ class OptionalWrapProjector : public ComponentProjector {
352
360
builder.createDeallocStack (loc, optAddr);
353
361
});
354
362
}
363
+
364
+ private:
365
+ KeyPathInst *keyPath;
355
366
};
356
367
357
368
class OptionalForceProjector : public ComponentProjector {
@@ -531,7 +542,8 @@ class CompleteKeyPathProjector : public KeyPathProjector {
531
542
// If we're reading an optional chain, create an optional result.
532
543
auto resultCanType = components.back ().getComponentType ();
533
544
auto &function = builder.getFunction ();
534
- auto optType = function.getLoweredType (resultCanType);
545
+ auto substType = resultCanType.subst (keyPath->getSubstitutions (), None);
546
+ auto optType = function.getLoweredType (substType);
535
547
536
548
assert (optType.getOptionalObjectType () &&
537
549
" Optional-chained key path should result in an optional" );
@@ -608,7 +620,7 @@ class CompleteKeyPathProjector : public KeyPathProjector {
608
620
break ;
609
621
case KeyPathPatternComponent::Kind::OptionalWrap:
610
622
projector = std::make_unique<OptionalWrapProjector>
611
- (comp, std::move (parent), loc, builder);
623
+ (keyPath, comp, std::move (parent), loc, builder);
612
624
break ;
613
625
case KeyPathPatternComponent::Kind::OptionalForce:
614
626
projector = std::make_unique<OptionalForceProjector>
0 commit comments