@@ -1459,21 +1459,91 @@ struct TargetEnumMetadata : public TargetValueMetadata<Runtime> {
1459
1459
};
1460
1460
using EnumMetadata = TargetEnumMetadata<InProcess>;
1461
1461
1462
+ template <typename Runtime>
1463
+ struct TargetFunctionGlobalActorMetadata {
1464
+ ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> GlobalActorType;
1465
+ };
1466
+ using FunctionGlobalActorMetadata = TargetFunctionGlobalActorMetadata<InProcess>;
1467
+
1468
+ template <typename Runtime>
1469
+ struct TargetFunctionThrownErrorMetadata {
1470
+ ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> ThrownErrorType;
1471
+ };
1472
+ using FunctionThrownErrorMetadata = TargetFunctionThrownErrorMetadata<InProcess>;
1473
+
1462
1474
// / The structure of function type metadata.
1463
1475
template <typename Runtime>
1464
- struct TargetFunctionTypeMetadata : public TargetMetadata <Runtime> {
1476
+ struct TargetFunctionTypeMetadata : public TargetMetadata <Runtime>,
1477
+ swift::ABI::TrailingObjects<
1478
+ TargetFunctionTypeMetadata<Runtime>,
1479
+ ConstTargetMetadataPointer<Runtime, swift::TargetMetadata>,
1480
+ ParameterFlags,
1481
+ TargetFunctionMetadataDifferentiabilityKind<typename Runtime::StoredSize>,
1482
+ TargetFunctionGlobalActorMetadata<Runtime>,
1483
+ ExtendedFunctionTypeFlags,
1484
+ TargetFunctionThrownErrorMetadata<Runtime>> {
1465
1485
using StoredSize = typename Runtime::StoredSize;
1466
1486
using Parameter = ConstTargetMetadataPointer<Runtime, swift::TargetMetadata>;
1467
1487
1488
+ private:
1489
+ using TrailingObjects =
1490
+ swift::ABI::TrailingObjects<
1491
+ TargetFunctionTypeMetadata<Runtime>,
1492
+ Parameter,
1493
+ ParameterFlags,
1494
+ TargetFunctionMetadataDifferentiabilityKind<StoredSize>,
1495
+ TargetFunctionGlobalActorMetadata<Runtime>,
1496
+ ExtendedFunctionTypeFlags,
1497
+ TargetFunctionThrownErrorMetadata<Runtime>>;
1498
+ friend TrailingObjects;
1499
+
1500
+ template <typename T>
1501
+ using OverloadToken = typename TrailingObjects::template OverloadToken<T>;
1502
+
1503
+ public:
1468
1504
TargetFunctionTypeFlags<StoredSize> Flags;
1469
1505
1470
1506
// / The type metadata for the result type.
1471
1507
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> ResultType;
1472
1508
1473
- Parameter *getParameters () { return reinterpret_cast <Parameter *>(this + 1 ); }
1509
+ private:
1510
+ size_t numTrailingObjects (OverloadToken<Parameter>) const {
1511
+ return getNumParameters ();
1512
+ }
1513
+
1514
+ size_t numTrailingObjects (OverloadToken<ParameterFlags>) const {
1515
+ return hasParameterFlags () ? getNumParameters () : 0 ;
1516
+ }
1517
+
1518
+ size_t numTrailingObjects (
1519
+ OverloadToken<TargetFunctionMetadataDifferentiabilityKind<StoredSize>>
1520
+ ) const {
1521
+ return isDifferentiable () ? 1 : 0 ;
1522
+ }
1523
+
1524
+ size_t numTrailingObjects (
1525
+ OverloadToken<TargetFunctionGlobalActorMetadata<Runtime>>
1526
+ ) const {
1527
+ return hasGlobalActor () ? 1 : 0 ;
1528
+ }
1529
+
1530
+ size_t numTrailingObjects (OverloadToken<ExtendedFunctionTypeFlags>) const {
1531
+ return hasExtendedFlags () ? 1 : 0 ;
1532
+ }
1533
+
1534
+ size_t numTrailingObjects (
1535
+ OverloadToken<TargetFunctionThrownErrorMetadata<Runtime>>
1536
+ ) const {
1537
+ return hasThrownError () ? 1 : 0 ;
1538
+ }
1539
+
1540
+ public:
1541
+ Parameter *getParameters () {
1542
+ return this ->template getTrailingObjects <Parameter>();
1543
+ }
1474
1544
1475
1545
const Parameter *getParameters () const {
1476
- return reinterpret_cast < const Parameter *>( this + 1 );
1546
+ return this -> template getTrailingObjects < Parameter>( );
1477
1547
}
1478
1548
1479
1549
Parameter getParameter (unsigned index) const {
@@ -1483,8 +1553,7 @@ struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
1483
1553
1484
1554
ParameterFlags getParameterFlags (unsigned index) const {
1485
1555
assert (index < getNumParameters ());
1486
- auto flags = hasParameterFlags () ? getParameterFlags ()[index] : 0 ;
1487
- return ParameterFlags::fromIntValue (flags);
1556
+ return hasParameterFlags () ? getParameterFlags ()[index] : ParameterFlags ();
1488
1557
}
1489
1558
1490
1559
StoredSize getNumParameters () const {
@@ -1500,39 +1569,38 @@ struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
1500
1569
bool hasParameterFlags () const { return Flags.hasParameterFlags (); }
1501
1570
bool isEscaping () const { return Flags.isEscaping (); }
1502
1571
bool hasGlobalActor () const { return Flags.hasGlobalActor (); }
1572
+ bool hasExtendedFlags () const { return Flags.hasExtendedFlags (); }
1573
+ bool hasThrownError () const {
1574
+ if (!Flags.hasExtendedFlags ())
1575
+ return false ;
1576
+
1577
+ return getExtendedFlags ().isTypedThrows ();
1578
+ }
1503
1579
1504
1580
static constexpr StoredSize OffsetToFlags = sizeof (TargetMetadata<Runtime>);
1505
1581
1506
1582
static bool classof (const TargetMetadata<Runtime> *metadata) {
1507
1583
return metadata->getKind () == MetadataKind::Function;
1508
1584
}
1509
1585
1510
- uint32_t *getParameterFlags () {
1511
- return reinterpret_cast < uint32_t *>( getParameters () + getNumParameters () );
1586
+ ParameterFlags *getParameterFlags () {
1587
+ return this -> template getTrailingObjects <ParameterFlags>( );
1512
1588
}
1513
1589
1514
- const uint32_t *getParameterFlags () const {
1515
- return reinterpret_cast <const uint32_t *>(getParameters () +
1516
- getNumParameters ());
1590
+ const ParameterFlags *getParameterFlags () const {
1591
+ return this ->template getTrailingObjects <ParameterFlags>();
1517
1592
}
1518
1593
1519
1594
TargetFunctionMetadataDifferentiabilityKind<StoredSize> *
1520
1595
getDifferentiabilityKindAddress () {
1521
1596
assert (isDifferentiable ());
1522
- void *previousEndAddr = hasParameterFlags ()
1523
- ? reinterpret_cast <void *>(getParameterFlags () + getNumParameters ())
1524
- : reinterpret_cast <void *>(getParameters () + getNumParameters ());
1525
- return reinterpret_cast <
1526
- TargetFunctionMetadataDifferentiabilityKind<StoredSize> *>(
1527
- llvm::alignAddr (previousEndAddr,
1528
- llvm::Align (alignof (typename Runtime::StoredPointer))));
1597
+ return this ->template getTrailingObjects <TargetFunctionMetadataDifferentiabilityKind<StoredSize>>();
1529
1598
}
1530
1599
1531
1600
TargetFunctionMetadataDifferentiabilityKind<StoredSize>
1532
1601
getDifferentiabilityKind () const {
1533
1602
if (isDifferentiable ()) {
1534
- return *const_cast <TargetFunctionTypeMetadata<Runtime> *>(this )
1535
- ->getDifferentiabilityKindAddress ();
1603
+ return *(this ->template getTrailingObjects <TargetFunctionMetadataDifferentiabilityKind<StoredSize>>());
1536
1604
}
1537
1605
return TargetFunctionMetadataDifferentiabilityKind<StoredSize>
1538
1606
::NonDifferentiable;
@@ -1541,26 +1609,47 @@ struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
1541
1609
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> *
1542
1610
getGlobalActorAddr () {
1543
1611
assert (hasGlobalActor ());
1544
-
1545
- void *endAddr =
1546
- isDifferentiable ()
1547
- ? reinterpret_cast <void *>(getDifferentiabilityKindAddress () + 1 ) :
1548
- hasParameterFlags ()
1549
- ? reinterpret_cast <void *>(getParameterFlags () + getNumParameters ()) :
1550
- reinterpret_cast <void *>(getParameters () + getNumParameters ());
1551
- return reinterpret_cast <
1552
- ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> *>(
1553
- llvm::alignAddr (
1554
- endAddr, llvm::Align (alignof (typename Runtime::StoredPointer))));
1612
+ auto globalActorAddr =
1613
+ this ->template getTrailingObjects <TargetFunctionGlobalActorMetadata<Runtime>>();
1614
+ return &globalActorAddr->GlobalActorType ;
1555
1615
}
1556
1616
1557
1617
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata>
1558
1618
getGlobalActor () const {
1559
1619
if (!hasGlobalActor ())
1560
1620
return ConstTargetMetadataPointer<Runtime, swift::TargetMetadata>();
1621
+ auto globalActorAddr =
1622
+ this ->template getTrailingObjects <TargetFunctionGlobalActorMetadata<Runtime>>();
1623
+ return globalActorAddr->GlobalActorType ;
1624
+ }
1625
+
1626
+ ExtendedFunctionTypeFlags *getExtendedFlagsAddr () {
1627
+ assert (hasExtendedFlags ());
1628
+ return this ->template getTrailingObjects <ExtendedFunctionTypeFlags>();
1629
+ }
1630
+
1631
+ ExtendedFunctionTypeFlags getExtendedFlags () const {
1632
+ if (!hasExtendedFlags ())
1633
+ return ExtendedFunctionTypeFlags ();
1634
+
1635
+ return this ->template getTrailingObjects <ExtendedFunctionTypeFlags>()[0 ];
1636
+ }
1637
+
1638
+ ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> *
1639
+ getThrownErrorAddr () {
1640
+ assert (hasThrownError ());
1641
+ auto thrownErrorAddr =
1642
+ this ->template getTrailingObjects <TargetFunctionThrownErrorMetadata<Runtime>>();
1643
+ return &thrownErrorAddr->ThrownErrorType ;
1644
+ }
1561
1645
1562
- return *const_cast <TargetFunctionTypeMetadata<Runtime> *>(this )
1563
- ->getGlobalActorAddr ();
1646
+ ConstTargetMetadataPointer<Runtime, swift::TargetMetadata>
1647
+ getThrownError () const {
1648
+ if (!hasThrownError ())
1649
+ return ConstTargetMetadataPointer<Runtime, swift::TargetMetadata>();
1650
+ auto thrownErrorAddr =
1651
+ this ->template getTrailingObjects <TargetFunctionThrownErrorMetadata<Runtime>>();
1652
+ return thrownErrorAddr->ThrownErrorType ;
1564
1653
}
1565
1654
};
1566
1655
using FunctionTypeMetadata = TargetFunctionTypeMetadata<InProcess>;
0 commit comments