experiment: approximate stable as shared types in view queries#5913
experiment: approximate stable as shared types in view queries#5913
Conversation
…that have no view but are shared, renable auth
…t-end can see them, but other canisters cannot
Backs out the support for user-define isAdmin predicates
|
I'm a bit worried about this, as it might give the indication that data is missing. For example, since we don't have a view function for You'd get I'm surprise by the shouldn't that be |
Yeah, that's probably true. I was hoping to have approximation: With the However, Motoko subtyping doesn't allow I guess another alternative might be to make the approximation apparent in the type of the generated query: __non_shared_array: () -> (variant { approximately : vec reserved }) query; (so we wrap an approximately on the outside of query result, for clarity).
The code actually defines a view for mutable arrays. The view returns an immutable sub-array of the mutable array, so it is just approximating the contents of the mutable array (dropping mutable |
Builds on #5796 (simplifying the stable to shared type approximation of #5913) @christoph-dfinity here's the version that always approximates to Any. I think this might actually be more alarming and a lot less informative than just dropping a few fields and promoting to Any in offending positions but at least it's simple. It does give an indication that each stable variable contains something, at least. (Marked do not merge because I want to switch the base to #5796)
Builds on #5796
#5796 requires the result of a generated view query to be shared, omitting viewers for stable vars that contain non-shared mutable data.
This PR relaxes that restriction by requiring them to just be stable and, if non-shared, coercing them to the nearest shared supertype by (recursively) erasing mutable fields and promoting mutable arrays to
Any.The type approximation is done by
Type.shared_of_stablewhich returns a shared supertype of a given stable type.The value of stable type can always be directly cast to the shared type via a no-cost upcast (subsumption).
This means a stable variable will always be displayed in some form, degrading to just
Anyin the worst case, but typically more informative than that.NB. It would be nice if we could approximate a mutable object field by a field of type
Any, but that's not allowed by subtyping at the moment. Instead, we just drop the field.For example, with a simple .viewer for mutable arrays,
the following (mixed) stable var signature:
.most
produces: