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

Replace AST::Method with existing AST::Function #2715

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

powerboat9
Copy link
Contributor

No description provided.

@powerboat9 powerboat9 force-pushed the unify-fn branch 2 times, most recently from 19b72e5 to 5134e1e Compare October 30, 2023 04:13
@P-E-P
Copy link
Member

P-E-P commented Oct 30, 2023

With these changes it will be possible to add the right error message in the ast validation pass.

`self` parameter is only allowed in associated functions

@P-E-P P-E-P self-requested a review October 30, 2023 12:59
@powerboat9
Copy link
Contributor Author

@philberty

@powerboat9 powerboat9 force-pushed the unify-fn branch 2 times, most recently from f2fb830 to 34e6284 Compare November 7, 2023 06:47
Copy link
Member

@P-E-P P-E-P left a comment

Choose a reason for hiding this comment

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

I was very reluctant about these changes and was waiting for other people's opinions, but when I went to see rustc I realised that they had something similar, altough the self type is not optional but rather a parameter variant with it's own type (ImplicitSelf). Our AST is massive and there is many duplicated structures, I'm in favor of merging this, but I still want @philberty 's opinion.

@P-E-P
Copy link
Member

P-E-P commented Nov 7, 2023

rustc consider the self parameter to be a plain parameter, a detail was still bothering me with this: Does rustc reject a wrong self parameter during the AST validation pass ? If so, we couldn't take this approach because our optional does not keep the self parameter's position. Hopefully it does not, this code is rejected during parsing.

@powerboat9
Copy link
Contributor Author

Judging by this the position of a self parameter is checked during parsing, but whether a method/function should have a self parameter is checked afterwards.

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 lets go for it.. I did this in the HIR because that's the dungeon where I live but was worried how this might impact higher level stuff like macro expansion so given that we already have loads of tests on the parsing and macros I think we should just go for it since it reduces a lot of duplication!

@philberty philberty added this pull request to the merge queue Nov 9, 2023
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to a conflict with the base branch Nov 9, 2023
gcc/rust/ChangeLog:

	* ast/rust-item.h
	(class Method): Remove.
	(Function::self_param): New.
	(Function::has_self_param): New.
	(Function::Function): Initialize self_param.
	(Function::operator=): Likewise.
	(Function::get_self_param): New.
	* ast/rust-ast.cc
	(Method::as_string): Remove.
	(Method::accept_vis): Remove.

	* ast/rust-ast-collector.cc
	(TokenCollector::visit):
	Remove AST::Method visitor, handle self_param in AST::Function visitor.
	* ast/rust-ast-collector.h
	(TokenCollector::visit): Remove AST::Method visitor.
	* ast/rust-ast-full-decls.h (class Method): Remove.

	* ast/rust-ast-visitor.h
	(ASTVisitor::visit): Remove AST::Method visitor.
	(DefaultASTVisitor::visit): Likewise.
	* ast/rust-ast-visitor.cc
	(DefaultASTVisitor::visit):
	Remove AST::Method visitor, handle self_param in AST::Function visitor.

	* checks/errors/rust-feature-gate.cc
	(FeatureGate::visit): Remove AST::Method visitor.
	* checks/errors/rust-feature-gate.h
	(FeatureGate::visit): Likewise..

	* expand/rust-cfg-strip.cc
	(CfgStrip::visit):
	Remove AST::Method visitor, handle self_param in AST::Function visitor.
	* expand/rust-cfg-strip.h
	(CfgStrip::visit): Remove AST::Method visitor.

	* expand/rust-derive-clone.cc
	(DeriveClone::clone_fn): Return AST::Function instead of AST::Method.
	* expand/rust-derive.h (DeriveVisitor::visit): Remove AST::Method visitor.

	* expand/rust-expand-visitor.cc
	(ExpandVisitor::visit):
	Remove AST::Method visitor, handle self_param in AST::Function visitor.
	* expand/rust-expand-visitor.h:
	(ExpandVisitor::visit): Remove AST::Method visitor.

	* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
	* hir/rust-ast-lower-base.h (ASTLoweringBase::visit): Likewise.

	* hir/rust-ast-lower-implitem.h
	(ASTLowerImplItem::visit):
	Remove AST::Method visitor, handle self_param in AST::Function visitor.

	* parse/rust-parse-impl.h: Include optional.h.
	(Parser::parse_function): Adjust AST::Function construction.
	(Parser::parse_inherent_impl_function_or_method):
	Construct AST::Function instead of AST::Method,
	adjust AST::Function construction.
	(Parser::parse_trait_impl_function_or_method): Likewise.
	(Parser::parse_method):
	Return std::unique_ptr<AST::Function> instead of AST::Method.

	* parse/rust-parse.h
	(Parser::parse_method): Likewise.

	* resolve/rust-ast-resolve-base.cc
	(ResolverBase::visit): Remove AST::Method visitor.
	* resolve/rust-ast-resolve-base.h
	(ResolverBase::visit): Likewise.

	* resolve/rust-ast-resolve-implitem.h
	(ResolveToplevelImplItem::visit): Likewise.

	* resolve/rust-ast-resolve-item.cc
	(ResolveItem::visit): Remove AST::Method visitor,
	handle self_param in AST::Function visitor.
	* resolve/rust-ast-resolve-item.h
	(ResolveItem::visit): Remove AST::Method visitor.

	* resolve/rust-default-resolver.cc
	(DefaultResolver::visit): Remove AST::Method visitor.
	* resolve/rust-default-resolver.h
	(DefaultResolver::visit): Likewise.

	* resolve/rust-early-name-resolver.cc
	(EarlyNameResolver::visit): Remove AST::Method visitor,
	handle self_param in AST::Function visitor.
	* resolve/rust-early-name-resolver.h
	(EarlyNameResolver::visit): Remove AST::Method visitor.

	* resolve/rust-toplevel-name-resolver-2.0.cc
	(TopLevel::visit): Likewise.
	* resolve/rust-toplevel-name-resolver-2.0.h
	(TopLevel::visit): Likewise.

	* util/rust-attributes.cc
	(AttributeChecker::visit): Likewise.
	* util/rust-attributes.h
	(AttributeChecker::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
@powerboat9
Copy link
Contributor Author

@philberty conflicts resolved

@P-E-P P-E-P enabled auto-merge November 9, 2023 20:40
@P-E-P P-E-P added this pull request to the merge queue Nov 9, 2023
Merged via the queue into Rust-GCC:master with commit 9864d7f Nov 9, 2023
9 checks passed
@powerboat9 powerboat9 deleted the unify-fn branch November 9, 2023 21:57
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.

3 participants