author | mcimadamore |
Thu, 04 Oct 2012 13:04:53 +0100 | |
changeset 14057 | b4b0377b8dba |
parent 14048 | 308d1cf8fe46 |
child 14058 | c7ec7facdd20 |
permissions | -rw-r--r-- |
10 | 1 |
/* |
11550
1d70546d4d78
7123100: javac fails with java.lang.StackOverflowError
mcimadamore
parents:
10950
diff
changeset
|
2 |
* Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved. |
10 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
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 |
|
5520 | 7 |
* published by the Free Software Foundation. Oracle designates this |
10 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5520 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
10 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5520 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
10 | 24 |
*/ |
25 |
||
26 |
package com.sun.tools.javac.comp; |
|
27 |
||
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
28 |
import com.sun.tools.javac.code.*; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
29 |
import com.sun.tools.javac.code.Symbol.*; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
30 |
import com.sun.tools.javac.code.Type.*; |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
31 |
import com.sun.tools.javac.code.Type.UndetVar.InferenceBound; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
32 |
import com.sun.tools.javac.comp.DeferredAttr.AttrMode; |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
33 |
import com.sun.tools.javac.comp.Resolve.InapplicableMethodException; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
34 |
import com.sun.tools.javac.comp.Resolve.VerboseResolutionMode; |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
35 |
import com.sun.tools.javac.tree.JCTree; |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
36 |
import com.sun.tools.javac.tree.JCTree.JCTypeCast; |
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
37 |
import com.sun.tools.javac.tree.TreeInfo; |
10 | 38 |
import com.sun.tools.javac.util.*; |
39 |
import com.sun.tools.javac.util.List; |
|
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10628
diff
changeset
|
40 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
10 | 41 |
|
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
42 |
import java.util.HashMap; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
43 |
import java.util.Map; |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
44 |
import java.util.Set; |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
45 |
|
10 | 46 |
import static com.sun.tools.javac.code.TypeTags.*; |
47 |
||
48 |
/** Helper class for type parameter inference, used by the attribution phase. |
|
49 |
* |
|
5847
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
50 |
* <p><b>This is NOT part of any supported API. |
1908176fd6e3
6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents:
5846
diff
changeset
|
51 |
* If you write code that depends on this, you do so at your own risk. |
10 | 52 |
* This code and its internal interfaces are subject to change or |
53 |
* deletion without notice.</b> |
|
54 |
*/ |
|
55 |
public class Infer { |
|
56 |
protected static final Context.Key<Infer> inferKey = |
|
57 |
new Context.Key<Infer>(); |
|
58 |
||
59 |
/** A value for prototypes that admit any type, including polymorphic ones. */ |
|
60 |
public static final Type anyPoly = new Type(NONE, null); |
|
61 |
||
62 |
Symtab syms; |
|
63 |
Types types; |
|
3778
38a70273507b
6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents:
3140
diff
changeset
|
64 |
Check chk; |
3140
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
3139
diff
changeset
|
65 |
Resolve rs; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
66 |
DeferredAttr deferredAttr; |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10628
diff
changeset
|
67 |
Log log; |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
735
diff
changeset
|
68 |
JCDiagnostic.Factory diags; |
10 | 69 |
|
70 |
public static Infer instance(Context context) { |
|
71 |
Infer instance = context.get(inferKey); |
|
72 |
if (instance == null) |
|
73 |
instance = new Infer(context); |
|
74 |
return instance; |
|
75 |
} |
|
76 |
||
77 |
protected Infer(Context context) { |
|
78 |
context.put(inferKey, this); |
|
79 |
syms = Symtab.instance(context); |
|
80 |
types = Types.instance(context); |
|
3140
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
3139
diff
changeset
|
81 |
rs = Resolve.instance(context); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
82 |
deferredAttr = DeferredAttr.instance(context); |
10816
ce8a7e9d8882
7098660: Write better overload resolution/inference tests
mcimadamore
parents:
10628
diff
changeset
|
83 |
log = Log.instance(context); |
3778
38a70273507b
6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents:
3140
diff
changeset
|
84 |
chk = Check.instance(context); |
1040
c0f5acfd9d15
6730423: Diagnostic formatter should be an instance field of JCDiagnostic
mcimadamore
parents:
735
diff
changeset
|
85 |
diags = JCDiagnostic.Factory.instance(context); |
13440
1ea85052f98d
7187104: Inference cleanup: remove redundant exception classes in Infer.java
mcimadamore
parents:
13438
diff
changeset
|
86 |
inferenceException = new InferenceException(diags); |
10 | 87 |
} |
88 |
||
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
89 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
90 |
* This exception class is design to store a list of diagnostics corresponding |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
91 |
* to inference errors that can arise during a method applicability check. |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
92 |
*/ |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
93 |
public static class InferenceException extends InapplicableMethodException { |
10 | 94 |
private static final long serialVersionUID = 0; |
95 |
||
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
96 |
List<JCDiagnostic> messages = List.nil(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
97 |
|
3140
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
3139
diff
changeset
|
98 |
InferenceException(JCDiagnostic.Factory diags) { |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
99 |
super(diags); |
10 | 100 |
} |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
101 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
102 |
@Override |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
103 |
InapplicableMethodException setMessage(JCDiagnostic diag) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
104 |
messages = messages.append(diag); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
105 |
return this; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
106 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
107 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
108 |
@Override |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
109 |
public JCDiagnostic getDiagnostic() { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
110 |
return messages.head; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
111 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
112 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
113 |
void clear() { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
114 |
messages = List.nil(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
115 |
} |
3140
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
3139
diff
changeset
|
116 |
} |
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
3139
diff
changeset
|
117 |
|
13440
1ea85052f98d
7187104: Inference cleanup: remove redundant exception classes in Infer.java
mcimadamore
parents:
13438
diff
changeset
|
118 |
private final InferenceException inferenceException; |
10 | 119 |
|
120 |
/*************************************************************************** |
|
121 |
* Mini/Maximization of UndetVars |
|
122 |
***************************************************************************/ |
|
123 |
||
124 |
/** Instantiate undetermined type variable to its minimal upper bound. |
|
125 |
* Throw a NoInstanceException if this not possible. |
|
126 |
*/ |
|
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
127 |
void maximizeInst(UndetVar that, Warner warn) throws InferenceException { |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
128 |
List<Type> hibounds = Type.filter(that.getBounds(InferenceBound.UPPER), boundFilter); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
129 |
if (that.getBounds(InferenceBound.EQ).isEmpty()) { |
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
130 |
if (hibounds.isEmpty()) |
10 | 131 |
that.inst = syms.objectType; |
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
132 |
else if (hibounds.tail.isEmpty()) |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
133 |
that.inst = hibounds.head; |
1991
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1257
diff
changeset
|
134 |
else |
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
135 |
that.inst = types.glb(hibounds); |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
136 |
} else { |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
137 |
that.inst = that.getBounds(InferenceBound.EQ).head; |
10 | 138 |
} |
1991
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1257
diff
changeset
|
139 |
if (that.inst == null || |
3139
01d76d311f8e
6835428: regression: return-type inference rejects valid code
mcimadamore
parents:
2212
diff
changeset
|
140 |
that.inst.isErroneous()) |
13440
1ea85052f98d
7187104: Inference cleanup: remove redundant exception classes in Infer.java
mcimadamore
parents:
13438
diff
changeset
|
141 |
throw inferenceException |
1991
aafb4bf914ee
6315770: javac inference allows creation of strange types: Integer & Runnable
mcimadamore
parents:
1257
diff
changeset
|
142 |
.setMessage("no.unique.maximal.instance.exists", |
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
143 |
that.qtype, hibounds); |
10 | 144 |
} |
145 |
||
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
146 |
private Filter<Type> boundFilter = new Filter<Type>() { |
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
147 |
@Override |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
148 |
public boolean accepts(Type t) { |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
149 |
return !t.isErroneous() && t.tag != BOT; |
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
150 |
} |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
151 |
}; |
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
152 |
|
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
153 |
/** Instantiate undetermined type variable to the lub of all its lower bounds. |
10 | 154 |
* Throw a NoInstanceException if this not possible. |
155 |
*/ |
|
13440
1ea85052f98d
7187104: Inference cleanup: remove redundant exception classes in Infer.java
mcimadamore
parents:
13438
diff
changeset
|
156 |
void minimizeInst(UndetVar that, Warner warn) throws InferenceException { |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
157 |
List<Type> lobounds = Type.filter(that.getBounds(InferenceBound.LOWER), boundFilter); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
158 |
if (that.getBounds(InferenceBound.EQ).isEmpty()) { |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
159 |
if (lobounds.isEmpty()) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
160 |
//do nothing - the inference variable is under-constrained |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
161 |
return; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
162 |
} else if (lobounds.tail.isEmpty()) |
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
163 |
that.inst = lobounds.head.isPrimitive() ? syms.errType : lobounds.head; |
10 | 164 |
else { |
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
165 |
that.inst = types.lub(lobounds); |
162
6620f2a8e265
6611449: Internal Error thrown during generic method/constructor invocation
mcimadamore
parents:
10
diff
changeset
|
166 |
} |
1257
873b053bf757
6557752: Original type of an AST should be made available even if it is replaced with an ErrorType
jjg
parents:
1206
diff
changeset
|
167 |
if (that.inst == null || that.inst.tag == ERROR) |
13440
1ea85052f98d
7187104: Inference cleanup: remove redundant exception classes in Infer.java
mcimadamore
parents:
13438
diff
changeset
|
168 |
throw inferenceException |
10 | 169 |
.setMessage("no.unique.minimal.instance.exists", |
8044
7fd529d4472c
6943278: spurious error message for inference and type-variable with erroneous bound
mcimadamore
parents:
8036
diff
changeset
|
170 |
that.qtype, lobounds); |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
171 |
} else { |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
172 |
that.inst = that.getBounds(InferenceBound.EQ).head; |
10 | 173 |
} |
174 |
} |
|
175 |
||
176 |
/*************************************************************************** |
|
177 |
* Exported Methods |
|
178 |
***************************************************************************/ |
|
179 |
||
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
180 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
181 |
* Instantiate uninferred inference variables (JLS 15.12.2.8). First |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
182 |
* if the method return type is non-void, we derive constraints from the |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
183 |
* expected type - then we use declared bound well-formedness to derive additional |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
184 |
* constraints. If no instantiation exists, or if several incomparable |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
185 |
* best instantiations exist throw a NoInstanceException. |
10 | 186 |
*/ |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
187 |
public void instantiateUninferred(DiagnosticPosition pos, |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
188 |
InferenceContext inferenceContext, |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
189 |
MethodType mtype, |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
190 |
Attr.ResultInfo resultInfo, |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
191 |
Warner warn) throws InferenceException { |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
192 |
Type to = resultInfo.pt; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
193 |
if (to.tag == NONE || resultInfo.checkContext.inferenceContext().free(resultInfo.pt)) { |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
194 |
to = mtype.getReturnType().tag <= VOID ? |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
195 |
mtype.getReturnType() : syms.objectType; |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
196 |
} |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
197 |
Type qtype1 = inferenceContext.asFree(mtype.getReturnType(), types); |
7331
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
6934
diff
changeset
|
198 |
if (!types.isSubtype(qtype1, |
02ffc087c654
6995200: JDK 7 compiler crashes when type-variable is inferred from expected primitive type
mcimadamore
parents:
6934
diff
changeset
|
199 |
qtype1.tag == UNDETVAR ? types.boxedTypeOrType(to) : to)) { |
13440
1ea85052f98d
7187104: Inference cleanup: remove redundant exception classes in Infer.java
mcimadamore
parents:
13438
diff
changeset
|
200 |
throw inferenceException |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
201 |
.setMessage("infer.no.conforming.instance.exists", |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
202 |
inferenceContext.restvars(), mtype.getReturnType(), to); |
10 | 203 |
} |
204 |
||
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
205 |
while (true) { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
206 |
boolean stuck = true; |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
207 |
for (Type t : inferenceContext.undetvars) { |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
208 |
UndetVar uv = (UndetVar)t; |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
209 |
if (uv.inst == null && (uv.getBounds(InferenceBound.EQ).nonEmpty() || |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
210 |
!inferenceContext.free(uv.getBounds(InferenceBound.UPPER)))) { |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
211 |
maximizeInst((UndetVar)t, warn); |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
212 |
stuck = false; |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
213 |
} |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
214 |
} |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
215 |
if (inferenceContext.restvars().isEmpty()) { |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
216 |
//all variables have been instantiated - exit |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
217 |
break; |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
218 |
} else if (stuck) { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
219 |
//some variables could not be instantiated because of cycles in |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
220 |
//upper bounds - provide a (possibly recursive) default instantiation |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
221 |
instantiateAsUninferredVars(inferenceContext); |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
222 |
break; |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
223 |
} else { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
224 |
//some variables have been instantiated - replace newly instantiated |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
225 |
//variables in remaining upper bounds and continue |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
226 |
for (Type t : inferenceContext.undetvars) { |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
227 |
UndetVar uv = (UndetVar)t; |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
228 |
uv.substBounds(inferenceContext.inferenceVars(), inferenceContext.instTypes(), types); |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
229 |
} |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
230 |
} |
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
6154
diff
changeset
|
231 |
} |
10 | 232 |
} |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
233 |
|
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
234 |
/** |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
235 |
* Infer cyclic inference variables as described in 15.12.2.8. |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
236 |
*/ |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
237 |
private void instantiateAsUninferredVars(InferenceContext inferenceContext) { |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
238 |
ListBuffer<Type> todo = ListBuffer.lb(); |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
239 |
//step 1 - create fresh tvars |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
240 |
for (Type t : inferenceContext.undetvars) { |
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
6154
diff
changeset
|
241 |
UndetVar uv = (UndetVar)t; |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
242 |
if (uv.inst == null) { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
243 |
TypeSymbol fresh_tvar = new TypeSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner); |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
244 |
fresh_tvar.type = new TypeVar(fresh_tvar, types.makeCompoundType(uv.getBounds(InferenceBound.UPPER)), null); |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
245 |
todo.append(uv); |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
246 |
uv.inst = fresh_tvar.type; |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
247 |
} |
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
6154
diff
changeset
|
248 |
} |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
249 |
//step 2 - replace fresh tvars in their bounds |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
250 |
List<Type> formals = inferenceContext.inferenceVars(); |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
251 |
for (Type t : todo) { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
252 |
UndetVar uv = (UndetVar)t; |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
253 |
TypeVar ct = (TypeVar)uv.inst; |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
254 |
ct.bound = types.glb(inferenceContext.asInstTypes(types.getBounds(ct), types)); |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
255 |
if (ct.bound.isErroneous()) { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
256 |
//report inference error if glb fails |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
257 |
reportBoundError(uv, BoundErrorKind.BAD_UPPER); |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
258 |
} |
11550
1d70546d4d78
7123100: javac fails with java.lang.StackOverflowError
mcimadamore
parents:
10950
diff
changeset
|
259 |
formals = formals.tail; |
6348
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
6154
diff
changeset
|
260 |
} |
6c9b14d4a438
6369605: Unconstrained type variables fails to include bounds
mcimadamore
parents:
6154
diff
changeset
|
261 |
} |
10 | 262 |
|
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
263 |
/** Instantiate a generic method type by finding instantiations for all its |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
264 |
* inference variables so that it can be applied to a given argument type list. |
10 | 265 |
*/ |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
266 |
public Type instantiateMethod(Env<AttrContext> env, |
5489
e7af65bf7577
6730476: invalid "unchecked generic array" warning
mcimadamore
parents:
3778
diff
changeset
|
267 |
List<Type> tvars, |
10 | 268 |
MethodType mt, |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
269 |
Attr.ResultInfo resultInfo, |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
270 |
Symbol msym, |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
271 |
List<Type> argtypes, |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
272 |
boolean allowBoxing, |
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
273 |
boolean useVarargs, |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
274 |
Resolve.MethodResolutionContext resolveContext, |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
275 |
Warner warn) throws InferenceException { |
10 | 276 |
//-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
277 |
final InferenceContext inferenceContext = new InferenceContext(tvars, this); |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
278 |
inferenceException.clear(); |
6710
b14e6fe7b290
5088624: cannot find symbol message should be more intelligent
mcimadamore
parents:
6592
diff
changeset
|
279 |
|
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
280 |
try { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
281 |
rs.checkRawArgumentsAcceptable(env, msym, resolveContext.attrMode(), inferenceContext, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
282 |
argtypes, mt.getParameterTypes(), allowBoxing, useVarargs, warn, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
283 |
new InferenceCheckHandler(inferenceContext)); |
10 | 284 |
|
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
285 |
// minimize as yet undetermined type variables |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
286 |
for (Type t : inferenceContext.undetvars) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
287 |
minimizeInst((UndetVar)t, warn); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
288 |
} |
3778
38a70273507b
6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents:
3140
diff
changeset
|
289 |
|
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
290 |
checkWithinBounds(inferenceContext, warn); |
10 | 291 |
|
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
292 |
mt = (MethodType)inferenceContext.asInstType(mt, types); |
10 | 293 |
|
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
294 |
List<Type> restvars = inferenceContext.restvars(); |
3140
15a274b13051
6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents:
3139
diff
changeset
|
295 |
|
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
296 |
if (!restvars.isEmpty()) { |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
297 |
if (resultInfo != null && !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) { |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
298 |
instantiateUninferred(env.tree.pos(), inferenceContext, mt, resultInfo, warn); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
299 |
checkWithinBounds(inferenceContext, warn); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
300 |
mt = (MethodType)inferenceContext.asInstType(mt, types); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
301 |
if (rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
302 |
log.note(env.tree.pos, "deferred.method.inst", msym, mt, resultInfo.pt); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
303 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
304 |
} |
12915
28cf1e0dafdc
7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents:
12468
diff
changeset
|
305 |
} |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
306 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
307 |
// return instantiated version of method type |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
308 |
return mt; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
309 |
} finally { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
310 |
inferenceContext.notifyChange(types); |
10 | 311 |
} |
312 |
} |
|
313 |
//where |
|
314 |
||
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
315 |
/** inference check handler **/ |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
316 |
class InferenceCheckHandler implements Resolve.MethodCheckHandler { |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
317 |
|
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
318 |
InferenceContext inferenceContext; |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
319 |
|
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
320 |
public InferenceCheckHandler(InferenceContext inferenceContext) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
321 |
this.inferenceContext = inferenceContext; |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
322 |
} |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
323 |
|
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
324 |
public InapplicableMethodException arityMismatch() { |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
325 |
return inferenceException.setMessage("infer.arg.length.mismatch", inferenceContext.inferenceVars()); |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
326 |
} |
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12915
diff
changeset
|
327 |
public InapplicableMethodException argumentMismatch(boolean varargs, JCDiagnostic details) { |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
328 |
String key = varargs ? |
13438
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12915
diff
changeset
|
329 |
"infer.varargs.argument.mismatch" : |
83729994273a
7175911: Simplify error reporting API in Check.CheckContext interface
mcimadamore
parents:
12915
diff
changeset
|
330 |
"infer.no.conforming.assignment.exists"; |
13440
1ea85052f98d
7187104: Inference cleanup: remove redundant exception classes in Infer.java
mcimadamore
parents:
13438
diff
changeset
|
331 |
return inferenceException.setMessage(key, |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
332 |
inferenceContext.inferenceVars(), details); |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
333 |
} |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
334 |
public InapplicableMethodException inaccessibleVarargs(Symbol location, Type expected) { |
13440
1ea85052f98d
7187104: Inference cleanup: remove redundant exception classes in Infer.java
mcimadamore
parents:
13438
diff
changeset
|
335 |
return inferenceException.setMessage("inaccessible.varargs.type", |
11707
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
336 |
expected, Kinds.kindName(location), location); |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
337 |
} |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
338 |
} |
532f41763bc9
7129801: Merge the two method applicability routines
mcimadamore
parents:
11550
diff
changeset
|
339 |
|
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
340 |
/** check that type parameters are within their bounds. |
8616
5a47f5535883
7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
8229
diff
changeset
|
341 |
*/ |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
342 |
void checkWithinBounds(InferenceContext inferenceContext, |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
343 |
Warner warn) throws InferenceException { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
344 |
//step 1 - check compatibility of instantiated type w.r.t. initial bounds |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
345 |
for (Type t : inferenceContext.undetvars) { |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
346 |
UndetVar uv = (UndetVar)t; |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
347 |
uv.substBounds(inferenceContext.inferenceVars(), inferenceContext.instTypes(), types); |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
348 |
checkCompatibleUpperBounds(uv, inferenceContext.inferenceVars()); |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
349 |
if (!inferenceContext.restvars().contains(uv.qtype)) { |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
350 |
Type inst = inferenceContext.asInstType(t, types); |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
351 |
for (Type u : uv.getBounds(InferenceBound.UPPER)) { |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
352 |
if (!types.isSubtypeUnchecked(inst, inferenceContext.asFree(u, types), warn)) { |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
353 |
reportBoundError(uv, BoundErrorKind.UPPER); |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
354 |
} |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
355 |
} |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
356 |
for (Type l : uv.getBounds(InferenceBound.LOWER)) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
357 |
Assert.check(!inferenceContext.free(l)); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
358 |
if (!types.isSubtypeUnchecked(l, inst, warn)) { |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
359 |
reportBoundError(uv, BoundErrorKind.LOWER); |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
360 |
} |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
361 |
} |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
362 |
for (Type e : uv.getBounds(InferenceBound.EQ)) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
363 |
Assert.check(!inferenceContext.free(e)); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
364 |
if (!types.isSameType(inst, e)) { |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
365 |
reportBoundError(uv, BoundErrorKind.EQ); |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
366 |
} |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
367 |
} |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
368 |
} |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
369 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
370 |
|
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
371 |
//step 2 - check that eq bounds are consistent w.r.t. eq/lower bounds |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
372 |
for (Type t : inferenceContext.undetvars) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
373 |
UndetVar uv = (UndetVar)t; |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
374 |
//check eq bounds consistency |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
375 |
Type eq = null; |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
376 |
for (Type e : uv.getBounds(InferenceBound.EQ)) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
377 |
Assert.check(!inferenceContext.free(e)); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
378 |
if (eq != null && !types.isSameType(e, eq)) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
379 |
reportBoundError(uv, BoundErrorKind.EQ); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
380 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
381 |
eq = e; |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
382 |
for (Type l : uv.getBounds(InferenceBound.LOWER)) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
383 |
Assert.check(!inferenceContext.free(l)); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
384 |
if (!types.isSubtypeUnchecked(l, e, warn)) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
385 |
reportBoundError(uv, BoundErrorKind.BAD_EQ_LOWER); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
386 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
387 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
388 |
for (Type u : uv.getBounds(InferenceBound.UPPER)) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
389 |
if (inferenceContext.free(u)) continue; |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
390 |
if (!types.isSubtypeUnchecked(e, u, warn)) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
391 |
reportBoundError(uv, BoundErrorKind.BAD_EQ_UPPER); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
392 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
393 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
394 |
} |
10 | 395 |
} |
8616
5a47f5535883
7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
8229
diff
changeset
|
396 |
} |
10 | 397 |
|
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
398 |
void checkCompatibleUpperBounds(UndetVar uv, List<Type> tvars) { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
399 |
// VGJ: sort of inlined maximizeInst() below. Adding |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
400 |
// bounds can cause lobounds that are above hibounds. |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
401 |
ListBuffer<Type> hiboundsNoVars = ListBuffer.lb(); |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
402 |
for (Type t : Type.filter(uv.getBounds(InferenceBound.UPPER), boundFilter)) { |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
403 |
if (!t.containsAny(tvars)) { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
404 |
hiboundsNoVars.append(t); |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
405 |
} |
10 | 406 |
} |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
407 |
List<Type> hibounds = hiboundsNoVars.toList(); |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
408 |
Type hb = null; |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
409 |
if (hibounds.isEmpty()) |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
410 |
hb = syms.objectType; |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
411 |
else if (hibounds.tail.isEmpty()) |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
412 |
hb = hibounds.head; |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
413 |
else |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
414 |
hb = types.glb(hibounds); |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
415 |
if (hb == null || hb.isErroneous()) |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
416 |
reportBoundError(uv, BoundErrorKind.BAD_UPPER); |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
417 |
} |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
418 |
|
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
419 |
enum BoundErrorKind { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
420 |
BAD_UPPER() { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
421 |
@Override |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
422 |
InapplicableMethodException setMessage(InferenceException ex, UndetVar uv) { |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
423 |
return ex.setMessage("incompatible.upper.bounds", uv.qtype, |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
424 |
uv.getBounds(InferenceBound.UPPER)); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
425 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
426 |
}, |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
427 |
BAD_EQ_UPPER() { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
428 |
@Override |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
429 |
InapplicableMethodException setMessage(InferenceException ex, UndetVar uv) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
430 |
return ex.setMessage("incompatible.eq.upper.bounds", uv.qtype, |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
431 |
uv.getBounds(InferenceBound.EQ), uv.getBounds(InferenceBound.UPPER)); |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
432 |
} |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
433 |
}, |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
434 |
BAD_EQ_LOWER() { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
435 |
@Override |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
436 |
InapplicableMethodException setMessage(InferenceException ex, UndetVar uv) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
437 |
return ex.setMessage("incompatible.eq.lower.bounds", uv.qtype, |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
438 |
uv.getBounds(InferenceBound.EQ), uv.getBounds(InferenceBound.LOWER)); |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
439 |
} |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
440 |
}, |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
441 |
UPPER() { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
442 |
@Override |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
443 |
InapplicableMethodException setMessage(InferenceException ex, UndetVar uv) { |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
444 |
return ex.setMessage("inferred.do.not.conform.to.upper.bounds", uv.inst, |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
445 |
uv.getBounds(InferenceBound.UPPER)); |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
446 |
} |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
447 |
}, |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
448 |
LOWER() { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
449 |
@Override |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
450 |
InapplicableMethodException setMessage(InferenceException ex, UndetVar uv) { |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
451 |
return ex.setMessage("inferred.do.not.conform.to.lower.bounds", uv.inst, |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
452 |
uv.getBounds(InferenceBound.LOWER)); |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
453 |
} |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
454 |
}, |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
455 |
EQ() { |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
456 |
@Override |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
457 |
InapplicableMethodException setMessage(InferenceException ex, UndetVar uv) { |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
458 |
return ex.setMessage("inferred.do.not.conform.to.eq.bounds", uv.inst, |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
459 |
uv.getBounds(InferenceBound.EQ)); |
12468
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
460 |
} |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
461 |
}; |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
462 |
|
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
463 |
abstract InapplicableMethodException setMessage(InferenceException ex, UndetVar uv); |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
464 |
} |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
465 |
//where |
1100643c0209
7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents:
12335
diff
changeset
|
466 |
void reportBoundError(UndetVar uv, BoundErrorKind bk) { |
13440
1ea85052f98d
7187104: Inference cleanup: remove redundant exception classes in Infer.java
mcimadamore
parents:
13438
diff
changeset
|
467 |
throw bk.setMessage(inferenceException, uv); |
10 | 468 |
} |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
469 |
|
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
470 |
/** |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
471 |
* Compute a synthetic method type corresponding to the requested polymorphic |
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
472 |
* method signature. The target return type is computed from the immediately |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
473 |
* enclosing scope surrounding the polymorphic-signature call. |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
474 |
*/ |
12335
4725d88691dd
7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents:
12334
diff
changeset
|
475 |
Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env, |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
476 |
MethodSymbol spMethod, // sig. poly. method or null if none |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
477 |
Resolve.MethodResolutionContext resolveContext, |
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
478 |
List<Type> argtypes) { |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
479 |
final Type restype; |
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
480 |
|
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
481 |
//The return type for a polymorphic signature call is computed from |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
482 |
//the enclosing tree E, as follows: if E is a cast, then use the |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
483 |
//target type of the cast expression as a return type; if E is an |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
484 |
//expression statement, the return type is 'void' - otherwise the |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
485 |
//return type is simply 'Object'. A correctness check ensures that |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
486 |
//env.next refers to the lexically enclosing environment in which |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
487 |
//the polymorphic signature call environment is nested. |
6934
258e5f06880f
6991980: polymorphic signature calls don't share the same CP entries
mcimadamore
parents:
6710
diff
changeset
|
488 |
|
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
489 |
switch (env.next.tree.getTag()) { |
10950 | 490 |
case TYPECAST: |
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
491 |
JCTypeCast castTree = (JCTypeCast)env.next.tree; |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
492 |
restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ? |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
493 |
castTree.clazz.type : |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
494 |
syms.objectType; |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
495 |
break; |
10950 | 496 |
case EXEC: |
8036
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
497 |
JCTree.JCExpressionStatement execTree = |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
498 |
(JCTree.JCExpressionStatement)env.next.tree; |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
499 |
restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ? |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
500 |
syms.voidType : |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
501 |
syms.objectType; |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
502 |
break; |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
503 |
default: |
17b976649c61
6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents:
7681
diff
changeset
|
504 |
restype = syms.objectType; |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
505 |
} |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
506 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
507 |
List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step)); |
6592
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
508 |
List<Type> exType = spMethod != null ? |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
509 |
spMethod.getThrownTypes() : |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
510 |
List.of(syms.throwableType); // make it throw all exceptions |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
511 |
|
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
512 |
MethodType mtype = new MethodType(paramtypes, |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
513 |
restype, |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
514 |
exType, |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
515 |
syms.methodClass); |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
516 |
return mtype; |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
517 |
} |
dc56420a69bc
6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents:
6348
diff
changeset
|
518 |
//where |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
519 |
class ImplicitArgType extends DeferredAttr.DeferredTypeMap { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
520 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
521 |
public ImplicitArgType(Symbol msym, Resolve.MethodResolutionPhase phase) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
522 |
deferredAttr.super(AttrMode.SPECULATIVE, msym, phase); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
523 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
524 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
525 |
public Type apply(Type t) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
526 |
t = types.erasure(super.apply(t)); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
527 |
if (t.tag == BOT) |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
528 |
// nulls type as the marker type Null (which has no instances) |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
529 |
// infer as java.lang.Void for now |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
530 |
t = types.boxedClass(syms.voidType).type; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
531 |
return t; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
532 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
533 |
} |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
534 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
535 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
536 |
* Mapping that turns inference variables into undet vars |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
537 |
* (used by inference context) |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
538 |
*/ |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
539 |
Mapping fromTypeVarFun = new Mapping("fromTypeVarFun") { |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
540 |
public Type apply(Type t) { |
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
541 |
if (t.tag == TYPEVAR) return new UndetVar((TypeVar)t, types); |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
542 |
else return t.map(this); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
543 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
544 |
}; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
545 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
546 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
547 |
* An inference context keeps track of the set of variables that are free |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
548 |
* in the current context. It provides utility methods for opening/closing |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
549 |
* types to their corresponding free/closed forms. It also provide hooks for |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
550 |
* attaching deferred post-inference action (see PendingCheck). Finally, |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
551 |
* it can be used as an entry point for performing upper/lower bound inference |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
552 |
* (see InferenceKind). |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
553 |
*/ |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
554 |
static class InferenceContext { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
555 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
556 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
557 |
* Single-method-interface for defining inference callbacks. Certain actions |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
558 |
* (i.e. subtyping checks) might need to be redone after all inference variables |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
559 |
* have been fixed. |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
560 |
*/ |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
561 |
interface FreeTypeListener { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
562 |
void typesInferred(InferenceContext inferenceContext); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
563 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
564 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
565 |
/** list of inference vars as undet vars */ |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
566 |
List<Type> undetvars; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
567 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
568 |
/** list of inference vars in this context */ |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
569 |
List<Type> inferencevars; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
570 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
571 |
java.util.Map<FreeTypeListener, List<Type>> freeTypeListeners = |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
572 |
new java.util.HashMap<FreeTypeListener, List<Type>>(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
573 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
574 |
List<FreeTypeListener> freetypeListeners = List.nil(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
575 |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
576 |
public InferenceContext(List<Type> inferencevars, Infer infer) { |
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
577 |
this.undetvars = Type.map(inferencevars, infer.fromTypeVarFun); |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
578 |
this.inferencevars = inferencevars; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
579 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
580 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
581 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
582 |
* returns the list of free variables (as type-variables) in this |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
583 |
* inference context |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
584 |
*/ |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
585 |
List<Type> inferenceVars() { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
586 |
return inferencevars; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
587 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
588 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
589 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
590 |
* returns the list of uninstantiated variables (as type-variables) in this |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
591 |
* inference context (usually called after instantiate()) |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
592 |
*/ |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
593 |
List<Type> restvars() { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
594 |
List<Type> undetvars = this.undetvars; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
595 |
ListBuffer<Type> restvars = ListBuffer.lb(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
596 |
for (Type t : instTypes()) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
597 |
UndetVar uv = (UndetVar)undetvars.head; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
598 |
if (uv.qtype == t) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
599 |
restvars.append(t); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
600 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
601 |
undetvars = undetvars.tail; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
602 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
603 |
return restvars.toList(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
604 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
605 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
606 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
607 |
* is this type free? |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
608 |
*/ |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
609 |
final boolean free(Type t) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
610 |
return t.containsAny(inferencevars); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
611 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
612 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
613 |
final boolean free(List<Type> ts) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
614 |
for (Type t : ts) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
615 |
if (free(t)) return true; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
616 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
617 |
return false; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
618 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
619 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
620 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
621 |
* Returns a list of free variables in a given type |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
622 |
*/ |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
623 |
final List<Type> freeVarsIn(Type t) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
624 |
ListBuffer<Type> buf = ListBuffer.lb(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
625 |
for (Type iv : inferenceVars()) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
626 |
if (t.contains(iv)) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
627 |
buf.add(iv); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
628 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
629 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
630 |
return buf.toList(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
631 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
632 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
633 |
final List<Type> freeVarsIn(List<Type> ts) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
634 |
ListBuffer<Type> buf = ListBuffer.lb(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
635 |
for (Type t : ts) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
636 |
buf.appendList(freeVarsIn(t)); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
637 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
638 |
ListBuffer<Type> buf2 = ListBuffer.lb(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
639 |
for (Type t : buf) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
640 |
if (!buf2.contains(t)) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
641 |
buf2.add(t); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
642 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
643 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
644 |
return buf2.toList(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
645 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
646 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
647 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
648 |
* Replace all free variables in a given type with corresponding |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
649 |
* undet vars (used ahead of subtyping/compatibility checks to allow propagation |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
650 |
* of inference constraints). |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
651 |
*/ |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
652 |
final Type asFree(Type t, Types types) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
653 |
return types.subst(t, inferencevars, undetvars); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
654 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
655 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
656 |
final List<Type> asFree(List<Type> ts, Types types) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
657 |
ListBuffer<Type> buf = ListBuffer.lb(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
658 |
for (Type t : ts) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
659 |
buf.append(asFree(t, types)); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
660 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
661 |
return buf.toList(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
662 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
663 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
664 |
List<Type> instTypes() { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
665 |
ListBuffer<Type> buf = ListBuffer.lb(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
666 |
for (Type t : undetvars) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
667 |
UndetVar uv = (UndetVar)t; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
668 |
buf.append(uv.inst != null ? uv.inst : uv.qtype); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
669 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
670 |
return buf.toList(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
671 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
672 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
673 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
674 |
* Replace all free variables in a given type with corresponding |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
675 |
* instantiated types - if one or more free variable has not been |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
676 |
* fully instantiated, it will still be available in the resulting type. |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
677 |
*/ |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
678 |
Type asInstType(Type t, Types types) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
679 |
return types.subst(t, inferencevars, instTypes()); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
680 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
681 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
682 |
List<Type> asInstTypes(List<Type> ts, Types types) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
683 |
ListBuffer<Type> buf = ListBuffer.lb(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
684 |
for (Type t : ts) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
685 |
buf.append(asInstType(t, types)); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
686 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
687 |
return buf.toList(); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
688 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
689 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
690 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
691 |
* Add custom hook for performing post-inference action |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
692 |
*/ |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
693 |
void addFreeTypeListener(List<Type> types, FreeTypeListener ftl) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
694 |
freeTypeListeners.put(ftl, freeVarsIn(types)); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
695 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
696 |
|
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
697 |
/** |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
698 |
* Mark the inference context as complete and trigger evaluation |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
699 |
* of all deferred checks. |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
700 |
*/ |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
701 |
void notifyChange(Types types) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
702 |
InferenceException thrownEx = null; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
703 |
for (Map.Entry<FreeTypeListener, List<Type>> entry : |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
704 |
new HashMap<FreeTypeListener, List<Type>>(freeTypeListeners).entrySet()) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
705 |
if (!Type.containsAny(entry.getValue(), restvars())) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
706 |
try { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
707 |
entry.getKey().typesInferred(this); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
708 |
freeTypeListeners.remove(entry.getKey()); |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
709 |
} catch (InferenceException ex) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
710 |
if (thrownEx == null) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
711 |
thrownEx = ex; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
712 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
713 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
714 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
715 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
716 |
//inference exception multiplexing - present any inference exception |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
717 |
//thrown when processing listeners as a single one |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
718 |
if (thrownEx != null) { |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
719 |
throw thrownEx; |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
720 |
} |
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
721 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
722 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
723 |
void solveAny(List<Type> varsToSolve, Types types, Infer infer) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
724 |
boolean progress = false; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
725 |
for (Type t : varsToSolve) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
726 |
UndetVar uv = (UndetVar)asFree(t, types); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
727 |
if (uv.inst == null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
728 |
infer.minimizeInst(uv, Warner.noWarnings); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
729 |
if (uv.inst != null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
730 |
progress = true; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
731 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
732 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
733 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
734 |
if (!progress) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
735 |
throw infer.inferenceException.setMessage("cyclic.inference", varsToSolve); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
736 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
14048
diff
changeset
|
737 |
} |
8616
5a47f5535883
7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents:
8229
diff
changeset
|
738 |
} |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
739 |
|
14048
308d1cf8fe46
7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents:
14047
diff
changeset
|
740 |
final InferenceContext emptyContext = new InferenceContext(List.<Type>nil(), this); |
14047
7c7a5611cf76
7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents:
13440
diff
changeset
|
741 |
} |