Skip to content

Commit 898b875

Browse files
committed
SIL: add some Instruction/Builder APIs
* `var UncheckedValueCastInst.fromValue` * `BeginApplyInst.isNonThrowing` and `BeginApplyInst.isNonAsync` * `Builder.createUncheckedValueCast`
1 parent 2cd625a commit 898b875

File tree

4 files changed

+28
-1
lines changed

4 files changed

+28
-1
lines changed

SwiftCompilerSources/Sources/SIL/Builder.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,11 @@ public struct Builder {
289289
return notifyNew(cast.getAs(UncheckedAddrCastInst.self))
290290
}
291291

292+
public func createUncheckedValueCast(from value: Value, to type: Type) -> UncheckedValueCastInst {
293+
let cast = bridged.createUncheckedValueCast(value.bridged, type.bridged)
294+
return notifyNew(cast.getAs(UncheckedValueCastInst.self))
295+
}
296+
292297
public func createUpcast(from value: Value, to type: Type) -> UpcastInst {
293298
let cast = bridged.createUpcast(value.bridged, type.bridged)
294299
return notifyNew(cast.getAs(UpcastInst.self))

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,9 @@ final public class UncheckedTrivialBitCastInst : SingleValueInstruction, UnaryIn
788788
}
789789

790790
final public class UncheckedBitwiseCastInst : SingleValueInstruction, UnaryInstruction {}
791-
final public class UncheckedValueCastInst : SingleValueInstruction, UnaryInstruction {}
791+
final public class UncheckedValueCastInst : SingleValueInstruction, UnaryInstruction {
792+
public var fromValue: Value { operand.value }
793+
}
792794

793795
final public class RefToRawPointerInst : SingleValueInstruction, UnaryInstruction {}
794796
final public class RefToUnmanagedInst : SingleValueInstruction, UnaryInstruction {}
@@ -1719,6 +1721,9 @@ final public class BeginApplyInst : MultipleValueInstruction, FullApplySite {
17191721
public var yieldedValues: Results {
17201722
Results(inst: self, numResults: resultCount - (isCalleeAllocated ? 2 : 1))
17211723
}
1724+
1725+
public var isNonThrowing: Bool { bridged.BeginApplyInst_getNonThrowing() }
1726+
public var isNonAsync: Bool { bridged.BeginApplyInst_getNonAsync() }
17221727
}
17231728

17241729
final public class EndApplyInst : SingleValueInstruction, UnaryInstruction {

include/swift/SIL/SILBridging.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,8 @@ struct BridgedInstruction {
816816
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGenericSpecializationInformation ApplyInst_getSpecializationInfo() const;
817817
BRIDGED_INLINE bool TryApplyInst_getNonAsync() const;
818818
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedGenericSpecializationInformation TryApplyInst_getSpecializationInfo() const;
819+
BRIDGED_INLINE bool BeginApplyInst_getNonThrowing() const;
820+
BRIDGED_INLINE bool BeginApplyInst_getNonAsync() const;
819821
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclRef ClassMethodInst_getMember() const;
820822
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedDeclRef WitnessMethodInst_getMember() const;
821823
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedCanType WitnessMethodInst_getLookupType() const;
@@ -1229,6 +1231,8 @@ struct BridgedBuilder{
12291231
BridgedType type) const;
12301232
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUncheckedAddrCast(BridgedValue op,
12311233
BridgedType type) const;
1234+
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUncheckedValueCast(BridgedValue op,
1235+
BridgedType type) const;
12321236
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createUpcast(BridgedValue op, BridgedType type) const;
12331237
SWIFT_IMPORT_UNSAFE BRIDGED_INLINE BridgedInstruction createCheckedCastAddrBranch(
12341238
BridgedValue source, BridgedCanType sourceFormalType,

include/swift/SIL/SILBridgingImpl.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1349,6 +1349,14 @@ BridgedGenericSpecializationInformation BridgedInstruction::TryApplyInst_getSpec
13491349
return {getAs<swift::TryApplyInst>()->getSpecializationInfo()};
13501350
}
13511351

1352+
bool BridgedInstruction::BeginApplyInst_getNonThrowing() const {
1353+
return getAs<swift::BeginApplyInst>()->isNonThrowing();
1354+
}
1355+
1356+
bool BridgedInstruction::BeginApplyInst_getNonAsync() const {
1357+
return getAs<swift::BeginApplyInst>()->isNonAsync();
1358+
}
1359+
13521360
BridgedDeclRef BridgedInstruction::ClassMethodInst_getMember() const {
13531361
return getAs<swift::ClassMethodInst>()->getMember();
13541362
}
@@ -2301,6 +2309,11 @@ BridgedInstruction BridgedBuilder::createUncheckedAddrCast(BridgedValue op, Brid
23012309
type.unbridged())};
23022310
}
23032311

2312+
BridgedInstruction BridgedBuilder::createUncheckedValueCast(BridgedValue op, BridgedType type) const {
2313+
return {unbridged().createUncheckedValueCast(regularLoc(), op.getSILValue(),
2314+
type.unbridged())};
2315+
}
2316+
23042317
BridgedInstruction BridgedBuilder::createUpcast(BridgedValue op, BridgedType type) const {
23052318
return {unbridged().createUpcast(regularLoc(), op.getSILValue(),
23062319
type.unbridged())};

0 commit comments

Comments
 (0)