-
Notifications
You must be signed in to change notification settings - Fork 79
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
Extensible variants #295
Comments
Oops. The dreaded subtype check again. :( |
One solution that might work, and even be simpler than what we have right now, is a middle ground between the previous solution (backtracking in We go back to backtracking decoding with Examples:
Benefits and notes:
|
Hm, yes, this sounds plausible and attractive to me. Just one question for clarification, You said:
Don't you mean "decode untyped values" here? That all makes sense to me, because it is closer to the original intention of the serialisation format simply describing values. Only once we optimised it by hoisting out structural information as types, we started considering stricter tests. That isn't really necessary for first-order values. However, for higher-order values (esp functions with negative type information), we handle them as if they were explicitly type-annotated and check that annotation. |
I mean typed, because we need the type information once we hit a reference. But for the other values, we just destruct the type as we go, but don't use it otherwise. (Previously, we could completely throw away the type after decoding but before coercion.) |
This sounds way more attractive. Do you have a draft spec change? |
No, I shied away from writing that on the phone |
I discovered this issue from the section on Candid variant extensibility in @roman-kashitsyn's blog post and I'm wondering if I understand things correctly. The blog post suggests making variant fields (such as
My concerns with this are:
My questions are:
Given that all of my variants are named, perhaps a simpler approach is to convert Thanks in advance. |
Yes, we would love to hear a better alternative.
By virtual of subtyping, it's okay (or even a space optimization) to omit a variant tag if the value doesn't contain that tag. The subtyping rule also allows to upgrade any type |
If you want a variabnt to be extensible, you have to put the whole variant in an (On the phone, sorry for terseness) |
I think the confusion is that the example on the post has two variant types, and it may not be clear which one is going to be extensible - Result or the Error values. |
When we designed the solution for extensible records, with special rules for
opt
so that they can be used in record fields, we thought we had also solved it dually for variants, as long as the variant itself is wrapped inopt
.And that was certainly true in the iteration that did a dynamic value-based check: if the tag was known, decoding would work; if it was a new, unknown tag, it would fail and turn to
null
.But later (for good reason) we switched to a type-based check, decoding as
null
any value if the type isn't a subtype of the expected type. But in the record extension case, the extended variant isn't a subtype of the expected type, so now all values map tonull
. Which is not what we wanted, I believe.This just came up in potential practice in https://forum.dfinity.org/t/enable-canisters-to-hold-icp/6153/167?u=nomeata
Not sure what to do about it, though. Besides maybe some
variant
-specific solution, e.g. some way to explicitly or implicitly declare a nullary tag as the default.The text was updated successfully, but these errors were encountered: