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

Make most lookup return an optional #2972

Merged
merged 32 commits into from May 17, 2024
Merged

Conversation

P-E-P
Copy link
Member

@P-E-P P-E-P commented Apr 25, 2024

Requires #2969

@P-E-P P-E-P added this to In progress in Project Pineapple via automation Apr 25, 2024
@P-E-P P-E-P force-pushed the lookup_optional branch 4 times, most recently from b5d74da to 02106d0 Compare May 1, 2024 13:23
@P-E-P P-E-P requested a review from CohenArthur May 6, 2024 11:33
P-E-P added 23 commits May 6, 2024 17:54
Previous API was using a boolean and a pointer, this was not practical
and could be replaced with an optional.

gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::visit): Change call to use
	the returned optional.
	(CompileExpr::generate_closure_function): Likewise.
	* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve):
	Likewise.
	* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise.
	* backend/rust-mangle-v0.cc (v0_path): Likewise.
	* checks/errors/privacy/rust-visibility-resolver.cc:
	Likewise.
	* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
	* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
	Likewise.
	* checks/lints/rust-lint-marklive.cc (MarkLive::visit): Likewise.
	(MarkLive::visit_path_segment): Likewise.
	* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait):
	Likewise.
	* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path):
	Likewise.
	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
	Likewise.
	(ResolveWhereClauseItem::visit): Likewise.
	* util/rust-hir-map.cc (Mappings::lookup_node_to_hir): Return an
	optional instead of a boolean.
	* util/rust-hir-map.h: Change function prototype to match the new
	return type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Optional are more convenient to use and avoid uninitialized data.

gcc/rust/ChangeLog:

	* backend/rust-compile-expr.cc (CompileExpr::generate_closure_function):
	Adapt code for new optional return type.
	* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
	Likewise.
	* util/rust-hir-map.cc (Mappings::lookup_hir_to_node): Change return
	type to an optional.
	* util/rust-hir-map.h: Adapt function prototype with the new return
	type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Change the return type to an optional.

gcc/rust/ChangeLog:

	* util/rust-hir-map.cc (Mappings::resolve_nodeid_to_stmt): Change the
	return type and remove pointer out argument.
	* util/rust-hir-map.h: Update function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile):
	Adapt function call to new return type.
	* backend/rust-mangle-v0.cc (v0_path): Likewise.
	* checks/errors/rust-const-checker.cc (ConstChecker::check_function_call):
	Likewise.
	* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::check_use_of_static):
	Likewise.
	(UnsafeChecker::check_function_call): Likewise.
	(UnsafeChecker::check_function_attr): Likewise.
	* checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise.
	(MarkLive::visit): Likewise.
	* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait):
	Likewise.
	* typecheck/rust-type-util.cc (query_type): Likewise.
	* util/rust-hir-map.cc (Mappings::insert_hir_item): Likewise.
	(Mappings::lookup_hir_item): Change function return type to use
	optional.
	* util/rust-hir-map.h: Update function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Change the return type to an optional instead of returning a null
pointer. This allows easier tracking of rogue null pointers in the
map. This commit also fixes a bug in trait associated function mangling,
the function was using an already invalidated pointer.

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile):
	Adapt return type to new optional.
	* backend/rust-mangle-v0.cc (v0_function_path): Change prototype to use
	the generic arguments vector instead of the whole HIR function.
	(v0_path): Fix a bug with a null pointer being used to create the
	trait function mangling.
	* util/rust-hir-map.cc (Mappings::insert_hir_trait_item): Adapt code
	to new return type.
	(Mappings::lookup_hir_trait_item): Change the return type of the
	function to an optional.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Change the return type to an optional in order to easily differentiate
between a null pointer and an missing value.

gcc/rust/ChangeLog:

	* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::check_function_call):
	Adapt function call to new return type.
	* typecheck/rust-type-util.cc (query_type): Likewise.
	* util/rust-hir-map.cc (Mappings::insert_hir_extern_block): Likewise.
	(Mappings::lookup_hir_extern_block): Change return type to an optional.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Change the return type to an optiona. This allows to differentiate
between missing hir impl block and null pointers.

gcc/rust/ChangeLog:

	* typecheck/rust-type-util.cc (query_type): Change call to the function
	in order to accomodate the new return type.
	* util/rust-hir-map.cc (Mappings::lookup_hir_impl_block): Change the
	function's return type to an optional.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Change the return type to an optional.

gcc/rust/ChangeLog:

	* typecheck/rust-type-util.cc (query_type): Adapt code to accomodate
	the new return type.
	* util/rust-hir-map.cc (Mappings::lookup_impl_block_type): Change
	the function's return type and remove the out pointer argument.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Change the function's return type to use an optional.

gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-toplevel.h: Adapt the code to the new
	return type.
	* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
	Likewise.
	* rust-session-manager.cc (Session::load_extern_crate): Likewise.
	* util/rust-hir-map.cc (Mappings::lookup_crate_name): Change the return
	type to an optional.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Change the function's return type to an optional.

gcc/rust/ChangeLog:

	* resolve/rust-ast-resolve-toplevel.h: Adapt the code to the new
	return type.
	* rust-session-manager.cc (Session::load_extern_crate): Likewise.
	* util/rust-hir-map.cc (Mappings::crate_num_to_nodeid): Change the
	return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Change their return type to a const reference in order to avoid copies
when possible. Also wrap this new return type into an optional.

gcc/rust/ChangeLog:

	* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go):
	Adapt the code to the new return types.
	* resolve/rust-ast-resolve.cc (NameResolution::go): Likewise.
	* util/rust-hir-map.cc (Mappings::get_crate_name): Change return type
	to const string reference optional.
	(Mappings::get_current_crate_name): Likewise.
	* util/rust-hir-map.h: Update function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Change the return type to an optional.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address):
	Change calling code to accomodate new return type.
	* checks/errors/privacy/rust-privacy-reporter.cc:
	Likewise.
	* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::get_marker_predicate):
	Likewise.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
	Likewise.
	* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_builtin_candidate):
	Likewise.
	* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): Likewise.
	* util/rust-hir-map.cc (Mappings::lookup_defid): Change function's
	return type.
	* util/rust-hir-map.h: Update function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Make the API more convenient by changing the function's return type. We
can now differentiate between a stored null pointer and a missing value.

gcc/rust/ChangeLog:

	* util/rust-hir-map.cc (Mappings::insert_defid_mapping): Adapt call
	to new return type.
	(Mappings::insert_local_defid_mapping): Likewise.
	(Mappings::lookup_local_defid): Change return type to wrap it with an
	optional.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the return type with an optional.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address):
	Update code around lookup return type.
	* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound):
	Likewise.
	* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output):
	Likewise.
	* util/rust-hir-map.cc (Mappings::insert_defid_mapping): Likewise.
	(Mappings::lookup_trait_item_defid): Update return type with an
	optional.
	(Mappings::get_lang_item): Likewise.
	* util/rust-hir-map.h: Update the functions prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the return type with an optional and make the return type a pair
with the parent hid.

gcc/rust/ChangeLog:

	* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile):
	Adapt code around new return type.
	* checks/errors/rust-const-checker.cc (ConstChecker::check_function_call):
	Likewise.
	* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::check_use_of_static):
	Likewise.
	(UnsafeChecker::check_function_call): Likewise.
	* typecheck/rust-type-util.cc (query_type): Likewise.
	* util/rust-hir-map.cc (Mappings::insert_hir_extern_item): Likewise.
	(Mappings::lookup_hir_extern_item): Change return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the return type into an optional.

gcc/rust/ChangeLog:

	* checks/errors/privacy/rust-visibility-resolver.cc: Update function
	call to match the new return type.
	* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path):
	Likewise.
	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
	Likewise.
	* util/rust-hir-map.cc (Mappings::insert_module): Likewise.
	(Mappings::lookup_module): Change the function's return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the function's return type with an optional.

gcc/rust/ChangeLog:

	* typecheck/rust-autoderef.cc: Adapt calling code to new return type.
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
	Likewise.
	(TypeCheckExpr::resolve_operator_overload): Likewise.
	* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_builtin_candidate):
	Likewise.
	* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): Likewise.
	* util/rust-hir-map.cc (Mappings::get_lang_item): Change return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the return type within an optional. Now return the parent id within
a pair instead of taking an out reference.

gcc/rust/ChangeLog:

	* backend/rust-compile-item.cc (CompileItem::visit): Change call site
	to accept new return type.
	* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile):
	Likewise.
	* backend/rust-mangle-v0.cc (v0_path): Likewise.
	* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
	Likewise.
	* checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise.
	(MarkLive::visit): Likewise.
	* typecheck/rust-type-util.cc (query_type): Likewise.
	* util/rust-hir-map.cc (Mappings::insert_hir_implitem): Likewise.
	(Mappings::lookup_hir_implitem): Change return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the function's return type with an optional in order to
differentiate missing values from null pointers.

gcc/rust/ChangeLog:

	* backend/rust-mangle-v0.cc (v0_path): Adapt call site to new returned
	type.
	* util/rust-hir-map.cc (Mappings::lookup_hir_expr): Change the
	function's return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Make the function's return type optional in order to differentiate
between null pointers and missing value.

gcc/rust/ChangeLog:

	* util/rust-hir-map.cc (Mappings::insert_hir_path_expr_seg): Change
	call site to accomodate the new return type.
	(Mappings::lookup_hir_path_expr_seg): Wrap the function's return type
	with an optional.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the function's return type with an optional.

gcc/rust/ChangeLog:

	* util/rust-hir-map.cc (Mappings::insert_hir_generic_param): Change
	call site to accomodate the new return type.
	(Mappings::lookup_hir_generic_param): Wrap the function's return type
	with an optional.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the function's return type with an optional in order to tell
appart a null pointer from a missing value.

gcc/rust/ChangeLog:

	* util/rust-hir-map.cc (Mappings::insert_hir_type): Change call site
	to accomodate the new return type.
	(Mappings::lookup_hir_type): Change the function's return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the function's return type within an optional in order to
differentiate missing values from null pointers.

gcc/rust/ChangeLog:

	* util/rust-hir-map.cc (Mappings::insert_hir_stmt): Change call site
	to accomodate new return type.
	(Mappings::lookup_hir_stmt): Change the function's return type.
	(Mappings::resolve_nodeid_to_stmt): Adapt call site to new return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
P-E-P added 9 commits May 6, 2024 18:03
Wrap the function's return type within an optional to differentiate
between a null ppointer and a missing value.

gcc/rust/ChangeLog:

	* util/rust-hir-map.cc (Mappings::insert_hir_param): Change call site
	to accomodate new return type.
	(Mappings::lookup_hir_param): Change the function's return type.
	* util/rust-hir-map.h: Updat ethe function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the function's return type within an optional in order to
differentiate null pointers from missing value.

gcc/rust/ChangeLog:

	* util/rust-hir-map.cc (Mappings::insert_hir_self_param): Adapt call
	site to new return type.
	(Mappings::lookup_hir_self_param): Change the function's return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the function's return type within an optional to differentiate
between a null pointer and a missing value.

gcc/rust/ChangeLog:

	* util/rust-hir-map.cc (Mappings::insert_hir_struct_field): Change
	call site to accomodate new return type.
	(Mappings::lookup_hir_struct_field): Change the function's return
	type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the function's return type within an optional in order to
differentiate between a null pointer and a missing value.

gcc/rust/ChangeLog:

	* util/rust-hir-map.cc (Mappings::insert_hir_pattern): Change call site
	in order to accomodate new return type.
	(Mappings::lookup_hir_pattern): Change the function's return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Change the function's return type to wrap it within an optional.

gcc/rust/ChangeLog:

	* backend/rust-compile-base.cc: Change call site to accomodate new
	return type.
	* backend/rust-compile-base.h: Change parameter to use a reference.
	* backend/rust-compile-extern.h: Likewise.
	* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
	Change call site for new return type.
	* backend/rust-compile-item.cc (CompileItem::visit): Likewise.
	* resolve/rust-ast-resolve-type.cc (ResolveTypeToCanonicalPath::visit):
	Likewise.
	* typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit):
	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.cc (TraitItemReference::get_type_from_fn):
	Likewise.
	* util/rust-hir-map.h: Update the function's prototype and change the
	function's return type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the function's return type within an optional.

gcc/rust/ChangeLog:

	* resolve/rust-early-name-resolver-2.0.cc (Early::insert_once): Change
	call site to accomodate the new return type.
	(Early::visit): Likewise.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Likewise.
	* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
	Likewise.
	* util/rust-hir-map.cc (Mappings::lookup_macro_def): Change the
	function's return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the function's return type within an optional and remove the out
reference argument.

gcc/rust/ChangeLog:

	* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Adapt
	the function call to match its new prototype.
	* resolve/rust-early-name-resolver-2.0.cc (Early::insert_once):
	Likewise.
	(Early::visit): Likewise.
	* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
	Likewise.
	* util/rust-hir-map.cc (Mappings::lookup_macro_invocation): Change the
	function's return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the return type within an optional.

gcc/rust/ChangeLog:

	* checks/errors/privacy/rust-privacy-reporter.cc: Change call site
	to accomodate new return type.
	* checks/errors/privacy/rust-pub-restricted-visitor.cc: Likewise.
	* util/rust-hir-map.cc (Mappings::lookup_visibility): Change the
	function's return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Wrap the function's return type within an optional.

gcc/rust/ChangeLog:

	* metadata/rust-export-metadata.cc (ExportContext::emit_trait):
	Adapt call site to the new return type.
	(ExportContext::emit_function): Likewise.
	(ExportContext::emit_macro): Likewise.
	* util/rust-hir-map.cc (Mappings::lookup_ast_item): Change the
	function's return type.
	* util/rust-hir-map.h: Update the function's prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
@P-E-P P-E-P marked this pull request as ready for review May 6, 2024 16:05
Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Project Pineapple automation moved this from In progress to Reviewer approved May 17, 2024
@P-E-P P-E-P added this pull request to the merge queue May 17, 2024
Merged via the queue into Rust-GCC:master with commit 06bc336 May 17, 2024
9 checks passed
Project Pineapple automation moved this from Reviewer approved to Done May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

Successfully merging this pull request may close these issues.

None yet

2 participants