From dd006e073aa548f399e65bea8ee22eea351c6e1a Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 1 Oct 2025 10:59:07 -0700 Subject: [PATCH 1/2] Serialize isAddressable on param decls --- lib/Serialization/Deserialization.cpp | 3 +++ lib/Serialization/ModuleFormat.h | 3 ++- lib/Serialization/Serialization.cpp | 1 + .../Inputs/lifetime_dependence.swift | 23 +++++++++++++++++++ test/Serialization/lifetime_dependence.swift | 15 ++++++++++++ 5 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 test/Serialization/Inputs/lifetime_dependence.swift create mode 100644 test/Serialization/lifetime_dependence.swift diff --git a/lib/Serialization/Deserialization.cpp b/lib/Serialization/Deserialization.cpp index 3246e46a6205a..ab9ec19fafaba 100644 --- a/lib/Serialization/Deserialization.cpp +++ b/lib/Serialization/Deserialization.cpp @@ -4167,6 +4167,7 @@ class DeclDeserializer { bool isCompileTimeLiteral, isConstValue; bool isSending; bool isCallerIsolated; + bool isAddressable; uint8_t rawDefaultArg; TypeID defaultExprType; uint8_t rawDefaultArgIsolation; @@ -4180,6 +4181,7 @@ class DeclDeserializer { isConstValue, isSending, isCallerIsolated, + isAddressable, rawDefaultArg, defaultExprType, rawDefaultArgIsolation, @@ -4226,6 +4228,7 @@ class DeclDeserializer { param->setConstValue(isConstValue); param->setSending(isSending); param->setCallerIsolated(isCallerIsolated); + param->setAddressable(isAddressable); // Decode the default argument kind. // FIXME: Default argument expression, if available. diff --git a/lib/Serialization/ModuleFormat.h b/lib/Serialization/ModuleFormat.h index cacdc8939727e..2c527272e69de 100644 --- a/lib/Serialization/ModuleFormat.h +++ b/lib/Serialization/ModuleFormat.h @@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0; /// describe what change you made. The content of this comment isn't important; /// it just ensures a conflict if two people change the module format. /// Don't worry about adhering to the 80-column limit for this line. -const uint16_t SWIFTMODULE_VERSION_MINOR = 963; // Add @inline(always) +const uint16_t SWIFTMODULE_VERSION_MINOR = 964; // serialize param decl isAddressable /// A standard hash seed used for all string hashes in a serialized module. /// @@ -1746,6 +1746,7 @@ namespace decls_block { BCFixed<1>, // isConst? BCFixed<1>, // isSending? BCFixed<1>, // isCallerIsolated? + BCFixed<1>, // isAddressable? DefaultArgumentField, // default argument kind TypeIDField, // default argument type ActorIsolationField, // default argument isolation diff --git a/lib/Serialization/Serialization.cpp b/lib/Serialization/Serialization.cpp index 4dd158def15b5..0995a50cd61c2 100644 --- a/lib/Serialization/Serialization.cpp +++ b/lib/Serialization/Serialization.cpp @@ -4785,6 +4785,7 @@ class Serializer::DeclSerializer : public DeclVisitor { param->isConstVal(), param->isSending(), param->isCallerIsolated(), + param->isAddressable(), getRawStableDefaultArgumentKind(argKind), S.addTypeRef(defaultExprType), getRawStableActorIsolationKind(isolation.getKind()), diff --git a/test/Serialization/Inputs/lifetime_dependence.swift b/test/Serialization/Inputs/lifetime_dependence.swift new file mode 100644 index 0000000000000..6d547e070d8da --- /dev/null +++ b/test/Serialization/Inputs/lifetime_dependence.swift @@ -0,0 +1,23 @@ +import Builtin + +@frozen +@safe +public struct Ref: Copyable, ~Escapable { + @usableFromInline + let _pointer: UnsafePointer + + @_lifetime(borrow value) + @_alwaysEmitIntoClient + @_transparent + public init(_ value: borrowing @_addressable T) { + unsafe _pointer = UnsafePointer(Builtin.unprotectedAddressOfBorrow(value)) + } + + @_alwaysEmitIntoClient + public subscript() -> T { + @_transparent + unsafeAddress { + unsafe _pointer + } + } +} diff --git a/test/Serialization/lifetime_dependence.swift b/test/Serialization/lifetime_dependence.swift new file mode 100644 index 0000000000000..c3a4361765dd9 --- /dev/null +++ b/test/Serialization/lifetime_dependence.swift @@ -0,0 +1,15 @@ +// RUN: %empty-directory(%t) +// RUN: %target-swift-frontend -emit-module -enable-builtin-module -enable-experimental-feature Lifetimes -enable-experimental-feature AddressableTypes -enable-experimental-feature AddressableParameters -module-name lifetime_dependence_ref -o %t %S/Inputs/lifetime_dependence.swift +// RUN: %target-swift-frontend -I %t -emit-ir %s -verify | %FileCheck %s + +// REQUIRES: swift_feature_Lifetimes + +import lifetime_dependence_ref + +public func foo() { + let x = 123 + let y = Ref(x) + + // CHECK: print + print(y[]) +} From cf8ccca71c05bd9ed32f35e9397852767bbbe110 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Wed, 1 Oct 2025 12:56:37 -0700 Subject: [PATCH 2/2] Update lifetime_dependence.swift --- test/Serialization/lifetime_dependence.swift | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/Serialization/lifetime_dependence.swift b/test/Serialization/lifetime_dependence.swift index c3a4361765dd9..1240e3328c3c8 100644 --- a/test/Serialization/lifetime_dependence.swift +++ b/test/Serialization/lifetime_dependence.swift @@ -3,6 +3,8 @@ // RUN: %target-swift-frontend -I %t -emit-ir %s -verify | %FileCheck %s // REQUIRES: swift_feature_Lifetimes +// REQUIRES: swift_feature_AddressableTypes +// REQUIRES: swift_feature_AddressableParameters import lifetime_dependence_ref