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

A new value is not saved by cage #1127

Closed
dours opened this issue Aug 30, 2022 · 7 comments
Closed

A new value is not saved by cage #1127

dours opened this issue Aug 30, 2022 · 7 comments
Assignees
Labels
Milestone

Comments

@dours
Copy link
Contributor

dours commented Aug 30, 2022

+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
@yegor256
Copy link
Member

@mximp can you try?

@mximp
Copy link
Contributor

mximp commented Sep 1, 2022

@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 @.

@dours
Copy link
Contributor Author

dours commented Sep 1, 2022

@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.

@mximp
Copy link
Contributor

mximp commented Sep 27, 2022

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
Copy link
Contributor

mximp commented Oct 3, 2022

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?

@yegor256
Copy link
Member

yegor256 commented Oct 3, 2022

@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.

@mximp
Copy link
Contributor

mximp commented Oct 4, 2022

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

@mximp mximp assigned dours and unassigned mximp Oct 10, 2022
@mximp mximp added this to the M3 milestone May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants