-
Notifications
You must be signed in to change notification settings - Fork 8
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
Use Stdlib instead of deprecated Pervasives for 5.00.0+trunk #5
base: master
Are you sure you want to change the base?
Use Stdlib instead of deprecated Pervasives for 5.00.0+trunk #5
Conversation
module State : sig | ||
type t | ||
val make : int -> int -> t | ||
val copy : t -> t | ||
val length : t -> int | ||
val get : t -> int -> int | ||
val set : t -> int -> int -> unit | ||
val fold_left : ('a -> int -> 'a) -> 'a -> t -> 'a | ||
val iteri : (int -> int -> unit) -> t -> unit | ||
val as_array : t -> int array | ||
end = struct | ||
type t = int array | ||
let copy a = Obj.(obj (with_tag abstract_tag (repr a))) | ||
let make len elt = copy (Array.make len elt) | ||
let length = Array.length | ||
let get = Array.get | ||
let set = Array.set | ||
let fold_left = Array.fold_left | ||
let iteri = Array.iteri | ||
let as_array x = x | ||
end |
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.
What is the reasoning behind this? Using Obj.magic
below seems highly dangerous
@@ -18,7 +18,6 @@ open Options | |||
open Ast | |||
open Types | |||
open Atom | |||
open Pervasives |
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.
Did the compiler tell you there was no use of Stdlib
here? If not removing an open is dangerous as it shadows comparision functions such as compare
that might be used somewhere
@@ -18,7 +18,6 @@ open Util | |||
open Ast | |||
open Types | |||
open Atom | |||
open Pervasives |
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.
Same question here
Hi, thanks for this PR. Could you split your commits in two, one for the Pervasives -> Stdlib and one for the redefinition of State with Obj and provide some explanation as to why this change? |
@mattiasdrp done in #6 |
A warning about this PR: I wrote this code a few months ago to allow cubicle to compile with Flambda 2 (except for the The main idea for the State module is to use from the start a representation of states that the GC doesn't need to scan. There are various other alternatives (some that don't even use Obj), but the complexity and impact on performance can vary. |
I ended up by clicking at stuff randomly. Apologies! Two comments:
(Another idea is |
Pros: Efficient memory layout (only one more word compared to int arrays)
Pros: Support for Both approaches also require patching the client code, which I was too lazy to do in my PR (but that shouldn't be a problem when implementing a robust solution). |
let get arr i = Int64.to_int (Bytes.get_int64_ne arr (i*8))
It looks like the compiler removes the coercions here. (I had checked before making the suggestion.) |
You'll notice that little |
Ah, right. Meh. |
To be honest, the problem is that the coercions are only removed with the native code compiler for a 64-bit x86 backend. Try the same code with the bytecode compiler, or on a 32-bit architecture, or on a 64-bit Mac M1, and you'll get different code. |
I don't know if anyone runs model checkers on 32bit architectures anymore. Regarding arm64, I think that the situation could be improved in this case, are we are indexing with obviously-aligned indices ( |
Wait until people compile their model checkers to WebAssembly and run them in their browsers :)
Using a |
The
Pervasives
module has been deprecated in OCaml 5.00.0+trunk, and the recommendation is to use theStdlib
module instead.