]>
git.ipfire.org Git - thirdparty/gcc.git/log
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>
Muhammad Mahad [Mon, 10 Jul 2023 12:26:45 +0000 (17:26 +0500)]
gccrs: [E0124] field x is already declared in struct
Refactored error message for more
than one duplicate fields.
gcc/rust/ChangeLog:
* hir/rust-ast-lower-base.cc (struct_field_name_exists):
called error function.
gcc/testsuite/ChangeLog:
* rust/compile/bad_pub_enumitems.rs: changed comment to pass test cases.
* rust/compile/dup_fields.rs: likewise.
* rust/execute/same_field_name.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Owen Avery [Mon, 10 Jul 2023 03:23:14 +0000 (23:23 -0400)]
gccrs: Add rust_error_at accepting location_t and ErrorCode
gcc/rust/ChangeLog:
* rust-diagnostics.cc
(rust_be_error_at): Add function accepting location_t and ErrorCode.
(rust_error_at): Likewise.
* rust-diagnostics.h
(rust_error_at): Likewise.
(rust_be_error_at): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Sun, 9 Jul 2023 02:28:30 +0000 (22:28 -0400)]
gccrs: Merge Gcc_linemap into Linemap
gcc/rust/ChangeLog:
* rust-linemap.cc
(class Gcc_linemap): Remove.
(Gcc_linemap::start_file): Move to...
(Linemap::start_file): ... here.
(Gcc_linemap::to_string): Move to...
(Linemap::to_string): ... here.
(Gcc_linemap::stop): Move to...
(Linemap::stop): ... here.
(Gcc_linemap::start_line): Move to...
(Linemap::start_line): ... here.
(Gcc_linemap::get_location): Move to...
(Linemap::get_location): ... here.
(rust_get_linemap): Use Linemap.
* rust-linemap.h
(Linemap::in_file_): New field from Gcc_linemap.
(Linemap::Linemap): Initialize in_file_.
(Linemap::~Linemap): Make non-virtual.
(Linemap::start_file): Likewise.
(Linemap::start_line): Likewise.
(Linemap::get_location): Likewise.
(Linemap::stop): Likewise.
(Linemap::to_string): Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Arthur Cohen [Mon, 26 Jun 2023 12:47:06 +0000 (14:47 +0200)]
gccrs: Remove Rust::Optional in favor of tl::optional
gcc/rust/ChangeLog:
* Make-lang.in: Remove rust-optional-test.cc's object file
* ast/rust-macro.h: Remove use of Rust::Optional
* backend/rust-compile-base.cc
(HIRCompileBase::resolve_method_address): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::check_for_privacy_violation): Likewise.
(PrivacyReporter::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.h: Likewise.
* checks/errors/rust-feature-gate.cc (FeatureGate::check): Likewise.
* checks/errors/rust-feature.cc (Feature::create): Likewise.
(Feature::as_name): Likewise.
* checks/errors/rust-feature.h: Likewise.
* expand/rust-macro-builtins.cc: Likewise.
* lex/rust-lex.cc (Lexer::Lexer): Likewise.
(Lexer::skip_token): Likewise.
(Lexer::dump_and_skip): Likewise.
* lex/rust-lex.h: Likewise.
* resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise.
* resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise.
* rust-lang.cc (run_rust_tests): Likewise.
* rust-session-manager.cc (Session::compile_crate): Likewise.
(TargetOptions::dump_target_options): Likewise.
* rust-session-manager.h (struct TargetOptions): Likewise.
* util/rust-hir-map.cc (Mappings::lookup_module_children): Likewise.
(Mappings::lookup_module_chidren_items): Likewise.
(Mappings::lookup_module_child): Likewise.
(Mappings::lookup_parent_module): Likewise.
* util/rust-hir-map.h (RUST_HIR_MAP_H): Likewise.
* util/rust-optional-test.cc: Removed.
* util/rust-optional.h: Removed.
Owen Avery [Mon, 3 Jul 2023 17:48:45 +0000 (13:48 -0400)]
gccrs: Replace Linemap::unknown_location with UNKNOWN_LOCATION
gcc/rust/ChangeLog:
* rust-linemap.h (Linemap::unknown_location): Remove.
* ast/rust-ast.cc:
Replace Linemap::unknown_location with UNKNOWN_LOCATION.
* ast/rust-path.cc: Likewise.
* hir/tree/rust-hir.cc: Likewise.
* metadata/rust-imports.cc: Likewise.
* parse/rust-parse-impl.h: Likewise.
* parse/rust-parse.h: Likewise.
* rust-backend.h: Likewise.
* rust-diagnostics.cc: Likewise.
* rust-session-manager.cc: Likewise.
* typecheck/rust-tyty.cc: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Muhammad Mahad [Fri, 7 Jul 2023 10:10:46 +0000 (15:10 +0500)]
gccrs: [E0070] invalid left-hand side of assignment
gcc/rust/ChangeLog:
* resolve/rust-ast-verify-assignee.h: called error function.
gcc/testsuite/ChangeLog:
* rust/compile/wrong_lhs_assignment.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Muhammad Mahad [Thu, 6 Jul 2023 12:08:56 +0000 (17:08 +0500)]
gccrs: [E0061] Refactored argument mismatch error function
Added Invalid number of arguments (argument mismatch)
was passed when calling a function - unexpected
number of arguments `x` expected `y` And Refactored
error into one function.
gcc/rust/ChangeLog:
* typecheck/rust-tyty-call.cc (emit_unexpected_argument_error):
Refactored invalid number of argument into one function.
(TypeCheckCallExpr::visit): called refactored function.
(TypeCheckMethodCallExpr::check): likewise.
gcc/testsuite/ChangeLog:
* rust/compile/func2.rs: updated comment to pass new test cases.
* rust/compile/tuple_struct2.rs: likewise.
* rust/compile/wrong_no_of_parameters.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Arthur Cohen [Tue, 27 Jun 2023 13:56:04 +0000 (15:56 +0200)]
gccrs: nr2.0: Add complex testcases
gcc/testsuite/ChangeLog:
* rust/compile/name_resolution1.rs: New test.
* rust/compile/name_resolution2.rs: New test.
* rust/compile/name_resolution3.rs: New test.
* rust/compile/name_resolution4.rs: New test.
* rust/compile/name_resolution5.rs: New test.
Co-authored-by: GuillaumeGomez <guillaume1.gomez@gmail.com>
Arthur Cohen [Wed, 28 Jun 2023 14:21:05 +0000 (16:21 +0200)]
gccrs: expected: Adapt type to GCC's requirements.
Disable exceptions and remove inclusion of poisoned headers.
gcc/rust/ChangeLog:
* util/expected.h: Adapt class to GCC requirements.
Arthur Cohen [Fri, 23 Jun 2023 14:37:21 +0000 (16:37 +0200)]
gccrs: util: Add tl::expected type
Directly taken from https://github.com/TartanLlama/expected.
gcc/rust/ChangeLog:
* util/expected.h: New file.
Arthur Cohen [Wed, 28 Jun 2023 10:59:34 +0000 (12:59 +0200)]
gccrs: optional: Adapt class to GCC's standards.
This commit removes the poisoned includes as well as the exception throwing
mechanism of the original class.
gcc/rust/ChangeLog:
* util/optional.h: Adapt for GCC.
Arthur Cohen [Fri, 23 Jun 2023 14:37:16 +0000 (16:37 +0200)]
gccrs: optional: Import tl's optional type
This is directly adapted from https://github.com/TartanLlama/optional.
This class is tested for C++11 and on GCC 4.8, which is our target mimimum
GCC version.
This optional class provides multiple advantages over our existing
implementation of Optional<T>:
- Easier API (no static constructors)
- Better method chaining (and_then, map...)
- Harsher semantics (no assign-through on Optional<T&>)
Over the std::optional type present in C++'s standard library, this type offers:
- Optional references without going through std::reference_wrapper
- Better method chaining
For these reasons, I am in favor of importing it directly rather than
adapt C++14's std::optional type to work with C++11 and GCC 4.8.
gcc/rust/ChangeLog:
* util/optional.h: New file.
Owen Avery [Mon, 3 Jul 2023 15:54:19 +0000 (11:54 -0400)]
gccrs: Replace value initialization of Location with UNDEF_LOCATION
gcc/rust/ChangeLog:
* rust-location.h (UNDEF_LOCATION): New.
* ast/rust-ast-collector.cc: Replace Location () with UNDEF_LOCATION.
* ast/rust-ast-fragment.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.h: Likewise.
* ast/rust-type.h: Likewise.
* backend/rust-compile-expr.cc: 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.cc: Likewise.
* backend/rust-constexpr.cc: Likewise.
* expand/rust-expand-visitor.cc: Likewise.
* expand/rust-macro-expand.cc: Likewise.
* expand/rust-macro-expand.h: Likewise.
* expand/rust-macro-invoc-lexer.cc: Likewise.
* expand/rust-proc-macro-invoc-lexer.cc: Likewise.
* expand/rust-proc-macro.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-type.h: Likewise.
* hir/tree/rust-hir.h: Likewise.
* lex/rust-lex.cc: Likewise.
* metadata/rust-export-metadata.cc: Likewise.
* parse/rust-parse-impl.h: Likewise.
* resolve/rust-ast-resolve-item.cc: Likewise.
* resolve/rust-ast-resolve.cc: Likewise.
* rust-diagnostics.h: Likewise.
* rust-session-manager.cc: Likewise.
* typecheck/rust-autoderef.cc: Likewise.
* typecheck/rust-coercion.cc: Likewise.
* typecheck/rust-hir-dot-operator.cc: Likewise.
* typecheck/rust-hir-path-probe.cc: Likewise.
* typecheck/rust-hir-trait-reference.cc: Likewise.
* typecheck/rust-hir-trait-reference.h: Likewise.
* typecheck/rust-hir-type-check-expr.cc: Likewise.
* typecheck/rust-hir-type-check-implitem.cc: Likewise.
* typecheck/rust-hir-type-check-type.cc: Likewise.
* typecheck/rust-hir-type-check.cc: Likewise.
* typecheck/rust-tyty-bounds.cc: Likewise.
* typecheck/rust-tyty-subst.cc: Likewise.
* typecheck/rust-tyty.cc: Likewise.
* util/rust-hir-map.cc: Likewise.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 14:16:08 +0000 (16:16 +0200)]
gccrs: collector: Fix abi output
Abi did output as several tokens instead of a fixed string.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Fix abit
output format.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 13:54:12 +0000 (15:54 +0200)]
gccrs: collector: Fix remaining trait & extern issues
Fix remaining failing tests with trait and extern. Outer attributes were
missing and the semicolon did output on macro invocations.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Fix
external item trailing semicolon and outer attributes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 13:37:15 +0000 (15:37 +0200)]
gccrs: collector: Output extern function attributes
Outer attributes on external functions did not output correctly.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Output
outer attributes on external functions.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 13:32:23 +0000 (15:32 +0200)]
gccrs: collector: Fix method qualifier output
Method qualifiers did not output correctly (no unsafe in the output).
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Fix method
qualifier output.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 13:25:06 +0000 (15:25 +0200)]
gccrs: collector: Add where clause to trait impl block
Trait impl block were missing a where clause for their output.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Add where
clause.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 13:19:51 +0000 (15:19 +0200)]
gccrs: collector: Output outer attributes on blockexpr
Outer attributes on block expr did not output properly.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Add outer
attributes to collector output.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 13:12:11 +0000 (15:12 +0200)]
gccrs: collector: Add variadics to collector output
Variadics were missing from collector output for external functions.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Add
variadics in collector output.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 12:52:31 +0000 (14:52 +0200)]
gccrs: collector: Add generics to external functions
Add generic to external functiond declaration collector output.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Add
generics.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 12:42:18 +0000 (14:42 +0200)]
gccrs: collector: Fix missing trait generics
Generics on the target structure did not correctly output.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Fix generic
output.
gcc/testsuite/ChangeLog:
* rust/link/trait_import_0.rs: Mark test as xfail.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 12:33:36 +0000 (14:33 +0200)]
gccrs: collector: Reformat trait impl
Trait impl were not readable, hence the reformat.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Reformat
trait impl block.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 12:23:56 +0000 (14:23 +0200)]
gccrs: collector: Add generic to inherent impl block
Generic in inherent impl block were did not output at all.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Output
generic in inherent impl.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 11:58:54 +0000 (13:58 +0200)]
gccrs: dump: Fix dollar spacing rule
Space should be removed after the dollar sign, not before.
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::require_spacing): Change dollar
spacing rule.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 11:12:07 +0000 (13:12 +0200)]
gccrs: collector: Change match arm format
Match arm were not readable with previous format options.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Change
formatting.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 11:10:57 +0000 (13:10 +0200)]
gccrs: collector: Fix trait impl block
Trait impl block did not output any generic declaration nor the trait
excalamation mark.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Fix trait
impl block output.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 10:43:49 +0000 (12:43 +0200)]
gccrs: collector: Fix doubled generics
Generics were output two times and binding args were missing in
TypePathSegmentGeneric collection.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Fix binding
args.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 09:44:04 +0000 (11:44 +0200)]
gccrs: collector: Fix output for function qualifiers
Function qualifiers did not output properly.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Output
function qualifiers after visibility.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 09:30:57 +0000 (11:30 +0200)]
gccrs: collector: Fix method self parameter
Fix visitor for self parameter in methods.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Fix self
param output.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 09:13:15 +0000 (11:13 +0200)]
gccrs: dump: Fix spacing with dots and references
A space was output around dots as well as after references, this made
things kinda horrible to look at and clearly not usual.
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::require_spacing): Add a rule to
remove spaces around dots and after references.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Tue, 27 Jun 2023 14:55:18 +0000 (16:55 +0200)]
gccrs: collector: Fix some token collector
Some ast subtrees where not correctly collected. Among those where macro
match repetition introducing empty tokens.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Fix several
token collection rules.
* ast/rust-ast-dump.cc (Dump::require_spacing): Add spacing rule
for comma.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Owen Avery [Fri, 30 Jun 2023 01:23:03 +0000 (21:23 -0400)]
gccrs: Create MacroInvocLexerBase
gcc/rust/ChangeLog:
* expand/rust-macro-invoc-lexer.h
(class MacroInvocLexerBase): New.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Owen Avery [Mon, 3 Jul 2023 17:33:16 +0000 (13:33 -0400)]
gccrs: Reduce Linemap/Gcc_linemap abstraction further
gcc/rust/ChangeLog:
* expand/rust-macro-builtins.cc
(source_relative_path): Use LOCATION_FILE.
(MacroBuiltin::file_handler): Likewise.
(MacroBuiltin::column_handler): Use LOCATION_COLUMN.
(MacroBuiltin::line_handler): Use LOCATION_LINE.
* rust-linemap.cc
(Gcc_linemap::location_file): Remove.
(Gcc_linemap::location_line): Remove.
(Gcc_linemap::location_column): Remove.
* rust-linemap.h
(Linemap::location_file): Remove.
(Linemap::location_line): Remove.
(Linemap::location_column): Remove.
(Linemap::location_to_file): Remove.
(Linemap::location_to_line): Remove.
(Linemap::location_to_column): Remove.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Muhammad Mahad [Thu, 6 Jul 2023 12:37:46 +0000 (17:37 +0500)]
gccrs: [E0425] Use of unresolved name
Refactored error message similiar to
rustc.
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-expr.cc (ResolveExpr::visit):
called error function and changed error message
similiar to rustc.
gcc/testsuite/ChangeLog:
* rust/compile/break-rust2.rs: Updated comment to pass testcase.
* rust/compile/const_generics_3.rs: likewise.
* rust/compile/const_generics_4.rs: likewise.
* rust/compile/not_find_value_in_scope.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Owen Avery [Mon, 3 Jul 2023 16:44:54 +0000 (12:44 -0400)]
gccrs: Reduce Linemap/Gcc_linemap abstraction
This should help work towards the removal of Linemap/Gcc_linemap.
gcc/rust/ChangeLog:
* rust-linemap.cc
(Gcc_linemap::get_unknown_location): Remove.
(Gcc_linemap::get_predeclared_location): Remove.
(Gcc_linemap::is_predeclared): Remove.
(Gcc_linemap::is_unknown): Remove.
* rust-linemap.h
(Linemap::get_predeclared_location): Remove.
(Linemap::get_unknown_location): Remove.
(Linemap::is_predeclared): Remove.
(Linemap::is_unknown): Remove.
(Linemap::predeclared_location): Use BUILTINS_LOCATION.
(Linemap::unknown_location): Use UNKNOWN_LOCATION.
(Linemap::is_predeclared_location): Remove.
(Linemap::is_unknown_location): Remove.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Muhammad Mahad [Wed, 5 Jul 2023 08:44:17 +0000 (13:44 +0500)]
gccrs: [E0053] method 'x' has an incompatible type for trait 'y'
The parameters of any trait method must match between
a trait implementation and the trait definition
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItemWithTrait::visit):
called error function
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Muhammad Mahad [Thu, 6 Jul 2023 13:26:26 +0000 (18:26 +0500)]
gccrs: [E0063] constructor is missing fields
Added error code for Missing Field in
struct or struct-like enum variant.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve):
called error function.
gcc/testsuite/ChangeLog:
* rust/compile/missing_constructor_fields.rs: New test.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Raiki Tamura [Tue, 4 Jul 2023 09:21:48 +0000 (18:21 +0900)]
gccrs: add utf-8 validation for input source
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::input_source_is_valid_utf8): New method of `Lexer`.
* lex/rust-lex.h: Likewise.
* rust-session-manager.cc (Session::compile_crate): Add error.
gcc/testsuite/ChangeLog:
* rust/compile/broken_utf8.rs: New test.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Owen Avery [Tue, 13 Jun 2023 04:25:03 +0000 (00:25 -0400)]
gccrs: Ignore semicolon following a macro expansion in expression context
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc
(transcribe_expression): Skip trailing semicolon.
gcc/testsuite/ChangeLog:
* rust/compile/macro-issue2273.rs: New test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Muhammad Mahad [Tue, 4 Jul 2023 11:48:20 +0000 (16:48 +0500)]
gccrs: gccrs:[E0046] Missing Items in Trait Implementation
missing foo in implementation of trait 'Foo'
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-item.cc: called error function.
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Raiki Tamura [Mon, 3 Jul 2023 07:34:59 +0000 (16:34 +0900)]
gccrs: Add location info to `Rust::Identifier`
gcc/rust/ChangeLog:
* ast/rust-ast.h: Modify constructors of `Rust::Identifier`
* ast/rust-pattern.h: Likewise.
* hir/tree/rust-hir-item.h: Likewise.
* parse/rust-parse-impl.h (Parser::parse_macro_rules_def): Likewise.
(Parser::parse_decl_macro_def): Likewise.
(Parser::parse_macro_match_fragment): Likewise.
(Parser::parse_module): Likewise.
(Parser::parse_use_tree): Likewise.
(Parser::parse_function): Likewise.
(Parser::parse_type_param): Likewise.
(Parser::parse_type_alias): Likewise.
(Parser::parse_struct): Likewise.
(Parser::parse_struct_field): Likewise.
(Parser::parse_enum): Likewise.
(Parser::parse_enum_item): Likewise.
(Parser::parse_union): Likewise.
(Parser::parse_static_item): Likewise.
(Parser::parse_trait): Likewise.
(Parser::parse_trait_item): Likewise.
(Parser::parse_trait_type): Likewise.
(Parser::parse_trait_const): Likewise.
(Parser::parse_external_item): Likewise.
(Parser::parse_generic_args_binding): Likewise.
(Parser::parse_method): Likewise.
(Parser::parse_maybe_named_param): Likewise.
(Parser::parse_identifier_pattern): Likewise.
(Parser::parse_struct_expr_field): Likewise.
(ResolveItem::visit): Likewise.
* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit):Add comments
* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise.
* checks/lints/rust-lint-scan-deadcode.h: Fix error location
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Owen Avery [Sun, 2 Jul 2023 23:59:29 +0000 (19:59 -0400)]
gccrs: Change class Location into typedef
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc
(HIRCompileBase::address_expression): Remove gcc_location method call.
(HIRCompileBase::indirect_expression): Likewise.
(HIRCompileBase::compile_constant_item): Likewise.
(HIRCompileBase::named_constant_expression): Likewise.
* backend/rust-compile-expr.cc
(CompileExpr::visit): Remove gcc_location method call, use UNKNOWN_LOCATION to initialize.
(CompileExpr::get_fn_addr_from_dyn): Remove gcc_location method call.
(CompileExpr::type_cast_expression): Likewise.
* backend/rust-compile-intrinsic.cc
(transmute_handler): Replace "Location ().gcc_location ()" with UNKNOWN_LOCATION.
(copy_nonoverlapping_handler): Likewise.
(prefetch_data_handler): Likewise.
(atomic_store_handler_inner): Likewise.
(atomic_load_handler_inner): Likewise.
* resolve/rust-ast-resolve-expr.cc
(ResolveExpr::visit): Remove gcc_location method call.
* rust-diagnostics.cc
(rust_be_error_at): Likewise.
(rust_be_warning_at): Likewise.
(rust_be_fatal_error): Likewise.
(rust_be_inform): Likewise.
* rust-diagnostics.h
(rust_sorry_at): Likewise.
* rust-gcc.cc
(Bvariable::get_tree): Likewise.
(Gcc_backend::fill_in_fields): Likewise.
(Gcc_backend::named_type): Likewise.
(Gcc_backend::real_part_expression): Likewise.
(Gcc_backend::imag_part_expression): Likewise.
(Gcc_backend::complex_expression): Likewise.
(Gcc_backend::convert_expression): Likewise.
(Gcc_backend::struct_field_expression): Likewise.
(Gcc_backend::compound_expression): Likewise.
(Gcc_backend::conditional_expression): Likewise.
(Gcc_backend::negation_expression): Likewise.
(Gcc_backend::arithmetic_or_logical_expression): Likewise.
(Gcc_backend::arithmetic_or_logical_expression_checked): Likewise.
(Gcc_backend::comparison_expression): Likewise.
(Gcc_backend::lazy_boolean_expression): Likewise.
(Gcc_backend::constructor_expression): Likewise.
(Gcc_backend::array_constructor_expression): Likewise.
(Gcc_backend::array_initializer): Likewise.
(Gcc_backend::array_index_expression): Likewise.
(Gcc_backend::call_expression): Likewise.
(Gcc_backend::assignment_statement): Likewise.
(Gcc_backend::return_statement): Likewise.
(Gcc_backend::exception_handler_statement): Likewise.
(Gcc_backend::if_statement): Likewise.
(Gcc_backend::loop_expression): Likewise.
(Gcc_backend::exit_expression): Likewise.
(Gcc_backend::block): Likewise.
(Gcc_backend::convert_tree): Likewise.
(Gcc_backend::global_variable): Likewise.
(Gcc_backend::local_variable): Likewise.
(Gcc_backend::parameter_variable): Likewise.
(Gcc_backend::static_chain_variable): Likewise.
(Gcc_backend::temporary_variable): Likewise.
(Gcc_backend::label): Likewise.
(Gcc_backend::goto_statement): Likewise.
(Gcc_backend::label_address): Likewise.
(Gcc_backend::function): Likewise.
* rust-linemap.cc
(Gcc_linemap::to_string): Likewise.
(Gcc_linemap::location_file): Likewise.
(Gcc_linemap::location_line): Likewise.
(Gcc_linemap::location_column): Likewise.
(Gcc_linemap::is_predeclared): Likewise.
(Gcc_linemap::is_unknown): Likewise.
(RichLocation::RichLocation): Likewise.
(RichLocation::add_range): Likewise.
(RichLocation::add_fixit_insert_before): Likewise.
(RichLocation::add_fixit_insert_after): Likewise.
* rust-location.h
(class Location): Replace with typedef.
(operator<): Remove.
(operator==): Remove.
(operator+): Remove.
(operator-): Remove.
* typecheck/rust-hir-trait-resolve.cc
(AssociatedImplTrait::setup_associated_types): Initialize Location with UNKNOWN_LOCATION.
* typecheck/rust-hir-type-check-stmt.cc
(TypeCheckStmt::visit): Likewise.
* util/rust-token-converter.cc
(convert): Remove gcc_location method call.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Marc Poulhiès [Sun, 2 Jul 2023 21:33:02 +0000 (23:33 +0200)]
gccrs: HIR cleanup
Some more HIR cleanup.
gcc/rust/ChangeLog:
* hir/tree/rust-hir-expr.h (BorrowExpr::is_double_borrow): New.
(ArrayElemsCopied::get_elem_to_copy)
(ArrayElemsCopied::get_num_copies_expr): Return unique_ptr.
(CallExpr::get_fnexpr): Likewise.
(ReturnExpr::get_expr): Likewise.
(StructExprStructFields::get_struct_base): New.
(MethodCallExpr::has_params): New.
(ClosureExpr::has_params): New.
(BlockExpr::get_inner_attrs): New.
(WhileLoopExpr::get_patterns): New.
(ForLoopExpr::get_pattern): New.
(IfLetExpr::get_if_block): Return ref to unique_ptr.
(IfLetExprConseqElse::get_else_block): Likewise.
(MatchExpr::get_inner_attrs): New.
* hir/tree/rust-hir-item.h (Module::get_module_name): New.
(ExternCrate::get_referenced_crate)
(ExternCrate::get_as_clause_name): New.
(UseTreeGlob::get_glob_type, UseTreeGlob::get_path): New.
(UseTreeList::get_path_type, UseTreeList::get_path)
(UseTreeList::get_trees): New.
(TraitItemKind::get_expr): Remove assert. unique_ptr can
be "empty". Must be checked in caller.
* hir/tree/rust-hir-pattern.h (IdentifierPattern::get_is_ref)
(IdentifierPattern::get_to_bind): New.
(RangePatternBoundType::get_has_minus): New.
(RangePattern::get_has_ellipsis_syntax): New.
(StructPatternField::get_outer_attrs): New.
(StructPatternFieldTuplePat::get_index)
(StructPatternFieldTuplePat::get_tuple_pattern): New.
(StructPatternFieldIdent::get_has_ref): New.
* hir/tree/rust-hir-stmt.h (LetStmt::get_outer_attrs): New.
(LetStmt::get_type)
(LetStmt::get_init_expr, LetStmt::get_pattern): Return unique_ptr.
(ExprStmt::get_expr): Likewise.
* hir/tree/rust-hir-type.h (TraitBound::get_for_lifetimes): New.
(TraitBound::get_in_params): New.
(TraitBound::get_opening_question_mark): New.
(ImplTraitType::get_type_param_bounds): New.
(TraitObjectType::get_has_dyn): New.
(TraitBound::get_type_in_parens): New.
(ImplTraitTypeOneBound::get_trait_bound): New.
(BareFunctionType::get_for_lifetimes)
(BareFunctionType::get_is_variadic)
(BareFunctionType::get_function_qualifiers): New.
* hir/tree/rust-hir.h (class Expr): Virtual inherit from FullVisitable.
(class Pattern): Likewise.
(ConstGenericParam::get_name): New.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Adjust call.
(TypeCheckExpr::resolve_fn_trait_call): Likewise.
* backend/rust-compile-expr.cc (CompileExpr::visit): Adjust call.
(CompileExpr::array_copied_expr): Likewise.
(CompileExpr::generate_possible_fn_trait_call): Likewise.
* backend/rust-compile-stmt.cc (CompileStmt::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise.
* hir/rust-hir-dump.cc (Dump::visit): Likewise.
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Likewise.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Muhammad Mahad [Mon, 3 Jul 2023 12:22:15 +0000 (17:22 +0500)]
gccrs: [E0034] Ambiguous Method Call Error
Ambiguous Method Call Error - more than one method
has the same prototype
gcc/rust/ChangeLog:
* typecheck/rust-hir-path-probe.h: called error function
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Muhammad Mahad [Mon, 3 Jul 2023 16:08:33 +0000 (21:08 +0500)]
gccrs: [E0229] associated type bindings error
Associated type binding outside of type
parameter Declaration and where Clause
gcc/rust/ChangeLog:
* typecheck/rust-tyty-subst.cc (SubstitutionRef::get_mappings_from_generic_args):
called error function
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Marc Poulhiès [Wed, 28 Jun 2023 20:11:50 +0000 (22:11 +0200)]
gccrs: minor HIR interface cleanup
Minor changes in HIR interface: add missing getters, make some classes
inherit from FullVisitable.
gcc/rust/ChangeLog:
* hir/tree/rust-hir-expr.h (class ArrayElems): Inherit from FullVisitable.
(class StructExprField): Likewise.
* hir/tree/rust-hir-item.h (class WhereClauseItem): Likewise.
(class UseTree): Likewise.
(UseTreeRebind::get_path, UseTreeRebind::get_identifier)
(UseTreeRebind::get_bind_type): New.
(UseDeclaration::get_use_tree): New.
(struct TraitFunctionDecl): Change struct to ...
(class TraitFunctionDecl): ... class.
(TraitFunctionDecl::get_where_clause): New.
(StructField::get_outer_attrs): New.
(struct TupleField): Change struct to ...
(class TupleField): ... class.
(TupleField::get_visibility, TupleField::get_outer_attrs): New.
* hir/tree/rust-hir-pattern.h (class TupleStructItems): Inherit
from FullVisitable.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Raiki Tamura [Thu, 29 Jun 2023 06:02:21 +0000 (15:02 +0900)]
gccrs: Remove unnecessary methods of `Rust::Lexer`
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::build_token): Replace function call.
(Lexer::parse_string): Likewise.
(Lexer::parse_identifier_or_keyword): Likewise.
(Lexer::parse_raw_string): Likewise.
(Lexer::parse_char_or_lifetime): Likewise.
(Lexer::get_input_codepoint_length): Deleted.
(Lexer::peek_codepoint_input): Deleted.
(Lexer::skip_codepoint_input): Deleted.
* lex/rust-lex.h: Remove some methods and fields
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Philip Herron [Sun, 2 Jul 2023 19:24:43 +0000 (20:24 +0100)]
gccrs: Track fn_once output lang item properly
In order to setup the Output assoicated type we can rely on using generic
argument bindings. So for example when we have the FnOnce trait:
#[lang = "fn_once"]
pub trait FnOnce<Args> {
#[lang = "fn_once_output"]
type Output;
extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
}
Thn we might have a function such as:
pub fn map<R, F: FnOnce(T) -> R>(self, f: F) -> Option<R> { ... }
This trait bound predicate of FnOnce(T) -> R we setup generics for the
bound as:
FnOnce<(T), Output=R>
This means we can reuse our generic arguments handling to get this support.
Fixes #2105
gcc/rust/ChangeLog:
* typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): track output
* util/rust-hir-map.cc (Mappings::lookup_trait_item_lang_item): new helper
* util/rust-hir-map.h: add prototype for helper
gcc/testsuite/ChangeLog:
* rust/compile/issue-2105.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Fri, 30 Jun 2023 21:08:10 +0000 (22:08 +0100)]
gccrs: fix ICE with inserting autoderef mappings
We were using the call-expr id for the autoderef mappings but this doesn't
work when the call expression itself is part of a coercion-site so this
changes the code to use the call-expression function path expression for
the id instead which will not be duplicated again.
Addresses #2105
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::generate_possible_fn_trait_call): use fnexpr
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_fn_trait_call): likewise
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Muhammad Mahad [Tue, 27 Jun 2023 12:08:59 +0000 (17:08 +0500)]
gccrs: [E0027] struct pattern fails to specify struct's fields
A pattern for a struct fails to specify a sub-pattern
for every one of the struct's fields. - pattern does
not mention fields `x`, `y`
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): called rust_error_at
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Marc Poulhiès [Thu, 29 Jun 2023 22:44:52 +0000 (00:44 +0200)]
gccrs: refactor: make crate.items private
Introduce Crate::get_items () and fixup all callers.
gcc/rust/ChangeLog:
* hir/tree/rust-hir.h (struct Crate): Rename struct into ...
(class Crate): ... class, and add get_items.
* backend/rust-compile.cc (CompileCrate::go): Adapt to visibility change of items.
* checks/errors/privacy/rust-privacy-check.cc (Resolver::resolve): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::go): Likewise.
* checks/errors/privacy/rust-pub-restricted-visitor.cc (PubRestrictedVisitor::go): Likewise.
* checks/errors/privacy/rust-visibility-resolver.cc (VisibilityResolver::go): Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::go): Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::go): Likewise.
* checks/lints/rust-lint-marklive.cc (FindEntryPoint::find): Likewise.
* checks/lints/rust-lint-scan-deadcode.h (ScanDeadCode::Scan): Likewise.
* metadata/rust-export-metadata.cc (PublicInterface::gather_export_data): Likewise.
* typecheck/rust-hir-type-check.cc (TypeResolution::Resolve): Likewise.
* hir/rust-hir-dump.cc (CompileCrate::go): Likewise.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Marc Poulhiès [Thu, 29 Jun 2023 18:47:16 +0000 (20:47 +0200)]
gccrs: Add new getters
Some class members were not accessible from outside, which will be needed
for the new HIR dump.
gcc/rust/ChangeLog:
* hir/tree/rust-hir-expr.h (AwaitExpr::get_awaited_expr): New.
(AsyncBlockExpr::get_has_move, AsyncBlockExpr::get_block_expr): New.
* hir/tree/rust-hir-item.h (Enum::get_where_clause): New.
(Trait::get_where_clause, Trait::is_unsafe): New.
(ExternalItem::get_visibility): New.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Marc Poulhiès [Thu, 29 Jun 2023 18:45:25 +0000 (20:45 +0200)]
gccrs: FullVisitable abstract class
Introduce FullVisitable class. HIR nodes implementing the FullVisitor
interface should inherit from this class.
gcc/rust/ChangeLog:
* hir/tree/rust-hir.h (class FullVisitable): New.
(class Stmt): Adjust with new class.
(class Expr): Likewise.
(class Pattern): Likewise.
(class Type): Likewise.
(class TypeParamBound): Likewise.
(class GenericParam): Likewise.
(class TraitItem): Likewise.
(class ImplItem): Likewise.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Marc Poulhiès [Wed, 28 Jun 2023 20:02:37 +0000 (22:02 +0200)]
gccrs: factor out inner attributes in a class
Introduce WithInnerAttrs class that can be inherited instead of
duplicating the same data/method in all HIR classes.
gcc/rust/ChangeLog:
* hir/tree/rust-hir.h (class WithInnerAttrs): New.
(class Item): Adjust to new WithInnerAttrs class.
(struct Crate): Likewise.
* hir/rust-hir-dump.cc (Dump::go): Likewise.
(Dump::visit): Likewise.
* hir/tree/rust-hir-expr.h (class GroupedExpr): Likewise.
(class ArrayExpr): Likewise.
(class TupleExpr): Likewise.
(class StructExprStruct): Likewise.
(class BlockExpr): Likewise.
(class MatchExpr): Likewise.
* hir/tree/rust-hir-item.h (TypeParam::get_outer_attribute): New.
(class Module): Adjust to new WithInnerAttrs class.
(struct StructField): change struct to...
(class StructField): ... a class.
(class ImplBlock): Adjust to new WithInnerAttrs class.
(class ExternBlock): Likewise.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Marc Poulhiès [Sun, 28 May 2023 20:10:35 +0000 (22:10 +0200)]
gccrs: cleanup getters to return &unique_ptr instead of pointer
Make all getter methods in HIR classes return a unique_ptr reference
instead of a pointer and adjust all callers.
gcc/rust/ChangeLog:
* hir/tree/rust-hir-type.h (ArrayType::get_element_type): Returns
unique_ptr.
* hir/tree/rust-hir-expr.h (ArithmeticOrLogicalExpr::get_lhs)
(ArithmeticOrLogicalExpr::get_rhs): Likewise.
(ComparisonExpr::get_lhs, ComparisonExpr::get_rhs): Likewise.
(LazyBooleanExpr::get_lhs, LazyBooleanExpr::get_rhs): Likewise.
(AssignmentExpr::get_lhs, AssignmentExpr::get_rhs): Likewise.
(ArrayExpr::get_internal_elements): Likewise.
(ArrayIndexExpr::get_index_expr, ArrayIndexExpr::get_array_expr):
Likewise.
(StructExprFieldWithVal::get_value): Likewise.
(IfExpr::get_if_condition, IfExpr::get_if_block): Likewise.
(ExprWithBlock::get_else_block): Likewise.
* hir/tree/rust-hir-item.h (FunctionParam::get_param_name)
(FunctionParam::get_type): Likewise.
(ConstantItem::get_type, ConstantItem::get_expr): Likewise.
(StaticItem::get_expr, StaticItem::get_type): Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit):
Adjust for previous change.
* backend/rust-compile-block.cc (CompileConditionalBlocks::visit):
Likewise.
* backend/rust-compile-expr.cc (CompileExpr::visit): Likewise.
* backend/rust-compile-item.cc (CompileItem::visit): Likewise.
* backend/rust-compile-struct-field-expr.cc
(CompileStructExprField::visit): Likewise.
* checks/errors/privacy/rust-privacy-reporter.cc
(PrivacyReporter::visit): Likewise.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit):
Likewise.
* typecheck/rust-hir-type-check-implitem.cc
(TypeCheckImplItem::visit): Likewise.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
Likewise.
* typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit):
Likewise.
* typecheck/rust-hir-type-check-struct.cc
(TypeCheckStructExpr::visit): Likewise.
* typecheck/rust-hir-type-check.cc
(TraitItemReference::get_type_from_fn): Likewise.
Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
Arthur Cohen [Fri, 30 Jun 2023 14:40:17 +0000 (16:40 +0200)]
gccrs: abi: Add testcase for using "Rust" as ABI string
gcc/testsuite/ChangeLog:
* rust/compile/rust_abi.rs: New test.
Pierre-Emmanuel Patry [Wed, 28 Jun 2023 11:53:37 +0000 (13:53 +0200)]
gccrs: parser: Propagate type hint value
Type hint value was not propagated correctly to LiteralPattern in ast.
This was defaulted to CORETYPE_STR instead, which introduced several
bugs with systems that did require any ast collection.
gcc/rust/ChangeLog:
* ast/rust-pattern.h: Change constructor to accept new parameter
instead of defaulting on string type.
* parse/rust-parse-impl.h (Parser::parse_literal_or_range_pattern):
Propagate type hint.
(Parser::parse_pattern_no_alt): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Raiki Tamura [Thu, 29 Jun 2023 03:06:44 +0000 (12:06 +0900)]
gccrs: fix lexing byte literal
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::parse_byte_char):add check for range of codepoint
gcc/testsuite/ChangeLog:
* rust/compile/bytecharstring.rs:add test for it
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Muhammad Mahad [Thu, 29 Jun 2023 14:24:00 +0000 (19:24 +0500)]
gccrs: refactored field error function
Refactored field error function into one funciton
Fixes #2336
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-pattern.cc (emit_invalid_field_error): Refactored Field
Error Function
(TypeCheckPattern::visit): called emit_invalid_field_error function
Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
Owen Avery [Sat, 3 Jun 2023 21:40:18 +0000 (17:40 -0400)]
gccrs: Improve macro repetition handling
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc
(MacroExpander::match_matcher): Remove append_fragment inside repetitions.
(MacroExpander::match_n_matches): Use sub_stack push/pop to handle repetitions.
(MatchedFragmentContainer::add_fragment): Add MatchedFragmentContainer accepting version.
* expand/rust-macro-expand.h
(MatchedFragmentContainer::add_fragment): Likewise.
(MatchedFragmentContainerRepetition::add_fragment): Likewise.
(SubstititionScope::append_fragment): Likewise.
gcc/testsuite/ChangeLog:
* rust/compile/macro56.rs: New test.
Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Philip Herron [Thu, 29 Jun 2023 09:13:01 +0000 (10:13 +0100)]
gccrs: fix how we handle coercions and casts of unsafe pointers
I copied swap_nonoverlapping badly from libcore which uses an unsafe
pointer case of x as *mut u8, I thought this was x as *mut T when i was
copying code form libcore this caused new infererence variables to be
introduced which actually automatically turned this swap_nonoverlapping
function to turn into a swap_nonoverlapping<u8> and lost the general
generic one in the type system context.
Rust allows for you to cast any pointer to another pointer of different
base type. The rules here are really subtle though because we need to
handle the case where we do really need to unify the types here there
are a few cases to consider but the main three are:
*u32 vs *u32 -> valid pointers match = simple coercion
*<?> vs *u8 -> inference variable unified with u8 which is valid
*T vs *u8 -> invalid coercion as the element types don't match
-> But this is a valid cast site
The code for casts try a coercion first then if that was sucsessful goes
on to perform a real coercion. Otherwise it follows the cast rules. The
bug here was that we saw the case of *T vs *u8 the try coercion used
inference variables to match T vs u8 but this will cause a cascase of
bad inference variables which we don't want when we perform the simple
coercion.
Fixes #2330
gcc/rust/ChangeLog:
* typecheck/rust-casts.cc (TypeCastRules::check): apply new argument
* typecheck/rust-coercion.cc (TypeCoercionRules::Coerce): track if this is a cast site
(TypeCoercionRules::TryCoerce): update ctor
(TypeCoercionRules::TypeCoercionRules): cleanup error handling
(TypeCoercionRules::do_coercion): likewise
(TypeCoercionRules::coerce_unsafe_ptr): only infer in try mode
(TypeCoercionRules::coerce_borrowed_pointer): cleanup
* typecheck/rust-coercion.h: update header
gcc/testsuite/ChangeLog:
* rust/compile/issue-1981.rs: Fix badly copied libcore code test
* rust/compile/issue-2330.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Thu, 29 Jun 2023 09:13:29 +0000 (10:13 +0100)]
gccrs: Track associated type generics
This fixes an issue with our qualified type-paths if we point to a generic
associated type this needs to either use the placeholder type on the trait
reference or use the impl-type but apply the generics.
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-reference.h: update prototype
* typecheck/rust-hir-trait-resolve.cc: add generic args as an out param
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): use the generics
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Pierre-Emmanuel Patry [Fri, 23 Jun 2023 12:33:53 +0000 (14:33 +0200)]
gccrs: dump: Add formatting to dump
Add formatting character output to ast dump.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Add comment
after tail expressions.
* ast/rust-ast-dump.cc (Dump::require_spacing): Check for
missing previous token.
* ast/rust-ast-dump.h: Output formatting characters.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Fri, 23 Jun 2023 11:59:51 +0000 (13:59 +0200)]
gccrs: collector: Implement formatting options
The collector did only output the tokens without any formatting.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::collect): Collect
CollectItems once done.
(TokenCollector::newline): Add newline formatting
implementation.
(TokenCollector::indentation): Add indentation implementation.
(TokenCollector::increment_indentation): Add indentation
increment.
(TokenCollector::comment): Add new comment formatting option.
* ast/rust-ast-collector.h: Update prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Fri, 23 Jun 2023 10:49:48 +0000 (12:49 +0200)]
gccrs: collector: Store CollectItem instead of TokenPtr
Store a custom type to differentiate formatting and metadata from data.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::collect_tokens):
Filter tokens.
(TokenCollector::visit_items_joined_by_separator): Change store
call.
(TokenCollector::visit_as_line): Likewise.
(TokenCollector::visit_items_as_block): Likewise.
(TokenCollector::trailing_comma): Likewise.
(TokenCollector::visit): Likewise.
(TokenCollector::visit_closure_common): Likewise.
(TokenCollector::visit_function_common): Likewise.
* ast/rust-ast-collector.h (class CollectItem): Add class to
differentiate between formatting and raw data (tokens).
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Fri, 23 Jun 2023 09:44:49 +0000 (11:44 +0200)]
gccrs: collector: Remove external container
The token collector was using an external container but it was later
revealed that this whole reuse thing was not necessary.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::TokenCollector):
Remove constructor, changing it to an implicit default
constructor.
* ast/rust-ast-collector.h: Change from container reference to
direct container.
* ast/rust-ast-dump.h: Change call to constructor.
* expand/rust-macro-expand.h (struct MacroExpander): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 21 Jun 2023 22:16:17 +0000 (00:16 +0200)]
gccrs: dump: Output separating space under condition
Separating space shall not be output between every tokens to make the
dump clear and easy to read.
gcc/rust/ChangeLog:
* ast/rust-ast-dump.cc (Dump::require_spacing): Add a function
to determine wether a space shall output.
* ast/rust-ast-dump.h: Add function prototype as well as
condition.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 21 Jun 2023 21:47:14 +0000 (23:47 +0200)]
gccrs: dump: Replace ast dump internals
Replace ast dump visitor with call to token collector.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Add a visit
function for visitable abstract class so we can call a dump on
any visitable item.
* ast/rust-ast-collector.h: Add new visit function prototype.
* ast/rust-ast-dump.cc (Dump::go): Add call to process function.
(Dump::visit): Remove functions.
(Dump::visit_items_joined_by_separator): Likewise.
(Dump::visit_as_line): Likewise.
(Dump::visit_items_as_lines): Likewise.
(Dump::visit_items_as_block): Likewise.
(Dump::visit_function_common): Likewise.
(get_delimiters): Likewise.
(Dump::debug): Update with call to tokencollector.
* ast/rust-ast-dump.h (RUST_AST_DUMP_H): Move include
directives.
(class Dump): Remove multiple prototypes and add generic process
function.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Thu, 22 Jun 2023 14:41:40 +0000 (16:41 +0200)]
gccrs: collector: Fix missing semicolon output
A final semicolon was missing after every items in an extern block.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Add
semicolon in extern blocks.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Pierre-Emmanuel Patry [Wed, 21 Jun 2023 21:11:19 +0000 (23:11 +0200)]
gccrs: dump: Remove tokenstream dump
This dump will soon replace ast-pretty print and is hence no longer
required.
gcc/rust/ChangeLog:
* rust-session-manager.cc (Session::enable_dump): Remove
tokenstream dump.
(Session::compile_crate): Likewise.
(Session::dump_tokenstream): Likewise.
* rust-session-manager.h (struct CompileOptions): Likewise.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Raiki Tamura [Wed, 28 Jun 2023 09:34:05 +0000 (18:34 +0900)]
gccrs: Add tests for Unicode identifiers
gcc/testsuite/ChangeLog:
* rust/compile/torture/raw_identifiers.rs: New test.
* rust/compile/torture/utf8_identifiers.rs: New test.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
Raiki Tamura [Wed, 28 Jun 2023 10:14:50 +0000 (19:14 +0900)]
gccrs: fix tokenizing utf-8 whitespaces
gcc/rust/ChangeLog:
* lex/rust-lex.cc (Lexer::build_token):add check for all kinds of whitespaces
gcc/testsuite/ChangeLog:
* rust/compile/torture/utf8_whitespaces.rs: New test.
Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>