unison icon indicating copy to clipboard operation
unison copied to clipboard

`view` and UCM console output render reversed arguments for nested delayed computations

Open rlmark opened this issue 2 years ago • 3 comments

The following expression

stream10 = Stream.range 0 10

In a watch expression and when viewed will render with the arguments reversed

 8 | > stream10
          ⧩
          _ -> Stream.range! 10 0

See slack thread from a Unison community member who found this

The problem is not unique to Stream or abilities. If you wrap a regular List.range function in the same way, you'll see the issue surface.

List.myRange n m _ = List.rangeClosed n m

> List.myRange 0 10
    6 | > List.myRange 0 10
          ⧩
          _ -> List.rangeClosed 10 0

rlmark avatar Jun 30 '22 20:06 rlmark

Actually, it seems to be not only a "rendering" issue but something more real with such partial application of terms. In my local instance of UCM, having these definitions in scratch file

use Nat +

stream10 = Stream.range 0 10
> stream10
> stream10 |> Stream.toList!
> Stream.map ((+)1) stream10 |> Stream.toList!

stream10' = 'let Stream.range! 0 10
> stream10'
> stream10' |> Stream.toList!
> Stream.map ((+)1) stream10' |> Stream.toList!

> Stream.range 0 10 |> Stream.map ((+)1) |> Stream.toList!

I've got when load it into UCM:

    4 | > stream10
          ⧩
          _ -> Stream.range! 10 0
  
    5 | > stream10 |> Stream.toList!
          ⧩
          []
  
    6 | > Stream.map ((+)1) stream10 |> Stream.toList!
          ⧩
          []
  
    9 | > stream10'
          ⧩
          '(Stream.range! 0 10)
  
    10 | > stream10' |> Stream.toList!
           ⧩
           [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  
    11 | > Stream.map ((+)1) stream10' |> Stream.toList!
           ⧩
           [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  
    13 | > Stream.range 0 10 |> Stream.map ((+)1) |> Stream.toList!
           ⧩
           [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

Notice, please, that it actually returns an empty list with stream10 but works fine with stream10'.

Version of my UCM

$ ucm version
ucm version: release/M3 (built on 2022-03-08)

sergey-scherbina avatar Jun 30 '22 21:06 sergey-scherbina

The weird runtime behavior is not present in trunk, but there is still an issue with decompilation flipping the order around.

finished evaluate in 0s (cpu), 0s (system)
Timing evaluate.respond...

    4 | > stream10
          ⧩
          _ -> Stream.range! 10 0
  
    5 | > stream10 |> Stream.toList!
          ⧩
          [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  
    6 | > Stream.map ((+)1) stream10 |> Stream.toList!
          ⧩
          [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  
    9 | > stream10'
          ⧩
          '(Stream.range! 0 10)
  
    10 | > stream10' |> Stream.toList!
           ⧩
           [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  
    11 | > Stream.map ((+)1) stream10' |> Stream.toList!
           ⧩
           [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
  
    13 | > Stream.range 0 10 |> Stream.map ((+)1) |> Stream.toList!
           ⧩
           [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

pchiusano avatar Jun 30 '22 21:06 pchiusano

Have found a case where this issue affects evaluation in the latest build of UCM and base library:

> t1 _ = forever '(ask |> emit)
> Stream.pipe (Stream.range 0 10) t1 |> Stream.toList!
> stream10 = Stream.range 0 10
> Stream.pipe stream10 t1 |> Stream.toList!

what evaluates to:

    1 | > t1 _ = forever '(ask |> emit)
          ⧩
          let
            _float _eta = emit _eta
            _float1 = '(ask |> _float)
            '(forever _float)
  
    2 | > Stream.pipe (Stream.range 0 10) t1 |> Stream.toList!
          ⧩
          [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
  
    3 | > stream10 = Stream.range 0 10
          ⧩
          _ -> Stream.range! 10 0
  
    4 | > Stream.pipe stream10 t1 |> Stream.toList!
          ⧩
          []

please note empty latest result also t1 displayed a bit broken

sergey-scherbina avatar Jul 06 '22 02:07 sergey-scherbina

I think the erroneous output 4 in the last message was the same problem as #3166 and was fixed by #3266.

The decompiling problem is still around.

dolio avatar Aug 30 '22 21:08 dolio