-
Notifications
You must be signed in to change notification settings - Fork 111
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
feat: preserve named types in semantic types and when translating between Motoko and Candid #4943
Open
crusso
wants to merge
22
commits into
master
Choose a base branch
from
claudio/named-types
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,164
−949
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading status checks…
…rough Named types
This is what base/OrderedMap renders as:
|
Loading status checks…
…claudio/named-types
crusso
commented
Mar 13, 2025
crusso
commented
Mar 13, 2025
crusso
commented
Mar 13, 2025
crusso
commented
Mar 13, 2025
crusso
commented
Mar 13, 2025
crusso
commented
Mar 13, 2025
Loading status checks…
…claudio/named-types
Fixes #4344. |
luc-blaeser
approved these changes
Mar 21, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for doing this PR. Let's merge.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Inspired by discussion with @giorgiopiatti-dfinity
Both Motoko and Candid support syntactically named types for more informative type (especially function) signatures.
Eg.
vs.
These are purely syntactic and erased from the syntax before type checking. They are not preserved by type checking nor by translation to Candid.
This PR attempts to preserve name types throughout front-end type checking to produce better Candid and more informative types. Named types are erased, along with type fields, in early IR pass erase_typ_fields, so most ir passes are unaffected.
This requires fairly extensive surgery to ignore names in various operations on types, e.g. sub-typing and type equivalence.
Example Candid output:
names.mo:
now produces Candid:
In comparison, master branch produces:
To avoid information overload, we suppress names under object fields, tags and options.
TODO:
[ ] perhaps drop names when reporting type errors, since they lead to spurious syntactic differences (either by erasing names before printing or instructing the printer to drop names in certain contexts (e.g. when displaying two types that should be related).
[x]
add space before around colon(current is consistent with current formatting of candid fields/tags)[x] suppress names under object fields, tags and options (too much information)