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

Design for polymorphic IDL types #611

Closed
wants to merge 2 commits into from
Closed

Design for polymorphic IDL types #611

wants to merge 2 commits into from

Conversation

chenyan-dfinity
Copy link
Contributor

No description provided.

@@ -117,6 +117,34 @@ In addition to this basic grammar, a few syntactic shorthands are supported that
| <name> := <name> : null (only in variants)
```

We also support polymorphic type definitions as syntactic shorthands that will be compiled to the basic forms:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking more about it, maybe we should just support polymorphism in the core grammar, instead of syntactic shorthands. It's up to the codegen for the target language to decide if they want to do monomorphization. If the target language supports polymorphism, the generated binding will be more readable this way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that easy. If you wanted to enable dispatching to monomorphised definitions on the callee end then you'd need to provide type information to do that with (the values are not generally enough). So we'd need to do type passing as evidence, and ways to construct/destruct that, which adds a whole layer of complexity (plus enables polymorphism to become non-parametric, which may be undesirable).

Copy link
Contributor

@rossberg rossberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks okay as far as syntax goes, but it doesn't fully define semantics. Type constructors introduce extra complexity regarding recursion, since you must ensure that their expansion always terminates. One way to enforce that is by requiring that all recursion is uniform, but that is a somewhat non-trivial check (which is the reason why we haven't even implemented that check in AS yet :) ).

So I'm somewhat hesitant to spend time on this right now, and would rather suggest deferring it until after devnet launch. WDYT?

@@ -117,6 +117,34 @@ In addition to this basic grammar, a few syntactic shorthands are supported that
| <name> := <name> : null (only in variants)
```

We also support polymorphic type definitions as syntactic shorthands that will be compiled to the basic forms:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not that easy. If you wanted to enable dispatching to monomorphised definitions on the callee end then you'd need to provide type information to do that with (the values are not generally enough). So we'd need to do type passing as evidence, and ways to construct/destruct that, which adds a whole layer of complexity (plus enables polymorphism to become non-parametric, which may be undesirable).

<typ-args> ::= < <typ>,* >
```

Polymorphism is only allowed in the type definitions. `<reftype>` and `<actor>` are always monomorphic. Type definitions are duplicated (monomorphized) to the basic forms according to the different instantiations of `<typ-args>`. For example, the following code
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be precise, this isn't polymorphism (type lambdas on the term level), it's type constructors (lambdas on the type level). So I would avoid talking about polymoprhism and monomorphisation. Better call it parameterised type definitions that get expanded.

@nomeata nomeata removed their request for review August 27, 2019 07:37
@nomeata
Copy link
Collaborator

nomeata commented Sep 13, 2019

Shall we close this until we know we want to go there?

@chenyan-dfinity
Copy link
Contributor Author

Sure, let's close this. Even Rust doesn't need IDL support for polymorphism, so we are good.

@nomeata nomeata deleted the idl-poly branch April 30, 2021 16:50
@nomeata nomeata restored the idl-poly branch April 30, 2021 16:50
@nomeata nomeata deleted the idl-poly branch April 30, 2021 16:50
dfinity-bot added a commit that referenced this pull request Feb 22, 2024
## Changelog for motoko-base:
Branch: next-moc
Commits: [dfinity/motoko-base@520ccf5d...712d0587](dfinity/motoko-base@520ccf5...712d058)

* [`cba05e81`](dfinity/motoko-base@cba05e8) Publish on Mops ([dfinity/motoko-base⁠#618](https://togithub.com/dfinity/motoko-base/issues/618))
* [`d81f5527`](dfinity/motoko-base@d81f552) Add commit hash to `matchers` dependency ([dfinity/motoko-base⁠#621](https://togithub.com/dfinity/motoko-base/issues/621))
* [`c86d76ff`](dfinity/motoko-base@c86d76f) doc: update `List.mo` ([dfinity/motoko-base⁠#616](https://togithub.com/dfinity/motoko-base/issues/616))
* [`4c2a90e7`](dfinity/motoko-base@4c2a90e) Fix compiler warning in `Array.take()` method ([dfinity/motoko-base⁠#611](https://togithub.com/dfinity/motoko-base/issues/611))
mergify bot pushed a commit that referenced this pull request Feb 22, 2024
## Changelog for motoko-base:
Branch: next-moc
Commits: [dfinity/motoko-base@520ccf5d...712d0587](dfinity/motoko-base@520ccf5...712d058)

* [`cba05e81`](dfinity/motoko-base@cba05e8) Publish on Mops ([dfinity/motoko-base⁠#618](https://togithub.com/dfinity/motoko-base/issues/618))
* [`d81f5527`](dfinity/motoko-base@d81f552) Add commit hash to `matchers` dependency ([dfinity/motoko-base⁠#621](https://togithub.com/dfinity/motoko-base/issues/621))
* [`c86d76ff`](dfinity/motoko-base@c86d76f) doc: update `List.mo` ([dfinity/motoko-base⁠#616](https://togithub.com/dfinity/motoko-base/issues/616))
* [`4c2a90e7`](dfinity/motoko-base@4c2a90e) Fix compiler warning in `Array.take()` method ([dfinity/motoko-base⁠#611](https://togithub.com/dfinity/motoko-base/issues/611))
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

Successfully merging this pull request may close these issues.

3 participants