@@ -1120,11 +1120,11 @@ class PartialApplicationForwarderEmission {
1120
1120
virtual void addDynamicFunctionContext (Explosion &explosion) = 0;
1121
1121
virtual void addDynamicFunctionPointer (Explosion &explosion) = 0;
1122
1122
1123
- virtual void addSelf (Explosion &explosion) { addArgument (explosion); }
1124
- virtual void addWitnessSelfMetadata (llvm::Value *value) {
1123
+ void addSelf (Explosion &explosion) { addArgument (explosion); }
1124
+ void addWitnessSelfMetadata (llvm::Value *value) {
1125
1125
addArgument (value);
1126
1126
}
1127
- virtual void addWitnessSelfWitnessTable (llvm::Value *value) {
1127
+ void addWitnessSelfWitnessTable (llvm::Value *value) {
1128
1128
addArgument (value);
1129
1129
}
1130
1130
virtual void forwardErrorResult () = 0;
@@ -1412,12 +1412,6 @@ class CoroPartialApplicationForwarderEmission
1412
1412
: public PartialApplicationForwarderEmission {
1413
1413
using super = PartialApplicationForwarderEmission;
1414
1414
1415
- private:
1416
- llvm::Value *Self;
1417
- llvm::Value *FirstData;
1418
- llvm::Value *SecondData;
1419
- WitnessMetadata Witness;
1420
-
1421
1415
public:
1422
1416
CoroPartialApplicationForwarderEmission (
1423
1417
IRGenModule &IGM, IRGenFunction &subIGF, llvm::Function *fwd,
@@ -1428,8 +1422,7 @@ class CoroPartialApplicationForwarderEmission
1428
1422
ArrayRef<ParameterConvention> conventions)
1429
1423
: PartialApplicationForwarderEmission(
1430
1424
IGM, subIGF, fwd, staticFnPtr, calleeHasContext, origSig, origType,
1431
- substType, outType, subs, layout, conventions),
1432
- Self (nullptr ), FirstData(nullptr ), SecondData(nullptr ) {}
1425
+ substType, outType, subs, layout, conventions) {}
1433
1426
1434
1427
void begin () override {
1435
1428
auto unsubstType = substType->getUnsubstitutedType (IGM.getSILModule ());
@@ -1473,41 +1466,13 @@ class CoroPartialApplicationForwarderEmission
1473
1466
void gatherArgumentsFromApply () override {
1474
1467
super::gatherArgumentsFromApply (false );
1475
1468
}
1476
- llvm::Value *getDynamicFunctionPointer () override {
1477
- llvm::Value *Ret = SecondData;
1478
- SecondData = nullptr ;
1479
- return Ret;
1480
- }
1481
- llvm::Value *getDynamicFunctionContext () override {
1482
- llvm::Value *Ret = FirstData;
1483
- FirstData = nullptr ;
1484
- return Ret;
1485
- }
1469
+ llvm::Value *getDynamicFunctionPointer () override { return args.takeLast (); }
1470
+ llvm::Value *getDynamicFunctionContext () override { return args.takeLast (); }
1486
1471
void addDynamicFunctionContext (Explosion &explosion) override {
1487
- assert (!Self && " context value overrides 'self'" );
1488
- FirstData = explosion.claimNext ();
1472
+ addArgument (explosion);
1489
1473
}
1490
1474
void addDynamicFunctionPointer (Explosion &explosion) override {
1491
- SecondData = explosion.claimNext ();
1492
- }
1493
- void addSelf (Explosion &explosion) override {
1494
- assert (!FirstData && " 'self' overrides another context value" );
1495
- if (!hasSelfContextParameter (origType)) {
1496
- // witness methods can be declared on types that are not classes. Pass
1497
- // such "self" argument as a plain argument.
1498
- addArgument (explosion);
1499
- return ;
1500
- }
1501
- Self = explosion.claimNext ();
1502
- FirstData = Self;
1503
- }
1504
-
1505
- void addWitnessSelfMetadata (llvm::Value *value) override {
1506
- Witness.SelfMetadata = value;
1507
- }
1508
-
1509
- void addWitnessSelfWitnessTable (llvm::Value *value) override {
1510
- Witness.SelfWitnessTable = value;
1475
+ addArgument (explosion);
1511
1476
}
1512
1477
1513
1478
void forwardErrorResult () override {
@@ -1528,13 +1493,26 @@ class CoroPartialApplicationForwarderEmission
1528
1493
}
1529
1494
1530
1495
Explosion callCoroutine (FunctionPointer &fnPtr) {
1531
- Callee callee ({origType, substType, subs}, fnPtr, FirstData, SecondData);
1496
+ bool isWitnessMethodCallee = origType->getRepresentation () ==
1497
+ SILFunctionTypeRepresentation::WitnessMethod;
1498
+
1499
+ WitnessMetadata witnessMetadata;
1500
+ if (isWitnessMethodCallee) {
1501
+ witnessMetadata.SelfWitnessTable = args.takeLast ();
1502
+ witnessMetadata.SelfMetadata = args.takeLast ();
1503
+ }
1504
+
1505
+ llvm::Value *selfValue = nullptr ;
1506
+ if (calleeHasContext || hasSelfContextParameter (origType))
1507
+ selfValue = args.takeLast ();
1508
+
1509
+ Callee callee ({origType, substType, subs}, fnPtr, selfValue);
1532
1510
1533
1511
std::unique_ptr<CallEmission> emitSuspend =
1534
- getCallEmission (subIGF, Self , std::move (callee));
1512
+ getCallEmission (subIGF, callee. getSwiftContext () , std::move (callee));
1535
1513
1536
1514
emitSuspend->begin ();
1537
- emitSuspend->setArgs (args, /* isOutlined=*/ false , &Witness );
1515
+ emitSuspend->setArgs (args, /* isOutlined=*/ false , &witnessMetadata );
1538
1516
Explosion yieldedValues;
1539
1517
emitSuspend->emitToExplosion (yieldedValues, /* isOutlined=*/ false );
1540
1518
emitSuspend->end ();
@@ -1940,12 +1918,7 @@ static llvm::Value *emitPartialApplicationForwarder(
1940
1918
} else {
1941
1919
argValue = subIGF.Builder .CreateBitCast (rawData, expectedArgTy);
1942
1920
}
1943
- if (haveContextArgument) {
1944
- Explosion e;
1945
- e.add (argValue);
1946
- emission->addDynamicFunctionContext (e);
1947
- } else
1948
- emission->addArgument (argValue);
1921
+ emission->addArgument (argValue);
1949
1922
1950
1923
// If there's a data pointer required, grab it and load out the
1951
1924
// extra, previously-curried parameters.
0 commit comments