-
Notifications
You must be signed in to change notification settings - Fork 22
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
Engine: rework global name representation #1199
Open
W95Psp
wants to merge
2
commits into
main
Choose a base branch
from
rework-name-repr
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
+1,960
−1,167
Conversation
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
W95Psp
force-pushed
the
rework-name-repr
branch
from
December 19, 2024 10:28
9cba2cd
to
69b4062
Compare
W95Psp
force-pushed
the
rework-name-repr
branch
4 times, most recently
from
January 15, 2025 15:18
33ea9a2
to
e0a3dc3
Compare
W95Psp
force-pushed
the
rework-name-repr
branch
3 times, most recently
from
January 15, 2025 19:46
3b1c176
to
1fca9c3
Compare
W95Psp
force-pushed
the
rework-name-repr
branch
from
January 15, 2025 19:46
1fca9c3
to
f21a709
Compare
W95Psp
commented
Jan 16, 2025
]} | ||
|
||
Here, the Rust raw definition identifier of [LocalStruct] is roughly | ||
[a::my_crate::<Impl 0>::assoc_fn::LocalStruct::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.
todo: fix the path, my_crate comes first
maximebuyse
reviewed
Jan 20, 2025
(match List.last_exn (Explicit_def_id.to_def_id did).path with | ||
| { data = GlobalAsm; disambiguator } -> into_d did disambiguator | ||
| _ -> broken_invariant "last path chunk to be GlobalAsm" did) | ||
| TyAlias | TyParam | ConstParam | InlineConst | LifetimeParam | Closure |
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 crashed on a TyAlias
in one of my tests. I don't have a simple reproducer for now
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR implements #1163.
It is expected most of the issues in #1135.
This PR is about:
Motivation
The previous design for global identifiers assumed every identifiers came from Rust. This was true at that time.
Since then, we shifted from that. The engine now creates names in the following situations:
The assumption that all the identifiers come from Rust is thus now completly broken, hence the need to move out from the current design.
A second motivation is the fact Rust identifiers were coming without any "kind" information: in the engine, we were not able to state whether a given identifier was, say, a struct or a function.
This was a big problem when printing names in the backends: the name of, e.g., a type cannot be printed with the same logic as, e.g., a constant.
Previous design
A concrete identifier in hax was basically a tuple containing:
In the previous design, we added incrementally hooks into that raw rust DefId representation so that we could alter the identifiers. This was providing us a way to create new identifiers.
Printing names
Rust have a very flexible namespacing.
Modules are just one way of doing namespacing: item declaration is allowed in expression bodies, thus items can be nested arbitrarily.
It is possible e.g. to define a module within an anonymous const within a method implementation.
The logic for printing name was very complicated and hard to maintain or to fix.
New design
Frontend
#1198 made the frontend output a definition kind along with any Rust definition identifier. Before that, #1054 added a parent information for each Rust defition identifier.
Together, those two PRs makes the frontend output, for each defintiion identifiers: (1) the full chain of identifiers up to the crate root (2) a precise definition kind, informing us precisely about the definition.
Engine
Representation
Now the engine has a representation for concrete identifiers in three layers:
DefId
type, generated from Rust to OCaml, defined by the frontendExplicit_def_id
: wraps a rust raw identifier, adding a metadata to disambiguate types and constructor (see the documentation of this module for more details)Concrete_ident
: aExplicit_def_id
that can be moved to a fresh module name and/or have a hygenic suffixConcrete_ident
is an type that describes an eventual need of freshness: the underlying explicit def id are never touched. BeforeConcrete_ident
, every identifier comes from Rust.The freshness of concrete identifier is guaranteed lazily: when one request the rendering of a concrete identifier, then the engine will produce a stable but fresh name.
View
Working with raw rust identifier is difficult, espcially for rendering identifiers as string in the backends.
Rust represents identifiers as a crate and a path. Each chunk of the path of an Rust identifier is roughly a level of nest in Rust. The path lacks informations about definition kinds.
There is two kinds of nesting for items.
Instead, the view transform each path as a list of smaller relational paths. For instance, consider the following piece of code:
Here, the Rust raw definition identifier of
LocalStruct
is roughlya::my_crate::<Impl 0>::assoc_fn::LocalStruct::field
.The view for
LocalStruct
looks like:Such a hierachical path approach makes printing names much easier under the following constraints:
Progress
kind
field toDefIdContents
#1198Explicit_def_id
)Concrete_ident_view_types
)Concrete_ident_view
)Concrete_ident
>Fresh_module
)concrete_ident
#793 and [META] Engine: enhancements to the concrete ident view API #973)Concrete_ident
)tests
folderexamples
foldermod
andfn
s #1136v_...
instead oft_...
#1156t_
in rec bundle #1169rec
qualifier in a mutually recursive top-levellet
#1158hax_lib::fstar::before
in recursive bundles #1179Review status
@karthikbhargavan and @maximebuyse, you can already take a look at the all modified OCaml modules in the subdirectoy
engine/lib/concrete_idents
.