| 39 | } |
| 40 | |
| 41 | public t_value apply(t_check check) { |
| 42 | t_witness w; |
| 43 | try { |
| 44 | w = witness.apply(check); |
| 45 | } |
| 46 | catch(Throwable t) |
| 47 | { |
| 48 | System.err.println(" exception thrown by witness :"+witness+" carying on"); |
| 49 | t.printStackTrace(); |
| 50 | w=null; |
| 51 | invalid = true; |
| 52 | } |
| 53 | |
| 54 | t_witness finalW = w; |
| 55 | if (invalid || !Util.safeEq(w, valid)) { |
| 56 | if (debug != null) { |
| 57 | Log.log("cached." + debug, ()->" cache invalid :" + invalid + " " + finalW + " " + valid + " " + Util.safeEq(finalW, valid)); |
| 58 | } |
| 59 | value = compute.apply(check, value); |
| 60 | valid = w; |
| 61 | |
| 62 | if (valid instanceof Mutable) |
| 63 | valid = (t_witness) ((Mutable)valid).duplicate(); |
| 64 | |
| 65 | invalid = false; |
| 66 | } else if (debug != null) |
| 67 | Log.log("cached." + debug,()-> " cache valid :" + invalid + " " + finalW + " " + valid + " " + Util.safeEq(finalW, valid)); |
| 68 | return value; |
| 69 | } |
| 70 | |
| 71 | public Cached<t_check, t_witness, t_value> debugOn(String name) { |
| 72 | this.debug = name; |