621 fun prepare_sorts_env ctxt tys = |
621 fun prepare_sorts_env ctxt tys = |
622 let |
622 let |
623 val tsig = tsig_of ctxt; |
623 val tsig = tsig_of ctxt; |
624 val defaultS = Type.defaultS tsig; |
624 val defaultS = Type.defaultS tsig; |
625 |
625 |
626 fun constraint (xi, S) env = |
626 fun constraint (xi, raw_S) env = |
627 if S = dummyS orelse Term_Position.is_positionS S then env |
627 let val (ps, S) = Term_Position.decode_positionS raw_S in |
628 else |
628 if S = dummyS then env |
629 Vartab.insert (op =) (xi, Type.minimize_sort tsig S) env |
629 else |
630 handle Vartab.DUP _ => |
630 Vartab.insert (op =) (xi, Type.minimize_sort tsig S) env |
631 error ("Inconsistent sort constraints for type variable " ^ |
631 handle Vartab.DUP _ => |
632 quote (Term.string_of_vname' xi)); |
632 error ("Inconsistent sort constraints for type variable " ^ |
|
633 quote (Term.string_of_vname' xi) ^ |
|
634 space_implode " " (map Position.here ps)) |
|
635 end; |
|
636 |
633 val env = |
637 val env = |
634 (fold o fold_atyps) |
638 (fold o fold_atyps) |
635 (fn TFree (x, S) => constraint ((x, ~1), S) |
639 (fn TFree (x, S) => constraint ((x, ~1), S) |
636 | TVar v => constraint v |
640 | TVar v => constraint v |
637 | _ => I) tys Vartab.empty; |
641 | _ => I) tys Vartab.empty; |
646 else |
650 else |
647 error ("Sort constraint " ^ Syntax.string_of_sort ctxt S ^ |
651 error ("Sort constraint " ^ Syntax.string_of_sort ctxt S ^ |
648 " inconsistent with default " ^ Syntax.string_of_sort ctxt S' ^ |
652 " inconsistent with default " ^ Syntax.string_of_sort ctxt S' ^ |
649 " for type variable " ^ quote (Term.string_of_vname' xi))); |
653 " for type variable " ^ quote (Term.string_of_vname' xi))); |
650 |
654 |
651 fun add_report raw_S S reports = |
655 fun add_report S pos reports = |
652 (case Term_Position.decode_positionS raw_S of |
656 if Position.is_reported pos andalso not (AList.defined (op =) reports pos) then |
653 SOME pos => |
657 (pos, Position.reported_text pos Isabelle_Markup.sorting (Syntax.string_of_sort ctxt S)) |
654 if Position.is_reported pos andalso not (AList.defined (op =) reports pos) then |
658 :: reports |
655 (pos, Position.reported_text pos Isabelle_Markup.sorting (Syntax.string_of_sort ctxt S)) |
659 else reports; |
656 :: reports |
660 |
657 else reports |
661 val decode_pos = #1 o Term_Position.decode_positionS; |
658 | NONE => reports); |
|
659 |
662 |
660 val reports = |
663 val reports = |
661 (fold o fold_atyps) |
664 (fold o fold_atyps) |
662 (fn T => |
665 (fn T => |
663 if Term_Position.is_positionT T then I |
666 if Term_Position.is_positionT T then I |
664 else |
667 else |
665 (case T of |
668 (case T of |
666 TFree (x, raw_S) => add_report raw_S (get_sort (x, ~1)) |
669 TFree (x, raw_S) => fold (add_report (get_sort (x, ~1))) (decode_pos raw_S) |
667 | TVar (xi, raw_S) => add_report raw_S (get_sort xi) |
670 | TVar (xi, raw_S) => fold (add_report (get_sort xi)) (decode_pos raw_S) |
668 | _ => I)) tys []; |
671 | _ => I)) tys []; |
669 |
672 |
670 in (implode (map #2 reports), get_sort) end; |
673 in (implode (map #2 reports), get_sort) end; |
671 |
674 |
672 fun replace_sortsT get_sort = |
675 fun replace_sortsT get_sort = |