@@ -60,9 +60,9 @@ type full_program = {
6060
6161let to_full_program (program : program ) (chains : Mast.chain_tag list ) :
6262 full_program =
63- let chains_orders =
63+ let chains_orders, _ =
6464 List. fold_left
65- (fun chains tag ->
65+ (fun ( chains , seen_customs ) tag ->
6666 let vars_to_rules, chain_rules =
6767 Mir.RuleMap. fold
6868 (fun rule_id rule (vars , rules ) ->
@@ -84,7 +84,73 @@ let to_full_program (program : program) (chains : Mast.chain_tag list) :
8484 let execution_order =
8585 Mir_dependency_graph. get_rules_execution_order dep_graph
8686 in
87- Mir.TagMap. add tag { dep_graph; execution_order } chains)
88- Mir.TagMap. empty chains
87+ let customs, _ =
88+ RuleMap. fold
89+ (fun rule_id rule (customs , in_primcorr ) ->
90+ List. fold_left
91+ (fun (customs , in_primcorr ) tag ->
92+ match tag with
93+ | Mast. Custom _ -> (
94+ let ipc =
95+ Mast. are_tags_part_of_chain rule.rule_tags Mast. PrimCorr
96+ in
97+ if in_primcorr && not ipc then
98+ Errors. raise_error
99+ " Custom chain must be attributed to rules with all \
100+ the exact same tagging."
101+ else
102+ match TagMap. find_opt tag customs with
103+ | Some rs ->
104+ ( TagMap. add tag (rule_id :: rs) customs,
105+ ipc || in_primcorr )
106+ | None ->
107+ ( TagMap. add tag [ rule_id ] customs,
108+ ipc || in_primcorr ))
109+ | _ -> (customs, in_primcorr))
110+ (customs, in_primcorr) rule.rule_tags)
111+ chain_rules (TagMap. empty, false )
112+ in
113+ let customs =
114+ TagMap. map
115+ (fun rules ->
116+ Mir_dependency_graph. pull_rules_dependencies dep_graph rules)
117+ customs
118+ in
119+ let seen_customs =
120+ TagMap. merge
121+ (fun custom_tag seen curr ->
122+ match (seen, curr) with
123+ | None , None -> None
124+ | Some _ , None -> seen
125+ | None , Some _ -> Some tag
126+ | Some s , Some _ -> (
127+ match (s, tag) with
128+ | Mast. Primitif , Mast. Corrective
129+ | Mast. Corrective , Mast. Primitif ->
130+ (* ignore this case *) seen
131+ | _ ->
132+ let custom_tag =
133+ match custom_tag with
134+ | Mast. Custom s -> s
135+ | _ -> assert false
136+ in
137+ Errors. raise_error
138+ (Format. asprintf
139+ " Rules with custom chain %s found with incompatible \
140+ tags %a and %a."
141+ custom_tag Format_mast. format_chain_tag s
142+ Format_mast. format_chain_tag tag)))
143+ seen_customs customs
144+ in
145+ let chains =
146+ TagMap. fold
147+ (fun tag (dep_graph , execution_order ) chains ->
148+ TagMap. add tag { dep_graph; execution_order } chains)
149+ customs
150+ (Mir.TagMap. add tag { dep_graph; execution_order } chains)
151+ in
152+ (chains, seen_customs))
153+ (Mir.TagMap. empty, Mir.TagMap. empty)
154+ chains
89155 in
90156 { program; chains_orders }
0 commit comments