Skip to content

Commit dc3106f

Browse files
committed
[Serialization] Explicit function arg lifetimes.
1 parent 93f6548 commit dc3106f

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

lib/Serialization/DeserializeSIL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -946,6 +946,8 @@ SILBasicBlock *SILDeserializer::readSILBasicBlock(SILFunction *Fn,
946946
auto *fArg = CurrentBB->createFunctionArgument(SILArgTy);
947947
bool isNoImplicitCopy = (Args[I + 1] >> 16) & 0x1;
948948
fArg->setNoImplicitCopy(isNoImplicitCopy);
949+
auto lifetime = (LifetimeAnnotation::Case)((Args[I + 1] >> 17) & 0x3);
950+
fArg->setLifetimeAnnotation(lifetime);
949951
Arg = fArg;
950952
} else {
951953
auto OwnershipKind = ValueOwnershipKind((Args[I + 1] >> 8) & 0xF);

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 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 = 703; // remove builtin unsafe guaran
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 704; // _eagerMove/_lexical function argument attributes
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///

lib/Serialization/SerializeSIL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,8 +626,9 @@ void SILSerializer::writeSILBasicBlock(const SILBasicBlock &BB) {
626626
packedMetadata |= unsigned(SA->getOwnershipKind()) << 8; // 8 bits
627627
if (auto *SFA = dyn_cast<SILFunctionArgument>(SA)) {
628628
packedMetadata |= unsigned(SFA->isNoImplicitCopy()) << 16; // 1 bit
629+
packedMetadata |= unsigned(SFA->getLifetimeAnnotation()) << 17; // 2 bits
629630
}
630-
// Used: 17 bits. Free: 15.
631+
// Used: 19 bits. Free: 13.
631632
//
632633
// TODO: We should be able to shrink the packed metadata of the first two.
633634
Args.push_back(packedMetadata);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// First parse this and then emit a *.sib. Then read in the *.sib, then recreate
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: %target-sil-opt %s -emit-sib -o %t/tmp.sib -module-name eager_move
5+
// RUN: %target-sil-opt %t/tmp.sib -module-name eager_move | %FileCheck %s
6+
7+
sil_stage canonical
8+
9+
class C {}
10+
11+
// CHECK-LABEL: sil [serialized] [ossa] @one_arg_eager_move : {{.*}} {
12+
// CHECK: bb0(%0 : @_eagerMove @owned $C):
13+
// CHECK: } // end sil function 'one_arg_eager_move'
14+
sil [serialized] [ossa] @one_arg_eager_move : $@convention(thin) (@owned C) -> () {
15+
bb0(%instance : @_eagerMove @owned $C):
16+
destroy_value %instance : $C
17+
%retval = tuple()
18+
return %retval : $()
19+
}
20+
21+
// CHECK-LABEL: sil [serialized] [ossa] @one_arg_lexical : {{.*}} {
22+
// CHECK: bb0(%0 : @_lexical @owned $C):
23+
// CHECK: } // end sil function 'one_arg_lexical'
24+
sil [serialized] [ossa] @one_arg_lexical : $@convention(thin) (@owned C) -> () {
25+
bb0(%instance : @_lexical @owned $C):
26+
destroy_value %instance : $C
27+
%retval = tuple()
28+
return %retval : $()
29+
}
30+

0 commit comments

Comments
 (0)