author | jlahoda |
Fri, 22 Jan 2016 21:00:26 +0100 | |
changeset 35355 | 817b3a285dbb |
parent 33020 | 7ed4f7ff42c5 |
child 36526 | 3b41f1c69604 |
permissions | -rw-r--r-- |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
1 |
/* |
28891
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
28458
diff
changeset
|
2 |
* Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved. |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
4 |
* |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
10 |
* |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
15 |
* accompanied this code). |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
16 |
* |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
20 |
* |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
23 |
* questions. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
24 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
25 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
26 |
package com.sun.tools.javac.comp; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
27 |
|
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
28 |
import com.sun.source.tree.LambdaExpressionTree.BodyKind; |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
29 |
import com.sun.source.tree.NewClassTree; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
30 |
import com.sun.tools.javac.code.*; |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
31 |
import com.sun.tools.javac.code.Type.TypeMapping; |
32911
6ee3c12d2d18
8137269: Add better support for local caching in ArgumentAttr
mcimadamore
parents:
32709
diff
changeset
|
32 |
import com.sun.tools.javac.comp.ArgumentAttr.LocalCacheContext; |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
33 |
import com.sun.tools.javac.comp.Resolve.ResolveError; |
28458
f20c5dd05e34
8069164: Fix langtools make build so that diagnostic framework can be used
mcimadamore
parents:
28457
diff
changeset
|
34 |
import com.sun.tools.javac.resources.CompilerProperties.Fragments; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
35 |
import com.sun.tools.javac.tree.*; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
36 |
import com.sun.tools.javac.util.*; |
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
37 |
import com.sun.tools.javac.util.DefinedBy.Api; |
16805
b419336382fd
8010922: Cleanup: add support for ad-hoc method check logic
mcimadamore
parents:
16566
diff
changeset
|
38 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
39 |
import com.sun.tools.javac.code.Symbol.*; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
40 |
import com.sun.tools.javac.comp.Attr.ResultInfo; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
41 |
import com.sun.tools.javac.comp.Resolve.MethodResolutionPhase; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
42 |
import com.sun.tools.javac.tree.JCTree.*; |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
43 |
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticType; |
28142
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
44 |
import com.sun.tools.javac.util.Log.DeferredDiagnosticHandler; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
45 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
46 |
import java.util.ArrayList; |
19914 | 47 |
import java.util.Collections; |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
48 |
import java.util.EnumSet; |
19914 | 49 |
import java.util.LinkedHashMap; |
14547 | 50 |
import java.util.LinkedHashSet; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
51 |
import java.util.Map; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
52 |
import java.util.Set; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
53 |
import java.util.WeakHashMap; |
28142
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
54 |
import java.util.function.Function; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
55 |
|
14547 | 56 |
import static com.sun.tools.javac.code.TypeTag.*; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
57 |
import static com.sun.tools.javac.tree.JCTree.Tag.*; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
58 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
59 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
60 |
* This is an helper class that is used to perform deferred type-analysis. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
61 |
* Each time a poly expression occurs in argument position, javac attributes it |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
62 |
* with a temporary 'deferred type' that is checked (possibly multiple times) |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
63 |
* against an expected formal type. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
64 |
* |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
65 |
* <p><b>This is NOT part of any supported API. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
66 |
* If you write code that depends on this, you do so at your own risk. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
67 |
* This code and its internal interfaces are subject to change or |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
68 |
* deletion without notice.</b> |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
69 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
70 |
public class DeferredAttr extends JCTree.Visitor { |
22163 | 71 |
protected static final Context.Key<DeferredAttr> deferredAttrKey = new Context.Key<>(); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
72 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
73 |
final Attr attr; |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
74 |
final ArgumentAttr argumentAttr; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
75 |
final Check chk; |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15039
diff
changeset
|
76 |
final JCDiagnostic.Factory diags; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
77 |
final Enter enter; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
78 |
final Infer infer; |
16294
0c291a3cd60d
8007462: Fix provisional applicability for method references
mcimadamore
parents:
15717
diff
changeset
|
79 |
final Resolve rs; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
80 |
final Log log; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
81 |
final Symtab syms; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
82 |
final TreeMaker make; |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
83 |
final TreeCopier<Void> treeCopier; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
84 |
final TypeMapping<Void> deferredCopier; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
85 |
final Types types; |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
86 |
final Flow flow; |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
87 |
final Names names; |
25007 | 88 |
final TypeEnvs typeEnvs; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
89 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
90 |
public static DeferredAttr instance(Context context) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
91 |
DeferredAttr instance = context.get(deferredAttrKey); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
92 |
if (instance == null) |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
93 |
instance = new DeferredAttr(context); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
94 |
return instance; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
95 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
96 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
97 |
protected DeferredAttr(Context context) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
98 |
context.put(deferredAttrKey, this); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
99 |
attr = Attr.instance(context); |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
100 |
argumentAttr = ArgumentAttr.instance(context); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
101 |
chk = Check.instance(context); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15039
diff
changeset
|
102 |
diags = JCDiagnostic.Factory.instance(context); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
103 |
enter = Enter.instance(context); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
104 |
infer = Infer.instance(context); |
16294
0c291a3cd60d
8007462: Fix provisional applicability for method references
mcimadamore
parents:
15717
diff
changeset
|
105 |
rs = Resolve.instance(context); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
106 |
log = Log.instance(context); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
107 |
syms = Symtab.instance(context); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
108 |
make = TreeMaker.instance(context); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
109 |
types = Types.instance(context); |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
110 |
flow = Flow.instance(context); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
111 |
names = Names.instance(context); |
18902 | 112 |
stuckTree = make.Ident(names.empty).setType(Type.stuckType); |
25007 | 113 |
typeEnvs = TypeEnvs.instance(context); |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18902
diff
changeset
|
114 |
emptyDeferredAttrContext = |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18902
diff
changeset
|
115 |
new DeferredAttrContext(AttrMode.CHECK, null, MethodResolutionPhase.BOX, infer.emptyContext, null, null) { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18902
diff
changeset
|
116 |
@Override |
19914 | 117 |
void addDeferredAttrNode(DeferredType dt, ResultInfo ri, DeferredStuckPolicy deferredStuckPolicy) { |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18902
diff
changeset
|
118 |
Assert.error("Empty deferred context!"); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18902
diff
changeset
|
119 |
} |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18902
diff
changeset
|
120 |
@Override |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18902
diff
changeset
|
121 |
void complete() { |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18902
diff
changeset
|
122 |
Assert.error("Empty deferred context!"); |
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18902
diff
changeset
|
123 |
} |
24226
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
24066
diff
changeset
|
124 |
|
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
24066
diff
changeset
|
125 |
@Override |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
24066
diff
changeset
|
126 |
public String toString() { |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
24066
diff
changeset
|
127 |
return "Empty deferred context!"; |
08b586e22328
8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents:
24066
diff
changeset
|
128 |
} |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18902
diff
changeset
|
129 |
}; |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
130 |
|
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
131 |
// For speculative attribution, skip the class definition in <>. |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
132 |
treeCopier = |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
133 |
new TreeCopier<Void>(make) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
134 |
@Override @DefinedBy(Api.COMPILER_TREE) |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
135 |
public JCTree visitNewClass(NewClassTree node, Void p) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
136 |
JCNewClass t = (JCNewClass) node; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
137 |
if (TreeInfo.isDiamond(t)) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
138 |
JCExpression encl = copy(t.encl, p); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
139 |
List<JCExpression> typeargs = copy(t.typeargs, p); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
140 |
JCExpression clazz = copy(t.clazz, p); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
141 |
List<JCExpression> args = copy(t.args, p); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
142 |
JCClassDecl def = null; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
143 |
return make.at(t.pos).NewClass(encl, typeargs, clazz, args, def); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
144 |
} else { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
145 |
return super.visitNewClass(node, p); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
146 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
147 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
148 |
}; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
149 |
deferredCopier = new TypeMapping<Void> () { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
150 |
@Override |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
151 |
public Type visitType(Type t, Void v) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
152 |
if (t.hasTag(DEFERRED)) { |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
153 |
DeferredType dt = (DeferredType) t; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
154 |
return new DeferredType(treeCopier.copy(dt.tree), dt.env); |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
155 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
156 |
return t; |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
157 |
} |
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
158 |
}; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
159 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
160 |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15039
diff
changeset
|
161 |
/** shared tree for stuck expressions */ |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15039
diff
changeset
|
162 |
final JCTree stuckTree; |
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15039
diff
changeset
|
163 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
164 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
165 |
* This type represents a deferred type. A deferred type starts off with |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
166 |
* no information on the underlying expression type. Such info needs to be |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
167 |
* discovered through type-checking the deferred type against a target-type. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
168 |
* Every deferred type keeps a pointer to the AST node from which it originated. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
169 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
170 |
public class DeferredType extends Type { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
171 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
172 |
public JCExpression tree; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
173 |
Env<AttrContext> env; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
174 |
AttrMode mode; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
175 |
SpeculativeCache speculativeCache; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
176 |
|
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26531
diff
changeset
|
177 |
DeferredType(JCExpression tree, Env<AttrContext> env) { |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
178 |
super(null, TypeMetadata.EMPTY); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
179 |
this.tree = tree; |
18912
e25cd61d8e59
8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents:
18910
diff
changeset
|
180 |
this.env = attr.copyEnv(env); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
181 |
this.speculativeCache = new SpeculativeCache(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
182 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
183 |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18643
diff
changeset
|
184 |
@Override |
29842
826ac2519523
8031744: Annotations on many Language Model elements are not returned
jjg
parents:
29776
diff
changeset
|
185 |
public DeferredType cloneWithMetadata(TypeMetadata md) { |
26781
a786b07c7b91
8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents:
26532
diff
changeset
|
186 |
throw new AssertionError("Cannot add metadata to a deferred type"); |
24396 | 187 |
} |
188 |
||
189 |
@Override |
|
18646
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18643
diff
changeset
|
190 |
public TypeTag getTag() { |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18643
diff
changeset
|
191 |
return DEFERRED; |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18643
diff
changeset
|
192 |
} |
e628560a86d1
8017104: javac should have a class for primitive types that inherits from Type
vromero
parents:
18643
diff
changeset
|
193 |
|
26266
2d24bda701dc
8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents:
25874
diff
changeset
|
194 |
@Override @DefinedBy(Api.LANGUAGE_MODEL) |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
195 |
public String toString() { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
196 |
return "DeferredType"; |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
197 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
198 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
199 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
200 |
* A speculative cache is used to keep track of all overload resolution rounds |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
201 |
* that triggered speculative attribution on a given deferred type. Each entry |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
202 |
* stores a pointer to the speculative tree and the resolution phase in which the entry |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
203 |
* has been added. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
204 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
205 |
class SpeculativeCache { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
206 |
|
22163 | 207 |
private Map<Symbol, List<Entry>> cache = new WeakHashMap<>(); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
208 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
209 |
class Entry { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
210 |
JCTree speculativeTree; |
19914 | 211 |
ResultInfo resultInfo; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
212 |
|
19914 | 213 |
public Entry(JCTree speculativeTree, ResultInfo resultInfo) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
214 |
this.speculativeTree = speculativeTree; |
19914 | 215 |
this.resultInfo = resultInfo; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
216 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
217 |
|
19914 | 218 |
boolean matches(MethodResolutionPhase phase) { |
219 |
return resultInfo.checkContext.deferredAttrContext().phase == phase; |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
220 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
221 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
222 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
223 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
224 |
* Retrieve a speculative cache entry corresponding to given symbol |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
225 |
* and resolution phase |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
226 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
227 |
Entry get(Symbol msym, MethodResolutionPhase phase) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
228 |
List<Entry> entries = cache.get(msym); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
229 |
if (entries == null) return null; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
230 |
for (Entry e : entries) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
231 |
if (e.matches(phase)) return e; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
232 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
233 |
return null; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
234 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
235 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
236 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
237 |
* Stores a speculative cache entry corresponding to given symbol |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
238 |
* and resolution phase |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
239 |
*/ |
19914 | 240 |
void put(JCTree speculativeTree, ResultInfo resultInfo) { |
241 |
Symbol msym = resultInfo.checkContext.deferredAttrContext().msym; |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
242 |
List<Entry> entries = cache.get(msym); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
243 |
if (entries == null) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
244 |
entries = List.nil(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
245 |
} |
19914 | 246 |
cache.put(msym, entries.prepend(new Entry(speculativeTree, resultInfo))); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
247 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
248 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
249 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
250 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
251 |
* Get the type that has been computed during a speculative attribution round |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
252 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
253 |
Type speculativeType(Symbol msym, MethodResolutionPhase phase) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
254 |
SpeculativeCache.Entry e = speculativeCache.get(msym, phase); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
255 |
return e != null ? e.speculativeTree.type : Type.noType; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
256 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
257 |
|
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
258 |
JCTree speculativeTree(DeferredAttrContext deferredAttrContext) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
259 |
DeferredType.SpeculativeCache.Entry e = speculativeCache.get(deferredAttrContext.msym, deferredAttrContext.phase); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
260 |
return e != null ? e.speculativeTree : stuckTree; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
261 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
262 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
263 |
DeferredTypeCompleter completer() { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
264 |
return basicCompleter; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
265 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
266 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
267 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
268 |
* Check a deferred type against a potential target-type. Depending on |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
269 |
* the current attribution mode, a normal vs. speculative attribution |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
270 |
* round is performed on the underlying AST node. There can be only one |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
271 |
* speculative round for a given target method symbol; moreover, a normal |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
272 |
* attribution round must follow one or more speculative rounds. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
273 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
274 |
Type check(ResultInfo resultInfo) { |
19914 | 275 |
DeferredStuckPolicy deferredStuckPolicy; |
276 |
if (resultInfo.pt.hasTag(NONE) || resultInfo.pt.isErroneous()) { |
|
277 |
deferredStuckPolicy = dummyStuckPolicy; |
|
28891
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
28458
diff
changeset
|
278 |
} else if (resultInfo.checkContext.deferredAttrContext().mode == AttrMode.SPECULATIVE || |
dc7d89f2e25c
8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents:
28458
diff
changeset
|
279 |
resultInfo.checkContext.deferredAttrContext().insideOverloadPhase()) { |
19914 | 280 |
deferredStuckPolicy = new OverloadStuckPolicy(resultInfo, this); |
281 |
} else { |
|
282 |
deferredStuckPolicy = new CheckStuckPolicy(resultInfo, this); |
|
283 |
} |
|
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
284 |
return check(resultInfo, deferredStuckPolicy, completer()); |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
285 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
286 |
|
19914 | 287 |
private Type check(ResultInfo resultInfo, DeferredStuckPolicy deferredStuckPolicy, |
288 |
DeferredTypeCompleter deferredTypeCompleter) { |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
289 |
DeferredAttrContext deferredAttrContext = |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
290 |
resultInfo.checkContext.deferredAttrContext(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
291 |
Assert.check(deferredAttrContext != emptyDeferredAttrContext); |
19914 | 292 |
if (deferredStuckPolicy.isStuck()) { |
293 |
deferredAttrContext.addDeferredAttrNode(this, resultInfo, deferredStuckPolicy); |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
294 |
return Type.noType; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
295 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
296 |
try { |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
297 |
return deferredTypeCompleter.complete(this, resultInfo, deferredAttrContext); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
298 |
} finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
299 |
mode = deferredAttrContext.mode; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
300 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
301 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
302 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
303 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
304 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
305 |
/** |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
306 |
* A completer for deferred types. Defines an entry point for type-checking |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
307 |
* a deferred type. |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
308 |
*/ |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
309 |
interface DeferredTypeCompleter { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
310 |
/** |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
311 |
* Entry point for type-checking a deferred type. Depending on the |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
312 |
* circumstances, type-checking could amount to full attribution |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
313 |
* or partial structural check (aka potential applicability). |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
314 |
*/ |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
315 |
Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext); |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
316 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
317 |
|
19914 | 318 |
|
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
319 |
/** |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
320 |
* A basic completer for deferred types. This completer type-checks a deferred type |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
321 |
* using attribution; depending on the attribution mode, this could be either standard |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
322 |
* or speculative attribution. |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
323 |
*/ |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
324 |
DeferredTypeCompleter basicCompleter = new DeferredTypeCompleter() { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
325 |
public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
326 |
switch (deferredAttrContext.mode) { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
327 |
case SPECULATIVE: |
16566
604ce45d5f23
8009820: AssertionError when compiling java code with two identical static imports
mcimadamore
parents:
16326
diff
changeset
|
328 |
//Note: if a symbol is imported twice we might do two identical |
604ce45d5f23
8009820: AssertionError when compiling java code with two identical static imports
mcimadamore
parents:
16326
diff
changeset
|
329 |
//speculative rounds... |
604ce45d5f23
8009820: AssertionError when compiling java code with two identical static imports
mcimadamore
parents:
16326
diff
changeset
|
330 |
Assert.check(dt.mode == null || dt.mode == AttrMode.SPECULATIVE); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26531
diff
changeset
|
331 |
JCTree speculativeTree = attribSpeculative(dt.tree, dt.env, resultInfo); |
19914 | 332 |
dt.speculativeCache.put(speculativeTree, resultInfo); |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
333 |
return speculativeTree.type; |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
334 |
case CHECK: |
15717 | 335 |
Assert.check(dt.mode != null); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26531
diff
changeset
|
336 |
return attr.attribTree(dt.tree, dt.env, resultInfo); |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
337 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
338 |
Assert.error(); |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
339 |
return null; |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
340 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
341 |
}; |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
342 |
|
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
343 |
/** |
19914 | 344 |
* Policy for detecting stuck expressions. Different criteria might cause |
345 |
* an expression to be judged as stuck, depending on whether the check |
|
346 |
* is performed during overload resolution or after most specific. |
|
347 |
*/ |
|
348 |
interface DeferredStuckPolicy { |
|
349 |
/** |
|
350 |
* Has the policy detected that a given expression should be considered stuck? |
|
351 |
*/ |
|
352 |
boolean isStuck(); |
|
353 |
/** |
|
354 |
* Get the set of inference variables a given expression depends upon. |
|
355 |
*/ |
|
356 |
Set<Type> stuckVars(); |
|
357 |
/** |
|
358 |
* Get the set of inference variables which might get new constraints |
|
359 |
* if a given expression is being type-checked. |
|
360 |
*/ |
|
361 |
Set<Type> depVars(); |
|
362 |
} |
|
363 |
||
364 |
/** |
|
365 |
* Basic stuck policy; an expression is never considered to be stuck. |
|
366 |
*/ |
|
367 |
DeferredStuckPolicy dummyStuckPolicy = new DeferredStuckPolicy() { |
|
368 |
@Override |
|
369 |
public boolean isStuck() { |
|
370 |
return false; |
|
371 |
} |
|
372 |
@Override |
|
373 |
public Set<Type> stuckVars() { |
|
374 |
return Collections.emptySet(); |
|
375 |
} |
|
376 |
@Override |
|
377 |
public Set<Type> depVars() { |
|
378 |
return Collections.emptySet(); |
|
379 |
} |
|
380 |
}; |
|
381 |
||
382 |
/** |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
383 |
* The 'mode' in which the deferred type is to be type-checked |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
384 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
385 |
public enum AttrMode { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
386 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
387 |
* A speculative type-checking round is used during overload resolution |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
388 |
* mainly to generate constraints on inference variables. Side-effects |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
389 |
* arising from type-checking the expression associated with the deferred |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
390 |
* type are reversed after the speculative round finishes. This means the |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
391 |
* expression tree will be left in a blank state. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
392 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
393 |
SPECULATIVE, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
394 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
395 |
* This is the plain type-checking mode. Produces side-effects on the underlying AST node |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
396 |
*/ |
22163 | 397 |
CHECK |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
398 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
399 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
400 |
/** |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
401 |
* Performs speculative attribution of a lambda body and returns the speculative lambda tree, |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
402 |
* in the absence of a target-type. Since {@link Attr#visitLambda(JCLambda)} cannot type-check |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
403 |
* lambda bodies w/o a suitable target-type, this routine 'unrolls' the lambda by turning it |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
404 |
* into a regular block, speculatively type-checks the block and then puts back the pieces. |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
405 |
*/ |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
406 |
JCLambda attribSpeculativeLambda(JCLambda that, Env<AttrContext> env, ResultInfo resultInfo) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
407 |
ListBuffer<JCStatement> stats = new ListBuffer<>(); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
408 |
stats.addAll(that.params); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
409 |
if (that.getBodyKind() == JCLambda.BodyKind.EXPRESSION) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
410 |
stats.add(make.Return((JCExpression)that.body)); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
411 |
} else { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
412 |
stats.add((JCBlock)that.body); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
413 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
414 |
JCBlock lambdaBlock = make.Block(0, stats.toList()); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
415 |
Env<AttrContext> localEnv = attr.lambdaEnv(that, env); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
416 |
try { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
417 |
localEnv.info.returnResult = resultInfo; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
418 |
JCBlock speculativeTree = (JCBlock)attribSpeculative(lambdaBlock, localEnv, resultInfo); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
419 |
List<JCVariableDecl> args = speculativeTree.getStatements().stream() |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
420 |
.filter(s -> s.hasTag(Tag.VARDEF)) |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
421 |
.map(t -> (JCVariableDecl)t) |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
422 |
.collect(List.collector()); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
423 |
JCTree lambdaBody = speculativeTree.getStatements().last(); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
424 |
if (lambdaBody.hasTag(Tag.RETURN)) { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
425 |
lambdaBody = ((JCReturn)lambdaBody).expr; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
426 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
427 |
JCLambda speculativeLambda = make.Lambda(args, lambdaBody); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
428 |
attr.preFlow(speculativeLambda); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
429 |
flow.analyzeLambda(env, speculativeLambda, make, false); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
430 |
return speculativeLambda; |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
431 |
} finally { |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
432 |
localEnv.info.scope.leave(); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
433 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
434 |
} |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
435 |
|
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
436 |
/** |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
437 |
* Routine that performs speculative type-checking; the input AST node is |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
438 |
* cloned (to avoid side-effects cause by Attr) and compiler state is |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
439 |
* restored after type-checking. All diagnostics (but critical ones) are |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
440 |
* disabled during speculative type-checking. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
441 |
*/ |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26531
diff
changeset
|
442 |
JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) { |
29776
984a79b71cfe
8062373: Project Coin: diamond and anonymous classes
sadayapalam
parents:
29774
diff
changeset
|
443 |
return attribSpeculative(tree, env, resultInfo, treeCopier, |
28142
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
444 |
(newTree)->new DeferredAttrDiagHandler(log, newTree)); |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
445 |
} |
16309
db71f8ecc136
8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents:
16294
diff
changeset
|
446 |
|
28142
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
447 |
<Z> JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo, TreeCopier<Z> deferredCopier, |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
448 |
Function<JCTree, DeferredDiagnosticHandler> diagHandlerCreator) { |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
449 |
final JCTree newTree = deferredCopier.copy(tree); |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
450 |
Env<AttrContext> speculativeEnv = env.dup(newTree, env.info.dup(env.info.scope.dupUnshared(env.info.scope.owner))); |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
451 |
speculativeEnv.info.isSpeculative = true; |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
452 |
Log.DeferredDiagnosticHandler deferredDiagnosticHandler = diagHandlerCreator.apply(newTree); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
453 |
try { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
454 |
attr.attribTree(newTree, speculativeEnv, resultInfo); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
455 |
unenterScanner.scan(newTree); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
456 |
return newTree; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
457 |
} finally { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
458 |
unenterScanner.scan(newTree); |
14538
384681be798f
8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents:
14359
diff
changeset
|
459 |
log.popDiagnosticHandler(deferredDiagnosticHandler); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
460 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
461 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
462 |
//where |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
463 |
protected UnenterScanner unenterScanner = new UnenterScanner(); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
464 |
|
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
465 |
class UnenterScanner extends TreeScanner { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
466 |
@Override |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
467 |
public void visitClassDef(JCClassDecl tree) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
468 |
ClassSymbol csym = tree.sym; |
14547 | 469 |
//if something went wrong during method applicability check |
470 |
//it is possible that nested expressions inside argument expression |
|
471 |
//are left unchecked - in such cases there's nothing to clean up. |
|
472 |
if (csym == null) return; |
|
25007 | 473 |
typeEnvs.remove(csym); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
474 |
chk.compiled.remove(csym.flatname); |
33020
7ed4f7ff42c5
8000316: Huge performance bottleneck in com.sun.tools.javac.comp.Check.localClassName
sadayapalam
parents:
32911
diff
changeset
|
475 |
chk.clearLocalClassNameIndexes(csym); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
476 |
syms.classes.remove(csym.flatname); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
477 |
super.visitClassDef(tree); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
478 |
} |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
479 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
480 |
|
28142
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
481 |
static class DeferredAttrDiagHandler extends Log.DeferredDiagnosticHandler { |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
482 |
|
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
483 |
static class PosScanner extends TreeScanner { |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
484 |
DiagnosticPosition pos; |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
485 |
boolean found = false; |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
486 |
|
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
487 |
PosScanner(DiagnosticPosition pos) { |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
488 |
this.pos = pos; |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
489 |
} |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
490 |
|
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
491 |
@Override |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
492 |
public void scan(JCTree tree) { |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
493 |
if (tree != null && |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
494 |
tree.pos() == pos) { |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
495 |
found = true; |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
496 |
} |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
497 |
super.scan(tree); |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
498 |
} |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
499 |
} |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
500 |
|
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
501 |
DeferredAttrDiagHandler(Log log, JCTree newTree) { |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
502 |
super(log, new Filter<JCDiagnostic>() { |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
503 |
public boolean accepts(JCDiagnostic d) { |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
504 |
PosScanner posScanner = new PosScanner(d.getDiagnosticPosition()); |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
505 |
posScanner.scan(newTree); |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
506 |
return posScanner.found; |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
507 |
} |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
508 |
}); |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
509 |
} |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
510 |
} |
32a6b1af81b1
8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents:
27551
diff
changeset
|
511 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
512 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
513 |
* A deferred context is created on each method check. A deferred context is |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
514 |
* used to keep track of information associated with the method check, such as |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
515 |
* the symbol of the method being checked, the overload resolution phase, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
516 |
* the kind of attribution mode to be applied to deferred types and so forth. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
517 |
* As deferred types are processed (by the method check routine) stuck AST nodes |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
518 |
* are added (as new deferred attribution nodes) to this context. The complete() |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
519 |
* routine makes sure that all pending nodes are properly processed, by |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
520 |
* progressively instantiating all inference variables on which one or more |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
521 |
* deferred attribution node is stuck. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
522 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
523 |
class DeferredAttrContext { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
524 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
525 |
/** attribution mode */ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
526 |
final AttrMode mode; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
527 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
528 |
/** symbol of the method being checked */ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
529 |
final Symbol msym; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
530 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
531 |
/** method resolution step */ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
532 |
final Resolve.MethodResolutionPhase phase; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
533 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
534 |
/** inference context */ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
535 |
final InferenceContext inferenceContext; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
536 |
|
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
537 |
/** parent deferred context */ |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
538 |
final DeferredAttrContext parent; |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
539 |
|
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
540 |
/** Warner object to report warnings */ |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
541 |
final Warner warn; |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
542 |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
543 |
/** list of deferred attribution nodes to be processed */ |
22163 | 544 |
ArrayList<DeferredAttrNode> deferredAttrNodes = new ArrayList<>(); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
545 |
|
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
546 |
DeferredAttrContext(AttrMode mode, Symbol msym, MethodResolutionPhase phase, |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
547 |
InferenceContext inferenceContext, DeferredAttrContext parent, Warner warn) { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
548 |
this.mode = mode; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
549 |
this.msym = msym; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
550 |
this.phase = phase; |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
551 |
this.parent = parent; |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
552 |
this.warn = warn; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
553 |
this.inferenceContext = inferenceContext; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
554 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
555 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
556 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
557 |
* Adds a node to the list of deferred attribution nodes - used by Resolve.rawCheckArgumentsApplicable |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
558 |
* Nodes added this way act as 'roots' for the out-of-order method checking process. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
559 |
*/ |
19914 | 560 |
void addDeferredAttrNode(final DeferredType dt, ResultInfo resultInfo, |
561 |
DeferredStuckPolicy deferredStuckPolicy) { |
|
562 |
deferredAttrNodes.add(new DeferredAttrNode(dt, resultInfo, deferredStuckPolicy)); |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
563 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
564 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
565 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
566 |
* Incrementally process all nodes, by skipping 'stuck' nodes and attributing |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
567 |
* 'unstuck' ones. If at any point no progress can be made (no 'unstuck' nodes) |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
568 |
* some inference variable might get eagerly instantiated so that all nodes |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
569 |
* can be type-checked. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
570 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
571 |
void complete() { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
572 |
while (!deferredAttrNodes.isEmpty()) { |
22163 | 573 |
Map<Type, Set<Type>> depVarsMap = new LinkedHashMap<>(); |
19914 | 574 |
List<Type> stuckVars = List.nil(); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
575 |
boolean progress = false; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
576 |
//scan a defensive copy of the node list - this is because a deferred |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
577 |
//attribution round can add new nodes to the list |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
578 |
for (DeferredAttrNode deferredAttrNode : List.from(deferredAttrNodes)) { |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
579 |
if (!deferredAttrNode.process(this)) { |
19914 | 580 |
List<Type> restStuckVars = |
581 |
List.from(deferredAttrNode.deferredStuckPolicy.stuckVars()) |
|
582 |
.intersect(inferenceContext.restvars()); |
|
583 |
stuckVars = stuckVars.prependList(restStuckVars); |
|
584 |
//update dependency map |
|
585 |
for (Type t : List.from(deferredAttrNode.deferredStuckPolicy.depVars()) |
|
586 |
.intersect(inferenceContext.restvars())) { |
|
587 |
Set<Type> prevDeps = depVarsMap.get(t); |
|
588 |
if (prevDeps == null) { |
|
22163 | 589 |
prevDeps = new LinkedHashSet<>(); |
19914 | 590 |
depVarsMap.put(t, prevDeps); |
591 |
} |
|
592 |
prevDeps.addAll(restStuckVars); |
|
593 |
} |
|
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15039
diff
changeset
|
594 |
} else { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
595 |
deferredAttrNodes.remove(deferredAttrNode); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
596 |
progress = true; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
597 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
598 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
599 |
if (!progress) { |
25444
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
600 |
if (insideOverloadPhase()) { |
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
601 |
for (DeferredAttrNode deferredNode: deferredAttrNodes) { |
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
602 |
deferredNode.dt.tree.type = Type.noType; |
19914 | 603 |
} |
25444
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
604 |
return; |
19914 | 605 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
606 |
//remove all variables that have already been instantiated |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
607 |
//from the list of stuck variables |
19914 | 608 |
try { |
609 |
inferenceContext.solveAny(stuckVars, depVarsMap, warn); |
|
610 |
inferenceContext.notifyChange(); |
|
611 |
} catch (Infer.GraphStrategy.NodeNotFoundException ex) { |
|
612 |
//this means that we are in speculative mode and the |
|
613 |
//set of contraints are too tight for progess to be made. |
|
614 |
//Just leave the remaining expressions as stuck. |
|
615 |
break; |
|
616 |
} |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
617 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
618 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
619 |
} |
25444
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
620 |
|
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
621 |
public boolean insideOverloadPhase() { |
25444
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
622 |
DeferredAttrContext dac = this; |
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
623 |
if (dac == emptyDeferredAttrContext) { |
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
624 |
return false; |
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
625 |
} |
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
626 |
if (dac.mode == AttrMode.SPECULATIVE) { |
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
627 |
return true; |
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
628 |
} |
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
629 |
return dac.parent.insideOverloadPhase(); |
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
630 |
} |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
631 |
} |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
632 |
|
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
633 |
/** |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
634 |
* Class representing a deferred attribution node. It keeps track of |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
635 |
* a deferred type, along with the expected target type information. |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
636 |
*/ |
19914 | 637 |
class DeferredAttrNode { |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
638 |
|
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
639 |
/** underlying deferred type */ |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
640 |
DeferredType dt; |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
641 |
|
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
642 |
/** underlying target type information */ |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
643 |
ResultInfo resultInfo; |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
644 |
|
19914 | 645 |
/** stuck policy associated with this node */ |
646 |
DeferredStuckPolicy deferredStuckPolicy; |
|
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
647 |
|
19914 | 648 |
DeferredAttrNode(DeferredType dt, ResultInfo resultInfo, DeferredStuckPolicy deferredStuckPolicy) { |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
649 |
this.dt = dt; |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
650 |
this.resultInfo = resultInfo; |
19914 | 651 |
this.deferredStuckPolicy = deferredStuckPolicy; |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
652 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
653 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
654 |
/** |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
655 |
* Process a deferred attribution node. |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
656 |
* Invariant: a stuck node cannot be processed. |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
657 |
*/ |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
658 |
@SuppressWarnings("fallthrough") |
19914 | 659 |
boolean process(final DeferredAttrContext deferredAttrContext) { |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
660 |
switch (deferredAttrContext.mode) { |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
661 |
case SPECULATIVE: |
19914 | 662 |
if (deferredStuckPolicy.isStuck()) { |
663 |
dt.check(resultInfo, dummyStuckPolicy, new StructuralStuckChecker()); |
|
664 |
return true; |
|
665 |
} else { |
|
666 |
Assert.error("Cannot get here"); |
|
667 |
} |
|
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
668 |
case CHECK: |
19914 | 669 |
if (deferredStuckPolicy.isStuck()) { |
15717 | 670 |
//stuck expression - see if we can propagate |
671 |
if (deferredAttrContext.parent != emptyDeferredAttrContext && |
|
19914 | 672 |
Type.containsAny(deferredAttrContext.parent.inferenceContext.inferencevars, |
673 |
List.from(deferredStuckPolicy.stuckVars()))) { |
|
674 |
deferredAttrContext.parent.addDeferredAttrNode(dt, |
|
675 |
resultInfo.dup(new Check.NestedCheckContext(resultInfo.checkContext) { |
|
676 |
@Override |
|
677 |
public InferenceContext inferenceContext() { |
|
678 |
return deferredAttrContext.parent.inferenceContext; |
|
679 |
} |
|
680 |
@Override |
|
681 |
public DeferredAttrContext deferredAttrContext() { |
|
682 |
return deferredAttrContext.parent; |
|
683 |
} |
|
684 |
}), deferredStuckPolicy); |
|
685 |
dt.tree.type = Type.stuckType; |
|
15717 | 686 |
return true; |
687 |
} else { |
|
688 |
return false; |
|
689 |
} |
|
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
690 |
} else { |
25444
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
691 |
Assert.check(!deferredAttrContext.insideOverloadPhase(), |
27045478cf23
8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents:
25443
diff
changeset
|
692 |
"attribution shouldn't be happening here"); |
19914 | 693 |
ResultInfo instResultInfo = |
694 |
resultInfo.dup(deferredAttrContext.inferenceContext.asInstType(resultInfo.pt)); |
|
695 |
dt.check(instResultInfo, dummyStuckPolicy, basicCompleter); |
|
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
696 |
return true; |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
697 |
} |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
698 |
default: |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
699 |
throw new AssertionError("Bad mode"); |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
700 |
} |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
701 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
702 |
|
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
703 |
/** |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
704 |
* Structural checker for stuck expressions |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
705 |
*/ |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
706 |
class StructuralStuckChecker extends TreeScanner implements DeferredTypeCompleter { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
707 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
708 |
ResultInfo resultInfo; |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
709 |
InferenceContext inferenceContext; |
19914 | 710 |
Env<AttrContext> env; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
711 |
|
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
712 |
public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) { |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
713 |
this.resultInfo = resultInfo; |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
714 |
this.inferenceContext = deferredAttrContext.inferenceContext; |
19914 | 715 |
this.env = dt.env; |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
716 |
dt.tree.accept(this); |
19914 | 717 |
dt.speculativeCache.put(stuckTree, resultInfo); |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
718 |
return Type.noType; |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
719 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
720 |
|
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
721 |
@Override |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
722 |
public void visitLambda(JCLambda tree) { |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
723 |
Check.CheckContext checkContext = resultInfo.checkContext; |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
724 |
Type pt = resultInfo.pt; |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
725 |
if (!inferenceContext.inferencevars.contains(pt)) { |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
726 |
//must be a functional descriptor |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
727 |
Type descriptorType = null; |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
728 |
try { |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
729 |
descriptorType = types.findDescriptorType(pt); |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
730 |
} catch (Types.FunctionDescriptorLookupError ex) { |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
731 |
checkContext.report(null, ex.getDiagnostic()); |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
732 |
} |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
733 |
|
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
734 |
if (descriptorType.getParameterTypes().length() != tree.params.length()) { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
735 |
checkContext.report(tree, |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
736 |
diags.fragment("incompatible.arg.types.in.lambda")); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
737 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
738 |
|
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
739 |
Type currentReturnType = descriptorType.getReturnType(); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
740 |
boolean returnTypeIsVoid = currentReturnType.hasTag(VOID); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
741 |
if (tree.getBodyKind() == BodyKind.EXPRESSION) { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
742 |
boolean isExpressionCompatible = !returnTypeIsVoid || |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
743 |
TreeInfo.isExpressionStatement((JCExpression)tree.getBody()); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
744 |
if (!isExpressionCompatible) { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
745 |
resultInfo.checkContext.report(tree.pos(), |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
746 |
diags.fragment("incompatible.ret.type.in.lambda", |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
747 |
diags.fragment("missing.ret.val", currentReturnType))); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
748 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
749 |
} else { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
750 |
LambdaBodyStructChecker lambdaBodyChecker = |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
751 |
new LambdaBodyStructChecker(); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
752 |
|
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
753 |
tree.body.accept(lambdaBodyChecker); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
754 |
boolean isVoidCompatible = lambdaBodyChecker.isVoidCompatible; |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
755 |
|
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
756 |
if (returnTypeIsVoid) { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
757 |
if (!isVoidCompatible) { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
758 |
resultInfo.checkContext.report(tree.pos(), |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
759 |
diags.fragment("unexpected.ret.val")); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
760 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
761 |
} else { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
762 |
boolean isValueCompatible = lambdaBodyChecker.isPotentiallyValueCompatible |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
763 |
&& !canLambdaBodyCompleteNormally(tree); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
764 |
if (!isValueCompatible && !isVoidCompatible) { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
765 |
log.error(tree.body.pos(), |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
766 |
"lambda.body.neither.value.nor.void.compatible"); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
767 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
768 |
|
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
769 |
if (!isValueCompatible) { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
770 |
resultInfo.checkContext.report(tree.pos(), |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
771 |
diags.fragment("incompatible.ret.type.in.lambda", |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
772 |
diags.fragment("missing.ret.val", currentReturnType))); |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
773 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
774 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
775 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
776 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
777 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
778 |
|
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
779 |
boolean canLambdaBodyCompleteNormally(JCLambda tree) { |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
780 |
List<JCVariableDecl> oldParams = tree.params; |
32911
6ee3c12d2d18
8137269: Add better support for local caching in ArgumentAttr
mcimadamore
parents:
32709
diff
changeset
|
781 |
LocalCacheContext localCacheContext = argumentAttr.withLocalCacheContext(); |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
782 |
try { |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
783 |
tree.params = tree.params.stream() |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
784 |
.map(vd -> make.VarDef(vd.mods, vd.name, make.Erroneous(), null)) |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
785 |
.collect(List.collector()); |
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
786 |
return attribSpeculativeLambda(tree, env, attr.unknownExprInfo).canCompleteNormally; |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
787 |
} finally { |
32911
6ee3c12d2d18
8137269: Add better support for local caching in ArgumentAttr
mcimadamore
parents:
32709
diff
changeset
|
788 |
localCacheContext.leave(); |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
789 |
tree.params = oldParams; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
790 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
791 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
792 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
793 |
@Override |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
794 |
public void visitNewClass(JCNewClass tree) { |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
795 |
//do nothing |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
796 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
797 |
|
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
798 |
@Override |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
799 |
public void visitApply(JCMethodInvocation tree) { |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
800 |
//do nothing |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
801 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
802 |
|
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
803 |
@Override |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
804 |
public void visitReference(JCMemberReference tree) { |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
805 |
Check.CheckContext checkContext = resultInfo.checkContext; |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
806 |
Type pt = resultInfo.pt; |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
807 |
if (!inferenceContext.inferencevars.contains(pt)) { |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
808 |
try { |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
809 |
types.findDescriptorType(pt); |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
810 |
} catch (Types.FunctionDescriptorLookupError ex) { |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
811 |
checkContext.report(null, ex.getDiagnostic()); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15039
diff
changeset
|
812 |
} |
19914 | 813 |
Env<AttrContext> localEnv = env.dup(tree); |
26532
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26531
diff
changeset
|
814 |
JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), localEnv, |
aa84b6606229
8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents:
26531
diff
changeset
|
815 |
attr.memberReferenceQualifierResult(tree)); |
20249
93f8eae31092
6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents:
19914
diff
changeset
|
816 |
ListBuffer<Type> argtypes = new ListBuffer<>(); |
19914 | 817 |
for (Type t : types.findDescriptorType(pt).getParameterTypes()) { |
818 |
argtypes.append(Type.noType); |
|
819 |
} |
|
820 |
JCMemberReference mref2 = new TreeCopier<Void>(make).copy(tree); |
|
821 |
mref2.expr = exprTree; |
|
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
20249
diff
changeset
|
822 |
Symbol lookupSym = |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
823 |
rs.resolveMemberReference(localEnv, mref2, exprTree.type, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
824 |
tree.name, argtypes.toList(), List.nil(), rs.arityMethodCheck, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
825 |
inferenceContext, rs.structuralReferenceChooser).fst; |
21718
74a5882faf79
8026231: Look at 'static' flag when checking method references
vromero
parents:
20249
diff
changeset
|
826 |
switch (lookupSym.kind) { |
27224
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
827 |
case WRONG_MTH: |
228abfa87080
8054457: Refactor Symbol kinds from small ints to an enum
emc
parents:
26781
diff
changeset
|
828 |
case WRONG_MTHS: |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
829 |
//note: as argtypes are erroneous types, type-errors must |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
830 |
//have been caused by arity mismatch |
28458
f20c5dd05e34
8069164: Fix langtools make build so that diagnostic framework can be used
mcimadamore
parents:
28457
diff
changeset
|
831 |
checkContext.report(tree, diags.fragment(Fragments.IncompatibleArgTypesInMref)); |
28456
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
832 |
break; |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
833 |
case ABSENT_MTH: |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
834 |
case STATICERR: |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
835 |
//if no method found, or method found with wrong staticness, report better message |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
836 |
checkContext.report(tree, ((ResolveError)lookupSym).getDiagnostic(DiagnosticType.FRAGMENT, |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
837 |
tree, exprTree.type.tsym, exprTree.type, tree.name, argtypes.toList(), List.nil())); |
b87fdde1404d
8068995: Cleanup method reference lookup code
mcimadamore
parents:
28275
diff
changeset
|
838 |
break; |
16294
0c291a3cd60d
8007462: Fix provisional applicability for method references
mcimadamore
parents:
15717
diff
changeset
|
839 |
} |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15039
diff
changeset
|
840 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
841 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
842 |
} |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
843 |
|
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
844 |
/* This visitor looks for return statements, its analysis will determine if |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
845 |
* a lambda body is void or value compatible. We must analyze return |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
846 |
* statements contained in the lambda body only, thus any return statement |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
847 |
* contained in an inner class or inner lambda body, should be ignored. |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
848 |
*/ |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
849 |
class LambdaBodyStructChecker extends TreeScanner { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
850 |
boolean isVoidCompatible = true; |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
851 |
boolean isPotentiallyValueCompatible = true; |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
852 |
|
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
853 |
@Override |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
854 |
public void visitClassDef(JCClassDecl tree) { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
855 |
// do nothing |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
856 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
857 |
|
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
858 |
@Override |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
859 |
public void visitLambda(JCLambda tree) { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
860 |
// do nothing |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
861 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
862 |
|
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
863 |
@Override |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
864 |
public void visitNewClass(JCNewClass tree) { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
865 |
// do nothing |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
866 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
867 |
|
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
868 |
@Override |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
869 |
public void visitReturn(JCReturn tree) { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
870 |
if (tree.expr != null) { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
871 |
isVoidCompatible = false; |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
872 |
} else { |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
873 |
isPotentiallyValueCompatible = false; |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
874 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
875 |
} |
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
876 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
877 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
878 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
879 |
/** an empty deferred attribution context - all methods throw exceptions */ |
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18902
diff
changeset
|
880 |
final DeferredAttrContext emptyDeferredAttrContext; |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
881 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
882 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
883 |
* Map a list of types possibly containing one or more deferred types |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
884 |
* into a list of ordinary types. Each deferred type D is mapped into a type T, |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
885 |
* where T is computed by retrieving the type that has already been |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
886 |
* computed for D during a previous deferred attribution round of the given kind. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
887 |
*/ |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
888 |
class DeferredTypeMap extends TypeMapping<Void> { |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
889 |
DeferredAttrContext deferredAttrContext; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
890 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
891 |
protected DeferredTypeMap(AttrMode mode, Symbol msym, MethodResolutionPhase phase) { |
15706
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
892 |
this.deferredAttrContext = new DeferredAttrContext(mode, msym, phase, |
37a81a6987ac
8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents:
15705
diff
changeset
|
893 |
infer.emptyContext, emptyDeferredAttrContext, types.noWarnings); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
894 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
895 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
896 |
@Override |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
897 |
public Type visitType(Type t, Void _unused) { |
14359
d4099818ab70
7200915: convert TypeTags from a series of small ints to an enum
jjg
parents:
14258
diff
changeset
|
898 |
if (!t.hasTag(DEFERRED)) { |
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
899 |
return super.visitType(t, null); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
900 |
} else { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
901 |
DeferredType dt = (DeferredType)t; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
902 |
return typeOf(dt); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
903 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
904 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
905 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
906 |
protected Type typeOf(DeferredType dt) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
907 |
switch (deferredAttrContext.mode) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
908 |
case CHECK: |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
909 |
return dt.tree.type == null ? Type.noType : dt.tree.type; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
910 |
case SPECULATIVE: |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
911 |
return dt.speculativeType(deferredAttrContext.msym, deferredAttrContext.phase); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
912 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
913 |
Assert.error(); |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
914 |
return null; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
915 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
916 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
917 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
918 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
919 |
* Specialized recovery deferred mapping. |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
920 |
* Each deferred type D is mapped into a type T, where T is computed either by |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
921 |
* (i) retrieving the type that has already been computed for D during a previous |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
922 |
* attribution round (as before), or (ii) by synthesizing a new type R for D |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
923 |
* (the latter step is useful in a recovery scenario). |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
924 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
925 |
public class RecoveryDeferredTypeMap extends DeferredTypeMap { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
926 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
927 |
public RecoveryDeferredTypeMap(AttrMode mode, Symbol msym, MethodResolutionPhase phase) { |
14547 | 928 |
super(mode, msym, phase != null ? phase : MethodResolutionPhase.BOX); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
929 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
930 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
931 |
@Override |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
932 |
protected Type typeOf(DeferredType dt) { |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
933 |
Type owntype = super.typeOf(dt); |
14547 | 934 |
return owntype == Type.noType ? |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
935 |
recover(dt) : owntype; |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
936 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
937 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
938 |
/** |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
939 |
* Synthesize a type for a deferred type that hasn't been previously |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
940 |
* reduced to an ordinary type. Functional deferred types and conditionals |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
941 |
* are mapped to themselves, in order to have a richer diagnostic |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
942 |
* representation. Remaining deferred types are attributed using |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
943 |
* a default expected type (j.l.Object). |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
944 |
*/ |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
945 |
private Type recover(DeferredType dt) { |
18902 | 946 |
dt.check(attr.new RecoveryInfo(deferredAttrContext) { |
947 |
@Override |
|
948 |
protected Type check(DiagnosticPosition pos, Type found) { |
|
949 |
return chk.checkNonVoid(pos, super.check(pos, found)); |
|
950 |
} |
|
951 |
}); |
|
29554
6d7957bd6866
8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents:
29292
diff
changeset
|
952 |
return super.visit(dt); |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
953 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
954 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
955 |
|
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
956 |
/** |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
957 |
* A special tree scanner that would only visit portions of a given tree. |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
958 |
* The set of nodes visited by the scanner can be customized at construction-time. |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
959 |
*/ |
32709
55d136799f79
8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents:
31937
diff
changeset
|
960 |
abstract static class FilterScanner extends com.sun.tools.javac.tree.TreeScanner { |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
961 |
|
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
962 |
final Filter<JCTree> treeFilter; |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
963 |
|
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
964 |
FilterScanner(final Set<JCTree.Tag> validTags) { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
965 |
this.treeFilter = new Filter<JCTree>() { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
966 |
public boolean accepts(JCTree t) { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
967 |
return validTags.contains(t.getTag()); |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
968 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
969 |
}; |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
970 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
971 |
|
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
972 |
@Override |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
973 |
public void scan(JCTree tree) { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
974 |
if (tree != null) { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
975 |
if (treeFilter.accepts(tree)) { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
976 |
super.scan(tree); |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
977 |
} else { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
978 |
skip(tree); |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
979 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
980 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
981 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
982 |
|
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
983 |
/** |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
984 |
* handler that is executed when a node has been discarded |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
985 |
*/ |
24066
1dfb66929538
8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents:
22163
diff
changeset
|
986 |
void skip(JCTree tree) {} |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
987 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
988 |
|
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
989 |
/** |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
990 |
* A tree scanner suitable for visiting the target-type dependent nodes of |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
991 |
* a given argument expression. |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
992 |
*/ |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
993 |
static class PolyScanner extends FilterScanner { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
994 |
|
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
995 |
PolyScanner() { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
996 |
super(EnumSet.of(CONDEXPR, PARENS, LAMBDA, REFERENCE)); |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
997 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
998 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
999 |
|
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1000 |
/** |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1001 |
* A tree scanner suitable for visiting the target-type dependent nodes nested |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1002 |
* within a lambda expression body. |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1003 |
*/ |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1004 |
static class LambdaReturnScanner extends FilterScanner { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1005 |
|
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1006 |
LambdaReturnScanner() { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1007 |
super(EnumSet.of(BLOCK, CASE, CATCH, DOLOOP, FOREACHLOOP, |
25275
e5e9bf4b8c49
8042759: Lambda returning implicitly-typed lambdas considered pertinent to applicability
vromero
parents:
25007
diff
changeset
|
1008 |
FORLOOP, IF, RETURN, SYNCHRONIZED, SWITCH, TRY, WHILELOOP)); |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1009 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1010 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1011 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1012 |
/** |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1013 |
* This visitor is used to check that structural expressions conform |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1014 |
* to their target - this step is required as inference could end up |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1015 |
* inferring types that make some of the nested expressions incompatible |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1016 |
* with their corresponding instantiated target |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1017 |
*/ |
19914 | 1018 |
class CheckStuckPolicy extends PolyScanner implements DeferredStuckPolicy, Infer.FreeTypeListener { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1019 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1020 |
Type pt; |
31937
ad43a6639c4a
8132215: class InferenceContext should live in a separate file
vromero
parents:
30728
diff
changeset
|
1021 |
InferenceContext inferenceContext; |
22163 | 1022 |
Set<Type> stuckVars = new LinkedHashSet<>(); |
1023 |
Set<Type> depVars = new LinkedHashSet<>(); |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1024 |
|
19914 | 1025 |
@Override |
1026 |
public boolean isStuck() { |
|
1027 |
return !stuckVars.isEmpty(); |
|
1028 |
} |
|
1029 |
||
1030 |
@Override |
|
1031 |
public Set<Type> stuckVars() { |
|
1032 |
return stuckVars; |
|
1033 |
} |
|
1034 |
||
1035 |
@Override |
|
1036 |
public Set<Type> depVars() { |
|
1037 |
return depVars; |
|
1038 |
} |
|
1039 |
||
1040 |
public CheckStuckPolicy(ResultInfo resultInfo, DeferredType dt) { |
|
1041 |
this.pt = resultInfo.pt; |
|
1042 |
this.inferenceContext = resultInfo.checkContext.inferenceContext(); |
|
1043 |
scan(dt.tree); |
|
1044 |
if (!stuckVars.isEmpty()) { |
|
1045 |
resultInfo.checkContext.inferenceContext() |
|
1046 |
.addFreeTypeListener(List.from(stuckVars), this); |
|
1047 |
} |
|
1048 |
} |
|
1049 |
||
1050 |
@Override |
|
1051 |
public void typesInferred(InferenceContext inferenceContext) { |
|
1052 |
stuckVars.clear(); |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1053 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1054 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1055 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1056 |
public void visitLambda(JCLambda tree) { |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1057 |
if (inferenceContext.inferenceVars().contains(pt)) { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1058 |
stuckVars.add(pt); |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1059 |
} |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15039
diff
changeset
|
1060 |
if (!types.isFunctionalInterface(pt)) { |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1061 |
return; |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1062 |
} |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1063 |
Type descType = types.findDescriptorType(pt); |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1064 |
List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes()); |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15039
diff
changeset
|
1065 |
if (tree.paramKind == JCLambda.ParameterKind.IMPLICIT && |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1066 |
freeArgVars.nonEmpty()) { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1067 |
stuckVars.addAll(freeArgVars); |
19914 | 1068 |
depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType())); |
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1069 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1070 |
scanLambdaBody(tree, descType.getReturnType()); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1071 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1072 |
|
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1073 |
@Override |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1074 |
public void visitReference(JCMemberReference tree) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1075 |
scan(tree.expr); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1076 |
if (inferenceContext.inferenceVars().contains(pt)) { |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1077 |
stuckVars.add(pt); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1078 |
return; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1079 |
} |
15374
fb8f6acf09cc
8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents:
15039
diff
changeset
|
1080 |
if (!types.isFunctionalInterface(pt)) { |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1081 |
return; |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1082 |
} |
14547 | 1083 |
|
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1084 |
Type descType = types.findDescriptorType(pt); |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1085 |
List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes()); |
19914 | 1086 |
if (freeArgVars.nonEmpty() && |
1087 |
tree.overloadKind == JCMemberReference.OverloadKind.OVERLOADED) { |
|
1088 |
stuckVars.addAll(freeArgVars); |
|
1089 |
depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType())); |
|
18910
c967bfda9283
8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents:
18902
diff
changeset
|
1090 |
} |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1091 |
} |
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1092 |
|
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1093 |
void scanLambdaBody(JCLambda lambda, final Type pt) { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1094 |
if (lambda.getBodyKind() == JCTree.JCLambda.BodyKind.EXPRESSION) { |
19914 | 1095 |
Type prevPt = this.pt; |
1096 |
try { |
|
1097 |
this.pt = pt; |
|
1098 |
scan(lambda.body); |
|
1099 |
} finally { |
|
1100 |
this.pt = prevPt; |
|
1101 |
} |
|
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1102 |
} else { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1103 |
LambdaReturnScanner lambdaScanner = new LambdaReturnScanner() { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1104 |
@Override |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1105 |
public void visitReturn(JCReturn tree) { |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1106 |
if (tree.expr != null) { |
19914 | 1107 |
Type prevPt = CheckStuckPolicy.this.pt; |
1108 |
try { |
|
1109 |
CheckStuckPolicy.this.pt = pt; |
|
1110 |
CheckStuckPolicy.this.scan(tree.expr); |
|
1111 |
} finally { |
|
1112 |
CheckStuckPolicy.this.pt = prevPt; |
|
1113 |
} |
|
15039
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1114 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1115 |
} |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1116 |
}; |
80190ab051c0
8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents:
14547
diff
changeset
|
1117 |
lambdaScanner.scan(lambda.body); |
14058
c7ec7facdd20
7177385: Add attribution support for lambda expressions
mcimadamore
parents:
14057
diff
changeset
|
1118 |
} |
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
1119 |
} |
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
1120 |
} |
16975
124c8436d59c
8010923: Avoid redundant speculative attribution
mcimadamore
parents:
16805
diff
changeset
|
1121 |
|
124c8436d59c
8010923: Avoid redundant speculative attribution
mcimadamore
parents:
16805
diff
changeset
|
1122 |
/** |
19914 | 1123 |
* This visitor is used to check that structural expressions conform |
1124 |
* to their target - this step is required as inference could end up |
|
1125 |
* inferring types that make some of the nested expressions incompatible |
|
1126 |
* with their corresponding instantiated target |
|
1127 |
*/ |
|
1128 |
class OverloadStuckPolicy extends CheckStuckPolicy implements DeferredStuckPolicy { |
|
1129 |
||
1130 |
boolean stuck; |
|
1131 |
||
1132 |
@Override |
|
1133 |
public boolean isStuck() { |
|
1134 |
return super.isStuck() || stuck; |
|
1135 |
} |
|
1136 |
||
1137 |
public OverloadStuckPolicy(ResultInfo resultInfo, DeferredType dt) { |
|
1138 |
super(resultInfo, dt); |
|
1139 |
} |
|
1140 |
||
1141 |
@Override |
|
1142 |
public void visitLambda(JCLambda tree) { |
|
1143 |
super.visitLambda(tree); |
|
1144 |
if (tree.paramKind == JCLambda.ParameterKind.IMPLICIT) { |
|
1145 |
stuck = true; |
|
1146 |
} |
|
1147 |
} |
|
1148 |
||
1149 |
@Override |
|
1150 |
public void visitReference(JCMemberReference tree) { |
|
1151 |
super.visitReference(tree); |
|
1152 |
if (tree.overloadKind == JCMemberReference.OverloadKind.OVERLOADED) { |
|
1153 |
stuck = true; |
|
1154 |
} |
|
1155 |
} |
|
1156 |
} |
|
14057
b4b0377b8dba
7177387: Add target-typing support in method context
mcimadamore
parents:
diff
changeset
|
1157 |
} |