@@ -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;
@@ -1438,12 +1438,6 @@ class CoroPartialApplicationForwarderEmission
1438
1438
: public PartialApplicationForwarderEmission {
1439
1439
using super = PartialApplicationForwarderEmission;
1440
1440
1441
- private:
1442
- llvm::Value *Self;
1443
- llvm::Value *FirstData;
1444
- llvm::Value *SecondData;
1445
- WitnessMetadata Witness;
1446
-
1447
1441
public:
1448
1442
CoroPartialApplicationForwarderEmission (
1449
1443
IRGenModule &IGM, IRGenFunction &subIGF, llvm::Function *fwd,
@@ -1454,8 +1448,7 @@ class CoroPartialApplicationForwarderEmission
1454
1448
ArrayRef<ParameterConvention> conventions)
1455
1449
: PartialApplicationForwarderEmission(
1456
1450
IGM, subIGF, fwd, staticFnPtr, calleeHasContext, origSig, origType,
1457
- substType, outType, subs, layout, conventions),
1458
- Self (nullptr ), FirstData(nullptr ), SecondData(nullptr ) {}
1451
+ substType, outType, subs, layout, conventions) {}
1459
1452
1460
1453
void begin () override {
1461
1454
auto unsubstType = substType->getUnsubstitutedType (IGM.getSILModule ());
@@ -1499,41 +1492,13 @@ class CoroPartialApplicationForwarderEmission
1499
1492
void gatherArgumentsFromApply () override {
1500
1493
super::gatherArgumentsFromApply (false );
1501
1494
}
1502
- llvm::Value *getDynamicFunctionPointer () override {
1503
- llvm::Value *Ret = SecondData;
1504
- SecondData = nullptr ;
1505
- return Ret;
1506
- }
1507
- llvm::Value *getDynamicFunctionContext () override {
1508
- llvm::Value *Ret = FirstData;
1509
- FirstData = nullptr ;
1510
- return Ret;
1511
- }
1495
+ llvm::Value *getDynamicFunctionPointer () override { return args.takeLast (); }
1496
+ llvm::Value *getDynamicFunctionContext () override { return args.takeLast (); }
1512
1497
void addDynamicFunctionContext (Explosion &explosion) override {
1513
- assert (!Self && " context value overrides 'self'" );
1514
- FirstData = explosion.claimNext ();
1498
+ addArgument (explosion);
1515
1499
}
1516
1500
void addDynamicFunctionPointer (Explosion &explosion) override {
1517
- SecondData = explosion.claimNext ();
1518
- }
1519
- void addSelf (Explosion &explosion) override {
1520
- assert (!FirstData && " 'self' overrides another context value" );
1521
- if (!hasSelfContextParameter (origType)) {
1522
- // witness methods can be declared on types that are not classes. Pass
1523
- // such "self" argument as a plain argument.
1524
- addArgument (explosion);
1525
- return ;
1526
- }
1527
- Self = explosion.claimNext ();
1528
- FirstData = Self;
1529
- }
1530
-
1531
- void addWitnessSelfMetadata (llvm::Value *value) override {
1532
- Witness.SelfMetadata = value;
1533
- }
1534
-
1535
- void addWitnessSelfWitnessTable (llvm::Value *value) override {
1536
- Witness.SelfWitnessTable = value;
1501
+ addArgument (explosion);
1537
1502
}
1538
1503
1539
1504
void forwardErrorResult () override {
@@ -1554,13 +1519,26 @@ class CoroPartialApplicationForwarderEmission
1554
1519
}
1555
1520
1556
1521
Explosion callCoroutine (FunctionPointer &fnPtr) {
1557
- Callee callee ({origType, substType, subs}, fnPtr, FirstData, SecondData);
1522
+ bool isWitnessMethodCallee = origType->getRepresentation () ==
1523
+ SILFunctionTypeRepresentation::WitnessMethod;
1524
+
1525
+ WitnessMetadata witnessMetadata;
1526
+ if (isWitnessMethodCallee) {
1527
+ witnessMetadata.SelfWitnessTable = args.takeLast ();
1528
+ witnessMetadata.SelfMetadata = args.takeLast ();
1529
+ }
1530
+
1531
+ llvm::Value *selfValue = nullptr ;
1532
+ if (calleeHasContext || hasSelfContextParameter (origType))
1533
+ selfValue = args.takeLast ();
1534
+
1535
+ Callee callee ({origType, substType, subs}, fnPtr, selfValue);
1558
1536
1559
1537
std::unique_ptr<CallEmission> emitSuspend =
1560
- getCallEmission (subIGF, Self , std::move (callee));
1538
+ getCallEmission (subIGF, callee. getSwiftContext () , std::move (callee));
1561
1539
1562
1540
emitSuspend->begin ();
1563
- emitSuspend->setArgs (args, /* isOutlined=*/ false , &Witness );
1541
+ emitSuspend->setArgs (args, /* isOutlined=*/ false , &witnessMetadata );
1564
1542
Explosion yieldedValues;
1565
1543
emitSuspend->emitToExplosion (yieldedValues, /* isOutlined=*/ false );
1566
1544
emitSuspend->end ();
@@ -1966,12 +1944,7 @@ static llvm::Value *emitPartialApplicationForwarder(
1966
1944
} else {
1967
1945
argValue = subIGF.Builder .CreateBitCast (rawData, expectedArgTy);
1968
1946
}
1969
- if (haveContextArgument) {
1970
- Explosion e;
1971
- e.add (argValue);
1972
- emission->addDynamicFunctionContext (e);
1973
- } else
1974
- emission->addArgument (argValue);
1947
+ emission->addArgument (argValue);
1975
1948
1976
1949
// If there's a data pointer required, grab it and load out the
1977
1950
// extra, previously-curried parameters.
0 commit comments