-
Notifications
You must be signed in to change notification settings - Fork 87
Narrowing gas #1879
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Narrowing gas #1879
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,96 @@ | ||||||||||||||||||||||||||||||||||||||
| (** narrowing delay with counters. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Abstract elements are paired with an integer counter, indicating how many times narrowing has been delayed. | ||||||||||||||||||||||||||||||||||||||
| Lifted abstract elements are only narrowed if the counter exceeds a predefined limit (gas). *) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| open Batteries | ||||||||||||||||||||||||||||||||||||||
| open Lattice | ||||||||||||||||||||||||||||||||||||||
| open Analyses | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| module LocalChainParams: Printable.ChainParams = | ||||||||||||||||||||||||||||||||||||||
| struct | ||||||||||||||||||||||||||||||||||||||
| let n () = GobConfig.get_int "ana.narrowing.gas" | ||||||||||||||||||||||||||||||||||||||
| let names = string_of_int | ||||||||||||||||||||||||||||||||||||||
| end | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| module GlobalChainParams: Printable.ChainParams = | ||||||||||||||||||||||||||||||||||||||
| struct | ||||||||||||||||||||||||||||||||||||||
| let n () = GobConfig.get_int "ana.narrowing.gas" | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+12
to
+18
|
||||||||||||||||||||||||||||||||||||||
| let n () = GobConfig.get_int "ana.narrowing.gas" | |
| let names = string_of_int | |
| end | |
| module GlobalChainParams: Printable.ChainParams = | |
| struct | |
| let n () = GobConfig.get_int "ana.narrowing.gas" | |
| (* Local default gas for narrowing; avoids reliance on a non-existent config key. *) | |
| let default_gas = 3 | |
| let n () = default_gas | |
| let names = string_of_int | |
| end | |
| module GlobalChainParams: Printable.ChainParams = | |
| struct | |
| (* Global default gas for narrowing; avoids reliance on a non-existent config key. *) | |
| let default_gas = 3 | |
| let n () = default_gas |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The configuration key "ana.narrowing.gas" does not exist in the schema. Since GlobalChainParams is not currently used in the codebase, this module references a non-existent configuration option. Consider either: 1) Adding "ana.narrowing.gas" to the schema if this is intended to be a general-purpose parameter, or 2) Removing GlobalChainParams if it's not needed, since the actual usage in apronAnalysis.apron.ml creates a custom ChainParams with the apron-specific narrowing_gas value.
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is misleading. When the counter is less than n(), the code uses meet to delay narrowing. When the counter reaches or exceeds n(), actual narrowing begins. The comment should say something like "Use meet to delay narrowing until counter reaches limit" to accurately reflect the behavior.
| (Base.meet b1 b2, i' + 1) (* Stop narrowing when counter exceeds limit. *) | |
| (Base.meet b1 b2, i' + 1) (* Use meet to delay narrowing until counter reaches limit. *) |
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation says "widening delay" but this module implements narrowing delay/gas, not widening delay. The comment should refer to "narrowing delay" or "narrowing gas" to match the actual functionality.
Copilot
AI
Jan 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation says "widening delay" but this module implements narrowing delay/gas, not widening delay. The comment should refer to "narrowing delay" or "narrowing gas" to match the actual functionality.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| // SKIP PARAM: --set ana.apron.narrowing_gas 1 --set ana.activated[+] apron --set ana.apron.domain polyhedra | ||
| // Apron is not precise enough for some nested loops | ||
| #include <goblint.h> | ||
| #include <stdio.h> | ||
|
|
||
| int loops0(){ | ||
| int i, j, k; | ||
| int a = 0; | ||
| for (i = 500; i >= 1; i--) | ||
| { | ||
| a++; | ||
| __goblint_check(a + i - 501 == 0); // needs 1x narrowing or octagons | ||
| int b = 0; | ||
| for (j = i; j >= 1; j--) | ||
| { | ||
| __goblint_check(a + b + j == 501); // needs 1x narrowing, octagons insufficient | ||
| b++; | ||
| } | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| int main() | ||
| { | ||
| loops0(); | ||
|
|
||
| return 0; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is in a slightly less ideal place than I imagined in #1494, but I can see why and it is fine.
Ideally, I'd like to just wrap this lifting around polyhedra, but not other Apron domains, somewhere in
ApronDomain, and have the analysis be completely oblivious to the fact.Because in some sense it's "just" a lifting of any
Lattice.S → Lattice.S. But that's only so if things are fully properly abstract, but ourRelationDomain/ApronDomainsetup is far from that. So it'd require a large cleanup/refactoring to be able to do it in my dream way.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think that's is purely a lattice -> lattice functor, as the gas needs to be reset at every transfer function, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually the
NarrowingGas.Domfunctor here (based onWideningDelay, etc) is essentially just that. It's the act ofunliftandliftto do the operation that leads to the reset. And that's whatNarrowingGas.DLifterused here exactly does.It additionally needs all relational domain operations (instead of
Specoperations) lifted, which needs more boilerplate. And it won't really gain anything from Goblint usage perspective.