]>
git.ipfire.org Git - thirdparty/gcc.git/log
0xn4utilus [Wed, 28 Feb 2024 14:05:30 +0000 (19:35 +0530)]
Remove dead code associated with `AST::ExternalFunctionItem`
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit):
Remove dead code.
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-full-decls.h (class ExternalFunctionItem):
Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit):
Likewise.
* ast/rust-ast-visitor.h: Likewise.
* ast/rust-ast.cc (ExternalFunctionItem::as_string): Likewise.
(ExternalFunctionItem::accept_vis): Likewise.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Likewise.
* checks/errors/rust-ast-validation.h: Likewise.
* checks/errors/rust-feature-gate.h: Likewise.
* expand/rust-cfg-strip.cc (CfgStrip::visit):
Likewise.
* expand/rust-cfg-strip.h: Likewise.
* expand/rust-derive.h: Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit):
Likewise.
* expand/rust-expand-visitor.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit):
Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* metadata/rust-export-metadata.cc (ExportContext::emit_function):
Likewise.
* parse/rust-parse-impl.h: Likewise.
* parse/rust-parse.h: Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit):
Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
* resolve/rust-default-resolver.cc (DefaultResolver::visit):
Likewise.
* resolve/rust-default-resolver.h: Likewise.
* util/rust-attributes.cc (AttributeChecker::visit): Likewise.
* util/rust-attributes.h: Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/extern_func_with_body.rs: New test.
Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
0xn4utilus [Sun, 25 Feb 2024 23:09:43 +0000 (04:39 +0530)]
Update resolver to use `AST::Function` instead of `AST::ExternalFunctionItem`
gcc/rust/ChangeLog:
* checks/errors/rust-feature-gate.cc (FeatureGate::visit):
Check if function is_external or not.
* hir/rust-ast-lower-extern.h: Use AST::Function
instead of AST::ExternalFunctionItem.
* parse/rust-parse-impl.h (Parser::parse_external_item):
Likewise.
(Parser::parse_pattern): Fix clang format.
* resolve/rust-ast-resolve-implitem.h: Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveExternItem::visit):
Likewise.
* resolve/rust-ast-resolve-item.h: Likewise.
* resolve/rust-default-resolver.cc (DefaultResolver::visit):
Check if param has_pattern before using get_pattern.
Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
0xn4utilus [Sun, 25 Feb 2024 13:33:55 +0000 (19:03 +0530)]
Unify ASTValidation::visit for ExternalFunctionItem and Function
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Add external function validation support. Add ErrorCode::E0130.
* parse/rust-parse-impl.h (Parser::parse_function): Parse
external functions from `parse_function`.
(Parser::parse_external_item): Clang format.
(Parser::parse_pattern): Clang format.
* parse/rust-parse.h: Add default parameter
`is_external` in `parse_function`.
Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
0xn4utilus [Sun, 25 Feb 2024 00:50:51 +0000 (06:20 +0530)]
Add get_pattern_kind to Pattern
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add Kind Enum to
Pattern.
* ast/rust-macro.h: Add get_pattern_kind().
* ast/rust-path.h: Likewise.
* ast/rust-pattern.h: Likewise.
Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
0xn4utilus [Sun, 25 Feb 2024 00:02:26 +0000 (05:32 +0530)]
Add support for external functions
gcc/rust/ChangeLog:
* ast/rust-ast.cc (Function::Function): Add `is_external_function` field.
(Function::operator=): Likewise.
* ast/rust-ast.h: New constructor for ExternalItem.
* ast/rust-item.h (class Function): Add `is_external_function`
field. Update `get_node_id`.
* ast/rust-macro.h: Update copy constructor.
Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
Sourabh Jaiswal [Fri, 1 Mar 2024 11:46:23 +0000 (19:46 +0800)]
Clean BiMap to use tl::optional for lookups
gcc/rust/Changelog:
* expand/rust-expand-visitor.cc
(ExpandVisitor::expand_inner_items): Adjust to use has_value ()
(ExpandVisitor::expand_inner_stmts): Likewise
* expand/rust-macro-builtins.cc (builtin_macro_from_string): Likewise
(make_macro_path_str): Likewise
* util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise
* util/rust-lang-item.cc (LangItem::Parse): Adjust to return tl::optional
(LangItem::toString) Likewise
* util/rust-token-converter.cc (handle_suffix): Adjust to use value.or ()
(from_literal) Likewise
* util/bi-map.h (BiMap::lookup): Adjust to use tl::optional for
lookups
Signed-off-by: Sourabh Jaiswal <sourabhrj31@gmail.com>
Owen Avery [Tue, 27 Feb 2024 21:34:23 +0000 (16:34 -0500)]
Ensure TupleStructPattern and TuplePattern have items
Note that instances of both classes which have been
moved from will have (items == nullptr).
gcc/rust/ChangeLog:
* ast/rust-pattern.h
(class TupleStructPattern): Assert that items != nullptr.
(class TuplePattern): Likewise.
(TupleStructPattern::has_items): Remove.
(TuplePattern::has_tuple_pattern_items): Likewise.
* parse/rust-parse-impl.h
(Parser::parse_ident_leading_pattern):
Prevent construction of TupleStructPattern with
(items == nullptr).
(Parser::parse_pattern_no_alt): Likewise.
* ast/rust-ast-collector.cc
(TokenCollector::visit): Remove usage of
TupleStructPattern::has_items.
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Likewise.
* resolve/rust-early-name-resolver.cc
(EarlyNameResolver::visit): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/pattern-struct.rs: Fix test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
jjasmine [Fri, 1 Mar 2024 21:40:17 +0000 (16:40 -0500)]
Add curly brackets, formatted clang
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add error emitting
jjasmine [Fri, 1 Mar 2024 10:31:15 +0000 (05:31 -0500)]
Add error emitting when we can't resolve id expr
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add error emitting
Arthur Cohen [Fri, 1 Mar 2024 14:37:45 +0000 (15:37 +0100)]
format-args: Add documentation for future expansion of function
gcc/rust/ChangeLog:
* expand/rust-macro-builtins.cc (MacroBuiltin::format_args_handler): Add
documentation regarding future tasks.
Arthur Cohen [Thu, 22 Feb 2024 13:59:17 +0000 (14:59 +0100)]
lower: Add base for lowering FormatArgs nodes
gcc/rust/ChangeLog:
* Make-lang.in: Compile the new source file.
* ast/rust-ast-collector.cc (TokenCollector::visit): Error out when
visiting FormatArgs nodes.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* ast/rust-ast.cc (FormatArgs::get_locus): New.
* ast/rust-builtin-ast-nodes.h: Improve FormatArgs API.
* ast/rust-fmt.cc (Pieces::~Pieces): Cleanup.
(Pieces::Pieces): Likewise.
* ast/rust-fmt.h (struct Pieces): Add pieces_vector member.
* hir/rust-ast-lower-format-args.cc: New file.
* hir/rust-ast-lower-format-args.h: New file.
Arthur Cohen [Fri, 16 Feb 2024 17:27:22 +0000 (18:27 +0100)]
format-args: Fix Rust interface and add input parsing.
gcc/rust/ChangeLog:
* Make-lang.in: Do not build Rust library in release mode.
* ast/rust-ast.cc: Make FormatArgs inherit from AST::Expr
* ast/rust-builtin-ast-nodes.h: Improve FormatArg* nodes and helpers.
* ast/rust-fmt.cc (Pieces::collect): Fix interface to match FFI function.
* ast/rust-fmt.h (collect_pieces): Likewise.
(struct Pieces): Add append_newline parameter.
* expand/rust-macro-builtins.cc: Add proper parsing of format_args
input.
* hir/rust-ast-lower-base.cc: Include diagnostics header.
libgrust/ChangeLog:
* libformat_parser/src/lib.rs: Switch interface to use more parser
parameters.
* libformat_parser/src/bin.rs: Use new interface.
Arthur Cohen [Mon, 19 Feb 2024 19:41:50 +0000 (20:41 +0100)]
parser: Add peek(n) method to parser
gcc/rust/ChangeLog:
* parse/rust-parse.h: New method.
Arthur Cohen [Fri, 16 Feb 2024 15:19:27 +0000 (16:19 +0100)]
macro-builtins: Add newline generic format_args!() handler
gcc/rust/ChangeLog:
* expand/rust-macro-builtins.cc (format_args_maker): New function.
(try_expand_many_expr): Add comment about reworking function.
(MacroBuiltin::format_args_handler): Add newline parameter.
* expand/rust-macro-builtins.h: Likewise.
Arthur Cohen [Thu, 15 Feb 2024 19:58:48 +0000 (20:58 +0100)]
ast: Add base nodes for FormatArgs
This commit adds a base for creating AST FormatArgs nodes after expanding
invocations of `format_args!()`. These nodes will then be expanded to
the proper runtime function calls (to core::fmt::rt) during the AST
lowering.
gcc/rust/ChangeLog:
* ast/rust-builtin-ast-nodes.h: New file.
* ast/rust-ast-full-decls.h (class FormatArgs): Declare new class.
* ast/rust-ast-collector.cc: Handle FormatArgs nodes properly.
* ast/rust-ast-collector.h: Likewise.
* ast/rust-ast-full.h: Likewise.
* ast/rust-ast-visitor.cc: Likewise.
* ast/rust-ast-visitor.h: Likewise.
* ast/rust-ast.cc: Likewise.
* ast/rust-ast.h: Likewise.
* expand/rust-derive.h: Likewise.
* hir/rust-ast-lower-base.cc: Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-expr.cc: Likewise.
* hir/rust-ast-lower-expr.h: Likewise.
* resolve/rust-ast-resolve-base.cc: Likewise.
* resolve/rust-ast-resolve-base.h: Likewise.
Owen Avery [Wed, 28 Feb 2024 22:42:49 +0000 (17:42 -0500)]
Make DefaultResolver visit more of the AST
gcc/rust/ChangeLog:
* resolve/rust-default-resolver.cc
(DefaultResolver::visit): Visit inner AST nodes of ClosureExprInner,
ClosureExprInnerTyped, IfExpr, IfExprConseqElse, MatchExpr,
PathInExpression, EnumItemTuple, EnumItemStruct, and
EnumItemDiscriminant.
* ast/rust-item.h
(EnumItemDiscriminant::has_expr): New function.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Arthur Cohen [Tue, 20 Feb 2024 15:22:20 +0000 (16:22 +0100)]
extern-types: Lower to HIR::ExternalTypeItem properly
gcc/rust/ChangeLog:
* hir/rust-ast-lower-extern.h: Lower to HIR::ExternalTypeItem nodes.
* hir/tree/rust-hir-item.h (class ExternalTypeItem): Create private
visibility by default as extern types have no visibility - add a comment
about the correctness of this.
Arthur Cohen [Tue, 20 Feb 2024 14:45:35 +0000 (15:45 +0100)]
hir: Add ExternalTypeItem node
gcc/rust/ChangeLog:
* hir/tree/rust-hir-item.h (class ExternalTypeItem): New class.
* hir/tree/rust-hir.cc (ExternalTypeItem::as_string): Likewise.
* backend/rust-compile-extern.h: Add base for handling HIR::ExternalTypeItem
node.
* checks/errors/borrowck/rust-bir-builder-struct.h: Likewise.
* checks/errors/borrowck/rust-function-collector.h: Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-const-checker.h: Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.h: Likewise.
* hir/rust-ast-lower-extern.h: Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/rust-hir-dump.h: Likewise.
* hir/tree/rust-hir-full-decls.h (class ExternalTypeItem): Likewise.
* hir/tree/rust-hir-visitor.h: Likewise.
(ExternalTypeItem::accept_vis): Likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.h: Likewise.
Arthur Cohen [Tue, 20 Feb 2024 13:53:32 +0000 (14:53 +0100)]
extern-types: Declare external types in name resolver.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-implitem.h: Declare external types as new
types.
Arthur Cohen [Tue, 27 Feb 2024 13:39:22 +0000 (14:39 +0100)]
lang-items: Make lang items enum stronger, rename class, cleanup ns.
gcc/rust/ChangeLog:
* util/rust-lang-item.h (class RustLangItem): Renamed to...
(class LangItem): ...this. Rename ItemType enum to Kind
* util/rust-lang-item.cc: Rename methods to use new class name.
* backend/rust-compile-expr.cc (CompileExpr::visit): Use new lang-item API.
(CompileExpr::resolve_operator_overload): Likewise.
* backend/rust-compile-expr.h: Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_lang_item_attribute): Likewise.
* typecheck/rust-autoderef.cc (Adjuster::try_deref_type): Likewise.
(AutoderefCycle::cycle): Likewise.
* typecheck/rust-autoderef.h: Likewise.
* typecheck/rust-hir-type-bounds.h: Likewise.
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::get_marker_predicate): Likewise.
* typecheck/rust-hir-type-check-base.h: Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::visit): Likewise.
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_sized_builtin): Likewise.
(TypeBoundsProbe::assemble_builtin_candidate): Likewise.
(TypeCheckBase::get_predicate_from_bound): Likewise.
* typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): Likewise.
* util/rust-hir-map.cc (Mappings::get_lang_item): Likewise.
(Mappings::lookup_trait_item_lang_item): Likewise.
* util/rust-hir-map.h: Likewise.
Arthur Cohen [Tue, 27 Feb 2024 12:35:50 +0000 (13:35 +0100)]
lang-items: Cleanup parsing and lookups of lang items.
gcc/rust/ChangeLog:
* Make-lang.in: Compile new rust-lang-item.o.
* util/rust-lang-item.h: Split into header and source.
* util/rust-lang-item.cc: Cleanup parsing of lang items by using a hashmap
and returning optional values, cleanup handling of exhaustive lang item
lookups.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_lang_item_attribute): Use
new optional API.
Thomas Schwinge [Thu, 29 Feb 2024 13:04:29 +0000 (14:04 +0100)]
jjasmine [Fri, 23 Feb 2024 21:06:14 +0000 (13:06 -0800)]
Fix small FixMe task in rust macro builtins
gcc/rust/ChangeLog:
* expand/rust-macro-builtins.cc: Change BuiltinMacro in
builtin_macro_from_string to tl::optional<>
* expand/rust-macro-builtins.h (enum class): Change BuiltinMacro
in builtin_macro_from_string to tl::optional<>
* resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit):
Resolved wrong type dependency of builtin_macro_from_string
Signed-off-by: jjasmine <tanghocle456@gmail.com>
Owen Avery [Fri, 23 Feb 2024 15:20:55 +0000 (10:20 -0500)]
Adjust error checks to match name resolution 2.0
gcc/testsuite/ChangeLog:
* rust/compile/bad_stmt_enums.rs: Adjust redefinition error.
* rust/compile/bad_toplevel_enums.rs: Likewise.
* rust/compile/redef_error1.rs: Likewise.
* rust/compile/redef_error3.rs: Likewise.
* rust/compile/redef_error4.rs: Likewise.
* rust/compile/redef_error6.rs: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Arthur Cohen [Mon, 26 Feb 2024 10:57:54 +0000 (11:57 +0100)]
ci: Install cargo on ubuntu 18.04 container.
ChangeLog:
* .github/workflows/ccpp.yml: Install cargo for GCC 4.8 job.
Arthur Cohen [Mon, 26 Feb 2024 10:55:47 +0000 (11:55 +0100)]
format-parser: Add `is_some_and` method for Option<T>
Workaround for Ubuntu 18.04, since we still use it for the GCC 4.8 CI.
The default Rust package is 1.65 (and unlikely to change I assume?),
but the generic format parser library uses `is_some_and` which was
introduced in 1.70. So this is a simple reimplementation, directly taken
from the standard library sources.
libgrust/ChangeLog:
* libformat_parser/generic_format_parser/src/lib.rs: Add IsSomeAnd<T>
trait, impl it for Option<T>.
Arthur Cohen [Thu, 15 Feb 2024 12:11:26 +0000 (13:11 +0100)]
libformat_parser: Fix Rust warnings.
libgrust/ChangeLog:
* libformat_parser/generic_format_parser/src/lib.rs: Remove
unused deprecated attribute and unused import.
* libformat_parser/src/lib.rs: Remove unused import.
Arthur Cohen [Tue, 13 Feb 2024 15:31:25 +0000 (16:31 +0100)]
rust-fmt: Store parsed string in Pieces struct
gcc/rust/ChangeLog:
* ast/rust-fmt.cc (Pieces::collect): Fix signature to take ownership
of the given string.
* ast/rust-fmt.h (struct Pieces): Store parsed string in the struct.
libgrust/ChangeLog:
* libformat_parser/src/lib.rs: Add debug prompt.
Arthur Cohen [Wed, 7 Feb 2024 11:46:16 +0000 (12:46 +0100)]
format_args: Parse entire token invocation
gcc/rust/ChangeLog:
* expand/rust-macro-builtins.cc (MacroBuiltin::format_args_handler):
Transform entire invocation token stream into string for the parser.
Arthur Cohen [Tue, 30 Jan 2024 15:16:36 +0000 (16:16 +0100)]
format_args: Parse format string properly
gcc/rust/ChangeLog:
* expand/rust-macro-builtins.cc (MacroBuiltin::format_args_handler):
Construct string to parser properly.
Arthur Cohen [Tue, 30 Jan 2024 00:48:13 +0000 (01:48 +0100)]
libformat_parser: Send boxed values across FFI properly
gcc/rust/ChangeLog:
* ast/rust-fmt.cc (Pieces::~Pieces): Call libformat_parser's release
function in destructor.
* ast/rust-fmt.h (struct PieceSlice): Add capacity.
(destroy_pieces): New.
(struct Pieces): Add destructor.
libgrust/ChangeLog:
* libformat_parser/src/lib.rs: Leak Boxes properly for C++ to
see them, add memory release function.
Arthur Cohen [Mon, 29 Jan 2024 21:06:39 +0000 (22:06 +0100)]
libformat_parser: Update header and remove old interface
gcc/rust/ChangeLog:
* ast/rust-fmt.cc (Pieces::collect): Use new Pieces API.
* ast/rust-fmt.h: Update interface with new FFI bindings.
libgrust/ChangeLog:
* libformat_parser/src/lib.rs: Add IntoFFI trait.
* libformat_parser/libformat-parser.h: Removed.
Arthur Cohen [Mon, 29 Jan 2024 15:17:00 +0000 (16:17 +0100)]
git: Ignore libgrust build folders
ChangeLog:
* .gitignore: Add libgrust target folders to the ignore list.
Arthur Cohen [Mon, 29 Jan 2024 15:14:13 +0000 (16:14 +0100)]
libformat_parser: Start experimenting with cbindgen
libgrust/ChangeLog:
* libformat_parser/cbindgen.toml: New file.
* libformat_parser/libformat-parser.h: New file.
gcc/rust/ChangeLog:
* ast/rust-fmt.h: Add remaining FFI types.
Arthur Cohen [Mon, 29 Jan 2024 15:13:24 +0000 (16:13 +0100)]
libformat_parser: Add FFI safe interface
libgrust/ChangeLog:
* libformat_parser/generic_format_parser/src/lib.rs: Add generic
library.
* libformat_parser/src/lib.rs: Add base for FFI interface.
Arthur Cohen [Thu, 30 Nov 2023 13:11:41 +0000 (14:11 +0100)]
libgrust: Add format_parser library
Compile libformat_parser and link to it.
gcc/rust/ChangeLog:
* Make-lang.in: Compile libformat_parser.
* ast/rust-fmt.cc: New FFI definitions.
* ast/rust-fmt.h: Likewise.
* expand/rust-macro-builtins.cc (MacroBuiltin::format_args_handler): Call
into libformat_parser.
* expand/rust-macro-builtins.h: Define format_args!() handler proper.
libgrust/ChangeLog:
* libformat_parser/Cargo.lock: New file.
* libformat_parser/Cargo.toml: New file.
* libformat_parser/generic_format_parser/Cargo.toml: New file.
* libformat_parser/generic_format_parser/src/lib.rs: New file.
* libformat_parser/src/bin.rs: New file.
* libformat_parser/src/lib.rs: New file.
Arthur Cohen [Thu, 9 Nov 2023 17:32:52 +0000 (18:32 +0100)]
fmt: Start working on format_args!() parser
This commit adds a base class for parsing the various constructs of a
Rust format string, according to the grammar in the reference:
https://doc.rust-lang.org/std/fmt/index.html#syntax
gcc/rust/ChangeLog:
* Make-lang.in: Compile rust-fmt object
* ast/rust-fmt.cc: New file.
* ast/rust-fmt.h: New file.
Marc Poulhiès [Mon, 19 Feb 2024 21:52:29 +0000 (22:52 +0100)]
gccrs: minor cleanup in langhook.type_for_mode
gcc/rust/ChangeLog:
* rust-lang.cc (grs_langhook_type_for_mode): simplify code for
xImode. Add missing long_double_type_node.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Owen Avery [Sun, 18 Feb 2024 05:19:25 +0000 (00:19 -0500)]
Fix false positive for top-level AltPattern
gcc/rust/ChangeLog:
* hir/rust-ast-lower-pattern.cc
(ASTLoweringPattern::visit):
Reset is_let_top_level while visiting GroupedPattern.
gcc/testsuite/ChangeLog:
* rust/compile/let_alt.rs: Check for false positive.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Marc Poulhiès [Mon, 19 Feb 2024 21:36:39 +0000 (22:36 +0100)]
gccrs: fix powif64 intrinsic
The signature was incorrectly using an i64 for the integer power,
instead of an i32.
gcc/testsuite/ChangeLog:
* rust/compile/torture/intrinsics-math.rs: Adjust powif64
intrinsic signature.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Pierre-Emmanuel Patry [Tue, 28 Nov 2023 12:40:55 +0000 (13:40 +0100)]
libgrust: Add entry for maintainers
ChangeLog:
* MAINTAINERS: Add maintainers for libgrust.
contrib/ChangeLog:
* gcc-changelog/git_commit.py: Add libgrust.
(cherry picked from commit
e4f0eb725d836ef0eec780cbb9e7be0d31c6fe8b )
Co-authored-by: Arthur Cohen <arthur.cohen@embecosm.com>
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 28 Nov 2023 12:39:35 +0000 (13:39 +0100)]
libgrust: Add ChangeLog file
libgrust/ChangeLog:
* ChangeLog: New file.
(cherry picked from commit
a857ec6aada08d8c334c389c7b682198d749b6c9 )
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Jakub Jelinek [Thu, 15 Feb 2024 12:55:49 +0000 (13:55 +0100)]
gccrs: Avoid *.bak suffixed tests - use dg-skip-if instead
On Fri, Feb 09, 2024 at 11:03:38AM +0100, Jakub Jelinek wrote:
> On Wed, Feb 07, 2024 at 12:43:59PM +0100, arthur.cohen@embecosm.com wrote:
> > This patch introduces one regression because generics are getting better
> > understood over time. The code here used to apply generics with the same
> > symbol from previous segments which was a bit of a hack with out limited
> > inference variable support. The regression looks like it will be related
> > to another issue which needs to default integer inference variables much
> > more aggresivly to default integer.
> >
> > Fixes #2723
> > * rust/compile/issue-1773.rs: Moved to...
> > * rust/compile/issue-1773.rs.bak: ...here.
>
> Please don't use such suffixes in the testsuite.
> Either delete the testcase, or xfail it somehow until the bug is fixed.
To be precise, I have scripts to look for backup files in the tree (*~,
*.bak, *.orig, *.rej etc.) and this stands in the way several times a day.
Here is a fix for that in patch form, tested on x86_64-linux with
make check-rust RUNTESTFLAGS='compile.exp=issue-1773.rs'
2024-02-15 Jakub Jelinek <jakub@redhat.com>
* rust/compile/issue-1773.rs.bak: Rename to ...
* rust/compile/issue-1773.rs: ... this. Add dg-skip-if directive.
Sahil Yeole [Thu, 15 Feb 2024 20:48:44 +0000 (02:18 +0530)]
Update copyright years.
Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com>
Sahil Yeole [Thu, 15 Feb 2024 20:45:17 +0000 (02:15 +0530)]
contrib: Add libgrust to update-copyright.py script
contrib/ChangeLog:
* update-copyright.py: Add libgrust folder.
Signed-off-by: Sahil Yeole <sahilyeole93@gmail.com>
0xn4utilus [Wed, 14 Feb 2024 16:49:15 +0000 (22:19 +0530)]
Add variadic check on function params
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Add variadic check on all parameters.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2850.rs: New test.
Signed-off-by: 0xn4utilus <gyanendrabanjare8@gmail.com>
Owen Avery [Mon, 12 Feb 2024 23:20:19 +0000 (18:20 -0500)]
Fix lookup of TuplePattern sub-pattern types
gcc/rust/ChangeLog:
* backend/rust-compile-pattern.cc
(CompilePatternLet::visit):
Lookup type of sub-pattern, not tuple pattern itself.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2847-b.rs: New test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Marc Poulhiès [Sun, 22 Oct 2023 16:52:22 +0000 (18:52 +0200)]
gccrs: add powi intrinsics
gcc/rust/ChangeLog:
* backend/rust-builtins.cc
(BuiltinsContext::register_rust_mappings): Add powi and reformat.
* backend/rust-builtins.h: Add missing copyright header.
gcc/testsuite/ChangeLog:
* rust/compile/torture/intrinsics-math.rs: Adjust pow test, add
test for powi.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Arthur Cohen [Wed, 7 Feb 2024 08:27:11 +0000 (09:27 +0100)]
gccrs: Add testcase for #[rustc_const_stable]
To ensure we don't introduce regressions back to issue #2314
gcc/testsuite/ChangeLog:
* rust/compile/rustc_const_stable.rs: New test.
Arthur Cohen [Tue, 6 Feb 2024 16:26:23 +0000 (17:26 +0100)]
expand: Fix formatting for "macro not found" error
gcc/rust/ChangeLog:
* expand/rust-macro-expand.h (struct MacroExpander): Nitpick: fix
formatting of emitted error.
Owen Avery [Wed, 21 Jun 2023 14:26:30 +0000 (10:26 -0400)]
Fix rebinding imports
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-item.cc
(flatten_glob): Use Import class.
(flatten_rebind): Likewise.
(flatten_list): Likewise.
(flatten): Likewise.
(flatten_use_dec_to_paths): Likewise.
(flatten_use_dec_to_imports): Likewise.
(ResolveItem::visit): Likewise.
(Import::add_prefix): New.
(rust_flatten_nested_glob): Adjust test.
(rust_flatten_glob): Likewise.
(rust_flatten_rebind_none): Likewise.
(rust_flatten_rebind): Likewise.
(rust_flatten_rebind_nested): Likewise.
(rust_flatten_list): Likewise.
* resolve/rust-ast-resolve-item.h
(class Import): New.
gcc/testsuite/ChangeLog:
* rust/compile/use_2.rs: New test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Arthur Cohen [Tue, 6 Feb 2024 16:01:46 +0000 (17:01 +0100)]
gccrs: Add testcase for matches!() macro
This adds a testcase for issue #2129.
gcc/testsuite/ChangeLog:
* rust/execute/torture/matches_macro.rs: New test.
Arthur Cohen [Wed, 7 Feb 2024 14:42:18 +0000 (15:42 +0100)]
gccrs: Fix typo in RegionConstraints instance
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-implitem.h: Fix typo in field
(region_costraints -> region_constraints).
Kushal Pal [Fri, 26 Jan 2024 13:05:59 +0000 (18:35 +0530)]
Fix macro parsing for trait items.
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_trait_item):
Handle macros in trait items similar to how its handled for trait
implementation items.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Fri, 26 Jan 2024 07:51:37 +0000 (13:21 +0530)]
Remove obsolete classes and functions.
Trait functions now use AST::Function class, so classes
AST::TraitItemFunc, AST::TraitItemMethod, AST::TraitFunctionDecl,
AST::TraitMethodDecl and their related functions can be removed.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit):
Remove obsolete classes and functions.
* ast/rust-ast-collector.h:
Likewise.
* ast/rust-ast-full-decls.h (class TraitFunctionDecl):
Likewise.
(class TraitItemFunc):
Likewise.
(class TraitMethodDecl):
Likewise.
(class TraitItemMethod):
Likewise.
* ast/rust-ast-visitor.cc (DefaultASTVisitor::visit):
Likewise.
* ast/rust-ast-visitor.h:
Likewise.
* ast/rust-ast.cc (TraitItemFunc::TraitItemFunc):
Likewise.
(TraitItemFunc::operator=):
Likewise.
(TraitItemFunc::as_string):
Likewise.
(TraitFunctionDecl::as_string):
Likewise.
(TraitItemMethod::TraitItemMethod):
Likewise.
(TraitItemMethod::operator=):
Likewise.
(TraitItemMethod::as_string):
Likewise.
(TraitMethodDecl::as_string):
Likewise.
(TraitItemFunc::accept_vis):
Likewise.
(TraitItemMethod::accept_vis):
Likewise.
* ast/rust-item.h (class TraitFunctionDecl):
Likewise.
(class TraitItemFunc):
Likewise.
(class TraitMethodDecl):
Likewise.
(class TraitItemMethod):
Likewise.
* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Likewise.
* checks/errors/rust-ast-validation.h:
Likewise.
* checks/errors/rust-feature-gate.h:
Likewise.
* expand/rust-cfg-strip.cc (CfgStrip::maybe_strip_trait_function_decl):
Likewise.
(CfgStrip::maybe_strip_trait_method_decl):
Likewise.
(CfgStrip::visit):
Likewise.
* expand/rust-cfg-strip.h:
Likewise.
* expand/rust-derive.h:
Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::expand_trait_function_decl):
Likewise.
(ExpandVisitor::expand_trait_method_decl):
Likewise.
(ExpandVisitor::visit):
Likewise.
* expand/rust-expand-visitor.h:
Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::visit):
Likewise.
* hir/rust-ast-lower-base.h:
Likewise.
* hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit):
Likewise.
* hir/rust-ast-lower-implitem.h:
Likewise.
* resolve/rust-ast-resolve-base.cc (ResolverBase::visit):
Likewise.
* resolve/rust-ast-resolve-base.h:
Likewise.
* resolve/rust-ast-resolve-implitem.h (visit):
Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit):
Likewise.
* resolve/rust-ast-resolve-item.h:
Likewise.
* resolve/rust-default-resolver.cc (DefaultResolver::visit):
Likewise.
* resolve/rust-default-resolver.h:
Likewise.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Likewise.
* resolve/rust-toplevel-name-resolver-2.0.h:
Likewise.
* util/rust-attributes.cc (AttributeChecker::visit):
Likewise.
* util/rust-attributes.h:
Likewise.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Fri, 26 Jan 2024 06:20:05 +0000 (11:50 +0530)]
Parse trait functions as `AST::Function`.
To use AST::Function for trait functions, we can parse trait functions
using available parse_function().
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_trait_item):
Use parse_function() to parse trait functions.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Fri, 26 Jan 2024 06:14:12 +0000 (11:44 +0530)]
Fix inconsistent formatting.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2040.rs:
Enclose 'const' in single quotes.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Fri, 26 Jan 2024 06:05:24 +0000 (11:35 +0530)]
Add missing visitors for AST::Function.
To use AST::Function instead of AST::TraitItemFunc and
AST::TraitItemMethod, we need to provide similar visitors during
lowering and resolving phase.
gcc/rust/ChangeLog:
* hir/rust-ast-lower-implitem.cc (ASTLowerTraitItem::visit):
Provide visitor for AST::Function.
* hir/rust-ast-lower-implitem.h:
Likewise.
* resolve/rust-ast-resolve-implitem.h:
Likewise.
* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit):
Likewise.
* resolve/rust-ast-resolve-item.h:
Likewise.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Fri, 26 Jan 2024 05:55:10 +0000 (11:25 +0530)]
Add checks for Trait functions
Since we want to use AST::Function class for trait functions as well, we
need to check against specific conditions in ASTValidation phase.
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Add checks for Trait functions.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 24 Jan 2024 11:33:09 +0000 (17:03 +0530)]
Use AssociatedItem in place of TraitItem
gcc/rust/ChangeLog:
* ast/rust-ast.h: Replace TraitItem with AssociatedItem.
* ast/rust-item.h (class Trait): Likewise.
* expand/rust-expand-visitor.cc (ExpandVisitor::visit):
Likewise.
* parse/rust-parse-impl.h (Parser::parse_trait): Likewise.
* parse/rust-parse.h: Likewise.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Philip Herron [Sun, 4 Feb 2024 17:07:05 +0000 (17:07 +0000)]
gccrs: fix bug in pattern check for tuples
We can point to generic parent types which means we need to do the shallow
resolve thing that rustc does. We have destructure which is similar to get
what the parameter type points to.
Fixes #2775
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): use destructure
gcc/testsuite/ChangeLog:
* rust/compile/issue-2775.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Sun, 4 Feb 2024 16:38:16 +0000 (16:38 +0000)]
gccrs: Add testcase to show issue is already fixed
Fixes #2782
gcc/testsuite/ChangeLog:
* rust/compile/issue-2782.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Nobel Singh [Mon, 29 Jan 2024 22:35:03 +0000 (04:20 +0545)]
Move the Implementation of implitem lowering into its own file.
This patch moves the implementation of the implitem lowering
from rust-ast-lower-implitem.h into the rust-ast-lower-implitem.cc
file.
gcc/rust/ChangeLog:
* Make-lang.in: Add rust-ast-lower-implitem.cc to list of objects.
* hir/rust-ast-lower-implitem.h (RUST_AST_LOWER_IMPLITEM_H): Remove
implementation.
* hir/rust-ast-lower-implitem.cc: Copy implementation from header.
Signed-off-by: Nobel Singh <Nobel2073@gmail.com>
Philip Herron [Sat, 3 Feb 2024 15:18:51 +0000 (15:18 +0000)]
gccrs: refactor inference variable computation into a seperate method
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check.cc (TypeResolution::Resolve): refactor
* typecheck/rust-hir-type-check.h: new prototype
* typecheck/rust-typecheck-context.cc (TypeCheckContext::compute_inference_variables): x
Philip Herron [Sat, 3 Feb 2024 11:46:42 +0000 (11:46 +0000)]
gccrs: remove similar hack in type paths as we had in path expressions
This keeps the resolution code in line with paths.
Addresses #2723
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-type.cc: remove hack
Philip Herron [Sat, 3 Feb 2024 11:34:30 +0000 (11:34 +0000)]
gccrs: remove old generics hack to reuse generic symbols from previous seg
This patch introduces one regression because generics are getting better
understood over time. The code here used to apply generics with the same
symbol from previous segments which was a bit of a hack with out limited
inference variable support. The regression looks like it will be related
to another issue which needs to default integer inference variables much
more aggresivly to default integer.
Fixes #2723
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): remove hack
gcc/testsuite/ChangeLog:
* rust/compile/issue-1773.rs: Moved to...
* rust/compile/issue-1773.rs.bak: ...here.
* rust/compile/issue-2723-1.rs: New test.
* rust/compile/issue-2723-2.rs: New test.
Philip Herron [Sat, 3 Feb 2024 16:32:13 +0000 (16:32 +0000)]
gccrs: Fix ICE accessing empty vector without check
Fixes #2747
gcc/rust/ChangeLog:
* typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args): fix
gcc/testsuite/ChangeLog:
* rust/compile/issue-2747.rs: New test.
Philip Herron [Sat, 3 Feb 2024 16:02:36 +0000 (16:02 +0000)]
gccrs: add test cases to prove type inference is working
Fixes #2772
gcc/testsuite/ChangeLog:
* rust/compile/issue-2772-1.rs: New test.
* rust/compile/issue-2772-2.rs: New test.
Philip Herron [Sat, 3 Feb 2024 15:43:59 +0000 (15:43 +0000)]
gccrs: add testcase to prove issue has already been fixed
Fixes #1483
gcc/testsuite/ChangeLog:
* rust/compile/issue-1483.rs: New test.
Nobel Singh [Fri, 19 Jan 2024 15:06:34 +0000 (20:51 +0545)]
Set the default ABI to C for extern blocks and extern functions
Previously, the default ABI was set to Rust, which is not correct for
extern blocks and extern functions. This patch changes the default
ABI to C for these cases.
gcc/rust/ChangeLog:
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_qualifiers):
Change default ABI to C for extern functions
(ASTLoweringBase::lower_extern_block): Likewise
Signed-off-by: Nobel Singh <nobel2073@gmail.com>
Jakub Dupak [Tue, 23 Jan 2024 13:50:57 +0000 (14:50 +0100)]
TyTy: Store reference to type before any substitutions
gcc/rust/ChangeLog:
* typecheck/rust-tyty.cc (BaseType::BaseType): Store orig ref.
(BaseType::get_orig_ref): Add getter.
* typecheck/rust-tyty.h: Store orig ref.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 23 Jan 2024 13:20:42 +0000 (14:20 +0100)]
TyTy: Store region constraints
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
Add region constraints.
(TypeCheckImplItem::visit): Add region constraints.
* typecheck/rust-hir-type-check-implitem.h: Add region constraints.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::ResolveImplBlockSelf):
Add region constraints.
(TypeCheckItem::visit): Add region constraints.
(TypeCheckItem::resolve_impl_item): Add region constraints.
(TypeCheckItem::resolve_impl_block_substitutions): Add region constraints.
* typecheck/rust-hir-type-check-item.h: Add region constraints.
* typecheck/rust-hir-type-check-type.cc (ResolveWhereClauseItem::Resolve):
Add region constraints.
(ResolveWhereClauseItem::visit): Add region constraints.
* typecheck/rust-hir-type-check-type.h (class ResolveWhereClauseItem):
Add region constraints.
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn):
Add region constraints.
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate):
Add region constraints.
* typecheck/rust-tyty-subst.cc (SubstitutionRef::get_region_constraints):
Add region constraints.
* typecheck/rust-tyty-subst.h (class BaseType): Add region constraints.
(struct RegionConstraints): Add region constraints.
* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): Add region constraints.
(ADTType::clone): Add region constraints.
(FnType::clone): Add region constraints.
(ProjectionType::clone): Add region constraints.
* typecheck/rust-tyty.h: Add region constraints.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Wed, 10 Jan 2024 13:48:22 +0000 (14:48 +0100)]
Typecheck: add regions (lifetimes) to TyTy
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc: add regions
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal):
add regions, resolve generic lifetimes
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): add regions
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
add regions, resolve lifetimes
(TypeCheckImplItem::visit): add regions, resove lifetimes
* typecheck/rust-hir-type-check-implitem.h: add default value for result
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): add regions,
resove lifetimes
(TypeCheckItem::resolve_impl_block_substitutions): add regions, resove lifetimes
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): add regions,
resove lifetimes
(TypeCheckExpr::resolve_root_path): add regions, resove lifetimes
(TypeCheckExpr::resolve_segments): add regions, resove lifetimes
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): add regions,
resove lifetimes
(TypeCheckType::resolve_root_path): add regions, resove lifetimes
(ResolveWhereClauseItem::Resolve): add regions, resove lifetimes
(ResolveWhereClauseItem::visit): add regions, resove lifetimes
* typecheck/rust-hir-type-check.cc (TypeCheckContext::LifetimeResolver::resolve):
add regions, resolve lifetimes
(TraitItemReference::get_type_from_fn): add regions, resove lifetimes
* typecheck/rust-hir-type-check.h: add regions, resove lifetimes
* typecheck/rust-substitution-mapper.cc (SubstMapper::SubstMapper): add regions,
resove lifetimes
(SubstMapper::Resolve): add regions, resove lifetimes
(SubstMapper::InferSubst): add regions, resove lifetimes
(SubstMapper::visit): add regions, resove lifetimes
* typecheck/rust-substitution-mapper.h: add regions, resove lifetimes
* typecheck/rust-typecheck-context.cc (TypeCheckContext::TypeCheckContext):
lifetime resolution
(TypeCheckContext::regions_from_generic_args): lifetime resolution helper
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate):
add regions, resove lifetimes
(TypeBoundPredicate::operator=): add regions, resove lifetimes
(TypeBoundPredicate::apply_generic_arguments): add regions, resove lifetimes
(TypeBoundPredicateItem::get_tyty_for_receiver): add regions, resove lifetimes
* typecheck/rust-tyty-subst.cc (SubstitutionArgumentMappings::get_regions):
add regions, resove lifetimes
(SubstitutionArgumentMappings::get_mut_regions): getter
(SubstitutionArgumentMappings::error): split error and empty
(SubstitutionArgumentMappings::empty): split error and empty
(SubstitutionArgumentMappings::find_symbol): helper
(SubstitutionRef::get_num_lifetime_params): getter
(SubstitutionRef::get_num_type_params): getter
(SubstitutionRef::needs_substitution): extend to regions
(SubstitutionRef::get_mappings_from_generic_args): helper
(SubstitutionRef::infer_substitions): add regions
* typecheck/rust-tyty-subst.h (class RegionParamList): region param handler
* typecheck/rust-tyty.cc (BaseType::monomorphized_clone): add regions, resove lifetimes
(InferType::default_type): add regions, resove lifetimes
(FnType::clone): add regions, resove lifetimes
(ReferenceType::ReferenceType): add regions
(ReferenceType::get_region): getter
(ReferenceType::clone): add regions
* typecheck/rust-tyty.h: add regions, resove
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 23 Jan 2024 12:55:20 +0000 (13:55 +0100)]
HIR: Add mising getter
gcc/rust/ChangeLog:
* hir/tree/rust-hir-item.h: Add missing getter
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 23 Jan 2024 11:29:25 +0000 (12:29 +0100)]
TyTy: Region (lifetime) representation
gcc/rust/ChangeLog:
* typecheck/rust-tyty-region.h: New file.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Wed, 10 Jan 2024 12:12:48 +0000 (13:12 +0100)]
Typecheck: lifetime interning and resolution tool
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check.h (class Lifetime): add interned lifetime class
* typecheck/rust-typecheck-context.cc (TypeCheckContext::TypeCheckContext): add
resolution tool
(TypeCheckContext::intern_lifetime): add method to intern lifetime from tyctx
(TypeCheckContext::lookup_lifetime): add method to lookup lifetime from tyctx
(TypeCheckContext::intern_and_insert_lifetime): add a helper method
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Raiki Tamura [Sat, 2 Dec 2023 12:01:59 +0000 (21:01 +0900)]
gccrs: Implement quick-check for Unicode
gcc/rust/ChangeLog:
* rust-lang.cc (run_rust_tests): Add test.
* rust-system.h: Add <algorithm>.
* util/make-rust-unicode.py: Output NFC_Quick_Check table.
* util/rust-codepoint.h (struct Codepoint): Add is_supplementary
method.
* util/rust-unicode-data.h: Generated.
* util/rust-unicode.cc (binary_search_sorted_array): Removed.
(lookup_cc): Remove namespace.
(is_alphabetic): Use std::binary_search
(nfc_quick_check): New function.
(nfc_normalize): Use nfc_quick_check.
(is_nfc_qc_maybe): New function.
(is_nfc_qc_no): New function.
(rust_nfc_qc_test): New test.
* util/rust-unicode.h (is_nfc_qc_no): New function.
(is_nfc_qc_maybe): New function.
(enum class): New enum class.
(nfc_quick_check): New function.
(rust_nfc_qc_test): New test.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Kushal Pal [Tue, 23 Jan 2024 11:53:05 +0000 (17:23 +0530)]
Parse normal functions with `self` parameter correctly
Fixes #2812
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_function):
Skip token if its a COMMA.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2812.rs: New test.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Arthur Cohen [Mon, 22 Jan 2024 13:04:11 +0000 (14:04 +0100)]
gccrs: Fix output line ending patterns.
gcc/testsuite/ChangeLog:
* rust/execute/torture/builtin_macros1.rs: Fix output pattern.
* rust/execute/torture/coercion3.rs: Likewise.
* rust/execute/torture/issue-2080.rs: Likewise.
* rust/execute/torture/issue-2179.rs: Likewise.
* rust/execute/torture/issue-2180.rs: Likewise.
* rust/execute/torture/iter1.rs: Likewise.
Owen Avery [Wed, 20 Dec 2023 08:04:36 +0000 (03:04 -0500)]
Remove TraitImplItem
gcc/rust/ChangeLog:
* ast/rust-ast-full-decls.h
(class TraitImplItem): Remove forward declaration.
(class AssociatedItem): Add forward declaration.
* ast/rust-ast.h
(class TraitImplItem): Remove.
(class TraitItem): Inherit from AssociatedItem.
(SingleASTNode::take_trait_impl_item):
Return std::unique_ptr<AssociatedItem> instead of
std::unique_ptr<TraitImplItem>.
* ast/rust-item.h
(class Function): Inherit from AssociatedItem instead of
TraitImplItem.
(class TypeAlias): Likewise.
(class ConstantItem): Likewise.
(class TraitImpl): Store items as AssociatedItem.
* expand/rust-derive-clone.cc
(DeriveClone::clone_fn): Return std::unique_ptr<AssociatedItem>.
(DeriveClone::clone_impl): Take std::unique_ptr<AssociatedItem>.
* expand/rust-derive-clone.h
(DeriveClone::clone_fn): Return std::unique_ptr<AssociatedItem>.
(DeriveClone::clone_impl): Take std::unique_ptr<AssociatedItem>.
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Handle changes to
SingleASTNode::take_trait_impl_item.
* parse/rust-parse-impl.h
(Parser::parse_impl): Parse TraitImpl as containing AssociatedItem.
(Parser::parse_trait_impl_item): Return
std::unique_ptr<AssociatedItem>.
(Parser::parse_trait_impl_function_or_method): Likewise.
* parse/rust-parse.h
(Parser::parse_trait_impl_item): Return
std::unique_ptr<AssociatedItem>.
(Parser::parse_trait_impl_function_or_method): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Robert Goss [Sun, 14 Jan 2024 17:34:22 +0000 (17:34 +0000)]
Add improved error when no fields in initializer
If a struct type with a variant that has fields is initialized with some fields the expression HIR StructExprStructFields is checked that all the fields are assigned. However, if no fields are initialized the HIR StructExprStruct is generated. This doesn't check if the struct is a unit during typechekc and only fails at the compile stage with a ICE.
Add a check at the typecheck stage that makes sure the struct does not have a variant with fields and give an error message based on the rustc one.
We have also updated the message given in the case where one field was present to list the missing fields and match more closely the new message.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit) Add additional check
* typecheck/rust-hir-type-check-struct-field.h: A helper method to make error added
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve) Update message
gcc/testsuite/ChangeLog:
* rust/compile/missing_constructor_fields.rs: Added case with no initializers
Signed-off-by: Robert Goss <goss.robert@gmail.com>
Jakub Dupak [Thu, 18 Jan 2024 13:37:58 +0000 (14:37 +0100)]
Test: check implemented for lifetime handling
gcc/testsuite/ChangeLog:
* rust/compile/for_lifetimes.rs: New test.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 9 Jan 2024 14:46:41 +0000 (15:46 +0100)]
AST: Fix for lifetime lowering
gcc/rust/ChangeLog:
* hir/rust-ast-lower-type.cc (ASTLoweringTypeBounds::visit): fix for lifetimes
(ASTLowerWhereClauseItem::visit): fix for lifetimes
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 9 Jan 2024 14:45:12 +0000 (15:45 +0100)]
AST: Fix for lifetime parsing
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_where_clause): fix parsing
(Parser::parse_where_clause_item): fix parsing
(Parser::parse_type_bound_where_clause_item): fix parsing
(Parser::parse_trait_bound): fix parsing
* parse/rust-parse.h: fix parsing
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Tue, 9 Jan 2024 14:43:01 +0000 (15:43 +0100)]
Test: fix missing lifetime in a test
This test did not compile with rustc.
gcc/testsuite/ChangeLog:
* rust/compile/torture/utf8_identifiers.rs: add mising lifetime
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Kushal Pal [Sat, 30 Dec 2023 04:10:19 +0000 (09:40 +0530)]
Added newline to get more readable lexdump
Fixes #2783
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::dump_and_skip):
Changed " " to '\n'
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Owen Avery [Wed, 20 Dec 2023 07:30:20 +0000 (02:30 -0500)]
Unify storage of associated items in SingleASTNode
gcc/rust/ChangeLog:
* ast/rust-ast-fragment.cc
(Fragment::assert_single_fragment): Update.
* ast/rust-ast.h
(class TraitImplItem): Move definition before that of TraitItem.
(class TraitItem):
Inherit from TraitImplItem instead of AssociatedItem.
(class SingleASTNode): Unify handling of associated items.
(SingleASTNode::take_assoc_item): Move from...
(SingleASTNode::take_impl_item): ...here, but leave stub calling
take_assoc_item behind.
(SingleASTNode::take_trait_item):
Cast associated item to TraitItem.
(SingleASTNode::take_trait_impl_item):
Cast associated item to TraitImplItem.
* ast/rust-ast.cc
(SingleASTNode::SingleASTNode):
Unify handling of associated items.
(SingleASTNode::operator=): Likewise.
(SingleASTNode::accept_vis): Likewise.
(SingleASTNode::is_error): Likewise.
(SingleASTNode::as_string): Likewise.
* ast/rust-item.h
(class Function): Remove direct inheritence from AssociatedItem.
(class ConstantItem): Likewise.
* ast/rust-macro.h
(class MacroInvocation):
Remove direct inheritence from AssociatedItem and TraitImplItem.
Robert Goss [Tue, 16 Jan 2024 22:50:51 +0000 (22:50 +0000)]
Add improved error when a field is redefined in a struct constructor
Fixes #2381
If a struct type is initialized with one of it's fields repeated it will currently issue an error at the use site. However we would like to give the rust error code and (like rustc) show both the specifications for the field to help the user diagnose the issue.
We move the check after the index for the field has been established so we can look up if the field has already been defined and get it's location.
We update the visit method to return if it has handled an error otherwise we then output a second fatal error as not all the field in the specification have been processed.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-struct-field.h: Allow visit to return a bool
* typecheck/rust-hir-type-check-struct.cc: Improve check of repeat fields
gcc/testsuite/ChangeLog:
* rust/compile/repeated_constructor_fields.rs: Added case with constructor field repeated
Signed-off-by: Robert Goss <goss.robert@gmail.com>
Arthur Cohen [Wed, 17 Jan 2024 13:15:27 +0000 (14:15 +0100)]
rust_debug: Cast size_t values to unsigned long before printing.
Using %lu to format size_t values breaks 32 bit targets, and %zu is not
supported by one of the hosts GCC aims to support - HPUX
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address):
Cast size_t value to unsigned long.
* expand/rust-proc-macro.cc (load_macros): Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise.
Kushal Pal [Sat, 6 Jan 2024 05:59:14 +0000 (11:29 +0530)]
Handle `async` keyword for regular implementations
Fixes #2788
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_inherent_impl_item):
Added switch-case for ASYNC token.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2788.rs: New test.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Tue, 16 Jan 2024 13:36:35 +0000 (19:06 +0530)]
Fix inconsistent formatting
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Enclose const in single quotes.
gcc/testsuite/ChangeLog:
* rust/compile/const_trait_fn.rs:
Enclose const in single quotes.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Kushal Pal [Wed, 3 Jan 2024 10:32:07 +0000 (16:02 +0530)]
Handle `async` functions in traits
Fixes #2785
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc (ASTValidation::visit):
Added check for `async` functions inside trait.
* parse/rust-parse-impl.h (Parser::parse_trait_item):
Added switch-case for ASYNC token.
gcc/testsuite/ChangeLog:
* rust/compile/issue-2785.rs: New test.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Arthur Cohen [Fri, 12 Jan 2024 12:48:43 +0000 (13:48 +0100)]
expand: C++ify proc macro decls generation
This uses a stringstream instead of the older, better and more readable
`sprintf` version as the format overflow warning in current GCC is
overzealous and triggered on that code, despite the non-zero allocation.
Even using an unsigned value instead of a signed one for the `size`
variable caused issues, so switching to this is simpler.
gcc/rust/ChangeLog:
* expand/rust-proc-macro.cc: Use stringstream instead of sprintf.
* rust-system.h: Include <iomanip>.
Nirmal Patel [Wed, 27 Dec 2023 22:49:58 +0000 (17:49 -0500)]
Handle newlines during string parsing while lexing
If newline strings are encountered while lexing, the lexer now handles
newline characters by incrementing current line number. This provides
correct line number when displaying errors. If the lexer encounters end
of file before string end, then it will use the start of the string as
the location to an report error.
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::parse_byte_string): Handle newline
while parsing byte strings
(Lexer::parse_string): Handle newline while parsing strings
Signed-off-by: Nirmal Patel <nirmal@nirmal.dev>
Jakub Dupak [Thu, 14 Dec 2023 11:54:11 +0000 (12:54 +0100)]
TyTy: Refactor FnType deprecated API
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): Use new API.
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Use new API.
* typecheck/rust-tyty-cmp.h: Remove old API.
* typecheck/rust-tyty.cc (FnPtr::is_equal): Use new API.
* typecheck/rust-tyty.h: Remove old API.
* typecheck/rust-unify.cc (UnifyRules::expect_fnptr): Use new API.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 11:32:55 +0000 (12:32 +0100)]
ast: Lower 'for' lifetimes
gcc/rust/ChangeLog:
* hir/rust-ast-lower-type.cc (ASTLoweringType::visit): For lifetimes.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 11:30:08 +0000 (12:30 +0100)]
ast: Infer static lifetime for const and static items
(probably incomplete propagation)
gcc/rust/ChangeLog:
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_lifetime): Propagate static
requirement.
* hir/rust-ast-lower-base.h: Propagate static requirement.
* hir/rust-ast-lower-implitem.h: Propagate static requirement.
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Propagate static requirement.
* hir/rust-ast-lower-type.cc (ASTLoweringType::translate): Propagate static requirement.
(ASTLoweringType::visit): Propagate static requirement.
* hir/rust-ast-lower-type.h: Propagate static requirement.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 11:28:07 +0000 (12:28 +0100)]
ast: Full lifetime elision handling
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::parse_generic_param): Lifetime elision control.
(Parser::parse_lifetime_where_clause_item): Lifetime elision control.
(Parser::parse_type_param_bound): Lifetime elision control.
(Parser::parse_lifetime_bounds): Lifetime elision control.
(Parser::parse_lifetime): Lifetime elision control.
(Parser::parse_path_generic_args): Lifetime elision control.
(Parser::parse_self_param): Lifetime elision control.
(Parser::parse_break_expr): Lifetime elision control.
(Parser::parse_continue_expr): Lifetime elision control.
(Parser::parse_reference_type_inner): Lifetime elision control.
* parse/rust-parse.h: Lifetime elision control.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 11:25:23 +0000 (12:25 +0100)]
ast: Unify explicitly and implicitly elided lifettimes
gcc/rust/ChangeLog:
* ast/rust-ast.h: Elided lifetime static constructor
* ast/rust-type.h: Default lifetime to elided.
* parse/rust-parse-impl.h (Parser::parse_lifetime_param): Use elided lifetime.
(Parser::parse_lifetime): Use elided lifetime/
(Parser::lifetime_from_token): Use elided lifetime.
(Parser::parse_self_param): Use elided lifetime.
(Parser::parse_reference_type_inner): Use elided lifetime.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
Jakub Dupak [Sun, 3 Dec 2023 11:23:17 +0000 (12:23 +0100)]
ast: Fix lifetime type parsing
There was a mismatch whether lifetime 'static is parsed as "static"
or "'static".
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h (Parser::lifetime_from_token): Fix matched pattern.
Signed-off-by: Jakub Dupak <dev@jakubdupak.com>