Commit 686f4383 authored by POTTIER Francois's avatar POTTIER Francois

Increase the maximum length of a production. Display polite message if exceeded.

Close issue #31.
parent 3666c879
Pipeline #115947 passed with stages
in 24 seconds
# Changes # Changes
## 2020/XX/XX
* Increase the maximum length of a production, which used to be 127,
up to 1023. Display a polite error message if this length is exceeded.
## 2020/01/21 ## 2020/01/21
* There used to be a distinction between two slightly different ways of * There used to be a distinction between two slightly different ways of
......
...@@ -168,8 +168,14 @@ module Make ...@@ -168,8 +168,14 @@ module Make
type item = type item =
int * int int * int
let low_bits =
10
let low_limit =
1 lsl low_bits
let export t : item = let export t : item =
(t lsr 7, t mod 128) (t lsr low_bits, t mod low_limit)
let items s = let items s =
(* Map [s] to its LR(0) core. *) (* Map [s] to its LR(0) core. *)
......
...@@ -20,25 +20,55 @@ open Grammar ...@@ -20,25 +20,55 @@ open Grammar
production and the index of the bullet in the production's production and the index of the bullet in the production's
right-hand side. *) right-hand side. *)
(* Both integers are packed into a single integer, using 7 bits for (* Both integers are packed into a single integer, using 10 bits for
the bullet position and the rest (usually 24 bits) for the the bullet position and the rest (21 bits on a 32-bit architecture,
production index. These widths could be adjusted. *) 53 bits on a 64-bit architecture) for the production index. This
means that the length of a production must be at most 1023. This
means that the number of productions must be at most:
- 2^21, that is about 2 million, on a 32-bit architecture;
- 2^53, that is practically unlimited, on a 64-bit architecture. *)
(* The function [export] is duplicated in [TableInterpreter]. Do not (* These static limits could be adjusted if necessary. It would also be
modify it; or modify it here and there in a consistent manner. *) possible to dynamically adjust the limits depending on the grammar
at hand. In practice, the need for this has not been felt. *)
(* WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING *)
(* The constant [low_bits], [low_limits] and the function [export] are
duplicated in [lib/InspectionTableInterpreter.ml]. Do not modify them,
or modify them here and there in a consistent manner. *)
type t = int type t = int
let import (prod, pos) = let low_bits =
assert (pos < 128); 10 (* have you read the above warning? *)
(Production.p2i prod) lsl 7 + pos
let low_limit =
1 lsl low_bits
let export t = let export t =
(Production.i2p (t lsr 7), t mod 128) (Production.i2p (t lsr low_bits), t mod low_limit)
let import (prod, pos) =
assert (pos < low_limit);
(Production.p2i prod) lsl low_bits + pos
let marshal (item : t) : int = let marshal (item : t) : int =
item item
(* In order to guarantee that the assertion in [import] cannot fail,
we check up front that every production is reasonably short. *)
let () =
Production.iter (fun index ->
let length = Production.length index in
if low_limit <= length then
Error.error
(Production.positions index)
"The length of this production is %d, which exceeds the limit of %d."
length (low_limit - 1)
)
(* Comparison. *) (* Comparison. *)
let equal (item1 : t) (item2: t) = let equal (item1 : t) (item2: t) =
...@@ -394,4 +424,3 @@ module Closure (L : Lookahead.S) = struct ...@@ -394,4 +424,3 @@ module Closure (L : Lookahead.S) = struct
(* End of closure computation *) (* End of closure computation *)
end end
File "crazy_long_production.mly", line 179, characters 11-10258:
Error: The length of this production is 1281, which exceeds the limit of 1023.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -3595,6 +3595,17 @@ ...@@ -3595,6 +3595,17 @@
(chdir ../good (run menhir --explain -lg 2 -la 2 -lc 2 %{deps}))))) (chdir ../good (run menhir --explain -lg 2 -la 2 -lc 2 %{deps})))))
(rule (alias parser_raw) (rule (alias parser_raw)
(action (diff ../good/parser_raw.exp parser_raw.out))) (action (diff ../good/parser_raw.exp parser_raw.out)))
(rule (target partest.opp.out) (deps ../good/partest.mly)
(action
(with-outputs-to %{target}
(chdir ../good (run menhir --only-preprocess %{deps})))))
(rule (alias partest)
(action (diff ../good/partest.opp.exp partest.opp.out)))
(rule (target partest.out) (deps ../good/partest.mly)
(action
(with-outputs-to %{target}
(chdir ../good (run menhir --explain -lg 2 -la 2 -lc 2 %{deps})))))
(rule (alias partest) (action (diff ../good/partest.exp partest.out)))
(rule (target permutation.opp.out) (deps ../good/permutation.mly) (rule (target permutation.opp.out) (deps ../good/permutation.mly)
(action (action
(with-outputs-to %{target} (with-outputs-to %{target}
...@@ -4701,6 +4712,14 @@ ...@@ -4701,6 +4712,14 @@
(action (action
(diff ../bad/constant-inline-in-multiple-def-1.expected (diff ../bad/constant-inline-in-multiple-def-1.expected
constant-inline-in-multiple-def-1.result))) constant-inline-in-multiple-def-1.result)))
(rule (target crazy_long_production.result)
(deps ../bad/crazy_long_production.mly)
(action
(with-outputs-to %{target}
(chdir ../bad (with-accepted-exit-codes (not 0) (run menhir %{deps}))))))
(rule (alias crazy_long_production)
(action
(diff ../bad/crazy_long_production.expected crazy_long_production.result)))
(rule (target cyclic-parameterized-definition.result) (rule (target cyclic-parameterized-definition.result)
(deps ../bad/cyclic-parameterized-definition.mly) (deps ../bad/cyclic-parameterized-definition.mly)
(action (action
...@@ -5591,9 +5610,9 @@ ...@@ -5591,9 +5610,9 @@
(alias condition_parser) (alias confluence) (alias confluence-fnf) (alias condition_parser) (alias confluence) (alias confluence-fnf)
(alias confluence-psl) (alias constant-arity-in-multiple-def-1) (alias confluence-psl) (alias constant-arity-in-multiple-def-1)
(alias constant-inline-in-multiple-def-1) (alias couac) (alias constant-inline-in-multiple-def-1) (alias couac)
(alias cppo_ocamlbuild.1.6.0-cppo_parser) (alias cubicle.1.1.2-parser) (alias cppo_ocamlbuild.1.6.0-cppo_parser) (alias crazy_long_production)
(alias cudf.0.9-cudf_type_parser) (alias cutdown) (alias cubicle.1.1.2-parser) (alias cudf.0.9-cudf_type_parser)
(alias cyclic-parameterized-definition) (alias dario) (alias cutdown) (alias cyclic-parameterized-definition) (alias dario)
(alias datalog.0.5.2-topDownParser) (alias dbforge.2.0.1-sqml_parser) (alias datalog.0.5.2-topDownParser) (alias dbforge.2.0.1-sqml_parser)
(alias debian-formats.0.1.1-DF822_parser) (alias declaration-error-a) (alias debian-formats.0.1.1-DF822_parser) (alias declaration-error-a)
(alias declaration-error-b) (alias dedukti.2.6.0-menhir_parser) (alias declaration-error-b) (alias dedukti.2.6.0-menhir_parser)
...@@ -5694,7 +5713,7 @@ ...@@ -5694,7 +5713,7 @@
(alias parameterized-start) (alias parameterized-start-weird) (alias parameterized-start) (alias parameterized-start-weird)
(alias parentheses) (alias parse_xquery) (alias parser_cocci_menhir) (alias parentheses) (alias parse_xquery) (alias parser_cocci_menhir)
(alias parser_cpp) (alias parser_css) (alias parser_java) (alias parser_js) (alias parser_cpp) (alias parser_css) (alias parser_java) (alias parser_js)
(alias parser_php) (alias parser_raw) (alias permutation) (alias parser_php) (alias parser_raw) (alias partest) (alias permutation)
(alias permutation-growth) (alias petit-1) (alias photos) (alias phpparser) (alias permutation-growth) (alias petit-1) (alias photos) (alias phpparser)
(alias pippijn) (alias positional-identifier-clash) (alias pre_parser) (alias pippijn) (alias positional-identifier-clash) (alias pre_parser)
(alias prec-inline-non-tail) (alias prec-inline-prec) (alias prec_inline) (alias prec-inline-non-tail) (alias prec-inline-prec) (alias prec_inline)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment