@@ -62,6 +62,10 @@ extension MutatingContext {
62
62
func notifyInvalidatedStackNesting( ) { _bridged. notifyInvalidatedStackNesting ( ) }
63
63
var needFixStackNesting : Bool { _bridged. getNeedFixStackNesting ( ) }
64
64
65
+ func verifyIsTransforming( function: Function ) {
66
+ precondition ( _bridged. isTransforming ( function. bridged) , " pass modifies wrong function " )
67
+ }
68
+
65
69
/// Splits the basic block, which contains `inst`, before `inst` and returns the
66
70
/// new block.
67
71
///
@@ -88,6 +92,9 @@ extension MutatingContext {
88
92
}
89
93
90
94
func erase( instruction: Instruction ) {
95
+ if !instruction. isInStaticInitializer {
96
+ verifyIsTransforming ( function: instruction. parentFunction)
97
+ }
91
98
if instruction is FullApplySite {
92
99
notifyCallsChanged ( )
93
100
}
@@ -374,18 +381,21 @@ extension Type {
374
381
extension Builder {
375
382
/// Creates a builder which inserts _before_ `insPnt`, using a custom `location`.
376
383
init ( before insPnt: Instruction , location: Location , _ context: some MutatingContext ) {
384
+ context. verifyIsTransforming ( function: insPnt. parentFunction)
377
385
self . init ( insertAt: . before( insPnt) , location: location,
378
386
context. notifyInstructionChanged, context. _bridged. asNotificationHandler ( ) )
379
387
}
380
388
381
389
/// Creates a builder which inserts _before_ `insPnt`, using the location of `insPnt`.
382
390
init ( before insPnt: Instruction , _ context: some MutatingContext ) {
391
+ context. verifyIsTransforming ( function: insPnt. parentFunction)
383
392
self . init ( insertAt: . before( insPnt) , location: insPnt. location,
384
393
context. notifyInstructionChanged, context. _bridged. asNotificationHandler ( ) )
385
394
}
386
395
387
396
/// Creates a builder which inserts _after_ `insPnt`, using a custom `location`.
388
397
init ( after insPnt: Instruction , location: Location , _ context: some MutatingContext ) {
398
+ context. verifyIsTransforming ( function: insPnt. parentFunction)
389
399
if let nextInst = insPnt. next {
390
400
self . init ( insertAt: . before( nextInst) , location: location,
391
401
context. notifyInstructionChanged, context. _bridged. asNotificationHandler ( ) )
@@ -397,17 +407,20 @@ extension Builder {
397
407
398
408
/// Creates a builder which inserts _after_ `insPnt`, using the location of `insPnt`.
399
409
init ( after insPnt: Instruction , _ context: some MutatingContext ) {
410
+ context. verifyIsTransforming ( function: insPnt. parentFunction)
400
411
self . init ( after: insPnt, location: insPnt. location, context)
401
412
}
402
413
403
414
/// Creates a builder which inserts at the end of `block`, using a custom `location`.
404
415
init ( atEndOf block: BasicBlock , location: Location , _ context: some MutatingContext ) {
416
+ context. verifyIsTransforming ( function: block. parentFunction)
405
417
self . init ( insertAt: . atEndOf( block) , location: location,
406
418
context. notifyInstructionChanged, context. _bridged. asNotificationHandler ( ) )
407
419
}
408
420
409
421
/// Creates a builder which inserts at the begin of `block`, using a custom `location`.
410
422
init ( atBeginOf block: BasicBlock , location: Location , _ context: some MutatingContext ) {
423
+ context. verifyIsTransforming ( function: block. parentFunction)
411
424
let firstInst = block. instructions. first!
412
425
self . init ( insertAt: . before( firstInst) , location: location,
413
426
context. notifyInstructionChanged, context. _bridged. asNotificationHandler ( ) )
@@ -416,6 +429,7 @@ extension Builder {
416
429
/// Creates a builder which inserts at the begin of `block`, using the location of the first
417
430
/// instruction of `block`.
418
431
init ( atBeginOf block: BasicBlock , _ context: some MutatingContext ) {
432
+ context. verifyIsTransforming ( function: block. parentFunction)
419
433
let firstInst = block. instructions. first!
420
434
self . init ( insertAt: . before( firstInst) , location: firstInst. location,
421
435
context. notifyInstructionChanged, context. _bridged. asNotificationHandler ( ) )
0 commit comments