Comments (6)
Oh, I've found libstd.chalk. It's a start, I guess, but some answers to the above would still save me a lot of time and print statements.
from chalk.
chalk
implements the trait system of Rust in a different (and cleaner?) way than the Rust compiler itself. Since it is a complex and non-trivial part of the compiler, it is good to have a separate "reference" implementation.
A .chalk
file is a stripped down version of Rust code where only types, traits and impls are declared (without actual code). Given the .chalk
file, chalk
can answer questions about the program like "does this type implement this trait" or "does this parameterized type implement this trait for each possible parameter" et cetera. The complete grammar can be found in the .lalrpop
file in this repository. (Sorry, I am typing this on my phone so can't easily lookup the exact name.)
Another use case for chalk
is to be able to test how certain additions (higher kinded types, etc) to the type system impact the whole system. It is probably much easier to implement experimental changes here, than in the Rust compiler. And hence, weird edge cases, inconsistencies, etc can be found earlier.
I think it is a good idea to have a tool which extracts a .chalk
file from an actual Rust source file. However, no such tool exists at the moment as far as I know.
Hopefully, I can take a look on my computer this evening to give you more pointers.
from chalk.
Alright, awesome! I'll take a look at the .lalrpop
file (that extension is a mouth-full XD). I've already put up a PR for the first file I tackled, bin/chalki.rs
. Feedback is welcome!
The one major thing I don't understand yet is how to specify parameterized types as goals. Normally for something like prolog, I can type in property(1, 6, A, B)
and it'll spit out all values of A
and B
that make the statement true. I tried to do that here with Vec<Box<T>>: Clone
, and it tells me "Invalid type name T". That makes sense, but what placeholder can I use so that it spits out a list of possible types for T?
If I understand the format correctly, generating a .chalk
file shouldn't be TOO hard... at least, a naive approach will get pretty close.
- Any enum gets copied over completely.
- Any global or default trait function is stripped of parameter names and function body.
- Any trait function is stripped of parameter names.
- Any struct has its field names stripped.
- Any trait impl is stripped of functions (leaving associated types intact)
- No idea how to deal with macros.
That might be a fun project eventually. Documentation and user-friendliness is my prime concern, though. Let's see if we can get more than just 11 contributors!
from chalk.
Prolog implicitly places quantifiers around your statements (universal ones around rules and existential ones around questions). In chalk
you need to explicitly specify them. For example,
?- exists<T> { Vec<u32> = Vec<T> }
Unique; substitution [?0 := u32], lifetime constraints []
Note that although Prolog normally tries to find all possible solutions, chalk
tries to find a unique solution. I am not sure about this, but I think chalk
never finds a non-unique solution. This is by design, since the compiler doesn't just choose a possible type, but errors if there are multiple solutions.
You can find a lot of examples in src/solve/test/mod.rs
.
from chalk.
Well I think Nico's blog posts which are linked in the Readme are a good start. I work on a glossary of important terms. So I would not say there is nothing, it is just a bit scattered. After I finish the next iteration of the glossary I will start a "book" where everything will be gathered. It's a young crate so there is a lot to do. And I'm slow because I am overworked. But that is another thing :)
from chalk.
Thanks for your help. I think I've got a hang of this now, and am working on more documentation, which I'll be pushing to my PR in the next few days.
from chalk.
Related Issues (20)
- Opaque type issue HOT 1
- identifying which method will run for a trait HOT 9
- Publishing is broken HOT 1
- CI Publish job using Mac runner HOT 2
- When Rust 1.55 hits stable, replace `ControlFlow` with std version
- Recursive solver reports ambiguity HOT 7
- Idea: rework how SLG solver uses the environment
- Auto traits are not handled for generic closures HOT 8
- Consider removing unused field
- Clean up coherence chapter in the Chalk book HOT 1
- Ambiguity through unrelated env clauses because of implied bounds HOT 1
- Fix/upgrade Chalk in wake of librarifying Copy/Clone on arrays and reinstate test HOT 1
- reconcile SLG/recursive solver's attempts to merge multiple results
- book: hard to read mermaid diagram in dark themes
- Lowered command panics with auto trait HOT 1
- Recursive solver hangs on cyclic traits HOT 3
- mdbook-mermaid needs updating
- Unable to deduce projection types of dyn types from supertrait bounds
- ICE: negative subgoal had delayed_subgoals HOT 2
- any progress and roadmap? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chalk.