-
Notifications
You must be signed in to change notification settings - Fork 164
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
Conversation
19b72e5
to
5134e1e
Compare
With these changes it will be possible to add the right error message in the ast validation pass.
|
f2fb830
to
34e6284
Compare
There was a problem hiding this 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.
|
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. |
There was a problem hiding this 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!
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>
@philberty conflicts resolved |
No description provided.