src/Pure/Syntax/syntax_phases.ML
changeset 45445 41e641a870de
parent 45444 ac069060e08a
child 45447 a97251eea458
equal deleted inserted replaced
45444:ac069060e08a 45445:41e641a870de
   211         val reports = Unsynchronized.ref reports0;
   211         val reports = Unsynchronized.ref reports0;
   212         fun report ps = Position.store_reports reports ps;
   212         fun report ps = Position.store_reports reports ps;
   213 
   213 
   214         fun decode ps qs bs (Const ("_constrain", _) $ t $ typ) =
   214         fun decode ps qs bs (Const ("_constrain", _) $ t $ typ) =
   215               (case Term_Position.decode_position typ of
   215               (case Term_Position.decode_position typ of
   216                 SOME p => decode (p :: ps) qs bs t
   216                 SOME (p, T) => Type.constraint T (decode (p :: ps) qs bs t)
   217               | NONE => Type.constraint (decode_typ typ) (decode ps qs bs t))
   217               | NONE => Type.constraint (decode_typ typ) (decode ps qs bs t))
   218           | decode ps qs bs (Const ("_constrainAbs", _) $ t $ typ) =
   218           | decode ps qs bs (Const ("_constrainAbs", _) $ t $ typ) =
   219               (case Term_Position.decode_position typ of
   219               (case Term_Position.decode_position typ of
   220                 SOME q => decode ps (q :: qs) bs t
   220                 SOME (q, T) => Type.constraint (T --> dummyT) (decode ps (q :: qs) bs t)
   221               | NONE => Type.constraint (decode_typ typ --> dummyT) (decode ps qs bs t))
   221               | NONE => Type.constraint (decode_typ typ --> dummyT) (decode ps qs bs t))
   222           | decode _ qs bs (Abs (x, T, t)) =
   222           | decode _ qs bs (Abs (x, T, t)) =
   223               let
   223               let
   224                 val id = serial ();
   224                 val id = serial ();
   225                 val _ = report qs (markup_bound true qs) (x, id);
   225                 val _ = report qs (markup_bound true qs) (x, id);
   792 val apply_typ_check = check fst false;
   792 val apply_typ_check = check fst false;
   793 val apply_term_check = check snd false;
   793 val apply_term_check = check snd false;
   794 val apply_typ_uncheck = check fst true;
   794 val apply_typ_uncheck = check fst true;
   795 val apply_term_uncheck = check snd true;
   795 val apply_term_uncheck = check snd true;
   796 
   796 
   797 fun prepare_types ctxt tys =
   797 fun prepare_sorts ctxt tys =
   798   let
   798   let
   799     fun constraint (xi: indexname, S) = S <> dummyS ? insert (op =) (xi, S);
   799     fun constraint (xi: indexname, S) = S <> dummyS ? insert (op =) (xi, S);
   800     val env =
   800     val env =
   801       (fold o fold_atyps)
   801       (fold o fold_atyps)
   802         (fn TFree (x, S) => constraint ((x, ~1), S)
   802         (fn TFree (x, S) => constraint ((x, ~1), S)
   811   end;
   811   end;
   812 
   812 
   813 in
   813 in
   814 
   814 
   815 fun check_typs ctxt =
   815 fun check_typs ctxt =
   816   prepare_types ctxt #>
   816   prepare_sorts ctxt #>
   817   apply_typ_check ctxt #>
   817   apply_typ_check ctxt #>
   818   Term_Sharing.typs (Proof_Context.theory_of ctxt);
   818   Term_Sharing.typs (Proof_Context.theory_of ctxt);
   819 
   819 
   820 fun check_terms ctxt =
   820 fun check_terms ctxt raw_ts =
   821   Term.burrow_types (prepare_types ctxt) #>
   821   let
   822   apply_term_check ctxt #>
   822     val (ts, ps) = Type_Infer_Context.prepare_positions ctxt raw_ts;
   823   Term_Sharing.terms (Proof_Context.theory_of ctxt);
   823     val tys = map (Logic.mk_type o snd) ps;
       
   824     val (ts', tys') =
       
   825       Term.burrow_types (prepare_sorts ctxt) ts @ tys
       
   826       |> apply_term_check ctxt
       
   827       |> chop (length ts);
       
   828     val _ =
       
   829       map2 (fn (pos, _) => fn ty =>
       
   830         if Position.is_reported pos then
       
   831           Markup.markup (Position.markup pos Markup.typing)
       
   832             (Syntax.string_of_typ ctxt (Logic.dest_type ty))
       
   833         else "") ps tys'
       
   834       |> implode |> Output.report
       
   835   in Term_Sharing.terms (Proof_Context.theory_of ctxt) ts' end;
   824 
   836 
   825 fun check_props ctxt = map (Type.constraint propT) #> check_terms ctxt;
   837 fun check_props ctxt = map (Type.constraint propT) #> check_terms ctxt;
   826 
   838 
   827 val uncheck_typs = apply_typ_uncheck;
   839 val uncheck_typs = apply_typ_uncheck;
   828 val uncheck_terms = apply_term_uncheck;
   840 val uncheck_terms = apply_term_uncheck;