-
Notifications
You must be signed in to change notification settings - Fork 165
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
Name resolution globbing #2796
Name resolution globbing #2796
Conversation
@CohenArthur how much of this can be merged as-is? |
b5c44d1
to
18fc6f5
Compare
29b4a0c
to
546a8da
Compare
546a8da
to
176b059
Compare
gcc/rust/ChangeLog: * Make-lang.in: Compile it. * resolve/rust-immutable-name-resolution-context.cc: New file. * resolve/rust-immutable-name-resolution-context.h: New file.
gcc/rust/ChangeLog: * rust-session-manager.cc (Session::compile_crate): Create name resolution context for Session::expansion and subsequent name resolution passes. (Session::expansion): Take name resolution context as a parameter instead. * rust-session-manager.h (Session::expansion): Fix declaration.
I still need to reorder some commits and fix the changelog but this is nearly done 🎉 |
209d7be
to
aaead7e
Compare
Error message did not match the test from the previous name resolver when a given path cannot be resolved. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Change error message to match old resolver and test case. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Function return type was not properly visited in the default resolver visitor pattern. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Visit function return type. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
The type of constant item expression was not properly visited in the default resolver. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Visit constant item's types. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
This overload did not dispatch the visitor to sub members of a raw pointer like the default one. It is therefore useless as pointed type shall be visited to be resolved correctly. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove function implementation. * resolve/rust-default-resolver.h: Remove function prototype. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Values were inserted in the label namespace instead of the value namespace this lead to several bugs. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change the namespace for values from "label" to "values". Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Unit struct have a special constructor that should be added to the struct namespace in order to be resolved later when called. As it is a function it should be added in the value namespace. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit): Add the struct constructor when the struct is a unit. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Only tuple struct constructor was added to the resolver. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit): Add tuple struct type to the resolver's context. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
The enum type shall be in type namespace, not value namespace. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit): Change enum type namespace. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
We shall search in the right namespace. The correct namespace for struct is type namespace. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Change search location for struct types. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Constants could not be resolved without their identifier in the right scope. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add constant identifiers to the resolver. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Remove extern block scoping visit function, use the default visitor visit function instead. We do not need scoping for extern block as their element shall be visible from the extern block scope. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove visitor implementation and scoping. * resolve/rust-default-resolver.h: Remove function prototype. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
We need to visit subcomponents in unsafe elements, this means we can leverage the default ast visitor's code instead of duplicating it. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove empty visit function. * resolve/rust-default-resolver.h: Remove function prototype. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Constant items were handled only by the old resolver, this lead to an ICE when using the new resolver on some rust code containing a constant item as the new and the old resolver cannot be used at the same time. gcc/rust/ChangeLog: * backend/rust-compile-item.cc (CompileItem::visit): Check the resolver flag and use the new one when required. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
The old resolver injected a Self generic parameter in order to help the trait solver. This is clearly sketchy at best and should be fixed in the future. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add Self generic parameter injection and a warning. * resolve/rust-toplevel-name-resolver-2.0.h: Add function prototype. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Crate number was not assigned with the other fields in the assignment operator overload of a CannonicalPath. gcc/rust/ChangeLog: * util/rust-canonical-path.h: Also assign crate number. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Immutable name resolution context is not initialized when the classic name resolution is in use. It can therefore not be used, the getter would error out. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Only get immutable name resolution context when name resolution 2.0 is used. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
This format dialog triggered a warning. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_dec): Replace the string format %<%s%> with the proper %qs format. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Definition/usage mapping during name resolution was missing. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add mapping implementation. * resolve/rust-late-name-resolver-2.0.h: Add function visitor prototype override. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Name resolution for rebind were missing. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_glob): Change function prototype to use a reference instead. (TopLevel::handle_use_dec): Likewise. (TopLevel::handle_rebind): Add name resolution on rebind use declarations. (flatten_rebind): Change prototype to accept a pair of path/alias. (flatten_list): Adapt call to flatten_rebind. (flatten): Adapt call to flatten_rebind. (flatten_glob): Remove unused part. (TopLevel::visit): Add rebind resolution. * resolve/rust-toplevel-name-resolver-2.0.h: Adapt function prototypes. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc: Attempt to resolve names also using new name resolution context. * backend/rust-compile-resolve-path.h: Add new declaration.
gcc/testsuite/ChangeLog: * rust/compile/name_resolution13.rs: Add new module and remove compile step. * rust/compile/name_resolution14.rs: New test. * rust/compile/name_resolution15.rs: New test. * rust/compile/name_resolution16.rs: New test. * rust/compile/name_resolution17.rs: New test. * rust/compile/name_resolution18.rs: New test. * rust/compile/name_resolution19.rs: New test. * rust/compile/name_resolution20.rs: New test. * rust/compile/name_resolution21.rs: New test.
Add a few test for globbing to highlight function call ambiguities. gcc/testsuite/ChangeLog: * rust/compile/name_resolution23.rs: New test. * rust/compile/name_resolution24.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
4b768eb
to
01d83db
Compare
I've added two tests, |
01d83db
to
33bed05
Compare
GCC 4.8 does not handle pair with references correctly. We need to use a properly typed struct instead. gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Change dfs function prototype and declare dfs return type structure. * resolve/rust-forever-stack.hxx: Adapt dfs function to the new return type. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
amazing work on this @P-E-P, well done :) |
Late name resolution was not used and did not handle globbing.