langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/InferenceContext.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2015, 2016, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
65 * <p><b>This is NOT part of any supported API. |
65 * <p><b>This is NOT part of any supported API. |
66 * If you write code that depends on this, you do so at your own risk. |
66 * If you write code that depends on this, you do so at your own risk. |
67 * This code and its internal interfaces are subject to change or |
67 * This code and its internal interfaces are subject to change or |
68 * deletion without notice.</b> |
68 * deletion without notice.</b> |
69 */ |
69 */ |
70 class InferenceContext { |
70 public class InferenceContext { |
71 |
71 |
72 /** list of inference vars as undet vars */ |
72 /** list of inference vars as undet vars */ |
73 List<Type> undetvars; |
73 List<Type> undetvars; |
74 |
74 |
75 Type update(Type t) { |
75 Type update(Type t) { |
107 * returns the list of free variables (as type-variables) in this |
107 * returns the list of free variables (as type-variables) in this |
108 * inference context |
108 * inference context |
109 */ |
109 */ |
110 List<Type> inferenceVars() { |
110 List<Type> inferenceVars() { |
111 return inferencevars; |
111 return inferencevars; |
|
112 } |
|
113 |
|
114 /** |
|
115 * returns the list of undetermined variables in this inference context |
|
116 */ |
|
117 public List<Type> undetVars() { |
|
118 return undetvars; |
112 } |
119 } |
113 |
120 |
114 /** |
121 /** |
115 * returns the list of uninstantiated variables (as type-variables) in this |
122 * returns the list of uninstantiated variables (as type-variables) in this |
116 * inference context |
123 * inference context |
206 /** |
213 /** |
207 * Replace all free variables in a given type with corresponding |
214 * Replace all free variables in a given type with corresponding |
208 * undet vars (used ahead of subtyping/compatibility checks to allow propagation |
215 * undet vars (used ahead of subtyping/compatibility checks to allow propagation |
209 * of inference constraints). |
216 * of inference constraints). |
210 */ |
217 */ |
211 final Type asUndetVar(Type t) { |
218 public final Type asUndetVar(Type t) { |
212 return types.subst(t, inferencevars, undetvars); |
219 return types.subst(t, inferencevars, undetvars); |
213 } |
220 } |
214 |
221 |
215 final List<Type> asUndetVars(List<Type> ts) { |
222 final List<Type> asUndetVars(List<Type> ts) { |
216 ListBuffer<Type> buf = new ListBuffer<>(); |
223 ListBuffer<Type> buf = new ListBuffer<>(); |
284 } |
291 } |
285 |
292 |
286 /** |
293 /** |
287 * Save the state of this inference context |
294 * Save the state of this inference context |
288 */ |
295 */ |
289 List<Type> save() { |
296 public List<Type> save() { |
290 ListBuffer<Type> buf = new ListBuffer<>(); |
297 ListBuffer<Type> buf = new ListBuffer<>(); |
291 for (Type t : undetvars) { |
298 for (Type t : undetvars) { |
292 buf.add(((UndetVar)t).dup(infer.types)); |
299 buf.add(((UndetVar)t).dup(infer.types)); |
293 } |
300 } |
294 return buf.toList(); |
301 return buf.toList(); |
296 |
303 |
297 /** Restore the state of this inference context to the previous known checkpoint. |
304 /** Restore the state of this inference context to the previous known checkpoint. |
298 * Consider that the number of saved undetermined variables can be different to the current |
305 * Consider that the number of saved undetermined variables can be different to the current |
299 * amount. This is because new captured variables could have been added. |
306 * amount. This is because new captured variables could have been added. |
300 */ |
307 */ |
301 void rollback(List<Type> saved_undet) { |
308 public void rollback(List<Type> saved_undet) { |
302 Assert.check(saved_undet != null); |
309 Assert.check(saved_undet != null); |
303 //restore bounds (note: we need to preserve the old instances) |
310 //restore bounds (note: we need to preserve the old instances) |
304 ListBuffer<Type> newUndetVars = new ListBuffer<>(); |
311 ListBuffer<Type> newUndetVars = new ListBuffer<>(); |
305 ListBuffer<Type> newInferenceVars = new ListBuffer<>(); |
312 ListBuffer<Type> newInferenceVars = new ListBuffer<>(); |
306 while (saved_undet.nonEmpty() && undetvars.nonEmpty()) { |
313 while (saved_undet.nonEmpty() && undetvars.nonEmpty()) { |