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

run is collecting IO.done value when it's a fun state #25

Closed
steinerkelvin opened this issue May 19, 2022 · 5 comments
Closed

run is collecting IO.done value when it's a fun state #25

steinerkelvin opened this issue May 19, 2022 · 5 comments

Comments

@steinerkelvin
Copy link
Contributor

This panics on the second run because the first one is collecting/clearing the state of Plist.

ctr Nil 0
ctr Cons 2

fun PList 1 {
  !(PList $(Get)) = $(IO.load λx $(IO.done x))
} = $(Cons #111 $(Nil))

run {
  $(IO.call @PList $(Tuple1 $(Get)) λx
  $(IO.done x)
  )
}

run {
  $(IO.call @PList $(Tuple1 $(Get)) λx
  $(IO.done x)
  )
}

cc @racs4

@steinerkelvin steinerkelvin changed the title run is collecting IO.done value when it should not run is collecting IO.done value when it's a fun state May 20, 2022
@steinerkelvin
Copy link
Contributor Author

Actually, even two loads in sequence fail:

ctr Nil 0
ctr Cons 2
ctr Get 0

fun Common 1 {
  !(Common $(Get)) = $(IO.load λx $(IO.done x))
} = $(Cons #111 $(Nil))

run {
  $(IO.call @Common $(Tuple1 $(Get)) λx0
  $(IO.call @Common $(Tuple1 $(Get)) λx1
  $(IO.done #0)
  ))
}

@steinerkelvin
Copy link
Contributor Author

Ok, this can be avoided by dupping the loaded state mannualy:

ctr Nil 0
ctr Cons 2
ctr Get 0

fun Common 1 {
  !(Common $(Get)) = 
    $(IO.load λx
    &{x1 x2} = x;
    $(IO.save x1 λ~
    $(IO.done x2)
    ))
} = $(Cons #111 $(Nil))

run {
  $(IO.call @Common $(Tuple1 $(Get)) λx0
  $(IO.call @Common $(Tuple1 $(Get)) λx1
  $(IO.done $(Tuple2 x0 x1))
  ))
}

The problem is that the contract's state would get linearly dupped away from the actual data by calls to $(Get).

Maybe we could manage the dups internally on calls to IO.load but that seems kinda hellish?

@steinerkelvin
Copy link
Contributor Author

steinerkelvin commented May 20, 2022

Maybe IO.load and IO.save should be replaced by something like IO.dump/IO.copy and IO.swap, respectively:

IO.dump/IO.copy would work like IO.load but would make a full copy of the contract state that you can inspect and use freely, leaving the actual state alone. This would be an expensive operation that should be avoided.

Usage of swap would be:

(IO.swap λx !(f x)  λ~ ..)

meaning you can only access the actual state of the contract if you consume it and immediately provide a new one.

But we would be still missing a way of peeking into the state of the contract.

@VictorTaelin
Copy link
Contributor

Very good job, @quleuber.

@VictorTaelin
Copy link
Contributor

VictorTaelin commented May 21, 2022

Can you test on all the examples you gave, plus as many more as possible?

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