Skip to content

Commit b488702

Browse files
committed
Merge remote-tracking branch 'origin/main' into bump-swift-version-to-6
2 parents 96d61d3 + 11ef6e5 commit b488702

File tree

79 files changed

+1716
-902
lines changed

Some content is hidden

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

79 files changed

+1716
-902
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,22 @@
1414
// includes target-independent information which can be usefully shared
1515
// between them.
1616
//
17+
// This header ought not to include any compiler-specific headers (such as
18+
// those from `swift/AST`, `swift/SIL`, etc.) since doing so may introduce
19+
// accidental ABI dependencies on compiler internals.
20+
//
1721
//===----------------------------------------------------------------------===//
1822

1923
#ifndef SWIFT_ABI_METADATAVALUES_H
2024
#define SWIFT_ABI_METADATAVALUES_H
2125

2226
#include "swift/ABI/KeyPath.h"
2327
#include "swift/ABI/ProtocolDispatchStrategy.h"
28+
29+
// FIXME: this include shouldn't be here, but removing it causes symbol
30+
// mangling mismatches on Windows for some reason?
2431
#include "swift/AST/Ownership.h"
32+
2533
#include "swift/Basic/Debug.h"
2634
#include "swift/Basic/LLVM.h"
2735
#include "swift/Basic/FlagSet.h"
@@ -1187,6 +1195,9 @@ class TargetExtendedFunctionTypeFlags {
11871195

11881196
// Values for the enumerated isolation kinds
11891197
IsolatedAny = 0x00000002U,
1198+
1199+
// Values if we have a transferring result.
1200+
HasTransferringResult = 0x00000010U,
11901201
};
11911202
int_type Data;
11921203

@@ -1211,12 +1222,23 @@ class TargetExtendedFunctionTypeFlags {
12111222
(Data & ~IsolationMask) | IsolatedAny);
12121223
}
12131224

1225+
const TargetExtendedFunctionTypeFlags<int_type>
1226+
withTransferringResult(bool newValue = true) const {
1227+
return TargetExtendedFunctionTypeFlags<int_type>(
1228+
(Data & ~HasTransferringResult) |
1229+
(newValue ? HasTransferringResult : 0));
1230+
}
1231+
12141232
bool isTypedThrows() const { return bool(Data & TypedThrowsMask); }
12151233

12161234
bool isIsolatedAny() const {
12171235
return (Data & IsolationMask) == IsolatedAny;
12181236
}
12191237

1238+
bool hasTransferringResult() const {
1239+
return bool(Data & HasTransferringResult);
1240+
}
1241+
12201242
int_type getIntValue() const {
12211243
return Data;
12221244
}
@@ -1234,14 +1256,30 @@ class TargetExtendedFunctionTypeFlags {
12341256
};
12351257
using ExtendedFunctionTypeFlags = TargetExtendedFunctionTypeFlags<uint32_t>;
12361258

1259+
/// Different kinds of value ownership supported by function types.
1260+
enum class ParameterOwnership : uint8_t {
1261+
/// the context-dependent default ownership (sometimes shared,
1262+
/// sometimes owned)
1263+
Default,
1264+
/// an 'inout' exclusive, mutating borrow
1265+
InOut,
1266+
/// a 'borrowing' nonexclusive, usually nonmutating borrow
1267+
Shared,
1268+
/// a 'consuming' ownership transfer
1269+
Owned,
1270+
1271+
Last_Kind = Owned
1272+
};
1273+
12371274
template <typename int_type>
12381275
class TargetParameterTypeFlags {
12391276
enum : int_type {
1240-
ValueOwnershipMask = 0x7F,
1277+
OwnershipMask = 0x7F,
12411278
VariadicMask = 0x80,
12421279
AutoClosureMask = 0x100,
12431280
NoDerivativeMask = 0x200,
12441281
IsolatedMask = 0x400,
1282+
TransferringMask = 0x800,
12451283
};
12461284
int_type Data;
12471285

@@ -1251,8 +1289,8 @@ class TargetParameterTypeFlags {
12511289
constexpr TargetParameterTypeFlags() : Data(0) {}
12521290

12531291
constexpr TargetParameterTypeFlags<int_type>
1254-
withValueOwnership(ValueOwnership ownership) const {
1255-
return TargetParameterTypeFlags<int_type>((Data & ~ValueOwnershipMask) |
1292+
withOwnership(ParameterOwnership ownership) const {
1293+
return TargetParameterTypeFlags<int_type>((Data & ~OwnershipMask) |
12561294
(int_type)ownership);
12571295
}
12581296

@@ -1280,14 +1318,21 @@ class TargetParameterTypeFlags {
12801318
(Data & ~IsolatedMask) | (isIsolated ? IsolatedMask : 0));
12811319
}
12821320

1321+
constexpr TargetParameterTypeFlags<int_type>
1322+
withTransferring(bool isTransferring) const {
1323+
return TargetParameterTypeFlags<int_type>(
1324+
(Data & ~TransferringMask) | (isTransferring ? TransferringMask : 0));
1325+
}
1326+
12831327
bool isNone() const { return Data == 0; }
12841328
bool isVariadic() const { return Data & VariadicMask; }
12851329
bool isAutoClosure() const { return Data & AutoClosureMask; }
12861330
bool isNoDerivative() const { return Data & NoDerivativeMask; }
12871331
bool isIsolated() const { return Data & IsolatedMask; }
1332+
bool isTransferring() const { return Data & TransferringMask; }
12881333

1289-
ValueOwnership getValueOwnership() const {
1290-
return (ValueOwnership)(Data & ValueOwnershipMask);
1334+
ParameterOwnership getOwnership() const {
1335+
return (ParameterOwnership)(Data & OwnershipMask);
12911336
}
12921337

12931338
int_type getIntValue() const { return Data; }

include/swift/AST/Decl.h

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "swift/AST/IfConfigClause.h"
3333
#include "swift/AST/Import.h"
3434
#include "swift/AST/Initializer.h"
35+
#include "swift/AST/InverseMarking.h"
3536
#include "swift/AST/LayoutConstraint.h"
3637
#include "swift/AST/LifetimeAnnotation.h"
3738
#include "swift/AST/ReferenceCounting.h"
@@ -3219,30 +3220,6 @@ class TypeDecl : public ValueDecl {
32193220
};
32203221
};
32213222

3222-
/// "Does a conformance for Copyable exist for this type declaration?"
3223-
///
3224-
/// This doesn't mean that all instance of this type are Copyable, because
3225-
/// if a conditional conformance to Copyable exists, this method will return
3226-
/// true.
3227-
///
3228-
/// If you need a more precise answer, ask this Decl's corresponding
3229-
/// Type if it `isCopyable` instead of using this.
3230-
CanBeInvertible::Result canBeCopyable() const;
3231-
3232-
/// "Does a conformance for Escapable exist for this type declaration?"
3233-
///
3234-
/// This doesn't mean that all instance of this type are Escapable, because
3235-
/// if a conditional conformance to Escapable exists, this method will return
3236-
/// true.
3237-
///
3238-
/// If you need a more precise answer, ask this Decl's corresponding
3239-
/// Type if it `isEscapable` instead of using this.
3240-
CanBeInvertible::Result canBeEscapable() const;
3241-
3242-
/// Determine how the given invertible protocol was written on this TypeDecl,
3243-
/// if at all.
3244-
InverseMarking getMarking(InvertibleProtocolKind ip) const;
3245-
32463223
static bool classof(const Decl *D) {
32473224
return D->getKind() >= DeclKind::First_TypeDecl &&
32483225
D->getKind() <= DeclKind::Last_TypeDecl;
@@ -3260,7 +3237,7 @@ class TypeDecl : public ValueDecl {
32603237
}
32613238
};
32623239

3263-
/// A type declaration that can have generic parameters attached to it. Because
3240+
/// A type declaration that have generic parameters attached to it. Because
32643241
/// it has these generic parameters, it is always a DeclContext.
32653242
class GenericTypeDecl : public GenericContext, public TypeDecl {
32663243
public:
@@ -3935,6 +3912,10 @@ class AssociatedTypeDecl : public TypeDecl {
39353912
TypeDecl::getOverriddenDecl());
39363913
}
39373914

3915+
/// Determine whether this type has ~<target>` stated as
3916+
/// one of its inherited types.
3917+
InverseMarking::Mark hasInverseMarking(InvertibleProtocolKind target) const;
3918+
39383919
/// Retrieve the set of associated types overridden by this associated
39393920
/// type.
39403921
llvm::TinyPtrVector<AssociatedTypeDecl *> getOverriddenDecls() const;
@@ -4372,6 +4353,34 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
43724353
/// Returns null if the type is a class, or does not have a declared `deinit`.
43734354
DestructorDecl *getValueTypeDestructor();
43744355

4356+
/// "Does a conformance for Copyable exist for this type declaration?"
4357+
///
4358+
/// This doesn't mean that all instance of this type are Copyable, because
4359+
/// if a conditional conformance to Copyable exists, this method will return
4360+
/// true.
4361+
///
4362+
/// If you need a more precise answer, ask this Decl's corresponding
4363+
/// Type if it `isCopyable` instead of using this.
4364+
CanBeInvertible::Result canBeCopyable() const;
4365+
4366+
/// "Does a conformance for Escapable exist for this type declaration?"
4367+
///
4368+
/// This doesn't mean that all instance of this type are Escapable, because
4369+
/// if a conditional conformance to Escapable exists, this method will return
4370+
/// true.
4371+
///
4372+
/// If you need a more precise answer, ask this Decl's corresponding
4373+
/// Type if it `isEscapable` instead of using this.
4374+
CanBeInvertible::Result canBeEscapable() const;
4375+
4376+
/// Determine whether this type has `: <target>` stated explicitly in
4377+
/// its inheritance clause.
4378+
bool hasMarking(InvertibleProtocolKind target) const;
4379+
4380+
/// Determine whether this type has ~<target>` stated on
4381+
/// itself, one of its inherited types or `Self` requirements.
4382+
InverseMarking::Mark hasInverseMarking(InvertibleProtocolKind target) const;
4383+
43754384
// Implement isa/cast/dyncast/etc.
43764385
static bool classof(const Decl *D) {
43774386
return D->getKind() >= DeclKind::First_NominalTypeDecl &&
@@ -5227,6 +5236,10 @@ class ProtocolDecl final : public NominalTypeDecl {
52275236
/// protocol.
52285237
bool inheritsFrom(const ProtocolDecl *Super) const;
52295238

5239+
/// Determine whether this protocol has ~<target>` stated on
5240+
/// itself, one of its inherited types or `Self` requirements.
5241+
InverseMarking::Mark hasInverseMarking(InvertibleProtocolKind target) const;
5242+
52305243
/// Determine whether this protocol requires conformance to `IP`, without
52315244
/// querying a generic signature.
52325245
bool requiresInvertible(InvertibleProtocolKind ip) const;

include/swift/AST/DiagnosticsSema.def

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -808,6 +808,19 @@ WARNING(sema_import_current_module_with_file,none,
808808
ERROR(sema_opening_import,Fatal,
809809
"opening import file for module %0: %1", (Identifier, StringRef))
810810

811+
REMARK(serialization_skipped_invalid_decl,none,
812+
"serialization skipped invalid %kind0",
813+
(const Decl *))
814+
REMARK(serialization_skipped_invalid_type,none,
815+
"serialization skipped for invalid type %0",
816+
(TypeRepr *))
817+
REMARK(serialization_skipped_invalid_type_unknown_name,none,
818+
"serialization skipped for invalid type",
819+
())
820+
ERROR(serialization_failed,none,
821+
"serialization of module %0 failed due to the errors above",
822+
(const ModuleDecl *))
823+
811824
ERROR(serialization_load_failed,Fatal,
812825
"failed to load module '%0'", (StringRef))
813826
ERROR(module_interface_build_failed,Fatal,

include/swift/AST/InverseMarking.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
namespace swift {
2121

22-
class InvertibleAnnotationRequest;
23-
2422
/// Describes the way an inverse and its corresponding positive contraint
2523
/// appears on a TypeDecl, i.e., the way it was marked.
2624
struct InverseMarking {
@@ -91,8 +89,6 @@ struct InverseMarking {
9189
Mark inverse;
9290
Mark positive;
9391

94-
// This friend initializes the marks.
95-
friend InvertibleAnnotationRequest;
9692
public:
9793

9894
// Creates an empty marking.

include/swift/AST/Ownership.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,14 @@ enum class ValueOwnership : uint8_t {
142142
enum : unsigned { NumValueOwnershipBits =
143143
countBitsUsed(static_cast<unsigned>(ValueOwnership::Last_Kind)) };
144144

145+
enum class ParameterOwnership : uint8_t;
146+
147+
/// Map a `ValueOwnership` to the corresponding ABI-stable constant used by
148+
/// runtime metadata.
149+
ParameterOwnership asParameterOwnership(ValueOwnership o);
150+
/// Map an ABI-stable ownership identifier to a `ValueOwnership`.
151+
ValueOwnership asValueOwnership(ParameterOwnership o);
152+
145153
static inline llvm::StringRef getOwnershipSpelling(ValueOwnership ownership) {
146154
switch (ownership) {
147155
case ValueOwnership::Default:

include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -429,28 +429,6 @@ class IsFinalRequest :
429429
void cacheResult(bool value) const;
430430
};
431431

432-
/// Determine the kind of invertible protocol markings for this declaration,
433-
/// for example, if a conformance to IP or ~IP was written on it in the
434-
/// inheritance clause and/or where clause.
435-
class InvertibleAnnotationRequest
436-
: public SimpleRequest<InvertibleAnnotationRequest,
437-
InverseMarking(TypeDecl *, InvertibleProtocolKind),
438-
RequestFlags::Cached> {
439-
public:
440-
using SimpleRequest::SimpleRequest;
441-
442-
private:
443-
friend SimpleRequest;
444-
445-
// Evaluation.
446-
InverseMarking evaluate(Evaluator &evaluator,
447-
TypeDecl *decl, InvertibleProtocolKind ip) const;
448-
449-
public:
450-
// Caching.
451-
bool isCached() const { return true; }
452-
};
453-
454432
/// Determine whether the given declaration is 'dynamic''.
455433
class IsDynamicRequest :
456434
public SimpleRequest<IsDynamicRequest,

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,6 @@ SWIFT_REQUEST(TypeChecker, IsDynamicRequest, bool(ValueDecl *),
217217
SeparatelyCached, NoLocationInfo)
218218
SWIFT_REQUEST(TypeChecker, IsFinalRequest, bool(ValueDecl *), SeparatelyCached,
219219
NoLocationInfo)
220-
SWIFT_REQUEST(TypeChecker, InvertibleAnnotationRequest,
221-
InverseMarking(TypeDecl *, InvertibleProtocolKind),
222-
Cached, NoLocationInfo)
223220
SWIFT_REQUEST(TypeChecker, IsGetterMutatingRequest, bool(AbstractStorageDecl *),
224221
SeparatelyCached, NoLocationInfo)
225222
SWIFT_REQUEST(TypeChecker, IsImplicitlyUnwrappedOptionalRequest,

include/swift/AST/TypeRepr.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ class alignas(1 << TypeReprAlignInBits) TypeRepr
137137
/// Is this type representation a protocol?
138138
bool isProtocolOrProtocolComposition(DeclContext *dc);
139139

140+
/// Is this `~<target>` representation.
141+
bool isInverseOf(InvertibleProtocolKind target,
142+
DeclContext *dc);
143+
140144
/// Is this type representation known to be invalid?
141145
bool isInvalid() const { return Bits.TypeRepr.Invalid; }
142146

include/swift/AST/Types.h

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,25 +1146,16 @@ class alignas(1 << TypeAlignInBits) TypeBase
11461146
/// function with each archetype-to-substituted-type binding. The callback
11471147
/// may return a new type to substitute into the result type, or return
11481148
/// CanType() to error out of the operation. Each invocation of the callback
1149-
/// receives three arguments:
1149+
/// receives two arguments:
11501150
/// - The `orig` archetype from a position in `this` type.
1151-
/// - The `subst` type in the same structural position of `ty` that is trying to be bound
1152-
/// to `orig`.
1153-
/// - The `upperBound` archetype, which if set, indicates the minimum set of constraints
1154-
/// that any type substituted in this structural position must conform to. May be null,
1155-
/// indicating an unconstrained context.
1156-
/// - If `upperBound` is set, then the `substConformances` array will contain the
1157-
/// protocol conformances for `subst` to each of the protocol requirements
1158-
/// on `upperBound` in `getConformsTo` order.
1151+
/// - The `subst` type in the same structural position of `ty` that is trying
1152+
/// to be bound to `orig`.
11591153
///
11601154
/// Returns the substituted type, or a null CanType() if this type
11611155
/// is not bindable to the substituted type, or the callback returns
11621156
/// CanType().
11631157
CanType substituteBindingsTo(Type ty,
1164-
llvm::function_ref<CanType(ArchetypeType *orig,
1165-
CanType subst,
1166-
ArchetypeType *upperBound,
1167-
ArrayRef<ProtocolConformanceRef> substConformances)> substFn);
1158+
llvm::function_ref<CanType(ArchetypeType *orig, CanType subst)> substFn);
11681159

11691160
/// Determines whether this type is similar to \p other as defined by
11701161
/// \p matchOptions.

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ LANGUAGE_FEATURE(TypedThrows, 413, "Typed throws")
125125
LANGUAGE_FEATURE(OptionalIsolatedParameters, 420, "Optional isolated parameters")
126126
SUPPRESSIBLE_LANGUAGE_FEATURE(Extern, 0, "@_extern")
127127
LANGUAGE_FEATURE(ExpressionMacroDefaultArguments, 422, "Expression macro as caller-side default argument")
128+
LANGUAGE_FEATURE(BuiltinStoreRaw, 0, "Builtin.storeRaw")
128129

129130
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
130131
UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,9 @@ namespace swift {
243243
/// Emit remarks about contextual inconsistencies in loaded modules.
244244
bool EnableModuleRecoveryRemarks = false;
245245

246+
/// Emit remarks for unexpected conditions when serializing a module.
247+
bool EnableModuleSerializationRemarks = false;
248+
246249
/// Emit remarks about the source of each element exposed by the module API.
247250
bool EnableModuleApiImportRemarks = false;
248251

include/swift/Demangling/Demangle.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ class Node {
278278
/// Prints the whole node tree in readable form to stderr.
279279
///
280280
/// Useful to be called from the debugger.
281-
void dump();
281+
void dump() LLVM_ATTRIBUTE_USED;
282282
};
283283

284284
/// Returns the length of the swift mangling prefix of the \p SymbolName.
@@ -555,6 +555,7 @@ struct [[nodiscard]] ManglingError {
555555
InvalidImplDifferentiability,
556556
InvalidImplFunctionAttribute,
557557
InvalidImplParameterConvention,
558+
InvalidImplParameterTransferring,
558559
InvalidMetatypeRepresentation,
559560
MultiByteRelatedEntity,
560561
BadValueWitnessKind,

0 commit comments

Comments
 (0)