src/share/classes/com/sun/tools/javac/comp/Infer.java

changeset 1347
1408af4cd8b0
parent 1338
ad2ca2a4ab5e
child 1348
573ceb23beeb
     1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Infer.java	Sat Sep 29 09:00:58 2012 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Infer.java	Thu Oct 04 13:04:53 2012 +0100
     1.3 @@ -29,6 +29,7 @@
     1.4  import com.sun.tools.javac.code.Symbol.*;
     1.5  import com.sun.tools.javac.code.Type.*;
     1.6  import com.sun.tools.javac.code.Type.UndetVar.InferenceBound;
     1.7 +import com.sun.tools.javac.comp.DeferredAttr.AttrMode;
     1.8  import com.sun.tools.javac.comp.Resolve.InapplicableMethodException;
     1.9  import com.sun.tools.javac.comp.Resolve.VerboseResolutionMode;
    1.10  import com.sun.tools.javac.tree.JCTree;
    1.11 @@ -62,6 +63,7 @@
    1.12      Types types;
    1.13      Check chk;
    1.14      Resolve rs;
    1.15 +    DeferredAttr deferredAttr;
    1.16      Log log;
    1.17      JCDiagnostic.Factory diags;
    1.18  
    1.19 @@ -77,6 +79,7 @@
    1.20          syms = Symtab.instance(context);
    1.21          types = Types.instance(context);
    1.22          rs = Resolve.instance(context);
    1.23 +        deferredAttr = DeferredAttr.instance(context);
    1.24          log = Log.instance(context);
    1.25          chk = Check.instance(context);
    1.26          diags = JCDiagnostic.Factory.instance(context);
    1.27 @@ -187,7 +190,7 @@
    1.28              Attr.ResultInfo resultInfo,
    1.29              Warner warn) throws InferenceException {
    1.30          Type to = resultInfo.pt;
    1.31 -        if (to.tag == NONE) {
    1.32 +        if (to.tag == NONE || resultInfo.checkContext.inferenceContext().free(resultInfo.pt)) {
    1.33              to = mtype.getReturnType().tag <= VOID ?
    1.34                      mtype.getReturnType() : syms.objectType;
    1.35          }
    1.36 @@ -268,14 +271,16 @@
    1.37                                    List<Type> argtypes,
    1.38                                    boolean allowBoxing,
    1.39                                    boolean useVarargs,
    1.40 +                                  Resolve.MethodResolutionContext resolveContext,
    1.41                                    Warner warn) throws InferenceException {
    1.42          //-System.err.println("instantiateMethod(" + tvars + ", " + mt + ", " + argtypes + ")"); //DEBUG
    1.43          final InferenceContext inferenceContext = new InferenceContext(tvars, this);
    1.44          inferenceException.clear();
    1.45  
    1.46          try {
    1.47 -            rs.checkRawArgumentsAcceptable(env, inferenceContext, argtypes, mt.getParameterTypes(),
    1.48 -                    allowBoxing, useVarargs, warn, new InferenceCheckHandler(inferenceContext));
    1.49 +            rs.checkRawArgumentsAcceptable(env, msym, resolveContext.attrMode(), inferenceContext,
    1.50 +                    argtypes, mt.getParameterTypes(), allowBoxing, useVarargs, warn,
    1.51 +                    new InferenceCheckHandler(inferenceContext));
    1.52  
    1.53              // minimize as yet undetermined type variables
    1.54              for (Type t : inferenceContext.undetvars) {
    1.55 @@ -469,6 +474,7 @@
    1.56       */
    1.57      Type instantiatePolymorphicSignatureInstance(Env<AttrContext> env,
    1.58                                              MethodSymbol spMethod,  // sig. poly. method or null if none
    1.59 +                                            Resolve.MethodResolutionContext resolveContext,
    1.60                                              List<Type> argtypes) {
    1.61          final Type restype;
    1.62  
    1.63 @@ -498,7 +504,7 @@
    1.64                  restype = syms.objectType;
    1.65          }
    1.66  
    1.67 -        List<Type> paramtypes = Type.map(argtypes, implicitArgType);
    1.68 +        List<Type> paramtypes = Type.map(argtypes, new ImplicitArgType(spMethod, resolveContext.step));
    1.69          List<Type> exType = spMethod != null ?
    1.70              spMethod.getThrownTypes() :
    1.71              List.of(syms.throwableType); // make it throw all exceptions
    1.72 @@ -510,16 +516,21 @@
    1.73          return mtype;
    1.74      }
    1.75      //where
    1.76 -        Mapping implicitArgType = new Mapping ("implicitArgType") {
    1.77 -                public Type apply(Type t) {
    1.78 -                    t = types.erasure(t);
    1.79 -                    if (t.tag == BOT)
    1.80 -                        // nulls type as the marker type Null (which has no instances)
    1.81 -                        // infer as java.lang.Void for now
    1.82 -                        t = types.boxedClass(syms.voidType).type;
    1.83 -                    return t;
    1.84 -                }
    1.85 -        };
    1.86 +        class ImplicitArgType extends DeferredAttr.DeferredTypeMap {
    1.87 +
    1.88 +            public ImplicitArgType(Symbol msym, Resolve.MethodResolutionPhase phase) {
    1.89 +                deferredAttr.super(AttrMode.SPECULATIVE, msym, phase);
    1.90 +            }
    1.91 +
    1.92 +            public Type apply(Type t) {
    1.93 +                t = types.erasure(super.apply(t));
    1.94 +                if (t.tag == BOT)
    1.95 +                    // nulls type as the marker type Null (which has no instances)
    1.96 +                    // infer as java.lang.Void for now
    1.97 +                    t = types.boxedClass(syms.voidType).type;
    1.98 +                return t;
    1.99 +            }
   1.100 +        }
   1.101  
   1.102      /**
   1.103       * Mapping that turns inference variables into undet vars
   1.104 @@ -708,6 +719,22 @@
   1.105                  throw thrownEx;
   1.106              }
   1.107          }
   1.108 +
   1.109 +        void solveAny(List<Type> varsToSolve, Types types, Infer infer) {
   1.110 +            boolean progress = false;
   1.111 +            for (Type t : varsToSolve) {
   1.112 +                UndetVar uv = (UndetVar)asFree(t, types);
   1.113 +                if (uv.inst == null) {
   1.114 +                    infer.minimizeInst(uv, Warner.noWarnings);
   1.115 +                    if (uv.inst != null) {
   1.116 +                        progress = true;
   1.117 +                    }
   1.118 +                }
   1.119 +            }
   1.120 +            if (!progress) {
   1.121 +                throw infer.inferenceException.setMessage("cyclic.inference", varsToSolve);
   1.122 +            }
   1.123 +        }
   1.124      }
   1.125  
   1.126      final InferenceContext emptyContext = new InferenceContext(List.<Type>nil(), this);

mercurial