daml icon indicating copy to clipboard operation
daml copied to clipboard

Enforce return types on interface view types

Open cocreature opened this issue 2 years ago • 9 comments

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.

cocreature avatar Jul 28 '22 16:07 cocreature

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

  1. a reference to a record type with no type arguments, or
  2. unit

So the LF representation of DefInterface#view can be a lot smaller than Type.

S11001001 avatar Jul 28 '22 16:07 S11001001

I'm not sure we want to allow unit. That still means we cannot just expose a Record on the ledger API.

cocreature avatar Jul 28 '22 16:07 cocreature

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 ().

S11001001 avatar Jul 28 '22 16:07 S11001001

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.

cocreature avatar Aug 02 '22 06:08 cocreature

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 ().

S11001001 avatar Aug 02 '22 15:08 S11001001

Do you mean, "it must be present, and must refer to a record type with no type arguments"?

yes

cocreature avatar Aug 02 '22 15:08 cocreature

It already would be, I'd wager. #14456 contains 79 uses of viewtype ().

Many of them are typechecked, too, unfortunately.

dylant-da avatar Aug 02 '22 16:08 dylant-da

Many of them are typechecked, too, unfortunately.

True but

data EmptyInterfaceView = EmptyInterfaceView {}

viewtype EmptyInterfaceView

doesn’t seem that terrible.

cocreature avatar Aug 02 '22 17:08 cocreature

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

dylant-da avatar Aug 08 '22 16:08 dylant-da

Fixed by https://github.com/digital-asset/daml/pull/14802 and https://github.com/digital-asset/daml/pull/14932

akrmn avatar Sep 07 '22 11:09 akrmn