Conversation
|
This looks so so cool! I'll do a proper review at some point I'm going to be annoyingly pedantic here but you're writing json and then parsing text in the text fields to get additional structure and it's killing me 🙃 "std::env::_var with sig"Can we have {
"name": "std::env::_var with sig",
"additional_args": [ "sig" ]
}(just a string should resolve to And then, small cherry on top, because it's free to do with AI, can you add a |
|
alrightttt you are right and i thought of it i just found the |
There was a problem hiding this comment.
LGTM.
The only comment I want to make is that this lacks documentation.
We need explanation somewhere, possibly in CONTRIBUTING.md? But we need a tutorial on adding support for an intrinsic.
One slightly unclear thing to me is why is there two different procedure to generate stubs for external things and stubs for intrinsics?
Yeah sure I can add that in contributing, but like none of soteria rust is publicly documented so idk it feels weird?
Because intrinsics are all in one place and you want to stub them all, so you dont need to do anything fancy you just parse them as-is. Same with externs, but which live in a separate world, and which dont have a signature defined, so you need to do it manually. Stubs (e.g. the tokio or std stubs) are for function that exist and have a buddy but we choose to stub, so we want to allow for selecting exactly what we do; we can be a lot coarser with intrinsics. i dont know if this answers the question or you meant something else :P |
Agreed, though most of the code can be navigated through OCaml "go to reference", except this part because it's meta-programmed |
then how about documented the builtins/eval.ml module with all the info for when the soteria rust doc is more refined |
* Bump Charon and Obol * Separate externs/intrinsics handling + fix poly * Update intrinsics script for new Charon AST * Add automated stub generation * organise into folders * simplify * organise intrinsics into folders * reorganise externs * remove leading underscores in arguments * finish cleaning * Rename `intrinsincs.py` -> `stubs.py` * I guess soteria should be stubbed like the rest * support "with sig" in stubs + fixes * Update eval.ml * Migrate new stubs * Delete intrinsics.py * Add missing stub * support custom "with" in patterns * move comment * this comment disappeared? @claude come on * hehe * Saner JSON + schema * We never needed that Miri lib * Better stubs.json * match on impl elems too + tokio !! * Add soteria comment * Add pattern aliases * Add `include` to stubs json * Add alias of std::rt::begin_panic * Document `eval.ml`
Taking inspiration from how we handle intrinsics, I have created a new mechanism, to define wrappers for arbitrary stubs! All stubs in
builtinsare now defined through this mechanism.How?
The entry point to all of this is the
stubs.jsonfile, inbuiltins/. This JSON is a dict, mapping category names (e.g.Optim,Fixme,Tokio`) to lists of patterns to match.The
stubs.py --stubsscript (previouslyintrinsics.py) will then generate, for each category, a folder inbuiltinscontaining:intf.ml: a module defining the interface for all stubs. we try looking through Rust's stdlib to find the matching function, and if none is found a genericargs:rust_val list -> rust_val retsignature is used.impl.ml: the hand-written implementation for the stubs, which must export aMfunctor to create a module matching the interface inintf.ml<category>.ml: hides both intf and impl, and instead exposes:fntype for each stubfn_patslist of patterns to match itemseval_stubfunction that given afnreturns the right symbolic processthis means we have basically the same thing as before but much more modular, and most of it is generated making adding new stubs hopefully easier
I've migrated all stubs to this system. Because AeneasVerif/charon#1088 got merged, I also managed to cleanly split out how we handle intrinsics, externs, and regular stubs: the resulting
eval.mlfile is incredibly small and simple which I'm very happy about, compared to before.Extras
Additional fields that can be used for categories:
dependencies(list of toml entries) if a category needs some dependency for its patterns (e.g. tokio)code(self-contained Rust code) useful for when Charon fails to find the item from its patternfeaturesif a category needs some features enabled (e.g. f16, f128)Additional fields that can be used for patterns:
extra_argsif a stub needs extra information (e.g. the signature of the function). valid values aresigfor the function's signature,typesfor the function's type arguments, andfun_execfor the OCaml function to execute ULLBC functionsincludeif a stub needs some other item to be resolved first (e.g. nested functions)aliasif a stub is not found by Charon but may be re-exposed under a different name (this is risky to use, as it will expect the alias's signature for this pattern. use sparingly)