Skip to content

Support for copy-on-write existentials - IRGen Support #8005

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 9 commits into from
Mar 10, 2017
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
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,10 @@ option(SWIFT_STDLIB_ENABLE_RESILIENCE
"Build the standard libraries and overlays with resilience enabled; see docs/LibraryEvolution.rst"
FALSE)

option(SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS
"Build the runtime with a copy-on-write implementation for opaque existentials"
FALSE)

option(SWIFT_STDLIB_USE_NONATOMIC_RC
"Build the standard libraries and overlays with nonatomic reference count operations enabled"
FALSE)
Expand Down
4 changes: 4 additions & 0 deletions cmake/modules/SwiftSource.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,10 @@ function(_compile_swift_files
list(APPEND swift_flags "-Xfrontend" "-assume-single-threaded")
endif()

if(SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS)
list(APPEND swift_flags "-Xfrontend" "-enable-cow-existentials")
endif()

if(SWIFT_STDLIB_ENABLE_SIL_OWNERSHIP AND SWIFTFILE_IS_STDLIB)
list(APPEND swift_flags "-Xfrontend" "-enable-sil-ownership")
endif()
Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/SILOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class SILOptions {
/// Assume that code will be executed in a single-threaded environment.
bool AssumeSingleThreaded = false;

/// Use the copy-on-write implementation for opaque existentials.
unsigned UseCOWExistentials = false;

/// Indicates which sanitizer is turned on.
SanitizerKind Sanitize : 2;

Expand Down
3 changes: 3 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,9 @@ def enable_experimental_property_behaviors :
Flag<["-"], "enable-experimental-property-behaviors">,
HelpText<"Enable experimental property behaviors">;

def enable_cow_existentials : Flag<["-"], "enable-cow-existentials">,
HelpText<"Enable the copy-on-write existential implementation">;

def disable_availability_checking : Flag<["-"],
"disable-availability-checking">,
HelpText<"Disable checking for potentially unavailable APIs">;
Expand Down
8 changes: 4 additions & 4 deletions include/swift/SIL/SILInstruction.h
Original file line number Diff line number Diff line change
Expand Up @@ -5736,6 +5736,10 @@ class ApplySite {

#undef FOREACH_IMPL_RETURN

SILArgumentConvention getArgumentConvention(unsigned index) const {
return getSubstCalleeConv().getSILArgumentConvention(index);
}

static ApplySite getFromOpaqueValue(void *p) {
return ApplySite(p);
}
Expand Down Expand Up @@ -5786,10 +5790,6 @@ class FullApplySite : public ApplySite {
return getArguments().slice(getNumIndirectSILResults());
}

SILArgumentConvention getArgumentConvention(unsigned index) const {
return getSubstCalleeConv().getSILArgumentConvention(index);
}

static FullApplySite getFromOpaqueValue(void *p) {
return FullApplySite(p);
}
Expand Down
4 changes: 4 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1237,6 +1237,10 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
IRGenOpts.Sanitize = Opts.Sanitize;
}

/// Should we use the copy-on-write implementation of opaque existentials.
/// FIXME: Use during bootstraping this feature. Remove later.
Opts.UseCOWExistentials = Args.hasArg(OPT_enable_cow_existentials);

return false;
}

Expand Down
10 changes: 7 additions & 3 deletions lib/IRGen/GenDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3328,7 +3328,8 @@ IRGenModule::getAddrOfAssociatedTypeWitnessTableAccessFunction(

/// Should we be defining the given helper function?
static llvm::Function *shouldDefineHelper(IRGenModule &IGM,
llvm::Constant *fn) {
llvm::Constant *fn,
bool setIsNoInline) {
llvm::Function *def = dyn_cast<llvm::Function>(fn);
if (!def) return nullptr;
if (!def->empty()) return nullptr;
Expand All @@ -3338,6 +3339,8 @@ static llvm::Function *shouldDefineHelper(IRGenModule &IGM,
def->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass);
def->setDoesNotThrow();
def->setCallingConv(IGM.DefaultCC);
if(setIsNoInline)
def->addFnAttr(llvm::Attribute::NoInline);
return def;
}

Expand All @@ -3352,13 +3355,14 @@ static llvm::Function *shouldDefineHelper(IRGenModule &IGM,
llvm::Constant *
IRGenModule::getOrCreateHelperFunction(StringRef fnName, llvm::Type *resultTy,
ArrayRef<llvm::Type*> paramTys,
llvm::function_ref<void(IRGenFunction &IGF)> generate) {
llvm::function_ref<void(IRGenFunction &IGF)> generate,
bool setIsNoInline) {
llvm::FunctionType *fnTy =
llvm::FunctionType::get(resultTy, paramTys, false);

llvm::Constant *fn = Module.getOrInsertFunction(fnName, fnTy);

if (llvm::Function *def = shouldDefineHelper(*this, fn)) {
if (llvm::Function *def = shouldDefineHelper(*this, fn, setIsNoInline)) {
IRGenFunction IGF(*this, def);
if (DebugInfo)
DebugInfo->emitArtificialFunction(IGF, def);
Expand Down
Loading