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

Refactored to use implicit insert and remove insert_type method from context object #3395 #3489

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mostafa630
Copy link

@mostafa630 mostafa630 commented Mar 6, 2025

This solution resolves issue #3395 by refactoring the code to use implicit_insert_type instead of insert_type, improving clarity and eliminating the insert_type method from the context object.
Changed files:
* typecheck/rust-typecheck-context.cc
(TypeCheckContext::insert_type): Remove.
* typecheck/rust-hir-type-check.h: Remove declaration of insert_type method.
* typecheck/rust-tyty-subst.cc: Replace all insert_type with insert_implicit_type.
* typecheck/rust-tyty-util.cc: Likewise.
* typecheck/rust-tyty.cc: Likewise.
* typecheck/rust-substitution-mapper.cc: Likewise.
* typecheck/rust-hir-trait-resolve.cc: Likewise.
* typecheck/rust-hir-type-check-base.cc: Likewise.
* typecheck/rust-hir-type-check-enumitem.cc: Likewise.
* typecheck/rust-hir-type-check-expr.cc: use Likewise.
* typecheck/rust-hir-type-check-implitem.cc: Likewise.
* typecheck/rust-hir-type-check-item.cc: use Likewise.
* typecheck/rust-hir-type-check-pattern.cc: Likewise.
* typecheck/rust-hir-type-check-stmt.cc: Likewise.
* typecheck/rust-hir-type-check-struct.cc: Likewise.
* typecheck/rust-hir-type-check-type.cc: Likewise.
* typecheck/rust-hir-type-check.cc: Likewise.
* typecheck/rust-unify.cc: Likewise.

@powerboat9
Copy link
Collaborator

You don't have to keep recreating the PR, you can just force-push

@powerboat9
Copy link
Collaborator

Looks good, just missing the removal of a few insert_type calls

@mostafa630
Copy link
Author

Looks good, just missing the removal of a few insert_type calls

Should I only remove the remaining ones, or should I replace them with insert_implicit_type?

@powerboat9
Copy link
Collaborator

Replace them with insert_implicit_type

@mostafa630 mostafa630 force-pushed the refactor-implicit-insert-3395 branch from 2704c26 to 533f40f Compare March 6, 2025 05:57
@dkm
Copy link
Member

dkm commented Mar 6, 2025

FYI, changelog is not really correct. You should have things like:

   * typecheck/rust-substitution-mapper.cc (SubstMapperInternal::Resolve): use insert_implicit_type.
   * typecheck/rust-typecheck-context.cc (TypeCheckContext::insert_type): Remove.
   (TypeCheckContext::compute_inference_variables): use insert_implicit_type.

...
You're not supposed to only point at the file where you've made changes, but to more precise "item" (function, type definition, etc).
Also, instead of repeating the same thing in sequence, you can use the idiomatic "Likewise" (have a look at existing entries in git log). Do not hesitate to ask for help if needed :)

@mostafa630 mostafa630 force-pushed the refactor-implicit-insert-3395 branch from 533f40f to a80e9a4 Compare March 6, 2025 23:50
@mostafa630
Copy link
Author

mostafa630 commented Mar 7, 2025

@dkm can I use clang-format-13 or I must use version 10 because I have some problems in installing version 10

@powerboat9
Copy link
Collaborator

I use version 19, which only very rarely disagrees with version 10. You can always try it with version 13 and see if the CI complains

…ject (Rust-GCC#3395)

gcc/rust/ChangeLog:

	* typecheck/rust-typecheck-context.cc
	(TypeCheckContext::insert_type): Remove.
	* typecheck/rust-hir-type-check.h: Remove declaration of insert_type method.
	* typecheck/rust-tyty-subst.cc: Replace all insert_type with insert_implicit_type.
	* typecheck/rust-tyty-util.cc: Likewise.
	* typecheck/rust-tyty.cc: Likewise.
	* typecheck/rust-substitution-mapper.cc: Likewise.
	* typecheck/rust-hir-trait-resolve.cc: Likewise.
	* typecheck/rust-hir-type-check-base.cc: Likewise.
	* typecheck/rust-hir-type-check-enumitem.cc: Likewise.
	* typecheck/rust-hir-type-check-expr.cc: use Likewise.
	* typecheck/rust-hir-type-check-implitem.cc: Likewise.
	* typecheck/rust-hir-type-check-item.cc: use Likewise.
	* typecheck/rust-hir-type-check-pattern.cc: Likewise.
	* typecheck/rust-hir-type-check-stmt.cc: Likewise.
	* typecheck/rust-hir-type-check-struct.cc: Likewise.
	* typecheck/rust-hir-type-check-type.cc: Likewise.
	* typecheck/rust-hir-type-check.cc: Likewise.
	* typecheck/rust-unify.cc: Likewise.

Signed-off-by: sasa630 <mostafayounis630@gmail.com>
@mostafa630 mostafa630 force-pushed the refactor-implicit-insert-3395 branch from a80e9a4 to 395d362 Compare March 7, 2025 11:04
@mostafa630
Copy link
Author

I use version 19, which only very rarely disagrees with version 10. You can always try it with version 13 and see if the CI complains

@powerboat9 Thanks! I tried it with version 13, and it works well. All tests passed successfully.

@P-E-P
Copy link
Member

P-E-P commented Mar 7, 2025

@dkm I wonder if pseudonyms are allowed for sign off

@P-E-P P-E-P requested a review from philberty March 7, 2025 17:03
Copy link
Member

@philberty philberty left a comment

Choose a reason for hiding this comment

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

LGTM can you just verify if we still need that node_id_refs map?

rust_assert (type != nullptr);
NodeId ref = mappings.get_nodeid ();
HirId id = mappings.get_hirid ();
node_id_refs[ref] = id;
Copy link
Member

Choose a reason for hiding this comment

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

can you check to see if we can remove the node_id_refs map? Is it still used elsewhere?

Copy link
Author

Choose a reason for hiding this comment

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

The following functions utilize the node_id_refs map:

-TypeCheckContext::lookup_builtin(NodeId id, TyTy::BaseType **type)
-TypeCheckContext::insert_builtin(HirId id, NodeId ref, TyTy::BaseType *type)
-TypeCheckContext::insert_type_by_node_id(NodeId ref, HirId id)
-TypeCheckContext::lookup_type_by_node_id(NodeId ref, HirId *id)

but , these functions are only exist in two files:
-rust-hir-type-check.h
-rust-typecheck-context.cc

Additionally, while TypeCheckContext::lookup_builtin is used elsewhere, the version being used is not the one mentioned above. Instead, the used version is an overloaded function:
-TypeCheckContext::lookup_builtin (std::string name, TyTy::BaseType **type)

Given this, we can safely remove the node_id_refs map and all functions that depend on it, as doing so will not impact the code , unless the project requires them in the future or in a context that is not clear to me.

Copy link
Author

Choose a reason for hiding this comment

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

sorry after more research i found that there are files in other folders like resolve call some function that use
node_id_refs map
and that is example :
in the file : rust-name-resolver.cc in the resolve folder it call that :

tyctx->insert_builtin (unit_tyty->get_ref (), unit_type->get_node_id (),
			 unit_tyty);

and that insert_builtin uses node_id_refs map

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants