]>
git.ipfire.org Git - thirdparty/gcc.git/log
Arthur Cohen [Mon, 31 Jul 2023 14:13:25 +0000 (16:13 +0200)]
gccrs: forever-stack: Use rust_assert instead of assert
This causes complaints by our GCC 4.8 builder.
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.hxx: assert() -> rust_assert()
Arthur Cohen [Thu, 20 Jul 2023 12:15:14 +0000 (14:15 +0200)]
gccrs: top-level: Add base `TopLevel` visitor
The `TopLevel` pass takes care of collecting definitions, placing them
in the proper namespaces, and making them accessible for later resolution
passes like `Early` and `Late`. It is meant to be run in a fixed point
fashion, as import resolution, macro resolution and macro expansion
may generate multiple new definitions.
gcc/rust/ChangeLog:
* Make-lang.in: Add new object file.
* resolve/rust-toplevel-name-resolver-2.0.cc: New file.
* resolve/rust-toplevel-name-resolver-2.0.h: New file.
Arthur Cohen [Fri, 23 Jun 2023 14:17:51 +0000 (16:17 +0200)]
gccrs: name resolution 2.0: Add base for our context data structure
This commit adds a first simple `NameResolutionContext` data structure, which will
be used by all passes of the name resolution to store definitions and access
them. Namely, it contains a few instances of `ForeverStack`, for each
namespace we will be using.
gcc/rust/ChangeLog:
* Make-lang.in: Add new object file.
* resolve/rust-name-resolution-context.cc: New file.
* resolve/rust-name-resolution-context.h: New file.
Muhammad Mahad [Mon, 31 Jul 2023 10:21:58 +0000 (15:21 +0500)]
gccrs: [E0572] return is outside of function context
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
called error function.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Owen Avery [Fri, 30 Jun 2023 01:28:23 +0000 (21:28 -0400)]
gccrs: Use MacroInvocLexerBase in MacroInvocLexer
gcc/rust/ChangeLog:
* expand/rust-macro-invoc-lexer.cc
(MacroInvocLexer::skip_token): Remove.
* expand/rust-macro-invoc-lexer.h
(class MacroInvocLexer): Extend MacroInvocLexerBase.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Marc Poulhiès [Wed, 19 Jul 2023 08:54:52 +0000 (10:54 +0200)]
gccrs: use tl::optional for macro transcribers
refs #2421.
gcc/rust/ChangeLog:
* ast/rust-ast-fragment.cc (Fragment::create_empty): New.
* ast/rust-ast-fragment.h (MacroTranscriberFunc): New.
* ast/rust-macro.h (MacroRulesDefinition): Use MacroTranscriberFunc.
* expand/rust-macro-builtins.cc
(MacroBuiltin::builtin_transcribers): likewise.
(MacroBuiltin::assert_handler): Return optional.
(MacroBuiltin::file_handler): Likewise.
(MacroBuiltin::column_handler): Likewise.
(MacroBuiltin::include_bytes_handler): Likewise.
(MacroBuiltin::include_str_handler): Likewise.
(MacroBuiltin::compile_error_handler): Likewise.
(MacroBuiltin::concat_handler): Likewise.
(MacroBuiltin::env_handler): Likewise.
(MacroBuiltin::cfg_handler): Likewise.
(MacroBuiltin::include_handler): Likewise.
(MacroBuiltin::line_handler): Likewise.
(MacroBuiltin::stringify_handler): Likewise.
(MacroBuiltin::sorry): Likewise.
* expand/rust-macro-builtins.h (builtin_transcribers): Use
MacroTranscriberFunc.
(assert_handler): Return optional.
(file_handler): Likewise.
(column_handler): Likewise.
(include_bytes_handler): Likewise.
(include_str_handler): Likewise.
(compile_error_handler): Likewise.
(concat_handler): Likewise.
(env_handler): Likewise.
(cfg_handler): Likewise.
(include_handler): Likewise.
(line_handler): Likewise.
(stringify_handler): Likewise.
(sorry): Likewise.
* expand/rust-macro-expand.cc (MacroExpander::expand_invoc):
Adjust to transcribers returning optional.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Philip Herron [Sun, 30 Jul 2023 17:59:06 +0000 (18:59 +0100)]
gccrs: Fix ICE by adding check for enum candidate's in TypePath resolution
Fixes #2479
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::resolve_item):
always resolve the type even when its an a mandatory trait item
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
Add check for enum candidates otherwise you get undefined behaviour
gcc/testsuite/ChangeLog:
* rust/compile/issue-2479.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Raiki Tamura [Fri, 14 Jul 2023 05:45:34 +0000 (14:45 +0900)]
gccrs: Add Unicode check for crate_name attributes
gcc/rust/ChangeLog:
* lex/rust-codepoint.h: Add comment
* lex/rust-lex.h: New method to get decoded characters
* rust-session-manager.cc (validate_crate_name): Modify unicode check
(rust_crate_name_validation_test): Add testcases
* util/rust-unicode.h (RUST_UNICODE_H): New class Utf8String.
(class Utf8String): New class.
* util/rust-unicode.cc (binary_search_sorted_array): Add comment.
(recursive_decomp_cano): Add comment.
(recomp): Remove dead code.
(dump_string): Removed.
gcc/testsuite/ChangeLog:
* rust/compile/bad-crate-name.rs: Moved to...
* rust/compile/bad-crate-name1.rs: ...here.
* rust/compile/bad-crate-name2.rs: New test.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Owen Avery [Sun, 30 Jul 2023 04:23:00 +0000 (00:23 -0400)]
gccrs: Add missing CHECKING_P guard to rust-unicode.cc
gcc/rust/ChangeLog:
* util/rust-unicode.cc: Add CHECKING_P guard.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Philip Herron [Sat, 29 Jul 2023 23:19:15 +0000 (00:19 +0100)]
gccrs: fix ice when function is outside of context
Fixes #2477
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
We need to check if a function context exists
gcc/testsuite/ChangeLog:
* rust/compile/issue-2477.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Tue, 18 Jul 2023 16:46:08 +0000 (17:46 +0100)]
gccrs: Begin enforcing Sized properly and support anti traits like ?Sized
Sized is implicitly applied to every generic type parameter apart from the
implicit Self type parameter on traits, as that would cause a recursive
bound and would make Traits unable to be appied to unsized types.
In order to keep everything happy this means we also need to support the
anti trait bound '?' so that Sized can be removed properly. The full Sized
rules are not completely implemented here. Slice's and Str's are currently
marked as Sized but there is a small regression here that looks like a more
general bug which should be fixed on its own as part of #2443. There is
a big testsuite update here to pull in the Sized lang item.
Note this lays the bound's ground work so we can start supporting Drop
trait properly which needs tackled very soon.
Fixes: #2375
Addresses: #2443
gcc/rust/ChangeLog:
* expand/rust-proc-macro.cc (literal_from_string): update Lexer constructor
(tokenstream_from_string): likewise
* lex/rust-lex.cc (Lexer::Lexer): likewise
* lex/rust-lex.h: pass through Linemap
* parse/rust-cfg-parser.cc (parse_cfg_option): likewise
* rust-session-manager.cc (Session::load_extern_crate): likewise
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait):
dont apply Sized on self
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::get_marker_predicate): new
* typecheck/rust-hir-type-check-base.h: add prototype
* typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::Resolve): apply Sized
(TypeResolveGenericParam::visit): likewise
* typecheck/rust-hir-type-check-type.h: update prototypes
* typecheck/rust-typecheck-context.cc: remove bad assertions
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_sized_builtin): cleanup
(TypeCheckBase::get_predicate_from_bound): apply sized rules properly
* util/rust-hir-map.cc (Mappings::lookup_trait_item_lang_item): helpers
(Mappings::get_lang_item): likewise
* util/rust-hir-map.h: likewise
* util/rust-token-converter.cc (from_ident): update lexer ctor
(from_punct): likewise
gcc/testsuite/ChangeLog:
* rust/compile/bounds1.rs: Apply sized trait
* rust/compile/canonical_paths1.rs: likewise
* rust/compile/cast_generics.rs: likewise
* rust/compile/closure_no_type_anno.rs: likewise
* rust/compile/complex_qualified_path_in_expr.rs: likewise
* rust/compile/const-issue1440.rs: likewise
* rust/compile/const_generics_1.rs: likewise
* rust/compile/const_generics_8.rs: likewise
* rust/compile/derive_macro1.rs: likewise
* rust/compile/derive_macro3.rs: likewise
* rust/compile/derive_macro4.rs: likewise
* rust/compile/derive_macro6.rs: likewise
* rust/compile/expected_type_args2.rs: likewise
* rust/compile/expected_type_args3.rs: likewise
* rust/compile/generics1.rs: likewise
* rust/compile/generics11.rs: likewise
* rust/compile/generics12.rs: likewise
* rust/compile/generics2.rs: likewise
* rust/compile/generics3.rs: likewise
* rust/compile/generics4.rs: likewise
* rust/compile/generics6.rs: likewise
* rust/compile/generics7.rs: likewise
* rust/compile/generics8.rs: likewise
* rust/compile/if_let_expr.rs: likewise
* rust/compile/issue-1005.rs: likewise
* rust/compile/issue-1019.rs: likewise
* rust/compile/issue-1031.rs: likewise
* rust/compile/issue-1034.rs: likewise
* rust/compile/issue-1128.rs: likewise
* rust/compile/issue-1129-2.rs: likewise
* rust/compile/issue-1130.rs: likewise
* rust/compile/issue-1131.rs: likewise
* rust/compile/issue-1165.rs: likewise
* rust/compile/issue-1173.rs: likewise
* rust/compile/issue-1235.rs: likewise
* rust/compile/issue-1237.rs: likewise
* rust/compile/issue-1289.rs: likewise
* rust/compile/issue-1383.rs: likewise
* rust/compile/issue-1447.rs: likewise
* rust/compile/issue-1589.rs: likewise
* rust/compile/issue-1725-1.rs: likewise
* rust/compile/issue-1725-2.rs: likewise
* rust/compile/issue-1773.rs: likewise
* rust/compile/issue-1786.rs: likewise
* rust/compile/issue-1893.rs: likewise
* rust/compile/issue-1901.rs: likewise
* rust/compile/issue-1930.rs: likewise
* rust/compile/issue-1981.rs: likewise
* rust/compile/issue-2019-1.rs: likewise
* rust/compile/issue-2019-2.rs: likewise
* rust/compile/issue-2019-3.rs: likewise
* rust/compile/issue-2036.rs: likewise
* rust/compile/issue-2037.rs: likewise
* rust/compile/issue-2070.rs: likewise
* rust/compile/issue-2105.rs: likewise
* rust/compile/issue-2106.rs: likewise
* rust/compile/issue-2135.rs: likewise
* rust/compile/issue-2136-1.rs: likewise
* rust/compile/issue-2136-2.rs: likewise
* rust/compile/issue-2139.rs: likewise
* rust/compile/issue-2142.rs: likewise
* rust/compile/issue-2165.rs: likewise
* rust/compile/issue-2166.rs: likewise
* rust/compile/issue-2190-1.rs: likewise
* rust/compile/issue-2190-2.rs: likewise
* rust/compile/issue-2195.rs: likewise
* rust/compile/issue-2238.rs: likewise
* rust/compile/issue-2304.rs: likewise
* rust/compile/issue-850.rs: likewise
* rust/compile/issue-855.rs: likewise
* rust/compile/issue-925.rs: likewise
* rust/compile/macro-issue1400.rs: likewise
* rust/compile/macro20.rs: likewise
* rust/compile/macro23.rs: likewise
* rust/compile/macro40.rs: likewise
* rust/compile/macro54.rs: likewise
* rust/compile/name_resolution2.rs: likewise
* rust/compile/name_resolution4.rs: likewise
* rust/compile/nested_generic.rs: likewise
* rust/compile/parse_associated_type_as_generic_arg.rs: likewise
* rust/compile/parse_associated_type_as_generic_arg2.rs: likewise
* rust/compile/parse_associated_type_as_generic_arg3.rs: likewise
* rust/compile/parse_complex_generic_application.rs: likewise
* rust/compile/parse_complex_generic_application2.rs: likewise
* rust/compile/path_as_generic_arg.rs: likewise
* rust/compile/privacy4.rs: likewise
* rust/compile/privacy6.rs: likewise
* rust/compile/sizeof-stray-infer-var-bug.rs: likewise
* rust/compile/stmt_with_block_dot.rs: likewise
* rust/compile/torture/associated_types1.rs: likewise
* rust/compile/torture/forward_decl_5.rs: likewise
* rust/compile/torture/generics1.rs: likewise
* rust/compile/torture/generics10.rs: likewise
* rust/compile/torture/generics11.rs: likewise
* rust/compile/torture/generics12.rs: likewise
* rust/compile/torture/generics13.rs: likewise
* rust/compile/torture/generics14.rs: likewise
* rust/compile/torture/generics15.rs: likewise
* rust/compile/torture/generics16.rs: likewise
* rust/compile/torture/generics17.rs: likewise
* rust/compile/torture/generics18.rs: likewise
* rust/compile/torture/generics19.rs: likewise
* rust/compile/torture/generics2.rs: likewise
* rust/compile/torture/generics20.rs: likewise
* rust/compile/torture/generics21.rs: likewise
* rust/compile/torture/generics22.rs: likewise
* rust/compile/torture/generics23.rs: likewise
* rust/compile/torture/generics24.rs: likewise
* rust/compile/torture/generics25.rs: likewise
* rust/compile/torture/generics26.rs: likewise
* rust/compile/torture/generics27.rs: likewise
* rust/compile/torture/generics28.rs: likewise
* rust/compile/torture/generics29.rs: likewise
* rust/compile/torture/generics3.rs: likewise
* rust/compile/torture/generics30.rs: likewise
* rust/compile/torture/generics31.rs: likewise
* rust/compile/torture/generics32.rs: likewise
* rust/compile/torture/generics4.rs: likewise
* rust/compile/torture/generics5.rs: likewise
* rust/compile/torture/generics6.rs: likewise
* rust/compile/torture/generics7.rs: likewise
* rust/compile/torture/generics8.rs: likewise
* rust/compile/torture/generics9.rs: likewise
* rust/compile/torture/intrinsics-2.rs: likewise
* rust/compile/torture/intrinsics-6.rs: likewise
* rust/compile/torture/intrinsics-7.rs: likewise
* rust/compile/torture/intrinsics-8.rs: likewise
* rust/compile/torture/issue-1024.rs: likewise
* rust/compile/torture/issue-1075.rs: likewise
* rust/compile/torture/issue-1432.rs: likewise
* rust/compile/torture/issue-1555.rs: likewise
* rust/compile/torture/issue-368.rs: likewise
* rust/compile/torture/issue-808.rs: likewise
* rust/compile/torture/issue-862.rs: likewise
* rust/compile/torture/issue-893-2.rs: likewise
* rust/compile/torture/issue-893.rs: likewise
* rust/compile/torture/must_use2.rs: likewise
* rust/compile/torture/nested_fn2.rs: likewise
* rust/compile/torture/phantom_data.rs: likewise
* rust/compile/torture/range-lang-item1.rs: likewise
* rust/compile/torture/traits1.rs: likewise
* rust/compile/torture/traits11.rs: likewise
* rust/compile/torture/traits12.rs: likewise
* rust/compile/torture/traits13.rs: likewise
* rust/compile/torture/traits14.rs: likewise
* rust/compile/torture/traits15.rs: likewise
* rust/compile/torture/traits16.rs: likewise
* rust/compile/torture/traits17.rs: likewise
* rust/compile/torture/traits18.rs: likewise
* rust/compile/torture/traits19.rs: likewise
* rust/compile/torture/traits2.rs: likewise
* rust/compile/torture/traits3.rs: likewise
* rust/compile/torture/traits4.rs: likewise
* rust/compile/torture/traits5.rs: likewise
* rust/compile/torture/traits6.rs: likewise
* rust/compile/torture/traits7.rs: likewise
* rust/compile/torture/traits8.rs: likewise
* rust/compile/torture/traits9.rs: likewise
* rust/compile/torture/transmute-size-check-1.rs: likewise
* rust/compile/torture/transmute1.rs: likewise
* rust/compile/torture/uninit-intrinsic-1.rs: likewise
* rust/compile/torture/utf8_identifiers.rs: likewise
* rust/compile/traits1.rs: likewise
* rust/compile/traits10.rs: likewise
* rust/compile/traits11.rs: likewise
* rust/compile/traits12.rs: likewise
* rust/compile/traits2.rs: likewise
* rust/compile/traits3.rs: likewise
* rust/compile/traits4.rs: likewise
* rust/compile/traits5.rs: likewise
* rust/compile/traits6.rs: likewise
* rust/compile/traits7.rs: likewise
* rust/compile/traits8.rs: likewise
* rust/compile/traits9.rs: likewise
* rust/compile/type-bindings1.rs: likewise
* rust/compile/unconstrained_type_param.rs: likewise
* rust/compile/unsafe10.rs: likewise
* rust/execute/torture/closure1.rs: likewise
* rust/execute/torture/closure2.rs: likewise
* rust/execute/torture/closure3.rs: likewise
* rust/execute/torture/closure4.rs: likewise
* rust/execute/torture/coercion1.rs: likewise
* rust/execute/torture/coercion2.rs: likewise
* rust/execute/torture/coercion3.rs: likewise
* rust/execute/torture/copy_nonoverlapping1.rs: likewise
* rust/execute/torture/derive_macro1.rs: likewise
* rust/execute/torture/derive_macro3.rs: likewise
* rust/execute/torture/derive_macro4.rs: likewise
* rust/execute/torture/index1.rs: likewise
* rust/execute/torture/issue-1120.rs: likewise
* rust/execute/torture/issue-1133.rs: likewise
* rust/execute/torture/issue-1198.rs: likewise
* rust/execute/torture/issue-1232.rs: likewise
* rust/execute/torture/issue-1249.rs: likewise
* rust/execute/torture/issue-1436.rs: likewise
* rust/execute/torture/issue-1496.rs: likewise
* rust/execute/torture/issue-1720-2.rs: likewise
* rust/execute/torture/issue-1720.rs: likewise
* rust/execute/torture/issue-2052.rs: likewise
* rust/execute/torture/issue-2179.rs: likewise
* rust/execute/torture/issue-2180.rs: likewise
* rust/execute/torture/issue-2236.rs: likewise
* rust/execute/torture/issue-647.rs: likewise
* rust/execute/torture/issue-845.rs: likewise
* rust/execute/torture/issue-851.rs: likewise
* rust/execute/torture/issue-858.rs: likewise
* rust/execute/torture/macros23.rs: likewise
* rust/execute/torture/macros28.rs: likewise
* rust/execute/torture/method2.rs: likewise
* rust/execute/torture/method3.rs: likewise
* rust/execute/torture/method4.rs: likewise
* rust/execute/torture/operator_overload_1.rs: likewise
* rust/execute/torture/operator_overload_10.rs: likewise
* rust/execute/torture/operator_overload_11.rs: likewise
* rust/execute/torture/operator_overload_12.rs: likewise
* rust/execute/torture/operator_overload_2.rs: likewise
* rust/execute/torture/operator_overload_3.rs: likewise
* rust/execute/torture/operator_overload_4.rs: likewise
* rust/execute/torture/operator_overload_5.rs: likewise
* rust/execute/torture/operator_overload_6.rs: likewise
* rust/execute/torture/operator_overload_7.rs: likewise
* rust/execute/torture/operator_overload_8.rs: likewise
* rust/execute/torture/operator_overload_9.rs: likewise
* rust/execute/torture/prefetch_data.rs: likewise
* rust/execute/torture/ref-pattern2.rs: likewise
* rust/execute/torture/slice-magic.rs: likewise
* rust/execute/torture/slice-magic2.rs: likewise
* rust/execute/torture/slice1.rs: likewise
* rust/execute/torture/str-layout1.rs: likewise
* rust/execute/torture/trait1.rs: likewise
* rust/execute/torture/trait10.rs: likewise
* rust/execute/torture/trait11.rs: likewise
* rust/execute/torture/trait12.rs: likewise
* rust/execute/torture/trait13.rs: likewise
* rust/execute/torture/trait2.rs: likewise
* rust/execute/torture/trait3.rs: likewise
* rust/execute/torture/trait4.rs: likewise
* rust/execute/torture/trait5.rs: likewise
* rust/execute/torture/trait6.rs: likewise
* rust/execute/torture/trait7.rs: likewise
* rust/execute/torture/trait8.rs: likewise
* rust/execute/torture/trait9.rs: likewise
* rust/execute/torture/transmute1.rs: likewise
* rust/execute/torture/wrapping_op1.rs: likewise
* rust/execute/torture/wrapping_op2.rs: likewise
* rust/link/generic_function_0.rs: likewise
* rust/link/generic_function_1.rs: likewise
* rust/compile/issue-2375.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Tue, 18 Jul 2023 15:07:32 +0000 (16:07 +0100)]
gccrs: Track polarity in type bound predicate
Addresses #2443
gcc/rust/ChangeLog:
* typecheck/rust-hir-path-probe.cc: track regular polarity
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): likewise
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): likewise
* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): likewise
(TypeBoundPredicate::TypeBoundPredicate): update ctor
(TypeBoundPredicate::operator=): update copy assignment ctor
(TypeBoundPredicate::error): update error node
* typecheck/rust-tyty.h: add polarity field to predicate
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Tue, 18 Jul 2023 11:12:22 +0000 (12:12 +0100)]
gccrs: Track trait bound polarity properly
Trait bounds can have three forms in Rust the regular trait bound, '!' the
negative trait bound to enforice that this trait must not be implmented and
'?' the anti trait bound to remove this bound. This patch extends our
Polarity enum to include the Anti trait bound and updates the HIR lowering
code to track this properly.
Addresses #2443
gcc/rust/ChangeLog:
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): use new BoundPolarity enum
* hir/rust-ast-lower-type.cc (ASTLoweringTypeBounds::visit): likewise
* hir/rust-hir-dump.cc (BoundPolarityString): new helper
(Dump::visit): update hir dump
* hir/tree/rust-hir-item.h (class ImplBlock): likewise
* hir/tree/rust-hir-type.h (class TraitBound): likewise
* hir/tree/rust-hir.cc (TraitBound::as_string): fix as string
* util/rust-common.h (enum Polarity): add new anti bound
(enum BoundPolarity): likewise
* util/rust-hir-map.cc (Mappings::Mappings): update naming
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Owen Avery [Fri, 14 Jul 2023 19:39:14 +0000 (15:39 -0400)]
gccrs: Move Gcc_backend declaration to header file
gcc/rust/ChangeLog:
* rust-backend.h: Include "rust-gcc.h".
(class Gcc_backend): Move to ...
* rust-gcc.cc (class Gcc_backend): ... here.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Philip Herron [Sat, 29 Jul 2023 16:33:47 +0000 (17:33 +0100)]
gccrs: fix ICE when we have unimplemented/invalid trait items
When the resulting trait item is in an error state this means the
underlying fields will be null.
Fixes #2478
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-item.cc: add is_error check
gcc/testsuite/ChangeLog:
* rust/compile/non_member_const.rs: add missing error message
* rust/compile/issue-2478.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Raiki Tamura [Fri, 14 Jul 2023 05:45:34 +0000 (14:45 +0900)]
gccrs: Add function for Unicode NFC normalization
gcc/rust/ChangeLog:
* Make-lang.in: Add rust-unicode.o
* rust-lang.cc (run_rust_tests): Add test.
* rust-system.h: Include <array>
* util/make-rust-unicode.py: Generater of rust-unicode-data.h.
* util/rust-unicode-data.h: Auto-generated file.
* util/rust-unicode.cc: New file.
* util/rust-unicode.h: New file.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Arthur Cohen [Fri, 28 Jul 2023 12:33:34 +0000 (14:33 +0200)]
gccrs: error codes: Add rust_error_codes.def, refactor ErrorCode enum
gcc/rust/ChangeLog:
* rust-diagnostics.cc: Rework `make_description` and `make_url` functions.
* rust-diagnostics.h: Specify ErrorCode's underlying type,
remove error_codes_strings table.
* rust_error_codes.def: New file.
Owen Avery [Tue, 11 Jul 2023 00:15:19 +0000 (20:15 -0400)]
gccrs: Remove Location typedef
gcc/rust/ChangeLog:
* rust-location.h (typedef Location): Remove.
* expand/rust-proc-macro.cc
(register_callback): Replace Location constructor with UNDEF_LOCATION.
* ast/rust-ast-collector.h: Replace Location with location_t.
* checks/errors/privacy/rust-privacy-reporter.cc: Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* checks/errors/privacy/rust-pub-restricted-visitor.cc: Likewise.
* checks/errors/privacy/rust-pub-restricted-visitor.h: Likewise.
* checks/errors/rust-feature-gate.cc: Likewise.
* checks/errors/rust-feature-gate.h: Likewise.
* metadata/rust-imports.h: Likewise.
* resolve/rust-ast-resolve-path.h: Likewise.
* resolve/rust-name-resolver.h: Likewise.
* rust-backend.h: Likewise.
* rust-diagnostics.h: Likewise.
* rust-gcc.cc: Likewise.
* rust-linemap.h: Likewise.
* util/rust-attributes.cc: Likewise.
* util/rust-hir-map.cc: Likewise.
* util/rust-hir-map.h: Likewise.
* util/rust-token-converter.cc: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Tue, 11 Jul 2023 02:19:51 +0000 (22:19 -0400)]
gccrs: Replace usages of Location with location_t in typechecking
gcc/rust/ChangeLog:
* typecheck/rust-autoderef.cc: Replace Location with location_t.
* typecheck/rust-coercion.cc: Likewise.
* typecheck/rust-coercion.h: Likewise.
* typecheck/rust-hir-path-probe.h: Likewise.
* typecheck/rust-hir-trait-reference.cc: Likewise.
* typecheck/rust-hir-trait-resolve.cc: Likewise.
* typecheck/rust-hir-type-check-base.cc: Likewise.
* typecheck/rust-hir-type-check-expr.cc: Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* typecheck/rust-hir-type-check-implitem.cc: Likewise.
* typecheck/rust-hir-type-check-item.cc: Likewise.
* typecheck/rust-hir-type-check-path.cc: Likewise.
* typecheck/rust-hir-type-check-pattern.cc: Likewise.
* typecheck/rust-hir-type-check-stmt.cc: Likewise.
* typecheck/rust-hir-type-check-struct.cc: Likewise.
* typecheck/rust-hir-type-check-type.cc: Likewise.
* typecheck/rust-hir-type-check-type.h: Likewise.
* typecheck/rust-type-util.cc: Likewise.
* typecheck/rust-type-util.h: Likewise.
* typecheck/rust-tyty-bounds.cc: Likewise.
* typecheck/rust-tyty-call.cc: Likewise.
* typecheck/rust-tyty-call.h: Likewise.
* typecheck/rust-tyty-cmp.h: Likewise.
* typecheck/rust-tyty-subst.cc: Likewise.
* typecheck/rust-tyty-subst.h: Likewise.
* typecheck/rust-tyty.cc: Likewise.
Muhammad Mahad [Thu, 27 Jul 2023 11:36:09 +0000 (16:36 +0500)]
gccrs: [E0571] break with argument in non-loop loop
Refactored error message similiar to rustc
& called error function.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
refactored error message & called error function.
gcc/testsuite/ChangeLog:
* rust/compile/break2.rs: Modified file to pass test case.
* rust/compile/break_with_value_inside_loop.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Pierre-Emmanuel Patry [Thu, 27 Jul 2023 14:21:25 +0000 (16:21 +0200)]
gccrs: proc_macro: Add literal_from_string callback
The function to get a literal from a string missed an implementation.
It did require a conversion function to achieve it, now that callback
system has been merged this function can be easily implemented.
gcc/rust/ChangeLog:
* expand/rust-proc-macro.cc (literal_from_string): Add callback
function.
(load_macros_array): Likewise.
libgrust/ChangeLog:
* libproc_macro/literal.cc (Literal__from_string): Add
implementation with call to constructor.
(Literal::make_literal): Add new constructor which calls the
callback.
* libproc_macro/literal.h: Add new constructor's
prototype.
* libproc_macro/proc_macro.cc (bridge_is_available):
Change symbol name to match convention.
* libproc_macro/registration.h: Add lit_from_str
symbol.
* libproc_macro/tokenstream.cc (TokenStream::make_tokenstream):
Change symbol name to disambiguate with literal from string.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 27 Jul 2023 13:57:07 +0000 (15:57 +0200)]
gccrs: converter: Move literal conversion out
The literal conversion code could be used for the literal_from_string
callback, this means we should move it out of the function in it's own
function. This involves a new switch, which is quite sad but we're not
yet at a performance profiling phase, there may be lower hanging fruits.
gcc/rust/ChangeLog:
* util/rust-token-converter.cc (handle_suffix): Rework function
to make it work with the new literal conversion function.
(convert_literal): Add a new function to convert to a proc macro
literal from a literal tokenptr. The function will abort if the
pointer does not point to a literal.
(convert): Add call to convert literal for every literal case.
* util/rust-token-converter.h (convert_literal): Add public
prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 27 Jul 2023 13:22:48 +0000 (15:22 +0200)]
gccrs: Move callbacked function in a new namespace
Move the function registered as a callback in a new anonymous namespace
in order to group every callback in the future under the same namespace.
gcc/rust/ChangeLog:
* expand/rust-proc-macro.cc: Remove static modifier and move to
an anonymous namespace.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Muhammad Mahad [Thu, 27 Jul 2023 16:36:55 +0000 (21:36 +0500)]
gccrs: New Error Code Framework
Updated ErrorCode struct to enum class to enforce proper
error codes, similiar to rustc. For converting the enum
to the respective error code, I used a map and updated
make_description & make_url function accordingly and
also removes the memory leak from the previous frame-
work. Also, added macro to safely convert the enum
number to string.
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (Intrinsics::compile):
Formatted according to enum class.
* checks/errors/rust-feature-gate.cc (FeatureGate::gate): likewise.
* checks/errors/rust-unsafe-checker.cc (check_unsafe_call): likewise.
* hir/rust-ast-lower-base.cc (struct_field_name_exists): likewise.
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit): likewise.
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path):
likewise.
* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::go): likewise.
(PatternDeclaration::add_new_binding): likewise.
* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): likewise.
* resolve/rust-ast-verify-assignee.h: likewise.
* rust-diagnostics.cc: updated make_desc & url function for enum class.
* rust-diagnostics.h (struct ErrorCode): removed struct to switch to enum.
(enum class): Switched from errorcode struct to enum class.
(XSTR): Macro for converting enum to string.
(STR): macro Used by XSTR for converting to string.
(ERROR_CODE): macro used by map for check.
(TABLE_TO_MAP): macro used by map for check
* typecheck/rust-casts.cc (TypeCastRules::emit_cast_error):
Formatted according to enum class.
* typecheck/rust-hir-path-probe.h: likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
likewise.
(TypeCheckImplItemWithTrait::visit): likewise.
* typecheck/rust-hir-type-check-item.cc: likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): likewise.
(emit_invalid_field_error): likewise.
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve): likewise.
* typecheck/rust-tyty-call.cc (emit_unexpected_argument_error): likewise.
(TypeCheckCallExpr::visit): likewise.
* typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args):
likewise.
* typecheck/rust-tyty.cc (BaseType::bounds_compatible): likewise.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 10:47:57 +0000 (12:47 +0200)]
gccrs: Add multiple tests for non root proc macro
Add multiple tests to prevent regressions on procedural macros errors
when one is declared outside of the crate's top level.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_attribute_non_root_function.rs: New test.
* rust/compile/proc_macro_attribute_non_root_method.rs: New test.
* rust/compile/proc_macro_attribute_non_root_module.rs: New test.
* rust/compile/proc_macro_derive_non_root_function.rs: New test.
* rust/compile/proc_macro_derive_non_root_method.rs: New test.
* rust/compile/proc_macro_derive_non_root_module.rs: New test.
* rust/compile/proc_macro_non_root_function.rs: New test.
* rust/compile/proc_macro_non_root_method.rs: New test.
* rust/compile/proc_macro_non_root_module.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 10:16:12 +0000 (12:16 +0200)]
gccrs: Check proc_macro attributes on non root functions
Check proc_macro, proc_macro_attribute and proc_macro_derive attributes
on non root functions, emit an error when one is found.
gcc/rust/ChangeLog:
* util/rust-attributes.cc (check_proc_macro_non_root): Add
function to emit this specific error.
(AttributeChecker::visit): Modify visitor to propagate to some
containers that were not handled correctly.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Owen Avery [Mon, 10 Jul 2023 23:39:02 +0000 (19:39 -0400)]
gccrs: Replace Location with location_t in unnamed function parameters
gcc/rust/ChangeLog:
* backend/rust-compile-base.h: Replace Location with location_t.
* metadata/rust-imports.h: Likewise.
* resolve/rust-name-resolver.cc: Likewise.
* resolve/rust-name-resolver.h: Likewise.
* rust-backend.h: Likewise.
* rust-gcc.cc: Likewise.
* rust-gcc.h: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Pierre-Emmanuel Patry [Thu, 27 Jul 2023 09:58:56 +0000 (11:58 +0200)]
gccrs: proc_macro: Remove useless typedef
Initially a typedef was used to easily get the callback function pointer
type. Since this type has changed to a simpler well defined type, this
using declaration has no more purpose.
libgrust/ChangeLog:
* libproc_macro/proc_macro.cc: Remove type alias.
* libproc_macro/registration.h: Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 16:05:42 +0000 (18:05 +0200)]
gccrs: proc_macro: Delete unused prototype
This function prototype was forgotten when the function was deleted.
libgrust/ChangeLog:
* libproc_macro/proc_macro.h (proc_macro_register_from_str):
Remove rogue function prototype.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 15:44:50 +0000 (17:44 +0200)]
gccrs: proc_macro: Remode function indirection
There was no need to register a function when the value could be
registered directly.
gcc/rust/ChangeLog:
* expand/rust-proc-macro.cc (available): Remove function.
(load_macros_array): There was no need for an indirection here.
libgrust/ChangeLog:
* libproc_macro/proc_macro.cc (not_available): Remove
function.
* libproc_macro/proc_macro.h (not_available): Remove
function prototype.
* libproc_macro/registration.h: Change symbol type.
* libproc_macro/bridge.h: New file.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 15:00:57 +0000 (17:00 +0200)]
gccrs: proc_macro: Add is_available function
Add is_available function to the C++ library.
libgrust/ChangeLog:
* libproc_macro/proc_macro.cc (bridge_is_available):
Add bridge function.
* libproc_macro/proc_macro.h (bridge_is_available):
Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 14:48:37 +0000 (16:48 +0200)]
gccrs: proc_macro: Add is_available callback
Add a callback from gcc to determine wether the bridge is available or
not.
gcc/rust/ChangeLog:
* expand/rust-proc-macro.cc (available): Add symbol
registration.
(load_macros_array): Likewise.
libgrust/ChangeLog:
* libproc_macro/proc_macro.cc (not_available): Add a
function to express bridge unavailability.
* libproc_macro/proc_macro.h (not_available): Likewise.
* libproc_macro/registration.h: Add symbol type.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 14:44:59 +0000 (16:44 +0200)]
gccrs: proc_macro: Rename from_string callback symbol
The symbol had a different convention from rust standard naming
convention (?) hence the change before adding new callback.
gcc/rust/ChangeLog:
* expand/rust-proc-macro.cc (load_macros_array): Symbol rename.
libgrust/ChangeLog:
* libproc_macro/proc_macro.cc (Procmacro::make_bang):
Change symbol name.
* libproc_macro/registration.h: Likewise.
* libproc_macro/tokenstream.cc (TokenStream::make_tokenstream): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 27 Jul 2023 11:11:08 +0000 (13:11 +0200)]
gccrs: proc_macro: Refactor attribute search
Refactor attribute search with early return. Also fix the optional
building an object with it's default empty constructor by explicitely
using tl::null_opt.
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-privacy-reporter.cc (find_proc_macro_attribute):
Refactor the function to be safer and more efficient.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 20 Jul 2023 11:40:35 +0000 (13:40 +0200)]
gccrs: privacy: Refactor proc macro privacy check
Refactor proc macro specific privacy check in multiple shorter
functions.
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-privacy-reporter.cc (find_proc_macro_attribute):
Add a new function to find a potential proc macro type
attribute on a given item.
(proc_macro_privacy_check): Move all proc macro privacy check in
their own function to avoid cluttering the usual privacy check.
(PrivacyReporter::go): Add call to newly created proc macro
privacy check function.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 20 Jul 2023 11:06:32 +0000 (13:06 +0200)]
gccrs: testsuite: Add tests for pub items in proc_macros
Crates of type 'proc-macro' should not have any other pub member than
procedural macros. These new test will avoid regression on error
messages in such sitation.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_pub_function.rs: New test.
* rust/compile/proc_macro_pub_module.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 20 Jul 2023 10:52:50 +0000 (12:52 +0200)]
gccrs: testsuite: Replace dg-excess-errors with dg-error
Some test were using dg-excess-errors instead of dg-error, this is now
fixed.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_attribute_crate_type.rs: Replace
dg-excess-errors with dg-error and fix the line so the test
can pass.
* rust/compile/proc_macro_crate_type.rs: Likewise.
* rust/compile/proc_macro_derive_crate_type.rs: Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 20 Jul 2023 10:37:47 +0000 (12:37 +0200)]
gccrs: privacy: Add tests for private proc macro error
Add some tests to prevent regression on private procedural macros error
messages.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_attribute_private.rs: New test.
* rust/compile/proc_macro_derive_private.rs: New test.
* rust/compile/proc_macro_private.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 18 Jul 2023 15:36:11 +0000 (17:36 +0200)]
gccrs: proc macro: Add privacy check
Proc macro crates cannot have any public function but proc macros. Proc
macros should be public.
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::go):
Add visibility verification.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Fri, 21 Jul 2023 12:18:12 +0000 (14:18 +0200)]
gccrs: Add tests for non function proc_macro_derive
Add a bunch of test cases to avoid regressions on proc_macro_derive
attribute errors when placed on any non function item.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_derive_non_function.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Fri, 21 Jul 2023 12:03:10 +0000 (14:03 +0200)]
gccrs: Add tests for non function proc_macro_attribute
Add a bunch of test case to avoid regressions on proc_macro_attribute
attribute error messages.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_attribute_non_function.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Fri, 21 Jul 2023 11:32:53 +0000 (13:32 +0200)]
gccrs: Add tests for non function proc_macro attributes
Add a bunch of test cases to avoid regressions on attribute error
message.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_non_function.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Fri, 21 Jul 2023 10:41:12 +0000 (12:41 +0200)]
gccrs: Emit error with proc macro on non functions
An error should be emitted when a proc_macro, proc_macro_attribute or
proc_macro_derive attribute is met on any non function item. Those
attribute shall be placed only on bare functions.
gcc/rust/ChangeLog:
* util/rust-attributes.cc (is_proc_macro_type): Add function to
identify matching proc macro attribute type.
(check_proc_macro_non_function): Add function to check and emit
error.
(AttributeChecker::visit): Add cal to new check function.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 13 Jul 2023 12:50:38 +0000 (14:50 +0200)]
gccrs: Remove NodeId member from Identifier
Remove the NodeId member from identifiers. This member did not make
sense and was solely used for procedural macros.
gcc/rust/ChangeLog:
* ast/rust-ast.h: Remove NodeId from identifiers.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Muhammad Mahad [Wed, 19 Jul 2023 10:49:25 +0000 (15:49 +0500)]
gccrs: [E0045] Variadic Parameters Used on Non-C ABI Function
Added error code support for using variadic parameters used
on Non-C ABI function. Fixes #2382
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit):
Added check for error code support.
gcc/testsuite/ChangeLog:
* rust/compile/abi-vardaic.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Muhammad Mahad [Tue, 18 Jul 2023 13:55:32 +0000 (18:55 +0500)]
gccrs: [E0323] Implemented associated const, expected another trait
Refactored Error message similiar to rustc.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItemWithTrait::visit):
called error function.
gcc/testsuite/ChangeLog:
* rust/compile/non_member_const.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 13:39:25 +0000 (15:39 +0200)]
gccrs: proc_macro: Mirror FFIString changes in C++library
Recent changes in the rust interface on some extern C function shall be
synced up in the C++ library.
libgrust/ChangeLog:
* libproc_macro/literal.cc (Literal__from_string):
Update to match rust interface.
* libproc_macro/literal.h (Literal__from_string):
Likewise.
* libproc_macro/tokenstream.cc (TokenStream__from_string):
Likewise.
* libproc_macro/tokenstream.h (TokenStream__from_string):
Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 26 Jul 2023 13:26:55 +0000 (15:26 +0200)]
gccrs: proc_macro: Increase FFIString usage
Two remaining structures in the rust interface were still using raw
string pointer and length couples to communicate with the C++ library
throught extern C functions. Using FFIString instead allow us to reduce
the scope of potential errors using those raw pointers. As FFIString
encapsulate raw pointer operations there will be only one locaiton to
look after.
libgrust/ChangeLog:
* libproc_macro/rust/bridge/literal.rs: Change extern C
function argument from raw string pointer and length to
FFIString.
* libproc_macro/rust/bridge/token_stream.rs: Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Owen Avery [Mon, 10 Jul 2023 20:06:27 +0000 (16:06 -0400)]
gccrs: Continue to replace usages of Location with location_t
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc: Replace Location with location_t.
* backend/rust-compile-base.h: Likewise.
* backend/rust-compile-expr.cc: Likewise.
* lex/rust-token.h: Likewise.
* metadata/rust-import-archive.cc: Likewise.
* metadata/rust-imports.cc: Likewise.
* metadata/rust-imports.h: Likewise.
* rust-backend.h: Likewise.
* rust-diagnostics.cc: Likewise.
* rust-diagnostics.h: Likewise.
* rust-gcc.cc: Likewise.
* rust-linemap.cc: Likewise.
* util/rust-token-converter.cc: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Mon, 10 Jul 2023 20:13:59 +0000 (16:13 -0400)]
gccrs: Replace usages of Location with location_t in the lexer, AST, and HIR
gcc/rust/ChangeLog:
* ast/rust-ast-builder.h: Replace Location with location_t.
* ast/rust-ast.h: Likewise.
* ast/rust-expr.h: Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-macro.h: Likewise.
* ast/rust-path.h: Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* hir/tree/rust-hir-item.h: Likewise.
* hir/tree/rust-hir-path.h: Likewise.
* hir/tree/rust-hir.h: Likewise.
* lex/rust-lex.cc: Likewise.
* lex/rust-lex.h: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Mon, 10 Jul 2023 20:21:36 +0000 (16:21 -0400)]
gccrs: Replace Location with location_t in parsing and macro expansion
gcc/rust/ChangeLog:
* expand/rust-derive-clone.cc: Replace Location with location_t.
* expand/rust-derive-clone.h: Likewise.
* expand/rust-derive-copy.cc: Likewise.
* expand/rust-derive-copy.h: Likewise.
* expand/rust-derive.cc: Likewise.
* expand/rust-derive.h: Likewise.
* expand/rust-macro-builtins.cc: Likewise.
* expand/rust-macro-builtins.h: Likewise.
* expand/rust-macro-expand.cc: Likewise.
* parse/rust-parse-impl.h: Likewise.
* parse/rust-parse.cc: Likewise.
* parse/rust-parse.h: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Tue, 16 May 2023 17:35:07 +0000 (13:35 -0400)]
gccrs: Improve keyword check while parsing a macro match
gcc/rust/ChangeLog:
* parse/rust-parse-impl.h
(Parser::parse_macro_match): Use token_id_is_keyword.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Pierre-Emmanuel Patry [Thu, 13 Jul 2023 10:48:18 +0000 (12:48 +0200)]
gccrs: resolve: Remove ProcMacroInvocable interface
Since all identifiers in attributes are converted to SimplePath, this
common interface is no longer required.
gcc/rust/ChangeLog:
* ast/rust-ast.h (class Identifier): Remove interface
inheritance.
(class SimplePath): Likewise.
* expand/rust-expand-visitor.cc (get_traits_to_derive): Change
return type.
(derive_item): Update according to get_traits_to_derive return
type.
(expand_item_attribute): Likewise.
(ExpandVisitor::expand_inner_stmts): Likewise.
* expand/rust-macro-expand.h (struct MacroExpander): Likewise.
* util/rust-hir-map.cc (Mappings::insert_derive_proc_macro_invocation):
Change input type to SimplePath.
(Mappings::lookup_derive_proc_macro_invocation): Likewise.
(Mappings::insert_attribute_proc_macro_invocation): Likewise.
(Mappings::lookup_attribute_proc_macro_invocation): Likewise.
* util/rust-hir-map.h: Likewise with function prototypes.
* util/rust-proc-macro-invocation.h: Removed.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 13 Jul 2023 09:57:41 +0000 (11:57 +0200)]
gccrs: resolve: Convert identifier to a SimplePath
We wish to remove node ids from identifiers, because they do not make
that much sense and are only used for procedural macros anyway. This
means we either have to wrap those into a structure or converting them
to an existing structure that already have a node id. This commit
convert those meta word identifiers to a meta path SimplePath.
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add new constructor for SimplePath from an
identifier.
* expand/rust-expand-visitor.cc (get_traits_to_derive): Add
conversion.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 19 Jun 2023 10:51:34 +0000 (12:51 +0200)]
gccrs: resolve: Add mappings for proc macros and resolving
Add multiple mappings for procedural macro name resolution.
Procedural macros were not resolved using name resolution and mapping
but rather with some hacky path comparison.
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc (MacroExpander::import_proc_macros):
Remove function.
* expand/rust-macro-expand.h (struct MacroExpander): Remove
import_proc_macro function.
* util/rust-hir-map.cc (Mappings::insert_derive_proc_macro_def):
Add a function to insert a derive proc macro definition.
(Mappings::insert_bang_proc_macro): Remove function.
(Mappings::insert_bang_proc_macro_def): Add function to insert a
bang proc macro definition.
(Mappings::insert_attribute_proc_macro_def): Likewise with
attribute proc macros.
(Mappings::lookup_derive_proc_macro_def): Add a function to
lookup a defined derive proc macro definition.
(Mappings::lookup_bang_proc_macro): Remove function.
(Mappings::lookup_bang_proc_macro_def): Add a function to lookup
a bang proc macro definition.
(Mappings::lookup_attribute_proc_macro_def): Add a function to
lookup an attribute prod macro definition.
(Mappings::insert_derive_proc_macro_invocation): Add a function
to insert a derive proc macro invocation.
(Mappings::lookup_derive_proc_macro_invocation): Add a function
to lookup a derive proc macro invocation.
(Mappings::insert_bang_proc_macro_invocation): Add a function to
insert a bang proc macro invocation.
(Mappings::lookup_bang_proc_macro_invocation): Add a function to
lookup a bang proc macro invocation.
(Mappings::insert_attribute_proc_macro_invocation): Add a
function to insert an attribute proc macro invocation.
(Mappings::lookup_attribute_proc_macro_invocation): Add a
function to lookup an attribute proc macro invocation.
* util/rust-hir-map.h: Add different proc macro mappings
and change function prototypes.
* expand/rust-expand-visitor.cc (get_traits_to_derive): Return a
vector of SimplePath instead.
(derive_item): Accept SimplePath instead of a string.
* ast/rust-ast.h: Add common ProcMacroInvocable interface to
Identifiers and SimplePath nodes.
* ast/rust-ast.cc: Add const modifier.
* ast/rust-macro.h: Change path and identifier getters.
* ast/rust-path.h: Change return type to reference.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 20 Jun 2023 13:46:20 +0000 (15:46 +0200)]
gccrs: attribute: Add missing header guard
Missing header guard may cause infinitie include recursion.
gcc/rust/ChangeLog:
* util/rust-attributes.h (RUST_ATTRIBUTES_H): Add missing header
guard.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 20 Jun 2023 11:26:45 +0000 (13:26 +0200)]
gccrs: ast: Add manual dispatch for meta item downcasting
Several meta items shall be downcasted in various places, this commit
introduces values to dispatch on.
gcc/rust/ChangeLog:
* ast/rust-ast.h (class MetaItem): Add MetaItem dispatch values.
* ast/rust-expr.h: Add LitExpr and PathLit dispatch.
* ast/rust-macro.h: Add remaining dispatch getters.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Fri, 16 Jun 2023 16:17:39 +0000 (18:17 +0200)]
gccrs: resolve: Add extern crate proc macro collection
Create a mapping for procedural macros with their crate num.
gcc/rust/ChangeLog:
* metadata/rust-extern-crate.h: Add proc macro getter.
* rust-session-manager.cc (Session::load_extern_crate): Collect
mappings and create mappings.
* util/rust-hir-map.cc: Add insertion and lookup functions for
every mapping.
* util/rust-hir-map.h: Add function prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 15 Jun 2023 14:37:07 +0000 (16:37 +0200)]
gccrs: import: Load procedural macros into external crate
Load the procedural macro array into the external crate structure.
gcc/rust/ChangeLog:
* metadata/rust-imports.cc (Import::try_package_in_directory):
Add call to load macros before loading metadatas.
* expand/rust-proc-macro.cc: Return empty vector instead of
panicking on error.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 15 Jun 2023 13:32:38 +0000 (15:32 +0200)]
gccrs: import: Change raw pointer to unique_ptr
Replace Stream raw pointer with a smart pointer.
gcc/rust/ChangeLog:
* metadata/rust-import-archive.cc (Stream_concatenate::do_peek):
Remove deletion.
(Stream_concatenate::do_advance): Likewise.
(Import::find_archive_export_data): Replace with a smart
pointer.
* metadata/rust-imports.cc (add_search_path): Change return type
to smart pointer.
(Import::open_package): Likewise.
(Import::try_package_in_directory): Likewise.
(Import::find_export_data): Likewise.
(Import::find_object_export_data): Likewise.
(Import::Import): Change constructor to accept unique_ptr.
* metadata/rust-imports.h: Change constructor prototype.
* rust-session-manager.cc (Session::load_extern_crate): Change
pointer to smart pointer.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 15 Jun 2023 11:58:08 +0000 (13:58 +0200)]
gccrs: import: Store procedural macros in extern crate
Store procedural macro data in extern crate node.
gcc/rust/ChangeLog:
* metadata/rust-extern-crate.cc (ExternCrate::ExternCrate):
Change constructor to accept procedural macro vector.
* metadata/rust-extern-crate.h: Add vector of procecural macro
in extern crate.
* rust-session-manager.cc (Session::load_extern_crate): Add
argument to new constructor call.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 15 Jun 2023 11:49:43 +0000 (13:49 +0200)]
gccrs: import: Change package opening prototypes
Also return a vector of proc macros when trying to open an external
crate.
gcc/rust/ChangeLog:
* metadata/rust-imports.cc (add_search_path): Change prototype,
now return a pair of Stream and procedural macro vector.
(Import::open_package): Likewise.
(Import::try_package_in_directory): Likewise.
* metadata/rust-imports.h: Likewise.
* rust-session-manager.cc (Session::load_extern_crate):
Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 14 Jun 2023 13:20:21 +0000 (15:20 +0200)]
gccrs: import: Add cli extern crate resolution
This commit add the ability to specify the path to an extern crate
through the -frust-extern cli option. Path given as cli argument
shall resolve to the exact extern crate location.
gcc/rust/ChangeLog:
* metadata/rust-imports.h: Make the function to load a given
file public.
* rust-session-manager.cc (Session::load_extern_crate): Change
path resolution depending on extern crate declaration in cli
arguments.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Owen Avery [Tue, 18 Jul 2023 19:55:51 +0000 (15:55 -0400)]
gccrs: Replace default argument with UNDEF_LOCATION
gcc/rust/ChangeLog:
* ast/rust-ast-collector.h
(TokenCollector::visit):
Replace default argument with UNDEF_LOCATION.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Tue, 11 Jul 2023 02:33:08 +0000 (22:33 -0400)]
gccrs: Replace Location with location_t in gccrs backend
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc: Replace Location with location_t.
* backend/rust-compile-base.h: Likewise.
* backend/rust-compile-block.cc: Likewise.
* backend/rust-compile-expr.cc: Likewise.
* backend/rust-compile-expr.h: Likewise.
* backend/rust-compile-extern.h: Likewise.
* backend/rust-compile-implitem.h: Likewise.
* backend/rust-compile-intrinsic.cc: Likewise.
* backend/rust-compile-item.h: Likewise.
* backend/rust-compile-pattern.h: Likewise.
* backend/rust-compile-resolve-path.cc: Likewise.
* backend/rust-compile-stmt.cc: Likewise.
* backend/rust-compile-type.cc: Likewise.
* backend/rust-compile.cc: Likewise.
* backend/rust-constexpr.cc: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Muhammad Mahad [Wed, 19 Jul 2023 15:54:28 +0000 (20:54 +0500)]
gccrs: [E0268] break or continue used outside of loop
Refactored error description similiar to rustc.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
refactored and call error function.
gcc/testsuite/ChangeLog:
* rust/compile/break1.rs: Modified to pass test case.
* rust/compile/continue1.rs: likewise.
* rust/compile/break_continue_outside_loop.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Pierre-Emmanuel Patry [Tue, 18 Jul 2023 14:10:01 +0000 (16:10 +0200)]
gccrs: Add a test for malformed derive declaration input
Add a new test to highlight possible future regressions on malformed
proc_macro_derive input.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_derive_malformed.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 18 Jul 2023 13:43:06 +0000 (15:43 +0200)]
gccrs: proc macro: Add crate type regression tests
Add several tests to prevent regression with proc_macro,
proc_macro_derive and proc_macro_attribute attributes error messages.
gcc/testsuite/ChangeLog:
* rust/compile/proc_macro_attribute_crate_type.rs: New test.
* rust/compile/proc_macro_crate_type.rs: New test.
* rust/compile/proc_macro_derive_crate_type.rs: New test.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 18 Jul 2023 12:38:58 +0000 (14:38 +0200)]
gccrs: proc macro: Add help message to malformed derive
Add an help message in case of malformed proc_macro_derive declaration.
gcc/rust/ChangeLog:
* util/rust-attributes.cc (AttributeChecker::visit): Add help
message.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 18 Jul 2023 11:37:03 +0000 (13:37 +0200)]
gccrs: proc macro: Detect malformed proc_macro_derive
A derive procedural macro declaration shall always have at least a trait
to refer to. We should error out when it doesn't.
gcc/rust/ChangeLog:
* util/rust-attributes.cc (AttributeChecker::visit): Add
attribute input check.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 18 Jul 2023 11:26:46 +0000 (13:26 +0200)]
gccrs: proc macros: Add crate type attribute check
A procedural macroa attribute can only be used on proc macro crates.
gcc/rust/ChangeLog:
* util/rust-attributes.cc (AttributeChecker::visit): Add
attribute check on functions.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 19 Jul 2023 11:18:14 +0000 (13:18 +0200)]
gccrs: libproc_macro: Change rust Ident definition
Change rust interface Ident definition to match C++ struct definition.
This structure now uses an FFIString instead of raw pointers.
libgrust/ChangeLog:
* libproc_macro/rust/bridge/ident.rs: Change raw
pointer string with an FFIString.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 19 Jul 2023 09:50:23 +0000 (11:50 +0200)]
gccrs: libproc_macro: Change Ident structure
Use FFIString in Ident structure rather that a raw pointer and a
length, this will reduce the size of the code dealing with raw
pointers. Which should prevent some error.
gcc/rust/ChangeLog:
* util/rust-token-converter.cc (from_ident): Adapt code to new
constructor.
libgrust/ChangeLog:
* libproc_macro/ident.cc (Ident__new): Constructor
accepts an FFIString now.
(Ident__new_raw): Likewise.
(Ident::clone): Internal members change means clone also change.
(Ident::make_ident): Change constructor call.
(Ident::drop): Add call to FFIString::clone.
* libproc_macro/ident.h (struct Ident): Remove raw
pointer and length, add an FFIString inside instead.
(Ident__new): Change constructor.
(Ident__new_raw): Change constructor.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 11 Jul 2023 12:41:33 +0000 (14:41 +0200)]
gccrs: proc_macro: Add from string implementation
Add a callback registration function into the proc macro library so the
compiler can register it's own lexing/parsing functions on load.
gcc/rust/ChangeLog:
* expand/rust-proc-macro.cc (tokenstream_from_string): Add a
function that creates a tokenstream from a given string.
(load_macros_array): Add call to registration function.
libgrust/ChangeLog:
* libproc_macro/proc_macro.cc (proc_macro_register_from_str):
Add registration function.
* libproc_macro/proc_macro.h (proc_macro_register_from_str):
Add registration function prototype.
* libproc_macro/tokenstream.cc (TokenStream::make_tokenstream):
Add a new constructor from a string that uses the registered
callback.
(TokenStream__from_string): Add call to new constructor.
* libproc_macro/tokenstream.h: Add registration
declaration.
* libproc_macro/registration.h: New file.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Mon, 17 Jul 2023 11:09:36 +0000 (13:09 +0200)]
gccrs: cli: Add frust-type option
Add a new option to crab1 cli to accept crate type. This version of the
argument only accept a single crate type. Rustc accepts a comma
separated list of crate types but this might require a litle more work
for gcc.
gcc/rust/ChangeLog:
* lang.opt: Add option
* rust-session-manager.cc: Add option registration in session
target options.
* rust-session-manager.h (struct CompileOptions): Add new getter
for proc macros instead of a boolean.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Arthur Cohen [Fri, 23 Jun 2023 14:16:34 +0000 (16:16 +0200)]
gccrs: nr2.0: Add `ForeverStack` data structure.
This data structure replaces our existing scopes and allows for multiple
name resolution passes to insert definitions or look up names at different
stages of the pipeline. The documentation goes into detail about how the
data structure works, and how the source's hierarchy is preserved
throughout the pipeline.
The class is templated to enforce specific behavior based on the namespace
the scope map targets.
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h: New file.
* resolve/rust-forever-stack.hxx: New file.
Marc Poulhiès [Mon, 3 Jul 2023 19:04:45 +0000 (21:04 +0200)]
gccrs: rework the HIR dump pass
Nearly complete rewrite of the HIR dump pass.
fixes #693
gcc/rust/ChangeLog:
* hir/rust-hir-dump.cc (convert_param_kind_to_str): New.
(convert_new_bind_type_to_str): New.
(convert_mut_to_str): New.
(Dump::go): New.
(Dump::put): New.
(Dump::begin): New.
(Dump::end): New.
(Dump::begin_field): New.
(Dump::end_field): New.
(Dump::put_field): New.
(Dump::visit_field): New.
(Dump::visit): Refactor.
(Dump::visit_collection): New.
(Dump::do_traititem): New.
(Dump::do_vis_item): New.
(Dump::do_functionparam): New.
(Dump::do_pathpattern): New.
(Dump::do_structexprstruct): New.
(Dump::do_expr): New.
(Dump::do_pathexpr): New.
(Dump::do_typepathsegment): New.
(Dump::do_typepathfunction): New.
(Dump::do_qualifiedpathtype): New.
(Dump::do_operatorexpr): New.
(Dump::do_mappings): New.
(Dump::do_inner_attrs): New.
(Dump::do_outer_attrs): New.
(Dump::do_baseloopexpr): New.
(Dump::do_ifletexpr): New.
(Dump::do_struct): New.
(Dump::do_enumitem): New.
(Dump::do_traitfunctiondecl): New.
(Dump::do_externalitem): New.
(Dump::do_namefunctionparam): New.
(Dump::do_stmt): New.
(Dump::do_type): New.
(Dump::do_item): New.
(Dump::do_tuplefield): New.
(Dump::do_structfield): New.
(Dump::do_genericargs): New.
(Dump::do_maybenamedparam): New.
* hir/rust-hir-dump.h: Refactor.
* hir/tree/rust-hir-item.h (enum_to_str): New.
* hir/tree/rust-hir-type.h (enum_to_str): New.
* hir/tree/rust-hir.cc (enum_to_str): New.
* util/rust-common.h (enum_to_str): New.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Arthur Cohen [Fri, 23 Jun 2023 14:15:29 +0000 (16:15 +0200)]
gccrs: nr2.0: Add basic Rib class
This class adds a basic Rib class for the new name resolution algorithm.
It uses `optional` and `expected` return types in order to try and
improve error handling in these new passes.
gcc/rust/ChangeLog:
* Make-lang.in: Add `rust-rib.cc` object.
* resolve/rust-rib.cc: New file.
* resolve/rust-rib.h: New file.
Co-authored-by: Matthew Jasper <mjjasper1@gmail.com>
Owen Avery [Mon, 10 Jul 2023 19:56:31 +0000 (15:56 -0400)]
gccrs: Replace some more usages of Location with location_t
gcc/rust/ChangeLog:
* ast/rust-ast.h: Replace Location with location_t.
* ast/rust-expr.h: Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-macro.h: Likewise.
* ast/rust-path.h: Likewise.
* ast/rust-pattern.h: Likewise.
* ast/rust-stmt.h: Likewise.
* ast/rust-type.h: Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* hir/tree/rust-hir-item.h: Likewise.
* hir/tree/rust-hir-path.h: Likewise.
* hir/tree/rust-hir-pattern.h: Likewise.
* hir/tree/rust-hir-stmt.h: Likewise.
* hir/tree/rust-hir-type.h: Likewise.
* hir/tree/rust-hir.h: Likewise.
* lex/rust-token.h: Likewise.
* resolve/rust-ast-resolve-pattern.h: Likewise.
* typecheck/rust-hir-trait-reference.h: Likewise.
* typecheck/rust-tyty-bounds.h: Likewise.
* typecheck/rust-tyty-call.h: Likewise.
* typecheck/rust-tyty-subst.h: Likewise.
* typecheck/rust-tyty-util.h: Likewise.
* typecheck/rust-tyty.h: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Mon, 10 Jul 2023 19:42:49 +0000 (15:42 -0400)]
gccrs: Replace some usages of Location with location_t
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc: Replace Location with location_t.
* ast/rust-ast.cc: Likewise.
* ast/rust-ast.h: Likewise.
* ast/rust-expr.h: Likewise.
* ast/rust-item.h: Likewise.
* ast/rust-macro.h: Likewise.
* ast/rust-path.cc: Likewise.
* ast/rust-path.h: Likewise.
* ast/rust-pattern.h: Likewise.
* ast/rust-stmt.h: Likewise.
* ast/rust-type.h: Likewise.
* backend/rust-compile-base.cc: Likewise.
* backend/rust-compile-base.h: Likewise.
* backend/rust-compile-block.cc: Likewise.
* backend/rust-compile-expr.cc: Likewise.
* backend/rust-compile-expr.h: Likewise.
* backend/rust-compile-fnparam.cc: Likewise.
* backend/rust-compile-fnparam.h: Likewise.
* backend/rust-compile-intrinsic.cc: Likewise.
* backend/rust-compile-pattern.cc: Likewise.
* backend/rust-compile-resolve-path.h: Likewise.
* backend/rust-compile.cc: Likewise.
* checks/errors/rust-const-checker.cc: Likewise.
* checks/errors/rust-const-checker.h: Likewise.
* checks/errors/rust-unsafe-checker.cc: Likewise.
* checks/errors/rust-unsafe-checker.h: Likewise.
* expand/rust-macro-builtins.cc: Likewise.
* expand/rust-macro-expand.h: Likewise.
* hir/rust-ast-lower-base.h: Likewise.
* hir/rust-ast-lower-implitem.h: Likewise.
* hir/rust-ast-lower-item.cc: Likewise.
* hir/tree/rust-hir-expr.h: Likewise.
* hir/tree/rust-hir-item.h: Likewise.
* hir/tree/rust-hir-path.h: Likewise.
* hir/tree/rust-hir-pattern.h: Likewise.
* hir/tree/rust-hir-stmt.h: Likewise.
* hir/tree/rust-hir-type.h: Likewise.
* hir/tree/rust-hir.cc: Likewise.
* hir/tree/rust-hir.h: Likewise.
* lex/rust-token.h: Likewise.
* metadata/rust-extern-crate.cc: Likewise.
* metadata/rust-extern-crate.h: Likewise.
* parse/rust-parse-impl.h: Likewise.
* parse/rust-parse.h: Likewise.
* resolve/rust-ast-resolve-expr.cc: Likewise.
* resolve/rust-ast-resolve-implitem.h: Likewise.
* resolve/rust-ast-resolve-pattern.h: Likewise.
* resolve/rust-ast-resolve-stmt.h: Likewise.
* resolve/rust-ast-resolve-toplevel.h: Likewise.
* resolve/rust-ast-resolve-type.h: Likewise.
* resolve/rust-name-resolver.cc: Likewise.
* resolve/rust-name-resolver.h: Likewise.
* rust-diagnostics.cc: Likewise.
* rust-diagnostics.h: Likewise.
* rust-gcc.cc: Likewise.
* rust-session-manager.cc: Likewise.
* rust-session-manager.h: Likewise.
* typecheck/rust-casts.cc: Likewise.
* typecheck/rust-casts.h: Likewise.
* typecheck/rust-coercion.cc: Likewise.
* typecheck/rust-coercion.h: Likewise.
* typecheck/rust-hir-path-probe.cc: Likewise.
* typecheck/rust-hir-path-probe.h: Likewise.
* typecheck/rust-hir-trait-reference.cc: Likewise.
* typecheck/rust-hir-trait-reference.h: Likewise.
* typecheck/rust-hir-trait-resolve.cc: Likewise.
* typecheck/rust-hir-type-check-base.cc: Likewise.
* typecheck/rust-hir-type-check-base.h: Likewise.
* typecheck/rust-hir-type-check-item.cc: Likewise.
* typecheck/rust-hir-type-check-item.h: Likewise.
* typecheck/rust-hir-type-check-path.cc: Likewise.
* typecheck/rust-hir-type-check-pattern.cc: Likewise.
* typecheck/rust-hir-type-check-pattern.h: Likewise.
* typecheck/rust-hir-type-check-type.cc: Likewise.
* typecheck/rust-hir-type-check-type.h: Likewise.
* typecheck/rust-hir-type-check.cc: Likewise.
* typecheck/rust-hir-type-check.h: Likewise.
* typecheck/rust-substitution-mapper.cc: Likewise.
* typecheck/rust-substitution-mapper.h: Likewise.
* typecheck/rust-type-util.cc: Likewise.
* typecheck/rust-typecheck-context.cc: Likewise.
* typecheck/rust-tyty-bounds.cc: Likewise.
* typecheck/rust-tyty-call.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-tyty.cc: Likewise.
* typecheck/rust-tyty.h: Likewise.
* typecheck/rust-unify.cc: Likewise.
* typecheck/rust-unify.h: Likewise.
* util/rust-hir-map.cc: Likewise.
* util/rust-hir-map.h: Likewise.
* util/rust-identifier.h: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Fri, 14 Jul 2023 19:27:54 +0000 (15:27 -0400)]
gccrs: Move some Gcc_backend method definitions out of class declaration
gcc/rust/ChangeLog:
* rust-gcc.cc
(Gcc_backend::debug): Move out of class declaration.
(Gcc_backend::get_identifier_node): Likewise.
(Gcc_backend::wchar_type): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Muhammad Mahad [Mon, 17 Jul 2023 07:32:17 +0000 (12:32 +0500)]
gccrs: [E0423] expected function, tuple struct or tuple variant, found struct
Give error when an identifier was used like a function
name or a value was expected and the identifier exists
but it belongs to a different namespace.
gcc/rust/ChangeLog:
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit):
called error function.
gcc/testsuite/ChangeLog:
* rust/compile/found_struct.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Owen Avery [Wed, 12 Jul 2023 17:36:15 +0000 (13:36 -0400)]
gccrs: Remove Linemap::predeclared_location
gcc/rust/ChangeLog:
* rust-linemap.h (Linemap::predeclared_location): Remove.
* backend/rust-compile-type.cc:
Replace Linemap::predeclared_location with BUILTINS_LOCATION.
* resolve/rust-name-resolver.cc: Likewise.
* typecheck/rust-hir-type-check-type.cc: Likewise.
* typecheck/rust-tyty.cc: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Fri, 14 Jul 2023 19:32:19 +0000 (15:32 -0400)]
gccrs: Add include guard for rust-gcc.h
gcc/rust/ChangeLog:
* rust-gcc.h: Add include guard.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Arthur Cohen [Sun, 9 Jul 2023 11:44:52 +0000 (13:44 +0200)]
gccrs: rust-unreachable: Add specific behavior for rust_unreachable
As discussed during the community call, rust_unreachable() should
always trigger an internal compiler error and should not offer
the behavior of __builtin_unreachable when asserts are disabled, unlike
gcc_unreachable().
gcc/rust/ChangeLog:
* rust-system.h (rust_unreachable): Change definition to fancy_abort
* ast/rust-ast-collector.cc (TokenCollector::visit): Use rust_unreachable
instead of gcc_unreachable.
(get_delimiters): Likewise.
* ast/rust-ast-dump.h: Likewise.
* ast/rust-ast-formatting.cc (get_string_in_delims): Likewise.
(get_mode_dump_desc): Likewise.
* ast/rust-ast.cc (Visibility::as_string): Likewise.
(UseTreeGlob::as_string): Likewise.
* ast/rust-ast.h: Likewise.
* ast/rust-macro.h: Likewise.
* ast/rust-path.h: Likewise.
* backend/rust-compile-expr.cc (sort_tuple_patterns): Likewise.
(CompileExpr::visit): Likewise.
(CompileExpr::generate_closure_fntype): Likewise.
* backend/rust-compile-intrinsic.cc (op_with_overflow_inner): Likewise.
* backend/rust-compile-pattern.cc (CompilePatternBindings::visit): Likewise.
(CompilePatternLet::visit): Likewise.
* backend/rust-constexpr.cc (base_field_constructor_elt): Likewise.
(eval_array_reference): Likewise.
(label_matches): Likewise.
(eval_store_expression): Likewise.
(eval_call_expression): Likewise.
(build_data_member_initialization): Likewise.
(array_index_cmp): Likewise.
(get_array_or_vector_nelts): Likewise.
(eval_bit_field_ref): Likewise.
(eval_loop_expr): Likewise.
(potential_constant_expression_1): Likewise.
* backend/rust-mangle.cc (v0_simple_type_prefix): Likewise.
(v0_type_prefix): Likewise.
(v0_mangle_item): Likewise.
(Mangler::mangle_item): Likewise.
* backend/rust-tree.cc (convert_to_void): Likewise.
(type_memfn_quals): Likewise.
(rs_tree_equal): Likewise.
(fold_offsetof): Likewise.
(fold_builtin_source_location): Likewise.
(lvalue_error): Likewise.
* backend/rust-tree.h (struct named_decl_hash): Likewise.
(struct named_label_hash): Likewise.
* checks/errors/privacy/rust-visibility-resolver.cc
(VisibilityResolver::resolve_visibility): Likewise.
(VisibilityResolver::visit): Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::ctx_to_str): Likewise.
* checks/errors/rust-feature.cc (Feature::create): Likewise.
* expand/rust-expand-visitor.cc (get_traits_to_derive): Likewise.
(derive_item): Likewise.
(expand_item_attribute): Likewise.
(expand_stmt_attribute): Likewise.
* expand/rust-macro-expand.cc (MacroExpander::match_matcher): Likewise.
(MacroExpander::match_repetition): Likewise.
(transcribe_context): Likewise.
(MacroExpander::import_proc_macros): Likewise.
(MacroExpander::parse_proc_macro_output): Likewise.
* expand/rust-macro-expand.h: Likewise.
* expand/rust-macro-invoc-lexer.h: Likewise.
* expand/rust-macro-substitute-ctx.cc (SubstituteCtx::substitute_token): Likewise.
* expand/rust-proc-macro-invoc-lexer.h: Likewise.
* expand/rust-proc-macro.cc (load_macros): Likewise.
* hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_generic_args): Likewise.
(ASTLoweringBase::lower_literal): Likewise.
* hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise.
* hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::visit): Likewise.
* hir/rust-ast-lower-type.cc (ASTLoweringType::visit): Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* hir/tree/rust-hir.cc (get_string_in_delims): Likewise.
(Visibility::as_string): Likewise.
(UseTreeGlob::as_string): Likewise.
(CompoundAssignmentExpr::as_string): Likewise.
(ArithmeticOrLogicalExpr::as_string): Likewise.
* lex/rust-lex.cc (Lexer::parse_byte_string): Likewise.
(Lexer::parse_string): Likewise.
* lex/rust-token.cc (RS_TOKEN): Likewise.
* parse/rust-parse-impl.h (Parser::parse_simple_path_segment): Likewise.
(Parser::parse_path_ident_segment): Likewise.
(Parser::parse_attr_input): Likewise.
(Parser::parse_inherent_impl_item): Likewise.
(Parser::parse_trait_impl_item): Likewise.
(Parser::parse_type_path_segment): Likewise.
(Parser::parse_reference_type): Likewise.
(get_lbp_for_comparison_expr): Likewise.
* parse/rust-parse.cc (peculiar_fragment_match_compatible): Likewise.
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise.
* resolve/rust-ast-resolve-pattern.cc (PatternDeclaration::visit): Likewise.
* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise.
(ResolveTypeToCanonicalPath::visit): Likewise.
(ResolveGenericArgs::resolve_disambiguated_generic): Likewise.
* rust-gcc.cc (operator_to_tree_code): Likewise.
(fetch_overflow_builtins): Likewise.
(Gcc_backend::non_zero_size_type): Likewise.
(Gcc_backend::convert_tree): Likewise.
* rust-lang.cc (grs_langhook_type_for_mode): Likewise.
(grs_langhook_global_bindings_p): Likewise.
(grs_langhook_pushdecl): Likewise.
(grs_langhook_getdecls): Likewise.
(convert): Likewise.
* typecheck/rust-autoderef.h: Likewise.
* typecheck/rust-hir-path-probe.cc: Likewise.
* typecheck/rust-hir-trait-reference.cc (TraitItemReference::get_tyty): Likewise.
* typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): Likewise.
* typecheck/rust-hir-type-check-expr.cc: Likewise.
* typecheck/rust-hir-type-check-expr.h: Likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Likewise.
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.h: Likewise.
* typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise.
* typecheck/rust-substitution-mapper.h: Likewise.
* typecheck/rust-typecheck-context.cc (TypeCheckContextItem::get_context_type): Likewise.
* typecheck/rust-tyty-call.h: Likewise.
* typecheck/rust-tyty.cc (TypeKindFormat::to_string): Likewise.
(BaseType::monomorphized_clone): Likewise.
(VariantDef::variant_type_string): Likewise.
(ClosureType::handle_substitions): Likewise.
(IntType::as_string): Likewise.
(UintType::as_string): Likewise.
(FloatType::as_string): Likewise.
* typecheck/rust-unify.cc (UnifyRules::expect_projection): Likewise.
* util/rust-token-converter.cc (convert): Likewise.
(from_literal): Likewise.
(from_group): Likewise.
(from_tokentree): Likewise.
Muhammad Mahad [Tue, 11 Jul 2023 09:50:39 +0000 (14:50 +0500)]
gccrs: [E0658] Use of unstable feature
gcc/rust/ChangeLog:
* checks/errors/rust-feature-gate.cc (FeatureGate::gate):
called error function.
gcc/testsuite/ChangeLog:
* rust/compile/changed_intrinsics.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Muhammad Mahad [Tue, 11 Jul 2023 09:27:53 +0000 (14:27 +0500)]
gccrs: [E0093] Declaration of unknown intrinsic function
Refactored error message similiar to rustc.
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (Intrinsics::compile):
called error function.
gcc/testsuite/ChangeLog:
* rust/compile/torture/intrinsics-3.rs: Updated comment to pass the test case.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Muhammad Mahad [Thu, 13 Jul 2023 08:57:37 +0000 (13:57 +0500)]
gccrs: [E0133] Use of unsafe code outside of unsafe function or block
gcc/rust/ChangeLog:
* checks/errors/rust-unsafe-checker.cc (check_unsafe_call):
called error function.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Owen Avery [Mon, 10 Jul 2023 18:05:09 +0000 (14:05 -0400)]
gccrs: Remove RichLocation typedef
gcc/rust/ChangeLog:
* rust-location.h
(typedef RichLocation): Remove.
* expand/rust-macro-expand.cc: Replace RichLocation with rich_location.
* hir/rust-ast-lower-base.cc: Likewise.
* resolve/rust-ast-resolve-implitem.h: Likewise.
* resolve/rust-ast-resolve-stmt.h: Likewise.
* resolve/rust-ast-resolve-toplevel.h: Likewise.
* rust-diagnostics.cc: Likewise.
* rust-diagnostics.h: Likewise.
* rust-session-manager.cc: Likewise.
* typecheck/rust-casts.cc: Likewise.
* typecheck/rust-coercion.cc: Likewise.
* typecheck/rust-hir-inherent-impl-overlap.h: Likewise.
* typecheck/rust-hir-path-probe.h: Likewise.
* typecheck/rust-hir-trait-reference.cc: Likewise.
* typecheck/rust-hir-type-check-expr.cc: Likewise.
* typecheck/rust-hir-type-check-implitem.cc: Likewise.
* typecheck/rust-hir-type-check-item.cc: Likewise.
* typecheck/rust-hir-type-check-pattern.cc: Likewise.
* typecheck/rust-tyty-cmp.h: Likewise.
* typecheck/rust-tyty-subst.cc: Likewise.
* typecheck/rust-tyty.cc: Likewise.
* typecheck/rust-unify.cc: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Mon, 10 Jul 2023 00:46:03 +0000 (20:46 -0400)]
gccrs: Remove Linemap::start_line
gcc/rust/ChangeLog:
* lex/rust-lex.cc
(Lexer::start_line): Use linemap_line_start.
* rust-linemap.cc
(Linemap::start_line): Remove.
* rust-linemap.h
(Linemap::start_line): Remove.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Mon, 10 Jul 2023 15:42:12 +0000 (11:42 -0400)]
gccrs: Change class RichLocation into typedef
gcc/rust/ChangeLog:
* rust-linemap.cc
(RichLocation::RichLocation): Remove.
(RichLocation::~RichLocation): Remove.
(RichLocation::add_range): Remove.
(RichLocation::add_fixit_insert_before): Remove.
(RichLocation::add_fixit_insert_after): Remove.
* rust-location.h
(class RichLocation): Remove.
* rust-diagnostics.cc
(rust_be_error_at): Remove RichLocation::get invocation.
* expand/rust-macro-expand.cc: Fix RichLocation constructor.
* hir/rust-ast-lower-base.cc: Likewise.
* resolve/rust-ast-resolve-implitem.h: Likewise.
* resolve/rust-ast-resolve-stmt.h: Likewise.
* resolve/rust-ast-resolve-toplevel.h: Likewise.
* rust-session-manager.cc: Likewise.
* typecheck/rust-casts.cc: Likewise.
* typecheck/rust-coercion.cc: Likewise.
* typecheck/rust-hir-inherent-impl-overlap.h: Likewise.
* typecheck/rust-hir-path-probe.h: Likewise.
* typecheck/rust-hir-trait-reference.cc: Likewise.
* typecheck/rust-hir-type-check-expr.cc: Likewise.
* typecheck/rust-hir-type-check-implitem.cc: Likewise.
* typecheck/rust-hir-type-check-item.cc: Likewise.
* typecheck/rust-hir-type-check-pattern.cc: Likewise.
* typecheck/rust-tyty-cmp.h: Likewise.
* typecheck/rust-tyty-subst.cc: Likewise.
* typecheck/rust-tyty.cc: Likewise.
* typecheck/rust-unify.cc: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Sun, 9 Jul 2023 03:51:51 +0000 (23:51 -0400)]
gccrs: Remove Linemap::get_location
gcc/rust/ChangeLog:
* lex/rust-lex.cc
(Lexer::get_current_location): Use linemap_position_for_column.
* rust-session-manager.cc
(Session::handle_crate_name): Likewise.
* rust-linemap.cc
(Linemap::get_location): Remove.
* rust-linemap.h
(Linemap::get_location): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Pierre-Emmanuel Patry [Mon, 10 Jul 2023 11:47:37 +0000 (13:47 +0200)]
gccrs: dump: Output escaped character values
Output escaped character values instead of their raw values in string.
gcc/rust/ChangeLog:
* lex/rust-token.cc (escape_special_chars): Add a function that
escape a given string.
(Token::as_string): Add call to escape function for string/char
representations.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Marc Poulhiès [Wed, 12 Jul 2023 07:48:31 +0000 (09:48 +0200)]
gccrs: minor HIR cleanup
Remove more rust_assert in accessors.
gcc/rust/ChangeLog:
* hir/tree/rust-hir-type.h (MaybeNamedParam::get_type): Remove
rust_assert.
(BareFunctionType::get_return_type): Likewise.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Pierre-Emmanuel Patry [Tue, 11 Jul 2023 15:49:31 +0000 (17:49 +0200)]
gccrs: remove braces around scalar initializers
Remove useless braces around scalar initializers. This will also remove
some warning emitted by the compiler and avoid cluttering it's output.
gcc/rust/ChangeLog:
* backend/rust-compile-intrinsic.cc (offset_handler): Remove
braces.
(sizeof_handler): Likewise.
(transmute_handler): Likewise.
(rotate_handler): Likewise.
(wrapping_op_handler_inner): Likewise.
(op_with_overflow_inner): Likewise.
(atomic_load_handler_inner): Likewise.
(unchecked_op_inner): Likewise.
(uninit_handler): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 11 Jul 2023 15:45:03 +0000 (17:45 +0200)]
gccrs: Add missing virtual destructor to interfaces
Those interfaces missed a virtual destructor. This lead to several
warning.
gcc/rust/ChangeLog:
* ast/rust-ast.h: Add virtual destructor.
* expand/rust-macro-expand.h: Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 11 Jul 2023 14:46:25 +0000 (16:46 +0200)]
gccrs: Change specifier of some forward declaration
Change storage specifier of some forward declaration to satisfy compiler
warning.
gcc/rust/ChangeLog:
* hir/tree/rust-hir-full-decls.h (struct Crate): Change to
class.
(class Crate): Likewise.
(struct StructField): Likewise.
(class StructField): Likewise.
(struct TupleField): Likewise.
(class TupleField): Likewise.
(struct TraitFunctionDecl): Likewise.
(class TraitFunctionDecl): Likewise.
* rust-session-manager.h (struct Crate): Likewise.
(class Crate): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Owen Avery [Mon, 10 Jul 2023 18:43:18 +0000 (14:43 -0400)]
gccrs: Remove unnecessary usage of Location copy constructor
gcc/rust/ChangeLog:
* ast/rust-expr.h
(MetaItemPathLit::get_locus): Remove copy construction.
* backend/rust-constexpr.cc
(eval_constant_expression): Likewise.
(is_valid_constexpr_fn): Likewise.
* util/rust-token-converter.cc
(convert): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Sun, 9 Jul 2023 03:20:01 +0000 (23:20 -0400)]
gccrs: Merge Linemap::to_string into Linemap::location_to_string
gcc/rust/ChangeLog:
* lex/rust-lex.cc
(Lexer::dump_and_skip): Use location_to_string.
* rust-linemap.cc
(Linemap::to_string): Move to...
(Linemap::location_to_string): ... here.
* rust-linemap.h
(Linemap::to_string): Remove.
(Linemap::location_to_string): Remove definition.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Marc Poulhiès [Mon, 10 Jul 2023 18:24:56 +0000 (20:24 +0200)]
gccrs: minor HIR cleanup
Add one more accessor and remove some rust_assert() in accessors for unique_ptr&.
gcc/rust/ChangeLog:
* hir/tree/rust-hir-expr.h (TypeCastExpr::get_casted_expr): Remove
assert in accessor.
(TypeCastExpr::get_type_to_convert_to): Likewise.
(CompoundAssignmentExpr::get_left_expr): Likewise.
(CompoundAssignmentExpr::get_right_expr): Likewise.
(GroupedExpr::get_expr_in_parens): Likewise.
(TupleIndexExpr::get_tuple_expr): Likewise.
(FieldAccessExpr::get_receiver_expr): Likewise.
(ClosureParam::get_pattern): Likewise.
(ClosureParam::get_type): Likewise.
(ExprType::get_return_type): Likewise.
(IfLetExpr::get_scrutinee_expr): Likewise.
(MatchArm::get_guard_expr): Likewise.
(MatchExpr::get_scrutinee_expr): Likewise.
* hir/tree/rust-hir-item.h (TypeParam::get_type): Likewise.
(SelfParam::get_type): Likewise.
(Function::get_return_type): Likewise.
(TypeAlias::get_type_aliased): Likewise.
(StructField::get_field_type): Likewise.
(TraitFunctionDecl::get_block_expr): Likewise.
(ImplBlock::get_trait_ref): Likewise.
* hir/tree/rust-hir-path.h (ConstGenericArg::get_expression): New.
(TypePathFunction::get_return_type): Remove assert in accessor.
(QualifiedPathType::get_trait): Likewise.
* hir/tree/rust-hir-pattern.h (PatternType::get_lower_bound): Likewise.
(PatternType::get_upper_bound): Likewise.
(ReferencePattern::get_referenced_pattern): Likewise.
* hir/tree/rust-hir.h (ConstGenericParam::get_default_expression): Likewise.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>