Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tobybenjaminclark/divinity
๐ช Peoples Prize for HackSheffield9! Dependently typed toy language with LLM-verified holes developed in Rust using Z3 Theorem Prover!
https://github.com/tobybenjaminclark/divinity
compiler dependent-types rust
Last synced: 20 days ago
JSON representation
๐ช Peoples Prize for HackSheffield9! Dependently typed toy language with LLM-verified holes developed in Rust using Z3 Theorem Prover!
- Host: GitHub
- URL: https://github.com/tobybenjaminclark/divinity
- Owner: tobybenjaminclark
- Created: 2024-11-16T12:22:05.000Z (about 1 month ago)
- Default Branch: larry
- Last Pushed: 2024-11-23T19:50:26.000Z (about 1 month ago)
- Last Synced: 2024-11-23T20:29:40.557Z (about 1 month ago)
- Topics: compiler, dependent-types, rust
- Language: Python
- Homepage: https://devpost.com/software/divine-intellect-compiler
- Size: 60.6 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Divine Intellect Compiler
๐ช Dependently typed toy language with holes developed in rust for HackSheffield 9! Developed using Rust, Larlpop and Z3!
View Devpost
ยท
Report Bug
ยท
Request Feature
## About The Project
The **Divine Intellect Compiler** brings together *dependently typed* programming and *large language models* (LLMs) in an experimental way. The compiler uses a toy language called Divinity, where developers can write programs with holes (placeholders) for incomplete code. These holes can then be filled in automatically by an integrated LLM, then verified (proved!).
The key feature of Divine Intellect is its ability to **verify** that the code generated by the LLM is correct. Using dependent types and satisfiability checking, the compiler ensures that any LLM-generated code adheres to the constraints you define. For instance, you can create a `BoundedInt` type to enforce that values must always fall within a specific range.
By combining LLM support with formal verification, the Divine Intellect Compiler allows you to generate code while making sure it meets the necessary requirements and constraints, offering an extra level of assurance that the code is working as expected.
Infact, the Divine Intellect Compiler is inspired by Terry Davis' famous [TempleOS](https://en.wikipedia.org/wiki/TempleOS) system, and surrounding projects such as [HolyC](https://holyc-lang.com/), but with a verification twist.
## Internals & Architecture
High Level Compiler Overview##### Compiler Frontend (Parsing)
Divine Intellect Compiler, uses [lalrpop](https://github.com/lalrpop/lalrpop), a lightweight language for defining grammars in a concise, declarative style, which builds a parser distinct for the given context-free-grammar. Here's an example of one rule, others can be found in `src/calculator1.lalrpop`.```rust
pub FunctionDefinition : Block = {
"fn" "(" > ")" "->" "{" > "}" => {
Block::FunctionDefinition(id, args, ret_type, stmts)
}
}
```##### Program Verification
After we have obtained the program in it's AST form, we can verify this using [Z3 Theorem Prover](https://github.com/Z3Prover/z3). Firstly, we perform a [Static Singular Assignment (SSA) transform](https://en.wikipedia.org/wiki/Static_single-assignment_form), before we encode the program into Z3 and check it's satisfiability.
- Types are given as expressions, i.e. ฯ > 10
- Since Z3 checks satisfiability, the complement is encoded, i.e. ฯ โค 10
- We prove the unsatisfiability of the complement, and the satisfiability of the type to prove correctness.##### Running Code (Interpreter)
The AST is then interpreted directly using a bespoke interpreter written in Rust. This can be found in `src/compile/interpreter.rs`, and supports I/O using `show` and `getint` commands.## Contributing
Since the project was born out of a 24-hour hackathon, there are going to be issues and bugs - note the lack of installation guidance here as an example. If you wish to contribute to Divine Intellect Compiler or Divinity, please feel free to create a feature branch or raise an issue! If you encounter any big issues, or get really stuck - feel free to contact whoever you think is most relevant to the issue you are encountering.1. Fork the Project
2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)
3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)
4. Push to the Branch (`git push origin feature/AmazingFeature`)
5. Open a Pull Request## License
Distributed under the MIT License. See `LICENSE.txt` for more information.
## Contributors
[Amber Swarbrick](https://github.com/aswarbs) - Compiler Implementation
[Toby Clark](https://github.com/tobybenjaminclark) - Verification Algorithm Implementation