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

refactor: add type candidates and template generators #1361

Merged
merged 3 commits into from
Dec 20, 2021

Conversation

scolsen
Copy link
Contributor

@scolsen scolsen commented Dec 6, 2021

This PR adds two new modules that help with managing user defined types:

  • TypeCandidate: defines a representation of user defined types that aren't yet fully defined. It's used as input for type validation and function/binding generation for user defined types. It simplifies managing user defined types by containing all the information needed for the type in a single structure (e.g., no more need to pair up field xobjs throughout the codebase)
  • TemplateGenerator: Defines an approach for standardizing the generation of function templates based on the contents of type candidates. It abstracts away some of the details involved in defining templates and makes their definition slightly more declarative. It also enables us to unify much of the generic and concrete template code.

This PR also removed SumtypeCase which is no longer needed after the introduction of TypeCandidate. TypeCandidates have TypeFields which do the old job of sumtype cases (and similarly of XObj pairings on the struct/product side).

This commit adds a new module and type, the TypeCandidate, which
represents a potentially valid or invalid type. We use it as the
input for both type validation routines and type binding generation. The
type also allows us to unify the structure of sum types and product
types in an xobj agnostic way, paving the way for future simplification
of binding generation for type definitions.

This commit also removes SumtypeCase.hs, since it's no longer needed.
This commit builds on the TypeCandidate data structure further by
providing "template generators" that work on candidates. Using
generators, templates for type functions ("methods") can be written
almost completely declaratively. Generators also remove some of the
typical boilerplate involved in creating templates from lists of tokens
and enable us to unify several of the generic and concrete templates for
types.

Generators can act on type candidates or their fields (for
field-specific functions). In general, this approach makes the
generation of type templates more structured. A type candidate now
contains all the information a generator needs to create appropriate
templates, thus it is a single and well-defined input for validation and
generation of user defined types.

This commit also updates the Deftype templates to use template
generators.
@scolsen
Copy link
Contributor Author

scolsen commented Dec 6, 2021

Again, the nix build failure seems to stem from nix related set up and is not the result of a failed build or failing tests.

@scolsen scolsen requested a review from a team December 6, 2021 22:19
@eriksvedang
Copy link
Collaborator

From reading your description of the PR, this sounds fabulous! I have yet to dig into the code, might take a few days to get through it.

@scolsen
Copy link
Contributor Author

scolsen commented Dec 7, 2021

Sounds good! Yeah the diff is pretty large. No functionality changes though, so hopefully the new code is easy enough to understand. Let me know if you have any questions!

Copy link
Collaborator

@eriksvedang eriksvedang left a comment

Choose a reason for hiding this comment

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

@scolsen I've read through once now, It looks very good! I want to go over some parts a second time to understand them better before mergeing. Sorry for the review taking a while, last week was super hectic.

@scolsen
Copy link
Contributor Author

scolsen commented Dec 12, 2021

No problem! Let me know if I can help at all.

Copy link
Collaborator

@eriksvedang eriksvedang left a comment

Choose a reason for hiding this comment

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

Alright, I feel like I've got a pretty good overview now! It was a lovely read, really.

Lots of new types, which is great :D

I do worry a little about the abstraction tower "TemplateGenerator > TemplateCreator > Template"; it's not very intuitive. But it definitely does the job, and also brings some more structure to the process.

I have one request before we merge – could you run ./scripts/format.sh on the code?

Apart from that, this is awesome and more than ready for master. Let's kick off a celebratory release once it's in!

@eriksvedang
Copy link
Collaborator

@scolsen Alternatively, I can make a follow up PR where I run the formatter. Might actually be better, the diff from this merge commit will be neater. If that sounds good, I'll just merge as-is.

@eriksvedang eriksvedang merged commit d82e8a5 into carp-lang:master Dec 20, 2021
@scolsen
Copy link
Contributor Author

scolsen commented Dec 24, 2021

@scolsen Alternatively, I can make a follow up PR where I run the formatter. Might actually be better, the diff from this merge commit will be neater. If that sounds good, I'll just merge as-is.

Sorry for missing this--I was away! Thanks for applying the formatting!

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.

2 participants