File tree Expand file tree Collapse file tree 4 files changed +24
-0
lines changed Expand file tree Collapse file tree 4 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -1628,6 +1628,14 @@ let chose_indexing predicate l =
16281628 in
16291629 aux 0 l
16301630
1631+ let check_rule_pattern_in_clique clique { Data.CHR. pattern; rule_name } =
1632+ try
1633+ let outside =
1634+ List. find (fun x -> not (Data.CHR. in_clique clique x)) pattern in
1635+ error (" CHR rule " ^ rule_name ^ " : matches " ^ C. show outside ^
1636+ " which is not a constraint on which it is applied. Check the list of predicates after the \" constraint\" keyword." );
1637+ with Not_found -> ()
1638+
16311639let run
16321640 {
16331641 WithMain. types;
@@ -1653,6 +1661,7 @@ let run
16531661 let chr, clique = CHR. new_clique clique chr in
16541662 let rules = filter_if flags.defined_variables pifexpr rules in
16551663 let rules = List. map (compile_chr initial_depth) rules in
1664+ List. iter (check_rule_pattern_in_clique clique) rules;
16561665 List. fold_left (fun x y -> CHR. add_rule clique y x) chr rules)
16571666 CHR. empty chr in
16581667 let ifexpr { Ast.Clause. attributes = { Assembled. ifexpr } } = ifexpr in
Original file line number Diff line number Diff line change @@ -469,6 +469,7 @@ module CHR : sig
469469 val new_clique : constant list -> t -> t * clique
470470 val clique_of : constant -> t -> Constants.Set .t option
471471 val add_rule : clique -> rule -> t -> t
472+ val in_clique : clique -> constant -> bool
472473
473474 val rules_for : constant -> t -> rule list
474475
@@ -498,6 +499,8 @@ end = struct (* {{{ *)
498499
499500 let empty = { cliques = Constants.Map. empty; rules = Constants.Map. empty }
500501
502+ let in_clique m c = Constants.Set. mem c m
503+
501504 let new_clique cl ({ cliques } as chr ) =
502505 if cl = [] then error " empty clique" ;
503506 let c = List. fold_right Constants.Set. add cl Constants.Set. empty in
Original file line number Diff line number Diff line change 1+ constraint a {
2+
3+ rule b.
4+
5+ }
Original file line number Diff line number Diff line change @@ -208,3 +208,10 @@ let () = declare "accumulate_twice2"
208208 ~typecheck: true
209209 ~expectation: Test. Failure
210210 ()
211+
212+ let () = declare " CHR_no_clique"
213+ ~source_elpi: " chr_not_clique.elpi"
214+ ~description: " CHR rule on a non constraint"
215+ ~typecheck: true
216+ ~expectation: Test. Failure
217+ ()
You can’t perform that action at this time.
0 commit comments