Commit ce5e392
EXPERIMENTS: shorten cache lookup chains, invalidate cache on new ensures (#3998)
### Fixes #3982
To avoid situations where the cache contains successive mappings `e ->
e1 -> e2 -> e3 ... -> e_n` (a "lookup chain"), the following
modifications are made:
1. When inserting `e -> e1`, first check whether `e1 -> e2` is in the
cache, and insert `e -> e2` instead in this case.
2. When looking up `e` and a binding `e -> e1` is found, check whether a
binding `e1 -> e2` is also in the cache.
In this case, update the binding for `e` to `e -> e2` and return `e2`.
This will eventually lead to removing all lookup chains that may exist
in a cache (for "interesting" cached values that are being looked up),
without the risk of a loop.
Assume the following:
* the cache was initially empty;
* insertions and lookups are performed as described above;
* the cache contains a lookup chain `e -> e1 -> e2`.
If `e1 -> e2` was inserted first, insertion of `e -> e1` would have
resulted in storing `e -> e2`. Therefore, `e -> e1` must have been
inserted first.
A subsequent lookup of `e` will update the cache to contain `e -> e2`.
Insertion of `e -> e1`, then `e1 -> e2`, then `e2 -> e3`, will create
the lookup chain `e -> e1 -> e2 -> e3`.
- A lookup of `e` would leave the cache containing two shorter chains `e
-> e2 -> e3` and `e1 -> e2 -> e3`.
- A lookup of `e1` would also leave the cache containing one shorter
chain `e -> e1 -> e3`, and `e2 -> e3`.
Every lookup potentially shortens a lookup chain, possibly to several
chains.
### Fixes #3993
When a new path condition is added (from an `ensures` clause), the
`Equations` cache is purged. While some entries may still be valid,
* all entries `t -> t` (no simplification possible) may be invalid
because new equations might be applicable with the new path condition
* even entries `t -> t'` with `t /= t'` may be invalid because while
they already memoise some applicable simplifications, they may store
sub-terms that could now be evaluated or simplified further (new
equations may apply)
---------
Co-authored-by: github-actions <github-actions@github.com>1 parent e4bd3aa commit ce5e392
File tree
2 files changed
+56
-15
lines changed- booster/library/Booster/Pattern
2 files changed
+56
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
| 25 | + | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
247 | | - | |
248 | | - | |
249 | | - | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
250 | 278 | | |
251 | 279 | | |
252 | 280 | | |
| |||
899 | 927 | | |
900 | 928 | | |
901 | 929 | | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
902 | 936 | | |
903 | 937 | | |
904 | 938 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
53 | 54 | | |
54 | | - | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
401 | 402 | | |
402 | 403 | | |
403 | 404 | | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
404 | 411 | | |
405 | 412 | | |
406 | 413 | | |
| |||
0 commit comments