@@ -28,16 +28,15 @@ import SIL
28
28
let computeEscapeEffects = FunctionPass ( name: " compute-escape-effects " , {
29
29
( function: Function , context: PassContext ) in
30
30
31
- var newEffects = Stack < EscapeEffects . ArgumentEffect > ( context)
32
- defer { newEffects. deinitialize ( ) }
31
+ var newEffects = function. effects. escapeEffects. arguments. filter { !$0. isDerived }
33
32
34
33
let returnInst = function. returnInstruction
35
34
let argsWithDefinedEffects = getArgIndicesWithDefinedEscapingEffects ( of: function)
36
35
37
36
for arg in function. arguments {
38
37
// We are not interested in arguments with trivial types.
39
38
if !arg. type. isNonTrivialOrContainsRawPointer ( in: function) { continue }
40
-
39
+
41
40
// Also, we don't want to override defined effects.
42
41
if argsWithDefinedEffects. contains ( arg. index) { continue }
43
42
@@ -52,7 +51,7 @@ let computeEscapeEffects = FunctionPass(name: "compute-escape-effects", {
52
51
context) {
53
52
let effect = EscapeEffects . ArgumentEffect ( . notEscaping, argumentIndex: arg. index,
54
53
pathPattern: SmallProjectionPath ( . anything) )
55
- newEffects. push ( effect)
54
+ newEffects. append ( effect)
56
55
continue
57
56
}
58
57
@@ -65,17 +64,22 @@ let computeEscapeEffects = FunctionPass(name: "compute-escape-effects", {
65
64
}
66
65
}
67
66
67
+ // Don't modify the effects if they didn't change. This avoids sending a change notification
68
+ // which can trigger unnecessary other invalidations.
69
+ if newEffects == function. effects. escapeEffects. arguments {
70
+ return
71
+ }
72
+
68
73
context. modifyEffects ( in: function) { ( effects: inout FunctionEffects ) in
69
- effects. escapeEffects. arguments = effects. escapeEffects. arguments. filter { !$0. isDerived }
70
- effects. escapeEffects. arguments. append ( contentsOf: newEffects)
74
+ effects. escapeEffects. arguments = newEffects
71
75
}
72
76
} )
73
77
74
78
75
79
/// Returns true if an argument effect was added.
76
80
private
77
81
func addArgEffects( _ arg: FunctionArgument , argPath ap: SmallProjectionPath ,
78
- to newEffects: inout Stack < EscapeEffects . ArgumentEffect > ,
82
+ to newEffects: inout [ EscapeEffects . ArgumentEffect ] ,
79
83
_ returnInst: ReturnInst ? , _ context: PassContext ) -> Bool {
80
84
// Correct the path if the argument is not a class reference itself, but a value type
81
85
// containing one or more references.
@@ -159,7 +163,7 @@ func addArgEffects(_ arg: FunctionArgument, argPath ap: SmallProjectionPath,
159
163
effect = EscapeEffects . ArgumentEffect ( . escapingToArgument( toArgIdx, toPath, exclusive) ,
160
164
argumentIndex: arg. index, pathPattern: argPath)
161
165
}
162
- newEffects. push ( effect)
166
+ newEffects. append ( effect)
163
167
return true
164
168
}
165
169
0 commit comments