langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/DeferredAttr.java
author mcimadamore
Thu, 19 Mar 2015 11:40:07 +0000
changeset 29554 6d7957bd6866
parent 29292 c10d63c667cd
child 29774 9d438163db79
permissions -rw-r--r--
8074100: Turn Type.Mapping into a true visitor Summary: replace Type.Mapping with a true visitor in Types Reviewed-by: jlahoda, vromero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    29
import com.sun.tools.javac.code.*;
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29292
diff changeset
    30
import com.sun.tools.javac.code.Type.TypeMapping;
28456
b87fdde1404d 8068995: Cleanup method reference lookup code
mcimadamore
parents: 28275
diff changeset
    31
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
    32
import com.sun.tools.javac.resources.CompilerProperties.Fragments;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    33
import com.sun.tools.javac.tree.*;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    34
import com.sun.tools.javac.util.*;
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
    35
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
    36
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    37
import com.sun.tools.javac.code.Symbol.*;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    38
import com.sun.tools.javac.code.Type.*;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    39
import com.sun.tools.javac.comp.Attr.ResultInfo;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    40
import com.sun.tools.javac.comp.Infer.InferenceContext;
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
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
    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
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
    49
import java.util.LinkedHashMap;
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
    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
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
    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.*;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
    58
import static com.sun.tools.javac.code.Kinds.*;
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
    59
import static com.sun.tools.javac.code.Kinds.Kind.*;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    60
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    61
/**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    62
 * 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
    63
 * 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
    64
 * with a temporary 'deferred type' that is checked (possibly multiple times)
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    65
 * against an expected formal type.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    66
 *
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    67
 *  <p><b>This is NOT part of any supported API.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    68
 *  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
    69
 *  This code and its internal interfaces are subject to change or
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    70
 *  deletion without notice.</b>
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    71
 */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    72
public class DeferredAttr extends JCTree.Visitor {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21718
diff changeset
    73
    protected static final Context.Key<DeferredAttr> deferredAttrKey = new Context.Key<>();
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    74
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    75
    final Attr attr;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    76
    final Check chk;
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
    77
    final JCDiagnostic.Factory diags;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    78
    final Enter enter;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    79
    final Infer infer;
16294
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
    80
    final Resolve rs;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    81
    final Log log;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    82
    final Symtab syms;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    83
    final TreeMaker make;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    84
    final Types types;
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
    85
    final Flow flow;
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
    86
    final Names names;
25007
eb097d3a68f5 8038975: Access control in enhanced for
pgovereau
parents: 24895
diff changeset
    87
    final TypeEnvs typeEnvs;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    88
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    89
    public static DeferredAttr instance(Context context) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    90
        DeferredAttr instance = context.get(deferredAttrKey);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    91
        if (instance == null)
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    92
            instance = new DeferredAttr(context);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    93
        return instance;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    94
    }
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
    protected DeferredAttr(Context context) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    97
        context.put(deferredAttrKey, this);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    98
        attr = Attr.instance(context);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
    99
        chk = Check.instance(context);
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   100
        diags = JCDiagnostic.Factory.instance(context);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   101
        enter = Enter.instance(context);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   102
        infer = Infer.instance(context);
16294
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   103
        rs = Resolve.instance(context);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   104
        log = Log.instance(context);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   105
        syms = Symtab.instance(context);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   106
        make = TreeMaker.instance(context);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   107
        types = Types.instance(context);
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   108
        flow = Flow.instance(context);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   109
        names = Names.instance(context);
18902
972298345a83 8016059: Cannot compile following lambda
mcimadamore
parents: 18901
diff changeset
   110
        stuckTree = make.Ident(names.empty).setType(Type.stuckType);
25007
eb097d3a68f5 8038975: Access control in enhanced for
pgovereau
parents: 24895
diff changeset
   111
        typeEnvs = TypeEnvs.instance(context);
18910
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18902
diff changeset
   112
        emptyDeferredAttrContext =
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18902
diff changeset
   113
            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
   114
                @Override
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   115
                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
   116
                    Assert.error("Empty deferred context!");
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18902
diff changeset
   117
                }
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18902
diff changeset
   118
                @Override
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18902
diff changeset
   119
                void complete() {
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18902
diff changeset
   120
                    Assert.error("Empty deferred context!");
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18902
diff changeset
   121
                }
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24066
diff changeset
   122
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24066
diff changeset
   123
                @Override
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24066
diff changeset
   124
                public String toString() {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24066
diff changeset
   125
                    return "Empty deferred context!";
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24066
diff changeset
   126
                }
18910
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18902
diff changeset
   127
            };
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   128
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   129
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   130
    /** shared tree for stuck expressions */
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   131
    final JCTree stuckTree;
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   132
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   133
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   134
     * 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
   135
     * 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
   136
     * discovered through type-checking the deferred type against a target-type.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   137
     * 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
   138
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   139
    public class DeferredType extends Type {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   140
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   141
        public JCExpression tree;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   142
        Env<AttrContext> env;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   143
        AttrMode mode;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   144
        SpeculativeCache speculativeCache;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   145
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26531
diff changeset
   146
        DeferredType(JCExpression tree, Env<AttrContext> env) {
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26532
diff changeset
   147
            super(null, TypeMetadata.empty);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   148
            this.tree = tree;
18912
e25cd61d8e59 8020147: Spurious errors when compiling nested stuck lambdas
mcimadamore
parents: 18910
diff changeset
   149
            this.env = attr.copyEnv(env);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   150
            this.speculativeCache = new SpeculativeCache();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   151
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   152
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18643
diff changeset
   153
        @Override
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26532
diff changeset
   154
        public DeferredType clone(TypeMetadata md) {
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26532
diff changeset
   155
            throw new AssertionError("Cannot add metadata to a deferred type");
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24226
diff changeset
   156
        }
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24226
diff changeset
   157
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24226
diff changeset
   158
        @Override
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18643
diff changeset
   159
        public TypeTag getTag() {
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18643
diff changeset
   160
            return DEFERRED;
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18643
diff changeset
   161
        }
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18643
diff changeset
   162
26266
2d24bda701dc 8056061: Mark implementations of public interfaces with an annotation
jlahoda
parents: 25874
diff changeset
   163
        @Override @DefinedBy(Api.LANGUAGE_MODEL)
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   164
        public String toString() {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   165
            return "DeferredType";
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   166
        }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   167
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   168
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   169
         * 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
   170
         * that triggered speculative attribution on a given deferred type. Each entry
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   171
         * 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
   172
         * has been added.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   173
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   174
        class SpeculativeCache {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   175
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21718
diff changeset
   176
            private Map<Symbol, List<Entry>> cache = new WeakHashMap<>();
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   177
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   178
            class Entry {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   179
                JCTree speculativeTree;
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   180
                ResultInfo resultInfo;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   181
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   182
                public Entry(JCTree speculativeTree, ResultInfo resultInfo) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   183
                    this.speculativeTree = speculativeTree;
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   184
                    this.resultInfo = resultInfo;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   185
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   186
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   187
                boolean matches(MethodResolutionPhase phase) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   188
                    return resultInfo.checkContext.deferredAttrContext().phase == phase;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   189
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   190
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   191
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   192
            /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   193
             * Retrieve a speculative cache entry corresponding to given symbol
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   194
             * and resolution phase
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   195
             */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   196
            Entry get(Symbol msym, MethodResolutionPhase phase) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   197
                List<Entry> entries = cache.get(msym);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   198
                if (entries == null) return null;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   199
                for (Entry e : entries) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   200
                    if (e.matches(phase)) return e;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   201
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   202
                return null;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   203
            }
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
            /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   206
             * Stores a speculative cache entry corresponding to given symbol
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   207
             * and resolution phase
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   208
             */
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   209
            void put(JCTree speculativeTree, ResultInfo resultInfo) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   210
                Symbol msym = resultInfo.checkContext.deferredAttrContext().msym;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   211
                List<Entry> entries = cache.get(msym);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   212
                if (entries == null) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   213
                    entries = List.nil();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   214
                }
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   215
                cache.put(msym, entries.prepend(new Entry(speculativeTree, 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
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   218
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   219
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   220
         * 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
   221
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   222
        Type speculativeType(Symbol msym, MethodResolutionPhase phase) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   223
            SpeculativeCache.Entry e = speculativeCache.get(msym, phase);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   224
            return e != null ? e.speculativeTree.type : Type.noType;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   225
        }
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
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   228
         * Check a deferred type against a potential target-type. Depending on
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   229
         * the current attribution mode, a normal vs. speculative attribution
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   230
         * 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
   231
         * speculative round for a given target method symbol; moreover, a normal
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   232
         * attribution round must follow one or more speculative rounds.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   233
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   234
        Type check(ResultInfo resultInfo) {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   235
            DeferredStuckPolicy deferredStuckPolicy;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   236
            if (resultInfo.pt.hasTag(NONE) || resultInfo.pt.isErroneous()) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   237
                deferredStuckPolicy = dummyStuckPolicy;
28891
dc7d89f2e25c 8069545: javac shouldn't check nested stuck lambdas during overload resolution
sadayapalam
parents: 28458
diff changeset
   238
            } 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
   239
                    resultInfo.checkContext.deferredAttrContext().insideOverloadPhase()) {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   240
                deferredStuckPolicy = new OverloadStuckPolicy(resultInfo, this);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   241
            } else {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   242
                deferredStuckPolicy = new CheckStuckPolicy(resultInfo, this);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   243
            }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   244
            return check(resultInfo, deferredStuckPolicy, basicCompleter);
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   245
        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   246
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   247
        private Type check(ResultInfo resultInfo, DeferredStuckPolicy deferredStuckPolicy,
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   248
                DeferredTypeCompleter deferredTypeCompleter) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   249
            DeferredAttrContext deferredAttrContext =
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   250
                    resultInfo.checkContext.deferredAttrContext();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   251
            Assert.check(deferredAttrContext != emptyDeferredAttrContext);
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   252
            if (deferredStuckPolicy.isStuck()) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   253
                deferredAttrContext.addDeferredAttrNode(this, resultInfo, deferredStuckPolicy);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   254
                return Type.noType;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   255
            } else {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   256
                try {
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   257
                    return deferredTypeCompleter.complete(this, resultInfo, deferredAttrContext);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   258
                } finally {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   259
                    mode = deferredAttrContext.mode;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   260
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   261
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   262
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   263
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   264
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   265
    /**
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   266
     * 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
   267
     * a deferred type.
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   268
     */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   269
    interface DeferredTypeCompleter {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   270
        /**
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   271
         * 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
   272
         * circumstances, type-checking could amount to full attribution
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   273
         * or partial structural check (aka potential applicability).
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   274
         */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   275
        Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   276
    }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   277
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   278
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   279
    /**
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   280
     * 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
   281
     * 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
   282
     * or speculative attribution.
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   283
     */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   284
    DeferredTypeCompleter basicCompleter = new DeferredTypeCompleter() {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   285
        public Type complete(DeferredType dt, ResultInfo resultInfo, DeferredAttrContext deferredAttrContext) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   286
            switch (deferredAttrContext.mode) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   287
                case SPECULATIVE:
16566
604ce45d5f23 8009820: AssertionError when compiling java code with two identical static imports
mcimadamore
parents: 16326
diff changeset
   288
                    //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
   289
                    //speculative rounds...
604ce45d5f23 8009820: AssertionError when compiling java code with two identical static imports
mcimadamore
parents: 16326
diff changeset
   290
                    Assert.check(dt.mode == null || dt.mode == AttrMode.SPECULATIVE);
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26531
diff changeset
   291
                    JCTree speculativeTree = attribSpeculative(dt.tree, dt.env, resultInfo);
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   292
                    dt.speculativeCache.put(speculativeTree, resultInfo);
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   293
                    return speculativeTree.type;
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   294
                case CHECK:
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   295
                    Assert.check(dt.mode != null);
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26531
diff changeset
   296
                    return attr.attribTree(dt.tree, dt.env, resultInfo);
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   297
            }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   298
            Assert.error();
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   299
            return null;
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   300
        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   301
    };
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   302
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   303
    /**
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   304
     * Policy for detecting stuck expressions. Different criteria might cause
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   305
     * an expression to be judged as stuck, depending on whether the check
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   306
     * is performed during overload resolution or after most specific.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   307
     */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   308
    interface DeferredStuckPolicy {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   309
        /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   310
         * Has the policy detected that a given expression should be considered stuck?
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   311
         */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   312
        boolean isStuck();
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   313
        /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   314
         * Get the set of inference variables a given expression depends upon.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   315
         */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   316
        Set<Type> stuckVars();
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   317
        /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   318
         * Get the set of inference variables which might get new constraints
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   319
         * if a given expression is being type-checked.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   320
         */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   321
        Set<Type> depVars();
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   322
    }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   323
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   324
    /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   325
     * Basic stuck policy; an expression is never considered to be stuck.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   326
     */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   327
    DeferredStuckPolicy dummyStuckPolicy = new DeferredStuckPolicy() {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   328
        @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   329
        public boolean isStuck() {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   330
            return false;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   331
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   332
        @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   333
        public Set<Type> stuckVars() {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   334
            return Collections.emptySet();
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   335
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   336
        @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   337
        public Set<Type> depVars() {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   338
            return Collections.emptySet();
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   339
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   340
    };
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   341
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   342
    /**
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   343
     * 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
   344
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   345
    public enum AttrMode {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   346
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   347
         * A speculative type-checking round is used during overload resolution
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   348
         * mainly to generate constraints on inference variables. Side-effects
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   349
         * arising from type-checking the expression associated with the deferred
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   350
         * type are reversed after the speculative round finishes. This means the
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   351
         * expression tree will be left in a blank state.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   352
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   353
        SPECULATIVE,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   354
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   355
         * 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
   356
         */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21718
diff changeset
   357
        CHECK
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   358
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   359
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   360
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   361
     * Routine that performs speculative type-checking; the input AST node is
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   362
     * 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
   363
     * restored after type-checking. All diagnostics (but critical ones) are
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   364
     * disabled during speculative type-checking.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   365
     */
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26531
diff changeset
   366
    JCTree attribSpeculative(JCTree tree, Env<AttrContext> env, ResultInfo resultInfo) {
28142
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   367
        return attribSpeculative(tree, env, resultInfo, new TreeCopier<>(make),
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   368
                (newTree)->new DeferredAttrDiagHandler(log, newTree));
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   369
    }
16309
db71f8ecc136 8008276: assertion error in com.sun.tools.javac.comp.TransTypes.visitApply
mcimadamore
parents: 16294
diff changeset
   370
28142
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   371
    <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
   372
                                 Function<JCTree, DeferredDiagnosticHandler> diagHandlerCreator) {
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   373
        final JCTree newTree = deferredCopier.copy(tree);
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   374
        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
   375
        speculativeEnv.info.isSpeculative = true;
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   376
        Log.DeferredDiagnosticHandler deferredDiagnosticHandler = diagHandlerCreator.apply(newTree);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   377
        try {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   378
            attr.attribTree(newTree, speculativeEnv, resultInfo);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   379
            unenterScanner.scan(newTree);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   380
            return newTree;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   381
        } finally {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   382
            unenterScanner.scan(newTree);
14538
384681be798f 8003299: Cleanup javac Log support for deferred diagnostics
jjg
parents: 14359
diff changeset
   383
            log.popDiagnosticHandler(deferredDiagnosticHandler);
14057
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
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   386
    //where
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   387
        protected UnenterScanner unenterScanner = new UnenterScanner();
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   388
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   389
        class UnenterScanner extends TreeScanner {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   390
            @Override
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   391
            public void visitClassDef(JCClassDecl tree) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   392
                ClassSymbol csym = tree.sym;
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   393
                //if something went wrong during method applicability check
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   394
                //it is possible that nested expressions inside argument expression
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   395
                //are left unchecked - in such cases there's nothing to clean up.
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   396
                if (csym == null) return;
25007
eb097d3a68f5 8038975: Access control in enhanced for
pgovereau
parents: 24895
diff changeset
   397
                typeEnvs.remove(csym);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   398
                chk.compiled.remove(csym.flatname);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   399
                syms.classes.remove(csym.flatname);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   400
                super.visitClassDef(tree);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   401
            }
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   402
        }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   403
28142
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   404
        static class DeferredAttrDiagHandler extends Log.DeferredDiagnosticHandler {
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   405
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   406
            static class PosScanner extends TreeScanner {
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   407
                DiagnosticPosition pos;
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   408
                boolean found = false;
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   409
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   410
                PosScanner(DiagnosticPosition pos) {
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   411
                    this.pos = pos;
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   412
                }
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   413
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   414
                @Override
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   415
                public void scan(JCTree tree) {
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   416
                    if (tree != null &&
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   417
                            tree.pos() == pos) {
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   418
                        found = true;
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   419
                    }
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   420
                    super.scan(tree);
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   421
                }
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   422
            }
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   423
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   424
            DeferredAttrDiagHandler(Log log, JCTree newTree) {
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   425
                super(log, new Filter<JCDiagnostic>() {
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   426
                    public boolean accepts(JCDiagnostic d) {
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   427
                        PosScanner posScanner = new PosScanner(d.getDiagnosticPosition());
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   428
                        posScanner.scan(newTree);
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   429
                        return posScanner.found;
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   430
                    }
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   431
                });
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   432
            }
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   433
        }
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
   434
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   435
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   436
     * 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
   437
     * 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
   438
     * the symbol of the method being checked, the overload resolution phase,
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   439
     * 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
   440
     * 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
   441
     * 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
   442
     * routine makes sure that all pending nodes are properly processed, by
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   443
     * progressively instantiating all inference variables on which one or more
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   444
     * deferred attribution node is stuck.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   445
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   446
    class DeferredAttrContext {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   447
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   448
        /** attribution mode */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   449
        final AttrMode mode;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   450
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   451
        /** symbol of the method being checked */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   452
        final Symbol msym;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   453
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   454
        /** method resolution step */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   455
        final Resolve.MethodResolutionPhase phase;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   456
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   457
        /** inference context */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   458
        final InferenceContext inferenceContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   459
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   460
        /** parent deferred context */
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   461
        final DeferredAttrContext parent;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   462
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   463
        /** Warner object to report warnings */
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   464
        final Warner warn;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   465
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   466
        /** list of deferred attribution nodes to be processed */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21718
diff changeset
   467
        ArrayList<DeferredAttrNode> deferredAttrNodes = new ArrayList<>();
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   468
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   469
        DeferredAttrContext(AttrMode mode, Symbol msym, MethodResolutionPhase phase,
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   470
                InferenceContext inferenceContext, DeferredAttrContext parent, Warner warn) {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   471
            this.mode = mode;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   472
            this.msym = msym;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   473
            this.phase = phase;
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   474
            this.parent = parent;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   475
            this.warn = warn;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   476
            this.inferenceContext = inferenceContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   477
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   478
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   479
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   480
         * 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
   481
         * 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
   482
         */
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   483
        void addDeferredAttrNode(final DeferredType dt, ResultInfo resultInfo,
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   484
                DeferredStuckPolicy deferredStuckPolicy) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   485
            deferredAttrNodes.add(new DeferredAttrNode(dt, resultInfo, deferredStuckPolicy));
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   486
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   487
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   488
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   489
         * Incrementally process all nodes, by skipping 'stuck' nodes and attributing
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   490
         * '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
   491
         * some inference variable might get eagerly instantiated so that all nodes
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   492
         * can be type-checked.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   493
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   494
        void complete() {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   495
            while (!deferredAttrNodes.isEmpty()) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21718
diff changeset
   496
                Map<Type, Set<Type>> depVarsMap = new LinkedHashMap<>();
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   497
                List<Type> stuckVars = List.nil();
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   498
                boolean progress = false;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   499
                //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
   500
                //attribution round can add new nodes to the list
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   501
                for (DeferredAttrNode deferredAttrNode : List.from(deferredAttrNodes)) {
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   502
                    if (!deferredAttrNode.process(this)) {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   503
                        List<Type> restStuckVars =
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   504
                                List.from(deferredAttrNode.deferredStuckPolicy.stuckVars())
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   505
                                .intersect(inferenceContext.restvars());
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   506
                        stuckVars = stuckVars.prependList(restStuckVars);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   507
                        //update dependency map
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   508
                        for (Type t : List.from(deferredAttrNode.deferredStuckPolicy.depVars())
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   509
                                .intersect(inferenceContext.restvars())) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   510
                            Set<Type> prevDeps = depVarsMap.get(t);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   511
                            if (prevDeps == null) {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21718
diff changeset
   512
                                prevDeps = new LinkedHashSet<>();
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   513
                                depVarsMap.put(t, prevDeps);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   514
                            }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   515
                            prevDeps.addAll(restStuckVars);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   516
                        }
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   517
                    } else {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   518
                        deferredAttrNodes.remove(deferredAttrNode);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   519
                        progress = true;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   520
                    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   521
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   522
                if (!progress) {
25444
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   523
                    if (insideOverloadPhase()) {
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   524
                        for (DeferredAttrNode deferredNode: deferredAttrNodes) {
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   525
                            deferredNode.dt.tree.type = Type.noType;
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   526
                        }
25444
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   527
                        return;
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   528
                    }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   529
                    //remove all variables that have already been instantiated
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   530
                    //from the list of stuck variables
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   531
                    try {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   532
                        inferenceContext.solveAny(stuckVars, depVarsMap, warn);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   533
                        inferenceContext.notifyChange();
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   534
                    } catch (Infer.GraphStrategy.NodeNotFoundException ex) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   535
                        //this means that we are in speculative mode and the
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   536
                        //set of contraints are too tight for progess to be made.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   537
                        //Just leave the remaining expressions as stuck.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   538
                        break;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   539
                    }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   540
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   541
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   542
        }
25444
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   543
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   544
        private boolean insideOverloadPhase() {
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   545
            DeferredAttrContext dac = this;
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   546
            if (dac == emptyDeferredAttrContext) {
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   547
                return false;
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   548
            }
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   549
            if (dac.mode == AttrMode.SPECULATIVE) {
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   550
                return true;
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   551
            }
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   552
            return dac.parent.insideOverloadPhase();
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   553
        }
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   554
    }
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   555
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   556
    /**
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   557
     * 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
   558
     * 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
   559
     */
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   560
    class DeferredAttrNode {
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   561
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   562
        /** underlying deferred type */
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   563
        DeferredType dt;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   564
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   565
        /** underlying target type information */
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   566
        ResultInfo resultInfo;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   567
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   568
        /** stuck policy associated with this node */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   569
        DeferredStuckPolicy deferredStuckPolicy;
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   570
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   571
        DeferredAttrNode(DeferredType dt, ResultInfo resultInfo, DeferredStuckPolicy deferredStuckPolicy) {
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   572
            this.dt = dt;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   573
            this.resultInfo = resultInfo;
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   574
            this.deferredStuckPolicy = deferredStuckPolicy;
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   575
        }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   576
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   577
        /**
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   578
         * Process a deferred attribution node.
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   579
         * Invariant: a stuck node cannot be processed.
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   580
         */
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   581
        @SuppressWarnings("fallthrough")
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   582
        boolean process(final DeferredAttrContext deferredAttrContext) {
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   583
            switch (deferredAttrContext.mode) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   584
                case SPECULATIVE:
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   585
                    if (deferredStuckPolicy.isStuck()) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   586
                        dt.check(resultInfo, dummyStuckPolicy, new StructuralStuckChecker());
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   587
                        return true;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   588
                    } else {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   589
                        Assert.error("Cannot get here");
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   590
                    }
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   591
                case CHECK:
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   592
                    if (deferredStuckPolicy.isStuck()) {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   593
                        //stuck expression - see if we can propagate
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   594
                        if (deferredAttrContext.parent != emptyDeferredAttrContext &&
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   595
                                Type.containsAny(deferredAttrContext.parent.inferenceContext.inferencevars,
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   596
                                        List.from(deferredStuckPolicy.stuckVars()))) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   597
                            deferredAttrContext.parent.addDeferredAttrNode(dt,
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   598
                                    resultInfo.dup(new Check.NestedCheckContext(resultInfo.checkContext) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   599
                                @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   600
                                public InferenceContext inferenceContext() {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   601
                                    return deferredAttrContext.parent.inferenceContext;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   602
                                }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   603
                                @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   604
                                public DeferredAttrContext deferredAttrContext() {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   605
                                    return deferredAttrContext.parent;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   606
                                }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   607
                            }), deferredStuckPolicy);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   608
                            dt.tree.type = Type.stuckType;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   609
                            return true;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   610
                        } else {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   611
                            return false;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   612
                        }
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   613
                    } else {
25444
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   614
                        Assert.check(!deferredAttrContext.insideOverloadPhase(),
27045478cf23 8033483: Should ignore nested lambda bodies during overload resolution
vromero
parents: 25443
diff changeset
   615
                                "attribution shouldn't be happening here");
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   616
                        ResultInfo instResultInfo =
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   617
                                resultInfo.dup(deferredAttrContext.inferenceContext.asInstType(resultInfo.pt));
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   618
                        dt.check(instResultInfo, dummyStuckPolicy, basicCompleter);
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   619
                        return true;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   620
                    }
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   621
                default:
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   622
                    throw new AssertionError("Bad mode");
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   623
            }
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   624
        }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   625
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   626
        /**
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   627
         * Structural checker for stuck expressions
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   628
         */
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   629
        class StructuralStuckChecker extends TreeScanner implements DeferredTypeCompleter {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   630
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   631
            ResultInfo resultInfo;
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   632
            InferenceContext inferenceContext;
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   633
            Env<AttrContext> env;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   634
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   635
            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
   636
                this.resultInfo = resultInfo;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   637
                this.inferenceContext = deferredAttrContext.inferenceContext;
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   638
                this.env = dt.env;
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   639
                dt.tree.accept(this);
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   640
                dt.speculativeCache.put(stuckTree, resultInfo);
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   641
                return Type.noType;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   642
            }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   643
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   644
            @Override
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   645
            public void visitLambda(JCLambda tree) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   646
                Check.CheckContext checkContext = resultInfo.checkContext;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   647
                Type pt = resultInfo.pt;
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   648
                if (!inferenceContext.inferencevars.contains(pt)) {
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   649
                    //must be a functional descriptor
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   650
                    Type descriptorType = null;
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   651
                    try {
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   652
                        descriptorType = types.findDescriptorType(pt);
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   653
                    } catch (Types.FunctionDescriptorLookupError ex) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   654
                        checkContext.report(null, ex.getDiagnostic());
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   655
                    }
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   656
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   657
                    if (descriptorType.getParameterTypes().length() != tree.params.length()) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   658
                        checkContext.report(tree,
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   659
                                diags.fragment("incompatible.arg.types.in.lambda"));
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   660
                    }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   661
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   662
                    Type currentReturnType = descriptorType.getReturnType();
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   663
                    boolean returnTypeIsVoid = currentReturnType.hasTag(VOID);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   664
                    if (tree.getBodyKind() == BodyKind.EXPRESSION) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   665
                        boolean isExpressionCompatible = !returnTypeIsVoid ||
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   666
                            TreeInfo.isExpressionStatement((JCExpression)tree.getBody());
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   667
                        if (!isExpressionCompatible) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   668
                            resultInfo.checkContext.report(tree.pos(),
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   669
                                diags.fragment("incompatible.ret.type.in.lambda",
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   670
                                    diags.fragment("missing.ret.val", currentReturnType)));
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   671
                        }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   672
                    } else {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   673
                        LambdaBodyStructChecker lambdaBodyChecker =
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   674
                                new LambdaBodyStructChecker();
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   675
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   676
                        tree.body.accept(lambdaBodyChecker);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   677
                        boolean isVoidCompatible = lambdaBodyChecker.isVoidCompatible;
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   678
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   679
                        if (returnTypeIsVoid) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   680
                            if (!isVoidCompatible) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   681
                                resultInfo.checkContext.report(tree.pos(),
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   682
                                    diags.fragment("unexpected.ret.val"));
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   683
                            }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   684
                        } else {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   685
                            boolean isValueCompatible = lambdaBodyChecker.isPotentiallyValueCompatible
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   686
                                && !canLambdaBodyCompleteNormally(tree);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   687
                            if (!isValueCompatible && !isVoidCompatible) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   688
                                log.error(tree.body.pos(),
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   689
                                    "lambda.body.neither.value.nor.void.compatible");
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   690
                            }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   691
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   692
                            if (!isValueCompatible) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   693
                                resultInfo.checkContext.report(tree.pos(),
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   694
                                    diags.fragment("incompatible.ret.type.in.lambda",
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   695
                                        diags.fragment("missing.ret.val", currentReturnType)));
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   696
                            }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   697
                        }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   698
                    }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   699
                }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   700
            }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   701
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   702
            boolean canLambdaBodyCompleteNormally(JCLambda tree) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   703
                JCLambda newTree = new TreeCopier<>(make).copy(tree);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   704
                /* attr.lambdaEnv will create a meaningful env for the
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   705
                 * lambda expression. This is specially useful when the
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   706
                 * lambda is used as the init of a field. But we need to
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   707
                 * remove any added symbol.
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   708
                 */
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   709
                Env<AttrContext> localEnv = attr.lambdaEnv(newTree, env);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   710
                try {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   711
                    List<JCVariableDecl> tmpParams = newTree.params;
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   712
                    while (tmpParams.nonEmpty()) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   713
                        tmpParams.head.vartype = make.at(tmpParams.head).Type(syms.errType);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   714
                        tmpParams = tmpParams.tail;
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   715
                    }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   716
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   717
                    attr.attribStats(newTree.params, localEnv);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   718
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   719
                    /* set pt to Type.noType to avoid generating any bound
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   720
                     * which may happen if lambda's return type is an
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   721
                     * inference variable
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   722
                     */
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   723
                    Attr.ResultInfo bodyResultInfo = attr.new ResultInfo(KindSelector.VAL, Type.noType);
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   724
                    localEnv.info.returnResult = bodyResultInfo;
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   725
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   726
                    // discard any log output
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   727
                    Log.DiagnosticHandler diagHandler = new Log.DiscardDiagnosticHandler(log);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   728
                    try {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   729
                        JCBlock body = (JCBlock)newTree.body;
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   730
                        /* we need to attribute the lambda body before
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   731
                         * doing the aliveness analysis. This is because
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   732
                         * constant folding occurs during attribution
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   733
                         * and the reachability of some statements depends
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   734
                         * on constant values, for example:
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   735
                         *
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   736
                         *     while (true) {...}
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
                        attr.attribStats(body.stats, localEnv);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   739
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   740
                        attr.preFlow(newTree);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   741
                        /* make an aliveness / reachability analysis of the lambda
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   742
                         * to determine if it can complete normally
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   743
                         */
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   744
                        flow.analyzeLambda(localEnv, newTree, make, true);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   745
                    } finally {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   746
                        log.popDiagnosticHandler(diagHandler);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   747
                    }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   748
                    return newTree.canCompleteNormally;
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   749
                } finally {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   750
                    JCBlock body = (JCBlock)newTree.body;
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   751
                    unenterScanner.scan(body.stats);
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   752
                    localEnv.info.scope.leave();
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   753
                }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   754
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   755
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   756
            @Override
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   757
            public void visitNewClass(JCNewClass tree) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   758
                //do nothing
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   759
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   760
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   761
            @Override
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   762
            public void visitApply(JCMethodInvocation tree) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   763
                //do nothing
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   764
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   765
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   766
            @Override
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   767
            public void visitReference(JCMemberReference tree) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   768
                Check.CheckContext checkContext = resultInfo.checkContext;
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   769
                Type pt = resultInfo.pt;
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   770
                if (!inferenceContext.inferencevars.contains(pt)) {
15706
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   771
                    try {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   772
                        types.findDescriptorType(pt);
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   773
                    } catch (Types.FunctionDescriptorLookupError ex) {
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   774
                        checkContext.report(null, ex.getDiagnostic());
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   775
                    }
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   776
                    Env<AttrContext> localEnv = env.dup(tree);
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26531
diff changeset
   777
                    JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), localEnv,
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26531
diff changeset
   778
                            attr.memberReferenceQualifierResult(tree));
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19914
diff changeset
   779
                    ListBuffer<Type> argtypes = new ListBuffer<>();
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   780
                    for (Type t : types.findDescriptorType(pt).getParameterTypes()) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   781
                        argtypes.append(Type.noType);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   782
                    }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   783
                    JCMemberReference mref2 = new TreeCopier<Void>(make).copy(tree);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   784
                    mref2.expr = exprTree;
21718
74a5882faf79 8026231: Look at 'static' flag when checking method references
vromero
parents: 20249
diff changeset
   785
                    Symbol lookupSym =
28456
b87fdde1404d 8068995: Cleanup method reference lookup code
mcimadamore
parents: 28275
diff changeset
   786
                            rs.resolveMemberReference(localEnv, mref2, exprTree.type,
b87fdde1404d 8068995: Cleanup method reference lookup code
mcimadamore
parents: 28275
diff changeset
   787
                                    tree.name, argtypes.toList(), List.nil(), rs.arityMethodCheck,
b87fdde1404d 8068995: Cleanup method reference lookup code
mcimadamore
parents: 28275
diff changeset
   788
                                    inferenceContext, rs.structuralReferenceChooser).fst;
21718
74a5882faf79 8026231: Look at 'static' flag when checking method references
vromero
parents: 20249
diff changeset
   789
                    switch (lookupSym.kind) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   790
                        case WRONG_MTH:
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
   791
                        case WRONG_MTHS:
28456
b87fdde1404d 8068995: Cleanup method reference lookup code
mcimadamore
parents: 28275
diff changeset
   792
                            //note: as argtypes are erroneous types, type-errors must
b87fdde1404d 8068995: Cleanup method reference lookup code
mcimadamore
parents: 28275
diff changeset
   793
                            //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
   794
                            checkContext.report(tree, diags.fragment(Fragments.IncompatibleArgTypesInMref));
28456
b87fdde1404d 8068995: Cleanup method reference lookup code
mcimadamore
parents: 28275
diff changeset
   795
                            break;
b87fdde1404d 8068995: Cleanup method reference lookup code
mcimadamore
parents: 28275
diff changeset
   796
                        case ABSENT_MTH:
b87fdde1404d 8068995: Cleanup method reference lookup code
mcimadamore
parents: 28275
diff changeset
   797
                        case STATICERR:
b87fdde1404d 8068995: Cleanup method reference lookup code
mcimadamore
parents: 28275
diff changeset
   798
                            //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
   799
                            checkContext.report(tree, ((ResolveError)lookupSym).getDiagnostic(DiagnosticType.FRAGMENT,
b87fdde1404d 8068995: Cleanup method reference lookup code
mcimadamore
parents: 28275
diff changeset
   800
                                    tree, exprTree.type.tsym, exprTree.type, tree.name, argtypes.toList(), List.nil()));
b87fdde1404d 8068995: Cleanup method reference lookup code
mcimadamore
parents: 28275
diff changeset
   801
                            break;
16294
0c291a3cd60d 8007462: Fix provisional applicability for method references
mcimadamore
parents: 15717
diff changeset
   802
                    }
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
   803
                }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   804
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   805
        }
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   806
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   807
        /* 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
   808
         * 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
   809
         * 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
   810
         * 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
   811
         */
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   812
        class LambdaBodyStructChecker extends TreeScanner {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   813
            boolean isVoidCompatible = true;
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   814
            boolean isPotentiallyValueCompatible = true;
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   815
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   816
            @Override
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   817
            public void visitClassDef(JCClassDecl tree) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   818
                // do nothing
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   819
            }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   820
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   821
            @Override
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   822
            public void visitLambda(JCLambda tree) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   823
                // do nothing
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   824
            }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   825
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   826
            @Override
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   827
            public void visitNewClass(JCNewClass tree) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   828
                // do nothing
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   829
            }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   830
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   831
            @Override
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   832
            public void visitReturn(JCReturn tree) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   833
                if (tree.expr != null) {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   834
                    isVoidCompatible = false;
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   835
                } else {
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   836
                    isPotentiallyValueCompatible = false;
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   837
                }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   838
            }
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   839
        }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   840
    }
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
    /** 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
   843
    final DeferredAttrContext emptyDeferredAttrContext;
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   844
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   845
    /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   846
     * 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
   847
     * 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
   848
     * 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
   849
     * 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
   850
     */
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29292
diff changeset
   851
    class DeferredTypeMap extends TypeMapping<Void> {
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   852
        DeferredAttrContext deferredAttrContext;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   853
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   854
        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
   855
            this.deferredAttrContext = new DeferredAttrContext(mode, msym, phase,
37a81a6987ac 8007479: Refactor DeferredAttrContext so that it points to parent context
mcimadamore
parents: 15705
diff changeset
   856
                    infer.emptyContext, emptyDeferredAttrContext, types.noWarnings);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   857
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   858
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   859
        @Override
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29292
diff changeset
   860
        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
   861
            if (!t.hasTag(DEFERRED)) {
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29292
diff changeset
   862
                return super.visitType(t, null);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   863
            } else {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   864
                DeferredType dt = (DeferredType)t;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   865
                return typeOf(dt);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   866
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   867
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   868
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   869
        protected Type typeOf(DeferredType dt) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   870
            switch (deferredAttrContext.mode) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   871
                case CHECK:
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   872
                    return dt.tree.type == null ? Type.noType : dt.tree.type;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   873
                case SPECULATIVE:
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   874
                    return dt.speculativeType(deferredAttrContext.msym, deferredAttrContext.phase);
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   875
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   876
            Assert.error();
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   877
            return null;
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
    }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   880
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
     * Specialized recovery deferred mapping.
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   883
     * 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
   884
     * (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
   885
     * 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
   886
     * (the latter step is useful in a recovery scenario).
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   887
     */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   888
    public class RecoveryDeferredTypeMap extends DeferredTypeMap {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   889
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   890
        public RecoveryDeferredTypeMap(AttrMode mode, Symbol msym, MethodResolutionPhase phase) {
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   891
            super(mode, msym, phase != null ? phase : MethodResolutionPhase.BOX);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   892
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   893
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   894
        @Override
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   895
        protected Type typeOf(DeferredType dt) {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   896
            Type owntype = super.typeOf(dt);
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
   897
            return owntype == Type.noType ?
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   898
                        recover(dt) : owntype;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   899
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   900
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   901
        /**
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   902
         * 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
   903
         * reduced to an ordinary type. Functional deferred types and conditionals
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   904
         * are mapped to themselves, in order to have a richer diagnostic
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   905
         * representation. Remaining deferred types are attributed using
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   906
         * a default expected type (j.l.Object).
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   907
         */
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
   908
        private Type recover(DeferredType dt) {
18902
972298345a83 8016059: Cannot compile following lambda
mcimadamore
parents: 18901
diff changeset
   909
            dt.check(attr.new RecoveryInfo(deferredAttrContext) {
972298345a83 8016059: Cannot compile following lambda
mcimadamore
parents: 18901
diff changeset
   910
                @Override
972298345a83 8016059: Cannot compile following lambda
mcimadamore
parents: 18901
diff changeset
   911
                protected Type check(DiagnosticPosition pos, Type found) {
972298345a83 8016059: Cannot compile following lambda
mcimadamore
parents: 18901
diff changeset
   912
                    return chk.checkNonVoid(pos, super.check(pos, found));
972298345a83 8016059: Cannot compile following lambda
mcimadamore
parents: 18901
diff changeset
   913
                }
972298345a83 8016059: Cannot compile following lambda
mcimadamore
parents: 18901
diff changeset
   914
            });
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29292
diff changeset
   915
            return super.visit(dt);
14057
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
    /**
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   920
     * 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
   921
     * 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
   922
     */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   923
    abstract static class FilterScanner extends TreeScanner {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   924
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   925
        final Filter<JCTree> treeFilter;
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   926
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   927
        FilterScanner(final Set<JCTree.Tag> validTags) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   928
            this.treeFilter = new Filter<JCTree>() {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   929
                public boolean accepts(JCTree t) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   930
                    return validTags.contains(t.getTag());
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   931
                }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   932
            };
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   933
        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   934
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   935
        @Override
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   936
        public void scan(JCTree tree) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   937
            if (tree != null) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   938
                if (treeFilter.accepts(tree)) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   939
                    super.scan(tree);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   940
                } else {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   941
                    skip(tree);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   942
                }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   943
            }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   944
        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   945
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   946
        /**
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   947
         * 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
   948
         */
24066
1dfb66929538 8029718: Should always use lambda body structure to disambiguate overload resolution
vromero
parents: 22163
diff changeset
   949
        void skip(JCTree tree) {}
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   950
    }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   951
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   952
    /**
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   953
     * 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
   954
     * a given argument expression.
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   955
     */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   956
    static class PolyScanner extends FilterScanner {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   957
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   958
        PolyScanner() {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   959
            super(EnumSet.of(CONDEXPR, PARENS, LAMBDA, REFERENCE));
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   960
        }
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
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
     * 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
   965
     * within a lambda expression body.
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   966
     */
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   967
    static class LambdaReturnScanner extends FilterScanner {
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
        LambdaReturnScanner() {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   970
            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
   971
                    FORLOOP, IF, RETURN, SYNCHRONIZED, SWITCH, TRY, WHILELOOP));
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
   972
        }
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   973
    }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   974
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   975
    /**
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   976
     * This visitor is used to check that structural expressions conform
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   977
     * 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
   978
     * inferring types that make some of the nested expressions incompatible
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   979
     * with their corresponding instantiated target
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   980
     */
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   981
    class CheckStuckPolicy extends PolyScanner implements DeferredStuckPolicy, Infer.FreeTypeListener {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   982
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   983
        Type pt;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   984
        Infer.InferenceContext inferenceContext;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21718
diff changeset
   985
        Set<Type> stuckVars = new LinkedHashSet<>();
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21718
diff changeset
   986
        Set<Type> depVars = new LinkedHashSet<>();
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   987
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   988
        @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   989
        public boolean isStuck() {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   990
            return !stuckVars.isEmpty();
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   991
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   992
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   993
        @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   994
        public Set<Type> stuckVars() {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   995
            return stuckVars;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   996
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   997
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   998
        @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
   999
        public Set<Type> depVars() {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1000
            return depVars;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1001
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1002
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1003
        public CheckStuckPolicy(ResultInfo resultInfo, DeferredType dt) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1004
            this.pt = resultInfo.pt;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1005
            this.inferenceContext = resultInfo.checkContext.inferenceContext();
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1006
            scan(dt.tree);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1007
            if (!stuckVars.isEmpty()) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1008
                resultInfo.checkContext.inferenceContext()
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1009
                        .addFreeTypeListener(List.from(stuckVars), this);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1010
            }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1011
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1012
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1013
        @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1014
        public void typesInferred(InferenceContext inferenceContext) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1015
            stuckVars.clear();
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1016
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1017
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1018
        @Override
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1019
        public void visitLambda(JCLambda tree) {
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1020
            if (inferenceContext.inferenceVars().contains(pt)) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1021
                stuckVars.add(pt);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1022
            }
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
  1023
            if (!types.isFunctionalInterface(pt)) {
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1024
                return;
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1025
            }
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1026
            Type descType = types.findDescriptorType(pt);
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1027
            List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes());
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
  1028
            if (tree.paramKind == JCLambda.ParameterKind.IMPLICIT &&
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1029
                    freeArgVars.nonEmpty()) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1030
                stuckVars.addAll(freeArgVars);
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1031
                depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType()));
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1032
            }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1033
            scanLambdaBody(tree, descType.getReturnType());
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1034
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1035
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1036
        @Override
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1037
        public void visitReference(JCMemberReference tree) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1038
            scan(tree.expr);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1039
            if (inferenceContext.inferenceVars().contains(pt)) {
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1040
                stuckVars.add(pt);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1041
                return;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1042
            }
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15039
diff changeset
  1043
            if (!types.isFunctionalInterface(pt)) {
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1044
                return;
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1045
            }
14547
86d8d242b0c4 8003280: Add lambda tests
mcimadamore
parents: 14538
diff changeset
  1046
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1047
            Type descType = types.findDescriptorType(pt);
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1048
            List<Type> freeArgVars = inferenceContext.freeVarsIn(descType.getParameterTypes());
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1049
            if (freeArgVars.nonEmpty() &&
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1050
                    tree.overloadKind == JCMemberReference.OverloadKind.OVERLOADED) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1051
                stuckVars.addAll(freeArgVars);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1052
                depVars.addAll(inferenceContext.freeVarsIn(descType.getReturnType()));
18910
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18902
diff changeset
  1053
            }
14058
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
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1056
        void scanLambdaBody(JCLambda lambda, final Type pt) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1057
            if (lambda.getBodyKind() == JCTree.JCLambda.BodyKind.EXPRESSION) {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1058
                Type prevPt = this.pt;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1059
                try {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1060
                    this.pt = pt;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1061
                    scan(lambda.body);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1062
                } finally {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1063
                    this.pt = prevPt;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1064
                }
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1065
            } else {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1066
                LambdaReturnScanner lambdaScanner = new LambdaReturnScanner() {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1067
                    @Override
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1068
                    public void visitReturn(JCReturn tree) {
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1069
                        if (tree.expr != null) {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1070
                            Type prevPt = CheckStuckPolicy.this.pt;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1071
                            try {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1072
                                CheckStuckPolicy.this.pt = pt;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1073
                                CheckStuckPolicy.this.scan(tree.expr);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1074
                            } finally {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1075
                                CheckStuckPolicy.this.pt = prevPt;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1076
                            }
15039
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1077
                        }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1078
                    }
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1079
                };
80190ab051c0 8005184: Restructure DeferredAttr to allow pluggable deferred type completers
mcimadamore
parents: 14547
diff changeset
  1080
                lambdaScanner.scan(lambda.body);
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
  1081
            }
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
  1082
        }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
  1083
    }
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1084
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1085
    /**
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1086
     * This visitor is used to check that structural expressions conform
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1087
     * to their target - this step is required as inference could end up
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1088
     * inferring types that make some of the nested expressions incompatible
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1089
     * with their corresponding instantiated target
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1090
     */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1091
    class OverloadStuckPolicy extends CheckStuckPolicy implements DeferredStuckPolicy {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1092
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1093
        boolean stuck;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1094
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1095
        @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1096
        public boolean isStuck() {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1097
            return super.isStuck() || stuck;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1098
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1099
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1100
        public OverloadStuckPolicy(ResultInfo resultInfo, DeferredType dt) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1101
            super(resultInfo, dt);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1102
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1103
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1104
        @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1105
        public void visitLambda(JCLambda tree) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1106
            super.visitLambda(tree);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1107
            if (tree.paramKind == JCLambda.ParameterKind.IMPLICIT) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1108
                stuck = true;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1109
            }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1110
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1111
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1112
        @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1113
        public void visitReference(JCMemberReference tree) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1114
            super.visitReference(tree);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1115
            if (tree.overloadKind == JCMemberReference.OverloadKind.OVERLOADED) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1116
                stuck = true;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1117
            }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1118
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1119
    }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1120
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1121
    /**
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1122
     * Does the argument expression {@code expr} need speculative type-checking?
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1123
     */
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1124
    boolean isDeferred(Env<AttrContext> env, JCExpression expr) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1125
        DeferredChecker dc = new DeferredChecker(env);
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1126
        dc.scan(expr);
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1127
        return dc.result.isPoly();
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1128
    }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1129
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1130
    /**
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1131
     * The kind of an argument expression. This is used by the analysis that
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1132
     * determines as to whether speculative attribution is necessary.
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1133
     */
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1134
    enum ArgumentExpressionKind {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1135
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1136
        /** kind that denotes poly argument expression */
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1137
        POLY,
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1138
        /** kind that denotes a standalone expression */
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1139
        NO_POLY,
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1140
        /** kind that denotes a primitive/boxed standalone expression */
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1141
        PRIMITIVE;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1142
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1143
        /**
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1144
         * Does this kind denote a poly argument expression
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1145
         */
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1146
        public final boolean isPoly() {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1147
            return this == POLY;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1148
        }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1149
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1150
        /**
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1151
         * Does this kind denote a primitive standalone expression
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1152
         */
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1153
        public final boolean isPrimitive() {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1154
            return this == PRIMITIVE;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1155
        }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1156
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1157
        /**
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1158
         * Compute the kind of a standalone expression of a given type
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1159
         */
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1160
        static ArgumentExpressionKind standaloneKind(Type type, Types types) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1161
            return types.unboxedTypeOrType(type).isPrimitive() ?
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1162
                    ArgumentExpressionKind.PRIMITIVE :
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1163
                    ArgumentExpressionKind.NO_POLY;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1164
        }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1165
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1166
        /**
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1167
         * Compute the kind of a method argument expression given its symbol
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1168
         */
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1169
        static ArgumentExpressionKind methodKind(Symbol sym, Types types) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1170
            Type restype = sym.type.getReturnType();
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1171
            if (sym.type.hasTag(FORALL) &&
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1172
                    restype.containsAny(((ForAll)sym.type).tvars)) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1173
                return ArgumentExpressionKind.POLY;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1174
            } else {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1175
                return ArgumentExpressionKind.standaloneKind(restype, types);
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1176
            }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1177
        }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1178
    }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1179
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1180
    /**
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1181
     * Tree scanner used for checking as to whether an argument expression
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1182
     * requires speculative attribution
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1183
     */
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1184
    final class DeferredChecker extends FilterScanner {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1185
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1186
        Env<AttrContext> env;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1187
        ArgumentExpressionKind result;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1188
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1189
        public DeferredChecker(Env<AttrContext> env) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1190
            super(deferredCheckerTags);
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1191
            this.env = env;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1192
        }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1193
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1194
        @Override
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1195
        public void visitLambda(JCLambda tree) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1196
            //a lambda is always a poly expression
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1197
            result = ArgumentExpressionKind.POLY;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1198
        }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1199
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1200
        @Override
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1201
        public void visitReference(JCMemberReference tree) {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1202
            //perform arity-based check
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1203
            Env<AttrContext> localEnv = env.dup(tree);
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26531
diff changeset
  1204
            JCExpression exprTree = (JCExpression)attribSpeculative(tree.getQualifierExpression(), localEnv,
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26531
diff changeset
  1205
                    attr.memberReferenceQualifierResult(tree));
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1206
            JCMemberReference mref2 = new TreeCopier<Void>(make).copy(tree);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1207
            mref2.expr = exprTree;
21718
74a5882faf79 8026231: Look at 'static' flag when checking method references
vromero
parents: 20249
diff changeset
  1208
            Symbol res =
74a5882faf79 8026231: Look at 'static' flag when checking method references
vromero
parents: 20249
diff changeset
  1209
                    rs.getMemberReference(tree, localEnv, mref2,
74a5882faf79 8026231: Look at 'static' flag when checking method references
vromero
parents: 20249
diff changeset
  1210
                        exprTree.type, tree.name);
74a5882faf79 8026231: Look at 'static' flag when checking method references
vromero
parents: 20249
diff changeset
  1211
            tree.sym = res;
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
  1212
            if (res.kind.isOverloadError() ||
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1213
                    res.type.hasTag(FORALL) ||
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1214
                    (res.flags() & Flags.VARARGS) != 0 ||
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1215
                    (TreeInfo.isStaticSelector(exprTree, tree.name.table.names) &&
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1216
                    exprTree.type.isRaw())) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1217
                tree.overloadKind = JCMemberReference.OverloadKind.OVERLOADED;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1218
            } else {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1219
                tree.overloadKind = JCMemberReference.OverloadKind.UNOVERLOADED;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 18912
diff changeset
  1220
            }
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1221
            //a method reference is always a poly expression
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1222
            result = ArgumentExpressionKind.POLY;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1223
        }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1224
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1225
        @Override
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1226
        public void visitTypeCast(JCTypeCast tree) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1227
            //a cast is always a standalone expression
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1228
            result = ArgumentExpressionKind.NO_POLY;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1229
        }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1230
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1231
        @Override
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1232
        public void visitConditional(JCConditional tree) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1233
            scan(tree.truepart);
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1234
            if (!result.isPrimitive()) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1235
                result = ArgumentExpressionKind.POLY;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1236
                return;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1237
            }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1238
            scan(tree.falsepart);
27551
14a74a56c4a0 8064464: regression with type inference of conditional expression
mcimadamore
parents: 27224
diff changeset
  1239
            result = reduce(ArgumentExpressionKind.PRIMITIVE).isPrimitive() ?
14a74a56c4a0 8064464: regression with type inference of conditional expression
mcimadamore
parents: 27224
diff changeset
  1240
                    ArgumentExpressionKind.PRIMITIVE :
14a74a56c4a0 8064464: regression with type inference of conditional expression
mcimadamore
parents: 27224
diff changeset
  1241
                    ArgumentExpressionKind.POLY;
14a74a56c4a0 8064464: regression with type inference of conditional expression
mcimadamore
parents: 27224
diff changeset
  1242
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1243
        }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1244
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1245
        @Override
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1246
        public void visitNewClass(JCNewClass tree) {
28142
32a6b1af81b1 8064365: Better support for finder capabilities in target-typing context
mcimadamore
parents: 27551
diff changeset
  1247
            result = TreeInfo.isDiamond(tree) ?
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1248
                    ArgumentExpressionKind.POLY : ArgumentExpressionKind.NO_POLY;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1249
        }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1250
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1251
        @Override
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1252
        public void visitApply(JCMethodInvocation tree) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1253
            Name name = TreeInfo.name(tree.meth);
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1254
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1255
            //fast path
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1256
            if (tree.typeargs.nonEmpty() ||
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1257
                    name == name.table.names._this ||
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1258
                    name == name.table.names._super) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1259
                result = ArgumentExpressionKind.NO_POLY;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1260
                return;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1261
            }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1262
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1263
            //slow path
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1264
            Symbol sym = quicklyResolveMethod(env, tree);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1265
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1266
            if (sym == null) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1267
                result = ArgumentExpressionKind.POLY;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1268
                return;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1269
            }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1270
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1271
            result = analyzeCandidateMethods(sym, ArgumentExpressionKind.PRIMITIVE,
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1272
                    argumentKindAnalyzer);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1273
        }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1274
        //where
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1275
            private boolean isSimpleReceiver(JCTree rec) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1276
                switch (rec.getTag()) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1277
                    case IDENT:
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1278
                        return true;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1279
                    case SELECT:
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1280
                        return isSimpleReceiver(((JCFieldAccess)rec).selected);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1281
                    case TYPEAPPLY:
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1282
                    case TYPEARRAY:
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1283
                        return true;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1284
                    case ANNOTATED_TYPE:
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1285
                        return isSimpleReceiver(((JCAnnotatedType)rec).underlyingType);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1286
                    case APPLY:
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1287
                        return true;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1288
                    default:
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1289
                        return false;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1290
                }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1291
            }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1292
            private ArgumentExpressionKind reduce(ArgumentExpressionKind kind) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1293
                return argumentKindAnalyzer.reduce(result, kind);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1294
            }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1295
            MethodAnalyzer<ArgumentExpressionKind> argumentKindAnalyzer =
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1296
                    new MethodAnalyzer<ArgumentExpressionKind>() {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1297
                @Override
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1298
                public ArgumentExpressionKind process(MethodSymbol ms) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1299
                    return ArgumentExpressionKind.methodKind(ms, types);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1300
                }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1301
                @Override
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1302
                public ArgumentExpressionKind reduce(ArgumentExpressionKind kind1,
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1303
                                                     ArgumentExpressionKind kind2) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1304
                    switch (kind1) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1305
                        case PRIMITIVE: return kind2;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1306
                        case NO_POLY: return kind2.isPoly() ? kind2 : kind1;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1307
                        case POLY: return kind1;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1308
                        default:
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1309
                            Assert.error();
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1310
                            return null;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1311
                    }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1312
                }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1313
                @Override
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1314
                public boolean shouldStop(ArgumentExpressionKind result) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1315
                    return result.isPoly();
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1316
                }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1317
            };
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1318
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1319
        @Override
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1320
        public void visitLiteral(JCLiteral tree) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1321
            Type litType = attr.litType(tree.typetag);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1322
            result = ArgumentExpressionKind.standaloneKind(litType, types);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1323
        }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1324
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1325
        @Override
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1326
        void skip(JCTree tree) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1327
            result = ArgumentExpressionKind.NO_POLY;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1328
        }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1329
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1330
        private Symbol quicklyResolveMethod(Env<AttrContext> env, final JCMethodInvocation tree) {
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1331
            final JCExpression rec = tree.meth.hasTag(SELECT) ?
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1332
                    ((JCFieldAccess)tree.meth).selected :
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1333
                    null;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1334
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1335
            if (rec != null && !isSimpleReceiver(rec)) {
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1336
                return null;
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1337
            }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1338
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1339
            Type site;
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1340
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1341
            if (rec != null) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1342
                if (rec.hasTag(APPLY)) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1343
                    Symbol recSym = quicklyResolveMethod(env, (JCMethodInvocation) rec);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1344
                    if (recSym == null)
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1345
                        return null;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1346
                    Symbol resolvedReturnType =
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1347
                            analyzeCandidateMethods(recSym, syms.errSymbol, returnSymbolAnalyzer);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1348
                    if (resolvedReturnType == null)
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1349
                        return null;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1350
                    site = resolvedReturnType.type;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1351
                } else {
26532
aa84b6606229 8056021: checkin for JDK-8027262 breaks Checker Framework
jfranck
parents: 26531
diff changeset
  1352
                    site = attribSpeculative(rec, env, attr.unknownTypeExprInfo).type;
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1353
                }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1354
            } else {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1355
                site = env.enclClass.sym.type;
18901
8309dd8e14d9 8019480: Javac crashes when method is called on a type-variable receiver from lambda expression
mcimadamore
parents: 18646
diff changeset
  1356
            }
8309dd8e14d9 8019480: Javac crashes when method is called on a type-variable receiver from lambda expression
mcimadamore
parents: 18646
diff changeset
  1357
29292
c10d63c667cd 8073842: Invalid method reference when referencing a method on a wildcard type
mcimadamore
parents: 29051
diff changeset
  1358
            site = types.skipTypeVars(site, true);
26531
c32c9586ea94 8056984: Exception in compiler: java.lang.AssertionError: isSubClass T
jlahoda
parents: 26530
diff changeset
  1359
18910
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18902
diff changeset
  1360
            List<Type> args = rs.dummyArgs(tree.args.length());
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1361
            Name name = TreeInfo.name(tree.meth);
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1362
18910
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18902
diff changeset
  1363
            Resolve.LookupHelper lh = rs.new LookupHelper(name, site, args, List.<Type>nil(), MethodResolutionPhase.VARARITY) {
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1364
                @Override
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1365
                Symbol lookup(Env<AttrContext> env, MethodResolutionPhase phase) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1366
                    return rec == null ?
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1367
                        rs.findFun(env, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired()) :
29051
7244db2ab176 8071241: Investigate alternate strategy for type-checking operators
mcimadamore
parents: 28891
diff changeset
  1368
                        rs.findMethod(env, site, name, argtypes, typeargtypes, phase.isBoxingRequired(), phase.isVarargsRequired());
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1369
                }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1370
                @Override
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1371
                Symbol access(Env<AttrContext> env, DiagnosticPosition pos, Symbol location, Symbol sym) {
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1372
                    return sym;
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1373
                }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1374
            };
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1375
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1376
            return rs.lookupMethod(env, tree, site.tsym, rs.arityMethodCheck, lh);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1377
        }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1378
        //where:
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1379
            MethodAnalyzer<Symbol> returnSymbolAnalyzer = new MethodAnalyzer<Symbol>() {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1380
                @Override
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1381
                public Symbol process(MethodSymbol ms) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1382
                    ArgumentExpressionKind kind = ArgumentExpressionKind.methodKind(ms, types);
26530
b4d78593e4c9 8056014: Type inference may be skipped for a complex receiver generic method in a parameter position
jlahoda
parents: 26266
diff changeset
  1383
                    if (kind == ArgumentExpressionKind.POLY || ms.getReturnType().hasTag(TYPEVAR))
b4d78593e4c9 8056014: Type inference may be skipped for a complex receiver generic method in a parameter position
jlahoda
parents: 26266
diff changeset
  1384
                        return null;
b4d78593e4c9 8056014: Type inference may be skipped for a complex receiver generic method in a parameter position
jlahoda
parents: 26266
diff changeset
  1385
                    return ms.getReturnType().tsym;
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1386
                }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1387
                @Override
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1388
                public Symbol reduce(Symbol s1, Symbol s2) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1389
                    return s1 == syms.errSymbol ? s2 : s1 == s2 ? s1 : null;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1390
                }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1391
                @Override
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1392
                public boolean shouldStop(Symbol result) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1393
                    return result == null;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1394
                }
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1395
            };
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1396
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1397
        /**
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1398
         * Process the result of Resolve.lookupMethod. If sym is a method symbol, the result of
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1399
         * MethodAnalyzer.process is returned. If sym is an ambiguous symbol, all the candidate
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1400
         * methods are inspected one by one, using MethodAnalyzer.process. The outcomes are
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1401
         * reduced using MethodAnalyzer.reduce (using defaultValue as the first value over which
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1402
         * the reduction runs). MethodAnalyzer.shouldStop can be used to stop the inspection early.
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1403
         */
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1404
        <E> E analyzeCandidateMethods(Symbol sym, E defaultValue, MethodAnalyzer<E> analyzer) {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1405
            switch (sym.kind) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
  1406
                case MTH:
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1407
                    return analyzer.process((MethodSymbol) sym);
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
  1408
                case AMBIGUOUS:
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1409
                    Resolve.AmbiguityError err = (Resolve.AmbiguityError)sym.baseSymbol();
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1410
                    E res = defaultValue;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1411
                    for (Symbol s : err.ambiguousSyms) {
27224
228abfa87080 8054457: Refactor Symbol kinds from small ints to an enum
emc
parents: 26781
diff changeset
  1412
                        if (s.kind == MTH) {
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1413
                            res = analyzer.reduce(res, analyzer.process((MethodSymbol) s));
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1414
                            if (analyzer.shouldStop(res))
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1415
                                return res;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1416
                        }
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1417
                    }
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1418
                    return res;
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1419
                default:
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1420
                    return defaultValue;
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1421
            }
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1422
        }
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1423
    }
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1424
24649
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1425
    /** Analyzer for methods - used by analyzeCandidateMethods. */
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1426
    interface MethodAnalyzer<E> {
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1427
        E process(MethodSymbol ms);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1428
        E reduce(E e1, E e2);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1429
        boolean shouldStop(E result);
1760d92bc6d2 8031967: For some sources compiler compiles for ever
jlahoda
parents: 24396
diff changeset
  1430
    }
16975
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1431
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1432
    //where
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1433
    private EnumSet<JCTree.Tag> deferredCheckerTags =
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1434
            EnumSet.of(LAMBDA, REFERENCE, PARENS, TYPECAST,
124c8436d59c 8010923: Avoid redundant speculative attribution
mcimadamore
parents: 16805
diff changeset
  1435
                    CONDEXPR, NEWCLASS, APPLY, LITERAL);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents:
diff changeset
  1436
}