Skip to content

Commit dc16a94

Browse files
Merge pull request #8005 from aschwaighofer/cow_existential_wip_04
Support for copy-on-write existentials - IRGen Support
2 parents e161c66 + 85b126d commit dc16a94

20 files changed

+1719
-24
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,10 @@ option(SWIFT_STDLIB_ENABLE_RESILIENCE
270270
"Build the standard libraries and overlays with resilience enabled; see docs/LibraryEvolution.rst"
271271
FALSE)
272272

273+
option(SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS
274+
"Build the runtime with a copy-on-write implementation for opaque existentials"
275+
FALSE)
276+
273277
option(SWIFT_STDLIB_USE_NONATOMIC_RC
274278
"Build the standard libraries and overlays with nonatomic reference count operations enabled"
275279
FALSE)

cmake/modules/SwiftSource.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,10 @@ function(_compile_swift_files
243243
list(APPEND swift_flags "-Xfrontend" "-assume-single-threaded")
244244
endif()
245245

246+
if(SWIFT_RUNTIME_ENABLE_COW_EXISTENTIALS)
247+
list(APPEND swift_flags "-Xfrontend" "-enable-cow-existentials")
248+
endif()
249+
246250
if(SWIFT_STDLIB_ENABLE_SIL_OWNERSHIP AND SWIFTFILE_IS_STDLIB)
247251
list(APPEND swift_flags "-Xfrontend" "-enable-sil-ownership")
248252
endif()

include/swift/AST/SILOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,9 @@ class SILOptions {
124124
/// Assume that code will be executed in a single-threaded environment.
125125
bool AssumeSingleThreaded = false;
126126

127+
/// Use the copy-on-write implementation for opaque existentials.
128+
unsigned UseCOWExistentials = false;
129+
127130
/// Indicates which sanitizer is turned on.
128131
SanitizerKind Sanitize : 2;
129132

include/swift/Option/FrontendOptions.td

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ def enable_experimental_property_behaviors :
260260
Flag<["-"], "enable-experimental-property-behaviors">,
261261
HelpText<"Enable experimental property behaviors">;
262262

263+
def enable_cow_existentials : Flag<["-"], "enable-cow-existentials">,
264+
HelpText<"Enable the copy-on-write existential implementation">;
265+
263266
def disable_availability_checking : Flag<["-"],
264267
"disable-availability-checking">,
265268
HelpText<"Disable checking for potentially unavailable APIs">;

include/swift/SIL/SILInstruction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5736,6 +5736,10 @@ class ApplySite {
57365736

57375737
#undef FOREACH_IMPL_RETURN
57385738

5739+
SILArgumentConvention getArgumentConvention(unsigned index) const {
5740+
return getSubstCalleeConv().getSILArgumentConvention(index);
5741+
}
5742+
57395743
static ApplySite getFromOpaqueValue(void *p) {
57405744
return ApplySite(p);
57415745
}
@@ -5786,10 +5790,6 @@ class FullApplySite : public ApplySite {
57865790
return getArguments().slice(getNumIndirectSILResults());
57875791
}
57885792

5789-
SILArgumentConvention getArgumentConvention(unsigned index) const {
5790-
return getSubstCalleeConv().getSILArgumentConvention(index);
5791-
}
5792-
57935793
static FullApplySite getFromOpaqueValue(void *p) {
57945794
return FullApplySite(p);
57955795
}

lib/Frontend/CompilerInvocation.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,10 @@ static bool ParseSILArgs(SILOptions &Opts, ArgList &Args,
12371237
IRGenOpts.Sanitize = Opts.Sanitize;
12381238
}
12391239

1240+
/// Should we use the copy-on-write implementation of opaque existentials.
1241+
/// FIXME: Use during bootstraping this feature. Remove later.
1242+
Opts.UseCOWExistentials = Args.hasArg(OPT_enable_cow_existentials);
1243+
12401244
return false;
12411245
}
12421246

lib/IRGen/GenDecl.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3328,7 +3328,8 @@ IRGenModule::getAddrOfAssociatedTypeWitnessTableAccessFunction(
33283328

33293329
/// Should we be defining the given helper function?
33303330
static llvm::Function *shouldDefineHelper(IRGenModule &IGM,
3331-
llvm::Constant *fn) {
3331+
llvm::Constant *fn,
3332+
bool setIsNoInline) {
33323333
llvm::Function *def = dyn_cast<llvm::Function>(fn);
33333334
if (!def) return nullptr;
33343335
if (!def->empty()) return nullptr;
@@ -3338,6 +3339,8 @@ static llvm::Function *shouldDefineHelper(IRGenModule &IGM,
33383339
def->setDLLStorageClass(llvm::GlobalVariable::DefaultStorageClass);
33393340
def->setDoesNotThrow();
33403341
def->setCallingConv(IGM.DefaultCC);
3342+
if(setIsNoInline)
3343+
def->addFnAttr(llvm::Attribute::NoInline);
33413344
return def;
33423345
}
33433346

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

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

3361-
if (llvm::Function *def = shouldDefineHelper(*this, fn)) {
3365+
if (llvm::Function *def = shouldDefineHelper(*this, fn, setIsNoInline)) {
33623366
IRGenFunction IGF(*this, def);
33633367
if (DebugInfo)
33643368
DebugInfo->emitArtificialFunction(IGF, def);

0 commit comments

Comments
 (0)