Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with using tuple.at inside of bool.while #2834

Closed
c71n93 opened this issue Jan 31, 2024 · 7 comments
Closed

Problem with using tuple.at inside of bool.while #2834

c71n93 opened this issue Jan 31, 2024 · 7 comments
Milestone

Comments

@c71n93
Copy link
Member

c71n93 commented Jan 31, 2024

The puzzles #2818 and #2819 describe the problems with bool.while. Trying to figure out what's wrong with the test from puzzle #2818, I got a strange result. I tried to simplify the test and took an already existing working test.

This test from bool-test.eo is passing successfully:

[] > last-while-dataization-object
  memory 0 > x
  eq. > @
    while.
      x.as-int.lt 2
      [i]
        seq > @
          *
            x.write (x.as-int.plus 1)
            x.as-int
    3

This modified test fails with error:

[] > last-while-dataization-object-modified
  * 1 2 3 4 > arr
  memory 0 > x
  eq. > @
    while.
      x.as-int.lt 2
      [i]
        seq > @
          *
            arr.at
              x.as-int
            x.write (x.as-int.plus 1)
            x.as-int
    3

The only thing I added here is iterating over a tuple before incrementing x (arr.at (x.as-int)). It turns out that in this case there is one extra iteration. I have not been able to figure out what exactly the problem is here.

@c71n93
Copy link
Member Author

c71n93 commented Jan 31, 2024

@maxonfjvipon WDYT? Do you have any ideas?

@maxonfjvipon
Copy link
Member

@c71n93 I think you need to try to repeat such behavior in test written on Java. Then it'll be possible to debug it

c71n93 added a commit to c71n93/eo that referenced this issue Feb 2, 2024
c71n93 added a commit to c71n93/eo that referenced this issue Feb 2, 2024
@c71n93
Copy link
Member Author

c71n93 commented Feb 2, 2024

@maxonfjvipon I implemented this broken test on Java (#2839), but behaviour was different (test on Java didn't fail). Then I discovered that the problem is seq.

This two tests work differently:

[] > seq-single-dataization-int-equal-to-test
  memory 0 > x
  eq. > @
    seq
      *
        x.write 0
        x.write (x.as-int.plus 1)
        x.as-int
    1

[] > seq-single-dataization-int-equal-to-test-bug
  memory 0 > x
  eq. > @
    seq
      *
        at.
          * 0 1
          x.as-int
        x.write (x.as-int.plus 1)
        x.as-int
    1

In the second test seq dataizes as 0 instead of the expected 1. I implemented this test on Java (#2840) and suddenly it didn't fail too.

I couldn't figure out what the reason might be. Obviously, code generated from eo tests and tests written manually on Java are different. As I could understand from the debugger, all elements of the seq are dataized in both cases.

@maxonfjvipon Do you have any ideas?

@maxonfjvipon
Copy link
Member

@c71n93 I wrote the same tests in java and first test returned 1, the second returned 0:

@Test
void test() {
    Phi counter = new EOmemory(Phi.Φ);
    counter.attr(0).put(new Data.ToPhi(0L));

    Phi arr = new PhWith(
        new PhWith(
            new EOtuple$EOempty(Phi.Φ).attr("with").get().copy(),
            0, new Data.ToPhi(0L)
        ).attr("with").get().copy(),
        0, new Data.ToPhi(1L)
    );

    Phi first = new PhWith(new PhCopy(new PhMethod(counter, "write")), 0, new Data.ToPhi(0L));

    Phi second = new PhWith(
        new PhCopy(new PhMethod(arr, "at")),
        0, new PhMethod(counter, "as-int")
    );

    Phi args = new PhWith(
        new PhCopy(
            new PhMethod(
                new PhWith(
                    new PhCopy(
                        new PhMethod(
                            new PhWith(
                                new PhCopy(new PhMethod(new EOtuple$EOempty(Phi.Φ), "with")),
                                0,
                                first
                            ),
                            "with"
                        )
                    ),
                    0,
                    new PhWith(
                        new PhCopy(new PhMethod(counter, "write")),
                        0,
                        new PhWith(
                            new PhCopy(new PhMethod(new PhMethod(counter, "as-int"), "plus")),
                            0, new Data.ToPhi(1L)
                        )
                    )
                ),
                "with"
            )
        ),
        0, new PhMethod(counter, "as-int")
    );

    System.out.println(
        new Dataized(
            new PhWith(new EOseq(Phi.Φ), 0, args)
        ).take(Long.class)
    );
}

first and second are variables that indicates both cases, they're almost the same. You can try to play with it

@maxonfjvipon
Copy link
Member

@c71n93 And yes, there's something wrong, but it's not related to seq.
There is one interesting line in PhDefault.

It caches the attribute that was got though decorator (φ or λ). If we're removing the caching - both tests become returning 1.

And I think the MAIN problem here is mutability of memory. How we can afford caching if memory is mutable and cache does not know about changes of the memory internal value?

c71n93 added a commit to c71n93/eo that referenced this issue Feb 2, 2024
@maxonfjvipon maxonfjvipon added this to the Important milestone Feb 2, 2024
c71n93 added a commit to c71n93/eo that referenced this issue Feb 7, 2024
c71n93 added a commit to c71n93/eo that referenced this issue Feb 7, 2024
c71n93 added a commit to c71n93/eo that referenced this issue Apr 11, 2024
c71n93 added a commit to c71n93/eo that referenced this issue Apr 11, 2024
c71n93 added a commit to c71n93/eo that referenced this issue Apr 11, 2024
@maxonfjvipon
Copy link
Member

@c71n93 still an issue?

@c71n93
Copy link
Member Author

c71n93 commented Apr 15, 2024

@maxonfjvipon it was resolved

@c71n93 c71n93 closed this as completed Apr 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants