[COMMITTED] gccrs: session-manager: Add ast-pretty-expanded dump

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * rust-session-manager.cc (Session::compile_crate): Allow the dump of prettified AST (Session::dump_ast_pretty): New * rust-session-manager.h: Add new output file for pretty AST dump Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/ru

[COMMITTED] gccrs: Desugar double borrows into two HIR:BorrowExpr's

2023-01-31 Thread Arthur Cohen
From: Philip Herron We simply hit a gcc_unreachable() on double borrows but it seems reasonable to just desugar the AST into a borrow of a borrow to foo. Instead of a borrow expression with a flag to be respected. Fixes #1506 gcc/rust/ChangeLog: * hir/rust-ast-lower-expr.h: Lower doubl

[COMMITTED] gccrs: builtins: Add add_overflow builtin and refactor class

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * backend/rust-builtins.h: Refactor builtin context class and add overflow builtins. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/backend/rust-builtins.h | 51 ++-- 1 file changed, 36 insertions(+), 15 deletions

[COMMITTED] gccrs: rustc_attrs: Allow `rustc_inherit_overflow_checks` as a builtin..

2023-01-31 Thread Arthur Cohen
..attribute. We cannot yet handle this attribute, but we should not reject it either gcc/rust/ChangeLog: * util/rust-attributes.cc: Add `rustc_inherit_overflow_checks` to list of builtin attributes. gcc/testsuite/ChangeLog: * rust/compile/rustc_attr1.rs: New test. Test

[COMMITTED] gccrs: backend: Add overflow checks to every arithmetic operation

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Insert overflow checks logic. (CompileExpr::array_copied_expr): Insert overflow checks logic. * backend/rust-compile-item.cc (CompileItem::visit): Insert overflow checks logic.

[COMMITTED] gccrs: dump: Add AST debugging using the AST::Dump class

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * ast/rust-ast-dump.h: Add shorthand `AST::Dump::debug` function to dump an AST node on `stderr`. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/ast/rust-ast-dump.h | 16 1 file changed, 16 insertions(+) diff --git a/gcc/ru

[COMMITTED] gccrs: transcriber: Do not infinite loop if the current parsed node is an error

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (parse_many): Return early from parsing loop if we encounter an error, and emit that error in the meantime. Co-authored-by: philberty Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/expand/rust-macro-expand.cc

[COMMITTED] gccrs: ast: Only expand expressions and types if the kind is right

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * ast/rust-ast.h: Add assertions and accessors for fragment nodes. * expand/rust-attribute-visitor.cc (AttrVisitor::visit): Fix expansion context typo when visiting `InherentImpl` items. (AttrVisitor::maybe_expand_expr): Use new Fragment accessor

[COMMITTED] gccrs: ast: Add better assertion on AST fragments

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * ast/rust-ast.h: Improve assertions within ASTFragment API. Co-authored-by: philberty Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/ast/rust-ast.h | 47 ++--- 1 file changed, 39 insertions(+), 8 deletions(-)

[COMMITTED] gccrs: Create canonical process of compiling constant items

2023-01-31 Thread Arthur Cohen
From: Philip Herron In order to compile a block expression constant, the simplest way for us was to reuse what code we have and to generate an artifical function which does not get added to the translation unit. The constant then becomes a CALL_EXPR to this artifical function which we can pass to

[COMMITTED] gccrs: macros: Handle matchers properly in repetitions

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (MacroExpander::match_matcher): Handle fragments differently based on whether or not we are currently trying to match a matcher in a repetition context. (MacroExpander::match_n_matches): Use new `in_repetition` argum

[COMMITTED] gccrs: Remove param_use_canonical_types checks ported from c++ front-end

2023-01-31 Thread Arthur Cohen
From: Philip Herron We are not fully setting TYPE_CANONICAL yet but we don't need to be as strict as the C++ front-end yet. param_use_canonical_types is a command line option we are not using either. gcc/rust/ChangeLog: * backend/rust-tree.cc (comptypes): Remove some C++ specific checks

[COMMITTED] gccrs: Add extra debugging for method call expressions

2023-01-31 Thread Arthur Cohen
From: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Add more calls to `rust_debug` for development. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/typecheck/rust-hir-type-check-expr.cc | 12 1 f

[COMMITTED] gccrs: Add guards against getting data from an empty vector

2023-01-31 Thread Arthur Cohen
From: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-tyctx.cc (TypeCheckContext::pop_return_type): Add guards around `std::vector.pop_back()`. (TypeCheckContext::peek_context): Likewise for `std::vector.back()`. Tested on x86_64-pc-linux-gnu, committed on master. --

[COMMITTED] gccrs: Add missing location info to coercions

2023-01-31 Thread Arthur Cohen
From: Philip Herron gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::TypeCheckBase): Remove constructor. (TypeCheckBase::coercion_site): Add `Location` argument to function. * typecheck/rust-hir-type-check-base.h: Use `TypeCheckBase::co

[COMMITTED] gccrs: remove bad assertion

2023-01-31 Thread Arthur Cohen
From: Philip Herron gcc/rust/ChangeLog: * backend/rust-tree.cc (rs_type_quals): Comment out bad assertion Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/backend/rust-tree.cc | 7 --- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gcc/rust/backend/r

[COMMITTED] gccrs: attributes: Add #[macro_use] as builtin

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * util/rust-attributes.cc: Add `macro_use` to list of builtin attributes. gcc/testsuite/ChangeLog: * rust/compile/macro_export_1.rs: New test. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/util/rust-attributes.cc | 1 +

[COMMITTED] gccrs: Refactor unify to hit a unify_site

2023-01-31 Thread Arthur Cohen
From: Philip Herron This allows us to enforce better error handling on unify sites gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::unify_site): Add better unification function with debug calls. * typecheck/rust-autoderef.cc (AutoderefCycle::cy

[COMMITTED] gccrs: Add testcase for const-eval issue from rust-blog

2023-01-31 Thread Arthur Cohen
From: Philip Herron 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. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/testsuite/rust/compile/rust-const-blog-issue.rs

[COMMITTED] gccrs: Unit structs are not concrete when they need substitutions

2023-01-31 Thread Arthur Cohen
From: Philip Herron Fixes #1518 gcc/rust/ChangeLog: * typecheck/rust-tyty.h: Fix `is_concrete` for unit types with substitutions. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/typecheck/rust-tyty.h | 5 + 1 file changed, 5 insertions(+) diff --git a/gc

[COMMITTED] gccrs: Add new check for contains_associated_types

2023-01-31 Thread Arthur Cohen
From: Philip Herron We don't need to setup associated types when a trait does not contain any associated types. gcc/rust/ChangeLog: * typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::contains_associated_types): Check if a type bound predicate contains assocated types.

[COMMITTED] gccrs: bugfix: initialize slice from array in const context

2023-01-31 Thread Arthur Cohen
From: Faisal Abbas <90.abbasfai...@gmail.com> gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Turn constant item typechecking into a coercion site instead of a unify site. gcc/testsuite/ChangeLog: * rust/compile/const6.rs: New

[COMMITTED] gccrs: testsuite/rust: add a testcase for testing ...

2023-01-31 Thread Arthur Cohen
From: liushuyu ... builtin macro and decl macro mixed expansion gcc/testsuite/ChangeLog: * rust/compile/builtin_macro_recurse.rs: New test. Signed-off-by: Zixing Liu Tested on x86_64-pc-linux-gnu, committed on master. --- .../rust/compile/builtin_macro_recurse.rs | 21 +

[COMMITTED] gccrs: Cleanup formatting of backend expression visitor

2023-01-31 Thread Arthur Cohen
From: Philip Herron gcc/rust/ChangeLog: * backend/rust-compile-expr.h: Formatting. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/backend/rust-compile-expr.h | 17 - 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/gcc/rust/backend/rust-

[COMMITTED] gccrs: Make constexpr constructors type-checking more permissive

2023-01-31 Thread Arthur Cohen
From: Philip Herron gcc/rust/ChangeLog: * backend/rust-constexpr.cc (eval_store_expression): Remove invalid assertion on constexpr constructors. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/backend/rust-constexpr.cc | 16 1 file changed, 8

[COMMITTED] gccrs: backend: correctly formulate the exit condition ...

2023-01-31 Thread Arthur Cohen
From: liushuyu ... previously the exit condition was treated the same as the loop condition (which is the inverse condition of the exit condition). Now this is corrected. gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Properly formulate exit condition w

[COMMITTED] gccrs: add testcase to test component_ref and constructor codes in eval_constant_expression()

2023-01-31 Thread Arthur Cohen
From: Faisal Abbas <90.abbasfai...@gmail.com> gcc/testsuite/ChangeLog: * rust/compile/const7.rs: New test. Signed-off-by: Faisal Abbas <90.abbasfai...@gmail.com> Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/testsuite/rust/compile/const7.rs | 12 1 file chan

[COMMITTED] gccrs: const generics: Make sure const generic types are visited properly

2023-01-31 Thread Arthur Cohen
...in all contexts. gcc/testsuite/ChangeLog: * rust/compile/const_generics_7.rs: New test. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/testsuite/rust/compile/const_generics_7.rs | 17 + 1 file changed, 17 insertions(+) create mode 100644 gcc/testsuite/r

[COMMITTED] gccrs: add testcase with struct to test component_ref and constructor codes..

2023-01-31 Thread Arthur Cohen
From: Faisal Abbas <90.abbasfai...@gmail.com> ..in eval_constant_expression() gcc/testsuite/ChangeLog: * rust/compile/const8.rs: New test. Signed-off-by: Faisal Abbas <90.abbasfai...@gmail.com> Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/testsuite/rust/compile/const8.

[COMMITTED] gccrs: Statics are a coercion site

2023-01-31 Thread Arthur Cohen
From: Philip Herron Statics can be assigned to a block expression meaning they need to behave similarly to constant items. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-toplevel.cc (TypeCheckTopLevel::visit): Make static items behave more similarly to const items. Tested

[COMMITTED] gccrs: testsuite: add loop condition execution test

2023-01-31 Thread Arthur Cohen
From: liushuyu gcc/testsuite/ChangeLog: * rust/execute/torture/loop-condition-eval.rs: New test. Signed-off-by: Zixing Liu Tested on x86_64-pc-linux-gnu, committed on master. --- .../execute/torture/loop-condition-eval.rs| 21 +++ 1 file changed, 21 insertions(+)

[COMMITTED] gccrs: rust: Add -frust-compile-until option

2023-01-31 Thread Arthur Cohen
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 testc

[COMMITTED] gccrs: const generics: Forbid default values in Functions, Traits and Impls

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * checks/errors/rust-const-checker.cc (ConstChecker::ctx_to_str): Allow getting an error string from a specific constant context. (ConstChecker::ctx_allows_default): New function, check if a context allows default values for Const generics.

[COMMITTED] gccrs: expand: eager evaluate macros inside builtin macros

2023-01-31 Thread Arthur Cohen
From: liushuyu 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 (t

[COMMITTED] gccrs: module lowering: Do not append null pointers as items

2023-01-31 Thread Arthur Cohen
Some module items do not need to get lowered to HIR such as `macro_rules!` definitions. Hence, module lowering should act the same as crate lowering: Only emplace back the lowered item if it is a valid pointer gcc/rust/ChangeLog: * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Do

[COMMITTED] gccrs: Refactor TypeResolution to be a simple query based system

2023-01-31 Thread Arthur Cohen
From: Philip Herron 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 resolut

[COMMITTED] gccrs: Static Items must be const evaluated

2023-01-31 Thread Arthur Cohen
From: Philip Herron Statics like constants need to have a singular value they are not functions to be lazy evaluated. So to evaluate a block expr we can just reuse our const code to resolve this to a singular value. gcc/rust/ChangeLog: * backend/rust-compile-item.cc (CompileItem::visit)

[COMMITTED] gccrs: Fix duplicated function generation on higher ranked trait bounds

2023-01-31 Thread Arthur Cohen
From: Philip Herron 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

[COMMITTED] gccrs: Add testcase to show forward declared items work

2023-01-31 Thread Arthur Cohen
From: Philip Herron Fixes #1006 gcc/testsuite/ChangeLog: * rust/compile/issue-1006.rs: New test. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/testsuite/rust/compile/issue-1006.rs | 10 ++ 1 file changed, 10 insertions(+) create mode 100644 gcc/testsuite/rust/c

[COMMITTED] gccrs: Add testcase to show forward declared items work via TypeAlias

2023-01-31 Thread Arthur Cohen
From: Philip Herron Fixes #1073 gcc/testsuite/ChangeLog: * rust/compile/issue-1073.rs: New test. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/testsuite/rust/compile/issue-1073.rs | 4 1 file changed, 4 insertions(+) create mode 100644 gcc/testsuite/rust/compile/i

[COMMITTED] gccrs: backend: Expose Bvariable class through rust-gcc header

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * rust-gcc.cc (class Bvariable): Move class to `rust-gcc.h` header. * rust-gcc.h: New file. Tested on x86_64-pc-linux-gnu, committed on master. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/rust-gcc.cc | 30 +-- gcc/ru

[COMMITTED] gccrs: lint: Do not emit unused warnings for public items

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * checks/lints/rust-lint-scan-deadcode.h: Do not report public items as dead code. gcc/testsuite/ChangeLog: * rust/compile/issue-1031.rs: Remove extraneous dead code warnings. * rust/compile/issue-1289.rs: Likewise. * rust/compile/test_

[COMMITTED] gccrs: parser: Parse RangeFullExpr without erroring out

2023-01-31 Thread Arthur Cohen
gcc/rust/ChangeLog: * parse/rust-parse-impl.h: Allow parsing full range expressions without erroring out. gcc/testsuite/ChangeLog: * rust/compile/parse_range.rs: New test. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/rust/parse/rust-parse-impl.h