Skip to content

Commit ce7be3b

Browse files
committed
drop precomputed_signature: quadratic in size
1 parent 40b90b6 commit ce7be3b

File tree

6 files changed

+19
-9
lines changed

6 files changed

+19
-9
lines changed

dune

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
(modules elpi_REPL)
77
(package elpi)
88
)
9+
10+
(executable
11+
(name elpi_inspect)
12+
(libraries elpi elpi.parser ;memtrace
13+
)
14+
(modules elpi_inspect)
15+
)
916
(env
1017
(dev
1118
(flags (:standard -w -9 -w -27 -warn-error -A))))

elpi_inspect.ml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
open Elpi.API
2+
3+
let () =
4+
let u : Compile.compilation_unit = Marshal.from_channel (open_in_bin Sys.argv.(1)) in
5+
Format.printf "%a" Compile.pp_compilation_unit u

src/API.ml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ module Compile = struct
148148
type executable = ED.executable
149149
type scoped_program = Compiler.scoped_program * int
150150
type compilation_unit = Compiler.checked_compilation_unit
151+
let pp_compilation_unit = Compiler.pp_checked_compilation_unit
151152
type compilation_unit_signature = Compiler.checked_compilation_unit_signature
152153
exception CompileError = Compiler_data.CompileError
153154

src/API.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,8 @@ module Compile : sig
293293
val scope : ?flags:flags -> elpi:Setup.elpi -> ?builtins:Setup.builtins -> Ast.program -> scoped_program
294294

295295
type compilation_unit
296+
val pp_compilation_unit : Format.formatter -> compilation_unit -> unit
297+
296298
type compilation_unit_signature
297299
val empty_base : elpi:Setup.elpi -> program
298300
val unit : ?flags:flags -> elpi:Setup.elpi -> base:program -> ?builtins:Setup.builtins -> scoped_program -> compilation_unit

src/compiler/compiler.ml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,6 @@ type checked_compilation_unit = {
419419
version : string;
420420
checked_code : CheckedFlat.program;
421421
base_hash : string;
422-
precomputed_signature : Assembled.signature;
423422
type_checking_time : float;
424423
det_checking_time : float;
425424
}
@@ -1571,15 +1570,12 @@ end = struct
15711570

15721571
let more_types = time_this type_check_time (fun () -> Type_checker.check_undeclared ~unknown ~type_abbrevs) in
15731572
let u_types = Flatten.merge_type_assignments u_types more_types in
1574-
let types = Flatten.merge_type_assignments types more_types in
15751573

15761574
let signature = { signature with types = u_types } in
1577-
let precomputed_signature = { precomputed_signature with types } in
15781575

15791576
let checked_code = { CheckedFlat.signature; clauses; chr; builtins } in
15801577

15811578
{ version; checked_code; base_hash = hash_base base;
1582-
precomputed_signature;
15831579
type_checking_time = if flags.time_typechecking then !type_check_time +. check_sig else 0.0;
15841580
det_checking_time = if flags.time_typechecking then !det_check_time else 0.0;
15851581
}
@@ -2158,10 +2154,7 @@ let allocate_new_symbols state ~symbols ~new_defined_symbols =
21582154

21592155
let extend1 flags (state, base) unit =
21602156

2161-
let signature =
2162-
if hash_base base = unit.base_hash
2163-
then unit.precomputed_signature
2164-
else extend1_signature base.Assembled.signature unit.checked_code.CheckedFlat.signature in
2157+
let signature = extend1_signature base.Assembled.signature unit.checked_code.CheckedFlat.signature in
21652158

21662159
let { Assembled.hash; clauses = cl; symbols; prolog_program; indexing; signature = bsig; chr = ochr; builtins = ob; total_type_checking_time; total_det_checking_time } = base in
21672160
let { version; base_hash; checked_code = { CheckedFlat.clauses; chr; builtins; signature = { types = new_types } }; type_checking_time; det_checking_time } = unit in
@@ -2684,5 +2677,6 @@ let info_of_clause ~types { Ast.Clause.body } =
26842677

26852678
let hover (u : checked_compilation_unit) =
26862679
let { CheckedFlat.clauses } = u.checked_code in
2687-
List.map (info_of_clause ~types:u.precomputed_signature.Assembled.types) clauses |> List.flatten
2680+
(* This signature does not contain all types ... *)
2681+
List.map (info_of_clause ~types:u.checked_code.signature.Assembled.types) clauses |> List.flatten
26882682

src/compiler/compiler.mli

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ type scoped_program
3434
val scoped_of_ast : flags:flags -> header:header -> ?calc:CalcHooks.descriptor -> ?builtins:declared_builtins list -> Ast.Program.t -> scoped_program
3535

3636
type checked_compilation_unit
37+
val pp_checked_compilation_unit : Format.formatter -> checked_compilation_unit -> unit
3738
type unchecked_compilation_unit
3839
val empty_base : header:header -> program
3940
val unit_of_scoped : flags:flags -> header:header -> ?builtins:declared_builtins list -> scoped_program -> unchecked_compilation_unit

0 commit comments

Comments
 (0)