Skip to content

Commit 1875f06

Browse files
Merge pull request #4523 from swiftwasm/main
[pull] swiftwasm from main
2 parents 01a915e + bf3eec4 commit 1875f06

24 files changed

+940
-867
lines changed

SwiftCompilerSources/Sources/SIL/BasicBlock.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ final public class BasicBlock : ListNode, CustomStringConvertible, HasName {
2525
public var function: Function { SILBasicBlock_getFunction(bridged).function }
2626

2727
public var description: String {
28-
var s = SILBasicBlock_debugDescription(bridged)
28+
let s = SILBasicBlock_debugDescription(bridged)
2929
return String(cString: s.c_str())
3030
}
3131

SwiftCompilerSources/Sources/SIL/Function.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ final public class Function : CustomStringConvertible, HasName {
2121
}
2222

2323
final public var description: String {
24-
var s = SILFunction_debugDescription(bridged)
24+
let s = SILFunction_debugDescription(bridged)
2525
return String(cString: s.c_str())
2626
}
2727

SwiftCompilerSources/Sources/SIL/GlobalVariable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ final public class GlobalVariable : CustomStringConvertible, HasName {
1919
}
2020

2121
public var description: String {
22-
var s = SILGlobalVariable_debugDescription(bridged)
22+
let s = SILGlobalVariable_debugDescription(bridged)
2323
return String(cString: s.c_str())
2424
}
2525

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class Instruction : ListNode, CustomStringConvertible, Hashable {
3838
final public var function: Function { block.function }
3939

4040
final public var description: String {
41-
var s = SILNode_debugDescription(bridgedNode)
41+
let s = SILNode_debugDescription(bridgedNode)
4242
return String(cString: s.c_str())
4343
}
4444

@@ -136,7 +136,7 @@ public class SingleValueInstruction : Instruction, Value {
136136

137137
public final class MultipleValueInstructionResult : Value {
138138
final public var description: String {
139-
var s = SILNode_debugDescription(bridgedNode)
139+
let s = SILNode_debugDescription(bridgedNode)
140140
return String(cString: s.c_str())
141141
}
142142

SwiftCompilerSources/Sources/SIL/Value.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public protocol Value : AnyObject, CustomStringConvertible {
2121

2222
extension Value {
2323
public var description: String {
24-
var s = SILNode_debugDescription(bridgedNode)
24+
let s = SILNode_debugDescription(bridgedNode)
2525
return String(cString: s.c_str())
2626
}
2727

include/swift/Runtime/Heap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace swift {
2929
// Never returns nil. The returned memory is uninitialized.
3030
//
3131
// An "alignment mask" is just the alignment (a power of 2) minus 1.
32-
SWIFT_RETURNS_NONNULL SWIFT_RUNTIME_EXPORT
32+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
3333
void *swift_slowAlloc(size_t bytes, size_t alignMask);
3434

3535
// If the caller cannot promise to zero the object during destruction,
@@ -53,7 +53,7 @@ void swift_slowDealloc(void *ptr, size_t bytes, size_t alignMask);
5353
/// This function is capable of returning well-aligned memory even on platforms
5454
/// that do not implement the C++17 "over-aligned new" feature.
5555
template <typename T, typename... Args>
56-
SWIFT_RETURNS_NONNULL
56+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD
5757
static inline T *swift_cxx_newObject(Args &&... args) {
5858
auto result = reinterpret_cast<T *>(swift_slowAlloc(sizeof(T),
5959
alignof(T) - 1));

include/swift/Runtime/HeapObject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ struct OpaqueValue;
6161
///
6262
/// POSSIBILITIES: The argument order is fair game. It may be useful
6363
/// to have a variant which guarantees zero-initialized memory.
64-
SWIFT_RETURNS_NONNULL SWIFT_RUNTIME_EXPORT
64+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
6565
HeapObject *swift_allocObject(HeapMetadata const *metadata,
6666
size_t requiredSize,
6767
size_t requiredAlignmentMask);
@@ -117,7 +117,7 @@ BoxPair swift_makeBoxUnique(OpaqueValue *buffer, Metadata const *type,
117117
size_t alignMask);
118118

119119
/// Returns the address of a heap object representing all empty box types.
120-
SWIFT_RETURNS_NONNULL SWIFT_RUNTIME_EXPORT
120+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
121121
HeapObject* swift_allocEmptyBox();
122122

123123
/// 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
@@ -307,7 +307,7 @@ swift_getGenericMetadata(MetadataRequest request,
307307
/// - installing new v-table entries and overrides; and
308308
/// - registering the class with the runtime under ObjC interop.
309309
/// Most of this work can be achieved by calling swift_initClassMetadata.
310-
SWIFT_RETURNS_NONNULL SWIFT_RUNTIME_EXPORT
310+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
311311
ClassMetadata *
312312
swift_allocateGenericClassMetadata(const ClassDescriptor *description,
313313
const void *arguments,
@@ -316,7 +316,7 @@ swift_allocateGenericClassMetadata(const ClassDescriptor *description,
316316
/// Allocate a generic value metadata object. This is intended to be
317317
/// called by the metadata instantiation function of a generic struct or
318318
/// enum.
319-
SWIFT_RETURNS_NONNULL SWIFT_RUNTIME_EXPORT
319+
SWIFT_RETURNS_NONNULL SWIFT_NODISCARD SWIFT_RUNTIME_EXPORT
320320
ValueMetadata *
321321
swift_allocateGenericValueMetadata(const ValueTypeDescriptor *description,
322322
const void *arguments,

lib/AST/DistributedDecl.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ bool AbstractFunctionDecl::isDistributedActorSystemRemoteCall(bool isVoidReturn)
472472
if (!invocationParam->isInOut()) {
473473
return false;
474474
}
475-
476475
// --- Check parameter: throwing: Err.Type
477476
auto thrownTypeParam = params->get(3);
478477
if (thrownTypeParam->getArgumentName() != C.Id_throwing) {

lib/Sema/TypeCheckAvailability.cpp

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,19 @@ bool swift::isExported(const ValueDecl *VD) {
7979
return false;
8080
}
8181

82+
static bool hasConformancesToPublicProtocols(const ExtensionDecl *ED) {
83+
auto protocols = ED->getLocalProtocols(ConformanceLookupKind::OnlyExplicit);
84+
for (const ProtocolDecl *PD : protocols) {
85+
AccessScope scope =
86+
PD->getFormalAccessScope(/*useDC*/ nullptr,
87+
/*treatUsableFromInlineAsPublic*/ true);
88+
if (scope.isPublic())
89+
return true;
90+
}
91+
92+
return false;
93+
}
94+
8295
bool swift::isExported(const ExtensionDecl *ED) {
8396
// An extension can only be exported if it extends an exported type.
8497
if (auto *NTD = ED->getExtendedNominal()) {
@@ -94,14 +107,8 @@ bool swift::isExported(const ExtensionDecl *ED) {
94107

95108
// If the extension declares a conformance to a public protocol then the
96109
// extension is exported.
97-
auto protocols = ED->getLocalProtocols(ConformanceLookupKind::OnlyExplicit);
98-
for (const ProtocolDecl *PD : protocols) {
99-
AccessScope scope =
100-
PD->getFormalAccessScope(/*useDC*/nullptr,
101-
/*treatUsableFromInlineAsPublic*/true);
102-
if (scope.isPublic())
103-
return true;
104-
}
110+
if (hasConformancesToPublicProtocols(ED))
111+
return true;
105112

106113
return false;
107114
}
@@ -313,7 +320,7 @@ static bool hasActiveAvailableAttribute(Decl *D,
313320
return getActiveAvailableAttribute(D, AC);
314321
}
315322

316-
static bool bodyIsResilienceBoundary(Decl *D) {
323+
static bool shouldConstrainBodyToDeploymentTarget(Decl *D) {
317324
// The declaration contains code...
318325
if (auto afd = dyn_cast<AbstractFunctionDecl>(D)) {
319326
// And it has a location so we can check it...
@@ -526,9 +533,7 @@ class TypeRefinementContextBuilder : private ASTWalker {
526533
AvailabilityContext DeclInfo = ExplicitDeclInfo;
527534
DeclInfo.intersectWith(getCurrentTRC()->getAvailabilityInfo());
528535

529-
// If the entire declaration is surrounded by a resilience boundary, it is
530-
// also constrained by the deployment target.
531-
if (signatureIsResilienceBoundary(D))
536+
if (shouldConstrainSignatureToDeploymentTarget(D))
532537
DeclInfo.intersectWith(AvailabilityContext::forDeploymentTarget(Context));
533538

534539
SourceRange Range = refinementSourceRangeForDecl(D);
@@ -562,9 +567,10 @@ class TypeRefinementContextBuilder : private ASTWalker {
562567
}
563568

564569
// No need to introduce a context if the declaration does not have an
565-
// availability attribute and the signature is not a resilience boundary.
570+
// availability attribute and the signature does not constrain availability
571+
// to the deployment target.
566572
if (!hasActiveAvailableAttribute(D, Context) &&
567-
!signatureIsResilienceBoundary(D)) {
573+
!shouldConstrainSignatureToDeploymentTarget(D)) {
568574
return false;
569575
}
570576

@@ -581,12 +587,23 @@ class TypeRefinementContextBuilder : private ASTWalker {
581587
return true;
582588
}
583589

584-
/// A declaration's signature is a resilience boundary if the entire
585-
/// declaration--not just the body--is not ABI-public and it's in a context
586-
/// where ABI-public declarations would be available below the minimum
587-
/// deployment target.
588-
bool signatureIsResilienceBoundary(Decl *D) {
589-
return !isCurrentTRCContainedByDeploymentTarget() && !::isExported(D);
590+
/// Checks whether the entire declaration, including its signature, should be
591+
/// constrained to the deployment target. Generally public API declarations
592+
/// are not constrained since they appear in the interface of the module and
593+
/// may be consumed by clients with lower deployment targets, but there are
594+
/// some exceptions.
595+
bool shouldConstrainSignatureToDeploymentTarget(Decl *D) {
596+
if (isCurrentTRCContainedByDeploymentTarget())
597+
return false;
598+
599+
// As a convenience, SPI decls and explicitly unavailable decls are
600+
// constrained to the deployment target. There's not much benefit to
601+
// checking these declarations at a lower availability version floor since
602+
// neither can be used by API clients.
603+
if (D->isSPI() || AvailableAttr::isUnavailable(D))
604+
return true;
605+
606+
return !::isExported(D);
590607
}
591608

592609
/// Returns the source range which should be refined by declaration. This
@@ -633,14 +650,14 @@ class TypeRefinementContextBuilder : private ASTWalker {
633650
}
634651

635652
bool bodyIntroducesNewContext(Decl *D) {
636-
// Are we already effectively in a resilience boundary? If not, adding one
637-
// wouldn't change availability.
653+
// Are we already constrained by the deployment target? If not, adding a
654+
// new context wouldn't change availability.
638655
if (isCurrentTRCContainedByDeploymentTarget())
639656
return false;
640657

641-
// If we're in a function, is its body a resilience boundary?
658+
// If we're in a function, check if it ought to use the deployment target.
642659
if (auto afd = dyn_cast<AbstractFunctionDecl>(D))
643-
return bodyIsResilienceBoundary(afd);
660+
return shouldConstrainBodyToDeploymentTarget(afd);
644661

645662
// The only other case we care about is top-level code.
646663
return isa<TopLevelCodeDecl>(D);
@@ -4089,14 +4106,7 @@ void swift::checkExplicitAvailability(Decl *decl) {
40894106
return false;
40904107
});
40914108

4092-
auto protocols = extension->getLocalProtocols(ConformanceLookupKind::OnlyExplicit);
4093-
auto hasProtocols = std::any_of(protocols.begin(), protocols.end(),
4094-
[](const ProtocolDecl *PD) -> bool {
4095-
AccessScope scope =
4096-
PD->getFormalAccessScope(/*useDC*/nullptr,
4097-
/*treatUsableFromInlineAsPublic*/true);
4098-
return scope.isPublic();
4099-
});
4109+
auto hasProtocols = hasConformancesToPublicProtocols(extension);
41004110

41014111
if (!hasMembers && !hasProtocols) return;
41024112

lib/Serialization/DeserializeSIL.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1346,7 +1346,6 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
13461346
ONEOPERAND_ONETYPE_INST(RefTo##Name) \
13471347
ONEOPERAND_ONETYPE_INST(Name##ToRef)
13481348
#include "swift/AST/ReferenceStorage.def"
1349-
ONEOPERAND_ONETYPE_INST(UncheckedRefCast)
13501349
ONEOPERAND_ONETYPE_INST(UncheckedAddrCast)
13511350
ONEOPERAND_ONETYPE_INST(UncheckedTrivialBitCast)
13521351
ONEOPERAND_ONETYPE_INST(UncheckedBitwiseCast)
@@ -2670,6 +2669,17 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
26702669
failureBB);
26712670
break;
26722671
}
2672+
case SILInstructionKind::UncheckedRefCastInst: {
2673+
assert(RecordKind == SIL_ONE_TYPE_ONE_OPERAND &&
2674+
"Layout should be OneTypeOneOperand.");
2675+
auto *urc = Builder.createUncheckedRefCast(Loc,
2676+
getLocalValue(ValID, getSILType(MF->getType(TyID2),
2677+
(SILValueCategory)TyCategory2, Fn)),
2678+
getSILType(MF->getType(TyID), (SILValueCategory)TyCategory, Fn));
2679+
urc->setForwardingOwnershipKind(decodeValueOwnership(Attr));
2680+
ResultInst = urc;
2681+
break;
2682+
}
26732683
case SILInstructionKind::UncheckedRefCastAddrInst: {
26742684
CanType sourceType = MF->getType(ListOfValues[0])->getCanonicalType();
26752685
// ignore attr.

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5656
/// describe what change you made. The content of this comment isn't important;
5757
/// it just ensures a conflict if two people change the module format.
5858
/// Don't worry about adhering to the 80-column limit for this line.
59-
const uint16_t SWIFTMODULE_VERSION_MINOR = 688; // SILBoxType extensions
59+
const uint16_t SWIFTMODULE_VERSION_MINOR = 689; // cast ownership serialization
6060

6161
/// A standard hash seed used for all string hashes in a serialized module.
6262
///

lib/Serialization/SILFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ namespace sil_block {
331331
using SILOneTypeOneOperandLayout = BCRecordLayout<
332332
SIL_ONE_TYPE_ONE_OPERAND,
333333
SILInstOpCodeField,
334-
BCFixed<1>, // Optional attribute
334+
BCFixed<2>, // Optional attribute
335335
TypeIDField,
336336
SILTypeCategoryField,
337337
TypeIDField,

lib/Serialization/SerializeSIL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1756,6 +1756,8 @@ void SILSerializer::writeSILInstruction(const SILInstruction &SI) {
17561756
if (SI.getKind() == SILInstructionKind::ConvertFunctionInst) {
17571757
if (cast<ConvertFunctionInst>(SI).withoutActuallyEscaping())
17581758
attrs |= 0x01;
1759+
} else if (auto *refCast = dyn_cast<UncheckedRefCastInst>(&SI)) {
1760+
attrs = encodeValueOwnership(refCast->getOwnershipKind());
17591761
}
17601762
writeConversionLikeInstruction(cast<SingleValueInstruction>(&SI), attrs);
17611763
break;

stdlib/public/Distributed/DistributedActorSystem.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
import Swift
1313
import _Concurrency
1414

15-
/// A distributed actor system
15+
/// A distributed actor system is what enables all functionality of distributed actors.
16+
///
17+
/// Distributed actors must always be associated with a concrete distributed actor system,
18+
/// and do so by declaring a `typealias ActorSystem = ...`, or by having a module wide
19+
/// `typealias DefaultDistributedActorSystem` declared which then applies to all distributed
20+
/// actors that do not declare a specific type alias in their bodies.
1621
@available(SwiftStdlib 5.7, *)
1722
public protocol DistributedActorSystem: Sendable {
1823
/// The identity used by actors that communicate via this transport

0 commit comments

Comments
 (0)