Skip to content

Commit c0c6db8

Browse files
authored
Merge branch 'main' into marker
2 parents 8719d00 + f00ab8a commit c0c6db8

File tree

137 files changed

+1555
-430
lines changed

Some content is hidden

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

137 files changed

+1555
-430
lines changed

docs/ABI/Mangling.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,6 @@ Types
637637
METATYPE-REPR ::= 'T' // Thick metatype representation
638638
METATYPE-REPR ::= 'o' // ObjC metatype representation
639639

640-
type ::= archetype
641640
type ::= associated-type
642641
type ::= any-generic-type
643642
type ::= protocol-list 'p' // existential type
@@ -654,6 +653,12 @@ Types
654653
type ::= assoc-type-list 'QY' GENERIC-PARAM-INDEX // associated type at depth
655654
type ::= assoc-type-list 'QZ' // shortcut for 'QYz'
656655
656+
type ::= pattern-type count-type 'Qp' // pack expansion type
657+
type ::= pack-element-list 'QP' // pack type
658+
659+
pack-element-list ::= type '_' type*
660+
pack-element-list ::= empty-list
661+
657662
#if SWIFT_RUNTIME_VERSION >= 5.2
658663
type ::= type assoc-type-name 'Qx' // associated type relative to base `type`
659664
type ::= type assoc-type-list 'QX' // associated type relative to base `type`
@@ -668,11 +673,8 @@ Types
668673

669674
assoc-type-list ::= assoc-type-name '_' assoc-type-name*
670675

671-
archetype ::= associated-type
672-
673676
associated-type ::= substitution
674-
associated-type ::= protocol 'QP' // self type of protocol
675-
associated-type ::= archetype identifier 'Qa' // associated type
677+
associated-type ::= type identifier 'Qa' // associated type
676678

677679
assoc-type-name ::= identifier // associated type name without protocol
678680
assoc-type-name ::= identifier protocol 'P' //

docs/Android.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ $ adb push build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/android/libBlo
133133
In addition, you'll also need to copy the Android NDK's libc++:
134134

135135
```
136-
$ adb push /path/to/android-ndk-r25b/sources/cxx-stl/llvm-libc++/libs/arm64-v8a/libc++_shared.so /data/local/tmp
136+
$ adb push /path/to/android-ndk-r25b/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/libc++_shared.so /data/local/tmp
137137
```
138138

139139
Finally, you'll need to copy the `hello` executable you built in the

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4721,7 +4721,7 @@ class ProtocolDecl final : public NominalTypeDecl {
47214721
AssociatedTypeDecl *getAssociatedType(Identifier name) const;
47224722

47234723
/// Returns the existential type for this protocol.
4724-
Type getExistentialType() const {
4724+
Type getDeclaredExistentialType() const {
47254725
return ExistentialType::get(getDeclaredInterfaceType());
47264726
}
47274727

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6530,6 +6530,11 @@ ERROR(experimental_moveonly_feature_can_only_be_used_when_enabled,
65306530
none, "Can not use feature when experimental move only is disabled! Pass"
65316531
" the frontend flag -enable-experimental-move-only to swift to enable "
65326532
"the usage of this language feature", ())
6533+
ERROR(experimental_moveonly_feature_can_only_be_imported_when_enabled,
6534+
none, "Can not import module %0 that uses move only features when "
6535+
"experimental move only is disabled! Pass the frontend flag "
6536+
"-enable-experimental-move-only to swift to enable the usage of this "
6537+
"language feature", (Identifier))
65336538
ERROR(noimplicitcopy_attr_valid_only_on_local_let_params,
65346539
none, "'@_noImplicitCopy' attribute can only be applied to local lets and params", ())
65356540
ERROR(noimplicitcopy_attr_invalid_in_generic_context,

include/swift/AST/GenericSignature.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,13 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
457457
/// will return an instance of \c ExistentialType.
458458
Type getNonDependentUpperBounds(Type type) const;
459459

460+
/// Given a type parameter, compute the most specific supertype (upper bound)
461+
/// that is possibly dependent on other type parameters.
462+
///
463+
/// \note If the upper bound is a protocol or protocol composition,
464+
/// will return an instance of \c ExistentialType.
465+
Type getDependentUpperBounds(Type type) const;
466+
460467
static void Profile(llvm::FoldingSetNodeID &ID,
461468
TypeArrayView<GenericTypeParamType> genericParams,
462469
ArrayRef<Requirement> requirements);

include/swift/AST/ModuleLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ struct InterfaceSubContextDelegate {
173173
StringRef interfacePath,
174174
StringRef outputPath,
175175
SourceLoc diagLoc,
176+
bool silenceErrors,
176177
llvm::function_ref<std::error_code(SubCompilerInstanceInfo&)> action) = 0;
177178

178179
virtual ~InterfaceSubContextDelegate() = default;

include/swift/AST/Types.h

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6689,17 +6689,6 @@ inline bool TypeBase::isOpenedExistential() const {
66896689
return isa<OpenedArchetypeType>(T);
66906690
}
66916691

6692-
inline bool TypeBase::isOpenedExistentialWithError() {
6693-
if (!hasOpenedExistential())
6694-
return false;
6695-
6696-
CanType T = getCanonicalType();
6697-
if (auto archetype = dyn_cast<OpenedArchetypeType>(T)) {
6698-
return archetype->getExistentialType()->isExistentialWithError();
6699-
}
6700-
return false;
6701-
}
6702-
67036692
inline bool TypeBase::canDynamicallyBeOptionalType(bool includeExistential) {
67046693
CanType T = getCanonicalType();
67056694
auto isArchetypeOrExistential = isa<ArchetypeType>(T) ||

include/swift/Demangling/DemangleNodes.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,8 @@ NODE(ThinFunctionType)
227227
NODE(Tuple)
228228
NODE(TupleElement)
229229
NODE(TupleElementName)
230+
NODE(Pack)
231+
NODE(PackExpansion)
230232
NODE(Type)
231233
CONTEXT_NODE(TypeSymbolicReference)
232234
CONTEXT_NODE(TypeAlias)

include/swift/Demangling/Demangler.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -518,6 +518,7 @@ class Demangler : public NodeFactory {
518518
NodePointer popFunctionParamLabels(NodePointer FuncType);
519519
NodePointer popTuple();
520520
NodePointer popTypeList();
521+
NodePointer popPack();
521522
NodePointer popProtocol();
522523
NodePointer demangleBoundGenericType();
523524
NodePointer demangleBoundGenericArgs(NodePointer nominalType,

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,6 +523,7 @@ struct InterfaceSubContextDelegateImpl: InterfaceSubContextDelegate {
523523
StringRef interfacePath,
524524
StringRef outputPath,
525525
SourceLoc diagLoc,
526+
bool silenceErrors,
526527
llvm::function_ref<std::error_code(SubCompilerInstanceInfo&)> action) override;
527528

528529
~InterfaceSubContextDelegateImpl() = default;

include/swift/Parse/LocalContext.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ class LocalContext {
5858
/// True if we saw any anonymous closures. This is useful when
5959
/// parsing an initializer context, because such contexts only
6060
/// need to exist if the initializer contains closures.
61-
bool hasClosures() const { return NextClosureDiscriminator != 0; }
61+
bool hasClosures() const { return NextClosureDiscriminator != 0; }
62+
63+
/// Override the next closure discriminator value.
64+
void overrideNextClosureDiscriminator(unsigned discriminator) {
65+
NextClosureDiscriminator = discriminator;
66+
}
6267
};
6368

6469
/// Information associated with parsing the top-level context.

include/swift/Runtime/Heap.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ SWIFT_BEGIN_DECLS
3030
// Never returns nil. The returned memory is uninitialized.
3131
//
3232
// An "alignment mask" is just the alignment (a power of 2) minus 1.
33-
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
33+
SWIFT_EXTERN_C SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT_ATTRIBUTE
3434
void *swift_slowAlloc(size_t bytes, size_t alignMask);
3535

3636
// If the caller cannot promise to zero the object during destruction,

include/swift/Runtime/HeapObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ SWIFT_BEGIN_DECLS
6363
///
6464
/// POSSIBILITIES: The argument order is fair game. It may be useful
6565
/// to have a variant which guarantees zero-initialized memory.
66-
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
66+
SWIFT_EXTERN_C SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT_ATTRIBUTE
6767
HeapObject *swift_allocObject(HeapMetadata const *metadata,
6868
size_t requiredSize,
6969
size_t requiredAlignmentMask);
@@ -123,7 +123,7 @@ BoxPair swift_makeBoxUnique(OpaqueValue *buffer, Metadata const *type,
123123
size_t alignMask);
124124

125125
/// Returns the address of a heap object representing all empty box types.
126-
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
126+
SWIFT_EXTERN_C SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT_ATTRIBUTE
127127
HeapObject* swift_allocEmptyBox();
128128

129129
/// Atomically increments the retain count of an object.

include/swift/Runtime/Metadata.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ swift_getGenericMetadata(MetadataRequest request,
325325
/// - installing new v-table entries and overrides; and
326326
/// - registering the class with the runtime under ObjC interop.
327327
/// Most of this work can be achieved by calling swift_initClassMetadata.
328-
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
328+
SWIFT_EXTERN_C SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT_ATTRIBUTE
329329
ClassMetadata *
330330
swift_allocateGenericClassMetadata(const ClassDescriptor *description,
331331
const void *arguments,
@@ -334,7 +334,7 @@ swift_allocateGenericClassMetadata(const ClassDescriptor *description,
334334
/// Allocate a generic value metadata object. This is intended to be
335335
/// called by the metadata instantiation function of a generic struct or
336336
/// enum.
337-
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
337+
SWIFT_EXTERN_C SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT_ATTRIBUTE
338338
ValueMetadata *
339339
swift_allocateGenericValueMetadata(const ValueTypeDescriptor *description,
340340
const void *arguments,

include/swift/SIL/AbstractionPattern.h

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,6 +1255,64 @@ class AbstractionPattern {
12551255
llvm_unreachable("bad kind");
12561256
}
12571257

1258+
/// Is the given pack type a valid substitution of this abstraction
1259+
/// pattern?
1260+
bool matchesPack(CanPackType substType);
1261+
1262+
bool isPack() const {
1263+
switch (getKind()) {
1264+
case Kind::Invalid:
1265+
llvm_unreachable("querying invalid abstraction pattern!");
1266+
case Kind::Opaque:
1267+
case Kind::PartialCurriedObjCMethodType:
1268+
case Kind::CurriedObjCMethodType:
1269+
case Kind::CFunctionAsMethodType:
1270+
case Kind::CurriedCFunctionAsMethodType:
1271+
case Kind::PartialCurriedCFunctionAsMethodType:
1272+
case Kind::ObjCMethodType:
1273+
case Kind::CXXMethodType:
1274+
case Kind::CurriedCXXMethodType:
1275+
case Kind::PartialCurriedCXXMethodType:
1276+
case Kind::OpaqueFunction:
1277+
case Kind::OpaqueDerivativeFunction:
1278+
case Kind::ObjCCompletionHandlerArgumentsType:
1279+
case Kind::Tuple:
1280+
case Kind::ClangType:
1281+
return false;
1282+
case Kind::Type:
1283+
case Kind::Discard:
1284+
return isa<PackType>(getType());
1285+
}
1286+
llvm_unreachable("bad kind");
1287+
}
1288+
1289+
size_t getNumPackElements() const {
1290+
switch (getKind()) {
1291+
case Kind::Invalid:
1292+
llvm_unreachable("querying invalid abstraction pattern!");
1293+
case Kind::Opaque:
1294+
case Kind::PartialCurriedObjCMethodType:
1295+
case Kind::CurriedObjCMethodType:
1296+
case Kind::CFunctionAsMethodType:
1297+
case Kind::CurriedCFunctionAsMethodType:
1298+
case Kind::PartialCurriedCFunctionAsMethodType:
1299+
case Kind::ObjCMethodType:
1300+
case Kind::CXXMethodType:
1301+
case Kind::CurriedCXXMethodType:
1302+
case Kind::PartialCurriedCXXMethodType:
1303+
case Kind::OpaqueFunction:
1304+
case Kind::OpaqueDerivativeFunction:
1305+
case Kind::ObjCCompletionHandlerArgumentsType:
1306+
case Kind::Tuple:
1307+
case Kind::ClangType:
1308+
llvm_unreachable("pattern is not a pack");
1309+
case Kind::Type:
1310+
case Kind::Discard:
1311+
return cast<PackType>(getType())->getNumElements();
1312+
}
1313+
llvm_unreachable("bad kind");
1314+
}
1315+
12581316
/// Given that the value being abstracted is a move only type, return the
12591317
/// abstraction pattern with the move only bit removed.
12601318
AbstractionPattern removingMoveOnlyWrapper() const;
@@ -1264,9 +1322,21 @@ class AbstractionPattern {
12641322
AbstractionPattern addingMoveOnlyWrapper() const;
12651323

12661324
/// Given that the value being abstracted is a tuple type, return
1267-
/// the abstraction pattern for its object type.
1325+
/// the abstraction pattern for an element type.
12681326
AbstractionPattern getTupleElementType(unsigned index) const;
12691327

1328+
/// Given that the value being abstracted is a pack type, return
1329+
/// the abstraction pattern for an element type.
1330+
AbstractionPattern getPackElementType(unsigned index) const;
1331+
1332+
/// Give that the value being abstracted is a pack expansion type, return the
1333+
/// underlying pattern type.
1334+
AbstractionPattern getPackExpansionPatternType() const;
1335+
1336+
/// Give that the value being abstracted is a pack expansion type, return the
1337+
/// underlying count type.
1338+
AbstractionPattern getPackExpansionCountType() const;
1339+
12701340
/// Given that the value being abstracted is a function, return the
12711341
/// abstraction pattern for its result type.
12721342
AbstractionPattern getFunctionResultType() const;

lib/AST/ASTContext.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -930,8 +930,8 @@ Type ASTContext::get##NAME##Type() const { \
930930
#include "swift/AST/KnownStdlibTypes.def"
931931

932932
CanType ASTContext::getErrorExistentialType() const {
933-
if (auto exn = getErrorDecl()) {
934-
return exn->getExistentialType()->getCanonicalType();
933+
if (auto *errorProto = getErrorDecl()) {
934+
return errorProto->getDeclaredExistentialType()->getCanonicalType();
935935
} else {
936936
// Use Builtin.NativeObject just as a stand-in.
937937
return TheNativeObjectType;
@@ -2605,7 +2605,7 @@ ASTContext::getSelfConformance(ProtocolDecl *protocol) {
26052605
auto &entry = selfConformances[protocol];
26062606
if (!entry) {
26072607
entry = new (*this, AllocationArena::Permanent)
2608-
SelfProtocolConformance(protocol->getExistentialType());
2608+
SelfProtocolConformance(protocol->getDeclaredExistentialType());
26092609
}
26102610
return entry;
26112611
}

lib/AST/ASTMangler.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,12 +1235,29 @@ void ASTMangler::appendType(Type type, GenericSignature sig,
12351235
return appendAnyGenericType(decl);
12361236
}
12371237

1238-
case TypeKind::Pack:
1239-
case TypeKind::PackExpansion:
1240-
assert(DWARFMangling && "sugared types are only legal for the debugger");
1241-
appendOperator("XSP");
1242-
llvm_unreachable("Unimplemented");
1238+
case TypeKind::PackExpansion: {
1239+
auto expansionTy = cast<PackExpansionType>(tybase);
1240+
appendType(expansionTy->getPatternType(), sig, forDecl);
1241+
appendType(expansionTy->getCountType(), sig, forDecl);
1242+
appendOperator("Qp");
12431243
return;
1244+
}
1245+
1246+
case TypeKind::Pack: {
1247+
auto packTy = cast<PackType>(tybase);
1248+
1249+
if (packTy->getNumElements() == 0)
1250+
appendOperator("y");
1251+
else {
1252+
bool firstField = true;
1253+
for (auto element : packTy->getElementTypes()) {
1254+
appendType(element, sig, forDecl);
1255+
appendListSeparator(firstField);
1256+
}
1257+
}
1258+
appendOperator("QP");
1259+
return;
1260+
}
12441261

12451262
case TypeKind::Paren:
12461263
assert(DWARFMangling && "sugared types are only legal for the debugger");

lib/AST/ASTPrinter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6473,6 +6473,13 @@ class TypePrinter : public TypeVisitor<TypePrinter> {
64736473
if (auto existential = constraint->getAs<ExistentialType>())
64746474
constraint = existential->getConstraintType();
64756475

6476+
// Opaque archetype substitutions are always canonical, so re-sugar the
6477+
// constraint type using the owning declaration's generic parameter names.
6478+
auto genericSig = T->getDecl()->getNamingDecl()->getInnermostDeclContext()
6479+
->getGenericSignatureOfContext();
6480+
if (genericSig)
6481+
constraint = genericSig->getSugaredType(constraint);
6482+
64766483
visit(constraint);
64776484
return;
64786485
}

0 commit comments

Comments
 (0)