]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
20 months agoMake early name resolver inherit from default one
Pierre-Emmanuel Patry [Mon, 27 Nov 2023 14:39:24 +0000 (15:39 +0100)] 
Make early name resolver inherit from default one

Many visit functions in the early name resolver are just plain old
traversal visit functions like the ones from the default visitor.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver.cc (EarlyNameResolver::resolve_generic_args):
Move function.
(EarlyNameResolver::resolve_qualified_path_type): Likewise.
(EarlyNameResolver::visit): Add a top level visit function for crate
and remove duplicated code.
* resolve/rust-early-name-resolver.h (class EarlyNameResolver): Update
overriden function list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoChange the attribute checker visitor to default one
Pierre-Emmanuel Patry [Fri, 24 Nov 2023 13:09:23 +0000 (14:09 +0100)] 
Change the attribute checker visitor to default one

Make the attribute checker visitor inherit from the default visitor
in order to keep visit behavior shared.

gcc/rust/ChangeLog:

* util/rust-attributes.cc (AttributeChecker::visit): Add visit function
for crates.
* util/rust-attributes.h (class AttributeChecker): Update function
prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoMake feature gate visitor inherit from default one
Pierre-Emmanuel Patry [Fri, 24 Nov 2023 10:17:52 +0000 (11:17 +0100)] 
Make feature gate visitor inherit from default one

The feature gating behavior may be shortened and kept cleaner using the
default visitor. This means less maintenance on visit functions as the
traversal is shared by multiple visitors.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Add a visit
function for the crate level.
(FeatureGate::check): Add call to crate visit.
* checks/errors/rust-feature-gate.h (class FeatureGate): Remove now
useless visit functions (traversal only).

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd regression test for const fn in trait
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 12:22:42 +0000 (13:22 +0100)] 
Add regression test for const fn in trait

Const fn declaration in trait declarations shall emit an error. This new
test highlight this behavior.

gcc/testsuite/ChangeLog:

* rust/compile/const_trait_fn.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd AST validation check for const in trait
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 12:08:13 +0000 (13:08 +0100)] 
Add AST validation check for const in trait

Add a new check in AST validation pass that checks that no function
declaration in traits are declared const.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
const check.
* checks/errors/rust-ast-validation.h: Add visit function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd a regression test for async const functions
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 10:12:05 +0000 (11:12 +0100)] 
Add a regression test for async const functions

Functions that are both async and const shall be rejected during the
AST validation pass. This new test highlight this behavior.

gcc/testsuite/ChangeLog:

* rust/compile/const_async_function.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd async const function ast validation pass
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 09:44:08 +0000 (10:44 +0100)] 
Add async const function ast validation pass

Add a check during AST validation pass to ensure functions are either
const or async but not both.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
async const check.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAllow const and async specifiers in functions
Pierre-Emmanuel Patry [Wed, 22 Nov 2023 09:35:44 +0000 (10:35 +0100)] 
Allow const and async specifiers in functions

We need to account for const specifiers in async parsing as const
can be used in the syntax before the async keyword.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_vis_item): Allow parsing async
items in const.
(Parser::parse_async_item): Account for const offset during async
lookahead.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoSplit async and const function qualifiers
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 09:29:35 +0000 (10:29 +0100)] 
Split async and const function qualifiers

A function cannot be both async and const, however this should not be
handled in the parser but rather at a later stage in the compiler. This
commit change the AsyncConstStatus in the AST and the HIR to allows a
function to be both async and const.

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (AstBuilder::fn_qualifiers): Change
constructor to match the new arguments.
* ast/rust-ast-collector.cc (TokenCollector::visit): Change behavior
to handle both const and async specifiers at the same time.
* ast/rust-ast.cc (FunctionQualifiers::as_string): Likewise.
* ast/rust-item.h (class FunctionQualifiers): Remove AsyncConstStatus
and replace it with both Async and Const status. Also change the safety
arguments to use an enum instead of a boolean.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_qualifiers):
Update constructor call.
* hir/tree/rust-hir-item.h: Add Const and Async status, remove
AsyncConstStatus, update the constructor.
* hir/tree/rust-hir.cc (FunctionQualifiers::as_string): Update with
the new status.
* parse/rust-parse-impl.h (Parser::parse_function_qualifiers): Update
constructor call.
* util/rust-common.h (enum Mutability): Make an enum class.
(enum class): Add Async and Const enum class to avoid booleans.
(enum Unsafety): Change to an enum class.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoRemove class AST::InherentImplItem
Owen Avery [Tue, 28 Nov 2023 06:07:00 +0000 (01:07 -0500)] 
Remove class AST::InherentImplItem

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h
(class InherentImplItem): Remove.
* ast/rust-ast.h
(class InherentImplItem): Remove.
(class SingleASTNode):
Store pointer to AssociatedItem instead of InherentImplItem.

* ast/rust-ast.cc
(SingleASTNode::SingleASTNode):
Use clone_associated_item instead of clone_inherent_impl_item.
(SingleASTNode::operator=): Likewise.

* ast/rust-item.h
(class InherentImpl):
Use AssociatedItem rather than InherentImplItem.
(class Function): Likewise.
(class ConstantItem): Likewise.
* ast/rust-macro.h
(class MacroInvocation): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_impl): Likewise.
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_inherent_impl_function_or_method): Likewise.
* parse/rust-parse.h
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_inherent_impl_function_or_method): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
20 months agogccrs: Remove backend dependancy on resolution rib information
Philip Herron [Mon, 2 Oct 2023 17:41:33 +0000 (18:41 +0100)] 
gccrs: Remove backend dependancy on resolution rib information

When making more desugaring for the HIR we can need to add new Let bindings
which will require namesolution information but also rib information for
which block the let binding is associated which was very unnessecary. This
patch simply updates the BLOCK_CONTEXT of the current scope as we are
compiling and encounter HIR::LetStmts instead of trying to do it all
upfront which lots of wierd checks

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::compile_locals_for_block): removed
* backend/rust-compile-base.h: update header
* backend/rust-compile-block.cc (CompileBlock::visit): remove old logic
* backend/rust-compile-expr.cc (CompileExpr::generate_closure_function): likewise
* backend/rust-compile-stmt.cc (CompileStmt::visit): likewise
* backend/rust-compile-var-decl.h: ensure we setup tuple bindings correctly

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
20 months agoAdd a regression test for unsafe module validation
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 18:34:36 +0000 (19:34 +0100)] 
Add a regression test for unsafe module validation

Add a new test to check for unsafe modules during AST validation pass.

gcc/testsuite/ChangeLog:

* rust/compile/unsafe_module.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoEmit an error on unsafe modules
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 17:51:21 +0000 (18:51 +0100)] 
Emit an error on unsafe modules

An error should be emitted on unsafe modules during the AST validation
pass as the syntax allows those even though they're not alowed later down
the line.

gcc/rust/ChangeLog:

* ast/rust-item.h: Add safety getter to modules.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Check
a module's safety and emit an error when meeting an unsafe module.
* checks/errors/rust-ast-validation.h: Add function prototype.
* parse/rust-parse-impl.h (Parser::parse_module): Move the module locus
to the first token instead of the mod keyword.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoParse module safety
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 17:28:30 +0000 (18:28 +0100)] 
Parse module safety

Unsafe module are rejected at a later stage but could not be parsed
properly. This commit changes the parser in order to allow unsafe module
in the AST.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_vis_item): Dispatch to parse
module when meeting an unsafe module.
(Parser::parse_module): Set unsafe status when the parser encounter an
unsafe keyword.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd unsafety member to modules
Pierre-Emmanuel Patry [Tue, 21 Nov 2023 16:56:10 +0000 (17:56 +0100)] 
Add unsafety member to modules

The rust syntax allows unsafe module even if those are rejected at a
later stage.

gcc/rust/ChangeLog:

* ast/rust-item.h: Add safety status to Modules in the AST.
* parse/rust-parse-impl.h (Parser::parse_module): Adapt constructors.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoCreate base class for TupleStructItems and TuplePatternItems
Owen Avery [Tue, 3 Oct 2023 21:50:14 +0000 (17:50 -0400)] 
Create base class for TupleStructItems and TuplePatternItems

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(class TupleItems): New.
(class TupleStructItems): Inherit from TupleItems.
(class TuplePatternItems): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
20 months agotoplevel: Resolve `use` declarations
Arthur Cohen [Wed, 23 Aug 2023 11:51:06 +0000 (13:51 +0200)] 
toplevel: Resolve `use` declarations

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::insert_or_error_out): New functions.
(TopLevel::handle_use_dec): New function.
(flatten_rebind): Likewise.
(flatten_list): Likewise.
(flatten_glob): Likewise.
(flatten): Likewise.
(TopLevel::visit): Visit various `use` declaration nodes.
* resolve/rust-toplevel-name-resolver-2.0.h: Declare functions and
visitors.

20 months agoearly: Move `use` declaration resolving to TopLevel
Arthur Cohen [Wed, 23 Aug 2023 11:50:54 +0000 (13:50 +0200)] 
early: Move `use` declaration resolving to TopLevel

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::visit): Remove visitors.
* resolve/rust-early-name-resolver-2.0.h: Likewise.

20 months agoast: Add NodeId to UseTree base class
Arthur Cohen [Wed, 23 Aug 2023 11:49:24 +0000 (13:49 +0200)] 
ast: Add NodeId to UseTree base class

gcc/rust/ChangeLog:

* ast/rust-item.h (class UseTree): Add `node_id` member.

20 months agotoplevel: Add comment about running the collector twice
Arthur Cohen [Tue, 22 Aug 2023 15:29:56 +0000 (17:29 +0200)] 
toplevel: Add comment about running the collector twice

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::insert_or_error_out): Add documentation comment.
(TopLevel::go): Likewise.

20 months agoearly: Resolve paths properly
Arthur Cohen [Mon, 21 Aug 2023 14:52:48 +0000 (16:52 +0200)] 
early: Resolve paths properly

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::insert_once): New function.
(Early::visit): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Likewise.

20 months agolate: Start storing mappings properly in the resolver
Arthur Cohen [Tue, 22 Aug 2023 15:29:05 +0000 (17:29 +0200)] 
late: Start storing mappings properly in the resolver

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Store mappings
after having resolved them.
* resolve/rust-late-name-resolver-2.0.h: Add `TypePath` visitor.

20 months agolate: Start setting up builtin types
Arthur Cohen [Tue, 22 Aug 2023 14:58:28 +0000 (16:58 +0200)] 
late: Start setting up builtin types

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::setup_builtin_types): New function.
(Late::go): Setup builtin types.
* resolve/rust-late-name-resolver-2.0.h:
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::map_usage): New function.
* resolve/rust-name-resolution-context.h: Likewise.

20 months agonr2.0: Store mappings in NameResolutionContext
Arthur Cohen [Tue, 22 Aug 2023 13:40:25 +0000 (15:40 +0200)] 
nr2.0: Store mappings in NameResolutionContext

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.h: Store a reference to the
mappings.
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::NameResolutionContext): Likewise.

20 months agotoplevel: Use DefaultResolver for Function
Arthur Cohen [Wed, 15 Nov 2023 10:33:25 +0000 (11:33 +0100)] 
toplevel: Use DefaultResolver for Function

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Use
the DefaultResolver in the toplevel visitor.

20 months agonr2.0: Add base for late name resolution
Arthur Cohen [Fri, 23 Jun 2023 14:37:51 +0000 (16:37 +0200)] 
nr2.0: Add base for late name resolution

gcc/rust/ChangeLog:

* Make-lang.in: Compile late name resolver.
* resolve/rust-late-name-resolver-2.0.cc: New file.
* resolve/rust-late-name-resolver-2.0.h: New file.

20 months agoctx: Add Labels ForeverStack to the resolver.
Arthur Cohen [Thu, 17 Aug 2023 12:07:27 +0000 (14:07 +0200)] 
ctx: Add Labels ForeverStack to the resolver.

Not sure if dealing with "labels" is the proper way of doing so, so we
might eventually change this to use `resolver.values` later on.

gcc/rust/ChangeLog:

* resolve/rust-name-resolution-context.h: Add a Labels stack.

20 months agoAdded support to Parse ASYNC function
M V V S Manoj Kumar [Tue, 21 Nov 2023 16:34:24 +0000 (22:04 +0530)] 
Added support to Parse ASYNC function

Fixes issue #2650
The parser now parses ASYNC functions. Added ASYNC case to parse_item
Added a new function parse_async_item which is called in
parse_vis_item to handle the ASYNC case. Parse_async_item
also checks the current Rust edition and generates an error if the
edition is 2015

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_item): Likewise.
(Parser::parse_vis_item): Likewise.
(Parser::parse_async_item): Likewise.
* parse/rust-parse.h: Made declaration for parse_async_item.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2650-1.rs: New test.(edition=2018)
* rust/compile/issue-2650-2.rs: New test.(edition=2015)

Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
20 months agoIntroduce a proper keyword list
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 15:20:49 +0000 (16:20 +0100)] 
Introduce a proper keyword list

The old "keyword" list was used for the lexer, and could therefore not
be used with keyword spanning over multiple tokens as those tokens should
remain lexed as is. Hence the introduction of a new list macro for
keyword exclusive tasks. This also means we can no longer match a token
id for each keyword. The token id map has been renamed to keep it's
properties.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::classify_keyword): Update keyword map name.
* lex/rust-token.h (enum PrimitiveCoreType): Remove some deprecated
comments.
* util/rust-keyword-values.cc (get_keywords): Update the keyword map
name.
(RS_TOKEN): Define as empty
(RS_TOKEN_KEYWORD_2015): Add the emission value.
(RS_TOKEN_KEYWORD_2018): Likewise.
* util/rust-keyword-values.h (RS_KEYWORD_LIST): Introduce the keyword
list.
(RS_TOKEN_KEYWORD_2018): Define multiple new keywords.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoReplace some weak keyword raw value with constexpr
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 14:18:41 +0000 (15:18 +0100)] 
Replace some weak keyword raw value with constexpr

Raw values may have typos or contain error, replacing those will
improve the codebase.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Replace raw value.
* parse/rust-parse-impl.h (Parser::is_macro_rules_def): Likewise.
(Parser::parse_item): Likewise.
(Parser::parse_vis_item): Likewise.
(Parser::parse_macro_rules_def): Likewise.
(Parser::parse_union): Likewise.
(Parser::parse_trait_impl_item): Likewise.
(Parser::parse_stmt): Likewise.
(Parser::parse_stmt_or_expr): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd a list of weak keyword
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 14:02:11 +0000 (15:02 +0100)] 
Add a list of weak keyword

Retrieving a weak keyword value is done using raw values. Introducing a
list of weak keywords means this could change.

gcc/rust/ChangeLog:

* util/rust-keyword-values.h (class WeakKeywords): Add new class with
weak keyword constexpr.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoReplace some keyword raw values
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 12:41:46 +0000 (13:41 +0100)] 
Replace some keyword raw values

Raw values cannot be understood easily by most tools. This commit replace
some raw values with their variable counterpart.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Replace raw value
with keyword call.
* ast/rust-ast.h: Likewise.
* parse/rust-parse-impl.h (Parser::parse_path_ident_segment): Likewise.
(Parser::parse_macro_match_fragment): Likewise.
(Parser::parse_extern_crate): Likewise.
(Parser::parse_use_tree): Likewise.
(Parser::parse_const_item): Likewise.
(Parser::parse_literal_expr): Likewise.
(Parser::parse_maybe_named_param): Likewise.
(Parser::parse_pattern_no_alt): Likewise.
(Parser::left_denotation): Likewise.
(Parser::parse_path_in_expression_pratt): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd await keyword
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 12:11:33 +0000 (13:11 +0100)] 
Add await keyword

The 2018 edition await keyword was missing from the keyword list.

gcc/rust/ChangeLog:

* lex/rust-token.h (enum PrimitiveCoreType): Add await keyword
definition.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoTreat underscore as a keyword
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 11:39:37 +0000 (12:39 +0100)] 
Treat underscore as a keyword

Make the underscore token a 2015 keyword.

gcc/rust/ChangeLog:

* lex/rust-token.h (enum PrimitiveCoreType): Change macro for
underscore in token list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd edition separation for keywords
Pierre-Emmanuel Patry [Thu, 16 Nov 2023 10:42:35 +0000 (11:42 +0100)] 
Add edition separation for keywords

It might be required in the future to get only the keywords from a
specific edition. To do so we need a mean to differentiate keywords based
on their edition. This commit changes the existing keyword macro to
allow such behavior.

gcc/rust/ChangeLog:

* lex/rust-token.h (enum PrimitiveCoreType): Change enum macro calls.
(RS_TOKEN_KEYWORD): Remove generic token keyword macro.
(RS_TOKEN_KEYWORD_2015): Introduce keywords for edition 2015.
(RS_TOKEN_KEYWORD_2018): Likewise with edition 2018.
* lex/rust-token.cc (RS_TOKEN_KEYWORD): Remove old macro definition.
(RS_TOKEN_KEYWORD_2015): Replace with 2015 definition...
(RS_TOKEN_KEYWORD_2018): ... and 2018 definition.
* util/rust-keyword-values.cc (RS_TOKEN_KEYWORD):  Likewise.
(RS_TOKEN_KEYWORD_2015): Likewise.
(RS_TOKEN_KEYWORD_2018): Likewise.
* util/rust-keyword-values.h (RS_TOKEN_KEYWORD): Likewise.
(RS_TOKEN_KEYWORD_2015): Likewise.
(RS_TOKEN_KEYWORD_2018): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoReplace TOK suffix with KW
Pierre-Emmanuel Patry [Wed, 15 Nov 2023 15:24:56 +0000 (16:24 +0100)] 
Replace TOK suffix with KW

TOK suffix was chosen to disambiguate some identifiers with c++ reserved
keyword. Even though this list lies within the rust-token header, this
macro is used in many context sometimes unrelated with the lexer and
tokens. This TOK suffix may appear surprising in such context.

gcc/rust/ChangeLog:

* lex/rust-token.h (enum PrimitiveCoreType): Change keyword suffix from
tok to kw.
* ast/rust-ast-collector.cc (TokenCollector::visit): Update suffix to
match the new declaration.
* lex/rust-lex.cc (Lexer::parse_raw_identifier): Likewise.
* parse/rust-parse-impl.h (can_tok_start_type): Likewise.
(Parser::parse_item): Likewise.
(Parser::parse_vis_item): Likewise.
(Parser::parse_extern_crate): Likewise.
(Parser::parse_function): Likewise.
(Parser::parse_function_qualifiers): Likewise.
(Parser::parse_struct): Likewise.
(Parser::parse_enum): Likewise.
(Parser::parse_static_item): Likewise.
(Parser::parse_trait_item): Likewise.
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_trait_impl_item): Likewise.
(Parser::parse_extern_block): Likewise.
(Parser::parse_external_item): Likewise.
(Parser::parse_stmt): Likewise.
(Parser::parse_return_expr): Likewise.
(Parser::parse_match_expr): Likewise.
(Parser::parse_type): Likewise.
(Parser::parse_for_prefixed_type): Likewise.
(Parser::parse_type_no_bounds): Likewise.
(Parser::parse_stmt_or_expr): Likewise.
* parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewie.
* util/rust-token-converter.cc (convert): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd ast validation check on union variant number
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 14:41:39 +0000 (15:41 +0100)] 
Add ast validation check on union variant number

Unions with zero fields are forbidden. Add regression test for empty
unions.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
zero field check during ast validation pass.
* checks/errors/rust-ast-validation.h: Add union visit function
prototype.

gcc/testsuite/ChangeLog:

* rust/compile/const_generics_8.rs: Fill the union with dummy values.
* rust/compile/empty_union.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd a test regular variadic functions errors
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 10:37:12 +0000 (11:37 +0100)] 
Add a test regular variadic functions errors

Add a new regression test for the error message in regular function
variadic errors during ast validation pass.

gcc/testsuite/ChangeLog:

* rust/compile/non_foreign_variadic_function.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoEmit an error on variadic non extern functions
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 10:19:46 +0000 (11:19 +0100)] 
Emit an error on variadic non extern functions

Variadic regular functions were recently added in the parser as they
should be rejected in the ast validation pass. This commit add the ast
validation pass rejecting this kind of variadic arguments.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
ast validation pass to reject variadic arguments on regular functions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd check for associated items on auto traits
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 13:59:56 +0000 (14:59 +0100)] 
Add check for associated items on auto traits

Reject rust code with associated items on auto traits.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add auto
trait associated item check in AST validation pass.
* parse/rust-parse-impl.h: Remove old error emission done during
parsing pass.

gcc/testsuite/ChangeLog:

* rust/compile/auto_trait_invalid.rs: Update old test with updated
error message.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd a regression test for super trait on auto trait
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 13:16:41 +0000 (14:16 +0100)] 
Add a regression test for super trait on auto trait

Add a new regression test to highlight the error behavior with a super
trait on an auto trait.

gcc/testsuite/ChangeLog:

* rust/compile/auto_trait_super_trait.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoReject auto traits with super trait
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 13:04:35 +0000 (14:04 +0100)] 
Reject auto traits with super trait

Reject auto traits containing a super trait bound during AST validation
pass.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Reject
auto traits with super traits.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd regression test for generic auto traits
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 12:53:51 +0000 (13:53 +0100)] 
Add regression test for generic auto traits

Generics are forbidden on auto traits and an error should be emitted.
This commit highlight this behavior.

gcc/testsuite/ChangeLog:

* rust/compile/generic_auto_trait.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoReject auto traits with generic parameters
Pierre-Emmanuel Patry [Mon, 20 Nov 2023 12:43:48 +0000 (13:43 +0100)] 
Reject auto traits with generic parameters

Generic parameters are not allowed on auto traits, the compiler should
emit an error.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
check for generics on auto traits.
* checks/errors/rust-ast-validation.h: Add visit function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agofixup: Ensure buffer allocation for bootstrap
Pierre-Emmanuel Patry [Fri, 17 Nov 2023 14:26:43 +0000 (15:26 +0100)] 
fixup: Ensure buffer allocation for bootstrap

Bootstrap was failing because the vector did not allocate the internal
buffer and was holding a null pointer.

Commit to fixup is b71fd2afa831

gcc/rust/ChangeLog:

* expand/rust-proc-macro.cc (generate_proc_macro_decls_symbol): Resize
the vector and initialize it with dummy data before changing it.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoforever stack: Remove development debug info
Arthur Cohen [Tue, 21 Nov 2023 10:14:12 +0000 (11:14 +0100)] 
forever stack: Remove development debug info

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Remove debug log.

20 months agoresolve: Format if properly
Arthur Cohen [Tue, 21 Nov 2023 10:13:59 +0000 (11:13 +0100)] 
resolve: Format if properly

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Format.

20 months agoforeverstack: Add `to_rib` method
Arthur Cohen [Fri, 25 Aug 2023 12:19:31 +0000 (14:19 +0200)] 
foreverstack: Add `to_rib` method

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: New method.
* resolve/rust-forever-stack.hxx: Likewise.

20 months agoforeverstack: Add `to_canonical_path` method
Arthur Cohen [Fri, 25 Aug 2023 11:40:44 +0000 (13:40 +0200)] 
foreverstack: Add `to_canonical_path` method

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: New method.
* resolve/rust-forever-stack.hxx: Likewise.

20 months agoforever stack: Improve resolve_path implementation
Arthur Cohen [Wed, 23 Aug 2023 11:50:16 +0000 (13:50 +0200)] 
forever stack: Improve resolve_path implementation

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Do not copy segment when
dereferencing iterator in `find_starting_point`.

20 months agoforever stack: Fix resolve_path signature
Arthur Cohen [Thu, 21 Sep 2023 13:55:03 +0000 (15:55 +0200)] 
forever stack: Fix resolve_path signature

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: Fix `ForeverStack::resolve_path`
signature.
* resolve/rust-forever-stack.hxx: Likewise.
* resolve/rust-early-name-resolver-2.0.cc (Early::visit): Use new API.
(Early::visit_attributes): Likewise.

20 months agoforeverstack: Specialize `get` for Namespace::Labels
Arthur Cohen [Mon, 21 Aug 2023 14:05:22 +0000 (16:05 +0200)] 
foreverstack: Specialize `get` for Namespace::Labels

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx: Add specific behavior for
`ForeverStack::get` when dealing with labels.

20 months agoforever-stack: Fix basic get logic
Arthur Cohen [Mon, 21 Aug 2023 13:52:06 +0000 (15:52 +0200)] 
forever-stack: Fix basic get logic

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: Improve resolve_path API.
* resolve/rust-forever-stack.hxx: Likewise and fix implementation.

20 months agorib: Add Namespace enum
Arthur Cohen [Thu, 17 Aug 2023 12:06:50 +0000 (14:06 +0200)] 
rib: Add Namespace enum

gcc/rust/ChangeLog:

* resolve/rust-rib.h: Add Namespace enum.

20 months agoast: Change *Path nodes API
Arthur Cohen [Thu, 17 Aug 2023 12:05:49 +0000 (14:05 +0200)] 
ast: Change *Path nodes API

gcc/rust/ChangeLog:

* ast/rust-ast.h: Change Path API to be more consistent.
* ast/rust-path.h: Likewise.
* ast/rust-ast-collector.cc (TokenCollector::visit): Use new API.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise.
* resolve/rust-forever-stack.hxx: Likewise.

20 months agoAdd new test for parsing errors on self pointers
Pierre-Emmanuel Patry [Wed, 15 Nov 2023 12:53:23 +0000 (13:53 +0100)] 
Add new test for parsing errors on self pointers

Add new tests to highlight the behavior of errors thrown when meeting a
self pointer.

gcc/testsuite/ChangeLog:

* rust/compile/self_const_ptr.rs: New test.
* rust/compile/self_mut_ptr.rs: New test.
* rust/compile/self_ptr.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoReport self parameter parsing error kind
Pierre-Emmanuel Patry [Wed, 15 Nov 2023 12:02:28 +0000 (13:02 +0100)] 
Report self parameter parsing error kind

Self parameter parsing errors may come from different situations, which
should not be handled in the same way. It is now possible to
differentiate a missing self parameter from a self pointer or a parsing
error.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_function): Early return on
unrecoverable errors.
(Parser::parse_trait_item): Likewise.
(Parser::parse_self_param): Update return type.
* parse/rust-parse.h (enum ParseSelfError): Add enumeration to describe
different self parameter parsing errors.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoFix error emission for self pointers
Pierre-Emmanuel Patry [Wed, 15 Nov 2023 10:08:09 +0000 (11:08 +0100)] 
Fix error emission for self pointers

Self pointer checking loop condition was inverted, the latter was
therefore never executed.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_self_param): Fix the loop
exit condition.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd a test to highlight public trait type parsing
Pierre-Emmanuel Patry [Thu, 2 Nov 2023 16:29:16 +0000 (17:29 +0100)] 
Add a test to highlight public trait type parsing

This new test highlight the parser's behavior around public trait types.

gcc/testsuite/ChangeLog:

* rust/compile/trait_pub_type.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd visibility to trait item
Pierre-Emmanuel Patry [Thu, 2 Nov 2023 16:10:33 +0000 (17:10 +0100)] 
Add visibility to trait item

The compiler shall parse visibility modifiers on trait items and reject
those at a later stage (ast validation).

gcc/rust/ChangeLog:

* ast/rust-item.h (struct Visibility): Move Visibility from here...
* ast/rust-ast.h (struct Visibility): ...to here.
* parse/rust-parse-impl.h (Parser::parse_trait_item): Parse visibility
before giving it back to the item parsing function.
(Parser::parse_trait_type): Add visibility modifier.
* parse/rust-parse.h (RUST_PARSE_H): Change function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdjust item kind enums for TupleStructItems and TuplePatternItems
Owen Avery [Fri, 6 Oct 2023 13:15:17 +0000 (09:15 -0400)] 
Adjust item kind enums for TupleStructItems and TuplePatternItems

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(TupleStructItems::ItemType::RANGE): Rename to...
(TupleStructItems::ItemType::RANGED): ...here.
(TupleStructItems::ItemType::NO_RANGE): Rename to...
(TupleStructItems::ItemType::MULTIPLE): ...here.

(TuplePatternItems::TuplePatternItemType): Rename to...
(TuplePatternItems::ItemType): ...here.

: Handle renames.

* backend/rust-compile-pattern.cc: Likewise.
* typecheck/rust-hir-type-check-pattern.cc: Likewise.
* checks/errors/borrowck/rust-bir-builder-pattern.h: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
20 months agoAdd a new test for float disambiguation
Pierre-Emmanuel Patry [Tue, 31 Oct 2023 14:43:51 +0000 (15:43 +0100)] 
Add a new test for float disambiguation

This new regression test highlight the behavior fixed for float
disambiguation with empty floating point.

gcc/testsuite/ChangeLog:

* rust/compile/tuple_float_index.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoFix float lexing and tuple index disambiguation
Pierre-Emmanuel Patry [Tue, 31 Oct 2023 14:23:45 +0000 (15:23 +0100)] 
Fix float lexing and tuple index disambiguation

When a float has a floating point but no value after it, a zero was added
this lead to errors when trying to disambiguate a float into a tuple
index.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::parse_decimal_int_or_float): Remove
additional zero after empty floating point.
* parse/rust-parse-impl.h (Parser::left_denotation): Handle float with
empty floating point.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agogccrs: v0-mangle closures
Raiki Tamura [Thu, 12 Oct 2023 08:24:46 +0000 (17:24 +0900)] 
gccrs: v0-mangle closures

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::generate_closure_function):
Fix reference to node.
* backend/rust-mangle.cc (struct V0Path): Modified to accept closures.
(v0_crate_path): Modified to accept closures.
(v0_closure): New function to mangle closures.
(v0_path): Modified to accept closures
* util/rust-mapping-common.h (UNKNOWN_NODEID): Change to UINT32_MAX.
(UNKNOWN_HIRID): Change to UINT32_MAX.

gcc/testsuite/ChangeLog:

* rust/compile/v0-mangle2.rs: New test.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
20 months agoMove default visitor templates to header
Pierre-Emmanuel Patry [Tue, 7 Nov 2023 12:02:20 +0000 (13:02 +0100)] 
Move default visitor templates to header

Move default ast visitor template implementation to headers in order to
match the codebase and avoid link errors.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Move from here...
* ast/rust-ast-visitor.h: ... to here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoMove templated functions to header file
Pierre-Emmanuel Patry [Tue, 7 Nov 2023 10:37:39 +0000 (11:37 +0100)] 
Move templated functions to header file

Templated functions shall remain in header files to stay in line with the
rest of the codebase.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Move to header
file.
(TokenCollector::visit_items_joined_by_separator): Likewise.
(TokenCollector::visit_as_line): Likewise.
(TokenCollector::visit_items_as_lines): Likewise.
(TokenCollector::visit_items_as_block): Likewise.
* ast/rust-ast-collector.h: Add implementation.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoBump actions/upload-artifact from v2 to v3
Owen Avery [Wed, 8 Nov 2023 14:12:37 +0000 (09:12 -0500)] 
Bump actions/upload-artifact from v2 to v3

ChangeLog:

* .github/workflows/ccpp.yml:
Bump actions/upload-artifact from v2 to v3.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
20 months agoRework function special parameters
Pierre-Emmanuel Patry [Sun, 12 Nov 2023 20:44:07 +0000 (21:44 +0100)] 
Rework function special parameters

Make self param and variadic param Param, introduce Param class and make
function parameters param too.
Self can now be represented as a standard parameter and is thus no longer
required as a separate function attribute.
Prevent self pointers and allow self in standard functions during parsing
so they could be rejected at a later stage.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Add visitor for
VariadicParam and remove Self parameter visitor from Function visit.
* expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_self_param): Remove
function.
(CfgStrip::maybe_strip_trait_method_decl): Remove self parameter visit.
(CfgStrip::maybe_strip_function_params): Handle new function
parameters.
(CfgStrip::visit): Handle VariadicParam, SelfParam and FunctionParam.
* expand/rust-expand-visitor.cc (ExpandVisitor::expand_self_param):
Remove function.
(ExpandVisitor::expand_trait_method_decl): Do not visit self parameter.
(ExpandVisitor::visit): Add visit for VariadicParam, FunctionParam and
SelfParam.
(ExpandVisitor::expand_function_params): Visit parameters instead.
* expand/rust-expand-visitor.h: Update function prototypes.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Update visit
with new parameters.
(ResolveTraitItems::visit): Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Update visit functions with the new visitor functions for VariadicParam
SelfParam and FunctionParam.
* resolve/rust-early-name-resolver.h: Update function prototypes.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Update visitor
according to the new function parameter structures.
* ast/rust-ast-visitor.h: Update prototypes and add visitor virtual
functions for SelfParam, FunctionParam and VariadicParam.
* ast/rust-ast.cc (Function::Function): Move constructor in
implementation instead of header.
(Function::operator=): Likewise.
(Function::as_string): Update function with pointer dereference.
(VariadicParam::as_string): Likewise.
(TraitFunctionDecl::as_string): Likewise.
(TraitMethodDecl::as_string): Likewise.
(FunctionParam::accept_vis): Add function for visitor.
(SelfParam::accept_vis): Likewise.
(VariadicParam::accept_vis): Likewise.
(TraitItemFunc::TraitItemFunc): Move constructor to implementation
file.
(TraitItemFunc::operator=): Likewise.
(TraitItemMethod::TraitItemMethod): Likewise.
(TraitItemMethod::operator=): Likewise.
* ast/rust-item.h (class Function): Remove self optional member.
(class TraitMethodDecl): Likewise.
(class TraitFunctionDecl): Likewise.
(class Param): Add abstract parameter class.
(class SelfParam): Inherit from Param and remove parameter common
members.
(class FunctionParam): Likewise.
(class VariadicParam): Likewise.
(struct Visibility): Move structure declaration.
(class VisItem):  Likewise.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
a self parameter check during AST validation.
* checks/errors/rust-ast-validation.h: Add function prototype.
* expand/rust-derive-clone.cc (DeriveClone::clone_fn): Update function
constructor.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_self): Rework
function for the new parameters.
(ASTLoweringBase::visit): Add visit functions for VariadicParam,
FunctionParam and SelfParam.
* hir/rust-ast-lower-base.h: Update function prototypes.
* parse/rust-parse-impl.h (Parser::parse_function): Update function
according to new function representation.
(Parser::parse_function_param): Return vector of abstract param instead
of FunctionParam.
(Parser::parse_method): Update according to new representation.
(Parser::parse_trait_item): Likewise.
(Parser::parse_self_param): Error out with
self pointers and prevent the lexer from eating regular function
parameters. Update return type.
* parse/rust-parse.h: Update function return types.
* ast/rust-ast-collector.h: Add VariadicParam visit prototype.
* ast/rust-ast.h (struct Visibility): Move struct declaration.
(class VisItem): Likewise.
* ast/rust-expr.h: Update included files.
* checks/errors/rust-feature-gate.h: Add visitor functions for
SelfParam, FunctionParam and VariadicParam.
* expand/rust-cfg-strip.h: Update function prototypes.
* expand/rust-derive.h: Likewise.
* hir/rust-ast-lower-implitem.h: Handle special arguments.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Likewise.
* metadata/rust-export-metadata.cc (ExportContext::emit_function):
Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Add visitor
functions.
* resolve/rust-ast-resolve-base.h: Update prototypes.
* resolve/rust-ast-resolve-stmt.h: Handle new parameter kind.
* resolve/rust-default-resolver.cc (DefaultResolver::visit): Likewise.
* resolve/rust-default-resolver.h: Update prototype.
* util/rust-attributes.cc (AttributeChecker::visit): Add visitor
functions for SelfParam and VariadicParam.
* util/rust-attributes.h: Add visit prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd new test for invalid variadics
Pierre-Emmanuel Patry [Thu, 9 Nov 2023 22:29:05 +0000 (23:29 +0100)] 
Add new test for invalid variadics

Highlight invalid variadic filtering through the ast validation checker.

gcc/testsuite/ChangeLog:

* rust/compile/invalid_variadics.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd multiple check on variadics position
Pierre-Emmanuel Patry [Thu, 9 Nov 2023 21:51:31 +0000 (22:51 +0100)] 
Add multiple check on variadics position

Variadics are forbidden alone as well as non final position, this should
be checked during ast validation.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Add
check for additional named argument as well as variadic argument's
position.
* checks/errors/rust-ast-validation.h: Add visit function prototype for
external functions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd trait context to ContextualASTVisitor
Pierre-Emmanuel Patry [Thu, 9 Nov 2023 18:45:08 +0000 (19:45 +0100)] 
Add trait context to ContextualASTVisitor

Some construct are forbidden in trait context (eg. pub, async...) and
we'll need to reject those. To do so we need to identify a trait context.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Push the new
trait context when visiting a trait.
* ast/rust-ast-visitor.h: Add visit function prototype and TRAIT
context.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd regression test for invalid label name
Pierre-Emmanuel Patry [Thu, 9 Nov 2023 14:45:04 +0000 (15:45 +0100)] 
Add regression test for invalid label name

An error message should be emitted when the rust code contains invalid
label name. Add a new test for this behavior.

gcc/testsuite/ChangeLog:

* rust/compile/invalid_label_name.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoChange error location for LoopLabel
Pierre-Emmanuel Patry [Thu, 9 Nov 2023 14:30:32 +0000 (15:30 +0100)] 
Change error location for LoopLabel

Loop label error reporting during ast validation was done at loop label
level. It lead to some innacurate error reporting in break loop labels
due to the way the label is built.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Change
reported error location to the lifetime location.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd validation pass for label name
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 15:50:50 +0000 (16:50 +0100)] 
Add validation pass for label name

Prevent from using reserved keyword in label name.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Check if there is
a label before visit.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Emit an
error when a label has a forbidden name.
* checks/errors/rust-ast-validation.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoUse a loop label in break expression
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 15:34:19 +0000 (16:34 +0100)] 
Use a loop label in break expression

Break expression were using a raw lifetime value instead of a loop label
this behavior would have lead to some errors in ast validation.

gcc/rust/ChangeLog:

* ast/rust-expr.h (class BreakExpr): Change Lifetime to LoopLabel.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Lower lifetime
inside the label instead.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Resolve the
inner lifetime.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoUse keyword const values instead of raw values
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 14:22:33 +0000 (15:22 +0100)] 
Use keyword const values instead of raw values

Change the keyword values from a raw string value to their matching const
value in utils.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::parse_raw_identifier): Use const value.
* parse/rust-parse-impl.h (Parser::parse_simple_path_segment):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoChange keyword set to a map
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 13:54:51 +0000 (14:54 +0100)] 
Change keyword set to a map

Some part of the code requires the token id behind a given keyword, a map
keep the "set" aspect whilst providing this additional feature.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (RS_TOKEN): Remove local map.
(RS_TOKEN_KEYWORD): Likewise.
(Lexer::classify_keyword): Change call to utils.
* util/rust-keyword-values.cc (get_keywords): Add init function.
(RS_TOKEN_KEYWORD): Call to X macro.
* util/rust-keyword-values.h: Change from set to a map.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoReplace local keyword set with the utils
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 09:57:48 +0000 (10:57 +0100)] 
Replace local keyword set with the utils

We don't require that local set anymore.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (RS_TOKEN): Remove locale set.
(RS_TOKEN_KEYWORD): Likewise.
(ASTValidation::visit): Change keyword set call to the one from utils.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd new keyword utility class
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 09:50:00 +0000 (10:50 +0100)] 
Add new keyword utility class

Much like attributes values, keywords are known beforehand and never
change. Instead of relying on handcrafted string we could centralize
everything in one place. We may require to check whether a word is a
keyword, which can now be done easily thanks to the keyword set.

gcc/rust/ChangeLog:

* Make-lang.in: Add rust-keyword-values.cc to the list.
* util/rust-keyword-values.cc: New file.
* util/rust-keyword-values.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd licence text and change header guard name
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 09:46:22 +0000 (10:46 +0100)] 
Add licence text and change header guard name

This file was missing a licence text and it's header guard was not
matching the file name.

gcc/rust/ChangeLog:

* util/rust-attribute-values.h (RUST_ATTRIBUTES_VALUE_H): Remove old
header guard.
(RUST_ATTRIBUTE_VALUES_H): Add new one.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd regression test for lifetime name validation
Pierre-Emmanuel Patry [Tue, 7 Nov 2023 18:13:57 +0000 (19:13 +0100)] 
Add regression test for lifetime name validation

Lifetime name are restricted and cannot be keyword, this commit add a
test failing the ast validation pass due to some keyword name.

gcc/testsuite/ChangeLog:

* rust/compile/lifetime_name_validation.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
20 months agoAdd lifetime name validation pass
Pierre-Emmanuel Patry [Tue, 7 Nov 2023 17:32:58 +0000 (18:32 +0100)] 
Add lifetime name validation pass

Add lifetime name check in ast validation visitor.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (RS_TOKEN): Add keyword set.
(RS_TOKEN_KEYWORD): Likewise.
(ASTValidation::visit): Add validation on lifetime visit.
* checks/errors/rust-ast-validation.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoReplace AST::Method with existing AST::Function
Owen Avery [Sat, 28 Oct 2023 05:04:19 +0000 (01:04 -0400)] 
Replace AST::Method with existing AST::Function

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>
21 months agoAdd named variadic argument test
Pierre-Emmanuel Patry [Mon, 6 Nov 2023 10:37:50 +0000 (11:37 +0100)] 
Add named variadic argument test

Variadic arguments may have a name or a pattern. This commit provides two
new tests in order to ensure their correct behavior.

gcc/testsuite/ChangeLog:

* rust/compile/pattern_variadic.rs: New test.
* rust/execute/torture/named_variadic.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoAdd a new regression test for named variadics
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 12:02:59 +0000 (14:02 +0200)] 
Add a new regression test for named variadics

This test ensure that extern C named variadics are parsed correctly.

gcc/testsuite/ChangeLog:

* rust/compile/extern_c_named_variadic.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoParse named variadic parameters
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 11:41:35 +0000 (13:41 +0200)] 
Parse named variadic parameters

Add ability to parse named variadic parameters in extern c functions.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_named_function_param): Add
new parsing ability.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoAdd a new regression test
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 11:22:11 +0000 (13:22 +0200)] 
Add a new regression test

This new test highlight the behavior of the new parser and it's ability
to parse variadic rust functions.

gcc/testsuite/ChangeLog:

* rust/compile/parse_variadic_function.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoFix multiple issues with variadic representation
Pierre-Emmanuel Patry [Thu, 19 Oct 2023 13:23:26 +0000 (15:23 +0200)] 
Fix multiple issues with variadic representation

The new variadic representation has introduced multiple issues and ICE
into the codebase. Some early passes in the compiler depend on the
parameters all having a type and being an actual parameter.

gcc/rust/ChangeLog:

* ast/rust-ast.cc (ExternalFunctionItem::as_string): Adapt as_string
function to the new ast representation.
(NamedFunctionParam::as_string): Likewise.
* ast/rust-item.h: Add a function to test whether a FunctionParam has
a name pattern.
* expand/rust-cfg-strip.cc (CfgStrip::visit): Adapt cfg strip visitor
for the new variadic arguments.
* hir/rust-ast-lower-extern.h: Adapt lowering to the new variadic
function representation.
* metadata/rust-export-metadata.cc (ExportContext::emit_function):
Change call to constructor.
* parse/rust-parse-impl.h (Parser::parse_named_function_param): Change
NamedFunctionParam parsing to accomodate new variadic representation.
(Parser::parse_external_item): Change external item parsing to use the
new NamedFunctionParam variadics.
* parse/rust-parse.h: Add new parsing function prototypes.
* ast/rust-ast-collector.cc (TokenCollector::visit): Rework token
collection to take into account variadic parameters.
* ast/rust-ast-visitor.cc: Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Change function
bound to avoid getting the type of a variadic parameter.
* resolve/rust-ast-resolve-item.cc (ResolveExternItem::visit):
Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoAllow variadic NamedFunctionParam
Pierre-Emmanuel Patry [Wed, 18 Oct 2023 13:30:57 +0000 (15:30 +0200)] 
Allow variadic NamedFunctionParam

This was made to align NamedFunctionParam with FunctionParam.

gcc/rust/ChangeLog:

* ast/rust-item.h (class NamedFunctionParam): Add variadic boolean and
another constructor.
* hir/rust-ast-lower-extern.h: Avoid last parameter when variadic.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoAdd a function to check if a function is variadic
Pierre-Emmanuel Patry [Wed, 18 Oct 2023 13:04:58 +0000 (15:04 +0200)] 
Add a function to check if a function is variadic

This function provides an easy way to check for a function's varidicity.

gcc/rust/ChangeLog:

* ast/rust-item.h: Add a getter to check if a given function is
variadic.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoParse variadic functions
Pierre-Emmanuel Patry [Wed, 18 Oct 2023 12:31:53 +0000 (14:31 +0200)] 
Parse variadic functions

Variadic functions were not parsed because it is an unstable feature.
While it is still unstable, it is required in order to parse libcore.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_function_param): Parse
variadic functions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoChange FunctionParam to represent variadic params
Pierre-Emmanuel Patry [Wed, 18 Oct 2023 12:24:31 +0000 (14:24 +0200)] 
Change FunctionParam to represent variadic params

Variadic were represented at the function level while retaining most
informations of a given parameter.

gcc/rust/ChangeLog:

* ast/rust-item.h (class FunctionParam): Add some informations to
function parameters in order to be able to store variadic argument as
a function parameter.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoAdd a new test for const without body
Pierre-Emmanuel Patry [Thu, 26 Oct 2023 13:48:52 +0000 (15:48 +0200)] 
Add a new test for const without body

This new regression test highlight the fixed behavior for 2709.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2709.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoMake use of the Contextual visitor in validation
Pierre-Emmanuel Patry [Thu, 26 Oct 2023 11:30:28 +0000 (13:30 +0200)] 
Make use of the Contextual visitor in validation

Use the new contextual ast visitor to reduce the amount of code in the
ast validation visitor.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::visit): Adapt
the call to the new visit functions.
(ASTValidation::check): Launch the parent class visitor root function.
* checks/errors/rust-ast-validation.h (class ASTValidation): Inherit
from the contextual visitor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoAdd a new visitor that gathers context information
Pierre-Emmanuel Patry [Thu, 26 Oct 2023 11:26:13 +0000 (13:26 +0200)] 
Add a new visitor that gathers context information

This visitor is intended to be used by other visitors that require
context at some point for a given item.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc (ContextualASTVisitor::visit): Add multiple
context saving calls.
* ast/rust-ast-visitor.h (class DefaultASTVisitor): Make visit
functions virtual.
(class ContextualASTVisitor): Add a stack like container for the
current context chain.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoAdd a default AST visitor
Pierre-Emmanuel Patry [Wed, 25 Oct 2023 14:56:09 +0000 (16:56 +0200)] 
Add a default AST visitor

This will allow us to derive other visitors from it and overload only a
few selected visit methods.

gcc/rust/ChangeLog:

* Make-lang.in: Add the new visitor object file.
* ast/rust-ast-visitor.h (class DefaultASTVisitor): Create the default
visitor class.
* ast/rust-ast.h: Add a new reference getter for visitor pattern.
* ast/rust-ast-visitor.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoAdd some reference getter
Pierre-Emmanuel Patry [Wed, 25 Oct 2023 14:53:59 +0000 (16:53 +0200)] 
Add some reference getter

Visitor pattern requires a getter to children using a mutable reference.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add some missing mutable reference getters.
* ast/rust-expr.h: Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-path.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoSmall fix to the ast collector visitor
Pierre-Emmanuel Patry [Wed, 25 Oct 2023 14:51:31 +0000 (16:51 +0200)] 
Small fix to the ast collector visitor

The parameter type was used instead of the default value.

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Check for presence
of a type and use the default value instead of the type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoEmit an error on associated const without values
Pierre-Emmanuel Patry [Tue, 24 Oct 2023 15:13:13 +0000 (17:13 +0200)] 
Emit an error on associated const without values

Associated const with no value that are not in trait impl are prohibited.

gcc/rust/ChangeLog:

* checks/errors/rust-ast-validation.cc (ASTValidation::check): Launch
check over the whole given crate.
(ASTValidation::visit): Implement visitor for some members of the ast.
* checks/errors/rust-ast-validation.h: Update some prototype according
to implemented visitor functions. Also add a context tracker.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
21 months agoAdd call to ast validation checker
Pierre-Emmanuel Patry [Tue, 24 Oct 2023 14:46:21 +0000 (16:46 +0200)] 
Add call to ast validation checker

Add call to ast validation check, also add appropriate step to this pass
and the feature gating.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Add call to ast
validation.

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