Skip to content
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

Open
wants to merge 23 commits into
base: master
Choose a base branch
from

Conversation

P-E-P
Copy link
Member

@P-E-P P-E-P commented Sep 4, 2024

Name resolution 2.0 continued.

This PR add fixes and add some work on top of #2940

@P-E-P P-E-P self-assigned this Sep 4, 2024
@P-E-P P-E-P added this to the Name Resolution 2.0 rework milestone Sep 4, 2024
@P-E-P P-E-P force-pushed the allow-use-before-items-being-used-continued branch 4 times, most recently from 3e15f81 to dd3b3d1 Compare September 5, 2024 15:59
@CohenArthur CohenArthur force-pushed the allow-use-before-items-being-used-continued branch from 04301d7 to fac42c6 Compare September 16, 2024 14:59
@P-E-P P-E-P marked this pull request as ready for review September 17, 2024 12:03
@P-E-P P-E-P force-pushed the allow-use-before-items-being-used-continued branch from fac42c6 to 1f67f70 Compare September 17, 2024 12:06
@P-E-P P-E-P disabled auto-merge September 17, 2024 12:45
@P-E-P P-E-P force-pushed the allow-use-before-items-being-used-continued branch 2 times, most recently from b1928ac to 28fd0a5 Compare September 17, 2024 14:57
CohenArthur and others added 14 commits September 19, 2024 16:19
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]>
@P-E-P P-E-P force-pushed the allow-use-before-items-being-used-continued branch from 28fd0a5 to 02f3600 Compare September 19, 2024 14:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

2 participants