3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
28 exception BaseUriNotSetYet
31 (CicNotationPt.term, CicNotationPt.term,
32 CicNotationPt.term GrafiteAst.reduction, string)
36 (Cic.term, Cic.lazy_term, Cic.lazy_term GrafiteAst.reduction, string)
39 let singleton msg = function
43 Printf.sprintf "GrafiteDisambiguate.singleton (%s): %u interpretations"
46 HLog.debug debug; assert false
48 let __Implicit = "__Implicit__"
49 let __Closed_Implicit = "__Closed_Implicit__"
51 let cic_mk_choice = function
52 | LexiconAst.Symbol_alias (name, _, dsc) ->
53 if name = __Implicit then
54 dsc, `Sym_interp (fun _ -> Cic.Implicit None)
55 else if name = __Closed_Implicit then
56 dsc, `Sym_interp (fun _ -> Cic.Implicit (Some `Closed))
58 DisambiguateChoices.cic_lookup_symbol_by_dsc name dsc
59 | LexiconAst.Number_alias (_, dsc) ->
60 DisambiguateChoices.lookup_num_by_dsc dsc
61 | LexiconAst.Ident_alias (name, uri) ->
63 (fun l->assert(l = []);CicUtil.term_of_uri (UriManager.uri_of_string uri))
66 let ncic_mk_choice = function
67 | LexiconAst.Symbol_alias (name, _, dsc) ->
68 if name = __Implicit then
69 dsc, `Sym_interp (fun _ -> NCic.Implicit `Term)
70 else if name = __Closed_Implicit then
71 dsc, `Sym_interp (fun _ -> NCic.Implicit `Closed)
73 DisambiguateChoices.lookup_symbol_by_dsc
74 ~mk_implicit:(function
75 | true -> NCic.Implicit `Closed
76 | false -> NCic.Implicit `Term)
78 (NCic.Appl l)::tl -> NCic.Appl (l@tl) | l -> NCic.Appl l)
79 ~term_of_uri:(fun uri ->
80 fst (OCic2NCic.convert_term uri (CicUtil.term_of_uri uri)))
82 | LexiconAst.Number_alias (_, dsc) ->
83 let desc,f = DisambiguateChoices.lookup_num_by_dsc dsc in
86 fst (OCic2NCic.convert_term
87 (UriManager.uri_of_string "cic:/xxx/x.con")
88 (match f with `Num_interp f -> f num | _ -> assert false)))
89 | LexiconAst.Ident_alias (name, uri) ->
91 (fun l->assert(l = []);
92 let uri = UriManager.uri_of_string uri in
93 fst (OCic2NCic.convert_term uri (CicUtil.term_of_uri uri)))
100 LexiconAst.Symbol_alias (__Implicit,-1,"Fake Implicit")
102 LexiconAst.Symbol_alias (__Closed_Implicit,-1,"Fake Closed Implicit")
105 let lookup_in_library
106 interactive_user_uri_choice input_or_locate_uri item
108 let mk_ident_alias id u =
109 LexiconAst.Ident_alias (id,UriManager.string_of_uri u)
111 let mk_num_alias instance =
113 (fun dsc,_ -> LexiconAst.Number_alias (instance,dsc))
114 (DisambiguateChoices.lookup_num_choices())
116 let mk_symbol_alias symb ino (dsc, _,_) =
117 LexiconAst.Symbol_alias (symb,ino,dsc)
119 let dbd = LibraryDb.instance () in
120 let choices_of_id id =
121 let uris = Whelp.locate ~dbd id in
126 ~title:("URI matching \"" ^ id ^ "\" unknown.")
133 interactive_user_uri_choice ~selection_mode:`MULTIPLE
134 ?ok:(Some "Try selected.")
135 ?enable_button_for_non_vars:(Some true)
136 ~title:"Ambiguous input."
137 ~msg: ("Ambiguous input \"" ^ id ^
138 "\". Please, choose one or more interpretations:")
143 | DisambiguateTypes.Id id ->
144 let uris = choices_of_id id in
145 List.map (mk_ident_alias id) uris
146 | DisambiguateTypes.Symbol (symb, ino) ->
148 List.map (mk_symbol_alias symb ino)
149 (TermAcicContent.lookup_interpretations symb)
151 TermAcicContent.Interpretation_not_found -> [])
152 | DisambiguateTypes.Num instance -> mk_num_alias instance
155 (** @param term not meaningful when context is given *)
156 let disambiguate_term goal text prefix_len lexicon_status_ref context metasenv
158 let lexicon_status = !lexicon_status_ref in
159 let (diff, metasenv, subst, cic, _) =
161 (CicDisambiguate.disambiguate_term
162 ~aliases:lexicon_status.LexiconEngine.aliases
163 ?goal ~universe:(Some lexicon_status.LexiconEngine.multi_aliases)
165 ~mk_choice:cic_mk_choice
167 ~description_of_alias:LexiconAst.description_of_alias
168 ~context ~metasenv ~subst:[] (text,prefix_len,term))
170 let lexicon_status = LexiconEngine.set_proof_aliases lexicon_status diff in
171 lexicon_status_ref := lexicon_status;
172 metasenv,(*subst,*) cic
175 (** disambiguate_lazy_term (circa): term -> (unit -> status) * lazy_term
176 * rationale: lazy_term will be invoked in different context to obtain a term,
177 * each invocation will disambiguate the term and can add aliases. Once all
178 * disambiguations have been performed, the first returned function can be
179 * used to obtain the resulting aliases *)
180 let disambiguate_lazy_term goal text prefix_len lexicon_status_ref term =
181 (fun context metasenv ugraph ->
182 let lexicon_status = !lexicon_status_ref in
183 let (diff, metasenv, _, cic, ugraph) =
185 (CicDisambiguate.disambiguate_term
187 ~mk_choice:cic_mk_choice
189 ~description_of_alias:LexiconAst.description_of_alias
190 ~initial_ugraph:ugraph ~aliases:lexicon_status.LexiconEngine.aliases
191 ~universe:(Some lexicon_status.LexiconEngine.multi_aliases)
192 ~context ~metasenv ~subst:[] ?goal
193 (text,prefix_len,term)) in
194 let lexicon_status = LexiconEngine.set_proof_aliases lexicon_status diff in
195 lexicon_status_ref := lexicon_status;
196 cic, metasenv, ugraph)
199 let disambiguate_pattern
200 text prefix_len lexicon_status_ref (wanted, hyp_paths, goal_path)
202 let interp path =CicDisambiguate.interpretate_path [] path in
203 let goal_path = HExtlib.map_option interp goal_path in
204 let hyp_paths = List.map (fun (name, path) -> name, interp path) hyp_paths in
210 disambiguate_lazy_term None text prefix_len lexicon_status_ref wanted
214 (wanted, hyp_paths, goal_path)
217 let disambiguate_reduction_kind text prefix_len lexicon_status_ref = function
218 | `Unfold (Some t) ->
220 disambiguate_lazy_term None text prefix_len lexicon_status_ref t in
225 | `Whd as kind -> kind
228 let disambiguate_auto_params
229 disambiguate_term metasenv context (terms, params)
231 let metasenv, terms =
233 (fun t (metasenv, terms) ->
234 let metasenv,t = disambiguate_term context metasenv t in
235 metasenv,t::terms) terms (metasenv, [])
237 metasenv, (terms, params)
240 let disambiguate_just disambiguate_term context metasenv =
243 let metasenv,t = disambiguate_term context metasenv t in
246 let metasenv,params = disambiguate_auto_params disambiguate_term metasenv
249 metasenv, `Auto params
252 let rec disambiguate_tactic
253 lexicon_status_ref context metasenv goal (text,prefix_len,tactic)
255 let disambiguate_term_hint =
256 disambiguate_term goal text prefix_len lexicon_status_ref in
257 let disambiguate_term =
258 disambiguate_term None text prefix_len lexicon_status_ref in
259 let disambiguate_pattern =
260 disambiguate_pattern text prefix_len lexicon_status_ref in
261 let disambiguate_reduction_kind =
262 disambiguate_reduction_kind text prefix_len lexicon_status_ref in
263 let disambiguate_lazy_term =
264 disambiguate_lazy_term None text prefix_len lexicon_status_ref in
265 let disambiguate_tactic metasenv tac =
266 disambiguate_tactic lexicon_status_ref context metasenv goal (text,prefix_len,tac)
268 let disambiguate_auto_params m p =
269 disambiguate_auto_params disambiguate_term m context p
272 (* Higher order tactics *)
273 | GrafiteAst.Progress (loc,tac) ->
274 let metasenv,tac = disambiguate_tactic metasenv tac in
275 metasenv,GrafiteAst.Progress (loc,tac)
276 | GrafiteAst.Solve (loc,tacl) ->
279 (fun tac (metasenv,tacl) ->
280 let metasenv,tac = disambiguate_tactic metasenv tac in
284 metasenv,GrafiteAst.Solve (loc,tacl)
285 | GrafiteAst.Try (loc,tac) ->
286 let metasenv,tac = disambiguate_tactic metasenv tac in
287 metasenv,GrafiteAst.Try (loc,tac)
288 | GrafiteAst.First (loc,tacl) ->
291 (fun tac (metasenv,tacl) ->
292 let metasenv,tac = disambiguate_tactic metasenv tac in
296 metasenv,GrafiteAst.First (loc,tacl)
297 | GrafiteAst.Seq (loc,tacl) ->
300 (fun tac (metasenv,tacl) ->
301 let metasenv,tac = disambiguate_tactic metasenv tac in
305 metasenv,GrafiteAst.Seq (loc,tacl)
306 | GrafiteAst.Repeat (loc,tac) ->
307 let metasenv,tac = disambiguate_tactic metasenv tac in
308 metasenv,GrafiteAst.Repeat (loc,tac)
309 | GrafiteAst.Do (loc,n,tac) ->
310 let metasenv,tac = disambiguate_tactic metasenv tac in
311 metasenv,GrafiteAst.Do (loc,n,tac)
312 | GrafiteAst.Then (loc,tac,tacl) ->
313 let metasenv,tac = disambiguate_tactic metasenv tac in
316 (fun tac (metasenv,tacl) ->
317 let metasenv,tac = disambiguate_tactic metasenv tac in
321 metasenv,GrafiteAst.Then (loc,tac,tacl)
322 (* First order tactics *)
323 | GrafiteAst.Absurd (loc, term) ->
324 let metasenv,cic = disambiguate_term context metasenv term in
325 metasenv,GrafiteAst.Absurd (loc, cic)
326 | GrafiteAst.Apply (loc, term) ->
327 let metasenv,cic = disambiguate_term context metasenv term in
328 metasenv,GrafiteAst.Apply (loc, cic)
329 | GrafiteAst.ApplyRule (loc, term) ->
330 let metasenv,cic = disambiguate_term_hint context metasenv term in
331 metasenv,GrafiteAst.ApplyRule (loc, cic)
332 | GrafiteAst.ApplyP (loc, term) ->
333 let metasenv,cic = disambiguate_term context metasenv term in
334 metasenv,GrafiteAst.ApplyP (loc, cic)
335 | GrafiteAst.ApplyS (loc, term, params) ->
336 let metasenv, params = disambiguate_auto_params metasenv params in
337 let metasenv,cic = disambiguate_term context metasenv term in
338 metasenv,GrafiteAst.ApplyS (loc, cic, params)
339 | GrafiteAst.Assumption loc ->
340 metasenv,GrafiteAst.Assumption loc
341 | GrafiteAst.AutoBatch (loc,params) ->
342 let metasenv, params = disambiguate_auto_params metasenv params in
343 metasenv,GrafiteAst.AutoBatch (loc,params)
344 | GrafiteAst.Cases (loc, what, pattern, idents) ->
345 let metasenv,what = disambiguate_term context metasenv what in
346 let pattern = disambiguate_pattern pattern in
347 metasenv,GrafiteAst.Cases (loc, what, pattern, idents)
348 | GrafiteAst.Change (loc, pattern, with_what) ->
349 let with_what = disambiguate_lazy_term with_what in
350 let pattern = disambiguate_pattern pattern in
351 metasenv,GrafiteAst.Change (loc, pattern, with_what)
352 | GrafiteAst.Clear (loc,id) ->
353 metasenv,GrafiteAst.Clear (loc,id)
354 | GrafiteAst.ClearBody (loc,id) ->
355 metasenv,GrafiteAst.ClearBody (loc,id)
356 | GrafiteAst.Compose (loc, t1, t2, times, spec) ->
357 let metasenv,t1 = disambiguate_term context metasenv t1 in
360 | None -> metasenv, None
362 let m, t2 = disambiguate_term context metasenv t2 in
365 metasenv, GrafiteAst.Compose (loc, t1, t2, times, spec)
366 | GrafiteAst.Constructor (loc,n) ->
367 metasenv,GrafiteAst.Constructor (loc,n)
368 | GrafiteAst.Contradiction loc ->
369 metasenv,GrafiteAst.Contradiction loc
370 | GrafiteAst.Cut (loc, ident, term) ->
371 let metasenv,cic = disambiguate_term context metasenv term in
372 metasenv,GrafiteAst.Cut (loc, ident, cic)
373 | GrafiteAst.Decompose (loc, names) ->
374 metasenv,GrafiteAst.Decompose (loc, names)
375 | GrafiteAst.Demodulate (loc, params) ->
376 let metasenv, params = disambiguate_auto_params metasenv params in
377 metasenv,GrafiteAst.Demodulate (loc, params)
378 | GrafiteAst.Destruct (loc, Some terms) ->
379 let map term (metasenv, terms) =
380 let metasenv, term = disambiguate_term context metasenv term in
381 metasenv, term :: terms
383 let metasenv, terms = List.fold_right map terms (metasenv, []) in
384 metasenv, GrafiteAst.Destruct(loc, Some terms)
385 | GrafiteAst.Destruct (loc, None) ->
386 metasenv,GrafiteAst.Destruct(loc,None)
387 | GrafiteAst.Exact (loc, term) ->
388 let metasenv,cic = disambiguate_term context metasenv term in
389 metasenv,GrafiteAst.Exact (loc, cic)
390 | GrafiteAst.Elim (loc, what, Some using, pattern, specs) ->
391 let metasenv,what = disambiguate_term context metasenv what in
392 let metasenv,using = disambiguate_term context metasenv using in
393 let pattern = disambiguate_pattern pattern in
394 metasenv,GrafiteAst.Elim (loc, what, Some using, pattern, specs)
395 | GrafiteAst.Elim (loc, what, None, pattern, specs) ->
396 let metasenv,what = disambiguate_term context metasenv what in
397 let pattern = disambiguate_pattern pattern in
398 metasenv,GrafiteAst.Elim (loc, what, None, pattern, specs)
399 | GrafiteAst.ElimType (loc, what, Some using, specs) ->
400 let metasenv,what = disambiguate_term context metasenv what in
401 let metasenv,using = disambiguate_term context metasenv using in
402 metasenv,GrafiteAst.ElimType (loc, what, Some using, specs)
403 | GrafiteAst.ElimType (loc, what, None, specs) ->
404 let metasenv,what = disambiguate_term context metasenv what in
405 metasenv,GrafiteAst.ElimType (loc, what, None, specs)
406 | GrafiteAst.Exists loc ->
407 metasenv,GrafiteAst.Exists loc
408 | GrafiteAst.Fail loc ->
409 metasenv,GrafiteAst.Fail loc
410 | GrafiteAst.Fold (loc,red_kind, term, pattern) ->
411 let pattern = disambiguate_pattern pattern in
412 let term = disambiguate_lazy_term term in
413 let red_kind = disambiguate_reduction_kind red_kind in
414 metasenv,GrafiteAst.Fold (loc, red_kind, term, pattern)
415 | GrafiteAst.FwdSimpl (loc, hyp, names) ->
416 metasenv,GrafiteAst.FwdSimpl (loc, hyp, names)
417 | GrafiteAst.Fourier loc ->
418 metasenv,GrafiteAst.Fourier loc
419 | GrafiteAst.Generalize (loc,pattern,ident) ->
420 let pattern = disambiguate_pattern pattern in
421 metasenv,GrafiteAst.Generalize (loc,pattern,ident)
422 | GrafiteAst.IdTac loc ->
423 metasenv,GrafiteAst.IdTac loc
424 | GrafiteAst.Intros (loc, specs) ->
425 metasenv,GrafiteAst.Intros (loc, specs)
426 | GrafiteAst.Inversion (loc, term) ->
427 let metasenv,term = disambiguate_term context metasenv term in
428 metasenv,GrafiteAst.Inversion (loc, term)
429 | GrafiteAst.LApply (loc, linear, depth, to_what, what, ident) ->
430 let f term (metasenv, to_what) =
431 let metasenv, term = disambiguate_term context metasenv term in
432 metasenv, term :: to_what
434 let metasenv, to_what = List.fold_right f to_what (metasenv, []) in
435 let metasenv, what = disambiguate_term context metasenv what in
436 metasenv,GrafiteAst.LApply (loc, linear, depth, to_what, what, ident)
437 | GrafiteAst.Left loc ->
438 metasenv,GrafiteAst.Left loc
439 | GrafiteAst.LetIn (loc, term, name) ->
440 let metasenv,term = disambiguate_term context metasenv term in
441 metasenv,GrafiteAst.LetIn (loc,term,name)
442 | GrafiteAst.Reduce (loc, red_kind, pattern) ->
443 let pattern = disambiguate_pattern pattern in
444 let red_kind = disambiguate_reduction_kind red_kind in
445 metasenv,GrafiteAst.Reduce(loc, red_kind, pattern)
446 | GrafiteAst.Reflexivity loc ->
447 metasenv,GrafiteAst.Reflexivity loc
448 | GrafiteAst.Replace (loc, pattern, with_what) ->
449 let pattern = disambiguate_pattern pattern in
450 let with_what = disambiguate_lazy_term with_what in
451 metasenv,GrafiteAst.Replace (loc, pattern, with_what)
452 | GrafiteAst.Rewrite (loc, dir, t, pattern, names) ->
453 let metasenv,term = disambiguate_term context metasenv t in
454 let pattern = disambiguate_pattern pattern in
455 metasenv,GrafiteAst.Rewrite (loc, dir, term, pattern, names)
456 | GrafiteAst.Right loc ->
457 metasenv,GrafiteAst.Right loc
458 | GrafiteAst.Ring loc ->
459 metasenv,GrafiteAst.Ring loc
460 | GrafiteAst.Split loc ->
461 metasenv,GrafiteAst.Split loc
462 | GrafiteAst.Symmetry loc ->
463 metasenv,GrafiteAst.Symmetry loc
464 | GrafiteAst.Transitivity (loc, term) ->
465 let metasenv,cic = disambiguate_term context metasenv term in
466 metasenv,GrafiteAst.Transitivity (loc, cic)
468 | GrafiteAst.Assume (loc, id, term) ->
469 let metasenv,cic = disambiguate_term context metasenv term in
470 metasenv,GrafiteAst.Assume (loc, id, cic)
471 | GrafiteAst.Suppose (loc, term, id, term') ->
472 let metasenv,cic = disambiguate_term context metasenv term in
475 None -> metasenv,None
477 let metasenv,t = disambiguate_term context metasenv t in
479 metasenv,GrafiteAst.Suppose (loc, cic, id, cic')
480 | GrafiteAst.Bydone (loc,just) ->
482 disambiguate_just disambiguate_term context metasenv just
484 metasenv,GrafiteAst.Bydone (loc, just)
485 | GrafiteAst.We_need_to_prove (loc,term,id,term') ->
486 let metasenv,cic = disambiguate_term context metasenv term in
489 None -> metasenv,None
491 let metasenv,t = disambiguate_term context metasenv t in
493 metasenv,GrafiteAst.We_need_to_prove (loc,cic,id,cic')
494 | GrafiteAst.By_just_we_proved (loc,just,term',id,term'') ->
496 disambiguate_just disambiguate_term context metasenv just in
497 let metasenv,cic' = disambiguate_term context metasenv term' in
500 None -> metasenv,None
502 let metasenv,t = disambiguate_term context metasenv t in
504 metasenv,GrafiteAst.By_just_we_proved (loc,just,cic',id,cic'')
505 | GrafiteAst.We_proceed_by_cases_on (loc, term, term') ->
506 let metasenv,cic = disambiguate_term context metasenv term in
507 let metasenv,cic' = disambiguate_term context metasenv term' in
508 metasenv,GrafiteAst.We_proceed_by_cases_on (loc, cic, cic')
509 | GrafiteAst.We_proceed_by_induction_on (loc, term, term') ->
510 let metasenv,cic = disambiguate_term context metasenv term in
511 let metasenv,cic' = disambiguate_term context metasenv term' in
512 metasenv,GrafiteAst.We_proceed_by_induction_on (loc, cic, cic')
513 | GrafiteAst.Byinduction (loc, term, id) ->
514 let metasenv,cic = disambiguate_term context metasenv term in
515 metasenv,GrafiteAst.Byinduction(loc, cic, id)
516 | GrafiteAst.Thesisbecomes (loc, term) ->
517 let metasenv,cic = disambiguate_term context metasenv term in
518 metasenv,GrafiteAst.Thesisbecomes (loc, cic)
519 | GrafiteAst.ExistsElim (loc, just, id1, term1, id2, term2) ->
521 disambiguate_just disambiguate_term context metasenv just in
522 let metasenv,cic' = disambiguate_term context metasenv term1 in
523 let cic''= disambiguate_lazy_term term2 in
524 metasenv,GrafiteAst.ExistsElim(loc, just, id1, cic', id2, cic'')
525 | GrafiteAst.AndElim (loc, just, id, term1, id1, term2) ->
527 disambiguate_just disambiguate_term context metasenv just in
528 let metasenv,cic'= disambiguate_term context metasenv term1 in
529 let metasenv,cic''= disambiguate_term context metasenv term2 in
530 metasenv,GrafiteAst.AndElim(loc, just, id, cic', id1, cic'')
531 | GrafiteAst.Case (loc, id, params) ->
532 let metasenv,params' =
534 (fun (id,term) (metasenv,params) ->
535 let metasenv,cic = disambiguate_term context metasenv term in
536 metasenv,(id,cic)::params
537 ) params (metasenv,[])
539 metasenv,GrafiteAst.Case(loc, id, params')
540 | GrafiteAst.RewritingStep (loc, term1, term2, term3, cont) ->
543 None -> metasenv,None
545 let metasenv,t = disambiguate_term context metasenv t in
546 metasenv,Some (start,t) in
547 let metasenv,cic'= disambiguate_term context metasenv term2 in
551 let metasenv,term = disambiguate_term context metasenv term in
552 metasenv, `SolveWith term
554 let metasenv, params = disambiguate_auto_params metasenv params in
555 metasenv,`Auto params
557 let metasenv,t = disambiguate_term context metasenv t in
559 | `Proof as t -> metasenv,t in
560 metasenv,GrafiteAst.RewritingStep (loc, cic, cic', cic'', cont)
562 let disambiguate_obj lexicon_status ?baseuri metasenv (text,prefix_len,obj) =
565 match baseuri with Some x -> x | None -> raise BaseUriNotSetYet
569 | CicNotationPt.Inductive (_,(name,_,_,_)::_)
570 | CicNotationPt.Record (_,name,_,_) -> name ^ ".ind"
571 | CicNotationPt.Theorem (_,name,_,_) -> name ^ ".con"
572 | CicNotationPt.Inductive _ -> assert false
574 UriManager.uri_of_string (baseuri ^ "/" ^ name)
577 (NCicLibrary.clear_cache ();
578 NCicEnvironment.invalidate ();
582 | Some (Cic.CurrentProof (_,metasenv, _, ty,_,_)) ->
584 CicTypeChecker.type_of_aux' metasenv [] ty CicUniv.empty_ugraph
587 | Some (Cic.Constant (_,_, ty,_,_)) ->
589 CicTypeChecker.type_of_aux' [] [] ty CicUniv.empty_ugraph
592 | _ -> CicUniv.empty_ugraph
596 prerr_endline "PRIMA COERCIONS";
597 let _,l = CicUniv.do_rank graph in
599 prerr_endline (CicUniv.string_of_universe k ^ " = " ^ string_of_int
600 (CicUniv.get_rank k))) l;
605 (fun graph (_,_,l) ->
607 (fun graph (uri,_,_) ->
608 let _,g = CicTypeChecker.typecheck uri in
609 CicUniv.merge_ugraphs ~base_ugraph:graph ~increment:(g,uri))
611 graph (CoercDb.to_list ())
613 ignore(CicUniv.do_rank graph);
617 prerr_endline "DOPO COERCIONS";
618 let _,l = CicUniv.do_rank graph in
620 prerr_endline (CicUniv.string_of_universe k ^ " = " ^ string_of_int
621 (CicUniv.get_rank k))) l;
625 prerr_endline "INIZIO NUOVA DISAMBIGUAZIONE";
626 let time = Unix.gettimeofday () in
629 NCicDisambiguate.disambiguate_obj
630 ~lookup_in_library:lookup_in_library
631 ~description_of_alias:LexiconAst.description_of_alias
632 ~mk_choice:ncic_mk_choice
634 ~uri:(OCic2NCic.nuri_of_ouri uri)
635 ~coercion_db:(NCicCoercion.db ())
636 ~aliases:lexicon_status.LexiconEngine.aliases
637 ~universe:(Some lexicon_status.LexiconEngine.multi_aliases)
638 (text,prefix_len,obj)
641 let time = Unix.gettimeofday () -. time in
642 (* NCicTypeChecker.typecheck_obj obj; *)
643 prerr_endline ("NUOVA DISAMBIGUAZIONE OK: "^ string_of_float time);
646 let u,i,m,_,o = obj in
650 prerr_endline (NCicPp.ppobj obj)
652 prerr_endline ("NUOVA DISAMBIGUAZIONE AMBIGUO!!!!!!!!! "))
654 | MultiPassDisambiguator.DisambiguationError (_,s) ->
655 prerr_endline ("ERRORE NUOVA DISAMBIGUAZIONE ("
656 ^UriManager.string_of_uri uri^
659 (List.map (fun _,_,x,_ -> snd (Lazy.force x)) (List.flatten s)))
660 (* | exn -> prerr_endline (Printexc.to_string exn) *)
667 (* let time = Unix.gettimeofday () in *)
670 let (diff, metasenv, _, cic, _) =
672 (CicDisambiguate.disambiguate_obj
674 ~mk_choice:cic_mk_choice
676 ~description_of_alias:LexiconAst.description_of_alias
677 ~aliases:lexicon_status.LexiconEngine.aliases
678 ~universe:(Some lexicon_status.LexiconEngine.multi_aliases)
680 (text,prefix_len,obj)) in
684 let time = Unix.gettimeofday () -. time in
685 prerr_endline ("VECCHIA DISAMBIGUAZIONE ("^
686 UriManager.string_of_uri uri ^"): " ^ string_of_float time);
688 (* try_new (Some cic); *)
691 let lexicon_status = LexiconEngine.set_proof_aliases lexicon_status diff in
692 lexicon_status, metasenv, cic
695 | Sys.Break as exn -> raise exn
702 let disambiguate_command lexicon_status ?baseuri metasenv (text,prefix_len,cmd)=
704 | GrafiteAst.Index(loc,key,uri) ->
705 let lexicon_status_ref = ref lexicon_status in
706 let disambiguate_term =
707 disambiguate_term None text prefix_len lexicon_status_ref [] in
708 let disambiguate_term_option metasenv =
710 None -> metasenv,None
712 let metasenv,t = disambiguate_term metasenv t in
715 let metasenv,key = disambiguate_term_option metasenv key in
716 !lexicon_status_ref, metasenv,GrafiteAst.Index(loc,key,uri)
717 | GrafiteAst.PreferCoercion (loc,t) ->
718 let lexicon_status_ref = ref lexicon_status in
719 let disambiguate_term =
720 disambiguate_term None text prefix_len lexicon_status_ref [] in
721 let metasenv,t = disambiguate_term metasenv t in
722 !lexicon_status_ref, metasenv, GrafiteAst.PreferCoercion (loc,t)
723 | GrafiteAst.Coercion (loc,t,b,a,s) ->
724 let lexicon_status_ref = ref lexicon_status in
725 let disambiguate_term =
726 disambiguate_term None text prefix_len lexicon_status_ref [] in
727 let metasenv,t = disambiguate_term metasenv t in
728 !lexicon_status_ref, metasenv, GrafiteAst.Coercion (loc,t,b,a,s)
729 | GrafiteAst.UnificationHint (loc, t, n) ->
730 let lexicon_status_ref = ref lexicon_status in
731 let disambiguate_term =
732 disambiguate_term None text prefix_len lexicon_status_ref [] in
733 let metasenv,t = disambiguate_term metasenv t in
734 !lexicon_status_ref, metasenv, GrafiteAst.UnificationHint (loc,t,n)
735 | GrafiteAst.Default _
737 | GrafiteAst.Include _
740 | GrafiteAst.Set _ as cmd ->
741 lexicon_status,metasenv,cmd
742 | GrafiteAst.Obj (loc,obj) ->
743 let lexicon_status,metasenv,obj =
744 disambiguate_obj lexicon_status ?baseuri metasenv (text,prefix_len,obj)in
745 lexicon_status, metasenv, GrafiteAst.Obj (loc,obj)
746 | GrafiteAst.Relation (loc,id,a,aeq,refl,sym,trans) ->
747 let lexicon_status_ref = ref lexicon_status in
748 let disambiguate_term =
749 disambiguate_term None text prefix_len lexicon_status_ref [] in
750 let disambiguate_term_option metasenv =
752 None -> metasenv,None
754 let metasenv,t = disambiguate_term metasenv t in
757 let metasenv,a = disambiguate_term metasenv a in
758 let metasenv,aeq = disambiguate_term metasenv aeq in
759 let metasenv,refl = disambiguate_term_option metasenv refl in
760 let metasenv,sym = disambiguate_term_option metasenv sym in
761 let metasenv,trans = disambiguate_term_option metasenv trans in
762 !lexicon_status_ref, metasenv,
763 GrafiteAst.Relation (loc,id,a,aeq,refl,sym,trans)
765 let disambiguate_macro
766 lexicon_status_ref metasenv context (text,prefix_len, macro)
768 let disambiguate_term = disambiguate_term None text prefix_len lexicon_status_ref in
769 let disambiguate_reduction_kind =
770 disambiguate_reduction_kind text prefix_len lexicon_status_ref in
772 | GrafiteAst.WMatch (loc,term) ->
773 let metasenv,term = disambiguate_term context metasenv term in
774 metasenv,GrafiteAst.WMatch (loc,term)
775 | GrafiteAst.WInstance (loc,term) ->
776 let metasenv,term = disambiguate_term context metasenv term in
777 metasenv,GrafiteAst.WInstance (loc,term)
778 | GrafiteAst.WElim (loc,term) ->
779 let metasenv,term = disambiguate_term context metasenv term in
780 metasenv,GrafiteAst.WElim (loc,term)
781 | GrafiteAst.WHint (loc,term) ->
782 let metasenv,term = disambiguate_term context metasenv term in
783 metasenv,GrafiteAst.WHint (loc,term)
784 | GrafiteAst.Check (loc,term) ->
785 let metasenv,term = disambiguate_term context metasenv term in
786 metasenv,GrafiteAst.Check (loc,term)
787 | GrafiteAst.Eval (loc,kind,term) ->
788 let metasenv, term = disambiguate_term context metasenv term in
789 let kind = disambiguate_reduction_kind kind in
790 metasenv,GrafiteAst.Eval (loc,kind,term)
791 | GrafiteAst.AutoInteractive (loc, params) ->
792 let metasenv, params =
793 disambiguate_auto_params disambiguate_term metasenv context params in
794 metasenv, GrafiteAst.AutoInteractive (loc, params)
796 | GrafiteAst.WLocate _
797 | GrafiteAst.Inline _ as macro ->