platform/upstream/gcc.git
15 months agoarm: mve: fix auto-inc generation [PR107674]
Richard Earnshaw [Thu, 6 Apr 2023 13:44:30 +0000 (14:44 +0100)]
arm: mve: fix auto-inc generation [PR107674]

My change r13-416-g485a0ae0982abe caused the compiler to stop
generating auto-inc operations on mve loads and stores.  The fix
is to check whether there is a replacement register available
when in strict mode and the register is still a pseudo.

gcc:

PR target/107674
* config/arm/arm.cc (arm_effective_regno): New function.
(mve_vector_mem_operand): Use it.

15 months agoCheck if dependency is valid before using in may_recompute_p.
Andrew MacLeod [Wed, 5 Apr 2023 19:59:38 +0000 (15:59 -0400)]
Check if dependency is valid before using in may_recompute_p.

When the IL is rewritten after a statement has been processed and
dependencies cached, its possible that an ssa-name in the dependency
cache is no longer in the IL.  Check this before trying to recompute.

PR tree-optimization/109417
gcc/
* gimple-range-gori.cc (gori_compute::may_recompute_p): Check if
dependency is in SSA_NAME_FREE_LIST.

gcc/testsuite/
* gcc.dg/pr109417.c: New.

15 months agogccrs: Fix issue with parsing unsafe block expression statements
Owen Avery [Fri, 27 Jan 2023 03:59:49 +0000 (22:59 -0500)]
gccrs: Fix issue with parsing unsafe block expression statements

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_stmt): Handle unsafe expression statements.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Address unsafe with/without block handling ambiguity
Owen Avery [Fri, 27 Jan 2023 03:48:45 +0000 (22:48 -0500)]
gccrs: Address unsafe with/without block handling ambiguity

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_expr_stmt): Remove hypothetical unsafe + expr_stmt_without_block handling.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Added AST Node AST::InlineAsm
M V V S Manoj Kumar [Fri, 17 Feb 2023 18:09:56 +0000 (23:39 +0530)]
gccrs: Added AST Node AST::InlineAsm

Addresses #1567
Created a AST node InlineAsm similar to the one found in rustc.
As there is no Symbol struct/class in gccrs I have made every instance
of Symbol a string.

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h (class InlineAsm):Added class declaration.
* ast/rust-expr.h (class InlineAsm):Added class definition.

Signed-off-by: M V V S Manoj Kumar <mvvsmanojkumar@gmail.com>
15 months agogccrs: diagnostic: Refactor Error class
Arthur Cohen [Wed, 15 Feb 2023 15:56:07 +0000 (16:56 +0100)]
gccrs: diagnostic: Refactor Error class

The class now allows for more variants including a `Hint` one which
then gets emitted by calling `rust_inform`. This allows us to display
hints/tips/notes in backtracking contexts such as the parser.

gcc/rust/ChangeLog:

* rust-diagnostics.h (struct Error): Add new Kind enum and various new
static constructors to allow for hints as well.
* rust-diagnostics.cc (Error::Error): Use new `kind` field properly.
* checks/errors/privacy/rust-visibility-resolver.cc
(VisibilityResolver::resolve_module_path): Use new Error API.
* expand/rust-macro-builtins.cc (MacroBuiltin::include_handler): Likewise.
* expand/rust-macro-expand.cc (parse_many): Likewise.
(transcribe_type): Likewise.
* parse/rust-parse-impl.h (Parser::parse_crate): Likewise.
* rust-session-manager.cc (Session::handle_crate_name): Likewise.
* ast/rust-ast.cc (Module::load_items): Likewise.

15 months agogccrs: ast: Refactor TraitItem to keep Location info
Arthur Cohen [Wed, 15 Feb 2023 16:10:54 +0000 (17:10 +0100)]
gccrs: ast: Refactor TraitItem to keep Location info

gcc/rust/ChangeLog:

* ast/rust-ast.h: Keep location in TraitItem base class
* ast/rust-item.h (class TraitItemFunc): Use base class location instead.
(class TraitItemMethod): Likewise.
(class TraitItemConst): Likewise.
(class TraitItemType): Likewise.
* ast/rust-macro.h: Likewise.

15 months agogccrs: add test case to show our query-type system is working
Philip Herron [Thu, 16 Feb 2023 16:14:23 +0000 (16:14 +0000)]
gccrs: add test case to show our query-type system is working

Fixes #1361

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/testsuite/ChangeLog:

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

15 months agogccrs: rename rust-hir-full-tests.cc
SainiAditya1 [Mon, 30 Jan 2023 17:07:08 +0000 (22:37 +0530)]
gccrs: rename rust-hir-full-tests.cc

gcc/rust/Changelog:

* hir/tree/rust-hir-full-test.cc: Moved to...
* hir/tree/rust-hir.cc: ...here.
* Make-lang.in: Rename rust-hir-full-test.

Signed-off-by: SainiAditya1 <Adityasaini10012001@outlook.com>
15 months agogccrs: Fix up DejaGnu directives in 'rust/compile/issue-1830_{bytes,str}.rs' test...
Thomas Schwinge [Tue, 14 Feb 2023 23:28:35 +0000 (00:28 +0100)]
gccrs: Fix up DejaGnu directives in 'rust/compile/issue-1830_{bytes,str}.rs' test cases [#1838]

'dg-excess-errors' "indicates that the test is expected to fail due to compiler
messages that are not handled by 'dg-error', [etc.]".  It's argument doesn't
specify the message to match but just just a comment.  Here, however, we'd like
to match specific compiler messages, so we should use 'dg-error', etc.  Use the
magic line number zero as the compiler error diagnostic doesn't tell which line
the error occurred on (separate issue to resolve).  This gives us:

    -XFAIL: rust/compile/issue-1830_str.rs (test for excess errors)
    +PASS: rust/compile/issue-1830_bytes.rs  at line 8 (test for errors, line )
    +PASS: rust/compile/issue-1830_bytes.rs (test for excess errors)
    -XFAIL: rust/compile/issue-1830_bytes.rs (test for excess errors)
    +PASS: rust/compile/issue-1830_str.rs  at line 8 (test for errors, line )
    +PASS: rust/compile/issue-1830_str.rs (test for excess errors)

Fix-up for recent GCC/Rust master branch #1838
commit cf9ed4001eec6a22686d19a13f7de8ac94f9cb2a
"testsuite: Add empty string macro test".

gcc/testsuite/
* rust/compile/issue-1830_bytes.rs: Fix up DejaGnu directives.
* rust/compile/issue-1830_str.rs: Likewise.

15 months agogccrs: Add AST::AltPattern class
Owen Avery [Tue, 14 Feb 2023 22:28:35 +0000 (17:28 -0500)]
gccrs: Add AST::AltPattern class

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc
(Dump::visit): Add AltPattern visitor.
* ast/rust-ast-dump.h:
(Dump::visit): Add AltPattern visitor.
* ast/rust-ast-full-decls.h
(class AltPattern): Add declaration.
* ast/rust-ast-visitor.h:
(ASTVisitor::visit): Add AltPattern visitor.
* ast/rust-ast.cc
(AltPattern::as_string): Add definition.
(AltPattern::accept_vis): Add definition.
* ast/rust-pattern.h
(class AltPattern): Add declaration.
* checks/errors/rust-feature-gate.h:
(FeatureGate::visit) Add AltPattern visitor
* expand/rust-attribute-visitor.cc
(AttrVisitor::visit): Add AltPattern visitor.
* expand/rust-attribute-visitor.h:
(AttrVisitor::visit): Add AltPattern visitor.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::visit): Add AltPattern visitor.
* hir/rust-ast-lower-base.h:
(ASTLoweringBase::visit): Add AltPattern visitor.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Add AltPattern visitor.
* resolve/rust-ast-resolve-base.h:
(ResolverBase::visit): Add AltPattern visitor.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Add AltPattern visitor.
* resolve/rust-early-name-resolver.h:
(EarlyNameResolver::visit): Add AltPattern visitor.
* util/rust-attributes.cc
(AttributeChecker::visit): Add AltPattern visitor.
* util/rust-attributes.h:
(AttributeChecker::visit): Add AltPattern visitor.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Fix formatting
Owen Avery [Wed, 15 Feb 2023 15:04:32 +0000 (10:04 -0500)]
gccrs: Fix formatting

gcc/rust/ChangeLog:

* ast/rust-pattern.h: Fix formatting.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: builtins: Return empty list of tokens instead of nullptr
Arthur Cohen [Wed, 15 Feb 2023 09:52:28 +0000 (10:52 +0100)]
gccrs: builtins: Return empty list of tokens instead of nullptr

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (MacroBuiltin::include_handler): Do not
return nullptr token in expansion of `include!()`

gcc/testsuite/ChangeLog:

* rust/compile/empty.in: New test.
* rust/compile/include_empty.rs: New test.

15 months agogccrs: Add trailing newline
Owen Avery [Tue, 14 Feb 2023 23:47:53 +0000 (18:47 -0500)]
gccrs: Add trailing newline

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.h: Add trailing newline before EOF.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Fix regression in testcase
Philip Herron [Mon, 13 Feb 2023 22:22:06 +0000 (22:22 +0000)]
gccrs: Fix regression in testcase

Fixes #776

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/testsuite/ChangeLog:

* rust/compile/torture/traits10.rs: Fix test-case

15 months agogccrs: Support for Sized builtin marker trait
Philip Herron [Mon, 13 Feb 2023 17:51:19 +0000 (17:51 +0000)]
gccrs: Support for Sized builtin marker trait

When implementing general bounds checking as part of unify calls, we did
not check associated types on bounds which lead to alot of missed error
checking. This now recursively checks the bounds and the associated types
with a decent error message. This also required us to implement the Sized
marker trait to keep existing test-cases happy.

Fixes #1725

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.cc (TraitReference::clear_associated_types): make const
(TraitReference::clear_associated_type_projections): new interface
* typecheck/rust-hir-trait-reference.h:
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): refactor
(TraitItemReference::associated_type_reset): reset projections
* typecheck/rust-hir-type-bounds.h:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): fix bounds
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::TypeBoundsProbe): refactor into cc file
(TypeBoundsProbe::Probe): refactor
(TypeBoundsProbe::is_bound_satisfied_for_type): likewise
(TypeBoundsProbe::assemble_sized_builtin): add builtin for Sized
(TypeCheckBase::get_predicate_from_bound): refactor
(TypeBoundPredicate::lookup_associated_type): refactor
* typecheck/rust-tyty-subst.cc (SubstitutionRef::lookup_associated_impl)
(SubstitutionRef::prepare_higher_ranked_bounds): new interface to clear hanging bounds
(SubstitutionRef::monomorphize): refactor
* typecheck/rust-tyty-subst.h:
* typecheck/rust-tyty.cc (BaseType::get_locus): helper
(BaseType::satisfies_bound): ensure bounds are satisfied and assoicated types
(ParamType::ParamType): new field in constructor
(ParamType::clone): update clone
(ParamType::set_implicit_self_trait): new interface
(ParamType::is_implicit_self_trait): likewise
* typecheck/rust-tyty.h: cleanup
* util/rust-hir-map.cc (Mappings::Mappings): builtin marker
(Mappings::~Mappings): delete marker
(Mappings::lookup_builtin_marker): lookup
* util/rust-hir-map.h: update header

gcc/testsuite/ChangeLog:

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

15 months agogccrs: Add new virtual function HIR::ImplItem::get_impl_item_name
Philip Herron [Mon, 6 Feb 2023 17:48:06 +0000 (17:48 +0000)]
gccrs: Add new virtual function HIR::ImplItem::get_impl_item_name

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* hir/tree/rust-hir-item.h: implement virtual function
* hir/tree/rust-hir.h: add virtual function

15 months agogccrs: Extract query_type from TypeCheckBase to be a simple extern
Philip Herron [Mon, 6 Feb 2023 17:46:07 +0000 (17:46 +0000)]
gccrs: Extract query_type from TypeCheckBase to be a simple extern

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* Make-lang.in: add new dependancy
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::query_type): refactor
* typecheck/rust-hir-type-check-base.h: refactor
* typecheck/rust-hir-type-check.h (RUST_HIR_TYPE_CHECK): refactor
* typecheck/rust-type-util.cc: New file.
* typecheck/rust-type-util.h: New file.

15 months agogccrs: Implemented UTF-8 checking for include_str!()
Owen Avery [Sun, 8 Jan 2023 22:19:12 +0000 (17:19 -0500)]
gccrs: Implemented UTF-8 checking for include_str!()

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc
(MacroBuiltin::include_str_handler): Add check for valid UTF-8.

gcc/testsuite/ChangeLog:

* rust/compile/builtin_macro_include_str.rs:
Include test of invalid UTF-8.
* rust/compile/invalid_utf8: File with invalid UTF-8.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add support for parsing empty tuple patterns.
Owen Avery [Tue, 14 Feb 2023 01:32:51 +0000 (20:32 -0500)]
gccrs: Add support for parsing empty tuple patterns.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_grouped_or_tuple_pattern): Add support for empty tuple patterns.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: testsuite: Add empty string macro test
Pierre-Emmanuel Patry [Thu, 9 Feb 2023 17:24:42 +0000 (18:24 +0100)]
gccrs: testsuite: Add empty string macro test

Add two new tests with empty string for include_str and include_bytes
macros.

gcc/testsuite/ChangeLog:

* rust/compile/issue-1830_bytes.rs: New test.
* rust/compile/issue-1830_str.rs: New test.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
15 months agogccrs: lex: Prevent directories in RAIIFile
Pierre-Emmanuel Patry [Thu, 9 Feb 2023 09:47:15 +0000 (10:47 +0100)]
gccrs: lex: Prevent directories in RAIIFile

RAIIFile constructor was accepting directory filename. This lead to
unattended directory opening in some part of the code (load_file_bytes)
wich resulted in ice. Since RAIIFile are used for the lexer, removing
the ability to open directories with RAIIFile fixes those issues and
prevent future mistakes.

gcc/rust/ChangeLog:

* lex/rust-lex.h: Add file type check.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
15 months agogccrs: Simplify WildcardPattern let statement handling
Owen Avery [Fri, 3 Feb 2023 15:19:32 +0000 (10:19 -0500)]
gccrs: Simplify WildcardPattern let statement handling

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc
(CompilePatternLet::visit): Simplify WildcardPattern compilation for let statements.
* backend/rust-compile-var-decl.h:
(CompileVarDecl::visit): Remove variable declaration for WildcardPattern.
* resolve/rust-ast-resolve-pattern.h:
(PatternDeclaration::visit): Remove name resolution for WildcardPattern.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add test
Owen Avery [Mon, 13 Feb 2023 16:29:07 +0000 (11:29 -0500)]
gccrs: Add test

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add variadic argument type checking
Owen Avery [Fri, 10 Feb 2023 15:19:24 +0000 (10:19 -0500)]
gccrs: Add variadic argument type checking

gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc
(TypeCheckCallExpr::visit): Add variadic argument type checking.
(TypeCheckCallExpr::visit): Fix comment spelling ("varadic").

gcc/testsuite/ChangeLog:

* rust/execute/torture/overflow1.rs: Fix test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add feature gate for "rust-intrinsic".
mxlol233 [Sun, 5 Feb 2023 13:17:34 +0000 (21:17 +0800)]
gccrs: Add feature gate for "rust-intrinsic".

This commit implemented a feature gate to check `intrinsics`.

gcc/rust/ChangeLog:

* checks/errors/rust-feature-gate.cc: Add implementation for
`void FeatureGate::visit (AST::ExternBlock &block)`. Add `valid_feature`
construction process in `FeatureGate::check`.
* checks/errors/rust-feature-gate.h: Add declaration for
`void FeatureGate::visit (AST::ExternBlock &block)`. Add private
variable `valid_feature`.
* checks/errors/rust-feature.h: Change `issue` to `m_issue`.

gcc/testsuite/ChangeLog:

* rust/compile/const-issue1440.rs: Add crate feature: `intrinsics`.
* rust/compile/feature_intrinsics.rs: New file.
* rust/compile/issue-1031.rs: Add crate feature: `intrinsics`.
* rust/compile/issue-1130.rs: Add crate feature: `intrinsics`.
* rust/compile/issue-1131.rs: Add crate feature: `intrinsics`.
* rust/compile/issue-1237.rs: Add crate feature: `intrinsics`.
* rust/compile/issue-1289.rs: Add crate feature: `intrinsics`.
* rust/compile/rust-const-blog-issue.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-3.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-4.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-5.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-6.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/intrinsics-7.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/issue-1024.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/issue-1075.rs: Add crate feature: `intrinsics`.
* rust/compile/torture/issue-1432.rs: Add crate feature: `intrinsics`.
* rust/compile/unsafe10.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/atomic_load.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/atomic_store.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/copy_nonoverlapping1.rs: Add crate feature:
`intrinsics`.
* rust/execute/torture/issue-1120.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/issue-1133.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/issue-1232.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/slice-magic.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/slice-magic2.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/str-layout1.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/transmute1.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/wrapping_op1.rs: Add crate feature: `intrinsics`.
* rust/execute/torture/wrapping_op2.rs: Add crate feature: `intrinsics`.

Signed-off-by: Xiao Ma <mxlol233@outlook.com>
15 months agogccrs: Update copyright years.
Thomas Schwinge [Mon, 27 Feb 2023 12:53:50 +0000 (13:53 +0100)]
gccrs: Update copyright years.

gcc/rust/ChangeLog:

* ast/rust-ast-fragment.cc: Update copyright years.
* ast/rust-ast-fragment.h: Likewise.
* ast/rust-macro.cc: Likewise.
* checks/errors/rust-feature-gate.cc: Likewise.
* checks/errors/rust-feature-gate.h: Likewise.
* checks/errors/rust-feature.cc: Likewise.
* checks/errors/rust-feature.h: Likewise.
* hir/rust-ast-lower-expr.cc: Likewise.
* hir/rust-ast-lower-type.cc: Likewise.
* resolve/rust-early-name-resolver.cc: Likewise.
* resolve/rust-early-name-resolver.h: Likewise.
* rust-gcc.h: Likewise.
* typecheck/rust-hir-path-probe.cc: Likewise.
* typecheck/rust-hir-trait-reference.cc: Likewise.
* typecheck/rust-tyty-bounds.h: Likewise.
* typecheck/rust-tyty-subst.cc: Likewise.
* typecheck/rust-tyty-subst.h: Likewise.
* typecheck/rust-tyty-util.cc: Likewise.
* typecheck/rust-tyty-util.h: Likewise.
* typecheck/rust-unify.cc: Likewise.
* typecheck/rust-unify.h: Likewise.
* util/rust-inline-visitor.h: Likewise.

15 months agogccrs: cli: Update safety warning message
Pierre-Emmanuel Patry [Thu, 9 Feb 2023 10:32:50 +0000 (11:32 +0100)]
gccrs: cli: Update safety warning message

The compiler's warning message about the safety flag did not match
cargo-gccrs environment variable name anymore.

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Update the
environment variable name.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
15 months agogccrs: typecheck: Refactor rust-hir-trait-reference.h
Pierre-Emmanuel Patry [Wed, 8 Feb 2023 15:19:41 +0000 (16:19 +0100)]
gccrs: typecheck: Refactor rust-hir-trait-reference.h

Move function body to their own cc file instead of keeping them in the
header file.

gcc/rust/ChangeLog:

* Make-lang.in: Add `rust-hir-trait-reference.o`.
* typecheck/rust-hir-trait-reference.h: Remove multiple function body.
* typecheck/rust-hir-trait-reference.cc: Add multiple function body.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
15 months agogccrs: expander: Add documentation for `expand_eager_invocations`
Arthur Cohen [Wed, 8 Feb 2023 11:23:06 +0000 (12:23 +0100)]
gccrs: expander: Add documentation for `expand_eager_invocations`

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (MacroExpander::expand_eager_invocations):
Add documentation explaining the algorithm.

15 months agogccrs: macros: Perform macro expansion in a fixed-point fashion.
Arthur Cohen [Wed, 18 Jan 2023 11:23:03 +0000 (12:23 +0100)]
gccrs: macros: Perform macro expansion in a fixed-point fashion.

This commit changes our macro expansion system from an eager and recursive
macro expansion to a fixed-point like system. Instead of, when seeing
a macro invocation, expanding it and all of the macros within it, we
now perform multiple passes of expansion on the entire crate.

This, however, leads to a problem. Rust macros are expanded lazily, but
Rust builtin macros should be expanded eagerly. Due to this, we must
work around the lazy expansion in builtin macros and perform eager
expansion for each pass of the fixed-point, before finally expanding
the builtin when there are no longer any inner macro invocations.

To perform proper macro scoping, the ENR now keeps track of the current
scope (`current_scope` member) and resolves macros accordingly.

This is done through the use of the `scoped` method, which creates a new
scope, runs a specified lambda and then exits the scope. This prevents
pushing/popping errors that we've seen happen already in similar
contexts.

We might think about generalizing it to other classes, providing a
`Scoped<EntryFn, ExitFn>` class or similar

gcc/rust/ChangeLog:

* ast/rust-macro.cc: New file.
* Make-lang.in: Add `rust-macro.o` object
* ast/rust-ast-fragment.cc (Fragment::Fragment): Change API around
the construction of AST fragments.
(Fragment::operator=): Correct `Fragment::operator=` to take into
account the fragment tokens.
(Fragment::create_error): Use new constructor.
(Fragment::complete): Remove in favor of new constructor.
(Fragment::unexpanded): Remove as that Fragment type is no longer used
or possible.
(Fragment::get_tokens): Add helper to access a fragment's tokens.
* ast/rust-ast-fragment.h (enum class): Remove `FragmentKind::Unused`
* ast/rust-ast.cc (MacroInvocation::as_string): Display
builtin macro invocations properly.
* ast/rust-ast.h: Fix `DelimTokenTree` class copy constructors and
handling of its token vector.
* ast/rust-macro.h (class MacroMatcher): Format.
(class MetaItemSeq): Likewise.
(builtin_macro_from_string): Get a `BuiltinMacroKind` from a given
string, i.e the name of the macro (`assert!`, `cfg!` and so on).
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Do not expand
macros recursively anymore.
(AttrVisitor::maybe_expand_expr): Likewise.
(AttrVisitor::maybe_expand_type): Likewise.
* expand/rust-attribute-visitor.h: Likewise, and remove
`expand_macro_fragment_recursively` function.
* expand/rust-macro-builtins.cc (make_token): Add shorthand for
returning `std::unique_ptr<AST::Token>`s.
(make_macro_invocation): Add shorthand for returning fragments
containing builtin macro invocations.
(try_expand_macro_expression): Do not expand macros recursively.
(try_expand_single_string_literal): Likewise.
(try_expand_many_expr): Likewise.
(parse_single_string_literal): Error out more appropriately.
(MacroBuiltin::compile_error_handler): Add explanation for eager
invocation
(MacroBuiltin::file_handler): Return the proper tokens associated with
macro invocation, and builtin macros in the case of necessary eager
expansion.
(MacroBuiltin::column_handler): Likewise.
(MacroBuiltin::include_bytes_handler): Likewise.
(MacroBuiltin::include_str_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::cfg_handler): Likewise.
(MacroBuiltin::include_handler): Likewise.
(MacroBuiltin::line_handler): Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_eager_invocations):
Add function to expand eager invocations *once* in the fixed point
pipeline.
(MacroExpander::expand_invoc): Call into `expand_eager_invocations` for
builtin macro invocations.
(MacroExpander::expand_crate): Use new `AttrVisitor` API.
(parse_many): Return tokens in `AST::Fragment`.
(transcribe_expression): Likewise.
(transcribe_type): Likewise.
* expand/rust-macro-expand.h (struct MacroExpander): Add `has_changed`
flag for fixed point checking.
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::EarlyNameResolver):
Keep track of the current macro scope.
(EarlyNameResolver::go): Use `scoped` API.
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h: Add `scoped` API.
* rust-session-manager.cc (Session::expansion): Perform macro expansion
in a fixed-point fashion.

gcc/testsuite/ChangeLog:

* rust/compile/macro17.rs: Fix testsuite for new recursion errors.
* rust/compile/macro44.rs: Fix invalid testcase assertions.
* rust/compile/builtin_macro_recurse.rs: Fix invalid test.
* rust/compile/builtin_macro_recurse2.rs: New test.
* rust/compile/macro46.rs: New test.

15 months agogccrs: expansion: Add `get_token_slice` to `MacroInvocLexer` class
Arthur Cohen [Tue, 17 Jan 2023 15:44:23 +0000 (16:44 +0100)]
gccrs: expansion: Add `get_token_slice` to `MacroInvocLexer` class

gcc/rust/ChangeLog:

* expand/rust-macro-invoc-lexer.cc (MacroInvocLexer::get_token_slice):
Add API to retrieve token slices when lexing macro expansions.
* expand/rust-macro-invoc-lexer.h: Declare `get_token_slice`.

15 months agogccrs: parser: Expose parse_macro_invocation as public API
Arthur Cohen [Fri, 13 Jan 2023 11:16:49 +0000 (12:16 +0100)]
gccrs: parser: Expose parse_macro_invocation as public API

gcc/rust/ChangeLog:

* parse/rust-parse.h: Move `parse_macro_invocation` to public API.

15 months agogccrs: rust-item: include rust-expr.h
Arthur Cohen [Tue, 17 Jan 2023 14:53:00 +0000 (15:53 +0100)]
gccrs: rust-item: include rust-expr.h

gcc/rust/ChangeLog:

* ast/rust-item.h (class BlockExpr): Remove forward declaration of
class `BlockExpr`.

15 months agogccrs: Add support for TuplePattern in let statements
Owen Avery [Sat, 4 Feb 2023 05:02:22 +0000 (00:02 -0500)]
gccrs: Add support for TuplePattern in let statements

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(TuplePatternItemsRanged::get_lower_patterns): Add method.
(TuplePatternItemsRanged::get_upper_patterns): Add method.
* backend/rust-compile-pattern.cc
(CompilePatternLet::visit): Implement TuplePattern visitor.
* backend/rust-compile-pattern.h
(CompilePatternLet::visit): Move TuplePattern visitor out of header file.

gcc/testsuite/ChangeLog:

* rust/execute/torture/let-pattern-1.rs: New test.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add general TypeBounds checks
Philip Herron [Sat, 4 Feb 2023 22:53:48 +0000 (22:53 +0000)]
gccrs: Add general TypeBounds checks

Existing tests are updated to use libcore copy and clone implementation.

Addresses #1725

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-unify.cc (UnifyRules::go): ensure the bounds are checked

gcc/testsuite/ChangeLog:

* rust/compile/torture/intrinsics-4.rs: implement Copy trait
* rust/compile/torture/intrinsics-5.rs: likewise
* rust/execute/torture/atomic_load.rs: likewise
* rust/execute/torture/atomic_store.rs: likewise
* rust/bounds1.rs: New test.

15 months agogccrs: Remove bad error message on checking function arguments
Philip Herron [Sat, 4 Feb 2023 23:02:31 +0000 (23:02 +0000)]
gccrs: Remove bad error message on checking function arguments

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): remove error message

gcc/testsuite/ChangeLog:

* rust/compile/func3.rs: update test case

15 months agogccrs: Fix higher ranked trait bounds computation of self
Philip Herron [Tue, 31 Jan 2023 18:52:33 +0000 (18:52 +0000)]
gccrs: Fix higher ranked trait bounds computation of self

This updates the higher ranked trait bounds computation to handle ambigious
cases. When we have a slice for example:

  let slice = &a[1..3];

This works by reusing the Index operator overload from libcore, so when the
index range of 1..3 is computed, the type system needs to compute what the
types of index are; this works by integer inference variables
Range<<integer>> that need to be unified with the impl Index for
Range<Usize> which computes the real type of usize for the index. This is
fine but what happens when we have the Copy and Clone traits bounds which
have implementations for all the primitive types i8, i16, i32, i64...
which is valid for any integer inference variable so the code prior to this
patch would have grabbed the first impl it would have found and used it
which is incorrect. When we have integer or float inference variables we
need to look for their respective defaults or emit an ambigious type bound
error.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.h: add const infterface
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): make const
(SubstitutionRef::monomorphize): fix issue
* typecheck/rust-tyty-subst.h: constify interface

15 months agogccrs: Add missing Sized, Copy and Clone lang item mappings
Philip Herron [Tue, 31 Jan 2023 14:39:29 +0000 (14:39 +0000)]
gccrs: Add missing Sized, Copy and Clone lang item mappings

We need these lang items to be defined and later down the line the mappings
will be used to implement proper copy and clone logic.

Fixes #1786

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* util/rust-lang-item.h:

gcc/testsuite/ChangeLog:

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

15 months agogccrs: Fix nullptr dereference
Philip Herron [Tue, 31 Jan 2023 14:27:49 +0000 (14:27 +0000)]
gccrs: Fix nullptr dereference

When we check if this is concrete the guard checks to ensure the argument
is non null but the check here is wrongly returning early when the check
is non null meaning when it is null and therefore not concrete it will
end up doing a null dereference.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc (SubstitutionArg::is_conrete): fix check

15 months agogccrs: Refactor the type unification code
Philip Herron [Mon, 30 Jan 2023 18:19:07 +0000 (18:19 +0000)]
gccrs: Refactor the type unification code

This refactors the unification systems to be a consistent interface using
switch statements and simple functions instead of the old clunky visitor
system. This is more maintainable as it is harder to miss cases when we
can take advantages of switch statements.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* Make-lang.in: update names
* backend/rust-compile-expr.cc (CompileExpr::resolve_method_address):
update to use new interface
* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_borrowed_pointer): likewise
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::unify_site): likewise
* typecheck/rust-tyty.cc (BaseType::destructure): likewise
(InferType::unify): removed old unify interface
(ErrorType::unify): likewise
(ADTType::unify): likewise
(TupleType::unify): likewise
(FnType::unify): likewise
(FnPtr::unify): likewise
(ClosureType::unify): likewise
(ArrayType::unify): likewise
(SliceType::unify): likewise
(BoolType::unify): likewise
(IntType::unify): likewise
(UintType::unify): likewise
(FloatType::unify): likewise
(USizeType::unify): likewise
(ISizeType::unify): likewise
(CharType::unify): likewise
(ReferenceType::unify): likewise
(PointerType::unify): likewise
(ParamType::unify): likewise
(StrType::unify): likewise
(NeverType::unify): likewise
(PlaceholderType::unify): likewise
(ProjectionType::unify): likewise
(DynamicObjectType::unify): likewise
* typecheck/rust-tyty.h: update destructure interface
* typecheck/rust-tyty-rules.h: Removed.
* typecheck/rust-unify.cc: New file.
* typecheck/rust-unify.h: New file.

gcc/testsuite/ChangeLog:

* rust/compile/never_type_err1.rs: Moved to...
* rust/compile/never_type1.rs: ...here. It now works

15 months agogccrs: Remove monomorphization hack to setup possible associated types
Philip Herron [Fri, 27 Jan 2023 15:38:58 +0000 (15:38 +0000)]
gccrs: Remove monomorphization hack to setup possible associated types

During CallExpr argument type checking we may be calling a default
implementation of a trait function this will require any possible
associated types to be resolved and setup. This monomoprhization call does
this but it will premtivly do extra unification of types which will throw
off type checking later on. This fix is required for my work into type
bounds checking.

Fixes #1773

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-reference.h: change interface to return self
* typecheck/rust-hir-trait-resolve.cc: likewise
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): likewise
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): remove monomorphization hack

gcc/testsuite/ChangeLog:

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

15 months agogccrs: Add missing param subst callback
Philip Herron [Fri, 27 Jan 2023 18:49:53 +0000 (18:49 +0000)]
gccrs: Add missing param subst callback

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc: add missing callback

15 months agogccrs: Clear the substitution callbacks when copying ArgumentMappings
Philip Herron [Fri, 27 Jan 2023 18:31:11 +0000 (18:31 +0000)]
gccrs: Clear the substitution callbacks when copying ArgumentMappings

When we set the callback on substitutions this is not safe to be copied
around since we store the used argument mappings and can reuse them in
different contexts. This clears the callback on copy's to make it safer.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty-subst.cc: update copy constructors

15 months agogccrs: Refactor handle_substitutions to take a reference
Philip Herron [Fri, 27 Jan 2023 18:28:06 +0000 (18:28 +0000)]
gccrs: Refactor handle_substitutions to take a reference

This patch changes the recusive substitution code to take a reference
instead of a copy. This is important as the callback field is going to be
made non-copyable in a future patch and this pipeline is for recursive
substitutions so its ok to reuse the same mappings here.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc: refactor to take a reference
* typecheck/rust-tyty-subst.cc: likewise
(SubstitutionRef::get_substitution_arguments): likewise
(SubstitutionRef::infer_substitions): likewise
* typecheck/rust-tyty-subst.h: likewise
* typecheck/rust-tyty.cc (ADTType::handle_substitions): likewise
(TupleType::handle_substitions): likewise
(FnType::handle_substitions): likewise
(ClosureType::handle_substitions): likewise
(ArrayType::handle_substitions): likewise
(SliceType::handle_substitions): likewise
(ReferenceType::handle_substitions): likewise
(PointerType::handle_substitions): likewise
(ParamType::handle_substitions): likewise
(ProjectionType::handle_substitions): likewise
* typecheck/rust-tyty.h: likewise

15 months agogccrs: Rename header rust-hir-trait-ref.h to rust-hir-trait-reference.h
Philip Herron [Tue, 17 Jan 2023 22:45:52 +0000 (22:45 +0000)]
gccrs: Rename header rust-hir-trait-ref.h to rust-hir-trait-reference.h

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-trait-ref.h: Moved to...
* typecheck/rust-hir-trait-reference.h: ...here.
* typecheck/rust-hir-trait-resolve.cc: refactor
* typecheck/rust-hir-trait-resolve.h (RUST_HIR_TRAIT_RESOLVE_H): likewise
* typecheck/rust-hir-type-check.h: likewise
* typecheck/rust-tyty.cc: likewise

15 months agogccrs: Rename rust-tyctx.cc to rust-typecheck-context.cc
Philip Herron [Mon, 16 Jan 2023 19:31:11 +0000 (19:31 +0000)]
gccrs: Rename rust-tyctx.cc to rust-typecheck-context.cc

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* Make-lang.in: update name
* typecheck/rust-tyctx.cc: Moved to...
* typecheck/rust-typecheck-context.cc: ...here.

15 months agogccrs: Refactor all code out of the rust-tyty.h header
Philip Herron [Mon, 16 Jan 2023 19:27:36 +0000 (19:27 +0000)]
gccrs: Refactor all code out of the rust-tyty.h header

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check.h: refactor
* typecheck/rust-tyctx.cc (TypeCheckContext::iterate): refactor
(TypeCheckContext::have_loop_context): likewise
(TypeCheckContext::push_new_loop_context): likewise
(TypeCheckContext::push_new_while_loop_context): likewise
(TypeCheckContext::peek_loop_context): likewise
(TypeCheckContext::pop_loop_context): likewise
(TypeCheckContext::swap_head_loop_context): likewise
(TypeCheckContext::insert_trait_reference): likewise
(TypeCheckContext::lookup_trait_reference): likewise
(TypeCheckContext::insert_receiver): likewise
(TypeCheckContext::lookup_receiver): likewise
(TypeCheckContext::insert_associated_type_mapping): likewise
(TypeCheckContext::clear_associated_type_mapping): likewise
(TypeCheckContext::lookup_associated_type_mapping): likewise
(TypeCheckContext::insert_variant_definition): likewise
(TypeCheckContext::lookup_variant_definition): likewise
(TypeCheckContext::insert_operator_overload): likewise
(TypeCheckContext::lookup_operator_overload): likewise
(TypeCheckContext::insert_unconstrained_check_marker): likewise
(TypeCheckContext::have_checked_for_unconstrained): likewise
(TypeCheckContext::insert_resolved_predicate): likewise
(TypeCheckContext::lookup_predicate): likewise
(TypeCheckContext::insert_query): likewise
(TypeCheckContext::query_completed): likewise
(TypeCheckContext::query_in_progress): likewise
(TypeCheckContext::insert_trait_query): likewise
(TypeCheckContext::trait_query_completed): likewise
(TypeCheckContext::trait_query_in_progress): likewise
(TypeCheckContextItem::Item::Item): likewise
(TypeCheckContextItem::TypeCheckContextItem): likewise
(TypeCheckContextItem::get_item): likewise
(TypeCheckContextItem::get_impl_item): likewise
(TypeCheckContextItem::get_trait_item): likewise
(TypeCheckContextItem::get_type): likewise
* typecheck/rust-tyty.cc (StructFieldType::StructFieldType): likewise
(StructFieldType::get_ref): likewise
(StructFieldType::get_name): likewise
(StructFieldType::get_field_type): likewise
(StructFieldType::set_field_type): likewise
(StructFieldType::is_concrete): likewise
(StructFieldType::debug): likewise
(StructFieldType::get_locus): likewise
(VariantDef::variant_type_string): likewise
(VariantDef::VariantDef): likewise
(VariantDef::operator=): likewise
(VariantDef::get_error_node): likewise
(VariantDef::is_error): likewise
(VariantDef::get_id): likewise
(VariantDef::get_defid): likewise
(VariantDef::get_variant_type): likewise
(VariantDef::is_data_variant): likewise
(VariantDef::is_dataless_variant): likewise
(VariantDef::get_identifier): likewise
(VariantDef::num_fields): likewise
(VariantDef::get_field_at_index): likewise
(VariantDef::get_fields): likewise
(VariantDef::lookup_field): likewise
(VariantDef::get_discriminant): likewise
(VariantDef::as_string): likewise
(VariantDef::is_equal): likewise
(VariantDef::clone): likewise
(VariantDef::monomorphized_clone): likewise
(VariantDef::get_ident): likewise
(TupleType::TupleType): likewise
(TupleType::get_unit_type): likewise
(TupleType::is_unit): likewise
(TupleType::num_fields): likewise
(TupleType::is_concrete): likewise
(TupleType::get_fields): likewise
(BoolType::BoolType): likewise
(BoolType::get_name): likewise
(BoolType::is_concrete): likewise
(IntType::IntType): likewise
(IntType::get_name): likewise
(IntType::get_int_kind): likewise
(IntType::is_concrete): likewise
(UintType::UintType): likewise
(UintType::get_name): likewise
(UintType::get_uint_kind): likewise
(UintType::is_concrete): likewise
(FloatType::FloatType): likewise
(FloatType::get_name): likewise
(FloatType::get_float_kind): likewise
(FloatType::is_concrete): likewise
(USizeType::USizeType): likewise
(USizeType::get_name): likewise
(USizeType::is_concrete): likewise
(ISizeType::ISizeType): likewise
(ISizeType::get_name): likewise
(ISizeType::is_concrete): likewise
(CharType::CharType): likewise
(CharType::is_concrete): likewise
(CharType::get_name): likewise
(ReferenceType::ReferenceType): likewise
(ReferenceType::is_concrete): likewise
(ReferenceType::mutability): likewise
(ReferenceType::is_mutable): likewise
(ReferenceType::is_dyn_object): likewise
(ReferenceType::is_dyn_slice_type): likewise
(ReferenceType::is_dyn_str_type): likewise
(PointerType::PointerType): likewise
(PointerType::is_concrete): likewise
(PointerType::mutability): likewise
(PointerType::is_mutable): likewise
(PointerType::is_const): likewise
(PointerType::is_dyn_object): likewise
(PointerType::is_dyn_slice_type): likewise
(PointerType::is_dyn_str_type): likewise
(ParamType::ParamType): likewise
(ParamType::get_generic_param): likewise
(ParamType::can_resolve): likewise
(ParamType::is_concrete): likewise
(StrType::StrType): likewise
(StrType::get_name): likewise
(StrType::is_concrete): likewise
(NeverType::NeverType): likewise
(NeverType::get_name): likewise
(NeverType::is_unit): likewise
(NeverType::is_concrete): likewise
(PlaceholderType::PlaceholderType): likewise
(PlaceholderType::get_name): likewise
(PlaceholderType::is_unit): likewise
(PlaceholderType::get_symbol): likewise
(PlaceholderType::is_concrete): likewise
(ProjectionType::is_unit): likewise
(ProjectionType::get_name): likewise
(ProjectionType::needs_generic_substitutions): likewise
(ProjectionType::supports_substitutions): likewise
(ProjectionType::has_subsititions_defined): likewise
(ProjectionType::get): likewise
(ProjectionType::is_concrete): likewise
(DynamicObjectType::is_concrete): likewise
* typecheck/rust-tyty.h: likewise

15 months agogccrs: Refactor PathProbeType code into CC file
Philip Herron [Mon, 16 Jan 2023 17:54:41 +0000 (17:54 +0000)]
gccrs: Refactor PathProbeType code into CC file

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc (PathProbeCandidate::Candidate::Candidate): refactor
(PathProbeCandidate::PathProbeCandidate): likewise
(PathProbeCandidate::as_string): likewise
(PathProbeCandidate::is_enum_candidate): likewise
(PathProbeCandidate::is_impl_candidate): likewise
(PathProbeCandidate::is_trait_candidate): likewise
(PathProbeCandidate::is_full_trait_item_candidate): likewise
(PathProbeCandidate::get_error): likewise
(PathProbeCandidate::is_error): likewise
(PathProbeCandidate::get_defid): likewise
(PathProbeCandidate::operator<): likewise
* typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): likewise

15 months agogccrs: Refactor PathProbe into cc file
Philip Herron [Mon, 16 Jan 2023 17:08:14 +0000 (17:08 +0000)]
gccrs: Refactor PathProbe into cc file

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-hir-path-probe.cc (PathProbeType::PathProbeType): refactor
(PathProbeType::Probe): likewise
(PathProbeType::visit): likewise
(PathProbeType::process_enum_item_for_candiates): likewise
(PathProbeType::process_impl_items_for_candidates): likewise
(PathProbeType::is_reciever_generic): likewise
(PathProbeImplTrait::PathProbeImplTrait): likewise
(PathProbeImplTrait::Probe): likewise
(PathProbeImplTrait::process_trait_impl_items_for_candidates): likewise
* typecheck/rust-hir-path-probe.h (struct PathProbeCandidate): likewise
* typecheck/rust-hir-trait-resolve.cc
(PathProbeImplTrait::process_trait_impl_items_for_candidates): likewise

15 months agogccrs: Refactor BaseType, InferType and ErrorType impl into cc file
Philip Herron [Sat, 14 Jan 2023 23:54:19 +0000 (23:54 +0000)]
gccrs: Refactor BaseType, InferType and ErrorType impl into cc file

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty.cc (BaseType::BaseType): refactor
(BaseType::~BaseType): likewise
(BaseType::get_ref): likewise
(BaseType::set_ref): likewise
(BaseType::get_ty_ref): likewise
(BaseType::set_ty_ref): likewise
(BaseType::is_equal): likewise
(BaseType::is_unit): likewise
(BaseType::get_kind): likewise
(BaseType::get_combined_refs): likewise
(BaseType::append_reference): likewise
(BaseType::supports_substitutions): likewise
(BaseType::has_subsititions_defined): likewise
(BaseType::can_substitute): likewise
(BaseType::needs_generic_substitutions): likewise
(BaseType::contains_type_parameters): likewise
(BaseType::get_ident): likewise
(BaseType::get_locus): likewise
(InferType::InferType): likewise
(InferType::get_infer_kind): likewise
(InferType::get_name): likewise
(InferType::is_concrete): likewise
(ErrorType::ErrorType): likewise
(ErrorType::is_unit): likewise
(ErrorType::is_concrete): likewise
(ErrorType::get_name): likewise
(ErrorType::monomorphized_clone): likewise
* typecheck/rust-tyty.h (class SubstitutionArgumentMappings): likewise

15 months agogccrs: Refactor all substitution mapper code implementation into its own CC file
Philip Herron [Sat, 14 Jan 2023 23:36:47 +0000 (23:36 +0000)]
gccrs: Refactor all substitution mapper code implementation into its own CC file

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-substitution-mapper.cc (SubstMapper::SubstMapper): refactor
(SubstMapper::Resolve): likewise
(SubstMapper::InferSubst): likewise
(SubstMapper::have_generic_args): likewise
(SubstMapper::visit): likewise
(SubstMapperInternal::visit): likewise
(SubstMapperFromExisting::SubstMapperFromExisting): likewise
(SubstMapperFromExisting::Resolve): likewise
(SubstMapperFromExisting::visit): likewise
(GetUsedSubstArgs::GetUsedSubstArgs): likewise
(GetUsedSubstArgs::From): likewise
(GetUsedSubstArgs::visit): likewise
* typecheck/rust-substitution-mapper.h: refactor
* typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_generic_param): likewise

15 months agogccrs: Refactor SubstitutionRef base class into its own CC file
Philip Herron [Sat, 14 Jan 2023 23:22:59 +0000 (23:22 +0000)]
gccrs: Refactor SubstitutionRef base class into its own CC file

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* Make-lang.in: update the makefile
* typecheck/rust-tyty.cc (SubstitutionParamMapping::need_substitution): likewise
(SubstitutionParamMapping::override_context): likewise
(SubstitutionRef::get_mappings_from_generic_args): likewise
(SubstitutionRef::infer_substitions): likewise
(SubstitutionRef::are_mappings_bound): likewise
(SubstitutionRef::solve_missing_mappings_from_this): likewise
(SubstitutionRef::monomorphize): likewise
* typecheck/rust-tyty.h (class SubstitutionParamMapping): likewise
(class SubstitutionArg): likewise
(std::function<void): likewise
(class SubstitutionArgumentMappings): likewise
(class SubstitutionRef): likewise
* typecheck/rust-tyty-subst.cc: New file.
* typecheck/rust-tyty-subst.h: New file.

15 months agogccrs: Refactor TyVar and TypeBoundPredicates
Philip Herron [Thu, 12 Jan 2023 18:00:52 +0000 (18:00 +0000)]
gccrs: Refactor TyVar and TypeBoundPredicates

This extract these helpers into seperate files

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* Make-lang.in: update makefile
* typecheck/rust-tyty.cc (TyVar::TyVar): move to new file
(TyVar::get_tyty): likewise
(TyVar::get_implicit_infer_var): likewise
(TyVar::subst_covariant_var): likewise
(TyVar::clone): likewise
(TyVar::monomorphized_clone): likewise
(TyWithLocation::TyWithLocation): likewise
* typecheck/rust-tyty.h (class BaseType): cleanup
(class TypeBoundPredicate): move to its own file
(class TypeBoundPredicateItem): likewise
(class TypeBoundsMappings): likewise
(class TyVar): likewise
(class TyWithLocation): likewise
* typecheck/rust-tyty-bounds.h: New file.
* typecheck/rust-tyty-util.cc: New file.
* typecheck/rust-tyty-util.h: New file.

15 months agogccrs: Move TypePredicateItem impl out of the header
Philip Herron [Thu, 12 Jan 2023 16:40:30 +0000 (16:40 +0000)]
gccrs: Move TypePredicateItem impl out of the header

This moves the implementation code out of the header and into its
respective cc file.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

* typecheck/rust-tyty-bounds.cc (TypeBoundPredicateItem::error): refactor
(TypeBoundPredicateItem::is_error): likewise
(TypeBoundPredicateItem::get_parent): likewise
* typecheck/rust-tyty.h: Move the implementation for the above

15 months agogccrs: Add another test case for passing associated type-bounds
Philip Herron [Thu, 12 Jan 2023 16:22:17 +0000 (16:22 +0000)]
gccrs: Add another test case for passing associated type-bounds

This demonstrates that this also works for custom algebraic data types too.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
15 months agogccrs: Removed comment copy-pasted from gcc/tree.def
Owen Avery [Sat, 4 Feb 2023 17:07:38 +0000 (12:07 -0500)]
gccrs: Removed comment copy-pasted from gcc/tree.def

gcc/rust/ChangeLog:

* backend/rust-compile-expr.cc (CompileExpr::visit): Removed copy-pasted comment.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add support for feature check.
mxlol233 [Thu, 12 Jan 2023 14:08:57 +0000 (22:08 +0800)]
gccrs: Add  support for feature check.

This commit implements a very basic feature checking module.

gcc/rust/ChangeLog:

* Make-lang.in: Add object files: `rust-feature.o` and `rust-feature-gate.o`
* checks/errors/rust-feature-gate.cc: New file.
* checks/errors/rust-feature-gate.h: New file.
* checks/errors/rust-feature.cc: New file.
* checks/errors/rust-feature.h: New file.
* rust-session-manager.cc: Add FeatureGate check.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Xiao Ma <mxlol233@outlook.com>
15 months agogccrs: parser: Fix parsing of closure param list
Arthur Cohen [Thu, 2 Feb 2023 14:32:17 +0000 (15:32 +0100)]
gccrs: parser: Fix parsing of closure param list

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_closure_expr): Advance tokens
properly when parsing closure param list.

gcc/testsuite/ChangeLog:

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

15 months agogccrs: parser: Improve parsing of complex generic arguments
Arthur Cohen [Wed, 1 Feb 2023 11:41:47 +0000 (12:41 +0100)]
gccrs: parser: Improve parsing of complex generic arguments

The parser was missing code for handling complex type arguments such
as type paths or nested generics.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_generic_arg): Handle type
paths and nested generics properly.

gcc/testsuite/ChangeLog:

* rust/compile/parse_complex_generic_application.rs: New test.
* rust/compile/parse_complex_generic_application2.rs: New test.

15 months agogccrs: Implement lowering ReferencePattern from AST to HIR
Owen Avery [Thu, 2 Feb 2023 05:05:36 +0000 (00:05 -0500)]
gccrs: Implement lowering ReferencePattern from AST to HIR

gcc/rust/ChangeLog:

* ast/rust-pattern.h:
(ReferencePattern::is_double_reference): Add method.
(ReferencePattern::get_is_mut): Add method.
* hir/rust-ast-lower-pattern.cc
(ASTLoweringPattern::visit): Add ReferencePattern visitor.
* hir/rust-ast-lower-pattern.h:
(ASTLoweringPattern::visit): Add ReferencePattern visitor.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Optimize HIR::ReferencePattern
Owen Avery [Thu, 2 Feb 2023 16:38:44 +0000 (11:38 -0500)]
gccrs: Optimize HIR::ReferencePattern

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h
(class ReferencePattern): Remove has_two_amps field.
* hir/tree/rust-hir-full-test.cc
(ReferencePattern::as_string): Remove usage of ReferencePattern::has_two_amps.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Remove HIR::GroupedPattern
Owen Avery [Tue, 31 Jan 2023 01:14:34 +0000 (20:14 -0500)]
gccrs: Remove HIR::GroupedPattern

gcc/rust/ChangeLog:

* backend/rust-compile-fnparam.h
(CompileFnParam::visit): Remove HIR::GroupedPattern visitor.
* backend/rust-compile-pattern.cc
(CompilePatternCaseLabelExpr::visit): Remove HIR::GroupedPattern visitor.
(CompilePatternBindings::visit): Remove HIR::GroupedPattern visitor.
* backend/rust-compile-pattern.h
(CompilePatternCaseLabelExpr::visit): Remove HIR::GroupedPattern visitor.
(CompilePatternBindings::visit): Remove HIR::GroupedPattern visitor.
(CompilePatternLet::visit): Remove HIR::GroupedPattern visitor.
* backend/rust-compile-resolve-path.h
(ResolvePathRef::visit): Remove HIR::GroupedPattern visitor.
* backend/rust-compile-var-decl.h
(CompileVarDecl::visit): Remove HIR::GroupedPattern visitor.
* checks/errors/rust-const-checker.cc
(ConstChecker::visit): Remove HIR::GroupedPattern visitor.
* checks/errors/rust-const-checker.h
(ConstChecker::visit): Remove HIR::GroupedPattern visitor.
* checks/errors/rust-unsafe-checker.cc
(UnsafeChecker::visit): Remove HIR::GroupedPattern visitor.
* checks/errors/rust-unsafe-checker.h
(UnsafeChecker::visit): Remove HIR::GroupedPattern visitor.
* hir/rust-hir-dump.cc (Dump::visit): Remove HIR::GroupedPattern visitor.
* hir/rust-hir-dump.h (Dump::visit): Remove HIR::GroupedPattern visitor.
* hir/tree/rust-hir-full-decls.h (class GroupedPattern): Remove class.
* hir/tree/rust-hir-full-test.cc (GroupedPattern::accept_vis): Remove method.
* hir/tree/rust-hir-pattern.h (class GroupedPattern): Remove class.
* hir/tree/rust-hir-visitor.h
(HIRFullVisitor::visit): Remove HIR::GroupedPattern visitor.
(HIRFullVisitorBase::visit): Remove HIR::GroupedPattern visitor.
(HIRPatternVisitor::visit): Remove HIR::GroupedPattern visitor.
* typecheck/rust-hir-type-check-pattern.cc
(TypeCheckPattern::visit): Remove HIR::GroupedPattern visitor.
* typecheck/rust-hir-type-check-pattern.h
(TypeCheckPattern::visit): Remove HIR::GroupedPattern visitor.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Improve GroupedPattern lowering
Owen Avery [Tue, 31 Jan 2023 01:13:52 +0000 (20:13 -0500)]
gccrs: Improve GroupedPattern lowering

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc
(ASTLoweringPattern::visit): Lower AST::GroupedPattern to its inner pattern.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Move rust-buffered-queue.h to util folder #1766
MAHAD [Wed, 1 Feb 2023 17:44:00 +0000 (22:44 +0500)]
gccrs: Move rust-buffered-queue.h to util folder #1766

gcc/rust/ChangeLog:

* rust-buffered-queue.h: Moved to...
* util/rust-buffered-queue.h: ...here.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
15 months agogccrs: parser: Allow parsing multiple reference types
Arthur Cohen [Wed, 1 Feb 2023 10:40:13 +0000 (11:40 +0100)]
gccrs: parser: Allow parsing multiple reference types

The parser now recursively tries to parse a reference type after seeing
a `&` or `&&` token.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_type): Handle double ampersan
properly
(Parser::parse_reference_type): Call into `parse_reference_type_inner`
and wrap double reference types in another `AST::ReferenceType` node
(Parser::parse_reference_type_inner): Add parsing implementation
which does not care about the leading token (& or  &&)
(Parser::parse_type_no_bounds): Handle double ampersand properly
* parse/rust-parse.h: Declare `parse_reference_type_inner`

gcc/testsuite/ChangeLog:

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

15 months agogccrs: Create and use CompilePatternLet visitor for compiling let statments
Owen Avery [Fri, 27 Jan 2023 16:47:30 +0000 (11:47 -0500)]
gccrs: Create and use CompilePatternLet visitor for compiling let statments

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternLet::visit): New function.
* backend/rust-compile-stmt.cc (CompileStmt::visit): Likewise.
* backend/rust-compile-pattern.h (class CompilePatternLet): New visitor.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: macro: Allow builtin `MacroInvocation`s within the AST
Arthur Cohen [Wed, 11 Jan 2023 14:29:22 +0000 (15:29 +0100)]
gccrs: macro: Allow builtin `MacroInvocation`s within the AST

gcc/rust/ChangeLog:

* ast/rust-macro.h (enum class): Add `BuiltinMacro` enum class.
* expand/rust-attribute-visitor.cc (AttrVisitor::visit): Mention
switching on `macro.kind` once builtin macro invocations are properly
handled.
* parse/rust-parse-impl.h (Parser::parse_macro_invocation): Switch to new MacroInvocation
API.
(Parser::parse_type): Likewise.
(Parser::parse_type_no_bounds): Likewise.

15 months agogccrs: fixed indentations in AST pretty expanded dump of trait
Abdul Rafey [Wed, 1 Feb 2023 05:32:16 +0000 (11:02 +0530)]
gccrs: fixed indentations in AST pretty expanded dump of trait

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::visit): removed extra indentations in trait ast dump

Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
15 months agogccrs: fixed compiler error message on wildcard pattern within expression
Abdul Rafey [Sun, 29 Jan 2023 11:35:23 +0000 (17:05 +0530)]
gccrs: fixed compiler error message on wildcard pattern within expression

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::null_denotation): Add proper error
when seeing wildcard var on right side of assignment.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
15 months agogccrs: moved operator.h to util/rust-operators.h
Abdul Rafey [Sun, 29 Jan 2023 11:29:17 +0000 (16:59 +0530)]
gccrs: moved operator.h to util/rust-operators.h

gcc/rust/ChangeLog:

* ast/rust-ast.cc: Fix include list.
* ast/rust-expr.h: Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* rust-backend.h: Likewise.
* util/rust-lang-item.h: Likewise.
* operator.h: Moved to...
* util/rust-operators.h: ...here.

Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
15 months agogccrs: Rename file rust-ast-full-test.cc to rust-ast.cc
Parthib [Sat, 28 Jan 2023 16:37:45 +0000 (22:07 +0530)]
gccrs: Rename file rust-ast-full-test.cc to rust-ast.cc

gcc/rust/ChangeLog:

* Make-lang.in: Rename object file.
* ast/rust-ast-full-test.cc: Moved to...
* ast/rust-ast.cc: ...here.

15 months agogccrs: Added missing GroupedPattern visitors for code generation
Owen Avery [Wed, 11 Jan 2023 16:57:28 +0000 (11:57 -0500)]
gccrs: Added missing GroupedPattern visitors for code generation

gcc/rust/ChangeLog:

* backend/rust-compile-pattern.cc (CompilePatternCaseLabelExpr::visit): Add proper
visitor.
(CompilePatternBindings::visit): Likewise.
* backend/rust-compile-pattern.h: Declare them.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add type resolution for grouped patterns
Owen Avery [Wed, 11 Jan 2023 16:56:05 +0000 (11:56 -0500)]
gccrs: Add type resolution for grouped patterns

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Add proper
visitor.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add get_item method for HIR::GroupedPattern
Owen Avery [Wed, 25 Jan 2023 18:00:38 +0000 (13:00 -0500)]
gccrs: Add get_item method for HIR::GroupedPattern

gcc/rust/ChangeLog:

* hir/tree/rust-hir-pattern.h: Add get_item method.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Add HIR lowering for GroupedPattern
Owen Avery [Wed, 11 Jan 2023 16:54:54 +0000 (11:54 -0500)]
gccrs: Add HIR lowering for GroupedPattern

gcc/rust/ChangeLog:

* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Add proper visitor.
* hir/rust-ast-lower-pattern.h: Declare it.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Do not crash on empty macros expand. Fixes #1712
Lyra [Tue, 24 Jan 2023 13:15:42 +0000 (14:15 +0100)]
gccrs: Do not crash on empty macros expand. Fixes #1712

This commit fixes a compiler crash when expanding an empty macro into an existing AST.

gcc/rust/ChangeLog:

* expand/rust-macro-expand.cc (transcribe_expression): Fix ICE when expanding
empty macros.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Lyra Karenai <teromene@teromene.fr>
15 months agogccrs: Support GroupedPattern during name resolution
Owen Avery [Wed, 11 Jan 2023 16:53:51 +0000 (11:53 -0500)]
gccrs: Support GroupedPattern during name resolution

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-pattern.h: Support GroupedPattern properly.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: testsuite: Handle Windows carriage returns properly
Arthur Cohen [Wed, 11 Jan 2023 10:36:11 +0000 (11:36 +0100)]
gccrs: testsuite: Handle Windows carriage returns properly

In dg-output, check for \r* carriage returns to make sure execution
tests pass on windows platforms

gcc/testsuite/ChangeLog:

* rust/execute/torture/builtin_macro_cfg.rs: Handle carriage returns
properly.
* rust/execute/torture/builtin_macro_concat.rs: Likewise.
* rust/execute/torture/builtin_macro_env.rs: Likewise.
* rust/execute/torture/builtin_macro_include_bytes.rs: Likewise.
* rust/execute/torture/builtin_macro_include_str.rs: Likewise.
* rust/execute/torture/builtin_macro_line.rs: Likewise.
* rust/execute/torture/builtin_macros1.rs: Likewise.
* rust/execute/torture/builtin_macros3.rs: Likewise.
* rust/execute/torture/cfg1.rs: Likewise.
* rust/execute/torture/cfg2.rs: Likewise.
* rust/execute/torture/cfg3.rs: Likewise.
* rust/execute/torture/cfg4.rs: Likewise.
* rust/execute/torture/coercion1.rs: Likewise.
* rust/execute/torture/coercion2.rs: Likewise.
* rust/execute/torture/extern_mod4.rs: Likewise.
* rust/execute/torture/helloworld1.rs: Likewise.
* rust/execute/torture/helloworld2.rs: Likewise.
* rust/execute/torture/issue-1198.rs: Likewise.
* rust/execute/torture/issue-1231.rs: Likewise.
* rust/execute/torture/issue-1232.rs: Likewise.
* rust/execute/torture/issue-1249.rs: Likewise.
* rust/execute/torture/issue-1436.rs: Likewise.
* rust/execute/torture/issue-1496.rs: Likewise.
* rust/execute/torture/issue-647.rs: Likewise.
* rust/execute/torture/issue-845.rs: Likewise.
* rust/execute/torture/issue-851.rs: Likewise.
* rust/execute/torture/issue-858.rs: Likewise.
* rust/execute/torture/issue-976.rs: Likewise.
* rust/execute/torture/macros10.rs: Likewise.
* rust/execute/torture/macros11.rs: Likewise.
* rust/execute/torture/macros12.rs: Likewise.
* rust/execute/torture/macros13.rs: Likewise.
* rust/execute/torture/macros14.rs: Likewise.
* rust/execute/torture/macros2.rs: Likewise.
* rust/execute/torture/macros22.rs: Likewise.
* rust/execute/torture/macros29.rs: Likewise.
* rust/execute/torture/macros3.rs: Likewise.
* rust/execute/torture/macros30.rs: Likewise.
* rust/execute/torture/macros31.rs: Likewise.
* rust/execute/torture/macros7.rs: Likewise.
* rust/execute/torture/macros8.rs: Likewise.
* rust/execute/torture/macros9.rs: Likewise.
* rust/execute/torture/match1.rs: Likewise.
* rust/execute/torture/match2.rs: Likewise.
* rust/execute/torture/match3.rs: Likewise.
* rust/execute/torture/match_bool1.rs: Likewise.
* rust/execute/torture/match_byte1.rs: Likewise.
* rust/execute/torture/match_char1.rs: Likewise.
* rust/execute/torture/match_int1.rs: Likewise.
* rust/execute/torture/match_loop1.rs: Likewise.
* rust/execute/torture/match_range1.rs: Likewise.
* rust/execute/torture/match_range2.rs: Likewise.
* rust/execute/torture/match_tuple1.rs: Likewise.
* rust/execute/torture/method1.rs: Likewise.
* rust/execute/torture/method2.rs: Likewise.
* rust/execute/torture/method3.rs: Likewise.
* rust/execute/torture/method4.rs: Likewise.
* rust/execute/torture/operator_overload_1.rs: Likewise.
* rust/execute/torture/operator_overload_10.rs: Likewise.
* rust/execute/torture/operator_overload_11.rs: Likewise.
* rust/execute/torture/operator_overload_12.rs: Likewise.
* rust/execute/torture/operator_overload_2.rs: Likewise.
* rust/execute/torture/operator_overload_4.rs: Likewise.
* rust/execute/torture/operator_overload_5.rs: Likewise.
* rust/execute/torture/operator_overload_6.rs: Likewise.
* rust/execute/torture/operator_overload_7.rs: Likewise.
* rust/execute/torture/operator_overload_8.rs: Likewise.
* rust/execute/torture/operator_overload_9.rs: Likewise.
* rust/execute/torture/str-layout1.rs: Likewise.
* rust/execute/torture/str-zero.rs: Likewise.
* rust/execute/torture/trait1.rs: Likewise.
* rust/execute/torture/trait10.rs: Likewise.
* rust/execute/torture/trait11.rs: Likewise.
* rust/execute/torture/trait12.rs: Likewise.
* rust/execute/torture/trait13.rs: Likewise.
* rust/execute/torture/trait2.rs: Likewise.
* rust/execute/torture/trait3.rs: Likewise.
* rust/execute/torture/trait4.rs: Likewise.
* rust/execute/torture/trait5.rs: Likewise.
* rust/execute/torture/trait6.rs: Likewise.
* rust/execute/torture/trait7.rs: Likewise.
* rust/execute/torture/trait8.rs: Likewise.
* rust/execute/torture/trait9.rs: Likewise.
* rust/execute/torture/closure2.rs: Likewise.
* rust/execute/torture/closure3.rs: Likewise.
* rust/execute/torture/loop-condition-eval.rs: Likewise.
* rust/execute/torture/operator_overload_3.rs: Likewise.

15 months agogccrs: Change how CompileVarDecl outputs Bvariable's
Owen Avery [Wed, 11 Jan 2023 17:05:39 +0000 (12:05 -0500)]
gccrs: Change how CompileVarDecl outputs Bvariable's

This allows patterns to declare multiple/no variables

gcc/rust/ChangeLog:

* backend/rust-compile-base.cc (HIRCompileBase::compile_locals_for_block):
Allow patterns to declare zero or multiple variables.
* backend/rust-compile-var-decl.h: Change function declaration.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: diagnostics: Add underline for tokens in diagnostics.
mxlol233 [Wed, 11 Jan 2023 12:36:13 +0000 (20:36 +0800)]
gccrs: diagnostics: Add underline for tokens in diagnostics.

Currently, the diagnostics only point to the corresponding token's
start position by carets, and lack of underlines for full token.  This
commit add support for such underlines in diagnostics by encoding range
information in location_t.

gcc/rust/ChangeLog:

* lex/rust-lex.cc (Lexer::build_token): Make location enclose entire token.
(Lexer::parse_byte_char): Likewise.
(Lexer::parse_byte_string): Likewise.
(Lexer::parse_raw_byte_string): Likewise.
(Lexer::parse_raw_identifier): Likewise.
(Lexer::parse_string): Likewise.
(Lexer::parse_identifier_or_keyword): Likewise.
(Lexer::parse_raw_string): Likewise.
(Lexer::parse_non_decimal_int_literal): Likewise.
(Lexer::parse_decimal_int_or_float): Likewise.
(Lexer::parse_char_or_lifetime): Likewise.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Xiao Ma <mxlol233@outlook.com>
15 months agogccrs: Add get_locus function for abstract class MetaItemInner.
mxlol233 [Wed, 11 Jan 2023 15:24:07 +0000 (23:24 +0800)]
gccrs: Add get_locus function for abstract class MetaItemInner.

This commit adds virtual function get_locus to base class MetaItemInner,
which is helpful when we need to print  diagnostics on some sub-classes of
MetaItemInner.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add get_locus method.
* ast/rust-expr.h: Likewise.
* ast/rust-macro.h: Likewise.

Signed-off-by: Xiao Ma <mxlol233@outlook.com>
15 months agogccrs: Reuse TypeCheckPattern on LetStmt's
Owen Avery [Tue, 10 Jan 2023 00:54:55 +0000 (19:54 -0500)]
gccrs: Reuse TypeCheckPattern on LetStmt's

Update Rust type-checking to reuse TypeCheckPattern on HIR::LetStmt's.
This will unify the paths and improve error handling.

gcc/rust/ChangeLog:

* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Cleanup LetStmt
type checking.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
15 months agogccrs: Support associated type bound arguments
Philip Herron [Sat, 7 Jan 2023 14:41:12 +0000 (14:41 +0000)]
gccrs: Support associated type bound arguments

This patch adds support for the GenercArgsBinding type, where you can
specify the associated types of a trait bound using `<Foo=i32>` style
syntax. Note that the type-resolution relys on the i32 impl for Add
as type resolution will resolve the `a+a` to the core::ops::Add method
so code generation will require this to exist.

I have ameded testsuite/rust/compile/bounds.rs as this code is wrongly
creating an HIR::GenericArgs with a trait-object type and causing issues.
the parsing is still correct but we dont have the mechanism to represent
this in AST and HIR properly. I think we will need a new HIR::GenericArgs
AssociatedTypeBindingBound or something similar. We are still lacking
bounds checking during are type coercions and unifications so running this
example using an f32 will wrongly pass type checking, this will need
addressed next.

Fixes #1720

gcc/rust/ChangeLog:

* hir/tree/rust-hir-path.h: Add const get_identifier and get_type method.
* typecheck/rust-hir-path-probe.h: Use new SubstitutionArgumentMappings constructor.
* typecheck/rust-hir-trait-resolve.cc: Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound):
Do not assert failure on size mismatch anymore.
(TypeBoundPredicate::TypeBoundPredicate): Use new SubstitutionArgumentMappings constructor.
(TypeBoundPredicate::operator=): Likewise.
(TypeBoundPredicate::apply_generic_arguments): Likewise.
(TypeBoundPredicateItem::get_tyty_for_receiver): Likewise.
(TypeBoundPredicate::get_num_associated_bindings): Likewise.
(TypeBoundPredicate::lookup_associated_type): Fix implementation for new system.
(TypeBoundPredicate::get_associated_type_items): Likewise.
* typecheck/rust-tyty.cc (SubstitutionRef::get_mappings_from_generic_args): Add new
behavior.
(SubstitutionRef::infer_substitions): Use new constructor and add comment.
(SubstitutionRef::solve_missing_mappings_from_this): Use new constructor.
* typecheck/rust-tyty.h: Define new constructors.

gcc/testsuite/ChangeLog:

* rust/compile/bounds.rs: change to use -fsyntax-only
* rust/execute/torture/issue-1720.rs: New test.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
15 months agogccrs: Add name resolution to generic argument associated item bindings
Philip Herron [Sat, 7 Jan 2023 17:15:23 +0000 (17:15 +0000)]
gccrs: Add name resolution to generic argument associated item bindings

When specifying generic arguments to Traits we can also specify the
associated types using `<BindingName=i32>` syntax we need to add
name resolution to the type argument here and rely on the type
resolution pass to ensure the associated type exists and to setup the
associated types accordingly.

Addresses #1720

gcc/rust/ChangeLog:

* resolve/rust-ast-resolve-type.cc (ResolveGenericArgs::go): Add name resolution to
Trait items.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
15 months agogccrs: Implement declarative macro 2.0 parser
Raiki Tamura [Sun, 18 Dec 2022 16:48:54 +0000 (01:48 +0900)]
gccrs: Implement declarative macro 2.0 parser

gcc/rust/ChangeLog:

* ast/rust-ast-full-decls.h (class MacroItem): Remove forward declaration.
* ast/rust-ast-full-test.cc (MacroRulesDefinition):
Rework MacroRulesDefinition class
* ast/rust-ast.h (class MacroItem): Remove abstract class.
* ast/rust-item.h (class MacroItem): Remove forward declaration.
* ast/rust-macro.h (class MacroItem): Likewise.
(class MacroRulesDefinition): Add MacroKind enum.
(class MacroInvocation): Fix inheritance.
* lex/rust-token.h: Token "macro" is now used.
* parse/rust-parse-impl.h (Parser::parse_item): Add handling for MACRO.
(Parser::parse_vis_item): Call into parse_decl_macro_def.
(Parser::parse_macro_item): Delete function.
(Parser::parse_macro_rules_def): Return MBE macros only.
(Parser::parse_decl_macro_def): New function.
(Parser::parse_stmt): Handle MACRO token.
(Parser::parse_stmt_or_expr_without_block): Call into parse_macro_rules_def.
* parse/rust-parse.h: Declare new function.

gcc/testsuite/ChangeLog:

* rust/compile/decl_macro1.rs: New test.
* rust/compile/decl_macro2.rs: New test.
* rust/compile/decl_macro3.rs: New test.
* rust/compile/decl_macro4.rs: New test.
* rust/compile/decl_macro5.rs: New test.
* rust/compile/decl_macro6.rs: New test.
* rust/compile/decl_macro7.rs: New test.
* rust/execute/torture/decl_macro1.rs: New test.
* rust/execute/torture/decl_macro2.rs: New test.
* rust/execute/torture/decl_macro3.rs: New test.
* rust/execute/torture/decl_macro4.rs: New test.

Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
15 months agogccrs: rust: add bound parsing in parse_generic_arg.
mxlol233 [Wed, 4 Jan 2023 13:21:59 +0000 (21:21 +0800)]
gccrs: rust: add bound parsing in parse_generic_arg.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h (Parser::parse_generic_arg): Add proper bound parsing.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Xiao Ma <mxlol233@outlook.com>
15 months agogccrs: Check for mutable references in const functions
Dave [Mon, 19 Dec 2022 16:59:00 +0000 (10:59 -0600)]
gccrs: Check for mutable references in const functions

Use StackedContext instead. Fix error string

Signed-off-by: Dave Evans <dave@dmetwo.org>
(Squashed commits) Check for mutable references in const functions using StackedContext

gcc/rust/ChangeLog:

* checks/errors/rust-const-checker.cc (ConstChecker::visit): Use StackedContext
class.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Dave Evans <dave@dmetwo.org>
15 months agogccrs: unsafe: check use of `target_feature` attribute
Prajwal S N [Sat, 31 Dec 2022 07:19:02 +0000 (12:49 +0530)]
gccrs: unsafe: check use of `target_feature` attribute

The `target_feature` attribute is for conditional compilation and may or
may not compile on all platforms. Using it requires an unsafe function
or block.

gcc/rust/ChangeLog:

* checks/errors/rust-unsafe-checker.cc (check_target_attr): New function.
(UnsafeChecker::check_function_attr): Call into `check_target_attr`.
(UnsafeChecker::visit): Check for target_feature attributes.
* checks/errors/rust-unsafe-checker.h: Add declarations.
* util/rust-attributes.cc: Add attribute.

gcc/testsuite/ChangeLog:

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

Signed-off-by: Prajwal S N <prajwalnadig21@gmail.com>
15 months agogccrs: fatal_error_flag: Fix typo in error message
Arthur Cohen [Fri, 16 Dec 2022 12:38:36 +0000 (13:38 +0100)]
gccrs: fatal_error_flag: Fix typo in error message

gcc/rust/ChangeLog:

* rust-session-manager.cc (Session::compile_crate): Fix typo.

15 months agoMAINTAINERS: Add myself as CTF and BTF reviewer
Indu Bhagat [Thu, 6 Apr 2023 06:23:33 +0000 (23:23 -0700)]
MAINTAINERS: Add myself as CTF and BTF reviewer

ChangeLog:

* MAINTAINERS: Add myself.

15 months ago[testsuite] enable -maltivec like vect_int for signbit-2.c
Alexandre Oliva [Wed, 5 Apr 2023 14:27:19 +0000 (11:27 -0300)]
[testsuite] enable -maltivec like vect_int for signbit-2.c

Explicitly enable altivec if it's supported.  vect_int tests for
powerpc_altivec_ok, but without the explicit option, if altivec is not
enabled by default, we end up expecting vectorization that doesn't
occur.

for  gcc/testsuite/ChangeLog

* gcc.dg/signbit-2.c: Add -maltivec if supported.

15 months agoFix typo in -param=vect-induction-float= attributes
Andrew Pinski [Thu, 6 Apr 2023 04:13:00 +0000 (21:13 -0700)]
Fix typo in -param=vect-induction-float= attributes

There was a typo in the attributes of the option
-param=vect-induction-float= for IntegerRange.
This fixes that typo.

Committed as obvious after a build/test.

gcc/ChangeLog:

PR tree-optimization/109427
* params.opt (-param=vect-induction-float=):
Fix option attribute typo for IntegerRange.

15 months agotestsuite: fix proc unsupported overriding in modules.exp [PR108899]
Alexandre Oliva [Wed, 5 Apr 2023 14:27:28 +0000 (11:27 -0300)]
testsuite: fix proc unsupported overriding in modules.exp [PR108899]

The overrider of proc unsupported in modules.exp had two problems
reported by Thomas Schwinge, even after Jakub Jelínek's fix:

- it remained in effect while running other dejagnu testsets

- it didn't quote correctly the argument list passed to it, which
  caused test names to be surrounded by curly braces, as in:

UNSUPPORTED: {...}

This patch fixes both issues, obsoleting and reverting Jakub's change,
by dropping the overrider and renaming the saved proc back, and by
using uplevel's argument list splicing.

Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
for  gcc/testsuite/ChangeLog

PR testsuite/108899
* g++.dg/modules/modules.exp (unsupported): Drop renaming.
Fix quoting.

15 months agoDaily bump.
GCC Administrator [Thu, 6 Apr 2023 00:16:43 +0000 (00:16 +0000)]
Daily bump.

15 months agoPR modula2/109423 cc1gm2 ICE if an INCL or EXCL is performed on an unknown set
Gaius Mulley [Wed, 5 Apr 2023 22:07:46 +0000 (23:07 +0100)]
PR modula2/109423 cc1gm2 ICE if an INCL or EXCL is performed on an unknown set

This patch fixes an ICE if attempting to INCL or EXCL on an unknown
set.  The fix was to correct an error format string.  Also included in
the patch are patches to remove unused variables.  The patch also
marks a variable as written in BuildAdr.

gcc/m2/ChangeLog:

PR modula2/109423
* gm2-compiler/M2Base.def (Unbounded): Remove.
* gm2-compiler/M2Error.def (ErrorAbort0): Add noreturn
attribute.
* gm2-compiler/M2Quads.mod (BuildInclProcedure): Correct
error format string.
(BuildExceptProcedure): Correct error format string.
(BuildAdrFunction): Call PutWriteQuad when taking the
address of a variable.
* gm2-libs-ch/SysExceptions.c (_M2_SysExceptions_init): Add
parameters.
* gm2-libs-ch/wrapc.c (_M2_wrapc_init): Add parameters.
* gm2-libs/DynamicStrings.mod (DumpStringInfo): Remove t.
(PopAllocationExemption): Remove f.
* gm2-libs/FIO.mod (BufferedWrite): Remove result.
* gm2-libs/FormatStrings.mod (Copy): Remove endpos and
afterperc.
(HandlePercent): Remove result.
* gm2-libs/Indexing.mod (RemoveIndiceFromIndex): Remove k.
* gm2-libs/M2Dependent.mod (CreateModule): Remove p0
and p1.
(DumpModuleData): Remove mptr.
(ConstructModules): Remove nulp.
* gm2-libs/RTExceptions.mod (PopHandler): Remove i.
* gm2-libs/RTint.mod (Listen): Remove b4s, b4m, afs
and afm.
* gm2-libs/SFIO.mod (ReadS): Remove c.
* gm2-libs/StringConvert.mod (doDecimalPlaces): Remove
whole and fraction.

gcc/testsuite/ChangeLog:

* gm2/pim/fail/setunknown.mod: New test.
PR modula2/109423
* gm2/pim/fail/setunknown2.mod: New test.

Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>
15 months agolibstdc++: Fix some freestanding test failures
Arsen Arsenović [Tue, 4 Apr 2023 21:24:52 +0000 (23:24 +0200)]
libstdc++: Fix some freestanding test failures

At some point, <charconv> was added to the non-hosted bit of the C++17
block, which induced failures in many tests.

In addition, some tests also lacked a dg-require-effective-target hosted
tag.

libstdc++-v3/ChangeLog:

* include/precompiled/stdc++.h (C++17): Don't double-include
<charconv>, once with wrong conditions.
* testsuite/18_support/96817.cc: Require hosted.
* testsuite/18_support/bad_exception/59392.cc: Ditto.
* testsuite/20_util/scoped_allocator/108952.cc: Ditto.
* testsuite/20_util/uses_allocator/lwg3527.cc: Ditto.
* testsuite/29_atomics/atomic/operators/pointer_partial_void.cc:
Ditto.

15 months agolibstdc++: Downgrade DEBUG to ASSERTIONS when !HOSTED
Arsen Arsenović [Tue, 4 Apr 2023 17:25:09 +0000 (19:25 +0200)]
libstdc++: Downgrade DEBUG to ASSERTIONS when !HOSTED

Supporting the debug mode in freestanding is a non-trivial job, so
instead, as a best-effort, enable assertions, which are light and easy.

libstdc++-v3/ChangeLog:

* include/bits/c++config: When __STDC_HOSTED__ is zero,
disable _GLIBCXX_DEBUG and, if it was set, enable
_GLIBCXX_ASSERTIONS.
* testsuite/lib/libstdc++.exp (check_v3_target_debug_mode):
Include <bits/c++config.h> when determining whether debug is
set, in order to inherit the logic from above

15 months agolibstdc++: Add a test for <version> FTM redefinitions
Arsen Arsenović [Wed, 8 Mar 2023 16:01:24 +0000 (17:01 +0100)]
libstdc++: Add a test for <version> FTM redefinitions

This test detects redefinitions by compiling stdc++.h and <version>, by
disabling the system_header pragma on the latter, to allow warnings in
it.  Thanks Patrick Palka for the suggestion.

libstdc++-v3/ChangeLog:

* testsuite/17_intro/versionconflict.cc: New test.
* include/std/version: Allow disabling the system_header pragma
via _GLIBCXX_TESTING_SYSHDR.

15 months agolibstdc++: Harmonize <version> and other headers
Arsen Arsenović [Wed, 8 Mar 2023 11:04:11 +0000 (12:04 +0100)]
libstdc++: Harmonize <version> and other headers

Due to recent, large changes in libstdc++, the feature test macros
declared in <version> got out of sync with the other headers that
possibly declare them.

libstdc++-v3/ChangeLog:

* include/bits/unique_ptr.h (__cpp_lib_constexpr_memory):
Synchronize the definition block with...
* include/bits/ptr_traits.h (__cpp_lib_constexpr_memory):
... this one here.  Also define the 202202L value, rather than
leaving it up to purely unique_ptr.h, so that the value is
synchronized across all headers.
(__gnu_debug::_Safe_iterator_base): Move into new conditional
block.
* include/std/memory (__cpp_lib_atomic_value_initialization):
Define on freestanding under the same conditions as in
atomic_base.h.
* include/std/version (__cpp_lib_robust_nonmodifying_seq_ops):
Also define on freestanding.
(__cpp_lib_to_chars): Ditto.
(__cpp_lib_gcd): Ditto.
(__cpp_lib_gcd_lcm): Ditto.
(__cpp_lib_raw_memory_algorithms): Ditto.
(__cpp_lib_array_constexpr): Ditto.
(__cpp_lib_nonmember_container_access): Ditto.
(__cpp_lib_clamp): Ditto.
(__cpp_lib_constexpr_char_traits): Ditto.
(__cpp_lib_constexpr_string): Ditto.
(__cpp_lib_sample): Ditto.
(__cpp_lib_lcm): Ditto.
(__cpp_lib_constexpr_iterator): Ditto.
(__cpp_lib_constexpr_char_traits): Ditto.
(__cpp_lib_interpolate): Ditto.
(__cpp_lib_constexpr_utility): Ditto.
(__cpp_lib_shift): Ditto.
(__cpp_lib_ranges): Ditto.
(__cpp_lib_move_iterator_concept): Ditto.
(__cpp_lib_constexpr_numeric): Ditto.
(__cpp_lib_constexpr_functional): Ditto.
(__cpp_lib_constexpr_algorithms): Ditto.
(__cpp_lib_constexpr_tuple): Ditto.
(__cpp_lib_constexpr_memory): Ditto.