-
Notifications
You must be signed in to change notification settings - Fork 12
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
Declaration engine #11
Conversation
rfcs/0003-declaration-engine.md
Outdated
} | ||
|
||
impl DeclarationEngine { | ||
fn add_function(&mut self, function: TypedFunctionDeclaration) -> DeclarationDefinition { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the function has to be typed when we insert it into the declaration, doesn't that mean we maintain the status quo of having to type check (and perform inference on) everything before beginning this process?
Sooo excited for work on this to begin 🚀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think you've addressed out of order declarations and dependencies here? Is that another thing the decl engine was supposed to handle?
Allowing out of order declarations and to remove the declaration sorting we have now and especially to allow recursive data structures and function calls is highly desirable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice one Emily!
I don't have much to add on top of the others' comments, though I think your insight about our current lack of clarity on how to perform type inference in a consistent manner being a core issue is a really key insight and makes a lot of sense! I can see the proposed DeclarationEngine
going a long way to help with this.
The described approach reminds me a little of the Hindley-Milner type system and its approach to inference, though maybe a little less formal and jargon-y 🥲 Considering it was the solution adopted by ML, Haskell, Rust and I'm sure many other languages, perhaps it's worth taking a closer look and seeing if there's anything we can learn from it as "Prior Art"? I'd imagine it might have some key design insights particularly when it comes to handling trait (typeclass) constraints and polymorphic types (Vec<T>
, (T, U)
, etc).
I actually based our current type engine on Hindley-Milner when I wrote it, hence the function names like |
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
Co-authored-by: Alex Hansen <alex@alex-hansen.com>
There hasn't been much activity on this RFC page, largely because I have been working on this prototype: https://github.com/emilyaherbert/declaration-engine-and-collection-context-demo/tree/master/de. The prototype should 1) help explain the idea and 2) acts as a guiding light for our implementation. Trait constraints for generic functions are working in the prototype. Also, I've basically reworked the entire RFC, so I'd love a second round of feedback. In the meantime, I will hack on a experimental branch in the Sway repo so that we can get things moving. Don't let this scare you away from iterating on the design though! |
ping @FuelLabs/sway-compiler would we be able to merge this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚀
rendered
prototype