langtools/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Infer.java
author mcimadamore
Thu, 25 Aug 2016 11:51:19 +0100
changeset 40594 8cbf5df9c503
parent 39599 3c7da4996d8c
child 41855 0d1a58e6beb7
permissions -rw-r--r--
8164399: inference of thrown variable does not work correctly Summary: Logic for inferring thrown variables should exclude non proper bounds as per JLS 18.1 Reviewed-by: vromero, dlsmith
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     1
/*
36157
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 33917
diff changeset
     2
 * Copyright (c) 1999, 2016, Oracle and/or its affiliates. All rights reserved.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
06bc494ca11e Initial load
duke
parents:
diff changeset
     4
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
06bc494ca11e Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5489
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
10
06bc494ca11e Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5489
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    10
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
06bc494ca11e Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
06bc494ca11e Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
06bc494ca11e Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
06bc494ca11e Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
06bc494ca11e Initial load
duke
parents:
diff changeset
    16
 *
06bc494ca11e Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
06bc494ca11e Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
06bc494ca11e Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
06bc494ca11e Initial load
duke
parents:
diff changeset
    20
 *
5520
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5489
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5489
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
86e4b9a9da40 6943119: Rebrand source copyright notices
ohair
parents: 5489
diff changeset
    23
 * questions.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    24
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    25
06bc494ca11e Initial load
duke
parents:
diff changeset
    26
package com.sun.tools.javac.comp;
06bc494ca11e Initial load
duke
parents:
diff changeset
    27
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
    28
import com.sun.tools.javac.code.Type.UndetVar.UndetVarListener;
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
    29
import com.sun.tools.javac.tree.JCTree;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
    30
import com.sun.tools.javac.tree.JCTree.JCTypeCast;
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
    31
import com.sun.tools.javac.tree.TreeInfo;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    32
import com.sun.tools.javac.util.*;
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
    33
import com.sun.tools.javac.util.GraphUtils.DottableNode;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    34
import com.sun.tools.javac.util.JCDiagnostic.DiagnosticPosition;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    35
import com.sun.tools.javac.util.List;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    36
import com.sun.tools.javac.code.*;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    37
import com.sun.tools.javac.code.Type.*;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    38
import com.sun.tools.javac.code.Type.UndetVar.InferenceBound;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    39
import com.sun.tools.javac.code.Symbol.*;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    40
import com.sun.tools.javac.comp.DeferredAttr.AttrMode;
32709
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
    41
import com.sun.tools.javac.comp.DeferredAttr.DeferredAttrContext;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    42
import com.sun.tools.javac.comp.Infer.GraphSolver.InferenceGraph;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    43
import com.sun.tools.javac.comp.Infer.GraphSolver.InferenceGraph.Node;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    44
import com.sun.tools.javac.comp.Resolve.InapplicableMethodException;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    45
import com.sun.tools.javac.comp.Resolve.VerboseResolutionMode;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    46
26267
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
    47
import java.io.IOException;
36157
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 33917
diff changeset
    48
import java.io.Writer;
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 33917
diff changeset
    49
import java.nio.file.Files;
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 33917
diff changeset
    50
import java.nio.file.Path;
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 33917
diff changeset
    51
import java.nio.file.Paths;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    52
import java.util.ArrayList;
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
    53
import java.util.Collection;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    54
import java.util.Collections;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    55
import java.util.EnumSet;
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
    56
import java.util.HashMap;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    57
import java.util.HashSet;
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
    58
import java.util.Map;
39589
0cbaed77814c 8048543: JLS8 18.5.3: inference variable seems to be instantiated unexpectedly
vromero
parents: 38832
diff changeset
    59
import java.util.Optional;
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
    60
import java.util.Properties;
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
    61
import java.util.Set;
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
    62
import java.util.function.BiFunction;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
    63
import java.util.function.BiPredicate;
40594
8cbf5df9c503 8164399: inference of thrown variable does not work correctly
mcimadamore
parents: 39599
diff changeset
    64
import java.util.stream.Collectors;
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
    65
39599
3c7da4996d8c 8153407: javac, fold debug options
vromero
parents: 39589
diff changeset
    66
import com.sun.tools.javac.main.Option;
3c7da4996d8c 8153407: javac, fold debug options
vromero
parents: 39589
diff changeset
    67
14359
d4099818ab70 7200915: convert TypeTags from a series of small ints to an enum
jjg
parents: 14258
diff changeset
    68
import static com.sun.tools.javac.code.TypeTag.*;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    69
06bc494ca11e Initial load
duke
parents:
diff changeset
    70
/** Helper class for type parameter inference, used by the attribution phase.
06bc494ca11e Initial load
duke
parents:
diff changeset
    71
 *
5847
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5846
diff changeset
    72
 *  <p><b>This is NOT part of any supported API.
1908176fd6e3 6944312: Potential rebranding issues in openjdk/langtools repository sources
jjg
parents: 5846
diff changeset
    73
 *  If you write code that depends on this, you do so at your own risk.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    74
 *  This code and its internal interfaces are subject to change or
06bc494ca11e Initial load
duke
parents:
diff changeset
    75
 *  deletion without notice.</b>
06bc494ca11e Initial load
duke
parents:
diff changeset
    76
 */
06bc494ca11e Initial load
duke
parents:
diff changeset
    77
public class Infer {
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
    78
    protected static final Context.Key<Infer> inferKey = new Context.Key<>();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    79
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    80
    Resolve rs;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    81
    Check chk;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    82
    Symtab syms;
06bc494ca11e Initial load
duke
parents:
diff changeset
    83
    Types types;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    84
    JCDiagnostic.Factory diags;
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
    85
    Log log;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
    86
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    87
    /** should the graph solver be used? */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
    88
    boolean allowGraphInference;
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15037
diff changeset
    89
26267
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
    90
    /**
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
    91
     * folder in which the inference dependency graphs should be written.
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
    92
     */
39599
3c7da4996d8c 8153407: javac, fold debug options
vromero
parents: 39589
diff changeset
    93
    private final String dependenciesFolder;
26267
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
    94
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
    95
    /**
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
    96
     * List of graphs awaiting to be dumped to a file.
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
    97
     */
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
    98
    private List<String> pendingGraphs;
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
    99
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   100
    public static Infer instance(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   101
        Infer instance = context.get(inferKey);
06bc494ca11e Initial load
duke
parents:
diff changeset
   102
        if (instance == null)
06bc494ca11e Initial load
duke
parents:
diff changeset
   103
            instance = new Infer(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   104
        return instance;
06bc494ca11e Initial load
duke
parents:
diff changeset
   105
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   106
06bc494ca11e Initial load
duke
parents:
diff changeset
   107
    protected Infer(Context context) {
06bc494ca11e Initial load
duke
parents:
diff changeset
   108
        context.put(inferKey, this);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   109
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   110
        rs = Resolve.instance(context);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   111
        chk = Check.instance(context);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   112
        syms = Symtab.instance(context);
06bc494ca11e Initial load
duke
parents:
diff changeset
   113
        types = Types.instance(context);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   114
        diags = JCDiagnostic.Factory.instance(context);
10816
ce8a7e9d8882 7098660: Write better overload resolution/inference tests
mcimadamore
parents: 10628
diff changeset
   115
        log = Log.instance(context);
13440
1ea85052f98d 7187104: Inference cleanup: remove redundant exception classes in Infer.java
mcimadamore
parents: 13438
diff changeset
   116
        inferenceException = new InferenceException(diags);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   117
        Options options = Options.instance(context);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   118
        allowGraphInference = Source.instance(context).allowGraphInference()
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   119
                && options.isUnset("useLegacyInference");
39599
3c7da4996d8c 8153407: javac, fold debug options
vromero
parents: 39589
diff changeset
   120
        dependenciesFolder = options.get("debug.dumpInferenceGraphsTo");
26267
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   121
        pendingGraphs = List.nil();
31937
ad43a6639c4a 8132215: class InferenceContext should live in a separate file
vromero
parents: 30014
diff changeset
   122
ad43a6639c4a 8132215: class InferenceContext should live in a separate file
vromero
parents: 30014
diff changeset
   123
        emptyContext = new InferenceContext(this, List.<Type>nil());
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   124
    }
06bc494ca11e Initial load
duke
parents:
diff changeset
   125
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   126
    /** A value for prototypes that admit any type, including polymorphic ones. */
18646
e628560a86d1 8017104: javac should have a class for primitive types that inherits from Type
vromero
parents: 18395
diff changeset
   127
    public static final Type anyPoly = new JCNoType();
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   128
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   129
   /**
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   130
    * This exception class is design to store a list of diagnostics corresponding
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   131
    * to inference errors that can arise during a method applicability check.
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   132
    */
11707
532f41763bc9 7129801: Merge the two method applicability routines
mcimadamore
parents: 11550
diff changeset
   133
    public static class InferenceException extends InapplicableMethodException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   134
        private static final long serialVersionUID = 0;
06bc494ca11e Initial load
duke
parents:
diff changeset
   135
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   136
        List<JCDiagnostic> messages = List.nil();
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   137
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   138
        InferenceException(JCDiagnostic.Factory diags) {
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   139
            super(diags);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   140
        }
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   141
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   142
        @Override
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
   143
        InapplicableMethodException setMessage() {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
   144
            //no message to set
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
   145
            return this;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
   146
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
   147
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
   148
        @Override
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   149
        InapplicableMethodException setMessage(JCDiagnostic diag) {
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   150
            messages = messages.append(diag);
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   151
            return this;
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   152
        }
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   153
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   154
        @Override
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   155
        public JCDiagnostic getDiagnostic() {
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   156
            return messages.head;
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   157
        }
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   158
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   159
        void clear() {
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   160
            messages = List.nil();
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   161
        }
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   162
    }
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   163
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   164
    protected final InferenceException inferenceException;
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   165
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   166
    // <editor-fold defaultstate="collapsed" desc="Inference routines">
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   167
    /**
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   168
     * Main inference entry point - instantiate a generic method type
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   169
     * using given argument types and (possibly) an expected target-type.
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   170
     */
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   171
    Type instantiateMethod( Env<AttrContext> env,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   172
                            List<Type> tvars,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   173
                            MethodType mt,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   174
                            Attr.ResultInfo resultInfo,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   175
                            MethodSymbol msym,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   176
                            List<Type> argtypes,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   177
                            boolean allowBoxing,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   178
                            boolean useVarargs,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   179
                            Resolve.MethodResolutionContext resolveContext,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   180
                            Warner warn) throws InferenceException {
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   181
        //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG
31937
ad43a6639c4a 8132215: class InferenceContext should live in a separate file
vromero
parents: 30014
diff changeset
   182
        final InferenceContext inferenceContext = new InferenceContext(this, tvars);  //B0
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   183
        inferenceException.clear();
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   184
        try {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   185
            DeferredAttr.DeferredAttrContext deferredAttrContext =
18910
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18909
diff changeset
   186
                        resolveContext.deferredAttrContext(msym, inferenceContext, resultInfo, warn);
6710
b14e6fe7b290 5088624: cannot find symbol message should be more intelligent
mcimadamore
parents: 6592
diff changeset
   187
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   188
            resolveContext.methodCheck.argumentsAcceptable(env, deferredAttrContext,   //B2
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   189
                    argtypes, mt.getParameterTypes(), warn);
32709
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   190
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   191
            if (allowGraphInference && resultInfo != null && resultInfo.pt == anyPoly) {
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   192
                doIncorporation(inferenceContext, warn);
32709
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   193
                //we are inside method attribution - just return a partially inferred type
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   194
                return new PartiallyInferredMethodType(mt, inferenceContext, env, warn);
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   195
            } else if (allowGraphInference &&
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   196
                    resultInfo != null &&
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15037
diff changeset
   197
                    !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   198
                //inject return constraints earlier
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   199
                doIncorporation(inferenceContext, warn); //propagation
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   200
38538
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   201
                boolean shouldPropagate = shouldPropagate(mt.getReturnType(), resultInfo, inferenceContext);
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   202
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   203
                InferenceContext minContext = shouldPropagate ?
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   204
                        inferenceContext.min(roots(mt, deferredAttrContext), true, warn) :
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   205
                        inferenceContext;
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   206
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   207
                Type newRestype = generateReturnConstraints(env.tree, resultInfo,  //B3
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   208
                        mt, minContext);
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
   209
                mt = (MethodType)types.createMethodTypeWithReturn(mt, newRestype);
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   210
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   211
                //propagate outwards if needed
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   212
                if (shouldPropagate) {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   213
                    //propagate inference context outwards and exit
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   214
                    minContext.dupTo(resultInfo.checkContext.inferenceContext());
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   215
                    deferredAttrContext.complete();
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   216
                    return mt;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   217
                }
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15037
diff changeset
   218
            }
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15037
diff changeset
   219
15037
8ba16ac61b1a 8005243: Restructure method check code to allow pluggable checkers
mcimadamore
parents: 14547
diff changeset
   220
            deferredAttrContext.complete();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   221
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   222
            // minimize as yet undetermined type variables
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   223
            if (allowGraphInference) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   224
                inferenceContext.solve(warn);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   225
            } else {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   226
                inferenceContext.solveLegacy(true, warn, LegacyInferenceSteps.EQ_LOWER.steps); //minimizeInst
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   227
            }
3778
38a70273507b 6650759: Inference of formal type parameter (unused in formal parameters) is not performed
mcimadamore
parents: 3140
diff changeset
   228
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15383
diff changeset
   229
            mt = (MethodType)inferenceContext.asInstType(mt);
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   230
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   231
            if (!allowGraphInference &&
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   232
                    inferenceContext.restvars().nonEmpty() &&
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   233
                    resultInfo != null &&
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   234
                    !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) {
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   235
                generateReturnConstraints(env.tree, resultInfo, mt, inferenceContext);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   236
                inferenceContext.solveLegacy(false, warn, LegacyInferenceSteps.EQ_UPPER.steps); //maximizeInst
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   237
                mt = (MethodType)inferenceContext.asInstType(mt);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   238
            }
3140
15a274b13051 6638712: Inference with wildcard types causes selection of inapplicable method
mcimadamore
parents: 3139
diff changeset
   239
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   240
            if (resultInfo != null && rs.verboseResolutionMode.contains(VerboseResolutionMode.DEFERRED_INST)) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   241
                log.note(env.tree.pos, "deferred.method.inst", msym, mt, resultInfo.pt);
12915
28cf1e0dafdc 7166552: Inference: cleanup usage of Type.ForAll
mcimadamore
parents: 12468
diff changeset
   242
            }
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   243
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   244
            // return instantiated version of method type
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   245
            return mt;
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   246
        } finally {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   247
            if (resultInfo != null || !allowGraphInference) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   248
                inferenceContext.notifyChange();
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   249
            } else {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   250
                inferenceContext.notifyChange(inferenceContext.boundedVars());
14048
308d1cf8fe46 7177306: Regression: unchecked method call does not erase return type
mcimadamore
parents: 14047
diff changeset
   251
            }
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   252
            if (resultInfo == null) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   253
                /* if the is no result info then we can clear the capture types
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   254
                 * cache without affecting any result info check
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   255
                 */
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   256
                inferenceContext.captureTypeCache.clear();
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   257
            }
26267
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   258
            dumpGraphsIfNeeded(env.tree, msym, resolveContext);
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   259
        }
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   260
    }
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   261
    //where
38538
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   262
        private boolean shouldPropagate(Type restype, Attr.ResultInfo target, InferenceContext inferenceContext) {
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   263
            return target.checkContext.inferenceContext() != emptyContext && //enclosing context is a generic method
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   264
                        inferenceContext.free(restype) && //return type contains inference vars
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   265
                        (!inferenceContext.inferencevars.contains(restype) || //no eager instantiation is required (as per 18.5.2)
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   266
                                !needsEagerInstantiation((UndetVar)inferenceContext.asUndetVar(restype), target.pt, inferenceContext));
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   267
        }
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   268
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   269
        private List<Type> roots(MethodType mt, DeferredAttrContext deferredAttrContext) {
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   270
            ListBuffer<Type> roots = new ListBuffer<>();
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   271
            roots.add(mt.getReturnType());
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   272
            if (deferredAttrContext != null && deferredAttrContext.mode == AttrMode.CHECK) {
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   273
                roots.addAll(mt.getThrownTypes());
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   274
                for (DeferredAttr.DeferredAttrNode n : deferredAttrContext.deferredAttrNodes) {
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   275
                    roots.addAll(n.deferredStuckPolicy.stuckVars());
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   276
                    roots.addAll(n.deferredStuckPolicy.depVars());
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   277
                }
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   278
            }
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   279
            return roots.toList();
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   280
        }
26267
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   281
32709
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   282
    /**
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   283
     * A partially infered method/constructor type; such a type can be checked multiple times
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   284
     * against different targets.
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   285
     */
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   286
    public class PartiallyInferredMethodType extends MethodType {
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   287
        public PartiallyInferredMethodType(MethodType mtype, InferenceContext inferenceContext, Env<AttrContext> env, Warner warn) {
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   288
            super(mtype.getParameterTypes(), mtype.getReturnType(), mtype.getThrownTypes(), mtype.tsym);
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   289
            this.inferenceContext = inferenceContext;
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   290
            this.env = env;
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   291
            this.warn = warn;
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   292
        }
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   293
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   294
        /** The inference context. */
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   295
        final InferenceContext inferenceContext;
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   296
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   297
        /** The attribution environment. */
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   298
        Env<AttrContext> env;
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   299
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   300
        /** The warner. */
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   301
        final Warner warn;
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   302
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   303
        @Override
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   304
        public boolean isPartial() {
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   305
            return true;
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   306
        }
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   307
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   308
        /**
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   309
         * Checks this type against a target; this means generating return type constraints, solve
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   310
         * and then roll back the results (to avoid poolluting the context).
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   311
         */
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   312
        Type check(Attr.ResultInfo resultInfo) {
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   313
            Warner noWarnings = new Warner(null);
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   314
            inferenceException.clear();
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   315
            List<Type> saved_undet = null;
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   316
            try {
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   317
                /** we need to save the inference context before generating target type constraints.
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   318
                 *  This constraints may pollute the inference context and make it useless in case we
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   319
                 *  need to use it several times: with several targets.
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   320
                 */
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   321
                saved_undet = inferenceContext.save();
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   322
                if (allowGraphInference && !warn.hasNonSilentLint(Lint.LintCategory.UNCHECKED)) {
38538
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   323
                    boolean shouldPropagate = shouldPropagate(getReturnType(), resultInfo, inferenceContext);
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   324
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   325
                    InferenceContext minContext = shouldPropagate ?
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   326
                            inferenceContext.min(roots(asMethodType(), null), false, warn) :
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   327
                            inferenceContext;
32709
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   328
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   329
                    MethodType other = (MethodType)minContext.update(asMethodType());
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   330
                    Type newRestype = generateReturnConstraints(env.tree, resultInfo,  //B3
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   331
                            other, minContext);
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   332
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   333
                    if (shouldPropagate) {
32709
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   334
                        //propagate inference context outwards and exit
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   335
                        minContext.dupTo(resultInfo.checkContext.inferenceContext(),
32709
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   336
                                resultInfo.checkContext.deferredAttrContext().insideOverloadPhase());
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   337
                        return newRestype;
32709
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   338
                    }
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   339
                }
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   340
                inferenceContext.solve(noWarnings);
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   341
                return inferenceContext.asInstType(this).getReturnType();
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   342
            } catch (InferenceException ex) {
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   343
                resultInfo.checkContext.report(null, ex.getDiagnostic());
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   344
                Assert.error(); //cannot get here (the above should throw)
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   345
                return null;
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   346
            } finally {
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   347
                if (saved_undet != null) {
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   348
                    inferenceContext.rollback(saved_undet);
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   349
                }
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   350
            }
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   351
        }
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   352
    }
55d136799f79 8078093: Severe compiler performance regression Java 7 to 8 for nested method invocations
mcimadamore
parents: 31937
diff changeset
   353
26267
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   354
    private void dumpGraphsIfNeeded(DiagnosticPosition pos, Symbol msym, Resolve.MethodResolutionContext rsContext) {
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   355
        int round = 0;
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   356
        try {
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   357
            for (String graph : pendingGraphs.reverse()) {
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   358
                Assert.checkNonNull(dependenciesFolder);
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   359
                Name name = msym.name == msym.name.table.names.init ?
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   360
                        msym.owner.name : msym.name;
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   361
                String filename = String.format("%s@%s[mode=%s,step=%s]_%d.dot",
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   362
                        name,
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   363
                        pos.getStartPosition(),
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   364
                        rsContext.attrMode(),
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   365
                        rsContext.step,
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   366
                        round);
36157
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 33917
diff changeset
   367
                Path dotFile = Paths.get(dependenciesFolder, filename);
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 33917
diff changeset
   368
                try (Writer w = Files.newBufferedWriter(dotFile)) {
fdbf6c9be2ab 8145472: replace remaining java.io.File with java.nio.file.Path
jjg
parents: 33917
diff changeset
   369
                    w.append(graph);
26267
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   370
                }
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   371
                round++;
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   372
            }
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   373
        } catch (IOException ex) {
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   374
            Assert.error("Error occurred when dumping inference graph: " + ex.getMessage());
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   375
        } finally {
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
   376
            pendingGraphs = List.nil();
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   377
        }
8616
5a47f5535883 7015430: Incorrect thrown type determined for unchecked invocations
mcimadamore
parents: 8229
diff changeset
   378
    }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   379
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   380
    /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   381
     * Generate constraints from the generic method's return type. If the method
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   382
     * call occurs in a context where a type T is expected, use the expected
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   383
     * type to derive more constraints on the generic method inference variables.
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   384
     */
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   385
    Type generateReturnConstraints(JCTree tree, Attr.ResultInfo resultInfo,
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   386
            MethodType mt, InferenceContext inferenceContext) {
23132
00a059740d87 8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents: 23124
diff changeset
   387
        InferenceContext rsInfoInfContext = resultInfo.checkContext.inferenceContext();
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
   388
        Type from = mt.getReturnType();
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
   389
        if (mt.getReturnType().containsAny(inferenceContext.inferencevars) &&
23132
00a059740d87 8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents: 23124
diff changeset
   390
                rsInfoInfContext != emptyContext) {
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
   391
            from = types.capture(from);
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
   392
            //add synthetic captured ivars
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
   393
            for (Type t : from.getTypeArguments()) {
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
   394
                if (t.hasTag(TYPEVAR) && ((TypeVar)t).isCaptured()) {
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
   395
                    inferenceContext.addVar((TypeVar)t);
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
   396
                }
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
   397
            }
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
   398
        }
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   399
        Type qtype = inferenceContext.asUndetVar(from);
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   400
        Type to = resultInfo.pt;
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   401
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   402
        if (qtype.hasTag(VOID)) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   403
            to = syms.voidType;
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   404
        } else if (to.hasTag(NONE)) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   405
            to = from.isPrimitive() ? from : syms.objectType;
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   406
        } else if (qtype.hasTag(UNDETVAR)) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   407
            if (resultInfo.pt.isReference()) {
38538
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   408
                if (needsEagerInstantiation((UndetVar)qtype, to, inferenceContext)) {
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   409
                    to = generateReferenceToTargetConstraint(tree, (UndetVar)qtype, to, resultInfo, inferenceContext);
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   410
                }
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   411
            } else {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   412
                if (to.isPrimitive()) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   413
                    to = generateReturnConstraintsPrimitive(tree, (UndetVar)qtype, to,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   414
                        resultInfo, inferenceContext);
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   415
                }
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   416
            }
33708
99085a01b536 8141613: Compiler fails to infer generic type
mcimadamore
parents: 32915
diff changeset
   417
        } else if (rsInfoInfContext.free(resultInfo.pt)) {
99085a01b536 8141613: Compiler fails to infer generic type
mcimadamore
parents: 32915
diff changeset
   418
            //propagation - cache captured vars
99085a01b536 8141613: Compiler fails to infer generic type
mcimadamore
parents: 32915
diff changeset
   419
            qtype = inferenceContext.asUndetVar(rsInfoInfContext.cachedCapture(tree, from, false));
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   420
        }
23132
00a059740d87 8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents: 23124
diff changeset
   421
        Assert.check(allowGraphInference || !rsInfoInfContext.free(to),
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   422
                "legacy inference engine cannot handle constraints on both sides of a subtyping assertion");
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   423
        //we need to skip capture?
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   424
        Warner retWarn = new Warner();
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   425
        if (!resultInfo.checkContext.compatible(qtype, rsInfoInfContext.asUndetVar(to), retWarn) ||
18008
6d75e3886bac 8015505: Spurious inference error when return type of generic method requires unchecked conversion to target
mcimadamore
parents: 16967
diff changeset
   426
                //unchecked conversion is not allowed in source 7 mode
6d75e3886bac 8015505: Spurious inference error when return type of generic method requires unchecked conversion to target
mcimadamore
parents: 16967
diff changeset
   427
                (!allowGraphInference && retWarn.hasLint(Lint.LintCategory.UNCHECKED))) {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   428
            throw inferenceException
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   429
                    .setMessage("infer.no.conforming.instance.exists",
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   430
                    inferenceContext.restvars(), mt.getReturnType(), to);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   431
        }
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
   432
        return from;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   433
    }
18910
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18909
diff changeset
   434
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   435
    private Type generateReturnConstraintsPrimitive(JCTree tree, UndetVar from,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   436
            Type to, Attr.ResultInfo resultInfo, InferenceContext inferenceContext) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   437
        if (!allowGraphInference) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   438
            //if legacy, just return boxed type
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   439
            return types.boxedClass(to).type;
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   440
        }
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   441
        //if graph inference we need to skip conflicting boxed bounds...
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   442
        for (Type t : from.getBounds(InferenceBound.EQ, InferenceBound.UPPER,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   443
                InferenceBound.LOWER)) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   444
            Type boundAsPrimitive = types.unboxedType(t);
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   445
            if (boundAsPrimitive == null || boundAsPrimitive.hasTag(NONE)) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   446
                continue;
18910
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18909
diff changeset
   447
            }
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   448
            return generateReferenceToTargetConstraint(tree, from, to,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   449
                    resultInfo, inferenceContext);
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   450
        }
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   451
        return types.boxedClass(to).type;
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   452
    }
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   453
38538
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   454
    private boolean needsEagerInstantiation(UndetVar from, Type to, InferenceContext inferenceContext) {
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   455
        Type captureOfTo = types.capture(to);
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   456
        /* T is a reference type, but is not a wildcard-parameterized type, and either
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   457
         */
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   458
        if (captureOfTo == to) { //not a wildcard parameterized type
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   459
            /* i) B2 contains a bound of one of the forms alpha = S or S <: alpha,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   460
             *      where S is a wildcard-parameterized type, or
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   461
             */
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   462
            for (Type t : from.getBounds(InferenceBound.EQ, InferenceBound.LOWER)) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   463
                Type captureOfBound = types.capture(t);
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   464
                if (captureOfBound != t) {
38538
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   465
                    return true;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   466
                }
12468
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 12335
diff changeset
   467
            }
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   468
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   469
            /* ii) B2 contains two bounds of the forms S1 <: alpha and S2 <: alpha,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   470
             * where S1 and S2 have supertypes that are two different
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   471
             * parameterizations of the same generic class or interface.
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   472
             */
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   473
            for (Type aLowerBound : from.getBounds(InferenceBound.LOWER)) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   474
                for (Type anotherLowerBound : from.getBounds(InferenceBound.LOWER)) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   475
                    if (aLowerBound != anotherLowerBound &&
26663
f2d8845a9bb2 8055963: Inference failure with nested invocation
mcimadamore
parents: 26267
diff changeset
   476
                            !inferenceContext.free(aLowerBound) &&
f2d8845a9bb2 8055963: Inference failure with nested invocation
mcimadamore
parents: 26267
diff changeset
   477
                            !inferenceContext.free(anotherLowerBound) &&
f2d8845a9bb2 8055963: Inference failure with nested invocation
mcimadamore
parents: 26267
diff changeset
   478
                            commonSuperWithDiffParameterization(aLowerBound, anotherLowerBound)) {
38538
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   479
                        return true;
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   480
                    }
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   481
                }
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   482
            }
10
06bc494ca11e Initial load
duke
parents:
diff changeset
   483
        }
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   484
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   485
        /* T is a parameterization of a generic class or interface, G,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   486
         * and B2 contains a bound of one of the forms alpha = S or S <: alpha,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   487
         * where there exists no type of the form G<...> that is a
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   488
         * supertype of S, but the raw type G is a supertype of S
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   489
         */
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   490
        if (to.isParameterized()) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   491
            for (Type t : from.getBounds(InferenceBound.EQ, InferenceBound.LOWER)) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   492
                Type sup = types.asSuper(t, to.tsym);
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   493
                if (sup != null && sup.isRaw()) {
38538
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   494
                    return true;
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   495
                }
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   496
            }
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   497
        }
38538
8bdc63ff6961 8157149: Inference: weird propagation of thrown inference variables
mcimadamore
parents: 38516
diff changeset
   498
        return false;
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   499
    }
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   500
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   501
    private boolean commonSuperWithDiffParameterization(Type t, Type s) {
24795
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
   502
        for (Pair<Type, Type> supers : getParameterizedSupers(t, s)) {
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
   503
            if (!types.isSameType(supers.fst, supers.snd)) return true;
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
   504
        }
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
   505
        return false;
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   506
    }
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   507
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   508
    private Type generateReferenceToTargetConstraint(JCTree tree, UndetVar from,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   509
            Type to, Attr.ResultInfo resultInfo,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   510
            InferenceContext inferenceContext) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   511
        inferenceContext.solve(List.of(from.qtype), new Warner());
25279
a665d5cbb8c3 8044546: Crash on faulty reduce/lambda
vromero
parents: 24795
diff changeset
   512
        inferenceContext.notifyChange();
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   513
        Type capturedType = resultInfo.checkContext.inferenceContext()
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   514
                .cachedCapture(tree, from.getInst(), false);
24226
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   515
        if (types.isConvertible(capturedType,
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   516
                resultInfo.checkContext.inferenceContext().asUndetVar(to))) {
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   517
            //effectively skip additional return-type constraint generation (compatibility)
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   518
            return syms.objectType;
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   519
        }
08b586e22328 8030741: Inference: implement eager resolution of return types, consistent with JDK-8028800
vromero
parents: 24063
diff changeset
   520
        return to;
18910
c967bfda9283 8016175: Add bottom-up type-checking support for unambiguous method references
mcimadamore
parents: 18909
diff changeset
   521
    }
12468
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 12335
diff changeset
   522
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   523
    /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   524
      * Infer cyclic inference variables as described in 15.12.2.8.
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   525
      */
31937
ad43a6639c4a 8132215: class InferenceContext should live in a separate file
vromero
parents: 30014
diff changeset
   526
    void instantiateAsUninferredVars(List<Type> vars, InferenceContext inferenceContext) {
20249
93f8eae31092 6386236: Please rename com.sun.tools.javac.util.ListBuffer.lb()
alundblad
parents: 19914
diff changeset
   527
        ListBuffer<Type> todo = new ListBuffer<>();
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   528
        //step 1 - create fresh tvars
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   529
        for (Type t : vars) {
23132
00a059740d87 8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents: 23124
diff changeset
   530
            UndetVar uv = (UndetVar)inferenceContext.asUndetVar(t);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   531
            List<Type> upperBounds = uv.getBounds(InferenceBound.UPPER);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   532
            if (Type.containsAny(upperBounds, vars)) {
16967
79d444669f3f 7015104: use new subtype of TypeSymbol for type parameters
jfranck
parents: 16805
diff changeset
   533
                TypeSymbol fresh_tvar = new TypeVariableSymbol(Flags.SYNTHETIC, uv.qtype.tsym.name, null, uv.qtype.tsym.owner);
29147
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27391
diff changeset
   534
                fresh_tvar.type = new TypeVar(fresh_tvar, types.makeIntersectionType(uv.getBounds(InferenceBound.UPPER)), null);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   535
                todo.append(uv);
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   536
                uv.setInst(fresh_tvar.type);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   537
            } else if (upperBounds.nonEmpty()) {
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   538
                uv.setInst(types.glb(upperBounds));
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   539
            } else {
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   540
                uv.setInst(syms.objectType);
12468
1100643c0209 7154127: Inference cleanup: remove bound check analysis from visitors in Types.java
mcimadamore
parents: 12335
diff changeset
   541
            }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   542
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   543
        //step 2 - replace fresh tvars in their bounds
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   544
        List<Type> formals = vars;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   545
        for (Type t : todo) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   546
            UndetVar uv = (UndetVar)t;
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   547
            TypeVar ct = (TypeVar)uv.getInst();
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   548
            ct.bound = types.glb(inferenceContext.asInstTypes(types.getBounds(ct)));
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   549
            if (ct.bound.isErroneous()) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   550
                //report inference error if glb fails
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   551
                reportBoundError(uv, InferenceBound.UPPER);
15374
fb8f6acf09cc 8005244: Implement overload resolution as per latest spec EDR
mcimadamore
parents: 15037
diff changeset
   552
            }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   553
            formals = formals.tail;
14058
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   554
        }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   555
    }
c7ec7facdd20 7177385: Add attribution support for lambda expressions
mcimadamore
parents: 14057
diff changeset
   556
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   557
    /**
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   558
     * Compute a synthetic method type corresponding to the requested polymorphic
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   559
     * method signature. The target return type is computed from the immediately
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   560
     * enclosing scope surrounding the polymorphic-signature call.
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   561
     */
12335
4725d88691dd 7133185: Update 292 overload resolution logic to match JLS
mcimadamore
parents: 12334
diff changeset
   562
    Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   563
                                            MethodSymbol spMethod,  // sig. poly. method or null if none
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14048
diff changeset
   564
                                            Resolve.MethodResolutionContext resolveContext,
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   565
                                            List<Type> argtypes) {
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   566
        final Type restype;
8036
17b976649c61 6992698: JSR 292: remove support for transient syntax in polymorphic signature calls
mcimadamore
parents: 7681
diff changeset
   567
36995
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   568
        if (spMethod == null || types.isSameType(spMethod.getReturnType(), syms.objectType, true)) {
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   569
            // The return type of the polymorphic signature is polymorphic,
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   570
            // and is computed from the enclosing tree E, as follows:
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   571
            // if E is a cast, then use the target type of the cast expression
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   572
            // as a return type; if E is an expression statement, the return
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   573
            // type is 'void'; otherwise
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   574
            // the return type is simply 'Object'. A correctness check ensures
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   575
            // that env.next refers to the lexically enclosing environment in
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   576
            // which the polymorphic signature call environment is nested.
6934
258e5f06880f 6991980: polymorphic signature calls don't share the same CP entries
mcimadamore
parents: 6710
diff changeset
   577
36995
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   578
            switch (env.next.tree.getTag()) {
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   579
                case TYPECAST:
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   580
                    JCTypeCast castTree = (JCTypeCast)env.next.tree;
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   581
                    restype = (TreeInfo.skipParens(castTree.expr) == env.tree) ?
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   582
                              castTree.clazz.type :
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   583
                              syms.objectType;
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   584
                    break;
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   585
                case EXEC:
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   586
                    JCTree.JCExpressionStatement execTree =
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   587
                            (JCTree.JCExpressionStatement)env.next.tree;
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   588
                    restype = (TreeInfo.skipParens(execTree.expr) == env.tree) ?
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   589
                              syms.voidType :
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   590
                              syms.objectType;
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   591
                    break;
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   592
                default:
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   593
                    restype = syms.objectType;
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   594
            }
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   595
        } else {
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   596
            // The return type of the polymorphic signature is fixed
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   597
            // (not polymorphic)
e19153419efd 8149644: Integrate VarHandles
psandoz
parents: 36157
diff changeset
   598
            restype = spMethod.getReturnType();
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   599
        }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   600
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   601
        List<Type> paramtypes = argtypes.map(new ImplicitArgType(spMethod, resolveContext.step));
6592
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   602
        List<Type> exType = spMethod != null ?
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   603
            spMethod.getThrownTypes() :
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   604
            List.of(syms.throwableType); // make it throw all exceptions
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   605
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   606
        MethodType mtype = new MethodType(paramtypes,
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   607
                                          restype,
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   608
                                          exType,
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   609
                                          syms.methodClass);
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   610
        return mtype;
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   611
    }
dc56420a69bc 6979327: method handle invocation should use casts instead of type parameters to specify return type
mcimadamore
parents: 6348
diff changeset
   612
    //where
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14048
diff changeset
   613
        class ImplicitArgType extends DeferredAttr.DeferredTypeMap {
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14048
diff changeset
   614
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14048
diff changeset
   615
            public ImplicitArgType(Symbol msym, Resolve.MethodResolutionPhase phase) {
25279
a665d5cbb8c3 8044546: Crash on faulty reduce/lambda
vromero
parents: 24795
diff changeset
   616
                (rs.deferredAttr).super(AttrMode.SPECULATIVE, msym, phase);
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14048
diff changeset
   617
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14048
diff changeset
   618
29554
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   619
            @Override
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   620
            public Type visitClassType(ClassType t, Void aVoid) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   621
                return types.erasure(t);
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   622
            }
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   623
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   624
            @Override
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   625
            public Type visitType(Type t, Void _unused) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   626
                if (t.hasTag(DEFERRED)) {
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   627
                    return visit(super.visitType(t, null));
6d7957bd6866 8074100: Turn Type.Mapping into a true visitor
mcimadamore
parents: 29147
diff changeset
   628
                } else if (t.hasTag(BOT))
14057
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14048
diff changeset
   629
                    // nulls type as the marker type Null (which has no instances)
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14048
diff changeset
   630
                    // infer as java.lang.Void for now
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14048
diff changeset
   631
                    t = types.boxedClass(syms.voidType).type;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14048
diff changeset
   632
                return t;
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14048
diff changeset
   633
            }
b4b0377b8dba 7177387: Add target-typing support in method context
mcimadamore
parents: 14048
diff changeset
   634
        }
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   635
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   636
    TypeMapping<Void> fromTypeVarFun = new TypeMapping<Void>() {
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   637
        @Override
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   638
        public Type visitTypeVar(TypeVar tv, Void aVoid) {
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   639
            return new UndetVar(tv, incorporationEngine(), types);
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   640
        }
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   641
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   642
        @Override
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   643
        public Type visitCapturedType(CapturedType t, Void aVoid) {
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   644
            return new CapturedUndetVar(t, incorporationEngine(), types);
33906
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   645
        }
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   646
    };
91b6bee06dc1 8046685: Uncompilable large expressions involving generics.
mcimadamore
parents: 33708
diff changeset
   647
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
   648
    /**
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   649
      * This method is used to infer a suitable target SAM in case the original
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   650
      * SAM type contains one or more wildcards. An inference process is applied
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   651
      * so that wildcard bounds, as well as explicit lambda/method ref parameters
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   652
      * (where applicable) are used to constraint the solution.
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   653
      */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   654
    public Type instantiateFunctionalInterface(DiagnosticPosition pos, Type funcInterface,
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   655
            List<Type> paramTypes, Check.CheckContext checkContext) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   656
        if (types.capture(funcInterface) == funcInterface) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   657
            //if capture doesn't change the type then return the target unchanged
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   658
            //(this means the target contains no wildcards!)
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   659
            return funcInterface;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   660
        } else {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   661
            Type formalInterface = funcInterface.tsym.type;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   662
            InferenceContext funcInterfaceContext =
31937
ad43a6639c4a 8132215: class InferenceContext should live in a separate file
vromero
parents: 30014
diff changeset
   663
                    new InferenceContext(this, funcInterface.tsym.type.getTypeArguments());
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   664
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   665
            Assert.check(paramTypes != null);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   666
            //get constraints from explicit params (this is done by
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   667
            //checking that explicit param types are equal to the ones
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   668
            //in the functional interface descriptors)
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   669
            List<Type> descParameterTypes = types.findDescriptorType(formalInterface).getParameterTypes();
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   670
            if (descParameterTypes.size() != paramTypes.size()) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   671
                checkContext.report(pos, diags.fragment("incompatible.arg.types.in.lambda"));
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   672
                return types.createErrorType(funcInterface);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   673
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   674
            for (Type p : descParameterTypes) {
23132
00a059740d87 8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents: 23124
diff changeset
   675
                if (!types.isSameType(funcInterfaceContext.asUndetVar(p), paramTypes.head)) {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   676
                    checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface));
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   677
                    return types.createErrorType(funcInterface);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   678
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   679
                paramTypes = paramTypes.tail;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   680
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   681
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   682
            List<Type> actualTypeargs = funcInterface.getTypeArguments();
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   683
            for (Type t : funcInterfaceContext.undetvars) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   684
                UndetVar uv = (UndetVar)t;
39589
0cbaed77814c 8048543: JLS8 18.5.3: inference variable seems to be instantiated unexpectedly
vromero
parents: 38832
diff changeset
   685
                Optional<Type> inst = uv.getBounds(InferenceBound.EQ).stream()
0cbaed77814c 8048543: JLS8 18.5.3: inference variable seems to be instantiated unexpectedly
vromero
parents: 38832
diff changeset
   686
                        .filter(b -> !b.containsAny(formalInterface.getTypeArguments())).findFirst();
0cbaed77814c 8048543: JLS8 18.5.3: inference variable seems to be instantiated unexpectedly
vromero
parents: 38832
diff changeset
   687
                uv.setInst(inst.orElse(actualTypeargs.head));
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   688
                actualTypeargs = actualTypeargs.tail;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   689
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   690
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   691
            Type owntype = funcInterfaceContext.asInstType(formalInterface);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   692
            if (!chk.checkValidGenericType(owntype)) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   693
                //if the inferred functional interface type is not well-formed,
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   694
                //or if it's not a subtype of the original target, issue an error
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   695
                checkContext.report(pos, diags.fragment("no.suitable.functional.intf.inst", funcInterface));
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   696
            }
25279
a665d5cbb8c3 8044546: Crash on faulty reduce/lambda
vromero
parents: 24795
diff changeset
   697
            //propagate constraints as per JLS 18.2.1
a665d5cbb8c3 8044546: Crash on faulty reduce/lambda
vromero
parents: 24795
diff changeset
   698
            checkContext.compatible(owntype, funcInterface, types.noWarnings);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   699
            return owntype;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   700
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   701
    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   702
    // </editor-fold>
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   703
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   704
    // <editor-fold defaultstate="collapsed" desc="Incorporation">
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   705
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   706
    /**
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   707
     * This class is the root of all incorporation actions.
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   708
     */
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   709
    public abstract class IncorporationAction {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   710
        UndetVar uv;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   711
        Type t;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   712
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   713
        IncorporationAction(UndetVar uv, Type t) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   714
            this.uv = uv;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   715
            this.t = t;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   716
        }
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   717
37003
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   718
        public abstract IncorporationAction dup(UndetVar that);
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   719
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   720
        /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   721
         * Incorporation action entry-point. Subclasses should define the logic associated with
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   722
         * this incorporation action.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   723
         */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   724
        abstract void apply(InferenceContext ic, Warner warn);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   725
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   726
        /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   727
         * Helper function: perform subtyping through incorporation cache.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   728
         */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   729
        boolean isSubtype(Type s, Type t, Warner warn) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   730
            return doIncorporationOp(IncorporationBinaryOpKind.IS_SUBTYPE, s, t, warn);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   731
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   732
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   733
        /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   734
         * Helper function: perform type-equivalence through incorporation cache.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   735
         */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   736
        boolean isSameType(Type s, Type t) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   737
            return doIncorporationOp(IncorporationBinaryOpKind.IS_SAME_TYPE, s, t, null);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   738
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   739
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   740
        @Override
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   741
        public String toString() {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   742
            return String.format("%s[undet=%s,t=%s]", getClass().getSimpleName(), uv.qtype, t);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   743
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   744
    }
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   745
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   746
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   747
     * Bound-check incorporation action. A newly added bound is checked against existing bounds,
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   748
     * to verify its compatibility; each bound is checked using either subtyping or type equivalence.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   749
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   750
    class CheckBounds extends IncorporationAction {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   751
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   752
        InferenceBound from;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   753
        BiFunction<InferenceContext, Type, Type> typeFunc;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   754
        BiPredicate<InferenceContext, Type> optFilter;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   755
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   756
        CheckBounds(UndetVar uv, Type t, InferenceBound from) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   757
            this(uv, t, InferenceContext::asUndetVar, null, from);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   758
        }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   759
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   760
        CheckBounds(UndetVar uv, Type t, BiFunction<InferenceContext, Type, Type> typeFunc,
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   761
                    BiPredicate<InferenceContext, Type> typeFilter, InferenceBound from) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   762
            super(uv, t);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   763
            this.from = from;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   764
            this.typeFunc = typeFunc;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   765
            this.optFilter = typeFilter;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   766
        }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   767
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   768
        @Override
37003
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   769
        public IncorporationAction dup(UndetVar that) {
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   770
            return new CheckBounds(that, t, typeFunc, optFilter, from);
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   771
        }
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   772
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   773
        @Override
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   774
        void apply(InferenceContext inferenceContext, Warner warn) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   775
            t = typeFunc.apply(inferenceContext, t);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   776
            if (optFilter != null && optFilter.test(inferenceContext, t)) return;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   777
            for (InferenceBound to : boundsToCheck()) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   778
                for (Type b : uv.getBounds(to)) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   779
                    b = typeFunc.apply(inferenceContext, b);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   780
                    if (optFilter != null && optFilter.test(inferenceContext, b)) continue;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   781
                    boolean success = checkBound(t, b, from, to, warn);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   782
                    if (!success) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   783
                        report(from, to);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   784
                    }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   785
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   786
            }
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
   787
        }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
   788
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   789
        /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   790
         * The list of bound kinds to be checked.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   791
         */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   792
        EnumSet<InferenceBound> boundsToCheck() {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   793
            return (from == InferenceBound.EQ) ?
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   794
                            EnumSet.allOf(InferenceBound.class) :
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   795
                            EnumSet.complementOf(EnumSet.of(from));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   796
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   797
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   798
        /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   799
         * Is source type 's' compatible with target type 't' given source and target bound kinds?
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   800
         */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   801
        boolean checkBound(Type s, Type t, InferenceBound ib_s, InferenceBound ib_t, Warner warn) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   802
            if (ib_s.lessThan(ib_t)) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   803
                return isSubtype(s, t, warn);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   804
            } else if (ib_t.lessThan(ib_s)) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   805
                return isSubtype(t, s, warn);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   806
            } else {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   807
                return isSameType(s, t);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   808
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   809
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   810
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   811
        /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   812
         * Report a bound check error.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   813
         */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   814
        void report(InferenceBound from, InferenceBound to) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   815
            //this is a workaround to preserve compatibility with existing messages
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   816
            if (from == to) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   817
                reportBoundError(uv, from);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   818
            } else if (from == InferenceBound.LOWER || to == InferenceBound.EQ) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   819
                reportBoundError(uv, to, from);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   820
            } else {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   821
                reportBoundError(uv, from, to);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   822
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   823
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   824
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   825
        @Override
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   826
        public String toString() {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   827
            return String.format("%s[undet=%s,t=%s,bound=%s]", getClass().getSimpleName(), uv.qtype, t, from);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   828
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   829
    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   830
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   831
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   832
     * Custom check executed by the legacy incorporation engine. Newly added bounds are checked
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   833
     * against existing eq bounds.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   834
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   835
    class EqCheckLegacy extends CheckBounds {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   836
        EqCheckLegacy(UndetVar uv, Type t, InferenceBound from) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   837
            super(uv, t, InferenceContext::asInstType, InferenceContext::free, from);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   838
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   839
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   840
        @Override
37003
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   841
        public IncorporationAction dup(UndetVar that) {
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   842
            return new EqCheckLegacy(that, t, from);
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   843
        }
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   844
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   845
        @Override
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   846
        EnumSet<InferenceBound> boundsToCheck() {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   847
            return (from == InferenceBound.EQ) ?
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   848
                            EnumSet.allOf(InferenceBound.class) :
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   849
                            EnumSet.of(InferenceBound.EQ);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   850
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   851
    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   852
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   853
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   854
     * Check that the inferred type conforms to all bounds.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   855
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   856
    class CheckInst extends CheckBounds {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   857
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   858
        EnumSet<InferenceBound> to;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   859
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   860
        CheckInst(UndetVar uv, InferenceBound ib, InferenceBound... rest) {
37003
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   861
            this(uv, EnumSet.of(ib, rest));
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   862
        }
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   863
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   864
        CheckInst(UndetVar uv, EnumSet<InferenceBound> to) {
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   865
            super(uv, uv.getInst(), InferenceBound.EQ);
37003
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   866
            this.to = to;
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   867
        }
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   868
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   869
        @Override
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   870
        public IncorporationAction dup(UndetVar that) {
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   871
            return new CheckInst(that, to);
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   872
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   873
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   874
        @Override
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   875
        EnumSet<InferenceBound> boundsToCheck() {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   876
            return to;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   877
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   878
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   879
        @Override
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   880
        void report(InferenceBound from, InferenceBound to) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   881
            reportInstError(uv, to);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   882
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   883
    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   884
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   885
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   886
     * Replace undetvars in bounds and check that the inferred type conforms to all bounds.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   887
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   888
    class SubstBounds extends CheckInst {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   889
        SubstBounds(UndetVar uv) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   890
            super(uv, InferenceBound.LOWER, InferenceBound.EQ, InferenceBound.UPPER);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   891
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   892
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   893
        @Override
37003
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   894
        public IncorporationAction dup(UndetVar that) {
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   895
            return new SubstBounds(that);
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   896
        }
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   897
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   898
        @Override
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   899
        void apply(InferenceContext inferenceContext, Warner warn) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   900
            for (Type undet : inferenceContext.undetvars) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   901
                //we could filter out variables not mentioning uv2...
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   902
                UndetVar uv2 = (UndetVar)undet;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   903
                uv2.substBounds(List.of(uv.qtype), List.of(uv.getInst()), types);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   904
                checkCompatibleUpperBounds(uv2, inferenceContext);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   905
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   906
            super.apply(inferenceContext, warn);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   907
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   908
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   909
        /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   910
         * Make sure that the upper bounds we got so far lead to a solvable inference
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   911
         * variable by making sure that a glb exists.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   912
         */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   913
        void checkCompatibleUpperBounds(UndetVar uv, InferenceContext inferenceContext) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   914
            List<Type> hibounds =
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   915
                    Type.filter(uv.getBounds(InferenceBound.UPPER), new BoundFilter(inferenceContext));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   916
            final Type hb;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   917
            if (hibounds.isEmpty())
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   918
                hb = syms.objectType;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   919
            else if (hibounds.tail.isEmpty())
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   920
                hb = hibounds.head;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   921
            else
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   922
                hb = types.glb(hibounds);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   923
            if (hb == null || hb.isErroneous())
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   924
                reportBoundError(uv, InferenceBound.UPPER);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   925
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   926
    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   927
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   928
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   929
     * Perform pairwise comparison between common generic supertypes of two upper bounds.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   930
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   931
    class CheckUpperBounds extends IncorporationAction {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   932
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   933
        public CheckUpperBounds(UndetVar uv, Type t) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   934
            super(uv, t);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   935
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   936
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   937
        @Override
37003
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   938
        public IncorporationAction dup(UndetVar that) {
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   939
            return new CheckUpperBounds(that, t);
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   940
        }
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   941
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   942
        @Override
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   943
        void apply(InferenceContext inferenceContext, Warner warn) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   944
            List<Type> boundList = uv.getBounds(InferenceBound.UPPER).stream()
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   945
                    .collect(types.closureCollector(true, types::isSameType));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   946
            for (Type b2 : boundList) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   947
                if (t == b2) continue;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   948
                    /* This wildcard check is temporary workaround. This code may need to be
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   949
                     * revisited once spec bug JDK-7034922 is fixed.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   950
                     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   951
                if (t != b2 && !t.hasTag(WILDCARD) && !b2.hasTag(WILDCARD)) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   952
                    for (Pair<Type, Type> commonSupers : getParameterizedSupers(t, b2)) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   953
                        List<Type> allParamsSuperBound1 = commonSupers.fst.allparams();
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   954
                        List<Type> allParamsSuperBound2 = commonSupers.snd.allparams();
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   955
                        while (allParamsSuperBound1.nonEmpty() && allParamsSuperBound2.nonEmpty()) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   956
                            //traverse the list of all params comparing them
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   957
                            if (!allParamsSuperBound1.head.hasTag(WILDCARD) &&
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   958
                                    !allParamsSuperBound2.head.hasTag(WILDCARD)) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   959
                                if (!isSameType(inferenceContext.asUndetVar(allParamsSuperBound1.head),
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   960
                                        inferenceContext.asUndetVar(allParamsSuperBound2.head))) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   961
                                    reportBoundError(uv, InferenceBound.UPPER);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   962
                                }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   963
                            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   964
                            allParamsSuperBound1 = allParamsSuperBound1.tail;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   965
                            allParamsSuperBound2 = allParamsSuperBound2.tail;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   966
                        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   967
                        Assert.check(allParamsSuperBound1.isEmpty() && allParamsSuperBound2.isEmpty());
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   968
                    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   969
                }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   970
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   971
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   972
    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   973
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   974
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   975
     * Perform propagation of bounds. Given a constraint of the kind {@code alpha <: T}, three
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   976
     * kind of propagation occur:
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   977
     *
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   978
     * <li>T is copied into all matching bounds (i.e. lower/eq bounds) B of alpha such that B=beta (forward propagation)</li>
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   979
     * <li>if T=beta, matching bounds (i.e. upper bounds) of beta are copied into alpha (backwards propagation)</li>
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   980
     * <li>if T=beta, sets a symmetric bound on beta (i.e. beta :> alpha) (symmetric propagation) </li>
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   981
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   982
    class PropagateBounds extends IncorporationAction {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   983
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   984
        InferenceBound ib;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   985
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   986
        public PropagateBounds(UndetVar uv, Type t, InferenceBound ib) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   987
            super(uv, t);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   988
            this.ib = ib;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   989
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   990
37003
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   991
        @Override
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   992
        public IncorporationAction dup(UndetVar that) {
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   993
            return new PropagateBounds(that, t, ib);
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   994
        }
12ece14d32e0 8152832: Type inference regression in javac
mcimadamore
parents: 36995
diff changeset
   995
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   996
        void apply(InferenceContext inferenceContext, Warner warner) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   997
            Type undetT = inferenceContext.asUndetVar(t);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   998
            if (undetT.hasTag(UNDETVAR) && !((UndetVar)undetT).isCaptured()) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
   999
                UndetVar uv2 = (UndetVar)undetT;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1000
                //symmetric propagation
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1001
                uv2.addBound(ib.complement(), uv, types);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1002
                //backwards propagation
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1003
                for (InferenceBound ib2 : backwards()) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1004
                    for (Type b : uv2.getBounds(ib2)) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1005
                        uv.addBound(ib2, b, types);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1006
                    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1007
                }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1008
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1009
            //forward propagation
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1010
            for (InferenceBound ib2 : forward()) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1011
                for (Type l : uv.getBounds(ib2)) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1012
                    Type undet = inferenceContext.asUndetVar(l);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1013
                    if (undet.hasTag(TypeTag.UNDETVAR) && !((UndetVar)undet).isCaptured()) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1014
                        UndetVar uv2 = (UndetVar)undet;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1015
                        uv2.addBound(ib, inferenceContext.asInstType(t), types);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1016
                    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1017
                }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1018
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1019
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1020
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1021
        EnumSet<InferenceBound> forward() {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1022
            return (ib == InferenceBound.EQ) ?
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1023
                    EnumSet.of(InferenceBound.EQ) : EnumSet.complementOf(EnumSet.of(ib));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1024
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1025
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1026
        EnumSet<InferenceBound> backwards() {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1027
            return (ib == InferenceBound.EQ) ?
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1028
                    EnumSet.allOf(InferenceBound.class) : EnumSet.of(ib);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1029
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1030
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1031
        @Override
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1032
        public String toString() {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1033
            return String.format("%s[undet=%s,t=%s,bound=%s]", getClass().getSimpleName(), uv.qtype, t, ib);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1034
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1035
    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1036
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1037
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1038
     * This class models an incorporation engine. The engine is responsible for listening to
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1039
     * changes in inference variables and register incorporation actions accordingly.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1040
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1041
    abstract class AbstractIncorporationEngine implements UndetVarListener {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1042
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1043
        @Override
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1044
        public void varInstantiated(UndetVar uv) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1045
            uv.incorporationActions.addFirst(new SubstBounds(uv));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1046
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1047
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1048
        @Override
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1049
        public void varBoundChanged(UndetVar uv, InferenceBound ib, Type bound, boolean update) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1050
            if (uv.isCaptured()) return;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1051
            uv.incorporationActions.addAll(getIncorporationActions(uv, ib, bound, update));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1052
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1053
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1054
        abstract List<IncorporationAction> getIncorporationActions(UndetVar uv, InferenceBound ib, Type t, boolean update);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1055
    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1056
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1057
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1058
     * A legacy incorporation engine. Used for source <= 7.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1059
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1060
    AbstractIncorporationEngine legacyEngine = new AbstractIncorporationEngine() {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1061
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1062
        List<IncorporationAction> getIncorporationActions(UndetVar uv, InferenceBound ib, Type t, boolean update) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1063
            ListBuffer<IncorporationAction> actions = new ListBuffer<>();
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1064
            Type inst = uv.getInst();
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1065
            if (inst != null) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1066
                actions.add(new CheckInst(uv, ib));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1067
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1068
            actions.add(new EqCheckLegacy(uv, t, ib));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1069
            return actions.toList();
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1070
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1071
    };
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1072
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1073
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1074
     * The standard incorporation engine. Used for source >= 8.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1075
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1076
    AbstractIncorporationEngine graphEngine = new AbstractIncorporationEngine() {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1077
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1078
        @Override
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1079
        List<IncorporationAction> getIncorporationActions(UndetVar uv, InferenceBound ib, Type t, boolean update) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1080
            ListBuffer<IncorporationAction> actions = new ListBuffer<>();
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1081
            Type inst = uv.getInst();
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1082
            if (inst != null) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1083
                actions.add(new CheckInst(uv, ib));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1084
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1085
            actions.add(new CheckBounds(uv, t, ib));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1086
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1087
            if (update) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1088
                return actions.toList();
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1089
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1090
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1091
            if (ib == InferenceBound.UPPER) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1092
                actions.add(new CheckUpperBounds(uv, t));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1093
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1094
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1095
            actions.add(new PropagateBounds(uv, t, ib));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1096
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1097
            return actions.toList();
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1098
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1099
    };
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1100
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1101
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1102
     * Get the incorporation engine to be used in this compilation.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1103
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1104
    AbstractIncorporationEngine incorporationEngine() {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1105
        return allowGraphInference ? graphEngine : legacyEngine;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1106
    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1107
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1108
    /** max number of incorporation rounds. */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1109
    static final int MAX_INCORPORATION_STEPS = 10000;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1110
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1111
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1112
     * Check bounds and perform incorporation.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1113
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1114
    void doIncorporation(InferenceContext inferenceContext, Warner warn) throws InferenceException {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1115
        try {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1116
            boolean progress = true;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1117
            int round = 0;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1118
            while (progress && round < MAX_INCORPORATION_STEPS) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1119
                progress = false;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1120
                for (Type t : inferenceContext.undetvars) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1121
                    UndetVar uv = (UndetVar)t;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1122
                    if (!uv.incorporationActions.isEmpty()) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1123
                        progress = true;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1124
                        uv.incorporationActions.removeFirst().apply(inferenceContext, warn);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1125
                    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1126
                }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1127
                round++;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1128
            }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1129
        } finally {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1130
            incorporationCache.clear();
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1131
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1132
    }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1133
24795
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1134
    /* If for two types t and s there is a least upper bound that contains
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1135
     * parameterized types G1, G2 ... Gn, then there exists supertypes of 't' of the form
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1136
     * G1<T1, ..., Tn>, G2<T1, ..., Tn>, ... Gn<T1, ..., Tn> and supertypes of 's' of the form
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1137
     * G1<S1, ..., Sn>, G2<S1, ..., Sn>, ... Gn<S1, ..., Sn> which will be returned by this method.
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1138
     * If no such common supertypes exists then an empty list is returned.
24063
3e3c18700277 8029002: javac should take multiple upper bounds into account in incorporation
vromero
parents: 23395
diff changeset
  1139
     *
3e3c18700277 8029002: javac should take multiple upper bounds into account in incorporation
vromero
parents: 23395
diff changeset
  1140
     * As an example for the following input:
3e3c18700277 8029002: javac should take multiple upper bounds into account in incorporation
vromero
parents: 23395
diff changeset
  1141
     *
3e3c18700277 8029002: javac should take multiple upper bounds into account in incorporation
vromero
parents: 23395
diff changeset
  1142
     * t = java.util.ArrayList<java.lang.String>
3e3c18700277 8029002: javac should take multiple upper bounds into account in incorporation
vromero
parents: 23395
diff changeset
  1143
     * s = java.util.List<T>
3e3c18700277 8029002: javac should take multiple upper bounds into account in incorporation
vromero
parents: 23395
diff changeset
  1144
     *
24795
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1145
     * we get this ouput (singleton list):
24063
3e3c18700277 8029002: javac should take multiple upper bounds into account in incorporation
vromero
parents: 23395
diff changeset
  1146
     *
24795
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1147
     * [Pair[java.util.List<java.lang.String>,java.util.List<T>]]
24063
3e3c18700277 8029002: javac should take multiple upper bounds into account in incorporation
vromero
parents: 23395
diff changeset
  1148
     */
24795
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1149
    private List<Pair<Type, Type>> getParameterizedSupers(Type t, Type s) {
24063
3e3c18700277 8029002: javac should take multiple upper bounds into account in incorporation
vromero
parents: 23395
diff changeset
  1150
        Type lubResult = types.lub(t, s);
24795
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1151
        if (lubResult == syms.errType || lubResult == syms.botType) {
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1152
            return List.nil();
24063
3e3c18700277 8029002: javac should take multiple upper bounds into account in incorporation
vromero
parents: 23395
diff changeset
  1153
        }
29147
4cba0458106b 8071291: Compiler crashes trying to cast UnionType to IntersectionClassType
mcimadamore
parents: 27391
diff changeset
  1154
        List<Type> supertypesToCheck = lubResult.isIntersection() ?
24795
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1155
                ((IntersectionClassType)lubResult).getComponents() :
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1156
                List.of(lubResult);
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1157
        ListBuffer<Pair<Type, Type>> commonSupertypes = new ListBuffer<>();
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1158
        for (Type sup : supertypesToCheck) {
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1159
            if (sup.isParameterized()) {
27391
17f7b6c40c6d 8062977: Inference: NullPointerException during bound incorporation
mcimadamore
parents: 27228
diff changeset
  1160
                Type asSuperOfT = asSuper(t, sup);
17f7b6c40c6d 8062977: Inference: NullPointerException during bound incorporation
mcimadamore
parents: 27228
diff changeset
  1161
                Type asSuperOfS = asSuper(s, sup);
24795
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1162
                commonSupertypes.add(new Pair<>(asSuperOfT, asSuperOfS));
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1163
            }
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1164
        }
ff348aab3b54 8043893: Inference doesn't report error on incompatible upper bounds
mcimadamore
parents: 24396
diff changeset
  1165
        return commonSupertypes.toList();
24063
3e3c18700277 8029002: javac should take multiple upper bounds into account in incorporation
vromero
parents: 23395
diff changeset
  1166
    }
27391
17f7b6c40c6d 8062977: Inference: NullPointerException during bound incorporation
mcimadamore
parents: 27228
diff changeset
  1167
    //where
17f7b6c40c6d 8062977: Inference: NullPointerException during bound incorporation
mcimadamore
parents: 27228
diff changeset
  1168
        private Type asSuper(Type t, Type sup) {
17f7b6c40c6d 8062977: Inference: NullPointerException during bound incorporation
mcimadamore
parents: 27228
diff changeset
  1169
            return (sup.hasTag(ARRAY)) ?
17f7b6c40c6d 8062977: Inference: NullPointerException during bound incorporation
mcimadamore
parents: 27228
diff changeset
  1170
                    new ArrayType(asSuper(types.elemtype(t), types.elemtype(sup)), syms.arrayClass) :
17f7b6c40c6d 8062977: Inference: NullPointerException during bound incorporation
mcimadamore
parents: 27228
diff changeset
  1171
                    types.asSuper(t, sup.tsym);
17f7b6c40c6d 8062977: Inference: NullPointerException during bound incorporation
mcimadamore
parents: 27228
diff changeset
  1172
        }
24063
3e3c18700277 8029002: javac should take multiple upper bounds into account in incorporation
vromero
parents: 23395
diff changeset
  1173
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1174
    boolean doIncorporationOp(IncorporationBinaryOpKind opKind, Type op1, Type op2, Warner warn) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1175
            IncorporationBinaryOp newOp = new IncorporationBinaryOp(opKind, op1, op2);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1176
            Boolean res = incorporationCache.get(newOp);
18918
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1177
            if (res == null) {
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1178
                incorporationCache.put(newOp, res = newOp.apply(warn));
18918
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1179
            }
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1180
            return res;
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1181
        }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1182
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1183
    /**
18918
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1184
     * Three kinds of basic operation are supported as part of an incorporation step:
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1185
     * (i) subtype check, (ii) same type check and (iii) bound addition (either
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1186
     * upper/lower/eq bound).
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1187
     */
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1188
    enum IncorporationBinaryOpKind {
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1189
        IS_SUBTYPE() {
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1190
            @Override
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1191
            boolean apply(Type op1, Type op2, Warner warn, Types types) {
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1192
                return types.isSubtypeUnchecked(op1, op2, warn);
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1193
            }
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1194
        },
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1195
        IS_SAME_TYPE() {
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1196
            @Override
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1197
            boolean apply(Type op1, Type op2, Warner warn, Types types) {
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1198
                return types.isSameType(op1, op2);
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1199
            }
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1200
        };
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1201
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1202
        abstract boolean apply(Type op1, Type op2, Warner warn, Types types);
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1203
    }
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1204
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1205
    /**
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1206
     * This class encapsulates a basic incorporation operation; incorporation
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1207
     * operations takes two type operands and a kind. Each operation performed
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1208
     * during an incorporation round is stored in a cache, so that operations
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1209
     * are not executed unnecessarily (which would potentially lead to adding
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1210
     * same bounds over and over).
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1211
     */
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1212
    class IncorporationBinaryOp {
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1213
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1214
        IncorporationBinaryOpKind opKind;
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1215
        Type op1;
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1216
        Type op2;
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1217
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1218
        IncorporationBinaryOp(IncorporationBinaryOpKind opKind, Type op1, Type op2) {
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1219
            this.opKind = opKind;
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1220
            this.op1 = op1;
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1221
            this.op2 = op2;
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1222
        }
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1223
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1224
        @Override
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1225
        public boolean equals(Object o) {
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1226
            if (!(o instanceof IncorporationBinaryOp)) {
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1227
                return false;
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1228
            } else {
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1229
                IncorporationBinaryOp that = (IncorporationBinaryOp)o;
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1230
                return opKind == that.opKind &&
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1231
                        types.isSameType(op1, that.op1, true) &&
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1232
                        types.isSameType(op2, that.op2, true);
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1233
            }
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1234
        }
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1235
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1236
        @Override
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1237
        public int hashCode() {
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1238
            int result = opKind.hashCode();
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1239
            result *= 127;
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1240
            result += types.hashCode(op1);
18918
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1241
            result *= 127;
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1242
            result += types.hashCode(op2);
18918
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1243
            return result;
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1244
        }
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1245
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1246
        boolean apply(Warner warn) {
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1247
            return opKind.apply(op1, op2, warn, types);
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1248
        }
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1249
    }
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1250
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1251
    /** an incorporation cache keeps track of all executed incorporation-related operations */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
  1252
    Map<IncorporationBinaryOp, Boolean> incorporationCache = new HashMap<>();
18918
4e8769f15a95 8019942: Graph inference: avoid redundant computation during bound incorporation
mcimadamore
parents: 18916
diff changeset
  1253
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1254
    protected static class BoundFilter implements Filter<Type> {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1255
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1256
        InferenceContext inferenceContext;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1257
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1258
        public BoundFilter(InferenceContext inferenceContext) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1259
            this.inferenceContext = inferenceContext;
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1260
        }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1261
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1262
        @Override
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1263
        public boolean accepts(Type t) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1264
            return !t.isErroneous() && !inferenceContext.free(t) &&
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1265
                    !t.hasTag(BOT);
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1266
        }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1267
    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1268
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1269
    /**
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1270
     * Incorporation error: mismatch between inferred type and given bound.
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1271
     */
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1272
    void reportInstError(UndetVar uv, InferenceBound ib) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1273
        reportInferenceError(
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1274
                String.format("inferred.do.not.conform.to.%s.bounds", StringUtils.toLowerCase(ib.name())),
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1275
                uv.getInst(),
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1276
                uv.getBounds(ib));
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1277
    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1278
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1279
    /**
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1280
     * Incorporation error: mismatch between two (or more) bounds of same kind.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1281
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1282
    void reportBoundError(UndetVar uv, InferenceBound ib) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1283
        reportInferenceError(
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1284
                String.format("incompatible.%s.bounds", StringUtils.toLowerCase(ib.name())),
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1285
                uv.qtype,
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1286
                uv.getBounds(ib));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1287
    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1288
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1289
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1290
     * Incorporation error: mismatch between two (or more) bounds of different kinds.
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1291
     */
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1292
    void reportBoundError(UndetVar uv, InferenceBound ib1, InferenceBound ib2) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1293
        reportInferenceError(
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1294
                String.format("incompatible.%s.%s.bounds",
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1295
                        StringUtils.toLowerCase(ib1.name()),
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1296
                        StringUtils.toLowerCase(ib2.name())),
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1297
                uv.qtype,
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1298
                uv.getBounds(ib1),
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1299
                uv.getBounds(ib2));
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1300
    }
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1301
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1302
    /**
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1303
     * Helper method: reports an inference error.
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1304
     */
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1305
    void reportInferenceError(String key, Object... args) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1306
        throw inferenceException.setMessage(key, args);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1307
    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1308
    // </editor-fold>
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1309
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1310
    // <editor-fold defaultstate="collapsed" desc="Inference engine">
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1311
    /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1312
     * Graph inference strategy - act as an input to the inference solver; a strategy is
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1313
     * composed of two ingredients: (i) find a node to solve in the inference graph,
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1314
     * and (ii) tell th engine when we are done fixing inference variables
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1315
     */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1316
    interface GraphStrategy {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1317
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1318
        /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1319
         * A NodeNotFoundException is thrown whenever an inference strategy fails
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1320
         * to pick the next node to solve in the inference graph.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1321
         */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1322
        public static class NodeNotFoundException extends RuntimeException {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1323
            private static final long serialVersionUID = 0;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1324
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1325
            InferenceGraph graph;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1326
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1327
            public NodeNotFoundException(InferenceGraph graph) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1328
                this.graph = graph;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1329
            }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1330
        }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1331
        /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1332
         * Pick the next node (leaf) to solve in the graph
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1333
         */
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1334
        Node pickNode(InferenceGraph g) throws NodeNotFoundException;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1335
        /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1336
         * Is this the last step?
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1337
         */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1338
        boolean done();
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1339
    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1340
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1341
    /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1342
     * Simple solver strategy class that locates all leaves inside a graph
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1343
     * and picks the first leaf as the next node to solve
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1344
     */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1345
    abstract class LeafSolver implements GraphStrategy {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1346
        public Node pickNode(InferenceGraph g) {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1347
            if (g.nodes.isEmpty()) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1348
                //should not happen
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1349
                throw new NodeNotFoundException(g);
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
  1350
            }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1351
            return g.nodes.get(0);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1352
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1353
    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1354
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1355
    /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1356
     * This solver uses an heuristic to pick the best leaf - the heuristic
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1357
     * tries to select the node that has maximal probability to contain one
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1358
     * or more inference variables in a given list
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1359
     */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1360
    abstract class BestLeafSolver extends LeafSolver {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1361
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1362
        /** list of ivars of which at least one must be solved */
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1363
        List<Type> varsToSolve;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1364
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1365
        BestLeafSolver(List<Type> varsToSolve) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1366
            this.varsToSolve = varsToSolve;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1367
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1368
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1369
        /**
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1370
         * Computes a path that goes from a given node to the leafs in the graph.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1371
         * Typically this will start from a node containing a variable in
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1372
         * {@code varsToSolve}. For any given path, the cost is computed as the total
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1373
         * number of type-variables that should be eagerly instantiated across that path.
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1374
         */
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1375
        Pair<List<Node>, Integer> computeTreeToLeafs(Node n) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1376
            Pair<List<Node>, Integer> cachedPath = treeCache.get(n);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1377
            if (cachedPath == null) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1378
                //cache miss
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1379
                if (n.isLeaf()) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1380
                    //if leaf, stop
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
  1381
                    cachedPath = new Pair<>(List.of(n), n.data.length());
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1382
                } else {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1383
                    //if non-leaf, proceed recursively
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
  1384
                    Pair<List<Node>, Integer> path = new Pair<>(List.of(n), n.data.length());
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1385
                    for (Node n2 : n.getAllDependencies()) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1386
                        if (n2 == n) continue;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1387
                        Pair<List<Node>, Integer> subpath = computeTreeToLeafs(n2);
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
  1388
                        path = new Pair<>(path.fst.prependList(subpath.fst),
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
  1389
                                          path.snd + subpath.snd);
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1390
                    }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1391
                    cachedPath = path;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1392
                }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1393
                //save results in cache
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1394
                treeCache.put(n, cachedPath);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1395
            }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1396
            return cachedPath;
18916
d93bea397df9 8020149: Graph inference: wrong logic for picking best variable to solve
mcimadamore
parents: 18911
diff changeset
  1397
        }
d93bea397df9 8020149: Graph inference: wrong logic for picking best variable to solve
mcimadamore
parents: 18911
diff changeset
  1398
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1399
        /** cache used to avoid redundant computation of tree costs */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
  1400
        final Map<Node, Pair<List<Node>, Integer>> treeCache = new HashMap<>();
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1401
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1402
        /** constant value used to mark non-existent paths */
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
  1403
        final Pair<List<Node>, Integer> noPath = new Pair<>(null, Integer.MAX_VALUE);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1404
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1405
        /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1406
         * Pick the leaf that minimize cost
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1407
         */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1408
        @Override
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1409
        public Node pickNode(final InferenceGraph g) {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1410
            treeCache.clear(); //graph changes at every step - cache must be cleared
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1411
            Pair<List<Node>, Integer> bestPath = noPath;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1412
            for (Node n : g.nodes) {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1413
                if (!Collections.disjoint(n.data, varsToSolve)) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1414
                    Pair<List<Node>, Integer> path = computeTreeToLeafs(n);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1415
                    //discard all paths containing at least a node in the
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1416
                    //closure computed above
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1417
                    if (path.snd < bestPath.snd) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1418
                        bestPath = path;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1419
                    }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1420
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1421
            }
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1422
            if (bestPath == noPath) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1423
                //no path leads there
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1424
                throw new NodeNotFoundException(g);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1425
            }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1426
            return bestPath.fst.head;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1427
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1428
    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1429
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1430
    /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1431
     * The inference process can be thought of as a sequence of steps. Each step
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1432
     * instantiates an inference variable using a subset of the inference variable
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1433
     * bounds, if certain condition are met. Decisions such as the sequence in which
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1434
     * steps are applied, or which steps are to be applied are left to the inference engine.
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1435
     */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1436
    enum InferenceStep {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1437
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1438
        /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1439
         * Instantiate an inference variables using one of its (ground) equality
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1440
         * constraints
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1441
         */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1442
        EQ(InferenceBound.EQ) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1443
            @Override
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1444
            Type solve(UndetVar uv, InferenceContext inferenceContext) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1445
                return filterBounds(uv, inferenceContext).head;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1446
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1447
        },
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1448
        /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1449
         * Instantiate an inference variables using its (ground) lower bounds. Such
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1450
         * bounds are merged together using lub().
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1451
         */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1452
        LOWER(InferenceBound.LOWER) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1453
            @Override
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1454
            Type solve(UndetVar uv, InferenceContext inferenceContext) {
31937
ad43a6639c4a 8132215: class InferenceContext should live in a separate file
vromero
parents: 30014
diff changeset
  1455
                Infer infer = inferenceContext.infer;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1456
                List<Type> lobounds = filterBounds(uv, inferenceContext);
18395
d56a5fbf0b32 8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents: 18008
diff changeset
  1457
                //note: lobounds should have at least one element
d56a5fbf0b32 8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents: 18008
diff changeset
  1458
                Type owntype = lobounds.tail.tail == null  ? lobounds.head : infer.types.lub(lobounds);
d56a5fbf0b32 8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents: 18008
diff changeset
  1459
                if (owntype.isPrimitive() || owntype.hasTag(ERROR)) {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1460
                    throw infer.inferenceException
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1461
                        .setMessage("no.unique.minimal.instance.exists",
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1462
                                    uv.qtype, lobounds);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1463
                } else {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1464
                    return owntype;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1465
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1466
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1467
        },
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1468
        /**
18909
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1469
         * Infer uninstantiated/unbound inference variables occurring in 'throws'
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1470
         * clause as RuntimeException
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1471
         */
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1472
        THROWS(InferenceBound.UPPER) {
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1473
            @Override
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1474
            public boolean accepts(UndetVar t, InferenceContext inferenceContext) {
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1475
                if ((t.qtype.tsym.flags() & Flags.THROWS) == 0) {
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1476
                    //not a throws undet var
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1477
                    return false;
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1478
                }
40594
8cbf5df9c503 8164399: inference of thrown variable does not work correctly
mcimadamore
parents: 39599
diff changeset
  1479
                Types types = inferenceContext.types;
8cbf5df9c503 8164399: inference of thrown variable does not work correctly
mcimadamore
parents: 39599
diff changeset
  1480
                Symtab syms = inferenceContext.infer.syms;
8cbf5df9c503 8164399: inference of thrown variable does not work correctly
mcimadamore
parents: 39599
diff changeset
  1481
                return t.getBounds(InferenceBound.UPPER).stream()
8cbf5df9c503 8164399: inference of thrown variable does not work correctly
mcimadamore
parents: 39599
diff changeset
  1482
                        .filter(b -> !inferenceContext.free(b))
8cbf5df9c503 8164399: inference of thrown variable does not work correctly
mcimadamore
parents: 39599
diff changeset
  1483
                        .allMatch(u -> types.isSubtype(syms.runtimeExceptionType, u));
18909
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1484
            }
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1485
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1486
            @Override
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1487
            Type solve(UndetVar uv, InferenceContext inferenceContext) {
31937
ad43a6639c4a 8132215: class InferenceContext should live in a separate file
vromero
parents: 30014
diff changeset
  1488
                return inferenceContext.infer.syms.runtimeExceptionType;
18909
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1489
            }
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1490
        },
8f9fc5d876e4 8012242: Lambda compatibility and checked exceptions
mcimadamore
parents: 18904
diff changeset
  1491
        /**
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1492
         * Instantiate an inference variables using its (ground) upper bounds. Such
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1493
         * bounds are merged together using glb().
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1494
         */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1495
        UPPER(InferenceBound.UPPER) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1496
            @Override
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1497
            Type solve(UndetVar uv, InferenceContext inferenceContext) {
31937
ad43a6639c4a 8132215: class InferenceContext should live in a separate file
vromero
parents: 30014
diff changeset
  1498
                Infer infer = inferenceContext.infer;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1499
                List<Type> hibounds = filterBounds(uv, inferenceContext);
24293
0d889f759fac 8033718: Inference ignores capture variable as upper bound
dlsmith
parents: 24226
diff changeset
  1500
                //note: hibounds should have at least one element
18395
d56a5fbf0b32 8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents: 18008
diff changeset
  1501
                Type owntype = hibounds.tail.tail == null  ? hibounds.head : infer.types.glb(hibounds);
d56a5fbf0b32 8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents: 18008
diff changeset
  1502
                if (owntype.isPrimitive() || owntype.hasTag(ERROR)) {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1503
                    throw infer.inferenceException
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1504
                        .setMessage("no.unique.maximal.instance.exists",
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1505
                                    uv.qtype, hibounds);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1506
                } else {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1507
                    return owntype;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1508
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1509
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1510
        },
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1511
        /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1512
         * Like the former; the only difference is that this step can only be applied
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1513
         * if all upper bounds are ground.
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1514
         */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1515
        UPPER_LEGACY(InferenceBound.UPPER) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1516
            @Override
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1517
            public boolean accepts(UndetVar t, InferenceContext inferenceContext) {
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1518
                return !inferenceContext.free(t.getBounds(ib)) && !t.isCaptured();
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1519
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1520
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1521
            @Override
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1522
            Type solve(UndetVar uv, InferenceContext inferenceContext) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1523
                return UPPER.solve(uv, inferenceContext);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1524
            }
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1525
        },
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1526
        /**
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1527
         * Like the former; the only difference is that this step can only be applied
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1528
         * if all upper/lower bounds are ground.
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1529
         */
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1530
        CAPTURED(InferenceBound.UPPER) {
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1531
            @Override
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1532
            public boolean accepts(UndetVar t, InferenceContext inferenceContext) {
19127
8a0cbd5cb055 8020804: javac crashes when speculative attribution infers intersection type with array component
mcimadamore
parents: 18918
diff changeset
  1533
                return t.isCaptured() &&
8a0cbd5cb055 8020804: javac crashes when speculative attribution infers intersection type with array component
mcimadamore
parents: 18918
diff changeset
  1534
                        !inferenceContext.free(t.getBounds(InferenceBound.UPPER, InferenceBound.LOWER));
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1535
            }
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1536
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1537
            @Override
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1538
            Type solve(UndetVar uv, InferenceContext inferenceContext) {
31937
ad43a6639c4a 8132215: class InferenceContext should live in a separate file
vromero
parents: 30014
diff changeset
  1539
                Infer infer = inferenceContext.infer;
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1540
                Type upper = UPPER.filterBounds(uv, inferenceContext).nonEmpty() ?
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1541
                        UPPER.solve(uv, inferenceContext) :
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1542
                        infer.syms.objectType;
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1543
                Type lower = LOWER.filterBounds(uv, inferenceContext).nonEmpty() ?
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1544
                        LOWER.solve(uv, inferenceContext) :
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1545
                        infer.syms.botType;
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1546
                CapturedType prevCaptured = (CapturedType)uv.qtype;
24396
3c36c6afcbca 8040327: Eliminate AnnotatedType
emc
parents: 24293
diff changeset
  1547
                return new CapturedType(prevCaptured.tsym.name, prevCaptured.tsym.owner,
26781
a786b07c7b91 8048614: Add TypeMetadata to contain type annotations and other type information
emc
parents: 26663
diff changeset
  1548
                                        upper, lower, prevCaptured.wildcard);
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1549
            }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1550
        };
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1551
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1552
        final InferenceBound ib;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1553
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1554
        InferenceStep(InferenceBound ib) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1555
            this.ib = ib;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1556
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1557
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1558
        /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1559
         * Find an instantiated type for a given inference variable within
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1560
         * a given inference context
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1561
         */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1562
        abstract Type solve(UndetVar uv, InferenceContext inferenceContext);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1563
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1564
        /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1565
         * Can the inference variable be instantiated using this step?
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1566
         */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1567
        public boolean accepts(UndetVar t, InferenceContext inferenceContext) {
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1568
            return filterBounds(t, inferenceContext).nonEmpty() && !t.isCaptured();
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1569
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1570
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1571
        /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1572
         * Return the subset of ground bounds in a given bound set (i.e. eq/lower/upper)
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1573
         */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1574
        List<Type> filterBounds(UndetVar uv, InferenceContext inferenceContext) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1575
            return Type.filter(uv.getBounds(ib), new BoundFilter(inferenceContext));
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1576
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1577
    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1578
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1579
    /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1580
     * This enumeration defines the sequence of steps to be applied when the
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1581
     * solver works in legacy mode. The steps in this enumeration reflect
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1582
     * the behavior of old inference routine (see JLS SE 7 15.12.2.7/15.12.2.8).
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1583
     */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1584
    enum LegacyInferenceSteps {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1585
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1586
        EQ_LOWER(EnumSet.of(InferenceStep.EQ, InferenceStep.LOWER)),
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1587
        EQ_UPPER(EnumSet.of(InferenceStep.EQ, InferenceStep.UPPER_LEGACY));
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1588
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1589
        final EnumSet<InferenceStep> steps;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1590
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1591
        LegacyInferenceSteps(EnumSet<InferenceStep> steps) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1592
            this.steps = steps;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1593
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1594
    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1595
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1596
    /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1597
     * This enumeration defines the sequence of steps to be applied when the
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1598
     * graph solver is used. This order is defined so as to maximize compatibility
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1599
     * w.r.t. old inference routine (see JLS SE 7 15.12.2.7/15.12.2.8).
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1600
     */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1601
    enum GraphInferenceSteps {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1602
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1603
        EQ(EnumSet.of(InferenceStep.EQ)),
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1604
        EQ_LOWER(EnumSet.of(InferenceStep.EQ, InferenceStep.LOWER)),
18911
dcc1e26a8c9c 8012238: Nested method capture and inference
mcimadamore
parents: 18910
diff changeset
  1605
        EQ_LOWER_THROWS_UPPER_CAPTURED(EnumSet.of(InferenceStep.EQ, InferenceStep.LOWER, InferenceStep.UPPER, InferenceStep.THROWS, InferenceStep.CAPTURED));
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1606
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1607
        final EnumSet<InferenceStep> steps;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1608
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1609
        GraphInferenceSteps(EnumSet<InferenceStep> steps) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1610
            this.steps = steps;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1611
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1612
    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1613
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1614
    /**
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1615
     * There are two kinds of dependencies between inference variables. The basic
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1616
     * kind of dependency (or bound dependency) arises when a variable mention
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1617
     * another variable in one of its bounds. There's also a more subtle kind
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1618
     * of dependency that arises when a variable 'might' lead to better constraints
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1619
     * on another variable (this is typically the case with variables holding up
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1620
     * stuck expressions).
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1621
     */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1622
    enum DependencyKind implements GraphUtils.DependencyKind {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1623
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1624
        /** bound dependency */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1625
        BOUND("dotted"),
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1626
        /** stuck dependency */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1627
        STUCK("dashed");
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1628
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1629
        final String dotSyle;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1630
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1631
        private DependencyKind(String dotSyle) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1632
            this.dotSyle = dotSyle;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1633
        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1634
    }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1635
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1636
    /**
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1637
     * This is the graph inference solver - the solver organizes all inference variables in
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1638
     * a given inference context by bound dependencies - in the general case, such dependencies
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1639
     * would lead to a cyclic directed graph (hence the name); the dependency info is used to build
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1640
     * an acyclic graph, where all cyclic variables are bundled together. An inference
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1641
     * step corresponds to solving a node in the acyclic graph - this is done by
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1642
     * relying on a given strategy (see GraphStrategy).
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1643
     */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1644
    class GraphSolver {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1645
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1646
        InferenceContext inferenceContext;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1647
        Warner warn;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1648
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1649
        GraphSolver(InferenceContext inferenceContext, Warner warn) {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1650
            this.inferenceContext = inferenceContext;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1651
            this.warn = warn;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1652
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1653
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1654
        /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1655
         * Solve variables in a given inference context. The amount of variables
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1656
         * to be solved, and the way in which the underlying acyclic graph is explored
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1657
         * depends on the selected solver strategy.
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1658
         */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1659
        void solve(GraphStrategy sstrategy) {
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1660
            doIncorporation(inferenceContext, warn); //initial propagation of bounds
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1661
            InferenceGraph inferenceGraph = new InferenceGraph();
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1662
            while (!sstrategy.done()) {
26267
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
  1663
                if (dependenciesFolder != null) {
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
  1664
                    //add this graph to the pending queue
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
  1665
                    pendingGraphs = pendingGraphs.prepend(inferenceGraph.toDot());
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
  1666
                }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1667
                InferenceGraph.Node nodeToSolve = sstrategy.pickNode(inferenceGraph);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1668
                List<Type> varsToSolve = List.from(nodeToSolve.data);
18904
3c4c6457ec5b 8019824: very long error messages on inference error
mcimadamore
parents: 18646
diff changeset
  1669
                List<Type> saved_undet = inferenceContext.save();
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1670
                try {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1671
                    //repeat until all variables are solved
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1672
                    outer: while (Type.containsAny(inferenceContext.restvars(), varsToSolve)) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1673
                        //for each inference phase
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1674
                        for (GraphInferenceSteps step : GraphInferenceSteps.values()) {
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1675
                            if (inferenceContext.solveBasic(varsToSolve, step.steps).nonEmpty()) {
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1676
                                doIncorporation(inferenceContext, warn);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1677
                                continue outer;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1678
                            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1679
                        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1680
                        //no progress
18395
d56a5fbf0b32 8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents: 18008
diff changeset
  1681
                        throw inferenceException.setMessage();
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1682
                    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1683
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1684
                catch (InferenceException ex) {
18395
d56a5fbf0b32 8016267: javac, TypeTag refactoring has provoked performance issues
vromero
parents: 18008
diff changeset
  1685
                    //did we fail because of interdependent ivars?
18904
3c4c6457ec5b 8019824: very long error messages on inference error
mcimadamore
parents: 18646
diff changeset
  1686
                    inferenceContext.rollback(saved_undet);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1687
                    instantiateAsUninferredVars(varsToSolve, inferenceContext);
33917
45d04023e689 8067767: type inference performance regression
mcimadamore
parents: 33906
diff changeset
  1688
                    doIncorporation(inferenceContext, warn);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1689
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1690
                inferenceGraph.deleteNode(nodeToSolve);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1691
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1692
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1693
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1694
        /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1695
         * The dependencies between the inference variables that need to be solved
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1696
         * form a (possibly cyclic) graph. This class reduces the original dependency graph
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1697
         * to an acyclic version, where cyclic nodes are folded into a single 'super node'.
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1698
         */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1699
        class InferenceGraph {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1700
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1701
            /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1702
             * This class represents a node in the graph. Each node corresponds
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1703
             * to an inference variable and has edges (dependencies) on other
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1704
             * nodes. The node defines an entry point that can be used to receive
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1705
             * updates on the structure of the graph this node belongs to (used to
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1706
             * keep dependencies in sync).
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1707
             */
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1708
            class Node extends GraphUtils.TarjanNode<ListBuffer<Type>, Node> implements DottableNode<ListBuffer<Type>, Node> {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1709
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1710
                /** node dependencies */
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1711
                Set<Node> deps;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1712
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1713
                Node(Type ivar) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1714
                    super(ListBuffer.of(ivar));
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1715
                    this.deps = new HashSet<>();
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1716
                }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1717
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1718
                @Override
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1719
                public GraphUtils.DependencyKind[] getSupportedDependencyKinds() {
38832
759100b68651 8158355: Inference graph dot support broken
mcimadamore
parents: 38538
diff changeset
  1720
                    return new GraphUtils.DependencyKind[] { DependencyKind.BOUND };
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1721
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1722
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1723
                public Iterable<? extends Node> getAllDependencies() {
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1724
                    return deps;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1725
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1726
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1727
                @Override
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1728
                public Collection<? extends Node> getDependenciesByKind(GraphUtils.DependencyKind dk) {
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1729
                    if (dk == DependencyKind.BOUND) {
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1730
                        return deps;
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1731
                    } else {
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1732
                        throw new IllegalStateException();
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1733
                    }
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1734
                }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1735
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1736
                /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1737
                 * Adds dependency with given kind.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1738
                 */
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1739
                protected void addDependency(Node depToAdd) {
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1740
                    deps.add(depToAdd);
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1741
                }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1742
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1743
                /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1744
                 * Add multiple dependencies of same given kind.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1745
                 */
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1746
                protected void addDependencies(Set<Node> depsToAdd) {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1747
                    for (Node n : depsToAdd) {
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1748
                        addDependency(n);
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1749
                    }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1750
                }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1751
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1752
                /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1753
                 * Remove a dependency, regardless of its kind.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1754
                 */
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1755
                protected boolean removeDependency(Node n) {
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1756
                    return deps.remove(n);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1757
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1758
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1759
                /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1760
                 * Compute closure of a give node, by recursively walking
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1761
                 * through all its dependencies (of given kinds)
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1762
                 */
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1763
                protected Set<Node> closure() {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1764
                    boolean progress = true;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
  1765
                    Set<Node> closure = new HashSet<>();
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1766
                    closure.add(this);
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1767
                    while (progress) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1768
                        progress = false;
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
  1769
                        for (Node n1 : new HashSet<>(closure)) {
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1770
                            progress = closure.addAll(n1.deps);
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1771
                        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1772
                    }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1773
                    return closure;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1774
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1775
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1776
                /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1777
                 * Is this node a leaf? This means either the node has no dependencies,
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1778
                 * or it just has self-dependencies.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1779
                 */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1780
                protected boolean isLeaf() {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1781
                    //no deps, or only one self dep
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1782
                    if (deps.isEmpty()) return true;
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1783
                    for (Node n : deps) {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1784
                        if (n != this) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1785
                            return false;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1786
                        }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1787
                    }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1788
                    return true;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1789
                }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1790
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1791
                /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1792
                 * Merge this node with another node, acquiring its dependencies.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1793
                 * This routine is used to merge all cyclic node together and
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1794
                 * form an acyclic graph.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1795
                 */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1796
                protected void mergeWith(List<? extends Node> nodes) {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1797
                    for (Node n : nodes) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1798
                        Assert.check(n.data.length() == 1, "Attempt to merge a compound node!");
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1799
                        data.appendList(n.data);
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1800
                        addDependencies(n.deps);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1801
                    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1802
                    //update deps
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1803
                    Set<Node> deps2 = new HashSet<>();
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1804
                    for (Node d : deps) {
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1805
                        if (data.contains(d.data.first())) {
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1806
                            deps2.add(this);
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1807
                        } else {
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1808
                            deps2.add(d);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1809
                        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1810
                    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1811
                    deps = deps2;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1812
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1813
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1814
                /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1815
                 * Notify all nodes that something has changed in the graph
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1816
                 * topology.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1817
                 */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1818
                private void graphChanged(Node from, Node to) {
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1819
                    if (removeDependency(from)) {
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1820
                        if (to != null) {
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1821
                            addDependency(to);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1822
                        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1823
                    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1824
                }
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1825
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1826
                @Override
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1827
                public Properties nodeAttributes() {
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1828
                    Properties p = new Properties();
26267
4ebd9393b373 8056075: Add support for dumping inference dependency graphs
mcimadamore
parents: 25874
diff changeset
  1829
                    p.put("label", "\"" + toString() + "\"");
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1830
                    return p;
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1831
                }
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1832
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1833
                @Override
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1834
                public Properties dependencyAttributes(Node sink, GraphUtils.DependencyKind dk) {
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1835
                    Properties p = new Properties();
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1836
                    p.put("style", ((DependencyKind)dk).dotSyle);
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1837
                    StringBuilder buf = new StringBuilder();
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1838
                    String sep = "";
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1839
                    for (Type from : data) {
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1840
                        UndetVar uv = (UndetVar)inferenceContext.asUndetVar(from);
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1841
                        for (Type bound : uv.getBounds(InferenceBound.values())) {
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1842
                            if (bound.containsAny(List.from(sink.data))) {
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1843
                                buf.append(sep);
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1844
                                buf.append(bound);
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1845
                                sep = ",";
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1846
                            }
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1847
                        }
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1848
                    }
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1849
                    p.put("label", "\"" + buf.toString() + "\"");
25844
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1850
                    return p;
48eab270456c 8048890: Add option to keep track of symbol completion dependencies
mcimadamore
parents: 25279
diff changeset
  1851
                }
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1852
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1853
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1854
            /** the nodes in the inference graph */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1855
            ArrayList<Node> nodes;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1856
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1857
            InferenceGraph() {
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1858
                initNodes();
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1859
            }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1860
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1861
            /**
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1862
             * Basic lookup helper for retrieving a graph node given an inference
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1863
             * variable type.
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1864
             */
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1865
            public Node findNode(Type t) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1866
                for (Node n : nodes) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1867
                    if (n.data.contains(t)) {
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1868
                        return n;
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1869
                    }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1870
                }
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1871
                return null;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1872
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1873
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1874
            /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1875
             * Delete a node from the graph. This update the underlying structure
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1876
             * of the graph (including dependencies) via listeners updates.
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1877
             */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1878
            public void deleteNode(Node n) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1879
                Assert.check(nodes.contains(n));
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1880
                nodes.remove(n);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1881
                notifyUpdate(n, null);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1882
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1883
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1884
            /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1885
             * Notify all nodes of a change in the graph. If the target node is
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1886
             * {@code null} the source node is assumed to be removed.
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1887
             */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1888
            void notifyUpdate(Node from, Node to) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1889
                for (Node n : nodes) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1890
                    n.graphChanged(from, to);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1891
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1892
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1893
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1894
            /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1895
             * Create the graph nodes. First a simple node is created for every inference
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1896
             * variables to be solved. Then Tarjan is used to found all connected components
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1897
             * in the graph. For each component containing more than one node, a super node is
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1898
             * created, effectively replacing the original cyclic nodes.
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1899
             */
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1900
            void initNodes() {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1901
                //add nodes
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
  1902
                nodes = new ArrayList<>();
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1903
                for (Type t : inferenceContext.restvars()) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1904
                    nodes.add(new Node(t));
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1905
                }
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1906
                //add dependencies
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1907
                for (Node n_i : nodes) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1908
                    Type i = n_i.data.first();
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1909
                    for (Node n_j : nodes) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1910
                        Type j = n_j.data.first();
23132
00a059740d87 8035891: javac, rename method asFree() in InferenceContext to asUndetVar() which reflects better it's purpose
vromero
parents: 23124
diff changeset
  1911
                        UndetVar uv_i = (UndetVar)inferenceContext.asUndetVar(i);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1912
                        if (Type.containsAny(uv_i.getBounds(InferenceBound.values()), List.of(j))) {
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1913
                            //update i's bound dependencies
38516
b643c42e9d25 8156954: javac incorrectly complains of incompatible types
mcimadamore
parents: 37003
diff changeset
  1914
                            n_i.addDependency(n_j);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1915
                        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1916
                    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1917
                }
19914
d86271bd430a 8016177: structural most specific and stuckness
vromero
parents: 19127
diff changeset
  1918
                //merge cyclic nodes
22163
3651128c74eb 8030244: Update langtools to use Diamond
briangoetz
parents: 21488
diff changeset
  1919
                ArrayList<Node> acyclicNodes = new ArrayList<>();
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1920
                for (List<? extends Node> conSubGraph : GraphUtils.tarjan(nodes)) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1921
                    if (conSubGraph.length() > 1) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1922
                        Node root = conSubGraph.head;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1923
                        root.mergeWith(conSubGraph.tail);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1924
                        for (Node n : conSubGraph) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1925
                            notifyUpdate(n, root);
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1926
                        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1927
                    }
16321
75e64bcd3ab0 8008723: Graph Inference: bad graph calculation leads to assertion error
mcimadamore
parents: 15717
diff changeset
  1928
                    acyclicNodes.add(conSubGraph.head);
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1929
                }
16321
75e64bcd3ab0 8008723: Graph Inference: bad graph calculation leads to assertion error
mcimadamore
parents: 15717
diff changeset
  1930
                nodes = acyclicNodes;
15717
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1931
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1932
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1933
            /**
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1934
             * Debugging: dot representation of this graph
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1935
             */
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1936
            String toDot() {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1937
                StringBuilder buf = new StringBuilder();
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1938
                for (Type t : inferenceContext.undetvars) {
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1939
                    UndetVar uv = (UndetVar)t;
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1940
                    buf.append(String.format("var %s - upper bounds = %s, lower bounds = %s, eq bounds = %s\\n",
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1941
                            uv.qtype, uv.getBounds(InferenceBound.UPPER), uv.getBounds(InferenceBound.LOWER),
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1942
                            uv.getBounds(InferenceBound.EQ)));
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1943
                }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1944
                return GraphUtils.toDot(nodes, "inferenceGraph" + hashCode(), buf.toString());
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1945
            }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1946
        }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1947
    }
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1948
    // </editor-fold>
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1949
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1950
    // <editor-fold defaultstate="collapsed" desc="Inference context">
ab55670d2e62 8007464: Add graph inference support
mcimadamore
parents: 15706
diff changeset
  1951
    /**
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15383
diff changeset
  1952
     * Functional interface for defining inference callbacks. Certain actions
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15383
diff changeset
  1953
     * (i.e. subtyping checks) might need to be redone after all inference variables
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15383
diff changeset
  1954
     * have been fixed.
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
  1955
     */
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15383
diff changeset
  1956
    interface FreeTypeListener {
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15383
diff changeset
  1957
        void typesInferred(InferenceContext inferenceContext);
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15383
diff changeset
  1958
    }
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
  1959
31937
ad43a6639c4a 8132215: class InferenceContext should live in a separate file
vromero
parents: 30014
diff changeset
  1960
    final InferenceContext emptyContext;
15705
c4124695db0c 8007463: Cleanup inference related classes
mcimadamore
parents: 15383
diff changeset
  1961
    // </editor-fold>
14047
7c7a5611cf76 7175433: Inference cleanup: add helper class to handle inference variables
mcimadamore
parents: 13440
diff changeset
  1962
}