@@ -18,7 +18,7 @@ private protocol VerifiableInstruction : Instruction {
1818 func verify( _ context: VerifierContext )
1919}
2020
21- private func require( _ condition: Bool , _ message: @autoclosure ( ) -> String , atInstruction: Instruction ? = nil ) {
21+ private func require( _ condition: Bool , _ message: @autoclosure ( ) -> String , atInstruction: Instruction ) {
2222 if !condition {
2323 let msg = message ( )
2424 msg. _withBridgedStringRef { stringRef in
@@ -27,6 +27,15 @@ private func require(_ condition: Bool, _ message: @autoclosure () -> String, at
2727 }
2828}
2929
30+ private func require( _ condition: Bool , _ message: @autoclosure ( ) -> String , atArgument: Argument ) {
31+ if !condition {
32+ let msg = message ( )
33+ msg. _withBridgedStringRef { stringRef in
34+ BridgedVerifier . verifierError ( stringRef, atArgument. bridged)
35+ }
36+ }
37+ }
38+
3039struct VerifierContext : Context {
3140 let _bridged : BridgedContext
3241}
@@ -53,16 +62,21 @@ extension Function {
5362private extension Instruction {
5463 func checkForwardingConformance( ) {
5564 if bridged. shouldBeForwarding ( ) {
56- require ( self is ForwardingInstruction , " instruction \( self ) \n should conform to ForwardingInstruction " )
65+ require ( self is ForwardingInstruction ,
66+ " instruction \( self ) \n should conform to ForwardingInstruction " ,
67+ atInstruction: self )
5768 } else {
58- require ( !( self is ForwardingInstruction ) , " instruction \( self ) \n should not conform to ForwardingInstruction " )
69+ require ( !( self is ForwardingInstruction ) ,
70+ " instruction \( self ) \n should not conform to ForwardingInstruction " ,
71+ atInstruction: self )
5972 }
6073 }
6174
6275 func checkGuaranteedResults( ) {
6376 for result in results where result. ownership == . guaranteed {
6477 require ( BeginBorrowValue ( result) != nil || self is ForwardingInstruction || result. isGuaranteedApplyResult,
65- " \( result) must either be a BeginBorrowValue or a ForwardingInstruction " )
78+ " \( result) must either be a BeginBorrowValue or a ForwardingInstruction " ,
79+ atInstruction: self )
6680 }
6781 }
6882}
@@ -89,22 +103,27 @@ private extension Phi {
89103 var forwardingBorrowedFromFound = false
90104 for use in value. uses {
91105 require ( use. instruction is BorrowedFromInst ,
92- " guaranteed phi: \( self ) \n has non borrowed-from use: \( use) " )
106+ " guaranteed phi: \( self ) \n has non borrowed-from use: \( use) " ,
107+ atArgument: self . value)
93108 if use. index == 0 {
94- require ( !forwardingBorrowedFromFound, " phi \( self ) has multiple forwarding borrowed-from uses " )
109+ require ( !forwardingBorrowedFromFound, " phi \( self ) has multiple forwarding borrowed-from uses " ,
110+ atArgument: self . value)
95111 forwardingBorrowedFromFound = true
96112 }
97113 }
98114 require ( forwardingBorrowedFromFound,
99- " missing forwarding borrowed-from user of guaranteed phi \( self ) " )
115+ " missing forwarding borrowed-from user of guaranteed phi \( self ) " ,
116+ atArgument: self . value)
100117 }
101118}
102119
103120extension BorrowedFromInst : VerifiableInstruction {
104121 func verify( _ context: VerifierContext ) {
105122
106123 for ev in enclosingValues {
107- require ( ev. isValidEnclosingValueInBorrowedFrom, " invalid enclosing value in borrowed-from: \( ev) " )
124+ require ( ev. isValidEnclosingValueInBorrowedFrom,
125+ " invalid enclosing value in borrowed-from: \( ev) " ,
126+ atInstruction: self )
108127 }
109128
110129 var computedEVs = Stack < Value > ( context)
@@ -120,7 +139,8 @@ extension BorrowedFromInst : VerifiableInstruction {
120139
121140 for computedEV in computedEVs {
122141 require ( existingEVs. contains ( computedEV) ,
123- " \( computedEV) \n missing in enclosing values of \( self ) " )
142+ " \( computedEV) \n missing in enclosing values of \( self ) " ,
143+ atInstruction: self )
124144 }
125145 }
126146}
@@ -189,10 +209,12 @@ extension BeginAccessInst : VerifiableInstruction {
189209extension VectorBaseAddrInst : VerifiableInstruction {
190210 func verify( _ context: VerifierContext ) {
191211 require ( vector. type. isBuiltinFixedArray,
192- " vector operand of vector_element_addr must be a Builtin.FixedArray " )
212+ " vector operand of vector_element_addr must be a Builtin.FixedArray " ,
213+ atInstruction: self )
193214 require ( type == vector. type. builtinFixedArrayElementType ( in: parentFunction,
194215 maximallyAbstracted: true ) . addressType,
195- " result of vector_element_addr has wrong type " )
216+ " result of vector_element_addr has wrong type " ,
217+ atInstruction: self )
196218 }
197219}
198220
@@ -235,7 +257,8 @@ private struct MutatingUsesWalker : AddressDefUseWalker {
235257 if let bf = phi. borrowedFrom {
236258 linearLiveranges. pushIfNotVisited ( bf)
237259 } else {
238- require ( false , " missing borrowed-from for \( phi. value) " )
260+ require ( false , " missing borrowed-from for \( phi. value) " ,
261+ atArgument: phi. value)
239262 }
240263 }
241264 }
0 commit comments