Skip to content

Commit c4a2545

Browse files
authored
Merge pull request #1468 from swiftwasm/release/5.3
[pull] swiftwasm-release/5.3 from release/5.3
2 parents 2c5b9cd + bba74cc commit c4a2545

File tree

18 files changed

+195
-57
lines changed

18 files changed

+195
-57
lines changed

docs/ABI/Mangling.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ Globals
171171
global ::= entity 'Wvd' // field offset
172172
global ::= entity 'WC' // resilient enum tag index
173173

174+
global ::= global 'MK' // instantiation cache associated with global
175+
174176
A direct symbol resolves directly to the address of an object. An
175177
indirect symbol resolves to the address of a pointer to the object.
176178
They are distinct manglings to make a certain class of bugs

include/swift/Demangling/DemangleNodes.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,5 +286,8 @@ NODE(OpaqueTypeDescriptorAccessorVar)
286286
NODE(OpaqueReturnType)
287287
CONTEXT_NODE(OpaqueReturnTypeOf)
288288

289+
// Added in Swift 5.3
290+
NODE(MetadataInstantiationCache)
291+
289292
#undef CONTEXT_NODE
290293
#undef NODE

lib/Demangling/Demangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1897,6 +1897,9 @@ NodePointer Demangler::demangleMetatype() {
18971897
case 'j':
18981898
return createWithChild(Node::Kind::OpaqueTypeDescriptorAccessorKey,
18991899
popNode());
1900+
case 'K':
1901+
return createWithChild(Node::Kind::MetadataInstantiationCache,
1902+
popNode());
19001903
case 'k':
19011904
return createWithChild(Node::Kind::OpaqueTypeDescriptorAccessorVar,
19021905
popNode());

lib/Demangling/NodePrinter.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ class NodePrinter {
447447
case Node::Kind::PropertyDescriptor:
448448
case Node::Kind::ProtocolConformance:
449449
case Node::Kind::ProtocolConformanceDescriptor:
450+
case Node::Kind::MetadataInstantiationCache:
450451
case Node::Kind::ProtocolDescriptor:
451452
case Node::Kind::ProtocolRequirementsBaseDescriptor:
452453
case Node::Kind::ProtocolSelfConformanceDescriptor:
@@ -2400,6 +2401,10 @@ NodePointer NodePrinter::print(NodePointer Node, bool asPrefixContext) {
24002401
case Node::Kind::AccessorFunctionReference:
24012402
Printer << "accessor function at " << Node->getIndex();
24022403
return nullptr;
2404+
case Node::Kind::MetadataInstantiationCache:
2405+
Printer << "metadata instantiation cache for ";
2406+
print(Node->getChild(0));
2407+
return nullptr;
24032408
}
24042409
printer_unreachable("bad node kind!");
24052410
}

lib/Demangling/OldRemangler.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2119,6 +2119,9 @@ void Remangler::mangleOpaqueTypeDescriptorAccessorVar(Node *node) {
21192119
void Remangler::mangleAccessorFunctionReference(Node *node) {
21202120
unreachable("can't remangle");
21212121
}
2122+
void Remangler::mangleMetadataInstantiationCache(Node *node) {
2123+
unreachable("unsupported");
2124+
}
21222125

21232126
/// The top-level interface to the remangler.
21242127
std::string Demangle::mangleNodeOld(NodePointer node) {

lib/Demangling/Remangler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2515,6 +2515,11 @@ void Remangler::mangleAccessorFunctionReference(Node *node) {
25152515
unreachable("can't remangle");
25162516
}
25172517

2518+
void Remangler::mangleMetadataInstantiationCache(Node *node) {
2519+
mangleSingleChildNode(node);
2520+
Buffer << "MK";
2521+
}
2522+
25182523
} // anonymous namespace
25192524

25202525
/// The top-level interface to the remangler.

lib/IDE/ExprContextAnalysis.cpp

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,16 +226,30 @@ class CCExprRemover: public ASTWalker, public ExprVisitor<CCExprRemover, Expr *>
226226
} else if (auto tuple = dyn_cast<TupleExpr>(E->getArg())) {
227227
lParenLoc = tuple->getLParenLoc();
228228
rParenLoc = tuple->getRParenLoc();
229+
230+
assert((!E->getUnlabeledTrailingClosureIndex().hasValue() ||
231+
(tuple->getNumElements() == E->getArgumentLabels().size() &&
232+
tuple->getNumElements() == E->getArgumentLabelLocs().size())) &&
233+
"CallExpr with trailing closure must have the same number of "
234+
"argument labels");
235+
assert(tuple->getNumElements() == E->getArgumentLabels().size());
236+
assert(tuple->getNumElements() == E->getArgumentLabelLocs().size() ||
237+
E->getArgumentLabelLocs().size() == 0);
238+
239+
bool hasArgumentLabelLocs = E->getArgumentLabelLocs().size() > 0;
240+
229241
for (unsigned i = 0, e = tuple->getNumElements(); i != e; ++i) {
230242
if (isa<CodeCompletionExpr>(tuple->getElement(i))) {
231243
removing = true;
232244
continue;
233245
}
234246

235-
if (i < E->getUnlabeledTrailingClosureIndex()) {
247+
if (!E->getUnlabeledTrailingClosureIndex().hasValue() ||
248+
i < *E->getUnlabeledTrailingClosureIndex()) {
236249
// Normal arguments.
237250
argLabels.push_back(E->getArgumentLabels()[i]);
238-
argLabelLocs.push_back(E->getArgumentLabelLocs()[i]);
251+
if (hasArgumentLabelLocs)
252+
argLabelLocs.push_back(E->getArgumentLabelLocs()[i]);
239253
args.push_back(tuple->getElement(i));
240254
} else {
241255
// Trailing closure arguments.
@@ -259,7 +273,20 @@ class CCExprRemover: public ASTWalker, public ExprVisitor<CCExprRemover, Expr *>
259273
}
260274

261275
std::pair<bool, Expr *> walkToExprPre(Expr *E) override {
262-
return {true, visit(E)};
276+
if (Removed)
277+
return {false, nullptr};
278+
E = visit(E);
279+
return {!Removed, E};
280+
}
281+
282+
std::pair<bool, Stmt *> walkToStmtPre(Stmt *S) override {
283+
if (Removed)
284+
return {false, nullptr};
285+
return {true, S};
286+
}
287+
288+
bool walkToDeclPre(Decl *D) override {
289+
return !Removed;
263290
}
264291
};
265292
}

lib/IRGen/GenProto.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1919,11 +1919,16 @@ namespace {
19191919
llvm::ArrayType::get(IGM.Int8PtrTy,
19201920
swift::NumGenericMetadataPrivateDataWords);
19211921
auto privateDataInit = llvm::Constant::getNullValue(privateDataTy);
1922+
1923+
IRGenMangler mangler;
1924+
auto symbolName =
1925+
mangler.mangleProtocolConformanceInstantiationCache(Conformance);
1926+
19221927
auto privateData =
19231928
new llvm::GlobalVariable(IGM.Module, privateDataTy,
19241929
/*constant*/ false,
19251930
llvm::GlobalVariable::InternalLinkage,
1926-
privateDataInit, "");
1931+
privateDataInit, symbolName);
19271932
B.addRelativeAddress(privateData);
19281933
}
19291934
}

lib/IRGen/IRGenMangler.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ IRGenMangler::mangleTypeForReflection(IRGenModule &IGM,
143143
});
144144
}
145145

146+
147+
146148
std::string IRGenMangler::mangleProtocolConformanceDescriptor(
147149
const RootProtocolConformance *conformance) {
148150
beginMangling();
@@ -157,6 +159,21 @@ std::string IRGenMangler::mangleProtocolConformanceDescriptor(
157159
return finalize();
158160
}
159161

162+
std::string IRGenMangler::mangleProtocolConformanceInstantiationCache(
163+
const RootProtocolConformance *conformance) {
164+
beginMangling();
165+
if (isa<NormalProtocolConformance>(conformance)) {
166+
appendProtocolConformance(conformance);
167+
appendOperator("Mc");
168+
} else {
169+
auto protocol = cast<SelfProtocolConformance>(conformance)->getProtocol();
170+
appendProtocolName(protocol);
171+
appendOperator("MS");
172+
}
173+
appendOperator("MK");
174+
return finalize();
175+
}
176+
160177
SymbolicMangling
161178
IRGenMangler::mangleProtocolConformanceForReflection(IRGenModule &IGM,
162179
Type ty, ProtocolConformanceRef conformance) {

lib/IRGen/IRGenMangler.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,10 @@ class IRGenMangler : public Mangle::ASTMangler {
306306
}
307307

308308
std::string mangleProtocolConformanceDescriptor(
309-
const RootProtocolConformance *conformance);
310-
309+
const RootProtocolConformance *conformance);
310+
std::string mangleProtocolConformanceInstantiationCache(
311+
const RootProtocolConformance *conformance);
312+
311313
std::string manglePropertyDescriptor(const AbstractStorageDecl *storage) {
312314
beginMangling();
313315
appendEntity(storage);

0 commit comments

Comments
 (0)