aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2023-07-21resolve: Add mappings for proc macros and resolvingPierre-Emmanuel Patry10-180/+215
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>
2023-07-21attribute: Add missing header guardPierre-Emmanuel Patry1-0/+4
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>
2023-07-21ast: Add manual dispatch for meta item downcastingPierre-Emmanuel Patry3-0/+66
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>
2023-07-21resolve: Add extern crate proc macro collectionPierre-Emmanuel Patry4-0/+114
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>
2023-07-21import: Load procedural macros into external cratePierre-Emmanuel Patry2-3/+5
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>
2023-07-21import: Change raw pointer to unique_ptrPierre-Emmanuel Patry4-50/+55
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>
2023-07-21import: Store procedural macros in extern cratePierre-Emmanuel Patry3-3/+8
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>
2023-07-21import: Change package opening prototypesPierre-Emmanuel Patry3-16/+19
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>
2023-07-21import: Add cli extern crate resolutionPierre-Emmanuel Patry2-5/+19
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>
2023-07-20Replace default argument with UNDEF_LOCATIONOwen Avery1-1/+1
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>
2023-07-20Replace Location with location_t in gccrs backendOwen Avery15-75/+78
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>
2023-07-20gccrs: [E0268] break or continue used outside of loopMuhammad Mahad4-5/+16
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>
2023-07-20Add a test for malformed derive declaration inputPierre-Emmanuel Patry1-0/+4
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>
2023-07-20proc macro: Add crate type regression testsPierre-Emmanuel Patry3-0/+14
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>
2023-07-20proc macro: Add help message to malformed derivePierre-Emmanuel Patry1-0/+4
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>
2023-07-20proc macro: Detect malformed proc_macro_derivePierre-Emmanuel Patry1-0/+5
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>
2023-07-20proc macros: Add crate type attribute checkPierre-Emmanuel Patry1-2/+33
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>
2023-07-19libproc_macro: Change Ident structurePierre-Emmanuel Patry1-1/+1
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. ChangeLog: * libgrust/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. * libgrust/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>
2023-07-19proc_macro: Add from string implementationPierre-Emmanuel Patry1-0/+62
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. ChangeLog: * libgrust/libproc_macro/proc_macro.cc (proc_macro_register_from_str): Add registration function. * libgrust/libproc_macro/proc_macro.h (proc_macro_register_from_str): Add registration function prototype. * libgrust/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. * libgrust/libproc_macro/tokenstream.h: Add registration declaration. * libgrust/libproc_macro/registration.h: New file. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2023-07-19cli: Add frust-type optionPierre-Emmanuel Patry3-2/+58
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>
2023-07-19nr2.0: Add `ForeverStack` data structure.Arthur Cohen2-0/+782
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.
2023-07-18gccrs: rework the HIR dump passMarc Poulhiès6-420/+2266
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>
2023-07-18nr2.0: Add basic Rib classArthur Cohen3-0/+206
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>
2023-07-18Replace some more usages of Location with location_tOwen Avery24-240/+240
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>
2023-07-17Replace some usages of Location with location_tOwen Avery94-943/+965
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>
2023-07-17Move some Gcc_backend method definitions out of class declarationOwen Avery1-12/+30
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>
2023-07-17gccrs: [E0423] expected function, tuple struct or tuple variant, found structMuhammad Mahad2-1/+12
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>
2023-07-17Remove Linemap::predeclared_locationOwen Avery5-94/+54
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>
2023-07-17Add include guard for rust-gcc.hOwen Avery1-0/+5
gcc/rust/ChangeLog: * rust-gcc.h: Add include guard. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2023-07-14rust-unreachable: Add specific behavior for rust_unreachableArthur Cohen56-220/+230
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.
2023-07-14gccrs: [E0658] Use of unstable featureMuhammad Mahad2-2/+11
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>
2023-07-14gccrs: [E0093] Declaration of unknown intrinsic functionMuhammad Mahad2-2/+3
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>
2023-07-13gccrs: [E0133] Use of unsafe code outside of unsafe function or blockMuhammad Mahad1-1/+2
gcc/rust/ChangeLog: * checks/errors/rust-unsafe-checker.cc (check_unsafe_call): called error function. Signed-off-by: Muhammad Mahad <mahadtxt@gmail.com>
2023-07-13Remove RichLocation typedefOwen Avery22-104/+102
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>
2023-07-13Remove Linemap::start_lineOwen Avery3-14/+1
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>
2023-07-12Change class RichLocation into typedefOwen Avery22-156/+97
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>
2023-07-12Remove Linemap::get_locationOwen Avery4-21/+2
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>
2023-07-12dump: Output escaped character valuesPierre-Emmanuel Patry1-4/+42
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>
2023-07-12gccrs: minor HIR cleanupMarc Poulhiès1-10/+2
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>
2023-07-12remove braces around scalar initializersPierre-Emmanuel Patry1-12/+9
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>
2023-07-12Add missing virtual destructor to interfacesPierre-Emmanuel Patry2-0/+3
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>
2023-07-12Change specifier of some forward declarationPierre-Emmanuel Patry2-5/+5
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>
2023-07-12Remove unnecessary usage of Location copy constructorOwen Avery3-4/+4
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>
2023-07-12Merge Linemap::to_string into Linemap::location_to_stringOwen Avery3-13/+6
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>
2023-07-11gccrs: minor HIR cleanupMarc Poulhiès5-138/+29
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>
2023-07-11gccrs: [E0124] field x is already declared in structMuhammad Mahad4-7/+16
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>
2023-07-11Add rust_error_at accepting location_t and ErrorCodeOwen Avery2-0/+28
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>
2023-07-11Merge Gcc_linemap into LinemapOwen Avery2-37/+17
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>
2023-07-10gccrs: Remove Rust::Optional in favor of tl::optionalArthur Cohen20-506/+98
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.
2023-07-10Replace Linemap::unknown_location with UNKNOWN_LOCATIONOwen Avery11-77/+67
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>