@@ -1445,15 +1445,21 @@ namespace {
1445
1445
.withThrows (type->isThrowing ())
1446
1446
.withParameterFlags (hasParameterFlags)
1447
1447
.withEscaping (isEscaping)
1448
- .withDifferentiable (type->isDifferentiable ());
1448
+ .withDifferentiable (type->isDifferentiable ())
1449
+ .withGlobalActor (!type->getGlobalActor ().isNull ());
1449
1450
1450
1451
auto flagsVal = llvm::ConstantInt::get (IGF.IGM .SizeTy ,
1451
1452
flags.getIntValue ());
1452
1453
llvm::Value *diffKindVal = nullptr ;
1453
1454
if (type->isDifferentiable ()) {
1454
1455
assert (metadataDifferentiabilityKind.isDifferentiable ());
1456
+ // FIXME: Shouldn't this use metadataDifferentiabilityKind?
1455
1457
diffKindVal = llvm::ConstantInt::get (IGF.IGM .SizeTy ,
1456
1458
flags.getIntValue ());
1459
+ } else if (type->getGlobalActor ()) {
1460
+ diffKindVal = llvm::ConstantInt::get (
1461
+ IGF.IGM .SizeTy ,
1462
+ FunctionMetadataDifferentiabilityKind::NonDifferentiable);
1457
1463
}
1458
1464
1459
1465
auto collectParameters =
@@ -1507,56 +1513,65 @@ namespace {
1507
1513
case 1 :
1508
1514
case 2 :
1509
1515
case 3 : {
1510
- if (!hasParameterFlags && !type->isDifferentiable ()) {
1516
+ if (!hasParameterFlags && !type->isDifferentiable () &&
1517
+ !type->getGlobalActor ()) {
1511
1518
llvm::SmallVector<llvm::Value *, 8 > arguments;
1512
1519
auto *metadataFn = constructSimpleCall (arguments);
1513
1520
auto *call = IGF.Builder .CreateCall (metadataFn, arguments);
1514
1521
call->setDoesNotThrow ();
1515
1522
return setLocal (CanType (type), MetadataResponse::forComplete (call));
1516
1523
}
1517
1524
1518
- // If function type has parameter flags or is differentiable, let's emit
1519
- // the most general function to retrieve them.
1525
+ // If function type has parameter flags or is differentiable or has a
1526
+ // global actor, emit the most general function to retrieve them.
1520
1527
LLVM_FALLTHROUGH;
1521
1528
}
1522
1529
1523
1530
default :
1524
- assert (!params.empty () || type->isDifferentiable () &&
1531
+ assert ((!params.empty () || type->isDifferentiable () ||
1532
+ type->getGlobalActor ()) &&
1525
1533
" 0 parameter case should be specialized unless it is a "
1526
- " differentiable function" );
1534
+ " differentiable function or has a global actor " );
1527
1535
1528
1536
auto *const Int32Ptr = IGF.IGM .Int32Ty ->getPointerTo ();
1529
1537
llvm::SmallVector<llvm::Value *, 8 > arguments;
1530
1538
1531
1539
arguments.push_back (flagsVal);
1532
1540
1533
- if (type->isDifferentiable ()) {
1534
- assert (diffKindVal);
1541
+ if (diffKindVal) {
1535
1542
arguments.push_back (diffKindVal);
1536
1543
}
1537
1544
1538
1545
ConstantInitBuilder paramFlags (IGF.IGM );
1539
1546
auto flagsArr = paramFlags.beginArray ();
1540
1547
1541
- auto arrayTy =
1542
- llvm::ArrayType::get (IGF.IGM .TypeMetadataPtrTy , numParams);
1543
- Address parameters = IGF.createAlloca (
1544
- arrayTy, IGF.IGM .getTypeMetadataAlignment (), " function-parameters" );
1545
-
1546
- IGF.Builder .CreateLifetimeStart (parameters,
1547
- IGF.IGM .getPointerSize () * numParams);
1548
-
1549
- collectParameters ([&](unsigned i, llvm::Value *typeRef,
1550
- ParameterFlags flags) {
1551
- auto argPtr = IGF.Builder .CreateStructGEP (parameters, i,
1552
- IGF.IGM .getPointerSize ());
1553
- IGF.Builder .CreateStore (typeRef, argPtr);
1554
- if (i == 0 )
1555
- arguments.push_back (argPtr.getAddress ());
1556
-
1557
- if (hasParameterFlags)
1558
- flagsArr.addInt32 (flags.getIntValue ());
1559
- });
1548
+ Address parameters;
1549
+ if (!params.empty ()) {
1550
+ auto arrayTy =
1551
+ llvm::ArrayType::get (IGF.IGM .TypeMetadataPtrTy , numParams);
1552
+ parameters = IGF.createAlloca (
1553
+ arrayTy, IGF.IGM .getTypeMetadataAlignment (), " function-parameters" );
1554
+
1555
+ IGF.Builder .CreateLifetimeStart (parameters,
1556
+ IGF.IGM .getPointerSize () * numParams);
1557
+
1558
+ collectParameters ([&](unsigned i, llvm::Value *typeRef,
1559
+ ParameterFlags flags) {
1560
+ auto argPtr = IGF.Builder .CreateStructGEP (parameters, i,
1561
+ IGF.IGM .getPointerSize ());
1562
+ IGF.Builder .CreateStore (typeRef, argPtr);
1563
+ if (i == 0 )
1564
+ arguments.push_back (argPtr.getAddress ());
1565
+
1566
+ if (hasParameterFlags)
1567
+ flagsArr.addInt32 (flags.getIntValue ());
1568
+ });
1569
+ } else {
1570
+ auto parametersPtr =
1571
+ llvm::ConstantPointerNull::get (
1572
+ IGF.IGM .TypeMetadataPtrTy ->getPointerTo ());
1573
+ arguments.push_back (parametersPtr);
1574
+ }
1560
1575
1561
1576
if (hasParameterFlags) {
1562
1577
auto *flagsVar = flagsArr.finishAndCreateGlobal (
@@ -1570,9 +1585,16 @@ namespace {
1570
1585
1571
1586
arguments.push_back (result);
1572
1587
1573
- auto *getMetadataFn = type->isDifferentiable ()
1574
- ? IGF.IGM .getGetFunctionMetadataDifferentiableFn ()
1575
- : IGF.IGM .getGetFunctionMetadataFn ();
1588
+ if (Type globalActor = type->getGlobalActor ()) {
1589
+ arguments.push_back (
1590
+ IGF.emitAbstractTypeMetadataRef (globalActor->getCanonicalType ()));
1591
+ }
1592
+
1593
+ auto *getMetadataFn = type->getGlobalActor ()
1594
+ ? IGF.IGM .getGetFunctionMetadataGlobalActorFn ()
1595
+ : type->isDifferentiable ()
1596
+ ? IGF.IGM .getGetFunctionMetadataDifferentiableFn ()
1597
+ : IGF.IGM .getGetFunctionMetadataFn ();
1576
1598
1577
1599
auto call = IGF.Builder .CreateCall (getMetadataFn, arguments);
1578
1600
call->setDoesNotThrow ();
0 commit comments