-
Notifications
You must be signed in to change notification settings - Fork 5
Polymorphism #220
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
Open
N1ark
wants to merge
32
commits into
main
Choose a base branch
from
polymorphism
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Polymorphism #220
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3b4319f to
1543a24
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Add support for some notion of polymorphic testing to Soteria Rust!
What's supported
We support symbolic tests that have generic arguments, e.g.:
In this case we generate a type
Tof unknown size and alignment. Currently I bound the size to the range[0; 1024[, to avoid detecting invalid layouts due to types having extremely large sizes, since that's not the point. I also limit the alignment to 1, to make generated layouts simpler, otherwise layout size expressions grow very (very) large from trying to calculate padding. If you have a clever solution let me know; this can also just be enabled through a flag maybe.We support creating nondeterministic
Tvariables, and reading/storing them, though that's about it.We also support symbolic tests that have const generic arguments, e.g.:
In this case we generate a nondet value of the constant's type. Note that the constant can be used in the body, but not in types, e.g.
fn generic_array<const C: usize>() { let x = [0; C] }currently doesn't work, since we would need symbolic arrays.What's not supported
This is a cool first step but is still quite limited; the following features are currently unsupported:
[u8; T])size_of::<T>and currently cannot be split or manipulated in any way.--polyflag) with Obol. Obol is for monomorphic analysis only, and if you want to use polymorphic analysis you must have--frontend charon.Implementation details
We keep track of the generic environment we're in by equipping
Rustsymexwith a substitution that is carried around. We also track a map of generic layouts inRustsymex, since symbolic information cannot be stored globally with the rest of the layouts.We keep track of const generics in
State(due to some module dependency problems aroundRust_valandSptr). It keeps a mapping of constant ID toRust_val, and generates a fresh nondet variable on the first access of each const. (Layouts works similarly, only computing generic layouts on the first access).The one ugly thing I had to do is that whenever I had a
Charon.Types.fun_decl_ref(e.g.State.declare_fnfor fn pointers), I now have a new ADTFun_kind.t = | Real of fun_decl_ref | Synthetic of synth_fnwhere for nowsynth_fnis onlyGenericDropInPlace. This is because in the function resolution step, there are cases where we want to emulate a trait method into a function that doesn't exist.We do this for
core::marker::Destruct::drop_in_place, i.e. the drop glue of a droppable type. If the trait clause associated toDestructis for a generic type, the functionSynthetic GenericDropInPlaceis used, which is a no-op. This is an approximation but is needed to allow values of typeT, since this function is called at the end of their scope.Review details
There are a few PRs dedicated to cleaning up dependencies / moving functions around; in particular:
layout.ml->rust_val.mldependency, by moving functions toencoder.mlrust_state_m.ml->state_intf.mldependency by redefining all thats neededlayout_common.ml->rust_val.mldependency, by moving stuff tocharon_util.mlLayout.tetc. tolayout_common.ml, to allow for the layout type to be used inRustsymex(for polymorphic layouts to be threaded through)Feel free to review them but they are just code moves, as far as I'm aware