@@ -6137,19 +6137,18 @@ static ManagedValue emitDynamicPartialApply(SILGenFunction &SGF,
6137
6137
return result;
6138
6138
}
6139
6139
6140
- RValue SILGenFunction::emitDynamicMemberRefExpr (DynamicMemberRefExpr *e ,
6141
- SGFContext c) {
6142
- // Emit the operand.
6143
- ManagedValue base = emitRValueAsSingleValue (e-> getBase ());
6140
+ RValue SILGenFunction::emitDynamicMemberRef (SILLocation loc, SILValue operand ,
6141
+ ConcreteDeclRef memberRef,
6142
+ CanType refTy, SGFContext C) {
6143
+ assert (refTy-> isOptional ());
6144
6144
6145
- SILValue operand = base.getValue ();
6146
- if (!e->getMember ().getDecl ()->isInstanceMember ()) {
6145
+ if (!memberRef.getDecl ()->isInstanceMember ()) {
6147
6146
auto metatype = operand->getType ().castTo <MetatypeType>();
6148
6147
assert (metatype->getRepresentation () == MetatypeRepresentation::Thick);
6149
6148
metatype = CanMetatypeType::get (metatype.getInstanceType (),
6150
6149
MetatypeRepresentation::ObjC);
6151
- operand = B.createThickToObjCMetatype (e, operand,
6152
- SILType::getPrimitiveObjectType (metatype));
6150
+ operand = B.createThickToObjCMetatype (
6151
+ loc, operand, SILType::getPrimitiveObjectType (metatype));
6153
6152
}
6154
6153
6155
6154
// Create the continuation block.
@@ -6162,38 +6161,39 @@ RValue SILGenFunction::emitDynamicMemberRefExpr(DynamicMemberRefExpr *e,
6162
6161
SILBasicBlock *hasMemberBB = createBasicBlock ();
6163
6162
6164
6163
// The continuation block
6165
- auto memberMethodTy = e-> getType ()-> getOptionalObjectType ();
6164
+ CanType memberMethodTy = refTy. getOptionalObjectType ();
6166
6165
6167
- const TypeLowering &optTL = getTypeLowering (e-> getType () );
6166
+ const TypeLowering &optTL = getTypeLowering (refTy );
6168
6167
auto loweredOptTy = optTL.getLoweredType ();
6169
6168
6170
- SILValue optTemp = emitTemporaryAllocation (e , loweredOptTy);
6169
+ SILValue optTemp = emitTemporaryAllocation (loc , loweredOptTy);
6171
6170
6172
6171
// Create the branch.
6173
6172
FuncDecl *memberFunc;
6174
- if (auto *VD = dyn_cast<VarDecl>(e-> getMember () .getDecl ())) {
6173
+ if (auto *VD = dyn_cast<VarDecl>(memberRef .getDecl ())) {
6175
6174
memberFunc = VD->getOpaqueAccessor (AccessorKind::Get);
6176
6175
// FIXME: Verify ExtInfo state is correct, not working by accident.
6177
6176
CanFunctionType::ExtInfo info;
6178
- memberMethodTy = FunctionType::get ({}, memberMethodTy, info);
6179
- } else
6180
- memberFunc = cast<FuncDecl>(e->getMember ().getDecl ());
6177
+ memberMethodTy = CanFunctionType::get ({}, memberMethodTy, info);
6178
+ } else {
6179
+ memberFunc = cast<FuncDecl>(memberRef.getDecl ());
6180
+ }
6181
6181
auto member = SILDeclRef (memberFunc, SILDeclRef::Kind::Func)
6182
6182
.asForeign ();
6183
- B.createDynamicMethodBranch (e , operand, member, hasMemberBB, noMemberBB);
6183
+ B.createDynamicMethodBranch (loc , operand, member, hasMemberBB, noMemberBB);
6184
6184
6185
6185
// Create the has-member branch.
6186
6186
{
6187
6187
B.emitBlock (hasMemberBB);
6188
6188
6189
- FullExpr hasMemberScope (Cleanups, CleanupLocation (e ));
6189
+ FullExpr hasMemberScope (Cleanups, CleanupLocation (loc ));
6190
6190
6191
6191
// The argument to the has-member block is the uncurried method.
6192
- auto valueTy = e-> getType ()-> getCanonicalType () .getOptionalObjectType ();
6192
+ const CanType valueTy = refTy .getOptionalObjectType ();
6193
6193
CanFunctionType methodTy;
6194
6194
6195
6195
// For a computed variable, we want the getter.
6196
- if (isa<VarDecl>(e-> getMember () .getDecl ())) {
6196
+ if (isa<VarDecl>(memberRef .getDecl ())) {
6197
6197
// FIXME: Verify ExtInfo state is correct, not working by accident.
6198
6198
CanFunctionType::ExtInfo info;
6199
6199
methodTy = CanFunctionType::get ({}, valueTy, info);
@@ -6205,50 +6205,49 @@ RValue SILGenFunction::emitDynamicMemberRefExpr(DynamicMemberRefExpr *e,
6205
6205
// TODO: instead of building this and then potentially converting, we
6206
6206
// should just build a single thunk.
6207
6207
auto foreignMethodTy =
6208
- getPartialApplyOfDynamicMethodFormalType (SGM, member, e-> getMember () );
6208
+ getPartialApplyOfDynamicMethodFormalType (SGM, member, memberRef );
6209
6209
6210
6210
// FIXME: Verify ExtInfo state is correct, not working by accident.
6211
6211
CanFunctionType::ExtInfo info;
6212
6212
FunctionType::Param arg (operand->getType ().getASTType ());
6213
- auto memberFnTy =
6214
- CanFunctionType::get ({arg}, memberMethodTy->getCanonicalType (), info);
6213
+ auto memberFnTy = CanFunctionType::get ({arg}, memberMethodTy, info);
6215
6214
6216
6215
auto loweredMethodTy = getDynamicMethodLoweredType (SGM.M , member,
6217
6216
memberFnTy);
6218
6217
SILValue memberArg =
6219
6218
hasMemberBB->createPhiArgument (loweredMethodTy, OwnershipKind::Owned);
6220
6219
6221
6220
// Create the result value.
6222
- Scope applyScope (Cleanups, CleanupLocation (e));
6223
- ManagedValue result =
6224
- emitDynamicPartialApply (*this , e, memberArg, operand,
6225
- foreignMethodTy, methodTy);
6221
+ Scope applyScope (Cleanups, CleanupLocation (loc));
6222
+ ManagedValue result = emitDynamicPartialApply (
6223
+ *this , loc, memberArg, operand, foreignMethodTy, methodTy);
6226
6224
6227
6225
RValue resultRV;
6228
- if (isa<VarDecl>(e-> getMember () .getDecl ())) {
6229
- resultRV = emitMonomorphicApply (e, result, {},
6230
- foreignMethodTy.getResult (), valueTy ,
6231
- ApplyOptions (), None, None);
6226
+ if (isa<VarDecl>(memberRef .getDecl ())) {
6227
+ resultRV =
6228
+ emitMonomorphicApply (loc, result, {}, foreignMethodTy.getResult (),
6229
+ valueTy, ApplyOptions (), None, None);
6232
6230
} else {
6233
- resultRV = RValue (*this , e , valueTy, result);
6231
+ resultRV = RValue (*this , loc , valueTy, result);
6234
6232
}
6235
6233
6236
6234
// Package up the result in an optional.
6237
- emitInjectOptionalValueInto (e, {e, std::move (resultRV)}, optTemp, optTL);
6235
+ emitInjectOptionalValueInto (loc, {loc, std::move (resultRV)}, optTemp,
6236
+ optTL);
6238
6237
6239
6238
applyScope.pop ();
6240
6239
// Branch to the continuation block.
6241
- B.createBranch (e , contBB);
6240
+ B.createBranch (loc , contBB);
6242
6241
}
6243
6242
6244
6243
// Create the no-member branch.
6245
6244
{
6246
6245
B.emitBlock (noMemberBB);
6247
6246
6248
- emitInjectOptionalNothingInto (e , optTemp, optTL);
6247
+ emitInjectOptionalNothingInto (loc , optTemp, optTL);
6249
6248
6250
6249
// Branch to the continuation block.
6251
- B.createBranch (e , contBB);
6250
+ B.createBranch (loc , contBB);
6252
6251
}
6253
6252
6254
6253
// Emit the continuation block.
@@ -6257,8 +6256,9 @@ RValue SILGenFunction::emitDynamicMemberRefExpr(DynamicMemberRefExpr *e,
6257
6256
// Package up the result.
6258
6257
auto optResult = optTemp;
6259
6258
if (optTL.isLoadable ())
6260
- optResult = optTL.emitLoad (B, e, optResult, LoadOwnershipQualifier::Take);
6261
- return RValue (*this , e, emitManagedRValueWithCleanup (optResult, optTL));
6259
+ optResult = optTL.emitLoad (B, loc, optResult, LoadOwnershipQualifier::Take);
6260
+ return RValue (*this , loc, refTy,
6261
+ emitManagedRValueWithCleanup (optResult, optTL));
6262
6262
}
6263
6263
6264
6264
RValue SILGenFunction::emitDynamicSubscriptExpr (DynamicSubscriptExpr *e,
0 commit comments