Skip to content

Commit 4fb9e6e

Browse files
authored
Merge pull request #84748 from Azoy/62-deserialization-issue
[6.2] [Serialization] Serialize isAddressable on param decls
2 parents 6c88224 + 9c4a299 commit 4fb9e6e

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

lib/Serialization/Deserialization.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4118,6 +4118,7 @@ class DeclDeserializer {
41184118
bool isCompileTimeLiteral, isConstValue;
41194119
bool isSending;
41204120
bool isCallerIsolated;
4121+
bool isAddressable;
41214122
uint8_t rawDefaultArg;
41224123
TypeID defaultExprType;
41234124
uint8_t rawDefaultArgIsolation;
@@ -4131,6 +4132,7 @@ class DeclDeserializer {
41314132
isConstValue,
41324133
isSending,
41334134
isCallerIsolated,
4135+
isAddressable,
41344136
rawDefaultArg,
41354137
defaultExprType,
41364138
rawDefaultArgIsolation,
@@ -4177,6 +4179,7 @@ class DeclDeserializer {
41774179
param->setConstValue(isConstValue);
41784180
param->setSending(isSending);
41794181
param->setCallerIsolated(isCallerIsolated);
4182+
param->setAddressable(isAddressable);
41804183

41814184
// Decode the default argument kind.
41824185
// 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 = 948; // @_expose kind
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 949; // serialize param decl isAddressable
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///
@@ -1730,6 +1730,7 @@ namespace decls_block {
17301730
BCFixed<1>, // isConst?
17311731
BCFixed<1>, // isSending?
17321732
BCFixed<1>, // isCallerIsolated?
1733+
BCFixed<1>, // isAddressable?
17331734
DefaultArgumentField, // default argument kind
17341735
TypeIDField, // default argument type
17351736
ActorIsolationField, // default argument isolation

lib/Serialization/Serialization.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4764,6 +4764,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
47644764
param->isConstVal(),
47654765
param->isSending(),
47664766
param->isCallerIsolated(),
4767+
param->isAddressable(),
47674768
getRawStableDefaultArgumentKind(argKind),
47684769
S.addTypeRef(defaultExprType),
47694770
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: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
// REQUIRES: swift_feature_AddressableTypes
7+
// REQUIRES: swift_feature_AddressableParameters
8+
9+
import lifetime_dependence_ref
10+
11+
public func foo() {
12+
let x = 123
13+
let y = Ref(x)
14+
15+
// CHECK: print
16+
print(y[])
17+
}

0 commit comments

Comments
 (0)