Skip to content

Commit 39e681c

Browse files
committed
OnoneSupport: hard-code the ABI of libswiftSwiftOnoneSupport into the compiler.
Add the list of symbols from the swift-5.0 release and only use that symbols to refer to pre-specializations in a Onone build. This ensures that future Onone executables can link to an old swift 5.0 libswiftSwiftOnoneSupport library. rdar://problem/48924409
1 parent 35f5c7a commit 39e681c

File tree

3 files changed

+1213
-84
lines changed

3 files changed

+1213
-84
lines changed

lib/SILOptimizer/Utils/Generics.cpp

Lines changed: 15 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/SILOptimizer/Utils/SILOptFunctionBuilder.h"
2424
#include "swift/SILOptimizer/Utils/GenericCloner.h"
2525
#include "swift/SILOptimizer/Utils/SpecializationMangler.h"
26+
#include "swift/Demangling/ManglingMacros.h"
2627
#include "swift/Strings.h"
2728

2829
using namespace swift;
@@ -2499,91 +2500,24 @@ static bool linkSpecialization(SILModule &M, SILFunction *F) {
24992500
return false;
25002501
}
25012502

2502-
bool swift::isKnownPrespecialization(StringRef SpecName) {
2503-
// Completely disable for now.
2504-
#if false
2505-
2506-
/// The list of classes and functions from the stdlib
2507-
/// whose specializations we want to preserve.
2508-
static const char *const KnownPrespecializations[] = {
2509-
"Array",
2510-
"_ArrayBuffer",
2511-
"_ContiguousArrayBuffer",
2512-
"Range",
2513-
"RangeIterator",
2514-
"CountableRange",
2515-
"CountableRangeIterator",
2516-
"ClosedRange",
2517-
"ClosedRangeIterator",
2518-
"CountableClosedRange",
2519-
"CountableClosedRangeIterator",
2520-
"IndexingIterator",
2521-
"Collection",
2522-
"ReversedCollection",
2523-
"MutableCollection",
2524-
"BidirectionalCollection",
2525-
"RandomAccessCollection",
2526-
"ReversedRandomAccessCollection",
2527-
"RangeReplaceableCollection",
2528-
"_allocateUninitializedArray",
2529-
"UTF8",
2530-
"UTF16",
2531-
"String",
2532-
"_StringBuffer",
2533-
};
2534-
2535-
// TODO: Once there is an efficient API to check if
2536-
// a given symbol is a specialization of a specific type,
2537-
// use it instead. Doing demangling just for this check
2538-
// is just wasteful.
2539-
auto DemangledNameString =
2540-
swift::Demangle::demangleSymbolAsString(SpecName);
2541-
2542-
StringRef DemangledName = DemangledNameString;
2543-
2544-
LLVM_DEBUG(llvm::dbgs() << "Check if known: " << DemangledName << "\n");
2545-
2546-
auto pos = DemangledName.find("generic ", 0);
2547-
auto oldpos = pos;
2548-
if (pos == StringRef::npos)
2549-
return false;
2550-
2551-
// Create "of Swift"
2552-
llvm::SmallString<64> OfString;
2553-
llvm::raw_svector_ostream buffer(OfString);
2554-
buffer << "of ";
2555-
buffer << STDLIB_NAME <<'.';
2556-
2557-
StringRef OfStr = buffer.str();
2558-
LLVM_DEBUG(llvm::dbgs() << "Check substring: " << OfStr << "\n");
2559-
2560-
pos = DemangledName.find(OfStr, oldpos);
2561-
2562-
if (pos == StringRef::npos) {
2563-
// Create "of (extension in Swift).Swift"
2564-
llvm::SmallString<64> OfString;
2565-
llvm::raw_svector_ostream buffer(OfString);
2566-
buffer << "of (extension in " << STDLIB_NAME << "):";
2567-
buffer << STDLIB_NAME << '.';
2568-
OfStr = buffer.str();
2569-
pos = DemangledName.find(OfStr, oldpos);
2570-
LLVM_DEBUG(llvm::dbgs() << "Check substring: " << OfStr << "\n");
2571-
if (pos == StringRef::npos)
2572-
return false;
2573-
}
2503+
#define PRESPEC_SYMBOL(s) MANGLE_AS_STRING(s),
2504+
static const char *PrespecSymbols[] = {
2505+
#include "OnonePrespecializations.def"
2506+
nullptr
2507+
};
2508+
#undef PRESPEC_SYMBOL
25742509

2575-
pos += OfStr.size();
2510+
llvm::DenseSet<StringRef> PrespecSet;
25762511

2577-
for (auto NameStr : KnownPrespecializations) {
2578-
StringRef Name = NameStr;
2579-
auto pos1 = DemangledName.find(Name, pos);
2580-
if (pos1 == pos && !isalpha(DemangledName[pos1+Name.size()])) {
2581-
return true;
2512+
bool swift::isKnownPrespecialization(StringRef SpecName) {
2513+
if (PrespecSet.empty()) {
2514+
const char **Pos = &PrespecSymbols[0];
2515+
while (const char *Sym = *Pos++) {
2516+
PrespecSet.insert(Sym);
25822517
}
2518+
assert(!PrespecSet.empty());
25832519
}
2584-
2585-
#endif
2586-
return false;
2520+
return PrespecSet.count(SpecName) != 0;
25872521
}
25882522

25892523
/// Try to look up an existing specialization in the specialization cache.

0 commit comments

Comments
 (0)