]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 years agotestsuite: Add empty string macro test
Pierre-Emmanuel Patry [Thu, 9 Feb 2023 17:24:42 +0000 (18:24 +0100)] 
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>
2 years agolex: Prevent directories in RAIIFile
Pierre-Emmanuel Patry [Thu, 9 Feb 2023 09:47:15 +0000 (10:47 +0100)] 
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>
2 years agoSimplify WildcardPattern let statement handling
Owen Avery [Fri, 3 Feb 2023 15:19:32 +0000 (10:19 -0500)] 
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>
2 years agoAdd test
Owen Avery [Mon, 13 Feb 2023 16:29:07 +0000 (11:29 -0500)] 
Add test

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 years agoAdd variadic argument type checking
Owen Avery [Fri, 10 Feb 2023 15:19:24 +0000 (10:19 -0500)] 
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>
2 years agoci: Add missing `merge_group` trigger for workflow
Arthur Cohen [Tue, 14 Feb 2023 15:02:51 +0000 (16:02 +0100)] 
ci: Add missing `merge_group` trigger for workflow

Now that we're using the Github merge queue, this is required to not
let the queue hanging.

ChangeLog:

* .github/workflows/bootstrap.yml: Add missing `merge_group` trigger.
* .github/workflows/ccpp.yml: Likewise.
* .github/workflows/clang-format.yml: Likewise.
* .github/workflows/commit-format.yml: Likewise.

2 years agoMerge #1825
bors[bot] [Tue, 14 Feb 2023 10:23:32 +0000 (10:23 +0000)] 
Merge #1825

1825: Add feature gate for "rust-intrinsic". r=CohenArthur a=TuringKi

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>
Co-authored-by: mxlol233 <mxlol233@outlook.com>
2 years agoAdd feature gate for "rust-intrinsic".
mxlol233 [Sun, 5 Feb 2023 13:17:34 +0000 (21:17 +0800)] 
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>
2 years agoMerge #1850 #1851
bors[bot] [Mon, 13 Feb 2023 15:32:22 +0000 (15:32 +0000)] 
Merge #1850 #1851

1850: Update GCC/Rust files per 'contrib/update-copyright.py --this-year' [#1831] r=tschwinge a=tschwinge

Fixes: #1831
1851: Merge upstream (dummy), 2023-01-31 GCC/Rust upstreaming r=tschwinge a=tschwinge

In #1847 "Merge upstream, last commit before 2023-01-31 GCC/Rust upstreaming"
we merged commit 9e56306f4d7c15e7667d8ac0b62ae6efb93ba756 from upstream GCC
master branch.

This one now merges the 2023-01-31 GCC/Rust upstreaming, commits
9e56306f4d7c15e7667d8ac0b62ae6efb93ba756..50335ddd301404e9053786b26a23a924471b4d09:

      - 5be4c2687a89 gccrs: session-manager: Add ast-pretty-expanded dump
      - e66fec8e6ba3 gccrs: const folding port
      - ff8a56950776 gccrs: Desugar double borrows into two HIR:BorrowExpr's
      - 86743891a6e9 gccrs: backend: Expose Bvariable class through rust-gcc header
      - 41547275c5e9 gccrs: builtins: Add add_overflow builtin and refactor class
      - 9c87dc0afe05 gccrs: backend: Add overflow checks to every arithmetic operation
      - 3a3a352091b7 gccrs: rustc_attrs: Allow `rustc_inherit_overflow_checks` as a builtin..
      - 938facc5e93a gccrs: lint: Do not emit unused warnings for public items
      - f7014b28b81f gccrs: parser: Parse RangeFullExpr without erroring out
      - 1fed030c1651 gccrs: macros: Handle matchers properly in repetitions
      - 252216dd0c59 gccrs: transcriber: Do not infinite loop if the current parsed node is an error
      - 7dc41901213d gccrs: dump: Add AST debugging using the AST::Dump class
      - 55fb35c51b2e gccrs: ast: Only expand expressions and types if the kind is right
      - 3663d7ef6662 gccrs: ast: Add better assertion on AST fragments
      - 245ce6f26a16 gccrs: Add guards against getting data from an empty vector
      - af22b54af53c gccrs: Add missing location info to coercions
      - 7ad24d802e59 gccrs: Refactor unify to hit a unify_site
      - 1eabeb5aecc9 gccrs: Remove param_use_canonical_types checks ported from c++ front-end
      - ffa16a4590ad gccrs: Create canonical process of compiling constant items
      - 43cb42a3d82d gccrs: Add extra debugging for method call expressions
      - e641158a5f5c gccrs: Add new check for contains_associated_types
      - 0fffc0e772d6 gccrs: Unit structs are not concrete when they need substitutions
      - 689a5c6711b8 gccrs: bugfix: initialize slice from array in const context
      - b0ff1647cbe6 gccrs: add testcase to test component_ref and constructor codes in eval_constant_expression()
      - e6a3886a833a gccrs: backend: correctly formulate the exit condition ...
      - dd9d6656e9a4 gccrs: add testcase with struct to test component_ref and constructor codes..
      - 0d5adf093566 gccrs: testsuite: add loop condition execution test
      - 288b6298a6ae gccrs: const generics: Make sure const generic types are visited properly
      - ff9d7741d4b9 gccrs: const generics: Forbid default values in Functions, Traits and Impls
      - 739d0509ed55 gccrs: attributes: Add #[macro_use] as builtin
      - 3736647947b6 gccrs: module lowering: Do not append null pointers as items
      - 70fc174b78a2 gccrs: Static Items must be const evaluated
      - 408ab8a6e412 gccrs: Statics are a coercion site
      - a0c2ea3ee6e4 gccrs: remove bad assertion
      - f92f8ee75bf0 gccrs: Add testcase for const-eval issue from rust-blog
      - 9d6b434e1fda gccrs: rust: Add -frust-compile-until option
      - e88ce5cc6847 gccrs: expand: eager evaluate macros inside builtin macros
      - c6c4342273a7 gccrs: testsuite/rust: add a testcase for testing ...
      - e1beb624ff5a gccrs: Cleanup formatting of backend expression visitor
      - 9c60f0e1e5cd gccrs: Make constexpr constructors type-checking more permissive
      - 11a37f895040 gccrs: Fix duplicated function generation on higher ranked trait bounds
      - 104cc285533e gccrs: Refactor TypeResolution to be a simple query based system
      - d9d7b6ccd45a gccrs: Add testcase to show forward declared items work
      - 50335ddd3014 gccrs: Add testcase to show forward declared items work via TypeAlias

This merge is done with 'git merge --strategy=ours', so effectively doesn't
merge any changes.  Rationale: those commits are taken from GCC/Rust master
branch, and any remaining changes we'd either like to persist, or assess
individually, later.

Co-authored-by: Thomas Schwinge <thomas@codesourcery.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Faisal Abbas <90.abbasfaisal@gmail.com>
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: liushuyu <liushuyu011@gmail.com>
2 years agoUpdate copyright years.
Thomas Schwinge [Mon, 13 Feb 2023 13:24:42 +0000 (14:24 +0100)] 
Update copyright years.

Update GCC/Rust files per 'contrib/update-copyright.py --this-year'.

Fixes: #1831
2 years agoMerge commit '50335ddd301404e9053786b26a23a924471b4d09' into HEAD
Thomas Schwinge [Mon, 13 Feb 2023 13:41:28 +0000 (14:41 +0100)] 
Merge commit '50335ddd301404e9053786b26a23a924471b4d09' into HEAD

In #1847 "Merge upstream, last commit before 2023-01-31 GCC/Rust upstreaming"
we merged commit 9e56306f4d7c15e7667d8ac0b62ae6efb93ba756 from upstream GCC
master branch.

This one now merges the 2023-01-31 GCC/Rust upstreaming, commits
9e56306f4d7c15e7667d8ac0b62ae6efb93ba756..50335ddd301404e9053786b26a23a924471b4d09:

      - 5be4c2687a89 gccrs: session-manager: Add ast-pretty-expanded dump
      - e66fec8e6ba3 gccrs: const folding port
      - ff8a56950776 gccrs: Desugar double borrows into two HIR:BorrowExpr's
      - 86743891a6e9 gccrs: backend: Expose Bvariable class through rust-gcc header
      - 41547275c5e9 gccrs: builtins: Add add_overflow builtin and refactor class
      - 9c87dc0afe05 gccrs: backend: Add overflow checks to every arithmetic operation
      - 3a3a352091b7 gccrs: rustc_attrs: Allow `rustc_inherit_overflow_checks` as a builtin..
      - 938facc5e93a gccrs: lint: Do not emit unused warnings for public items
      - f7014b28b81f gccrs: parser: Parse RangeFullExpr without erroring out
      - 1fed030c1651 gccrs: macros: Handle matchers properly in repetitions
      - 252216dd0c59 gccrs: transcriber: Do not infinite loop if the current parsed node is an error
      - 7dc41901213d gccrs: dump: Add AST debugging using the AST::Dump class
      - 55fb35c51b2e gccrs: ast: Only expand expressions and types if the kind is right
      - 3663d7ef6662 gccrs: ast: Add better assertion on AST fragments
      - 245ce6f26a16 gccrs: Add guards against getting data from an empty vector
      - af22b54af53c gccrs: Add missing location info to coercions
      - 7ad24d802e59 gccrs: Refactor unify to hit a unify_site
      - 1eabeb5aecc9 gccrs: Remove param_use_canonical_types checks ported from c++ front-end
      - ffa16a4590ad gccrs: Create canonical process of compiling constant items
      - 43cb42a3d82d gccrs: Add extra debugging for method call expressions
      - e641158a5f5c gccrs: Add new check for contains_associated_types
      - 0fffc0e772d6 gccrs: Unit structs are not concrete when they need substitutions
      - 689a5c6711b8 gccrs: bugfix: initialize slice from array in const context
      - b0ff1647cbe6 gccrs: add testcase to test component_ref and constructor codes in eval_constant_expression()
      - e6a3886a833a gccrs: backend: correctly formulate the exit condition ...
      - dd9d6656e9a4 gccrs: add testcase with struct to test component_ref and constructor codes..
      - 0d5adf093566 gccrs: testsuite: add loop condition execution test
      - 288b6298a6ae gccrs: const generics: Make sure const generic types are visited properly
      - ff9d7741d4b9 gccrs: const generics: Forbid default values in Functions, Traits and Impls
      - 739d0509ed55 gccrs: attributes: Add #[macro_use] as builtin
      - 3736647947b6 gccrs: module lowering: Do not append null pointers as items
      - 70fc174b78a2 gccrs: Static Items must be const evaluated
      - 408ab8a6e412 gccrs: Statics are a coercion site
      - a0c2ea3ee6e4 gccrs: remove bad assertion
      - f92f8ee75bf0 gccrs: Add testcase for const-eval issue from rust-blog
      - 9d6b434e1fda gccrs: rust: Add -frust-compile-until option
      - e88ce5cc6847 gccrs: expand: eager evaluate macros inside builtin macros
      - c6c4342273a7 gccrs: testsuite/rust: add a testcase for testing ...
      - e1beb624ff5a gccrs: Cleanup formatting of backend expression visitor
      - 9c60f0e1e5cd gccrs: Make constexpr constructors type-checking more permissive
      - 11a37f895040 gccrs: Fix duplicated function generation on higher ranked trait bounds
      - 104cc285533e gccrs: Refactor TypeResolution to be a simple query based system
      - d9d7b6ccd45a gccrs: Add testcase to show forward declared items work
      - 50335ddd3014 gccrs: Add testcase to show forward declared items work via TypeAlias

This merge is done with 'git merge --strategy=ours', so effectively doesn't
merge any changes.  Rationale: those commits are taken from GCC/Rust master
branch, and any remaining changes we'd either like to persist, or assess
individually, later.

2 years agoMerge #1847
bors[bot] [Mon, 13 Feb 2023 12:27:06 +0000 (12:27 +0000)] 
Merge #1847

1847: Merge upstream, last commit before 2023-01-31 GCC/Rust upstreaming r=tschwinge a=tschwinge

Co-authored-by: Andrea Corallo <andrea.corallo@arm.com>
Co-authored-by: Richard Biener <rguenther@suse.de>
Co-authored-by: Srinath Parvathaneni <srinath.parvathaneni@arm.com>
Co-authored-by: Iain Sandoe <iain@sandoe.co.uk>
Co-authored-by: François Dumont <fdumont@gcc.gnu.org>
Co-authored-by: Jason Merrill <jason@redhat.com>
Co-authored-by: Harald Anlauf <anlauf@gmx.de>
Co-authored-by: Marek Polacek <polacek@redhat.com>
Co-authored-by: GCC Administrator <gccadmin@gcc.gnu.org>
Co-authored-by: Lulu Cheng <chenglulu@loongson.cn>
Co-authored-by: Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
Co-authored-by: Jakub Jelinek <jakub@redhat.com>
Co-authored-by: Eric Biggers <ebiggers@google.com>
Co-authored-by: Xianmiao Qu <cooper.qu@linux.alibaba.com>
Co-authored-by: Andre Vieira <andre.simoesdiasvieira@arm.com>
2 years agoMerge #1750
bors[bot] [Mon, 13 Feb 2023 11:15:24 +0000 (11:15 +0000)] 
Merge #1750

1750: Implement fixed point macro expansion r=CohenArthur a=CohenArthur

This is a cleanup of #1606's branch, which also contains the code necessary for performing eager macro expansion in builtin macros.

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

Fixes #1795

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2 years agoAdjust '.github/bors_log_expected_warnings'
Thomas Schwinge [Sun, 12 Feb 2023 21:51:41 +0000 (22:51 +0100)] 
Adjust '.github/bors_log_expected_warnings'

2 years agoMerge commit '9e56306f4d7c15e7667d8ac0b62ae6efb93ba756' into HEAD
Thomas Schwinge [Sun, 12 Feb 2023 15:43:57 +0000 (16:43 +0100)] 
Merge commit '9e56306f4d7c15e7667d8ac0b62ae6efb93ba756' into HEAD

2 years agoMerge commit '83ffe9cde7fe0b4deb0d1b54175fd9b19c38179c' into HEAD
Thomas Schwinge [Sun, 12 Feb 2023 15:37:19 +0000 (16:37 +0100)] 
Merge commit '83ffe9cde7fe0b4deb0d1b54175fd9b19c38179c' into HEAD

Conflicts:
gcc/rust/rust-gcc-diagnostics.cc
gcc/rust/typecheck/rust-hir-trait-ref.h
gcc/rust/typecheck/rust-hir-type-check-toplevel.cc
gcc/rust/typecheck/rust-hir-type-check-toplevel.h
gcc/rust/typecheck/rust-tyctx.cc
gcc/rust/typecheck/rust-tyty-rules.h

Upstream GCC commit r13-5197-g83ffe9cde7fe0b4deb0d1b54175fd9b19c38179c
"Update copyright years" did updated those files that don't exist in
GCC/Rust master branch anymore.

2 years agoMerge commit '83ffe9cde7fe0b4deb0d1b54175fd9b19c38179c^' into HEAD
Thomas Schwinge [Sun, 12 Feb 2023 15:35:44 +0000 (16:35 +0100)] 
Merge commit '83ffe9cde7fe0b4deb0d1b54175fd9b19c38179c^' into HEAD

2 years agoMerge commit 'efce0caf2d75dff5a83812b8da2dd3725197ac7c' into HEAD
Thomas Schwinge [Sun, 12 Feb 2023 15:34:59 +0000 (16:34 +0100)] 
Merge commit 'efce0caf2d75dff5a83812b8da2dd3725197ac7c' into HEAD

2 years agoMerge commit 'b0edfa0ef02c0f4820cec0601a4fd85aba516428' into HEAD
Thomas Schwinge [Sun, 12 Feb 2023 15:34:43 +0000 (16:34 +0100)] 
Merge commit 'b0edfa0ef02c0f4820cec0601a4fd85aba516428' into HEAD

2 years agoMerge commit 'b0edfa0ef02c0f4820cec0601a4fd85aba516428^' into HEAD
Thomas Schwinge [Sun, 12 Feb 2023 15:34:35 +0000 (16:34 +0100)] 
Merge commit 'b0edfa0ef02c0f4820cec0601a4fd85aba516428^' into HEAD

2 years agoMerge commit '02c031088ac0bbf716aec52e027d615b7a5a572b' into HEAD [#1704]
Thomas Schwinge [Sun, 12 Feb 2023 15:29:33 +0000 (16:29 +0100)] 
Merge commit '02c031088ac0bbf716aec52e027d615b7a5a572b' into HEAD [#1704]

"Empty" merge: GCC/Rust #1704 commit 404cdd1eeb6f473ef690ad780798800948f946ee
"rust: fix link serialization [PR108113]"
and upstream GCC commit r13-4804-g02c031088ac0bbf716aec52e027d615b7a5a572b
"rust: fix link serialization [PR108113]" are identical.

2 years agoMerge commit '02c031088ac0bbf716aec52e027d615b7a5a572b^' into HEAD
Thomas Schwinge [Sun, 12 Feb 2023 15:29:21 +0000 (16:29 +0100)] 
Merge commit '02c031088ac0bbf716aec52e027d615b7a5a572b^' into HEAD

2 years agoMerge commit 'f80f540e394e87ac70349bad109bfc4b465c7c98' into HEAD [#1512]
Thomas Schwinge [Sun, 12 Feb 2023 15:28:14 +0000 (16:28 +0100)] 
Merge commit 'f80f540e394e87ac70349bad109bfc4b465c7c98' into HEAD [#1512]

Conflicts:
gcc/config/rs6000/rs6000-logue.cc

This overrides GCC/Rust #1512 commit 8e9dcd47d3ea97bd4bea892ad4c968acf486676b
"Add missing language selection for rs6000"
with upstream GCC commit r13-4762-gf80f540e394e87ac70349bad109bfc4b465c7c98
"rs6000: Add Rust support to traceback table".

2 years agoMerge commit 'f80f540e394e87ac70349bad109bfc4b465c7c98^' into HEAD
Thomas Schwinge [Sun, 12 Feb 2023 15:27:19 +0000 (16:27 +0100)] 
Merge commit 'f80f540e394e87ac70349bad109bfc4b465c7c98^' into HEAD

2 years agoMerge commit '4a1648084137f515eddd5dc087d5dfbf360a5bfa' into HEAD
Thomas Schwinge [Sun, 12 Feb 2023 15:26:52 +0000 (16:26 +0100)] 
Merge commit '4a1648084137f515eddd5dc087d5dfbf360a5bfa' into HEAD

2 years agoMerge commit '9cf9f3c7629d768d940d9f87cddcd616bb0449e0' into HEAD
Thomas Schwinge [Sun, 12 Feb 2023 15:26:43 +0000 (16:26 +0100)] 
Merge commit '9cf9f3c7629d768d940d9f87cddcd616bb0449e0' into HEAD

2 years agoMerge commit '9cf9f3c7629d768d940d9f87cddcd616bb0449e0^' into HEAD
Thomas Schwinge [Sun, 12 Feb 2023 15:26:22 +0000 (16:26 +0100)] 
Merge commit '9cf9f3c7629d768d940d9f87cddcd616bb0449e0^' into HEAD

2 years agoMerge commit '95dc11475dac06b5eecd904079de8aa94827a36a' into HEAD [#1619]
Thomas Schwinge [Sun, 12 Feb 2023 15:22:35 +0000 (16:22 +0100)] 
Merge commit '95dc11475dac06b5eecd904079de8aa94827a36a' into HEAD [#1619]

Conflicts:
gcc/rust/parse/rust-parse-impl.h

This overrides GCC/Rust #1619 commit db4b399c25fd3c37e52c6b8dbdf6bc9c0f1deb6c
"parser: Fix ICE in closure parsing"
with upstream GCC commit r13-4697-g95dc11475dac06b5eecd904079de8aa94827a36a
"rust: Fix up aarch64-linux bootstrap [PR106072]".

2 years agoMerge commit '95dc11475dac06b5eecd904079de8aa94827a36a^' into HEAD
Thomas Schwinge [Sun, 12 Feb 2023 15:20:58 +0000 (16:20 +0100)] 
Merge commit '95dc11475dac06b5eecd904079de8aa94827a36a^' into HEAD

2 years agoMerge #1820
bors[bot] [Fri, 10 Feb 2023 11:40:27 +0000 (11:40 +0000)] 
Merge #1820

1820: Support for TuplePattern in let statements r=CohenArthur a=powerboat9

Added support for TuplePattern in let statements, along with a test.

Co-authored-by: Owen Avery <powerboat9.gamer@gmail.com>
2 years agoMerge #1810 #1823 #1824 #1837 #1839
bors[bot] [Fri, 10 Feb 2023 10:17:07 +0000 (10:17 +0000)] 
Merge #1810 #1823 #1824 #1837 #1839

1810: fixed indentation in AST pretty printed expanded dump of trait. r=CohenArthur a=00AR

fixes #1785

Signed-off-by: Abdul Rafey <abdulrafeyq@gmail.com>
---

In Dump::visit (TraitImpl), the for loop adds indentation before calling visit () on every iteration. I think when Dump::visit (Method) is executed it adds extra indentation on top of it.

1823: parser: Improve parsing of complex generic arguments r=CohenArthur a=CohenArthur

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.

1824: parser: Fix parsing of closure param list r=CohenArthur a=CohenArthur

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.

1837: typecheck: Refactor rust-hir-trait-reference.h r=CohenArthur a=P-E-P

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.

Fixes #1835

1839: cli: Update safety warning message r=CohenArthur a=P-E-P

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>
Fixes #1829

Co-authored-by: Abdul Rafey <abdulrafeyq@gmail.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Co-authored-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 years agoMerge #1789
bors[bot] [Fri, 10 Feb 2023 09:47:36 +0000 (09:47 +0000)] 
Merge #1789

1789: Run workflow r=CohenArthur a=Parthib314

Fixes #1767

Co-authored-by: Parthib <94271200+Parthib314@users.noreply.github.com>
2 years agoMerge #1832
bors[bot] [Fri, 10 Feb 2023 09:05:28 +0000 (09:05 +0000)] 
Merge #1832

1832: ci: Run commit format checker on push to `trying` branch r=CohenArthur a=CohenArthur

ChangeLog:

* .github/workflows/commit-format.yml: Run job on pushes to `trying`.

This should hopefully stop bors from timing out.

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2 years agoci: Revert bors running of commit checkers
Arthur Cohen [Wed, 8 Feb 2023 12:48:43 +0000 (13:48 +0100)] 
ci: Revert bors running of commit checkers

ChangeLog:

* .github/bors.toml: Remove checks for commit formats.

2 years agofixed indentations in AST pretty expanded dump of trait gcc/rust/ChangeLog:
Abdul Rafey [Wed, 1 Feb 2023 05:32:16 +0000 (11:02 +0530)] 
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>
2 years agocli: Update safety warning message
Pierre-Emmanuel Patry [Thu, 9 Feb 2023 10:32:50 +0000 (11:32 +0100)] 
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>
2 years agotypecheck: Refactor rust-hir-trait-reference.h
Pierre-Emmanuel Patry [Wed, 8 Feb 2023 15:19:41 +0000 (16:19 +0100)] 
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>
2 years agoexpander: Add documentation for `expand_eager_invocations`
Arthur Cohen [Wed, 8 Feb 2023 11:23:06 +0000 (12:23 +0100)] 
expander: Add documentation for `expand_eager_invocations`

gcc/rust/ChangeLog:

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

2 years agomacros: Perform macro expansion in a fixed-point fashion.
Arthur Cohen [Wed, 18 Jan 2023 11:23:37 +0000 (12:23 +0100)] 
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::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.

2 years agomacro: Allow builtin `MacroInvocation`s within the AST
Arthur Cohen [Wed, 18 Jan 2023 11:23:03 +0000 (12:23 +0100)] 
macro: Allow builtin `MacroInvocation`s within the AST

This commit turns AST::MacroInvocation into a sum type.
The class can now represent a regular macro invocation (lazily expanded)
or a builtin one (eagerly expanded)

gcc/rust/ChangeLog:

* expand/rust-macro-builtins.cc (make_macro_invocation): Add short hand
function for returning fragments containing macro invocations.
(MacroBuiltin::compile_error_handler): Add explanation for eager
invocation

2 years agoexpansion: Add `get_token_slice` to `MacroInvocLexer` class
Arthur Cohen [Tue, 17 Jan 2023 15:44:23 +0000 (16:44 +0100)] 
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`.

2 years agoparser: Expose parse_macro_invocation as public API
Arthur Cohen [Fri, 13 Jan 2023 11:16:49 +0000 (12:16 +0100)] 
parser: Expose parse_macro_invocation as public API

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

2 years agoAdd support for TuplePattern in let statements
Owen Avery [Sat, 4 Feb 2023 05:02:22 +0000 (00:02 -0500)] 
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>
2 years agoci: Require commits check to pass for bors to merge and fix CI names
Arthur Cohen [Wed, 1 Feb 2023 18:11:32 +0000 (19:11 +0100)] 
ci: Require commits check to pass for bors to merge and fix CI names

ChangeLog:

* .github/bors.toml: Add commit checkers.
* .github/workflows/commit-format.yml: Rename commit checker jobs.

2 years agoMerge #1739
bors[bot] [Sun, 5 Feb 2023 00:56:44 +0000 (00:56 +0000)] 
Merge #1739

1739: Initial type bounds checking for all type checks r=philberty a=philberty

This patchset is my branch for general improvements to the type-system and
for improved type bounds checking in preparation for opaque types.

Fixes #1773 #1786

Co-authored-by: Philip Herron <herron.philip@googlemail.com>
2 years 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.

2 years 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

2 years 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

2 years 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.

2 years 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

2 years 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

2 years 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.

2 years 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

2 years 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

2 years 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

2 years 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

2 years 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.

2 years 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

2 years 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

2 years 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

2 years 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

2 years 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

2 years 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.

2 years 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.

2 years 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

2 years 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>
2 years agoMerge #1826
bors[bot] [Sat, 4 Feb 2023 23:42:46 +0000 (23:42 +0000)] 
Merge #1826

1826: Removed comment copy-pasted from gcc/tree.def r=philberty a=powerboat9

Addresses #1640.

Co-authored-by: Owen Avery <powerboat9.gamer@gmail.com>
2 years agoRemoved comment copy-pasted from gcc/tree.def
Owen Avery [Sat, 4 Feb 2023 17:07:38 +0000 (12:07 -0500)] 
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>
2 years agoMerge #1818
bors[bot] [Fri, 3 Feb 2023 20:17:06 +0000 (20:17 +0000)] 
Merge #1818

1818: Implement lowering ReferencePattern from AST to HIR r=CohenArthur a=powerboat9

gcc/rust/ChangeLog:

* ast/rust-pattern.h (ReferencePattern::get_has_two_amps): 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>
Partially addresses #1813

Co-authored-by: Owen Avery <powerboat9.gamer@gmail.com>
2 years agoMerge #1737
bors[bot] [Fri, 3 Feb 2023 17:04:01 +0000 (17:04 +0000)] 
Merge #1737

1737: Add  support for feature check. r=CohenArthur a=TuringKi

This commit implements a very basic feature checking module.

The results like this:

```

../gcc/testsuite/rust/compile/feature.rs:1:12: error: unknown feature 'AA'
    1 | #![feature(AA)] //{ dg-error "unknown feature 'AA'" }
      |            ^

```

This commit is split from pr https://github.com/Rust-GCC/gccrs/pull/1718.

Signed-off-by: Xiao Ma <mxlol233@outlook.com>
Co-authored-by: mxlol233 <mxlol233@outlook.com>
2 years agoMerge #1698
bors[bot] [Fri, 3 Feb 2023 13:28:26 +0000 (13:28 +0000)] 
Merge #1698

1698: update the ubuntu version r=CohenArthur a=ArshErgon

Fixes: #1689
updated the ubuntu-version from 20.04 to 22.04

Thank you for making Rust GCC better!

If your PR fixes an issue, you can add "Fixes #issue_number" into this
PR description and the git commit message. This way the issue will be
automatically closed when your PR is merged. If your change addresses
an issue but does not fully fix it please mark it as "Addresses #issue_number"
in the git commit message.

Here is a checklist to help you with your PR.

- \[ ] GCC development requires copyright assignment or the Developer's Certificate of Origin sign-off, see https://gcc.gnu.org/contribute.html or https://gcc.gnu.org/dco.html
- \[ ] Read contributing guidlines
- \[ ] `make check-rust` passes locally
- \[ ] Run `clang-format`
- \[ ] Added any relevant test cases to `gcc/testsuite/rust/`

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.
---

*Please write a comment explaining your change. This is the message
that will be part of the merge commit.

Co-authored-by: ArshErgon <arshergon@gmail.com>
2 years agoAdd support for feature check.
mxlol233 [Thu, 12 Jan 2023 14:08:57 +0000 (22:08 +0800)] 
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>
2 years agoMoving Functions from rust-gcc-diagnostics to rust-diagnostics.cc
Parthib [Tue, 31 Jan 2023 13:15:01 +0000 (18:45 +0530)] 
Moving Functions from rust-gcc-diagnostics to rust-diagnostics.cc

gcc/rust/ChangeLog:

* Make-lang.in: Modified
* rust-diagnostics.cc (rust_be_get_quotechars): Added
(rust_be_internal_error_at): Added
(rust_be_error_at): Added
(class rust_error_code_rule): Added
(rust_be_warning_at): Added
(rust_be_fatal_error): Added
(rust_be_inform): Added
(rust_be_debug_p): Added

* rust-gcc-diagnostics.cc: Removed

2 years agoMerge #1812
bors[bot] [Fri, 3 Feb 2023 12:45:58 +0000 (12:45 +0000)] 
Merge #1812

1812: parser: Allow parsing multiple reference types r=CohenArthur a=CohenArthur

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.

Addresses #1807 partly

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2 years agoMerge #1816
bors[bot] [Fri, 3 Feb 2023 11:03:52 +0000 (11:03 +0000)] 
Merge #1816

1816: Move rust-buffered-queue.h to util folder #1766 r=CohenArthur a=drmahad

### gcc/rust/ChangeLog:

-  rust-buffered-queue.h
-  Moved to util/rust-buffered-queue.h.

Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Co-authored-by: MAHAD <mahadtxt@gmail.com>
2 years agoparser: Fix parsing of closure param list
Arthur Cohen [Thu, 2 Feb 2023 14:32:17 +0000 (15:32 +0100)] 
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.

2 years agoparser: Improve parsing of complex generic arguments
Arthur Cohen [Wed, 1 Feb 2023 11:41:47 +0000 (12:41 +0100)] 
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.

2 years agoMerge #1783
bors[bot] [Thu, 2 Feb 2023 18:29:46 +0000 (18:29 +0000)] 
Merge #1783

1783: Remove HIR::GroupedPattern r=philberty a=powerboat9

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Removes HIR::GroupedPattern and lowers AST::GroupedPattern to its inner pattern directly. Addresses https://github.com/Rust-GCC/gccrs/pull/1771#pullrequestreview-1271272084

Co-authored-by: Owen Avery <powerboat9.gamer@gmail.com>
2 years agoImplement lowering ReferencePattern from AST to HIR
Owen Avery [Thu, 2 Feb 2023 05:05:36 +0000 (00:05 -0500)] 
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>
2 years agoOptimize HIR::ReferencePattern
Owen Avery [Thu, 2 Feb 2023 16:38:44 +0000 (11:38 -0500)] 
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>
2 years agoRemove HIR::GroupedPattern
Owen Avery [Tue, 31 Jan 2023 01:14:34 +0000 (20:14 -0500)] 
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>
2 years agoImprove GroupedPattern lowering
Owen Avery [Tue, 31 Jan 2023 01:13:52 +0000 (20:13 -0500)] 
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>
2 years agoMove rust-buffered-queue.h to util folder #1766
MAHAD [Wed, 1 Feb 2023 17:44:00 +0000 (22:44 +0500)] 
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>
2 years agoci: update ubuntu version
ArshErgon [Tue, 13 Dec 2022 12:26:47 +0000 (16:56 +0430)] 
ci: update ubuntu version

This updates the CI to use ubuntu's latest LTS release, 22.04

ChangeLog:

* .github/bors_log_expected_warnings: Update warnings.
* .github/workflows/bootstrap.yml: Update Ubuntu version to 22.04.
* .github/workflows/ccpp.yml: Likewise.

2 years agoMerge #1811
bors[bot] [Wed, 1 Feb 2023 14:24:35 +0000 (14:24 +0000)] 
Merge #1811

1811: Merge upstream (dummy), "Rust front-end patches v4" r=tschwinge a=tschwinge

Last we did #1700 "Merge upstream, last commit before GCC/Rust upstreaming",
which merged commit b4fddbe9592e9feb37ce567d90af822b75995531 from GCC upstream
master branch.

This one now merges the "Rust front-end patches v4", commits
b4fddbe9592e9feb37ce567d90af822b75995531..edc676cfe8988c62c81b0df224c7fe82583012b1:

      - dd950cbbb97 Use DW_ATE_UTF for the Rust 'char' type
      - b772a504eff gccrs: Add necessary hooks for a Rust front-end testsuite
      - 4b8f3005af0 gccrs: Add Debug info testsuite
      - f60df7e6202 gccrs: Add link cases testsuite
      - 97705b4459b gccrs: Add general compilation test cases
      - 5a56869d6e3 gccrs: Add execution test cases
      - dc4171edb3c gccrs: Add gcc-check-target check-rust
      - 6b35ae12ce9 gccrs: Add Rust front-end base AST data structures
      - 438ae944fa6 gccrs: Add definitions of Rust Items in AST data structures
      - d588754c826 gccrs: Add full definitions of Rust AST data structures
      - 5b981e9c741 gccrs: Add Rust AST visitors
      - 18f6990f842 gccrs: Add Lexer for Rust front-end
      - 35e4f3b4af4 gccrs: Add Parser for Rust front-end pt.1
      - 32c8fb0eeaf gccrs: Add Parser for Rust front-end pt.2
      - 1841081a8a3 gccrs: Add expansion pass for the Rust front-end
      - 85a8fe00f80 gccrs: Add name resolution pass to the Rust front-end
      - 8ad1d56d68a gccrs: Add declarations for Rust HIR
      - 7641eaead40 gccrs: Add HIR definitions and visitor framework
      - 7999cf327de gccrs: Add AST to HIR lowering pass
      - b32b1b1576a gccrs: Add wrapper for make_unique
      - c7f8347e83c gccrs: Add port of FNV hash used during legacy symbol mangling
      - 15b0278905e gccrs: Add Rust ABI enum helpers
      - eb10bc5225e gccrs: Add Base62 implementation
      - 9a4fee5f57c gccrs: Add implementation of Optional
      - 2e7fc8780e0 gccrs: Add attributes checker
      - 9ce37e72062 gccrs: Add helpers mappings canonical path and lang items
      - c6c3db21769 gccrs: Add type resolution and trait solving pass
      - 24393cb68fa gccrs: Add Rust type information
      - 06688fe40a2 gccrs: Add remaining type system transformations
      - b1b35204d8a gccrs: Add unsafe checks for Rust
      - 5215235f016 gccrs: Add const checker
      - ca246e573fb gccrs: Add privacy checks
      - 520b52b24e7 gccrs: Add dead code scan on HIR
      - 4d67468d1d4 gccrs: Add unused variable scan
      - 509e4c32c6a gccrs: Add metadata output pass
      - 15f04af347e gccrs: Add base for HIR to GCC GENERIC lowering
      - 019b2f15581 gccrs: Add HIR to GCC GENERIC lowering for all nodes
      - cfbda2f78ba gccrs: Add HIR to GCC GENERIC lowering entry point
      - fe6264fa28a gccrs: These are wrappers ported from reusing gccgo
      - bba14a0790f gccrs: Add compiler driver
      - ea34614225d gccrs: Compiler proper interface kicks off the pipeline
      - ab1e0db43c2 gccrs: Add lang-spec.h
      - 5e7d199739f gccrs: Add lang.opt
      - 88415d33bb3 gccrs: Add GCC Rust front-end Make-lang.in
      - b07ef39ffbf gccrs: Add fatal_error when experimental flag is not present
      - a75f038c069 gccrs: Add config-lang.in
      - edc676cfe89 gccrs: Add README, CONTRIBUTING and compiler logo

This merge is done with `git merge --strategy=ours`, so that we effectively
don't bring any changes.  Rationale: any changes due to upstream review etc.,
have already been applied individually to GCC/Rust master branch, and any
remaining changes we'd either like to persist, or assess individually, later.

Co-authored-by: Tom Tromey <tom@tromey.com>
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Co-authored-by: Joel Phillips <simplytheother@gmail.com>
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2 years agoparser: Allow parsing multiple reference types
Arthur Cohen [Wed, 1 Feb 2023 10:40:13 +0000 (11:40 +0100)] 
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.

2 years agoMerge commit 'edc676cfe8988c62c81b0df224c7fe82583012b1' into HEAD
Thomas Schwinge [Wed, 1 Feb 2023 09:34:30 +0000 (10:34 +0100)] 
Merge commit 'edc676cfe8988c62c81b0df224c7fe82583012b1' into HEAD

Last we did #1700 "Merge upstream, last commit before GCC/Rust upstreaming",
which merged commit b4fddbe9592e9feb37ce567d90af822b75995531 from GCC upstream
master branch.

This one now merges the "Rust front-end patches v4", commits
b4fddbe9592e9feb37ce567d90af822b75995531..edc676cfe8988c62c81b0df224c7fe82583012b1:

      - dd950cbbb97 Use DW_ATE_UTF for the Rust 'char' type
      - b772a504eff gccrs: Add necessary hooks for a Rust front-end testsuite
      - 4b8f3005af0 gccrs: Add Debug info testsuite
      - f60df7e6202 gccrs: Add link cases testsuite
      - 97705b4459b gccrs: Add general compilation test cases
      - 5a56869d6e3 gccrs: Add execution test cases
      - dc4171edb3c gccrs: Add gcc-check-target check-rust
      - 6b35ae12ce9 gccrs: Add Rust front-end base AST data structures
      - 438ae944fa6 gccrs: Add definitions of Rust Items in AST data structures
      - d588754c826 gccrs: Add full definitions of Rust AST data structures
      - 5b981e9c741 gccrs: Add Rust AST visitors
      - 18f6990f842 gccrs: Add Lexer for Rust front-end
      - 35e4f3b4af4 gccrs: Add Parser for Rust front-end pt.1
      - 32c8fb0eeaf gccrs: Add Parser for Rust front-end pt.2
      - 1841081a8a3 gccrs: Add expansion pass for the Rust front-end
      - 85a8fe00f80 gccrs: Add name resolution pass to the Rust front-end
      - 8ad1d56d68a gccrs: Add declarations for Rust HIR
      - 7641eaead40 gccrs: Add HIR definitions and visitor framework
      - 7999cf327de gccrs: Add AST to HIR lowering pass
      - b32b1b1576a gccrs: Add wrapper for make_unique
      - c7f8347e83c gccrs: Add port of FNV hash used during legacy symbol mangling
      - 15b0278905e gccrs: Add Rust ABI enum helpers
      - eb10bc5225e gccrs: Add Base62 implementation
      - 9a4fee5f57c gccrs: Add implementation of Optional
      - 2e7fc8780e0 gccrs: Add attributes checker
      - 9ce37e72062 gccrs: Add helpers mappings canonical path and lang items
      - c6c3db21769 gccrs: Add type resolution and trait solving pass
      - 24393cb68fa gccrs: Add Rust type information
      - 06688fe40a2 gccrs: Add remaining type system transformations
      - b1b35204d8a gccrs: Add unsafe checks for Rust
      - 5215235f016 gccrs: Add const checker
      - ca246e573fb gccrs: Add privacy checks
      - 520b52b24e7 gccrs: Add dead code scan on HIR
      - 4d67468d1d4 gccrs: Add unused variable scan
      - 509e4c32c6a gccrs: Add metadata output pass
      - 15f04af347e gccrs: Add base for HIR to GCC GENERIC lowering
      - 019b2f15581 gccrs: Add HIR to GCC GENERIC lowering for all nodes
      - cfbda2f78ba gccrs: Add HIR to GCC GENERIC lowering entry point
      - fe6264fa28a gccrs: These are wrappers ported from reusing gccgo
      - bba14a0790f gccrs: Add compiler driver
      - ea34614225d gccrs: Compiler proper interface kicks off the pipeline
      - ab1e0db43c2 gccrs: Add lang-spec.h
      - 5e7d199739f gccrs: Add lang.opt
      - 88415d33bb3 gccrs: Add GCC Rust front-end Make-lang.in
      - b07ef39ffbf gccrs: Add fatal_error when experimental flag is not present
      - a75f038c069 gccrs: Add config-lang.in
      - edc676cfe89 gccrs: Add README, CONTRIBUTING and compiler logo

This merge is done with `git merge --strategy=ours`, so that we effectively
don't bring any changes.  Rationale: any changes due to upstream review etc.,
have already been applied individually to GCC/Rust master branch, and any
remaining changes we'd either like to persist, or assess individually, later.

2 years agoMerge #1788
bors[bot] [Tue, 31 Jan 2023 21:46:24 +0000 (21:46 +0000)] 
Merge #1788

1788: ci: Add commit format checker r=CohenArthur a=CohenArthur

Bring over the commit checker from `gcc-patch-dev` with the `gccrs` prefix checker enabled only for `gcc-patch-dev` PRs. I'll open up an issue to make sure that in the future it's easier to keep that folder in sync between the two branches

Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
2 years agoci: Add commit format checker
Arthur Cohen [Tue, 31 Jan 2023 14:38:02 +0000 (15:38 +0100)] 
ci: Add commit format checker

2 years agogccrs: Add testcase to show forward declared items work via TypeAlias
Philip Herron [Tue, 27 Sep 2022 07:57:49 +0000 (08:57 +0100)] 
gccrs: Add testcase to show forward declared items work via TypeAlias

Fixes #1073

gcc/testsuite/ChangeLog:

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

2 years agogccrs: Add testcase to show forward declared items work
Philip Herron [Tue, 27 Sep 2022 07:56:16 +0000 (08:56 +0100)] 
gccrs: Add testcase to show forward declared items work

Fixes #1006

gcc/testsuite/ChangeLog:

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

2 years agogccrs: Refactor TypeResolution to be a simple query based system
Philip Herron [Mon, 16 Jan 2023 11:36:53 +0000 (12:36 +0100)] 
gccrs: Refactor TypeResolution to be a simple query based system

This patch refactors the type resolution system to introduce a new
interface

  bool query_type (HirId, TyTy::BaseType** result)

This is needed in order to properly support forward declared items. Our
name resolution system has two parts:

  1. Toplevel scan
  2. Item resolution

The toplevel scan gathers all the nesseacry 'names' into their respective
namespace by doing a full toplevel scan and generate canonical paths for
each item. The second pass is responsible for drilling down into each
structure or function to resolve each field or variable etc. This means
our name resolution system supports forward decalred items but our type
resolution system did not.

This patch removes the toplevel scan from our type resolution pass which
is not able to handle all cases such as a function with return type and
the type is decalred after the fact or a type alias to a type declared
after the fact. The name resolution mappings are resolved so when errors
occured here we got errors such as unable to lookup HirId 1234, which meant
yes we have 'resolved' this reference to this HirId but we are unable to
find any type information for it. This means we needed a new way to figure
out the type in a query based way.

This is where the new query_type inferface comes in so when we have an
HirId we want to resolve the mappings class allows us to figure out what
item this is such as:

  1. HIR::Item (normal HIR::Function, Struct, TypeAlias, ...)
  2. HIR::ImplItem (function, constant, ... within an impl-block)
  3. HIR::ImplBlock (Self type on an impl-block)
  4. HIR::ExternalItem (extern-block item)

The mappings class allows us to simply lookup these HIR nodes and then
call the relevant resolver class to compute the type. This patch does not
add support for self-referencial types but is the starting point to be able
to support such types.

Fixes #1455

gcc/rust/ChangeLog:

* Make-lang.in: Remove `rust-hir-typecheck-toplevel` object and add
`rust-hir-path-probe` one.
* typecheck/rust-hir-dot-operator.cc (MethodResolver::MethodResolver):
Remove no longer used `context` and `mapping` fields, and use new
`query_type` API.
(MethodResolver::MethodResolver): Likewise.
(MethodResolver::select): Use new `query_type` API.
* typecheck/rust-hir-path-probe.h: New header.
* typecheck/rust-hir-path-probe.cc: New file.
* typecheck/rust-hir-dot-operator.h (class MethodResolver): Remove no
longer used `context` and `mapping` fields, and use new `query_type` API.
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::query_type): New function.
* typecheck/rust-hir-type-check-base.h: Declare `query_type` function.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add debug print.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::Resolve):
Refactor and make use of new query system.
(TypeCheckTopLevelExternItem::Resolve): Likewise.
(TypeCheckTopLevelExternItem::visit): Likewise.
(TypeCheckTopLevelImplItem::visit): Likewise.
(TypeCheckImplItem::visit): Likewise.
(TypeCheckImplItem::TypeCheckImplItem): Likewise.
(TypeCheckImplItem::Resolve): Likewise.
(TypeCheckImplItemWithTrait::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.h (class TypeCheckTopLevelImplItem): Likewise.
(class TypeCheckImplItemWithTrait): Likewise.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::TypeCheckItem): Likewise.
(TypeCheckItem::Resolve): Likewise.
(TypeCheckItem::ResolveImplItem): Likewise.
(TypeCheckItem::ResolveImplBlockSelf): Likewise.
(TypeCheckItem::visit): Likewise.
(TypeCheckItem::resolve_impl_item): Likewise.
(TypeCheckItem::resolve_impl_block_substitutions): Likewise.
(TypeCheckItem::resolve_impl_block_self): Likewise.
* typecheck/rust-hir-type-check-item.h: Likewise.
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Likewise.
(TypeCheckExpr::resolve_segments): Likewise.
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.h: Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::Resolve): Likewise.
(TypeCheckType::visit): Likewise.
(TypeCheckType::resolve_root_path): Likewise.
* typecheck/rust-hir-type-check.cc (TypeResolution::Resolve): Likewise.
* typecheck/rust-hir-type-check.h: Likewise.
* typecheck/rust-substitution-mapper.h: Likewise.
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Likewise.
(TypeCheckBase::get_predicate_from_bound): Likewise.
(TypeBoundsMappings::add_bound): Likewise.
* typecheck/rust-tyty-cmp.h: Likewise.
* typecheck/rust-tyty.h: Likewise.
* typecheck/rust-tyty.cc (SubstitutionRef::infer_substitions): Likewise.
(ParamType::resolve): Do not infinite loop anymore.
* util/rust-hir-map.h: Add new `hirImplBlockTypeMappings` and
declare `lookup_impl_block_type`.
* util/rust-hir-map.cc (Mappings::insert_hir_impl_block): Use new
`hirImplBlockTypeMappings`
(Mappings::lookup_impl_block_type): New function.

gcc/testsuite/ChangeLog:

* rust/compile/const_generics_5.rs: Fix assertions.
* rust/compile/unconstrained_type_param.rs: Add more assertions.

2 years agogccrs: Fix duplicated function generation on higher ranked trait bounds
Philip Herron [Tue, 27 Sep 2022 11:19:43 +0000 (12:19 +0100)] 
gccrs: Fix duplicated function generation on higher ranked trait bounds

Deuplicate function elimination can fail when we compile helpers during
higher ranked trait bound monomorphization. This because the
TyTy::BaseType info can be lost/reset during the compilation process. This
adds a second mechanism to match based on the manged names which is a bit
more reliable. This patch is required since the query based refactor of
the type system so this issue was likely hidden to to using duplicated type
info for higher ranked trait bounds.

gcc/rust/ChangeLog:

* backend/rust-compile-context.h: Add new optional `asm_name` string
argument to `lookup_function_decl`.
* backend/rust-compile-item.cc (CompileItem::visit): Compute assembly
name and pass it to `lookup_function_decl` when calling it.

2 years agogccrs: Make constexpr constructors type-checking more permissive
Philip Herron [Tue, 27 Sep 2022 10:36:35 +0000 (11:36 +0100)] 
gccrs: Make constexpr constructors type-checking more permissive

gcc/rust/ChangeLog:

* backend/rust-constexpr.cc (eval_store_expression): Remove invalid
assertion on constexpr constructors.

2 years agogccrs: Cleanup formatting of backend expression visitor
Philip Herron [Tue, 27 Sep 2022 10:34:21 +0000 (11:34 +0100)] 
gccrs: Cleanup formatting of backend expression visitor

gcc/rust/ChangeLog:

* backend/rust-compile-expr.h: Formatting.

2 years agogccrs: testsuite/rust: add a testcase for testing ...
liushuyu [Tue, 27 Sep 2022 04:30:33 +0000 (22:30 -0600)] 
gccrs: testsuite/rust: add a testcase for testing ...

... builtin macro and decl macro mixed expansion

gcc/testsuite/ChangeLog:

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

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2 years agogccrs: expand: eager evaluate macros inside builtin macros
liushuyu [Fri, 2 Sep 2022 22:08:39 +0000 (16:08 -0600)] 
gccrs: expand: eager evaluate macros inside builtin macros

gcc/rust/ChangeLog:

* ast/rust-ast.h (class MacroInvocData): Store expander as
member of the class.
(class Expr): Add `is_literal` virtual method
* ast/rust-expr.h: Override `is_literal` for `LiteralExpr`s.
* expand/rust-macro-builtins.cc (try_expand_macro_expression): New function.
(try_extract_string_literal_from_fragment): Likewise.
(try_expand_single_string_literal): Likewise.
(try_expand_many_expr): Likewise.
(parse_single_string_literal): Add macro expander as argument.
(MacroBuiltin::include_bytes): Pass expander as argument to
`parse_single_string_literal`.
(MacroBuiltin::include_str): Likewise.
(MacroBuiltin::compile_error): Likewise.
(MacroBuiltin::include): Likewise.
(MacroBuiltin::concat): Likewise and add better error handling.
(MacroBuiltin::env): Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Expand
invocations recursively.

gcc/testsuite/ChangeLog:

* rust/compile/builtin_macro_concat.rs: Fix test error messages.
* rust/compile/builtin_macro_env.rs: Likewise.

Signed-off-by: Zixing Liu <liushuyu011@gmail.com>
2 years agogccrs: rust: Add -frust-compile-until option
Arthur Cohen [Wed, 31 Aug 2022 11:53:28 +0000 (13:53 +0200)] 
gccrs: rust: Add -frust-compile-until option

This option helps ensure that we do not introduce regressions on various
parts of the compilation pipeline. For example, a testcase (or testsuite
from the `testing` project) might pass attribute checking, expansion and
lowering, but fail during typechecking. Should a change suddenly make
that testcase fail expansion, we would not be able to notice it. By
generating tests that run up until expansion, typechecking, compilation
and so forth we ensure that no regressions are added accidentally to
already failing tests/testsuites.

gcc/rust/ChangeLog:

* lang.opt: Add new ``-frust-compile-until` option.
* rust-session-manager.cc (Session::compile_crate): Add stops around
various compilation steps in the pipeline.
* rust-session-manager.h (struct CompileOptions): Add `CompileStep` enum
and field.

gcc/testsuite/ChangeLog:

* rust/compile/frust-compile-until.rs: New test.

2 years agogccrs: Add testcase for const-eval issue from rust-blog
Philip Herron [Sun, 18 Sep 2022 09:37:06 +0000 (10:37 +0100)] 
gccrs: Add testcase for const-eval issue from rust-blog

see:
https://blog.rust-lang.org/2022/09/15/const-eval-safety-rule-revision.html

gcc/testsuite/ChangeLog:

* rust/compile/rust-const-blog-issue.rs: New test.