]> git.ipfire.org Git - thirdparty/gcc.git/log
thirdparty/gcc.git
2 years agoRust: Make 'tree'-level 'MAIN_NAME_P' work
Thomas Schwinge [Wed, 12 Apr 2023 09:47:01 +0000 (11:47 +0200)] 
Rust: Make 'tree'-level 'MAIN_NAME_P' work

'gcc/tree.h':

    #define main_identifier_node global_trees[TI_MAIN_IDENTIFIER]
    #define MAIN_NAME_P(NODE) \
      (IDENTIFIER_NODE_CHECK (NODE) == main_identifier_node)

..., which is not initialized by default, but has to be set up by every front
end individually.  'MAIN_NAME_P' enables certain code optimizations, but is
especially also relevant for back ends that emit additional program entry setup
code for 'main'.

gcc/rust/
* backend/rust-compile-base.cc (HIRCompileBase::compile_function):
For 'main', initialize 'main_identifier_node'.

2 years agoRevert "Rust: Make 'tree'-level 'MAIN_NAME_P' work"
Thomas Schwinge [Fri, 14 Apr 2023 09:57:21 +0000 (11:57 +0200)] 
Revert "Rust: Make 'tree'-level 'MAIN_NAME_P' work"

This reverts commit 41c7e1d0a707f97327f097022e9e6fa7f6f13533.

2 years agoRust: Make 'tree'-level 'MAIN_NAME_P' work
Thomas Schwinge [Wed, 12 Apr 2023 09:38:58 +0000 (11:38 +0200)] 
Rust: Make 'tree'-level 'MAIN_NAME_P' work

'gcc/tree.h':

    #define main_identifier_node global_trees[TI_MAIN_IDENTIFIER]
    #define MAIN_NAME_P(NODE) \
      (IDENTIFIER_NODE_CHECK (NODE) == main_identifier_node)

..., which is not initialized by default, but has to be set up by every front
end individually.  'MAIN_NAME_P' enables certain code optimizations, but is
especially also relevant for back ends that emit additional program entry setup
code for 'main'.

gcc/rust/
* backend/rust-compile-base.cc (HIRCompileBase::compile_function):
Handle 'main' specially.
* rust-lang.cc (grs_langhook_init): Initialize
'main_identifier_node'.

2 years agoHandle underscore in MacroMatch.
Owen Avery [Fri, 7 Apr 2023 20:47:54 +0000 (16:47 -0400)] 
Handle underscore in MacroMatch.

gcc/rust/ChangeLog:

* parse/rust-parse-impl.h
(Parser::parse_macro_match): Handle underscore.

gcc/testsuite/ChangeLog:

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

2 years agoFully unify deriving classes into HIR::ExprStmt
Owen Avery [Sat, 8 Apr 2023 06:24:03 +0000 (02:24 -0400)] 
Fully unify deriving classes into HIR::ExprStmt

gcc/rust/ChangeLog:

* hir/tree/rust-hir-full-decls.h
(class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
* hir/tree/rust-hir-stmt.h
(class ExprStmt):
Add remaining ExprStmtWith{,out}Block functionality.
(class ExprStmtWithoutBlock): Remove.
(class ExprStmtWithBlock): Remove.
* hir/rust-ast-lower-stmt.cc
(ASTLoweringStmt::visit):
Lower to HIR::ExprStmt instead of deriving class.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 years agoUnify HIR::ExprStmt derived class visiting
Owen Avery [Sat, 8 Apr 2023 05:37:56 +0000 (01:37 -0400)] 
Unify HIR::ExprStmt derived class visiting

gcc/rust/ChangeLog:

* backend/rust-compile-stmt.cc
(CompileStmt::visit): Unify ExprStmtWith{,out}Block visitors.
* backend/rust-compile-stmt.h
(CompileStmt::visit): Likewise.
* backend/rust-compile-item.h
(CompileItem::visit): Likewise.
* hir/rust-hir-dump.cc
(Dump::visit): Likewise.
* hir/rust-hir-dump.h
(Dump::visit): Likewise.
* hir/tree/rust-hir-stmt.h
(ExprStmt::accept_vis): Add.
(ExprStmtWithoutBlock::accept_vis): Remove.
(ExprStmtWithBlock::accept_vis): Remove.
* hir/tree/rust-hir.cc
(ExprStmt::accept_vis): Add.
(ExprStmtWithoutBlock::accept_vis): Remove.
(ExprStmtWithBlock::accept_vis): Remove.
* hir/tree/rust-hir-visitor.h
(HIRFullVisitor::visit): Likewise.
(HIRFullVisitorBase::visit): Likewise.
(HIRStmtVisitor::visit): Likewise.
* checks/errors/rust-const-checker.cc
(ConstChecker::visit): Likewise.
* checks/errors/rust-const-checker.h
(ConstChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.cc
(UnsafeChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.h
(UnsafeChecker::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h
(PrivacyReporter::visit): Likewise.
* checks/lints/rust-lint-marklive.h
(MarkLive::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.cc
(TypeCheckStmt::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.h
(TypeCheckStmt::visit): Likewise.
* typecheck/rust-tycheck-dump.h
(TypeResolverDump::visit): Likewise.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 years agoMove method as_string into HIR::ExprStmt from deriving classes
Owen Avery [Sun, 5 Feb 2023 01:24:32 +0000 (20:24 -0500)] 
Move method as_string into HIR::ExprStmt from deriving classes

gcc/rust/ChangeLog:

* hir/tree/rust-hir.cc
(ExprStmt::as_string): Add method.
(ExprStmtWithBlock::as_string): Remove method.
(ExprStmtWithoutBlock::as_string): Remove method.
* hir/tree/rust-hir-stmt.h
(ExprStmt::as_string): Add method.
(ExprStmtWithBlock::as_string): Remove method.
(ExprStmtWithoutBlock::as_string): Remove method.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 years agoMove functionality into HIR::ExprStmt from deriving classes
Owen Avery [Sun, 5 Feb 2023 01:15:52 +0000 (20:15 -0500)] 
Move functionality into HIR::ExprStmt from deriving classes

gcc/rust/ChangeLog:

* hir/tree/rust-hir-stmt.h
(ExprStmt::expr): Add field.
(ExprStmt::get_expr): Add method.
(ExprStmt::ExprStmt): Add copy/move constructors, modify existing constructor.
(ExprStmt::operator=): Add assignment operator.
(ExprStmtWithoutBlock::expr): Remove field.
(ExprStmtWithoutBlock::get_expr): Remove method.
(ExprStmtWithoutBlock::ExprStmt):
Remove copy/move constructors, modify existing constructor.
(ExprStmtWithoutBlock::operator=): Remove assignment operator.
(ExprStmtWithBlock::expr): Remove field.
(ExprStmtWithBlock::get_expr): Remove method.
(ExprStmtWithBlock::ExprStmt): Remove copy/move constructors, modify existing constructor.
(ExprStmtWithBlock::operator=): Remove assignment operator.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 years agoUnify AST::IfExprConseqIf{,Let} into AST::IfExprConseqElse
Owen Avery [Thu, 16 Mar 2023 03:05:07 +0000 (23:05 -0400)] 
Unify AST::IfExprConseqIf{,Let} into AST::IfExprConseqElse

This simplifies the AST's representation of if-statements
to match the HIR.

gcc/rust/ChangeLog:

* ast/rust-expr.h
(class IfExprConseqElse): Make else_block ExprWithBlock.
(class IfExprConseqIf): Remove.
(class IfExprConseqIfLet): Remove.
* ast/rust-ast-full-decls.h
(class IfExprConseqIf): Remove.
(class IfExprConseqIfLet): Remove.
* ast/rust-ast.cc
(IfExprConseqElse::as_string): Adjust output.
(IfExprConseqIf::as_string): Remove.
(IfExprConseqIfLet::as_string): Remove.
(IfExprConseqIf::accept_vis): Remove.
(IfExprConseqIfLet::accept_vis): Remove.
* ast/rust-ast-visitor.h
(ASTVisitor::visit): Remove IfExprConseqIf{,Let} visitors.
* ast/rust-ast-tokenstream.cc
(TokenStream::visit): Likewise.
* ast/rust-ast-tokenstream.h
(TokenStream::visit): Likewise.
* ast/rust-ast-dump.cc
(Dump::visit): Likewise.
* ast/rust-ast-dump.h
(Dump::visit): Likewise.
* checks/errors/rust-feature-gate.h
(FeatureGate::visit): Likewise.
* util/rust-attributes.cc
(AttributeChecker::visit): Likewise.
* util/rust-attributes.h
(AttributeChecker::visit): Likewise.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.
* resolve/rust-early-name-resolver.h
(EarlyNameResolver::visit): Likewise.
* resolve/rust-ast-resolve-base.h
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-base.cc
(ResolverBase::visit): Likewise.
* resolve/rust-ast-resolve-expr.h
(ResolveExpr::visit): Remove IfExprConseqIf visitor.
* resolve/rust-ast-resolve-expr.cc
(ResolveExpr::visit): Likewise.
* expand/rust-cfg-strip.cc
(CfgStrip::visit): Remove IfExprConseqIf{,Let} visitors.
* expand/rust-cfg-strip.h
(CfgStrip::visit): Likewise.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Likewise.
* expand/rust-expand-visitor.h
(ExpandVisitor::visit): Likewise.
* hir/rust-ast-lower-base.cc
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-base.h
(ASTLoweringBase::visit): Likewise.
* hir/rust-ast-lower-block.h
(ASTLoweringIfBlock::visit): Remove IfExprConseqIf visitor.
(ASTLoweringExprWithBlock::visit): Likewise.
* hir/rust-ast-lower.cc
(ASTLoweringIfBlock::visit):
Remove IfExprConseqIf visitor, adjust IfExprConseqElse lowering.
* hir/rust-ast-lower-expr.h
(ASTLoweringExpr::visit): Remove IfExprConseqIf visitor.
* hir/rust-ast-lower-expr.cc
(ASTLoweringExpr::visit): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_if_expr): Replace IfExprConseqIf{,Let} with IfExprConseqElse.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2 years agoast: Fix inner attribute tokenstream
Pierre-Emmanuel Patry [Tue, 11 Apr 2023 16:11:09 +0000 (18:11 +0200)] 
ast: Fix inner attribute tokenstream

Inner attribute did not output exclamation tokens as there was no way to
differentiate inner from outer attributes previously.

gcc/rust/ChangeLog:

* ast/rust-ast-tokenstream.cc (TokenStream::visit): Fix inner
attribute tokenstream output.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 years agoMerge commit 'df3a80d97fe58eafcd880448b3768ca302c743f6' into HEAD [#2115]
Thomas Schwinge [Tue, 11 Apr 2023 08:43:08 +0000 (10:43 +0200)] 
Merge commit 'df3a80d97fe58eafcd880448b3768ca302c743f6' into HEAD [#2115]

2 years agogccrs: Introduce AST::Visitable class for AST
Marc Poulhiès [Thu, 6 Apr 2023 17:20:55 +0000 (19:20 +0200)] 
gccrs: Introduce AST::Visitable class for AST

AST::Visitable is an abstract class with a unique accept_vis() method.
Make all abstract AST node class inherit from this class.

Allows for easy definition of operations on nodes that must accept a
visitor.

The static Dump::dump() is an example of such use: the static method
accepts any AST node, creates a Dump visitor and have it visit the AST
starting at the node.

This change also inserts a debug(Visitable&) function in the global
namespace to make it easy to call from the debugger (similar to
debug_tree or debug(rtx*) functions).

gcc/rust/ChangeLog:

* ast/rust-ast-dump.cc (Dump::debug): New.
* ast/rust-ast-dump.h (Dump::debug): Untemplate it.
(debug): New.
* ast/rust-ast.h (class Visitable): New.
(class TokenTree): Inherit from Visitable.
(class MacroMatch): Likewise.
(class AttrInput): Likewise.
(class MetaItemInner): Likewise.
(class Pattern): Likewise.
(classTypeParamBound): Likewise.
(class GenericParam): Likewise.
(class TraitItem): Likewise.
(classInherentImplItem): Likewise.
(class TraitImplItem): Likewise.
(class ExternalItem): Likewise.
(class SingleASTNode): Likewise.

Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2 years agoPlacate clang-format, 'gcc/rust/rust-lang.cc:grs_langhook_type_for_mode'
Thomas Schwinge [Tue, 11 Apr 2023 06:47:24 +0000 (08:47 +0200)] 
Placate clang-format, 'gcc/rust/rust-lang.cc:grs_langhook_type_for_mode'

Yesterday's commit 3757e8d71794cece4a5c9d08245b7ad111044853
"Merge commit '6baa95c9c5b3fea96fd22d03d961db4e4cf48d88' into HEAD [#2112]"
brought in the #1713 change from GCC upstream master branch that broke the
rules (via code copied verbatim from elsehwhere in GCC).

gcc/rust/
* rust-lang.cc (grs_langhook_type_for_mode): Placate clang-format.

2 years agoMerge upstream (dummy), "Rust front-end update 2023-04-05"
Thomas Schwinge [Mon, 10 Apr 2023 09:06:35 +0000 (11:06 +0200)] 
Merge upstream (dummy), "Rust front-end update 2023-04-05"

In #2112 'Merge upstream, last commit before "Rust front-end update 2023-04-05"'
we merged commit 939fb3fffebf7be2638ddef25dbe1c15f2aaa9d6 from upstream GCC
master branch.

This one now merges the "Rust front-end update 2023-04-05", commits
939fb3fffebf7be2638ddef25dbe1c15f2aaa9d6..d2a499a9881c7c079d2a722b57c7fcf022a864dd:

      - f66b135d0b5 gccrs: fatal_error_flag: Fix typo in error message
      - 776ff053800 gccrs: unsafe: check use of `target_feature` attribute
      - d9e05700ac3 gccrs: Check for mutable references in const functions
      - ef792b9658d gccrs: rust: add bound parsing in parse_generic_arg.
      - e1394230b3f gccrs: Implement declarative macro 2.0 parser
      - 3f1dbb2cf8f gccrs: Add name resolution to generic argument associated item bindings
      - 7eab9d18d97 gccrs: Support associated type bound arguments
      - 364f4cd3072 gccrs: Reuse TypeCheckPattern on LetStmt's
      - 8e2abbef4cc gccrs: Add get_locus function for abstract class MetaItemInner.
      - 86f8e47f9df gccrs: diagnostics: Add underline for tokens in diagnostics.
      - 881ed7fb273 gccrs: Change how CompileVarDecl outputs Bvariable's
      - 60affc3a1c5 gccrs: testsuite: Handle Windows carriage returns properly
      - 910e7e0a958 gccrs: Support GroupedPattern during name resolution
      - cb42610bfba gccrs: Do not crash on empty macros expand. Fixes #1712
      - 93fcadd208a gccrs: Add HIR lowering for GroupedPattern
      - d5a303cc664 gccrs: Add get_item method for HIR::GroupedPattern
      - 83e5f634d74 gccrs: Add type resolution for grouped patterns
      - 221650c280c gccrs: Added missing GroupedPattern visitors for code generation
      - 9b19e93873c gccrs: Rename file rust-ast-full-test.cc to rust-ast.cc
      - d6cb04bf5c0 gccrs: moved operator.h to util/rust-operators.h
      - 760f529d813 gccrs: fixed compiler error message on wildcard pattern within expression
      - 8e7e682a9f8 gccrs: fixed indentations in AST pretty expanded dump of trait
      - 51b607c2227 gccrs: macro: Allow builtin `MacroInvocation`s within the AST
      - ad9d75f5080 gccrs: Create and use CompilePatternLet visitor for compiling let statments
      - 9cbd270632b gccrs: parser: Allow parsing multiple reference types
      - 2dab57c3f2f gccrs: Move rust-buffered-queue.h to util folder #1766
      - fd7358af3cf gccrs: Improve GroupedPattern lowering
      - 95efd84db13 gccrs: Remove HIR::GroupedPattern
      - 0e4bf6e7fc4 gccrs: Optimize HIR::ReferencePattern
      - 86f53e5853d gccrs: Implement lowering ReferencePattern from AST to HIR
      - 2af66ebd1d8 gccrs: parser: Improve parsing of complex generic arguments
      - 7f5144d1c96 gccrs: parser: Fix parsing of closure param list
      - 476faea3563 gccrs: Add  support for feature check.
      - 4141941ae7b gccrs: Removed comment copy-pasted from gcc/tree.def
      - 8d1d08cdbcf gccrs: Add another test case for passing associated type-bounds
      - c1b1bbbc645 gccrs: Move TypePredicateItem impl out of the header
      - 688fccb5227 gccrs: Refactor TyVar and TypeBoundPredicates
      - e42118c327f gccrs: Refactor SubstitutionRef base class into its own CC file
      - 6abbfb5280f gccrs: Refactor all substitution mapper code implementation into its own CC file
      - d73082efece gccrs: Refactor BaseType, InferType and ErrorType impl into cc file
      - 26af4b0604d gccrs: Refactor PathProbe into cc file
      - 547e511fbdd gccrs: Refactor PathProbeType code into CC file
      - 615ee14c08e gccrs: Refactor all code out of the rust-tyty.h header
      - 6c4fa22d384 gccrs: Rename rust-tyctx.cc to rust-typecheck-context.cc
      - 1019fd6337b gccrs: Rename header rust-hir-trait-ref.h to rust-hir-trait-reference.h
      - dcb2e571ac6 gccrs: Refactor handle_substitutions to take a reference
      - 2f228578d56 gccrs: Clear the substitution callbacks when copying ArgumentMappings
      - 31f1e59962b gccrs: Add missing param subst callback
      - e42c28bcfdd gccrs: Remove monomorphization hack to setup possible associated types
      - 68d671ac725 gccrs: Refactor the type unification code
      - 2a2e6712ba0 gccrs: Fix nullptr dereference
      - f62dcf2c65a gccrs: Add missing Sized, Copy and Clone lang item mappings
      - 9754a60623c gccrs: Fix higher ranked trait bounds computation of self
      - 11150b7c05c gccrs: Remove bad error message on checking function arguments
      - eb4a61ac1ba gccrs: Add general TypeBounds checks
      - fa7b3a2f07f gccrs: Add support for TuplePattern in let statements
      - 1c57244dbc0 gccrs: rust-item: include rust-expr.h
      - f548ddee96a gccrs: parser: Expose parse_macro_invocation as public API
      - 2d30e0b882f gccrs: expansion: Add `get_token_slice` to `MacroInvocLexer` class
      - 3821669164d gccrs: macros: Perform macro expansion in a fixed-point fashion.
      - fbd5244df6b gccrs: expander: Add documentation for `expand_eager_invocations`
      - 5fd04425c09 gccrs: typecheck: Refactor rust-hir-trait-reference.h
      - f64799a567e gccrs: cli: Update safety warning message
      - b4229fb086b gccrs: Update copyright years.
      - fd5eb9f2b01 gccrs: Add feature gate for "rust-intrinsic".
      - a9d72ef2d03 gccrs: Add variadic argument type checking
      - 8a9886a85ea gccrs: Add test
      - e81f5be60d1 gccrs: Simplify WildcardPattern let statement handling
      - b56d093e952 gccrs: lex: Prevent directories in RAIIFile
      - 7b00a80c9df gccrs: testsuite: Add empty string macro test
      - 20529dff93f gccrs: Add support for parsing empty tuple patterns.
      - fd406fc7046 gccrs: Implemented UTF-8 checking for include_str!()
      - c627781b8f6 gccrs: Extract query_type from TypeCheckBase to be a simple extern
      - e90d06c5447 gccrs: Add new virtual function HIR::ImplItem::get_impl_item_name
      - 4b25fc15b92 gccrs: Support for Sized builtin marker trait
      - a11b44b6a57 gccrs: Fix regression in testcase
      - ecdce2bf17a gccrs: Add trailing newline
      - 8b0ed2387a5 gccrs: builtins: Return empty list of tokens instead of nullptr
      - 6774d569c61 gccrs: Fix formatting
      - 8628486f487 gccrs: Add AST::AltPattern class
      - 0ec543c7c61 gccrs: Fix up DejaGnu directives in 'rust/compile/issue-1830_{bytes,str}.rs' test cases [#1838]
      - 1a58da7c2d8 gccrs: rename rust-hir-full-tests.cc
      - 3b342e11627 gccrs: add test case to show our query-type system is working
      - fa7675df86a gccrs: ast: Refactor TraitItem to keep Location info
      - 2785d591116 gccrs: diagnostic: Refactor Error class
      - f2d6ab839ce gccrs: Added AST Node AST::InlineAsm
      - 990ae497b86 gccrs: Address unsafe with/without block handling ambiguity
      - d2a499a9881 gccrs: Fix issue with parsing unsafe block expression statements

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 commit '6baa95c9c5b3fea96fd22d03d961db4e4cf48d88' into HEAD [#2112]
Thomas Schwinge [Mon, 10 Apr 2023 08:59:48 +0000 (10:59 +0200)] 
Merge commit '6baa95c9c5b3fea96fd22d03d961db4e4cf48d88' into HEAD [#2112]

2 years agoAdjust '.github/bors_log_expected_warnings'
Thomas Schwinge [Sat, 8 Apr 2023 21:02:06 +0000 (23:02 +0200)] 
Adjust '.github/bors_log_expected_warnings'

2 years agoMerge commit '939fb3fffebf7be2638ddef25dbe1c15f2aaa9d6' into HEAD
Thomas Schwinge [Fri, 7 Apr 2023 20:04:54 +0000 (22:04 +0200)] 
Merge commit '939fb3fffebf7be2638ddef25dbe1c15f2aaa9d6' into HEAD

2 years agoMerge commit 'aee5ee35602e0098c2ae16fa2fc9c8845caf92ed' into HEAD
Thomas Schwinge [Fri, 7 Apr 2023 19:56:15 +0000 (21:56 +0200)] 
Merge commit 'aee5ee35602e0098c2ae16fa2fc9c8845caf92ed' into HEAD

Addresses: #1713
Fixes: #1973
2 years agoMerge commit 'aee5ee35602e0098c2ae16fa2fc9c8845caf92ed~1' into HEAD
Thomas Schwinge [Fri, 7 Apr 2023 19:56:06 +0000 (21:56 +0200)] 
Merge commit 'aee5ee35602e0098c2ae16fa2fc9c8845caf92ed~1' into HEAD

2 years agoMerge commit '334f23d83261997ca89d8919b94b97aa22003a65' into HEAD
Thomas Schwinge [Fri, 7 Apr 2023 19:53:02 +0000 (21:53 +0200)] 
Merge commit '334f23d83261997ca89d8919b94b97aa22003a65' into HEAD

2 years agoMerge commit '320dc51c2d9969f644885cc1afa0d8a924f0ab87' into HEAD [#1540]
Thomas Schwinge [Fri, 7 Apr 2023 19:50:40 +0000 (21:50 +0200)] 
Merge commit '320dc51c2d9969f644885cc1afa0d8a924f0ab87' into HEAD [#1540]

2 years agoMerge commit '7411eca498beb13729cc2acec77e68250940aa81' into HEAD
Thomas Schwinge [Fri, 7 Apr 2023 19:44:55 +0000 (21:44 +0200)] 
Merge commit '7411eca498beb13729cc2acec77e68250940aa81' into HEAD

2 years agoMerge commit '7411eca498beb13729cc2acec77e68250940aa81~1' into HEAD
Thomas Schwinge [Fri, 7 Apr 2023 19:43:06 +0000 (21:43 +0200)] 
Merge commit '7411eca498beb13729cc2acec77e68250940aa81~1' into HEAD

2 years agoast: Add difference between attributes
Pierre-Emmanuel Patry [Wed, 5 Apr 2023 10:36:41 +0000 (12:36 +0200)] 
ast: Add difference between attributes

Add a boolean to tell inner and outer attributes ast nodes appart. This
meant refactoring a bit their parsing function.

gcc/rust/ChangeLog:

* ast/rust-ast.h: Add boolean for differenciation.
* parse/rust-parse-impl.h (Parser::parse_doc_comment): Change
function interface to make code cleaner. It should return a body
instead of the whole attribute.
(Parser::parse_inner_attribute): Specify the inner status of the
node.
(Parser::parse_attribute_body): Change function interface to
make the code cleaner much like parse_doc_comment.
(Parser::parse_outer_attribute): Specify outer status of the
node.
* parse/rust-parse.h: Update functions prototypes.

Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2 years agogccrs: Fix issue with parsing unsafe block expression statements
Owen Avery [Fri, 27 Jan 2023 03:59:49 +0000 (22:59 -0500)] 
gccrs: Fix issue with parsing unsafe block expression statements

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

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

gcc/rust/ChangeLog:

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

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

Fixes #1361

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

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

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

gcc/rust/Changelog:

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

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

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

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

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

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

Fixes #776

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

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

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

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

Fixes #1725

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

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

gcc/testsuite/ChangeLog:

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

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

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

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

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

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

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

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

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

gcc/testsuite/ChangeLog:

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

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/testsuite/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

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

gcc/rust/ChangeLog:

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

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

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

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

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

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

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

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
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 agogccrs: Removed comment copy-pasted from gcc/tree.def
Owen Avery [Sat, 4 Feb 2023 17:07:38 +0000 (12:07 -0500)] 
gccrs: Removed comment copy-pasted from gcc/tree.def

gcc/rust/ChangeLog:

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

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

This commit implements a very basic feature checking module.

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

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

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

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

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

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

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

gcc/rust/ChangeLog:

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

gcc/testsuite/ChangeLog:

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

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

gcc/rust/ChangeLog:

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

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>