]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
9 months agogccrs: Fix ICE during path probe
Philip Herron [Mon, 3 Feb 2025 15:15:40 +0000 (15:15 +0000)] 
gccrs: Fix ICE during path probe

It is valid for the query to fail here so its valid to not assert here.

gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc (PathProbeType::visit): remove assertion

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
9 months agogccrs: Fix ICE when fn_once and fn_once_output lang item is not defined
Philip Herron [Mon, 3 Feb 2025 15:14:01 +0000 (15:14 +0000)] 
gccrs: Fix ICE when fn_once and fn_once_output lang item is not defined

We needed to check for the optional has a value here or not it leads to an
ICE.

gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): add checks for lang items

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
9 months agoFix bug in type resolution of paths
Owen Avery [Sat, 4 Jan 2025 19:59:54 +0000 (14:59 -0500)] 
Fix bug in type resolution of paths

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::resolve_glob_import): Use
NameResolutionContext::resolve_path instead of
ForeverStack::resolve_path.
(Early::visit): Likewise.
(Early::visit_attributes): Likewise.
* resolve/rust-early-name-resolver-2.0.h
(Early::resolve_path_in_all_ns): Likewise.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Likewise, insert segment resolutions not
handled by NameResolutionContext::resolve_path, and avoid throwing
an error when path resolution could be finished by the typechecker.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::resolve_path): Add.
* typecheck/rust-hir-type-check-path.cc
(TypeCheckExpr::resolve_root_path): Use segment node ids instead
of the path node id to look up segment resolutions when using
the 2.0 resolver, as is done with the 1.0 resolver.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::resolve_root_path): Likewise.
* resolve/rust-forever-stack.h
(ForeverStack::resolve_path): Add callback parameter for
inserting segment resolutions.
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_segments): Likewise.
* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Likewise.
(ForeverStack::resolve_segments): Likewise.
(ForeverStack::resolve_path): Likewise and avoid resolving
inside TraitOrImpl ribs.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
9 months agonr2.0: Remove accidental copies of resolver
Owen Avery [Mon, 21 Oct 2024 22:02:48 +0000 (18:02 -0400)] 
nr2.0: Remove accidental copies of resolver

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc
(CompileExpr::generate_closure_function): Take
NameResolutionContext by reference instead of by value.
* backend/rust-compile-item.cc
(CompileItem::visit): Likewise.
* backend/rust-compile-resolve-path.cc
(ResolvePathRef::resolve): Likewise.
* checks/lints/rust-lint-marklive.cc
(MarkLive::find_ref_node_id): Likewise.
* typecheck/rust-hir-type-check-enumitem.cc
(TypeCheckEnumItem::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.cc
(TypeCheckImplItem::visit): Likewise.
* typecheck/rust-hir-type-check-item.cc
(TypeCheckItem::visit): Likewise.
* typecheck/rust-hir-type-check-path.cc
(TypeCheckExpr::resolve_root_path): Likewise.
* typecheck/rust-hir-type-check-type.cc
(TypeCheckType::resolve_root_path): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
9 months agoast: builder: Add Return expression builder
Arthur Cohen [Thu, 23 Jan 2025 11:42:38 +0000 (11:42 +0000)] 
ast: builder: Add Return expression builder

gcc/rust/ChangeLog:

* ast/rust-ast-builder.h: Declare it.
* ast/rust-ast-builder.cc (Builder::return_expr): Define it.

9 months agoderive(Debug): Add stub implementation.
Arthur Cohen [Wed, 29 Jan 2025 18:10:01 +0000 (18:10 +0000)] 
derive(Debug): Add stub implementation.

gcc/rust/ChangeLog:

* expand/rust-derive-debug.cc: New file.
* expand/rust-derive-debug.h: New file.
* Make-lang.in: Compile them.
* expand/rust-derive.cc (DeriveVisitor::derive): Call into DeriveDebug.

gcc/testsuite/ChangeLog:

* rust/compile/derive-debug1.rs: New test.
* rust/compile/nr2/exclude: Exclude it.

9 months agoderive(Clone, Copy): Cleanup using new method from DeriveVisitor
Arthur Cohen [Thu, 30 Jan 2025 10:01:33 +0000 (11:01 +0100)] 
derive(Clone, Copy): Cleanup using new method from DeriveVisitor

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc: Cleanup using DeriveVisitor::setup_impl_generics.
* expand/rust-derive-copy.cc: Likewise.

9 months agoderive-visitor: Add method for setting up derived impl generics
Arthur Cohen [Thu, 30 Jan 2025 09:50:30 +0000 (10:50 +0100)] 
derive-visitor: Add method for setting up derived impl generics

gcc/rust/ChangeLog:

* expand/rust-derive.cc (DeriveVisitor::setup_impl_generics): New method.
* expand/rust-derive.h: Declare it, define DeriveVisitor::ImplGenerics struct.

9 months agoast-builder: Add new methods for functions, traits and tuples.
Arthur Cohen [Thu, 30 Jan 2025 09:50:13 +0000 (10:50 +0100)] 
ast-builder: Add new methods for functions, traits and tuples.

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc: New methods.
* ast/rust-ast-builder.h: Declare them.

9 months agoast-builder: Add new functions to create type paths.
Arthur Cohen [Wed, 29 Jan 2025 18:11:28 +0000 (18:11 +0000)] 
ast-builder: Add new functions to create type paths.

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::type_path): New functions.
* ast/rust-ast-builder.h: Declare them.

9 months agoscan-deadcode: Do not warn unused fields if they start with '_'
Arthur Cohen [Thu, 30 Jan 2025 12:08:33 +0000 (13:08 +0100)] 
scan-deadcode: Do not warn unused fields if they start with '_'

gcc/rust/ChangeLog:

* checks/lints/rust-lint-scan-deadcode.h: Check if the field name starts with an
underscore before warning.

9 months agolang-items: Add structural_{peq, teq}
Arthur Cohen [Thu, 30 Jan 2025 13:19:03 +0000 (14:19 +0100)] 
lang-items: Add structural_{peq, teq}

These lang items are used when deriving Eq and PartialEq, and will be checked when compiling pattern matching.

gcc/rust/ChangeLog:

* util/rust-lang-item.cc: New items.
* util/rust-lang-item.h: Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/structural-eq-peq.rs: New test.

9 months agonr2.0: late: Add proper handling for lang item PathInExpressions
Arthur Cohen [Fri, 31 Jan 2025 12:26:21 +0000 (12:26 +0000)] 
nr2.0: late: Add proper handling for lang item PathInExpressions

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Special case lang item paths.

9 months agoFix an issue with ForeverStack::dfs_rib
Owen Avery [Sat, 1 Feb 2025 04:03:03 +0000 (23:03 -0500)] 
Fix an issue with ForeverStack::dfs_rib

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.hxx
(ForeverStack::dfs_rib): Fix const implementation.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
9 months agoAdd option_env! support
Liam Naddell [Fri, 31 Jan 2025 01:51:21 +0000 (20:51 -0500)] 
Add option_env! support

gcc/rust/ChangeLog:
* expand/rust-macro-builtins-utility.cc: Add macro expansion for
option_env with eager expansion
* expand/rust-macro-builtins.cc: Add option_env to builtin list
* expand/rust-macro-builtins.h: Add option_env handler to header
file
* resolve/rust-late-name-resolver-2.0.cc: Prevent NR2.0 from
recursing into lang-item segments

gcc/testsuite/ChangeLog:
* rust/compile/macros/builtin/option_env1.rs: Add success case for option_env
* rust/compile/macros/builtin/option_env2.rs: Add failure case for option_env
* rust/execute/torture/builtin_macro_option_env.rs: Add
execution case for option_env

9 months agoast: Add new Expr::Kinds
Arthur Cohen [Thu, 23 Jan 2025 11:43:31 +0000 (11:43 +0000)] 
ast: Add new Expr::Kinds

Collapses all of the OperatorExprs into Expr instead of first having to check for OperatorExpr and
then check for each OperatorExpr::Kind.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add new Expr::Kinds.
* ast/rust-expr.h: Implement missing get_expr_kind(), Add get_function_expr_ptr()

10 months agogccrs: add support for ref literal patterns
Philip Herron [Tue, 21 Jan 2025 17:20:06 +0000 (17:20 +0000)] 
gccrs: add support for ref literal patterns

Fixes Rust-GCC#3174

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternBindings::visit): make recursive
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): handle ref flag

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/issue-3174.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
10 months agolang-items: Add From::from
Arthur Cohen [Thu, 23 Jan 2025 11:46:48 +0000 (11:46 +0000)] 
lang-items: Add From::from

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Declare it.
* util/rust-lang-item.cc: Use it.

10 months agogccrs: add new -frust-overflow-checks flag to control overflow checks
Philip Herron [Thu, 23 Jan 2025 14:44:20 +0000 (14:44 +0000)] 
gccrs: add new -frust-overflow-checks flag to control overflow checks

This will be crucial for more complex gimple debugging to make it easier
to follow the code vs the original rust code.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): disable overflow checks
* lang.opt: new flag

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
10 months agoRemove some passing test from exclude file
Pierre-Emmanuel Patry [Sat, 11 Jan 2025 21:35:08 +0000 (22:35 +0100)] 
Remove some passing test from exclude file

Those tests are now passing.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove some tests.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agoCompile unit struct with constructor
Pierre-Emmanuel Patry [Mon, 13 Jan 2025 17:26:37 +0000 (18:26 +0100)] 
Compile unit struct with constructor

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Do
not use query system for unit struct but compile it's constructor
instead.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agoResolved item type shall be differentiated later
Pierre-Emmanuel Patry [Mon, 6 Jan 2025 14:55:53 +0000 (15:55 +0100)] 
Resolved item type shall be differentiated later

We need to query all namespaces and error out at a later stage if the
retrieved item is wrong.

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait):
Query all namespaces.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agoMake foreverstack debug string const
Pierre-Emmanuel Patry [Mon, 6 Jan 2025 14:53:31 +0000 (15:53 +0100)] 
Make foreverstack debug string const

Those function should not change anything within the foreverstack, it
can therefore be made const.

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h: Make debug functions const.
* resolve/rust-forever-stack.hxx: Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agoClone expr instead of taking it
Pierre-Emmanuel Patry [Thu, 12 Dec 2024 17:30:09 +0000 (18:30 +0100)] 
Clone expr instead of taking it

We're reusing the value, it could therefore not be taken be should be
cloned.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit):
Clone expr instead of taking it.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agoRemove some tests from nr2 exclusion file
Pierre-Emmanuel Patry [Thu, 12 Dec 2024 13:39:12 +0000 (14:39 +0100)] 
Remove some tests from nr2 exclusion file

Those test are now passing.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove passing tests.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agoRemove query mode on CompileItem
Pierre-Emmanuel Patry [Thu, 12 Dec 2024 12:16:14 +0000 (13:16 +0100)] 
Remove query mode on CompileItem

Query mode was a hack to catch up some compile errors early, it was
deemed to be removed at some time. Recent changes to NR1 highlighted
an incompatibility with it hence it's removal.

gcc/rust/ChangeLog:

* backend/rust-compile-item.h: Remove query mode.
* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile):
Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agoAdd unit struct to name namespace in old resolver
Pierre-Emmanuel Patry [Wed, 11 Dec 2024 14:12:00 +0000 (15:12 +0100)] 
Add unit struct to name namespace in old resolver

We missed the name namespace for unit struct in the old resolver.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-toplevel.h: Add struct to name namespace.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agoAdd debug dump to old name resolver
Pierre-Emmanuel Patry [Wed, 11 Dec 2024 13:19:44 +0000 (14:19 +0100)] 
Add debug dump to old name resolver

It might be necessary to compare both name resolution' internal states
during the transition. This new debug representation could help with
that.

gcc/rust/ChangeLog:

* resolve/rust-name-resolver.h: Add new degug dump for old name
resolver.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agoLabels shall be pushed within label namespace
Pierre-Emmanuel Patry [Wed, 11 Dec 2024 11:04:32 +0000 (12:04 +0100)] 
Labels shall be pushed within label namespace

Labels were using the wrong namespace.

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Change label
push function from type rib to label rib.
* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit):
Likewise.
(ResolveItem::visit): Likewise.
(ResolveExternItem::visit): Likewise.
* resolve/rust-ast-resolve-stmt.h: Likewise.
* resolve/rust-ast-resolve.cc (NameResolution::go): Likewise.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agobackend: Improve handling of lang-item PathInExpressions
Arthur Cohen [Fri, 24 Jan 2025 09:42:54 +0000 (10:42 +0100)] 
backend: Improve handling of lang-item PathInExpressions

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (ResolvePathRef::visit): Call into
resolve_path_like instead.
(ResolvePathRef::resolve_path_like): New.
(ResolvePathRef::resolve): Call into resolve_with_node_id.
* backend/rust-compile-resolve-path.h: Declare new functions and document them.

10 months agoast: Add Path::is_lang_item()
Arthur Cohen [Wed, 22 Jan 2025 16:52:26 +0000 (16:52 +0000)] 
ast: Add Path::is_lang_item()

gcc/rust/ChangeLog:

* ast/rust-path.h: New function.

10 months agomarklive: Fix handling for lang item PathInExpressions.
Arthur Cohen [Tue, 24 Dec 2024 11:45:25 +0000 (11:45 +0000)] 
marklive: Fix handling for lang item PathInExpressions.

gcc/rust/ChangeLog:

* checks/lints/rust-lint-marklive.cc (MarkLive::visit): Adapt to lang items.

10 months agohir: Adapt visitors to lang item PathInExpressions
Arthur Cohen [Wed, 22 Jan 2025 12:36:59 +0000 (12:36 +0000)] 
hir: Adapt visitors to lang item PathInExpressions

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (ResolvePathRef::visit): Adapt visitor to lang item
HIR::PathInExpressions.
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise.

10 months agohir: Add LangItem paths to PathPattern class
Arthur Cohen [Mon, 16 Dec 2024 12:01:13 +0000 (13:01 +0100)] 
hir: Add LangItem paths to PathPattern class

gcc/rust/ChangeLog:

* hir/tree/rust-hir-path.h: Adapt PathPattern to accept lang-item paths.
* hir/tree/rust-hir-path.cc: Assert we are dealing with a segmented path, create lang-item
constructors.
* hir/tree/rust-hir.cc (PathPattern::convert_to_simple_path): Likewise.

10 months agoast: More visitors to allow lang item paths in expressions
Arthur Cohen [Wed, 22 Jan 2025 14:09:08 +0000 (14:09 +0000)] 
ast: More visitors to allow lang item paths in expressions

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Adapt visitor to lang item
PathInExpressions.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower.cc (ASTLoweringExprWithBlock::visit): Likewise.
(ASTLowerPathInExpression::visit): Likewise.
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise.

10 months agolang-items: Add LangItem::IsEnumVariant
Arthur Cohen [Mon, 23 Dec 2024 16:43:35 +0000 (16:43 +0000)] 
lang-items: Add LangItem::IsEnumVariant

gcc/rust/ChangeLog:

* util/rust-lang-item.cc (LangItem::IsEnumVariant): New function.
* util/rust-lang-item.h: Declare it.

10 months agomappings: Improve error message for get_lang_item_node
Arthur Cohen [Wed, 22 Jan 2025 12:37:58 +0000 (12:37 +0000)] 
mappings: Improve error message for get_lang_item_node

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::get_lang_item_node): Better formatting when a lang
item does not exist when it should.

10 months agolang-items: Collect enum variants as lang items
Arthur Cohen [Mon, 23 Dec 2024 10:27:13 +0000 (10:27 +0000)] 
lang-items: Collect enum variants as lang items

gcc/rust/ChangeLog:

* ast/rust-collect-lang-items.h: Declare visitor.
* ast/rust-collect-lang-items.cc (CollectLangItems::visit): New.

10 months agogccrs: catch missing guard for optional result
Philip Herron [Tue, 21 Jan 2025 17:19:13 +0000 (17:19 +0000)] 
gccrs: catch missing guard for optional result

When we lookup here it returns an optional which can lead to a crash
because it needs a guard if it has a value.

gcc/rust/ChangeLog:

* backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): add guard

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: these tests now work it seems

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
10 months agoInfer crate name after file opening
Dylan Gardner [Thu, 29 Aug 2024 11:43:42 +0000 (04:43 -0700)] 
Infer crate name after file opening

Fixes #3129.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::handle_crate_name): Remove
crate name inference
(Session::compile_crate): Add crate name inference and error if
inferred name is empty. Remove CompileOptions::get_instance ()
that returned a local copy of the options. Rename
crate_name_changed to crate_name_found to match semantics.
(rust_crate_name_validation_test): Test inferring ".rs" name
* rust-session-manager.h: Modify handle_crate_name definition to
include filename.

10 months agoAdd captures for ClosureExprInnerTyped with nr2
Pierre-Emmanuel Patry [Fri, 24 Jan 2025 15:02:10 +0000 (16:02 +0100)] 
Add captures for ClosureExprInnerTyped with nr2

Captures were only processed for regular ClosureExprInner.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add
ClosureExprInnerTyped visit implementation.
(add_captures): Add a function to avoid code duplication.
* resolve/rust-late-name-resolver-2.0.h: Add function prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agoAdd environment capture to NR2
Pierre-Emmanuel Patry [Mon, 20 Jan 2025 12:49:25 +0000 (13:49 +0100)] 
Add environment capture to NR2

The compiler was still relying on NR1 for closure captures when using nr2
even though the resolver was not used and thus it's state empty.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add environment
collection.
* resolve/rust-late-name-resolver-2.0.h: Add function prototype.
* resolve/rust-name-resolver.cc (Resolver::get_captures): Add assertion
to prevent NR2 usage with nr1 capture functions.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Use
nr2 captures.
* util/rust-hir-map.cc (Mappings::add_capture): Add function to
register capture for a given closure.
(Mappings::lookup_captures):  Add a function to lookup all captures
available for a given closure.
* util/rust-hir-map.h: Add function prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agoUpdate upload-artifact to v4
Owen Avery [Thu, 23 Jan 2025 17:34:01 +0000 (12:34 -0500)] 
Update upload-artifact to v4

ChangeLog:

* .github/workflows/ccpp.yml: Update actions/upload-artifact
from v3 to v4, handle any artifact name conflicts.
* .github/workflows/ccpp32alpine.yml: Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
10 months agoCheck for type paths nr2.0 can't handle yet
Owen Avery [Tue, 21 Jan 2025 22:02:35 +0000 (17:02 -0500)] 
Check for type paths nr2.0 can't handle yet

Some of our tests only work with name resolution 2.0 because the latter
misinterprets type paths. This change should cause the compiler to error out
if it would otherwise misinterpret a type path. A fix for type path
resolution isn't included in this comment, since doing so would make it
harder to track the meaningfulness of test regressions.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Error out if a type path has multiple segments,
as we currently ignore every segment except the last.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Add entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
10 months agobackend: Allow anything as a match scrutinee
Arthur Cohen [Tue, 24 Dec 2024 11:45:09 +0000 (11:45 +0000)] 
backend: Allow anything as a match scrutinee

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (check_match_scrutinee): Allow anything to be used as a
match scrutinee, not just ADTs.

10 months agolang-items: Add Result and Try lang items
Arthur Cohen [Tue, 21 Jan 2025 15:13:11 +0000 (16:13 +0100)] 
lang-items: Add Result and Try lang items

gcc/rust/ChangeLog:

* util/rust-lang-item.h: Add handling for Result::Ok, Result::Err, Try, Try::into_result,
Try::from_ok, Try::from_err.
* util/rust-lang-item.cc: Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/try-trait.rs: New test.

10 months agoFix rust breakage with nr2
Pierre-Emmanuel Patry [Mon, 25 Nov 2024 17:04:06 +0000 (18:04 +0100)] 
Fix rust breakage with nr2

Nr2 did not emit the correct error message for break identifier "rust".

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add "rust"
identifier detection akin to nr1.
(funny_ice_finalizer): Copy ICE finalizer from nr1.
* resolve/rust-late-name-resolver-2.0.h: Add funny_error member
context state.
* Make-lang.in: Add new translation unit for new ice finalizer.
* resolve/rust-ast-resolve-expr.cc: Move ice
finalizer to it's own file.
* resolve/rust-ice-finalizer.cc: New file.
* resolve/rust-ice-finalizer.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove break-rust3.rs from exclude list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
10 months agoderive(Copy): Improve bounds when deriving Copy
Arthur Cohen [Thu, 16 Jan 2025 13:46:06 +0000 (14:46 +0100)] 
derive(Copy): Improve bounds when deriving Copy

gcc/rust/ChangeLog:

* expand/rust-derive-copy.cc: Always add an extra Copy bound on generic Copy impls.

10 months agoderive(Clone): Use lang item bounds on AssertParamIsCopy
Arthur Cohen [Mon, 20 Jan 2025 11:36:53 +0000 (11:36 +0000)] 
derive(Clone): Use lang item bounds on AssertParamIsCopy

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::visit_union): Use lang items for Copy and
Sized bounds.

gcc/testsuite/ChangeLog:

* rust/compile/derive_macro6.rs: Add lang item attribute to Copy trait.

10 months agoderive(Clone): Add Clone bound on generated impl blocks
Arthur Cohen [Wed, 15 Jan 2025 13:00:45 +0000 (13:00 +0000)] 
derive(Clone): Add Clone bound on generated impl blocks

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc: Add extra bound when deriving generic Clone

10 months agoast-builder: Add extra parameter for TypeParam builder
Arthur Cohen [Wed, 15 Jan 2025 12:59:51 +0000 (12:59 +0000)] 
ast-builder: Add extra parameter for TypeParam builder

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::new_type_param): Add optional extra trait bounds.
* ast/rust-ast-builder.h: Likewise.

10 months agohir-dump: Improve handling of typepathsegments that are lang items.
Arthur Cohen [Wed, 15 Jan 2025 12:58:53 +0000 (12:58 +0000)] 
hir-dump: Improve handling of typepathsegments that are lang items.

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::do_typepathsegment): Add handling for lang items.

10 months agolang-item:Add LangItem::Kind::RECEIVER
lishin [Mon, 20 Jan 2025 17:53:18 +0000 (17:53 +0000)] 
lang-item:Add LangItem::Kind::RECEIVER

Add and implement a lang item (receiver) in source code.

gcc/rust/ChangeLog:

* util/rust-lang-item.cc: Add receiver to map.
* util/rust-lang-item.h: Define LangItem::Kind::RECEIVER.

gcc/testsuite/ChangeLog:

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

Signed-off-by: lishin <lishin1008@gmail.com>
10 months agotypecheck: Add basic handling for applying auto trait bounds
Arthur Cohen [Thu, 16 Jan 2025 16:10:02 +0000 (17:10 +0100)] 
typecheck: Add basic handling for applying auto trait bounds

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Register auto traits in mappings.
* util/rust-hir-map.cc (Mappings::insert_auto_trait): New.
(Mappings::get_auto_traits): New.
* util/rust-hir-map.h: Declare them.
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Add auto trait bounds when
scanning.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Some parts of nr2.0 can't handle auto traits yet.
* rust/compile/auto_traits3.rs: Removed in favor of...
* rust/compile/auto_traits2.rs: ...this one.
* rust/compile/auto_traits4.rs: New test.

10 months agotypecheck: Separate assemble_builtin_candidate in two
Arthur Cohen [Thu, 16 Jan 2025 15:55:56 +0000 (16:55 +0100)] 
typecheck: Separate assemble_builtin_candidate in two

This paves the way for adding trait bounds that aren't necessarily Sized.

gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::add_trait_bound): New function.
* typecheck/rust-hir-type-bounds.h: Declare it.
(TypeBoundsProbe::assemble_builtin_candidate): Call into add_trait_bound.

10 months agonr2.0: late: Better format PathInExpression resolution
Arthur Cohen [Wed, 15 Jan 2025 11:55:54 +0000 (11:55 +0000)] 
nr2.0: late: Better format PathInExpression resolution

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Improve formatting.

10 months agoderive(Clone): Add lang item typepaths failure testcases to nr2 exclude
Arthur Cohen [Wed, 15 Jan 2025 10:41:28 +0000 (10:41 +0000)] 
derive(Clone): Add lang item typepaths failure testcases to nr2 exclude

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Add failing lang item typepaths tests.
* rust/execute/torture/derive_macro4.rs: Mark Clone as lang item.

10 months agoderive(Clone): Implement derive clone for enum struct variants
Arthur Cohen [Fri, 3 Jan 2025 15:14:45 +0000 (15:14 +0000)] 
derive(Clone): Implement derive clone for enum struct variants

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::clone_enum_struct): New function for deriving
enum struct variants.
(DeriveClone::visit_enum): Call into the new function.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude:
* rust/compile/derive_clone_enum1.rs: New test.
* rust/compile/derive_clone_enum2.rs: New test.
* rust/compile/derive_clone_enum3.rs: New test.
* rust/execute/torture/derive_clone_enum1.rs: New test.

10 months agoderive(Clone): Implement clone for enum tuple variants
Arthur Cohen [Fri, 3 Jan 2025 14:27:52 +0000 (14:27 +0000)] 
derive(Clone): Implement clone for enum tuple variants

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::variant_match_path): New function.
(DeriveClone::clone_enum_identifier): Rename.
(DeriveClone::clone_enum_tuple): New function.
(DeriveClone::visit_enum): Visit tuple variants properly.
* expand/rust-derive-clone.h: Declare new functions.

10 months agoast-builder: Add new methods for building structs
Arthur Cohen [Fri, 3 Jan 2025 14:27:38 +0000 (14:27 +0000)] 
ast-builder: Add new methods for building structs

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc: Add new methods for constructing struct exprs.
* ast/rust-ast-builder.h: Mention how to build tuple expressions.

10 months agoderive(Clone): Add deriving of simple enum variants
Arthur Cohen [Thu, 2 Jan 2025 10:59:33 +0000 (10:59 +0000)] 
derive(Clone): Add deriving of simple enum variants

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc: Clone enum identifier variants properly
* expand/rust-derive-clone.h: Declare new functions used.

10 months agoderive(Clone): Improve existing testcase
Arthur Cohen [Thu, 2 Jan 2025 11:00:21 +0000 (11:00 +0000)] 
derive(Clone): Improve existing testcase

gcc/testsuite/ChangeLog:

* rust/compile/derive_macro4.rs: Mark Copy and Clone as lang items.

10 months agoderive(Clone): Add note about Clone::clone()
Arthur Cohen [Thu, 2 Jan 2025 10:56:11 +0000 (10:56 +0000)] 
derive(Clone): Add note about Clone::clone()

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::clone_call): Mention using `clone_fn`
lang item in the future.

10 months agoderive(Clone): Use lang item for PhantomData in Clone
Arthur Cohen [Thu, 26 Dec 2024 23:01:32 +0000 (23:01 +0000)] 
derive(Clone): Use lang item for PhantomData in Clone

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::visit_union): Create a lang item path
instead of a regular path.

10 months agoast-builder: Add new methods around type paths.
Arthur Cohen [Thu, 26 Dec 2024 22:09:46 +0000 (22:09 +0000)] 
ast-builder: Add new methods around type paths.

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc: New functions.
* ast/rust-ast-builder.h: Declare them.

10 months agoderive(Copy): Use copy lang item when deriving Copy.
Arthur Cohen [Thu, 26 Dec 2024 22:09:11 +0000 (22:09 +0000)] 
derive(Copy): Use copy lang item when deriving Copy.

gcc/rust/ChangeLog:

* expand/rust-derive-copy.cc: Use lang item path.

10 months agoderive(Clone): Mark PhantomData as a lang item
Arthur Cohen [Thu, 26 Dec 2024 10:57:07 +0000 (10:57 +0000)] 
derive(Clone): Mark PhantomData as a lang item

gcc/testsuite/ChangeLog:

* rust/compile/derive_macro4.rs: Make PhantomData a lang item.

10 months agoderive(Clone): Manually generate AssertParamIsCopy struct for unions
Arthur Cohen [Thu, 26 Dec 2024 10:50:13 +0000 (10:50 +0000)] 
derive(Clone): Manually generate AssertParamIsCopy struct for unions

gcc/rust/ChangeLog:

* expand/rust-derive-clone.cc (DeriveClone::visit_union): Manually generate
the struct used for asserting a union implements Copy.

10 months agobuilder: Allow generating struct statements
Arthur Cohen [Thu, 26 Dec 2024 10:49:16 +0000 (10:49 +0000)] 
builder: Allow generating struct statements

gcc/rust/ChangeLog:

* ast/rust-ast-builder.cc (Builder::struct_struct): New function.
* ast/rust-ast-builder.h (vec): New function.

10 months agolang-items: Mark Clone trait as a lang item in testsuite
Arthur Cohen [Fri, 3 Jan 2025 15:46:33 +0000 (15:46 +0000)] 
lang-items: Mark Clone trait as a lang item in testsuite

gcc/testsuite/ChangeLog:

* rust/compile/derive_macro1.rs: Add #[lang = "clone"] to Clone trait.
* rust/compile/derive_macro3.rs: Likewise.
* rust/compile/derive_macro6.rs: Likewise.
* rust/execute/torture/derive_macro3.rs: Likewise.

10 months agoast-collector: Fix tuple struct pattern collection
Arthur Cohen [Fri, 3 Jan 2025 14:28:07 +0000 (14:28 +0000)] 
ast-collector: Fix tuple struct pattern collection

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Visit tuple pattern items as
separated by commas.

10 months agoast-collector: Adapt to lang item type path segments
Arthur Cohen [Tue, 31 Dec 2024 17:36:50 +0000 (17:36 +0000)] 
ast-collector: Adapt to lang item type path segments

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc (TokenCollector::visit): Fix collector to better
handle lang item type path segments.

10 months agomappings: Add get_lang_item_node
Arthur Cohen [Thu, 26 Dec 2024 23:00:08 +0000 (23:00 +0000)] 
mappings: Add get_lang_item_node

This method errors out if the lang item has not been declared yet.

gcc/rust/ChangeLog:

* util/rust-hir-map.cc (Mappings::get_lang_item_node): New.
* util/rust-hir-map.h: New function.

10 months agolang-item: Add LangItem::PrettyString
Arthur Cohen [Thu, 26 Dec 2024 22:45:12 +0000 (22:45 +0000)] 
lang-item: Add LangItem::PrettyString

Which formats a lang item as it appears in source code.

gcc/rust/ChangeLog:

* util/rust-lang-item.cc (LangItem::PrettyString): New.
* util/rust-lang-item.h: New.

10 months agolang-items: Collect struct lang items.
Arthur Cohen [Thu, 26 Dec 2024 22:35:15 +0000 (22:35 +0000)] 
lang-items: Collect struct lang items.

gcc/rust/ChangeLog:

* ast/rust-collect-lang-items.cc (CollectLangItems::visit): New.
* ast/rust-collect-lang-items.h: New.

10 months agolower: Properly lower non-generic lang item type path segments.
Arthur Cohen [Thu, 2 Jan 2025 10:41:44 +0000 (10:41 +0000)] 
lower: Properly lower non-generic lang item type path segments.

gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLowerTypePath::visit): Adapt code to lang item
type path segments.

10 months agotychk: resolve lang item type paths properly
Arthur Cohen [Thu, 2 Jan 2025 10:37:00 +0000 (10:37 +0000)] 
tychk: resolve lang item type paths properly

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Adapt
code to handle lang item type paths.

10 months agoast: Refactor how lang item paths are handled.
Arthur Cohen [Thu, 26 Dec 2024 21:46:03 +0000 (21:46 +0000)] 
ast: Refactor how lang item paths are handled.

Lang item typepaths were not handled properly, and required a complete overhaul.
All old classes that concerned lang item paths are now modified to use a simpler
version of `AST::LangItemPath`, which has been removed. TypePath segments can now
be lang items, as this is requied for having generic lang item paths such as
PhantomData<T>.

gcc/rust/ChangeLog:

* ast/rust-path.h: Rework how lang item paths are represented.
* ast/rust-path.cc: Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-ast.cc: Likewise.
* ast/rust-ast-collector.cc: Adapt to new lang item path system.
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-visitor.h: Likewise.
* expand/rust-derive-copy.cc: Likewise.
* expand/rust-derive.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Likewise.
(ASTLowerTypePath::visit): Likewise.
* hir/rust-ast-lower-type.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise.
* resolve/rust-ast-resolve-type.h: Likewise.
* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise.
* resolve/rust-late-name-resolver-2.0.h: Likewise.
* hir/tree/rust-hir-path.cc (TypePathSegment::TypePathSegment): Likewise.
(TypePathSegmentGeneric::TypePathSegmentGeneric): Likewise.
* hir/tree/rust-hir-path.h: Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise.
* ast/rust-ast-builder.cc: Likewise.
* ast/rust-ast-builder.h: Likewise.

10 months agocollect-lang-items: Display attribute upon error finding it
Arthur Cohen [Fri, 3 Jan 2025 15:45:39 +0000 (15:45 +0000)] 
collect-lang-items: Display attribute upon error finding it

gcc/rust/ChangeLog:

* ast/rust-collect-lang-items.cc (get_lang_item_attr): Show unknown attribute upon error.

10 months agoattributes: Add #[derive] as a built-in attribute
Arthur Cohen [Fri, 3 Jan 2025 15:45:57 +0000 (15:45 +0000)] 
attributes: Add #[derive] as a built-in attribute

gcc/rust/ChangeLog:

* util/rust-attribute-values.h: Declare new attribute value.
* util/rust-attributes.cc: Use it.

10 months agoast: Fix warning about copy elision for moved expr
Arthur Cohen [Thu, 26 Dec 2024 21:31:21 +0000 (21:31 +0000)] 
ast: Fix warning about copy elision for moved expr

gcc/rust/ChangeLog:

* ast/rust-ast.cc (BlockExpr::normalize_tail_expr): Remove overzealous
std::move

10 months agoRemove dead code related to external functions
Owen Avery [Fri, 10 Jan 2025 20:50:25 +0000 (15:50 -0500)] 
Remove dead code related to external functions

gcc/rust/ChangeLog:

* ast/rust-ast-collector.cc
(TokenCollector::visit): Remove visitor for NamedFunctionParam.
* ast/rust-ast-collector.h
(TokenCollector::visit): Likewise.
* ast/rust-ast-full-decls.h
(class NamedFunctionParam): Remove forward declaration.
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Remove visitor for
NamedFunctionParam.
* ast/rust-ast-visitor.h
(DefaultASTVisitor::visit): Likewise.
* ast/rust-ast.cc
(NamedFunctionParam::as_string): Remove.
* ast/rust-item.h
(class NamedFunctionParam): Remove.
(class ExternalFunctionItem): Remove.
* parse/rust-parse-impl.h
(Parser::parse_named_function_param): Remove.
(Parser::parse_named_function_params): Remove.
* parse/rust-parse.h
(Parser::parse_named_function_param): Remove.
(Parser::parse_named_function_params): Remove.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
10 months agonr2.0: Early resolve pending eager macro invocations
Owen Avery [Sat, 11 Jan 2025 04:55:29 +0000 (23:55 -0500)] 
nr2.0: Early resolve pending eager macro invocations

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc
(Early::visit): Resolve the pending eager invocations inside
builtin macro invocations.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
10 months agogccrs: Add missing name resolution to static items in blocks
Philip Herron [Mon, 13 Jan 2025 11:51:51 +0000 (11:51 +0000)] 
gccrs: Add missing name resolution to static items in blocks

We need to add name resolution and hir lowering for items as part of blocks
in order to typecheck and compile them correctly.

Fixes Rust-GCC#3350

gcc/rust/ChangeLog:

* hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): hir lowering
* hir/rust-ast-lower-stmt.h: likewise
* resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): name resolution
* resolve/rust-ast-resolve-stmt.h: likewise

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
10 months agoRevert "gcc/rust/ChangeLog:"
CohenArthur [Fri, 10 Jan 2025 14:26:39 +0000 (15:26 +0100)] 
Revert "gcc/rust/ChangeLog:"

This reverts commit 600fd806b8821ea24103ea0f31d666077245c6b7.

10 months agogccrs: Fix scan-gimple testcases on LE platforms.
Arthur Cohen [Tue, 23 Jan 2024 16:19:31 +0000 (17:19 +0100)] 
gccrs: Fix scan-gimple testcases on LE platforms.

gcc/testsuite/ChangeLog:

* rust/compile/macros/builtin/eager1.rs: Switch to scan-assembler directive as the
GIMPLE dump does not contain strings on LE.
* rust/compile/macros/builtin/recurse2.rs: Likewise.

10 months agotestsuite: Fix missing handling of little endian.
Arthur Cohen [Thu, 18 Jan 2024 16:24:01 +0000 (17:24 +0100)] 
testsuite: Fix missing handling of little endian.

Some failures occur in the testsuite because we
did not account for the little-endian case.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1446.rs: Add swap_bytes function.
* rust/compile/iterators1.rs: Remove unused {to, from}_le functions.

10 months agoAdd ForeverStackStore
Owen Avery [Fri, 15 Nov 2024 00:57:42 +0000 (19:57 -0500)] 
Add ForeverStackStore

ForeverStackStore is meant to partially unify the internal states of
per-namespace ForeverStack instances. This commit does not contain
modifications to ForeverStack which would allow it to rely on a
ForeverStackStore to store nodes, but a future commit should address
this.

gcc/rust/ChangeLog:

* Make-lang.in: Handle rust-forever-stack.cc.
* resolve/rust-forever-stack.h
(class ForeverStackStore): Add.
* resolve/rust-forever-stack.cc: New file, based on
rust-forever-stack.hxx.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
10 months agogcc/rust/ChangeLog:
Om Swaroop Nayak [Wed, 1 Jan 2025 17:02:02 +0000 (09:02 -0800)] 
gcc/rust/ChangeLog:

* ast/rust-collect-lang-items.cc (get_lang_item_attr): "removed checker fn"
* util/rust-attributes.cc (Attributes::is_lang_item): "added fn"
* util/rust-attributes.h: "added fn"

Signed-off-by: Om Swaroop Nayak <96killerat96@gmail.com>
10 months agogccrs: improve mutability checks
Philip Herron [Mon, 16 Dec 2024 14:51:17 +0000 (14:51 +0000)] 
gccrs: improve mutability checks

This ensures that we handle var decls readonly checks much better

Addresses: Rust-GCC#807 Rust-GCC#3287

gcc/rust/ChangeLog:

* checks/errors/rust-readonly-check.cc (check_decl): improve mut check
(emit_error): helper
(check_modify_expr): likewise
(readonly_walk_fn): reuse helper
(ReadonlyCheck::Lint): cleanup context each run

gcc/testsuite/ChangeLog:

* rust/execute/torture/builtin_macro_include_bytes.rs: needs mut
* rust/compile/mutability_checks1.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
10 months agoVisit the trait paths of trait implementations
Owen Avery [Sat, 28 Dec 2024 20:58:41 +0000 (15:58 -0500)] 
Visit the trait paths of trait implementations

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): When visiting a TraitImpl, visit its
trait path.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
10 months agogccrs: add two more tests to test try-catch (unwind) code generation
liushuyu [Mon, 2 Dec 2024 21:52:35 +0000 (14:52 -0700)] 
gccrs: add two more tests to test try-catch (unwind) code generation

gcc/testsuite/ChangeLog:
* rust/compile/try-catch-unwind-old.rs: add a test to test the older
try intrinsics from plain old Rust to v1.78.0
* rust/compile/try-catch-unwind-new.rs: add a test to test the newer
catch_unwind instrinsics since Rust v1.78.0

10 months agorust/intrinsic: add new "catch_unwind" variant of API
liushuyu [Mon, 2 Dec 2024 21:24:04 +0000 (14:24 -0700)] 
rust/intrinsic: add new "catch_unwind" variant of API

gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc: add the new `catch_unwind` variant
of the `try` intrinsic: this variant can be seen on Rust 1.78+
and returns `()` instead of `i32`.

10 months agorust/intrinsic: add try intrinsic and panic strategy options
liushuyu [Sat, 9 Sep 2023 20:19:06 +0000 (14:19 -0600)] 
rust/intrinsic: add try intrinsic and panic strategy options

gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc: add `try` intrinsic handler.
* lang.opt: add `-frust-panic` option.
* rust-lang.cc: enable exception handler code generation.
* rust-session-manager.cc: add getter and setter for panic
strategy option.
* rust-session-manager.h: Likewise.

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
10 months agogccrs: match arms are a LUB
Philip Herron [Thu, 9 Jan 2025 16:47:47 +0000 (16:47 +0000)] 
gccrs: match arms are a LUB

Unify rules are not the same as coercion rules. The coercion of ! is
allowed to any type but not for a unify site which is different.

Match arms are another least upper bound coercion.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): implement coercion
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): this is an LUB
* typecheck/rust-unify.cc (UnifyRules::go): remove unify ! coercion

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
10 months agoAllow float type to be casted as integer type
Nobel [Sat, 21 Dec 2024 18:11:39 +0000 (23:56 +0545)] 
Allow float type to be casted as integer type

gccrs now should be able to cast float types as numeric.

gcc/rust/ChangeLog:

* typecheck/rust-casts.cc (TypeCastRules::cast_rules): Add rule.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Nobel Singh <nobel2073@gmail.com>
10 months agogccrs: cleanup our enum type layout to be closer to rustc
Philip Herron [Tue, 7 Jan 2025 18:15:37 +0000 (18:15 +0000)] 
gccrs: cleanup our enum type layout to be closer to rustc

This changes our enum type layout so for example:

  enum Foo {
      A,
      B,
      C(char),
      D { x: i32, y: i32 },
  }

Used to get layed out like this in gccrs:

  union {
    struct A { int RUST$ENUM$DISR; };
    struct B { int RUST$ENUM$DISR; };
    struct C { int RUST$ENUM$DISR; char __0; };
    struct D { int RUST$ENUM$DISR; i64 x; i64 y; };
  }

This has some issues notably with the constexpr because this is just a
giant union it means its not simple to constify what enum variant we are
looking at because the discriminant is a mess.

This now gets layed out as:

  struct {
     int RUST$ENUM$DISR;
     union {
         struct A { };
         struct B { };
         struct C { char __0; };
         struct D { i64 x; i64 y; };
     } payload;
  }

This layout is much cleaner and allows for our constexpr to work properly.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): new layout
* backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): likewise
(CompilePatternBindings::visit): likewise
* backend/rust-compile-resolve-path.cc: likewise
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): implement new layout
* rust-gcc.cc (constructor_expression): get rid of useless assert

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
10 months agonr2.0: Resolve Self inside impl blocks
Owen Avery [Tue, 7 Jan 2025 19:03:13 +0000 (14:03 -0500)] 
nr2.0: Resolve Self inside impl blocks

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert a definition for Self when visiting
InherentImpl and TraitImpl instances.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Add visitors for InherentImpl and TraitImpl.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove entries.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
10 months agogccrs: fix ICE with hir dump on closure
Philip Herron [Tue, 7 Jan 2025 18:43:32 +0000 (18:43 +0000)] 
gccrs: fix ICE with hir dump on closure

Return type and parameter types are optional on closures.

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): add null guard

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
10 months agogccrs: add support for lang_item eq and PartialEq trait
Philip Herron [Thu, 19 Dec 2024 16:43:49 +0000 (16:43 +0000)] 
gccrs: add support for lang_item eq and PartialEq trait

The Eq and Partial Ord are very similar to the operator overloads
we support for add/sub/etc... but they differ in that usually the
function call name matches the name of the lang item. This time
we need to have support to send in a new path for the method call
on the lang item we want instead of just the name of the lang item.

NOTE: this test case doesnt work correctly yet we need to support
the derive of partial eq on enums to generate the correct comparison
code for that.

Fixes Rust-GCC#3302

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): handle partial_eq possible call
* backend/rust-compile-expr.h: handle case where lang item calls differ from name
* hir/tree/rust-hir-expr.cc (OperatorExprMeta::OperatorExprMeta): new helper
* hir/tree/rust-hir-expr.h: likewise
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): handle partial_eq
(TypeCheckExpr::resolve_operator_overload): likewise
* typecheck/rust-hir-type-check-expr.h: likewise
* util/rust-lang-item.cc (LangItem::ComparisonToLangItem): map comparison to lang item
(LangItem::ComparisonToSegment): likewise
* util/rust-lang-item.h: new lang items PartialOrd and Eq
* util/rust-operators.h (enum class): likewise

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 cant handle this
* rust/compile/cmp1.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>