-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Translate function bodies to Isabelle/HOL (#2868)
* Closes #2813 Implements a translation from Juvix functions to Isabelle/HOL functions. This extends the previous Juvix -> Isabelle translation which could handle only type signatures. Checklist --------- - [x] Basic translation - [x] Polymorphism - [x] Arithmetic operators - [x] Numeric literals - [x] List literals - [x] Comparison operators - [x] Boolean operators - [x] `if` translated to Isabelle `if` - [x] `true` and `false` translated to Isabelle `True` and `False` - [x] `zero` and `suc` translated to Isabelle `0` and `Suc` - [x] `Maybe` translated to Isabelle `option` - [x] Pairs translated to Isabelle tuples - [x] Quote Isabelle identifier names (e.g. cannot begin with `_`) - [x] Rename variables to avoid clashes (in Isabelle/HOL pattern variables don't shadow function identifiers) - [x] Common stdlib functions (`map`, `filter`, etc) translated to corresponding Isabelle functions - [x] Multiple assignments in a single `let` - [x] CLI - [x] Test - The test is very fragile, similar to the markdown test. It just compares the result of translation to Isabelle against a predefined expected output file. Limitations ----------- The translation is not designed to be completely correct under all circumstances. There are aspects of the Juvix language that cannot be straightforwardly translated to Isabelle/HOL, and these are not planned to ever be properly handled. There are other aspects that are difficult but not impossible to translate, and these are left for future work. Occasionally, the generated code may need manual adjustments to type-check in Isabelle/HOL. In particular: * Higher-rank polymorphism or functions on types cannot be translated as these features are not supported by Isabelle/HOL. Juvix programs using these features will not be correctly translated (the generated output may need manual adjustment). * In cases where Juvix termination checking diverges from Isabelle/HOL termination checking, providing a termination proof manually may be necessary. Non-terminating Juvix functions cannot be automatically translated and need to be manually modelled in Isabelle/HOL in a different way (e.g. as relations). * Comments (including judoc) are ignored. This is left for future work. * Traits are not translated to Isabelle/HOL type classes / locales. This is left for future work. * Mutually recursive functions are not correctly translated. This is left for future work. * Record creation, update, field access and pattern matching are not correctly translated. This is left for future work. * Named patterns are not correctly translated. This is left for future work. * Side conditions in patterns are not supported. This is left for future work. * If a Juvix function in the translated module has the same name as some function from the Isabelle/HOL standard library, there will be a name clash in the generated code. --------- Co-authored-by: Paul Cadman <[email protected]>
- Loading branch information
1 parent
2793514
commit 83837b9
Showing
32 changed files
with
1,507 additions
and
94 deletions.
There are no files selected for viewing
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
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
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
Submodule juvix-stdlib
updated
29 files
+5 −4 | Package.juvix | |
+10 −13 | Stdlib/Cairo/Ec.juvix | |
+4 −17 | Stdlib/Cairo/Poseidon.juvix | |
+1 −0 | Stdlib/Data/Bool/Base.juvix | |
+13 −21 | Stdlib/Data/List/Base.juvix | |
+1 −1 | Stdlib/Data/Maybe/Base.juvix | |
+3 −7 | Stdlib/Data/Pair.juvix | |
+2 −2 | Stdlib/Data/Pair/Base.juvix | |
+3 −11 | Stdlib/Data/Range.juvix | |
+5 −14 | Stdlib/Data/Result/Base.juvix | |
+1 −2 | Stdlib/Data/String/Base.juvix | |
+1 −8 | Stdlib/Extra/Gcd.juvix | |
+1 −2 | Stdlib/Function.juvix | |
+2 −4 | Stdlib/System/IO.juvix | |
+1 −2 | Stdlib/System/IO/Bool.juvix | |
+1 −2 | Stdlib/System/IO/Int.juvix | |
+1 −2 | Stdlib/System/IO/Nat.juvix | |
+1 −2 | Stdlib/System/IO/String.juvix | |
+2 −0 | Stdlib/Trait/DivMod.juvix | |
+2 −2 | Stdlib/Trait/Eq.juvix | |
+1 −0 | Stdlib/Trait/Integral.juvix | |
+4 −4 | Stdlib/Trait/Ord.juvix | |
+2 −1 | Stdlib/Trait/Ord/Eq.juvix | |
+2 −4 | Stdlib/Trait/Partial.juvix | |
+5 −8 | test/Package.juvix | |
+43 −117 | test/Test.juvix | |
+2 −4 | test/Test/Arb.juvix | |
+1 −2 | test/Test/StdlibTestExtra.juvix | |
+1 −1 | test/juvix.lock.yaml |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Juvix.Compiler.Backend.Isabelle.Extra where | ||
|
||
import Juvix.Compiler.Backend.Isabelle.Language | ||
|
||
mkApp :: Expression -> [Expression] -> Expression | ||
mkApp fn = \case | ||
[] -> fn | ||
arg : args -> mkApp (ExprApp (Application fn arg)) args |
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
Oops, something went wrong.