-
Notifications
You must be signed in to change notification settings - Fork 173
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
Allow use before items being used continued #3150
Merged
P-E-P
merged 30 commits into
Rust-GCC:master
from
P-E-P:allow-use-before-items-being-used-continued
Sep 26, 2024
Merged
Allow use before items being used continued #3150
P-E-P
merged 30 commits into
Rust-GCC:master
from
P-E-P:allow-use-before-items-being-used-continued
Sep 26, 2024
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
3e15f81
to
dd3b3d1
Compare
04301d7
to
fac42c6
Compare
fac42c6
to
1f67f70
Compare
b1928ac
to
28fd0a5
Compare
28fd0a5
to
02f3600
Compare
This could trigger an assertions as `get_type` on `SelfParam` asserts that the self param does have a given type, which is not always the case. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Do not visit self's type if it does not have one.
gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_dec): Add notes on the problem. * resolve/rust-toplevel-name-resolver-2.0.h: Likewise.
gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc: Comment out handle_use call and error emission. * resolve/rust-toplevel-name-resolver-2.0.h: Create ImportKind class.
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): New function. (Early::resolve_simple_import): Likewise. (Early::resolve_rebind_import): Likewise. (Early::build_import_mapping): Likewise. * resolve/rust-early-name-resolver-2.0.h: Add declarations and list of imports to resolve. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_glob): Remove function, which is now being handled by the Early name resolver. (TopLevel::handle_use_dec): Likewise. (TopLevel::handle_rebind): Likewise. * resolve/rust-toplevel-name-resolver-2.0.h: Likewise, and add functions for creating import list and fetching it.
gcc/rust/ChangeLog: * Make-lang.in: Add new object file. * ast/rust-item.h: Constify method. * resolve/rust-early-name-resolver-2.0.cc (Early::go): Call into the imports finalizer. (Early::resolve_glob_import): Remove old resolution. (Early::resolve_rebind_import): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::go): New function. (GlobbingVisitor::visit): Likewise. (TopLevel::visit): Do not call into handle_use_* functions anymore. * resolve/rust-toplevel-name-resolver-2.0.h (class GlobbingVisitor): New. * resolve/rust-finalize-imports-2.0.cc: New file. * resolve/rust-finalize-imports-2.0.h: New file.
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Use ImportData class. (Early::resolve_simple_import): Likewise. (Early::resolve_rebind_import): Likewise. (Early::build_import_mapping): Likewise. * resolve/rust-early-name-resolver-2.0.h: Likewise. * resolve/rust-finalize-imports-2.0.cc (finalize_simple_import): Likewise. (finalize_glob_import): Likewise. (finalize_rebind_import): Likewise. (FinalizeImports::go): Likewise. * resolve/rust-finalize-imports-2.0.h: Likewise. * resolve/rust-name-resolution-context.h: Likewise. * resolve/rust-rib.h: Define ImportData class.
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add debug call. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Store imports using the new classes. * resolve/rust-toplevel-name-resolver-2.0.h: Use new classes.
gcc/rust/ChangeLog: * resolve/rust-finalize-imports-2.0.cc (FinalizeImports::go): Turn static method into method. (FinalizeImports::visit): New. * resolve/rust-finalize-imports-2.0.h (class FinalizeImports): Make FinalizeImports a visitor. * resolve/rust-early-name-resolver-2.0.cc (Early::go): Use new FinalizeImports API. (Early::resolve_glob_import): Use new API. (Early::resolve_simple_import): Likewise. (Early::resolve_rebind_import): Likewise. (Early::build_import_mapping): Likewise. * resolve/rust-early-name-resolver-2.0.h: Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.h: Likewise.
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): Store errors for later.
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_simple_import): Insert import in all namespaces where they were resolved. (Early::resolve_rebind_import): Likewise. * resolve/rust-early-name-resolver-2.0.h: Improve APIs, make them accept multiple resolutions. * resolve/rust-finalize-imports-2.0.cc: Handle multiple resolutions. * resolve/rust-name-resolution-context.h (resolve_path): Remove function.
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.h: New class for imports. * resolve/rust-finalize-imports-2.0.cc (finalize_simple_import): Use the new API. (finalize_glob_import): Likewise. (finalize_rebind_import): Likewise. (FinalizeImports::FinalizeImports): Likewise. (FinalizeImports::visit): Likewise. * resolve/rust-finalize-imports-2.0.h: Likewise. * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Likewise. (Early::resolve_simple_import): Likewise. (Early::resolve_rebind_import): Likewise.
When we tried to insert a shadowable node and another shadowable node has been inserted before, we didn't emit any error if the node has already been inserted previously and failed silently. gcc/rust/ChangeLog: * resolve/rust-rib.cc (Rib::insert): Emit an error when trying to insert an already inserted node. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
When a use statement requires a reexported item it cannot find it in the same pass, an additional pass shall be performed. This means we need to detect whether a new item has been reexported and resolve until the end. gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::Early): Add dirty flag initialization. (Early::go): Set dirty flag using top level resolver. * resolve/rust-early-name-resolver-2.0.h: Add dirty flag. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::TopLevel): Initialize dirty flag. (TopLevel::insert_or_error_out): Set dirty flag on successful namespace modification. * resolve/rust-toplevel-name-resolver-2.0.h: Add dirty flag. * rust-session-manager.cc (Session::expansion): Modify fixed point condition to include name resolution modifications. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Those function prototype were not marked as override and throwing warning. gcc/rust/ChangeLog: * resolve/rust-default-resolver.h: Make most visit function override. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
We can let the default visitor visit those nodes anyway so we're sure all nodes can be reached. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove empty visit function implementations. * resolve/rust-default-resolver.h: Remove corresponding prototypes. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Regular visit code can be replaced with default visit functions. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove default visit code and replace it with call to default visitor. * resolve/rust-default-resolver.h: Remove removed function's prototypes. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
We can reduce code duplication by using the default visitor functions from within the scoped lambda function. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Use default visitor instead. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
gcc/rust/ChangeLog: * resolve/rust-finalize-imports-2.0.h: Add parent member functions from default resolver. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Make those functions public so they can be used within a lambda on GCC 4.8. gcc/rust/ChangeLog: * ast/rust-ast-visitor.h: Make visit functions public. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
We want to begin experimenting with this new name resolution 2.0 algorithm as soon as possible. This test highlight a problem where the compiler should emit an error and should be fixed soon. gcc/testsuite/ChangeLog: * rust/compile/name_resolution21.rs: Move to... * rust/compile/xfail/name_resolution21.rs: ...here. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Move function implementation to their own file. gcc/rust/ChangeLog: * Make-lang.in: Add new rust-bir-builder-pattern file. * checks/errors/borrowck/rust-bir-builder-pattern.h: Remove implementation. * checks/errors/borrowck/rust-bir-builder-pattern.cc: New file. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
We might have some duplicated name in some pattern and we should therefore not assert the non duplication of identifiers. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove assertion and explicitely tells why we ignore the insertion result. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove working tests from nr2 exclude list. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
48d4cc2
to
8a2f112
Compare
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.h: Add visit function prototype. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change resolved type segment. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
gcc/rust/ChangeLog: * ast/rust-ast.h: Node id getter could be const. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
It requires the standard library and Copy to work correctly which we cannot provide. Stopping the compiler before the name resolution allow us to prevent an error whilst resolving Copy and keep the test's goal. gcc/testsuite/ChangeLog: * rust/compile/functions_without_body.rs: Add compile step argument. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Box definition is part of the standard library and cannot be found during name resolution. This simple definition prevent any error from being emitted. gcc/testsuite/ChangeLog: * rust/compile/box_syntax_feature_gate.rs: Add box land item definition. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
Resolve TypeParam unless it is Self. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Resolve TypeParam. * resolve/rust-toplevel-name-resolver-2.0.h: Add visit function prototype. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
We need the top level to run at least once before breaking because it will be required by the other name resolution steps. gcc/rust/ChangeLog: * rust-session-manager.cc (Session::expansion): Break on error after top level name resolution. Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove cast_generics.rs, issue-1131.rs, issue-1383.rs and unsafe10.rs Signed-off-by: Pierre-Emmanuel Patry <[email protected]>
8a2f112
to
2843ceb
Compare
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.
Name resolution 2.0 continued.
This PR add fixes and add some work on top of #2940