Skip to content

Commit dd006e0

Browse files
committed
Serialize isAddressable on param decls
1 parent 9f30c85 commit dd006e0

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4167,6 +4167,7 @@ class DeclDeserializer {
41674167
bool isCompileTimeLiteral, isConstValue;
41684168
bool isSending;
41694169
bool isCallerIsolated;
4170+
bool isAddressable;
41704171
uint8_t rawDefaultArg;
41714172
TypeID defaultExprType;
41724173
uint8_t rawDefaultArgIsolation;
@@ -4180,6 +4181,7 @@ class DeclDeserializer {
41804181
isConstValue,
41814182
isSending,
41824183
isCallerIsolated,
4184+
isAddressable,
41834185
rawDefaultArg,
41844186
defaultExprType,
41854187
rawDefaultArgIsolation,
@@ -4226,6 +4228,7 @@ class DeclDeserializer {
42264228
param->setConstValue(isConstValue);
42274229
param->setSending(isSending);
42284230
param->setCallerIsolated(isCallerIsolated);
4231+
param->setAddressable(isAddressable);
42294232

42304233
// Decode the default argument kind.
42314234
// FIXME: Default argument expression, if available.

lib/Serialization/ModuleFormat.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 963; // Add @inline(always)
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 964; // serialize param decl isAddressable
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -1746,6 +1746,7 @@ namespace decls_block {
17461746
BCFixed<1>, // isConst?
17471747
BCFixed<1>, // isSending?
17481748
BCFixed<1>, // isCallerIsolated?
1749+
BCFixed<1>, // isAddressable?
17491750
DefaultArgumentField, // default argument kind
17501751
TypeIDField, // default argument type
17511752
ActorIsolationField, // default argument isolation

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4785,6 +4785,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
47854785
param->isConstVal(),
47864786
param->isSending(),
47874787
param->isCallerIsolated(),
4788+
param->isAddressable(),
47884789
getRawStableDefaultArgumentKind(argKind),
47894790
S.addTypeRef(defaultExprType),
47904791
getRawStableActorIsolationKind(isolation.getKind()),
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import Builtin
2+
3+
@frozen
4+
@safe
5+
public struct Ref<T: ~Copyable>: Copyable, ~Escapable {
6+
@usableFromInline
7+
let _pointer: UnsafePointer<T>
8+
9+
@_lifetime(borrow value)
10+
@_alwaysEmitIntoClient
11+
@_transparent
12+
public init(_ value: borrowing @_addressable T) {
13+
unsafe _pointer = UnsafePointer(Builtin.unprotectedAddressOfBorrow(value))
14+
}
15+
16+
@_alwaysEmitIntoClient
17+
public subscript() -> T {
18+
@_transparent
19+
unsafeAddress {
20+
unsafe _pointer
21+
}
22+
}
23+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %empty-directory(%t)
2+
// 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
3+
// RUN: %target-swift-frontend -I %t -emit-ir %s -verify | %FileCheck %s
4+
5+
// REQUIRES: swift_feature_Lifetimes
6+
7+
import lifetime_dependence_ref
8+
9+
public func foo() {
10+
let x = 123
11+
let y = Ref(x)
12+
13+
// CHECK: print
14+
print(y[])
15+
}

0 commit comments

Comments
 (0)