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;

include/swift/AST/ModuleLoader.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ class ModuleLoader {
226226
virtual void loadExtensions(NominalTypeDecl *nominal,
227227
unsigned previousGeneration) { }
228228

229-
/// Load the methods within the given class that produce
229+
/// Load the methods within the given type that produce
230230
/// Objective-C class or instance methods with the given selector.
231231
///
232-
/// \param classDecl The class in which we are searching for @objc methods.
233-
/// The search only considers this class and its extensions; not any
232+
/// \param typeDecl The type in which we are searching for @objc methods.
233+
/// The search only considers this type and its extensions; not any
234234
/// superclasses.
235235
///
236236
/// \param selector The selector to search for.
@@ -246,7 +246,7 @@ class ModuleLoader {
246246
/// selector and are instance/class methods as requested. This list will be
247247
/// extended with any methods found in subsequent generations.
248248
virtual void loadObjCMethods(
249-
ClassDecl *classDecl,
249+
NominalTypeDecl *typeDecl,
250250
ObjCSelector selector,
251251
bool isInstanceMethod,
252252
unsigned previousGeneration,

include/swift/AST/SourceFile.h

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "swift/AST/Import.h"
1818
#include "swift/AST/SynthesizedFileUnit.h"
1919
#include "swift/Basic/Debug.h"
20+
#include "llvm/ADT/Hashing.h"
2021
#include "llvm/ADT/SetVector.h"
2122
#include "llvm/ADT/SmallPtrSet.h"
2223

@@ -243,11 +244,20 @@ class SourceFile final : public FileUnit {
243244
std::vector<ObjCUnsatisfiedOptReq> ObjCUnsatisfiedOptReqs;
244245

245246
/// A selector that is used by two different declarations in the same class.
246-
/// Fields: typeDecl, selector, isInstanceMethod.
247-
using ObjCMethodConflict = std::tuple<NominalTypeDecl *, ObjCSelector, bool>;
247+
struct ObjCMethodConflict {
248+
NominalTypeDecl *typeDecl;
249+
ObjCSelector selector;
250+
bool isInstanceMethod;
251+
252+
ObjCMethodConflict(NominalTypeDecl *typeDecl, ObjCSelector selector,
253+
bool isInstanceMethod)
254+
: typeDecl(typeDecl), selector(selector),
255+
isInstanceMethod(isInstanceMethod)
256+
{}
257+
};
248258

249259
/// List of Objective-C member conflicts we have found during type checking.
250-
std::vector<ObjCMethodConflict> ObjCMethodConflicts;
260+
llvm::SetVector<ObjCMethodConflict> ObjCMethodConflicts;
251261

252262
/// List of attributes added by access notes, used to emit remarks for valid
253263
/// ones.
@@ -636,4 +646,30 @@ inline void simple_display(llvm::raw_ostream &out, const SourceFile *SF) {
636646
}
637647
} // end namespace swift
638648

649+
namespace llvm {
650+
651+
template<>
652+
struct DenseMapInfo<swift::SourceFile::ObjCMethodConflict> {
653+
using ObjCMethodConflict = swift::SourceFile::ObjCMethodConflict;
654+
655+
static inline ObjCMethodConflict getEmptyKey() {
656+
return ObjCMethodConflict(nullptr, {}, false);
657+
}
658+
static inline ObjCMethodConflict getTombstoneKey() {
659+
return ObjCMethodConflict(nullptr, {}, true);
660+
}
661+
static inline unsigned getHashValue(ObjCMethodConflict a) {
662+
return hash_combine(hash_value(a.typeDecl),
663+
DenseMapInfo<swift::ObjCSelector>::getHashValue(a.selector),
664+
hash_value(a.isInstanceMethod));
665+
}
666+
static bool isEqual(ObjCMethodConflict a, ObjCMethodConflict b) {
667+
return a.typeDecl == b.typeDecl && a.selector == b.selector &&
668+
a.isInstanceMethod == b.isInstanceMethod;
669+
}
670+
};
671+
672+
}
673+
674+
639675
#endif

0 commit comments

Comments
 (0)