-
Notifications
You must be signed in to change notification settings - Fork 9
Rust store optimisation #206
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
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 |
|---|---|---|
| @@ -1,10 +1,50 @@ | ||
| open Charon | ||
|
|
||
| include Stdlib.Map.Make (struct | ||
| module Map = Stdlib.Map.Make (struct | ||
| type t = Expressions.LocalId.id | ||
|
|
||
| let compare = Expressions.LocalId.compare_id | ||
| end) | ||
|
|
||
| let find_type sym store = Option.map snd (find_opt sym store) | ||
| let find_value sym store = Option.bind (find_opt sym store) fst | ||
| (** We have four kinds of bindings: | ||
|
|
||
| - Stackptr: the symbol is bound to a stack pointer, that lives in the heap. | ||
| - Value: the symbol is bound to an immediate value; it does not have an | ||
| address. | ||
| - Uninit: the symbol is bound to an immediate, uninitialized value. | ||
| - Dead: the symbol is dead; it doesn't exist (e.g. after a [StorageDead]). | ||
| *) | ||
| type 'a binding_kind = | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is sufficiently identical to soteria-C that we should probably factor it out?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (In a future PR of course)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm yes we could! |
||
| | Stackptr of 'a Rust_val.full_ptr | ||
| | Value of 'a Rust_val.t | ||
| | Uninit | ||
| | Dead | ||
| [@@deriving show { with_path = false }] | ||
|
|
||
| type 'a binding = { kind : 'a binding_kind; ty : Types.ty } | ||
| [@@deriving show { with_path = false }] | ||
|
|
||
| type 'a t = 'a binding Map.t | ||
|
|
||
| let reserve sym ty = | ||
| let binding = { kind = Dead; ty } in | ||
| Map.add sym binding | ||
|
|
||
| let[@inline] declare sym kind = | ||
| Map.update sym (function | ||
| | None -> failwith "Store: Assigning unknown symbol?" | ||
| | Some { kind = _; ty } -> Some { kind; ty }) | ||
|
|
||
| let declare_value sym value t = declare sym (Value value) t | ||
| let declare_ptr sym ptr t = declare sym (Stackptr ptr) t | ||
| let declare_uninit sym t = declare sym Uninit t | ||
| let dealloc sym t = declare sym Dead t | ||
|
|
||
| let get_ty sym t = | ||
| match Map.find_opt sym t with | ||
| | None -> failwith "Store: Getting type of unknown symbol?" | ||
| | Some { ty; _ } -> ty | ||
|
|
||
| let find local (store : 'a t) = Map.find local store | ||
| let empty = Map.empty | ||
| let bindings (store : 'a t) = Map.bindings store | ||
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.
How is lazy_ptr not just "place"?
Or possibly "resolved_place" or something
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.
well because you don't know if
lazy_ptris a lazy pointer; really it's an(lazy_ptr, full_ptr) Either.twherelazy_ptr = local ⊂ place