@@ -348,6 +348,38 @@ private module Cached {
348
348
yield .asExpr ( ) .getExpr ( ) = call
349
349
)
350
350
}
351
+
352
+ /**
353
+ * A place in which a named constant can be looked up during constant lookup.
354
+ */
355
+ cached
356
+ newtype TConstLookupScope =
357
+ /** Look up in a qualified constant name `base::`. */
358
+ MkQualifiedLookup ( ConstantAccess base ) or
359
+ /** Look up in the ancestors of `mod`. */
360
+ MkAncestorLookup ( Module mod ) or
361
+ /** Look up in a module syntactically nested in a declaration of `mod`. */
362
+ MkNestedLookup ( Module mod ) or
363
+ /** Pseudo-scope for accesses that are known to resolve to `mod`. */
364
+ MkExactLookup ( Module mod )
365
+
366
+ /**
367
+ * Gets a `LocalSourceNode` to represent the constant read or written by `access`.
368
+ */
369
+ cached
370
+ LocalSourceNode getConstantAccessNode ( ConstantAccess access ) {
371
+ // Namespaces don't evaluate to the constant being accessed, they return the value of their last statement.
372
+ // Use the definition of 'self' in the namespace as the representative in this case.
373
+ if access instanceof Namespace
374
+ then result = getNamespaceSelf ( access )
375
+ else result .asExpr ( ) .getExpr ( ) = access
376
+ }
377
+
378
+ cached
379
+ predicate forceCachingInSameStage ( ) { any ( ) }
380
+
381
+ cached
382
+ predicate forceCachingBackref ( ) { exists ( any ( ConstRef const ) .getConst ( _) ) }
351
383
}
352
384
353
385
private import Cached
@@ -1098,30 +1130,6 @@ class ArrayLiteralNode extends LocalSourceNode, ExprNode {
1098
1130
Node getAnElement ( ) { result = this .( CallNode ) .getPositionalArgument ( _) }
1099
1131
}
1100
1132
1101
- /**
1102
- * A place in which a named constant can be looked up during constant lookup.
1103
- */
1104
- private newtype TConstLookupScope =
1105
- /** Look up in a qualified constant name `base::`. */
1106
- MkQualifiedLookup ( ConstantAccess base ) or
1107
- /** Look up in the ancestors of `mod`. */
1108
- MkAncestorLookup ( Module mod ) or
1109
- /** Look up in a module syntactically nested in a declaration of `mod`. */
1110
- MkNestedLookup ( Module mod ) or
1111
- /** Pseudo-scope for accesses that are known to resolve to `mod`. */
1112
- MkExactLookup ( Module mod )
1113
-
1114
- /**
1115
- * Gets a `LocalSourceNode` to represent the constant read or written by `access`.
1116
- */
1117
- private LocalSourceNode getConstantAccessNode ( ConstantAccess access ) {
1118
- // Namespaces don't evaluate to the constant being accessed, they return the value of their last statement.
1119
- // Use the definition of 'self' in the namespace as the representative in this case.
1120
- if access instanceof Namespace
1121
- then result = getNamespaceSelf ( access )
1122
- else result .asExpr ( ) .getExpr ( ) = access
1123
- }
1124
-
1125
1133
/**
1126
1134
* An access to a constant, such as `C`, `C::D`, or a class or module declaration.
1127
1135
*
@@ -1188,8 +1196,9 @@ class ConstRef extends LocalSourceNode {
1188
1196
/**
1189
1197
* Gets a scope in which a constant lookup may access the contents of the module referenced by this constant.
1190
1198
*/
1191
- pragma [ nomagic ]
1199
+ cached
1192
1200
private TConstLookupScope getATargetScope ( ) {
1201
+ forceCachingInSameStage ( ) and
1193
1202
result = MkAncestorLookup ( this .getAncestryTarget ( ) .getAnImmediateDescendent * ( ) )
1194
1203
or
1195
1204
access = any ( ConstantAccess ac ) .getScopeExpr ( ) and
@@ -1222,8 +1231,9 @@ class ConstRef extends LocalSourceNode {
1222
1231
/**
1223
1232
* Holds if this can reference a constant named `name` from `scope` using a lookup of `kind`.
1224
1233
*/
1225
- pragma [ nomagic ]
1234
+ cached
1226
1235
private predicate accesses ( TConstLookupScope scope , string name ) {
1236
+ forceCachingInSameStage ( ) and
1227
1237
scope = this .getLookupScope ( ) and
1228
1238
name = this .getName ( )
1229
1239
or
0 commit comments