Skip to content

Commit 36be9d9

Browse files
authored
Merge pull request #77211 from bnbarham/manually-merge-main-to-rebranch
Manually merge main to rebranch
2 parents 85d3dab + af53b3f commit 36be9d9

File tree

102 files changed

+4409
-699
lines changed

Some content is hidden

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

102 files changed

+4409
-699
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ To switch to this template when drafting a pull request in a [swiftlang](https:/
236236
### Commit Access
237237

238238
Commit access is granted to contributors with a track record of submitting high-quality changes.
239-
If you would like commit access, please send an email to [the code owners list]([email protected]) with the GitHub user name that you want to use and a list of 5 non-trivial pull requests that were accepted without modifications.
239+
If you would like commit access, please send an email to [the code owners list](mailto:[email protected]) with the GitHub user name that you want to use and a list of 5 non-trivial pull requests that were accepted without modifications.
240240

241241
Once you’ve been granted commit access, you will be able to commit to all of the GitHub repositories that host Swift.org projects.
242242
To verify that your commit access works, please make a test commit (for example, change a comment or add a blank line). The following policies apply to users with commit access:

SwiftCompilerSources/Sources/Optimizer/Utilities/GenericSpecialization.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ private struct VTableSpecializer {
8686
let methodSubs = classContextSubs.getMethodSubstitutions(for: entry.implementation)
8787

8888
guard !methodSubs.conformances.contains(where: {!$0.isValid}),
89+
context.loadFunction(function: entry.implementation, loadCalleesRecursively: true),
8990
let specializedMethod = context.specialize(function: entry.implementation, for: methodSubs) else
9091
{
9192
context.diagnosticEngine.diagnose(entry.methodDecl.location.sourceLoc, .non_final_generic_class_function)
@@ -125,6 +126,7 @@ func specializeWitnessTable(forConformance conformance: Conformance,
125126
let methodSubs = conformance.specializedSubstitutions.getMethodSubstitutions(for: origMethod)
126127

127128
guard !methodSubs.conformances.contains(where: {!$0.isValid}),
129+
context.loadFunction(function: origMethod, loadCalleesRecursively: true),
128130
let specializedMethod = context.specialize(function: origMethod, for: methodSubs) else
129131
{
130132
context.diagnosticEngine.diagnose(errorLocation.sourceLoc, .cannot_specialize_witness_method, requirement)

docs/ABI/Mangling.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -693,6 +693,7 @@ Types
693693
type ::= 'Bp' // Builtin.RawPointer
694694
type ::= 'Bt' // Builtin.SILToken
695695
type ::= type 'Bv' NATURAL '_' // Builtin.Vec<n>x<type>
696+
type ::= type type 'BV' // Builtin.FixedArray<N, T>
696697
type ::= 'Bw' // Builtin.Word
697698
type ::= function-signature 'c' // function type (escaping)
698699
type ::= function-signature 'X' FUNCTION-KIND // special function type

include/swift/ABI/Metadata.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1665,6 +1665,27 @@ struct TargetMetatypeMetadata : public TargetMetadata<Runtime> {
16651665
};
16661666
using MetatypeMetadata = TargetMetatypeMetadata<InProcess>;
16671667

1668+
/// The structure of `Builtin.FixedArray` type metadata.
1669+
template <typename Runtime>
1670+
struct TargetFixedArrayTypeMetadata : public TargetMetadata<Runtime> {
1671+
using StoredPointerDifference = typename Runtime::StoredPointerDifference;
1672+
1673+
StoredPointerDifference Count;
1674+
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> Element;
1675+
1676+
// Returns the number of elements for which storage is reserved.
1677+
// A type that is instantiated with negative size cannot have values
1678+
// instantiated, so is laid out with zero size like an uninhabited type.
1679+
StoredPointerDifference getRealizedCount() const {
1680+
return Count < 0 ? 0 : Count;
1681+
}
1682+
1683+
static bool classof(const TargetMetadata<Runtime> *metadata) {
1684+
return metadata->getKind() == MetadataKind::FixedArray;
1685+
}
1686+
};
1687+
using FixedArrayTypeMetadata = TargetFixedArrayTypeMetadata<InProcess>;
1688+
16681689
/// The structure of tuple type metadata.
16691690
template <typename Runtime>
16701691
struct TargetTupleTypeMetadata : public TargetMetadata<Runtime> {

include/swift/ABI/MetadataKind.def

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ NOMINALTYPEMETADATAKIND(Class, 0)
4444
NOMINALTYPEMETADATAKIND(Struct, 0 | MetadataKindIsNonHeap)
4545

4646
/// An enum type.
47-
/// If we add reference enums, that needs to go here.
4847
NOMINALTYPEMETADATAKIND(Enum, 1 | MetadataKindIsNonHeap)
4948

5049
/// An optional type.
@@ -80,6 +79,10 @@ METADATAKIND(ExistentialMetatype, 6 | MetadataKindIsRuntimePrivate | MetadataKin
8079
/// An extended existential type.
8180
METADATAKIND(ExtendedExistential, 7 | MetadataKindIsRuntimePrivate | MetadataKindIsNonHeap)
8281

82+
/// A `Builtin.FixedArray`.
83+
METADATAKIND(FixedArray, 8 | MetadataKindIsRuntimePrivate | MetadataKindIsNonHeap)
84+
85+
8386
/// A heap-allocated local variable using statically-generated metadata.
8487
METADATAKIND(HeapLocalVariable, 0 | MetadataKindIsNonType)
8588

include/swift/AST/Builtins.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,6 +1126,13 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(DistributedActorAsAnyActor, "distributedActor
11261126
/// lowered away at IRGen, no sooner.
11271127
BUILTIN_MISC_OPERATION_WITH_SILGEN(AddressOfRawLayout, "addressOfRawLayout", "n", Special)
11281128

1129+
/// emplace<T>((Builtin.RawPointer) -> Void) -> T
1130+
///
1131+
/// Passes a pointer to an uninitialized result value to the given function,
1132+
/// which must initialize the memory before finishing execution. The value in
1133+
/// memory becomes the result of the call.
1134+
BUILTIN_SIL_OPERATION(Emplace, "emplace", Special)
1135+
11291136
/// Builtins for instrumentation added by sanitizers during SILGen.
11301137
#ifndef BUILTIN_SANITIZER_OPERATION
11311138
#define BUILTIN_SANITIZER_OPERATION(Id, Name, Attrs) BUILTIN(Id, Name, Attrs)

include/swift/AST/DiagnosticsParse.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,8 @@ ERROR(static_var_decl_global_scope,none,
255255
(StaticSpellingKind))
256256
ERROR(expected_getset_in_protocol,none,
257257
"expected get or set in a protocol property", ())
258+
ERROR(expected_getreadset_in_protocol,none,
259+
"expected get, read, or set in a protocol property", ())
258260
ERROR(unexpected_getset_implementation_in_protocol,none,
259261
"protocol property %0 cannot have a default implementation specified "
260262
"here; use extension instead", (StringRef))

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4641,6 +4641,8 @@ ERROR(cannot_explicitly_specialize_function,none,
46414641
"cannot explicitly specialize %kind0", (ValueDecl *))
46424642
ERROR(not_a_generic_type,none,
46434643
"cannot specialize non-generic type %0", (Type))
4644+
ERROR(invalid_generic_builtin_type,none,
4645+
"invalid generic arguments to builtin type %0", (Type))
46444646
ERROR(not_a_generic_macro,none,
46454647
"cannot specialize a non-generic external macro %0", (const ValueDecl *))
46464648
ERROR(protocol_declares_unknown_primary_assoc_type,none,

include/swift/AST/ExistentialLayout.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212
//
13-
// This file defines the ExistentialLayout struct.
13+
// The ExistentialLayout struct describes the in-memory layout of an existential
14+
// type.
15+
//
16+
// It flattens and canonicalizes protocol compositions, and also expands defaults
17+
// for invertible protocols.
1418
//
1519
//===----------------------------------------------------------------------===//
1620

@@ -33,7 +37,6 @@ struct ExistentialLayout {
3337
hasExplicitAnyObject = false;
3438
containsObjCProtocol = false;
3539
containsSwiftProtocol = false;
36-
containsParameterized = false;
3740
representsAnyObject = false;
3841
}
3942

@@ -53,9 +56,6 @@ struct ExistentialLayout {
5356
/// Whether any protocol members require a witness table.
5457
bool containsSwiftProtocol : 1;
5558

56-
/// Whether any protocol members are parameterized.s
57-
bool containsParameterized : 1;
58-
5959
/// Whether this layout is the canonical layout for plain-old 'AnyObject'.
6060
bool representsAnyObject : 1;
6161

@@ -105,14 +105,18 @@ struct ExistentialLayout {
105105
/// calling this on a temporary is likely to be incorrect.
106106
ArrayRef<ProtocolDecl*> getProtocols() const && = delete;
107107

108+
ArrayRef<ParameterizedProtocolType *> getParameterizedProtocols() const & {
109+
return parameterized;
110+
}
111+
/// The returned ArrayRef points to internal storage, so
112+
/// calling this on a temporary is likely to be incorrect.
113+
ArrayRef<ProtocolDecl*> getParameterizedProtocols() const && = delete;
114+
108115
LayoutConstraint getLayoutConstraint() const;
109116

110117
private:
111118
SmallVector<ProtocolDecl *, 4> protocols;
112-
113-
/// Zero or more primary associated type requirements from a
114-
/// ParameterizedProtocolType
115-
ArrayRef<Type> sameTypeRequirements;
119+
SmallVector<ParameterizedProtocolType *, 4> parameterized;
116120
};
117121

118122
}

include/swift/AST/TypeDifferenceVisitor.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,19 @@ class CanTypeDifferenceVisitor : public CanTypePairVisitor<Impl, bool> {
129129
return asImpl().visitDifferentTypeStructure(type1, type2);
130130
return asImpl().visit(type1.getElementType(), type2.getElementType());
131131
}
132+
133+
bool visitBuiltinUnboundGenericType(CanBuiltinUnboundGenericType type1,
134+
CanBuiltinUnboundGenericType type2) {
135+
return asImpl().visitDifferentTypeStructure(type1, type2);
136+
}
137+
138+
bool visitBuiltinFixedArrayType(CanBuiltinFixedArrayType type1,
139+
CanBuiltinFixedArrayType type2) {
140+
if (asImpl().visit(type1->getSize(), type2->getSize())) {
141+
return true;
142+
}
143+
return asImpl().visit(type1->getElementType(), type2->getElementType());
144+
}
132145

133146
bool visitPackType(CanPackType type1, CanPackType type2) {
134147
return visitComponentArray(type1, type2,

include/swift/AST/TypeMatcher.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ class TypeMatcher {
111111
TRIVIAL_CASE(BuiltinIntegerType)
112112
TRIVIAL_CASE(BuiltinFloatType)
113113
TRIVIAL_CASE(BuiltinVectorType)
114+
TRIVIAL_CASE(BuiltinUnboundGenericType)
115+
TRIVIAL_CASE(BuiltinFixedArrayType)
114116
TRIVIAL_CASE(IntegerType)
115117
#define SINGLETON_TYPE(SHORT_ID, ID) TRIVIAL_CASE(ID##Type)
116118
#include "swift/AST/TypeNodes.def"

include/swift/AST/TypeNodes.def

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727
/// This type is a builtin type. The default behavior is
2828
/// ALWAYS_CANONICAL_TYPE(id, parent).
2929

30+
/// BUILTIN_CONCRETE_TYPE(id, parent)
31+
/// This type is a builtin type without generic parameters. The default
32+
/// behavior is BUILTIN_TYPE(id, parent).
33+
34+
/// BUILTIN_GENERIC_TYPE(id, parent)
35+
/// This type is a builtin type with generic parameters. The default
36+
/// behavior is BUILTIN_TYPE(id, parent).
37+
3038
/// SUGARED_TYPE(id, parent)
3139
/// This type is never canonical. It provides an efficient accessor,
3240
/// getSinglyDesugaredType(), which removes one level of sugar. This
@@ -72,6 +80,14 @@
7280
#define BUILTIN_TYPE(id, parent) ALWAYS_CANONICAL_TYPE(id, parent)
7381
#endif
7482

83+
#ifndef BUILTIN_CONCRETE_TYPE
84+
#define BUILTIN_CONCRETE_TYPE(id, parent) BUILTIN_TYPE(id, parent)
85+
#endif
86+
87+
#ifndef BUILTIN_GENERIC_TYPE
88+
#define BUILTIN_GENERIC_TYPE(id, parent) BUILTIN_TYPE(id, parent)
89+
#endif
90+
7591
#ifndef SUGARED_TYPE
7692
#define SUGARED_TYPE(id, parent) TYPE(id, parent)
7793
#endif
@@ -111,22 +127,24 @@ UNCHECKED_TYPE(Unresolved, Type)
111127
UNCHECKED_TYPE(Placeholder, Type)
112128
ABSTRACT_TYPE(Builtin, Type)
113129
ABSTRACT_TYPE(AnyBuiltinInteger, BuiltinType)
114-
BUILTIN_TYPE(BuiltinInteger, AnyBuiltinIntegerType)
115-
BUILTIN_TYPE(BuiltinIntegerLiteral, AnyBuiltinIntegerType)
130+
BUILTIN_CONCRETE_TYPE(BuiltinInteger, AnyBuiltinIntegerType)
131+
BUILTIN_CONCRETE_TYPE(BuiltinIntegerLiteral, AnyBuiltinIntegerType)
116132
TYPE_RANGE(AnyBuiltinInteger, BuiltinInteger, BuiltinIntegerLiteral)
117-
BUILTIN_TYPE(BuiltinExecutor, BuiltinType)
118-
BUILTIN_TYPE(BuiltinFloat, BuiltinType)
119-
BUILTIN_TYPE(BuiltinJob, BuiltinType)
120-
BUILTIN_TYPE(BuiltinPackIndex, BuiltinType)
121-
BUILTIN_TYPE(BuiltinRawPointer, BuiltinType)
122-
BUILTIN_TYPE(BuiltinRawUnsafeContinuation, BuiltinType)
123-
BUILTIN_TYPE(BuiltinNativeObject, BuiltinType)
124-
BUILTIN_TYPE(BuiltinBridgeObject, BuiltinType)
125-
BUILTIN_TYPE(BuiltinUnsafeValueBuffer, BuiltinType)
126-
BUILTIN_TYPE(BuiltinDefaultActorStorage, BuiltinType)
127-
BUILTIN_TYPE(BuiltinNonDefaultDistributedActorStorage, BuiltinType)
128-
BUILTIN_TYPE(BuiltinVector, BuiltinType)
129-
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinVector)
133+
BUILTIN_CONCRETE_TYPE(BuiltinExecutor, BuiltinType)
134+
BUILTIN_CONCRETE_TYPE(BuiltinFloat, BuiltinType)
135+
BUILTIN_CONCRETE_TYPE(BuiltinJob, BuiltinType)
136+
BUILTIN_CONCRETE_TYPE(BuiltinPackIndex, BuiltinType)
137+
BUILTIN_CONCRETE_TYPE(BuiltinRawPointer, BuiltinType)
138+
BUILTIN_CONCRETE_TYPE(BuiltinRawUnsafeContinuation, BuiltinType)
139+
BUILTIN_CONCRETE_TYPE(BuiltinNativeObject, BuiltinType)
140+
BUILTIN_CONCRETE_TYPE(BuiltinBridgeObject, BuiltinType)
141+
BUILTIN_CONCRETE_TYPE(BuiltinUnsafeValueBuffer, BuiltinType)
142+
BUILTIN_CONCRETE_TYPE(BuiltinDefaultActorStorage, BuiltinType)
143+
BUILTIN_CONCRETE_TYPE(BuiltinNonDefaultDistributedActorStorage, BuiltinType)
144+
BUILTIN_CONCRETE_TYPE(BuiltinVector, BuiltinType)
145+
BUILTIN_GENERIC_TYPE(BuiltinFixedArray, BuiltinType)
146+
BUILTIN_CONCRETE_TYPE(BuiltinUnboundGeneric, BuiltinType)
147+
TYPE_RANGE(Builtin, BuiltinInteger, BuiltinUnboundGeneric)
130148
TYPE(Tuple, Type)
131149
ABSTRACT_TYPE(ReferenceStorage, Type)
132150
#define REF_STORAGE(Name, ...) \
@@ -228,6 +246,8 @@ SINGLETON_TYPE(SILToken, SILToken)
228246
#undef UNCHECKED_TYPE
229247
#undef ARTIFICIAL_TYPE
230248
#undef SUGARED_TYPE
249+
#undef BUILTIN_GENERIC_TYPE
250+
#undef BUILTIN_CONCRETE_TYPE
231251
#undef BUILTIN_TYPE
232252
#undef ALWAYS_CANONICAL_TYPE
233253
#undef ALWAYS_CANONICAL_ARTIFICIAL_TYPE

include/swift/AST/TypeTransform.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class TypeTransform {
106106
TypeBase *base = t.getPointer();
107107

108108
switch (base->getKind()) {
109-
#define BUILTIN_TYPE(Id, Parent) \
109+
#define BUILTIN_CONCRETE_TYPE(Id, Parent) \
110110
case TypeKind::Id:
111111
#define TYPE(Id, Parent)
112112
#include "swift/AST/TypeNodes.def"
@@ -120,6 +120,31 @@ case TypeKind::Id:
120120
case TypeKind::Integer:
121121
return t;
122122

123+
case TypeKind::BuiltinFixedArray: {
124+
auto bfaTy = cast<BuiltinFixedArrayType>(base);
125+
126+
Type transSize = doIt(bfaTy->getSize(),
127+
TypePosition::Invariant);
128+
if (!transSize) {
129+
return Type();
130+
}
131+
132+
Type transElement = doIt(bfaTy->getElementType(),
133+
TypePosition::Invariant);
134+
if (!transElement) {
135+
return Type();
136+
}
137+
138+
CanType canTransSize = transSize->getCanonicalType();
139+
CanType canTransElement = transElement->getCanonicalType();
140+
if (canTransSize != bfaTy->getSize()
141+
|| canTransElement != bfaTy->getElementType()) {
142+
return BuiltinFixedArrayType::get(canTransSize, canTransElement);
143+
}
144+
145+
return bfaTy;
146+
}
147+
123148
case TypeKind::PrimaryArchetype:
124149
case TypeKind::PackArchetype: {
125150
auto *archetype = cast<ArchetypeType>(base);

0 commit comments

Comments
 (0)