merged
authorwenzelm
Tue Sep 29 18:14:08 2009 +0200 (2009-09-29)
changeset 32760ea6672bff5dd
parent 32759 1476fe841023
parent 32742 58e5f4ae52a6
child 32761 54fee94b2b29
merged
src/HOL/Tools/record.ML
     1.1 --- a/NEWS	Tue Sep 29 14:26:33 2009 +1000
     1.2 +++ b/NEWS	Tue Sep 29 18:14:08 2009 +0200
     1.3 @@ -182,6 +182,19 @@
     1.4  
     1.5  *** ML ***
     1.6  
     1.7 +* Structure Synchronized (cf. src/Pure/Concurrent/synchronized.ML)
     1.8 +provides a high-level programming interface to synchronized state
     1.9 +variables with atomic update.  This works via pure function
    1.10 +application within a critical section -- its runtime should be as
    1.11 +short as possible; beware of deadlocks if critical code is nested,
    1.12 +either directly or indirectly via other synchronized variables!
    1.13 +
    1.14 +* Structure Unsynchronized (cf. src/Pure/ML-Systems/unsynchronized.ML)
    1.15 +wraps raw ML references, explicitly indicating their non-thread-safe
    1.16 +behaviour.  The Isar toplevel keeps this structure open, to
    1.17 +accommodate Proof General as well as quick and dirty interactive
    1.18 +experiments with references.
    1.19 +
    1.20  * PARALLEL_CHOICE and PARALLEL_GOALS provide basic support for
    1.21  parallel tactical reasoning.
    1.22  
     2.1 --- a/src/CCL/ROOT.ML	Tue Sep 29 14:26:33 2009 +1000
     2.2 +++ b/src/CCL/ROOT.ML	Tue Sep 29 18:14:08 2009 +0200
     2.3 @@ -3,12 +3,11 @@
     2.4      Copyright   1993  University of Cambridge
     2.5  
     2.6  Classical Computational Logic based on First-Order Logic.
     2.7 +
     2.8 +A computational logic for an untyped functional language with
     2.9 +evaluation to weak head-normal form.
    2.10  *)
    2.11  
    2.12 -set eta_contract;
    2.13 -
    2.14 -(* CCL - a computational logic for an untyped functional language *)
    2.15 -(*                       with evaluation to weak head-normal form *)
    2.16 +Unsynchronized.set eta_contract;
    2.17  
    2.18  use_thys ["Wfd", "Fix"];
    2.19 -
     3.1 --- a/src/FOLP/IFOLP.thy	Tue Sep 29 14:26:33 2009 +1000
     3.2 +++ b/src/FOLP/IFOLP.thy	Tue Sep 29 18:14:08 2009 +0200
     3.3 @@ -69,7 +69,7 @@
     3.4  ML {*
     3.5  
     3.6  (*show_proofs:=true displays the proof terms -- they are ENORMOUS*)
     3.7 -val show_proofs = ref false;
     3.8 +val show_proofs = Unsynchronized.ref false;
     3.9  
    3.10  fun proof_tr [p,P] = Const (@{const_name Proof}, dummyT) $ P $ p;
    3.11  
     4.1 --- a/src/FOLP/simp.ML	Tue Sep 29 14:26:33 2009 +1000
     4.2 +++ b/src/FOLP/simp.ML	Tue Sep 29 18:14:08 2009 +0200
     4.3 @@ -49,7 +49,7 @@
     4.4  (* temporarily disabled:
     4.5    val extract_free_congs        : unit -> thm list
     4.6  *)
     4.7 -  val tracing   : bool ref
     4.8 +  val tracing   : bool Unsynchronized.ref
     4.9  end;
    4.10  
    4.11  functor SimpFun (Simp_data: SIMP_DATA) : SIMP =
    4.12 @@ -366,7 +366,7 @@
    4.13  
    4.14  (** Tracing **)
    4.15  
    4.16 -val tracing = ref false;
    4.17 +val tracing = Unsynchronized.ref false;
    4.18  
    4.19  (*Replace parameters by Free variables in P*)
    4.20  fun variants_abs ([],P) = P
     5.1 --- a/src/HOL/Code_Evaluation.thy	Tue Sep 29 14:26:33 2009 +1000
     5.2 +++ b/src/HOL/Code_Evaluation.thy	Tue Sep 29 18:14:08 2009 +0200
     5.3 @@ -249,14 +249,14 @@
     5.4  ML {*
     5.5  signature EVAL =
     5.6  sig
     5.7 -  val eval_ref: (unit -> term) option ref
     5.8 +  val eval_ref: (unit -> term) option Unsynchronized.ref
     5.9    val eval_term: theory -> term -> term
    5.10  end;
    5.11  
    5.12  structure Eval : EVAL =
    5.13  struct
    5.14  
    5.15 -val eval_ref = ref (NONE : (unit -> term) option);
    5.16 +val eval_ref = Unsynchronized.ref (NONE : (unit -> term) option);
    5.17  
    5.18  fun eval_term thy t =
    5.19    Code_ML.eval NONE ("Eval.eval_ref", eval_ref) I thy (HOLogic.mk_term_of (fastype_of t) t) [];
     6.1 --- a/src/HOL/Decision_Procs/cooper_tac.ML	Tue Sep 29 14:26:33 2009 +1000
     6.2 +++ b/src/HOL/Decision_Procs/cooper_tac.ML	Tue Sep 29 18:14:08 2009 +0200
     6.3 @@ -4,7 +4,7 @@
     6.4  
     6.5  signature COOPER_TAC =
     6.6  sig
     6.7 -  val trace: bool ref
     6.8 +  val trace: bool Unsynchronized.ref
     6.9    val linz_tac: Proof.context -> bool -> int -> tactic
    6.10    val setup: theory -> theory
    6.11  end
    6.12 @@ -12,7 +12,7 @@
    6.13  structure Cooper_Tac: COOPER_TAC =
    6.14  struct
    6.15  
    6.16 -val trace = ref false;
    6.17 +val trace = Unsynchronized.ref false;
    6.18  fun trace_msg s = if !trace then tracing s else ();
    6.19  
    6.20  val cooper_ss = @{simpset};
     7.1 --- a/src/HOL/Decision_Procs/ferrack_tac.ML	Tue Sep 29 14:26:33 2009 +1000
     7.2 +++ b/src/HOL/Decision_Procs/ferrack_tac.ML	Tue Sep 29 18:14:08 2009 +0200
     7.3 @@ -4,7 +4,7 @@
     7.4  
     7.5  signature FERRACK_TAC =
     7.6  sig
     7.7 -  val trace: bool ref
     7.8 +  val trace: bool Unsynchronized.ref
     7.9    val linr_tac: Proof.context -> bool -> int -> tactic
    7.10    val setup: theory -> theory
    7.11  end
    7.12 @@ -12,7 +12,7 @@
    7.13  structure Ferrack_Tac =
    7.14  struct
    7.15  
    7.16 -val trace = ref false;
    7.17 +val trace = Unsynchronized.ref false;
    7.18  fun trace_msg s = if !trace then tracing s else ();
    7.19  
    7.20  val ferrack_ss = let val ths = [@{thm real_of_int_inject}, @{thm real_of_int_less_iff}, 
     8.1 --- a/src/HOL/Decision_Procs/mir_tac.ML	Tue Sep 29 14:26:33 2009 +1000
     8.2 +++ b/src/HOL/Decision_Procs/mir_tac.ML	Tue Sep 29 18:14:08 2009 +0200
     8.3 @@ -4,7 +4,7 @@
     8.4  
     8.5  signature MIR_TAC =
     8.6  sig
     8.7 -  val trace: bool ref
     8.8 +  val trace: bool Unsynchronized.ref
     8.9    val mir_tac: Proof.context -> bool -> int -> tactic
    8.10    val setup: theory -> theory
    8.11  end
    8.12 @@ -12,7 +12,7 @@
    8.13  structure Mir_Tac =
    8.14  struct
    8.15  
    8.16 -val trace = ref false;
    8.17 +val trace = Unsynchronized.ref false;
    8.18  fun trace_msg s = if !trace then tracing s else ();
    8.19  
    8.20  val mir_ss = 
     9.1 --- a/src/HOL/Fun.thy	Tue Sep 29 14:26:33 2009 +1000
     9.2 +++ b/src/HOL/Fun.thy	Tue Sep 29 18:14:08 2009 +0200
     9.3 @@ -589,7 +589,7 @@
     9.4  attach (test) {*
     9.5  fun gen_fun_type aF aT bG bT i =
     9.6    let
     9.7 -    val tab = ref [];
     9.8 +    val tab = Unsynchronized.ref [];
     9.9      fun mk_upd (x, (_, y)) t = Const ("Fun.fun_upd",
    9.10        (aT --> bT) --> aT --> bT --> aT --> bT) $ t $ aF x $ y ()
    9.11    in
    10.1 --- a/src/HOL/HOL.thy	Tue Sep 29 14:26:33 2009 +1000
    10.2 +++ b/src/HOL/HOL.thy	Tue Sep 29 18:14:08 2009 +0200
    10.3 @@ -1970,7 +1970,7 @@
    10.4  structure Eval_Method =
    10.5  struct
    10.6  
    10.7 -val eval_ref : (unit -> bool) option ref = ref NONE;
    10.8 +val eval_ref : (unit -> bool) option Unsynchronized.ref = Unsynchronized.ref NONE;
    10.9  
   10.10  end;
   10.11  *}
    11.1 --- a/src/HOL/Import/hol4rews.ML	Tue Sep 29 14:26:33 2009 +1000
    11.2 +++ b/src/HOL/Import/hol4rews.ML	Tue Sep 29 18:14:08 2009 +0200
    11.3 @@ -168,7 +168,7 @@
    11.4    fun merge _ = Library.gen_union Thm.eq_thm
    11.5  )
    11.6  
    11.7 -val hol4_debug = ref false
    11.8 +val hol4_debug = Unsynchronized.ref false
    11.9  fun message s = if !hol4_debug then writeln s else ()
   11.10  
   11.11  local
    12.1 --- a/src/HOL/Import/import.ML	Tue Sep 29 14:26:33 2009 +1000
    12.2 +++ b/src/HOL/Import/import.ML	Tue Sep 29 18:14:08 2009 +0200
    12.3 @@ -4,7 +4,7 @@
    12.4  
    12.5  signature IMPORT =
    12.6  sig
    12.7 -    val debug      : bool ref
    12.8 +    val debug      : bool Unsynchronized.ref
    12.9      val import_tac : Proof.context -> string * string -> tactic
   12.10      val setup      : theory -> theory
   12.11  end
   12.12 @@ -21,7 +21,7 @@
   12.13  structure Import :> IMPORT =
   12.14  struct
   12.15  
   12.16 -val debug = ref false
   12.17 +val debug = Unsynchronized.ref false
   12.18  fun message s = if !debug then writeln s else ()
   12.19  
   12.20  fun import_tac ctxt (thyname, thmname) =
    13.1 --- a/src/HOL/Import/import_syntax.ML	Tue Sep 29 14:26:33 2009 +1000
    13.2 +++ b/src/HOL/Import/import_syntax.ML	Tue Sep 29 18:14:08 2009 +0200
    13.3 @@ -157,8 +157,9 @@
    13.4  	val _ = TextIO.closeIn is
    13.5  	val orig_source = Source.of_string inp
    13.6  	val symb_source = Symbol.source {do_recover = false} orig_source
    13.7 -	val lexes = ref (Scan.make_lexicon (map Symbol.explode ["import_segment","ignore_thms","import","end",">","::","const_maps","const_moves","thm_maps","const_renames","type_maps","def_maps"]),
    13.8 -			 Scan.empty_lexicon)
    13.9 +	val lexes = Unsynchronized.ref
   13.10 +	  (Scan.make_lexicon (map Symbol.explode ["import_segment","ignore_thms","import","end",">","::","const_maps","const_moves","thm_maps","const_renames","type_maps","def_maps"]),
   13.11 +		  Scan.empty_lexicon)
   13.12  	val get_lexes = fn () => !lexes
   13.13  	val token_source = OuterLex.source {do_recover = NONE} get_lexes Position.start symb_source
   13.14  	val token_list = filter_out (OuterLex.is_kind OuterLex.Space) (Source.exhaust token_source)
    14.1 --- a/src/HOL/Import/importrecorder.ML	Tue Sep 29 14:26:33 2009 +1000
    14.2 +++ b/src/HOL/Import/importrecorder.ML	Tue Sep 29 18:14:08 2009 +0200
    14.3 @@ -72,9 +72,9 @@
    14.4  		       | AbortReplay of string*string
    14.5  		       | Delta of deltastate list
    14.6  
    14.7 -val history = ref ([]:history_entry list)
    14.8 -val history_dir = ref (SOME "")
    14.9 -val skip_imports = ref false
   14.10 +val history = Unsynchronized.ref ([]:history_entry list)
   14.11 +val history_dir = Unsynchronized.ref (SOME "")
   14.12 +val skip_imports = Unsynchronized.ref false
   14.13  
   14.14  fun set_skip_import b = skip_imports := b
   14.15  fun get_skip_import () = !skip_imports
    15.1 --- a/src/HOL/Import/lazy_seq.ML	Tue Sep 29 14:26:33 2009 +1000
    15.2 +++ b/src/HOL/Import/lazy_seq.ML	Tue Sep 29 18:14:08 2009 +0200
    15.3 @@ -299,7 +299,7 @@
    15.4  
    15.5  fun cycle seqfn =
    15.6      let
    15.7 -	val knot = ref (Seq (Lazy.value NONE))
    15.8 +	val knot = Unsynchronized.ref (Seq (Lazy.value NONE))
    15.9      in
   15.10  	knot := seqfn (fn () => !knot);
   15.11  	!knot
   15.12 @@ -350,7 +350,7 @@
   15.13  
   15.14  fun of_instream is =
   15.15      let
   15.16 -	val buffer : char list ref = ref []
   15.17 +	val buffer : char list Unsynchronized.ref = Unsynchronized.ref []
   15.18  	fun get_input () =
   15.19  	    case !buffer of
   15.20  		(c::cs) => (buffer:=cs;
    16.1 --- a/src/HOL/Import/proof_kernel.ML	Tue Sep 29 14:26:33 2009 +1000
    16.2 +++ b/src/HOL/Import/proof_kernel.ML	Tue Sep 29 18:14:08 2009 +0200
    16.3 @@ -53,7 +53,7 @@
    16.4  
    16.5      val get_proof_dir: string -> theory -> string option
    16.6      val disambiguate_frees : Thm.thm -> Thm.thm
    16.7 -    val debug : bool ref
    16.8 +    val debug : bool Unsynchronized.ref
    16.9      val disk_info_of : proof -> (string * string) option
   16.10      val set_disk_info_of : proof -> string -> string -> unit
   16.11      val mk_proof : proof_content -> proof
   16.12 @@ -132,7 +132,7 @@
   16.13  fun add_dump s thy = (ImportRecorder.add_dump s; replay_add_dump s thy)
   16.14  
   16.15  datatype proof_info
   16.16 -  = Info of {disk_info: (string * string) option ref}
   16.17 +  = Info of {disk_info: (string * string) option Unsynchronized.ref}
   16.18  
   16.19  datatype proof = Proof of proof_info * proof_content
   16.20       and proof_content
   16.21 @@ -258,7 +258,7 @@
   16.22      end
   16.23  
   16.24  fun disk_info_of (Proof(Info{disk_info,...},_)) = !disk_info
   16.25 -fun mk_proof p = Proof(Info{disk_info = ref NONE},p)
   16.26 +fun mk_proof p = Proof(Info{disk_info = Unsynchronized.ref NONE},p)
   16.27  fun content_of (Proof(_,p)) = p
   16.28  
   16.29  fun set_disk_info_of (Proof(Info{disk_info,...},_)) thyname thmname =
   16.30 @@ -463,8 +463,8 @@
   16.31          s |> no_quest |> beg_prime
   16.32      end
   16.33  
   16.34 -val protected_varnames = ref (Symtab.empty:string Symtab.table)
   16.35 -val invented_isavar = ref 0
   16.36 +val protected_varnames = Unsynchronized.ref (Symtab.empty:string Symtab.table)
   16.37 +val invented_isavar = Unsynchronized.ref 0
   16.38  
   16.39  fun innocent_varname s = Syntax.is_identifier s andalso not (String.isPrefix "u_" s)
   16.40  
   16.41 @@ -482,7 +482,7 @@
   16.42        SOME t => t
   16.43      | NONE =>
   16.44        let
   16.45 -          val _ = inc invented_isavar
   16.46 +          val _ = Unsynchronized.inc invented_isavar
   16.47            val t = "u_" ^ string_of_int (!invented_isavar)
   16.48            val _ = ImportRecorder.protect_varname s t
   16.49            val _ = protected_varnames := Symtab.update (s, t) (!protected_varnames)
   16.50 @@ -497,7 +497,7 @@
   16.51            SOME t' => raise REPLAY_PROTECT_VARNAME (s, t, t')
   16.52          | NONE =>
   16.53            let
   16.54 -              val _ = inc invented_isavar
   16.55 +              val _ = Unsynchronized.inc invented_isavar
   16.56                val t = "u_" ^ string_of_int (!invented_isavar)
   16.57                val _ = protected_varnames := Symtab.update (s, t) (!protected_varnames)
   16.58            in
   16.59 @@ -1188,7 +1188,7 @@
   16.60          end
   16.61      end
   16.62  
   16.63 -val debug = ref false
   16.64 +val debug = Unsynchronized.ref false
   16.65  
   16.66  fun if_debug f x = if !debug then f x else ()
   16.67  val message = if_debug writeln
    17.1 --- a/src/HOL/Import/shuffler.ML	Tue Sep 29 14:26:33 2009 +1000
    17.2 +++ b/src/HOL/Import/shuffler.ML	Tue Sep 29 18:14:08 2009 +0200
    17.3 @@ -7,7 +7,7 @@
    17.4  
    17.5  signature Shuffler =
    17.6  sig
    17.7 -    val debug      : bool ref
    17.8 +    val debug      : bool Unsynchronized.ref
    17.9  
   17.10      val norm_term  : theory -> term -> thm
   17.11      val make_equal : theory -> term -> term -> thm option
   17.12 @@ -30,7 +30,7 @@
   17.13  structure Shuffler :> Shuffler =
   17.14  struct
   17.15  
   17.16 -val debug = ref false
   17.17 +val debug = Unsynchronized.ref false
   17.18  
   17.19  fun if_debug f x = if !debug then f x else ()
   17.20  val message = if_debug writeln
    18.1 --- a/src/HOL/Library/Eval_Witness.thy	Tue Sep 29 14:26:33 2009 +1000
    18.2 +++ b/src/HOL/Library/Eval_Witness.thy	Tue Sep 29 18:14:08 2009 +0200
    18.3 @@ -48,7 +48,7 @@
    18.4  structure Eval_Witness_Method =
    18.5  struct
    18.6  
    18.7 -val eval_ref : (unit -> bool) option ref = ref NONE;
    18.8 +val eval_ref : (unit -> bool) option Unsynchronized.ref = Unsynchronized.ref NONE;
    18.9  
   18.10  end;
   18.11  *}
    19.1 --- a/src/HOL/Library/Sum_Of_Squares/sos_wrapper.ML	Tue Sep 29 14:26:33 2009 +1000
    19.2 +++ b/src/HOL/Library/Sum_Of_Squares/sos_wrapper.ML	Tue Sep 29 18:14:08 2009 +0200
    19.3 @@ -10,7 +10,7 @@
    19.4    datatype prover_result = Success | Failure | Error
    19.5  
    19.6    val setup: theory -> theory
    19.7 -  val destdir: string ref
    19.8 +  val destdir: string Unsynchronized.ref
    19.9    val get_prover_name: unit -> string
   19.10    val set_prover_name: string -> unit
   19.11  end
   19.12 @@ -30,7 +30,7 @@
   19.13  
   19.14  (*** calling provers ***)
   19.15  
   19.16 -val destdir = ref ""
   19.17 +val destdir = Unsynchronized.ref ""
   19.18  
   19.19  fun filename dir name =
   19.20    let
   19.21 @@ -113,7 +113,7 @@
   19.22  
   19.23  (* default prover *)
   19.24  
   19.25 -val prover_name = ref "remote_csdp"
   19.26 +val prover_name = Unsynchronized.ref "remote_csdp"
   19.27  
   19.28  fun get_prover_name () = CRITICAL (fn () => ! prover_name);
   19.29  fun set_prover_name str = CRITICAL (fn () => prover_name := str);
    20.1 --- a/src/HOL/Library/Sum_Of_Squares/sum_of_squares.ML	Tue Sep 29 14:26:33 2009 +1000
    20.2 +++ b/src/HOL/Library/Sum_Of_Squares/sum_of_squares.ML	Tue Sep 29 18:14:08 2009 +0200
    20.3 @@ -15,7 +15,7 @@
    20.4    val sos_tac : (RealArith.pss_tree -> unit) ->
    20.5      proof_method -> Proof.context -> int -> tactic
    20.6  
    20.7 -  val debugging : bool ref;
    20.8 +  val debugging : bool Unsynchronized.ref;
    20.9    
   20.10    exception Failure of string;
   20.11  end
   20.12 @@ -58,7 +58,7 @@
   20.13  val pow2 = rat_pow rat_2;
   20.14  val pow10 = rat_pow rat_10;
   20.15  
   20.16 -val debugging = ref false;
   20.17 +val debugging = Unsynchronized.ref false;
   20.18  
   20.19  exception Sanity;
   20.20  
    21.1 --- a/src/HOL/Library/positivstellensatz.ML	Tue Sep 29 14:26:33 2009 +1000
    21.2 +++ b/src/HOL/Library/positivstellensatz.ML	Tue Sep 29 18:14:08 2009 +0200
    21.3 @@ -190,20 +190,20 @@
    21.4    thm list * thm list * thm list -> thm * pss_tree
    21.5  type cert_conv = cterm -> thm * pss_tree
    21.6  
    21.7 -val my_eqs = ref ([] : thm list);
    21.8 -val my_les = ref ([] : thm list);
    21.9 -val my_lts = ref ([] : thm list);
   21.10 -val my_proof = ref (Axiom_eq 0);
   21.11 -val my_context = ref @{context};
   21.12 +val my_eqs = Unsynchronized.ref ([] : thm list);
   21.13 +val my_les = Unsynchronized.ref ([] : thm list);
   21.14 +val my_lts = Unsynchronized.ref ([] : thm list);
   21.15 +val my_proof = Unsynchronized.ref (Axiom_eq 0);
   21.16 +val my_context = Unsynchronized.ref @{context};
   21.17  
   21.18 -val my_mk_numeric = ref ((K @{cterm True}) :Rat.rat -> cterm);
   21.19 -val my_numeric_eq_conv = ref no_conv;
   21.20 -val my_numeric_ge_conv = ref no_conv;
   21.21 -val my_numeric_gt_conv = ref no_conv;
   21.22 -val my_poly_conv = ref no_conv;
   21.23 -val my_poly_neg_conv = ref no_conv;
   21.24 -val my_poly_add_conv = ref no_conv;
   21.25 -val my_poly_mul_conv = ref no_conv;
   21.26 +val my_mk_numeric = Unsynchronized.ref ((K @{cterm True}) :Rat.rat -> cterm);
   21.27 +val my_numeric_eq_conv = Unsynchronized.ref no_conv;
   21.28 +val my_numeric_ge_conv = Unsynchronized.ref no_conv;
   21.29 +val my_numeric_gt_conv = Unsynchronized.ref no_conv;
   21.30 +val my_poly_conv = Unsynchronized.ref no_conv;
   21.31 +val my_poly_neg_conv = Unsynchronized.ref no_conv;
   21.32 +val my_poly_add_conv = Unsynchronized.ref no_conv;
   21.33 +val my_poly_mul_conv = Unsynchronized.ref no_conv;
   21.34  
   21.35  
   21.36      (* Some useful derived rules *)
    22.1 --- a/src/HOL/Matrix/cplex/Cplex_tools.ML	Tue Sep 29 14:26:33 2009 +1000
    22.2 +++ b/src/HOL/Matrix/cplex/Cplex_tools.ML	Tue Sep 29 18:14:08 2009 +0200
    22.3 @@ -62,7 +62,7 @@
    22.4  
    22.5  datatype cplexSolver = SOLVER_DEFAULT | SOLVER_CPLEX | SOLVER_GLPK
    22.6  
    22.7 -val cplexsolver = ref SOLVER_DEFAULT;
    22.8 +val cplexsolver = Unsynchronized.ref SOLVER_DEFAULT;
    22.9  fun get_solver () = !cplexsolver;
   22.10  fun set_solver s = (cplexsolver := s);
   22.11  
   22.12 @@ -305,8 +305,8 @@
   22.13  fun load_cplexFile name =
   22.14      let
   22.15      val f = TextIO.openIn name
   22.16 -        val ignore_NL = ref true
   22.17 -    val rest = ref []
   22.18 +        val ignore_NL = Unsynchronized.ref true
   22.19 +    val rest = Unsynchronized.ref []
   22.20  
   22.21      fun is_symbol s c = (fst c) = TOKEN_SYMBOL andalso (to_upper (snd c)) = s
   22.22  
   22.23 @@ -612,7 +612,7 @@
   22.24  
   22.25      fun basic_write s = TextIO.output(f, s)
   22.26  
   22.27 -    val linebuf = ref ""
   22.28 +    val linebuf = Unsynchronized.ref ""
   22.29      fun buf_flushline s =
   22.30          (basic_write (!linebuf);
   22.31           basic_write "\n";
   22.32 @@ -860,7 +860,7 @@
   22.33  
   22.34      val f = TextIO.openIn name
   22.35  
   22.36 -    val rest = ref []
   22.37 +    val rest = Unsynchronized.ref []
   22.38  
   22.39      fun readToken_helper () =
   22.40          if length (!rest) > 0 then
   22.41 @@ -995,7 +995,7 @@
   22.42  
   22.43      val f = TextIO.openIn name
   22.44  
   22.45 -    val rest = ref []
   22.46 +    val rest = Unsynchronized.ref []
   22.47  
   22.48      fun readToken_helper () =
   22.49          if length (!rest) > 0 then
    23.1 --- a/src/HOL/Matrix/cplex/FloatSparseMatrixBuilder.ML	Tue Sep 29 14:26:33 2009 +1000
    23.2 +++ b/src/HOL/Matrix/cplex/FloatSparseMatrixBuilder.ML	Tue Sep 29 18:14:08 2009 +0200
    23.3 @@ -136,7 +136,7 @@
    23.4  
    23.5  fun cplexProg c A b =
    23.6      let
    23.7 -        val ytable = ref Inttab.empty
    23.8 +        val ytable = Unsynchronized.ref Inttab.empty
    23.9          fun indexof s =
   23.10              if String.size s = 0 then raise (No_name s)
   23.11              else case Int.fromString (String.extract(s, 1, NONE)) of
   23.12 @@ -145,7 +145,7 @@
   23.13          fun nameof i =
   23.14              let
   23.15                  val s = "x"^(Int.toString i)
   23.16 -                val _ = change ytable (Inttab.update (i, s))
   23.17 +                val _ = Unsynchronized.change ytable (Inttab.update (i, s))
   23.18              in
   23.19                  s
   23.20              end
   23.21 @@ -242,7 +242,7 @@
   23.22  
   23.23  fun cut_vector size v =
   23.24    let
   23.25 -    val count = ref 0;
   23.26 +    val count = Unsynchronized.ref 0;
   23.27      fun app (i, s) =  if (!count < size) then
   23.28          (count := !count +1 ; Inttab.update (i, s))
   23.29        else I
    24.1 --- a/src/HOL/Mirabelle/Tools/mirabelle_sledgehammer.ML	Tue Sep 29 14:26:33 2009 +1000
    24.2 +++ b/src/HOL/Mirabelle/Tools/mirabelle_sledgehammer.ML	Tue Sep 29 18:14:08 2009 +0200
    24.3 @@ -202,7 +202,8 @@
    24.4  fun log_metis_data log tag sh_calls sh_success metis_calls metis_success metis_proofs metis_time
    24.5      metis_timeout metis_lemmas metis_posns =
    24.6   (log ("Total number of " ^ tag ^ "metis calls: " ^ str metis_calls);
    24.7 -  log ("Number of successful " ^ tag ^ "metis calls: " ^ str metis_success ^ " (proof: " ^ str metis_proofs ^ ")");
    24.8 +  log ("Number of successful " ^ tag ^ "metis calls: " ^ str metis_success ^
    24.9 +    " (proof: " ^ str metis_proofs ^ ")");
   24.10    log ("Number of " ^ tag ^ "metis timeouts: " ^ str metis_timeout);
   24.11    log ("Success rate: " ^ percentage metis_success sh_calls ^ "%");
   24.12    log ("Number of successful " ^ tag ^ "metis lemmas: " ^ str metis_lemmas);
   24.13 @@ -252,15 +253,15 @@
   24.14  
   24.15  
   24.16  (* Warning: we implicitly assume single-threaded execution here! *)
   24.17 -val data = ref ([] : (int * data) list)
   24.18 +val data = Unsynchronized.ref ([] : (int * data) list)
   24.19  
   24.20 -fun init id thy = (change data (cons (id, empty_data)); thy)
   24.21 +fun init id thy = (Unsynchronized.change data (cons (id, empty_data)); thy)
   24.22  fun done id ({log, ...}: Mirabelle.done_args) =
   24.23    AList.lookup (op =) (!data) id
   24.24    |> Option.map (log_data id log)
   24.25    |> K ()
   24.26  
   24.27 -fun change_data id f = (change data (AList.map_entry (op =) id f); ())
   24.28 +fun change_data id f = (Unsynchronized.change data (AList.map_entry (op =) id f); ())
   24.29  
   24.30  
   24.31  fun get_atp thy args =
   24.32 @@ -419,7 +420,7 @@
   24.33          inc_metis_timeout, inc_metis_lemmas, inc_metis_posns)
   24.34      val metis0_fns = (inc_metis_calls0, inc_metis_success0, inc_metis_proofs0, inc_metis_time0,
   24.35          inc_metis_timeout0, inc_metis_lemmas0, inc_metis_posns0)
   24.36 -    val named_thms = ref (NONE : (string * thm list) list option)
   24.37 +    val named_thms = Unsynchronized.ref (NONE : (string * thm list) list option)
   24.38      val minimize = AList.defined (op =) args minimizeK
   24.39    in 
   24.40      Mirabelle.catch sh_tag (run_sledgehammer args named_thms) id st;
    25.1 --- a/src/HOL/Modelcheck/EindhovenSyn.thy	Tue Sep 29 14:26:33 2009 +1000
    25.2 +++ b/src/HOL/Modelcheck/EindhovenSyn.thy	Tue Sep 29 18:14:08 2009 +0200
    25.3 @@ -26,7 +26,7 @@
    25.4    "Nu "         :: "[idts, 'a pred] => 'a pred"         ("(3[nu _./ _])" 1000)
    25.5  
    25.6  ML {*
    25.7 -  val trace_eindhoven = ref false;
    25.8 +  val trace_eindhoven = Unsynchronized.ref false;
    25.9  *}
   25.10  
   25.11  oracle mc_eindhoven_oracle =
    26.1 --- a/src/HOL/Modelcheck/mucke_oracle.ML	Tue Sep 29 14:26:33 2009 +1000
    26.2 +++ b/src/HOL/Modelcheck/mucke_oracle.ML	Tue Sep 29 18:14:08 2009 +0200
    26.3 @@ -1,5 +1,5 @@
    26.4  
    26.5 -val trace_mc = ref false; 
    26.6 +val trace_mc = Unsynchronized.ref false; 
    26.7  
    26.8  
    26.9  (* transform_case post-processes output strings of the syntax "Mucke" *)
    27.1 --- a/src/HOL/Nominal/nominal_thmdecls.ML	Tue Sep 29 14:26:33 2009 +1000
    27.2 +++ b/src/HOL/Nominal/nominal_thmdecls.ML	Tue Sep 29 18:14:08 2009 +0200
    27.3 @@ -18,7 +18,7 @@
    27.4    val setup: theory -> theory
    27.5    val get_eqvt_thms: Proof.context -> thm list
    27.6  
    27.7 -  val NOMINAL_EQVT_DEBUG : bool ref
    27.8 +  val NOMINAL_EQVT_DEBUG : bool Unsynchronized.ref
    27.9  end;
   27.10  
   27.11  structure NominalThmDecls: NOMINAL_THMDECLS =
   27.12 @@ -43,7 +43,7 @@
   27.13  (* equality-lemma can be derived. *)
   27.14  exception EQVT_FORM of string
   27.15  
   27.16 -val NOMINAL_EQVT_DEBUG = ref false
   27.17 +val NOMINAL_EQVT_DEBUG = Unsynchronized.ref false
   27.18  
   27.19  fun tactic (msg, tac) =
   27.20    if !NOMINAL_EQVT_DEBUG
    28.1 --- a/src/HOL/Prolog/prolog.ML	Tue Sep 29 14:26:33 2009 +1000
    28.2 +++ b/src/HOL/Prolog/prolog.ML	Tue Sep 29 18:14:08 2009 +0200
    28.3 @@ -2,7 +2,7 @@
    28.4      Author:   David von Oheimb (based on a lecture on Lambda Prolog by Nadathur)
    28.5  *)
    28.6  
    28.7 -set Proof.show_main_goal;
    28.8 +Unsynchronized.set Proof.show_main_goal;
    28.9  
   28.10  structure Prolog =
   28.11  struct
    29.1 --- a/src/HOL/Random.thy	Tue Sep 29 14:26:33 2009 +1000
    29.2 +++ b/src/HOL/Random.thy	Tue Sep 29 18:14:08 2009 +0200
    29.3 @@ -154,7 +154,7 @@
    29.4  
    29.5  local
    29.6  
    29.7 -val seed = ref 
    29.8 +val seed = Unsynchronized.ref 
    29.9    (let
   29.10      val now = Time.toMilliseconds (Time.now ());
   29.11      val (q, s1) = IntInf.divMod (now, 2147483562);
    30.1 --- a/src/HOL/SMT/Tools/smt_normalize.ML	Tue Sep 29 14:26:33 2009 +1000
    30.2 +++ b/src/HOL/SMT/Tools/smt_normalize.ML	Tue Sep 29 18:14:08 2009 +0200
    30.3 @@ -304,11 +304,11 @@
    30.4  fun lift_lambdas ctxt thms =
    30.5    let
    30.6      val declare_frees = fold (Thm.fold_terms Term.declare_term_frees)
    30.7 -    val names = ref (declare_frees thms (Name.make_context []))
    30.8 -    val fresh_name = change_result names o yield_singleton Name.variants
    30.9 +    val names = Unsynchronized.ref (declare_frees thms (Name.make_context []))
   30.10 +    val fresh_name = Unsynchronized.change_result names o yield_singleton Name.variants
   30.11  
   30.12 -    val defs = ref (Termtab.empty : (int * thm) Termtab.table)
   30.13 -    fun add_def t thm = change defs (Termtab.update (t, (serial (), thm)))
   30.14 +    val defs = Unsynchronized.ref (Termtab.empty : (int * thm) Termtab.table)
   30.15 +    fun add_def t thm = Unsynchronized.change defs (Termtab.update (t, (serial (), thm)))
   30.16      fun make_def cvs eq = Thm.symmetric (fold norm_meta_def cvs eq)
   30.17      fun def_conv cvs ctxt ct =
   30.18        let
    31.1 --- a/src/HOL/Statespace/DistinctTreeProver.thy	Tue Sep 29 14:26:33 2009 +1000
    31.2 +++ b/src/HOL/Statespace/DistinctTreeProver.thy	Tue Sep 29 18:14:08 2009 +0200
    31.3 @@ -664,7 +664,7 @@
    31.4       HOLogic.Trueprop$
    31.5         (Const ("DistinctTreeProver.all_distinct",DistinctTreeProver.treeT (Type ("nat",[])) --> HOLogic.boolT)$t')
    31.6  
    31.7 -val da = ref refl;
    31.8 +val da = Unsynchronized.ref refl;
    31.9  
   31.10  *}
   31.11  
    32.1 --- a/src/HOL/Tools/ATP_Manager/atp_manager.ML	Tue Sep 29 14:26:33 2009 +1000
    32.2 +++ b/src/HOL/Tools/ATP_Manager/atp_manager.ML	Tue Sep 29 18:14:08 2009 +0200
    32.3 @@ -41,10 +41,10 @@
    32.4  
    32.5  local
    32.6  
    32.7 -val atps = ref "e remote_vampire";
    32.8 -val max_atps = ref 5;   (* ~1 means infinite number of atps *)
    32.9 -val timeout = ref 60;
   32.10 -val full_types = ref false;
   32.11 +val atps = Unsynchronized.ref "e remote_vampire";
   32.12 +val max_atps = Unsynchronized.ref 5;   (* ~1 means infinite number of atps *)
   32.13 +val timeout = Unsynchronized.ref 60;
   32.14 +val full_types = Unsynchronized.ref false;
   32.15  
   32.16  in
   32.17  
    33.1 --- a/src/HOL/Tools/ATP_Manager/atp_minimal.ML	Tue Sep 29 14:26:33 2009 +1000
    33.2 +++ b/src/HOL/Tools/ATP_Manager/atp_minimal.ML	Tue Sep 29 18:14:08 2009 +0200
    33.3 @@ -69,7 +69,7 @@
    33.4           forall e in v. ~p(v \ e)
    33.5     *)
    33.6    fun minimal p s =
    33.7 -    let val c = ref 0
    33.8 +    let val c = Unsynchronized.ref 0
    33.9          fun pc xs = (c := !c + 1; p xs)
   33.10      in
   33.11      (case min pc [] s of
    34.1 --- a/src/HOL/Tools/ATP_Manager/atp_wrapper.ML	Tue Sep 29 14:26:33 2009 +1000
    34.2 +++ b/src/HOL/Tools/ATP_Manager/atp_wrapper.ML	Tue Sep 29 18:14:08 2009 +0200
    34.3 @@ -6,8 +6,8 @@
    34.4  
    34.5  signature ATP_WRAPPER =
    34.6  sig
    34.7 -  val destdir: string ref
    34.8 -  val problem_name: string ref
    34.9 +  val destdir: string Unsynchronized.ref
   34.10 +  val problem_name: string Unsynchronized.ref
   34.11    val tptp_prover_opts_full: int -> bool -> bool -> Path.T * string -> AtpManager.prover
   34.12    val tptp_prover_opts: int -> bool -> Path.T * string -> AtpManager.prover
   34.13    val tptp_prover: Path.T * string -> AtpManager.prover
   34.14 @@ -35,8 +35,8 @@
   34.15  
   34.16  (* global hooks for writing problemfiles *)
   34.17  
   34.18 -val destdir = ref "";   (*Empty means write files to /tmp*)
   34.19 -val problem_name = ref "prob";
   34.20 +val destdir = Unsynchronized.ref "";   (*Empty means write files to /tmp*)
   34.21 +val problem_name = Unsynchronized.ref "prob";
   34.22  
   34.23  
   34.24  (* basic template *)
    35.1 --- a/src/HOL/Tools/Function/fundef_common.ML	Tue Sep 29 14:26:33 2009 +1000
    35.2 +++ b/src/HOL/Tools/Function/fundef_common.ML	Tue Sep 29 18:14:08 2009 +0200
    35.3 @@ -11,7 +11,7 @@
    35.4  local open FundefLib in
    35.5  
    35.6  (* Profiling *)
    35.7 -val profile = ref false;
    35.8 +val profile = Unsynchronized.ref false;
    35.9  
   35.10  fun PROFILE msg = if !profile then timeap_msg msg else I
   35.11  
    36.1 --- a/src/HOL/Tools/Function/scnp_solve.ML	Tue Sep 29 14:26:33 2009 +1000
    36.2 +++ b/src/HOL/Tools/Function/scnp_solve.ML	Tue Sep 29 18:14:08 2009 +0200
    36.3 @@ -23,7 +23,7 @@
    36.4  
    36.5    val generate_certificate : bool -> label list -> graph_problem -> certificate option
    36.6  
    36.7 -  val solver : string ref
    36.8 +  val solver : string Unsynchronized.ref
    36.9  end
   36.10  
   36.11  structure ScnpSolve : SCNP_SOLVE =
   36.12 @@ -71,7 +71,7 @@
   36.13  fun exactly_one n f = iexists n (the_one f n)
   36.14  
   36.15  (* SAT solving *)
   36.16 -val solver = ref "auto";
   36.17 +val solver = Unsynchronized.ref "auto";
   36.18  fun sat_solver x =
   36.19    FundefCommon.PROFILE "sat_solving..." (SatSolver.invoke_solver (!solver)) x
   36.20  
    37.1 --- a/src/HOL/Tools/Predicate_Compile/pred_compile_fun.ML	Tue Sep 29 14:26:33 2009 +1000
    37.2 +++ b/src/HOL/Tools/Predicate_Compile/pred_compile_fun.ML	Tue Sep 29 18:14:08 2009 +0200
    37.3 @@ -16,7 +16,7 @@
    37.4  
    37.5  (* Oracle for preprocessing  *)
    37.6  
    37.7 -val (oracle : (string * (cterm -> thm)) option ref) = ref NONE;
    37.8 +val (oracle : (string * (cterm -> thm)) option Unsynchronized.ref) = Unsynchronized.ref NONE;
    37.9  
   37.10  fun the_oracle () =
   37.11    case !oracle of
    38.1 --- a/src/HOL/Tools/Predicate_Compile/pred_compile_quickcheck.ML	Tue Sep 29 14:26:33 2009 +1000
    38.2 +++ b/src/HOL/Tools/Predicate_Compile/pred_compile_quickcheck.ML	Tue Sep 29 18:14:08 2009 +0200
    38.3 @@ -6,13 +6,15 @@
    38.4  signature PRED_COMPILE_QUICKCHECK =
    38.5  sig
    38.6    val quickcheck : Proof.context -> term -> int -> term list option
    38.7 -  val test_ref : ((unit -> int -> int * int -> term list Predicate.pred * (int * int)) option) ref
    38.8 +  val test_ref :
    38.9 +    ((unit -> int -> int * int -> term list Predicate.pred * (int * int)) option) Unsynchronized.ref
   38.10  end;
   38.11  
   38.12  structure Pred_Compile_Quickcheck : PRED_COMPILE_QUICKCHECK =
   38.13  struct
   38.14  
   38.15 -val test_ref = ref (NONE : (unit -> int -> int * int -> term list Predicate.pred * (int * int)) option) 
   38.16 +val test_ref =
   38.17 +  Unsynchronized.ref (NONE : (unit -> int -> int * int -> term list Predicate.pred * (int * int)) option)
   38.18  val target = "Quickcheck"
   38.19  
   38.20  fun dest_compfuns (Predicate_Compile_Core.CompilationFuns funs) = funs
    39.1 --- a/src/HOL/Tools/Predicate_Compile/predicate_compile_core.ML	Tue Sep 29 14:26:33 2009 +1000
    39.2 +++ b/src/HOL/Tools/Predicate_Compile/predicate_compile_core.ML	Tue Sep 29 18:14:08 2009 +0200
    39.3 @@ -35,10 +35,10 @@
    39.4    val set_nparams : string -> int -> theory -> theory
    39.5    val print_stored_rules: theory -> unit
    39.6    val print_all_modes: theory -> unit
    39.7 -  val do_proofs: bool ref
    39.8 +  val do_proofs: bool Unsynchronized.ref
    39.9    val mk_casesrule : Proof.context -> int -> thm list -> term
   39.10    val analyze_compr: theory -> term -> term
   39.11 -  val eval_ref: (unit -> term Predicate.pred) option ref
   39.12 +  val eval_ref: (unit -> term Predicate.pred) option Unsynchronized.ref
   39.13    val add_equations : string list -> theory -> theory
   39.14    val code_pred_intros_attrib : attribute
   39.15    (* used by Quickcheck_Generator *) 
   39.16 @@ -123,7 +123,7 @@
   39.17  fun print_tac s = Seq.single; (*Tactical.print_tac s;*) (* (if ! Toplevel.debug then Tactical.print_tac s else Seq.single); *)
   39.18  fun debug_tac msg = Seq.single; (* (fn st => (Output.tracing msg; Seq.single st)); *)
   39.19  
   39.20 -val do_proofs = ref true;
   39.21 +val do_proofs = Unsynchronized.ref true;
   39.22  
   39.23  (* reference to preprocessing of InductiveSet package *)
   39.24  
   39.25 @@ -2334,7 +2334,7 @@
   39.26  
   39.27  (* transformation for code generation *)
   39.28  
   39.29 -val eval_ref = ref (NONE : (unit -> term Predicate.pred) option);
   39.30 +val eval_ref = Unsynchronized.ref (NONE : (unit -> term Predicate.pred) option);
   39.31  
   39.32  (*FIXME turn this into an LCF-guarded preprocessor for comprehensions*)
   39.33  fun analyze_compr thy t_compr =
    40.1 --- a/src/HOL/Tools/TFL/rules.ML	Tue Sep 29 14:26:33 2009 +1000
    40.2 +++ b/src/HOL/Tools/TFL/rules.ML	Tue Sep 29 18:14:08 2009 +0200
    40.3 @@ -47,10 +47,10 @@
    40.4  
    40.5    val rbeta: thm -> thm
    40.6  (* For debugging my isabelle solver in the conditional rewriter *)
    40.7 -  val term_ref: term list ref
    40.8 -  val thm_ref: thm list ref
    40.9 -  val ss_ref: simpset list ref
   40.10 -  val tracing: bool ref
   40.11 +  val term_ref: term list Unsynchronized.ref
   40.12 +  val thm_ref: thm list Unsynchronized.ref
   40.13 +  val ss_ref: simpset list Unsynchronized.ref
   40.14 +  val tracing: bool Unsynchronized.ref
   40.15    val CONTEXT_REWRITE_RULE: term * term list * thm * thm list
   40.16                               -> thm -> thm * term list
   40.17    val RIGHT_ASSOC: thm -> thm
   40.18 @@ -544,10 +544,10 @@
   40.19  (*---------------------------------------------------------------------------
   40.20   * Trace information for the rewriter
   40.21   *---------------------------------------------------------------------------*)
   40.22 -val term_ref = ref [] : term list ref
   40.23 -val ss_ref = ref [] : simpset list ref;
   40.24 -val thm_ref = ref [] : thm list ref;
   40.25 -val tracing = ref false;
   40.26 +val term_ref = Unsynchronized.ref [] : term list Unsynchronized.ref
   40.27 +val ss_ref = Unsynchronized.ref [] : simpset list Unsynchronized.ref;
   40.28 +val thm_ref = Unsynchronized.ref [] : thm list Unsynchronized.ref;
   40.29 +val tracing = Unsynchronized.ref false;
   40.30  
   40.31  fun say s = if !tracing then writeln s else ();
   40.32  
   40.33 @@ -666,7 +666,7 @@
   40.34   let val globals = func::G
   40.35       val ss0 = Simplifier.theory_context (Thm.theory_of_thm th) empty_ss
   40.36       val pbeta_reduce = simpl_conv ss0 [split_conv RS eq_reflection];
   40.37 -     val tc_list = ref[]: term list ref
   40.38 +     val tc_list = Unsynchronized.ref []: term list Unsynchronized.ref
   40.39       val dummy = term_ref := []
   40.40       val dummy = thm_ref  := []
   40.41       val dummy = ss_ref  := []
    41.1 --- a/src/HOL/Tools/TFL/tfl.ML	Tue Sep 29 14:26:33 2009 +1000
    41.2 +++ b/src/HOL/Tools/TFL/tfl.ML	Tue Sep 29 18:14:08 2009 +0200
    41.3 @@ -6,7 +6,7 @@
    41.4  
    41.5  signature PRIM =
    41.6  sig
    41.7 -  val trace: bool ref
    41.8 +  val trace: bool Unsynchronized.ref
    41.9    val trace_thms: string -> thm list -> unit
   41.10    val trace_cterm: string -> cterm -> unit
   41.11    type pattern
   41.12 @@ -40,7 +40,7 @@
   41.13  structure Prim: PRIM =
   41.14  struct
   41.15  
   41.16 -val trace = ref false;
   41.17 +val trace = Unsynchronized.ref false;
   41.18  
   41.19  structure R = Rules;
   41.20  structure S = USyntax;
   41.21 @@ -75,8 +75,8 @@
   41.22   * function contains embedded refs!
   41.23   *---------------------------------------------------------------------------*)
   41.24  fun gvvariant names =
   41.25 -  let val slist = ref names
   41.26 -      val vname = ref "u"
   41.27 +  let val slist = Unsynchronized.ref names
   41.28 +      val vname = Unsynchronized.ref "u"
   41.29        fun new() =
   41.30           if !vname mem_string (!slist)
   41.31           then (vname := Symbol.bump_string (!vname);  new())
    42.1 --- a/src/HOL/Tools/cnf_funcs.ML	Tue Sep 29 14:26:33 2009 +1000
    42.2 +++ b/src/HOL/Tools/cnf_funcs.ML	Tue Sep 29 18:14:08 2009 +0200
    42.3 @@ -399,12 +399,10 @@
    42.4  
    42.5  fun make_cnfx_thm thy t =
    42.6  let
    42.7 -	val var_id = ref 0  (* properly initialized below *)
    42.8 -	(* unit -> Term.term *)
    42.9 +	val var_id = Unsynchronized.ref 0  (* properly initialized below *)
   42.10  	fun new_free () =
   42.11 -		Free ("cnfx_" ^ string_of_int (inc var_id), HOLogic.boolT)
   42.12 -	(* Term.term -> Thm.thm *)
   42.13 -	fun make_cnfx_thm_from_nnf (Const ("op &", _) $ x $ y) =
   42.14 +		Free ("cnfx_" ^ string_of_int (Unsynchronized.inc var_id), HOLogic.boolT)
   42.15 +	fun make_cnfx_thm_from_nnf (Const ("op &", _) $ x $ y) : thm =
   42.16  		let
   42.17  			val thm1 = make_cnfx_thm_from_nnf x
   42.18  			val thm2 = make_cnfx_thm_from_nnf y
    43.1 --- a/src/HOL/Tools/lin_arith.ML	Tue Sep 29 14:26:33 2009 +1000
    43.2 +++ b/src/HOL/Tools/lin_arith.ML	Tue Sep 29 18:14:08 2009 +0200
    43.3 @@ -22,8 +22,8 @@
    43.4    val global_setup: theory -> theory
    43.5    val split_limit: int Config.T
    43.6    val neq_limit: int Config.T
    43.7 -  val warning_count: int ref
    43.8 -  val trace: bool ref
    43.9 +  val warning_count: int Unsynchronized.ref
   43.10 +  val trace: bool Unsynchronized.ref
   43.11  end;
   43.12  
   43.13  structure Lin_Arith: LIN_ARITH =
    44.1 --- a/src/HOL/Tools/meson.ML	Tue Sep 29 14:26:33 2009 +1000
    44.2 +++ b/src/HOL/Tools/meson.ML	Tue Sep 29 18:14:08 2009 +0200
    44.3 @@ -319,7 +319,7 @@
    44.4    Strips universal quantifiers and breaks up conjunctions.
    44.5    Eliminates existential quantifiers using skoths: Skolemization theorems.*)
    44.6  fun cnf skoths ctxt (th,ths) =
    44.7 -  let val ctxtr = ref ctxt
    44.8 +  let val ctxtr = Unsynchronized.ref ctxt
    44.9        fun cnf_aux (th,ths) =
   44.10          if not (can HOLogic.dest_Trueprop (prop_of th)) then ths (*meta-level: ignore*)
   44.11          else if not (has_conns ["All","Ex","op &"] (prop_of th))
    45.1 --- a/src/HOL/Tools/polyhash.ML	Tue Sep 29 14:26:33 2009 +1000
    45.2 +++ b/src/HOL/Tools/polyhash.ML	Tue Sep 29 18:14:08 2009 +0200
    45.3 @@ -108,8 +108,8 @@
    45.4      HT of {hashVal   : 'key -> int,
    45.5  	   sameKey   : 'key * 'key -> bool,
    45.6  	   not_found : exn,
    45.7 -	   table     : ('key, 'data) bucket_t Array.array ref,
    45.8 -	   n_items   : int ref}
    45.9 +	   table     : ('key, 'data) bucket_t Array.array Unsynchronized.ref,
   45.10 +	   n_items   : int Unsynchronized.ref}
   45.11  
   45.12  local
   45.13  (*
   45.14 @@ -134,8 +134,8 @@
   45.15              hashVal=hashVal,
   45.16  	    sameKey=sameKey,
   45.17  	    not_found = notFound,
   45.18 -	    table = ref (Array.array(roundUp sizeHint, NIL)),
   45.19 -	    n_items = ref 0
   45.20 +	    table = Unsynchronized.ref (Array.array(roundUp sizeHint, NIL)),
   45.21 +	    n_items = Unsynchronized.ref 0
   45.22  	  };
   45.23  
   45.24    (* conditionally grow a table *)
   45.25 @@ -174,7 +174,7 @@
   45.26  	  val indx = index (hash, sz)
   45.27  	  fun look NIL = (
   45.28  		Array.update(arr, indx, B(hash, key, item, Array.sub(arr, indx)));
   45.29 -		inc n_items;
   45.30 +		Unsynchronized.inc n_items;
   45.31  		growTable tbl;
   45.32  		NIL)
   45.33  	    | look (B(h, k, v, r)) = if ((hash = h) andalso sameKey(key, k))
   45.34 @@ -200,7 +200,7 @@
   45.35  	    fun look NIL = 
   45.36  		(Array.update(arr, indx, B(hash, key, item, 
   45.37  					   Array.sub(arr, indx)));
   45.38 -		 inc n_items;
   45.39 +		 Unsynchronized.inc n_items;
   45.40  		 growTable tbl;
   45.41  		 NONE)
   45.42  	      | look (B(h, k, v, r)) = 
   45.43 @@ -261,7 +261,7 @@
   45.44     fun numItems (HT{n_items, ...}) = !n_items
   45.45  
   45.46    (* return a list of the items in the table *)
   45.47 -    fun listItems (HT{table = ref arr, n_items, ...}) = let
   45.48 +    fun listItems (HT{table = Unsynchronized.ref arr, n_items, ...}) = let
   45.49  	  fun f (_, l, 0) = l
   45.50  	    | f (~1, l, _) = l
   45.51  	    | f (i, l, n) = let
   45.52 @@ -306,8 +306,8 @@
   45.53  	    mapTbl 0;
   45.54  	    HT{hashVal=hashVal,
   45.55  	       sameKey=sameKey,
   45.56 -	       table = ref newArr, 
   45.57 -	       n_items = ref(!n_items), 
   45.58 +	       table = Unsynchronized.ref newArr, 
   45.59 +	       n_items = Unsynchronized.ref(!n_items), 
   45.60  	       not_found = not_found}
   45.61  	  end (* transform *);
   45.62  
   45.63 @@ -348,8 +348,8 @@
   45.64  	    mapTbl 0;
   45.65  	    HT{hashVal=hashVal, 
   45.66  	       sameKey=sameKey, 
   45.67 -	       table = ref newArr, 
   45.68 -	       n_items = ref(!n_items), 
   45.69 +	       table = Unsynchronized.ref newArr, 
   45.70 +	       n_items = Unsynchronized.ref(!n_items), 
   45.71  	       not_found = not_found}
   45.72  	  end (* transform *);
   45.73  
   45.74 @@ -365,15 +365,15 @@
   45.75  	    (mapTbl 0) handle _ => ();  (* FIXME avoid handle _ *)
   45.76  	    HT{hashVal=hashVal, 
   45.77  	       sameKey=sameKey,
   45.78 -	       table = ref newArr, 
   45.79 -	       n_items = ref(!n_items), 
   45.80 +	       table = Unsynchronized.ref newArr, 
   45.81 +	       n_items = Unsynchronized.ref(!n_items), 
   45.82  	       not_found = not_found}
   45.83  	  end (* copy *);
   45.84  
   45.85    (* returns a list of the sizes of the various buckets.  This is to
   45.86     * allow users to gauge the quality of their hashing function.
   45.87     *)
   45.88 -    fun bucketSizes (HT{table = ref arr, ...}) = let
   45.89 +    fun bucketSizes (HT{table = Unsynchronized.ref arr, ...}) = let
   45.90  	  fun len (NIL, n) = n
   45.91  	    | len (B(_, _, _, r), n) = len(r, n+1)
   45.92  	  fun f (~1, l) = l
    46.1 --- a/src/HOL/Tools/prop_logic.ML	Tue Sep 29 14:26:33 2009 +1000
    46.2 +++ b/src/HOL/Tools/prop_logic.ML	Tue Sep 29 18:14:08 2009 +0200
    46.3 @@ -292,7 +292,7 @@
    46.4  			val fm' = nnf fm
    46.5  			(* 'new' specifies the next index that is available to introduce an auxiliary variable *)
    46.6  			(* int ref *)
    46.7 -			val new = ref (maxidx fm' + 1)
    46.8 +			val new = Unsynchronized.ref (maxidx fm' + 1)
    46.9  			(* unit -> int *)
   46.10  			fun new_idx () = let val idx = !new in new := idx+1; idx end
   46.11  			(* replaces 'And' by an auxiliary variable (and its definition) *)
   46.12 @@ -381,15 +381,15 @@
   46.13  	(* Term.term -> int Termtab.table -> prop_formula * int Termtab.table *)
   46.14  	fun prop_formula_of_term t table =
   46.15  	let
   46.16 -		val next_idx_is_valid = ref false
   46.17 -		val next_idx          = ref 0
   46.18 +		val next_idx_is_valid = Unsynchronized.ref false
   46.19 +		val next_idx          = Unsynchronized.ref 0
   46.20  		fun get_next_idx () =
   46.21  			if !next_idx_is_valid then
   46.22 -				inc next_idx
   46.23 +				Unsynchronized.inc next_idx
   46.24  			else (
   46.25  				next_idx          := Termtab.fold (curry Int.max o snd) table 0;
   46.26  				next_idx_is_valid := true;
   46.27 -				inc next_idx
   46.28 +				Unsynchronized.inc next_idx
   46.29  			)
   46.30  		fun aux (Const ("True", _))         table =
   46.31  			(True, table)
    47.1 --- a/src/HOL/Tools/quickcheck_generators.ML	Tue Sep 29 14:26:33 2009 +1000
    47.2 +++ b/src/HOL/Tools/quickcheck_generators.ML	Tue Sep 29 18:14:08 2009 +0200
    47.3 @@ -16,7 +16,7 @@
    47.4      -> term list * (term * term) list
    47.5    val ensure_random_datatype: Datatype.config -> string list -> theory -> theory
    47.6    val compile_generator_expr: theory -> term -> int -> term list option
    47.7 -  val eval_ref: (unit -> int -> seed -> term list option * seed) option ref
    47.8 +  val eval_ref: (unit -> int -> seed -> term list option * seed) option Unsynchronized.ref
    47.9    val setup: theory -> theory
   47.10  end;
   47.11  
   47.12 @@ -43,7 +43,7 @@
   47.13      val ((y, t2), seed') = random seed;
   47.14      val (seed'', seed''') = random_split seed';
   47.15  
   47.16 -    val state = ref (seed'', [], fn () => Abs ("x", T1, t2 ()));
   47.17 +    val state = Unsynchronized.ref (seed'', [], fn () => Abs ("x", T1, t2 ()));
   47.18      fun random_fun' x =
   47.19        let
   47.20          val (seed, fun_map, f_t) = ! state;
   47.21 @@ -345,7 +345,9 @@
   47.22  
   47.23  (** building and compiling generator expressions **)
   47.24  
   47.25 -val eval_ref : (unit -> int -> int * int -> term list option * (int * int)) option ref = ref NONE;
   47.26 +val eval_ref :
   47.27 +    (unit -> int -> int * int -> term list option * (int * int)) option Unsynchronized.ref =
   47.28 +  Unsynchronized.ref NONE;
   47.29  
   47.30  val target = "Quickcheck";
   47.31  
    48.1 --- a/src/HOL/Tools/record.ML	Tue Sep 29 14:26:33 2009 +1000
    48.2 +++ b/src/HOL/Tools/record.ML	Tue Sep 29 18:14:08 2009 +0200
    48.3 @@ -16,15 +16,15 @@
    48.4    val record_split_simp_tac: thm list -> (term -> int) -> int -> tactic
    48.5    val record_split_name: string
    48.6    val record_split_wrapper: string * wrapper
    48.7 -  val print_record_type_abbr: bool ref
    48.8 -  val print_record_type_as_fields: bool ref
    48.9 +  val print_record_type_abbr: bool Unsynchronized.ref
   48.10 +  val print_record_type_as_fields: bool Unsynchronized.ref
   48.11  end;
   48.12  
   48.13  signature RECORD =
   48.14  sig
   48.15    include BASIC_RECORD
   48.16 -  val timing: bool ref
   48.17 -  val record_quick_and_dirty_sensitive: bool ref
   48.18 +  val timing: bool Unsynchronized.ref
   48.19 +  val record_quick_and_dirty_sensitive: bool Unsynchronized.ref
   48.20    val updateN: string
   48.21    val updN: string
   48.22    val ext_typeN: string
   48.23 @@ -287,7 +287,7 @@
   48.24  
   48.25  (* timing *)
   48.26  
   48.27 -val timing = ref false;
   48.28 +val timing = Unsynchronized.ref false;
   48.29  fun timeit_msg s x = if !timing then (warning s; timeit x) else x ();
   48.30  fun timing_msg s = if !timing then warning s else ();
   48.31  
   48.32 @@ -879,8 +879,8 @@
   48.33  
   48.34  (* print translations *)
   48.35  
   48.36 -val print_record_type_abbr = ref true;
   48.37 -val print_record_type_as_fields = ref true;
   48.38 +val print_record_type_abbr = Unsynchronized.ref true;
   48.39 +val print_record_type_as_fields = Unsynchronized.ref true;
   48.40  
   48.41  fun gen_field_upds_tr' mark sfx (tm as Const (name_field, _) $ k $ u) =
   48.42    let val t = (case k of (Abs (_,_,(Abs (_,_,t)$Bound 0))) 
   48.43 @@ -1072,7 +1072,7 @@
   48.44  
   48.45  (** record simprocs **)
   48.46  
   48.47 -val record_quick_and_dirty_sensitive = ref false;
   48.48 +val record_quick_and_dirty_sensitive = Unsynchronized.ref false;
   48.49  
   48.50  
   48.51  fun quick_and_dirty_prove stndrd thy asms prop tac =
    49.1 --- a/src/HOL/Tools/res_axioms.ML	Tue Sep 29 14:26:33 2009 +1000
    49.2 +++ b/src/HOL/Tools/res_axioms.ML	Tue Sep 29 18:14:08 2009 +0200
    49.3 @@ -16,7 +16,8 @@
    49.4    val combinators: thm -> thm
    49.5    val neg_conjecture_clauses: Proof.context -> thm -> int -> thm list * (string * typ) list
    49.6    val atpset_rules_of: Proof.context -> (string * thm) list
    49.7 -  val suppress_endtheory: bool ref     (*for emergency use where endtheory causes problems*)
    49.8 +  val suppress_endtheory: bool Unsynchronized.ref
    49.9 +    (*for emergency use where endtheory causes problems*)
   49.10    val setup: theory -> theory
   49.11  end;
   49.12  
   49.13 @@ -66,11 +67,11 @@
   49.14    prefix for the Skolem constant.*)
   49.15  fun declare_skofuns s th =
   49.16    let
   49.17 -    val nref = ref 0
   49.18 +    val nref = Unsynchronized.ref 0
   49.19      fun dec_sko (Const ("Ex",_) $ (xtp as Abs (_, T, p))) (axs, thy) =
   49.20            (*Existential: declare a Skolem function, then insert into body and continue*)
   49.21            let
   49.22 -            val cname = "sko_" ^ s ^ "_" ^ Int.toString (inc nref)
   49.23 +            val cname = "sko_" ^ s ^ "_" ^ Int.toString (Unsynchronized.inc nref)
   49.24              val args0 = OldTerm.term_frees xtp  (*get the formal parameter list*)
   49.25              val Ts = map type_of args0
   49.26              val extraTs = rhs_extra_types (Ts ---> T) xtp
   49.27 @@ -97,14 +98,14 @@
   49.28  
   49.29  (*Traverse a theorem, accumulating Skolem function definitions.*)
   49.30  fun assume_skofuns s th =
   49.31 -  let val sko_count = ref 0
   49.32 +  let val sko_count = Unsynchronized.ref 0
   49.33        fun dec_sko (Const ("Ex",_) $ (xtp as Abs(_,T,p))) defs =
   49.34              (*Existential: declare a Skolem function, then insert into body and continue*)
   49.35              let val skos = map (#1 o Logic.dest_equals) defs  (*existing sko fns*)
   49.36                  val args = OldTerm.term_frees xtp \\ skos  (*the formal parameters*)
   49.37                  val Ts = map type_of args
   49.38                  val cT = Ts ---> T
   49.39 -                val id = "sko_" ^ s ^ "_" ^ Int.toString (inc sko_count)
   49.40 +                val id = "sko_" ^ s ^ "_" ^ Int.toString (Unsynchronized.inc sko_count)
   49.41                  val c = Free (id, cT)
   49.42                  val rhs = list_abs_free (map dest_Free args,
   49.43                                           HOLogic.choice_const T $ xtp)
   49.44 @@ -449,7 +450,7 @@
   49.45  
   49.46  end;
   49.47  
   49.48 -val suppress_endtheory = ref false;
   49.49 +val suppress_endtheory = Unsynchronized.ref false;
   49.50  
   49.51  fun clause_cache_endtheory thy =
   49.52    if ! suppress_endtheory then NONE
    50.1 --- a/src/HOL/Tools/sat_funcs.ML	Tue Sep 29 14:26:33 2009 +1000
    50.2 +++ b/src/HOL/Tools/sat_funcs.ML	Tue Sep 29 18:14:08 2009 +0200
    50.3 @@ -48,9 +48,9 @@
    50.4  
    50.5  signature SAT =
    50.6  sig
    50.7 -	val trace_sat: bool ref    (* input: print trace messages *)
    50.8 -	val solver: string ref  (* input: name of SAT solver to be used *)
    50.9 -	val counter: int ref     (* output: number of resolution steps during last proof replay *)
   50.10 +	val trace_sat: bool Unsynchronized.ref    (* input: print trace messages *)
   50.11 +	val solver: string Unsynchronized.ref  (* input: name of SAT solver to be used *)
   50.12 +	val counter: int Unsynchronized.ref     (* output: number of resolution steps during last proof replay *)
   50.13  	val rawsat_thm: Proof.context -> cterm list -> thm
   50.14  	val rawsat_tac: Proof.context -> int -> tactic
   50.15  	val sat_tac: Proof.context -> int -> tactic
   50.16 @@ -60,11 +60,12 @@
   50.17  functor SATFunc(cnf : CNF) : SAT =
   50.18  struct
   50.19  
   50.20 -val trace_sat = ref false;
   50.21 +val trace_sat = Unsynchronized.ref false;
   50.22  
   50.23 -val solver = ref "zchaff_with_proofs";  (* see HOL/Tools/sat_solver.ML for possible values *)
   50.24 +val solver = Unsynchronized.ref "zchaff_with_proofs";
   50.25 +  (*see HOL/Tools/sat_solver.ML for possible values*)
   50.26  
   50.27 -val counter = ref 0;
   50.28 +val counter = Unsynchronized.ref 0;
   50.29  
   50.30  val resolution_thm =
   50.31    @{lemma "(P ==> False) ==> (~ P ==> False) ==> False" by (rule case_split)}
   50.32 @@ -191,7 +192,7 @@
   50.33  					  " (hyps: " ^ ML_Syntax.print_list
   50.34  					      (Syntax.string_of_term_global (theory_of_thm c_new)) (#hyps (rep_thm c_new)) ^ ")")
   50.35  				else ()
   50.36 -			val _ = inc counter
   50.37 +			val _ = Unsynchronized.inc counter
   50.38  		in
   50.39  			(c_new, new_hyps)
   50.40  		end
    51.1 --- a/src/HOL/Tools/sat_solver.ML	Tue Sep 29 14:26:33 2009 +1000
    51.2 +++ b/src/HOL/Tools/sat_solver.ML	Tue Sep 29 18:14:08 2009 +0200
    51.3 @@ -26,7 +26,7 @@
    51.4    val read_dimacs_cnf_file : Path.T -> PropLogic.prop_formula
    51.5  
    51.6    (* generic solver interface *)
    51.7 -  val solvers       : (string * solver) list ref
    51.8 +  val solvers       : (string * solver) list Unsynchronized.ref
    51.9    val add_solver    : string * solver -> unit
   51.10    val invoke_solver : string -> solver  (* exception Option *)
   51.11  end;
   51.12 @@ -363,7 +363,7 @@
   51.13  (* solvers: a (reference to a) table of all registered SAT solvers           *)
   51.14  (* ------------------------------------------------------------------------- *)
   51.15  
   51.16 -  val solvers = ref ([] : (string * solver) list);
   51.17 +  val solvers = Unsynchronized.ref ([] : (string * solver) list);
   51.18  
   51.19  (* ------------------------------------------------------------------------- *)
   51.20  (* add_solver: updates 'solvers' by adding a new solver                      *)
   51.21 @@ -629,7 +629,7 @@
   51.22        val _ = init_array (cnf, 0)
   51.23        (* optimization for the common case where MiniSat "R"s clauses in their *)
   51.24        (* original order:                                                      *)
   51.25 -      val last_ref_clause = ref (number_of_clauses - 1)
   51.26 +      val last_ref_clause = Unsynchronized.ref (number_of_clauses - 1)
   51.27        (* search the 'clauses' array for the given list of literals 'lits', *)
   51.28        (* starting at index '!last_ref_clause + 1'                          *)
   51.29        (* int list -> int option *)
   51.30 @@ -661,17 +661,17 @@
   51.31          | NONE   => raise INVALID_PROOF ("File format error: number expected (" ^ quote s ^ " encountered).")
   51.32        )
   51.33        (* parse the proof file *)
   51.34 -      val clause_table  = ref (Inttab.empty : int list Inttab.table)
   51.35 -      val empty_id      = ref ~1
   51.36 +      val clause_table  = Unsynchronized.ref (Inttab.empty : int list Inttab.table)
   51.37 +      val empty_id      = Unsynchronized.ref ~1
   51.38        (* contains a mapping from clause IDs as used by MiniSat to clause IDs in *)
   51.39        (* our proof format, where original clauses are numbered starting from 0  *)
   51.40 -      val clause_id_map = ref (Inttab.empty : int Inttab.table)
   51.41 +      val clause_id_map = Unsynchronized.ref (Inttab.empty : int Inttab.table)
   51.42        fun sat_to_proof id = (
   51.43          case Inttab.lookup (!clause_id_map) id of
   51.44            SOME id' => id'
   51.45          | NONE     => raise INVALID_PROOF ("Clause ID " ^ Int.toString id ^ " used, but not defined.")
   51.46        )
   51.47 -      val next_id = ref (number_of_clauses - 1)
   51.48 +      val next_id = Unsynchronized.ref (number_of_clauses - 1)
   51.49        (* string list -> unit *)
   51.50        fun process_tokens [] =
   51.51          ()
   51.52 @@ -708,7 +708,7 @@
   51.53                  | unevens (x :: _ :: xs) = x :: unevens xs
   51.54                val rs       = (map sat_to_proof o unevens o map int_from_string) ids
   51.55                (* extend the mapping of clause IDs with this newly defined ID *)
   51.56 -              val proof_id = inc next_id
   51.57 +              val proof_id = Unsynchronized.inc next_id
   51.58                val _        = clause_id_map := Inttab.update_new (cid, proof_id) (!clause_id_map)
   51.59                                 handle Inttab.DUP _ => raise INVALID_PROOF ("File format error: clause " ^ id ^ " defined more than once (in \"C\").")
   51.60              in
   51.61 @@ -821,9 +821,9 @@
   51.62          | NONE   => raise INVALID_PROOF ("File format error: number expected (" ^ quote s ^ " encountered).")
   51.63        )
   51.64        (* parse the "resolve_trace" file *)
   51.65 -      val clause_offset = ref ~1
   51.66 -      val clause_table  = ref (Inttab.empty : int list Inttab.table)
   51.67 -      val empty_id      = ref ~1
   51.68 +      val clause_offset = Unsynchronized.ref ~1
   51.69 +      val clause_table  = Unsynchronized.ref (Inttab.empty : int list Inttab.table)
   51.70 +      val empty_id      = Unsynchronized.ref ~1
   51.71        (* string list -> unit *)
   51.72        fun process_tokens [] =
   51.73          ()
    52.1 --- a/src/HOL/ex/SVC_Oracle.thy	Tue Sep 29 14:26:33 2009 +1000
    52.2 +++ b/src/HOL/ex/SVC_Oracle.thy	Tue Sep 29 18:14:08 2009 +0200
    52.3 @@ -44,8 +44,8 @@
    52.4      and body   = Term.strip_all_body t
    52.5      val Us = map #2 params
    52.6      val nPar = length params
    52.7 -    val vname = ref "V_a"
    52.8 -    val pairs = ref ([] : (term*term) list)
    52.9 +    val vname = Unsynchronized.ref "V_a"
   52.10 +    val pairs = Unsynchronized.ref ([] : (term*term) list)
   52.11      fun insert t =
   52.12          let val T = fastype_of t
   52.13              val v = Logic.combound (Var ((!vname,0), Us--->T), 0, nPar)
    53.1 --- a/src/HOL/ex/predicate_compile.ML	Tue Sep 29 14:26:33 2009 +1000
    53.2 +++ b/src/HOL/ex/predicate_compile.ML	Tue Sep 29 18:14:08 2009 +0200
    53.3 @@ -27,10 +27,10 @@
    53.4    val code_pred_cmd: string -> Proof.context -> Proof.state
    53.5    val print_stored_rules: theory -> unit
    53.6    val print_all_modes: theory -> unit
    53.7 -  val do_proofs: bool ref
    53.8 +  val do_proofs: bool Unsynchronized.ref
    53.9    val mk_casesrule : Proof.context -> int -> thm list -> term
   53.10    val analyze_compr: theory -> term -> term
   53.11 -  val eval_ref: (unit -> term Predicate.pred) option ref
   53.12 +  val eval_ref: (unit -> term Predicate.pred) option Unsynchronized.ref
   53.13    val add_equations : string list -> theory -> theory
   53.14    val code_pred_intros_attrib : attribute
   53.15    (* used by Quickcheck_Generator *) 
   53.16 @@ -111,7 +111,7 @@
   53.17  fun print_tac s = Seq.single; (* (if ! Toplevel.debug then Tactical.print_tac s else Seq.single); *)
   53.18  fun debug_tac msg = Seq.single; (* (fn st => (Output.tracing msg; Seq.single st)); *)
   53.19  
   53.20 -val do_proofs = ref true;
   53.21 +val do_proofs = Unsynchronized.ref true;
   53.22  
   53.23  fun mycheat_tac thy i st =
   53.24    (Tactic.rtac (SkipProof.make_thm thy (Var (("A", 0), propT))) i) st
   53.25 @@ -2100,7 +2100,7 @@
   53.26  
   53.27  (* transformation for code generation *)
   53.28  
   53.29 -val eval_ref = ref (NONE : (unit -> term Predicate.pred) option);
   53.30 +val eval_ref = Unsynchronized.ref (NONE : (unit -> term Predicate.pred) option);
   53.31  
   53.32  (*FIXME turn this into an LCF-guarded preprocessor for comprehensions*)
   53.33  fun analyze_compr thy t_compr =
    54.1 --- a/src/HOL/ex/svc_funcs.ML	Tue Sep 29 14:26:33 2009 +1000
    54.2 +++ b/src/HOL/ex/svc_funcs.ML	Tue Sep 29 18:14:08 2009 +0200
    54.3 @@ -18,7 +18,7 @@
    54.4  
    54.5  structure Svc =
    54.6  struct
    54.7 - val trace = ref false;
    54.8 + val trace = Unsynchronized.ref false;
    54.9  
   54.10   datatype expr =
   54.11       Buildin of string * expr list
   54.12 @@ -127,7 +127,7 @@
   54.13    let
   54.14      val params = rev (Term.rename_wrt_term t (Term.strip_all_vars t))
   54.15      and body   = Term.strip_all_body t
   54.16 -    val nat_vars = ref ([] : string list)
   54.17 +    val nat_vars = Unsynchronized.ref ([] : string list)
   54.18      (*translation of a variable: record all natural numbers*)
   54.19      fun trans_var (a,T,is) =
   54.20          (if T = HOLogic.natT then nat_vars := (insert (op =) a (!nat_vars))
    55.1 --- a/src/HOLCF/Tools/Domain/domain_theorems.ML	Tue Sep 29 14:26:33 2009 +1000
    55.2 +++ b/src/HOLCF/Tools/Domain/domain_theorems.ML	Tue Sep 29 18:14:08 2009 +0200
    55.3 @@ -1,6 +1,6 @@
    55.4  (*  Title:      HOLCF/Tools/Domain/domain_theorems.ML
    55.5      Author:     David von Oheimb
    55.6 -                New proofs/tactics by Brian Huffman
    55.7 +    Author:     Brian Huffman
    55.8  
    55.9  Proof generator for domain command.
   55.10  *)
   55.11 @@ -11,15 +11,15 @@
   55.12  sig
   55.13    val theorems: Domain_Library.eq * Domain_Library.eq list -> theory -> thm list * theory;
   55.14    val comp_theorems: bstring * Domain_Library.eq list -> theory -> thm list * theory;
   55.15 -  val quiet_mode: bool ref;
   55.16 -  val trace_domain: bool ref;
   55.17 +  val quiet_mode: bool Unsynchronized.ref;
   55.18 +  val trace_domain: bool Unsynchronized.ref;
   55.19  end;
   55.20  
   55.21  structure Domain_Theorems :> DOMAIN_THEOREMS =
   55.22  struct
   55.23  
   55.24 -val quiet_mode = ref false;
   55.25 -val trace_domain = ref false;
   55.26 +val quiet_mode = Unsynchronized.ref false;
   55.27 +val trace_domain = Unsynchronized.ref false;
   55.28  
   55.29  fun message s = if !quiet_mode then () else writeln s;
   55.30  fun trace s = if !trace_domain then tracing s else ();
    56.1 --- a/src/Provers/Arith/fast_lin_arith.ML	Tue Sep 29 14:26:33 2009 +1000
    56.2 +++ b/src/Provers/Arith/fast_lin_arith.ML	Tue Sep 29 18:14:08 2009 +0200
    56.3 @@ -96,8 +96,8 @@
    56.4                       lessD: thm list, neqE: thm list, simpset: Simplifier.simpset,
    56.5                       number_of : serial * (theory -> typ -> int -> cterm)})
    56.6                  -> Context.generic -> Context.generic
    56.7 -  val trace: bool ref
    56.8 -  val warning_count: int ref;
    56.9 +  val trace: bool Unsynchronized.ref
   56.10 +  val warning_count: int Unsynchronized.ref;
   56.11  end;
   56.12  
   56.13  functor Fast_Lin_Arith
   56.14 @@ -152,7 +152,7 @@
   56.15     treat non-negative atoms separately rather than adding 0 <= atom
   56.16  *)
   56.17  
   56.18 -val trace = ref false;
   56.19 +val trace = Unsynchronized.ref false;
   56.20  
   56.21  datatype lineq_type = Eq | Le | Lt;
   56.22  
   56.23 @@ -426,7 +426,7 @@
   56.24  fun trace_msg msg =
   56.25    if !trace then tracing msg else ();
   56.26  
   56.27 -val warning_count = ref 0;
   56.28 +val warning_count = Unsynchronized.ref 0;
   56.29  val warning_count_max = 10;
   56.30  
   56.31  val union_term = curry (gen_union Pattern.aeconv);
   56.32 @@ -533,7 +533,7 @@
   56.33        val _ =
   56.34          if LA_Logic.is_False fls then ()
   56.35          else
   56.36 -          let val count = CRITICAL (fn () => inc warning_count) in
   56.37 +          let val count = CRITICAL (fn () => Unsynchronized.inc warning_count) in
   56.38              if count > warning_count_max then ()
   56.39              else
   56.40                (tracing (cat_lines
    57.1 --- a/src/Provers/blast.ML	Tue Sep 29 14:26:33 2009 +1000
    57.2 +++ b/src/Provers/blast.ML	Tue Sep 29 18:14:08 2009 +0200
    57.3 @@ -66,9 +66,9 @@
    57.4    exception TRANS of string    (*reports translation errors*)
    57.5    datatype term =
    57.6        Const of string * term list
    57.7 -    | Skolem of string * term option ref list
    57.8 +    | Skolem of string * term option Unsynchronized.ref list
    57.9      | Free  of string
   57.10 -    | Var   of term option ref
   57.11 +    | Var   of term option Unsynchronized.ref
   57.12      | Bound of int
   57.13      | Abs   of string*term
   57.14      | $  of term*term;
   57.15 @@ -78,10 +78,10 @@
   57.16    val blast_tac         : claset -> int -> tactic
   57.17    val setup             : theory -> theory
   57.18    (*debugging tools*)
   57.19 -  val stats             : bool ref
   57.20 -  val trace             : bool ref
   57.21 -  val fullTrace         : branch list list ref
   57.22 -  val fromType          : (indexname * term) list ref -> Term.typ -> term
   57.23 +  val stats             : bool Unsynchronized.ref
   57.24 +  val trace             : bool Unsynchronized.ref
   57.25 +  val fullTrace         : branch list list Unsynchronized.ref
   57.26 +  val fromType          : (indexname * term) list Unsynchronized.ref -> Term.typ -> term
   57.27    val fromTerm          : theory -> Term.term -> term
   57.28    val fromSubgoal       : theory -> Term.term -> term
   57.29    val instVars          : term -> (unit -> unit)
   57.30 @@ -98,14 +98,14 @@
   57.31  
   57.32  type claset = Data.claset;
   57.33  
   57.34 -val trace = ref false
   57.35 -and stats = ref false;   (*for runtime and search statistics*)
   57.36 +val trace = Unsynchronized.ref false
   57.37 +and stats = Unsynchronized.ref false;   (*for runtime and search statistics*)
   57.38  
   57.39  datatype term =
   57.40      Const  of string * term list  (*typargs constant--as a terms!*)
   57.41 -  | Skolem of string * term option ref list
   57.42 +  | Skolem of string * term option Unsynchronized.ref list
   57.43    | Free   of string
   57.44 -  | Var    of term option ref
   57.45 +  | Var    of term option Unsynchronized.ref
   57.46    | Bound  of int
   57.47    | Abs    of string*term
   57.48    | op $   of term*term;
   57.49 @@ -115,7 +115,7 @@
   57.50      {pairs: ((term*bool) list * (*safe formulae on this level*)
   57.51                 (term*bool) list) list,  (*haz formulae  on this level*)
   57.52       lits:   term list,                 (*literals: irreducible formulae*)
   57.53 -     vars:   term option ref list,      (*variables occurring in branch*)
   57.54 +     vars:   term option Unsynchronized.ref list,  (*variables occurring in branch*)
   57.55       lim:    int};                      (*resource limit*)
   57.56  
   57.57  
   57.58 @@ -123,11 +123,11 @@
   57.59  
   57.60  datatype state = State of
   57.61   {thy: theory,
   57.62 -  fullTrace: branch list list ref,
   57.63 -  trail: term option ref list ref,
   57.64 -  ntrail: int ref,
   57.65 -  nclosed: int ref,
   57.66 -  ntried: int ref}
   57.67 +  fullTrace: branch list list Unsynchronized.ref,
   57.68 +  trail: term option Unsynchronized.ref list Unsynchronized.ref,
   57.69 +  ntrail: int Unsynchronized.ref,
   57.70 +  nclosed: int Unsynchronized.ref,
   57.71 +  ntried: int Unsynchronized.ref}
   57.72  
   57.73  fun reject_const thy c =
   57.74    is_some (Sign.const_type thy c) andalso
   57.75 @@ -138,11 +138,11 @@
   57.76    reject_const thy "*False*";
   57.77    State
   57.78     {thy = thy,
   57.79 -    fullTrace = ref [],
   57.80 -    trail = ref [],
   57.81 -    ntrail = ref 0,
   57.82 -    nclosed = ref 0,  (*branches closed: number of branches closed during the search*)
   57.83 -    ntried = ref 1}); (*branches tried: number of branches created by splitting (counting from 1)*)
   57.84 +    fullTrace = Unsynchronized.ref [],
   57.85 +    trail = Unsynchronized.ref [],
   57.86 +    ntrail = Unsynchronized.ref 0,
   57.87 +    nclosed = Unsynchronized.ref 0, (*branches closed: number of branches closed during the search*)
   57.88 +    ntried = Unsynchronized.ref 1}); (*branches tried: number of branches created by splitting (counting from 1)*)
   57.89  
   57.90  
   57.91  
   57.92 @@ -199,7 +199,7 @@
   57.93    | fromType alist (Term.TFree(a,_)) = Free a
   57.94    | fromType alist (Term.TVar (ixn,_)) =
   57.95                (case (AList.lookup (op =) (!alist) ixn) of
   57.96 -                   NONE => let val t' = Var(ref NONE)
   57.97 +                   NONE => let val t' = Var (Unsynchronized.ref NONE)
   57.98                             in  alist := (ixn, t') :: !alist;  t'
   57.99                             end
  57.100                   | SOME v => v)
  57.101 @@ -209,11 +209,11 @@
  57.102  
  57.103  
  57.104  (*Tests whether 2 terms are alpha-convertible; chases instantiations*)
  57.105 -fun (Const (a, ts)) aconv (Const (b, us)) = a=b andalso aconvs (ts, us)
  57.106 -  | (Skolem (a,_)) aconv (Skolem (b,_)) = a=b  (*arglists must then be equal*)
  57.107 -  | (Free a)       aconv (Free b)       = a=b
  57.108 -  | (Var(ref(SOME t))) aconv u          = t aconv u
  57.109 -  | t          aconv (Var(ref(SOME u))) = t aconv u
  57.110 +fun (Const (a, ts)) aconv (Const (b, us)) = a = b andalso aconvs (ts, us)
  57.111 +  | (Skolem (a,_)) aconv (Skolem (b,_)) = a = b  (*arglists must then be equal*)
  57.112 +  | (Free a) aconv (Free b) = a = b
  57.113 +  | (Var (Unsynchronized.ref(SOME t))) aconv u = t aconv u
  57.114 +  | t aconv (Var (Unsynchronized.ref (SOME u))) = t aconv u
  57.115    | (Var v)        aconv (Var w)        = v=w   (*both Vars are un-assigned*)
  57.116    | (Bound i)      aconv (Bound j)      = i=j
  57.117    | (Abs(_,t))     aconv (Abs(_,u))     = t aconv u
  57.118 @@ -229,7 +229,7 @@
  57.119  
  57.120  fun ins_term(t,ts) = if mem_term(t,ts) then ts else t :: ts;
  57.121  
  57.122 -fun mem_var (v: term option ref, []) = false
  57.123 +fun mem_var (v: term option Unsynchronized.ref, []) = false
  57.124    | mem_var (v, v'::vs)              = v=v' orelse mem_var(v,vs);
  57.125  
  57.126  fun ins_var(v,vs) = if mem_var(v,vs) then vs else v :: vs;
  57.127 @@ -238,19 +238,19 @@
  57.128  (** Vars **)
  57.129  
  57.130  (*Accumulates the Vars in the term, suppressing duplicates*)
  57.131 -fun add_term_vars (Skolem(a,args),      vars) = add_vars_vars(args,vars)
  57.132 -  | add_term_vars (Var (v as ref NONE), vars) = ins_var (v, vars)
  57.133 -  | add_term_vars (Var (ref (SOME u)), vars)  = add_term_vars(u,vars)
  57.134 -  | add_term_vars (Const (_,ts),        vars) = add_terms_vars(ts,vars)
  57.135 -  | add_term_vars (Abs (_,body),        vars) = add_term_vars(body,vars)
  57.136 -  | add_term_vars (f$t, vars) =  add_term_vars (f, add_term_vars(t, vars))
  57.137 -  | add_term_vars (_,   vars) = vars
  57.138 +fun add_term_vars (Skolem(a,args),  vars) = add_vars_vars(args,vars)
  57.139 +  | add_term_vars (Var (v as Unsynchronized.ref NONE), vars) = ins_var (v, vars)
  57.140 +  | add_term_vars (Var (Unsynchronized.ref (SOME u)), vars) = add_term_vars (u, vars)
  57.141 +  | add_term_vars (Const (_, ts), vars) = add_terms_vars (ts, vars)
  57.142 +  | add_term_vars (Abs (_, body), vars) = add_term_vars (body, vars)
  57.143 +  | add_term_vars (f $ t, vars) = add_term_vars (f, add_term_vars (t, vars))
  57.144 +  | add_term_vars (_, vars) = vars
  57.145  (*Term list version.  [The fold functionals are slow]*)
  57.146  and add_terms_vars ([],    vars) = vars
  57.147    | add_terms_vars (t::ts, vars) = add_terms_vars (ts, add_term_vars(t,vars))
  57.148  (*Var list version.*)
  57.149 -and add_vars_vars ([],    vars) = vars
  57.150 -  | add_vars_vars (ref (SOME u) :: vs, vars) =
  57.151 +and add_vars_vars ([], vars) = vars
  57.152 +  | add_vars_vars (Unsynchronized.ref (SOME u) :: vs, vars) =
  57.153          add_vars_vars (vs, add_term_vars(u,vars))
  57.154    | add_vars_vars (v::vs, vars) =   (*v must be a ref NONE*)
  57.155          add_vars_vars (vs, ins_var (v, vars));
  57.156 @@ -297,10 +297,10 @@
  57.157  
  57.158  (*Normalize...but not the bodies of ABSTRACTIONS*)
  57.159  fun norm t = case t of
  57.160 -    Skolem (a,args)      => Skolem(a, vars_in_vars args)
  57.161 -  | Const(a,ts)          => Const(a, map norm ts)
  57.162 -  | (Var (ref NONE))     => t
  57.163 -  | (Var (ref (SOME u))) => norm u
  57.164 +    Skolem (a, args) => Skolem (a, vars_in_vars args)
  57.165 +  | Const (a, ts) => Const (a, map norm ts)
  57.166 +  | (Var (Unsynchronized.ref NONE)) => t
  57.167 +  | (Var (Unsynchronized.ref (SOME u))) => norm u
  57.168    | (f $ u) => (case norm f of
  57.169                      Abs(_,body) => norm (subst_bound (u, body))
  57.170                    | nf => nf $ norm u)
  57.171 @@ -394,14 +394,14 @@
  57.172  (*Convert from "real" terms to prototerms; eta-contract.
  57.173    Code is similar to fromSubgoal.*)
  57.174  fun fromTerm thy t =
  57.175 -  let val alistVar = ref []
  57.176 -      and alistTVar = ref []
  57.177 +  let val alistVar = Unsynchronized.ref []
  57.178 +      and alistTVar = Unsynchronized.ref []
  57.179        fun from (Term.Const aT) = fromConst thy alistTVar aT
  57.180          | from (Term.Free  (a,_)) = Free a
  57.181          | from (Term.Bound i)     = Bound i
  57.182          | from (Term.Var (ixn,T)) =
  57.183                (case (AList.lookup (op =) (!alistVar) ixn) of
  57.184 -                   NONE => let val t' = Var(ref NONE)
  57.185 +                   NONE => let val t' = Var (Unsynchronized.ref NONE)
  57.186                             in  alistVar := (ixn, t') :: !alistVar;  t'
  57.187                             end
  57.188                   | SOME v => v)
  57.189 @@ -417,10 +417,10 @@
  57.190  (*A debugging function: replaces all Vars by dummy Frees for visual inspection
  57.191    of whether they are distinct.  Function revert undoes the assignments.*)
  57.192  fun instVars t =
  57.193 -  let val name = ref "a"
  57.194 -      val updated = ref []
  57.195 +  let val name = Unsynchronized.ref "a"
  57.196 +      val updated = Unsynchronized.ref []
  57.197        fun inst (Const(a,ts)) = List.app inst ts
  57.198 -        | inst (Var(v as ref NONE)) = (updated := v :: (!updated);
  57.199 +        | inst (Var(v as Unsynchronized.ref NONE)) = (updated := v :: (!updated);
  57.200                                         v       := SOME (Free ("?" ^ !name));
  57.201                                         name    := Symbol.bump_string (!name))
  57.202          | inst (Abs(a,t))    = inst t
  57.203 @@ -450,7 +450,7 @@
  57.204  fun delete_concl [] = raise ElimBadPrem
  57.205    | delete_concl (P :: Ps) =
  57.206        (case P of
  57.207 -        Const (c, _) $ Var (ref (SOME (Const ("*False*", _)))) =>
  57.208 +        Const (c, _) $ Var (Unsynchronized.ref (SOME (Const ("*False*", _)))) =>
  57.209            if c = "*Goal*" orelse c = Data.not_name then Ps
  57.210            else P :: delete_concl Ps
  57.211        | _ => P :: delete_concl Ps);
  57.212 @@ -606,10 +606,10 @@
  57.213  (*Convert from prototerms to ordinary terms with dummy types for tracing*)
  57.214  fun showTerm d (Const (a,_)) = Term.Const (a,dummyT)
  57.215    | showTerm d (Skolem(a,_)) = Term.Const (a,dummyT)
  57.216 -  | showTerm d (Free a)      = Term.Free  (a,dummyT)
  57.217 -  | showTerm d (Bound i)     = Term.Bound i
  57.218 -  | showTerm d (Var(ref(SOME u))) = showTerm d u
  57.219 -  | showTerm d (Var(ref NONE))    = dummyVar2
  57.220 +  | showTerm d (Free a) = Term.Free  (a,dummyT)
  57.221 +  | showTerm d (Bound i) = Term.Bound i
  57.222 +  | showTerm d (Var (Unsynchronized.ref(SOME u))) = showTerm d u
  57.223 +  | showTerm d (Var (Unsynchronized.ref NONE)) = dummyVar2
  57.224    | showTerm d (Abs(a,t))    = if d=0 then dummyVar
  57.225                                 else Term.Abs(a, dummyT, showTerm (d-1) t)
  57.226    | showTerm d (f $ u)       = if d=0 then dummyVar
  57.227 @@ -687,10 +687,10 @@
  57.228  
  57.229  (*Replace the ATOMIC term "old" by "new" in t*)
  57.230  fun subst_atomic (old,new) t =
  57.231 -    let fun subst (Var(ref(SOME u))) = subst u
  57.232 -          | subst (Abs(a,body))      = Abs(a, subst body)
  57.233 -          | subst (f$t)              = subst f $ subst t
  57.234 -          | subst t                  = if t aconv old then new else t
  57.235 +    let fun subst (Var(Unsynchronized.ref(SOME u))) = subst u
  57.236 +          | subst (Abs(a,body)) = Abs(a, subst body)
  57.237 +          | subst (f$t) = subst f $ subst t
  57.238 +          | subst t = if t aconv old then new else t
  57.239      in  subst t  end;
  57.240  
  57.241  (*Eta-contract a term from outside: just enough to reduce it to an atom*)
  57.242 @@ -723,11 +723,11 @@
  57.243                       Skolem(_,vars) => vars
  57.244                     | _ => []
  57.245        fun occEq u = (t aconv u) orelse occ u
  57.246 -      and occ (Var(ref(SOME u))) = occEq u
  57.247 -        | occ (Var v)            = not (mem_var (v, vars))
  57.248 -        | occ (Abs(_,u))         = occEq u
  57.249 -        | occ (f$u)              = occEq u  orelse  occEq f
  57.250 -        | occ (_)                = false;
  57.251 +      and occ (Var(Unsynchronized.ref(SOME u))) = occEq u
  57.252 +        | occ (Var v) = not (mem_var (v, vars))
  57.253 +        | occ (Abs(_,u)) = occEq u
  57.254 +        | occ (f$u) = occEq u  orelse  occEq f
  57.255 +        | occ _ = false;
  57.256    in  occEq  end;
  57.257  
  57.258  exception DEST_EQ;
  57.259 @@ -1199,8 +1199,8 @@
  57.260  
  57.261  (*Translation of a subgoal: Skolemize all parameters*)
  57.262  fun fromSubgoal thy t =
  57.263 -  let val alistVar = ref []
  57.264 -      and alistTVar = ref []
  57.265 +  let val alistVar = Unsynchronized.ref []
  57.266 +      and alistTVar = Unsynchronized.ref []
  57.267        fun hdvar ((ix,(v,is))::_) = v
  57.268        fun from lev t =
  57.269          let val (ht,ts) = Term.strip_comb t
  57.270 @@ -1219,7 +1219,7 @@
  57.271              | Term.Bound i     => apply (Bound i)
  57.272              | Term.Var (ix,_) =>
  57.273                    (case (AList.lookup (op =) (!alistVar) ix) of
  57.274 -                       NONE => (alistVar := (ix, (ref NONE, bounds ts))
  57.275 +                       NONE => (alistVar := (ix, (Unsynchronized.ref NONE, bounds ts))
  57.276                                            :: !alistVar;
  57.277                                  Var (hdvar(!alistVar)))
  57.278                       | SOME(v,is) => if is=bounds ts then Var v
  57.279 @@ -1290,7 +1290,7 @@
  57.280  (*** For debugging: these apply the prover to a subgoal and return
  57.281       the resulting tactics, trace, etc.                            ***)
  57.282  
  57.283 -val fullTrace = ref ([]: branch list list);
  57.284 +val fullTrace = Unsynchronized.ref ([]: branch list list);
  57.285  
  57.286  (*Read a string to make an initial, singleton branch*)
  57.287  fun readGoal thy s = Syntax.read_prop_global thy s |> fromTerm thy |> rand |> mkGoal;
    58.1 --- a/src/Provers/classical.ML	Tue Sep 29 14:26:33 2009 +1000
    58.2 +++ b/src/Provers/classical.ML	Tue Sep 29 18:14:08 2009 +0200
    58.3 @@ -74,7 +74,7 @@
    58.4  
    58.5    val fast_tac          : claset -> int -> tactic
    58.6    val slow_tac          : claset -> int -> tactic
    58.7 -  val weight_ASTAR      : int ref
    58.8 +  val weight_ASTAR      : int Unsynchronized.ref
    58.9    val astar_tac         : claset -> int -> tactic
   58.10    val slow_astar_tac    : claset -> int -> tactic
   58.11    val best_tac          : claset -> int -> tactic
   58.12 @@ -746,7 +746,7 @@
   58.13  
   58.14  
   58.15  (***ASTAR with weight weight_ASTAR, by Norbert Voelker*)
   58.16 -val weight_ASTAR = ref 5;
   58.17 +val weight_ASTAR = Unsynchronized.ref 5;
   58.18  
   58.19  fun astar_tac cs =
   58.20    ObjectLogic.atomize_prems_tac THEN'
    59.1 --- a/src/Provers/order.ML	Tue Sep 29 14:26:33 2009 +1000
    59.2 +++ b/src/Provers/order.ML	Tue Sep 29 18:14:08 2009 +0200
    59.3 @@ -656,10 +656,10 @@
    59.4       let
    59.5    (* Ordered list of the vertices that DFS has finished with;
    59.6       most recently finished goes at the head. *)
    59.7 -  val finish : term list ref = ref nil
    59.8 +  val finish : term list Unsynchronized.ref = Unsynchronized.ref []
    59.9  
   59.10    (* List of vertices which have been visited. *)
   59.11 -  val visited : term list ref = ref nil
   59.12 +  val visited : term list Unsynchronized.ref = Unsynchronized.ref []
   59.13  
   59.14    fun been_visited v = exists (fn w => w aconv v) (!visited)
   59.15  
   59.16 @@ -715,7 +715,7 @@
   59.17  fun dfs_int_reachable g u =
   59.18   let
   59.19    (* List of vertices which have been visited. *)
   59.20 -  val visited : int list ref = ref nil
   59.21 +  val visited : int list Unsynchronized.ref = Unsynchronized.ref []
   59.22  
   59.23    fun been_visited v = exists (fn w => w = v) (!visited)
   59.24  
   59.25 @@ -755,8 +755,8 @@
   59.26  
   59.27  fun dfs eq_comp g u v =
   59.28   let
   59.29 -    val pred = ref nil;
   59.30 -    val visited = ref nil;
   59.31 +    val pred = Unsynchronized.ref [];
   59.32 +    val visited = Unsynchronized.ref [];
   59.33  
   59.34      fun been_visited v = exists (fn w => eq_comp (w, v)) (!visited)
   59.35  
    60.1 --- a/src/Provers/quasi.ML	Tue Sep 29 14:26:33 2009 +1000
    60.2 +++ b/src/Provers/quasi.ML	Tue Sep 29 18:14:08 2009 +0200
    60.3 @@ -348,8 +348,8 @@
    60.4  
    60.5  fun dfs eq_comp g u v =
    60.6   let
    60.7 -    val pred = ref nil;
    60.8 -    val visited = ref nil;
    60.9 +    val pred = Unsynchronized.ref [];
   60.10 +    val visited = Unsynchronized.ref [];
   60.11  
   60.12      fun been_visited v = exists (fn w => eq_comp (w, v)) (!visited)
   60.13  
    61.1 --- a/src/Provers/trancl.ML	Tue Sep 29 14:26:33 2009 +1000
    61.2 +++ b/src/Provers/trancl.ML	Tue Sep 29 18:14:08 2009 +0200
    61.3 @@ -275,8 +275,8 @@
    61.4  
    61.5  fun dfs eq_comp g u v =
    61.6   let
    61.7 -    val pred = ref nil;
    61.8 -    val visited = ref nil;
    61.9 +    val pred = Unsynchronized.ref [];
   61.10 +    val visited = Unsynchronized.ref [];
   61.11  
   61.12      fun been_visited v = exists (fn w => eq_comp (w, v)) (!visited)
   61.13  
   61.14 @@ -349,7 +349,7 @@
   61.15  fun dfs_reachable eq_comp g u =
   61.16   let
   61.17    (* List of vertices which have been visited. *)
   61.18 -  val visited  = ref nil;
   61.19 +  val visited  = Unsynchronized.ref nil;
   61.20  
   61.21    fun been_visited v = exists (fn w => eq_comp (w, v)) (!visited)
   61.22  
    62.1 --- a/src/Pure/Concurrent/future.ML	Tue Sep 29 14:26:33 2009 +1000
    62.2 +++ b/src/Pure/Concurrent/future.ML	Tue Sep 29 18:14:08 2009 +0200
    62.3 @@ -99,13 +99,13 @@
    62.4  
    62.5  (* global state *)
    62.6  
    62.7 -val queue = ref Task_Queue.empty;
    62.8 -val next = ref 0;
    62.9 -val workers = ref ([]: (Thread.thread * bool) list);
   62.10 -val scheduler = ref (NONE: Thread.thread option);
   62.11 -val excessive = ref 0;
   62.12 -val canceled = ref ([]: Task_Queue.group list);
   62.13 -val do_shutdown = ref false;
   62.14 +val queue = Unsynchronized.ref Task_Queue.empty;
   62.15 +val next = Unsynchronized.ref 0;
   62.16 +val workers = Unsynchronized.ref ([]: (Thread.thread * bool) list);
   62.17 +val scheduler = Unsynchronized.ref (NONE: Thread.thread option);
   62.18 +val excessive = Unsynchronized.ref 0;
   62.19 +val canceled = Unsynchronized.ref ([]: Task_Queue.group list);
   62.20 +val do_shutdown = Unsynchronized.ref false;
   62.21  
   62.22  
   62.23  (* synchronization *)
   62.24 @@ -162,7 +162,8 @@
   62.25    in (result, job) end;
   62.26  
   62.27  fun do_cancel group = (*requires SYNCHRONIZED*)
   62.28 - (change canceled (insert Task_Queue.eq_group group); broadcast scheduler_event);
   62.29 + (Unsynchronized.change canceled (insert Task_Queue.eq_group group);
   62.30 +  broadcast scheduler_event);
   62.31  
   62.32  fun execute name (task, group, jobs) =
   62.33    let
   62.34 @@ -171,7 +172,7 @@
   62.35        fold (fn job => fn ok => job valid andalso ok) jobs true) ();
   62.36      val _ = SYNCHRONIZED "finish" (fn () =>
   62.37        let
   62.38 -        val maximal = change_result queue (Task_Queue.finish task);
   62.39 +        val maximal = Unsynchronized.change_result queue (Task_Queue.finish task);
   62.40          val _ =
   62.41            if ok then ()
   62.42            else if Task_Queue.cancel (! queue) group then ()
   62.43 @@ -188,7 +189,8 @@
   62.44    fold (fn (_, active) => fn i => if active then i + 1 else i) (! workers) 0;
   62.45  
   62.46  fun change_active active = (*requires SYNCHRONIZED*)
   62.47 -  change workers (AList.update Thread.equal (Thread.self (), active));
   62.48 +  Unsynchronized.change workers
   62.49 +    (AList.update Thread.equal (Thread.self (), active));
   62.50  
   62.51  
   62.52  (* worker threads *)
   62.53 @@ -198,14 +200,15 @@
   62.54  
   62.55  fun worker_next () = (*requires SYNCHRONIZED*)
   62.56    if ! excessive > 0 then
   62.57 -    (dec excessive;
   62.58 -     change workers (filter_out (fn (thread, _) => Thread.equal (thread, Thread.self ())));
   62.59 +    (Unsynchronized.dec excessive;
   62.60 +     Unsynchronized.change workers
   62.61 +      (filter_out (fn (thread, _) => Thread.equal (thread, Thread.self ())));
   62.62       broadcast scheduler_event;
   62.63       NONE)
   62.64    else if count_active () > Multithreading.max_threads_value () then
   62.65      (worker_wait scheduler_event; worker_next ())
   62.66    else
   62.67 -    (case change_result queue (Task_Queue.dequeue (Thread.self ())) of
   62.68 +    (case Unsynchronized.change_result queue (Task_Queue.dequeue (Thread.self ())) of
   62.69        NONE => (worker_wait work_available; worker_next ())
   62.70      | some => some);
   62.71  
   62.72 @@ -215,13 +218,13 @@
   62.73    | SOME work => (execute name work; worker_loop name));
   62.74  
   62.75  fun worker_start name = (*requires SYNCHRONIZED*)
   62.76 -  change workers (cons (SimpleThread.fork false (fn () =>
   62.77 +  Unsynchronized.change workers (cons (SimpleThread.fork false (fn () =>
   62.78       (broadcast scheduler_event; worker_loop name)), true));
   62.79  
   62.80  
   62.81  (* scheduler *)
   62.82  
   62.83 -val last_status = ref Time.zeroTime;
   62.84 +val last_status = Unsynchronized.ref Time.zeroTime;
   62.85  val next_status = Time.fromMilliseconds 500;
   62.86  val next_round = Time.fromMilliseconds 50;
   62.87  
   62.88 @@ -263,7 +266,8 @@
   62.89      val _ = excessive := l - mm;
   62.90      val _ =
   62.91        if mm > l then
   62.92 -        funpow (mm - l) (fn () => worker_start ("worker " ^ string_of_int (inc next))) ()
   62.93 +        funpow (mm - l) (fn () =>
   62.94 +          worker_start ("worker " ^ string_of_int (Unsynchronized.inc next))) ()
   62.95        else ();
   62.96  
   62.97      (*canceled groups*)
   62.98 @@ -272,7 +276,7 @@
   62.99        else
  62.100         (Multithreading.tracing 1 (fn () =>
  62.101            string_of_int (length (! canceled)) ^ " canceled groups");
  62.102 -        change canceled (filter_out (Task_Queue.cancel (! queue)));
  62.103 +        Unsynchronized.change canceled (filter_out (Task_Queue.cancel (! queue)));
  62.104          broadcast_work ());
  62.105  
  62.106      (*delay loop*)
  62.107 @@ -317,7 +321,8 @@
  62.108      val (result, job) = future_job group e;
  62.109      val task = SYNCHRONIZED "enqueue" (fn () =>
  62.110        let
  62.111 -        val (task, minimal) = change_result queue (Task_Queue.enqueue group deps pri job);
  62.112 +        val (task, minimal) =
  62.113 +          Unsynchronized.change_result queue (Task_Queue.enqueue group deps pri job);
  62.114          val _ = if minimal then signal work_available else ();
  62.115          val _ = scheduler_check ();
  62.116        in task end);
  62.117 @@ -347,7 +352,7 @@
  62.118  fun join_next deps = (*requires SYNCHRONIZED*)
  62.119    if null deps then NONE
  62.120    else
  62.121 -    (case change_result queue (Task_Queue.dequeue_towards (Thread.self ()) deps) of
  62.122 +    (case Unsynchronized.change_result queue (Task_Queue.dequeue_towards (Thread.self ()) deps) of
  62.123        (NONE, []) => NONE
  62.124      | (NONE, deps') => (worker_wait work_finished; join_next deps')
  62.125      | (SOME work, deps') => SOME (work, deps'));
    63.1 --- a/src/Pure/Concurrent/synchronized.ML	Tue Sep 29 14:26:33 2009 +1000
    63.2 +++ b/src/Pure/Concurrent/synchronized.ML	Tue Sep 29 18:14:08 2009 +0200
    63.3 @@ -24,13 +24,13 @@
    63.4   {name: string,
    63.5    lock: Mutex.mutex,
    63.6    cond: ConditionVar.conditionVar,
    63.7 -  var: 'a ref};
    63.8 +  var: 'a Unsynchronized.ref};
    63.9  
   63.10  fun var name x = Var
   63.11   {name = name,
   63.12    lock = Mutex.mutex (),
   63.13    cond = ConditionVar.conditionVar (),
   63.14 -  var = ref x};
   63.15 +  var = Unsynchronized.ref x};
   63.16  
   63.17  fun value (Var {var, ...}) = ! var;
   63.18  
    64.1 --- a/src/Pure/Concurrent/synchronized_dummy.ML	Tue Sep 29 14:26:33 2009 +1000
    64.2 +++ b/src/Pure/Concurrent/synchronized_dummy.ML	Tue Sep 29 18:14:08 2009 +0200
    64.3 @@ -7,9 +7,9 @@
    64.4  structure Synchronized: SYNCHRONIZED =
    64.5  struct
    64.6  
    64.7 -datatype 'a var = Var of 'a ref;
    64.8 +datatype 'a var = Var of 'a Unsynchronized.ref;
    64.9  
   64.10 -fun var _ x = Var (ref x);
   64.11 +fun var _ x = Var (Unsynchronized.ref x);
   64.12  fun value (Var var) = ! var;
   64.13  
   64.14  fun timed_access (Var var) _ f =
    65.1 --- a/src/Pure/General/file.ML	Tue Sep 29 14:26:33 2009 +1000
    65.2 +++ b/src/Pure/General/file.ML	Tue Sep 29 18:14:08 2009 +0200
    65.3 @@ -85,7 +85,8 @@
    65.4  (* file identification *)
    65.5  
    65.6  local
    65.7 -  val ident_cache = ref (Symtab.empty: {time_stamp: string, id: string} Symtab.table);
    65.8 +  val ident_cache =
    65.9 +    Unsynchronized.ref (Symtab.empty: {time_stamp: string, id: string} Symtab.table);
   65.10  in
   65.11  
   65.12  fun check_cache (path, time) = CRITICAL (fn () =>
   65.13 @@ -94,7 +95,8 @@
   65.14    | SOME {time_stamp, id} => if time_stamp = time then SOME id else NONE));
   65.15  
   65.16  fun update_cache (path, (time, id)) = CRITICAL (fn () =>
   65.17 -  change ident_cache (Symtab.update (path, {time_stamp = time, id = id})));
   65.18 +  Unsynchronized.change ident_cache
   65.19 +    (Symtab.update (path, {time_stamp = time, id = id})));
   65.20  
   65.21  end;
   65.22  
    66.1 --- a/src/Pure/General/lazy.ML	Tue Sep 29 14:26:33 2009 +1000
    66.2 +++ b/src/Pure/General/lazy.ML	Tue Sep 29 18:14:08 2009 +0200
    66.3 @@ -26,12 +26,12 @@
    66.4    Lazy of unit -> 'a |
    66.5    Result of 'a Exn.result;
    66.6  
    66.7 -type 'a lazy = 'a T ref;
    66.8 +type 'a lazy = 'a T Unsynchronized.ref;
    66.9  
   66.10  fun same (r1: 'a lazy, r2) = r1 = r2;
   66.11  
   66.12 -fun lazy e = ref (Lazy e);
   66.13 -fun value x = ref (Result (Exn.Result x));
   66.14 +fun lazy e = Unsynchronized.ref (Lazy e);
   66.15 +fun value x = Unsynchronized.ref (Result (Exn.Result x));
   66.16  
   66.17  fun peek r =
   66.18    (case ! r of
    67.1 --- a/src/Pure/General/markup.ML	Tue Sep 29 14:26:33 2009 +1000
    67.2 +++ b/src/Pure/General/markup.ML	Tue Sep 29 18:14:08 2009 +0200
    67.3 @@ -323,10 +323,10 @@
    67.4  
    67.5  local
    67.6    val default = {output = default_output};
    67.7 -  val modes = ref (Symtab.make [("", default)]);
    67.8 +  val modes = Unsynchronized.ref (Symtab.make [("", default)]);
    67.9  in
   67.10    fun add_mode name output = CRITICAL (fn () =>
   67.11 -    change modes (Symtab.update_new (name, {output = output})));
   67.12 +    Unsynchronized.change modes (Symtab.update_new (name, {output = output})));
   67.13    fun get_mode () =
   67.14      the_default default (Library.get_first (Symtab.lookup (! modes)) (print_mode_value ()));
   67.15  end;
    68.1 --- a/src/Pure/General/name_space.ML	Tue Sep 29 14:26:33 2009 +1000
    68.2 +++ b/src/Pure/General/name_space.ML	Tue Sep 29 18:14:08 2009 +0200
    68.3 @@ -9,9 +9,9 @@
    68.4  
    68.5  signature BASIC_NAME_SPACE =
    68.6  sig
    68.7 -  val long_names: bool ref
    68.8 -  val short_names: bool ref
    68.9 -  val unique_names: bool ref
   68.10 +  val long_names: bool Unsynchronized.ref
   68.11 +  val short_names: bool Unsynchronized.ref
   68.12 +  val unique_names: bool Unsynchronized.ref
   68.13  end;
   68.14  
   68.15  signature NAME_SPACE =
   68.16 @@ -105,9 +105,9 @@
   68.17      else ext (get_accesses space name)
   68.18    end;
   68.19  
   68.20 -val long_names = ref false;
   68.21 -val short_names = ref false;
   68.22 -val unique_names = ref true;
   68.23 +val long_names = Unsynchronized.ref false;
   68.24 +val short_names = Unsynchronized.ref false;
   68.25 +val unique_names = Unsynchronized.ref true;
   68.26  
   68.27  fun extern space name =
   68.28    extern_flags
   68.29 @@ -261,6 +261,6 @@
   68.30  
   68.31  end;
   68.32  
   68.33 -structure BasicNameSpace: BASIC_NAME_SPACE = NameSpace;
   68.34 -open BasicNameSpace;
   68.35 +structure Basic_Name_Space: BASIC_NAME_SPACE = NameSpace;
   68.36 +open Basic_Name_Space;
   68.37  
    69.1 --- a/src/Pure/General/output.ML	Tue Sep 29 14:26:33 2009 +1000
    69.2 +++ b/src/Pure/General/output.ML	Tue Sep 29 18:14:08 2009 +0200
    69.3 @@ -11,13 +11,13 @@
    69.4    val priority: string -> unit
    69.5    val tracing: string -> unit
    69.6    val warning: string -> unit
    69.7 -  val tolerate_legacy_features: bool ref
    69.8 +  val tolerate_legacy_features: bool Unsynchronized.ref
    69.9    val legacy_feature: string -> unit
   69.10    val cond_timeit: bool -> string -> (unit -> 'a) -> 'a
   69.11    val timeit: (unit -> 'a) -> 'a
   69.12    val timeap: ('a -> 'b) -> 'a -> 'b
   69.13    val timeap_msg: string -> ('a -> 'b) -> 'a -> 'b
   69.14 -  val timing: bool ref
   69.15 +  val timing: bool Unsynchronized.ref
   69.16  end;
   69.17  
   69.18  signature OUTPUT =
   69.19 @@ -32,18 +32,18 @@
   69.20    val std_output: output -> unit
   69.21    val std_error: output -> unit
   69.22    val writeln_default: output -> unit
   69.23 -  val writeln_fn: (output -> unit) ref
   69.24 -  val priority_fn: (output -> unit) ref
   69.25 -  val tracing_fn: (output -> unit) ref
   69.26 -  val warning_fn: (output -> unit) ref
   69.27 -  val error_fn: (output -> unit) ref
   69.28 -  val debug_fn: (output -> unit) ref
   69.29 -  val prompt_fn: (output -> unit) ref
   69.30 -  val status_fn: (output -> unit) ref
   69.31 +  val writeln_fn: (output -> unit) Unsynchronized.ref
   69.32 +  val priority_fn: (output -> unit) Unsynchronized.ref
   69.33 +  val tracing_fn: (output -> unit) Unsynchronized.ref
   69.34 +  val warning_fn: (output -> unit) Unsynchronized.ref
   69.35 +  val error_fn: (output -> unit) Unsynchronized.ref
   69.36 +  val debug_fn: (output -> unit) Unsynchronized.ref
   69.37 +  val prompt_fn: (output -> unit) Unsynchronized.ref
   69.38 +  val status_fn: (output -> unit) Unsynchronized.ref
   69.39    val error_msg: string -> unit
   69.40    val prompt: string -> unit
   69.41    val status: string -> unit
   69.42 -  val debugging: bool ref
   69.43 +  val debugging: bool Unsynchronized.ref
   69.44    val no_warnings: ('a -> 'b) -> 'a -> 'b
   69.45    val debug: (unit -> string) -> unit
   69.46  end;
   69.47 @@ -60,10 +60,10 @@
   69.48  
   69.49  local
   69.50    val default = {output = default_output, escape = default_escape};
   69.51 -  val modes = ref (Symtab.make [("", default)]);
   69.52 +  val modes = Unsynchronized.ref (Symtab.make [("", default)]);
   69.53  in
   69.54    fun add_mode name output escape = CRITICAL (fn () =>
   69.55 -    change modes (Symtab.update_new (name, {output = output, escape = escape})));
   69.56 +    Unsynchronized.change modes (Symtab.update_new (name, {output = output, escape = escape})));
   69.57    fun get_mode () =
   69.58      the_default default (Library.get_first (Symtab.lookup (! modes)) (print_mode_value ()));
   69.59  end;
   69.60 @@ -91,14 +91,14 @@
   69.61  
   69.62  (* Isabelle output channels *)
   69.63  
   69.64 -val writeln_fn = ref writeln_default;
   69.65 -val priority_fn = ref (fn s => ! writeln_fn s);
   69.66 -val tracing_fn = ref (fn s => ! writeln_fn s);
   69.67 -val warning_fn = ref (std_output o suffix "\n" o prefix_lines "### ");
   69.68 -val error_fn = ref (std_output o suffix "\n" o prefix_lines "*** ");
   69.69 -val debug_fn = ref (std_output o suffix "\n" o prefix_lines "::: ");
   69.70 -val prompt_fn = ref std_output;
   69.71 -val status_fn = ref (fn _: string => ());
   69.72 +val writeln_fn = Unsynchronized.ref writeln_default;
   69.73 +val priority_fn = Unsynchronized.ref (fn s => ! writeln_fn s);
   69.74 +val tracing_fn = Unsynchronized.ref (fn s => ! writeln_fn s);
   69.75 +val warning_fn = Unsynchronized.ref (std_output o suffix "\n" o prefix_lines "### ");
   69.76 +val error_fn = Unsynchronized.ref (std_output o suffix "\n" o prefix_lines "*** ");
   69.77 +val debug_fn = Unsynchronized.ref (std_output o suffix "\n" o prefix_lines "::: ");
   69.78 +val prompt_fn = Unsynchronized.ref std_output;
   69.79 +val status_fn = Unsynchronized.ref (fn _: string => ());
   69.80  
   69.81  fun writeln s = ! writeln_fn (output s);
   69.82  fun priority s = ! priority_fn (output s);
   69.83 @@ -108,13 +108,13 @@
   69.84  fun prompt s = ! prompt_fn (output s);
   69.85  fun status s = ! status_fn (output s);
   69.86  
   69.87 -val tolerate_legacy_features = ref true;
   69.88 +val tolerate_legacy_features = Unsynchronized.ref true;
   69.89  fun legacy_feature s =
   69.90    (if ! tolerate_legacy_features then warning else error) ("Legacy feature! " ^ s);
   69.91  
   69.92  fun no_warnings f = setmp warning_fn (K ()) f;
   69.93  
   69.94 -val debugging = ref false;
   69.95 +val debugging = Unsynchronized.ref false;
   69.96  fun debug s = if ! debugging then ! debug_fn (output (s ())) else ()
   69.97  
   69.98  
   69.99 @@ -140,9 +140,9 @@
  69.100  fun timeap_msg msg f x = cond_timeit true msg (fn () => f x);
  69.101  
  69.102  (*global timing mode*)
  69.103 -val timing = ref false;
  69.104 +val timing = Unsynchronized.ref false;
  69.105  
  69.106  end;
  69.107  
  69.108 -structure BasicOutput: BASIC_OUTPUT = Output;
  69.109 -open BasicOutput;
  69.110 +structure Basic_Output: BASIC_OUTPUT = Output;
  69.111 +open Basic_Output;
    70.1 --- a/src/Pure/General/pretty.ML	Tue Sep 29 14:26:33 2009 +1000
    70.2 +++ b/src/Pure/General/pretty.ML	Tue Sep 29 18:14:08 2009 +0200
    70.3 @@ -86,10 +86,10 @@
    70.4  
    70.5  local
    70.6    val default = {indent = default_indent};
    70.7 -  val modes = ref (Symtab.make [("", default)]);
    70.8 +  val modes = Unsynchronized.ref (Symtab.make [("", default)]);
    70.9  in
   70.10    fun add_mode name indent = CRITICAL (fn () =>
   70.11 -    change modes (Symtab.update_new (name, {indent = indent})));
   70.12 +    Unsynchronized.change modes (Symtab.update_new (name, {indent = indent})));
   70.13    fun get_mode () =
   70.14      the_default default (Library.get_first (Symtab.lookup (! modes)) (print_mode_value ()));
   70.15  end;
   70.16 @@ -186,14 +186,14 @@
   70.17    breakgain = m div 20,         (*minimum added space required of a break*)
   70.18    emergencypos = m div 2};      (*position too far to right*)
   70.19  
   70.20 -val margin_info = ref (make_margin_info 76);
   70.21 +val margin_info = Unsynchronized.ref (make_margin_info 76);
   70.22  fun setmargin m = margin_info := make_margin_info m;
   70.23  fun setmp_margin m f = setmp margin_info (make_margin_info m) f;
   70.24  
   70.25  
   70.26  (* depth limitation *)
   70.27  
   70.28 -val depth = ref 0;   (*maximum depth; 0 means no limit*)
   70.29 +val depth = Unsynchronized.ref 0;   (*maximum depth; 0 means no limit*)
   70.30  fun setdepth dp = (depth := dp);
   70.31  
   70.32  local
    71.1 --- a/src/Pure/General/print_mode.ML	Tue Sep 29 14:26:33 2009 +1000
    71.2 +++ b/src/Pure/General/print_mode.ML	Tue Sep 29 18:14:08 2009 +0200
    71.3 @@ -7,9 +7,9 @@
    71.4  
    71.5  signature BASIC_PRINT_MODE =
    71.6  sig
    71.7 -  val print_mode: string list ref            (*global template*)
    71.8 -  val print_mode_value: unit -> string list  (*thread-local value*)
    71.9 -  val print_mode_active: string -> bool      (*thread-local value*)
   71.10 +  val print_mode: string list Unsynchronized.ref  (*global template*)
   71.11 +  val print_mode_value: unit -> string list       (*thread-local value*)
   71.12 +  val print_mode_active: string -> bool           (*thread-local value*)
   71.13  end;
   71.14  
   71.15  signature PRINT_MODE =
   71.16 @@ -28,7 +28,7 @@
   71.17  val input = "input";
   71.18  val internal = "internal";
   71.19  
   71.20 -val print_mode = ref ([]: string list);
   71.21 +val print_mode = Unsynchronized.ref ([]: string list);
   71.22  val tag = Universal.tag () : string list option Universal.tag;
   71.23  
   71.24  fun print_mode_value () =
    72.1 --- a/src/Pure/General/secure.ML	Tue Sep 29 14:26:33 2009 +1000
    72.2 +++ b/src/Pure/General/secure.ML	Tue Sep 29 18:14:08 2009 +0200
    72.3 @@ -13,6 +13,7 @@
    72.4    val use_text: use_context -> int * string -> bool -> string -> unit
    72.5    val use_file: use_context -> bool -> string -> unit
    72.6    val toplevel_pp: string list -> string -> unit
    72.7 +  val open_unsynchronized: unit -> unit
    72.8    val commit: unit -> unit
    72.9    val system_out: string -> string * int
   72.10    val system: string -> int
   72.11 @@ -23,7 +24,7 @@
   72.12  
   72.13  (** secure flag **)
   72.14  
   72.15 -val secure = ref false;
   72.16 +val secure = Unsynchronized.ref false;
   72.17  
   72.18  fun set_secure () = secure := true;
   72.19  fun is_secure () = ! secure;
   72.20 @@ -47,8 +48,13 @@
   72.21  
   72.22  fun toplevel_pp path pp = (secure_mltext (); raw_toplevel_pp ML_Parse.global_context path pp);
   72.23  
   72.24 -(*commit is dynamically bound!*)
   72.25 -fun commit () = raw_use_text ML_Parse.global_context (0, "") false "commit();";
   72.26 +
   72.27 +(* global evaluation *)
   72.28 +
   72.29 +val use_global = raw_use_text ML_Parse.global_context (0, "") false;
   72.30 +
   72.31 +fun commit () = use_global "commit();";   (*commit is dynamically bound!*)
   72.32 +fun open_unsynchronized () = use_global "open Unsynchronized";
   72.33  
   72.34  
   72.35  (* shell commands *)
    73.1 --- a/src/Pure/IsaMakefile	Tue Sep 29 14:26:33 2009 +1000
    73.2 +++ b/src/Pure/IsaMakefile	Tue Sep 29 18:14:08 2009 +0200
    73.3 @@ -32,7 +32,7 @@
    73.4    ML-Systems/pp_polyml.ML ML-Systems/proper_int.ML ML-Systems/smlnj.ML	\
    73.5    ML-Systems/system_shell.ML ML-Systems/thread_dummy.ML			\
    73.6    ML-Systems/timing.ML ML-Systems/time_limit.ML				\
    73.7 -  ML-Systems/universal.ML
    73.8 +  ML-Systems/universal.ML ML-Systems/unsynchronized.ML
    73.9  
   73.10  RAW: $(OUT)/RAW
   73.11  
    74.1 --- a/src/Pure/Isar/code.ML	Tue Sep 29 14:26:33 2009 +1000
    74.2 +++ b/src/Pure/Isar/code.ML	Tue Sep 29 18:14:08 2009 +0200
    74.3 @@ -217,8 +217,8 @@
    74.4    purge: theory -> string list -> Object.T -> Object.T
    74.5  };
    74.6  
    74.7 -val kinds = ref (Datatab.empty: kind Datatab.table);
    74.8 -val kind_keys = ref ([]: serial list);
    74.9 +val kinds = Unsynchronized.ref (Datatab.empty: kind Datatab.table);
   74.10 +val kind_keys = Unsynchronized.ref ([]: serial list);
   74.11  
   74.12  fun invoke f k = case Datatab.lookup (! kinds) k
   74.13   of SOME kind => f kind
   74.14 @@ -230,8 +230,8 @@
   74.15    let
   74.16      val k = serial ();
   74.17      val kind = {empty = empty, purge = purge};
   74.18 -    val _ = change kinds (Datatab.update (k, kind));
   74.19 -    val _ = change kind_keys (cons k);
   74.20 +    val _ = Unsynchronized.change kinds (Datatab.update (k, kind));
   74.21 +    val _ = Unsynchronized.change kind_keys (cons k);
   74.22    in k end;
   74.23  
   74.24  fun invoke_init k = invoke (fn kind => #empty kind) k;
   74.25 @@ -252,13 +252,13 @@
   74.26  
   74.27  structure Code_Data = TheoryDataFun
   74.28  (
   74.29 -  type T = spec * data ref;
   74.30 +  type T = spec * data Unsynchronized.ref;
   74.31    val empty = (make_spec (false,
   74.32 -    (Symtab.empty, (Symtab.empty, (Symtab.empty, Symtab.empty)))), ref empty_data);
   74.33 -  fun copy (spec, data) = (spec, ref (! data));
   74.34 +    (Symtab.empty, (Symtab.empty, (Symtab.empty, Symtab.empty)))), Unsynchronized.ref empty_data);
   74.35 +  fun copy (spec, data) = (spec, Unsynchronized.ref (! data));
   74.36    val extend = copy;
   74.37    fun merge pp ((spec1, data1), (spec2, data2)) =
   74.38 -    (merge_spec (spec1, spec2), ref empty_data);
   74.39 +    (merge_spec (spec1, spec2), Unsynchronized.ref empty_data);
   74.40  );
   74.41  
   74.42  fun thy_data f thy = f ((snd o Code_Data.get) thy);
   74.43 @@ -267,7 +267,7 @@
   74.44    case Datatab.lookup (! data_ref) kind
   74.45     of SOME x => x
   74.46      | NONE => let val y = invoke_init kind
   74.47 -        in (change data_ref (Datatab.update (kind, y)); y) end;
   74.48 +        in (Unsynchronized.change data_ref (Datatab.update (kind, y)); y) end;
   74.49  
   74.50  in
   74.51  
   74.52 @@ -281,11 +281,11 @@
   74.53      | SOME (c', _) => insert (op =) c' #> insert (op =) c) cs [];
   74.54  
   74.55  fun map_exec_purge touched f thy =
   74.56 -  Code_Data.map (fn (exec, data) => (f exec, ref (case touched
   74.57 +  Code_Data.map (fn (exec, data) => (f exec, Unsynchronized.ref (case touched
   74.58     of SOME cs => invoke_purge_all thy (complete_class_params thy cs) (! data)
   74.59      | NONE => empty_data))) thy;
   74.60  
   74.61 -val purge_data = (Code_Data.map o apsnd) (K (ref empty_data));
   74.62 +val purge_data = (Code_Data.map o apsnd) (K (Unsynchronized.ref empty_data));
   74.63  
   74.64  fun change_eqns delete c f = (map_exec_purge (SOME [c]) o map_eqns
   74.65    o (if delete then Symtab.map_entry c else Symtab.map_default (c, ((false, (true, Lazy.value [])), [])))
   74.66 @@ -332,7 +332,7 @@
   74.67        let
   74.68          val data = get_ensure_init kind data_ref;
   74.69          val data' = f (dest data);
   74.70 -      in (change data_ref (Datatab.update (kind, mk data')); data') end;
   74.71 +      in (Unsynchronized.change data_ref (Datatab.update (kind, mk data')); data') end;
   74.72    in thy_data chnge end;
   74.73  
   74.74  fun change_yield_data (kind, mk, dest) =
   74.75 @@ -341,7 +341,7 @@
   74.76        let
   74.77          val data = get_ensure_init kind data_ref;
   74.78          val (x, data') = f (dest data);
   74.79 -      in (x, (change data_ref (Datatab.update (kind, mk data')); data')) end;
   74.80 +      in (x, (Unsynchronized.change data_ref (Datatab.update (kind, mk data')); data')) end;
   74.81    in thy_data chnge end;
   74.82  
   74.83  end; (*local*)
    75.1 --- a/src/Pure/Isar/isar_document.ML	Tue Sep 29 14:26:33 2009 +1000
    75.2 +++ b/src/Pure/Isar/isar_document.ML	Tue Sep 29 18:14:08 2009 +0200
    75.3 @@ -112,18 +112,18 @@
    75.4  (** global configuration **)
    75.5  
    75.6  local
    75.7 -  val global_states = ref (Symtab.empty: Toplevel.state option future Symtab.table);
    75.8 -  val global_commands = ref (Symtab.empty: Toplevel.transition Symtab.table);
    75.9 -  val global_documents = ref (Symtab.empty: document Symtab.table);
   75.10 +  val global_states = Unsynchronized.ref (Symtab.empty: Toplevel.state option future Symtab.table);
   75.11 +  val global_commands = Unsynchronized.ref (Symtab.empty: Toplevel.transition Symtab.table);
   75.12 +  val global_documents = Unsynchronized.ref (Symtab.empty: document Symtab.table);
   75.13  in
   75.14  
   75.15 -fun change_states f = NAMED_CRITICAL "Isar" (fn () => change global_states f);
   75.16 +fun change_states f = NAMED_CRITICAL "Isar" (fn () => Unsynchronized.change global_states f);
   75.17  fun get_states () = NAMED_CRITICAL "Isar" (fn () => ! global_states);
   75.18  
   75.19 -fun change_commands f = NAMED_CRITICAL "Isar" (fn () => change global_commands f);
   75.20 +fun change_commands f = NAMED_CRITICAL "Isar" (fn () => Unsynchronized.change global_commands f);
   75.21  fun get_commands () = NAMED_CRITICAL "Isar" (fn () => ! global_commands);
   75.22  
   75.23 -fun change_documents f = NAMED_CRITICAL "Isar" (fn () => change global_documents f);
   75.24 +fun change_documents f = NAMED_CRITICAL "Isar" (fn () => Unsynchronized.change global_documents f);
   75.25  fun get_documents () = NAMED_CRITICAL "Isar" (fn () => ! global_documents);
   75.26  
   75.27  fun init () = NAMED_CRITICAL "Isar" (fn () =>
    76.1 --- a/src/Pure/Isar/local_syntax.ML	Tue Sep 29 14:26:33 2009 +1000
    76.2 +++ b/src/Pure/Isar/local_syntax.ML	Tue Sep 29 18:14:08 2009 +0200
    76.3 @@ -4,7 +4,7 @@
    76.4  Local syntax depending on theory syntax.
    76.5  *)
    76.6  
    76.7 -val show_structs = ref false;
    76.8 +val show_structs = Unsynchronized.ref false;
    76.9  
   76.10  signature LOCAL_SYNTAX =
   76.11  sig
    77.1 --- a/src/Pure/Isar/method.ML	Tue Sep 29 14:26:33 2009 +1000
    77.2 +++ b/src/Pure/Isar/method.ML	Tue Sep 29 18:14:08 2009 +0200
    77.3 @@ -8,7 +8,7 @@
    77.4  sig
    77.5    val FINDGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq
    77.6    val HEADGOAL: (int -> thm -> 'a Seq.seq) -> thm -> 'a Seq.seq
    77.7 -  val trace_rules: bool ref
    77.8 +  val trace_rules: bool Unsynchronized.ref
    77.9  end;
   77.10  
   77.11  signature METHOD =
   77.12 @@ -215,7 +215,7 @@
   77.13  
   77.14  (* rule etc. -- single-step refinements *)
   77.15  
   77.16 -val trace_rules = ref false;
   77.17 +val trace_rules = Unsynchronized.ref false;
   77.18  
   77.19  fun trace ctxt rules =
   77.20    if ! trace_rules andalso not (null rules) then
    78.1 --- a/src/Pure/Isar/outer_keyword.ML	Tue Sep 29 14:26:33 2009 +1000
    78.2 +++ b/src/Pure/Isar/outer_keyword.ML	Tue Sep 29 18:14:08 2009 +0200
    78.3 @@ -116,16 +116,16 @@
    78.4  
    78.5  local
    78.6  
    78.7 -val global_commands = ref (Symtab.empty: T Symtab.table);
    78.8 -val global_lexicons = ref (Scan.empty_lexicon, Scan.empty_lexicon);
    78.9 +val global_commands = Unsynchronized.ref (Symtab.empty: T Symtab.table);
   78.10 +val global_lexicons = Unsynchronized.ref (Scan.empty_lexicon, Scan.empty_lexicon);
   78.11  
   78.12  in
   78.13  
   78.14  fun get_commands () = CRITICAL (fn () => ! global_commands);
   78.15  fun get_lexicons () = CRITICAL (fn () => ! global_lexicons);
   78.16  
   78.17 -fun change_commands f = CRITICAL (fn () => change global_commands f);
   78.18 -fun change_lexicons f = CRITICAL (fn () => change global_lexicons f);
   78.19 +fun change_commands f = CRITICAL (fn () => Unsynchronized.change global_commands f);
   78.20 +fun change_lexicons f = CRITICAL (fn () => Unsynchronized.change global_lexicons f);
   78.21  
   78.22  end;
   78.23  
    79.1 --- a/src/Pure/Isar/outer_lex.ML	Tue Sep 29 14:26:33 2009 +1000
    79.2 +++ b/src/Pure/Isar/outer_lex.ML	Tue Sep 29 18:14:08 2009 +0200
    79.3 @@ -83,7 +83,7 @@
    79.4  datatype slot =
    79.5    Slot |
    79.6    Value of value option |
    79.7 -  Assignable of value option ref;
    79.8 +  Assignable of value option Unsynchronized.ref;
    79.9  
   79.10  
   79.11  (* datatype token *)
   79.12 @@ -245,7 +245,7 @@
   79.13  (* static binding *)
   79.14  
   79.15  (*1st stage: make empty slots assignable*)
   79.16 -fun assignable (Token (x, y, Slot)) = Token (x, y, Assignable (ref NONE))
   79.17 +fun assignable (Token (x, y, Slot)) = Token (x, y, Assignable (Unsynchronized.ref NONE))
   79.18    | assignable tok = tok;
   79.19  
   79.20  (*2nd stage: assign values as side-effect of scanning*)
   79.21 @@ -253,7 +253,7 @@
   79.22    | assign _ _ = ();
   79.23  
   79.24  (*3rd stage: static closure of final values*)
   79.25 -fun closure (Token (x, y, Assignable (ref v))) = Token (x, y, Value v)
   79.26 +fun closure (Token (x, y, Assignable (Unsynchronized.ref v))) = Token (x, y, Value v)
   79.27    | closure tok = tok;
   79.28  
   79.29  
    80.1 --- a/src/Pure/Isar/outer_syntax.ML	Tue Sep 29 14:26:33 2009 +1000
    80.2 +++ b/src/Pure/Isar/outer_syntax.ML	Tue Sep 29 18:14:08 2009 +0200
    80.3 @@ -88,11 +88,11 @@
    80.4  
    80.5  local
    80.6  
    80.7 -val global_commands = ref (Symtab.empty: command Symtab.table);
    80.8 -val global_markups = ref ([]: (string * ThyOutput.markup) list);
    80.9 +val global_commands = Unsynchronized.ref (Symtab.empty: command Symtab.table);
   80.10 +val global_markups = Unsynchronized.ref ([]: (string * ThyOutput.markup) list);
   80.11  
   80.12  fun change_commands f = CRITICAL (fn () =>
   80.13 - (change global_commands f;
   80.14 + (Unsynchronized.change global_commands f;
   80.15    global_markups :=
   80.16      Symtab.fold (fn (name, Command {markup = SOME m, ...}) => cons (name, m) | _ => I)
   80.17        (! global_commands) []));
    81.1 --- a/src/Pure/Isar/proof.ML	Tue Sep 29 14:26:33 2009 +1000
    81.2 +++ b/src/Pure/Isar/proof.ML	Tue Sep 29 18:14:08 2009 +0200
    81.3 @@ -30,8 +30,8 @@
    81.4    val enter_forward: state -> state
    81.5    val goal_message: (unit -> Pretty.T) -> state -> state
    81.6    val get_goal: state -> context * (thm list * thm)
    81.7 -  val show_main_goal: bool ref
    81.8 -  val verbose: bool ref
    81.9 +  val show_main_goal: bool Unsynchronized.ref
   81.10 +  val verbose: bool Unsynchronized.ref
   81.11    val pretty_state: int -> state -> Pretty.T list
   81.12    val pretty_goals: bool -> state -> Pretty.T list
   81.13    val refine: Method.text -> state -> state Seq.seq
   81.14 @@ -315,7 +315,7 @@
   81.15  
   81.16  (** pretty_state **)
   81.17  
   81.18 -val show_main_goal = ref false;
   81.19 +val show_main_goal = Unsynchronized.ref false;
   81.20  val verbose = ProofContext.verbose;
   81.21  
   81.22  fun pretty_facts _ _ NONE = []
   81.23 @@ -930,8 +930,8 @@
   81.24  
   81.25  fun gen_show prep_att prepp before_qed after_qed stmt int state =
   81.26    let
   81.27 -    val testing = ref false;
   81.28 -    val rule = ref (NONE: thm option);
   81.29 +    val testing = Unsynchronized.ref false;
   81.30 +    val rule = Unsynchronized.ref (NONE: thm option);
   81.31      fun fail_msg ctxt =
   81.32        "Local statement will fail to refine any pending goal" ::
   81.33        (case ! rule of NONE => [] | SOME th => [ProofDisplay.string_of_rule ctxt "Failed" th])
    82.1 --- a/src/Pure/Isar/proof_context.ML	Tue Sep 29 14:26:33 2009 +1000
    82.2 +++ b/src/Pure/Isar/proof_context.ML	Tue Sep 29 18:14:08 2009 +0200
    82.3 @@ -123,15 +123,15 @@
    82.4    val add_abbrev: string -> Properties.T ->
    82.5      binding * term -> Proof.context -> (term * term) * Proof.context
    82.6    val revert_abbrev: string -> string -> Proof.context -> Proof.context
    82.7 -  val verbose: bool ref
    82.8 +  val verbose: bool Unsynchronized.ref
    82.9    val setmp_verbose: ('a -> 'b) -> 'a -> 'b
   82.10    val print_syntax: Proof.context -> unit
   82.11    val print_abbrevs: Proof.context -> unit
   82.12    val print_binds: Proof.context -> unit
   82.13    val print_lthms: Proof.context -> unit
   82.14    val print_cases: Proof.context -> unit
   82.15 -  val debug: bool ref
   82.16 -  val prems_limit: int ref
   82.17 +  val debug: bool Unsynchronized.ref
   82.18 +  val prems_limit: int Unsynchronized.ref
   82.19    val pretty_ctxt: Proof.context -> Pretty.T list
   82.20    val pretty_context: Proof.context -> Pretty.T list
   82.21    val query_type: Proof.context -> string -> Properties.T
   82.22 @@ -1208,9 +1208,9 @@
   82.23  
   82.24  (** print context information **)
   82.25  
   82.26 -val debug = ref false;
   82.27 +val debug = Unsynchronized.ref false;
   82.28  
   82.29 -val verbose = ref false;
   82.30 +val verbose = Unsynchronized.ref false;
   82.31  fun verb f x = if ! verbose then f (x ()) else [];
   82.32  
   82.33  fun setmp_verbose f x = Library.setmp verbose true f x;
   82.34 @@ -1320,7 +1320,7 @@
   82.35  
   82.36  (* core context *)
   82.37  
   82.38 -val prems_limit = ref ~1;
   82.39 +val prems_limit = Unsynchronized.ref ~1;
   82.40  
   82.41  fun pretty_ctxt ctxt =
   82.42    if ! prems_limit < 0 andalso not (! debug) then []
    83.1 --- a/src/Pure/Isar/toplevel.ML	Tue Sep 29 14:26:33 2009 +1000
    83.2 +++ b/src/Pure/Isar/toplevel.ML	Tue Sep 29 18:14:08 2009 +0200
    83.3 @@ -24,12 +24,12 @@
    83.4    val enter_proof_body: state -> Proof.state
    83.5    val print_state_context: state -> unit
    83.6    val print_state: bool -> state -> unit
    83.7 -  val quiet: bool ref
    83.8 -  val debug: bool ref
    83.9 -  val interact: bool ref
   83.10 -  val timing: bool ref
   83.11 -  val profiling: int ref
   83.12 -  val skip_proofs: bool ref
   83.13 +  val quiet: bool Unsynchronized.ref
   83.14 +  val debug: bool Unsynchronized.ref
   83.15 +  val interact: bool Unsynchronized.ref
   83.16 +  val timing: bool Unsynchronized.ref
   83.17 +  val profiling: int Unsynchronized.ref
   83.18 +  val skip_proofs: bool Unsynchronized.ref
   83.19    exception TERMINATE
   83.20    exception TOPLEVEL_ERROR
   83.21    val program: (unit -> 'a) -> 'a
   83.22 @@ -216,12 +216,12 @@
   83.23  
   83.24  (** toplevel transitions **)
   83.25  
   83.26 -val quiet = ref false;
   83.27 +val quiet = Unsynchronized.ref false;
   83.28  val debug = Output.debugging;
   83.29 -val interact = ref false;
   83.30 +val interact = Unsynchronized.ref false;
   83.31  val timing = Output.timing;
   83.32 -val profiling = ref 0;
   83.33 -val skip_proofs = ref false;
   83.34 +val profiling = Unsynchronized.ref 0;
   83.35 +val skip_proofs = Unsynchronized.ref false;
   83.36  
   83.37  exception TERMINATE = Runtime.TERMINATE;
   83.38  exception EXCURSION_FAIL = Runtime.EXCURSION_FAIL;
   83.39 @@ -550,9 +550,9 @@
   83.40  
   83.41  (* post-transition hooks *)
   83.42  
   83.43 -local val hooks = ref ([]: (transition -> state -> state -> unit) list) in
   83.44 +local val hooks = Unsynchronized.ref ([]: (transition -> state -> state -> unit) list) in
   83.45  
   83.46 -fun add_hook f = CRITICAL (fn () => change hooks (cons f));
   83.47 +fun add_hook f = CRITICAL (fn () => Unsynchronized.change hooks (cons f));
   83.48  fun get_hooks () = CRITICAL (fn () => ! hooks);
   83.49  
   83.50  end;
    84.1 --- a/src/Pure/ML-Systems/compiler_polyml-5.0.ML	Tue Sep 29 14:26:33 2009 +1000
    84.2 +++ b/src/Pure/ML-Systems/compiler_polyml-5.0.ML	Tue Sep 29 18:14:08 2009 +0200
    84.3 @@ -5,11 +5,11 @@
    84.4  
    84.5  fun use_text ({tune_source, print, error, ...}: use_context) (line, name) verbose txt =
    84.6    let
    84.7 -    val in_buffer = ref (explode (tune_source txt));
    84.8 -    val out_buffer = ref ([]: string list);
    84.9 +    val in_buffer = Unsynchronized.ref (explode (tune_source txt));
   84.10 +    val out_buffer = Unsynchronized.ref ([]: string list);
   84.11      fun output () = implode (rev (case ! out_buffer of "\n" :: cs => cs | cs => cs));
   84.12  
   84.13 -    val current_line = ref line;
   84.14 +    val current_line = Unsynchronized.ref line;
   84.15      fun get () =
   84.16        (case ! in_buffer of
   84.17          [] => ""
    85.1 --- a/src/Pure/ML-Systems/compiler_polyml-5.2.ML	Tue Sep 29 14:26:33 2009 +1000
    85.2 +++ b/src/Pure/ML-Systems/compiler_polyml-5.2.ML	Tue Sep 29 18:14:08 2009 +0200
    85.3 @@ -14,9 +14,9 @@
    85.4  fun use_text ({tune_source, name_space, str_of_pos, print, error, ...}: use_context)
    85.5      (start_line, name) verbose txt =
    85.6    let
    85.7 -    val current_line = ref start_line;
    85.8 -    val in_buffer = ref (String.explode (tune_source txt));
    85.9 -    val out_buffer = ref ([]: string list);
   85.10 +    val current_line = Unsynchronized.ref start_line;
   85.11 +    val in_buffer = Unsynchronized.ref (String.explode (tune_source txt));
   85.12 +    val out_buffer = Unsynchronized.ref ([]: string list);
   85.13      fun output () = drop_newline (implode (rev (! out_buffer)));
   85.14  
   85.15      fun get () =
    86.1 --- a/src/Pure/ML-Systems/compiler_polyml-5.3.ML	Tue Sep 29 14:26:33 2009 +1000
    86.2 +++ b/src/Pure/ML-Systems/compiler_polyml-5.3.ML	Tue Sep 29 18:14:08 2009 +0200
    86.3 @@ -14,9 +14,9 @@
    86.4  fun use_text ({tune_source, name_space, str_of_pos, print, error, ...}: use_context)
    86.5      (start_line, name) verbose txt =
    86.6    let
    86.7 -    val line = ref start_line;
    86.8 -    val in_buffer = ref (String.explode (tune_source txt));
    86.9 -    val out_buffer = ref ([]: string list);
   86.10 +    val line = Unsynchronized.ref start_line;
   86.11 +    val in_buffer = Unsynchronized.ref (String.explode (tune_source txt));
   86.12 +    val out_buffer = Unsynchronized.ref ([]: string list);
   86.13      fun output () = drop_newline (implode (rev (! out_buffer)));
   86.14  
   86.15      fun get () =
    87.1 --- a/src/Pure/ML-Systems/mosml.ML	Tue Sep 29 14:26:33 2009 +1000
    87.2 +++ b/src/Pure/ML-Systems/mosml.ML	Tue Sep 29 18:14:08 2009 +0200
    87.3 @@ -41,6 +41,7 @@
    87.4  fun reraise exn = raise exn;
    87.5  
    87.6  use "ML-Systems/exn.ML";
    87.7 +use "ML-Systems/unsynchronized.ML";
    87.8  use "ML-Systems/universal.ML";
    87.9  use "ML-Systems/thread_dummy.ML";
   87.10  use "ML-Systems/multithreading.ML";
    88.1 --- a/src/Pure/ML-Systems/multithreading_polyml.ML	Tue Sep 29 14:26:33 2009 +1000
    88.2 +++ b/src/Pure/ML-Systems/multithreading_polyml.ML	Tue Sep 29 18:14:08 2009 +0200
    88.3 @@ -31,7 +31,7 @@
    88.4  
    88.5  val available = true;
    88.6  
    88.7 -val max_threads = ref 0;
    88.8 +val max_threads = Unsynchronized.ref 0;
    88.9  
   88.10  val tested_platform =
   88.11    let val ml_platform = getenv "ML_PLATFORM"
   88.12 @@ -114,7 +114,7 @@
   88.13  
   88.14  (* tracing *)
   88.15  
   88.16 -val trace = ref 0;
   88.17 +val trace = Unsynchronized.ref 0;
   88.18  
   88.19  fun tracing level msg =
   88.20    if level > ! trace then ()
   88.21 @@ -148,7 +148,7 @@
   88.22  fun timeLimit time f x = uninterruptible (fn restore_attributes => fn () =>
   88.23    let
   88.24      val worker = Thread.self ();
   88.25 -    val timeout = ref false;
   88.26 +    val timeout = Unsynchronized.ref false;
   88.27      val watchdog = Thread.fork (fn () =>
   88.28        (OS.Process.sleep time; timeout := true; Thread.interrupt worker), []);
   88.29  
   88.30 @@ -173,7 +173,7 @@
   88.31  
   88.32      (*result state*)
   88.33      datatype result = Wait | Signal | Result of int;
   88.34 -    val result = ref Wait;
   88.35 +    val result = Unsynchronized.ref Wait;
   88.36      val lock = Mutex.mutex ();
   88.37      val cond = ConditionVar.conditionVar ();
   88.38      fun set_result res =
   88.39 @@ -231,8 +231,8 @@
   88.40  local
   88.41  
   88.42  val critical_lock = Mutex.mutex ();
   88.43 -val critical_thread = ref (NONE: Thread.thread option);
   88.44 -val critical_name = ref "";
   88.45 +val critical_thread = Unsynchronized.ref (NONE: Thread.thread option);
   88.46 +val critical_name = Unsynchronized.ref "";
   88.47  
   88.48  in
   88.49  
   88.50 @@ -274,7 +274,7 @@
   88.51  local
   88.52  
   88.53  val serial_lock = Mutex.mutex ();
   88.54 -val serial_count = ref 0;
   88.55 +val serial_count = Unsynchronized.ref 0;
   88.56  
   88.57  in
   88.58  
    89.1 --- a/src/Pure/ML-Systems/polyml_common.ML	Tue Sep 29 14:26:33 2009 +1000
    89.2 +++ b/src/Pure/ML-Systems/polyml_common.ML	Tue Sep 29 18:14:08 2009 +0200
    89.3 @@ -6,6 +6,7 @@
    89.4  exception Interrupt = SML90.Interrupt;
    89.5  
    89.6  use "ML-Systems/exn.ML";
    89.7 +use "ML-Systems/unsynchronized.ML";
    89.8  use "ML-Systems/multithreading.ML";
    89.9  use "ML-Systems/time_limit.ML";
   89.10  use "ML-Systems/timing.ML";
   89.11 @@ -19,6 +20,8 @@
   89.12  val forget_structure = PolyML.Compiler.forgetStructure;
   89.13  
   89.14  val _ = PolyML.Compiler.forgetValue "print";
   89.15 +val _ = PolyML.Compiler.forgetValue "ref";
   89.16 +val _ = PolyML.Compiler.forgetType "ref";
   89.17  
   89.18  
   89.19  (* Compiler options *)
   89.20 @@ -50,7 +53,7 @@
   89.21  (* print depth *)
   89.22  
   89.23  local
   89.24 -  val depth = ref 10;
   89.25 +  val depth = Unsynchronized.ref 10;
   89.26  in
   89.27    fun get_print_depth () = ! depth;
   89.28    fun print_depth n = (depth := n; PolyML.print_depth n);
    90.1 --- a/src/Pure/ML-Systems/smlnj.ML	Tue Sep 29 14:26:33 2009 +1000
    90.2 +++ b/src/Pure/ML-Systems/smlnj.ML	Tue Sep 29 18:14:08 2009 +0200
    90.3 @@ -9,6 +9,7 @@
    90.4  use "ML-Systems/proper_int.ML";
    90.5  use "ML-Systems/overloading_smlnj.ML";
    90.6  use "ML-Systems/exn.ML";
    90.7 +use "ML-Systems/unsynchronized.ML";
    90.8  use "ML-Systems/universal.ML";
    90.9  use "ML-Systems/thread_dummy.ML";
   90.10  use "ML-Systems/multithreading.ML";
    91.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    91.2 +++ b/src/Pure/ML-Systems/unsynchronized.ML	Tue Sep 29 18:14:08 2009 +0200
    91.3 @@ -0,0 +1,25 @@
    91.4 +(*  Title:      Pure/ML-Systems/unsynchronized.ML
    91.5 +    Author:     Makarius
    91.6 +
    91.7 +Raw ML references as unsynchronized state variables.
    91.8 +*)
    91.9 +
   91.10 +structure Unsynchronized =
   91.11 +struct
   91.12 +
   91.13 +datatype ref = datatype ref;
   91.14 +
   91.15 +val op := = op :=;
   91.16 +val ! = !;
   91.17 +
   91.18 +fun set flag = (flag := true; true);
   91.19 +fun reset flag = (flag := false; false);
   91.20 +fun toggle flag = (flag := not (! flag); ! flag);
   91.21 +
   91.22 +fun change r f = r := f (! r);
   91.23 +fun change_result r f = let val (x, y) = f (! r) in r := y; x end;
   91.24 +
   91.25 +fun inc i = (i := ! i + (1: int); ! i);
   91.26 +fun dec i = (i := ! i - (1: int); ! i);
   91.27 +
   91.28 +end;
    92.1 --- a/src/Pure/ML/ml_compiler_polyml-5.3.ML	Tue Sep 29 14:26:33 2009 +1000
    92.2 +++ b/src/Pure/ML/ml_compiler_polyml-5.3.ML	Tue Sep 29 18:14:08 2009 +0200
    92.3 @@ -91,8 +91,8 @@
    92.4        if null toks then Position.none
    92.5        else ML_Lex.end_pos_of (List.last toks);
    92.6  
    92.7 -    val input_buffer = ref (input @ [(offset_of end_pos, #"\n")]);
    92.8 -    val line = ref (the_default 1 (Position.line_of pos));
    92.9 +    val input_buffer = Unsynchronized.ref (input @ [(offset_of end_pos, #"\n")]);
   92.10 +    val line = Unsynchronized.ref (the_default 1 (Position.line_of pos));
   92.11  
   92.12      fun get_offset () = (case ! input_buffer of [] => 0 | (i, _) :: _ => i);
   92.13      fun get () =
   92.14 @@ -106,9 +106,9 @@
   92.15  
   92.16      (* output *)
   92.17  
   92.18 -    val output_buffer = ref Buffer.empty;
   92.19 +    val output_buffer = Unsynchronized.ref Buffer.empty;
   92.20      fun output () = Buffer.content (! output_buffer);
   92.21 -    fun put s = change output_buffer (Buffer.add s);
   92.22 +    fun put s = Unsynchronized.change output_buffer (Buffer.add s);
   92.23  
   92.24      fun put_message {message, hard, location, context = _} =
   92.25       (put ((if hard then "Error" else "Warning") ^ Position.str_of (position_of location) ^ ":\n");
    93.1 --- a/src/Pure/ML/ml_context.ML	Tue Sep 29 14:26:33 2009 +1000
    93.2 +++ b/src/Pure/ML/ml_context.ML	Tue Sep 29 18:14:08 2009 +0200
    93.3 @@ -19,20 +19,21 @@
    93.4    val the_global_context: unit -> theory
    93.5    val the_local_context: unit -> Proof.context
    93.6    val exec: (unit -> unit) -> Context.generic -> Context.generic
    93.7 -  val stored_thms: thm list ref
    93.8 +  val stored_thms: thm list Unsynchronized.ref
    93.9    val ml_store_thm: string * thm -> unit
   93.10    val ml_store_thms: string * thm list -> unit
   93.11    type antiq =
   93.12      {struct_name: string, background: Proof.context} ->
   93.13        (Proof.context -> string * string) * Proof.context
   93.14    val add_antiq: string -> (Position.T -> antiq context_parser) -> unit
   93.15 -  val trace: bool ref
   93.16 +  val trace: bool Unsynchronized.ref
   93.17    val eval_antiquotes: ML_Lex.token Antiquote.antiquote list * Position.T ->
   93.18      Context.generic option -> (ML_Lex.token list * ML_Lex.token list) * Context.generic option
   93.19    val eval: bool -> Position.T -> Symbol_Pos.text -> unit
   93.20    val eval_file: Path.T -> unit
   93.21    val eval_in: Proof.context option -> bool -> Position.T -> Symbol_Pos.text -> unit
   93.22 -  val evaluate: Proof.context -> bool -> string * (unit -> 'a) option ref -> string -> 'a
   93.23 +  val evaluate: Proof.context -> bool ->
   93.24 +    string * (unit -> 'a) option Unsynchronized.ref -> string -> 'a
   93.25    val expression: Position.T -> string -> string -> string -> Context.generic -> Context.generic
   93.26  end
   93.27  
   93.28 @@ -53,7 +54,7 @@
   93.29  
   93.30  (* theorem bindings *)
   93.31  
   93.32 -val stored_thms: thm list ref = ref [];
   93.33 +val stored_thms: thm list Unsynchronized.ref = Unsynchronized.ref [];
   93.34  
   93.35  fun ml_store sel (name, ths) =
   93.36    let
   93.37 @@ -89,12 +90,13 @@
   93.38  
   93.39  local
   93.40  
   93.41 -val global_parsers = ref (Symtab.empty: (Position.T -> antiq context_parser) Symtab.table);
   93.42 +val global_parsers =
   93.43 +  Unsynchronized.ref (Symtab.empty: (Position.T -> antiq context_parser) Symtab.table);
   93.44  
   93.45  in
   93.46  
   93.47  fun add_antiq name scan = CRITICAL (fn () =>
   93.48 -  change global_parsers (fn tab =>
   93.49 +  Unsynchronized.change global_parsers (fn tab =>
   93.50     (if not (Symtab.defined tab name) then ()
   93.51      else warning ("Redefined ML antiquotation: " ^ quote name);
   93.52      Symtab.update (name, scan) tab)));
   93.53 @@ -162,7 +164,7 @@
   93.54          in (ml, SOME (Context.Proof ctxt')) end;
   93.55    in ((begin_env @ ml_env @ end_env, ml_body), opt_ctxt') end;
   93.56  
   93.57 -val trace = ref false;
   93.58 +val trace = Unsynchronized.ref false;
   93.59  
   93.60  fun eval verbose pos txt =
   93.61    let
    94.1 --- a/src/Pure/Proof/extraction.ML	Tue Sep 29 14:26:33 2009 +1000
    94.2 +++ b/src/Pure/Proof/extraction.ML	Tue Sep 29 18:14:08 2009 +0200
    94.3 @@ -91,7 +91,7 @@
    94.4        Pattern.rewrite_term thy [] (condrew' :: procs) tm
    94.5      and condrew' tm =
    94.6        let
    94.7 -        val cache = ref ([] : (term * term) list);
    94.8 +        val cache = Unsynchronized.ref ([] : (term * term) list);
    94.9          fun lookup f x = (case AList.lookup (op =) (!cache) x of
   94.10              NONE =>
   94.11                let val y = f x
    95.1 --- a/src/Pure/Proof/reconstruct.ML	Tue Sep 29 14:26:33 2009 +1000
    95.2 +++ b/src/Pure/Proof/reconstruct.ML	Tue Sep 29 18:14:08 2009 +0200
    95.3 @@ -6,7 +6,7 @@
    95.4  
    95.5  signature RECONSTRUCT =
    95.6  sig
    95.7 -  val quiet_mode : bool ref
    95.8 +  val quiet_mode : bool Unsynchronized.ref
    95.9    val reconstruct_proof : theory -> term -> Proofterm.proof -> Proofterm.proof
   95.10    val prop_of' : term list -> Proofterm.proof -> term
   95.11    val prop_of : Proofterm.proof -> term
   95.12 @@ -19,7 +19,7 @@
   95.13  
   95.14  open Proofterm;
   95.15  
   95.16 -val quiet_mode = ref true;
   95.17 +val quiet_mode = Unsynchronized.ref true;
   95.18  fun message s = if !quiet_mode then () else writeln s;
   95.19  
   95.20  fun vars_of t = map Var (rev (Term.add_vars t []));
    96.1 --- a/src/Pure/ProofGeneral/preferences.ML	Tue Sep 29 14:26:33 2009 +1000
    96.2 +++ b/src/Pure/ProofGeneral/preferences.ML	Tue Sep 29 18:14:08 2009 +0200
    96.3 @@ -18,11 +18,11 @@
    96.4      get: unit -> string,
    96.5      set: string -> unit}
    96.6    val generic_pref: ('a -> string) -> (string -> 'a) -> PgipTypes.pgiptype ->
    96.7 -    'a ref -> string -> string -> preference
    96.8 -  val string_pref: string ref -> string -> string -> preference
    96.9 -  val int_pref: int ref -> string -> string -> preference
   96.10 -  val nat_pref: int ref -> string -> string -> preference
   96.11 -  val bool_pref: bool ref -> string -> string -> preference
   96.12 +    'a Unsynchronized.ref -> string -> string -> preference
   96.13 +  val string_pref: string Unsynchronized.ref -> string -> string -> preference
   96.14 +  val int_pref: int Unsynchronized.ref -> string -> string -> preference
   96.15 +  val nat_pref: int Unsynchronized.ref -> string -> string -> preference
   96.16 +  val bool_pref: bool Unsynchronized.ref -> string -> string -> preference
   96.17    type T = (string * preference list) list
   96.18    val pure_preferences: T
   96.19    val remove: string -> T -> T
   96.20 @@ -95,8 +95,9 @@
   96.21    let
   96.22      fun get () = PgipTypes.bool_to_pgstring (print_mode_active thm_depsN);
   96.23      fun set s =
   96.24 -      if PgipTypes.read_pgipbool s then change print_mode (insert (op =) thm_depsN)
   96.25 -      else change print_mode (remove (op =) thm_depsN);
   96.26 +      if PgipTypes.read_pgipbool s
   96.27 +      then Unsynchronized.change print_mode (insert (op =) thm_depsN)
   96.28 +      else Unsynchronized.change print_mode (remove (op =) thm_depsN);
   96.29    in
   96.30      mkpref get set PgipTypes.Pgipbool "theorem-dependencies"
   96.31        "Track theorem dependencies within Proof General"
    97.1 --- a/src/Pure/ProofGeneral/proof_general_emacs.ML	Tue Sep 29 14:26:33 2009 +1000
    97.2 +++ b/src/Pure/ProofGeneral/proof_general_emacs.ML	Tue Sep 29 18:14:08 2009 +0200
    97.3 @@ -226,7 +226,7 @@
    97.4  
    97.5  (* init *)
    97.6  
    97.7 -val initialized = ref false;
    97.8 +val initialized = Unsynchronized.ref false;
    97.9  
   97.10  fun init false = panic "No Proof General interface support for Isabelle/classic mode."
   97.11    | init true =
   97.12 @@ -239,9 +239,9 @@
   97.13            ProofGeneralPgip.init_pgip_channel (! Output.priority_fn);
   97.14            setup_thy_loader ();
   97.15            setup_present_hook ();
   97.16 -          set initialized);
   97.17 +          Unsynchronized.set initialized);
   97.18          sync_thy_loader ();
   97.19 -       change print_mode (update (op =) proof_generalN);
   97.20 +       Unsynchronized.change print_mode (update (op =) proof_generalN);
   97.21         Isar.toplevel_loop {init = true, welcome = true, sync = true, secure = Secure.is_secure ()});
   97.22  
   97.23  end;
    98.1 --- a/src/Pure/ProofGeneral/proof_general_pgip.ML	Tue Sep 29 14:26:33 2009 +1000
    98.2 +++ b/src/Pure/ProofGeneral/proof_general_pgip.ML	Tue Sep 29 18:14:08 2009 +0200
    98.3 @@ -32,20 +32,20 @@
    98.4  (** print mode **)
    98.5  
    98.6  val proof_generalN = "ProofGeneral";
    98.7 -val pgmlsymbols_flag = ref true;
    98.8 +val pgmlsymbols_flag = Unsynchronized.ref true;
    98.9  
   98.10  
   98.11  (* assembling and issuing PGIP packets *)
   98.12  
   98.13 -val pgip_refid = ref NONE: string option ref;
   98.14 -val pgip_refseq = ref NONE: int option ref;
   98.15 +val pgip_refid = Unsynchronized.ref NONE: string option Unsynchronized.ref;
   98.16 +val pgip_refseq = Unsynchronized.ref NONE: int option Unsynchronized.ref;
   98.17  
   98.18  local
   98.19    val pgip_class  = "pg"
   98.20    val pgip_tag = "Isabelle/Isar"
   98.21 -  val pgip_id = ref ""
   98.22 -  val pgip_seq = ref 0
   98.23 -  fun pgip_serial () = inc pgip_seq
   98.24 +  val pgip_id = Unsynchronized.ref ""
   98.25 +  val pgip_seq = Unsynchronized.ref 0
   98.26 +  fun pgip_serial () = Unsynchronized.inc pgip_seq
   98.27  
   98.28    fun assemble_pgips pgips =
   98.29      Pgip { tag = SOME pgip_tag,
   98.30 @@ -65,7 +65,7 @@
   98.31  
   98.32  fun matching_pgip_id id = (id = ! pgip_id)
   98.33  
   98.34 -val output_xml_fn = ref Output.writeln_default
   98.35 +val output_xml_fn = Unsynchronized.ref Output.writeln_default
   98.36  fun output_xml s = ! output_xml_fn (XML.string_of s);
   98.37  
   98.38  val output_pgips = XML.string_of o PgipOutput.output o assemble_pgips o map PgipOutput.output;
   98.39 @@ -280,7 +280,7 @@
   98.40  
   98.41  (* theorem dependeny output *)
   98.42  
   98.43 -val show_theorem_dependencies = ref false;
   98.44 +val show_theorem_dependencies = Unsynchronized.ref false;
   98.45  
   98.46  local
   98.47  
   98.48 @@ -368,13 +368,13 @@
   98.49  
   98.50  (* Preferences: tweak for PGIP interfaces *)
   98.51  
   98.52 -val preferences = ref Preferences.pure_preferences;
   98.53 +val preferences = Unsynchronized.ref Preferences.pure_preferences;
   98.54  
   98.55  fun add_preference cat pref =
   98.56 -  CRITICAL (fn () => change preferences (Preferences.add cat pref));
   98.57 +  CRITICAL (fn () => Unsynchronized.change preferences (Preferences.add cat pref));
   98.58  
   98.59  fun setup_preferences_tweak () =
   98.60 -  CRITICAL (fn () => change preferences
   98.61 +  CRITICAL (fn () => Unsynchronized.change preferences
   98.62     (Preferences.set_default ("show-question-marks", "false") #>
   98.63      Preferences.remove "show-question-marks" #>   (* we use markup, not ?s *)
   98.64      Preferences.remove "theorem-dependencies" #>  (* set internally *)
   98.65 @@ -471,7 +471,7 @@
   98.66  fun set_proverflag_pgmlsymbols b =
   98.67      (pgmlsymbols_flag := b;
   98.68        NAMED_CRITICAL "print_mode" (fn () =>
   98.69 -        change print_mode
   98.70 +        Unsynchronized.change print_mode
   98.71              (fn mode =>
   98.72                  remove (op =) Symbol.xsymbolsN mode @ (if b then [Symbol.xsymbolsN] else []))))
   98.73  
   98.74 @@ -677,7 +677,7 @@
   98.75     about this special status, but for now we just keep a local reference.
   98.76  *)
   98.77  
   98.78 -val currently_open_file = ref (NONE : pgipurl option)
   98.79 +val currently_open_file = Unsynchronized.ref (NONE : pgipurl option)
   98.80  
   98.81  fun get_currently_open_file () = ! currently_open_file;
   98.82  
   98.83 @@ -779,7 +779,7 @@
   98.84  *)
   98.85  
   98.86  local
   98.87 -    val current_working_dir = ref (NONE : string option)
   98.88 +    val current_working_dir = Unsynchronized.ref (NONE : string option)
   98.89  in
   98.90  fun changecwd_dir newdirpath =
   98.91     let
   98.92 @@ -1021,7 +1021,7 @@
   98.93  
   98.94  (* init *)
   98.95  
   98.96 -val initialized = ref false;
   98.97 +val initialized = Unsynchronized.ref false;
   98.98  
   98.99  fun init_pgip false = panic "No Proof General interface support for Isabelle/classic mode."
  98.100    | init_pgip true =
  98.101 @@ -1035,9 +1035,9 @@
  98.102           setup_present_hook ();
  98.103           init_pgip_session_id ();
  98.104           welcome ();
  98.105 -         set initialized);
  98.106 +         Unsynchronized.set initialized);
  98.107          sync_thy_loader ();
  98.108 -       change print_mode (update (op =) proof_generalN);
  98.109 +       Unsynchronized.change print_mode (update (op =) proof_generalN);
  98.110         pgip_toplevel tty_src);
  98.111  
  98.112  
  98.113 @@ -1045,7 +1045,7 @@
  98.114  (** Out-of-loop PGIP commands (for Emacs hybrid mode) **)
  98.115  
  98.116  local
  98.117 -    val pgip_output_channel = ref Output.writeln_default
  98.118 +    val pgip_output_channel = Unsynchronized.ref Output.writeln_default
  98.119  in
  98.120  
  98.121  (* Set recipient for PGIP results *)
    99.1 --- a/src/Pure/ROOT.ML	Tue Sep 29 14:26:33 2009 +1000
    99.2 +++ b/src/Pure/ROOT.ML	Tue Sep 29 18:14:08 2009 +0200
    99.3 @@ -8,7 +8,7 @@
    99.4  end;
    99.5  
    99.6  (*if true then some tools will OMIT some proofs*)
    99.7 -val quick_and_dirty = ref false;
    99.8 +val quick_and_dirty = Unsynchronized.ref false;
    99.9  
   99.10  print_depth 10;
   99.11  
   100.1 --- a/src/Pure/Syntax/ast.ML	Tue Sep 29 14:26:33 2009 +1000
   100.2 +++ b/src/Pure/Syntax/ast.ML	Tue Sep 29 18:14:08 2009 +0200
   100.3 @@ -24,8 +24,8 @@
   100.4    val fold_ast_p: string -> ast list * ast -> ast
   100.5    val unfold_ast: string -> ast -> ast list
   100.6    val unfold_ast_p: string -> ast -> ast list * ast
   100.7 -  val trace_ast: bool ref
   100.8 -  val stat_ast: bool ref
   100.9 +  val trace_ast: bool Unsynchronized.ref
  100.10 +  val stat_ast: bool Unsynchronized.ref
  100.11  end;
  100.12  
  100.13  signature AST =
  100.14 @@ -173,9 +173,9 @@
  100.15  
  100.16  fun normalize trace stat get_rules pre_ast =
  100.17    let
  100.18 -    val passes = ref 0;
  100.19 -    val failed_matches = ref 0;
  100.20 -    val changes = ref 0;
  100.21 +    val passes = Unsynchronized.ref 0;
  100.22 +    val failed_matches = Unsynchronized.ref 0;
  100.23 +    val changes = Unsynchronized.ref 0;
  100.24  
  100.25      fun subst _ (ast as Constant _) = ast
  100.26        | subst env (Variable x) = the (Symtab.lookup env x)
  100.27 @@ -184,8 +184,8 @@
  100.28      fun try_rules ((lhs, rhs) :: pats) ast =
  100.29            (case match ast lhs of
  100.30              SOME (env, args) =>
  100.31 -              (inc changes; SOME (mk_appl (subst env rhs) args))
  100.32 -          | NONE => (inc failed_matches; try_rules pats ast))
  100.33 +              (Unsynchronized.inc changes; SOME (mk_appl (subst env rhs) args))
  100.34 +          | NONE => (Unsynchronized.inc failed_matches; try_rules pats ast))
  100.35        | try_rules [] _ = NONE;
  100.36      val try_headless_rules = try_rules (get_rules "");
  100.37  
  100.38 @@ -226,7 +226,7 @@
  100.39          val old_changes = ! changes;
  100.40          val new_ast = norm ast;
  100.41        in
  100.42 -        inc passes;
  100.43 +        Unsynchronized.inc passes;
  100.44          if old_changes = ! changes then new_ast else normal new_ast
  100.45        end;
  100.46  
  100.47 @@ -245,8 +245,8 @@
  100.48  
  100.49  (* normalize_ast *)
  100.50  
  100.51 -val trace_ast = ref false;
  100.52 -val stat_ast = ref false;
  100.53 +val trace_ast = Unsynchronized.ref false;
  100.54 +val stat_ast = Unsynchronized.ref false;
  100.55  
  100.56  fun normalize_ast get_rules ast =
  100.57    normalize (! trace_ast) (! stat_ast) get_rules ast;
   101.1 --- a/src/Pure/Syntax/parser.ML	Tue Sep 29 14:26:33 2009 +1000
   101.2 +++ b/src/Pure/Syntax/parser.ML	Tue Sep 29 18:14:08 2009 +0200
   101.3 @@ -17,7 +17,7 @@
   101.4      Tip of Lexicon.token
   101.5    val parse: gram -> string -> Lexicon.token list -> parsetree list
   101.6    val guess_infix_lr: gram -> string -> (string * bool * bool * int) option
   101.7 -  val branching_level: int ref
   101.8 +  val branching_level: int Unsynchronized.ref
   101.9  end;
  101.10  
  101.11  structure Parser: PARSER =
  101.12 @@ -690,7 +690,7 @@
  101.13        else movedot_lambda (B, j, tss, Nonterminal (A, k) :: sa, id, i) ts;
  101.14  
  101.15  
  101.16 -val branching_level = ref 600;                   (*trigger value for warnings*)
  101.17 +val branching_level = Unsynchronized.ref 600;   (*trigger value for warnings*)
  101.18  
  101.19  (*get all productions of a NT and NTs chained to it which can
  101.20    be started by specified token*)
  101.21 @@ -821,7 +821,7 @@
  101.22      val Estate = Array.array (s, []);
  101.23    in
  101.24      Array.update (Estate, 0, S0);
  101.25 -    get_trees (produce (ref false) prods tags chains Estate 0 indata eof)
  101.26 +    get_trees (produce (Unsynchronized.ref false) prods tags chains Estate 0 indata eof)
  101.27    end;
  101.28  
  101.29  
   102.1 --- a/src/Pure/Syntax/printer.ML	Tue Sep 29 14:26:33 2009 +1000
   102.2 +++ b/src/Pure/Syntax/printer.ML	Tue Sep 29 18:14:08 2009 +0200
   102.3 @@ -6,11 +6,11 @@
   102.4  
   102.5  signature PRINTER0 =
   102.6  sig
   102.7 -  val show_brackets: bool ref
   102.8 -  val show_sorts: bool ref
   102.9 -  val show_types: bool ref
  102.10 -  val show_no_free_types: bool ref
  102.11 -  val show_all_types: bool ref
  102.12 +  val show_brackets: bool Unsynchronized.ref
  102.13 +  val show_sorts: bool Unsynchronized.ref
  102.14 +  val show_types: bool Unsynchronized.ref
  102.15 +  val show_no_free_types: bool Unsynchronized.ref
  102.16 +  val show_all_types: bool Unsynchronized.ref
  102.17    val pp_show_brackets: Pretty.pp -> Pretty.pp
  102.18  end;
  102.19  
  102.20 @@ -42,11 +42,11 @@
  102.21  
  102.22  (** options for printing **)
  102.23  
  102.24 -val show_types = ref false;
  102.25 -val show_sorts = ref false;
  102.26 -val show_brackets = ref false;
  102.27 -val show_no_free_types = ref false;
  102.28 -val show_all_types = ref false;
  102.29 +val show_types = Unsynchronized.ref false;
  102.30 +val show_sorts = Unsynchronized.ref false;
  102.31 +val show_brackets = Unsynchronized.ref false;
  102.32 +val show_no_free_types = Unsynchronized.ref false;
  102.33 +val show_all_types = Unsynchronized.ref false;
  102.34  
  102.35  fun pp_show_brackets pp = Pretty.pp (setmp show_brackets true (Pretty.term pp),
  102.36    Pretty.typ pp, Pretty.sort pp, Pretty.classrel pp, Pretty.arity pp);
   103.1 --- a/src/Pure/Syntax/syn_trans.ML	Tue Sep 29 14:26:33 2009 +1000
   103.2 +++ b/src/Pure/Syntax/syn_trans.ML	Tue Sep 29 18:14:08 2009 +0200
   103.3 @@ -6,7 +6,7 @@
   103.4  
   103.5  signature SYN_TRANS0 =
   103.6  sig
   103.7 -  val eta_contract: bool ref
   103.8 +  val eta_contract: bool Unsynchronized.ref
   103.9    val atomic_abs_tr': string * typ * term -> term * term
  103.10    val preserve_binder_abs_tr': string -> string -> string * (term list -> term)
  103.11    val preserve_binder_abs2_tr': string -> string -> string * (term list -> term)
  103.12 @@ -276,7 +276,7 @@
  103.13  
  103.14  (*do (partial) eta-contraction before printing*)
  103.15  
  103.16 -val eta_contract = ref true;
  103.17 +val eta_contract = Unsynchronized.ref true;
  103.18  
  103.19  fun eta_contr tm =
  103.20    let
   104.1 --- a/src/Pure/Syntax/syntax.ML	Tue Sep 29 14:26:33 2009 +1000
   104.2 +++ b/src/Pure/Syntax/syntax.ML	Tue Sep 29 18:14:08 2009 +0200
   104.3 @@ -36,9 +36,9 @@
   104.4    val print_syntax: syntax -> unit
   104.5    val guess_infix: syntax -> string -> mixfix option
   104.6    val read_token: string -> Symbol_Pos.T list * Position.T
   104.7 -  val ambiguity_is_error: bool ref
   104.8 -  val ambiguity_level: int ref
   104.9 -  val ambiguity_limit: int ref
  104.10 +  val ambiguity_is_error: bool Unsynchronized.ref
  104.11 +  val ambiguity_level: int Unsynchronized.ref
  104.12 +  val ambiguity_limit: int Unsynchronized.ref
  104.13    val standard_parse_term: Pretty.pp -> (term -> string option) ->
  104.14      (((string * int) * sort) list -> string * int -> Term.sort) ->
  104.15      (string -> bool * string) -> (string -> string option) ->
  104.16 @@ -472,9 +472,9 @@
  104.17  
  104.18  (* read_ast *)
  104.19  
  104.20 -val ambiguity_is_error = ref false;
  104.21 -val ambiguity_level = ref 1;
  104.22 -val ambiguity_limit = ref 10;
  104.23 +val ambiguity_is_error = Unsynchronized.ref false;
  104.24 +val ambiguity_level = Unsynchronized.ref 1;
  104.25 +val ambiguity_limit = Unsynchronized.ref 10;
  104.26  
  104.27  fun ambiguity_msg pos = "Parse error: ambiguous syntax" ^ Position.str_of pos;
  104.28  
  104.29 @@ -711,7 +711,7 @@
  104.30      unparse_typ: Proof.context -> typ -> Pretty.T,
  104.31      unparse_term: Proof.context -> term -> Pretty.T};
  104.32  
  104.33 -  val operations = ref (NONE: operations option);
  104.34 +  val operations = Unsynchronized.ref (NONE: operations option);
  104.35  
  104.36    fun operation which ctxt x =
  104.37      (case ! operations of
   105.1 --- a/src/Pure/System/isabelle_process.ML	Tue Sep 29 14:26:33 2009 +1000
   105.2 +++ b/src/Pure/System/isabelle_process.ML	Tue Sep 29 18:14:08 2009 +0200
   105.3 @@ -130,7 +130,7 @@
   105.4  (* init *)
   105.5  
   105.6  fun init out =
   105.7 - (change print_mode (update (op =) isabelle_processN);
   105.8 + (Unsynchronized.change print_mode (update (op =) isabelle_processN);
   105.9    setup_channels out |> init_message;
  105.10    OuterKeyword.report ();
  105.11    Output.status (Markup.markup Markup.ready "");
   106.1 --- a/src/Pure/System/isar.ML	Tue Sep 29 14:26:33 2009 +1000
   106.2 +++ b/src/Pure/System/isar.ML	Tue Sep 29 18:14:08 2009 +0200
   106.3 @@ -18,7 +18,7 @@
   106.4    val undo: int -> unit
   106.5    val kill: unit -> unit
   106.6    val kill_proof: unit -> unit
   106.7 -  val crashes: exn list ref
   106.8 +  val crashes: exn list Unsynchronized.ref
   106.9    val toplevel_loop: {init: bool, welcome: bool, sync: bool, secure: bool} -> unit
  106.10    val loop: unit -> unit
  106.11    val main: unit -> unit
  106.12 @@ -36,9 +36,9 @@
  106.13    (*previous state, state transition -- regular commands only*)
  106.14  
  106.15  local
  106.16 -  val global_history = ref ([]: history);
  106.17 -  val global_state = ref Toplevel.toplevel;
  106.18 -  val global_exn = ref (NONE: (exn * string) option);
  106.19 +  val global_history = Unsynchronized.ref ([]: history);
  106.20 +  val global_state = Unsynchronized.ref Toplevel.toplevel;
  106.21 +  val global_exn = Unsynchronized.ref (NONE: (exn * string) option);
  106.22  in
  106.23  
  106.24  fun edit_history count f = NAMED_CRITICAL "Isar" (fn () =>
  106.25 @@ -115,7 +115,7 @@
  106.26  
  106.27  (* toplevel loop *)
  106.28  
  106.29 -val crashes = ref ([]: exn list);
  106.30 +val crashes = Unsynchronized.ref ([]: exn list);
  106.31  
  106.32  local
  106.33  
  106.34 @@ -130,7 +130,7 @@
  106.35      handle exn =>
  106.36        (Output.error_msg (ML_Compiler.exn_message exn)
  106.37          handle crash =>
  106.38 -          (CRITICAL (fn () => change crashes (cons crash));
  106.39 +          (CRITICAL (fn () => Unsynchronized.change crashes (cons crash));
  106.40              warning "Recovering from Isar toplevel crash -- see also Isar.crashes");
  106.41            raw_loop secure src)
  106.42    end;
  106.43 @@ -139,6 +139,7 @@
  106.44  
  106.45  fun toplevel_loop {init = do_init, welcome, sync, secure} =
  106.46   (Context.set_thread_data NONE;
  106.47 +  Secure.open_unsynchronized ();
  106.48    if do_init then init () else ();
  106.49    if welcome then writeln (Session.welcome ()) else ();
  106.50    uninterruptible (fn _ => fn () => raw_loop secure (OuterSyntax.isar sync)) ());
   107.1 --- a/src/Pure/System/session.ML	Tue Sep 29 14:26:33 2009 +1000
   107.2 +++ b/src/Pure/System/session.ML	Tue Sep 29 18:14:08 2009 +0200
   107.3 @@ -21,10 +21,10 @@
   107.4  
   107.5  (* session state *)
   107.6  
   107.7 -val session = ref ([Context.PureN]: string list);
   107.8 -val session_path = ref ([]: string list);
   107.9 -val session_finished = ref false;
  107.10 -val remote_path = ref (NONE: Url.T option);
  107.11 +val session = Unsynchronized.ref ([Context.PureN]: string list);
  107.12 +val session_path = Unsynchronized.ref ([]: string list);
  107.13 +val session_finished = Unsynchronized.ref false;
  107.14 +val remote_path = Unsynchronized.ref (NONE: Url.T option);
  107.15  
  107.16  
  107.17  (* access path *)
   108.1 --- a/src/Pure/Thy/html.ML	Tue Sep 29 14:26:33 2009 +1000
   108.2 +++ b/src/Pure/Thy/html.ML	Tue Sep 29 18:14:08 2009 +0200
   108.3 @@ -267,8 +267,8 @@
   108.4  
   108.5  (* document *)
   108.6  
   108.7 -val charset = ref "ISO-8859-1";
   108.8 -fun with_charset s = setmp_noncritical charset s;
   108.9 +val charset = Unsynchronized.ref "ISO-8859-1";
  108.10 +fun with_charset s = setmp_noncritical charset s;   (* FIXME *)
  108.11  
  108.12  fun begin_document title =
  108.13    let val cs = ! charset in
   109.1 --- a/src/Pure/Thy/present.ML	Tue Sep 29 14:26:33 2009 +1000
   109.2 +++ b/src/Pure/Thy/present.ML	Tue Sep 29 18:14:08 2009 +0200
   109.3 @@ -161,10 +161,11 @@
   109.4  
   109.5  (* state *)
   109.6  
   109.7 -val browser_info = ref empty_browser_info;
   109.8 -fun change_browser_info f = CRITICAL (fn () => change browser_info (map_browser_info f));
   109.9 +val browser_info = Unsynchronized.ref empty_browser_info;
  109.10 +fun change_browser_info f =
  109.11 +  CRITICAL (fn () => Unsynchronized.change browser_info (map_browser_info f));
  109.12  
  109.13 -val suppress_tex_source = ref false;
  109.14 +val suppress_tex_source = Unsynchronized.ref false;
  109.15  fun no_document f x = setmp_noncritical suppress_tex_source true f x;
  109.16  
  109.17  fun init_theory_info name info =
  109.18 @@ -229,7 +230,7 @@
  109.19  
  109.20  (* state *)
  109.21  
  109.22 -val session_info = ref (NONE: session_info option);
  109.23 +val session_info = Unsynchronized.ref (NONE: session_info option);
  109.24  
  109.25  fun with_session x f = (case ! session_info of NONE => x | SOME info => f info);
  109.26  fun with_context f = f (Context.theory_name (ML_Context.the_global_context ()));
  109.27 @@ -534,5 +535,5 @@
  109.28  
  109.29  end;
  109.30  
  109.31 -structure BasicPresent: BASIC_PRESENT = Present;
  109.32 -open BasicPresent;
  109.33 +structure Basic_Present: BASIC_PRESENT = Present;
  109.34 +open Basic_Present;
   110.1 --- a/src/Pure/Thy/thy_info.ML	Tue Sep 29 14:26:33 2009 +1000
   110.2 +++ b/src/Pure/Thy/thy_info.ML	Tue Sep 29 18:14:08 2009 +0200
   110.3 @@ -50,9 +50,9 @@
   110.4  val str_of_action = fn Update => "Update" | Outdate => "Outdate" | Remove => "Remove";
   110.5  
   110.6  local
   110.7 -  val hooks = ref ([]: (action -> string -> unit) list);
   110.8 +  val hooks = Unsynchronized.ref ([]: (action -> string -> unit) list);
   110.9  in
  110.10 -  fun add_hook f = CRITICAL (fn () => change hooks (cons f));
  110.11 +  fun add_hook f = CRITICAL (fn () => Unsynchronized.change hooks (cons f));
  110.12    fun perform action name = List.app (fn f => (try (fn () => f action name) (); ())) (! hooks);
  110.13  end;
  110.14  
  110.15 @@ -111,10 +111,10 @@
  110.16  type thy = deps option * theory option;
  110.17  
  110.18  local
  110.19 -  val database = ref (Graph.empty: thy Graph.T);
  110.20 +  val database = Unsynchronized.ref (Graph.empty: thy Graph.T);
  110.21  in
  110.22    fun get_thys () = ! database;
  110.23 -  fun change_thys f = CRITICAL (fn () => Library.change database f);
  110.24 +  fun change_thys f = CRITICAL (fn () => Unsynchronized.change database f);
  110.25  end;
  110.26  
  110.27  
   111.1 --- a/src/Pure/Thy/thy_load.ML	Tue Sep 29 14:26:33 2009 +1000
   111.2 +++ b/src/Pure/Thy/thy_load.ML	Tue Sep 29 18:14:08 2009 +0200
   111.3 @@ -37,14 +37,16 @@
   111.4  
   111.5  (* maintain load path *)
   111.6  
   111.7 -local val load_path = ref [Path.current] in
   111.8 +local val load_path = Unsynchronized.ref [Path.current] in
   111.9  
  111.10  fun show_path () = map Path.implode (! load_path);
  111.11  
  111.12 -fun del_path s = CRITICAL (fn () => change load_path (remove (op =) (Path.explode s)));
  111.13 -fun add_path s = CRITICAL (fn () => (del_path s; change load_path (cons (Path.explode s))));
  111.14 -fun path_add s =
  111.15 -  CRITICAL (fn () => (del_path s; change load_path (fn path => path @ [Path.explode s])));
  111.16 +fun del_path s = CRITICAL (fn () =>
  111.17 +    Unsynchronized.change load_path (remove (op =) (Path.explode s)));
  111.18 +fun add_path s = CRITICAL (fn () =>
  111.19 +    (del_path s; Unsynchronized.change load_path (cons (Path.explode s))));
  111.20 +fun path_add s = CRITICAL (fn () =>
  111.21 +    (del_path s; Unsynchronized.change load_path (fn path => path @ [Path.explode s])));
  111.22  fun reset_path () = load_path := [Path.current];
  111.23  
  111.24  fun with_paths ss f x =
  111.25 @@ -124,5 +126,5 @@
  111.26  
  111.27  end;
  111.28  
  111.29 -structure BasicThyLoad: BASIC_THY_LOAD = ThyLoad;
  111.30 -open BasicThyLoad;
  111.31 +structure Basic_Thy_Load: BASIC_THY_LOAD = ThyLoad;
  111.32 +open Basic_Thy_Load;
   112.1 --- a/src/Pure/Thy/thy_output.ML	Tue Sep 29 14:26:33 2009 +1000
   112.2 +++ b/src/Pure/Thy/thy_output.ML	Tue Sep 29 18:14:08 2009 +0200
   112.3 @@ -6,11 +6,11 @@
   112.4  
   112.5  signature THY_OUTPUT =
   112.6  sig
   112.7 -  val display: bool ref
   112.8 -  val quotes: bool ref
   112.9 -  val indent: int ref
  112.10 -  val source: bool ref
  112.11 -  val break: bool ref
  112.12 +  val display: bool Unsynchronized.ref
  112.13 +  val quotes: bool Unsynchronized.ref
  112.14 +  val indent: int Unsynchronized.ref
  112.15 +  val source: bool Unsynchronized.ref
  112.16 +  val break: bool Unsynchronized.ref
  112.17    val add_commands: (string * (Args.src -> Toplevel.state -> string)) list -> unit
  112.18    val add_options: (string * (string -> (unit -> string) -> unit -> string)) list -> unit
  112.19    val defined_command: string -> bool
  112.20 @@ -21,7 +21,7 @@
  112.21    val antiquotation: string -> 'a context_parser ->
  112.22      ({state: Toplevel.state, source: Args.src, context: Proof.context} -> 'a -> string) -> unit
  112.23    datatype markup = Markup | MarkupEnv | Verbatim
  112.24 -  val modes: string list ref
  112.25 +  val modes: string list Unsynchronized.ref
  112.26    val eval_antiquote: Scan.lexicon -> Toplevel.state -> Symbol_Pos.text * Position.T -> string
  112.27    val present_thy: Scan.lexicon -> (string -> string list) -> (markup -> string -> bool) ->
  112.28      (Toplevel.transition * Toplevel.state) list -> (OuterLex.token, 'a) Source.source -> Buffer.T
  112.29 @@ -42,11 +42,11 @@
  112.30  
  112.31  (** global options **)
  112.32  
  112.33 -val display = ref false;
  112.34 -val quotes = ref false;
  112.35 -val indent = ref 0;
  112.36 -val source = ref false;
  112.37 -val break = ref false;
  112.38 +val display = Unsynchronized.ref false;
  112.39 +val quotes = Unsynchronized.ref false;
  112.40 +val indent = Unsynchronized.ref 0;
  112.41 +val source = Unsynchronized.ref false;
  112.42 +val break = Unsynchronized.ref false;
  112.43  
  112.44  
  112.45  
  112.46 @@ -55,10 +55,10 @@
  112.47  local
  112.48  
  112.49  val global_commands =
  112.50 -  ref (Symtab.empty: (Args.src -> Toplevel.state -> string) Symtab.table);
  112.51 +  Unsynchronized.ref (Symtab.empty: (Args.src -> Toplevel.state -> string) Symtab.table);
  112.52  
  112.53  val global_options =
  112.54 -  ref (Symtab.empty: (string -> (unit -> string) -> unit -> string) Symtab.table);
  112.55 +  Unsynchronized.ref (Symtab.empty: (string -> (unit -> string) -> unit -> string) Symtab.table);
  112.56  
  112.57  fun add_item kind (name, x) tab =
  112.58   (if not (Symtab.defined tab name) then ()
  112.59 @@ -67,8 +67,10 @@
  112.60  
  112.61  in
  112.62  
  112.63 -fun add_commands xs = CRITICAL (fn () => change global_commands (fold (add_item "command") xs));
  112.64 -fun add_options xs = CRITICAL (fn () => change global_options (fold (add_item "option") xs));
  112.65 +fun add_commands xs =
  112.66 +  CRITICAL (fn () => Unsynchronized.change global_commands (fold (add_item "command") xs));
  112.67 +fun add_options xs =
  112.68 +  CRITICAL (fn () => Unsynchronized.change global_options (fold (add_item "option") xs));
  112.69  
  112.70  fun defined_command name = Symtab.defined (! global_commands) name;
  112.71  fun defined_option name = Symtab.defined (! global_options) name;
  112.72 @@ -143,7 +145,7 @@
  112.73  
  112.74  (* eval_antiquote *)
  112.75  
  112.76 -val modes = ref ([]: string list);
  112.77 +val modes = Unsynchronized.ref ([]: string list);
  112.78  
  112.79  fun eval_antiquote lex state (txt, pos) =
  112.80    let
   113.1 --- a/src/Pure/Tools/find_theorems.ML	Tue Sep 29 14:26:33 2009 +1000
   113.2 +++ b/src/Pure/Tools/find_theorems.ML	Tue Sep 29 18:14:08 2009 +0200
   113.3 @@ -9,8 +9,8 @@
   113.4    datatype 'term criterion =
   113.5      Name of string | Intro | IntroIff | Elim | Dest | Solves | Simp of 'term |
   113.6      Pattern of 'term
   113.7 -  val tac_limit: int ref
   113.8 -  val limit: int ref
   113.9 +  val tac_limit: int Unsynchronized.ref
  113.10 +  val limit: int Unsynchronized.ref
  113.11    val find_theorems: Proof.context -> thm option -> int option -> bool ->
  113.12      (bool * string criterion) list -> int option * (Facts.ref * thm) list
  113.13    val pretty_thm: Proof.context -> Facts.ref * thm -> Pretty.T
  113.14 @@ -186,7 +186,7 @@
  113.15      end
  113.16    else NONE
  113.17  
  113.18 -val tac_limit = ref 5;
  113.19 +val tac_limit = Unsynchronized.ref 5;
  113.20  
  113.21  fun filter_solves ctxt goal =
  113.22    let
  113.23 @@ -372,7 +372,7 @@
  113.24     (Facts.dest_static [] (PureThy.facts_of (ProofContext.theory_of ctxt)) @
  113.25      Facts.dest_static [] (ProofContext.facts_of ctxt));
  113.26  
  113.27 -val limit = ref 40;
  113.28 +val limit = Unsynchronized.ref 40;
  113.29  
  113.30  fun find_theorems ctxt opt_goal opt_limit rem_dups raw_criteria =
  113.31    let
   114.1 --- a/src/Pure/codegen.ML	Tue Sep 29 14:26:33 2009 +1000
   114.2 +++ b/src/Pure/codegen.ML	Tue Sep 29 18:14:08 2009 +0200
   114.3 @@ -6,10 +6,10 @@
   114.4  
   114.5  signature CODEGEN =
   114.6  sig
   114.7 -  val quiet_mode : bool ref
   114.8 +  val quiet_mode : bool Unsynchronized.ref
   114.9    val message : string -> unit
  114.10 -  val mode : string list ref
  114.11 -  val margin : int ref
  114.12 +  val mode : string list Unsynchronized.ref
  114.13 +  val margin : int Unsynchronized.ref
  114.14    val string_of : Pretty.T -> string
  114.15    val str : string -> Pretty.T
  114.16  
  114.17 @@ -75,9 +75,9 @@
  114.18    val mk_type: bool -> typ -> Pretty.T
  114.19    val mk_term_of: codegr -> string -> bool -> typ -> Pretty.T
  114.20    val mk_gen: codegr -> string -> bool -> string list -> string -> typ -> Pretty.T
  114.21 -  val test_fn: (int -> term list option) ref
  114.22 +  val test_fn: (int -> term list option) Unsynchronized.ref
  114.23    val test_term: Proof.context -> term -> int -> term list option
  114.24 -  val eval_result: (unit -> term) ref
  114.25 +  val eval_result: (unit -> term) Unsynchronized.ref
  114.26    val eval_term: theory -> term -> term
  114.27    val evaluation_conv: cterm -> thm
  114.28    val parse_mixfix: (string -> 'a) -> string -> 'a mixfix list
  114.29 @@ -102,12 +102,12 @@
  114.30  structure Codegen : CODEGEN =
  114.31  struct
  114.32  
  114.33 -val quiet_mode = ref true;
  114.34 +val quiet_mode = Unsynchronized.ref true;
  114.35  fun message s = if !quiet_mode then () else writeln s;
  114.36  
  114.37 -val mode = ref ([] : string list);
  114.38 +val mode = Unsynchronized.ref ([] : string list);
  114.39  
  114.40 -val margin = ref 80;
  114.41 +val margin = Unsynchronized.ref 80;
  114.42  
  114.43  fun string_of p = (Pretty.string_of |>
  114.44    PrintMode.setmp [] |>
  114.45 @@ -878,7 +878,8 @@
  114.46                [mk_gen gr module true xs a T, mk_type true T]) Ts) @
  114.47           (if member (op =) xs s then [str a] else []))));
  114.48  
  114.49 -val test_fn : (int -> term list option) ref = ref (fn _ => NONE);
  114.50 +val test_fn : (int -> term list option) Unsynchronized.ref =
  114.51 +  Unsynchronized.ref (fn _ => NONE);
  114.52  
  114.53  fun test_term ctxt t =
  114.54    let
  114.55 @@ -912,7 +913,7 @@
  114.56  
  114.57  (**** Evaluator for terms ****)
  114.58  
  114.59 -val eval_result = ref (fn () => Bound 0);
  114.60 +val eval_result = Unsynchronized.ref (fn () => Bound 0);
  114.61  
  114.62  fun eval_term thy t =
  114.63    let
   115.1 --- a/src/Pure/context.ML	Tue Sep 29 14:26:33 2009 +1000
   115.2 +++ b/src/Pure/context.ML	Tue Sep 29 18:14:08 2009 +0200
   115.3 @@ -107,7 +107,7 @@
   115.4    extend: Object.T -> Object.T,
   115.5    merge: Pretty.pp -> Object.T * Object.T -> Object.T};
   115.6  
   115.7 -val kinds = ref (Datatab.empty: kind Datatab.table);
   115.8 +val kinds = Unsynchronized.ref (Datatab.empty: kind Datatab.table);
   115.9  
  115.10  fun invoke f k =
  115.11    (case Datatab.lookup (! kinds) k of
  115.12 @@ -125,7 +125,7 @@
  115.13    let
  115.14      val k = serial ();
  115.15      val kind = {empty = empty, copy = copy, extend = extend, merge = merge};
  115.16 -    val _ = CRITICAL (fn () => change kinds (Datatab.update (k, kind)));
  115.17 +    val _ = CRITICAL (fn () => Unsynchronized.change kinds (Datatab.update (k, kind)));
  115.18    in k end;
  115.19  
  115.20  val copy_data = Datatab.map' invoke_copy;
  115.21 @@ -149,7 +149,7 @@
  115.22  datatype theory =
  115.23    Theory of
  115.24     (*identity*)
  115.25 -   {self: theory ref option,      (*dynamic self reference -- follows theory changes*)
  115.26 +   {self: theory Unsynchronized.ref option,  (*dynamic self reference -- follows theory changes*)
  115.27      draft: bool,                  (*draft mode -- linear destructive changes*)
  115.28      id: serial,                   (*identifier*)
  115.29      ids: unit Inttab.table} *     (*cumulative identifiers of non-drafts -- symbolic body content*)
  115.30 @@ -186,14 +186,15 @@
  115.31  fun eq_id (i: int, j) = i = j;
  115.32  
  115.33  fun is_stale
  115.34 -    (Theory ({self = SOME (ref (Theory ({id = id', ...}, _, _, _))), id, ...}, _, _, _)) =
  115.35 +    (Theory ({self =
  115.36 +        SOME (Unsynchronized.ref (Theory ({id = id', ...}, _, _, _))), id, ...}, _, _, _)) =
  115.37        not (eq_id (id, id'))
  115.38    | is_stale (Theory ({self = NONE, ...}, _, _, _)) = true;
  115.39  
  115.40  fun vitalize (thy as Theory ({self = SOME r, ...}, _, _, _)) = (r := thy; thy)
  115.41    | vitalize (thy as Theory ({self = NONE, draft, id, ids}, data, ancestry, history)) =
  115.42        let
  115.43 -        val r = ref thy;
  115.44 +        val r = Unsynchronized.ref thy;
  115.45          val thy' = Theory (make_identity (SOME r) draft id ids, data, ancestry, history);
  115.46        in r := thy'; thy' end;
  115.47  
  115.48 @@ -243,9 +244,9 @@
  115.49    theory in external data structures -- a plain theory value would
  115.50    become stale as the self reference moves on*)
  115.51  
  115.52 -datatype theory_ref = TheoryRef of theory ref;
  115.53 +datatype theory_ref = TheoryRef of theory Unsynchronized.ref;
  115.54  
  115.55 -fun deref (TheoryRef (ref thy)) = thy;
  115.56 +fun deref (TheoryRef (Unsynchronized.ref thy)) = thy;
  115.57  
  115.58  fun check_thy thy =  (*thread-safe version*)
  115.59    let val thy_ref = TheoryRef (the_self thy) in
  115.60 @@ -437,7 +438,7 @@
  115.61  
  115.62  local
  115.63  
  115.64 -val kinds = ref (Datatab.empty: (theory -> Object.T) Datatab.table);
  115.65 +val kinds = Unsynchronized.ref (Datatab.empty: (theory -> Object.T) Datatab.table);
  115.66  
  115.67  fun invoke_init k =
  115.68    (case Datatab.lookup (! kinds) k of
  115.69 @@ -470,7 +471,7 @@
  115.70  fun declare init =
  115.71    let
  115.72      val k = serial ();
  115.73 -    val _ = CRITICAL (fn () => change kinds (Datatab.update (k, init)));
  115.74 +    val _ = CRITICAL (fn () => Unsynchronized.change kinds (Datatab.update (k, init)));
  115.75    in k end;
  115.76  
  115.77  fun get k dest prf =
   116.1 --- a/src/Pure/display.ML	Tue Sep 29 14:26:33 2009 +1000
   116.2 +++ b/src/Pure/display.ML	Tue Sep 29 18:14:08 2009 +0200
   116.3 @@ -7,10 +7,10 @@
   116.4  
   116.5  signature BASIC_DISPLAY =
   116.6  sig
   116.7 -  val goals_limit: int ref
   116.8 -  val show_consts: bool ref
   116.9 -  val show_hyps: bool ref
  116.10 -  val show_tags: bool ref
  116.11 +  val goals_limit: int Unsynchronized.ref
  116.12 +  val show_consts: bool Unsynchronized.ref
  116.13 +  val show_hyps: bool Unsynchronized.ref
  116.14 +  val show_tags: bool Unsynchronized.ref
  116.15  end;
  116.16  
  116.17  signature DISPLAY =
  116.18 @@ -39,8 +39,8 @@
  116.19  val goals_limit = Goal_Display.goals_limit;
  116.20  val show_consts = Goal_Display.show_consts;
  116.21  
  116.22 -val show_hyps = ref false;      (*false: print meta-hypotheses as dots*)
  116.23 -val show_tags = ref false;      (*false: suppress tags*)
  116.24 +val show_hyps = Unsynchronized.ref false;    (*false: print meta-hypotheses as dots*)
  116.25 +val show_tags = Unsynchronized.ref false;    (*false: suppress tags*)
  116.26  
  116.27  
  116.28  
   117.1 --- a/src/Pure/goal.ML	Tue Sep 29 14:26:33 2009 +1000
   117.2 +++ b/src/Pure/goal.ML	Tue Sep 29 18:14:08 2009 +0200
   117.3 @@ -6,7 +6,7 @@
   117.4  
   117.5  signature BASIC_GOAL =
   117.6  sig
   117.7 -  val parallel_proofs: int ref
   117.8 +  val parallel_proofs: int Unsynchronized.ref
   117.9    val SELECT_GOAL: tactic -> int -> tactic
  117.10    val CONJUNCTS: tactic -> int -> tactic
  117.11    val PRECISE_CONJUNCTS: int -> tactic -> int -> tactic
  117.12 @@ -102,7 +102,7 @@
  117.13  
  117.14  (* future_enabled *)
  117.15  
  117.16 -val parallel_proofs = ref 1;
  117.17 +val parallel_proofs = Unsynchronized.ref 1;
  117.18  
  117.19  fun future_enabled () =
  117.20    Multithreading.enabled () andalso Future.is_worker () andalso ! parallel_proofs >= 1;
   118.1 --- a/src/Pure/goal_display.ML	Tue Sep 29 14:26:33 2009 +1000
   118.2 +++ b/src/Pure/goal_display.ML	Tue Sep 29 18:14:08 2009 +0200
   118.3 @@ -7,8 +7,8 @@
   118.4  
   118.5  signature GOAL_DISPLAY =
   118.6  sig
   118.7 -  val goals_limit: int ref
   118.8 -  val show_consts: bool ref
   118.9 +  val goals_limit: int Unsynchronized.ref
  118.10 +  val show_consts: bool Unsynchronized.ref
  118.11    val pretty_flexpair: Proof.context -> term * term -> Pretty.T
  118.12    val pretty_goals: Proof.context -> {total: bool, main: bool, maxgoals: int} ->
  118.13      thm -> Pretty.T list
  118.14 @@ -18,8 +18,8 @@
  118.15  structure Goal_Display: GOAL_DISPLAY =
  118.16  struct
  118.17  
  118.18 -val goals_limit = ref 10;      (*max number of goals to print*)
  118.19 -val show_consts = ref false;   (*true: show consts with types in proof state output*)
  118.20 +val goals_limit = Unsynchronized.ref 10;     (*max number of goals to print*)
  118.21 +val show_consts = Unsynchronized.ref false;  (*true: show consts with types in proof state output*)
  118.22  
  118.23  fun pretty_flexpair ctxt (t, u) = Pretty.block
  118.24    [Syntax.pretty_term ctxt t, Pretty.str " =?=", Pretty.brk 1, Syntax.pretty_term ctxt u];
   119.1 --- a/src/Pure/library.ML	Tue Sep 29 14:26:33 2009 +1000
   119.2 +++ b/src/Pure/library.ML	Tue Sep 29 18:14:08 2009 +0200
   119.3 @@ -57,13 +57,8 @@
   119.4    val andf: ('a -> bool) * ('a -> bool) -> 'a -> bool
   119.5    val exists: ('a -> bool) -> 'a list -> bool
   119.6    val forall: ('a -> bool) -> 'a list -> bool
   119.7 -  val set: bool ref -> bool
   119.8 -  val reset: bool ref -> bool
   119.9 -  val toggle: bool ref -> bool
  119.10 -  val change: 'a ref -> ('a -> 'a) -> unit
  119.11 -  val change_result: 'a ref -> ('a -> 'b * 'a) -> 'b
  119.12 -  val setmp_noncritical: 'a ref -> 'a -> ('b -> 'c) -> 'b -> 'c
  119.13 -  val setmp: 'a ref -> 'a -> ('b -> 'c) -> 'b -> 'c
  119.14 +  val setmp_noncritical: 'a Unsynchronized.ref -> 'a -> ('b -> 'c) -> 'b -> 'c
  119.15 +  val setmp: 'a Unsynchronized.ref -> 'a -> ('b -> 'c) -> 'b -> 'c
  119.16    val setmp_thread_data: 'a Universal.tag -> 'a -> 'a -> ('b -> 'c) -> 'b -> 'c
  119.17  
  119.18    (*lists*)
  119.19 @@ -123,8 +118,6 @@
  119.20    val suffixes: 'a list -> 'a list list
  119.21  
  119.22    (*integers*)
  119.23 -  val inc: int ref -> int
  119.24 -  val dec: int ref -> int
  119.25    val upto: int * int -> int list
  119.26    val downto: int * int -> int list
  119.27    val radixpand: int * int -> int list
  119.28 @@ -326,13 +319,6 @@
  119.29  
  119.30  (* flags *)
  119.31  
  119.32 -fun set flag = (flag := true; true);
  119.33 -fun reset flag = (flag := false; false);
  119.34 -fun toggle flag = (flag := not (! flag); ! flag);
  119.35 -
  119.36 -fun change r f = r := f (! r);
  119.37 -fun change_result r f = let val (x, y) = f (! r) in r := y; x end;
  119.38 -
  119.39  (*temporarily set flag during execution*)
  119.40  fun setmp_noncritical flag value f x =
  119.41    uninterruptible (fn restore_attributes => fn () =>
  119.42 @@ -643,10 +629,6 @@
  119.43  
  119.44  (** integers **)
  119.45  
  119.46 -fun inc i = (i := ! i + (1: int); ! i);
  119.47 -fun dec i = (i := ! i - (1: int); ! i);
  119.48 -
  119.49 -
  119.50  (* lists of integers *)
  119.51  
  119.52  (*make the list [from, from + 1, ..., to]*)
  119.53 @@ -1055,7 +1037,7 @@
  119.54  local
  119.55    val a = 16807.0;
  119.56    val m = 2147483647.0;
  119.57 -  val random_seed = ref 1.0;
  119.58 +  val random_seed = Unsynchronized.ref 1.0;
  119.59  in
  119.60  
  119.61  fun random () = CRITICAL (fn () =>
  119.62 @@ -1121,17 +1103,18 @@
  119.63  val char_vec = Vector.tabulate (62, gensym_char);
  119.64  fun newid n = implode (map (fn i => Vector.sub (char_vec, i)) (radixpand (62, n)));
  119.65  
  119.66 -val gensym_seed = ref (0: int);
  119.67 +val gensym_seed = Unsynchronized.ref (0: int);
  119.68  
  119.69  in
  119.70 -  fun gensym pre = pre ^ newid (NAMED_CRITICAL "gensym" (fn () => inc gensym_seed));
  119.71 +  fun gensym pre =
  119.72 +    pre ^ newid (NAMED_CRITICAL "gensym" (fn () => Unsynchronized.inc gensym_seed));
  119.73  end;
  119.74  
  119.75  
  119.76  (* stamps and serial numbers *)
  119.77  
  119.78 -type stamp = unit ref;
  119.79 -val stamp: unit -> stamp = ref;
  119.80 +type stamp = unit Unsynchronized.ref;
  119.81 +val stamp: unit -> stamp = Unsynchronized.ref;
  119.82  
  119.83  type serial = int;
  119.84  val serial = Multithreading.serial;
   120.1 --- a/src/Pure/meta_simplifier.ML	Tue Sep 29 14:26:33 2009 +1000
   120.2 +++ b/src/Pure/meta_simplifier.ML	Tue Sep 29 18:14:08 2009 +0200
   120.3 @@ -11,9 +11,9 @@
   120.4  
   120.5  signature BASIC_META_SIMPLIFIER =
   120.6  sig
   120.7 -  val debug_simp: bool ref
   120.8 -  val trace_simp: bool ref
   120.9 -  val trace_simp_depth_limit: int ref
  120.10 +  val debug_simp: bool Unsynchronized.ref
  120.11 +  val trace_simp: bool Unsynchronized.ref
  120.12 +  val trace_simp_depth_limit: int Unsynchronized.ref
  120.13    type rrule
  120.14    val eq_rrule: rrule * rrule -> bool
  120.15    type simpset
  120.16 @@ -84,7 +84,7 @@
  120.17     {rules: rrule Net.net,
  120.18      prems: thm list,
  120.19      bounds: int * ((string * typ) * string) list,
  120.20 -    depth: int * bool ref,
  120.21 +    depth: int * bool Unsynchronized.ref,
  120.22      context: Proof.context option} *
  120.23     {congs: (string * thm) list * string list,
  120.24      procs: proc Net.net,
  120.25 @@ -112,7 +112,7 @@
  120.26    val the_context: simpset -> Proof.context
  120.27    val context: Proof.context -> simpset -> simpset
  120.28    val theory_context: theory  -> simpset -> simpset
  120.29 -  val debug_bounds: bool ref
  120.30 +  val debug_bounds: bool Unsynchronized.ref
  120.31    val set_reorient: (theory -> term list -> term -> term -> bool) -> simpset -> simpset
  120.32    val set_solvers: solver list -> simpset -> simpset
  120.33    val rewrite_cterm: bool * bool * bool -> (simpset -> thm -> thm option) -> simpset -> conv
  120.34 @@ -190,7 +190,7 @@
  120.35     {rules: rrule Net.net,
  120.36      prems: thm list,
  120.37      bounds: int * ((string * typ) * string) list,
  120.38 -    depth: int * bool ref,
  120.39 +    depth: int * bool Unsynchronized.ref,
  120.40      context: Proof.context option} *
  120.41     {congs: (string * thm) list * string list,
  120.42      procs: proc Net.net,
  120.43 @@ -256,7 +256,7 @@
  120.44  val simp_depth_limit_value = Config.declare false "simp_depth_limit" (Config.Int 100);
  120.45  val simp_depth_limit = Config.int simp_depth_limit_value;
  120.46  
  120.47 -val trace_simp_depth_limit = ref 1;
  120.48 +val trace_simp_depth_limit = Unsynchronized.ref 1;
  120.49  
  120.50  fun trace_depth (Simpset ({depth = (depth, exceeded), ...}, _)) msg =
  120.51    if depth > ! trace_simp_depth_limit then
  120.52 @@ -266,7 +266,8 @@
  120.53  
  120.54  val inc_simp_depth = map_simpset1 (fn (rules, prems, bounds, (depth, exceeded), context) =>
  120.55    (rules, prems, bounds,
  120.56 -    (depth + 1, if depth = ! trace_simp_depth_limit then ref false else exceeded), context));
  120.57 +    (depth + 1,
  120.58 +      if depth = ! trace_simp_depth_limit then Unsynchronized.ref false else exceeded), context));
  120.59  
  120.60  fun simp_depth (Simpset ({depth = (depth, _), ...}, _)) = depth;
  120.61  
  120.62 @@ -275,8 +276,8 @@
  120.63  
  120.64  exception SIMPLIFIER of string * thm;
  120.65  
  120.66 -val debug_simp = ref false;
  120.67 -val trace_simp = ref false;
  120.68 +val debug_simp = Unsynchronized.ref false;
  120.69 +val trace_simp = Unsynchronized.ref false;
  120.70  
  120.71  local
  120.72  
  120.73 @@ -746,7 +747,7 @@
  120.74  (* empty *)
  120.75  
  120.76  fun init_ss mk_rews termless subgoal_tac solvers =
  120.77 -  make_simpset ((Net.empty, [], (0, []), (0, ref false), NONE),
  120.78 +  make_simpset ((Net.empty, [], (0, []), (0, Unsynchronized.ref false), NONE),
  120.79      (([], []), Net.empty, mk_rews, termless, subgoal_tac, [], solvers));
  120.80  
  120.81  fun clear_ss (ss as Simpset (_, {mk_rews, termless, subgoal_tac, solvers, ...})) =
  120.82 @@ -1209,7 +1210,7 @@
  120.83      prover: how to solve premises in conditional rewrites and congruences
  120.84  *)
  120.85  
  120.86 -val debug_bounds = ref false;
  120.87 +val debug_bounds = Unsynchronized.ref false;
  120.88  
  120.89  fun check_bounds ss ct =
  120.90    if ! debug_bounds then
  120.91 @@ -1337,5 +1338,5 @@
  120.92  
  120.93  end;
  120.94  
  120.95 -structure BasicMetaSimplifier: BASIC_META_SIMPLIFIER = MetaSimplifier;
  120.96 -open BasicMetaSimplifier;
  120.97 +structure Basic_Meta_Simplifier: BASIC_META_SIMPLIFIER = MetaSimplifier;
  120.98 +open Basic_Meta_Simplifier;
   121.1 --- a/src/Pure/old_goals.ML	Tue Sep 29 14:26:33 2009 +1000
   121.2 +++ b/src/Pure/old_goals.ML	Tue Sep 29 18:14:08 2009 +0200
   121.3 @@ -19,7 +19,7 @@
   121.4    type proof
   121.5    val premises: unit -> thm list
   121.6    val reset_goals: unit -> unit
   121.7 -  val result_error_fn: (thm -> string -> thm) ref
   121.8 +  val result_error_fn: (thm -> string -> thm) Unsynchronized.ref
   121.9    val print_sign_exn: theory -> exn -> 'a
  121.10    val prove_goalw_cterm: thm list->cterm->(thm list->tactic list)->thm
  121.11    val prove_goalw_cterm_nocheck: thm list->cterm->(thm list->tactic list)->thm
  121.12 @@ -233,21 +233,21 @@
  121.13  (*** References ***)
  121.14  
  121.15  (*Current assumption list -- set by "goal".*)
  121.16 -val curr_prems = ref([] : thm list);
  121.17 +val curr_prems = Unsynchronized.ref([] : thm list);
  121.18  
  121.19  (*Return assumption list -- useful if you didn't save "goal"'s result. *)
  121.20  fun premises() = !curr_prems;
  121.21  
  121.22  (*Current result maker -- set by "goal", used by "result".  *)
  121.23  fun init_mkresult _ = error "No goal has been supplied in subgoal module";
  121.24 -val curr_mkresult = ref (init_mkresult: bool*thm->thm);
  121.25 +val curr_mkresult = Unsynchronized.ref (init_mkresult: bool*thm->thm);
  121.26  
  121.27  (*List of previous goal stacks, for the undo operation.  Set by setstate.
  121.28    A list of lists!*)
  121.29 -val undo_list = ref([[(asm_rl, Seq.empty)]] : gstack list);
  121.30 +val undo_list = Unsynchronized.ref([[(asm_rl, Seq.empty)]] : gstack list);
  121.31  
  121.32  (* Stack of proof attempts *)
  121.33 -val proofstack = ref([]: proof list);
  121.34 +val proofstack = Unsynchronized.ref([]: proof list);
  121.35  
  121.36  (*reset all refs*)
  121.37  fun reset_goals () =
  121.38 @@ -272,7 +272,7 @@
  121.39        Goal_Display.pretty_goals_without_context (!goals_limit) state @
  121.40      [Pretty.str msg, Pretty.str "Proof failed!"] |> Pretty.chunks |> Pretty.string_of |> error;
  121.41  
  121.42 -val result_error_fn = ref result_error_default;
  121.43 +val result_error_fn = Unsynchronized.ref result_error_default;
  121.44  
  121.45  
  121.46  (*Common treatment of "goal" and "prove_goal":
   122.1 --- a/src/Pure/pattern.ML	Tue Sep 29 14:26:33 2009 +1000
   122.2 +++ b/src/Pure/pattern.ML	Tue Sep 29 18:14:08 2009 +0200
   122.3 @@ -14,7 +14,7 @@
   122.4  
   122.5  signature PATTERN =
   122.6  sig
   122.7 -  val trace_unify_fail: bool ref
   122.8 +  val trace_unify_fail: bool Unsynchronized.ref
   122.9    val aeconv: term * term -> bool
  122.10    val eta_long: typ list -> term -> term
  122.11    val match: theory -> term * term -> Type.tyenv * Envir.tenv -> Type.tyenv * Envir.tenv
  122.12 @@ -40,7 +40,7 @@
  122.13  exception Unif;
  122.14  exception Pattern;
  122.15  
  122.16 -val trace_unify_fail = ref false;
  122.17 +val trace_unify_fail = Unsynchronized.ref false;
  122.18  
  122.19  fun string_of_term thy env binders t =
  122.20    Syntax.string_of_term_global thy
   123.1 --- a/src/Pure/proofterm.ML	Tue Sep 29 14:26:33 2009 +1000
   123.2 +++ b/src/Pure/proofterm.ML	Tue Sep 29 18:14:08 2009 +0200
   123.3 @@ -8,7 +8,7 @@
   123.4  
   123.5  signature BASIC_PROOFTERM =
   123.6  sig
   123.7 -  val proofs: int ref
   123.8 +  val proofs: int Unsynchronized.ref
   123.9  
  123.10    datatype proof =
  123.11       MinProof
  123.12 @@ -885,7 +885,7 @@
  123.13  
  123.14  (***** axioms and theorems *****)
  123.15  
  123.16 -val proofs = ref 2;
  123.17 +val proofs = Unsynchronized.ref 2;
  123.18  
  123.19  fun vars_of t = map Var (rev (Term.add_vars t []));
  123.20  fun frees_of t = map Free (rev (Term.add_frees t []));
   124.1 --- a/src/Pure/search.ML	Tue Sep 29 14:26:33 2009 +1000
   124.2 +++ b/src/Pure/search.ML	Tue Sep 29 18:14:08 2009 +0200
   124.3 @@ -13,23 +13,23 @@
   124.4    val THEN_MAYBE        : tactic * tactic -> tactic
   124.5    val THEN_MAYBE'       : ('a -> tactic) * ('a -> tactic) -> ('a -> tactic)
   124.6  
   124.7 -  val trace_DEPTH_FIRST : bool ref
   124.8 +  val trace_DEPTH_FIRST : bool Unsynchronized.ref
   124.9    val DEPTH_FIRST       : (thm -> bool) -> tactic -> tactic
  124.10    val DEPTH_SOLVE       : tactic -> tactic
  124.11    val DEPTH_SOLVE_1     : tactic -> tactic
  124.12    val ITER_DEEPEN       : (thm->bool) -> (int->tactic) -> tactic
  124.13    val THEN_ITER_DEEPEN  : tactic -> (thm->bool) -> (int->tactic) -> tactic
  124.14 -  val iter_deepen_limit : int ref
  124.15 +  val iter_deepen_limit : int Unsynchronized.ref
  124.16  
  124.17    val has_fewer_prems   : int -> thm -> bool
  124.18    val IF_UNSOLVED       : tactic -> tactic
  124.19    val SOLVE             : tactic -> tactic
  124.20    val DETERM_UNTIL_SOLVED: tactic -> tactic
  124.21 -  val trace_BEST_FIRST  : bool ref
  124.22 +  val trace_BEST_FIRST  : bool Unsynchronized.ref
  124.23    val BEST_FIRST        : (thm -> bool) * (thm -> int) -> tactic -> tactic
  124.24    val THEN_BEST_FIRST   : tactic -> (thm->bool) * (thm->int) -> tactic
  124.25                            -> tactic
  124.26 -  val trace_ASTAR       : bool ref
  124.27 +  val trace_ASTAR       : bool Unsynchronized.ref
  124.28    val ASTAR             : (thm -> bool) * (int->thm->int) -> tactic -> tactic
  124.29    val THEN_ASTAR        : tactic -> (thm->bool) * (int->thm->int) -> tactic
  124.30                            -> tactic
  124.31 @@ -50,7 +50,7 @@
  124.32  
  124.33  (**** Depth-first search ****)
  124.34  
  124.35 -val trace_DEPTH_FIRST = ref false;
  124.36 +val trace_DEPTH_FIRST = Unsynchronized.ref false;
  124.37  
  124.38  (*Searches until "satp" reports proof tree as satisfied.
  124.39    Suppresses duplicate solutions to minimize search space.*)
  124.40 @@ -130,7 +130,7 @@
  124.41  
  124.42  
  124.43  (*No known example (on 1-5-2007) needs even thirty*)
  124.44 -val iter_deepen_limit = ref 50;
  124.45 +val iter_deepen_limit = Unsynchronized.ref 50;
  124.46  
  124.47  (*Depth-first iterative deepening search for a state that satisfies satp
  124.48    tactic tac0 sets up the initial goal queue, while tac1 searches it.
  124.49 @@ -138,7 +138,7 @@
  124.50    to suppress solutions arising from earlier searches, as the accumulated cost
  124.51    (k) can be wrong.*)
  124.52  fun THEN_ITER_DEEPEN tac0 satp tac1 = traced_tac (fn st =>
  124.53 - let val countr = ref 0
  124.54 + let val countr = Unsynchronized.ref 0
  124.55       and tf = tracify trace_DEPTH_FIRST (tac1 1)
  124.56       and qs0 = tac0 st
  124.57       (*bnd = depth bound; inc = estimate of increment required next*)
  124.58 @@ -156,7 +156,7 @@
  124.59         | depth (bnd,inc) ((k,np,rgd,q)::qs) =
  124.60            if k>=bnd then depth (bnd,inc) qs
  124.61            else
  124.62 -          case (countr := !countr+1;
  124.63 +          case (Unsynchronized.inc countr;
  124.64                  if !trace_DEPTH_FIRST then
  124.65                      tracing (string_of_int np ^ implode (map (fn _ => "*") qs))
  124.66                  else ();
  124.67 @@ -199,7 +199,7 @@
  124.68  
  124.69  (*** Best-first search ***)
  124.70  
  124.71 -val trace_BEST_FIRST = ref false;
  124.72 +val trace_BEST_FIRST = Unsynchronized.ref false;
  124.73  
  124.74  (*For creating output sequence*)
  124.75  fun some_of_list []     = NONE
  124.76 @@ -273,7 +273,7 @@
  124.77  fun some_of_list []     = NONE
  124.78    | some_of_list (x::l) = SOME (x, Seq.make (fn () => some_of_list l));
  124.79  
  124.80 -val trace_ASTAR = ref false;
  124.81 +val trace_ASTAR = Unsynchronized.ref false;
  124.82  
  124.83  fun THEN_ASTAR tac0 (satp, costf) tac1 =
  124.84    let val tf = tracify trace_ASTAR tac1;
   125.1 --- a/src/Pure/simplifier.ML	Tue Sep 29 14:26:33 2009 +1000
   125.2 +++ b/src/Pure/simplifier.ML	Tue Sep 29 18:14:08 2009 +0200
   125.3 @@ -32,7 +32,7 @@
   125.4    include BASIC_SIMPLIFIER
   125.5    val pretty_ss: Proof.context -> simpset -> Pretty.T
   125.6    val clear_ss: simpset -> simpset
   125.7 -  val debug_bounds: bool ref
   125.8 +  val debug_bounds: bool Unsynchronized.ref
   125.9    val inherit_context: simpset -> simpset -> simpset
  125.10    val the_context: simpset -> Proof.context
  125.11    val context: Proof.context -> simpset -> simpset
  125.12 @@ -424,5 +424,5 @@
  125.13  
  125.14  end;
  125.15  
  125.16 -structure BasicSimplifier: BASIC_SIMPLIFIER = Simplifier;
  125.17 -open BasicSimplifier;
  125.18 +structure Basic_Simplifier: BASIC_SIMPLIFIER = Simplifier;
  125.19 +open Basic_Simplifier;
   126.1 --- a/src/Pure/tactical.ML	Tue Sep 29 14:26:33 2009 +1000
   126.2 +++ b/src/Pure/tactical.ML	Tue Sep 29 18:14:08 2009 +0200
   126.3 @@ -34,9 +34,9 @@
   126.4    val RANGE: (int -> tactic) list -> int -> tactic
   126.5    val print_tac: string -> tactic
   126.6    val pause_tac: tactic
   126.7 -  val trace_REPEAT: bool ref
   126.8 -  val suppress_tracing: bool ref
   126.9 -  val tracify: bool ref -> tactic -> tactic
  126.10 +  val trace_REPEAT: bool Unsynchronized.ref
  126.11 +  val suppress_tracing: bool Unsynchronized.ref
  126.12 +  val tracify: bool Unsynchronized.ref -> tactic -> tactic
  126.13    val traced_tac: (thm -> (thm * thm Seq.seq) option) -> tactic
  126.14    val DETERM_UNTIL: (thm -> bool) -> tactic -> tactic
  126.15    val REPEAT_DETERM_N: int -> tactic -> tactic
  126.16 @@ -204,16 +204,16 @@
  126.17  and TRACE_QUIT;
  126.18  
  126.19  (*Tracing flags*)
  126.20 -val trace_REPEAT= ref false
  126.21 -and suppress_tracing = ref false;
  126.22 +val trace_REPEAT= Unsynchronized.ref false
  126.23 +and suppress_tracing = Unsynchronized.ref false;
  126.24  
  126.25  (*Handle all tracing commands for current state and tactic *)
  126.26  fun exec_trace_command flag (tac, st) =
  126.27     case TextIO.inputLine TextIO.stdIn of
  126.28         SOME "\n" => tac st
  126.29       | SOME "f\n" => Seq.empty
  126.30 -     | SOME "o\n" => (flag:=false;  tac st)
  126.31 -     | SOME "s\n" => (suppress_tracing:=true;  tac st)
  126.32 +     | SOME "o\n" => (flag := false;  tac st)
  126.33 +     | SOME "s\n" => (suppress_tracing := true;  tac st)
  126.34       | SOME "x\n" => (tracing "Exiting now";  raise (TRACE_EXIT st))
  126.35       | SOME "quit\n" => raise TRACE_QUIT
  126.36       | _     => (tracing
   127.1 --- a/src/Pure/term.ML	Tue Sep 29 14:26:33 2009 +1000
   127.2 +++ b/src/Pure/term.ML	Tue Sep 29 18:14:08 2009 +0200
   127.3 @@ -112,7 +112,7 @@
   127.4    val exists_type: (typ -> bool) -> term -> bool
   127.5    val exists_subterm: (term -> bool) -> term -> bool
   127.6    val exists_Const: (string * typ -> bool) -> term -> bool
   127.7 -  val show_question_marks: bool ref
   127.8 +  val show_question_marks: bool Unsynchronized.ref
   127.9  end;
  127.10  
  127.11  signature TERM =
  127.12 @@ -963,7 +963,7 @@
  127.13  
  127.14  (* display variables *)
  127.15  
  127.16 -val show_question_marks = ref true;
  127.17 +val show_question_marks = Unsynchronized.ref true;
  127.18  
  127.19  fun string_of_vname (x, i) =
  127.20    let
   128.1 --- a/src/Pure/term_subst.ML	Tue Sep 29 14:26:33 2009 +1000
   128.2 +++ b/src/Pure/term_subst.ML	Tue Sep 29 18:14:08 2009 +0200
   128.3 @@ -157,28 +157,32 @@
   128.4  in
   128.5  
   128.6  fun instantiateT_maxidx instT ty i =
   128.7 -  let val maxidx = ref i
   128.8 +  let val maxidx = Unsynchronized.ref i
   128.9    in (instantiateT_same maxidx instT ty handle Same.SAME => ty, ! maxidx) end;
  128.10  
  128.11  fun instantiate_maxidx insts tm i =
  128.12 -  let val maxidx = ref i
  128.13 +  let val maxidx = Unsynchronized.ref i
  128.14    in (instantiate_same maxidx insts tm handle Same.SAME => tm, ! maxidx) end;
  128.15  
  128.16  fun instantiateT [] ty = ty
  128.17    | instantiateT instT ty =
  128.18 -      (instantiateT_same (ref ~1) (no_indexes1 instT) ty handle Same.SAME => ty);
  128.19 +      (instantiateT_same (Unsynchronized.ref ~1) (no_indexes1 instT) ty
  128.20 +        handle Same.SAME => ty);
  128.21  
  128.22  fun instantiate ([], []) tm = tm
  128.23    | instantiate insts tm =
  128.24 -      (instantiate_same (ref ~1) (no_indexes2 insts) tm handle Same.SAME => tm);
  128.25 +      (instantiate_same (Unsynchronized.ref ~1) (no_indexes2 insts) tm
  128.26 +        handle Same.SAME => tm);
  128.27  
  128.28  fun instantiateT_option [] _ = NONE
  128.29    | instantiateT_option instT ty =
  128.30 -      (SOME (instantiateT_same (ref ~1) (no_indexes1 instT) ty) handle Same.SAME => NONE);
  128.31 +      (SOME (instantiateT_same (Unsynchronized.ref ~1) (no_indexes1 instT) ty)
  128.32 +        handle Same.SAME => NONE);
  128.33  
  128.34  fun instantiate_option ([], []) _ = NONE
  128.35    | instantiate_option insts tm =
  128.36 -      (SOME (instantiate_same (ref ~1) (no_indexes2 insts) tm) handle Same.SAME => NONE);
  128.37 +      (SOME (instantiate_same (Unsynchronized.ref ~1) (no_indexes2 insts) tm)
  128.38 +        handle Same.SAME => NONE);
  128.39  
  128.40  end;
  128.41  
   129.1 --- a/src/Pure/type.ML	Tue Sep 29 14:26:33 2009 +1000
   129.2 +++ b/src/Pure/type.ML	Tue Sep 29 18:14:08 2009 +0200
   129.3 @@ -417,8 +417,8 @@
   129.4  (*order-sorted unification*)
   129.5  fun unify (tsig as TSig {classes = (_, classes), ...}) TU (tyenv, maxidx) =
   129.6    let
   129.7 -    val tyvar_count = ref maxidx;
   129.8 -    fun gen_tyvar S = TVar ((Name.aT, inc tyvar_count), S);
   129.9 +    val tyvar_count = Unsynchronized.ref maxidx;
  129.10 +    fun gen_tyvar S = TVar ((Name.aT, Unsynchronized.inc tyvar_count), S);
  129.11  
  129.12      fun mg_domain a S = Sorts.mg_domain classes a S
  129.13        handle Sorts.CLASS_ERROR _ => raise TUNIFY;
   130.1 --- a/src/Pure/unify.ML	Tue Sep 29 14:26:33 2009 +1000
   130.2 +++ b/src/Pure/unify.ML	Tue Sep 29 18:14:08 2009 +0200
   130.3 @@ -106,7 +106,7 @@
   130.4    the occurs check must ignore the types of variables. This avoids
   130.5    that ?x::?'a is unified with f(?x::T), which may lead to a cyclic
   130.6    substitution when ?'a is instantiated with T later. *)
   130.7 -fun occurs_terms (seen: (indexname list) ref,
   130.8 +fun occurs_terms (seen: (indexname list) Unsynchronized.ref,
   130.9        env: Envir.env, v: indexname, ts: term list): bool =
  130.10    let fun occurs [] = false
  130.11    | occurs (t::ts) =  occur t  orelse  occurs ts
  130.12 @@ -160,7 +160,7 @@
  130.13  Warning: finds a rigid occurrence of ?f in ?f(t).
  130.14    Should NOT be called in this case: there is a flex-flex unifier
  130.15  *)
  130.16 -fun rigid_occurs_term (seen: (indexname list)ref, env, v: indexname, t) =
  130.17 +fun rigid_occurs_term (seen: (indexname list) Unsynchronized.ref, env, v: indexname, t) =
  130.18    let fun nonrigid t = if occurs_terms(seen,env,v,[t]) then Nonrigid
  130.19             else NoOcc
  130.20        fun occurs [] = NoOcc
  130.21 @@ -230,7 +230,7 @@
  130.22    If v occurs nonrigidly then must use full algorithm. *)
  130.23  fun assignment thy (env, rbinder, t, u) =
  130.24      let val vT as (v,T) = get_eta_var (rbinder, 0, t)
  130.25 -    in  case rigid_occurs_term (ref [], env, v, u) of
  130.26 +    in  case rigid_occurs_term (Unsynchronized.ref [], env, v, u) of
  130.27          NoOcc => let val env = unify_types thy (body_type env T,
  130.28               fastype env (rbinder,u),env)
  130.29      in Envir.update ((vT, Logic.rlist_abs (rbinder, u)), env) end
  130.30 @@ -429,7 +429,7 @@
  130.31    Attempts to update t with u, raising ASSIGN if impossible*)
  130.32  fun ff_assign thy (env, rbinder, t, u) : Envir.env =
  130.33  let val vT as (v,T) = get_eta_var(rbinder,0,t)
  130.34 -in if occurs_terms (ref [], env, v, [u]) then raise ASSIGN
  130.35 +in if occurs_terms (Unsynchronized.ref [], env, v, [u]) then raise ASSIGN
  130.36     else let val env = unify_types thy (body_type env T,
  130.37            fastype env (rbinder,u),
  130.38            env)
   131.1 --- a/src/Sequents/prover.ML	Tue Sep 29 14:26:33 2009 +1000
   131.2 +++ b/src/Sequents/prover.ML	Tue Sep 29 18:14:08 2009 +0200
   131.3 @@ -10,12 +10,11 @@
   131.4  infix 4 add_safes add_unsafes;
   131.5  
   131.6  structure Cla =
   131.7 -
   131.8  struct
   131.9  
  131.10  datatype pack = Pack of thm list * thm list;
  131.11  
  131.12 -val trace = ref false;
  131.13 +val trace = Unsynchronized.ref false;
  131.14  
  131.15  (*A theorem pack has the form  (safe rules, unsafe rules)
  131.16    An unsafe rule is incomplete or introduces variables in subgoals,
   132.1 --- a/src/Tools/Code/code_ml.ML	Tue Sep 29 14:26:33 2009 +1000
   132.2 +++ b/src/Tools/Code/code_ml.ML	Tue Sep 29 18:14:08 2009 +0200
   132.3 @@ -6,7 +6,7 @@
   132.4  
   132.5  signature CODE_ML =
   132.6  sig
   132.7 -  val eval: string option -> string * (unit -> 'a) option ref
   132.8 +  val eval: string option -> string * (unit -> 'a) option Unsynchronized.ref
   132.9      -> ((term -> term) -> 'a -> 'a) -> theory -> term -> string list -> 'a
  132.10    val target_Eval: string
  132.11    val setup: theory -> theory
   133.1 --- a/src/Tools/Code/code_target.ML	Tue Sep 29 14:26:33 2009 +1000
   133.2 +++ b/src/Tools/Code/code_target.ML	Tue Sep 29 18:14:08 2009 +0200
   133.3 @@ -38,7 +38,7 @@
   133.4    val code_of: theory -> string -> string
   133.5      -> string list -> (Code_Thingol.naming -> string list) -> string
   133.6    val shell_command: string (*theory name*) -> string (*export_code expr*) -> unit
   133.7 -  val code_width: int ref
   133.8 +  val code_width: int Unsynchronized.ref
   133.9  
  133.10    val allow_abort: string -> theory -> theory
  133.11    val add_syntax_class: string -> class -> string option -> theory -> theory
  133.12 @@ -59,7 +59,7 @@
  133.13  datatype destination = Compile | Export | File of Path.T | String of string list;
  133.14  type serialization = destination -> (string * string option list) option;
  133.15  
  133.16 -val code_width = ref 80; (*FIXME after Pretty module no longer depends on print mode*)
  133.17 +val code_width = Unsynchronized.ref 80; (*FIXME after Pretty module no longer depends on print mode*)
  133.18  fun code_setmp f = PrintMode.setmp [] (Pretty.setmp_margin (!code_width) f);
  133.19  fun code_of_pretty p = code_setmp Pretty.string_of p ^ "\n";
  133.20  fun code_writeln p = Pretty.setmp_margin (!code_width) Pretty.writeln p;
   134.1 --- a/src/Tools/Compute_Oracle/am_compiler.ML	Tue Sep 29 14:26:33 2009 +1000
   134.2 +++ b/src/Tools/Compute_Oracle/am_compiler.ML	Tue Sep 29 18:14:08 2009 +0200
   134.3 @@ -18,7 +18,7 @@
   134.4  
   134.5  open AbstractMachine;
   134.6  
   134.7 -val compiled_rewriter = ref (NONE:(term -> term)Option.option)
   134.8 +val compiled_rewriter = Unsynchronized.ref (NONE:(term -> term)Option.option)
   134.9  
  134.10  fun set_compiled_rewriter r = (compiled_rewriter := SOME r)
  134.11  
  134.12 @@ -81,7 +81,7 @@
  134.13      
  134.14  fun load_rules sname name prog = 
  134.15      let
  134.16 -	val buffer = ref ""
  134.17 +	val buffer = Unsynchronized.ref ""
  134.18  	fun write s = (buffer := (!buffer)^s)
  134.19  	fun writeln s = (write s; write "\n")
  134.20  	fun writelist [] = ()
  134.21 @@ -112,7 +112,7 @@
  134.22  		"",
  134.23  		"fun do_reduction reduce p =",
  134.24  		"    let",
  134.25 -		"       val s = ref (Continue p)",
  134.26 +		"       val s = Unsynchronized.ref (Continue p)",
  134.27  		"       val _ = while cont (!s) do (s := reduce (proj_C (!s)))",
  134.28  		"   in",
  134.29  		"       proj_S (!s)",
   135.1 --- a/src/Tools/Compute_Oracle/am_ghc.ML	Tue Sep 29 14:26:33 2009 +1000
   135.2 +++ b/src/Tools/Compute_Oracle/am_ghc.ML	Tue Sep 29 18:14:08 2009 +0200
   135.3 @@ -144,7 +144,7 @@
   135.4  
   135.5  fun haskell_prog name rules = 
   135.6      let
   135.7 -	val buffer = ref ""
   135.8 +	val buffer = Unsynchronized.ref ""
   135.9  	fun write s = (buffer := (!buffer)^s)
  135.10  	fun writeln s = (write s; write "\n")
  135.11  	fun writelist [] = ()
  135.12 @@ -200,7 +200,7 @@
  135.13  	(arity, !buffer)
  135.14      end
  135.15  
  135.16 -val guid_counter = ref 0
  135.17 +val guid_counter = Unsynchronized.ref 0
  135.18  fun get_guid () = 
  135.19      let
  135.20  	val c = !guid_counter
  135.21 @@ -214,7 +214,7 @@
  135.22  
  135.23  fun writeTextFile name s = File.write (Path.explode name) s
  135.24      
  135.25 -val ghc = ref (case getenv "GHC_PATH" of "" => "ghc" | s => s)
  135.26 +val ghc = Unsynchronized.ref (case getenv "GHC_PATH" of "" => "ghc" | s => s)
  135.27  
  135.28  fun fileExists name = ((OS.FileSys.fileSize name; true) handle OS.SysErr _ => false)
  135.29  
   136.1 --- a/src/Tools/Compute_Oracle/am_interpreter.ML	Tue Sep 29 14:26:33 2009 +1000
   136.2 +++ b/src/Tools/Compute_Oracle/am_interpreter.ML	Tue Sep 29 18:14:08 2009 +0200
   136.3 @@ -5,7 +5,7 @@
   136.4  signature AM_BARRAS = 
   136.5  sig
   136.6    include ABSTRACT_MACHINE
   136.7 -  val max_reductions : int option ref
   136.8 +  val max_reductions : int option Unsynchronized.ref
   136.9  end
  136.10  
  136.11  structure AM_Interpreter : AM_BARRAS = struct
  136.12 @@ -129,12 +129,12 @@
  136.13  fun cont (Continue _) = true
  136.14    | cont _ = false
  136.15  
  136.16 -val max_reductions = ref (NONE : int option)
  136.17 +val max_reductions = Unsynchronized.ref (NONE : int option)
  136.18  
  136.19  fun do_reduction reduce p =
  136.20      let
  136.21 -	val s = ref (Continue p)
  136.22 -	val counter = ref 0
  136.23 +	val s = Unsynchronized.ref (Continue p)
  136.24 +	val counter = Unsynchronized.ref 0
  136.25  	val _ = case !max_reductions of 
  136.26  		    NONE => while cont (!s) do (s := reduce (proj_C (!s)))
  136.27  		  | SOME m => while cont (!s) andalso (!counter < m) do (s := reduce (proj_C (!s)); counter := (!counter) + 1)
   137.1 --- a/src/Tools/Compute_Oracle/am_sml.ML	Tue Sep 29 14:26:33 2009 +1000
   137.2 +++ b/src/Tools/Compute_Oracle/am_sml.ML	Tue Sep 29 18:14:08 2009 +0200
   137.3 @@ -12,18 +12,18 @@
   137.4    val save_result : (string * term) -> unit
   137.5    val set_compiled_rewriter : (term -> term) -> unit				       
   137.6    val list_nth : 'a list * int -> 'a
   137.7 -  val dump_output : (string option) ref 
   137.8 +  val dump_output : (string option) Unsynchronized.ref 
   137.9  end
  137.10  
  137.11  structure AM_SML : AM_SML = struct
  137.12  
  137.13  open AbstractMachine;
  137.14  
  137.15 -val dump_output = ref (NONE: string option)
  137.16 +val dump_output = Unsynchronized.ref (NONE: string option)
  137.17  
  137.18  type program = string * string * (int Inttab.table) * (int Inttab.table) * (term Inttab.table) * (term -> term)
  137.19  
  137.20 -val saved_result = ref (NONE:(string*term)option)
  137.21 +val saved_result = Unsynchronized.ref (NONE:(string*term)option)
  137.22  
  137.23  fun save_result r = (saved_result := SOME r)
  137.24  fun clear_result () = (saved_result := NONE)
  137.25 @@ -32,7 +32,7 @@
  137.26  
  137.27  (*fun list_nth (l,n) = (writeln (makestring ("list_nth", (length l,n))); List.nth (l,n))*)
  137.28  
  137.29 -val compiled_rewriter = ref (NONE:(term -> term)Option.option)
  137.30 +val compiled_rewriter = Unsynchronized.ref (NONE:(term -> term)Option.option)
  137.31  
  137.32  fun set_compiled_rewriter r = (compiled_rewriter := SOME r)
  137.33  
  137.34 @@ -295,7 +295,7 @@
  137.35  
  137.36  fun sml_prog name code rules = 
  137.37      let
  137.38 -	val buffer = ref ""
  137.39 +	val buffer = Unsynchronized.ref ""
  137.40  	fun write s = (buffer := (!buffer)^s)
  137.41  	fun writeln s = (write s; write "\n")
  137.42  	fun writelist [] = ()
  137.43 @@ -480,7 +480,7 @@
  137.44  	(arity, toplevel_arity, inlinetab, !buffer)
  137.45      end
  137.46  
  137.47 -val guid_counter = ref 0
  137.48 +val guid_counter = Unsynchronized.ref 0
  137.49  fun get_guid () = 
  137.50      let
  137.51  	val c = !guid_counter
   138.1 --- a/src/Tools/Compute_Oracle/compute.ML	Tue Sep 29 14:26:33 2009 +1000
   138.2 +++ b/src/Tools/Compute_Oracle/compute.ML	Tue Sep 29 18:14:08 2009 +0200
   138.3 @@ -171,20 +171,21 @@
   138.4  
   138.5  fun default_naming i = "v_" ^ Int.toString i
   138.6  
   138.7 -datatype computer = Computer of (theory_ref * Encode.encoding * term list * unit Sorttab.table * prog * unit ref * naming) 
   138.8 -                    option ref
   138.9 +datatype computer = Computer of
  138.10 +  (theory_ref * Encode.encoding * term list * unit Sorttab.table * prog * unit Unsynchronized.ref * naming)
  138.11 +    option Unsynchronized.ref
  138.12  
  138.13 -fun theory_of (Computer (ref (SOME (rthy,_,_,_,_,_,_)))) = Theory.deref rthy
  138.14 -fun hyps_of (Computer (ref (SOME (_,_,hyps,_,_,_,_)))) = hyps
  138.15 -fun shyps_of (Computer (ref (SOME (_,_,_,shyptable,_,_,_)))) = Sorttab.keys (shyptable)
  138.16 -fun shyptab_of (Computer (ref (SOME (_,_,_,shyptable,_,_,_)))) = shyptable
  138.17 -fun stamp_of (Computer (ref (SOME (_,_,_,_,_,stamp,_)))) = stamp
  138.18 -fun prog_of (Computer (ref (SOME (_,_,_,_,prog,_,_)))) = prog
  138.19 -fun encoding_of (Computer (ref (SOME (_,encoding,_,_,_,_,_)))) = encoding
  138.20 -fun set_encoding (Computer (r as ref (SOME (p1,encoding,p2,p3,p4,p5,p6)))) encoding' = 
  138.21 +fun theory_of (Computer (Unsynchronized.ref (SOME (rthy,_,_,_,_,_,_)))) = Theory.deref rthy
  138.22 +fun hyps_of (Computer (Unsynchronized.ref (SOME (_,_,hyps,_,_,_,_)))) = hyps
  138.23 +fun shyps_of (Computer (Unsynchronized.ref (SOME (_,_,_,shyptable,_,_,_)))) = Sorttab.keys (shyptable)
  138.24 +fun shyptab_of (Computer (Unsynchronized.ref (SOME (_,_,_,shyptable,_,_,_)))) = shyptable
  138.25 +fun stamp_of (Computer (Unsynchronized.ref (SOME (_,_,_,_,_,stamp,_)))) = stamp
  138.26 +fun prog_of (Computer (Unsynchronized.ref (SOME (_,_,_,_,prog,_,_)))) = prog
  138.27 +fun encoding_of (Computer (Unsynchronized.ref (SOME (_,encoding,_,_,_,_,_)))) = encoding
  138.28 +fun set_encoding (Computer (r as Unsynchronized.ref (SOME (p1,encoding,p2,p3,p4,p5,p6)))) encoding' = 
  138.29      (r := SOME (p1,encoding',p2,p3,p4,p5,p6))
  138.30 -fun naming_of (Computer (ref (SOME (_,_,_,_,_,_,n)))) = n
  138.31 -fun set_naming (Computer (r as ref (SOME (p1,p2,p3,p4,p5,p6,naming)))) naming'= 
  138.32 +fun naming_of (Computer (Unsynchronized.ref (SOME (_,_,_,_,_,_,n)))) = n
  138.33 +fun set_naming (Computer (r as Unsynchronized.ref (SOME (p1,p2,p3,p4,p5,p6,naming)))) naming'= 
  138.34      (r := SOME (p1,p2,p3,p4,p5,p6,naming'))
  138.35  
  138.36  fun ref_of (Computer r) = r
  138.37 @@ -320,7 +321,8 @@
  138.38  
  138.39      in (Theory.check_thy thy, encoding, Termtab.keys hyptable, shyptable, prog, stamp, default_naming) end
  138.40  
  138.41 -fun make_with_cache machine thy cache_patterns raw_thms = Computer (ref (SOME (make_internal machine thy (ref ()) Encode.empty cache_patterns raw_thms)))
  138.42 +fun make_with_cache machine thy cache_patterns raw_thms =
  138.43 +  Computer (Unsynchronized.ref (SOME (make_internal machine thy (Unsynchronized.ref ()) Encode.empty cache_patterns raw_thms)))
  138.44  
  138.45  fun make machine thy raw_thms = make_with_cache machine thy [] raw_thms
  138.46  
  138.47 @@ -415,7 +417,7 @@
  138.48  
  138.49  datatype prem = EqPrem of AbstractMachine.term * AbstractMachine.term * Term.typ * int 
  138.50                | Prem of AbstractMachine.term
  138.51 -datatype theorem = Theorem of theory_ref * unit ref * (int * typ) Symtab.table * (AbstractMachine.term option) Inttab.table  
  138.52 +datatype theorem = Theorem of theory_ref * unit Unsynchronized.ref * (int * typ) Symtab.table * (AbstractMachine.term option) Inttab.table  
  138.53                 * prem list * AbstractMachine.term * term list * sort list
  138.54  
  138.55  
   139.1 --- a/src/Tools/Compute_Oracle/linker.ML	Tue Sep 29 14:26:33 2009 +1000
   139.2 +++ b/src/Tools/Compute_Oracle/linker.ML	Tue Sep 29 18:14:08 2009 +0200
   139.3 @@ -239,7 +239,9 @@
   139.4  datatype theorem = MonoThm of thm | PolyThm of thm * Linker.instances * thm list
   139.5  datatype pattern = MonoPattern of term | PolyPattern of term * Linker.instances * term list
   139.6  
   139.7 -datatype pcomputer = PComputer of theory_ref * Compute.computer * theorem list ref * pattern list ref 
   139.8 +datatype pcomputer =
   139.9 +  PComputer of theory_ref * Compute.computer * theorem list Unsynchronized.ref *
  139.10 +    pattern list Unsynchronized.ref 
  139.11  
  139.12  (*fun collect_consts (Var x) = []
  139.13    | collect_consts (Bound _) = []
  139.14 @@ -324,7 +326,7 @@
  139.15  
  139.16  fun add_monos thy monocs pats ths =
  139.17      let
  139.18 -        val changed = ref false
  139.19 +        val changed = Unsynchronized.ref false
  139.20          fun add monocs (th as (MonoThm _)) = ([], th)
  139.21            | add monocs (PolyThm (th, instances, instanceths)) =
  139.22              let
  139.23 @@ -386,9 +388,9 @@
  139.24  
  139.25  fun remove_duplicates ths =
  139.26      let
  139.27 -        val counter = ref 0
  139.28 -        val tab = ref (CThmtab.empty : unit CThmtab.table)
  139.29 -        val thstab = ref (Inttab.empty : thm Inttab.table)
  139.30 +        val counter = Unsynchronized.ref 0
  139.31 +        val tab = Unsynchronized.ref (CThmtab.empty : unit CThmtab.table)
  139.32 +        val thstab = Unsynchronized.ref (Inttab.empty : thm Inttab.table)
  139.33          fun update th =
  139.34              let
  139.35                  val key = thm2cthm th
  139.36 @@ -415,7 +417,7 @@
  139.37  	val (_, (pats, ths)) = add_monos thy monocs pats ths
  139.38  	val computer = create_computer machine thy pats ths
  139.39      in
  139.40 -	PComputer (Theory.check_thy thy, computer, ref ths, ref pats)
  139.41 +	PComputer (Theory.check_thy thy, computer, Unsynchronized.ref ths, Unsynchronized.ref pats)
  139.42      end
  139.43  
  139.44  fun make machine thy ths cs = make_with_cache machine thy [] ths cs
   140.1 --- a/src/Tools/Compute_Oracle/report.ML	Tue Sep 29 14:26:33 2009 +1000
   140.2 +++ b/src/Tools/Compute_Oracle/report.ML	Tue Sep 29 18:14:08 2009 +0200
   140.3 @@ -3,7 +3,7 @@
   140.4  
   140.5  local
   140.6  
   140.7 -    val report_depth = ref 0
   140.8 +    val report_depth = Unsynchronized.ref 0
   140.9      fun space n = if n <= 0 then "" else (space (n-1))^" "
  140.10      fun report_space () = space (!report_depth)
  140.11  
   141.1 --- a/src/Tools/Metis/make-metis	Tue Sep 29 14:26:33 2009 +1000
   141.2 +++ b/src/Tools/Metis/make-metis	Tue Sep 29 18:14:08 2009 +0200
   141.3 @@ -30,16 +30,19 @@
   141.4      then
   141.5        echo -e "$FILE (global)" >&2
   141.6        "$THIS/scripts/mlpp" -c isabelle "src/$FILE" | \
   141.7 -      perl -p -e 's/\b([A-Za-z]+\.[A-Za-z]+)/Metis.\1/g;' -e 's/\bfrag\b/Metis.frag/;'
   141.8 +      perl -p -e 's/\b([A-Za-z]+\.[A-Za-z]+)/Metis.\1/g;' -e 's/\bfrag\b/Metis.frag/;' | \
   141.9 +      perl -p -e 's/\bref\b/Unsynchronized.ref/g;'
  141.10      elif fgrep -q functor "src/$FILE"
  141.11      then
  141.12        "$THIS/scripts/mlpp" -c isabelle "src/$FILE" | \
  141.13 -      perl -p -e 's/ union / op union /g;' -e 's/ subset / op subset /g;'
  141.14 +      perl -p -e 's/ union / op union /g;' -e 's/ subset / op subset /g;' | \
  141.15 +      perl -p -e 's/\bref\b/Unsynchronized.ref/g;'
  141.16      else
  141.17        echo -e "$FILE (local)" >&2
  141.18        echo "structure Metis = struct open Metis"
  141.19        cat < "metis_env.ML"
  141.20 -      "$THIS/scripts/mlpp" -c isabelle "src/$FILE"
  141.21 +      "$THIS/scripts/mlpp" -c isabelle "src/$FILE" | \
  141.22 +      perl -p -e 's/\bref\b/Unsynchronized.ref/g;'
  141.23        echo "end;"
  141.24      fi
  141.25    done
   142.1 --- a/src/Tools/Metis/metis.ML	Tue Sep 29 14:26:33 2009 +1000
   142.2 +++ b/src/Tools/Metis/metis.ML	Tue Sep 29 18:14:08 2009 +0200
   142.3 @@ -395,18 +395,18 @@
   142.4  in
   142.5  
   142.6  abstype 'a queue = QUEUE of {elems: 'a array, (* the contents *)
   142.7 -                             front: int ref,
   142.8 -                             back: int ref,
   142.9 +                             front: int Unsynchronized.ref,
  142.10 +                             back: int Unsynchronized.ref,
  142.11                               size: int}  (* fixed size of element array *)
  142.12  with
  142.13  
  142.14 -  fun is_empty (QUEUE{front=ref ~1, back=ref ~1,...}) = true
  142.15 +  fun is_empty (QUEUE{front=Unsynchronized.ref ~1, back=Unsynchronized.ref ~1,...}) = true
  142.16      | is_empty _ = false
  142.17  
  142.18    fun mk_queue n init_val =
  142.19        if (n < 2)
  142.20        then raise REQUESTED_QUEUE_SIZE_TOO_SMALL
  142.21 -      else QUEUE{elems=array(n, init_val), front=ref ~1, back=ref ~1, size=n}
  142.22 +      else QUEUE{elems=array(n, init_val), front=Unsynchronized.ref ~1, back=Unsynchronized.ref ~1, size=n}
  142.23  
  142.24    fun clear_queue (QUEUE{front,back,...}) = (front := ~1; back := ~1)
  142.25  
  142.26 @@ -459,9 +459,9 @@
  142.27  (* Some global values *)
  142.28  val INFINITY = 999999
  142.29  
  142.30 -abstype indent_stack = Istack of break_info list ref
  142.31 +abstype indent_stack = Istack of break_info list Unsynchronized.ref
  142.32  with
  142.33 -  fun mk_indent_stack() = Istack (ref([]:break_info list))
  142.34 +  fun mk_indent_stack() = Istack (Unsynchronized.ref([]:break_info list))
  142.35    fun clear_indent_stack (Istack stk) = (stk := ([]:break_info list))
  142.36    fun top (Istack stk) =
  142.37        case !stk
  142.38 @@ -501,7 +501,7 @@
  142.39  end
  142.40  
  142.41  
  142.42 -type block_info = { Block_size : int ref,
  142.43 +type block_info = { Block_size : int Unsynchronized.ref,
  142.44                      Block_offset : int,
  142.45                      How_to_indent : break_style }
  142.46  
  142.47 @@ -512,10 +512,10 @@
  142.48  *)
  142.49  datatype pp_token
  142.50    = S of  {String : string, Length : int}
  142.51 -  | BB of {Pblocks : block_info list ref,   (* Processed   *)
  142.52 -           Ublocks : block_info list ref}  (* Unprocessed *)
  142.53 -  | E of  {Pend : int ref, Uend : int ref}
  142.54 -  | BR of {Distance_to_next_break : int ref,
  142.55 +  | BB of {Pblocks : block_info list Unsynchronized.ref,   (* Processed   *)
  142.56 +           Ublocks : block_info list Unsynchronized.ref}  (* Unprocessed *)
  142.57 +  | E of  {Pend : int Unsynchronized.ref, Uend : int Unsynchronized.ref}
  142.58 +  | BR of {Distance_to_next_break : int Unsynchronized.ref,
  142.59             Number_of_blanks : int,
  142.60             Break_offset : int}
  142.61  
  142.62 @@ -532,12 +532,12 @@
  142.63        the_token_buffer : pp_token array,
  142.64        the_delim_stack : delim_stack,
  142.65        the_indent_stack : indent_stack,
  142.66 -      ++ : int ref -> unit,    (* increment circular buffer index *)
  142.67 -      space_left : int ref,    (* remaining columns on page *)
  142.68 -      left_index : int ref,    (* insertion index *)
  142.69 -      right_index : int ref,   (* output index *)
  142.70 -      left_sum : int ref,      (* size of strings and spaces inserted *)
  142.71 -      right_sum : int ref}     (* size of strings and spaces printed *)
  142.72 +      ++ : int Unsynchronized.ref -> unit,    (* increment circular buffer index *)
  142.73 +      space_left : int Unsynchronized.ref,    (* remaining columns on page *)
  142.74 +      left_index : int Unsynchronized.ref,    (* insertion index *)
  142.75 +      right_index : int Unsynchronized.ref,   (* output index *)
  142.76 +      left_sum : int Unsynchronized.ref,      (* size of strings and spaces inserted *)
  142.77 +      right_sum : int Unsynchronized.ref}     (* size of strings and spaces printed *)
  142.78  
  142.79  type ppstream = ppstream_
  142.80  
  142.81 @@ -557,9 +557,9 @@
  142.82  		 the_delim_stack = new_delim_stack buf_size,
  142.83  		 the_indent_stack = mk_indent_stack (),
  142.84  		 ++ = fn i => i := ((!i + 1) mod buf_size),
  142.85 -		 space_left = ref linewidth,
  142.86 -		 left_index = ref 0, right_index = ref 0,
  142.87 -		 left_sum = ref 0, right_sum = ref 0}
  142.88 +		 space_left = Unsynchronized.ref linewidth,
  142.89 +		 left_index = Unsynchronized.ref 0, right_index = Unsynchronized.ref 0,
  142.90 +		 left_sum = Unsynchronized.ref 0, right_sum = Unsynchronized.ref 0}
  142.91                   ) : ppstream
  142.92  	 end
  142.93  
  142.94 @@ -595,25 +595,25 @@
  142.95     be printable? Because of what goes on in add_string. See there for details.
  142.96  *)
  142.97  
  142.98 -fun print_BB (_,{Pblocks = ref [], Ublocks = ref []}) =
  142.99 +fun print_BB (_,{Pblocks = Unsynchronized.ref [], Ublocks = Unsynchronized.ref []}) =
 142.100               raise Fail "PP-error: print_BB"
 142.101 -  | print_BB (PPS{the_indent_stack,linewidth,space_left=ref sp_left,...},
 142.102 -             {Pblocks as ref({How_to_indent=CONSISTENT,Block_size,
 142.103 +  | print_BB (PPS{the_indent_stack,linewidth,space_left=Unsynchronized.ref sp_left,...},
 142.104 +             {Pblocks as Unsynchronized.ref({How_to_indent=CONSISTENT,Block_size,
 142.105                                Block_offset}::rst),
 142.106 -              Ublocks=ref[]}) =
 142.107 +              Ublocks=Unsynchronized.ref[]}) =
 142.108         (push ((if (!Block_size > sp_left)
 142.109                 then ONE_PER_LINE (linewidth - (sp_left - Block_offset))
 142.110                 else FITS),
 142.111  	      the_indent_stack);
 142.112          Pblocks := rst)
 142.113 -  | print_BB(PPS{the_indent_stack,linewidth,space_left=ref sp_left,...},
 142.114 -             {Pblocks as ref({Block_size,Block_offset,...}::rst),Ublocks=ref[]}) =
 142.115 +  | print_BB(PPS{the_indent_stack,linewidth,space_left=Unsynchronized.ref sp_left,...},
 142.116 +             {Pblocks as Unsynchronized.ref({Block_size,Block_offset,...}::rst),Ublocks=Unsynchronized.ref[]}) =
 142.117         (push ((if (!Block_size > sp_left)
 142.118                 then PACK_ONTO_LINE (linewidth - (sp_left - Block_offset))
 142.119                 else FITS),
 142.120  	      the_indent_stack);
 142.121          Pblocks := rst)
 142.122 -  | print_BB (PPS{the_indent_stack, linewidth, space_left=ref sp_left,...},
 142.123 +  | print_BB (PPS{the_indent_stack, linewidth, space_left=Unsynchronized.ref sp_left,...},
 142.124                {Ublocks,...}) =
 142.125        let fun pr_end_Ublock [{How_to_indent=CONSISTENT,Block_size,Block_offset}] l =
 142.126  		(push ((if (!Block_size > sp_left)
 142.127 @@ -635,7 +635,7 @@
 142.128  
 142.129  
 142.130  (* Uend should always be 0 when print_E is called. *)
 142.131 -fun print_E (_,{Pend = ref 0, Uend = ref 0}) =
 142.132 +fun print_E (_,{Pend = Unsynchronized.ref 0, Uend = Unsynchronized.ref 0}) =
 142.133        raise Fail "PP-error: print_E"
 142.134    | print_E (istack,{Pend, ...}) =
 142.135        let fun pop_n_times 0 = ()
 142.136 @@ -710,9 +710,9 @@
 142.137  fun pointers_coincide(PPS{left_index,right_index,the_token_buffer,...}) =
 142.138      (!left_index = !right_index) andalso
 142.139      (case (the_token_buffer sub (!left_index))
 142.140 -       of (BB {Pblocks = ref [], Ublocks = ref []}) => true
 142.141 +       of (BB {Pblocks = Unsynchronized.ref [], Ublocks = Unsynchronized.ref []}) => true
 142.142  	| (BB _) => false
 142.143 -	| (E {Pend = ref 0, Uend = ref 0}) => true
 142.144 +	| (E {Pend = Unsynchronized.ref 0, Uend = Unsynchronized.ref 0}) => true
 142.145  	| (E _) => false
 142.146  	| _ => true)
 142.147  
 142.148 @@ -732,13 +732,13 @@
 142.149  	fun token_size (S{Length, ...}) = Length
 142.150  	  | token_size (BB b) =
 142.151  	     (case b
 142.152 -                of {Pblocks = ref [], Ublocks = ref []} =>
 142.153 +                of {Pblocks = Unsynchronized.ref [], Ublocks = Unsynchronized.ref []} =>
 142.154                       raise Fail "PP-error: BB_size"
 142.155 -	         | {Pblocks as ref(_::_),Ublocks=ref[]} => POS
 142.156 +	         | {Pblocks as Unsynchronized.ref(_::_),Ublocks=Unsynchronized.ref[]} => POS
 142.157  		 | {Ublocks, ...} => last_size (!Ublocks))
 142.158 -	  | token_size (E{Pend = ref 0, Uend = ref 0}) =
 142.159 +	  | token_size (E{Pend = Unsynchronized.ref 0, Uend = Unsynchronized.ref 0}) =
 142.160                raise Fail "PP-error: token_size.E"
 142.161 -	  | token_size (E{Pend = ref 0, ...}) = NEG
 142.162 +	  | token_size (E{Pend = Unsynchronized.ref 0, ...}) = NEG
 142.163  	  | token_size (E _) = POS
 142.164  	  | token_size (BR {Distance_to_next_break, ...}) = !Distance_to_next_break
 142.165  	fun loop (instr) =
 142.166 @@ -761,12 +761,12 @@
 142.167         mangled output.)
 142.168      *)
 142.169  		       (case (the_token_buffer sub (!left_index))
 142.170 -			  of (BB {Pblocks = ref [], Ublocks = ref []}) =>
 142.171 +			  of (BB {Pblocks = Unsynchronized.ref [], Ublocks = Unsynchronized.ref []}) =>
 142.172  			       (update(the_token_buffer,!left_index,
 142.173  				       initial_token_value);
 142.174  				++left_index)
 142.175  			   | (BB _) => ()
 142.176 -			   | (E {Pend = ref 0, Uend = ref 0}) =>
 142.177 +			   | (E {Pend = Unsynchronized.ref 0, Uend = Unsynchronized.ref 0}) =>
 142.178  			       (update(the_token_buffer,!left_index,
 142.179  				       initial_token_value);
 142.180  				++left_index)
 142.181 @@ -791,12 +791,12 @@
 142.182      else BB_inc_right_index ppstrm;
 142.183      case (the_token_buffer sub (!right_index))
 142.184        of (BB {Ublocks, ...}) =>
 142.185 -	   Ublocks := {Block_size = ref (~(!right_sum)),
 142.186 +	   Ublocks := {Block_size = Unsynchronized.ref (~(!right_sum)),
 142.187  		       Block_offset = offset,
 142.188  		       How_to_indent = style}::(!Ublocks)
 142.189         | _ => (update(the_token_buffer, !right_index,
 142.190 -		      BB{Pblocks = ref [],
 142.191 -			 Ublocks = ref [{Block_size = ref (~(!right_sum)),
 142.192 +		      BB{Pblocks = Unsynchronized.ref [],
 142.193 +			 Ublocks = Unsynchronized.ref [{Block_size = Unsynchronized.ref (~(!right_sum)),
 142.194  					 Block_offset = offset,
 142.195  					 How_to_indent = style}]});
 142.196  	       push_delim_stack (!right_index, the_delim_stack)))
 142.197 @@ -808,12 +808,12 @@
 142.198              = ppstrm
 142.199    in
 142.200      if (delim_stack_is_empty the_delim_stack)
 142.201 -    then print_token(ppstrm,(E{Pend = ref 1, Uend = ref 0}))
 142.202 +    then print_token(ppstrm,(E{Pend = Unsynchronized.ref 1, Uend = Unsynchronized.ref 0}))
 142.203      else (E_inc_right_index ppstrm;
 142.204  	  case (the_token_buffer sub (!right_index))
 142.205              of (E{Uend, ...}) => Uend := !Uend + 1
 142.206  	     | _ => (update(the_token_buffer,!right_index,
 142.207 -			    E{Uend = ref 1, Pend = ref 0});
 142.208 +			    E{Uend = Unsynchronized.ref 1, Pend = Unsynchronized.ref 0});
 142.209  		     push_delim_stack (!right_index, the_delim_stack)))
 142.210    end
 142.211  
 142.212 @@ -823,7 +823,7 @@
 142.213  	      if (delim_stack_is_empty the_delim_stack)
 142.214  	      then ()
 142.215  	      else case(the_token_buffer sub (top_delim_stack the_delim_stack))
 142.216 -		     of (BB{Ublocks as ref ((b as {Block_size, ...})::rst),
 142.217 +		     of (BB{Ublocks as Unsynchronized.ref ((b as {Block_size, ...})::rst),
 142.218  			    Pblocks}) =>
 142.219  			   if (k>0)
 142.220  			   then (Block_size := !right_sum + !Block_size;
 142.221 @@ -862,7 +862,7 @@
 142.222  	     left_sum := 1;   right_sum := 1)
 142.223         else ++right_index;
 142.224         update(the_token_buffer, !right_index,
 142.225 -	      BR{Distance_to_next_break = ref (~(!right_sum)),
 142.226 +	      BR{Distance_to_next_break = Unsynchronized.ref (~(!right_sum)),
 142.227  		 Number_of_blanks = n,
 142.228  		 Break_offset = break_offset});
 142.229         check_delim_stack ppstrm;
 142.230 @@ -899,10 +899,10 @@
 142.231  	  | fnl (_::rst) = fnl rst
 142.232            | fnl _ = raise Fail "PP-error: fnl: internal error"
 142.233  
 142.234 -	fun set(dstack,BB{Ublocks as ref[{Block_size,...}:block_info],...}) =
 142.235 +	fun set(dstack,BB{Ublocks as Unsynchronized.ref[{Block_size,...}:block_info],...}) =
 142.236  	      (pop_bottom_delim_stack dstack;
 142.237  	       Block_size := INFINITY)
 142.238 -	  | set (_,BB {Ublocks = ref(_::rst), ...}) = fnl rst
 142.239 +	  | set (_,BB {Ublocks = Unsynchronized.ref(_::rst), ...}) = fnl rst
 142.240  	  | set (dstack, E{Pend,Uend}) =
 142.241  	      (Pend := (!Pend) + (!Uend);
 142.242  	       Uend := 0;
 142.243 @@ -958,7 +958,7 @@
 142.244       (TextIO.print (">>>> Pretty-printer failure: " ^ msg ^ "\n"))
 142.245  
 142.246  fun pp_to_string linewidth ppfn ob =
 142.247 -    let val l = ref ([]:string list)
 142.248 +    let val l = Unsynchronized.ref ([]:string list)
 142.249  	fun attach s = l := (s::(!l))
 142.250       in with_pp {consumer = attach, linewidth=linewidth, flush = fn()=>()}
 142.251  		(fn ppstrm =>  ppfn ppstrm ob);
 142.252 @@ -995,7 +995,7 @@
 142.253  (* Tracing.                                                                  *)
 142.254  (* ------------------------------------------------------------------------- *)
 142.255  
 142.256 -val tracePrint : (string -> unit) ref
 142.257 +val tracePrint : (string -> unit) Unsynchronized.ref
 142.258  
 142.259  val trace : string -> unit
 142.260  
 142.261 @@ -1228,7 +1228,7 @@
 142.262  
 142.263  val newInts : int -> int list
 142.264  
 142.265 -val withRef : 'r ref * 'r -> ('a -> 'b) -> 'a -> 'b
 142.266 +val withRef : 'r Unsynchronized.ref * 'r -> ('a -> 'b) -> 'a -> 'b
 142.267  
 142.268  val cloneArray : 'a Metis.Array.array -> 'a Metis.Array.array
 142.269  
 142.270 @@ -1305,7 +1305,7 @@
 142.271  (* Tracing                                                                   *)
 142.272  (* ------------------------------------------------------------------------- *)
 142.273  
 142.274 -val tracePrint = ref print;
 142.275 +val tracePrint = Unsynchronized.ref print;
 142.276  
 142.277  fun trace message = !tracePrint message;
 142.278  
 142.279 @@ -1629,7 +1629,7 @@
 142.280  
 142.281    fun calcPrimes n = looking [] n (K true) 2
 142.282  
 142.283 -  val primesList = ref (calcPrimes 10);
 142.284 +  val primesList = Unsynchronized.ref (calcPrimes 10);
 142.285  in
 142.286    fun primes n = CRITICAL (fn () =>
 142.287        if length (!primesList) <= n then List.take (!primesList,n)
 142.288 @@ -1828,7 +1828,7 @@
 142.289  (* ------------------------------------------------------------------------- *)
 142.290  
 142.291  local
 142.292 -  val generator = ref 0
 142.293 +  val generator = Unsynchronized.ref 0
 142.294  in
 142.295    fun newInt () = CRITICAL (fn () =>
 142.296        let
 142.297 @@ -1986,12 +1986,12 @@
 142.298      Value of 'a
 142.299    | Thunk of unit -> 'a;
 142.300  
 142.301 -datatype 'a lazy = Lazy of 'a thunk ref;
 142.302 -
 142.303 -fun delay f = Lazy (ref (Thunk f));
 142.304 -
 142.305 -fun force (Lazy (ref (Value v))) = v
 142.306 -  | force (Lazy (s as ref (Thunk f))) =
 142.307 +datatype 'a lazy = Lazy of 'a thunk Unsynchronized.ref;
 142.308 +
 142.309 +fun delay f = Lazy (Unsynchronized.ref (Thunk f));
 142.310 +
 142.311 +fun force (Lazy (Unsynchronized.ref (Value v))) = v
 142.312 +  | force (Lazy (s as Unsynchronized.ref (Thunk f))) =
 142.313      let
 142.314        val v = f ()
 142.315        val () = s := Value v
 142.316 @@ -4141,7 +4141,7 @@
 142.317  
 142.318  fun cache cmp f =
 142.319      let
 142.320 -      val cache = ref (Map.new cmp)
 142.321 +      val cache = Unsynchronized.ref (Map.new cmp)
 142.322      in
 142.323        fn a =>
 142.324           case Map.peek (!cache) a of
 142.325 @@ -4620,7 +4620,7 @@
 142.326  
 142.327  type 'a pp = ppstream -> 'a -> unit
 142.328  
 142.329 -val lineLength : int ref
 142.330 +val lineLength : int Unsynchronized.ref
 142.331  
 142.332  val beginBlock : ppstream -> breakStyle -> int -> unit
 142.333  
 142.334 @@ -4797,7 +4797,7 @@
 142.335  
 142.336  type 'a pp = PP.ppstream -> 'a -> unit;
 142.337  
 142.338 -val lineLength = ref 75;
 142.339 +val lineLength = Unsynchronized.ref 75;
 142.340  
 142.341  fun beginBlock pp Consistent = PP.begin_block pp PP.CONSISTENT
 142.342    | beginBlock pp Inconsistent = PP.begin_block pp PP.INCONSISTENT;
 142.343 @@ -5766,19 +5766,19 @@
 142.344  
 142.345  (* Infix symbols *)
 142.346  
 142.347 -val infixes : Metis.Parser.infixities ref
 142.348 +val infixes : Metis.Parser.infixities Unsynchronized.ref
 142.349  
 142.350  (* The negation symbol *)
 142.351  
 142.352 -val negation : Metis.Name.name ref
 142.353 +val negation : Metis.Name.name Unsynchronized.ref
 142.354  
 142.355  (* Binder symbols *)
 142.356  
 142.357 -val binders : Metis.Name.name list ref
 142.358 +val binders : Metis.Name.name list Unsynchronized.ref
 142.359  
 142.360  (* Bracket symbols *)
 142.361  
 142.362 -val brackets : (Metis.Name.name * Metis.Name.name) list ref
 142.363 +val brackets : (Metis.Name.name * Metis.Name.name) list Unsynchronized.ref
 142.364  
 142.365  (* Pretty printing *)
 142.366  
 142.367 @@ -6137,7 +6137,7 @@
 142.368  
 142.369  (* Operators parsed and printed infix *)
 142.370  
 142.371 -val infixes : Parser.infixities ref = ref
 142.372 +val infixes : Parser.infixities Unsynchronized.ref = Unsynchronized.ref
 142.373    [(* ML symbols *)
 142.374     {token = " / ", precedence = 7, leftAssoc = true},
 142.375     {token = " div ", precedence = 7, leftAssoc = true},
 142.376 @@ -6174,15 +6174,15 @@
 142.377  
 142.378  (* The negation symbol *)
 142.379  
 142.380 -val negation : Name.name ref = ref "~";
 142.381 +val negation : Name.name Unsynchronized.ref = Unsynchronized.ref "~";
 142.382  
 142.383  (* Binder symbols *)
 142.384  
 142.385 -val binders : Name.name list ref = ref ["\\","!","?","?!"];
 142.386 +val binders : Name.name list Unsynchronized.ref = Unsynchronized.ref ["\\","!","?","?!"];
 142.387  
 142.388  (* Bracket symbols *)
 142.389  
 142.390 -val brackets : (Name.name * Name.name) list ref = ref [("[","]"),("{","}")];
 142.391 +val brackets : (Name.name * Name.name) list Unsynchronized.ref = Unsynchronized.ref [("[","]"),("{","}")];
 142.392  
 142.393  (* Pretty printing *)
 142.394  
 142.395 @@ -11051,11 +11051,11 @@
 142.396  
 142.397  val newSkolemFunction =
 142.398      let
 142.399 -      val counter : int NameMap.map ref = ref (NameMap.new ())
 142.400 +      val counter : int NameMap.map Unsynchronized.ref = Unsynchronized.ref (NameMap.new ())
 142.401      in
 142.402        fn n => CRITICAL (fn () =>
 142.403        let
 142.404 -        val ref m = counter
 142.405 +        val Unsynchronized.ref m = counter
 142.406          val i = Option.getOpt (NameMap.peek m n, 0)
 142.407          val () = counter := NameMap.insert m (n, i + 1)
 142.408        in
 142.409 @@ -11249,11 +11249,11 @@
 142.410  
 142.411  val newDefinitionRelation =
 142.412      let
 142.413 -      val counter : int ref = ref 0
 142.414 +      val counter : int Unsynchronized.ref = Unsynchronized.ref 0
 142.415      in
 142.416        fn () => CRITICAL (fn () =>
 142.417        let
 142.418 -        val ref i = counter
 142.419 +        val Unsynchronized.ref i = counter
 142.420          val () = counter := i + 1
 142.421        in
 142.422          "defCNF_" ^ Int.toString i
 142.423 @@ -11820,8 +11820,8 @@
 142.424      Model of
 142.425        {size : int,
 142.426         fixed : fixedModel,
 142.427 -       functions : (Term.functionName * int list, int) Map.map ref,
 142.428 -       relations : (Atom.relationName * int list, bool) Map.map ref};
 142.429 +       functions : (Term.functionName * int list, int) Map.map Unsynchronized.ref,
 142.430 +       relations : (Atom.relationName * int list, bool) Map.map Unsynchronized.ref};
 142.431  
 142.432  local
 142.433    fun cmp ((n1,l1),(n2,l2)) =
 142.434 @@ -11834,8 +11834,8 @@
 142.435        Model
 142.436          {size = N,
 142.437           fixed = fixed {size = N},
 142.438 -         functions = ref (Map.new cmp),
 142.439 -         relations = ref (Map.new cmp)};
 142.440 +         functions = Unsynchronized.ref (Map.new cmp),
 142.441 +         relations = Unsynchronized.ref (Map.new cmp)};
 142.442  end;
 142.443  
 142.444  fun size (Model {size = s, ...}) = s;
 142.445 @@ -11905,7 +11905,7 @@
 142.446                  | (Term.Fn (f,tms), tms') => (f, tms @ tms')
 142.447              val elts = map interpret tms
 142.448              val f_elts = (f,elts)
 142.449 -            val ref funcs = functions
 142.450 +            val Unsynchronized.ref funcs = functions
 142.451            in
 142.452              case Map.peek funcs f_elts of
 142.453                SOME k => k
 142.454 @@ -11932,7 +11932,7 @@
 142.455  
 142.456        val elts = map (interpretTerm M V) tms
 142.457        val r_elts = (r,elts)
 142.458 -      val ref rels = relations
 142.459 +      val Unsynchronized.ref rels = relations
 142.460      in
 142.461        case Map.peek rels r_elts of
 142.462          SOME b => b
 142.463 @@ -14717,7 +14717,7 @@
 142.464  (* Pretty printing.                                                          *)
 142.465  (* ------------------------------------------------------------------------- *)
 142.466  
 142.467 -val showId : bool ref
 142.468 +val showId : bool Unsynchronized.ref
 142.469  
 142.470  val pp : clause Metis.Parser.pp
 142.471  
 142.472 @@ -14747,10 +14747,10 @@
 142.473  
 142.474  val newId =
 142.475      let
 142.476 -      val r = ref 0
 142.477 +      val r = Unsynchronized.ref 0
 142.478      in
 142.479        fn () => CRITICAL (fn () =>
 142.480 -        case r of ref n => let val () = r := n + 1 in n end)
 142.481 +        case r of Unsynchronized.ref n => let val () = r := n + 1 in n end)
 142.482      end;
 142.483  
 142.484  (* ------------------------------------------------------------------------- *)
 142.485 @@ -14777,7 +14777,7 @@
 142.486  (* Pretty printing.                                                          *)
 142.487  (* ------------------------------------------------------------------------- *)
 142.488  
 142.489 -val showId = ref false;
 142.490 +val showId = Unsynchronized.ref false;
 142.491  
 142.492  local
 142.493    val ppIdThm = Parser.ppPair Parser.ppInt Thm.pp;
 142.494 @@ -16372,9 +16372,9 @@
 142.495  (* Mapping TPTP functions and relations to different names.                  *)
 142.496  (* ------------------------------------------------------------------------- *)
 142.497  
 142.498 -val functionMapping : {name : string, arity : int, tptp : string} list ref
 142.499 -
 142.500 -val relationMapping : {name : string, arity : int, tptp : string} list ref
 142.501 +val functionMapping : {name : string, arity : int, tptp : string} list Unsynchronized.ref
 142.502 +
 142.503 +val relationMapping : {name : string, arity : int, tptp : string} list Unsynchronized.ref
 142.504  
 142.505  (* ------------------------------------------------------------------------- *)
 142.506  (* TPTP literals.                                                            *)
 142.507 @@ -16491,7 +16491,7 @@
 142.508  (* Mapping TPTP functions and relations to different names.                  *)
 142.509  (* ------------------------------------------------------------------------- *)
 142.510  
 142.511 -val functionMapping = ref
 142.512 +val functionMapping = Unsynchronized.ref
 142.513      [(* Mapping TPTP functions to infix symbols *)
 142.514       {name = "*", arity = 2, tptp = "multiply"},
 142.515       {name = "/", arity = 2, tptp = "divide"},
 142.516 @@ -16504,7 +16504,7 @@
 142.517       {name = ".", arity = 2, tptp = "apply"},
 142.518       {name = "<=", arity = 0, tptp = "less_equal"}];
 142.519  
 142.520 -val relationMapping = ref
 142.521 +val relationMapping = Unsynchronized.ref
 142.522      [(* Mapping TPTP relations to infix symbols *)
 142.523       {name = "=", arity = 2, tptp = "="},
 142.524       {name = "==", arity = 2, tptp = "equalish"},
   143.1 --- a/src/Tools/auto_solve.ML	Tue Sep 29 14:26:33 2009 +1000
   143.2 +++ b/src/Tools/auto_solve.ML	Tue Sep 29 18:14:08 2009 +0200
   143.3 @@ -11,9 +11,9 @@
   143.4  
   143.5  signature AUTO_SOLVE =
   143.6  sig
   143.7 -  val auto : bool ref
   143.8 -  val auto_time_limit : int ref
   143.9 -  val limit : int ref
  143.10 +  val auto : bool Unsynchronized.ref
  143.11 +  val auto_time_limit : int Unsynchronized.ref
  143.12 +  val limit : int Unsynchronized.ref
  143.13  end;
  143.14  
  143.15  structure AutoSolve : AUTO_SOLVE =
  143.16 @@ -21,9 +21,9 @@
  143.17  
  143.18  (* preferences *)
  143.19  
  143.20 -val auto = ref false;
  143.21 -val auto_time_limit = ref 2500;
  143.22 -val limit = ref 5;
  143.23 +val auto = Unsynchronized.ref false;
  143.24 +val auto_time_limit = Unsynchronized.ref 2500;
  143.25 +val limit = Unsynchronized.ref 5;
  143.26  
  143.27  val _ =
  143.28    ProofGeneralPgip.add_preference Preferences.category_tracing
   144.1 --- a/src/Tools/coherent.ML	Tue Sep 29 14:26:33 2009 +1000
   144.2 +++ b/src/Tools/coherent.ML	Tue Sep 29 18:14:08 2009 +0200
   144.3 @@ -20,8 +20,8 @@
   144.4  
   144.5  signature COHERENT =
   144.6  sig
   144.7 -  val verbose: bool ref
   144.8 -  val show_facts: bool ref
   144.9 +  val verbose: bool Unsynchronized.ref
  144.10 +  val show_facts: bool Unsynchronized.ref
  144.11    val coherent_tac: Proof.context -> thm list -> int -> tactic
  144.12    val setup: theory -> theory
  144.13  end;
  144.14 @@ -31,7 +31,7 @@
  144.15  
  144.16  (** misc tools **)
  144.17  
  144.18 -val verbose = ref false;
  144.19 +val verbose = Unsynchronized.ref false;
  144.20  
  144.21  fun message f = if !verbose then tracing (f ()) else ();
  144.22  
  144.23 @@ -117,7 +117,7 @@
  144.24          | NONE => is_valid_disj ctxt facts ds
  144.25        end;
  144.26  
  144.27 -val show_facts = ref false;
  144.28 +val show_facts = Unsynchronized.ref false;
  144.29  
  144.30  fun string_of_facts ctxt s facts = space_implode "\n"
  144.31    (s :: map (Syntax.string_of_term ctxt)
   145.1 --- a/src/Tools/eqsubst.ML	Tue Sep 29 14:26:33 2009 +1000
   145.2 +++ b/src/Tools/eqsubst.ML	Tue Sep 29 18:14:08 2009 +0200
   145.3 @@ -278,8 +278,8 @@
   145.4               * (string * typ) list (* Type abs env *)
   145.5               * term) (* outer term *);
   145.6  
   145.7 -val trace_subst_err = (ref NONE : trace_subst_errT option ref);
   145.8 -val trace_subst_search = ref false;
   145.9 +val trace_subst_err = (Unsynchronized.ref NONE : trace_subst_errT option Unsynchronized.ref);
  145.10 +val trace_subst_search = Unsynchronized.ref false;
  145.11  exception trace_subst_exp of trace_subst_errT;
  145.12  *)
  145.13  
   146.1 --- a/src/Tools/more_conv.ML	Tue Sep 29 14:26:33 2009 +1000
   146.2 +++ b/src/Tools/more_conv.ML	Tue Sep 29 18:14:08 2009 +0200
   146.3 @@ -46,11 +46,11 @@
   146.4    Conv.arg_conv (Conv.abs_conv (fn (_, cx) => cv cx) ctxt)
   146.5  
   146.6  
   146.7 -fun cache_conv conv =
   146.8 +fun cache_conv conv =   (* FIXME not thread-safe *)
   146.9    let 
  146.10 -    val tab = ref Termtab.empty
  146.11 +    val tab = Unsynchronized.ref Termtab.empty
  146.12      fun add_result t thm =
  146.13 -      let val _ = change tab (Termtab.insert Thm.eq_thm (t, thm))
  146.14 +      let val _ = Unsynchronized.change tab (Termtab.insert Thm.eq_thm (t, thm))
  146.15        in thm end
  146.16      fun cconv ct =  
  146.17        (case Termtab.lookup (!tab) (Thm.term_of ct) of
   147.1 --- a/src/Tools/nbe.ML	Tue Sep 29 14:26:33 2009 +1000
   147.2 +++ b/src/Tools/nbe.ML	Tue Sep 29 18:14:08 2009 +0200
   147.3 @@ -19,8 +19,8 @@
   147.4                                               (*abstractions as closures*)
   147.5    val same: Univ -> Univ -> bool
   147.6  
   147.7 -  val univs_ref: (unit -> Univ list -> Univ list) option ref
   147.8 -  val trace: bool ref
   147.9 +  val univs_ref: (unit -> Univ list -> Univ list) option Unsynchronized.ref
  147.10 +  val trace: bool Unsynchronized.ref
  147.11  
  147.12    val setup: theory -> theory
  147.13    val add_const_alias: thm -> theory -> theory
  147.14 @@ -31,7 +31,7 @@
  147.15  
  147.16  (* generic non-sense *)
  147.17  
  147.18 -val trace = ref false;
  147.19 +val trace = Unsynchronized.ref false;
  147.20  fun traced f x = if !trace then (tracing (f x); x) else x;
  147.21  
  147.22  
  147.23 @@ -216,7 +216,7 @@
  147.24  
  147.25  (* nbe specific syntax and sandbox communication *)
  147.26  
  147.27 -val univs_ref = ref (NONE : (unit -> Univ list -> Univ list) option);
  147.28 +val univs_ref = Unsynchronized.ref (NONE : (unit -> Univ list -> Univ list) option);
  147.29  
  147.30  local
  147.31    val prefix =      "Nbe.";
   148.1 --- a/src/Tools/quickcheck.ML	Tue Sep 29 14:26:33 2009 +1000
   148.2 +++ b/src/Tools/quickcheck.ML	Tue Sep 29 18:14:08 2009 +0200
   148.3 @@ -6,8 +6,8 @@
   148.4  
   148.5  signature QUICKCHECK =
   148.6  sig
   148.7 -  val auto: bool ref
   148.8 -  val auto_time_limit: int ref
   148.9 +  val auto: bool Unsynchronized.ref
  148.10 +  val auto_time_limit: int Unsynchronized.ref
  148.11    val test_term: Proof.context -> bool -> string option -> int -> int -> term ->
  148.12      (string * term) list option
  148.13    val add_generator: string * (Proof.context -> term -> int -> term list option) -> theory -> theory
  148.14 @@ -19,8 +19,8 @@
  148.15  
  148.16  (* preferences *)
  148.17  
  148.18 -val auto = ref false;
  148.19 -val auto_time_limit = ref 2500;
  148.20 +val auto = Unsynchronized.ref false;
  148.21 +val auto_time_limit = Unsynchronized.ref 2500;
  148.22  
  148.23  val _ =
  148.24    ProofGeneralPgip.add_preference Preferences.category_tracing
   149.1 --- a/src/Tools/random_word.ML	Tue Sep 29 14:26:33 2009 +1000
   149.2 +++ b/src/Tools/random_word.ML	Tue Sep 29 18:14:08 2009 +0200
   149.3 @@ -35,8 +35,8 @@
   149.4  val a = 0w777138309;
   149.5  fun step x = Word.andb (a * x + 0w1, max_word);
   149.6  
   149.7 -local val rand = ref 0w1
   149.8 -in fun next_word () = (change rand step; ! rand) end;
   149.9 +local val rand = Unsynchronized.ref 0w1
  149.10 +in fun next_word () = (Unsynchronized.change rand step; ! rand) end;
  149.11  
  149.12  (*NB: higher bits are more random than lower ones*)
  149.13  fun next_bool () = Word.andb (next_word (), top_bit) = 0w0;
   150.1 --- a/src/ZF/Datatype_ZF.thy	Tue Sep 29 14:26:33 2009 +1000
   150.2 +++ b/src/ZF/Datatype_ZF.thy	Tue Sep 29 18:14:08 2009 +0200
   150.3 @@ -59,7 +59,7 @@
   150.4  (*Simproc for freeness reasoning: compare datatype constructors for equality*)
   150.5  structure DataFree =
   150.6  struct
   150.7 -  val trace = ref false;
   150.8 +  val trace = Unsynchronized.ref false;
   150.9  
  150.10    fun mk_new ([],[]) = Const("True",FOLogic.oT)
  150.11      | mk_new (largs,rargs) =
   151.1 --- a/src/ZF/ZF.thy	Tue Sep 29 14:26:33 2009 +1000
   151.2 +++ b/src/ZF/ZF.thy	Tue Sep 29 18:14:08 2009 +0200
   151.3 @@ -8,7 +8,7 @@
   151.4  
   151.5  theory ZF imports FOL begin
   151.6  
   151.7 -ML {* reset eta_contract *}
   151.8 +ML {* Unsynchronized.reset eta_contract *}
   151.9  
  151.10  global
  151.11  
   152.1 --- a/src/ZF/ind_syntax.ML	Tue Sep 29 14:26:33 2009 +1000
   152.2 +++ b/src/ZF/ind_syntax.ML	Tue Sep 29 18:14:08 2009 +0200
   152.3 @@ -10,7 +10,7 @@
   152.4  struct
   152.5  
   152.6  (*Print tracing messages during processing of "inductive" theory sections*)
   152.7 -val trace = ref false;
   152.8 +val trace = Unsynchronized.ref false;
   152.9  
  152.10  fun traceIt msg thy t =
  152.11    if !trace then (tracing (msg ^ Syntax.string_of_term_global thy t); t)