Skip to content

Commit

Permalink
Mangling: support new mangling of partial apply forwarders in IRGen
Browse files Browse the repository at this point in the history
  • Loading branch information
eeckstein committed Dec 9, 2016
1 parent 7dbab5a commit ad1c079
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
7 changes: 5 additions & 2 deletions lib/Basic/Mangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,12 @@ std::string NewMangling::selectMangling(const std::string &Old,
std::string Remangled = mangleNodeNew(NewNode);
if (New != Remangled) {
bool isEqual = false;
if (containsDependentAssociatedTypeRef(NewNode)) {
if (containsDependentAssociatedTypeRef(NewNode) ||
// Does the mangling contain an identifier which is the name of
// an old-mangled function?
New.find("_T") != std::string::npos) {
NodePointer RemangledNode = demangleSymbolAsNode(Remangled);
isEqual = areTreesEqual(RemangledNode, NewNode);
isEqual = areTreesEqual(NewNode, RemangledNode);
}
if (!isEqual) {
llvm::errs() << "Remangling failed at #" << numCmp << ":\n"
Expand Down
18 changes: 13 additions & 5 deletions lib/IRGen/GenFunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@
#include "ScalarTypeInfo.h"
#include "GenFunc.h"
#include "Signature.h"
#include "IRGenMangler.h"

using namespace swift;
using namespace irgen;
Expand Down Expand Up @@ -700,13 +701,20 @@ static llvm::Function *emitPartialApplicationForwarder(IRGenModule &IGM,
llvm::FunctionType *fwdTy = IGM.getFunctionType(outType, outAttrs);
// Build a name for the thunk. If we're thunking a static function reference,
// include its symbol name in the thunk name.
llvm::SmallString<20> thunkName;
thunkName += "_TPA";
llvm::SmallString<20> OldThunkName;
StringRef FnName;
OldThunkName += "_TPA";
if (staticFnPtr) {
thunkName += '_';
thunkName += staticFnPtr->getName();
FnName = staticFnPtr->getName();
OldThunkName += '_';
OldThunkName += FnName;
}

IRGenMangler Mangler;
std::string NewThunkName = Mangler.manglePartialApplyForwarder(FnName);

std::string thunkName = NewMangling::selectMangling(OldThunkName.str(),
NewThunkName);

// FIXME: Maybe cache the thunk by function and closure types?.
llvm::Function *fwd =
llvm::Function::Create(fwdTy, llvm::Function::InternalLinkage,
Expand Down
16 changes: 16 additions & 0 deletions lib/IRGen/IRGenMangler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//

#include "IRGenMangler.h"
#include "swift/Basic/ManglingMacros.h"

using namespace swift;
using namespace irgen;
Expand All @@ -33,3 +34,18 @@ std::string IRGenMangler::mangleValueWitness(Type type, ValueWitness witness) {
appendOperator("w", Code);
return finalize();
}

std::string IRGenMangler::manglePartialApplyForwarder(StringRef FuncName) {
if (FuncName.empty()) {
beginMangling();
} else {
if (FuncName.startswith(MANGLING_PREFIX_STR)) {
Buffer << FuncName;
} else {
beginMangling();
appendIdentifier(FuncName);
}
}
appendOperator("TA");
return finalize();
}
1 change: 1 addition & 0 deletions lib/IRGen/IRGenMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class IRGenMangler : public NewMangling::ASTMangler {
return mangleNominalTypeSymbol(Decl, "MC");
}

std::string manglePartialApplyForwarder(StringRef FuncName);

protected:

Expand Down

0 comments on commit ad1c079

Please sign in to comment.