Skip to content
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

PoC for interface hierarchies #11978

Closed
cocreature opened this issue Dec 6, 2021 · 2 comments
Closed

PoC for interface hierarchies #11978

cocreature opened this issue Dec 6, 2021 · 2 comments
Assignees

Comments

@cocreature
Copy link
Contributor

No description provided.

@sofiafaro-da
Copy link
Contributor

sofiafaro-da commented Dec 6, 2021

Idea is to have interfaces declare that other interfaces that are required, e.g.

interface B requires A where
  ...

So that when a template T implements interface B, the template T must also implement interface A:

template T
  with ...
  where
    ...
    implements A where ...
    implements B where ...

In LF, this means adding a repeated "requires" field in the interface definition, and checking that the required interface is correctly.

Additionally, we want to change EToInterface and EFromInterface to also allow converting between the interface B and its superinterface A, or introduce new expression forms that allow converting between an interface and its superinterfaces:

     A, B are typecons, 
     (A & B are interfaces and A is a superinterface of B),            // new case
     or (A is an interface and B is a template that implements it)     // existing case
     Γ  ⊢  e : B
   -------------------------------
     Γ  ⊢  EToInterface @A @B e : A 

     A, B are typecons, 
     (A & B are interfaces and A is a superinterface of B),            // new case
     or (A is an interface and B is a template that implements it)     // existing case
     Γ  ⊢  e : A
   -------------------------------
     Γ  ⊢  EFromInterface @A @B e : Optional B 

Then in daml we expose everything as nicely as we can via typeclasses. E.g. we make sure that Implements B A is satisfied, so you can treat B as if it were a template that implements A.

sofiafaro-da added a commit that referenced this issue Dec 6, 2021
Part of #11978

changelog_begin
changelog_end
sofiafaro-da added a commit that referenced this issue Dec 6, 2021
Part of #11978

changelog_begin
changelog_end
sofiafaro-da added a commit that referenced this issue Dec 7, 2021
sofiafaro-da added a commit that referenced this issue Dec 7, 2021
Part of #11978. Adds typechecking for this on the interface and
implementation side.

changelog_begin
changelog_end
remyhaemmerle-da added a commit that referenced this issue Dec 7, 2021
Part of #11978. Adds typechecking for this field on the interface side,
and enforces that any template that implements A must implement B if A requires B.

CHANGELOG_BEGIN
CHANGELOG_END
sofiafaro-da added a commit that referenced this issue Dec 7, 2021
Part of #11978

changelog_begin
changelog_end
sofiafaro-da added a commit that referenced this issue Dec 7, 2021
* interfaces: Add "requires" field in Haskell AST.

Part of #11978. Adds typechecking for this on the interface and
implementation side.

changelog_begin
changelog_end

* Fix all the errors
remyhaemmerle-da added a commit that referenced this issue Dec 7, 2021
Part of #11978. Adds typechecking for this field on the interface side,
and enforces that any template that implements A must implement B if A requires B.

CHANGELOG_BEGIN
CHANGELOG_END
sofiafaro-da added a commit that referenced this issue Dec 7, 2021
remyhaemmerle-da added a commit that referenced this issue Dec 8, 2021
Part of #11978. Adds typechecking for those primitives.

CHANGELOG_BEGIN
CHANGELOG_END
remyhaemmerle-da added a commit that referenced this issue Dec 8, 2021
…#12042)

Part of #11978. Adds typechecking for those primitives.

CHANGELOG_BEGIN
CHANGELOG_END
remyhaemmerle-da added a commit that referenced this issue Dec 8, 2021
Part of #11978. Adds typechecking for those primitives.

CHANGELOG_BEGIN
CHANGELOG_END
remyhaemmerle-da added a commit that referenced this issue Dec 8, 2021
remyhaemmerle-da added a commit that referenced this issue Dec 8, 2021
remyhaemmerle-da added a commit that referenced this issue Dec 8, 2021
sofiafaro-da added a commit that referenced this issue Dec 8, 2021
Adds EToRequiredInterface and EFromRequiredInterface in
the Haskell AST, and the typechecker.

Part of #11978

changelog_begin
changelog_end
sofiafaro-da added a commit that referenced this issue Dec 8, 2021
Adds EToRequiredInterface and EFromRequiredInterface in
the Haskell AST, and the typechecker.

Part of #11978

changelog_begin
changelog_end
remyhaemmerle-da added a commit that referenced this issue Dec 8, 2021
sofiafaro-da added a commit that referenced this issue Dec 8, 2021
Part of #11978.
Adds a test that "requires" is enforced.

changelog_begin
changelog_end
sofiafaro-da added a commit that referenced this issue Dec 8, 2021
Part of #11978.
Adds a test that "requires" is enforced.

changelog_begin
changelog_end
sofiafaro-da added a commit that referenced this issue Dec 9, 2021
Updates the haskell side to be more strict about requirements:
- requirements must be transitively closed, so if A requires B, and B requires C,
  then A requires C.
- no circular requirements allowed

The logic for circular requirements is a bit duplicated to get a better
error message.

Part of #11978

changelog_begin
changelog_end
sofiafaro-da added a commit that referenced this issue Dec 9, 2021
* interfaces: Prevent circular and non-closed reqs

Updates the haskell side to be more strict about requirements:
- requirements must be transitively closed, so if A requires B, and B requires C,
  then A requires C.
- no circular requirements allowed

The logic for circular requirements is a bit duplicated to get a better
error message.

Part of #11978

changelog_begin
changelog_end

* Update compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Check.hs

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>

* take a list in NotClosed error

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
sofiafaro-da added a commit that referenced this issue Dec 9, 2021
Part of #11978

changelog_begin
changelog_end
sofiafaro-da added a commit that referenced this issue Dec 9, 2021
…n LFConversion (#12086)

* interfaces: Support up/downcast in LFConversion

Part of #11978

changelog_begin
changelog_end

* update TODO
realvictorprm pushed a commit that referenced this issue Dec 10, 2021
Part of #11978.
Adds a test that "requires" is enforced.

changelog_begin
changelog_end
realvictorprm pushed a commit that referenced this issue Dec 10, 2021
* interfaces: Prevent circular and non-closed reqs

Updates the haskell side to be more strict about requirements:
- requirements must be transitively closed, so if A requires B, and B requires C,
  then A requires C.
- no circular requirements allowed

The logic for circular requirements is a bit duplicated to get a better
error message.

Part of #11978

changelog_begin
changelog_end

* Update compiler/daml-lf-tools/src/DA/Daml/LF/TypeChecker/Check.hs

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>

* take a list in NotClosed error

Co-authored-by: Moritz Kiefer <moritz.kiefer@purelyfunctional.org>
realvictorprm pushed a commit that referenced this issue Dec 10, 2021
…n LFConversion (#12086)

* interfaces: Support up/downcast in LFConversion

Part of #11978

changelog_begin
changelog_end

* update TODO
sofiafaro-da added a commit that referenced this issue Dec 10, 2021
part of: #11978

ghc counterpart: digital-asset/ghc#92

changelog_begin
changelog_end
sofiafaro-da added a commit that referenced this issue Dec 10, 2021
Part of #11978

changelog_begin
changelog_end
sofiafaro-da added a commit that referenced this issue Dec 14, 2021
* interfaces: Implement 'requires' syntax

part of: #11978

ghc counterpart: digital-asset/ghc#92

changelog_begin
changelog_end

* .

* ...

* ...

* ....

* ....

* update bazel-haskell-deps

* use requires syntax in tests

* .......

* .......

* update bazel-haskell-deps

* update InterfaceDesugared

* .........

* update bazel-haskell-deps

* ...........

* update bazel-haskell-depos

* update compile.yml

* update bazel-haskell-deps
sofiafaro-da added a commit that referenced this issue Dec 14, 2021
Part of #11978

changelog_begin
changelog_end
@sofiafaro-da
Copy link
Contributor

This proof-of-concept has been implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants