Skip to content
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
3 changes: 3 additions & 0 deletions cmake/modules/AddSwiftUnittests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ function(add_swift_unittest test_dirname)
endif()
endif()

is_build_type_with_debuginfo("${CMAKE_BUILD_TYPE}" HAS_DEBUG_INFO)
target_compile_options("${test_dirname}" PRIVATE $<$<BOOL:${HAS_DEBUG_INFO}>:-g>)

file(RELATIVE_PATH relative_lib_path "${CMAKE_CURRENT_BINARY_DIR}" "${SWIFT_LIBRARY_OUTPUT_INTDIR}")

if(SWIFT_HOST_VARIANT_SDK IN_LIST SWIFT_DARWIN_PLATFORMS)
Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/ActorIsolation.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ class ActorIsolation {

static ActorIsolation forActorInstanceSelf(ValueDecl *decl);

/// Create an ActorIsolation appropriate for a type that is self.
static ActorIsolation forActorInstanceSelf(NominalTypeDecl *decl);

static ActorIsolation forActorInstanceParameter(NominalTypeDecl *actor,
unsigned parameterIndex) {
return ActorIsolation(ActorInstance, actor, parameterIndex + 1);
Expand Down
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ ERROR(bridging_objcbridgeable_broken,none,
ERROR(sil_function_redefinition,none,
"multiple definitions of symbol '%0'",
(StringRef))
NOTE(sil_function_redefinition_note,none,
"other definition here",
())

ERROR(invalid_sil_builtin,none,
"INTERNAL ERROR: invalid use of builtin: %0",
Expand Down
5 changes: 5 additions & 0 deletions include/swift/Option/FrontendOptions.td
Original file line number Diff line number Diff line change
Expand Up @@ -1332,4 +1332,9 @@ def disable_experimental_parser_round_trip : Flag<["-"],
"disable-experimental-parser-round-trip">,
HelpText<"Disable round trip through the new swift parser">;

def disable_strict_concurrency_region_based_isolation : Flag<["-"],
"disable-region-based-isolation-with-strict-concurrency">,
HelpText<"Disable region based isolation when running with strict concurrency enabled. Only enabled with asserts">,
Flags<[HelpHidden]>;

} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]
6 changes: 2 additions & 4 deletions include/swift/SIL/SILFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ class SILFunction
unsigned BlockListChangeIdx = 0;

/// The isolation of this function.
std::optional<ActorIsolation> actorIsolation;
ActorIsolation actorIsolation = ActorIsolation::forUnspecified();

/// The function's bare attribute. Bare means that the function is SIL-only
/// and does not require debug info.
Expand Down Expand Up @@ -1374,9 +1374,7 @@ class SILFunction
actorIsolation = newActorIsolation;
}

std::optional<ActorIsolation> getActorIsolation() const {
return actorIsolation;
}
ActorIsolation getActorIsolation() const { return actorIsolation; }

//===--------------------------------------------------------------------===//
// Block List Access
Expand Down
2 changes: 1 addition & 1 deletion include/swift/SILOptimizer/Analysis/RegionAnalysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ class regionanalysisimpl::TrackableValueState {
}

ActorIsolation getActorIsolation() const {
return regionInfo.getActorIsolation().value();
return regionInfo.getActorIsolation();
}

void mergeIsolationRegionInfo(SILIsolationInfo newRegionInfo) {
Expand Down
66 changes: 24 additions & 42 deletions include/swift/SILOptimizer/Utils/PartitionUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,20 +110,19 @@ class SILIsolationInfo {
// clang-format off
std::variant<
// Used for actor isolated when we have ActorIsolation info from the AST.
std::optional<ActorIsolation>,
// Used for actor isolation when we infer the actor at the SIL level.
NominalTypeDecl *,
ActorIsolation,
// The task isolated parameter when we find a task isolated value.
SILValue
> data;
// clang-format on

SILIsolationInfo(Kind kind, std::optional<ActorIsolation> actorIsolation)
: kind(kind), data(actorIsolation) {}
SILIsolationInfo(Kind kind, NominalTypeDecl *decl) : kind(kind), data(decl) {}
SILIsolationInfo(ActorIsolation actorIsolation)
: kind(Actor), data(actorIsolation) {}

SILIsolationInfo(Kind kind, SILValue value) : kind(kind), data(value) {}

SILIsolationInfo(Kind kind) : kind(kind), data() {}

public:
SILIsolationInfo() : kind(Kind::Unknown), data() {}

Expand All @@ -146,18 +145,11 @@ class SILIsolationInfo {

void printForDiagnostics(llvm::raw_ostream &os) const;

std::optional<ActorIsolation> getActorIsolation() const {
ActorIsolation getActorIsolation() const {
assert(kind == Actor);
assert(std::holds_alternative<std::optional<ActorIsolation>>(data) &&
assert(std::holds_alternative<ActorIsolation>(data) &&
"Doesn't have an actor isolation?!");
return std::get<std::optional<ActorIsolation>>(data);
}

NominalTypeDecl *getActorInstance() const {
assert(kind == Actor);
assert(std::holds_alternative<NominalTypeDecl *>(data) &&
"Doesn't have an actor instance?!");
return std::get<NominalTypeDecl *>(data);
return std::get<ActorIsolation>(data);
}

SILValue getTaskIsolatedValue() const {
Expand All @@ -167,45 +159,35 @@ class SILIsolationInfo {
return std::get<SILValue>(data);
}

bool hasActorIsolation() const {
return kind == Actor &&
std::holds_alternative<std::optional<ActorIsolation>>(data);
}

bool hasActorInstance() const {
return kind == Actor && std::holds_alternative<NominalTypeDecl *>(data);
}
bool hasActorIsolation() const { return kind == Actor; }

bool hasTaskIsolatedValue() const {
return kind == Task && std::holds_alternative<SILValue>(data);
}

/// If we actually have an actor decl, return that. Otherwise, see if we have
/// an actor isolation if we can find one in there. Returns nullptr if we
/// fail.
NominalTypeDecl *tryInferActorDecl() const;

[[nodiscard]] SILIsolationInfo merge(SILIsolationInfo other) const;

SILIsolationInfo withActorIsolated(ActorIsolation isolation) {
return SILIsolationInfo::getActorIsolated(isolation);
}

static SILIsolationInfo getDisconnected() { return {Kind::Disconnected, {}}; }
static SILIsolationInfo getDisconnected() { return {Kind::Disconnected}; }

static SILIsolationInfo getActorIsolated(ActorIsolation actorIsolation) {
return {Kind::Actor, actorIsolation};
return {actorIsolation};
}

/// Sometimes we may have something that is actor isolated or that comes from
/// a type. First try getActorIsolation and otherwise, just use the type.
static SILIsolationInfo getActorIsolated(NominalTypeDecl *nomDecl) {
auto actorIsolation = swift::getActorIsolation(nomDecl);
if (actorIsolation.isActorIsolated())
return getActorIsolated(actorIsolation);
if (nomDecl->isActor())
return {Kind::Actor, nomDecl};
return SILIsolationInfo();
static SILIsolationInfo getActorIsolated(NominalTypeDecl *typeDecl) {
if (typeDecl->isActor())
return {ActorIsolation::forActorInstanceSelf(typeDecl)};
auto isolation = swift::getActorIsolation(typeDecl);
if (isolation.isGlobalActor())
return {isolation};
return {};
}

static SILIsolationInfo getGlobalActorIsolated(Type globalActorType) {
return getActorIsolated(ActorIsolation::forGlobalActor(globalActorType));
}

static SILIsolationInfo getTaskIsolated(SILValue value) {
Expand Down Expand Up @@ -901,8 +883,8 @@ struct PartitionOpEvaluator {
// our transferring operand. If so, we can squelch this.
if (auto functionIsolation =
transferringOp->getUser()->getFunction()->getActorIsolation()) {
if (functionIsolation->isActorIsolated() &&
SILIsolationInfo::getActorIsolated(*functionIsolation) ==
if (functionIsolation.isActorIsolated() &&
SILIsolationInfo::getActorIsolated(functionIsolation) ==
SILIsolationInfo::get(transferringOp->getUser()))
return;
}
Expand Down
4 changes: 4 additions & 0 deletions lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11387,6 +11387,10 @@ ActorIsolation::forActorInstanceSelf(ValueDecl *decl) {
return ActorIsolation(ActorInstance, dc->getSelfNominalTypeDecl(), 0);
}

ActorIsolation ActorIsolation::forActorInstanceSelf(NominalTypeDecl *selfDecl) {
return ActorIsolation(ActorInstance, selfDecl, 0);
}

NominalTypeDecl *ActorIsolation::getActor() const {
assert(getKind() == ActorInstance ||
getKind() == GlobalActor);
Expand Down
12 changes: 11 additions & 1 deletion lib/DriverTool/sil_opt_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -534,6 +534,11 @@ struct SILOptOptions {
llvm::cl::list<std::string> ClangXCC = llvm::cl::list<std::string>(
"Xcc",
llvm::cl::desc("option to pass to clang"));

llvm::cl::opt<bool> DisableRegionBasedIsolationWithStrictConcurrency =
llvm::cl::opt<bool>(
"disable-region-based-isolation-with-strict-concurrency",
llvm::cl::init(false));
};

/// Regular expression corresponding to the value given in one of the
Expand Down Expand Up @@ -698,9 +703,14 @@ int sil_opt_main(ArrayRef<const char *> argv, void *MainAddr) {

Invocation.getLangOptions().UnavailableDeclOptimizationMode =
options.UnavailableDeclOptimization;
if (options.StrictConcurrencyLevel.hasArgStr())
if (options.StrictConcurrencyLevel.hasArgStr()) {
Invocation.getLangOptions().StrictConcurrencyLevel =
options.StrictConcurrencyLevel;
if (options.StrictConcurrencyLevel == StrictConcurrency::Complete &&
!options.DisableRegionBasedIsolationWithStrictConcurrency) {
Invocation.getLangOptions().enableFeature(Feature::RegionBasedIsolation);
}
}

Invocation.getDiagnosticOptions().VerifyMode =
options.VerifyMode ? DiagnosticOptions::Verify : DiagnosticOptions::NoVerify;
Expand Down
10 changes: 10 additions & 0 deletions lib/Frontend/CompilerInvocation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,16 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
if (Opts.StrictConcurrencyLevel == StrictConcurrency::Complete) {
Opts.enableFeature(Feature::IsolatedDefaultValues);
Opts.enableFeature(Feature::GlobalConcurrency);

// If asserts are enabled, allow for region based isolation to be disabled
// with a flag. This is intended only to be used with tests.
bool enableRegionIsolation = true;
#ifndef NDEBUG
enableRegionIsolation =
!Args.hasArg(OPT_disable_strict_concurrency_region_based_isolation);
#endif
if (enableRegionIsolation)
Opts.enableFeature(Feature::RegionBasedIsolation);
}

Opts.WarnImplicitOverrides =
Expand Down
18 changes: 15 additions & 3 deletions lib/SILGen/SILGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,13 @@ SILFunction *SILGenModule::getFunction(SILDeclRef constant,
return IGM.getFunction(constant, NotForDefinition);
});

// If we have global actor isolation for our constant, put the isolation onto
// the function.
if (auto isolation =
getActorIsolationOfContext(constant.getInnermostDeclContext())) {
F->setActorIsolation(isolation);
}

assert(F && "SILFunction should have been defined");

emittedFunctions[constant] = F;
Expand Down Expand Up @@ -806,6 +813,8 @@ void SILGenModule::emitFunctionDefinition(SILDeclRef constant, SILFunction *f) {
if (!f->empty()) {
diagnose(constant.getAsRegularLocation(), diag::sil_function_redefinition,
f->getName());
if (f->hasLocation())
diagnose(f->getLocation(), diag::sil_function_redefinition_note);
return;
}

Expand Down Expand Up @@ -1217,9 +1226,12 @@ void SILGenModule::preEmitFunction(SILDeclRef constant, SILFunction *F,
if (F->getLoweredFunctionType()->isPolymorphic())
F->setGenericEnvironment(Types.getConstantGenericEnvironment(constant));

// Set the actor isolation of the function to its innermost decl context.
F->setActorIsolation(
getActorIsolationOfContext(constant.getInnermostDeclContext()));
// If we have global actor isolation for our constant, put the isolation onto
// the function.
if (auto isolation =
getActorIsolationOfContext(constant.getInnermostDeclContext())) {
F->setActorIsolation(isolation);
}

// Create a debug scope for the function using astNode as source location.
F->setDebugScope(new (M) SILDebugScope(Loc, F));
Expand Down
Loading