]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
13 months agoUse name resolution 2.0 in TraitResolver
Owen Avery [Sat, 26 Oct 2024 23:43:11 +0000 (19:43 -0400)] 
Use name resolution 2.0 in TraitResolver

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-resolve.cc: Add includes.
(TraitResolver::resolve_path_to_trait):
Use name resolution 2.0 resolver when enabled.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agorust: Desugar IfLet* into MatchExpr
Marc Poulhiès [Wed, 12 Jun 2024 19:58:26 +0000 (21:58 +0200)] 
rust: Desugar IfLet* into MatchExpr

Replace the "regular" AST->HIR lowering for IfLet* with a desugaring
into a MatchExpr.

Desugar a simple if let:

   if let Some(y) = some_value {
     bar();
   }

into:

   match some_value {
     Some(y) => {bar();},
     _ => ()
   }

Same applies for IfLetExprConseqElse (if let with an else block).

Desugar:

   if let Some(y) = some_value {
     bar();
   } else {
     baz();
   }

into:

   match some_value {
     Some(y) => {bar();},
     _ => {baz();}
   }

Fixes https://github.com/Rust-GCC/gccrs/issues/1177

gcc/rust/ChangeLog:

* backend/rust-compile-block.h: Adjust after removal of
HIR::IfLetExpr and HIR::IfLetExprConseqElse.
* 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/borrowck/rust-bir-builder-struct.h: Likewise.
* checks/errors/borrowck/rust-function-collector.h: Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit):
Likewise.
* checks/errors/rust-const-checker.h: Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
Likewise.
* checks/errors/rust-unsafe-checker.h: Likewise.
* hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::translate):
Change return type.
* hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet):
New.
(ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use
desugar_iflet.
* hir/rust-ast-lower.h: Add comment.
* hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove.
(Dump::visit(IfLetExpr&)): Remove.
(Dump::visit(IfLetExprConseqElse&)): Remove.
* hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove.
(Dump::visit(IfLetExpr&)): Remove.
(Dump::visit(IfLetExprConseqElse&)): Remove.
* hir/tree/rust-hir-expr.h (class IfLetExpr): Remove.
(class IfLetExprConseqElse): Remove.
* hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove.
(class IfLetExprConseqElse): Remove.
* hir/tree/rust-hir-visitor.h: Adjust after removal of
HIR::IfLetExpr and HIR::IfLetExprConseqElse.
* hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove.
(IfLetExprConseqElse::as_string): Remove.
(IfLetExpr::accept_vis): Remove.
(IfLetExprConseqElse::accept_vis): Remove.
* hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and
HIR::IfLetExprConseqElse.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* checks/errors/rust-hir-pattern-analysis.cc
(PatternChecker::visit (IfLetExpr &)): Remove.
(PatternChecker::visit (IfLetExprConseqElse &)): Remove.
* checks/errors/rust-hir-pattern-analysis.h (visit(IfLetExpr &)): Remove.
(visit(IfLetExprConseqElse &)): Remove.

gcc/testsuite/ChangeLog:

* rust/compile/if_let_expr.rs: Adjust.
* rust/compile/if_let_expr_simple.rs: New test.
* rust/compile/iflet.rs: New test.
* rust/execute/torture/iflet.rs: New test.
* rust/compile/nr2/exclude: Add iflet.rs and if_let_expr_simple.rs

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
13 months agoFix name resolution 2.0 definition lookups in unsafe checker
Owen Avery [Wed, 9 Oct 2024 04:16:27 +0000 (00:16 -0400)] 
Fix name resolution 2.0 definition lookups in unsafe checker

gcc/rust/ChangeLog:

* checks/errors/rust-unsafe-checker.cc: Add includes.
(UnsafeChecker::visit): Use 2.0 version of resolver when name
resolution 2.0 is enabled.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoImprove path handling while testing name resolution 2.0
Owen Avery [Thu, 17 Oct 2024 00:18:48 +0000 (20:18 -0400)] 
Improve path handling while testing name resolution 2.0

gcc/testsuite/ChangeLog:

* rust/compile/nr2/compile.exp: Handle paths using "file join"
and "file split".
* rust/compile/nr2/exclude: Remove debug-diagnostics-on.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoUse name resolver 2.0 in CompileTraitItem
Owen Avery [Sat, 26 Oct 2024 23:53:42 +0000 (19:53 -0400)] 
Use name resolver 2.0 in CompileTraitItem

gcc/rust/ChangeLog:

* backend/rust-compile-implitem.cc
(CompileTraitItem::visit): Use name resolver 2.0 (when enabled)
to obtain canonical paths for instances of TraitItemConst and
TraitItemFunc.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoUse name resolution 2.0 in TraitItemReference
Owen Avery [Sun, 27 Oct 2024 19:55:48 +0000 (15:55 -0400)] 
Use name resolution 2.0 in TraitItemReference

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.cc: Add includes.
(TraitItemReference::get_type_from_fn): Use
ForeverStack::to_canonical_path when name resolution 2.0 is
enabled.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoRename some PathIdentSegment functions
Owen Avery [Sat, 26 Oct 2024 19:05:43 +0000 (15:05 -0400)] 
Rename some PathIdentSegment functions

This makes PathIdentSegment more similar to other classes used to
represent path segments.

gcc/rust/ChangeLog:

* ast/rust-path.h
(PathIdentSegment::is_super_segment): Rename to...
(PathIdentSegment::is_super_path_seg): ...here.
(PathIdentSegment::is_crate_segment): Rename to...
(PathIdentSegment::is_crate_path_seg): ...here.
(PathIdentSegment::is_lower_self): Rename to...
(PathIdentSegment::is_lower_self_seg): ...here.
(PathIdentSegment::is_big_self): Rename to...
(PathIdentSegment::is_big_self_seg): ...here.

(PathExprSegment::is_super_path_seg): Handle renames.
(PathExprSegment::is_crate_path_seg): Likewise.
(PathExprSegment::is_lower_self_seg): Likewise.
(TypePathSegment::is_crate_path_seg): Likewise.
(TypePathSegment::is_super_path_seg): Likewise.
(TypePathSegment::is_big_self_seg): Likewise.
(TypePathSegment::is_lower_self_seg): Likewise.
* ast/rust-ast-collector.cc
(TokenCollector::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoAdd a newline to the end of nr2/exclude
Owen Avery [Thu, 24 Oct 2024 18:20:29 +0000 (14:20 -0400)] 
Add a newline to the end of nr2/exclude

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Add trailing newline along with
comment.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoFix variable shadowing in late resolution 2.0
Owen Avery [Sun, 27 Oct 2024 17:32:09 +0000 (13:32 -0400)] 
Fix variable shadowing in late resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Visit the initialization expressions of let
statements before visiting their patterns.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoInsert trait names during toplevel resolution 2.0
Owen Avery [Wed, 16 Oct 2024 04:40:01 +0000 (00:40 -0400)] 
Insert trait names during toplevel resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert trait names into the type namespace.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agogccrs: Fix bad recursive operator overload call
Philip Herron [Fri, 11 Oct 2024 16:53:50 +0000 (17:53 +0100)] 
gccrs: Fix bad recursive operator overload call

When we are typechecking the impl block for DerefMut for &mut T
the implementation follows the usual operator overload check
but this ended up just resolving directly to the Trait definition
which ends up being recursive which we usually handle. The issue
we had is that a dereference call can be for either the DEREF
or DEREF_MUT lang item here it was looking for a recurisve call
to the DEREF lang item but we were in the DEREF_MUT lang item
so this case was not accounted for.

Fixes #3032

gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.h: new get locus helper
* typecheck/rust-hir-trait-resolve.cc (AssociatedImplTrait::get_locus): implemention
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_operator_overload):
fix overload

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
13 months agoHandle external static items in toplevel resolver 2.0
Owen Avery [Wed, 16 Oct 2024 03:42:41 +0000 (23:42 -0400)] 
Handle external static items in toplevel resolver 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Handle ExternalStaticItem.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoUse name resolver 2.0 in pattern checker
Owen Avery [Tue, 15 Oct 2024 19:34:06 +0000 (15:34 -0400)] 
Use name resolver 2.0 in pattern checker

gcc/rust/ChangeLog:

* checks/errors/rust-hir-pattern-analysis.cc: Add includes.
(PatternChecker::visit): Use name resolver 2.0 when enabled.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoUse name resolver 2.0 for compiling break/continue
Owen Avery [Tue, 15 Oct 2024 18:56:04 +0000 (14:56 -0400)] 
Use name resolver 2.0 for compiling break/continue

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc
(CompileExpr::visit): Use name resolver 2.0 to lookup label
definitions for break and continue statements when name
resolution 2.0 is enabled.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoUse name resolver 2.0 in const checker
Owen Avery [Tue, 15 Oct 2024 19:33:46 +0000 (15:33 -0400)] 
Use name resolver 2.0 in const checker

gcc/rust/ChangeLog:

* checks/errors/rust-const-checker.cc: Add includes.
(ConstChecker::visit): Use name resolver 2.0 to lookup
function definitions when name resolution 2.0 is enabled.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoLoad unloaded modules during toplevel resolution 2.0
Owen Avery [Wed, 16 Oct 2024 02:24:29 +0000 (22:24 -0400)] 
Load unloaded modules during toplevel resolution 2.0

This may load conditionally compiled modules too eagerly.

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Load unloaded modules before attempting to
visit their items.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove issue-1089.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoMake const references to ForeverStack more useful
Owen Avery [Mon, 21 Oct 2024 22:35:30 +0000 (18:35 -0400)] 
Make const references to ForeverStack more useful

gcc/rust/ChangeLog:

* resolve/rust-forever-stack.h
(ForeverStack::to_canonical_path): Make const.
(ForeverStack::to_rib): Add const overload.
(ForeverStack::reverse_iter): Add const overloads.
(ForeverStack::ConstDfsResult): Add.
(ForeverStack::dfs): Add const overload.
(ForeverStack::dfs_rib): Likewise.
* resolve/rust-forever-stack.hxx
(ForeverStack::reverse_iter): Add const overloads.
(ForeverStack::dfs): Add const overload.
(ForeverStack::to_canonical_path): Make const.
(ForeverStack::dfs_rib): Likewise.
(ForeverStack::to_rib): Add const overload.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoUse name resolver 2.0 in MarkLive
Owen Avery [Tue, 15 Oct 2024 19:34:28 +0000 (15:34 -0400)] 
Use name resolver 2.0 in MarkLive

gcc/rust/ChangeLog:

* checks/lints/rust-lint-marklive.cc
(MarkLive::visit_path_segment): Use name resolver 2.0 when
enabled.
(MarkLive::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoHandle const generic parameters during resolution 2.0
Owen Avery [Wed, 16 Oct 2024 02:10:35 +0000 (22:10 -0400)] 
Handle const generic parameters during resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Handle ConstGenericParam.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoDisambiguate generic args during name resolution 2.0
Owen Avery [Wed, 16 Oct 2024 03:16:23 +0000 (23:16 -0400)] 
Disambiguate generic args during name resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Visit GenericArgs and GenericArg, the former
because the latter involves a non-virtual member function call.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoFix compiler error on ast wrong implicit construct push_back
badumbatish [Thu, 17 Oct 2024 05:41:47 +0000 (22:41 -0700)] 
Fix compiler error on ast wrong implicit construct push_back

gcc/rust/ChangeLog:

* expand/rust-macro-builtins-asm.cc (parse_reg_operand_in): Fix
compiler error on ast wrong implicit construct push_back

13 months agoProvide input operand for gccrs
badumbatish [Thu, 5 Sep 2024 06:59:36 +0000 (23:59 -0700)] 
Provide input operand for gccrs

gcc/rust/ChangeLog:

* backend/rust-compile-asm.cc (CompileAsm::asm_construct_inputs):
Provide input operand for gccrs
* expand/rust-macro-builtins-asm.cc (parse_reg_operand_in):
Move expr to In
(expand_inline_asm_strings):
Add comments to debug strings

gcc/testsuite/ChangeLog:

* rust/compile/inline_asm_parse_operand.rs:
Remove inout, functionality not supported. Remove redundant {}
* rust/execute/torture/inline_asm_mov_x_5_ARM.rs: Add operand in
* rust/execute/torture/inline_asm_mov_x_5_x86_64.rs: Likewise

13 months agoUse name resolver 2.0 during pattern typechecking
Owen Avery [Tue, 15 Oct 2024 19:35:21 +0000 (15:35 -0400)] 
Use name resolver 2.0 during pattern typechecking

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc: Add includes.
(TypeCheckPattern::visit): Use name resolver 2.0 if enabled.

* resolve/rust-name-resolution-context.cc
(NameResolutionContext::lookup): Make const qualified.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::lookup): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoAllow identifiers and paths to reference types during nr2.0
Owen Avery [Tue, 15 Oct 2024 02:07:54 +0000 (22:07 -0400)] 
Allow identifiers and paths to reference types during nr2.0

gcc/rust/ChangeLog:

* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Allow IdentifierExpr and PathInExpression to
reference types as well as values, remove ability for
IdentifierExpr to reference labels.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoImprove handling of InlineAsm in DefaultASTVisitor
Owen Avery [Thu, 10 Oct 2024 01:47:02 +0000 (21:47 -0400)] 
Improve handling of InlineAsm in DefaultASTVisitor

gcc/rust/ChangeLog:

* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Visit fields of InlineAsm.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoInsert static items into the value namespace
Owen Avery [Fri, 11 Oct 2024 05:24:14 +0000 (01:24 -0400)] 
Insert static items into the value namespace

gcc/rust/ChangeLog:

* backend/rust-compile-item.cc
(CompileItem::visit): Check canonical path of StaticItem
properly when name resolution 2.0 is enabled.
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Insert static items into the value namespace.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoRework InlineAsmOperand
Owen Avery [Fri, 11 Oct 2024 01:24:50 +0000 (21:24 -0400)] 
Rework InlineAsmOperand

Not thrilled with some of this boilerplate, but it does seem like an
improvement.

gcc/rust/ChangeLog:

* ast/rust-expr.h
(InlineAsmOperand): Replace multiple mutually-exclusive tl::optional
fields with a std::unique_ptr and modify nested classes to allow
this. Also, make getters return references where possible.
* expand/rust-macro-builtins-asm.cc
(parse_reg_operand_out): Pass location when constructing
InlineAsmOperand.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoHandle TypeAlias during toplevel resolution 2.0
Owen Avery [Thu, 10 Oct 2024 04:46:01 +0000 (00:46 -0400)] 
Handle TypeAlias during toplevel resolution 2.0

gcc/rust/ChangeLog:

* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): Handle TypeAlias.
* resolve/rust-toplevel-name-resolver-2.0.h
(TopLevel::visit): Likewise.

gcc/testsuite/ChangeLog:

* rust/compile/nr2/exclude: Remove type-alias1.rs.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoCheck for writes outside of the build directory
Owen Avery [Thu, 25 Apr 2024 17:08:14 +0000 (13:08 -0400)] 
Check for writes outside of the build directory

ChangeLog:

* .github/workflows/ccpp.yml: Make files outside the build
directory read-only.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoFix some issues with canonical path fetching in name resolution 2.0
Owen Avery [Wed, 9 Oct 2024 03:29:27 +0000 (23:29 -0400)] 
Fix some issues with canonical path fetching in name resolution 2.0

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-enumitem.cc: Add includes.
(TypeCheckEnumItem::visit): Fetch canonical paths properly when
name resolution 2.0 is enabled.
* typecheck/rust-hir-type-check-implitem.cc: Add includes.
(TypeCheckImplItem::visit): Fetch canonical paths properly when
name resolution 2.0 is enabled.
* typecheck/rust-hir-type-check-item.cc: Add include.
(TypeCheckItem::visit): Fetch canonical paths properly when name
resolution 2.0 is enabled.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
13 months agoImprove Rib::Definition shadowing
Owen Avery [Fri, 4 Oct 2024 21:33:42 +0000 (17:33 -0400)] 
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>
13 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>
13 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>
14 months agoChange alpine allowed warning list
Pierre-Emmanuel Patry [Fri, 27 Sep 2024 12:57:25 +0000 (14:57 +0200)] 
Change alpine allowed warning list

ChangeLog:

* .github/alpine_32bit_log_warnings: Update alpine warning list.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 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>
14 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>
14 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

14 months agoRemove some passing test from nr2 passing list
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 21:37:35 +0000 (23:37 +0200)] 
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>
14 months agoPostpone break on error after name resolution
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 21:17:59 +0000 (23:17 +0200)] 
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>
14 months agoResolve TypeParam with name resolution 2.0
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 21:16:21 +0000 (23:16 +0200)] 
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>
14 months agoAdd box definition to avoid error
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 20:59:48 +0000 (22:59 +0200)] 
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>
14 months agoThis test requires the standard library
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 20:51:17 +0000 (22:51 +0200)] 
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>
14 months agoMake node id getter const.
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 20:46:16 +0000 (22:46 +0200)] 
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>
14 months agoChange resolved type segment
Pierre-Emmanuel Patry [Thu, 26 Sep 2024 20:43:18 +0000 (22:43 +0200)] 
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>
14 months agoUpdate exclude list with working tests
Pierre-Emmanuel Patry [Tue, 17 Sep 2024 13:25:41 +0000 (15:25 +0200)] 
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>
14 months agoDo not assert insertion result
Pierre-Emmanuel Patry [Tue, 17 Sep 2024 14:15:40 +0000 (16:15 +0200)] 
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>
14 months agoMove bir builder function implementation
Pierre-Emmanuel Patry [Fri, 6 Sep 2024 10:16:22 +0000 (12:16 +0200)] 
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>
14 months agoMove failing test to xfail
Pierre-Emmanuel Patry [Wed, 4 Sep 2024 15:13:04 +0000 (17:13 +0200)] 
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>
14 months agoMake AST default visitor visit functions public
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 14:13:30 +0000 (16:13 +0200)] 
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>
14 months agoAdd default resolver parent functions by default
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 13:39:59 +0000 (15:39 +0200)] 
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>
14 months agoChange lambda content with default visitor call
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 11:54:48 +0000 (13:54 +0200)] 
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>
14 months agoRemove regular visit code
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 11:37:51 +0000 (13:37 +0200)] 
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>
14 months agoRemove empty visit functions
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 11:23:52 +0000 (13:23 +0200)] 
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>
14 months agoMark virtual function override in default resolver
Pierre-Emmanuel Patry [Thu, 5 Sep 2024 11:01:07 +0000 (13:01 +0200)] 
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>
14 months agoLoop on expansion if a new export has been defined
Pierre-Emmanuel Patry [Wed, 21 Aug 2024 15:14:46 +0000 (17:14 +0200)] 
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>
14 months agoFix missing error on duplicated nodes
Pierre-Emmanuel Patry [Wed, 21 Aug 2024 15:01:29 +0000 (17:01 +0200)] 
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>
14 months agonr2.0: Cleanup import mappings and factor into a class.
Arthur Cohen [Wed, 10 Apr 2024 15:38:19 +0000 (17:38 +0200)] 
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.

14 months agoInsert imports in all namespaces they were resolved in
Arthur Cohen [Mon, 8 Apr 2024 16:44:15 +0000 (18:44 +0200)] 
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.

14 months agoearly: Do not emit errors for unresolved imports, store them instead
Arthur Cohen [Sat, 6 Apr 2024 21:23:39 +0000 (23:23 +0200)] 
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.

14 months agoimports: Make FinalizeImports a resolver visitor as well
Arthur Cohen [Sat, 6 Apr 2024 21:02:51 +0000 (23:02 +0200)] 
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.

14 months agoimports: Start storing Ribs in ImportKind
Arthur Cohen [Fri, 5 Apr 2024 22:32:57 +0000 (00:32 +0200)] 
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.

14 months agoimports: Create ImportData class and use it in import_mappings
Arthur Cohen [Fri, 5 Apr 2024 22:00:49 +0000 (00:00 +0200)] 
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.

14 months agoimports: Add FinalizeImports class
Arthur Cohen [Thu, 4 Apr 2024 15:07:54 +0000 (17:07 +0200)] 
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.

14 months agoearly: Resolve imports and create import mappings
Arthur Cohen [Thu, 4 Apr 2024 14:25:30 +0000 (16:25 +0200)] 
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.

14 months agotoplevel: Build list of imports for Early to resolve
Arthur Cohen [Thu, 4 Apr 2024 13:42:29 +0000 (15:42 +0200)] 
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.

14 months agotoplevel: Add note for resolving use declarations
Arthur Cohen [Wed, 3 Apr 2024 15:41:47 +0000 (17:41 +0200)] 
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.

14 months agonr2.0: default-visitor: Conditionally visit type in self parameters.
Arthur Cohen [Wed, 27 Mar 2024 16:20:15 +0000 (17:20 +0100)] 
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.

14 months agorust fix ICE when hir lowering qualified path expressions without an as
Philip Herron [Fri, 20 Sep 2024 16:13:38 +0000 (17:13 +0100)] 
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>
14 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>
14 months agoRemove some overloaded methods from DefaultResolver.
Owen Avery [Mon, 23 Sep 2024 21:44:19 +0000 (17:44 -0400)] 
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>
14 months agoAdd extra assertions to tl::optional
Owen Avery [Wed, 18 Sep 2024 20:05:31 +0000 (16:05 -0400)] 
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>
14 months agomingw: Fix build with patch from Liu Hao
Arthur Cohen [Mon, 16 Sep 2024 12:06:13 +0000 (14:06 +0200)] 
mingw: Fix build with patch from Liu Hao

This commit adds Liu Hao's patch from
https://github.com/lhmouse/MINGW-packages/blob/5859d27b2b6101204a08ad9702cb2937f8797be9/mingw-w64-gcc/0100-rust-fix.patch

gcc/rust/ChangeLog:

* checks/errors/borrowck/rust-borrow-checker.cc (mkdir_wrapped): Remove.
(BorrowChecker::go): Use `mkdir` instead.
* expand/rust-proc-macro.cc (register_callback): Use Windows APIs to
open dynamic proc macro library.
(load_macros_array): Likewise.
* parse/rust-parse.cc (defined): Replace separators in paths using
std::replace.

14 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>
14 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>
14 months agoFix ICE on error propagation with generic
benjamin.thos [Thu, 12 Sep 2024 17:10:49 +0000 (17:10 +0000)] 
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>
14 months agoAdjust expected warnings for alpine 32 bit
Owen Avery [Wed, 18 Sep 2024 21:20:48 +0000 (17:20 -0400)] 
Adjust expected warnings for alpine 32 bit

ChangeLog:

* .github/alpine_32bit_log_warnings: Adjust.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
14 months agoCheck if the type has been correctly resolved
Pierre-Emmanuel Patry [Thu, 19 Sep 2024 12:38:48 +0000 (14:38 +0200)] 
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>
14 months agoChange upload artifact github action version
Pierre-Emmanuel Patry [Tue, 17 Sep 2024 11:59:27 +0000 (13:59 +0200)] 
Change upload artifact github action version

Version 2 of this github action has been deprecated, we shall bump the
version used in the CI.

ChangeLog:

* .github/workflows/bootstrap.yml: Bump version from 2 to 4.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 months agogithub: adjust footer detection for Tested-by
Marc Poulhiès [Mon, 9 Sep 2024 19:46:57 +0000 (21:46 +0200)] 
github: adjust footer detection for Tested-by

Add the "Tested-by" prefix to the list of already matched footer
prefixes.
Adjust the error message.
This avoid warnings on commits using it.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
14 months agoCreate new test system for name resolution 2.0
Owen Avery [Mon, 16 Sep 2024 22:27:19 +0000 (18:27 -0400)] 
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>
14 months ago[#3141] Remove double negation by returning CompileExpr::Compile early
JoanVC [Sun, 15 Sep 2024 13:59:34 +0000 (15:59 +0200)] 
[#3141] Remove double negation by returning CompileExpr::Compile early

Fixes #3141.

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc

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

Fixes #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>
14 months agosession-manager: Fix typos in -frust-incomplete message
Arthur Cohen [Thu, 5 Sep 2024 14:17:57 +0000 (16:17 +0200)] 
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.

14 months agoEmit error on auto-traits
benjamin.thos [Wed, 11 Sep 2024 14:31:20 +0000 (14:31 +0000)] 
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>
14 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>
14 months agoCompile using ASAN on the github CI
Owen Avery [Tue, 27 Aug 2024 03:08:30 +0000 (23:08 -0400)] 
Compile using ASAN on the github CI

ChangeLog:

* .github/workflows/ccpp.yml: Add job for running tests with
ASAN.
* .github/no-bootstrap-asan.mk: New file.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
14 months agoDynamic dispatch with supertraits
Liam Naddell [Thu, 8 Aug 2024 09:31:58 +0000 (05:31 -0400)] 
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>
14 months agoUsed `IndexVec` for place_map
Kushal Pal [Wed, 28 Aug 2024 06:39:28 +0000 (06:39 +0000)] 
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>
14 months agoUse `IndexVec` for bb_fold_map
Kushal Pal [Wed, 28 Aug 2024 06:16:11 +0000 (06:16 +0000)] 
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>
14 months agoUsed `IndexVec` for Places
Kushal Pal [Tue, 20 Aug 2024 06:09:51 +0000 (06:09 +0000)] 
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>
14 months agoUsed `IndexVec` for BasicBlocks
Kushal Pal [Mon, 19 Aug 2024 10:06:49 +0000 (10:06 +0000)] 
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>
14 months agoUsed `IndexVec` for Loans
Kushal Pal [Mon, 19 Aug 2024 09:48:49 +0000 (09:48 +0000)] 
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>
14 months agoUsed `IndexVec` for Scopes
Kushal Pal [Mon, 19 Aug 2024 09:38:52 +0000 (09:38 +0000)] 
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>
14 months agoIntroduce `IndexVec`
Kushal Pal [Mon, 19 Aug 2024 09:28:25 +0000 (09:28 +0000)] 
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>
14 months agoStrong type BasicBlockId
Kushal Pal [Wed, 7 Aug 2024 10:58:17 +0000 (10:58 +0000)] 
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>
14 months agoStrong type ScopeId
Kushal Pal [Wed, 7 Aug 2024 10:16:24 +0000 (10:16 +0000)] 
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>
14 months agoStrong type LoanId
Kushal Pal [Wed, 7 Aug 2024 08:44:03 +0000 (08:44 +0000)] 
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>
14 months agoUse FreeRegions inplace of `std::vector<FreeRegion>`
Kushal Pal [Thu, 8 Aug 2024 07:12:00 +0000 (07:12 +0000)] 
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>
14 months agoStrong type FreeRegion
Kushal Pal [Wed, 7 Aug 2024 05:19:28 +0000 (05:19 +0000)] 
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>
14 months agoStrong type PlaceId
Kushal Pal [Mon, 5 Aug 2024 10:50:55 +0000 (10:50 +0000)] 
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>