From 1683dd4109e67a6ef2f2523ba1b6aede800eceb9 Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Mon, 28 Feb 2011 11:50:56 +0000 Subject: [PATCH] 7015715: lub gets stuck on type with complex supertype Lub should not scan supertypes unnecessarily Reviewed-by: jjg, dlsmith --- .../com/sun/tools/javac/code/Types.java | 32 +++++++++++-- .../javac/generics/inference/T7015715.java | 46 +++++++++++++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 langtools/test/tools/javac/generics/inference/T7015715.java diff --git a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java index c29b317115f..661fd7bc857 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/code/Types.java +++ b/langtools/src/share/classes/com/sun/tools/javac/code/Types.java @@ -2832,12 +2832,26 @@ public class Types { while (ts.head.tag != CLASS && ts.head.tag != TYPEVAR) ts = ts.tail; Assert.check(!ts.isEmpty()); - List cl = closure(ts.head); + //step 1 - compute erased candidate set (EC) + List cl = erasedSupertypes(ts.head); for (Type t : ts.tail) { if (t.tag == CLASS || t.tag == TYPEVAR) - cl = intersect(cl, closure(t)); + cl = intersect(cl, erasedSupertypes(t)); } - return compoundMin(cl); + //step 2 - compute minimal erased candidate set (MEC) + List mec = closureMin(cl); + //step 3 - for each element G in MEC, compute lci(Inv(G)) + List candidates = List.nil(); + for (Type erasedSupertype : mec) { + List lci = List.of(asSuper(ts.head, erasedSupertype.tsym)); + for (Type t : ts) { + lci = intersect(lci, List.of(asSuper(t, erasedSupertype.tsym))); + } + candidates = candidates.appendList(lci); + } + //step 4 - let MEC be { G1, G2 ... Gn }, then we have that + //lub = lci(Inv(G1)) & lci(Inv(G2)) & ... & lci(Inv(Gn)) + return compoundMin(candidates); default: // calculate lub(A, B[]) @@ -2851,6 +2865,18 @@ public class Types { } } // where + List erasedSupertypes(Type t) { + ListBuffer buf = lb(); + for (Type sup : closure(t)) { + if (sup.tag == TYPEVAR) { + buf.append(sup); + } else { + buf.append(erasure(sup)); + } + } + return buf.toList(); + } + private Type arraySuperType = null; private Type arraySuperType() { // initialized lazily to avoid problems during compiler startup diff --git a/langtools/test/tools/javac/generics/inference/T7015715.java b/langtools/test/tools/javac/generics/inference/T7015715.java new file mode 100644 index 00000000000..44e1b02e2f7 --- /dev/null +++ b/langtools/test/tools/javac/generics/inference/T7015715.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. + */ + +/* + * @test + * @bug 7015715 + * + * @summary lub gets stuck on type with complex supertype + * @author Neal Gafter + * @compile T7015715.java + * + */ + +class T7015715 { + + interface I {} + + interface A extends I>>{} + + static abstract class X { + abstract T foo(T x, T y); + void bar(A x, A y){ + foo(x, y); + } + } +}