BinaryAnalysisPlatform / bap

Binary Analysis Platform
MIT License
2.05k stars 271 forks source link

extends the knowledge monad interface #1360

Closed ivg closed 2 years ago

ivg commented 2 years ago

This is a quality of life PR (an extract from another PR that I am currently working on) that adds a few useful primitives to the knowledge base monad interface.

The most important addition is the new operator require that works like collect but raises the empty value conflict if the returned value is empty. This function is inteded to be used in the context of promises and proposals that now catch this exception and evaluate the whole scoped expression to the empty value of the computed domain. This vastly simplify the implementation logic of promises for domains that do not use None as the empty value.

To make things work even more smoothly we extend the KB.Syntax module with a few new operators. First of all, we include the Monad.Let directly into the KB.Syntax so that you don't need to open KB.Let anymore. Next, we introduce let*? and let+?, which let-binding couterparts of the already existing >>=? and >>|? infix operators. Next, we add -->? to complement -->, it collects an optional domain value and fails if it is None.

Finally, we add indexing operators for accessing fields of KB values. The also come with the empty-checking variants.

The PR also applies the new operators to the existing code for the demonstration purposes (and to show that it works). I also believe that the rewritten code is more reable, even despite that I still prefer the infix syntax to the let-binding operators.