Skip to content

Commit a77d119

Browse files
authored
Merge pull request #71261 from xedin/introduce-thunks-for-runtime-check-func-refs
[Sema/SILGen] DynamicActorIsolation: Implement dynamic actor isolation checks for unsafe APIs
2 parents b12370a + 53b2d86 commit a77d119

30 files changed

+494
-72
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,10 @@ class ValueDecl : public Decl {
27342734
}
27352735

27362736
public:
2737+
/// Find the import that makes the given declaration available.
2738+
llvm::Optional<AttributedImport<ImportedModule>>
2739+
findImport(const DeclContext *fromDC);
2740+
27372741
/// Return true if this protocol member is a protocol requirement.
27382742
///
27392743
/// Asserts if this is not a member of a protocol.

include/swift/AST/DiagnosticsSema.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5642,7 +5642,7 @@ ERROR(preconcurrency_not_inheritance_clause,none,
56425642
ERROR(preconcurrency_not_existential,none,
56435643
"'preconcurrency' attribute cannot apply to non-protocol type %0", (Type))
56445644
ERROR(preconcurrency_attr_disabled,none,
5645-
"attribute requires '-enable-experimental-feature PreconcurrencyConformances'", ())
5645+
"attribute requires '-enable-experimental-feature DynamicActorIsolation'", ())
56465646

56475647
ERROR(redundant_any_in_existential,none,
56485648
"redundant 'any' in type %0",

include/swift/AST/Expr.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3519,6 +3519,19 @@ class BridgeToObjCExpr : public ImplicitConversionExpr {
35193519
}
35203520
};
35213521

3522+
/// ActorIsolationErasureExpr - A special kind of function conversion that
3523+
/// drops actor isolation.
3524+
class ActorIsolationErasureExpr : public ImplicitConversionExpr {
3525+
public:
3526+
ActorIsolationErasureExpr(Expr *subExpr, Type type)
3527+
: ImplicitConversionExpr(ExprKind::ActorIsolationErasure, subExpr, type) {
3528+
}
3529+
3530+
static bool classof(const Expr *E) {
3531+
return E->getKind() == ExprKind::ActorIsolationErasure;
3532+
}
3533+
};
3534+
35223535
/// UnresolvedSpecializeExpr - Represents an explicit specialization using
35233536
/// a type parameter list (e.g. "Vector<Int>") that has not been resolved.
35243537
class UnresolvedSpecializeExpr final : public Expr,

include/swift/AST/ExprNodes.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ ABSTRACT_EXPR(ImplicitConversion, Expr)
189189
EXPR(DifferentiableFunctionExtractOriginal, ImplicitConversionExpr)
190190
EXPR(LinearFunctionExtractOriginal, ImplicitConversionExpr)
191191
EXPR(LinearToDifferentiableFunction, ImplicitConversionExpr)
192-
EXPR_RANGE(ImplicitConversion, Load, LinearToDifferentiableFunction)
192+
EXPR(ActorIsolationErasure, ImplicitConversionExpr)
193+
EXPR_RANGE(ImplicitConversion, Load, ActorIsolationErasure)
193194
ABSTRACT_EXPR(ExplicitCast, Expr)
194195
ABSTRACT_EXPR(CheckedCast, ExplicitCastExpr)
195196
EXPR(ForcedCheckedCast, CheckedCastExpr)

include/swift/AST/FileUnit.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/RawComment.h"
1818
#include "swift/Basic/BasicSourceInfo.h"
1919
#include "swift/Basic/Debug.h"
20+
#include "swift/Basic/Version.h"
2021

2122
#include "llvm/ADT/PointerIntPair.h"
2223

@@ -417,6 +418,10 @@ class LoadedFile : public FileUnit {
417418
assert(classof(this) && "invalid kind");
418419
}
419420
public:
421+
/// Returns the language version that was used to compile the contents of this
422+
/// file. An empty `Version` is returned if the information is not available.
423+
virtual version::Version getLanguageVersionBuiltWith() const = 0;
424+
420425
/// Returns an arbitrary string representing the storage backing this file.
421426
///
422427
/// This is usually a filesystem path.

include/swift/AST/Module.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,6 +1147,10 @@ class ModuleDecl
11471147

11481148
SourceRange getSourceRange() const { return SourceRange(); }
11491149

1150+
/// Returns the language version that was used to compile this module.
1151+
/// An empty `Version` is returned if the information is not available.
1152+
version::Version getLanguageVersionBuiltWith() const;
1153+
11501154
static bool classof(const DeclContext *DC) {
11511155
if (auto D = DC->getAsDecl())
11521156
return classof(D);

include/swift/Basic/Features.def

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,8 +268,10 @@ EXPERIMENTAL_FEATURE(GroupActorErrors, true)
268268
// Allow for the 'transferring' keyword to be applied to arguments and results.
269269
EXPERIMENTAL_FEATURE(TransferringArgsAndResults, true)
270270

271-
// Enable `@preconcurrency` attribute on protocol conformances.
272-
EXPERIMENTAL_FEATURE(PreconcurrencyConformances, false)
271+
// Enable `@preconcurrency` attribute on protocol conformances and runtime checks
272+
// of actor isolation in @obj thunks and arguments of APIs that haven't yet adopted
273+
// strict concurrency checking.
274+
EXPERIMENTAL_FEATURE(DynamicActorIsolation, false)
273275

274276
// Allow for `switch` of noncopyable values to be borrowing or consuming.
275277
EXPERIMENTAL_FEATURE(BorrowingSwitch, true)

include/swift/ClangImporter/ClangModule.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#define SWIFT_CLANGIMPORTER_CLANGMODULE_H
1818

1919
#include "swift/AST/FileUnit.h"
20+
#include "swift/Basic/Version.h"
2021
#include "swift/ClangImporter/ClangImporter.h"
2122
#include "clang/AST/ExternalASTSource.h"
2223
#include "clang/Basic/Module.h"
@@ -109,6 +110,10 @@ class ClangModuleUnit final : public LoadedFile {
109110
llvm_unreachable("no private decls in Clang modules");
110111
}
111112

113+
virtual version::Version getLanguageVersionBuiltWith() const override {
114+
return version::Version();
115+
}
116+
112117
virtual StringRef getFilename() const override;
113118

114119
virtual StringRef getLoadedFilename() const override;

include/swift/Serialization/SerializedModuleLoader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ class SerializedASTFile final : public LoadedFile {
400400

401401
/// Returns the language version that was used to compile the contents of this
402402
/// file.
403-
const version::Version &getLanguageVersionBuiltWith() const;
403+
virtual version::Version getLanguageVersionBuiltWith() const override;
404404

405405
virtual bool hadLoadError() const override;
406406

lib/AST/ASTDumper.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2695,6 +2695,13 @@ class PrintExpr : public ExprVisitor<PrintExpr, void, StringRef>,
26952695
printFoot();
26962696
}
26972697

2698+
void visitActorIsolationErasureExpr(ActorIsolationErasureExpr *E,
2699+
StringRef label) {
2700+
printCommon(E, "actor_isolation_erasure_expr", label);
2701+
printRec(E->getSubExpr());
2702+
printFoot();
2703+
}
2704+
26982705
void visitInOutExpr(InOutExpr *E, StringRef label) {
26992706
printCommon(E, "inout_expr", label);
27002707
printRec(E->getSubExpr());

0 commit comments

Comments
 (0)