WIP: Fix testsuite regressions for Name Resolution 2.0#4544
Closed
nsvke wants to merge 17 commits into
Closed
Conversation
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Move declarations from ForeverStack to NRCtx, make most of the ForeverStack members public as it helps the Ctx a lot. * resolve/rust-forever-stack.hxx: Move implementation of resolve_path methods to NRCtx. * resolve/rust-name-resolution-context.h: Declare resolve_path methods. * resolve/rust-name-resolution-context.hxx: New file with resolve_path impls.
gcc/rust/ChangeLog: * resolve/rust-name-resolution-context.hxx: Do segment resolution in types NS for more correctness and correct behavior when later resolving paths that use imports and/or modules.
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc: Properly resolve and insert imports in the types NS. * resolve/rust-name-resolution-context.cc (find_leaf_definition_inner): New. (NameResolutionContext::find_leaf_definition): New. (NameResolutionContext::flatten): New. * resolve/rust-name-resolution-context.h: Declare flattening functions. * rust-session-manager.cc (Session::compile_crate): Call NR flattening.
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Move resolve_segments and resolve_final_segment to... * resolve/rust-forever-stack.hxx: Likewise. * resolve/rust-name-resolution-context.h: ...here. * resolve/rust-name-resolution-context.hxx: Likewise.
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import): Insert imports as possible glob containers. * resolve/rust-name-resolution-context.cc (NameResolutionContext::map_usage): Allow multiple mappings of the same usage. * resolve/rust-name-resolution-context.hxx: Properly handle imports and modules in segments. gcc/testsuite/ChangeLog: * rust/compile/import_in_type_ns6.rs: New test. * rust/compile/import_in_type_ns7.rs: New test.
…ontext. The ImmutableNRCtx was actually very mutable, as part of the pipeline needs to still map usages later down the line deep within the backend and typecheckers. Instead, add a new `map_usage` method which maps to the leafmost definition possible. gcc/rust/ChangeLog: * Make-lang.in: Rename. * backend/rust-compile-base.cc: Use new name and API. * backend/rust-compile-context.h: Likewise. * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise. (CompileExpr::generate_closure_function): Likewise. * backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise. * backend/rust-compile-item.cc (CompileItem::visit): Likewise. * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Likewise. * checks/errors/borrowck/rust-bir-builder-internal.h (struct BuilderContext): Likewise. * checks/errors/privacy/rust-privacy-check.cc (Resolver::resolve): Likewise. * checks/errors/privacy/rust-privacy-reporter.cc: Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/privacy/rust-visibility-resolver.cc: Likewise. * checks/errors/privacy/rust-visibility-resolver.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::PatternChecker): Likewise. * checks/errors/rust-hir-pattern-analysis.h: Likewise. * checks/errors/rust-readonly-check.cc (ReadonlyChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::visit_path_segment): Likewise. (MarkLive::visit): Likewise. (MarkLive::find_ref_node_id): Likewise. * checks/lints/unused/rust-unused-checker.cc (UnusedChecker::UnusedChecker): Likewise. * checks/lints/unused/rust-unused-checker.h: Likewise. * checks/lints/unused/rust-unused-collector.cc (UnusedCollector::UnusedCollector): Likewise. * checks/lints/unused/rust-unused-collector.h: Likewise. * resolve/rust-immutable-name-resolution-context.cc: Move to... * resolve/rust-finalized-name-resolution-context.cc: ...here. * resolve/rust-name-resolution-context.h: Likewise. * rust-session-manager.cc (Session::compile_crate): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait): Likewise. * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_fn_trait_call): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Likewise. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_root_path): Likewise. (TypeCheckExpr::resolve_segments): Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. (ResolveWhereClauseItem::visit): Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * resolve/rust-immutable-name-resolution-context.h: Removed. * resolve/rust-finalized-name-resolution-context.h: New file.
This patch fixes multiple ICEs and test failures in the Name Resolution 2.0 - Map directly to definition IDs instead of intermediate import IDs. - Remove redundant `flatten()` calls. Flattening stripped generic arguments from aliases like `Self`, causing typecheck errors. - Prevent ICEs on invalid `use self;` imports by adding early returns. - Add `Namespace::Types` to pattern lookups to correctly emit E0532 instead of crashing. - Remove an unsafe debug loop in `Rib::get` that caused ICEs on ambiguous names. - Use `value_or` for safe optional unwrapping in module resolution. gcc/rust/ChangeLog: * checks/lints/rust-lint-marklive.cc (MarkLive::visit_path_segment): Add Types namespace lookup. * checks/lints/unused/rust-unused-checker.cc (UnusedChecker::visit): Use safe optional unwrapping. * checks/lints/unused/rust-unused-collector.cc (UnusedCollector::visit): Likewise. * checks/lints/unused/rust-unused-collector.h: Use helper for multiple namespace lookups. * resolve/rust-early-name-resolver-2.0.cc (Early::finalize_simple_import): Prevent ICE on single self imports. (Early::finalize_rebind_import): Return early to prevent ICE. * resolve/rust-name-resolution-context.hxx: Use value_or for safe leaf module lookup. * resolve/rust-rib.cc (Rib::get): Remove debug loop causing ICE. * rust-session-manager.cc (Session::compile_crate): Remove obsolete flatten() calls. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Look up enum variants in Types namespace. Signed-off-by: Enes Cevik <nsvke@proton.me>
Member
|
@nsvke thank you for your work, but the rest of my commits is in really poor shape haha. I'll add your commit on top of my branch and create another PR so that I can more easily rework my stuff and make it cleaner. You'll still be marked as the commit's author and everything. I'll close this for now and will reopen a PR once I've cleaned up my stuff |
Member
This file contains hidden or 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
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 fixes the broken regression tests for @CohenArthur's Name Resolution 2.0 branch. All tests are now passing.
This PR is opened for review and testing purposes only.
gcc/rust/ChangeLog: