]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
18 months agogccrs: Extract helper lookup_associated_impl_block
Philip Herron [Thu, 20 Apr 2023 15:56:46 +0000 (16:56 +0100)] 
gccrs: Extract helper lookup_associated_impl_block

This will look for a specified predicate that is associated with it so we
might have the predicate Foo<u16, i32> which would refer to:

  impl Foo<i32> for u16 {}

This is a general helper which can be used in several places.

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.cc (AssociatedImplTrait::AssociatedImplTrait):
bind the predicate
(AssociatedImplTrait::get_trait): remove
(AssociatedImplTrait::get_predicate): new getter
* typecheck/rust-hir-trait-reference.h: bind predicate
* typecheck/rust-hir-type-check-item.cc: update ctor
* typecheck/rust-type-util.cc (lookup_associated_impl_block): new function
* typecheck/rust-type-util.h (class BaseType): remove unused forward decl
(lookup_associated_impl_block): new helper
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::is_equal): new
* typecheck/rust-tyty-subst.cc (SubstitutionRef::lookup_associated_impl): use new helper
(SubstitutionRef::monomorphize): update usage/error handling
* typecheck/rust-tyty-subst.h: remove old prototype
* typecheck/rust-tyty.h: add is_equal decl

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Type check StructPatternFieldIdentPat
Owen Avery [Thu, 27 Apr 2023 02:19:40 +0000 (22:19 -0400)] 
gccrs: Type check StructPatternFieldIdentPat

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc
(TypeCheckPattern::visit): Type check StructPatternFieldIdentPat.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Lower StructPatternFieldIdentPat
Owen Avery [Thu, 27 Apr 2023 02:14:53 +0000 (22:14 -0400)] 
gccrs: Lower StructPatternFieldIdentPat

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc
(ASTLoweringPattern::visit): Lower StructPatternFieldIdentPat.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: resolve the associated_predicate when mapping Fn traits
Philip Herron [Thu, 20 Apr 2023 10:12:29 +0000 (11:12 +0100)] 
gccrs: resolve the associated_predicate when mapping Fn traits

This is required to solve #2105

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_fn_trait_call):
return the assoicated predicate
* typecheck/rust-hir-type-check-expr.h: update prototype

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Add missing where clause lowering for Impl functions
Philip Herron [Thu, 20 Apr 2023 09:26:18 +0000 (10:26 +0100)] 
gccrs: Add missing where clause lowering for Impl functions

Fixes #2106

gcc/rust/ChangeLog:

* hir/rust-ast-lower-implitem.h: add missing where clause lowering

gcc/testsuite/ChangeLog:

* rust/compile/issue-2106.rs: New test.
* rust/compile/issue-1524.rs: regression (placeholder generic)

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Add missing TypeBoundWhereClauseItem::get_locus
Philip Herron [Thu, 20 Apr 2023 08:59:47 +0000 (09:59 +0100)] 
gccrs: Add missing TypeBoundWhereClauseItem::get_locus

gcc/rust/ChangeLog:

* hir/tree/rust-hir-item.h: add get_locus() const

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Add accessors to HIR::StructPatternFieldIdentPat
Owen Avery [Wed, 26 Apr 2023 20:33:07 +0000 (16:33 -0400)] 
gccrs: Add accessors to HIR::StructPatternFieldIdentPat

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(StructPatternFieldIdentPat::get_identifier): New.
(StructPatternFieldIdentPat::get_pattern): New.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Minor tuning in AST dump
Marc Poulhiès [Wed, 26 Apr 2023 21:08:30 +0000 (23:08 +0200)] 
gccrs: Minor tuning in AST dump

Use parentheses to remove any ambiguities when dumping expressions with
unary ! and -.

gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::visit): print parentheses around
unique expression operand.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: Fix -frust-dump-* error messages
Owen Avery [Wed, 26 Apr 2023 12:42:36 +0000 (08:42 -0400)] 
gccrs: Fix -frust-dump-* error messages

gcc/rust/ChangeLog:

* rust-session-manager.cc
(Session::enable_dump): Fix error messages.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Add missing ABI checking on function types
Philip Herron [Sun, 23 Apr 2023 22:12:45 +0000 (23:12 +0100)] 
gccrs: Add missing ABI checking on function types

Addresses #2304

gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::emit_abi_mismatch): new error method
(UnifyRules::expect_fndef): add ABI check
* typecheck/rust-unify.h: prototype for new error method

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Add missing ABI mapping
Philip Herron [Sun, 23 Apr 2023 22:01:06 +0000 (23:01 +0100)] 
gccrs: Add missing ABI mapping

gcc/rust/ChangeLog:

* util/rust-abi.cc (get_abi_from_string): add ABI mapping

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Add mechanism use pattern information to improve type info
Philip Herron [Sun, 23 Apr 2023 21:41:21 +0000 (22:41 +0100)] 
gccrs: Add mechanism use pattern information to improve type info

When we have an untyped closure we assumed all parameters were inference
variables but we can use the pattern type to try and improve the type info
so if we have a reference pattern it must be a reference to an inference
variables '&_'. This patch adds a new visitor to figure this out for
untyped closure parameters.

Note this test case does fully type resolve into the gimple:

    bool test::main::{{closure}}
        (struct test::main::{{closure}} $closure, struct (& u8) args)
    { ... }

Though the Rustc version does fail type-resolution but we make some
assumptions during comparison expressions here that they resolve to a bool
this will change when we implement the comparison lang items.

Fixes #2142

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h: add missing get_mutability
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
use new ClosureParamInfer on untyped parameters
* typecheck/rust-hir-type-check-pattern.cc (ClosureParamInfer::Resolve): interface
(ClosureParamInfer::ClosureParamInfer): constructor
(ClosureParamInfer::visit): visitors for each pattern
* typecheck/rust-hir-type-check-pattern.h (class ClosureParamInfer): new visitor

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: remove unused header
Philip Herron [Sun, 23 Apr 2023 20:49:12 +0000 (21:49 +0100)] 
gccrs: remove unused header

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.h: cleanup

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Fix ICE when we dont get a reference type
Philip Herron [Fri, 21 Apr 2023 16:52:01 +0000 (17:52 +0100)] 
gccrs: Fix ICE when we dont get a reference type

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
return so we dont hit undefined behaviour

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: remove unused includes
Philip Herron [Thu, 20 Apr 2023 10:20:41 +0000 (11:20 +0100)] 
gccrs: remove unused includes

gcc/rust/ChangeLog:

* backend/rust-compile-implitem.h: remove includes

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: fix ICE with recursive function calls
Philip Herron [Thu, 20 Apr 2023 11:33:55 +0000 (12:33 +0100)] 
gccrs: fix ICE with recursive function calls

Fixes #2136

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc (CompileItem::visit): remove bad checks

gcc/testsuite/ChangeLog:

* rust/compile/issue-2136-1.rs: New test.
* rust/compile/issue-2136-2.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: enable -Winfinite-recursion warnings by default
Philip Herron [Thu, 20 Apr 2023 11:06:21 +0000 (12:06 +0100)] 
gccrs: enable -Winfinite-recursion warnings by default

gcc/rust/ChangeLog:

* lang.opt: add lang option flag
* rust-lang.cc (grs_langhook_init_options_struct): enable by default

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Fix ICE in assignment of error type bound predicates
Philip Herron [Thu, 20 Apr 2023 10:55:20 +0000 (11:55 +0100)] 
gccrs: Fix ICE in assignment of error type bound predicates

gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::operator=):
we are done if other is in an error state

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Fix ICE during method resolution
Philip Herron [Thu, 20 Apr 2023 11:44:31 +0000 (12:44 +0100)] 
gccrs: Fix ICE during method resolution

We were missing a check for trait item selection to ensure they are
actually methods and remove assertion to check if the trait item is a
function this is a valid error check not an assertion.

Fixes #2139

gcc/rust/ChangeLog:

* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): verify it is a method

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Track Self properly with TypePredicateBounds
Philip Herron [Tue, 18 Apr 2023 16:56:43 +0000 (17:56 +0100)] 
gccrs: Track Self properly with TypePredicateBounds

When we handle generic trait bounds we never tracked its associated Self
type. Its important to remember a Trait Predicate is associated with a type
this means we end up missing a lot of helpful type information down the
line relating to higher ranked trait bounds and associated types
compuations. Remember traits have an implict Generic Type Parameter of Self
we use this in computing trait defintions so in that case no associated
type is specified which is to be expected but in all other cases we do
even if it is generic its still useful type information to keep track of.

There is one regression here with compile/issue-1893.rs this testcase
mostly worked out as a fluke rather than a proper fix so its no suprise
here it has regressed the other two test cases one where the number
generic arguments has changed, Rustc gets around this and has a seperate
error message for this case.

We need to solve this patch in order to solve #2019

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): use new interface
* typecheck/rust-hir-type-check-base.h: update prototype to include Self
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): lifewise
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::resolve_impl_block_substitutions):
likewise
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): likewise
(TypeCheckExpr::resolve_segments): likewise
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): likewise
(TypeResolveGenericParam::visit): likewise
(ResolveWhereClauseItem::visit): likewise
* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): likewise
(TypeBoundPredicate::apply_generic_arguments): likewise
(TypeBoundsMappings::lookup_predicate): likewise
* typecheck/rust-tyty-bounds.h: likewise
* typecheck/rust-tyty.h:likewise

gcc/testsuite/ChangeLog:

* rust/compile/issue-1893.rs: regression
* rust/compile/traits12.rs: rustc uses a custom error message here
* rust/compile/unconstrained_type_param.rs: extra error message

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: add error state to TypeCheckContextItem and missing copy ctor's
Philip Herron [Tue, 18 Apr 2023 11:36:29 +0000 (12:36 +0100)] 
gccrs: add error state to TypeCheckContextItem and missing copy ctor's

When checking current context we might be in the const or static context
which does not have a current function or impl or trait context associated
with it. So this allows us to represent the an error state for that case.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.h: New error state and missing copy implementations
* typecheck/rust-typecheck-context.cc (TypeCheckContextItem::TypeCheckContextItem):
missing copy ctor
(TypeCheckContextItem::operator=): missing copy implementation
(TypeCheckContextItem::get_error): new static function
(TypeCheckContextItem::is_error): new method
(TypeCheckContextItem::get_context_type): handle error state
(TypeCheckContextItem::get_defid): handle error state

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: add helper to check for a const or static context
Philip Herron [Mon, 17 Apr 2023 21:04:11 +0000 (22:04 +0100)] 
gccrs: add helper to check for a const or static context

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.h: new helper
* typecheck/rust-typecheck-context.cc (TypeCheckContext::have_function_context):
implementation

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Add get_defid helper to TypeCheckContextItem
Philip Herron [Mon, 17 Apr 2023 20:50:54 +0000 (21:50 +0100)] 
gccrs: Add get_defid helper to TypeCheckContextItem

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.h: Add prototype
* typecheck/rust-typecheck-context.cc (TypeCheckContextItem::get_defid): implementation

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: minor refactor to reuse a variable instead of recreating it later
Philip Herron [Mon, 17 Apr 2023 20:01:25 +0000 (21:01 +0100)] 
gccrs: minor refactor to reuse a variable instead of recreating it later

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc: refactor

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Fix memory corruption at peek_context
Philip Herron [Mon, 17 Apr 2023 19:48:41 +0000 (20:48 +0100)] 
gccrs: Fix memory corruption at peek_context

When working in the resolve_operator_overload it was found that we got
memory corruption as method resolution will use the query system and
therefore resolve new methods and the current function context info will
change and due to the fact the peek_context interface returns a reference
to the element which was now safe from a vector which can change and all
you need is the current function context at that moment in time.

gcc/rust/ChangeLog:

* typecheck/rust-autoderef.cc: don't take a reference
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
* typecheck/rust-hir-type-check.h: remove reference
* typecheck/rust-typecheck-context.cc (TypeCheckContext::pop_return_type): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: patterns: Add execution testcases to verify proper pattern matching
Arthur Cohen [Fri, 21 Apr 2023 09:22:52 +0000 (11:22 +0200)] 
gccrs: patterns: Add execution testcases to verify proper pattern matching

These testcases are similar to the ones added in #2072 but regarding
execution. One more issue was opened from them - #2144

gcc/testsuite/ChangeLog:

* rust/execute/torture/issue-1852-1.rs: New test.
* rust/execute/torture/issue-1852.rs: New test.

18 months agogccrs: Resolve identifier-pattern struct pattern fields
Owen Avery [Mon, 24 Apr 2023 19:49:49 +0000 (15:49 -0400)] 
gccrs: Resolve identifier-pattern struct pattern fields

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-pattern.cc
(PatternDeclaration::visit): Handle StructPatternFieldIdentPat.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: libproc_macro: Fix literal drop function
Pierre-Emmanuel Patry [Fri, 21 Apr 2023 10:00:08 +0000 (12:00 +0200)] 
gccrs: libproc_macro: Fix literal drop function

Fix drop function by changing the delete operator to delete[] in order
to avoid undefined behaviors.

libgrust/ChangeLog:

* libproc_macro/literal.cc (Literal::drop): Change
delete operator to delete[].

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Implement Drop for TokenStream
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 16:07:08 +0000 (18:07 +0200)] 
gccrs: libproc_macro: Implement Drop for TokenStream

TokenStream did not have any drop implementation, the memory could not
have been freed correctly.

libgrust/ChangeLog:

* libproc_macro/rust/bridge/token_stream.rs: Implement
drop.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Add remaining drop functions
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 15:58:27 +0000 (17:58 +0200)] 
gccrs: libproc_macro: Add remaining drop functions

Remaining structures from the rust bridge that missed a drop function
now have one.

libgrust/ChangeLog:

* libproc_macro/group.cc (Group::drop): Add drop
implementation.
* libproc_macro/group.h: Add drop prototype.
* libproc_macro/tokenstream.cc (TokenStream::drop): Add
drop implementation.
(TokenStream__drop): Change to a call to TokenStream::drop.
* libproc_macro/tokenstream.h: Add drop prototype.
* libproc_macro/tokentree.cc (TokenTree::drop): Add
drop implementation.
* libproc_macro/tokentree.h: Add drop prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Add drop function to Literal struct
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 15:56:36 +0000 (17:56 +0200)] 
gccrs: libproc_macro: Add drop function to Literal struct

Add a drop function to clean internal fields of a Literal struct.

libgrust/ChangeLog:

* libproc_macro/literal.cc (Literal__drop): Replace
implementation by a call to Literal::drop.
(Literal::drop): Add drop implementation.
* libproc_macro/literal.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Add drop function on Ident struct
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 15:47:43 +0000 (17:47 +0200)] 
gccrs: libproc_macro: Add drop function on Ident struct

Add a drop function that cleans internal fields of a given Ident struct.

libgrust/ChangeLog:

* libproc_macro/ident.cc (Ident__drop): Replace by call
to Ident::drop.
(Ident::drop): Add drop function.
* libproc_macro/ident.h: Add drop prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Add remaining tokenstream structs.
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 13:28:45 +0000 (15:28 +0200)] 
gccrs: libproc_macro: Add remaining tokenstream structs.

Add remaining missing tokenstream structures. Most are interdependent.

libgrust/ChangeLog:

* libproc_macro/group.cc: New file.
* libproc_macro/group.h: New file.
* libproc_macro/tokenstream.cc: New file.
* libproc_macro/tokenstream.h: New file.
* libproc_macro/tokentree.cc: New file.
* libproc_macro/tokentree.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Fix translation mistakes 2023 in GCC/Rust [PR108890]
TieWay59 [Wed, 19 Apr 2023 06:07:34 +0000 (14:07 +0800)] 
gccrs: Fix translation mistakes 2023 in GCC/Rust [PR108890]

In https://gcc.gnu.org/PR108890 "Translation mistakes 2023"
@rillig lists several issues with GCC/Rust diagnostics and
option help texts (but also a few non-GCC/Rust).

This commit fix mistakes only related to GCC/Rust,
specifically to the file `gcc/rust/lang.opt`.

closes https://github.com/Rust-GCC/gccrs/issues/1916

PR translation/108890
gcc/rust/
* lang.opt: Fix translation mistakes 2023 in
GCC/Rust [PR108890]
(line 67): change the inconsistent tab to spaces
(line 75): wrap bare placeholder `integer`
(line 79): remove redundant text of `Choose which`
(line 96): remove redundant text of `Choose which`
(line 112): remove redundant `Flag to`
(line 124): correct the exclusive term `When to stop`
(line 124): correct typo of `copimlation`

Signed-off-by: Tieway59 <tieway59@foxmail.com>
18 months agogccrs: libproc_macro: Add Punct struct
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 12:24:43 +0000 (14:24 +0200)] 
gccrs: libproc_macro: Add Punct struct

Add Punct struct for rust interface as well as a basic named
constructor.

libgrust/ChangeLog:

* libproc_macro/punct.cc: New file.
* libproc_macro/punct.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Add namespace to Ident
Pierre-Emmanuel Patry [Wed, 12 Apr 2023 10:11:37 +0000 (12:11 +0200)] 
gccrs: libproc_macro: Add namespace to Ident

Add a new Ident namespace to group Ident related enumeration and
structures.

libgrust/ChangeLog:

* libproc_macro/ident.cc (Ident::make_ident): Add Ident
namespace.
* libproc_macro/ident.h (Ident__clone): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Add named constructor
Pierre-Emmanuel Patry [Tue, 11 Apr 2023 13:07:03 +0000 (15:07 +0200)] 
gccrs: libproc_macro: Add named constructor

Add named constructor directly in Ident struct.

libgrust/ChangeLog:

* libproc_macro/ident.cc (Ident__new): Use named
constructor.
(Ident__new_raw): Use named constructor.
(Ident__clone): Use clone member function.
(Ident::clone): Make clone const.
(Ident::make_ident): Add named construcot.
* libproc_macro/ident.h (struct Ident): Add named
constructor prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Change drop rust interface
Pierre-Emmanuel Patry [Tue, 11 Apr 2023 11:53:13 +0000 (13:53 +0200)] 
gccrs: libproc_macro: Change drop rust interface

Change rust interface on drop function to take a mut pointer instead.
This will match the drop trait interface more closely.

libgrust/ChangeLog:

* libproc_macro/rust/bridge/ident.rs: Change drop
function interface.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Add ident implementation
Pierre-Emmanuel Patry [Tue, 11 Apr 2023 10:18:54 +0000 (12:18 +0200)] 
gccrs: libproc_macro: Add ident implementation

Add implementation and representation for ident cpp structure as well as
a high level wrapper interface.

libgrust/ChangeLog:

* libproc_macro/ident.cc: New file.
* libproc_macro/ident.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Deleted the as_string ASR and HIR dumps
M V V S Manoj Kumar [Fri, 14 Apr 2023 12:59:48 +0000 (18:29 +0530)] 
gccrs: Deleted the as_string ASR and HIR dumps

Fixes #2021, #2022
Deleted Parser::debug_dump_ast_output, removed any functions that called
it i.e Session::dump_ast and Session::dump_ast_expanded, and any
associated items.

Made it so that when you use the dump option "expanded" it dumps the
pretty ast only.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::debug_dump_ast_output): Removed this funtion.
* rust-session-manager.cc (Session::enable_dump): Removed else if (arg == "parse").
(Session::compile_crate): Removed calls of dump_ast and dump_ast_expanded.
(Session::dump_ast): Removed this function.
(Session::dump_ast_expanded): Removed this function.
* rust-session-manager.h (struct CompileOptions): Removed the PARSER_AST_DUMP option.

Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
18 months agogccrs: parser: Parse reference patterns correctly
Arthur Cohen [Wed, 19 Apr 2023 15:40:15 +0000 (17:40 +0200)] 
gccrs: parser: Parse reference patterns correctly

Reference patterns cannot contain AltPatterns per the Rust reference,
so we should not call into `parse_pattern` to parse the referenced pattern,
but rather the more restrictive `parse_pattern_no_alt`.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_reference_pattern): Do not
call into `parse_pattern` anymore.

gcc/testsuite/ChangeLog:

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

18 months agogccrs: Add error message for AltPattern in let statements
Owen Avery [Fri, 21 Apr 2023 05:43:25 +0000 (01:43 -0400)] 
gccrs: Add error message for AltPattern in let statements

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc
(ASTLoweringPattern::translate): Add is_let_top_level parameter.
(ASTLoweringPattern::visit): Handle is_let_top_level.
* hir/rust-ast-lower-pattern.h
(class ASTLoweringPattern): Add is_let_top_level.
* hir/rust-ast-lower-stmt.cc
(ASTLoweringStmt::visit): Set is_let_top_level.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Implement Dump:visit() function for QualifiedPathInType argument.
Zheyuan Chen [Thu, 13 Apr 2023 12:57:31 +0000 (05:57 -0700)] 
gccrs: Implement Dump:visit() function for QualifiedPathInType argument.

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc: fix bad formatting for associated type.

Signed-off-by: Zheyuan Chen <sephirotheca17@gmail.com>
18 months agogccrs: Add testcase to show matching of enum variants
Philip Herron [Wed, 29 Mar 2023 21:27:38 +0000 (22:27 +0100)] 
gccrs: Add testcase to show matching of enum variants

Fixes #852

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Lower ErrorPropagationExpr from AST to HIR
Sergey Bugaev [Fri, 14 Apr 2023 16:47:46 +0000 (19:47 +0300)] 
gccrs: Lower ErrorPropagationExpr from AST to HIR

gcc/rust/ChangeLog:
* hir/rust-ast-lower-expr.h, hir/rust-ast-lower-expr.cc:
Lower AST::ErrorPropagationExpr to HIR::ErrorPropagationExpr

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
18 months agogccrs: libproc_macro: Add member functions to Literal
Pierre-Emmanuel Patry [Tue, 11 Apr 2023 14:24:09 +0000 (16:24 +0200)] 
gccrs: libproc_macro: Add member functions to Literal

Add some member functions to the Literal structure as well as named
constructors.

libgrust/ChangeLog:

* libproc_macro/literal.cc (Literal__string): Add call
to named constructor.
(Literal__byte_string): Likewise.
(Literal::make_unsigned): Add function.
(Literal::make_signed): Add function.
(Literal::clone): Likewise.
(Literal::make_u8): Likewise.
(Literal::make_u16): Likewise.
(Literal::make_u32): Likewise.
(Literal::make_u64): Likewise.
(Literal::make_i8): Likewise.
(Literal::make_i16): Likewise.
(Literal::make_i32): Likewise.
(Literal::make_i64): Likewise.
(Literal::make_string): Likewise.
(Literal::make_byte_string): Likewise.
(Literal::make_f32): Likewise.
(Literal::make_f64): Likewise.
(make_char): Likewise.
(Literal::make_char): Likewise.
(make_usize): Likewise.
(Literal::make_usize): Likewise.
(make_isize): Likewise.
(Literal::make_isize): Likewise.
* libproc_macro/literal.h: Add prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Put literal members in namespace
Pierre-Emmanuel Patry [Fri, 7 Apr 2023 13:02:55 +0000 (15:02 +0200)] 
gccrs: libproc_macro: Put literal members in namespace

Add a Literal namespace to gather all every literal related code.

libgrust/ChangeLog:

* libproc_macro/literal.cc (Literal__from_string):
Add abort because unimplemented.
* libproc_macro/literal.h (Literal__from_string): Add
namespace.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Drop function shall take a mutable
Pierre-Emmanuel Patry [Fri, 7 Apr 2023 11:52:04 +0000 (13:52 +0200)] 
gccrs: libproc_macro: Drop function shall take a mutable

The rust API requires a mut reference, hence having a mutable pointer
seems to match better. Furthermore the implementation is now modifying
the struct in order to set the size to 0 instead of simply freeing the
data, this will allow us to easily identify mistaken manual call to this
function.

libgrust/ChangeLog:

* libproc_macro/rust/bridge/literal.rs: Make the
pointer mutable.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Add literal ffi implementations
Pierre-Emmanuel Patry [Thu, 6 Apr 2023 12:29:53 +0000 (14:29 +0200)] 
gccrs: libproc_macro: Add literal ffi implementations

Add literal type related ffi functions implementation.

libgrust/ChangeLog:

* libproc_macro/literal.h (Literal__drop): Implement
drop.
(Literal__string): Constructor from a string function prototype.
(Literal__byte_string): Constructor from a byte string function
prototype.
(Literal__from_string): Add function body, no implementation
yet.
* libproc_macro/literal.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Add Literal type
Pierre-Emmanuel Patry [Thu, 6 Apr 2023 10:13:13 +0000 (12:13 +0200)] 
gccrs: libproc_macro: Add Literal type

Add the Literal type matching rust ffi definitions.

libgrust/ChangeLog:

* libproc_macro/proc_macro.h (PROC_MACRO_H): Add
literal header include directive.
* libproc_macro/literal.h: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: libproc_macro: Add license headers
Pierre-Emmanuel Patry [Thu, 6 Apr 2023 10:10:39 +0000 (12:10 +0200)] 
gccrs: libproc_macro: Add license headers

Add license headers to existing files.

libgrust/ChangeLog:

* libproc_macro/proc_macro.cc (test): Remove dummy
function.
* libproc_macro/proc_macro.h (test): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Fix scope separator in tokenstreams
Pierre-Emmanuel Patry [Mon, 17 Apr 2023 16:27:24 +0000 (18:27 +0200)] 
gccrs: ast: Fix scope separator in tokenstreams

Qualified types had a simple colon output instead of full scope
resolution tokens in QualifiedPathInTypes.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix scope
resolution token output.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Fix tokenstream QualifiedPathInExpression
Pierre-Emmanuel Patry [Mon, 17 Apr 2023 16:26:03 +0000 (18:26 +0200)] 
gccrs: ast: Fix tokenstream QualifiedPathInExpression

The associated type was not kept in the tokenstream.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Keep
associated type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Fix tokenstream function body
Pierre-Emmanuel Patry [Mon, 17 Apr 2023 16:04:41 +0000 (18:04 +0200)] 
gccrs: ast: Fix tokenstream function body

Function body were skipped in tokenstream when no return type was
provided.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit_function_common):
Fix function body output.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: parser: Fix attribute differentation
Pierre-Emmanuel Patry [Mon, 17 Apr 2023 14:20:32 +0000 (16:20 +0200)] 
gccrs: parser: Fix attribute differentation

In some cases, while parsing an outer attribute, the parser would return
an inner attribute.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_outer_attribute): Fix
attribute status.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: lex: Fix lifetime string representation
Pierre-Emmanuel Patry [Mon, 17 Apr 2023 13:59:03 +0000 (15:59 +0200)] 
gccrs: lex: Fix lifetime string representation

Lifetime string representation used two single quotes instead of one.

gcc/rust/ChangeLog:

* lex/rust-token.cc (Token::as_string): Fix lifetime string
representation.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: resolve: Add "break rust" Easter egg
Sergey Bugaev [Mon, 3 Apr 2023 15:58:43 +0000 (18:58 +0300)] 
gccrs: resolve: Add "break rust" Easter egg

When we encounter a "break rust" statement, emit a funny error message
and intentionally cause an ICE. This matches the corresponding Easter
egg in rustc. As a GNU extension, "break gcc" is also supported.

The conditions for this to happen are:
* The break expression must be literally "rust" or "gcc". For instance,
  "break (rust)" will not trigger the Easter egg.
* The name ("rust" or "gcc") must not be in scope; if it is, no error
  is emitted, and the compilation proceeds as usual. In other words,
  this only affects how GCC diagnoses programs that would fail to
  compile anyway.

Note that this is different from the conditions under which rustc emits
its ICE. For rustc, it matters whether or not the "break" is inside a
loop, and for us it matters whether or not the name resolves. The end
result should be the same anyway: valid programs continue to compile,
and typing in

fn main() {
    break rust;
}

triggers a funny ICE.

Closes https://github.com/Rust-GCC/gccrs/issues/1996

gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.cc: Add "break rust" Easter egg

gcc/testsuite/ChangeLog:
* lib/prune.exp (prune_ices):
Also prune "You have broken GCC Rust. This is a feature."
* rust/compile/break-rust1.rs: New test
* rust/compile/break-rust2.rs: New test
* rust/compile/break-rust3.rs: New test

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
18 months agogccrs: resolve: Add ResolveExpr::funny_error
Sergey Bugaev [Mon, 3 Apr 2023 15:51:58 +0000 (18:51 +0300)] 
gccrs: resolve: Add ResolveExpr::funny_error

...and thread it through the constructors and the ResolveExpr::go ()
method.

This will be used for implementing the "break rust" Easter egg.

gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.h,
resolve/rust-ast-resolve-expr.cc: Add ResolveExpr::funny_error

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
18 months agogccrs: ast: Add AST::Kind::IDENTIFIER
Sergey Bugaev [Mon, 3 Apr 2023 15:48:45 +0000 (18:48 +0300)] 
gccrs: ast: Add AST::Kind::IDENTIFIER

...and return it from IdentifierExpr::get_ast_kind (). This enables
other code to dynamically test whether an expression is in fact an
IdentifierExpr.

gcc/rust/ChangeLog:
* ast/rust-ast.h: Add AST::Kind::IDENTIFIER

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
18 months agogccrs: ast: Make AST::Kind an enum class
Sergey Bugaev [Mon, 3 Apr 2023 15:43:08 +0000 (18:43 +0300)] 
gccrs: ast: Make AST::Kind an enum class

We're going to introduce AST::Kind::IDENTIFIER next, and with the
default C-style enum member scoping, this would cause name clashes.
Instead, convert AST::Kind into an enum class, so that its members
are properly namespaced.

gcc/rust/ChangeLog:
* ast/rust-ast.h (Kind): Convert into a C++ enum class
* expand/rust-macro-builtins.cc: Adapt to the change

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
18 months agogccrs: Add lowering for if-let expressions
Owen Avery [Sat, 18 Mar 2023 05:41:01 +0000 (01:41 -0400)] 
gccrs: Add lowering for if-let expressions

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc
(TypeCheckExpr::visit): Add implementation for IfLetExprConseqElse.
* typecheck/rust-hir-type-check-expr.h:
(TypeCheckExpr::visit): Remove stub implementation for IfLetExprConseqElse.
* hir/rust-ast-lower-expr.cc
(ASTLoweringExpr::visit): Lower IfLetExpr{,ConseqElse}.
* hir/rust-ast-lower-expr.h:
(ASTLoweringExpr::visit): Likewise.
* hir/rust-ast-lower-block.h
(ASTLoweringIfLetBlock::visit): Lower IfLetExprConseqElse.
(ASTLoweringExprWithBlock::visit): Likewise.
* hir/rust-ast-lower.cc
(ASTLoweringIfLetBlock::visit): Lower IfLetExprConseqElse.
* hir/tree/rust-hir-expr.h
(IfLetExprConseqElse::IfLetExprConseqElse): Make constructor more general.
(IfLetExprConseqElse::vis_else_block): Add.
(IfLetExprConseqElse::get_else_block): Add.
* resolve/rust-ast-resolve-expr.cc
(ResolveExpr::visit): Add IfLetExprConseqElse visitor.
* resolve/rust-ast-resolve-expr.h
(ResolveExpr::visit): Add IfLetExprConseqElse visitor.

gcc/testsuite/ChangeLog:

* rust/compile/if_let_expr.rs: Increase test coverage.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: parser: macro: reject separator in `?` repetition
Sebastian Kirmayer [Wed, 5 Apr 2023 04:09:11 +0000 (06:09 +0200)] 
gccrs: parser: macro: reject separator in `?` repetition

A matcher like $(a),? is no longer accepted.

Fixes #2092.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser<ManagedTokenSource>::parse_macro_match_repetition):
reject separator in `?` repetition

gcc/testsuite/ChangeLog:

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

Signed-off-by: Sebastian Kirmayer <gnu@kirmayer.eu>
18 months agogccrs: Unify AST::IfLetExprConseqIf{,Let} into AST::IfLetExprConseqElse
Owen Avery [Thu, 16 Mar 2023 03:30:19 +0000 (23:30 -0400)] 
gccrs: Unify AST::IfLetExprConseqIf{,Let} into AST::IfLetExprConseqElse

This simplifies the AST's representation of if-let-statements
to match the HIR.

gcc/rust/ChangeLog:

* ast/rust-expr.h
(class IfLetExprConseqElse): Make else_block ExprWithBlock.
(class IfLetExprConseqIf): Remove.
(class IfLetExprConseqIfLet): Remove.
* ast/rust-ast-full-decls.h
(class IfLetExprConseqIf): Remove.
(class IfLetExprConseqIfLet): Remove.
* ast/rust-ast.cc
(IfLetExprConseqElse::as_string): Adjust output.
(IfLetExprConseqIf::as_string): Remove.
(IfLetExprConseqIfLet::as_string): Remove.
(IfLetExprConseqIf::accept_vis): Remove.
(IfLetExprConseqIfLet::accept_vis): Remove.
* ast/rust-ast-visitor.h
(ASTVisitor::visit): Remove IfLetExprConseqIf{,Let} visitors.
* ast/rust-ast-dump.cc
(Dump::visit): Likewise.
* ast/rust-ast-dump.h:
(Dump::visit): Likewise.
* ast/rust-ast-tokenstream.cc
(TokenStream::visit): Likewise.
* ast/rust-ast-tokenstream.h
(TokenStream::visit): Likewise.
* util/rust-attributes.cc
(AttributeChecker::visit): Likewise.
* util/rust-attributes.h:
(AttributeChecker::visit): Likewise.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h
(EarlyNameResolver::visit): Likewise.
* resolve/rust-ast-resolve-base.h
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Likewise.
* checks/errors/rust-feature-gate.h
(FeatureGate::visit): Likewise.
* expand/rust-cfg-strip.cc
(CfgStrip::visit): Likewise.
* expand/rust-cfg-strip.h:
(CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h
(ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h:
(ASTLoweringBase::visit): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_if_let_expr): Replace IfLetExprConseqIf{,Let} with IfLetExprConseqElse.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: ast: Fix StructExprStruct tokenstream
Pierre-Emmanuel Patry [Wed, 5 Apr 2023 11:45:36 +0000 (13:45 +0200)] 
gccrs: ast: Fix StructExprStruct tokenstream

StructExprStructFields inherit from StructExprStruct and shall output
the struct name and curly braces.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add struct
name and curly braces to output tokenstream.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Handle underscore in MacroMatch.
Owen Avery [Fri, 7 Apr 2023 20:47:54 +0000 (16:47 -0400)] 
gccrs: Handle underscore in MacroMatch.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_macro_match): Handle underscore.

gcc/testsuite/ChangeLog:

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

18 months agogccrs: Fully unify deriving classes into HIR::ExprStmt
Owen Avery [Sat, 8 Apr 2023 06:24:03 +0000 (02:24 -0400)] 
gccrs: Fully unify deriving classes into HIR::ExprStmt

gcc/rust/ChangeLog:

* hir/tree/rust-hir-full-decls.h
(class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
* hir/tree/rust-hir-stmt.h
(class ExprStmt):
Add remaining ExprStmtWith{,out}Block functionality.
(class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
* hir/rust-ast-lower-stmt.cc
(ASTLoweringStmt::visit):
Lower to HIR::ExprStmt instead of deriving class.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Unify HIR::ExprStmt derived class visiting
Owen Avery [Sat, 8 Apr 2023 05:37:56 +0000 (01:37 -0400)] 
gccrs: Unify HIR::ExprStmt derived class visiting

gcc/rust/ChangeLog:

* backend/rust-compile-stmt.cc
(CompileStmt::visit): Unify ExprStmtWith{,out}Block visitors.
* backend/rust-compile-stmt.h
(CompileStmt::visit): Likewise.
* backend/rust-compile-item.h
(CompileItem::visit): Likewise.
* hir/rust-hir-dump.cc
(Dump::visit): Likewise.
* hir/rust-hir-dump.h
(Dump::visit): Likewise.
* hir/tree/rust-hir-stmt.h
(ExprStmt::accept_vis): Add.
(ExprStmtWithoutBlock::accept_vis): Remove.
(ExprStmtWithBlock::accept_vis): Remove.
* hir/tree/rust-hir.cc
(ExprStmt::accept_vis): Add.
(ExprStmtWithoutBlock::accept_vis): Remove.
(ExprStmtWithBlock::accept_vis): Remove.
* hir/tree/rust-hir-visitor.h
(HIRFullVisitor::visit): Likewise.
(HIRFullVisitorBase::visit): Likewise.
(HIRStmtVisitor::visit): Likewise.
* checks/errors/rust-const-checker.cc
(ConstChecker::visit): Likewise.
* checks/errors/rust-const-checker.h
(ConstChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.cc
(UnsafeChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.h
(UnsafeChecker::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h
(PrivacyReporter::visit): Likewise.
* checks/lints/rust-lint-marklive.h
(MarkLive::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.cc
(TypeCheckStmt::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.h
(TypeCheckStmt::visit): Likewise.
* typecheck/rust-tycheck-dump.h
(TypeResolverDump::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Move functionality into HIR::ExprStmt from deriving classes
Owen Avery [Sun, 5 Feb 2023 01:15:52 +0000 (20:15 -0500)] 
gccrs: Move functionality into HIR::ExprStmt from deriving classes

And move method as_string into HIR::ExprStmt from deriving classes

gcc/rust/ChangeLog:

* hir/tree/rust-hir-stmt.h
(ExprStmt::expr): Add field.
(ExprStmt::get_expr): Add method.
(ExprStmt::ExprStmt): Add copy/move constructors, modify existing constructor.
(ExprStmt::operator=): Add assignment operator.
(ExprStmtWithoutBlock::expr): Remove field.
(ExprStmtWithoutBlock::get_expr): Remove method.
(ExprStmtWithoutBlock::ExprStmt):
Remove copy/move constructors, modify existing constructor.
(ExprStmtWithoutBlock::operator=): Remove assignment operator.
(ExprStmtWithBlock::expr): Remove field.
(ExprStmtWithBlock::get_expr): Remove method.
(ExprStmtWithBlock::ExprStmt): Remove copy/move constructors, modify existing constructor.
(ExprStmtWithBlock::operator=): Remove assignment operator.
(ExprStmt::as_string): Add method.
(ExprStmtWithBlock::as_string): Remove method.
(ExprStmtWithoutBlock::as_string): Remove method.
* hir/tree/rust-hir.cc
(ExprStmt::as_string): Add method.
(ExprStmtWithBlock::as_string): Remove method.
(ExprStmtWithoutBlock::as_string): Remove method.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: Unify AST::IfExprConseqIf{,Let} into AST::IfExprConseqElse
Owen Avery [Thu, 16 Mar 2023 03:05:07 +0000 (23:05 -0400)] 
gccrs: Unify AST::IfExprConseqIf{,Let} into AST::IfExprConseqElse

This simplifies the AST's representation of if-statements
to match the HIR.

gcc/rust/ChangeLog:

* ast/rust-expr.h
(class IfExprConseqElse): Make else_block ExprWithBlock.
(class IfExprConseqIf): Remove.
(class IfExprConseqIfLet): Remove.
* ast/rust-ast-full-decls.h
(class IfExprConseqIf): Remove.
(class IfExprConseqIfLet): Remove.
* ast/rust-ast.cc
(IfExprConseqElse::as_string): Adjust output.
(IfExprConseqIf::as_string): Remove.
(IfExprConseqIfLet::as_string): Remove.
(IfExprConseqIf::accept_vis): Remove.
(IfExprConseqIfLet::accept_vis): Remove.
* ast/rust-ast-visitor.h
(ASTVisitor::visit): Remove IfExprConseqIf{,Let} visitors.
* ast/rust-ast-tokenstream.cc
(TokenStream::visit): Likewise.
* ast/rust-ast-tokenstream.h
(TokenStream::visit): Likewise.
* ast/rust-ast-dump.cc
(Dump::visit): Likewise.
* ast/rust-ast-dump.h
(Dump::visit): Likewise.
* checks/errors/rust-feature-gate.h
(FeatureGate::visit): Likewise.
* util/rust-attributes.cc
(AttributeChecker::visit): Likewise.
* util/rust-attributes.h
(AttributeChecker::visit): Likewise.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h
(EarlyNameResolver::visit): Likewise.
* resolve/rust-ast-resolve-base.h
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-expr.h
(ResolveExpr::visit): Remove IfExprConseqIf visitor.
* resolve/rust-ast-resolve-expr.cc
(ResolveExpr::visit): Likewise.
* expand/rust-cfg-strip.cc
(CfgStrip::visit): Remove IfExprConseqIf{,Let} visitors.
* expand/rust-cfg-strip.h
(CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h
(ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-block.h
(ASTLoweringIfBlock::visit): Remove IfExprConseqIf visitor.
(ASTLoweringExprWithBlock::visit): Likewise.
* hir/rust-ast-lower.cc
(ASTLoweringIfBlock::visit):
Remove IfExprConseqIf visitor, adjust IfExprConseqElse lowering.
* hir/rust-ast-lower-expr.h
(ASTLoweringExpr::visit): Remove IfExprConseqIf visitor.
* hir/rust-ast-lower-expr.cc
(ASTLoweringExpr::visit): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_if_expr): Replace IfExprConseqIf{,Let} with IfExprConseqElse.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
18 months agogccrs: ast: Fix inner attribute tokenstream
Pierre-Emmanuel Patry [Tue, 11 Apr 2023 16:11:09 +0000 (18:11 +0200)] 
gccrs: ast: Fix inner attribute tokenstream

Inner attribute did not output exclamation tokens as there was no way to
differentiate inner from outer attributes previously.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix inner
attribute tokenstream output.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Introduce AST::Visitable class for AST
Marc Poulhiès [Thu, 6 Apr 2023 17:20:55 +0000 (19:20 +0200)] 
gccrs: Introduce AST::Visitable class for AST

AST::Visitable is an abstract class with a unique accept_vis() method.
Make all abstract AST node class inherit from this class.

Allows for easy definition of operations on nodes that must accept a
visitor.

The static Dump::dump() is an example of such use: the static method
accepts any AST node, creates a Dump visitor and have it visit the AST
starting at the node.

This change also inserts a debug(Visitable&) function in the global
namespace to make it easy to call from the debugger (similar to
debug_tree or debug(rtx*) functions).

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::debug): New.
* ast/rust-ast-dump.h (Dump::debug): Untemplate it.
(debug): New.
* ast/rust-ast.h (class Visitable): New.
(class TokenTree): Inherit from Visitable.
(class MacroMatch): Likewise.
(class AttrInput): Likewise.
(class MetaItemInner): Likewise.
(class Pattern): Likewise.
(classTypeParamBound): Likewise.
(class GenericParam): Likewise.
(class TraitItem): Likewise.
(classInherentImplItem): Likewise.
(class TraitImplItem): Likewise.
(class ExternalItem): Likewise.
(class SingleASTNode): Likewise.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
18 months agogccrs: Placate clang-format, 'gcc/rust/rust-lang.cc:grs_langhook_type_for_mode'
Thomas Schwinge [Tue, 11 Apr 2023 06:47:24 +0000 (08:47 +0200)] 
gccrs: Placate clang-format, 'gcc/rust/rust-lang.cc:grs_langhook_type_for_mode'

Yesterday's commit 3757e8d71794cece4a5c9d08245b7ad111044853
"Merge commit '6baa95c9c5b3fea96fd22d03d961db4e4cf48d88' into HEAD [#2112]"
brought in the #1713 change from GCC upstream master branch that broke the
rules (via code copied verbatim from elsehwhere in GCC).

gcc/rust/
* rust-lang.cc (grs_langhook_type_for_mode): Placate clang-format.

18 months agogccrs: ast: Add difference between attributes
Pierre-Emmanuel Patry [Wed, 5 Apr 2023 10:36:41 +0000 (12:36 +0200)] 
gccrs: ast: Add difference between attributes

Add a boolean to tell inner and outer attributes ast nodes appart. This
meant refactoring a bit their parsing function.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add boolean for differenciation.
* parse/rust-parse-impl.h (Parser::parse_doc_comment): Change
function interface to make code cleaner. It should return a body
instead of the whole attribute.
(Parser::parse_inner_attribute): Specify the inner status of the
node.
(Parser::parse_attribute_body): Change function interface to
make the code cleaner much like parse_doc_comment.
(Parser::parse_outer_attribute): Specify outer status of the
node.
* parse/rust-parse.h: Update functions prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Support fully qualified calls to trait items from CallExpr's
Philip Herron [Tue, 4 Apr 2023 14:40:26 +0000 (15:40 +0100)] 
gccrs: Support fully qualified calls to trait items from CallExpr's

Fixes #2070

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile):
reuse resolve_method_address to monomorphize the call if required
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments):
allow matching against unimplemented trait item bounds

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: never re-setup trait item bound with a dyn object
Philip Herron [Tue, 4 Apr 2023 15:13:18 +0000 (16:13 +0100)] 
gccrs: never re-setup trait item bound with a dyn object

It results in a recursive generic Param cycle.

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc: dont subst with a dynamic object

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: refactor resolve_method_address to be inside base class
Philip Herron [Tue, 4 Apr 2023 14:49:20 +0000 (15:49 +0100)] 
gccrs: refactor resolve_method_address to be inside base class

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address): moved here
* backend/rust-compile-base.h: refactored prototype
* backend/rust-compile-expr.cc (CompileExpr::resolve_method_address): refactor
* backend/rust-compile-expr.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: remove unused code in query_compile
Philip Herron [Tue, 4 Apr 2023 14:37:33 +0000 (15:37 +0100)] 
gccrs: remove unused code in query_compile

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): remove unused

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: cleanup query_compile to reuse destructure call
Philip Herron [Tue, 4 Apr 2023 14:34:03 +0000 (15:34 +0100)] 
gccrs: cleanup query_compile to reuse destructure call

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): call destructure

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: cleanup resolve method address
Philip Herron [Tue, 4 Apr 2023 14:24:01 +0000 (15:24 +0100)] 
gccrs: cleanup resolve method address

Calling PathProbeImplTrait resolves directly to the trait bound in question
to stop resolving to potentially multiple implementations of that bound

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::resolve_method_address):
call path probe impl trait

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: expand: Add outer attribute expansion on expr
Pierre-Emmanuel Patry [Mon, 3 Apr 2023 10:38:50 +0000 (12:38 +0200)] 
gccrs: expand: Add outer attribute expansion on expr

Add additional outer attribute expansion on some expressions.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Add call
to attribute expansion function.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: expand: Add builtin attribute identification
Pierre-Emmanuel Patry [Mon, 3 Apr 2023 09:03:37 +0000 (11:03 +0200)] 
gccrs: expand: Add builtin attribute identification

Add a function to identify builtin attributes and skip those on proc
macro expansion phase.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::visit_outer_attrs):
Change condition order.
(ExpandVisitor::visit_inner_using_attrs): Likewise.
(ExpandVisitor::visit_attrs_with_derive): Likewise.
(ExpandVisitor::is_builtin): Add builtin identification
function.
* expand/rust-expand-visitor.h: Add function prototype.
* util/rust-attributes.cc: Add missing rustc_builtin_macro
attribute.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: expand: Add call to outer attributes stubs
Pierre-Emmanuel Patry [Fri, 31 Mar 2023 10:17:04 +0000 (12:17 +0200)] 
gccrs: expand: Add call to outer attributes stubs

Add call to outer attribute expansion stub on required types.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::expand_struct_fields):
Add call to expand structu fields.
(ExpandVisitor::expand_function_params): Add call to expand
function parameters.
(ExpandVisitor::expand_closure_params): Add call to expand
closure parameters.
(ExpandVisitor::visit): Add calls for item outer attribute
expansions.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: expand: Add stub function for attribute expansion
Pierre-Emmanuel Patry [Thu, 30 Mar 2023 18:40:07 +0000 (20:40 +0200)] 
gccrs: expand: Add stub function for attribute expansion

Add a stub function and utility functions that should be called on some
nodes to expand attribute procedural macros.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::expand_outer_attribute):
Stub for a single attribute expansion.
(ExpandVisitor::visit_outer_attrs): Visit the attributes to
expand on a given item.
* expand/rust-expand-visitor.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Add outer attribute getter to Expr class
Pierre-Emmanuel Patry [Thu, 30 Mar 2023 18:05:14 +0000 (20:05 +0200)] 
gccrs: ast: Add outer attribute getter to Expr class

We need to retrieve outer attributes from some Expressions depending on
their context. This means this should be retrieved from their parent
node. But expr did not have a getter for outer attributes since some
expr can't have any outer attribute.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add getter to Expr class.
* ast/rust-expr.h: Add override attribute to existing getters.
Also implement it for RangeExpr, attempting to retrieve outer
attributes on those types will crash the compiler.
* ast/rust-macro.h: Add override attribute to existing getters.
* ast/rust-path.h: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: expand: Add inner attribute expansion stubs
Pierre-Emmanuel Patry [Thu, 30 Mar 2023 14:35:53 +0000 (16:35 +0200)] 
gccrs: expand: Add inner attribute expansion stubs

Add function stubs for inner attribute proc macros expansion.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Add call
to inner attribute stub.
(ExpandVisitor::expand_inner_attribute): Expand one single
attribute.
(ExpandVisitor::visit_inner_using_attrs): Expand a given item
using a vector of attributes.
(ExpandVisitor::visit_inner_attrs): Visit inner attributes of a
given item.
* expand/rust-expand-visitor.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: expand: Add derive expansion stubs
Pierre-Emmanuel Patry [Thu, 30 Mar 2023 14:28:12 +0000 (16:28 +0200)] 
gccrs: expand: Add derive expansion stubs

Add derive macros expansion stub functions.

gcc/rust/ChangeLog:

* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Add call
to derive expander.
(ExpandVisitor::expand_derive): Expand a single derive.
(ExpandVisitor::visit_attrs_with_derive): Visit an item with
derive attributes.
(ExpandVisitor::is_derive): Identify a derive attribute.
* expand/rust-expand-visitor.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Fix ICE on generic args path
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 17:52:38 +0000 (19:52 +0200)] 
gccrs: ast: Fix ICE on generic args path

The path should be retrieved only when a generic arg has either type.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix ICE.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Fix macros in tokenstreams
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 16:22:56 +0000 (18:22 +0200)] 
gccrs: ast: Fix macros in tokenstreams

A default token was used as a separator, wich resulted in a wrong token
stream.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Remove
default separator.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Visit crate inner attributes for tokenstreams
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 14:56:00 +0000 (16:56 +0200)] 
gccrs: ast: Visit crate inner attributes for tokenstreams

Crate level inner attributes were not visited.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Visit inner
attributes.

18 months agogccrs: ast: Change visibility in token type
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 14:19:51 +0000 (16:19 +0200)] 
gccrs: ast: Change visibility in token type

Change the token type from a custom identifier to the reserved token
keyword "in".

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Change token
type.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Fix attribute tokenstreams
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 13:56:02 +0000 (15:56 +0200)] 
gccrs: ast: Fix attribute tokenstreams

Attributes were not converted to a correct tokenstream, furthermore meta
items containers and token trees attribute arguments were not even
implemented. This commit fix the literal attribute type and implement
both unimplemented types.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix existing
and implement remaining attribute visitors.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Output union's outer attributes
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 11:53:34 +0000 (13:53 +0200)] 
gccrs: ast: Output union's outer attributes

Output a union's outer attributes in a tokenstream.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add visitor
to the union's outer attributes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Output inner attributes in tokenstreams
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 10:50:25 +0000 (12:50 +0200)] 
gccrs: ast: Output inner attributes in tokenstreams

Inner attributes were not correctly visited.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Add call to
inner attribute visitor.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Fix char literal ICE
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 09:54:59 +0000 (11:54 +0200)] 
gccrs: ast: Fix char literal ICE

The code was attempting to convert a char to an integer by parsing it
instead of taking it's raw value.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix ICE.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Fix match case comma output
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 09:26:51 +0000 (11:26 +0200)] 
gccrs: ast: Fix match case comma output

Even though the comma may be optional with blocks of expressions, it is
mandatory for a single expression alone. By changing this behavior we
ensure a working behavior with any kind of expressions.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Make comma
mandatory.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Fix tokenstream extern block statements
Pierre-Emmanuel Patry [Tue, 4 Apr 2023 09:24:44 +0000 (11:24 +0200)] 
gccrs: ast: Fix tokenstream extern block statements

The visitor created some additional semicolon between statements in
extern blocks, this lead to empty statement.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Remove
additional semicolon output.
* ast/rust-ast-tokenstream.h: Change block visitor prototype
with a default value for trailing tokens.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Move pattern implementation out of rust-ast
Pierre-Emmanuel Patry [Mon, 3 Apr 2023 18:44:45 +0000 (20:44 +0200)] 
gccrs: ast: Move pattern implementation out of rust-ast

Move rust-pattern implementation out of rust-ast.cc in their own file.

gcc/rust/ChangeLog:

* Make-lang.in: Add two new files to the list of sources.
* ast/rust-ast-full.h: Add new ast formatting header.
* ast/rust-ast.cc (enum indent_mode): Move formatting function
to it's own file.
(indent_spaces): Likewise.
(get_string_in_delims): Likewise.
(enum AttrMode): Likewise.
(get_mode_dump_desc): Likewise.
(append_attributes): Likewise.
(unquote_string): Likewise.
(GroupedExpr::as_string): Move pattern implementation to it's
own file.
(RangePattern::as_string): Likewise.
(RangePatternBoundLiteral::as_string): Likewise.
(SlicePattern::as_string): Likewise.
(AltPattern::as_string): Likewise.
(TuplePatternItemsMultiple::as_string): Likewise.
(TuplePatternItemsRanged::as_string): Likewise.
(TuplePattern::as_string): Likewise.
(StructPatternField::as_string): Likewise.
(StructPatternFieldIdent::as_string): Likewise.
(StructPatternFieldTuplePat::as_string): Likewise.
(StructPatternFieldIdentPat::as_string): Likewise.
(StructPatternElements::as_string): Likewise.
(StructPattern::as_string): Likewise.
(LiteralPattern::as_string): Likewise.
(ReferencePattern::as_string): Likewise.
(IdentifierPattern::as_string): Likewise.
(TupleStructItemsNoRange::as_string): Likewise.
(TupleStructItemsRange::as_string): Likewise.
(TupleStructPattern::as_string): Likewise.
(GroupedExpr::accept_vis): Likewise.
(LiteralPattern::accept_vis): Likewise.
(IdentifierPattern::accept_vis): Likewise.
(WildcardPattern::accept_vis): Likewise.
(RestPattern::accept_vis): Likewise.
(RangePatternBoundLiteral::accept_vis): Likewise.
(RangePatternBoundPath::accept_vis): Likewise.
(RangePatternBoundQualPath::accept_vis): Likewise.
(RangePattern::accept_vis): Likewise.
(ReferencePattern::accept_vis): Likewise.
(StructPatternFieldTuplePat::accept_vis): Likewise.
(StructPatternFieldIdentPat::accept_vis): Likewise.
(StructPatternFieldIdent::accept_vis): Likewise.
(StructPattern::accept_vis): Likewise.
(TupleStructItemsNoRange::accept_vis): Likewise.
(TupleStructItemsRange::accept_vis): Likewise.
(TupleStructPattern::accept_vis): Likewise.
(TuplePatternItemsMultiple::accept_vis): Likewise.
(TuplePatternItemsRanged::accept_vis): Likewise.
(TuplePattern::accept_vis): Likewise.
(GroupedPattern::accept_vis): Likewise.
(SlicePattern::accept_vis): Likewise.
(AltPattern::accept_vis): Likewise.
* ast/rust-ast-formatting.cc: New file.
* ast/rust-ast-formatting.h: New file.
* ast/rust-pattern.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: ast: Move rust-path implementation out of rust-ast
Pierre-Emmanuel Patry [Mon, 3 Apr 2023 15:22:57 +0000 (17:22 +0200)] 
gccrs: ast: Move rust-path implementation out of rust-ast

Move rust-path implementation details out of rust-ast.cc file. This will
hopefully decrease compile time and make things clearer.

gcc/rust/ChangeLog:

* Make-lang.in: Add new file for rust-path implementation.
* ast/rust-ast.cc (PathInExpression::as_string): Move function
to the new file.
(PathPattern::as_string): Likewise.
(QualifiedPathInExpression::as_string): Likewise.
(ConstGenericParam::as_string): Likewise.
(QualifiedPathInType::as_string): Likewise.
(TypePath::as_string): Likewise.
(PathPattern::convert_to_simple_path): Likewise.
(TypePath::as_simple_path): Likewise.
(PathExprSegment::as_string): Likewise.
(GenericArgs::as_string): Likewise.
(GenericArgsBinding::as_string): Likewise.
(TypePath::to_trait_bound): Likewise.
(TypePathSegmentGeneric::as_string): Likewise.
(TypePathFunction::as_string): Likewise.
(TypePathSegmentFunction::as_string): Likewise.
(ConstGenericParam::accept_vis): Likewise.
(PathInExpression::accept_vis): Likewise.
(TypePathSegment::accept_vis): Likewise.
(TypePathSegmentGeneric::accept_vis): Likewise.
(TypePathSegmentFunction::accept_vis): Likewise.
(TypePath::accept_vis): Likewise.
(QualifiedPathInExpression::accept_vis): Likewise.
(QualifiedPathInType::accept_vis): Likewise.
(GenericArg::disambiguate_to_const): Likewise.
(GenericArg::disambiguate_to_type): Likewise.
* ast/rust-path.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
18 months agogccrs: Fix ICE using constructors for intilizers in statics
Philip Herron [Sun, 2 Apr 2023 20:59:50 +0000 (21:59 +0100)] 
gccrs: Fix ICE using constructors for intilizers in statics

We are getting constant expressions for the initilizers for static items
this hits an assertion in the GCC middle-end which is looking for a
constructor so we need to unwrap the constant expression using DECL_INITIAL
as the initilizer to the global static.

Fixes #2080

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc (CompileItem::visit): unwrap the constant expression

gcc/testsuite/ChangeLog:

* rust/execute/torture/issue-2080.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
18 months agogccrs: Handle "fn" and "fn_mut" lang items
Owen Avery [Mon, 3 Apr 2023 22:52:23 +0000 (18:52 -0400)] 
gccrs: Handle "fn" and "fn_mut" lang items

gcc/rust/ChangeLog:

* util/rust-lang-item.h
(RustLangItem::ItemType::FN): Add.
(RustLangItem::ItemType::FN_MUT): Add.
(RustLangItem::Parse): Handle FN and FN_MUT.
(RustLangItem::ToString): Handle FN and FN_MUT.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>