An example of substituability test that is recursive
forax at univ-mlv.fr
forax at univ-mlv.fr
Thu Jan 31 17:38:51 UTC 2019
----- Mail original -----
> De: "Brian Goetz" <brian.goetz at oracle.com>
> À: "Remi Forax" <forax at univ-mlv.fr>
> Cc: "Karen Kinnear" <karen.kinnear at oracle.com>, "valhalla-spec-experts" <valhalla-spec-experts at openjdk.java.net>
> Envoyé: Jeudi 31 Janvier 2019 17:56:47
> Objet: Re: An example of substituability test that is recursive
> Currently, `==` is almost useless on lambdas, as we disclaim nearly all
> promises. What this would mean is that `==` becomes slightly less useless and
> slightly more expensive. It’s not obvious this is a bad trade (or that it
> really matters, because people are discouraged from using `==` on lambdas
> anyway.)
>
I agree.
and it's still useless because there is no guarantee that with
Runnable r1 = () -> {};
Runnable r2 = () -> {};
r1 and r2 use the same proxy, so r1 == r2 can still return false.
I'm just saying that having recursive value types are more frequent that what i was thinking before.
Rémi
>> On Jan 31, 2019, at 11:53 AM, Remi Forax <forax at univ-mlv.fr> wrote:
>>
>> Thinking a little more about this example,
>> i think it will be more common if we retrofit lambdas to be value type because a
>> series of composition of lambdas is a kind of linked list in term of data
>> structure in memory.
>>
>> For the composition of lambdas, a stack overflow is unlikely because otherwise
>> calling the lambda will stack overflow too but it means that == will be slow
>> (because it does a recursive comparison).
>>
>> Rémi
>>
>> ----- Mail original -----
>>> De: "Remi Forax" <forax at univ-mlv.fr>
>>> À: "Karen Kinnear" <karen.kinnear at oracle.com>
>>> Cc: "valhalla-spec-experts" <valhalla-spec-experts at openjdk.java.net>
>>> Envoyé: Jeudi 31 Janvier 2019 12:19:32
>>> Objet: An example of substituability test that is recursive
>>
>>> Hi Karen,
>>> here is an example that recurse to its death with the current prototype
>>>
>>> import java.lang.invoke.ValueBootstrapMethods;
>>> import java.util.stream.IntStream;
>>>
>>> public class Substituable {
>>> static value class Link {
>>> private final int value;
>>> private final Object next;
>>>
>>> public Link(int value, Object next) {
>>> this.value = value;
>>> this.next = next;
>>> }
>>>
>>> static Object times(int count) {
>>> return IntStream.range(0, count).boxed().reduce(null, (acc, index) -> new
>>> Link(index, acc), (l1, l2) -> { throw null; });
>>> }
>>> }
>>>
>>>
>>> public static void main(String[] args) {
>>> var l = Link.times(1_000);
>>>
>>> //System.out.println(l == l);
>>> System.out.println(ValueBootstrapMethods.isSubstitutable(l, l));
>>> }
>>> }
>>>
>>>
> >> Rémi
More information about the valhalla-spec-observers
mailing list