Replies: 1 comment
-
This is pretty much the pattern that OrderedMap is using, and it also works for mutable state. This reminds me of the small orderedset examples I worked out here: functional, imperative and class based. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an idea that I'd like to discuss as an alternative to the 'stable functions PR'.
Why: What are the issues with the PR:
Goals
transient
keyword and have all thingsstable
. While this is a nice simplification. I'm not sure with the current PR this is worth complicating other aspects of developing in Motoko.transient
we can develop a partial solution that allows us to compile more cases asstable
. I have an idea to support stable definitions of classes in a restricted context, but the one that appears common in practiceIdea
transient
but it does not mean that its state is discarded on each upgrade. The state of the class is explicitly stored in the app-code and made persistent over upgrades.Stable classes as (stable data + transient funcs)
The idea is to compile classes by separating out their
stable
data and persisting only that, and hiding thetransient
nature of the object with funcs.Stable classes would need to be desugared to classes with no internal state (no internal fields), where state is passed via the constructor.
Why it might work?
Cls(args)
on each upgrade whenargs
are persistently stored as an actor field. This means that we can desugarlet c = Cls(args)
toWhat about
args
that have functions inside, e.g.args = (arg, Int.compare)
? We don't need to persistInt.compare
. We should decomposeargs
into a set of stable fields:I guess this is tricky to communicate. However, when trying to provide a migration function the compiler would know the required type. User would only need to inspect the inferred type.
Restrictions:
This means that classes are not considered
stable
, it only means that some classes can be transformed to stable code...Migrations
let c = Cls(args)
to a newlet c' = Cls'(args')
User would need to translate the
c
record like{ arg1; ...; argN }
(with names taken from the Cls) to a recordc'
with its stable state.Beta Was this translation helpful? Give feedback.
All reactions