Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/Serialization/Deserialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4167,6 +4167,7 @@ class DeclDeserializer {
bool isCompileTimeLiteral, isConstValue;
bool isSending;
bool isCallerIsolated;
bool isAddressable;
uint8_t rawDefaultArg;
TypeID defaultExprType;
uint8_t rawDefaultArgIsolation;
Expand All @@ -4180,6 +4181,7 @@ class DeclDeserializer {
isConstValue,
isSending,
isCallerIsolated,
isAddressable,
rawDefaultArg,
defaultExprType,
rawDefaultArgIsolation,
Expand Down Expand Up @@ -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.
Expand Down
3 changes: 2 additions & 1 deletion lib/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/Serialization/Serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4785,6 +4785,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
param->isConstVal(),
param->isSending(),
param->isCallerIsolated(),
param->isAddressable(),
getRawStableDefaultArgumentKind(argKind),
S.addTypeRef(defaultExprType),
getRawStableActorIsolationKind(isolation.getKind()),
Expand Down
23 changes: 23 additions & 0 deletions test/Serialization/Inputs/lifetime_dependence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Builtin

@frozen
@safe
public struct Ref<T: ~Copyable>: Copyable, ~Escapable {
@usableFromInline
let _pointer: UnsafePointer<T>

@_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
}
}
}
17 changes: 17 additions & 0 deletions test/Serialization/lifetime_dependence.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// 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
// REQUIRES: swift_feature_AddressableTypes
// REQUIRES: swift_feature_AddressableParameters

import lifetime_dependence_ref

public func foo() {
let x = 123
let y = Ref(x)

// CHECK: print
print(y[])
}