Skip to content

Commit 8074ce0

Browse files
committed
[SIL] Function args may have lifetime annotations.
By default, whether a function argument's lifetime is determined by its type. To allow that behavior to be overridden on an argument-by-argument basis, the argument may have its own lifetime.
1 parent f3ea548 commit 8074ce0

File tree

1 file changed

+25
-6
lines changed

1 file changed

+25
-6
lines changed

include/swift/SIL/SILArgument.h

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@
1313
#ifndef SWIFT_SIL_SILARGUMENT_H
1414
#define SWIFT_SIL_SILARGUMENT_H
1515

16+
#include "swift/AST/LifetimeAnnotation.h"
1617
#include "swift/Basic/Compiler.h"
18+
#include "swift/SIL/Lifetime.h"
1719
#include "swift/SIL/SILArgumentConvention.h"
18-
#include "swift/SIL/SILValue.h"
1920
#include "swift/SIL/SILFunctionConventions.h"
21+
#include "swift/SIL/SILValue.h"
2022

2123
namespace swift {
2224

@@ -327,14 +329,17 @@ class SILFunctionArgument : public SILArgument {
327329
friend class SILBasicBlock;
328330

329331
bool noImplicitCopy = false;
332+
LifetimeAnnotation lifetimeAnnotation = LifetimeAnnotation::None;
330333

331-
SILFunctionArgument(SILBasicBlock *parentBlock, SILType type,
332-
ValueOwnershipKind ownershipKind,
333-
const ValueDecl *decl = nullptr,
334-
bool isNoImplicitCopy = false)
334+
SILFunctionArgument(
335+
SILBasicBlock *parentBlock, SILType type,
336+
ValueOwnershipKind ownershipKind, const ValueDecl *decl = nullptr,
337+
bool isNoImplicitCopy = false,
338+
LifetimeAnnotation lifetimeAnnotation = LifetimeAnnotation::None)
335339
: SILArgument(ValueKind::SILFunctionArgument, parentBlock, type,
336340
ownershipKind, decl),
337-
noImplicitCopy(isNoImplicitCopy) {}
341+
noImplicitCopy(isNoImplicitCopy),
342+
lifetimeAnnotation(lifetimeAnnotation) {}
338343
// A special constructor, only intended for use in
339344
// SILBasicBlock::replaceFunctionArg.
340345
explicit SILFunctionArgument(SILType type, ValueOwnershipKind ownershipKind,
@@ -347,6 +352,20 @@ class SILFunctionArgument : public SILArgument {
347352

348353
void setNoImplicitCopy(bool newValue) { noImplicitCopy = newValue; }
349354

355+
LifetimeAnnotation getLifetimeAnnotation() const {
356+
return lifetimeAnnotation;
357+
}
358+
359+
void setLifetimeAnnotation(LifetimeAnnotation newValue) {
360+
lifetimeAnnotation = newValue;
361+
}
362+
363+
Lifetime getLifetime() const {
364+
return getType()
365+
.getLifetime(*getFunction())
366+
.getLifetimeForAnnotatedValue(getLifetimeAnnotation());
367+
}
368+
350369
bool isIndirectResult() const;
351370

352371
SILArgumentConvention getArgumentConvention() const;

0 commit comments

Comments
 (0)