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

Merge DHExp and UExp #1197

Merged
merged 114 commits into from
Jul 31, 2024
Merged

Merge DHExp and UExp #1197

merged 114 commits into from
Jul 31, 2024

Conversation

Negabinary
Copy link
Contributor

@Negabinary Negabinary commented Feb 6, 2024

Motivation:

Implements #878,

The advantages of merging DHExp and UExp are:

  • Removing duplication of code, making it easier & quicker to add new features to the Hazel language
  • Consistency between evaluation results and written code - making easier to copy outputs into code, or to edit outputs, etc.
  • Creating a consistency between the way static and dynamic code are pretty-printed, hopefully eventually replacing the pretty printer
  • Tracing of ids through code allows us to correspond each construct from an output with the construct in the input

This pr replaces #931 which replaced #857. I have started again (using the previous iterations as inspiration) because the codebase has changed too much since those prs.

Key Changes

  • DHExp is no longer a separate data structure to UExp.
  • Fixpoints are now surfaced in user expressions
  • Elaboration has been rewritten to more closely match elaboration rules from the POPL 2019 paper.
  • Pattern matching has been rewritten to separate out an "unboxing" routine.
  • Patterns can now have casts

How to Merge with this PR:

If you used any dynamic expressions (DHExp) before the merge:

You will need to replace these with terms from TermBase.re. Most constructs retain the same name, the complication is that TermBase.re terms also have Ids. The following functions should help you add ids to terms:

  • When creating a new term add |> Exp.fresh, |> Pat.fresh, or |> Typ.temp to the end of the construct. (e.g. IntLit(4) becomes Int(4) |> Exp.fresh). Typ.temp is preferred over Typ.fresh because fresh generates new ids which can slow down type operations where types are often created then thrown out quickly. Ids are added to Typ.t values before they are printed to the screen.
  • When pattern matching on a term, switch (exp) will usually become switch (exp.term). If you want to pattern match on a term and then wrap it back up with the same Id, you can use Exp.unwrap and rewrap. (There are many examples of this in Term.re)

If you have added any new constructs to DHExp:

  • First, you'll need to make sure that there are constructs in TermBase.re that can store these dynamic expressions.
  • Then you'll need to adapt your elaborator code to use only these constructs, and to make sure that all the types match up (we're no longer relying on statics information to provide types for elaboration.)

If you have added any new constructs to TermBase.re that are removed at elaboration:

Since the pre- and post-elaboration data structures are the same, it's now preferred not to have elaboration remove constructs. (This also makes stepper traces more readable.) You might need to add transition rules and DHDoc_Exp rules for your new constructs.

If you have made any new "value" expressions:

I've tried to clarify how casting works in Unboxing.re. If you have a new value type, you might find it easier to write Transition.re rules if you add a new unbox_request constructor to Unboxing.re

@cyrus- cyrus- marked this pull request as draft May 13, 2024 18:38
@Negabinary Negabinary marked this pull request as ready for review May 16, 2024 20:20
@cyrus-
Copy link
Member

cyrus- commented May 27, 2024

  • Needs some conflicts resolved
  • The polymorphism casting seems to have some issues (see Polymorphism under documentation):

image

@Crazycolorz5
Copy link
Contributor

Crazycolorz5 commented May 27, 2024

The casting in the documentation page seems to be an issue with -> associativity -- adding parens like so removes that:
image
However, after doing so, I do get an "InvalidBoxedIntLit" error, which I am now investigating.

@Crazycolorz5
Copy link
Contributor

The current branch also seems to not inherit bound names in stepped code / function output. E.g. in Cyrus's comment above you can see several . Additionally, see the screenshot:

image

See (c119777) also for how this was extended to type functions.

@Crazycolorz5
Copy link
Contributor

image

Seems to be not a polymorphism in particular. This is a minimal reproducible example. It seems to be an error in the term_of -- somehow the internal variable binding isn't being looked up?

@Negabinary
Copy link
Contributor Author

Ah yeah thanks @Crazycolorz5 - it was an issue with the transition rules for builtin application not using the evaluated version of the argument.

@cyrus-
Copy link
Member

cyrus- commented Jun 7, 2024

@Negabinary couple of conflicts to resolve here

@cyrus-
Copy link
Member

cyrus- commented Jul 25, 2024

@Negabinary looks like we've got quite a few merge conflicts here -- can you resolve those?

src/haz3lcore/dynamics/TypeAssignment.re Outdated Show resolved Hide resolved
src/haz3lcore/zipper/EditorUtil.re Show resolved Hide resolved
src/haz3lweb/Update.re Outdated Show resolved Hide resolved
src/haz3lcore/lang/Form.re Outdated Show resolved Hide resolved
src/haz3lcore/statics/Term.re Outdated Show resolved Hide resolved
src/haz3lcore/lang/term/Typ.re Show resolved Hide resolved
src/haz3lcore/lang/term/Typ.re Show resolved Hide resolved
@cyrus- cyrus- merged commit 40d1896 into dev Jul 31, 2024
2 checks passed
@cyrus- cyrus- deleted the remove-dhexp branch July 31, 2024 18:26
@Negabinary Negabinary mentioned this pull request Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in-development for PRs that remain in development
Projects
None yet
4 participants