@@ -118,6 +118,8 @@ enum class ImplParameterConvention {
118118enum class ImplParameterInfoFlags : uint8_t {
119119 NotDifferentiable = 0x1 ,
120120 Sending = 0x2 ,
121+ Isolated = 0x4 ,
122+ ImplicitLeading = 0x8
121123};
122124
123125using ImplParameterInfoOptions = OptionSet<ImplParameterInfoFlags>;
@@ -192,6 +194,22 @@ class ImplFunctionParam {
192194 return result;
193195 }
194196
197+ static OptionsType getIsolated () {
198+ OptionsType result;
199+
200+ result |= ImplParameterInfoFlags::Isolated;
201+
202+ return result;
203+ }
204+
205+ static OptionsType getImplicitLeading () {
206+ OptionsType result;
207+
208+ result |= ImplParameterInfoFlags::ImplicitLeading;
209+
210+ return result;
211+ }
212+
195213 ImplFunctionParam (BuiltType type, ImplParameterConvention convention,
196214 OptionsType options)
197215 : Type(type), Convention(convention), Options(options) {}
@@ -1143,11 +1161,11 @@ class TypeDecoder {
11431161 return MAKE_NODE_TYPE_ERROR0 (child,
11441162 " failed to decode function yields" );
11451163 } else if (child->getKind () == NodeKind::ImplResult) {
1146- if (decodeImplFunctionParam (child, depth + 1 , results))
1164+ if (decodeImplFunctionResult (child, depth + 1 , results))
11471165 return MAKE_NODE_TYPE_ERROR0 (child,
11481166 " failed to decode function results" );
11491167 } else if (child->getKind () == NodeKind::ImplErrorResult) {
1150- if (decodeImplFunctionPart (child, depth + 1 , errorResults))
1168+ if (decodeImplFunctionResult (child, depth + 1 , errorResults))
11511169 return MAKE_NODE_TYPE_ERROR0 (child,
11521170 " failed to decode function part" );
11531171 } else {
@@ -1638,40 +1656,70 @@ class TypeDecoder {
16381656 }
16391657
16401658 template <typename T>
1641- bool decodeImplFunctionPart (Demangle::NodePointer node, unsigned depth,
1642- llvm::SmallVectorImpl<T> &results) {
1659+ bool decodeImplFunctionParam (Demangle::NodePointer node, unsigned depth,
1660+ llvm::SmallVectorImpl<T> &results) {
16431661 if (depth > TypeDecoder::MaxDepth)
16441662 return true ;
16451663
1646- if (node->getNumChildren () != 2 )
1664+ // Children: `convention, attrs, type`
1665+ // attrs: `differentiability?, sending?, isolated?, implicit_leading?`
1666+ if (node->getNumChildren () < 2 )
16471667 return true ;
1648-
1649- if (node->getChild (0 )->getKind () != Node::Kind::ImplConvention ||
1650- node->getChild (1 )->getKind () != Node::Kind::Type)
1668+
1669+ auto *conventionNode = node->getChild (0 );
1670+ auto *typeNode = node->getLastChild ();
1671+ if (conventionNode->getKind () != Node::Kind::ImplConvention ||
1672+ typeNode->getKind () != Node::Kind::Type)
16511673 return true ;
16521674
1653- StringRef conventionString = node->getChild (0 )->getText ();
1654- std::optional<typename T::ConventionType> convention =
1655- T::getConventionFromString (conventionString);
1675+ StringRef conventionString = conventionNode->getText ();
1676+ auto convention = T::getConventionFromString (conventionString);
16561677 if (!convention)
16571678 return true ;
1658- auto type = decodeMangledType (node-> getChild ( 1 ) , depth + 1 );
1659- if (type .isError ())
1679+ auto result = decodeMangledType (typeNode , depth + 1 );
1680+ if (result .isError ())
16601681 return true ;
16611682
1662- results.emplace_back (type.getType (), *convention);
1683+ typename T::OptionsType options;
1684+ for (unsigned i = 1 ; i < node->getNumChildren () - 1 ; ++i) {
1685+ auto child = node->getChild (i);
1686+ switch (child->getKind ()) {
1687+ case Node::Kind::ImplParameterResultDifferentiability: {
1688+ auto optDiffOptions =
1689+ T::getDifferentiabilityFromString (child->getText ());
1690+ if (!optDiffOptions)
1691+ return true ;
1692+ options |= *optDiffOptions;
1693+ break ;
1694+ }
1695+ case Node::Kind::ImplParameterSending:
1696+ options |= T::getSending ();
1697+ break ;
1698+ case Node::Kind::ImplParameterIsolated:
1699+ options |= T::getIsolated ();
1700+ break ;
1701+ case Node::Kind::ImplParameterImplicitLeading:
1702+ options |= T::getImplicitLeading ();
1703+ break ;
1704+ default :
1705+ return true ;
1706+ }
1707+ }
1708+
1709+ results.emplace_back (result.getType (), *convention, options);
1710+
16631711 return false ;
16641712 }
16651713
16661714 template <typename T>
1667- bool decodeImplFunctionParam (Demangle::NodePointer node, unsigned depth,
1668- llvm::SmallVectorImpl<T> &results) {
1715+ bool decodeImplFunctionResult (Demangle::NodePointer node, unsigned depth,
1716+ llvm::SmallVectorImpl<T> &results) {
16691717 if (depth > TypeDecoder::MaxDepth)
16701718 return true ;
16711719
1672- // Children: `convention, differentiability?, sending? , type`
1673- if (node-> getNumChildren () != 2 && node-> getNumChildren () != 3 &&
1674- node->getNumChildren () != 4 )
1720+ // Children: `convention, attrs , type`
1721+ // attrs: `differentiability?, sending?, isolated?, implicit_leading?`
1722+ if ( node->getNumChildren () < 2 )
16751723 return true ;
16761724
16771725 auto *conventionNode = node->getChild (0 );
@@ -1689,23 +1737,24 @@ class TypeDecoder {
16891737 return true ;
16901738
16911739 typename T::OptionsType options;
1692- if (node->getNumChildren () == 3 || node->getNumChildren () == 4 ) {
1693- auto diffKindNode = node->getChild (1 );
1694- if (diffKindNode->getKind () !=
1695- Node::Kind::ImplParameterResultDifferentiability)
1696- return true ;
1697- auto optDiffOptions =
1698- T::getDifferentiabilityFromString (diffKindNode->getText ());
1699- if (!optDiffOptions)
1700- return true ;
1701- options |= *optDiffOptions;
1702- }
1703-
1704- if (node->getNumChildren () == 4 ) {
1705- auto sendingKindNode = node->getChild (2 );
1706- if (sendingKindNode->getKind () != Node::Kind::ImplParameterSending)
1740+ for (unsigned i = 1 ; i < node->getNumChildren () - 1 ; ++i) {
1741+ auto child = node->getChild (i);
1742+ switch (child->getKind ()) {
1743+ case Node::Kind::ImplParameterResultDifferentiability: {
1744+ auto optDiffOptions =
1745+ T::getDifferentiabilityFromString (child->getText ());
1746+ if (!optDiffOptions)
1747+ return true ;
1748+ options |= *optDiffOptions;
1749+ break ;
1750+ }
1751+ case Node::Kind::ImplParameterSending:
1752+ options |= T::getSending ();
1753+ break ;
1754+ break ;
1755+ default :
17071756 return true ;
1708- options |= T::getSending ();
1757+ }
17091758 }
17101759
17111760 results.emplace_back (result.getType (), *convention, options);
0 commit comments