Mon, 28 Feb 2011 11:50:56 +0000
7015715: lub gets stuck on type with complex supertype
Summary: lub should not scan supertypes unnecessarily
Reviewed-by: jjg, dlsmith
src/share/classes/com/sun/tools/javac/code/Types.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/generics/inference/T7015715.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javac/code/Types.java Mon Feb 28 11:48:53 2011 +0000 1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Types.java Mon Feb 28 11:50:56 2011 +0000 1.3 @@ -2832,12 +2832,26 @@ 1.4 while (ts.head.tag != CLASS && ts.head.tag != TYPEVAR) 1.5 ts = ts.tail; 1.6 Assert.check(!ts.isEmpty()); 1.7 - List<Type> cl = closure(ts.head); 1.8 + //step 1 - compute erased candidate set (EC) 1.9 + List<Type> cl = erasedSupertypes(ts.head); 1.10 for (Type t : ts.tail) { 1.11 if (t.tag == CLASS || t.tag == TYPEVAR) 1.12 - cl = intersect(cl, closure(t)); 1.13 + cl = intersect(cl, erasedSupertypes(t)); 1.14 } 1.15 - return compoundMin(cl); 1.16 + //step 2 - compute minimal erased candidate set (MEC) 1.17 + List<Type> mec = closureMin(cl); 1.18 + //step 3 - for each element G in MEC, compute lci(Inv(G)) 1.19 + List<Type> candidates = List.nil(); 1.20 + for (Type erasedSupertype : mec) { 1.21 + List<Type> lci = List.of(asSuper(ts.head, erasedSupertype.tsym)); 1.22 + for (Type t : ts) { 1.23 + lci = intersect(lci, List.of(asSuper(t, erasedSupertype.tsym))); 1.24 + } 1.25 + candidates = candidates.appendList(lci); 1.26 + } 1.27 + //step 4 - let MEC be { G1, G2 ... Gn }, then we have that 1.28 + //lub = lci(Inv(G1)) & lci(Inv(G2)) & ... & lci(Inv(Gn)) 1.29 + return compoundMin(candidates); 1.30 1.31 default: 1.32 // calculate lub(A, B[]) 1.33 @@ -2851,6 +2865,18 @@ 1.34 } 1.35 } 1.36 // where 1.37 + List<Type> erasedSupertypes(Type t) { 1.38 + ListBuffer<Type> buf = lb(); 1.39 + for (Type sup : closure(t)) { 1.40 + if (sup.tag == TYPEVAR) { 1.41 + buf.append(sup); 1.42 + } else { 1.43 + buf.append(erasure(sup)); 1.44 + } 1.45 + } 1.46 + return buf.toList(); 1.47 + } 1.48 + 1.49 private Type arraySuperType = null; 1.50 private Type arraySuperType() { 1.51 // initialized lazily to avoid problems during compiler startup
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/generics/inference/T7015715.java Mon Feb 28 11:50:56 2011 +0000 2.3 @@ -0,0 +1,46 @@ 2.4 +/* 2.5 + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. 2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2.7 + * 2.8 + * This code is free software; you can redistribute it and/or modify it 2.9 + * under the terms of the GNU General Public License version 2 only, as 2.10 + * published by the Free Software Foundation. 2.11 + * 2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2.15 + * version 2 for more details (a copy is included in the LICENSE file that 2.16 + * accompanied this code). 2.17 + * 2.18 + * You should have received a copy of the GNU General Public License version 2.19 + * 2 along with this work; if not, write to the Free Software Foundation, 2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2.21 + * 2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 2.23 + * or visit www.oracle.com if you need additional information or have any 2.24 + * questions. 2.25 + */ 2.26 + 2.27 +/* 2.28 + * @test 2.29 + * @bug 7015715 2.30 + * 2.31 + * @summary lub gets stuck on type with complex supertype 2.32 + * @author Neal Gafter 2.33 + * @compile T7015715.java 2.34 + * 2.35 + */ 2.36 + 2.37 +class T7015715 { 2.38 + 2.39 + interface I<T> {} 2.40 + 2.41 + interface A<T> extends I<A<A<T>>>{} 2.42 + 2.43 + static abstract class X { 2.44 + abstract <T> T foo(T x, T y); 2.45 + void bar(A<Integer> x, A<String> y){ 2.46 + foo(x, y); 2.47 + } 2.48 + } 2.49 +}