Most specific method in diagnostic generation for overload resolution

B. Blaser bsrbnd at gmail.com
Wed Oct 4 10:12:56 UTC 2017


On 4 October 2017 at 01:40, Vicente Romero <vicente.romero at oracle.com> wrote:
> Hi Bernard,
>
> [1] is a link to the fix for the bug you reported. I used your email to mark
> it as contributed by you. Finally we made some minor adjustments to the code
> in order to avoid cloning the key set.

Perfect, thanks!

Bernard

> Thanks!
> Vicente
>
> [1] http://hg.openjdk.java.net/jdk10/master/rev/2e947e1bd907
>
> On 09/20/2017 10:56 AM, B. Blaser wrote:
>>
>> Hi,
>>
>> Related to [1], I wrote a specialized map to store only the most
>> specific candidates during the diagnostic generation for overload
>> resolution, here under.
>>
>> It's then used in "Resolve.InapplicableSymbolsError.mapCandidates()"
>> when non-applicable methods are collected to generate the diagnostic.
>>
>> What do you think?
>> Bernard
>>
>> [1]
>> http://mail.openjdk.java.net/pipermail/compiler-dev/2017-September/011062.html
>>
>> diff --git
>> a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
>> b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
>> --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
>> +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Resolve.java
>> @@ -59,6 +59,7 @@
>>   import java.util.HashSet;
>>   import java.util.Iterator;
>>   import java.util.LinkedHashMap;
>> +import java.util.LinkedList;
>>   import java.util.Map;
>>   import java.util.Set;
>>   import java.util.function.BiFunction;
>> @@ -3995,14 +3996,29 @@
>>           }
>>           //where
>>               private Map<Symbol, JCDiagnostic> mapCandidates() {
>> -                Map<Symbol, JCDiagnostic> candidates = new
>> LinkedHashMap<>();
>> +                MostSpecificMap candidates = new MostSpecificMap();
>>                   for (Candidate c : resolveContext.candidates) {
>>                       if (c.isApplicable()) continue;
>> -                    candidates.put(c.sym, c.details);
>> +                    candidates.put(c);
>>                   }
>>                   return candidates;
>>               }
>>
>> +            @SuppressWarnings("serial")
>> +            private class MostSpecificMap extends
>> LinkedHashMap<Symbol, JCDiagnostic> {
>> +                private void put(Candidate c) {
>> +                    new LinkedList<>(keySet()).stream()
>> +                            .filter( s -> !s.equals(c.sym) )
>> +                            .filter( s -> c.sym.overrides(s,
>> (TypeSymbol)s.owner, types, false) )
>> +                            .forEach( s -> remove(s) );
>> +
>> +                    if (!keySet().stream()
>> +                            .filter( s -> !s.equals(c.sym) )
>> +                            .anyMatch( s -> s.overrides(c.sym,
>> (TypeSymbol)c.sym.owner, types, false) ))
>> +                        put(c.sym, c.details);
>> +                }
>> +            }
>> +
>>               Map<Symbol, JCDiagnostic> filterCandidates(Map<Symbol,
>> JCDiagnostic> candidatesMap) {
>>                   Map<Symbol, JCDiagnostic> candidates = new
>> LinkedHashMap<>();
>>                   for (Map.Entry<Symbol, JCDiagnostic> _entry :
>> candidatesMap.entrySet()) {
>
>


More information about the compiler-dev mailing list