]> gcc.gnu.org Git - gcc.git/log
gcc.git
7 months agogccrs: Add new keyword utility class
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 09:50:00 +0000 (10:50 +0100)]
gccrs: 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>
7 months agogccrs: Add licence text and change header guard name
Pierre-Emmanuel Patry [Wed, 8 Nov 2023 09:46:22 +0000 (10:46 +0100)]
gccrs: 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>
7 months agogccrs: Add regression test for lifetime name validation
Pierre-Emmanuel Patry [Tue, 7 Nov 2023 18:13:57 +0000 (19:13 +0100)]
gccrs: 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>
7 months agogccrs: Add lifetime name validation pass
Pierre-Emmanuel Patry [Tue, 7 Nov 2023 17:32:58 +0000 (18:32 +0100)]
gccrs: 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>
7 months agogccrs: Replace AST::Method with existing AST::Function
Owen Avery [Sat, 28 Oct 2023 05:04:19 +0000 (01:04 -0400)]
gccrs: 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>
7 months agogccrs: Add named variadic argument test
Pierre-Emmanuel Patry [Mon, 6 Nov 2023 10:37:50 +0000 (11:37 +0100)]
gccrs: 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>
7 months agogccrs: Add a new regression test for named variadics
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 12:02:59 +0000 (14:02 +0200)]
gccrs: 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>
7 months agogccrs: Parse named variadic parameters
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 11:41:35 +0000 (13:41 +0200)]
gccrs: 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>
7 months agogccrs: Add a new regression test
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 11:22:11 +0000 (13:22 +0200)]
gccrs: 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>
7 months agogccrs: Fix multiple issues with variadic representation
Pierre-Emmanuel Patry [Thu, 19 Oct 2023 13:23:26 +0000 (15:23 +0200)]
gccrs: 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>
7 months agogccrs: Allow variadic NamedFunctionParam
Pierre-Emmanuel Patry [Wed, 18 Oct 2023 13:30:57 +0000 (15:30 +0200)]
gccrs: 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>
7 months agogccrs: Add a function to check if a function is variadic
Pierre-Emmanuel Patry [Wed, 18 Oct 2023 13:04:58 +0000 (15:04 +0200)]
gccrs: 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>
7 months agogccrs: Parse variadic functions
Pierre-Emmanuel Patry [Wed, 18 Oct 2023 12:31:53 +0000 (14:31 +0200)]
gccrs: 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>
7 months agogccrs: Change FunctionParam to represent variadic params
Pierre-Emmanuel Patry [Wed, 18 Oct 2023 12:24:31 +0000 (14:24 +0200)]
gccrs: 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>
7 months agogccrs: Add a new test for const without body
Pierre-Emmanuel Patry [Thu, 26 Oct 2023 13:48:52 +0000 (15:48 +0200)]
gccrs: 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>
7 months agogccrs: Make use of the Contextual visitor in validation
Pierre-Emmanuel Patry [Thu, 26 Oct 2023 11:30:28 +0000 (13:30 +0200)]
gccrs: 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>
7 months agogccrs: Add a new visitor that gathers context information
Pierre-Emmanuel Patry [Thu, 26 Oct 2023 11:26:13 +0000 (13:26 +0200)]
gccrs: 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>
7 months agogccrs: Add a default AST visitor
Pierre-Emmanuel Patry [Wed, 25 Oct 2023 14:56:09 +0000 (16:56 +0200)]
gccrs: 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>
7 months agogccrs: Add some reference getter
Pierre-Emmanuel Patry [Wed, 25 Oct 2023 14:53:59 +0000 (16:53 +0200)]
gccrs: 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>
7 months agogccrs: Small fix to the ast collector visitor
Pierre-Emmanuel Patry [Wed, 25 Oct 2023 14:51:31 +0000 (16:51 +0200)]
gccrs: 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>
7 months agogccrs: Emit an error on associated const without values
Pierre-Emmanuel Patry [Tue, 24 Oct 2023 15:13:13 +0000 (17:13 +0200)]
gccrs: 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>
7 months agogccrs: Add call to ast validation checker
Pierre-Emmanuel Patry [Tue, 24 Oct 2023 14:46:21 +0000 (16:46 +0200)]
gccrs: 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>
7 months agogccrs: Add two new steps to compile process
Pierre-Emmanuel Patry [Tue, 24 Oct 2023 14:16:34 +0000 (16:16 +0200)]
gccrs: Add two new steps to compile process

Add the ast validation and feature gating steps to the compile pipeline.

gcc/rust/ChangeLog:

* lang.opt: Add the new compile options and update the enum values.
* rust-session-manager.h (struct CompileOptions): Add the new steps to
the enumeration.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add ast validation checker
Pierre-Emmanuel Patry [Tue, 24 Oct 2023 14:08:00 +0000 (16:08 +0200)]
gccrs: Add ast validation checker

Add a new visitor to validate a given ast after the expansion pass.

gcc/rust/ChangeLog:

* Make-lang.in: Add the new object file the list.
* checks/errors/rust-ast-validation.cc: New file.
* checks/errors/rust-ast-validation.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add more checks for expr value in early visitors
Pierre-Emmanuel Patry [Tue, 24 Oct 2023 14:01:52 +0000 (16:01 +0200)]
gccrs: Add more checks for expr value in early visitors

Early passes visitors may encounter constant item without a value, this
is expected as the pass rejecting a constant without an expression is
done later during the ast validation.

gcc/rust/ChangeLog:

* expand/rust-cfg-strip.cc (CfgStrip::visit): Add expr value check.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Move SingleASTNode implementation out of header
Pierre-Emmanuel Patry [Thu, 2 Nov 2023 17:23:03 +0000 (18:23 +0100)]
gccrs: Move SingleASTNode implementation out of header

Those functions implementation put additional constraints on the headers
which makes the codebase harder to work with.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Move implementation from here...
* ast/rust-ast.cc (SingleASTNode::SingleASTNode): ...to here.
(SingleASTNode::operator=): ...and here...
(SingleASTNode::accept_vis): ...and here...
(SingleASTNode::is_error): ...and here...
(SingleASTNode::as_string): ...also here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add missing override specifier
Pierre-Emmanuel Patry [Thu, 2 Nov 2023 17:10:32 +0000 (18:10 +0100)]
gccrs: Add missing override specifier

Some function lacked the override specifier, this made the compiler emit
several warning.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add override specifier.
* ast/rust-item.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add regression test for float literal tuple indices
Pierre-Emmanuel Patry [Tue, 17 Oct 2023 11:40:47 +0000 (13:40 +0200)]
gccrs: Add regression test for float literal tuple indices

Add a new regression test in order to highlight the fix for #2659.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Fix token lexed as a float literal
Pierre-Emmanuel Patry [Tue, 17 Oct 2023 11:24:54 +0000 (13:24 +0200)]
gccrs: Fix token lexed as a float literal

The lexer cannot distinguish the difference between a float literal and a
tuple index in some cases. This means we should fix this while parsing
depending on the context.

gcc/rust/ChangeLog:

* expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::split_current_token):
Add implementation for multiple token split.
* expand/rust-macro-invoc-lexer.h: Add function prototype.
* expand/rust-proc-macro-invoc-lexer.cc (ProcMacroInvocLexer::split_current_token):
Add implementation for 2+ token split for procedural macros.
* expand/rust-proc-macro-invoc-lexer.h: Add function prototype.
* lex/rust-lex.cc (Lexer::split_current_token): Add function to split a
token in multiple other tokens.
* lex/rust-lex.h: Add function prototype for split_current_token.
* parse/rust-parse-impl.h (Parser::left_denotation): Handle float tuple
index identified as a float literal.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: HIR: remove obsole double borrow member
Jakub Dupak [Thu, 2 Nov 2023 12:42:48 +0000 (13:42 +0100)]
gccrs: HIR: remove obsole double borrow member

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): Remove obsolete member.
* hir/tree/rust-hir-expr.h (class BorrowExpr): Remove obsolete member.
* hir/tree/rust-hir.cc (BorrowExpr::as_string): Remove obsolete member.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: HIR: fix typo
Jakub Dupak [Thu, 2 Nov 2023 12:31:17 +0000 (13:31 +0100)]
gccrs: HIR: fix typo

gcc/rust/ChangeLog:

* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Fix typo.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: Compile pattern match statements into conditional statements
Owen Avery [Mon, 23 Oct 2023 01:44:01 +0000 (21:44 -0400)]
gccrs: Compile pattern match statements into conditional statements

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc
(patterns_mergeable): Remove.
(struct PatternMerge): Remove.
(sort_tuple_patterns): Remove.
(simplify_tuple_match): Remove.
(CompileExpr::visit): Modify compilation of MatchExpr.

* backend/rust-compile-pattern.cc
(CompilePatternCaseLabelExpr::visit): Replace with...
(CompilePatternCheckExpr::visit): ...this.
* backend/rust-compile-pattern.h
(class CompilePatternCaseLabelExpr): Replace with...
(class CompilePatternCheckExpr): ...this.

* backend/rust-compile-type.cc
(TyTyResolveCompile::get_implicit_enumeral_node_type):
Make enumeral type equivalent to isize.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 months agogccrs: Document proc macro token tree indices
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 13:00:54 +0000 (15:00 +0200)]
gccrs: Document proc macro token tree indices

Multiple references to procedural macro token trees were left as magic
number in the code. This commit introduces some constexpr for those along
some explanation for the selected value.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (get_attributes): Add documentation for
indices 3 and 4.
(get_trait_name): Add documentation for index 1.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Move proc macro builders to their own file
Pierre-Emmanuel Patry [Tue, 17 Oct 2023 14:00:30 +0000 (16:00 +0200)]
gccrs: Move proc macro builders to their own file

The code to build the required procedural macro symbols is rather long
and could be placed in it's own file.

gcc/rust/ChangeLog:

* Make-lang.in: Add gcc/rust/backend/rust-compile-proc-macro.cc to the
list of file to compile.
* backend/rust-compile.cc (attribute_array): Move to
rust-compile-proc-macro.cc
(derive_proc_macro): Likewise.
(bang_proc_macro): Likewise.
(attribute_proc_macro): Likewise.
(proc_macro_payload): Likewise.
(proc_macro): Likewise.
(proc_macro_buffer): Likewise.
(entrypoint): Likewise.
(proc_macro_array): Likewise.
(CompileCrate::add_proc_macro_symbols): Likewise.
* backend/rust-compile-proc-macro.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add array length to the proc macro buffer
Pierre-Emmanuel Patry [Thu, 5 Oct 2023 10:28:38 +0000 (12:28 +0200)]
gccrs: Add array length to the proc macro buffer

The compiler cannot infer the array length from the type, we should
therefore hand it the information. The proc macro buffer missed that
information.

gcc/rust/ChangeLog:

* backend/rust-compile.cc (proc_macro_buffer): Update type builder with
array length information.
(proc_macro_array): Update type initializer with array length
information.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Put common functions in their own namespace
Pierre-Emmanuel Patry [Wed, 4 Oct 2023 16:48:04 +0000 (18:48 +0200)]
gccrs: Put common functions in their own namespace

Half of the functions introduced recently had a similar goal while the
other half had a similar goal too. Introducing some namespace to separate
those will keep the code cleaner and avoid confusion.

gcc/rust/ChangeLog:

* backend/rust-compile.cc (build_attribute_array): Renamed from...
(attribute_array): ...to attribute array.
(build_derive_proc_macro): Likewise from...
(derive_proc_macro): ... to derive_proc_macro.
(build_bang_proc_macro): Likewise from...
(bang_proc_macro): ...to bang_proc_macro.
(build_attribute_proc_macro): Likewise from...
(attribute_proc_macro): ... to attribute_proc_macro.
(build_proc_macro_payload): Likewise from...
(proc_macro_payload): to proc_macro_payload.
(build_proc_macro): Likewise from...
(proc_macro): ...to proc_macro.
(build_proc_macro_buffer): Likewise from...
(proc_macro_buffer): ... to proc_macro_buffer.
(build_entrypoint): Likewise from...
(entrypoint): ...to entrypoint.
(init_derive_proc_macro): Renamed to it's shorter counterpart.
(init_attribute_proc_macro): Likewise.
(init_bang_proc_macro): Likewise.
(init_proc_macro): Likewise.
(initialize_proc_macro_array): Likewise.
(proc_macro_array): Likewise.
(CompileCrate::add_proc_macro_symbols): Update function calls.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add macro buffer global variable export
Pierre-Emmanuel Patry [Wed, 20 Sep 2023 15:39:16 +0000 (17:39 +0200)]
gccrs: Add macro buffer global variable export

Export a new symbol containing the proc macros.

gcc/rust/ChangeLog:

* backend/rust-compile-base.h: Make static function address_expression
public.
* backend/rust-compile.cc (CompileCrate::add_proc_macro_symbols): Add
new global variable in export function.
(build_bang_proc_macro): Add a function to build the bang proc macro
structure type.
(build_proc_macro): Add a function to build the proc macro structure
type.
(build_proc_macro_payload): Add a function to build the proc macro
union used in proc macro structures.
(init_derive_proc_macro): Add a function to initialize custom derive
proc macros.
(init_attribute_proc_macro): Add a function to initialize attribute
proc macros.
(init_bang_proc_macro): Add a function to initialize bang proc macros.
(init_proc_macro): Add a function to initialize proc macro structures.
(initialize_proc_macro_array): Add a function to initialize the proc
macro buffer array.
(CompileCrate::add_proc_macro_symbols): Add call to the new functions
to correctly initialize proc macros as well as their entrypoint.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add an explicit value to proc macro enum kind
Pierre-Emmanuel Patry [Wed, 27 Sep 2023 14:21:25 +0000 (16:21 +0200)]
gccrs: Add an explicit value to proc macro enum kind

We'll need this value in the final binary, it should therefore be kept
explicit.

libgrust/ChangeLog:

* libproc_macro_internal/proc_macro.h (enum ProcmacroTag): Add
explicit value for proc macro tag enum.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Change proc macro entrypoint
Pierre-Emmanuel Patry [Wed, 4 Oct 2023 10:01:44 +0000 (12:01 +0200)]
gccrs: Change proc macro entrypoint

Change proc macro entrypoint from a fixed constant declaration to a
proper generation from the stable crate id. Although the stable crate id
is not in use yet, the mechanism to handle it is.

gcc/rust/ChangeLog:

* expand/rust-proc-macro.cc (CustomDeriveProcMacro::CustomDeriveProcMacro):
Remove constant string declaration.
(load_macros_array): Add call to the new generation function.
(generate_proc_macro_decls_symbol): Add a new function to generate the
entrypoint symbol name from the stable crate id.
(PROC_MACRO_DECLS_FMT_ARGS):
New macro to keep formats arguments in sync between each call.
* expand/rust-proc-macro.h (generate_proc_macro_decls_symbol): Add
function prototype.
* rust-system.h: Include <iomanip>.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add utility function to build proc macro types
Pierre-Emmanuel Patry [Fri, 15 Sep 2023 09:08:13 +0000 (11:08 +0200)]
gccrs: Add utility function to build proc macro types

Add some utility function to build proc macro entrypoint related types.
Those functions will help generate all required metadata in order for
proc macros to be expanded properly.

gcc/rust/ChangeLog:

* backend/rust-compile.cc (build_attribute_array): Add a function to
build the attribute array type.
(build_derive_proc_macro): Add a function to build the derive proc
macro type.
(build_bang_proc_macro): Add a function to build the bang proc macro
type.
(build_attribute_proc_macro): Add a function to build the attribute
proc macro type.
(build_proc_macro): Add a function to build the proc macro tagged union
type.
(build_proc_macro_buffer): Add a function to build the proc macro
buffer type.
(build_entrypoint): Add a function to build the proc macro entrypoint
type.
* backend/rust-compile.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add getters for proc macro mappings
Pierre-Emmanuel Patry [Fri, 8 Sep 2023 09:23:51 +0000 (11:23 +0200)]
gccrs: Add getters for proc macro mappings

Add three different getters, one for each proc macro type.

gcc/rust/ChangeLog:

* backend/rust-compile-context.h: Add getters.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Collect procedural macros in the crate
Pierre-Emmanuel Patry [Wed, 6 Sep 2023 12:44:20 +0000 (14:44 +0200)]
gccrs: Collect procedural macros in the crate

Collect informations on procedural macros in the compiled crate. For
attribute and bang procedural macros we only require the final address
as well as the name of the function. Derive procedural macros are a bit
different, we collect the fonction's address through it's fndecl tree as
well as the trait's name and the multiple attributes.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::setup_fndecl):
Make the function non static in order to be able to access the
compile context. Also add the whole proc macro infomrmation
collection.
(get_attributes): Add a function to retrieve the different
attributes from a derive procedural macro definition attribute.
(get_trait_name): Add a function to retrieve the trait name from
a derive procedural macro definition attribute.
* backend/rust-compile-base.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Reformat comments
Pierre-Emmanuel Patry [Wed, 6 Sep 2023 12:39:46 +0000 (14:39 +0200)]
gccrs: Reformat comments

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::setup_abi_options):
Reformat uncorrectly formatted comments.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add containers for proc macro collection mappings
Pierre-Emmanuel Patry [Wed, 6 Sep 2023 12:34:45 +0000 (14:34 +0200)]
gccrs: Add containers for proc macro collection mappings

Add one container for each kind of procedural macro mapping. Also add a
new structure to gather informations required for derive procedural
macros. Add different functions to fill those new containers.

gcc/rust/ChangeLog:

* backend/rust-compile-context.h (struct CustomDeriveInfo): Add
new derive procedural macro metadata information holder for
mappings.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add const getter for tokentrees
Pierre-Emmanuel Patry [Wed, 6 Sep 2023 12:09:25 +0000 (14:09 +0200)]
gccrs: Add const getter for tokentrees

We often need to retrieve the underlying tokentree without modifying it,
this getter will help achieve this.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add const getter.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Change ABI setup and add gccrs_proc_macro attr
Pierre-Emmanuel Patry [Mon, 4 Sep 2023 12:23:10 +0000 (14:23 +0200)]
gccrs: Change ABI setup and add gccrs_proc_macro attr

Change the way the ABI is setup on a function to avoid duplicates. ABI
is setup by the setup function only now. Add a new attribute to the
function "gccrs_proc_macro" in order to differentiate it from another
type of function.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (handle_proc_macro_common): Add
new attribute "gccrs_proc_macro" to all procedural macro
functions.
(get_abi): Add a function to retrieve the correct ABI depending
on wether the function is a proc macro or not.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Make proc macro definition cdecl
Pierre-Emmanuel Patry [Mon, 4 Sep 2023 11:22:21 +0000 (13:22 +0200)]
gccrs: Make proc macro definition cdecl

We need to make sure proc macros have the C abi in order to be called by
the compiler with dlopen.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::setup_fndecl):
Add proc macro handlers dispatch.
(handle_proc_macro_common): Add a function for common behavior
between all kinds of proc macros.
* backend/rust-compile-base.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: borrowck: Refactor and BIR improvements
Jakub Dupak [Thu, 19 Oct 2023 13:26:35 +0000 (15:26 +0200)]
gccrs: borrowck: Refactor and BIR improvements

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::setup_loop): Move.
(ExprStmtBuilder::get_label_ctx): Move.
(ExprStmtBuilder::get_unnamed_loop_ctx): Moved.
(ExprStmtBuilder::visit): BIR improvements.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Refactor.
* checks/errors/borrowck/rust-bir-builder-internal.h (class LifetimeResolver):
Refactor.
(struct BuilderContext): Move.Refactor.
(optional_from_ptr): Map on null ptr.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h (class LazyBooleanExprBuilder):
Refactor.
* checks/errors/borrowck/rust-bir-builder-pattern.h: Refactor.
* checks/errors/borrowck/rust-bir-builder-struct.h (class StructBuilder): Refactor.
* checks/errors/borrowck/rust-bir-builder.h: Refactor.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Refactor.
(Dump::visit): Refactor.
(Dump::visit_place): Refactor.
(Dump::visit_move_place): Refactor.
(Dump::visit_lifetime): Refactor.
* checks/errors/borrowck/rust-bir-dump.h: Refactor.
* checks/errors/borrowck/rust-bir-place.h: Refactor.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: Dev notes
Jakub Dupak [Tue, 24 Oct 2023 06:32:20 +0000 (08:32 +0200)]
gccrs: borrowck: Dev notes

gcc/rust/ChangeLog:

* checks/errors/borrowck/dev-notes.md: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: Docs
Jakub Dupak [Wed, 18 Oct 2023 21:11:20 +0000 (23:11 +0200)]
gccrs: borrowck: Docs

gcc/rust/ChangeLog:

* checks/errors/borrowck/bir-design-notes.md: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: Make goto explicit.
Jakub Dupak [Thu, 19 Oct 2023 08:47:50 +0000 (10:47 +0200)]
gccrs: borrowck: Make goto explicit.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Use goto.
* checks/errors/borrowck/rust-bir-builder-internal.h: Explicit goto.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Explicit goto.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: BIR continue
Jakub Dupak [Wed, 18 Oct 2023 21:01:06 +0000 (23:01 +0200)]
gccrs: borrowck: BIR continue

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Continue.
(ExprStmtBuilder::setup_loop): Continue.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: Dump: handle infinite loops
Jakub Dupak [Thu, 19 Oct 2023 09:04:29 +0000 (11:04 +0200)]
gccrs: borrowck: Dump: handle infinite loops

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg): Detech infinite loops.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: BIR: handle break
Jakub Dupak [Wed, 18 Oct 2023 20:54:37 +0000 (22:54 +0200)]
gccrs: borrowck: BIR: handle break

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Push ctx.
(ExprStmtBuilder::setup_loop): Common loop infractructure setup.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Loop ctx.
* checks/errors/borrowck/rust-bir-builder-internal.h (struct BuilderContext): Loop ctx.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: Dump improve jumps
Jakub Dupak [Wed, 18 Oct 2023 21:27:48 +0000 (23:27 +0200)]
gccrs: borrowck: Dump improve jumps

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Improve jumps dump.
(Dump::visit): Improve jumps dump.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Improve jumps dump.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: Dump: simplify cfg
Jakub Dupak [Wed, 18 Oct 2023 20:50:02 +0000 (22:50 +0200)]
gccrs: borrowck: Dump: simplify cfg

Add option to simplify cfg for better readability. Off by default.

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg): Simplify cfg logic.
(Dump::go): Run simplify cfg.
* checks/errors/borrowck/rust-bir-dump.h: Option to simplify cfg.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: Dump: proper comma separation
Jakub Dupak [Wed, 18 Oct 2023 20:38:30 +0000 (22:38 +0200)]
gccrs: borrowck: Dump: proper comma separation

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use new print.
(print_comma_separated): Comma separation print.
(Dump::visit): Use new print.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: BIR dump
Jakub Dupak [Wed, 18 Oct 2023 20:36:38 +0000 (22:36 +0200)]
gccrs: borrowck: BIR dump

gcc/rust/ChangeLog:

* Make-lang.in: Build BIR dump.
* checks/errors/borrowck/rust-borrow-checker.cc (mkdir_wrapped): Cross-platform mkdir.
(dump_function_bir): Save dump to file.
(BorrowChecker::go): Run dump during borrowck.
* checks/errors/borrowck/rust-bir-dump.cc: New file.
* checks/errors/borrowck/rust-bir-dump.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: Create BIR builders (visitors)
Jakub Dupak [Wed, 18 Oct 2023 18:43:17 +0000 (20:43 +0200)]
gccrs: borrowck: Create BIR builders (visitors)

gcc/rust/ChangeLog:

* Make-lang.in: Compile BIR expr visitor.
* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Use BIR builder.
* rust-session-manager.cc (Session::compile_crate): Run borrow checker.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc: New file.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: New file.
* checks/errors/borrowck/rust-bir-builder-internal.h: New file.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: New file.
* checks/errors/borrowck/rust-bir-builder-pattern.h: New file.
* checks/errors/borrowck/rust-bir-builder-struct.h: New file.
* checks/errors/borrowck/rust-bir-builder.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: Create Borrow-checker IR (BIR)
Jakub Dupak [Wed, 18 Oct 2023 17:49:59 +0000 (19:49 +0200)]
gccrs: borrowck: Create Borrow-checker IR (BIR)

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-borrow-checker.cc: Include to compile new code.
* checks/errors/borrowck/rust-bir-place.h: New file.
* checks/errors/borrowck/rust-bir-visitor.h: New file.
* checks/errors/borrowck/rust-bir.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: Execute only with CLI flag
Jakub Dupak [Thu, 19 Oct 2023 09:37:41 +0000 (11:37 +0200)]
gccrs: borrowck: Execute only with CLI flag

gcc/rust/ChangeLog:

* lang.opt: CLI flag.
* rust-session-manager.cc (Session::compile_crate): Guard execution.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: Add CLI option for borrowck
Jakub Dupak [Thu, 19 Oct 2023 08:59:54 +0000 (10:59 +0200)]
gccrs: borrowck: Add CLI option for borrowck

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::BorrowChecker): Opt dump.
(BorrowChecker::go): Opt dump.
* checks/errors/borrowck/rust-borrow-checker.h (class BorrowChecker): Opt dump.
* lang.opt: Add compile until borrowcheck.
* rust-session-manager.cc (Session::enable_dump): Add BIR.
(Session::compile_crate): Handle new options.
* rust-session-manager.h (struct CompileOptions): Add BIR.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: borrowck: Add initial structure for borrowchecking
Jakub Dupak [Wed, 18 Oct 2023 17:09:34 +0000 (19:09 +0200)]
gccrs: borrowck: Add initial structure for borrowchecking

gcc/rust/ChangeLog:

* Make-lang.in: Build borrowck.
* checks/errors/borrowck/rust-borrow-checker.cc: New file.
* checks/errors/borrowck/rust-borrow-checker.h: New file.
* checks/errors/borrowck/rust-function-collector.h: New file.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: Fix warning with overridden virtual methods
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 14:09:54 +0000 (16:09 +0200)]
gccrs: Fix warning with overridden virtual methods

Overridden virtual methods were not marked as such.

gcc/rust/ChangeLog:

* ast/rust-pattern.h: Add override modifier to overriding methods.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add a new regression test for issue 2665
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 15:16:25 +0000 (17:16 +0200)]
gccrs: Add a new regression test for issue 2665

Highlight issue 2665's fix for const with no value expression.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Parse const with no value expression
Pierre-Emmanuel Patry [Mon, 23 Oct 2023 15:06:43 +0000 (17:06 +0200)]
gccrs: Parse const with no value expression

Const with no value expression may exist either in trait or in disabled
blocks. This means we should be able to parse those correctly.

gcc/rust/ChangeLog:

* ast/rust-item.h: Add a new constructor for const with no value
expression.
* parse/rust-parse-impl.h (Parser::parse_const_item): Allow const with
no expression value.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: hir: Avoid copy in getter (PathPattern)
Jakub Dupak [Tue, 17 Oct 2023 15:23:16 +0000 (17:23 +0200)]
gccrs: hir: Avoid copy in getter (PathPattern)

gcc/rust/ChangeLog:

* hir/tree/rust-hir-path.h: Avoid copy in getter.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: hir: Rename ComoundAssignment getters
Jakub Dupak [Tue, 17 Oct 2023 14:21:56 +0000 (16:21 +0200)]
gccrs: hir: Rename ComoundAssignment getters

Use more a consistent name.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Rename method.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Rename method.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Rename method.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Rename method.
* hir/rust-hir-dump.cc (Dump::visit): Rename method.
* hir/tree/rust-hir-expr.h: Rename method.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Rename method.
* typecheck/rust-tyty.h: Rename method.

7 months agogccrs: hir: Rename get_pattern_mappings method
Jakub Dupak [Tue, 17 Oct 2023 14:02:32 +0000 (16:02 +0200)]
gccrs: hir: Rename get_pattern_mappings method

Unify with the name used in Expr to allow convenient template over
everything that has mappings.

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc: Rename method.
* backend/rust-compile-expr.cc (sort_tuple_patterns): Rename method.
* backend/rust-compile-pattern.cc (CompilePatternCaseLabelExpr::visit): Rename method.
(CompilePatternBindings::visit): Rename method.
(CompilePatternLet::visit): Rename method.
* backend/rust-compile-stmt.cc (CompileStmt::visit): Rename method.
* backend/rust-compile-var-decl.h: Rename method.
* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::translate): Rename method.
* hir/rust-hir-dump.cc (Dump::visit): Rename method.
* hir/tree/rust-hir-path.h: Rename method.
* hir/tree/rust-hir-pattern.h: Rename method.
* hir/tree/rust-hir.h: Rename method.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::Resolve): Rename method.
(TypeCheckPattern::visit): Rename method.
(ClosureParamInfer::visit): Rename method.
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Rename method.
* util/rust-hir-map.cc (Mappings::insert_hir_pattern): Rename method.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: hir: Add missing getter
Jakub Dupak [Tue, 17 Oct 2023 13:46:05 +0000 (15:46 +0200)]
gccrs: hir: Add missing getter

gcc/rust/ChangeLog:

* hir/tree/rust-hir-expr.h: Add getter for name.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: ast: Handle tuplestruct pattern with indices
Jakub Dupak [Tue, 17 Oct 2023 13:39:06 +0000 (15:39 +0200)]
gccrs: ast: Handle tuplestruct pattern with indices

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Implement for tuple pat.
* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Implement for tupple pat.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: hir: Refactor - avoid copy in getter
Jakub Dupak [Tue, 17 Oct 2023 13:18:03 +0000 (15:18 +0200)]
gccrs: hir: Refactor - avoid copy in getter

gcc/rust/ChangeLog:

* hir/tree/rust-hir-path.h: Avoid copy in getter.
* hir/tree/rust-hir-pattern.h: Avoid copy in getter.
* hir/tree/rust-hir.h: Avoid copy in getter.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: Make resolution of AssociatedItem instances polymorphic
Owen Avery [Wed, 11 Oct 2023 19:06:21 +0000 (15:06 -0400)]
gccrs: Make resolution of AssociatedItem instances polymorphic

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-implitem.h
(ResolveToplevelImplItem::go): Take AssociatedItem as parameter.
(ResolveTopLevelTraitItems::go): Likewise.
* resolve/rust-ast-resolve-item.cc
(ResolveTraitItems::go): Likewise.
(ResolveItem::resolve_impl_item): Likewise.
(ResolveImplItems::go): Likewise.
* resolve/rust-ast-resolve-item.h
(ResolveTraitItems::go): Likewise.
(ResolveItem::resolve_impl_item): Likewise.
(ResolveImplItems::go): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 months agogccrs: Make lowering of AssociatedItem instances polymorphic
Owen Avery [Wed, 11 Oct 2023 19:02:38 +0000 (15:02 -0400)]
gccrs: Make lowering of AssociatedItem instances polymorphic

gcc/rust/ChangeLog:

* hir/rust-ast-lower-implitem.h
(ASTLoweringImplItem::translate): Take AssociatedItem as parameter.
(ASTLoweringTraitItem::translate): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 months agogccrs: compile: bail on labelled block
Jakub Dupak [Mon, 16 Oct 2023 13:33:19 +0000 (15:33 +0200)]
gccrs: compile: bail on labelled block

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Bail on labelled block.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: typecheck: add loop ctx for labelled block
Jakub Dupak [Mon, 16 Oct 2023 13:28:03 +0000 (15:28 +0200)]
gccrs: typecheck: add loop ctx for labelled block

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add loop ctx.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: resolve: Resolve labelled block
Jakub Dupak [Mon, 16 Oct 2023 13:25:29 +0000 (15:25 +0200)]
gccrs: resolve: Resolve labelled block

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Resolve using loop logic.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: hir: Lower labelled block
Jakub Dupak [Mon, 16 Oct 2023 13:17:33 +0000 (15:17 +0200)]
gccrs: hir: Lower labelled block

gcc/rust/ChangeLog:

* hir/rust-ast-lower.cc (ASTLoweringBlock::visit): Call loop lowering and add it to constr.
* hir/tree/rust-hir-expr.h (class LoopLabel): Move before BlockExpr and add to BlockExpr.

7 months agogccrs: ast: Parse labelled block
Jakub Dupak [Mon, 16 Oct 2023 12:42:49 +0000 (14:42 +0200)]
gccrs: ast: Parse labelled block

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (AstBuilder::block): Add label arg to constructor call.
* ast/rust-expr.h (class LoopLabel): Move before BlockExpr.
(class BlockExpr): Add LoopLabel member.
* expand/rust-derive-clone.cc (DeriveClone::clone_fn): Add label arg to constructor call.
* parse/rust-parse-impl.h (Parser::parse_block_expr): Add label parameter.
(Parser::parse_labelled_loop_expr): Add label arg to constructor call.
* parse/rust-parse.h: Add label arg to constructor call.

Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
7 months agogccrs: Create base class AssociatedItem
Owen Avery [Wed, 11 Oct 2023 16:58:27 +0000 (12:58 -0400)]
gccrs: Create base class AssociatedItem

gcc/rust/ChangeLog:

* ast/rust-ast.h
(class AssociatedItem):
New, based on TraitItem, InherentImplItem, and TraitImplItem classes.
(class TraitItem): Inherit from AssociatedItem.
(class InherentImplItem): Likewise.
(class TraitImplItem): Likewise.
* ast/rust-item.h
(class Method): Update cloning functions.
(class Function): Likewise.
(class TypeAlias): Likewise.
(class ConstantItem): Likewise.
(class TraitItemFunc): Likewise.
(class TraitItemMethod): Likewise.
(class TraitItemConst): Likewise.
(class TraitItemType): Likewise.
* ast/rust-macro.h
(class MacroInvocation): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 months agogccrs: Add tests for v0 mangling
Raiki Tamura [Fri, 22 Sep 2023 10:39:21 +0000 (19:39 +0900)]
gccrs: Add tests for v0 mangling

gcc/rust/ChangeLog:

* backend/rust-mangle.cc (v0_identifier): Fix broken encoding.
(v0_scope_path): Modify paramter.
(v0_path): Fix namespace for modules.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
7 months agogccrs: Add new test for closure in closure parsing
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 12:16:52 +0000 (14:16 +0200)]
gccrs: Add new test for closure in closure parsing

This new test highlight the fix of #2656.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Break OR tokens in closure parameter list context
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 12:06:30 +0000 (14:06 +0200)]
gccrs: Break OR tokens in closure parameter list context

The parser was unable to process as closure inside a closure because the
lexer could not differentiate an OR from two PIPE tokens.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_closure_expr_pratt): Fix
closure parsing function to handle consecutive parameter lists.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add new regression test for macro matcher behavior
Pierre-Emmanuel Patry [Mon, 16 Oct 2023 08:41:06 +0000 (10:41 +0200)]
gccrs: Add new regression test for macro matcher behavior

Add a new test to highlight the fix introduced for #2653.

gcc/testsuite/ChangeLog:

* rust/compile/macro-issue2653.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add path to macro fragment follow restrictions
Pierre-Emmanuel Patry [Mon, 16 Oct 2023 08:29:35 +0000 (10:29 +0200)]
gccrs: Add path to macro fragment follow restrictions

The previous follow set rules did not allow PATH fragment, changing this
allow gccrs to accept more valid rust macros.

gcc/rust/ChangeLog:

* ast/rust-macro.h: Add PATH fragment to follow set restrictions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add a new test for mbe named macro_rules
Pierre-Emmanuel Patry [Tue, 17 Oct 2023 12:56:09 +0000 (14:56 +0200)]
gccrs: Add a new test for mbe named macro_rules

Macro rules named macro_rules may cause some problems if not handled
correctly. This new test ensure we always compile those macros named
macro_rules correctly as well as other macro definitions.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add new regression test
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 14:03:45 +0000 (16:03 +0200)]
gccrs: Add new regression test

This new test highlight the fix for #2651.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Allow macro named macro_rules
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 13:46:48 +0000 (15:46 +0200)]
gccrs: Allow macro named macro_rules

Change the constraints around macro rules declaration in order to allow
macro_rules named macro as well as tighter constraint around macro rules
definitions.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::is_macro_rules_def): Add a function
that checks tokens given by the lexer represents an accurate macro
definition. This will reduce code duplication.
(Parser::parse_item): Replace condition with call to new checking
function.
(Parser::parse_stmt): Likewise.
* parse/rust-parse.h: Add function prototype for is_macro_rules_def.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add new regression test
Pierre-Emmanuel Patry [Mon, 16 Oct 2023 12:21:42 +0000 (14:21 +0200)]
gccrs: Add new regression test

Add a new test to highlight fix of #2658.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add a new regression test
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 11:20:33 +0000 (13:20 +0200)]
gccrs: Add a new regression test

Add a new test to highlight the fix made for #2660.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Fix RangeFromExpr parsing in for loops
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 11:11:55 +0000 (13:11 +0200)]
gccrs: Fix RangeFromExpr parsing in for loops

Those ranges were looking for a curly brace after the brace, leading
to an error when using range from expr in for loops.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_expr): Fix range from expr.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add a new regression test for macro call "default"
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 12:53:39 +0000 (14:53 +0200)]
gccrs: Add a new regression test for macro call "default"

This test highlight the fix required for #2655.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Allow call to macro named "default" at item level
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 12:36:35 +0000 (14:36 +0200)]
gccrs: Allow call to macro named "default" at item level

The parser was too agressive and did reject any line beginning with
default even if this was a macro call.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_item): Relax constraints
around default identifier at item scope to accept "default" macros.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add a new regression test
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 08:21:16 +0000 (10:21 +0200)]
gccrs: Add a new regression test

New regression test to highlight behavior of #2652.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Fix path expr segment parsing with generic path
Pierre-Emmanuel Patry [Tue, 10 Oct 2023 08:04:57 +0000 (10:04 +0200)]
gccrs: Fix path expr segment parsing with generic path

When a token was identified as bit left shift it slipped through the
parser and resulted in an error.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_path_expr_segment): Accept
left shift tokens in order to let generic parsing function split the
token.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Replace get_pattern_node_id with get_node_id
Owen Avery [Wed, 11 Oct 2023 02:50:55 +0000 (22:50 -0400)]
gccrs: Replace get_pattern_node_id with get_node_id

gcc/rust/ChangeLog:

* ast/rust-ast.h
(Pattern::get_pattern_node_id): Rename to...
(Pattern::get_node_id): ...here.
* ast/rust-macro.h
(MacroInvocation::get_pattern_node_id): Rename to...
(MacroInvocation::get_node_id): ...here.
* ast/rust-path.h
(PathInExpression::get_pattern_node_id): Remove.
(QualifiedPathInExpression::get_pattern_node_id): Remove.
* ast/rust-pattern.h
(LiteralPattern::get_pattern_node_id): Remove.
(IdentifierPattern::get_pattern_node_id): Remove.
(WildcardPattern::get_pattern_node_id): Remove.
(RestPattern::get_pattern_node_id): Rename to...
(RestPattern::get_node_id): ...here.
(RangePattern::get_pattern_node_id): Remove.
(ReferencePattern::get_pattern_node_id): Remove.
(StructPattern::get_pattern_node_id): Remove.
(TupleStructPattern::get_pattern_node_id): Remove.
(TuplePattern::get_pattern_node_id): Remove.
(GroupedPattern::get_pattern_node_id): Remove.
(SlicePattern::get_pattern_node_id): Remove.
(AltPattern::get_pattern_node_id): Remove.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit):
Use get_node_id instead of get_pattern_node_id.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
7 months agogccrs: Add regression test
Pierre-Emmanuel Patry [Wed, 11 Oct 2023 12:40:18 +0000 (14:40 +0200)]
gccrs: Add regression test

This new test highlight the fix for issue #2657.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add comma for expr delimiter to fix match arms
Pierre-Emmanuel Patry [Wed, 11 Oct 2023 12:31:25 +0000 (14:31 +0200)]
gccrs: Add comma for expr delimiter to fix match arms

Add a comma as an expr delimiter, this will allow correct parsing of
match arm expressions.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_expr): Add comma delimiter.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Add regression test
Pierre-Emmanuel Patry [Mon, 16 Oct 2023 09:41:27 +0000 (11:41 +0200)]
gccrs: Add regression test

Add a new test to highlight fix for #2648.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
7 months agogccrs: Fix pub unit type parsing
Pierre-Emmanuel Patry [Mon, 16 Oct 2023 09:28:34 +0000 (11:28 +0200)]
gccrs: Fix pub unit type parsing

Public unit types where not parsed correctly due to visibility specifiers
within parenthesis. Fixes #2648.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_visibility): Relax constraints
over public visibility return condition in order to accept pub unit
types.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This page took 0.097377 seconds and 5 git commands to generate.