Skip to content

Commit 662e2cf

Browse files
authored
Merge branch 'main' into es-pkg-in-public
2 parents 2f9c605 + 9e7d927 commit 662e2cf

File tree

160 files changed

+3499
-1014
lines changed

Some content is hidden

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

160 files changed

+3499
-1014
lines changed

cmake/modules/AddPureSwift.cmake

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ function(_add_host_swift_compile_options name)
3131
"$<$<COMPILE_LANGUAGE:Swift>:SHELL:-Xfrontend -disable-implicit-backtracing-module-import>")
3232
endif()
3333

34+
if(SWIFT_ANALYZE_CODE_COVERAGE)
35+
set(_cov_flags $<$<COMPILE_LANGUAGE:Swift>:-profile-generate -profile-coverage-mapping>)
36+
target_compile_options(${name} PRIVATE ${_cov_flags})
37+
target_link_options(${name} PRIVATE ${_cov_flags})
38+
endif()
39+
3440
# The compat56 library is not available in current toolchains. The stage-0
3541
# compiler will build fine since the builder compiler is not aware of the 56
3642
# compat library, but the stage-1 and subsequent stage compilers will fail as

cmake/modules/AddSwift.cmake

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,12 @@ function(_add_host_variant_c_compile_link_flags name)
179179
target_compile_options(${name} PRIVATE $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:${_lto_flag_out}>)
180180
target_link_options(${name} PRIVATE ${_lto_flag_out})
181181
endif()
182+
183+
if(SWIFT_ANALYZE_CODE_COVERAGE)
184+
set(_cov_flags $<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-fprofile-instr-generate -fcoverage-mapping>)
185+
target_compile_options(${name} PRIVATE ${_cov_flags})
186+
target_link_options(${name} PRIVATE ${_cov_flags})
187+
endif()
182188
endfunction()
183189

184190

@@ -322,11 +328,6 @@ function(_add_host_variant_c_compile_flags target)
322328
target_compile_definitions(${target} PRIVATE
323329
"SWIFT_THREADING_${_threading_package}")
324330
325-
if(SWIFT_ANALYZE_CODE_COVERAGE)
326-
target_compile_options(${target} PRIVATE
327-
$<$<COMPILE_LANGUAGE:C,CXX,OBJC,OBJCXX>:-fprofile-instr-generate -fcoverage-mapping>)
328-
endif()
329-
330331
if((SWIFT_HOST_VARIANT_ARCH STREQUAL "armv7" OR
331332
SWIFT_HOST_VARIANT_ARCH STREQUAL "aarch64") AND
332333
(SWIFT_HOST_VARIANT_SDK STREQUAL "LINUX" OR

docs/ABI/Mangling.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,9 @@ Types
646646
global-actor :: = type 'Yc' // Global actor on function type
647647
#endif
648648
throws ::= 'K' // 'throws' annotation on function types
649+
#if SWIFT_RUNTIME_VERSION >= 5.11
650+
throws ::= type 'YK' // 'throws(type)' annotation on function types
651+
#endif
649652
differentiable ::= 'Yjf' // @differentiable(_forward) on function type
650653
differentiable ::= 'Yjr' // @differentiable(reverse) on function type
651654
differentiable ::= 'Yjd' // @differentiable on function type

docs/LibraryEvolution.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,10 @@ compiler):
262262
- They must not reference any ``internal`` entities except for those that have
263263
been declared ``@usableFromInline`` or ``@inlinable``.
264264

265+
Inlinable functions that return opaque types also have additional restrictions.
266+
The underlying concrete type cannot be changed for such a function without
267+
breaking backward compatibility, because the identity of the concrete type has
268+
been exposed by inlining the body of the function into client modules.
265269

266270
Always Emit Into Client
267271
-----------------------

include/swift/ABI/Metadata.h

Lines changed: 121 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,21 +1459,91 @@ struct TargetEnumMetadata : public TargetValueMetadata<Runtime> {
14591459
};
14601460
using EnumMetadata = TargetEnumMetadata<InProcess>;
14611461

1462+
template <typename Runtime>
1463+
struct TargetFunctionGlobalActorMetadata {
1464+
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> GlobalActorType;
1465+
};
1466+
using FunctionGlobalActorMetadata = TargetFunctionGlobalActorMetadata<InProcess>;
1467+
1468+
template <typename Runtime>
1469+
struct TargetFunctionThrownErrorMetadata {
1470+
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> ThrownErrorType;
1471+
};
1472+
using FunctionThrownErrorMetadata = TargetFunctionThrownErrorMetadata<InProcess>;
1473+
14621474
/// The structure of function type metadata.
14631475
template <typename Runtime>
1464-
struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
1476+
struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime>,
1477+
swift::ABI::TrailingObjects<
1478+
TargetFunctionTypeMetadata<Runtime>,
1479+
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata>,
1480+
ParameterFlags,
1481+
TargetFunctionMetadataDifferentiabilityKind<typename Runtime::StoredSize>,
1482+
TargetFunctionGlobalActorMetadata<Runtime>,
1483+
ExtendedFunctionTypeFlags,
1484+
TargetFunctionThrownErrorMetadata<Runtime>> {
14651485
using StoredSize = typename Runtime::StoredSize;
14661486
using Parameter = ConstTargetMetadataPointer<Runtime, swift::TargetMetadata>;
14671487

1488+
private:
1489+
using TrailingObjects =
1490+
swift::ABI::TrailingObjects<
1491+
TargetFunctionTypeMetadata<Runtime>,
1492+
Parameter,
1493+
ParameterFlags,
1494+
TargetFunctionMetadataDifferentiabilityKind<StoredSize>,
1495+
TargetFunctionGlobalActorMetadata<Runtime>,
1496+
ExtendedFunctionTypeFlags,
1497+
TargetFunctionThrownErrorMetadata<Runtime>>;
1498+
friend TrailingObjects;
1499+
1500+
template<typename T>
1501+
using OverloadToken = typename TrailingObjects::template OverloadToken<T>;
1502+
1503+
public:
14681504
TargetFunctionTypeFlags<StoredSize> Flags;
14691505

14701506
/// The type metadata for the result type.
14711507
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> ResultType;
14721508

1473-
Parameter *getParameters() { return reinterpret_cast<Parameter *>(this + 1); }
1509+
private:
1510+
size_t numTrailingObjects(OverloadToken<Parameter>) const {
1511+
return getNumParameters();
1512+
}
1513+
1514+
size_t numTrailingObjects(OverloadToken<ParameterFlags>) const {
1515+
return hasParameterFlags() ? getNumParameters() : 0;
1516+
}
1517+
1518+
size_t numTrailingObjects(
1519+
OverloadToken<TargetFunctionMetadataDifferentiabilityKind<StoredSize>>
1520+
) const {
1521+
return isDifferentiable() ? 1 : 0;
1522+
}
1523+
1524+
size_t numTrailingObjects(
1525+
OverloadToken<TargetFunctionGlobalActorMetadata<Runtime>>
1526+
) const {
1527+
return hasGlobalActor() ? 1 : 0;
1528+
}
1529+
1530+
size_t numTrailingObjects(OverloadToken<ExtendedFunctionTypeFlags>) const {
1531+
return hasExtendedFlags() ? 1 : 0;
1532+
}
1533+
1534+
size_t numTrailingObjects(
1535+
OverloadToken<TargetFunctionThrownErrorMetadata<Runtime>>
1536+
) const {
1537+
return hasThrownError() ? 1 : 0;
1538+
}
1539+
1540+
public:
1541+
Parameter *getParameters() {
1542+
return this->template getTrailingObjects<Parameter>();
1543+
}
14741544

14751545
const Parameter *getParameters() const {
1476-
return reinterpret_cast<const Parameter *>(this + 1);
1546+
return this->template getTrailingObjects<Parameter>();
14771547
}
14781548

14791549
Parameter getParameter(unsigned index) const {
@@ -1483,8 +1553,7 @@ struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
14831553

14841554
ParameterFlags getParameterFlags(unsigned index) const {
14851555
assert(index < getNumParameters());
1486-
auto flags = hasParameterFlags() ? getParameterFlags()[index] : 0;
1487-
return ParameterFlags::fromIntValue(flags);
1556+
return hasParameterFlags() ? getParameterFlags()[index] : ParameterFlags();
14881557
}
14891558

14901559
StoredSize getNumParameters() const {
@@ -1500,39 +1569,38 @@ struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
15001569
bool hasParameterFlags() const { return Flags.hasParameterFlags(); }
15011570
bool isEscaping() const { return Flags.isEscaping(); }
15021571
bool hasGlobalActor() const { return Flags.hasGlobalActor(); }
1572+
bool hasExtendedFlags() const { return Flags.hasExtendedFlags(); }
1573+
bool hasThrownError() const {
1574+
if (!Flags.hasExtendedFlags())
1575+
return false;
1576+
1577+
return getExtendedFlags().isTypedThrows();
1578+
}
15031579

15041580
static constexpr StoredSize OffsetToFlags = sizeof(TargetMetadata<Runtime>);
15051581

15061582
static bool classof(const TargetMetadata<Runtime> *metadata) {
15071583
return metadata->getKind() == MetadataKind::Function;
15081584
}
15091585

1510-
uint32_t *getParameterFlags() {
1511-
return reinterpret_cast<uint32_t *>(getParameters() + getNumParameters());
1586+
ParameterFlags *getParameterFlags() {
1587+
return this->template getTrailingObjects<ParameterFlags>();
15121588
}
15131589

1514-
const uint32_t *getParameterFlags() const {
1515-
return reinterpret_cast<const uint32_t *>(getParameters() +
1516-
getNumParameters());
1590+
const ParameterFlags *getParameterFlags() const {
1591+
return this->template getTrailingObjects<ParameterFlags>();
15171592
}
15181593

15191594
TargetFunctionMetadataDifferentiabilityKind<StoredSize> *
15201595
getDifferentiabilityKindAddress() {
15211596
assert(isDifferentiable());
1522-
void *previousEndAddr = hasParameterFlags()
1523-
? reinterpret_cast<void *>(getParameterFlags() + getNumParameters())
1524-
: reinterpret_cast<void *>(getParameters() + getNumParameters());
1525-
return reinterpret_cast<
1526-
TargetFunctionMetadataDifferentiabilityKind<StoredSize> *>(
1527-
llvm::alignAddr(previousEndAddr,
1528-
llvm::Align(alignof(typename Runtime::StoredPointer))));
1597+
return this->template getTrailingObjects<TargetFunctionMetadataDifferentiabilityKind<StoredSize>>();
15291598
}
15301599

15311600
TargetFunctionMetadataDifferentiabilityKind<StoredSize>
15321601
getDifferentiabilityKind() const {
15331602
if (isDifferentiable()) {
1534-
return *const_cast<TargetFunctionTypeMetadata<Runtime> *>(this)
1535-
->getDifferentiabilityKindAddress();
1603+
return *(this->template getTrailingObjects<TargetFunctionMetadataDifferentiabilityKind<StoredSize>>());
15361604
}
15371605
return TargetFunctionMetadataDifferentiabilityKind<StoredSize>
15381606
::NonDifferentiable;
@@ -1541,26 +1609,47 @@ struct TargetFunctionTypeMetadata : public TargetMetadata<Runtime> {
15411609
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> *
15421610
getGlobalActorAddr() {
15431611
assert(hasGlobalActor());
1544-
1545-
void *endAddr =
1546-
isDifferentiable()
1547-
? reinterpret_cast<void *>(getDifferentiabilityKindAddress() + 1) :
1548-
hasParameterFlags()
1549-
? reinterpret_cast<void *>(getParameterFlags() + getNumParameters()) :
1550-
reinterpret_cast<void *>(getParameters() + getNumParameters());
1551-
return reinterpret_cast<
1552-
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> *>(
1553-
llvm::alignAddr(
1554-
endAddr, llvm::Align(alignof(typename Runtime::StoredPointer))));
1612+
auto globalActorAddr =
1613+
this->template getTrailingObjects<TargetFunctionGlobalActorMetadata<Runtime>>();
1614+
return &globalActorAddr->GlobalActorType;
15551615
}
15561616

15571617
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata>
15581618
getGlobalActor() const {
15591619
if (!hasGlobalActor())
15601620
return ConstTargetMetadataPointer<Runtime, swift::TargetMetadata>();
1621+
auto globalActorAddr =
1622+
this->template getTrailingObjects<TargetFunctionGlobalActorMetadata<Runtime>>();
1623+
return globalActorAddr->GlobalActorType;
1624+
}
1625+
1626+
ExtendedFunctionTypeFlags *getExtendedFlagsAddr() {
1627+
assert(hasExtendedFlags());
1628+
return this->template getTrailingObjects<ExtendedFunctionTypeFlags>();
1629+
}
1630+
1631+
ExtendedFunctionTypeFlags getExtendedFlags() const {
1632+
if (!hasExtendedFlags())
1633+
return ExtendedFunctionTypeFlags();
1634+
1635+
return this->template getTrailingObjects<ExtendedFunctionTypeFlags>()[0];
1636+
}
1637+
1638+
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata> *
1639+
getThrownErrorAddr() {
1640+
assert(hasThrownError());
1641+
auto thrownErrorAddr =
1642+
this->template getTrailingObjects<TargetFunctionThrownErrorMetadata<Runtime>>();
1643+
return &thrownErrorAddr->ThrownErrorType;
1644+
}
15611645

1562-
return *const_cast<TargetFunctionTypeMetadata<Runtime> *>(this)
1563-
->getGlobalActorAddr();
1646+
ConstTargetMetadataPointer<Runtime, swift::TargetMetadata>
1647+
getThrownError() const {
1648+
if (!hasThrownError())
1649+
return ConstTargetMetadataPointer<Runtime, swift::TargetMetadata>();
1650+
auto thrownErrorAddr =
1651+
this->template getTrailingObjects<TargetFunctionThrownErrorMetadata<Runtime>>();
1652+
return thrownErrorAddr->ThrownErrorType;
15641653
}
15651654
};
15661655
using FunctionTypeMetadata = TargetFunctionTypeMetadata<InProcess>;

include/swift/ABI/MetadataValues.h

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,8 @@ class TargetFunctionTypeFlags {
10371037
GlobalActorMask = 0x10000000U,
10381038
AsyncMask = 0x20000000U,
10391039
SendableMask = 0x40000000U,
1040-
// NOTE: The next bit will need to introduce a separate flags word.
1040+
ExtendedFlagsMask = 0x80000000U,
1041+
// NOTE: No more room for flags here. Use TargetExtendedFunctionTypeFlags.
10411042
};
10421043
int_type Data;
10431044

@@ -1099,6 +1100,12 @@ class TargetFunctionTypeFlags {
10991100
(Data & ~GlobalActorMask) | (globalActor ? GlobalActorMask : 0));
11001101
}
11011102

1103+
constexpr TargetFunctionTypeFlags<int_type>
1104+
withExtendedFlags(bool extendedFlags) const {
1105+
return TargetFunctionTypeFlags<int_type>(
1106+
(Data & ~ExtendedFlagsMask) | (extendedFlags ? ExtendedFlagsMask : 0));
1107+
}
1108+
11021109
unsigned getNumParameters() const { return Data & NumParametersMask; }
11031110

11041111
FunctionMetadataConvention getConvention() const {
@@ -1127,6 +1134,10 @@ class TargetFunctionTypeFlags {
11271134
return bool (Data & GlobalActorMask);
11281135
}
11291136

1137+
bool hasExtendedFlags() const {
1138+
return bool (Data & ExtendedFlagsMask);
1139+
}
1140+
11301141
int_type getIntValue() const {
11311142
return Data;
11321143
}
@@ -1144,6 +1155,43 @@ class TargetFunctionTypeFlags {
11441155
};
11451156
using FunctionTypeFlags = TargetFunctionTypeFlags<size_t>;
11461157

1158+
/// Extended flags in a function type metadata record.
1159+
template <typename int_type>
1160+
class TargetExtendedFunctionTypeFlags {
1161+
enum : int_type {
1162+
TypedThrowsMask = 0x00000001U,
1163+
};
1164+
int_type Data;
1165+
1166+
constexpr TargetExtendedFunctionTypeFlags(int_type Data) : Data(Data) {}
1167+
public:
1168+
constexpr TargetExtendedFunctionTypeFlags() : Data(0) {}
1169+
1170+
constexpr TargetExtendedFunctionTypeFlags<int_type>
1171+
withTypedThrows(bool typedThrows) const {
1172+
return TargetExtendedFunctionTypeFlags<int_type>(
1173+
(Data & ~TypedThrowsMask) | (typedThrows ? TypedThrowsMask : 0));
1174+
}
1175+
1176+
bool isTypedThrows() const { return bool(Data & TypedThrowsMask); }
1177+
1178+
int_type getIntValue() const {
1179+
return Data;
1180+
}
1181+
1182+
static TargetExtendedFunctionTypeFlags<int_type> fromIntValue(int_type Data) {
1183+
return TargetExtendedFunctionTypeFlags(Data);
1184+
}
1185+
1186+
bool operator==(TargetExtendedFunctionTypeFlags<int_type> other) const {
1187+
return Data == other.Data;
1188+
}
1189+
bool operator!=(TargetExtendedFunctionTypeFlags<int_type> other) const {
1190+
return Data != other.Data;
1191+
}
1192+
};
1193+
using ExtendedFunctionTypeFlags = TargetExtendedFunctionTypeFlags<uint32_t>;
1194+
11471195
template <typename int_type>
11481196
class TargetParameterTypeFlags {
11491197
enum : int_type {

include/swift/AST/ASTContext.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,9 @@ class ASTContext final {
914914
/// Get the runtime availability of support for differentiation.
915915
AvailabilityContext getDifferentiationAvailability();
916916

917+
/// Get the runtime availability of support for typed throws.
918+
AvailabilityContext getTypedThrowsAvailability();
919+
917920
/// Get the runtime availability of getters and setters of multi payload enum
918921
/// tag single payloads.
919922
AvailabilityContext getMultiPayloadEnumTagSinglePayload();
@@ -982,6 +985,10 @@ class ASTContext final {
982985
/// compiler for the target platform.
983986
AvailabilityContext getSwift59Availability();
984987

988+
/// Get the runtime availability of features introduced in the Swift 5.9
989+
/// compiler for the target platform.
990+
AvailabilityContext getSwift511Availability();
991+
985992
// Note: Update this function if you add a new getSwiftXYAvailability above.
986993
/// Get the runtime availability for a particular version of Swift (5.0+).
987994
AvailabilityContext

include/swift/AST/ASTDemangler.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,8 @@ class ASTBuilder {
144144
Type createFunctionType(
145145
ArrayRef<Demangle::FunctionParam<Type>> params,
146146
Type output, FunctionTypeFlags flags,
147-
FunctionMetadataDifferentiabilityKind diffKind, Type globalActor);
147+
FunctionMetadataDifferentiabilityKind diffKind, Type globalActor,
148+
Type thrownError);
148149

149150
Type createImplFunctionType(
150151
Demangle::ImplParameterConvention calleeConvention,

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,8 @@ NOTE(compiled_module_ignored_reason,none,
440440
"compiled module '%0' was ignored because %select{%error"
441441
"|it belongs to a framework in the SDK"
442442
"|loading from module interfaces is preferred"
443-
"|it's a compiler host module}1",
443+
"|it's a compiler host module"
444+
"|the module name is blocklisted}1",
444445
(StringRef, unsigned))
445446
NOTE(out_of_date_module_here,none,
446447
"%select{compiled|cached|forwarding|prebuilt}0 module is out of date: '%1'",

0 commit comments

Comments
 (0)