Skip to content

Commit 1535f30

Browse files
committed
Fix Runtime Attribute mangling
use here fix tests
1 parent cbdf6e5 commit 1535f30

File tree

9 files changed

+193
-176
lines changed

9 files changed

+193
-176
lines changed

docs/ABI/Mangling.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ Entities
348348
entity-spec ::= type 'fU' INDEX // explicit anonymous closure expression
349349
entity-spec ::= type 'fu' INDEX // implicit anonymous closure
350350
entity-spec ::= 'fA' INDEX // default argument N+1 generator
351-
entity-spec ::= 'fa' // runtime discoverable attribute generator
351+
entity-spec ::= entity 'fa' // runtime discoverable attribute generator
352352
entity-spec ::= 'fi' // non-local variable initializer
353353
entity-spec ::= 'fP' // property wrapper backing initializer
354354
entity-spec ::= 'fW' // property wrapper init from projected value

lib/AST/ASTMangler.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3864,8 +3864,13 @@ void ASTMangler::appendRuntimeAttributeGeneratorEntity(const ValueDecl *decl,
38643864
CustomAttr *attr) {
38653865
auto *attrType = decl->getRuntimeDiscoverableAttrTypeDecl(attr);
38663866

3867-
appendEntity(decl, "vp", decl->isStatic());
3867+
appendContext(attrType, attrType->getAlternateModuleName());
3868+
3869+
if (auto dc = dyn_cast<DeclContext>(decl)) {
3870+
appendContext(dc, decl->getAlternateModuleName());
3871+
} else {
3872+
appendEntity(decl);
3873+
}
3874+
38683875
appendOperator("fa");
3869-
appendContextOf(attrType);
3870-
appendDeclName(attrType);
38713876
}

lib/Demangling/Demangler.cpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3574,7 +3574,7 @@ NodePointer Demangler::demangleFunctionEntity() {
35743574
TypeAndMaybePrivateName,
35753575
TypeAndIndex,
35763576
Index,
3577-
ContextAndName,
3577+
ContextArg,
35783578
} Args;
35793579

35803580
Node::Kind Kind = Node::Kind::EmptyList;
@@ -3592,7 +3592,7 @@ NodePointer Demangler::demangleFunctionEntity() {
35923592
case 'u': Args = TypeAndIndex; Kind = Node::Kind::ImplicitClosure; break;
35933593
case 'A': Args = Index; Kind = Node::Kind::DefaultArgumentInitializer; break;
35943594
case 'a':
3595-
Args = ContextAndName;
3595+
Args = ContextArg;
35963596
Kind = Node::Kind::RuntimeAttributeGenerator;
35973597
break;
35983598
case 'm': return demangleEntity(Node::Kind::Macro);
@@ -3610,7 +3610,7 @@ NodePointer Demangler::demangleFunctionEntity() {
36103610
}
36113611

36123612
NodePointer NameOrIndex = nullptr, ParamType = nullptr, LabelList = nullptr,
3613-
Context = nullptr, Id = nullptr;
3613+
Context = nullptr;
36143614
switch (Args) {
36153615
case None:
36163616
break;
@@ -3626,9 +3626,8 @@ NodePointer Demangler::demangleFunctionEntity() {
36263626
case Index:
36273627
NameOrIndex = demangleIndexAsNode();
36283628
break;
3629-
case ContextAndName:
3630-
Context = demangleOperator();
3631-
Id = demangleOperator();
3629+
case ContextArg:
3630+
Context = popNode();
36323631
break;
36333632
}
36343633
NodePointer Entity = createWithChild(Kind, popContext());
@@ -3647,9 +3646,8 @@ NodePointer Demangler::demangleFunctionEntity() {
36473646
Entity = addChild(Entity, NameOrIndex);
36483647
Entity = addChild(Entity, ParamType);
36493648
break;
3650-
case ContextAndName:
3649+
case ContextArg:
36513650
Entity = addChild(Entity, Context);
3652-
Entity = addChild(Entity, Id);
36533651
break;
36543652
}
36553653
return Entity;

lib/Demangling/NodePrinter.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,11 +3098,14 @@ NodePointer NodePrinter::print(NodePointer Node, unsigned depth,
30983098
Printer << "#_hasSymbol query for ";
30993099
return nullptr;
31003100
case Node::Kind::RuntimeAttributeGenerator:
3101-
printEntity(Node, depth, asPrefixContext, TypePrinting::NoType,
3102-
/*hasName*/ false,
3103-
"runtime attribute generator");
3104-
Printer << " for attribute = " << Node->getChild(1)->getText() << "."
3105-
<< Node->getChild(2)->getText();
3101+
Printer << "runtime attribute generator of ";
3102+
3103+
print(Node->getChild(1), depth);
3104+
3105+
printEntity(Node, depth, asPrefixContext,
3106+
TypePrinting::NoType, /*hasName*/ false,
3107+
" for attribute");
3108+
31063109
return nullptr;
31073110
case Node::Kind::OpaqueReturnTypeIndex:
31083111
case Node::Kind::OpaqueReturnTypeParent:

lib/Demangling/Remangler.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3616,9 +3616,9 @@ ManglingError
36163616
Remangler::mangleRuntimeAttributeGenerator(Node *node,
36173617
unsigned depth) {
36183618
RETURN_IF_ERROR(mangleChildNode(node, 0, depth + 1));
3619-
Buffer << "fa";
36203619
RETURN_IF_ERROR(mangleChildNode(node, 1, depth + 1));
3621-
return mangleChildNode(node, 2, depth + 1);
3620+
Buffer << "fa";
3621+
return ManglingError::Success;
36223622
}
36233623

36243624
} // anonymous namespace

test/Demangle/Inputs/manglings.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -444,12 +444,13 @@ $s7Library5KlassCTwS ---> #_hasSymbol query for Library.Klass
444444
$s14swift_ide_test14myColorLiteral3red5green4blue5alphaAA0E0VSf_S3ftcfm ---> swift_ide_test.myColorLiteral(red: Swift.Float, green: Swift.Float, blue: Swift.Float, alpha: Swift.Float) -> swift_ide_test.Color
445445
$s14swift_ide_test10myFilenamexfm ---> swift_ide_test.myFilename : A
446446
$s4main4FlagVHa ---> runtime discoverable attribute record for main.Flag
447-
$s4main4TestV11doSomethingyycvpfaAA4FlagHF ---> accessible function runtime record for runtime attribute generator of main.Test.doSomething : () -> () for attribute = main.Flag
448-
$s4main10globalTest1a_ySi_SStcvpfaAA4Flag ---> runtime attribute generator of main.globalTest : (a: Swift.Int, _: Swift.String) -> () for attribute = main.Flag
449-
$s4main4TestV11doSomethingyycvpfaAA4Flag ---> runtime attribute generator of main.Test.doSomething : () -> () for attribute = main.Flag
450-
$s4main4TestV11doSomethingyycvpZfaAA4Flag ---> runtime attribute generator of static main.Test.doSomething : () -> () for attribute = main.Flag
451-
$s4main4TestV1xSivpfaAA4Flag ---> runtime attribute generator of main.Test.x : Swift.Int for attribute = main.Flag
452-
$s4main4TestAaBVmvpfaAA9OtherFlag ---> runtime attribute generator of main.Test : main.Test.Type for attribute = main.OtherFlag
447+
$s4main4FlagVAA4TestV11doSomethingyycvpfaHF ---> accessible function runtime record for runtime attribute generator of main.Test.doSomething : () -> () for attribute of main.Flag
448+
$s4main4FlagVAA10globalTest1a_ySi_SStcvpfa ---> runtime attribute generator of main.globalTest : (a: Swift.Int, _: Swift.String) -> () for attribute of main.Flag
449+
$s4main4FlagVAA4TestV11doSomethingyycvpfa ---> runtime attribute generator of main.Test.doSomething : () -> () for attribute of main.Flag
450+
$s4main4FlagVAA4TestV11doSomethingyycvpZfa ---> runtime attribute generator of static main.Test.doSomething : () -> () for attribute of main.Flag
451+
$s4main4FlagVAA4TestV1xSivpfa ---> runtime attribute generator of main.Test.x : Swift.Int for attribute of main.Flag
452+
$s4main9OtherFlagVAA4TestVfa ---> runtime attribute generator of main.Test for attribute of main.OtherFlag
453+
$s4main4TestVAA3ABCV4hereyySiFfa ---> runtime attribute generator of main.ABC.here(Swift.Int) -> () for attribute of main.Test
453454
$s9MacroUser13testStringify1a1bySi_SitF9stringifyfMf1_ ---> freestanding macro expansion #3 of stringify in MacroUser.testStringify(a: Swift.Int, b: Swift.Int) -> ()
454455
$s9MacroUser016testFreestandingA9ExpansionyyF4Foo3L_V23bitwidthNumberedStructsfMf_6methodfMu0_ ---> unique name #2 of method in freestanding macro expansion #1 of bitwidthNumberedStructs in Foo3 #1 in MacroUser.testFreestandingMacroExpansion() -> ()
455456
@__swiftmacro_1a13testStringifyAA1bySi_SitF9stringifyfMf_ ---> freestanding macro expansion #1 of stringify in a.testStringify(a: Swift.Int, b: Swift.Int) -> ()

0 commit comments

Comments
 (0)