Skip to content

Move pre-specializations of popular types away from the stdlib #1392

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/swift/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace swift {
static const char LLVM_IR_EXTENSION[] = "ll";
/// The name of the standard library, which is a reserved module name.
static const char STDLIB_NAME[] = "Swift";
/// The name of the Onone support library, which is a reserved module name.
static const char SWIFT_ONONE_SUPPORT[] = "SwiftOnoneSupport";
/// The name of the SwiftShims module, which contains private stdlib decls.
static const char SWIFT_SHIMS_NAME[] = "SwiftShims";
/// The prefix of module names used by LLDB to capture Swift expressions
Expand Down
13 changes: 13 additions & 0 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,19 @@ void CompilerInstance::performSema() {
return;
}

const auto &silOptions = Invocation.getSILOptions();
if ((silOptions.Optimization <= SILOptions::SILOptMode::None &&
(options.RequestedAction == FrontendOptions::EmitObject ||
options.RequestedAction == FrontendOptions::Immediate)) ||
(silOptions.Optimization == SILOptions::SILOptMode::None &&
options.RequestedAction >= FrontendOptions::EmitSILGen)) {
// Implicitly import the SwiftOnoneSupport module in non-optimized
// builds. This allows for use of popular specialized functions
// from the standard library, which makes the non-optimized builds
// execute much faster.
Invocation.getFrontendOptions()
.ImplicitImportModuleNames.push_back(SWIFT_ONONE_SUPPORT);
}
break;
}
}
Expand Down
5 changes: 3 additions & 2 deletions lib/SILOptimizer/Utils/Generics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ static bool cacheSpecialization(SILModule &M, SILFunction *F) {

if (M.getOptions().Optimization >= SILOptions::SILOptMode::Optimize &&
F->getLinkage() != SILLinkage::Public &&
F->getModule().getSwiftModule()->getName().str() == STDLIB_NAME) {
F->getModule().getSwiftModule()->getName().str() == SWIFT_ONONE_SUPPORT) {
if (F->getLinkage() != SILLinkage::Public &&
isWhitelistedSpecialization(F->getName())) {

Expand Down Expand Up @@ -209,7 +209,8 @@ SILFunction *swift::getExistingSpecialization(SILModule &M,
assert((Specialization->isExternalDeclaration() ||
convertExternalDefinitionIntoDeclaration(Specialization)) &&
"Could not remove body of the found specialization");
if (!convertExternalDefinitionIntoDeclaration(Specialization)) {
if (!Specialization->isExternalDeclaration() &&
!convertExternalDefinitionIntoDeclaration(Specialization)) {
DEBUG(
llvm::dbgs() << "Could not remove body of specialization: "
<< FunctionName << '\n');
Expand Down
11 changes: 10 additions & 1 deletion lib/Serialization/SerializeSIL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#define DEBUG_TYPE "sil-serialize"
#include "SILFormat.h"
#include "Serialization.h"
#include "swift/Strings.h"
#include "swift/AST/Module.h"
#include "swift/SIL/SILArgument.h"
#include "swift/SIL/SILModule.h"
Expand Down Expand Up @@ -1682,8 +1683,16 @@ void SILSerializer::writeSILBlock(const SILModule *SILMod) {
// Go through all the SILFunctions in SILMod and write out any
// mandatory function bodies.
for (const SILFunction &F : *SILMod) {
if (shouldEmitFunctionBody(F) || ShouldSerializeAll)
if (shouldEmitFunctionBody(F) || ShouldSerializeAll) {
if (F.getModule().getSwiftModule()->getNameStr() == SWIFT_ONONE_SUPPORT) {
// Serialize only the declarations so that it is possible to check the
// existance of this function later.
// FIXME: SILLinker::lookupFunction does not work with functions having
// empty bodies, otherwise we could have serialized only declarations.
//writeSILFunction(F, true);
}
writeSILFunction(F);
}
}

if (ShouldSerializeAll)
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ if(SWIFT_BUILD_STDLIB)
add_subdirectory(runtime)
add_subdirectory(stubs)
add_subdirectory(core)
add_subdirectory(SwiftOnoneSupport)
endif()

if(CMAKE_SYSTEM_NAME STREQUAL "Darwin")
Expand Down
6 changes: 6 additions & 0 deletions stdlib/public/SwiftOnoneSupport/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
add_swift_library(swiftSwiftOnoneSupport SHARED IS_STDLIB
# This file should be listed the first. Module name is inferred from the
# filename.
SwiftOnoneSupport.swift
SWIFT_COMPILE_FLAGS ${STDLIB_SIL_SERIALIZE_ALL}
INSTALL_IN_COMPONENT stdlib)
1 change: 0 additions & 1 deletion stdlib/public/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ set(SWIFTLIB_SOURCES
Tuple.swift.gyb
VarArgs.swift
Zip.swift
Prespecialized.swift
)

set(swift_core_link_flags)
Expand Down
8 changes: 4 additions & 4 deletions test/Driver/emit-sib-single-file.swift
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
// RUN: %target-build-swift -emit-sib %s -o %t.sib
// RUN: %target-build-swift -Onone -emit-sib %s -o %t.sib
// RUN: %target-build-swift %t.sib -o %t
// RUN: %target-run %t | FileCheck %s

// RUN: %target-build-swift -c %t.sib -o %t.o
// RUN: %target-build-swift -Onone -c %t.sib -o %t.o
// RUN: %target-build-swift %t.o -o %t
// RUN: %target-run %t | FileCheck %s

// RUN: %target-build-swift -emit-sibgen %s -o %t.sib
// RUN: %target-build-swift -Onone -emit-sibgen %s -o %t.sib
// RUN: %target-build-swift %t.sib -o %t
// RUN: %target-run %t | FileCheck %s

// RUN: %target-build-swift -c %t.sib -o %t.o
// RUN: %target-build-swift -Onone -c %t.sib -o %t.o
// RUN: %target-build-swift %t.o -o %t
// RUN: %target-run %t | FileCheck %s
// REQUIRES: executable_test
Expand Down