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

Unify TraitItemMethod & TraitItemFunc with Function #2811

Closed
wants to merge 2 commits into from

Conversation

braw-lee
Copy link
Contributor

Addresses #2787

To use AST::Function instead of duplicated classes AST::TraitItemFunc
and AST::TraitItemMethod, we need AST::Function to be AST::TraitItem.

gcc/rust/ChangeLog:

	* ast/rust-ast.cc (Function::Function):
	Provide explicit constructor for TraitItem.
	(Function::operator=):
	Copy trait item using overloaded `operator=`
	* ast/rust-ast.h:
	Provide another constructor to TraitItem so we can create new
	instance but reuse same node_id.
	* ast/rust-item.h (class Function):
	Make Function inherit from TraitItem,
	define get_node_id() as the call will be ambigious otherwise,
	provide explicit constructor for TraitItem

Signed-off-by: Kushal Pal <[email protected]>
@braw-lee
Copy link
Contributor Author

This PR is getting a bit bigger, but I am not sure if I can divide it into seperate buildable commits.

gcc/rust/ChangeLog:

	* ast/rust-item.h (RUST_AST_ITEM_H):
	Make get_definition() public.
	* backend/rust-compile-implitem.cc (CompileTraitItem::visit):
	Use Function instead of TraitItemFunc.
	* backend/rust-compile-implitem.h:
	Add visitor for HIR::Function.
	* backend/rust-mangle-v0.cc (v0_path):
	Rename get_item_kind() to get trait_item_kind().
	* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
	TRAIT is valid context for function as it will be used instead
	of TraitItemFunc.
	* hir/rust-ast-lower-implitem.h:
	Lower Function as a trait item.
	* hir/tree/rust-hir-item.h (class Function):
	Make Function inherit from TraitItem and add necessary
	functions, also add necessary parameters for constructors.
	* hir/tree/rust-hir-visitor.h:
	Add vistor for Function in HIRTraitItemVisitor.
	* hir/tree/rust-hir.cc (Function::accept_vis):
	Add accept_vis for Function.
	* hir/tree/rust-hir.h:
	Rename get_item_kind() to get trait_item_kind().
	* parse/rust-parse-impl.h (Parser::parse_trait_item):
	Return AST::Function instead of AST::TraitItemFunc or
	AST::TriatItemMethod.
	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select):
	Rename get_item_kind() to get trait_item_kind().
	* typecheck/rust-hir-trait-reference.cc (TraitItemReference::get_tyty):
	Use HIR::Function instead of HIR::TraitItemFunc.
	* typecheck/rust-hir-trait-reference.h:
	Add functions for Function instead of TraitItemFunc.
	* typecheck/rust-hir-trait-resolve.cc (ResolveTraitItemToRef::visit):
	Add visit to Function.
	(TraitItemReference::on_resolved):
	Use HIR::Function instead of HIR::TraitItemFunc.
	(TraitItemReference::resolve_item):
	Add resolve_item() for Function.
	* typecheck/rust-hir-trait-resolve.h:
	Add visitor for Function.
	* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn):
	Add overload for Function.
	* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output):
	Rename get_item_kind() to get trait_item_kind().

Signed-off-by: Kushal Pal <[email protected]>
@braw-lee braw-lee mentioned this pull request Jan 24, 2024
@braw-lee braw-lee closed this Jan 24, 2024
@braw-lee braw-lee deleted the issue_2787 branch January 24, 2024 10:51
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.

1 participant