-
Notifications
You must be signed in to change notification settings - Fork 40
feat(lean): Add support for namespaces #1780
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
base: main
Are you sure you want to change the base?
Conversation
This commit does not improve (nor test) support for internal recursion within traits
* Context: In preparation for a namespace mechanism in the Lean backend, we needed a way to compare items identifiers with the identifier of the current module (to strip prefixes). However, hax can introduce [fresh_modules] (typically, for bundles), and they did not have a normal identifier: as they were not present in the rust code, they do not get an [ExplicitDefId] and only exist as metadata (the [moved] field of [ConcreteId]). To be able to handle the identifier of normal rust modules as well as fresh modules in a unified way, this commit adds a new case in the [GlobalId] enum. This commit also contains some refactoring. * refactor: remove conversion function from [ConcreteId] to [GlobalId] * feat: add a memoized conversion function from [TupleId] to [ConcreteId]
- Add a comment for empty structures and inductives - Do not print empty modules - Capitalize the output-file name
1fcee47 to
ccaa2fc
Compare
W95Psp
left a comment
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.
Thanks, that generally looks good to me, though I have a few remarks :)
| kind: hax_types::diagnostics::Kind::Unimplemented { | ||
| issue_id: Some(1779), | ||
| details: Some( | ||
| "Unsupported fresh modules, which should only come from the fstar-phase for bundling" |
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.
Maybe change to "Fresh modules are not implemented yet in the Rust engine" or something in those lines?
See my comment in #1779, it's not so much F* specific
| #[allow(unused)] | ||
| /// Prints identifiers for debugging/development. Should not be used in production code. | ||
| trait DebugString { | ||
| /// Debug printing of identifiers, for testing purposes only. | ||
| /// Prints path in a Rust-like way, as a `::` separated dismabiguated path. | ||
| fn to_debug_string(&self) -> String; | ||
| } | ||
|
|
||
| impl DebugString for TupleId { | ||
| fn to_debug_string(&self) -> String { | ||
| match self { | ||
| TupleId::Type { length } => format!("Tuple_type({length})"), | ||
| TupleId::Constructor { length } => format!("Tuple_constructor({length})"), | ||
| TupleId::Field { length, field } => format!("Tuple_projector({length}, {field})"), | ||
| } | ||
| } | ||
| } |
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.
Let's implement https://doc.rust-lang.org/std/fmt/trait.Debug.html instead of creating a new trait
| // Removing unprintable items | ||
| let items: Vec<Item> = items | ||
| .into_iter() | ||
| .filter(LeanPrinter::printable_item) | ||
| .collect(); |
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.
This should be a phase, no?
| .collect() | ||
| } | ||
|
|
||
| fn apply(&self, mut items: Vec<Item>) -> Vec<File> { |
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.
We should pull that out of the backend trait: this method should not be overridable IMO 🤔
| /// This runs all of the backend's [`Backend::phases`], groups the items into | ||
| /// modules via [`Backend::items_to_module`], and then uses the backend's printer | ||
| /// to generate source files with paths determined by [`Backend::module_path`]. | ||
| pub fn apply_backend<B: Backend + 'static>(backend: B, mut items: Vec<Item>) -> Vec<File> { |
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.
Ah, that was not part of the trait?
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.
Makes sense, this should be the same logic for every backend
| derive_generic_visitor = "0.3.0" | ||
| pastey = "0.1.0" | ||
| camino = "1.1.11" | ||
| capitalize = "0.3.4" |
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.
Let's not bring an extra dependency for such a small utility function, just add it to as an helper somewhere (e.g. in a helper.rs file)
W95Psp
left a comment
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.
(sorry, I meant request changes, not approving 😓)
Co-authored-by: Lucas Franceschino <lucas@cryspen.com>
5c4ea61 to
8de75af
Compare
Overview
This PR uses the module mechanism of the rust-engine to gather definitions in Lean namespaces, shortening their names. To do so, a refactor of global ids have been made, adding a proper
FreshModulecase. The logic for rendering those is not done yet (see #1779), as it will only be required by F*-like bundling in the rust engine (which might only come when porting the F* backend).Example