daml
daml copied to clipboard
Enforce return types on interface view types
The design tries to keep the view types equivalent to templates, i.e., records with no type arguments. Daml Engine & the typechecker does not.
We need to change one of the two. I think changing Daml Engine makes more sense.
I believe this matches the rules we want:
https://github.com/digital-asset/daml/blob/531221da73fe69756b0f7c0b6e026ad64097c8f5/daml-lf/interface/src/main/scala/com/digitalasset/daml/lf/iface/reader/InterfaceReader.scala#L248-L256
In other words
- a reference to a record type with no type arguments, or
- unit
So the LF representation of DefInterface#view
can be a lot smaller than Type
.
I'm not sure we want to allow unit. That still means we cannot just expose a Record
on the ledger API.
We can use absence of a Record
in the InterfaceView
as a representation of ()
. e: ~~This would mean either it's ()
or include_interface_views=false
. Is that a problem?~~ e2: Or absence of the InterfaceView
itself means the latter. I'm not 100% sure of the semantics here, as I've only been concerned with cases where include_interface_views=true
.
One thing that was unclear from the design was whether a view would be required. It makes sense to me that it wouldn't be required, but permitting ()
is functionally identical.
On the ledger API, we can interpret absence of a view as just stated, though it might make more sense to just reject transaction filters that specify interfaces whose viewtype is ()
.
Currently we make it mandatory and I’d keep this. It means interface subscriptions always work exactly like template subscriptions and there are no interfaces you cannot subscribe to or get no meaningful return value. Relaxing it later to make them optional is also backwards compatible while the inverse isn’t so I’d start with the more restricted version.
If in our tests this becomes fairly annoying, we can define a shared record type (like Archive) that we use instead of unit where we don’t care about the view.
we make it mandatory and I’d keep this
@cocreature Do you mean, "it must be present, and must refer to a record type with no type arguments"?
If in our tests this becomes fairly annoying
It already would be, I'd wager. #14456 contains 79 uses of viewtype ()
.
Do you mean, "it must be present, and must refer to a record type with no type arguments"?
yes
It already would be, I'd wager. #14456 contains 79 uses of
viewtype ()
.
Many of them are typechecked, too, unfortunately.
Many of them are typechecked, too, unfortunately.
True but
data EmptyInterfaceView = EmptyInterfaceView {}
viewtype EmptyInterfaceView
doesn’t seem that terrible.
data EmptyInterfaceView = EmptyInterfaceView {} viewtype EmptyInterfaceView
doesn’t seem that terrible.
You're right it looks fine - started work on this in https://github.com/digital-asset/daml/tree/non-unit-viewtypes
Fixed by https://github.com/digital-asset/daml/pull/14802 and https://github.com/digital-asset/daml/pull/14932