121 /** |
121 /** |
122 * returns the list of uninstantiated variables (as type-variables) in this |
122 * returns the list of uninstantiated variables (as type-variables) in this |
123 * inference context |
123 * inference context |
124 */ |
124 */ |
125 List<Type> restvars() { |
125 List<Type> restvars() { |
126 return filterVars(new Filter<UndetVar>() { |
126 return filterVars(uv -> uv.getInst() == null); |
127 public boolean accepts(UndetVar uv) { |
|
128 return uv.getInst() == null; |
|
129 } |
|
130 }); |
|
131 } |
127 } |
132 |
128 |
133 /** |
129 /** |
134 * returns the list of instantiated variables (as type-variables) in this |
130 * returns the list of instantiated variables (as type-variables) in this |
135 * inference context |
131 * inference context |
136 */ |
132 */ |
137 List<Type> instvars() { |
133 List<Type> instvars() { |
138 return filterVars(new Filter<UndetVar>() { |
134 return filterVars(uv -> uv.getInst() != null); |
139 public boolean accepts(UndetVar uv) { |
|
140 return uv.getInst() != null; |
|
141 } |
|
142 }); |
|
143 } |
135 } |
144 |
136 |
145 /** |
137 /** |
146 * Get list of bounded inference variables (where bound is other than |
138 * Get list of bounded inference variables (where bound is other than |
147 * declared bounds). |
139 * declared bounds). |
148 */ |
140 */ |
149 final List<Type> boundedVars() { |
141 final List<Type> boundedVars() { |
150 return filterVars(new Filter<UndetVar>() { |
142 return filterVars(uv -> uv.getBounds(InferenceBound.UPPER) |
151 public boolean accepts(UndetVar uv) { |
143 .diff(uv.getDeclaredBounds()) |
152 return uv.getBounds(InferenceBound.UPPER) |
144 .appendList(uv.getBounds(InferenceBound.EQ, InferenceBound.LOWER)).nonEmpty()); |
153 .diff(uv.getDeclaredBounds()) |
|
154 .appendList(uv.getBounds(InferenceBound.EQ, InferenceBound.LOWER)).nonEmpty(); |
|
155 } |
|
156 }); |
|
157 } |
145 } |
158 |
146 |
159 /* Returns the corresponding inference variables. |
147 /* Returns the corresponding inference variables. |
160 */ |
148 */ |
161 private List<Type> filterVars(Filter<UndetVar> fu) { |
149 private List<Type> filterVars(Filter<UndetVar> fu) { |
339 List<Type> undetsToPropagate = clone ? save() : undetvars; |
327 List<Type> undetsToPropagate = clone ? save() : undetvars; |
340 that.undetvars = that.undetvars.appendList(undetsToPropagate.diff(that.undetvars)); //propagate cloned undet!! |
328 that.undetvars = that.undetvars.appendList(undetsToPropagate.diff(that.undetvars)); //propagate cloned undet!! |
341 //set up listeners to notify original inference contexts as |
329 //set up listeners to notify original inference contexts as |
342 //propagated vars are inferred in new context |
330 //propagated vars are inferred in new context |
343 for (Type t : inferencevars) { |
331 for (Type t : inferencevars) { |
344 that.freeTypeListeners.put(new FreeTypeListener() { |
332 that.freeTypeListeners.put(inferenceContext -> InferenceContext.this.notifyChange(), List.of(t)); |
345 public void typesInferred(InferenceContext inferenceContext) { |
|
346 InferenceContext.this.notifyChange(); |
|
347 } |
|
348 }, List.of(t)); |
|
349 } |
333 } |
350 } |
334 } |
351 |
335 |
352 InferenceContext min(List<Type> roots, boolean shouldSolve, Warner warn) { |
336 InferenceContext min(List<Type> roots, boolean shouldSolve, Warner warn) { |
353 ReachabilityVisitor rv = new ReachabilityVisitor(); |
337 ReachabilityVisitor rv = new ReachabilityVisitor(); |