Skip to content

Commit 13a9b90

Browse files
authored
Merge branch 'main' into address-only-operators
2 parents 52d55de + 8b20c88 commit 13a9b90

File tree

201 files changed

+6937
-3068
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

201 files changed

+6937
-3068
lines changed

SwiftCompilerSources/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ function(add_swift_compiler_modules_library name)
7575

7676
set(swift_compile_options
7777
"-Xfrontend" "-validate-tbd-against-ir=none"
78-
"-Xfrontend" "-enable-cxx-interop"
78+
"-Xfrontend" "-enable-experimental-cxx-interop"
7979
"-Xcc" "-UIBOutlet" "-Xcc" "-UIBAction" "-Xcc" "-UIBInspectable")
8080
if (NOT BOOTSTRAPPING_MODE STREQUAL "HOSTTOOLS")
8181
list(APPEND swift_compile_options "-Xfrontend" "-disable-implicit-string-processing-module-import")

SwiftCompilerSources/Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ private extension Target {
1717
static let defaultSwiftSettings: [SwiftSetting] = [
1818
.unsafeFlags([
1919
"-Xfrontend", "-validate-tbd-against-ir=none",
20-
"-Xfrontend", "-enable-cxx-interop",
20+
"-Xfrontend", "-enable-experimental-cxx-interop",
2121
// Bridging modules and headers
2222
"-Xcc", "-I", "-Xcc", "../include",
2323
"-cross-module-optimization"

SwiftCompilerSources/Sources/SIL/BasicBlock.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ final public class BasicBlock : ListNode, CustomStringConvertible, HasShortDescr
2525
public var function: Function { SILBasicBlock_getFunction(bridged).function }
2626

2727
public var description: String {
28-
String(_cxxString: SILBasicBlock_debugDescription(bridged))
28+
let stdString = SILBasicBlock_debugDescription(bridged)
29+
return String(_cxxString: stdString)
2930
}
3031
public var shortDescription: String { name }
3132

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ final public class Function : CustomStringConvertible, HasShortDescription {
2121
}
2222

2323
final public var description: String {
24-
String(_cxxString: SILFunction_debugDescription(bridged))
24+
let stdString = SILFunction_debugDescription(bridged)
25+
return String(_cxxString: stdString)
2526
}
2627

2728
public var shortDescription: String { name.string }

SwiftCompilerSources/Sources/SIL/GlobalVariable.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ final public class GlobalVariable : CustomStringConvertible, HasShortDescription
1919
}
2020

2121
public var description: String {
22-
String(_cxxString: SILGlobalVariable_debugDescription(bridged))
22+
let stdString = SILGlobalVariable_debugDescription(bridged)
23+
return String(_cxxString: stdString)
2324
}
2425

2526
public var shortDescription: String { name.string }

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public class Instruction : ListNode, CustomStringConvertible, Hashable {
3838
final public var function: Function { block.function }
3939

4040
final public var description: String {
41-
String(_cxxString: SILNode_debugDescription(bridgedNode))
41+
let stdString = SILNode_debugDescription(bridgedNode)
42+
return String(_cxxString: stdString)
4243
}
4344

4445
final public var operands: OperandArray {
@@ -142,7 +143,8 @@ public class SingleValueInstruction : Instruction, Value {
142143

143144
public final class MultipleValueInstructionResult : Value {
144145
final public var description: String {
145-
String(_cxxString: SILNode_debugDescription(bridgedNode))
146+
let stdString = SILNode_debugDescription(bridgedNode)
147+
return String(_cxxString: stdString)
146148
}
147149

148150
public var instruction: Instruction {

SwiftCompilerSources/Sources/SIL/Value.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ public enum Ownership {
8181

8282
extension Value {
8383
public var description: String {
84-
String(_cxxString: SILNode_debugDescription(bridgedNode))
84+
let stdString = SILNode_debugDescription(bridgedNode)
85+
return String(_cxxString: stdString)
8586
}
8687

8788
public var uses: UseList {

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,7 @@ Entities
349349
entity-spec ::= 'fE' // ivar destroyer; untyped
350350
entity-spec ::= 'fe' // ivar initializer; untyped
351351
entity-spec ::= 'Tv' NATURAL // outlined global variable (from context function)
352+
entity-spec ::= 'Tv' NATURAL 'r' // outlined global read-only object
352353
entity-spec ::= 'Te' bridge-spec // outlined objective c method call
353354

354355
entity-spec ::= decl-name label-list function-signature generic-signature? 'F' // function

docs/CppInteroperability/CppInteroperabilityStatus.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,31 @@ This status table describes which of the following Swift language features have
140140
| **Swift Language Feature** | **Implemented Experimental Support For Using It In C++** |
141141
|--------------------------------|----------------------------------------------------------|
142142
| Top-level `@_cdecl` functions | Yes |
143-
| Top-level Swift functions | Partially, only with C compatible types |
144-
| `inout` parameters | No |
143+
| Top-level Swift functions | Partially, only with primitive and Swift struct types |
144+
| `inout` parameters | Yes |
145145
| Variadic parameters | No |
146146
| Multiple return values | No |
147+
148+
**Structs**
149+
150+
| **Swift Language Feature** | **Implemented Experimental Support For Using It In C++** |
151+
|--------------------------------|----------------------------------------------------------|
152+
| Fixed layout structs | Yes |
153+
| Resilient / opaque structs | Yes |
154+
| Copy and destroy semantics | Yes |
155+
| Initializers | Partially, as static `init` methods. No failable support |
156+
157+
**Methods**
158+
159+
| **Swift Language Feature** | **Implemented Experimental Support For Using It In C++** |
160+
|--------------------------------|----------------------------------------------------------|
161+
| Instance methods | Yes, for structs only |
162+
| Static methods | No |
163+
164+
**Properties**
165+
166+
| **Swift Language Feature** | **Implemented Experimental Support For Using It In C++** |
167+
|--------------------------------|----------------------------------------------------------|
168+
| Getter accessors | Yes, via `get<name>`. For structs only |
169+
| Setter accessors | No |
170+
| Mutation accessors | No |

docs/DevelopmentTips.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,25 @@ Copy the invocation that has ` -o <build-path>/swift-macosx-x86_64/stdlib/publi
2323
### Choosing the bootstrapping mode
2424
By default, the compiler builds with the `boostrapping-with-hostlibs` (macOS) or `bootstrapping` (Linux) bootstrapping mode. To speed up local development it's recommended to build with the `hosttools` mode: `utils/build-script --bootstrapping=hosttools`.
2525

26-
It requires a recently new swift toolchain to be installed on your build machine. On macOS this comes with your Xcode installation.
26+
It requires a recently new swift toolchain to be installed on your build machine. You might need to download and install a nightly Swift toolchain to build the Swift project in `hosttools` mode.
2727

2828
Not that changing the bootstrapping mode needs a reconfiguration.
2929

30+
#### Using a locally built Swift toolchain
31+
32+
If you do not want to install a nightly Swift toolchain, or you need to debug Swift code within SwiftCompilerSources, you can build the Swift toolchain in `boostrapping-with-hostlibs` mode on your local machine once, and then use this toolchain to iterate on your changes with the `hosttools` mode:
33+
34+
* Build the toolchain locally in `boostrapping-with-hostlibs` mode: `./utils/build-toolchain com.yourname`.
35+
* Copy the `swift-LOCAL-YYYY-MM-DD.xctoolchain` file from `./swift-nightly-install/Library/Developer/Toolchains` to `/Library/Developer/Toolchains`.
36+
* Launch Xcode, in the menu bar select _Xcode_ > _Toolchains_ > _Local Swift Development Snapshot YYYY-MM-DD_.
37+
* Remove the Swift build directory: `./build`.
38+
* Run the Swift build script with the locally built Swift toolchain in `hosttools` mode: `TOOLCHAINS=com.yourname.YYYYMMDD ./utils/build-script --bootstrapping=hosttools`. Repeat this step as you iterate on your change.
39+
40+
To debug using LLDB, run LLDB from the locally built toolchain with a couple of environment variables set:
41+
```
42+
DYLD_LIBRARY_PATH=/Library/Developer/Toolchains/swift-LOCAL-YYYY-MM-DD.xctoolchain/usr/lib/swift/macosx DYLD_FRAMEWORK_PATH=/Applications/Xcode.app/Contents/Developer/Library/Frameworks /Library/Developer/Toolchains/swift-LOCAL-YYYY-MM-DD.xctoolchain/usr/bin/lldb
43+
```
44+
3045
### Working with two build directories
3146
For developing and debugging you are probably building a debug configuration of swift. But it's often beneficial to also build a release-assert configuration in parallel (`utils/build-script -R`).
3247

docs/HowToGuides/GettingStarted.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,7 @@ In project settings, locate `Build, Execution, Deployment > CMake`. You will nee
376376
- `-D SWIFT_PATH_TO_CMARK_BUILD=SOME_PATH/swift-project/build/Ninja-RelWithDebInfoAssert/cmark-macosx-arm64 -D LLVM_DIR=SOME_PATH/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/lib/cmake/llvm -D Clang_DIR=SOME_PATH/swift-project/build/Ninja-RelWithDebInfoAssert/llvm-macosx-arm64/lib/cmake/clang -D CMAKE_BUILD_TYPE=RelWithDebInfoAssert -G Ninja -S .`
377377
- replace the `SOME_PATH` to the path where your `swift-project` directory is
378378
- the CMAKE_BUILD_TYPE should match the build configuration name, so if you named this profile `RelWithDebInfo` the CMAKE_BUILD_TYPE should also be `RelWithDebInfo`
379+
- **Note**: If you're using an intel machine to build swift, you'll need to replace the architecture in the options. (ex: `arm64` with `x86_64`)
379380
380381
With this done, CLion should be able to successfully import the project and have full autocomplete and code navigation powers.
381382

include/swift/ABI/Metadata.h

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ template <typename Runtime> struct TargetStructMetadata;
5555
template <typename Runtime> struct TargetOpaqueMetadata;
5656
template <typename Runtime> struct TargetValueMetadata;
5757
template <typename Runtime> struct TargetForeignClassMetadata;
58+
template <typename Runtime> struct TargetForeignReferenceTypeMetadata;
5859
template <typename Runtime> struct TargetContextDescriptor;
5960
template <typename Runtime> class TargetTypeContextDescriptor;
6061
template <typename Runtime> class TargetClassDescriptor;
@@ -258,6 +259,7 @@ struct TargetMetadata {
258259
case MetadataKind::Class:
259260
case MetadataKind::ObjCClassWrapper:
260261
case MetadataKind::ForeignClass:
262+
case MetadataKind::ForeignReferenceType:
261263
return true;
262264

263265
default:
@@ -375,6 +377,9 @@ struct TargetMetadata {
375377
case MetadataKind::ForeignClass:
376378
return static_cast<const TargetForeignClassMetadata<Runtime> *>(this)
377379
->Description;
380+
case MetadataKind::ForeignReferenceType:
381+
return static_cast<const TargetForeignReferenceTypeMetadata<Runtime> *>(this)
382+
->Description;
378383
default:
379384
return nullptr;
380385
}
@@ -1159,6 +1164,44 @@ struct TargetForeignClassMetadata : public TargetForeignTypeMetadata<Runtime> {
11591164
};
11601165
using ForeignClassMetadata = TargetForeignClassMetadata<InProcess>;
11611166

1167+
/// The structure of metadata objects for foreign reference types.
1168+
/// A foreign reference type is a non-Swift, non-Objective-C foreign type with
1169+
/// reference semantics. Foreign reference types are pointers/reference to
1170+
/// value types marked with the "import_as_ref" attribute.
1171+
///
1172+
/// Foreign reference types may have *custom* reference counting operations, or
1173+
/// they may be immortal (and therefore trivial).
1174+
///
1175+
/// We assume for now that foreign reference types are entirely opaque
1176+
/// to Swift introspection.
1177+
template <typename Runtime>
1178+
struct TargetForeignReferenceTypeMetadata : public TargetForeignTypeMetadata<Runtime> {
1179+
using StoredPointer = typename Runtime::StoredPointer;
1180+
1181+
/// An out-of-line description of the type.
1182+
TargetSignedPointer<Runtime, const TargetClassDescriptor<Runtime> * __ptrauth_swift_type_descriptor> Description;
1183+
1184+
/// Reserved space. For now, this should be zero-initialized.
1185+
/// If this is used for anything in the future, at least some of these
1186+
/// first bits should be flags.
1187+
StoredPointer Reserved[1];
1188+
1189+
ConstTargetMetadataPointer<Runtime, TargetClassDescriptor>
1190+
getDescription() const {
1191+
return Description;
1192+
}
1193+
1194+
typename Runtime::StoredSignedPointer
1195+
getDescriptionAsSignedPointer() const {
1196+
return Description;
1197+
}
1198+
1199+
static bool classof(const TargetMetadata<Runtime> *metadata) {
1200+
return metadata->getKind() == MetadataKind::ForeignReferenceType;
1201+
}
1202+
};
1203+
using ForeignReferenceTypeMetadata = TargetForeignReferenceTypeMetadata<InProcess>;
1204+
11621205
/// The common structure of metadata for structs and enums.
11631206
template <typename Runtime>
11641207
struct TargetValueMetadata : public TargetMetadata<Runtime> {

include/swift/ABI/MetadataKind.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ NOMINALTYPEMETADATAKIND(Optional, 2 | MetadataKindIsNonHeap)
5353
/// A foreign class, such as a Core Foundation class.
5454
METADATAKIND(ForeignClass, 3 | MetadataKindIsNonHeap)
5555

56+
/// A non-Swift non-Objective-C class type.
57+
METADATAKIND(ForeignReferenceType, 4 | MetadataKindIsNonHeap)
58+
5659
/// A type whose value is not exposed in the metadata system.
5760
METADATAKIND(Opaque, 0 | MetadataKindIsRuntimePrivate | MetadataKindIsNonHeap)
5861

include/swift/ABI/MetadataValues.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -899,6 +899,7 @@ class ExtendedExistentialTypeShapeFlags {
899899
SpecialKind getSpecialKind() const {
900900
return SpecialKind((Data & SpecialKindMask) >> SpecialKindShift);
901901
}
902+
bool isOpaque() const { return getSpecialKind() == SpecialKind::None; }
902903
bool isClassConstrained() const {
903904
return getSpecialKind() == SpecialKind::Class;
904905
}

include/swift/APIDigester/ModuleAnalyzerNodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ struct CheckerOptions {
157157
bool PrintModule;
158158
bool SwiftOnly;
159159
bool SkipOSCheck;
160+
bool SkipRemoveDeprecatedCheck;
160161
bool CompilerStyle;
161162
bool Migrator;
162163
StringRef LocationFilter;

include/swift/AST/ASTContext.h

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,11 +223,13 @@ class ASTContext final {
223223
ASTContext(const ASTContext&) = delete;
224224
void operator=(const ASTContext&) = delete;
225225

226-
ASTContext(LangOptions &langOpts, TypeCheckerOptions &typecheckOpts,
227-
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
228-
ClangImporterOptions &ClangImporterOpts,
229-
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
230-
SourceManager &SourceMgr, DiagnosticEngine &Diags);
226+
ASTContext(
227+
LangOptions &langOpts, TypeCheckerOptions &typecheckOpts,
228+
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
229+
ClangImporterOptions &ClangImporterOpts,
230+
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
231+
SourceManager &SourceMgr, DiagnosticEngine &Diags,
232+
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback = {});
231233

232234
public:
233235
// Members that should only be used by ASTContext.cpp.
@@ -238,11 +240,13 @@ class ASTContext final {
238240

239241
void operator delete(void *Data) throw();
240242

241-
static ASTContext *get(LangOptions &langOpts, TypeCheckerOptions &typecheckOpts,
242-
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
243-
ClangImporterOptions &ClangImporterOpts,
244-
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
245-
SourceManager &SourceMgr, DiagnosticEngine &Diags);
243+
static ASTContext *
244+
get(LangOptions &langOpts, TypeCheckerOptions &typecheckOpts,
245+
SILOptions &silOpts, SearchPathOptions &SearchPathOpts,
246+
ClangImporterOptions &ClangImporterOpts,
247+
symbolgraphgen::SymbolGraphOptions &SymbolGraphOpts,
248+
SourceManager &SourceMgr, DiagnosticEngine &Diags,
249+
std::function<bool(llvm::StringRef, bool)> PreModuleImportCallback = {});
246250
~ASTContext();
247251

248252
/// Optional table of counters to report, nullptr when not collecting.
@@ -374,6 +378,10 @@ class ASTContext final {
374378
llvm::BumpPtrAllocator &
375379
getAllocator(AllocationArena arena = AllocationArena::Permanent) const;
376380

381+
/// An optional generic callback function invoked prior to importing a module.
382+
mutable std::function<bool(llvm::StringRef ModuleName, bool IsOverlay)>
383+
PreModuleImportCallback;
384+
377385
public:
378386
/// Allocate - Allocate memory from the ASTContext bump pointer.
379387
void *Allocate(unsigned long bytes, unsigned alignment,
@@ -1107,6 +1115,9 @@ class ASTContext final {
11071115
/// If a module by this name has already been loaded, the existing module will
11081116
/// be returned.
11091117
///
1118+
/// \param ModulePath The module's \c ImportPath which describes
1119+
/// the name of the module being loaded, possibly including submodules.
1120+
11101121
/// \returns The requested module, or NULL if the module cannot be found.
11111122
ModuleDecl *getModule(ImportPath::Module ModulePath);
11121123

include/swift/AST/ASTMangler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ class ASTMangler : public Mangler {
197197
Type GlobalActorBound,
198198
ModuleDecl *Module);
199199

200-
std::string mangleDistributedThunk(const FuncDecl *thunk);
200+
std::string mangleDistributedThunk(const AbstractFunctionDecl *thunk);
201201

202202
/// Mangle a completion handler block implementation function, used for importing ObjC
203203
/// APIs as async.

include/swift/AST/Attr.def

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ SIMPLE_DECL_ATTR(_inheritActorContext, InheritActorContext,
664664
// 117 was 'spawn' and is now unused
665665

666666
CONTEXTUAL_SIMPLE_DECL_ATTR(distributed, DistributedActor,
667-
DeclModifier | OnClass | OnFunc | OnVar |
667+
DeclModifier | OnClass | OnFunc | OnAccessor | OnVar |
668668
ABIBreakingToAdd | ABIBreakingToRemove |
669669
APIBreakingToAdd | APIBreakingToRemove,
670670
118)
@@ -735,6 +735,12 @@ CONTEXTUAL_SIMPLE_DECL_ATTR(_local, KnownToBeLocal,
735735
APIBreakingToAdd | APIBreakingToRemove,
736736
130)
737737

738+
SIMPLE_DECL_ATTR(_distributed_thunk, DistributedThunk,
739+
OnFunc | UserInaccessible |
740+
ABIBreakingToAdd | ABIBreakingToRemove |
741+
APIBreakingToAdd | APIBreakingToRemove,
742+
131)
743+
738744
// If you're adding a new underscored attribute here, please document it in
739745
// docs/ReferenceGuides/UnderscoredAttributes.md.
740746

include/swift/AST/Decl.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5355,6 +5355,10 @@ class VarDecl : public AbstractStorageDecl {
53555355
/// Does this have a 'distributed' modifier?
53565356
bool isDistributed() const;
53575357

5358+
/// Return a distributed thunk if this computed property is marked as
5359+
/// 'distributed' and and nullptr otherwise.
5360+
FuncDecl *getDistributedThunk() const;
5361+
53585362
/// Is this var known to be a "local" distributed actor,
53595363
/// if so the implicit throwing ans some isolation checks can be skipped.
53605364
bool isKnownToBeLocal() const;
@@ -5744,6 +5748,10 @@ class ParamDecl : public VarDecl {
57445748
Bits.ParamDecl.defaultArgumentKind = static_cast<unsigned>(K);
57455749
}
57465750

5751+
void setDefaultArgumentKind(ArgumentAttrs K) {
5752+
setDefaultArgumentKind(K.argumentKind);
5753+
}
5754+
57475755
bool isNoImplicitCopy() const {
57485756
return getAttrs().hasAttribute<NoImplicitCopyAttr>();
57495757
}
@@ -6406,6 +6414,9 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
64066414
/// A function is concurrent if it has the @Sendable attribute.
64076415
bool isSendable() const;
64086416

6417+
/// Determine if function has 'nonisolated' attribute
6418+
bool isNonisolated() const;
6419+
64096420
/// Returns true if the function is a suitable 'async' context.
64106421
///
64116422
/// Functions that are an 'async' context can make calls to 'async' functions.
@@ -6425,6 +6436,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
64256436
/// Returns 'true' if the function is distributed.
64266437
bool isDistributed() const;
64276438

6439+
/// Is this a thunk function used to access a distributed method outside
6440+
/// of its actor isolation context?
6441+
bool isDistributedThunk() const;
6442+
64286443
/// For a 'distributed' target (func or computed property),
64296444
/// get the 'thunk' responsible for performing the 'remoteCall'.
64306445
///
@@ -6753,7 +6768,7 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
67536768
bool hasDynamicSelfResult() const;
67546769

67556770
/// The async function marked as the alternative to this function, if any.
6756-
AbstractFunctionDecl *getAsyncAlternative() const;
6771+
AbstractFunctionDecl *getAsyncAlternative(bool isKnownObjC = false) const;
67576772

67586773
/// If \p asyncAlternative is set, then compare its parameters to this
67596774
/// (presumed synchronous) function's parameters to find the index of the

0 commit comments

Comments
 (0)