1010//
1111//===----------------------------------------------------------------------===//
1212
13- import SIL
14- import OptimizerBridging
13+ import SILBridging
1514
15+ /// To add verification for a specific instruction, let the instruction class conform to
16+ /// this protocol and implement the `verify` method.
1617private protocol VerifiableInstruction : Instruction {
17- func verify( _ context: FunctionPassContext )
18+ func verify( _ context: VerifierContext )
1819}
1920
2021private func require( _ condition: Bool , _ message: @autoclosure ( ) -> String , atInstruction: Instruction ? = nil ) {
2122 if !condition {
2223 let msg = message ( )
2324 msg. _withBridgedStringRef { stringRef in
24- verifierError ( stringRef, atInstruction. bridged, Optional < Argument > . none. bridged)
25+ BridgedVerifier . verifierError ( stringRef, atInstruction. bridged, Optional < Argument > . none. bridged)
2526 }
2627 }
2728}
2829
30+ struct VerifierContext : Context {
31+ let _bridged : BridgedContext
32+ }
33+
2934extension Function {
30- func verify( _ context: FunctionPassContext ) {
35+ func verify( _ context: VerifierContext ) {
3136 for block in blocks {
3237 for arg in block. arguments {
3338 arg. verify ( context)
@@ -63,16 +68,17 @@ private extension Instruction {
6368}
6469
6570private extension Argument {
66- func verify( _ context: FunctionPassContext ) {
71+ func verify( _ context: VerifierContext ) {
6772 if let phi = Phi ( self ) , phi. value. ownership == . guaranteed {
6873
6974 phi. verifyBorrowedFromUse ( )
7075
71- require ( phi . isReborrow == phi . hasBorrowEndingUse ||
72- // In a dead-end block an end_borrow might have been deleted.
73- // TODO: this check is not needed anymore once we have complete OSSA lifetimes.
74- ( isReborrow && context . deadEndBlocks . isDeadEnd ( parentBlock ) ) ,
76+ // TODO: enable this check once we have complete OSSA lifetimes.
77+ // In a dead-end block an end_borrow might have been deleted.
78+ /*
79+ require(phi. isReborrow == phi.hasBorrowEndingUse ,
7580 "\(self) has stale reborrow flag");
81+ */
7682 }
7783 }
7884
@@ -95,7 +101,7 @@ private extension Phi {
95101}
96102
97103extension BorrowedFromInst : VerifiableInstruction {
98- func verify( _ context: FunctionPassContext ) {
104+ func verify( _ context: VerifierContext ) {
99105
100106 for ev in enclosingValues {
101107 require ( ev. isValidEnclosingValueInBorrowedFrom, " invalid enclosing value in borrowed-from: \( ev) " )
@@ -135,7 +141,7 @@ private extension Value {
135141}
136142
137143extension LoadBorrowInst : VerifiableInstruction {
138- func verify( _ context: FunctionPassContext ) {
144+ func verify( _ context: VerifierContext ) {
139145 if isUnchecked {
140146 return
141147 }
@@ -149,7 +155,7 @@ extension LoadBorrowInst : VerifiableInstruction {
149155}
150156
151157extension VectorBaseAddrInst : VerifiableInstruction {
152- func verify( _ context: FunctionPassContext ) {
158+ func verify( _ context: VerifierContext ) {
153159 require ( vector. type. isBuiltinFixedArray,
154160 " vector operand of vector_element_addr must be a Builtin.FixedArray " )
155161 require ( type == vector. type. builtinFixedArrayElementType ( in: parentFunction,
@@ -164,10 +170,10 @@ extension VectorBaseAddrInst : VerifiableInstruction {
164170// Otherwise the risk would be too big for false alarms. It also means that this verification is not perfect and
165171// might miss some subtle violations.
166172private struct MutatingUsesWalker : AddressDefUseWalker {
167- let context : FunctionPassContext
173+ let context : VerifierContext
168174 var mutatingInstructions : InstructionSet
169175
170- init ( _ context: FunctionPassContext ) {
176+ init ( _ context: VerifierContext ) {
171177 self . context = context
172178 self . mutatingInstructions = InstructionSet ( context)
173179 }
@@ -268,9 +274,9 @@ private extension Operand {
268274}
269275
270276func registerVerifier( ) {
271- BridgedUtilities . registerVerifier (
277+ BridgedVerifier . registerVerifier (
272278 { ( bridgedCtxt: BridgedContext , bridgedFunction: BridgedFunction ) in
273- let context = FunctionPassContext ( _bridged: bridgedCtxt)
279+ let context = VerifierContext ( _bridged: bridgedCtxt)
274280 bridgedFunction. function. verify ( context)
275281 }
276282 )
0 commit comments