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

Naive compilation of complex pattern matches with match-expressions to decision trees with case-expressions #1531

Closed
lukaszcz opened this issue Sep 13, 2022 · 0 comments · Fixed by #1824
Assignees
Labels
core Related to JuvixCore enhancement New feature or request pattern-matching

Comments

@lukaszcz
Copy link
Collaborator

lukaszcz commented Sep 13, 2022

This should be implemented as a transformation on the core which compiles the 'Match' nodes into multiple 'Case' nodes. At first, we may implement an inefficient naive algorithm. A more efficient version will be implemented later (issue #1798).

@lukaszcz lukaszcz added enhancement New feature or request pending-review pattern-matching core Related to JuvixCore labels Sep 13, 2022
@lukaszcz lukaszcz added this to the 0.3 milestone Sep 13, 2022
lukaszcz added a commit that referenced this issue Jan 9, 2023
An implementation of the translation from JuvixCore to JuvixAsm. After
merging this PR, the only remaining step to complete the basic
compilation pipeline (#1556) is the compilation of complex pattern
matching (#1531).

* Fixes several bugs in lambda-lifting.
* Fixes several bugs in the RemoveTypeArgs transformation.
* Fixes several bugs in the TopEtaExpand transformation.
* Adds the ConvertBuiltinTypes transformation which converts the builtin
bool inductive type to Core primitive bool.
* Adds the `juvix dev core strip` command.
* Adds the `juvix dev core asm` command.
* Adds the `juvix dev core compile` command.
* Adds two groups of tests: 
- JuvixCore to JuvixAsm translation: translate JuvixCore tests to
JuvixAsm and run the results with the JuvixAsm interpreter,
- JuvixCore compilation: compile JuvixCore tests to native code and WASM
and execute the results.
* Closes #1520 
* Closes #1549
paulcadman added a commit that referenced this issue Feb 1, 2023
Core transformations apply to the whole InfoTable, the REPL needs to
apply Core transformations to the single node that it compiles from the
user input string.

The solution in this commit is to:

1. Compile the input string as before to obtain a Core Node.
2. Add this Node to a copy of the Core InfoTable for the loaded file.
3. Apply the (CLI specified) Core transformations to this InfoTable.
4. Extract the (now transformed) Node from the InfoTable.

We can think of a way to improve this, maybe when we tackle allowing the
user to make new definitions in the REPL.

As soon as compilation of pattern matching is complete we should enable
some (all?) Core transformations by default.

Example:

At the moment we get the following result in the REPL:

```
juvix repl
...
Stdlib.Prelude> 1 + 1
suc (suc zero)
```

After this commit we can turn on `nat-to-int` transformation:

```
juvix repl -t nat-to-int
Stdlib.Prelude> 1 + 1
2
```

* Part of #1531
@lukaszcz lukaszcz changed the title Compile complex pattern matching with match-expressions to decision trees with case-expressions Naive compilation of complex pattern matches with match-expressions to decision trees with case-expressions Feb 1, 2023
@lukaszcz lukaszcz linked a pull request Feb 9, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Related to JuvixCore enhancement New feature or request pattern-matching
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants