Skip to content

Commit 94e856e

Browse files
Merge pull request #4655 from swiftwasm/main
[pull] swiftwasm from main
2 parents 417c643 + 0c67ce6 commit 94e856e

File tree

111 files changed

+4198
-2925
lines changed

Some content is hidden

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

111 files changed

+4198
-2925
lines changed

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 |

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/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: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -880,10 +880,6 @@ class ASTContext final {
880880
/// for extended existential types.
881881
AvailabilityContext getParameterizedExistentialRuntimeAvailability();
882882

883-
/// Get the runtime availability of immortal ref-count symbols, which are
884-
/// needed to place array buffers into constant data sections.
885-
AvailabilityContext getImmortalRefCountSymbolsAvailability();
886-
887883
/// Get the runtime availability of features introduced in the Swift 5.2
888884
/// compiler for the target platform.
889885
AvailabilityContext getSwift52Availability();

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: 12 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;
@@ -6410,6 +6414,9 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
64106414
/// A function is concurrent if it has the @Sendable attribute.
64116415
bool isSendable() const;
64126416

6417+
/// Determine if function has 'nonisolated' attribute
6418+
bool isNonisolated() const;
6419+
64136420
/// Returns true if the function is a suitable 'async' context.
64146421
///
64156422
/// Functions that are an 'async' context can make calls to 'async' functions.
@@ -6429,6 +6436,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
64296436
/// Returns 'true' if the function is distributed.
64306437
bool isDistributed() const;
64316438

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

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

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

include/swift/AST/DiagnosticsSema.def

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4604,6 +4604,9 @@ ERROR(distributed_actor_isolated_method,none,
46044604
ERROR(distributed_local_cannot_be_used,none,
46054605
"'local' cannot be used in user-defined code currently",
46064606
())
4607+
ERROR(distributed_thunk_cannot_be_used,none,
4608+
"'distributed_thunk' cannot be used in user-defined code",
4609+
())
46074610
ERROR(distributed_actor_func_param_not_codable,none,
46084611
"parameter '%0' of type %1 in %2 does not conform to serialization requirement '%3'",
46094612
(StringRef, Type, DescriptiveDeclKind, StringRef))
@@ -4801,6 +4804,9 @@ ERROR(distributed_property_cannot_be_static,none,
48014804
ERROR(distributed_property_can_only_be_computed,none,
48024805
"%0 %1 cannot be 'distributed', only computed properties can",
48034806
(DescriptiveDeclKind, DeclName))
4807+
ERROR(distributed_property_accessor_only_get_can_be_distributed,none,
4808+
"only 'get' accessors may be 'distributed'",
4809+
())
48044810
NOTE(distributed_actor_isolated_property,none,
48054811
"access to %0 %1 is only permitted within distributed actor %2",
48064812
(DescriptiveDeclKind, DeclName, DeclName))
@@ -6179,6 +6185,10 @@ ERROR(result_builder_requires_explicit_var_initialization,none,
61796185
ERROR(cannot_declare_computed_var_in_result_builder,none,
61806186
"cannot declare local %select{lazy|wrapped|computed|observed}0 variable "
61816187
"in result builder", (unsigned))
6188+
ERROR(cannot_convert_result_builder_result_to_return_type,none,
6189+
"cannot convert result builder result type %0 to return type %1",
6190+
(Type,Type))
6191+
61826192

61836193
//------------------------------------------------------------------------------
61846194
// MARK: Tuple Shuffle Diagnostics

include/swift/AST/Expr.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ class alignas(8) Expr : public ASTAllocated<Expr> {
319319
ImplicitlyAsync : 1,
320320
ImplicitlyThrows : 1,
321321
NoAsync : 1,
322-
ShouldApplyDistributedThunk : 1
322+
UsesDistributedThunk : 1
323323
);
324324

325325
SWIFT_INLINE_BITFIELD_EMPTY(CallExpr, ApplyExpr);
@@ -4445,7 +4445,7 @@ class ApplyExpr : public Expr {
44454445
Bits.ApplyExpr.ImplicitlyAsync = false;
44464446
Bits.ApplyExpr.ImplicitlyThrows = false;
44474447
Bits.ApplyExpr.NoAsync = false;
4448-
Bits.ApplyExpr.ShouldApplyDistributedThunk = false;
4448+
Bits.ApplyExpr.UsesDistributedThunk = false;
44494449
}
44504450

44514451
public:
@@ -4532,11 +4532,11 @@ class ApplyExpr : public Expr {
45324532

45334533
/// Informs IRGen to that this expression should be applied as its distributed
45344534
/// thunk, rather than invoking the function directly.
4535-
bool shouldApplyDistributedThunk() const {
4536-
return Bits.ApplyExpr.ShouldApplyDistributedThunk;
4535+
bool usesDistributedThunk() const {
4536+
return Bits.ApplyExpr.UsesDistributedThunk;
45374537
}
4538-
void setShouldApplyDistributedThunk(bool flag) {
4539-
Bits.ApplyExpr.ShouldApplyDistributedThunk = flag;
4538+
void setUsesDistributedThunk(bool flag) {
4539+
Bits.ApplyExpr.UsesDistributedThunk = flag;
45404540
}
45414541

45424542
ValueDecl *getCalledValue() const;

0 commit comments

Comments
 (0)