Skip to content

Commit

Permalink
fix CI for various architectures (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
art-w authored Feb 1, 2024
1 parent 38b494b commit 757ad2b
Show file tree
Hide file tree
Showing 15 changed files with 269 additions and 236 deletions.
95 changes: 48 additions & 47 deletions db/type_polarity.mli
Original file line number Diff line number Diff line change
@@ -1,51 +1,52 @@
(** This module provide a way to transform a type into strings, in such a way
that the strings can be used for type search.
The chosen representation is polarity : we do not represent the [->] or the [*]
constructors, but instead compute the "polarity" of every type name/constructor
like [int] or ['a] that is part of the whole type expression.
The polarity of a component of a type indicates if it is produced or consumed by
the type. In the type [int -> string], [int] has negative polarity because it is
being consumed, and [string] has positive polarity because it is being produced.
We say that the polarities of [int -> string] are [-int] and [+string].
Once you have computed the polarities of the type of an entry [e], you can
register each polarity as corresponding to [e] in the search database.
Then, when the user queries for a type, we compute the polarities of the query
type, and search for the entries.
We then return the result corresponding to intersection of each polarity: if the
user queries for [int -> string], we want to have every entry which consumes an
[int] and produces a [string], that is the intersection of the entries
associated to [-int] with the entries associated to [+string].
How is polarity computed exactly ? When you have [t -> u], the polarity of [t]
is inversed, and the polarity of [u] stays the same. A good example of this is
the type of {!Stdlib.Out_channel.with_open_gen} :
{| val with_open_gen : open_flag list -> int -> string -> (t -> 'a) -> 'a |}
Here the polarities are [-open_flag list], [-int], [-string], [+Out_channel.t],
[-'a] and [+'a]. The fact that we have [+Out_channel.t] might be puzzling at
first, because an [Out_channel.t] is not returned by the function, but
{!Stdlib.Out_channel.with_open_gen} is indeed one of the possible ways to create
an [Out_channel.t].
There is however a complication. If the user queries for [int -> int -> string],
then the polarities will be [-int], [-int] and [+string]. An entry of type [int
-> string] would be included in the intersection of these polarities. But the
user explicitely asked for two integers to be consumed. To fix this issue, we
track the number of occurences of each polarity.
The polarities for [int -> int -> string], become [(-int, 2)] and [(+string,
1)], and allows us to filter entries according to this information.
There is a mechanism for types with parameters like ['a list]. I might explain
it in the future.
TODO : Give an example even if not the full explanation.
*)
that the strings can be used for type search.
The chosen representation is polarity : we do not represent the [->] or the [*]
constructors, but instead compute the "polarity" of every type name/constructor
like [int] or ['a] that is part of the whole type expression.
The polarity of a component of a type indicates if it is produced or consumed by
the type. In the type [int -> string], [int] has negative polarity because it is
being consumed, and [string] has positive polarity because it is being produced.
We say that the polarities of [int -> string] are [-int] and [+string].
Once you have computed the polarities of the type of an entry [e], you can
register each polarity as corresponding to [e] in the search database.
Then, when the user queries for a type, we compute the polarities of the query
type, and search for the entries.
We then return the result corresponding to intersection of each polarity: if the
user queries for [int -> string], we want to have every entry which consumes an
[int] and produces a [string], that is the intersection of the entries
associated to [-int] with the entries associated to [+string].
How is polarity computed exactly ? When you have [t -> u], the polarity of [t]
is inversed, and the polarity of [u] stays the same. A good example of this is
the type of {!Stdlib.Out_channel.with_open_gen} :
{[
val with_open_gen : open_flag list -> int -> string -> (t -> 'a) -> 'a
]}
Here the polarities are [-open_flag list], [-int], [-string], [+Out_channel.t],
[-'a] and [+'a]. The fact that we have [+Out_channel.t] might be puzzling at
first, because an [Out_channel.t] is not returned by the function, but
{!Stdlib.Out_channel.with_open_gen} is indeed one of the possible ways to create
an [Out_channel.t].
There is however a complication. If the user queries for [int -> int -> string],
then the polarities will be [-int], [-int] and [+string]. An entry of type [int
tring] would be included in the intersection of these polarities. But the
user explicitely asked for two integers to be consumed. To fix this issue, we
track the number of occurences of each polarity.
The polarities for [int -> int -> string], become [(-int, 2)] and [(+string, 1)]
and allows us to filter entries according to this information.
There is a mechanism for types with parameters like ['a list]. I might explain
it in the future.
TODO : Give an example even if not the full explanation. *)

module Sign : sig
type t =
Expand Down
9 changes: 6 additions & 3 deletions store/storage_ancient.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
let base_addr = 0x100000000000n
let base_addr () =
if Sys.word_size > 32
then Int64.to_nativeint 0x100000000000L
else failwith "TODO: support ancient on 32 bits"

type writer =
{ mutable write_shard : int
Expand All @@ -7,7 +10,7 @@ type writer =

let open_out filename =
let handle = Unix.openfile filename Unix.[ O_RDWR; O_TRUNC; O_CREAT ] 0o640 in
let ancient = Ancient.attach handle base_addr in
let ancient = Ancient.attach handle (base_addr ()) in
{ write_shard = 0; ancient }

let save ~db (t : Db.t) =
Expand All @@ -34,7 +37,7 @@ let load_shards md =
let db_open_in db : reader =
let filename = db in
let handle = Unix.openfile filename Unix.[ O_RDWR ] 0o640 in
let md = Ancient.attach handle base_addr in
let md = Ancient.attach handle (base_addr ()) in
{ shards = load_shards md }

let load db_filename =
Expand Down
4 changes: 4 additions & 0 deletions test/cram/base_benchmark.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
This test will fail, it is not deterministic. Please just check that the values
are not crazy and discard the changes
$ ODOCLS=$(find ../docs/odoc/base/ -name '*.odocl' | sort)
$ sherlodoc index --format=js --db=db.js $ODOCLS > /dev/null
2 changes: 1 addition & 1 deletion test/cram/base_cli.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
$ export ODOCLS=$(find ../docs/odoc/base/ -name '*.odocl')
$ ODOCLS=$(find ../docs/odoc/base/ -name '*.odocl')
$ export SHERLODOC_DB=db.bin
$ export SHERLODOC_FORMAT=marshal
$ sherlodoc index --index-docstring=false $ODOCLS > /dev/null
Expand Down
Loading

0 comments on commit 757ad2b

Please sign in to comment.