eo icon indicating copy to clipboard operation
eo copied to clipboard

A new value is not saved by cage

Open dours opened this issue 3 years ago • 3 comments

+package preface
+alias cage org.eolang.cage
+junit

[] > test
  [init] > mycage
    [value] > wrapper
    cage (wrapper init) > value
    [new-value] > write
      value.write (wrapper new-value) > @
    value.value > @
  mycage 0 > c
  seq > @
    c
    c.write 1
    c.eq 1

dours avatar Aug 30 '22 21:08 dours

@mximp can you try?

yegor256 avatar Aug 31 '22 11:08 yegor256

@dours What is the result of dataization? Is the snippet above valid? I don't get what would be the result of dataization for:

[value] > wrapper

It has no @.

mximp avatar Sep 01 '22 07:09 mximp

@mximp The snippet above is written as an EO test. So, a result of dataization of the whole snippet should be boolean TRUE. It is in fact boolean FALSE. Which means that the snippet is dataizable, though the result is incorrect (IMHO).

The wrapper object is not dataizable. But it is never dataized. It is used as a trivial container for other objects. For integers in this case. An integer is wrapped into wrapper and saved into cage by mycage object. It is explicitly extracted from the wrapper each time it is used in this line value.value > @ of the mycage object.

dours avatar Sep 01 '22 12:09 dours

If we remove first statement in seq the snippet works fine. It also works fine if replace wrapper with plain data.

It is still not clear why it fails. Need to add more logging to understand what's happening inside.

mximp avatar Sep 27 '22 19:09 mximp

After further analysis - the issue is in internal caching. In the initial example after first c within seq the c.@ is calculated which becomes mycage.@=value.value=0. And it's cached. Next time we try to calculate c.eq it will pick 0.eq regardless of previous c.write 1.

If we change @ to some custom attribute the code works as expected:

[] > test
  [init] > mycage
    [value] > wrapper
    cage (wrapper init) > value
    [new-value] > write
      value.write (wrapper new-value) > @
    value.value > res
  mycage 0 > c
  seq > @
    c
    c.write 1
    c.res.eq 1

It also work well if we try to access value directly:

[] > test
  [init] > mycage
    [value] > wrapper
    cage (wrapper init) > value
    [new-value] > write
      value.write (wrapper new-value) > @
    value.value > @
  mycage 0 > c
  seq > @
    c
    c.write 1
    c.value.value.eq 1

@yegor256 is caching for @ attribute is somewhat designed initially? Is my logic correct here or I'm missing something?

mximp avatar Oct 03 '22 13:10 mximp

@mximp you are right. We have a special annotation @Volatile in the runtime, which is attached to EOcage: https://github.com/objectionary/eo/blob/0.28.7/eo-runtime/src/main/java/EOorg/EOeolang/EOcage.java#L44 Thanks to this annotation, cage is "volatile" and doesn't have this @-caching logic. However, if we decorate cage, this new object is not volatile anymore.

yegor256 avatar Oct 03 '22 17:10 yegor256

@dours So this behaviour is by design. Is it clear how to workaround the issue?

mximp avatar Oct 04 '22 11:10 mximp