Skip to content

Commit 11631c0

Browse files
committed
SIL: make isLexical a protocol requirement of Value
This avoids the need for checking if a value is a `move_value`, `begin_borrow` or function argument to get the is-lexical information.
1 parent 418e9d4 commit 11631c0

File tree

5 files changed

+23
-2
lines changed

5 files changed

+23
-2
lines changed

SwiftCompilerSources/Sources/SIL/Argument.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public class Argument : Value, Hashable {
3232

3333
public var isReborrow: Bool { bridged.isReborrow() }
3434

35+
public var isLexical: Bool { false }
36+
3537
public var varDecl: VarDecl? { bridged.getVarDecl().getAs(VarDecl.self) }
3638

3739
public var sourceLoc: SourceLoc? { varDecl?.nameLoc }
@@ -50,6 +52,10 @@ final public class FunctionArgument : Argument {
5052
parentFunction.argumentConventions[index]
5153
}
5254

55+
public override var isLexical: Bool {
56+
bridged.FunctionArgument_isLexical()
57+
}
58+
5359
public var isSelf: Bool {
5460
parentFunction.argumentConventions.selfIndex == index
5561
}

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ public class SingleValueInstruction : Instruction, Value {
198198
public static func ==(lhs: SingleValueInstruction, rhs: SingleValueInstruction) -> Bool {
199199
lhs === rhs
200200
}
201+
202+
public var isLexical: Bool { false }
201203
}
202204

203205
public final class MultipleValueInstructionResult : Value, Hashable {
@@ -209,6 +211,8 @@ public final class MultipleValueInstructionResult : Value, Hashable {
209211

210212
public var parentBlock: BasicBlock { parentInstruction.parentBlock }
211213

214+
public var isLexical: Bool { false }
215+
212216
public var index: Int { bridged.getIndex() }
213217

214218
var bridged: BridgedMultiValueResult {
@@ -1028,7 +1032,7 @@ final public class UncheckedOwnershipConversionInst : SingleValueInstruction {}
10281032
final public class MoveValueInst : SingleValueInstruction, UnaryInstruction {
10291033
public var fromValue: Value { operand.value }
10301034

1031-
public var isLexical: Bool { bridged.MoveValue_isLexical() }
1035+
public override var isLexical: Bool { bridged.MoveValue_isLexical() }
10321036
public var hasPointerEscape: Bool { bridged.MoveValue_hasPointerEscape() }
10331037
public var isFromVarDecl: Bool { bridged.MoveValue_isFromVarDecl() }
10341038
}
@@ -1253,7 +1257,7 @@ extension BorrowIntroducingInstruction {
12531257
final public class BeginBorrowInst : SingleValueInstruction, UnaryInstruction, BorrowIntroducingInstruction {
12541258
public var borrowedValue: Value { operand.value }
12551259

1256-
public var isLexical: Bool { bridged.BeginBorrow_isLexical() }
1260+
public override var isLexical: Bool { bridged.BeginBorrow_isLexical() }
12571261
public var hasPointerEscape: Bool { bridged.BeginBorrow_hasPointerEscape() }
12581262
public var isFromVarDecl: Bool { bridged.BeginBorrow_isFromVarDecl() }
12591263

SwiftCompilerSources/Sources/SIL/Value.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public protocol Value : AnyObject, CustomStringConvertible {
3737

3838
/// True if the value has a trivial type which is and does not contain a Builtin.RawPointer.
3939
var hasTrivialNonPointerType: Bool { get }
40+
41+
var isLexical: Bool { get }
4042
}
4143

4244
public enum Ownership {
@@ -269,6 +271,8 @@ public final class Undef : Value {
269271
/// Undef has not parent function, therefore the default `hasTrivialNonPointerType` does not work.
270272
/// Return the conservative default in this case.
271273
public var hasTrivialNonPointerType: Bool { false }
274+
275+
public var isLexical: Bool { false }
272276
}
273277

274278
final class PlaceholderValue : Value {
@@ -278,6 +282,8 @@ final class PlaceholderValue : Value {
278282
fatalError("PlaceholderValue has no defining block")
279283
}
280284

285+
public var isLexical: Bool { false }
286+
281287
public var parentFunction: Function { bridged.PlaceholderValue_getParentFunction().function }
282288
}
283289

include/swift/SIL/SILBridging.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,7 @@ struct BridgedArgument {
865865
BRIDGED_INLINE swift::SILArgument * _Nonnull getArgument() const;
866866
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedBasicBlock getParent() const;
867867
BRIDGED_INLINE bool isReborrow() const;
868+
BRIDGED_INLINE bool FunctionArgument_isLexical() const;
868869
BRIDGED_INLINE void setReborrow(bool reborrow) const;
869870
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE OptionalBridgedDeclObj getVarDecl() const;
870871
BRIDGED_INLINE void copyFlags(BridgedArgument fromArgument) const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,10 @@ void BridgedArgument::setReborrow(bool reborrow) const {
676676
getArgument()->setReborrow(reborrow);
677677
}
678678

679+
bool BridgedArgument::FunctionArgument_isLexical() const {
680+
return llvm::cast<swift::SILFunctionArgument>(getArgument())->getLifetime().isLexical();
681+
}
682+
679683
OptionalBridgedDeclObj BridgedArgument::getVarDecl() const {
680684
return {llvm::dyn_cast_or_null<swift::VarDecl>(getArgument()->getDecl())};
681685
}

0 commit comments

Comments
 (0)