]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
4 months agogccrs: Improve Rib::Definition shadowing
Owen Avery [Fri, 4 Oct 2024 21:33:42 +0000 (17:33 -0400)] 
gccrs: Improve Rib::Definition shadowing

gcc/rust/ChangeLog:

* resolve/rust-finalize-imports-2.0.cc
(GlobbingVisitor::visit): Replace calls to insert_shadowable with
insert_globbed.
* resolve/rust-forever-stack.h
(ForeverStack::insert_globbed): Add.
* resolve/rust-forever-stack.hxx
(ForeverStack::insert_globbed): Add.
(ForeverStack::dfs): Handle modifications to Rib::Definition
fields.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Make IdentifierPattern-based declarations
shadowable.
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::insert_globbed): Add.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::insert_globbed): Add.
* resolve/rust-rib.cc
(Rib::Definition::Definition): Use Rib::Definition::Mode to
indicate shadowing mode instead of boolean, handle modifications
to Rib::Definition fields.
(Rib::Definition::is_ambiguous): Handle modifications to
Rib::Definition fields.
(Rib::Definition::to_string): Likewise.
(Rib::Definition::Shadowable): Handle changed constructor
signature.
(Rib::Definition::NonShadowable): Likewise.
(Rib::Definition::Globbed): Add.
(Rib::insert): Handle changes to Rib::Definition fields.
* resolve/rust-rib.h
(Rib::Definition::Globbed): Add.
(Rib::Definition::ids): Remove.
(Rib::Definition::ids_shadowable): Add.
(Rib::Definition::ids_non_shadowable): Add.
(Rib::Definition::ids_globbed): Add.
(Rib::Definition::get_node_id): Handle modifications to
Rib::Definition fields.
(Rib::Definition::Mode): Add.
(Rib::Definition::Definition): Use Rib::Definition::Mode to
indicate shadowing mode instead of boolean.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove shadow1.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Fix ICE when typechecking non-trait item when we expect one
Philip Herron [Wed, 2 Oct 2024 14:47:33 +0000 (15:47 +0100)] 
gccrs: Fix ICE when typechecking non-trait item when we expect one

We just had an assertion here for this case where we expect a trait.
This changes the assertion into error handling producing the correct
error code with fixit suggestion like rustc.

Fixes #2499

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait):
use error handling instead of assertion
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): reuse trait reference
* typecheck/rust-hir-type-check-item.h: update prototype

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Add test case to show ICE is fixed
Philip Herron [Wed, 2 Oct 2024 13:23:26 +0000 (14:23 +0100)] 
gccrs: Add test case to show ICE is fixed

This was resolved in: 18422c9c386 which was missing the name
resolution step for unit-types.

Fixes #2203

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude:
* rust/compile/issue-2203.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: add test case to show impl block on ! works
Philip Herron [Thu, 26 Sep 2024 14:25:21 +0000 (15:25 +0100)] 
gccrs: add test case to show impl block on ! works

The resolution with ! was fixed in: 09cfe530f9c this adds a
test case to show the other issue is also fixed.

Fixes #2951

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: nr2 is crashing here
* rust/compile/issue-2951.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agorust: fix ICE during name resolution for impls on unit-types
Philip Herron [Fri, 20 Sep 2024 16:38:14 +0000 (17:38 +0100)] 
rust: fix ICE during name resolution for impls on unit-types

The canonical paths need to support unit-types which are technically a
TupleType with no fields. This handles this case and adds an unreachable.

Fixes #3036

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc (ResolveTypeToCanonicalPath::visit): add unit-type catch
* resolve/rust-ast-resolve-type.h: likewise

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agorust: Add support for Clone and Copy derive on generic types
Philip Herron [Thu, 19 Sep 2024 15:45:54 +0000 (16:45 +0100)] 
rust: Add support for Clone and Copy derive on generic types

When we generate derivations for Copy and Clone we need to make sure
the associated impl block sets up the generic parameters and arguments
correctly. This patch introduces the framework to copy chunks of the AST
because we need to make sure these new AST nodes have their own associated
id, calling clone on the nodes will just confuse name-resolution and
subsequent mappings.

Fixes #3139

gcc/rust/ChangeLog:

* Make-lang.in: new objects
* ast/rust-ast-builder.cc (Builder::generic_type_path_segment): new helper
(Builder::single_generic_type_path): likewise
(Builder::new_type): likewise
(Builder::new_lifetime_param): likewise
(Builder::new_type_param): likewise
(Builder::new_lifetime): likewise
(Builder::new_generic_args): likewise
* ast/rust-ast-builder.h: new helper decls
* ast/rust-ast.h: new const getters
* ast/rust-path.h: likewise
* ast/rust-type.h: likewise
* expand/rust-derive-clone.cc (DeriveClone::clone_impl): take the types generics
(DeriveClone::visit_tuple): likewise
(DeriveClone::visit_struct): likewise
(DeriveClone::visit_union): likewise
* expand/rust-derive-clone.h: update header
* expand/rust-derive-copy.cc (DeriveCopy::copy_impl): similarly take type generics
(DeriveCopy::visit_struct): likewise
(DeriveCopy::visit_tuple): likewise
(DeriveCopy::visit_enum): likewise
(DeriveCopy::visit_union): likewise
* expand/rust-derive-copy.h: likewse
* ast/rust-ast-builder-type.cc: New file.
* ast/rust-ast-builder-type.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/issue-3139-1.rs: New test.
* rust/compile/issue-3139-2.rs: New test.
* rust/compile/issue-3139-3.rs: New test.
* rust/compile/nr2/exclude: these all break nr2

4 months agogccrs: Remove some passing test from nr2 passing list
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 21:37:35 +0000 (23:37 +0200)] 
gccrs: Remove some passing test from nr2 passing list

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove cast_generics.rs, issue-1131.rs,
issue-1383.rs and unsafe10.rs

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Postpone break on error after name resolution
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 21:17:59 +0000 (23:17 +0200)] 
gccrs: Postpone break on error after name resolution

We need the top level to run at least once before breaking because it
will be required by the other name resolution steps.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::expansion): Break on error after
top level name resolution.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Resolve TypeParam with name resolution 2.0
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 21:16:21 +0000 (23:16 +0200)] 
gccrs: Resolve TypeParam with name resolution 2.0

Resolve TypeParam unless it is Self.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Resolve
TypeParam.
* resolve/rust-toplevel-name-resolver-2.0.h: Add visit function
prototype.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add box definition to avoid error
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 20:59:48 +0000 (22:59 +0200)] 
gccrs: Add box definition to avoid error

Box definition is part of the standard library and cannot be found during
name resolution. This simple definition prevent any error from being
emitted.

gcc/testsuite/ChangeLog:

* rust/compile/box_syntax_feature_gate.rs: Add box land item
definition.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: This test requires the standard library
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 20:51:17 +0000 (22:51 +0200)] 
gccrs: This test requires the standard library

It requires the standard library and Copy to work correctly which we
cannot provide. Stopping the compiler before the name resolution allow us
to prevent an error whilst resolving Copy and keep the test's goal.

gcc/testsuite/ChangeLog:

* rust/compile/functions_without_body.rs: Add compile step argument.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Make node id getter const.
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 20:46:16 +0000 (22:46 +0200)] 
gccrs: Make node id getter const.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Node id getter could be const.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Change resolved type segment
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 20:43:18 +0000 (22:43 +0200)] 
gccrs: Change resolved type segment

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.h: Add visit function prototype.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change resolved
type segment.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Update exclude list with working tests
Pierre-Emmanuel Patry [Tue, 17 Sep 2024 13:25:41 +0000 (15:25 +0200)] 
gccrs: Update exclude list with working tests

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove working tests from nr2 exclude list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Do not assert insertion result
Pierre-Emmanuel Patry [Tue, 17 Sep 2024 14:15:40 +0000 (16:15 +0200)] 
gccrs: Do not assert insertion result

We might have some duplicated name in some pattern and we should
therefore not assert the non duplication of identifiers.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
assertion and explicitely tells why we ignore the insertion result.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Move bir builder function implementation
Pierre-Emmanuel Patry [Fri, 6 Sep 2024 10:16:22 +0000 (12:16 +0200)] 
gccrs: Move bir builder function implementation

Move function implementation to their own file.

gcc/rust/ChangeLog:

* Make-lang.in: Add new rust-bir-builder-pattern file.
* checks/errors/borrowck/rust-bir-builder-pattern.h: Remove
implementation.
* checks/errors/borrowck/rust-bir-builder-pattern.cc: New file.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Move failing test to xfail
Pierre-Emmanuel Patry [Wed, 4 Sep 2024 15:13:04 +0000 (17:13 +0200)] 
gccrs: Move failing test to xfail

We want to begin experimenting with this new name resolution 2.0
algorithm as soon as possible. This test highlight a problem where the
compiler should emit an error and should be fixed soon.

gcc/testsuite/ChangeLog:

* rust/compile/name_resolution21.rs: Move to...
* rust/compile/xfail/name_resolution21.rs: ...here.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Make AST default visitor visit functions public
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 14:13:30 +0000 (16:13 +0200)] 
gccrs: Make AST default visitor visit functions public

Make those functions public so they can be used within a lambda on GCC
4.8.

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.h: Make visit functions public.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Add default resolver parent functions by default
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 13:39:59 +0000 (15:39 +0200)] 
gccrs: Add default resolver parent functions by default

gcc/rust/ChangeLog:

* resolve/rust-finalize-imports-2.0.h: Add parent member functions
from default resolver.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Change lambda content with default visitor call
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 11:54:48 +0000 (13:54 +0200)] 
gccrs: Change lambda content with default visitor call

We can reduce code duplication by using the default visitor functions
from within the scoped lambda function.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Use
default visitor instead.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Remove regular visit code
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 11:37:51 +0000 (13:37 +0200)] 
gccrs: Remove regular visit code

Regular visit code can be replaced with default visit functions.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
default visit code and replace it with call to default visitor.
* resolve/rust-default-resolver.h: Remove removed function's
prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Remove empty visit functions
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 11:23:52 +0000 (13:23 +0200)] 
gccrs: Remove empty visit functions

We can let the default visitor visit those nodes anyway so we're sure
all nodes can be reached.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove
empty visit function implementations.
* resolve/rust-default-resolver.h: Remove corresponding prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Mark virtual function override in default resolver
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 11:01:07 +0000 (13:01 +0200)] 
gccrs: Mark virtual function override in default resolver

Those function prototype were not marked as override and throwing
warning.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.h: Make most visit function override.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Loop on expansion if a new export has been defined
Pierre-Emmanuel Patry [Wed, 21 Aug 2024 15:14:46 +0000 (17:14 +0200)] 
gccrs: Loop on expansion if a new export has been defined

When a use statement requires a reexported item it cannot find it in
the same pass, an additional pass shall be performed. This means we need
to detect whether a new item has been reexported and resolve until the
end.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::Early): Add dirty
flag initialization.
(Early::go): Set dirty flag using top level resolver.
* resolve/rust-early-name-resolver-2.0.h: Add dirty flag.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::TopLevel):
Initialize dirty flag.
(TopLevel::insert_or_error_out): Set dirty flag on successful
namespace modification.
* resolve/rust-toplevel-name-resolver-2.0.h: Add dirty flag.
* rust-session-manager.cc (Session::expansion): Modify fixed point
condition to include name resolution modifications.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Fix missing error on duplicated nodes
Pierre-Emmanuel Patry [Wed, 21 Aug 2024 15:01:29 +0000 (17:01 +0200)] 
gccrs: Fix missing error on duplicated nodes

When we tried to insert a shadowable node and another shadowable node has
been inserted before, we didn't emit any error if the node has already
been inserted previously and failed silently.

gcc/rust/ChangeLog:

* resolve/rust-rib.cc (Rib::insert): Emit an error when trying to
insert an already inserted node.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: nr2.0: Cleanup import mappings and factor into a class.
Arthur Cohen [Wed, 10 Apr 2024 15:38:19 +0000 (17:38 +0200)] 
gccrs: nr2.0: Cleanup import mappings and factor into a class.

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.h: New class for imports.
* resolve/rust-finalize-imports-2.0.cc (finalize_simple_import): Use
the new API.
(finalize_glob_import): Likewise.
(finalize_rebind_import): Likewise.
(FinalizeImports::FinalizeImports): Likewise.
(FinalizeImports::visit): Likewise.
* resolve/rust-finalize-imports-2.0.h: Likewise.
* resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Likewise.
(Early::resolve_simple_import): Likewise.
(Early::resolve_rebind_import): Likewise.

4 months agogccrs: Insert imports in all namespaces they were resolved in
Arthur Cohen [Mon, 8 Apr 2024 16:44:15 +0000 (18:44 +0200)] 
gccrs: Insert imports in all namespaces they were resolved in

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::resolve_simple_import):
Insert import in all namespaces where they were resolved.
(Early::resolve_rebind_import): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Improve APIs, make them
accept multiple resolutions.
* resolve/rust-finalize-imports-2.0.cc: Handle multiple resolutions.
* resolve/rust-name-resolution-context.h (resolve_path): Remove function.

4 months agogccrs: early: Do not emit errors for unresolved imports, store them instead
Arthur Cohen [Sat, 6 Apr 2024 21:23:39 +0000 (23:23 +0200)] 
gccrs: early: Do not emit errors for unresolved imports, store them instead

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes):
Store errors for later.

4 months agogccrs: imports: Make FinalizeImports a resolver visitor as well
Arthur Cohen [Sat, 6 Apr 2024 21:02:51 +0000 (23:02 +0200)] 
gccrs: imports: Make FinalizeImports a resolver visitor as well

gcc/rust/ChangeLog:

* resolve/rust-finalize-imports-2.0.cc (FinalizeImports::go): Turn
static method into method.
(FinalizeImports::visit): New.
* resolve/rust-finalize-imports-2.0.h (class FinalizeImports): Make
FinalizeImports a visitor.
* resolve/rust-early-name-resolver-2.0.cc (Early::go): Use new FinalizeImports API.
(Early::resolve_glob_import): Use new API.
(Early::resolve_simple_import): Likewise.
(Early::resolve_rebind_import): Likewise.
(Early::build_import_mapping): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h: Likewise.

4 months agogccrs: imports: Start storing Ribs in ImportKind
Arthur Cohen [Fri, 5 Apr 2024 22:32:57 +0000 (00:32 +0200)] 
gccrs: imports: Start storing Ribs in ImportKind

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add debug call.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Store
imports using the new classes.
* resolve/rust-toplevel-name-resolver-2.0.h: Use new classes.

4 months agogccrs: imports: Create ImportData class and use it in import_mappings
Arthur Cohen [Fri, 5 Apr 2024 22:00:49 +0000 (00:00 +0200)] 
gccrs: imports: Create ImportData class and use it in import_mappings

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import):
Use ImportData class.
(Early::resolve_simple_import): Likewise.
(Early::resolve_rebind_import): Likewise.
(Early::build_import_mapping): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Likewise.
* resolve/rust-finalize-imports-2.0.cc (finalize_simple_import): Likewise.
(finalize_glob_import): Likewise.
(finalize_rebind_import): Likewise.
(FinalizeImports::go): Likewise.
* resolve/rust-finalize-imports-2.0.h: Likewise.
* resolve/rust-name-resolution-context.h: Likewise.
* resolve/rust-rib.h: Define ImportData class.

4 months agogccrs: imports: Add FinalizeImports class
Arthur Cohen [Thu, 4 Apr 2024 15:07:54 +0000 (17:07 +0200)] 
gccrs: imports: Add FinalizeImports class

gcc/rust/ChangeLog:

* Make-lang.in: Add new object file.
* ast/rust-item.h: Constify method.
* resolve/rust-early-name-resolver-2.0.cc (Early::go): Call into
the imports finalizer.
(Early::resolve_glob_import): Remove old resolution.
(Early::resolve_rebind_import): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::go):
New function.
(GlobbingVisitor::visit): Likewise.
(TopLevel::visit): Do not call into handle_use_* functions anymore.
* resolve/rust-toplevel-name-resolver-2.0.h (class GlobbingVisitor):
New.
* resolve/rust-finalize-imports-2.0.cc: New file.
* resolve/rust-finalize-imports-2.0.h: New file.

4 months agogccrs: early: Resolve imports and create import mappings
Arthur Cohen [Thu, 4 Apr 2024 14:25:30 +0000 (16:25 +0200)] 
gccrs: early: Resolve imports and create import mappings

gcc/rust/ChangeLog:

* resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): New function.
(Early::resolve_simple_import): Likewise.
(Early::resolve_rebind_import): Likewise.
(Early::build_import_mapping): Likewise.
* resolve/rust-early-name-resolver-2.0.h: Add declarations and list of imports to
resolve.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_glob): Remove function,
which is now being handled by the Early name resolver.
(TopLevel::handle_use_dec): Likewise.
(TopLevel::handle_rebind): Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h: Likewise, and add functions for creating
import list and fetching it.

4 months agogccrs: toplevel: Build list of imports for Early to resolve
Arthur Cohen [Thu, 4 Apr 2024 13:42:29 +0000 (15:42 +0200)] 
gccrs: toplevel: Build list of imports for Early to resolve

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc: Comment out handle_use
call and error emission.
* resolve/rust-toplevel-name-resolver-2.0.h: Create ImportKind class.

4 months agogccrs: toplevel: Add note for resolving use declarations
Arthur Cohen [Wed, 3 Apr 2024 15:41:47 +0000 (17:41 +0200)] 
gccrs: toplevel: Add note for resolving use declarations

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_dec):
Add notes on the problem.
* resolve/rust-toplevel-name-resolver-2.0.h: Likewise.

4 months agogccrs: nr2.0: default-visitor: Conditionally visit type in self parameters.
Arthur Cohen [Wed, 27 Mar 2024 16:20:15 +0000 (17:20 +0100)] 
gccrs: nr2.0: default-visitor: Conditionally visit type in self parameters.

This could trigger an assertions as `get_type` on `SelfParam` asserts that
the self param does have a given type, which is not always the case.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc (DefaultResolver::visit): Do not
visit self's type if it does not have one.

4 months agogccrs: rust fix ICE when hir lowering qualified path expressions without an as
Philip Herron [Fri, 20 Sep 2024 16:13:38 +0000 (17:13 +0100)] 
gccrs: rust fix ICE when hir lowering qualified path expressions without an as

Qualified path expressions usually are <X as Y>::... but the as is optional
this adds the extra checking in hir lowering to not hit that nullptr.

Fixes #3082

gcc/rust/ChangeLog:

* hir/rust-ast-lower-type.cc (ASTLowerQualifiedPathInType::visit):
check for valid as segment

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agorust: fix ICE when compiling impl block for !
Philip Herron [Fri, 20 Sep 2024 17:45:12 +0000 (18:45 +0100)] 
rust: fix ICE when compiling impl block for !

We need to resolve the never type which is its own special AST node so it
doesnt magically get handled like the regular builtin type paths such as
i32.

Fixes #3035

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc (ResolveType::visit):
handle never type
(ResolveTypeToCanonicalPath::visit): likewise
* resolve/rust-ast-resolve-type.h: missing never type
* resolve/rust-name-resolver.cc (Resolver::generate_builtins):
track never type node_id
(Resolver::setup_builtin): likewise
* resolve/rust-name-resolver.h: new never type getter

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Remove some overloaded methods from DefaultResolver.
Owen Avery [Mon, 23 Sep 2024 21:44:19 +0000 (17:44 -0400)] 
gccrs: Remove some overloaded methods from DefaultResolver.

gcc/rust/ChangeLog:

* resolve/rust-default-resolver.cc
(DefaultResolver::visit): Remove some empty overloads which
DefaultASTVisitor::visit should be able to handle.
* resolve/rust-default-resolver.h
(DefaultResolver::visit): Likewise.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Add extra assertions to tl::optional
Owen Avery [Wed, 18 Sep 2024 20:05:31 +0000 (16:05 -0400)] 
gccrs: Add extra assertions to tl::optional

gcc/rust/ChangeLog:

* util/optional.h
(optional): Add assertions to dereference operator overloads
when C++14 is available.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: adjust hir dump of BlockExpr
Marc Poulhiès [Sat, 21 Sep 2024 08:44:12 +0000 (10:44 +0200)] 
gccrs: adjust hir dump of BlockExpr

Add tail_reachable and label fields to the dump.

gcc/rust/ChangeLog:

* hir/rust-hir-dump.cc (Dump::visit): Add missing fields.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
4 months agorust: negative polarity removes restrictions on validation of impl blocks
Philip Herron [Fri, 20 Sep 2024 16:49:36 +0000 (17:49 +0100)] 
rust: negative polarity removes restrictions on validation of impl blocks

Negative polarity means we can just ignore if any trait items are not
implemented.

Fxies #3030

gcc/rust/ChangeLog:

* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): the polarity was reversed
* typecheck/rust-hir-type-check-item.cc: check the polarity

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
4 months agogccrs: Fix ICE on error propagation with generic
benjamin.thos [Thu, 12 Sep 2024 17:10:49 +0000 (17:10 +0000)] 
gccrs: Fix ICE on error propagation with generic

add a resolve expr visitor on error propagation to avoid internal
compiler error when used with generics

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): Add
implementation of error propagation visitor
* resolve/rust-ast-resolve-expr.h: Add prototype of error
propagation

Signed-off-by: benjamin.thos <benjamin.thos@epita.fr>
4 months agogccrs: Check if the type has been correctly resolved
Pierre-Emmanuel Patry [Thu, 19 Sep 2024 12:38:48 +0000 (14:38 +0200)] 
gccrs: Check if the type has been correctly resolved

We did not check the optional was valid, this lead to rogue dereference
and undefined behaviors.

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add optional
check.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
4 months agogccrs: Create new test system for name resolution 2.0
Owen Avery [Mon, 16 Sep 2024 22:27:19 +0000 (18:27 -0400)] 
gccrs: Create new test system for name resolution 2.0

This runs the standard compile/**.rs tests
with name resolution 2.0 enabled. The exclude file
can be used to exclude tests which are not yet working
with name resolution 2.0.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/compile.exp: New test.
* rust/compile/nr2/exclude: New.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: [gccrs#3141] Remove double negation by returning CompileExpr::Compile early
JoanVC [Sun, 15 Sep 2024 13:59:34 +0000 (15:59 +0200)] 
gccrs: [gccrs#3141] Remove double negation by returning CompileExpr::Compile early

Fixes gccrs#3141.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc

Signed-off-by: Joan Vilardaga <github-91yu@joanvc.cat>
4 months agogccrs: [gccrs#3141] Fix incorrect handling of overflow in numeric types
JoanVC [Tue, 10 Sep 2024 19:52:50 +0000 (21:52 +0200)] 
gccrs: [gccrs#3141] Fix incorrect handling of overflow in numeric types

Fixes gccrs#3141.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc: Fix range checking for both integers and floats.
* hir/tree/rust-hir-expr.h: Add "negative_number" boolean to LiteralExpr class.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Joan Vilardaga <github-91yu@joanvc.cat>
4 months agogccrs: session-manager: Fix typos in -frust-incomplete message
Arthur Cohen [Thu, 5 Sep 2024 14:17:57 +0000 (16:17 +0200)] 
gccrs: session-manager: Fix typos in -frust-incomplete message

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Use less repetition,
fix a typo in `reports`, fix word order.

4 months agogccrs: Emit error on auto-traits
benjamin.thos [Wed, 11 Sep 2024 14:31:20 +0000 (14:31 +0000)] 
gccrs: Emit error on auto-traits

Throw an error when auto-traits used without feature attribute.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Emit error
on trait when auto field member true.
* checks/errors/rust-feature-gate.h: add prototype of trait visitor.
* checks/errors/rust-feature.cc (Feature::create): add
optin_builtin_traits in match of feature.

gcc/testsuite/ChangeLog:

* rust/compile/auto_trait_super_trait.rs: Add feature attribute.
* rust/compile/generic_auto_trait.rs: likewise.
* rust/compile/auto_trait.rs: add test for error without
feature attribute

Signed-off-by: benjamin.thos <benjamin.thos@epita.fr>
4 months agogccrs: Implement initial pattern analysis pass.
Raiki Tamura [Wed, 7 Aug 2024 17:25:05 +0000 (02:25 +0900)] 
gccrs: Implement initial pattern analysis pass.

gcc/rust/ChangeLog:

* Make-lang.in: Add rust-hir-pattern-analysis.o.
* rust-session-manager.cc (Session::compile_crate):
Add pattern analysis pass.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Do typecheck for subpatterns.
* checks/errors/rust-hir-pattern-analysis.cc: New file.
* checks/errors/rust-hir-pattern-analysis.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/exhaustiveness1.rs: New test.
* rust/compile/exhaustiveness2.rs: New test.
* rust/compile/exhaustiveness3.rs: New test.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
4 months agogccrs: Dynamic dispatch with supertraits
Liam Naddell [Thu, 8 Aug 2024 09:31:58 +0000 (05:31 -0400)] 
gccrs: Dynamic dispatch with supertraits

gcc/rust/ChangeLog:

* backend/rust-compile.cc:
Modify compute_address_for_trait_item to support supertraits
* typecheck/rust-tyty.cc:
Remove auto

gcc/testsuite/ChangeLog:

* rust/compile/trait13.rs:
Add test for supertraits of supertraits
* rust/compile/trait14.rs:
Diamond problem with supertraits test
* rust/execute/torture/trait14.rs:
Add test for dynamic dispatch with supertraits
* rust/execute/torture/trait15.rs:
Add test for dynamic dispatch with generics
* rust/execute/torture/trait16.rs:
Add test for dynamic dispatch with lifetime params 1
* rust/execute/torture/trait17.rs:
Add test for dynamic dispatch with lifetime params 2
* rust/execute/torture/trait18.rs:
Add test for default implementations with dynamic dispatch and
supertraits

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
4 months agogccrs: Used `IndexVec` for place_map
Kushal Pal [Wed, 28 Aug 2024 06:39:28 +0000 (06:39 +0000)] 
gccrs: Used `IndexVec` for place_map

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use strong
type instead of size_t.
(Dump::visit_place): Likewise.
(Dump::visit_scope): Likewise.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Use
IndeVec for place_map.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Use `IndexVec` for bb_fold_map
Kushal Pal [Wed, 28 Aug 2024 06:16:11 +0000 (06:16 +0000)] 
gccrs: Use `IndexVec` for bb_fold_map

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Used `IndexVec` for bb_fold_map.
(Dump::go): Use strong type as index instead of value as now we
are using `IndexVec`.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-dump.h (class Dump): Use
`IndexVec` for bb_fold_map.
* checks/errors/borrowck/rust-bir-place.h: Add constructor for
`IndexVec` that can reserve size.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Used `IndexVec` for Places
Kushal Pal [Tue, 20 Aug 2024 06:09:51 +0000 (06:09 +0000)] 
gccrs: Used `IndexVec` for Places

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h: Use strong types as
index.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Used `IndexVec` for BasicBlocks
Kushal Pal [Mon, 19 Aug 2024 10:06:49 +0000 (10:06 +0000)] 
gccrs: Used `IndexVec` for BasicBlocks

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::visit): Use strong type as index and
remove access to numeric value.
* checks/errors/borrowck/rust-bir-builder-internal.h
(struct BuilderContext): Likewise.
* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Likewise.
(Dump::go): Likewise.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h
(class FactCollector): Likewise.
(points): Likewise.
* checks/errors/borrowck/rust-bir.h (struct BasicBlockId): Used
IndexVec for BasicBlocks.
(struct Function): Likewise.
* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::get_statement): Change the extracted
index to strong type.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Used `IndexVec` for Loans
Kushal Pal [Mon, 19 Aug 2024 09:48:49 +0000 (09:48 +0000)] 
gccrs: Used `IndexVec` for Loans

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h: Used `IndexVec` with
ScopeId as index.
* checks/errors/borrowck/rust-borrow-checker-diagnostics.cc
(BorrowCheckerDiagnostics::get_loan): Convert Polonius::Loan to
BIR::Loan, so we can use it as index.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Used `IndexVec` for Scopes
Kushal Pal [Mon, 19 Aug 2024 09:38:52 +0000 (09:38 +0000)] 
gccrs: Used `IndexVec` for Scopes

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h:
Used `IndexVec` with ScopeId as index.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Introduce `IndexVec`
Kushal Pal [Mon, 19 Aug 2024 09:28:25 +0000 (09:28 +0000)] 
gccrs: Introduce `IndexVec`

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-place.h (struct Loan):
Introduce new class `IndexVec` inspired from IndexVec of rust.
It acts as a wrapper around `std::vector` and lets user specify
a strong type to use as index.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Strong type BasicBlockId
Kushal Pal [Wed, 7 Aug 2024 10:58:17 +0000 (10:58 +0000)] 
gccrs: Strong type BasicBlockId

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit):
Use value of BasicBlockId as index.
* checks/errors/borrowck/rust-bir-builder-internal.h (struct BuilderContext):
Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h:
Initialize with ENTRY_BASIC_BLOCK.
* checks/errors/borrowck/rust-bir-dump.cc (simplify_cfg):
Use value of BasicBlockId as index.
(Dump::go): Likewise.
(Dump::visit): Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (class FactCollector):
Initialize with ENTRY_BASIC_BLOCK.
(points): Use value of BasicBlockId as index.
* checks/errors/borrowck/rust-bir.h (struct BasicBlockId):
BasicBlockId is a struct now.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Strong type ScopeId
Kushal Pal [Wed, 7 Aug 2024 10:16:24 +0000 (10:16 +0000)] 
gccrs: Strong type ScopeId

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc
(ExprStmtBuilder::setup_loop): Use value of ScopeId.
(ExprStmtBuilder::visit): Use continue scope id instead of
continue basic block id.
* checks/errors/borrowck/rust-bir-builder-internal.h: Use value
of ScopeId.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Use
ROOT_VALUE instead of hardcoded 0.
(Dump::visit_scope): Use value of ScopeId.
* checks/errors/borrowck/rust-bir-place.h (struct ScopeId):
ScopeId is now a struct.
(std::numeric_limits::max): Set invalid ScopeId.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Strong type LoanId
Kushal Pal [Wed, 7 Aug 2024 08:44:03 +0000 (08:44 +0000)] 
gccrs: Strong type LoanId

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): Use new
API, i.e get_loan_id() instead of get_loan().
* checks/errors/borrowck/rust-bir-fact-collector.h (points): Use
value of LoanId in Polonius facts.
* checks/errors/borrowck/rust-bir-place.h (struct LoanId):
LoanId is a struct now.
* checks/errors/borrowck/rust-bir.h (class AbstractExpr): Use
new API, as we are getting a LoanId and not a loan itself.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Use FreeRegions inplace of `std::vector<FreeRegion>`
Kushal Pal [Thu, 8 Aug 2024 07:12:00 +0000 (07:12 +0000)] 
gccrs: Use FreeRegions inplace of `std::vector<FreeRegion>`

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-internal.h: Use
FreeRegions instead of making a temporary vector of FreeRegion.
* checks/errors/borrowck/rust-bir-builder.h: Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (class FactCollector):
Likewise.
(points): Likewise.
* checks/errors/borrowck/rust-bir-free-region.h: Remove obsolete
set_from() helpers, add push_back().
* checks/errors/borrowck/rust-bir-place.h: Use FreeRegions
instead of making a temporary vector of Origin.
* typecheck/rust-tyty-variance-analysis-private.h: Change type
of `regions`.
* typecheck/rust-tyty-variance-analysis.cc (CrateCtx::query_type_regions):
Use new type.
(GenericTyPerCrateCtx::query_generic_variance): Likewise.
(TyVisitorCtx::add_constraints_from_generic_args): Likewise.
(FieldVisitorCtx::add_constraints_from_region): Likewise.
(FieldVisitorCtx::add_constrints_from_param): Likewise.
* typecheck/rust-tyty-variance-analysis.h: Likewise.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Strong type FreeRegion
Kushal Pal [Wed, 7 Aug 2024 05:19:28 +0000 (05:19 +0000)] 
gccrs: Strong type FreeRegion

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-builder-internal.h: Use
STATIC_FREE_REGION, use value of FreeRegion for origin.
* checks/errors/borrowck/rust-bir-builder.h: Use free region
value.
* checks/errors/borrowck/rust-bir-dump.cc (Dump::visit_scope):
Likewise.
* checks/errors/borrowck/rust-bir-fact-collector.h (points):
Likewise.
* checks/errors/borrowck/rust-bir-free-region.h (struct FreeRegion):
Make FreeRegion a struct.
* checks/errors/borrowck/rust-bir-place.h: Use FreeRegion
instead of Origin in PlaceDB.
* typecheck/rust-tyty-variance-analysis.cc (FieldVisitorCtx::add_constraints_from_region):
Use value of FreeRegion for origin.
(FieldVisitorCtx::add_constrints_from_param): Likewise.
(Term::make_transform): Likewise.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Strong type PlaceId
Kushal Pal [Mon, 5 Aug 2024 10:50:55 +0000 (10:50 +0000)] 
gccrs: Strong type PlaceId

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-bir-dump.cc (renumber_places):
Use value of PlaceId as index.
(Dump::visit_place): Likewise.
(Dump::visit_scope): Likewise.
(Dump::go): Refill `place_map` with for loop instead of
using std::iota().
* checks/errors/borrowck/rust-bir-fact-collector.h (points): Use
value as index.
* checks/errors/borrowck/rust-bir-place.h (struct PlaceId):
PlaceId is now a class holding a uint32_t value. Overloaded
comparision operators for easier comparision.

Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
4 months agogccrs: Avoid accidental insertion into map
Owen Avery [Thu, 5 Sep 2024 23:44:55 +0000 (19:44 -0400)] 
gccrs: Avoid accidental insertion into map

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-pattern.cc
(PatternDeclaration::check_bindings_consistency): Check if
outer_bindings_map contains an entry before indexing.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Fix v0-mangle1.rs test when run with ASAN
Owen Avery [Wed, 4 Sep 2024 02:49:15 +0000 (22:49 -0400)] 
gccrs: Fix v0-mangle1.rs test when run with ASAN

gcc/rust/ChangeLog:

* util/rust-canonical-path.h
(CanonicalPath::CanonicalPath): Properly initialize crate_num
with copy constructor.

gcc/testsuite/ChangeLog:

* rust/compile/v0-mangle1.rs: Make v0-mangle test more crate_num
agnostic.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
4 months agogccrs: Provide new asm test case for amd64
badumbatish [Sun, 1 Sep 2024 06:37:19 +0000 (23:37 -0700)] 
gccrs: Provide new asm test case for amd64

gcc/testsuite/ChangeLog:

* rust/execute/torture/inline_asm_mov_x_5.rs: Move to...
* rust/execute/torture/inline_asm_mov_x_5_ARM.rs: ...here.
* rust/execute/torture/inline_asm_mov_x_5_x86_64.rs: New test.

4 months agogccrs: Rehaul, Apply code review from Arthur
badumbatish [Thu, 29 Aug 2024 17:07:19 +0000 (10:07 -0700)] 
gccrs: Rehaul, Apply code review from Arthur

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::visit):
Change API, public/private, comments, formatting from code
review
(CompileAsm::asm_build_expr): Likewise.
(CompileAsm::tree_codegen_asm): Likewise.
* backend/rust-compile-asm.h (class CompileAsm): Likewise.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise.
* expand/rust-macro-builtins-asm.cc (strip_double_quotes): Likewise.
(parse_options): Likewise.
(parse_asm_arg): Likewise.
(expand_inline_asm_strings): Likewise.
(parse_asm): Likewise.
* expand/rust-macro-builtins-asm.h (strip_double_quotes): Likewise.
(expand_inline_asm_strings): Likewise.
(expand_inline_asm_string): Likewise.
* hir/tree/rust-hir-expr.h: Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_typecheck.rs: Change comments

4 months agogccrs: Fix return type of asm mov 5 to i32:0, tortured
badumbatish [Wed, 28 Aug 2024 07:15:14 +0000 (00:15 -0700)] 
gccrs: Fix return type of asm mov 5 to i32:0, tortured

gcc/testsuite/ChangeLog:

* rust/execute/inline_asm_mov_x_5.rs: Move to...
* rust/execute/torture/inline_asm_mov_x_5.rs: ...here.

4 months agogccrs: Make inline mov compiles
badumbatish [Wed, 28 Aug 2024 01:15:26 +0000 (18:15 -0700)] 
gccrs: Make inline mov compiles

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Remove debug
* expand/rust-macro-builtins-asm.cc (expand_inline_asm_strings):
properly formatted via rust instead of c
(parse_asm): formatted comment
(parse_format_strings): formatted comment
* hir/tree/rust-hir-expr.h: fix is_simple_asm()

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_parse_operand.rs: Fix format asm
* rust/compile/inline_asm_parse_output_operand.rs:
Fix format asm
* rust/execute/torture/inline_asm_mov_x_5.rs: Move to...
* rust/execute/inline_asm_mov_x_5.rs: ...here.

4 months agogccrs: Use's array type when constring string tree
badumbatish [Thu, 8 Aug 2024 21:22:05 +0000 (14:22 -0700)] 
gccrs: Use's array type when constring string tree

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Use's array type when constring string tree
(CompileAsm::asm_construct_string_tree):
Use's array type when constring string tree

4 months agogccrs: Added noreturn checking for nevertype, new test
badumbatish [Fri, 2 Aug 2024 18:36:04 +0000 (11:36 -0700)] 
gccrs: Added noreturn checking for nevertype, new test

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Added noreturn checking for nevertype

gcc/testsuite/ChangeLog:

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

4 months agogccrs: Perform lowering hir output operand to tree
badumbatish [Thu, 1 Aug 2024 23:22:32 +0000 (16:22 -0700)] 
gccrs: Perform lowering hir output operand to tree

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Add debug comment
(CompileAsm::asm_construct_outputs):
Perform lowering hir output operand to tree

4 months agogccrs: Perform type check on InlineAsm's operand
badumbatish [Thu, 1 Aug 2024 23:18:38 +0000 (16:18 -0700)] 
gccrs: Perform type check on InlineAsm's operand

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Perform type check on InlineAsm's operand
(typecheck_inline_asm_operand): Likewise

4 months agogccrs: Lower the HIR to tree with CompileExpr
badumbatish [Tue, 30 Jul 2024 04:59:13 +0000 (21:59 -0700)] 
gccrs: Lower the HIR to tree with CompileExpr

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_construct_outputs):
Lower the HIR to tree with CompileExpr
* backend/rust-compile-asm.h: Remove static from method

4 months agogccrs: Move strip double quotes, add scaffold expand
badumbatish [Sat, 27 Jul 2024 03:26:01 +0000 (20:26 -0700)] 
gccrs: Move strip double quotes, add scaffold expand

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (strip_double_quotes):
Move strip double quotes to parse phase
(CompileAsm::asm_construct_string_tree): Likewise
* backend/rust-compile-asm.h (strip_double_quotes): Likewise
* expand/rust-macro-builtins-asm.cc (strip_double_quotes):
Likewise
(expand_inline_asm): Renamed to expand_inline_asm_strings
(expand_inline_asm_strings): Renamed from expand_inline_asm
(parse_asm): Move strip double quotes to parse phase
(parse_format_strings): Likewise
* expand/rust-macro-builtins-asm.h (strip_double_quotes):
Likewise
(expand_inline_asm_strings): Inline asm expansion fn
(expand_inline_asm_string): Inline asm expansion fn

4 months agogccrs: Start work on expand inline asm
badumbatish [Fri, 26 Jul 2024 06:07:00 +0000 (23:07 -0700)] 
gccrs: Start work on expand inline asm

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Remove warnings
(parse_reg_operand_out): Remove warnings
(expand_inline_asm): New function for eventual expansion
(parse_asm): Use expand_inline_asm

gcc/testsuite/ChangeLog:

* rust/execute/torture/inline_asm_mov_x_5.rs: New test.

4 months agogccrs: Added counting to check for asm_construct_outputs
badumbatish [Wed, 24 Jul 2024 05:17:12 +0000 (22:17 -0700)] 
gccrs: Added counting to check for asm_construct_outputs

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_construct_outputs):
Set up counting to check

4 months agogccrs: Added new test for prep of output {}
badumbatish [Sun, 21 Jul 2024 22:13:25 +0000 (15:13 -0700)] 
gccrs: Added new test for prep of output {}

gcc/testsuite/ChangeLog:

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

4 months agogccrs: Minor fix to asm codegen pr
badumbatish [Thu, 18 Jul 2024 14:34:43 +0000 (07:34 -0700)] 
gccrs: Minor fix to asm codegen pr

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_build_expr):
Use expr's is_simple_asm and is_inline_asm
(CompileAsm::asm_is_simple): removed
(CompileAsm::asm_is_inline): removed
* backend/rust-compile-asm.h: Add docs to ASM_TREE_ARRAY_LENGTH
* hir/tree/rust-hir-expr.h: Add is_simple_asm, is_inline_asm
and remove #include tree

4 months agogccrs: Refactor compile-asm for first round review
badumbatish [Mon, 8 Jul 2024 05:03:12 +0000 (22:03 -0700)] 
gccrs: Refactor compile-asm for first round review

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (strip_double_quotes):
Refactor compile-asm for first round review
(CompileAsm::asm_build_asm_stmt): Likewise.
(CompileAsm::asm_build_expr): Likewise.
(CompileAsm::asm_get_locus): Likewise.
(CompileAsm::asm_construct_string_tree): Likewise.
(CompileAsm::asm_construct_outputs): Likewise.
(CompileAsm::asm_construct_inputs): Likewise.
(CompileAsm::asm_construct_clobber_tree): Likewise.
(CompileAsm::asm_construct_label_tree): Likewise.
(CompileAsm::asm_is_simple): Likewise.
(CompileAsm::asm_is_inline): Likewise.
* backend/rust-compile-asm.h (strip_double_quotes): Likewise.
(class CompileAsm): Likewise.

4 months agogccrs: Successfully produce pseudo-nop
badumbatish [Sat, 6 Jul 2024 20:17:00 +0000 (13:17 -0700)] 
gccrs: Successfully produce pseudo-nop

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::add_stmt):
Deleted
(CompileAsm::CompileAsm):
Successfully produce pseudo-nop
(CompileAsm::visit): Likewise
(CompileAsm::asm_build_asm_stmt): Likewise
(CompileAsm::asm_construct_string_tree): Likewise
(CompileAsm::asm_is_inline): Likewise
* backend/rust-compile-asm.h (class CompileAsm): Likewise
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise

4 months agogccrs: Scaffolding code
badumbatish [Fri, 5 Jul 2024 17:03:56 +0000 (10:03 -0700)] 
gccrs: Scaffolding code

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::add_stmt):
Scaffolding code.
(CompileAsm::asm_build_asm_stmt): Likewise.
(CompileAsm::asm_build_expr): Likewise.
(CompileAsm::asm_construct_string_tree): Likewise.
* backend/rust-compile-asm.h: Likewise.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.

4 months agogccrs: Scaffolding new compile-asm files
badumbatish [Sun, 30 Jun 2024 23:48:30 +0000 (16:48 -0700)] 
gccrs: Scaffolding new compile-asm files

gcc/rust/ChangeLog:

* Make-lang.in:
Scaffolding new compile-asm files
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise
* hir/tree/rust-hir-expr.h: Likewise
* backend/rust-compile-asm.cc: New file. Likewise
* backend/rust-compile-asm.h: New file. Likewise

4 months agogccrs: Setting up interfaces for codegen
jjasmine [Mon, 24 Jun 2024 02:47:17 +0000 (19:47 -0700)] 
gccrs: Setting up interfaces for codegen

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit):
Setting up interfaces for codegen
* hir/tree/rust-hir-expr.h: Likewise.

4 months agogccrs: Local testing for build_string and debug()
jjasmine [Sun, 23 Jun 2024 17:39:12 +0000 (10:39 -0700)] 
gccrs: Local testing for build_string and debug()

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit):
Local testing for build_string and debug()

4 months agogccrs: Make sure CompileExpr::visit is reached
jjasmine [Sat, 22 Jun 2024 21:33:47 +0000 (14:33 -0700)] 
gccrs: Make sure CompileExpr::visit is reached

gcc/rust/ChangeLog:

* hir/tree/rust-hir.cc (InlineAsm::accept_vis):
Make sure CompileExpr::visit is reached
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Likewise
gcc/testsuite/ChangeLog:

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

4 months agogccrs: Scaffolding asm codegen
jjasmine [Sat, 22 Jun 2024 18:56:50 +0000 (11:56 -0700)] 
gccrs: Scaffolding asm codegen

gcc/rust/ChangeLog:

* backend/rust-compile-block.h:
Scaffolding asm codegen
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-expr.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise.
* checks/errors/borrowck/rust-bir-builder-expr-stmt.h: Likewise.
* checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* hir/tree/rust-hir-visitor.h: Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.

4 months agogccrs: Fix the parser's operand and flags storage
badumbatish [Wed, 24 Jul 2024 05:17:12 +0000 (22:17 -0700)] 
gccrs: Fix the parser's operand and flags storage

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg_operand):
Fix parsing logic & reassignment logic
(parse_reg_operand_in): Fix parsing
(parse_reg_operand_out): Fix parsing
(parse_reg_operand_inout): Fix parsing
(parse_reg_operand_unexpected): Remove rust_unreachable()
(parse_asm_arg): Fix parsing logic

4 months agogccrs: Add pop guard for binder
badumbatish [Sat, 24 Aug 2024 05:21:05 +0000 (22:21 -0700)] 
gccrs: Add pop guard for binder

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.h:
Add pop guard for binder

4 months agogccrs: Fix warnings from const auto& to const auto
badumbatish [Sun, 4 Aug 2024 19:43:09 +0000 (12:43 -0700)] 
gccrs: Fix warnings from const auto& to const auto

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve.cc (NameResolution::go):
Fix warnings from const auto& to const auto

4 months agogccrs: emit error code for E0758
Raiki Tamura [Wed, 28 Aug 2024 17:48:29 +0000 (02:48 +0900)] 
gccrs: emit error code for E0758

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::build_token): Emit error code.
* lex/rust-lex.h: Fix comment.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
4 months agogccrs: Add typecheck for path patterns.
Raiki Tamura [Fri, 9 Aug 2024 14:56:55 +0000 (23:56 +0900)] 
gccrs: Add typecheck for path patterns.

gcc/rust/ChangeLog:

* hir/tree/rust-hir.cc (Item::item_kind_string): New function.
* hir/tree/rust-hir.h: New function.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Modify to check all arms in match expressions even if some of them
has errors.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Add and fix check for path patterns.

gcc/testsuite/ChangeLog:

* rust/compile/issue-2324-2.rs: Fix error message.
* rust/compile/match9.rs: New test.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
4 months agorust: Add checking for union patterns
Raiki Tamura [Wed, 31 Jul 2024 07:09:30 +0000 (16:09 +0900)] 
rust: Add checking for union patterns

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit):
Add check for union patterns.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
4 months agogccrs: feature-gate: Cleanup visitor and constructor
Arthur Cohen [Wed, 21 Aug 2024 13:42:58 +0000 (15:42 +0200)] 
gccrs: feature-gate: Cleanup visitor and constructor

This commit turns a few of the fields into `tl::optional<T>` and cleanups
the constructor with a couple default parameters. We can also reuse the
variable that we are `switch`ing on, instead of repeating the enum variants
each time.

Most importantly, the `FeatureGate` visitor now uses the `DefaultAstVisitor`
correctly, and will now visit nested items. This means that we have to
fix a bunch of the testsuite as some feature attributes were missing.

gcc/rust/ChangeLog:

* checks/errors/rust-feature.cc (Feature::create): Reuse variable,
remove now optional parameters from constructor.
* checks/errors/rust-feature.h: Cleanup class definition.
* checks/errors/rust-feature-gate.cc (FeatureGate::gate): Use optional.
* checks/errors/rust-feature-gate.h: Cleanup visitor implementation.

gcc/testsuite/ChangeLog:

* rust/compile/assume.rs: Add missing feature attribute.
* rust/compile/issue-1901.rs: Likewise.
* rust/compile/issue-1981.rs: Likewise.
* rust/compile/sizeof-stray-infer-var-bug.rs: Likewise.
* rust/compile/torture/intrinsics-8.rs: Likewise.
* rust/compile/torture/transmute-size-check-1.rs: Likewise.
* rust/compile/torture/transmute1.rs: Likewise.
* rust/compile/torture/uninit-intrinsic-1.rs: Likewise.
* rust/execute/torture/issue-1436.rs: Likewise.
* rust/execute/torture/issue-2583.rs: Likewise.

4 months agogccrs: attributes: Start handling prelude_import properly
Arthur Cohen [Wed, 21 Aug 2024 13:09:23 +0000 (15:09 +0200)] 
gccrs: attributes: Start handling prelude_import properly

This commit adds basic handling for the `#[prelude_import]` attribute,
without doing anything functionality wise.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc (FeatureGate::visit): Add base
feature gating for `#[feature(prelude_import)]`.
* checks/errors/rust-feature-gate.h: Likewise.
* checks/errors/rust-feature.cc (Feature::create): Likewise.
* checks/errors/rust-feature.h: Likewise.
* util/rust-attribute-values.h: Add base handling for `#[prelude_import]`
attribute.
* util/rust-attributes.cc: Likewise.

gcc/testsuite/ChangeLog:

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

4 months agogccrs: Fix the disorder struct and class in inline asm
badumbatish [Mon, 19 Aug 2024 23:39:11 +0000 (16:39 -0700)] 
gccrs: Fix the disorder struct and class in inline asm

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h (struct InlineAsmOperand):
Change to class
(class InlineAsmOperand): Change from struct
* hir/tree/rust-hir-full-decls.h (struct InlineAsmRegOrRegClass):
Removed from decl, used from AST
(struct AnonConst): new decl from rust-hir-expr.h
(class InlineAsmOperand): new decl from rust-hir-expr.h

4 months agogccrs: ast: Introduce class hierarchy for lang item paths
Arthur Cohen [Mon, 24 Jun 2024 16:25:15 +0000 (18:25 +0200)] 
gccrs: ast: Introduce class hierarchy for lang item paths

Create a base Path class which is derived into two children classes for
regular paths and lang item paths. This allows it to hold either the
segments of a fully formed path, or the node ID of a lang-item path.
This is required in order to create these special paths
which do not have segments, and do not necessarily have a canonical
form - they only depend on where the item was defined.

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h (class PathPattern): Rename PathPattern to...
(class Path): ...Path
* ast/rust-ast-collector.cc (TokenCollector::visit): Add required methods
for LangItemPath and RegularPath.
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise.
* ast/rust-ast-visitor.h: Likewise.
* ast/rust-path.cc (PathPattern::as_string): Likewise.
(RegularPath::as_string): Likewise.
(LangItemPath::as_string): Likewise.
(PathPattern::convert_to_simple_path): Likewise.
(RegularPath::convert_to_simple_path): Likewise.
(RegularPath::accept_vis): Likewise.
(LangItemPath::accept_vis): Likewise.
(PathInExpression::as_string): Likewise.
(QualifiedPathInExpression::as_string): Likewise.
* ast/rust-path.h (class PathPattern): Likewise.
(class Path): Likewise.
(class RegularPath): Likewise.
(class LangItemPath): Likewise.
(class PathInExpression): Likewise.
(class QualifiedPathInExpression): Likewise.
* ast/rust-pattern.h (class PathPattern): Likewise.
(class Path): Likewise.
* expand/rust-derive.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.

4 months agogccrs: ast: Remove PathExpr abstract class
Arthur Cohen [Mon, 24 Jun 2024 15:04:13 +0000 (17:04 +0200)] 
gccrs: ast: Remove PathExpr abstract class

Inherit directly from ExprWithoutBlock instead.

gcc/rust/ChangeLog:

* ast/rust-ast.h (class PathExpr): Remove class.
* ast/rust-path.h (class PathInExpression): Inherit from ExprWithoutBlock.
(class QualifiedPathInExpression): Likewise.

4 months agogccrs: ast: PathPattern: Remove `remove_all_segments` method
Arthur Cohen [Mon, 24 Jun 2024 14:50:43 +0000 (16:50 +0200)] 
gccrs: ast: PathPattern: Remove `remove_all_segments` method

This method was used only for stripping PathPattern AST nodes during
`cfg-strip`, which seems like a misnomer and makes it a good candidate
for simplification.

gcc/rust/ChangeLog:

* ast/rust-path.h (class PathInExpression): Remove `remove_all_segments`
method, add a `marked_for_strip` flag instead.