aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2024-03-26Remove unsafe block empty visit functionPierre-Emmanuel Patry2-5/+0
We need to visit subcomponents in unsafe elements, this means we can leverage the default ast visitor's code instead of duplicating it. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove empty visit function. * resolve/rust-default-resolver.h: Remove function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Remove extern block scopingPierre-Emmanuel Patry2-13/+0
Remove extern block scoping visit function, use the default visitor visit function instead. We do not need scoping for extern block as their element shall be visible from the extern block scope. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove visitor implementation and scoping. * resolve/rust-default-resolver.h: Remove function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Add constant identifiers to the value namespacePierre-Emmanuel Patry1-0/+3
Constants could not be resolved without their identifier in the right scope. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add constant identifiers to the resolver. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Struct are types, not valuesPierre-Emmanuel Patry1-1/+3
We shall search in the right namespace. The correct namespace for struct is type namespace. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Change search location for struct types. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Change enum namespace from value to typePierre-Emmanuel Patry1-1/+1
The enum type shall be in type namespace, not value namespace. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit): Change enum type namespace. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Add tuple struct to the type namespacePierre-Emmanuel Patry1-2/+7
Only tuple struct constructor was added to the resolver. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit): Add tuple struct type to the resolver's context. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Unit struct constructor shall be resolvedPierre-Emmanuel Patry1-2/+7
Unit struct have a special constructor that should be added to the struct namespace in order to be resolved later when called. As it is a function it should be added in the value namespace. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit): Add the struct constructor when the struct is a unit. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Values shall be inserted in the value namespacePierre-Emmanuel Patry1-1/+4
Values were inserted in the label namespace instead of the value namespace this lead to several bugs. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Change the namespace for values from "label" to "values". Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Raw pointer type visitor didn't require overloadPierre-Emmanuel Patry2-5/+0
This overload did not dispatch the visitor to sub members of a raw pointer like the default one. It is therefore useless as pointed type shall be visited to be resolved correctly. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Remove function implementation. * resolve/rust-default-resolver.h: Remove function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Visit constant item type in default resolverPierre-Emmanuel Patry1-1/+4
The type of constant item expression was not properly visited in the default resolver. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Visit constant item's types. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Visit function return type in default resolverPierre-Emmanuel Patry1-0/+3
Function return type was not properly visited in the default resolver visitor pattern. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Visit function return type. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Change error message to match testPierre-Emmanuel Patry1-2/+4
Error message did not match the test from the previous name resolver when a given path cannot be resolved. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Change error message to match old resolver and test case. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Add tuple struct constructor to value namespacePierre-Emmanuel Patry2-0/+8
A tuple struct constructor should be inserted in the value namespace during name resolution in order to reject multiple definitions of the function. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add the struct constructor to the value namespace. gcc/testsuite/ChangeLog: * rust/compile/name_resolution22.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Add support for ambiguous use declarationsPierre-Emmanuel Patry7-71/+142
Glob use declarations may lead to ambiguous situation where two definitions with the same name are imported in a given scope. The compiler now handles shadowable items inserted after non shadowable items. An error is now thrown when multiple shadowable items are imported and used in the same rib. gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::visit): Adapt resolved type to the new API. (Early::visit_attributes): Retrieve the node id from the definition. * resolve/rust-forever-stack.h: Change the return type of getter functions. Those functions now return a definition type instead of a node id. * resolve/rust-forever-stack.hxx: Change member function implementation in the forever stack to accomodate it's API changes. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Use internal node id. Emit an error when resolving multiple ambiguous values. * resolve/rust-rib.cc (Rib::Definition::Definition): Add a default constructor. (Rib::Definition::is_ambiguous): Add a new function to determine whether a function definition is ambiguous or not. (Rib::Definition::to_string): Add a member function to convert a given definition to a string. (Rib::insert): Add new rules for value insertion in a rib. Insertion order does not impact the result anymore: inserting a shadowable value after a non shadowable one does not trigger an error anymore. All shadowable values inserted in a rib are kepts until being replaced by a non shadowable one. (Rib::get): Return a definition instead of a node id. * resolve/rust-rib.h: Update function prototypes. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_glob): Update return value container to match the new function's prototype. (TopLevel::handle_use_dec): Likewise. (flatten_glob): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Make globbing definition shadowable by defaultPierre-Emmanuel Patry5-17/+65
Elements from glob use declaration shall be shadowable by default. gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Add a new function prototype to insert a shadowable definition. * resolve/rust-forever-stack.hxx: Add the new insert_shadowable function to insert shadowable definition into the forever stack. * resolve/rust-name-resolution-context.cc (NameResolutionContext::insert_shadowable): Likewise with the name resolution context. * resolve/rust-name-resolution-context.h: Add name resolution context insert_shadowable member function prototype. * resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit): Insert shadowable definition into the forever stack for glob use declaration. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Add call to globbing visitorPierre-Emmanuel Patry3-1/+11
Globbing visitor did not visit subitems. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add a check for missing item. * resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::go): Add a new function in the visitor to dispatch the visitor to items in the given module. (TopLevel::handle_use_glob): Change call to visitor to use the pointer. * resolve/rust-toplevel-name-resolver-2.0.h: Add prototype for new member function. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Shape up name resolver for normal direct callsPierre-Emmanuel Patry2-5/+21
Direct function calls did not work anymore due to the transition to the new resolver. gcc/rust/ChangeLog: * checks/lints/rust-lint-marklive.cc (MarkLive::find_ref_node_id): Add code path for the resolver 2.0 * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove failing label context resolve call. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Add name resolution for on globbing use declPierre-Emmanuel Patry4-25/+199
This is the first part of the code required to enable globbing on use declarations. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (GlobbingVisitor::visit): Insert names into their namespace. (TopLevel::visit): Insert ast module. (TopLevel::handle_use_dec): Resolve use declaration. (TopLevel::handle_use_glob): Use globbing visitor. (flatten_list): Use globbing path vector. (flatten_glob): Likewise. (flatten): Likewise. (prefix_subpaths): Add a function to prefix subpath. * resolve/rust-toplevel-name-resolver-2.0.h (class GlobbingVisitor): Add globbing visitor. * util/rust-hir-map.cc (Mappings::insert_ast_module): Add function to insert module in module hashmap. (Mappings::lookup_ast_module): Add function to retrieve ast module. * util/rust-hir-map.h: Add module map and getter/setter prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Add modules to type namespacePierre-Emmanuel Patry1-1/+1
gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Module should be added to the type namespace in order to be retrieved later. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26late: Add bool builtin typeArthur Cohen1-0/+1
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::setup_builtin_types): Setup bool as builtin type.
2024-03-26Prevent error emission on resolver reentryPierre-Emmanuel Patry1-2/+2
The resolver was emitting an error when meeting the same symbol twice. What is important here is the origin of the resolved symbol, we should emit an error when the name is similar but the symbol isn't be not when the resolver is simply meeting the exact same symbol. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (insert_macros): Add constraint over the ast node id. (TopLevel::visit): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Change error message on unresolved importPierre-Emmanuel Patry1-2/+1
The error message did not match rustc's. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Change error message. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Emit error on identical use declarationsPierre-Emmanuel Patry2-34/+46
The compiler did not emit any warning when a same target was declared from different sources. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_dec): Use the new dict to track down already resolved use declarations. * resolve/rust-toplevel-name-resolver-2.0.h: Add new dict to store previous use declarations. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26Fix duplicate detectionPierre-Emmanuel Patry1-4/+1
The resolver did report duplicate symbols when being run multiple times even if the node id was the same. This commit adds an additional condition, the error will only be reported if the existing node id is different from the current node id. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::insert_or_error_out): Add new constraint to duplicate errors. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-03-26late: Setup builtin types properly, change Rib APIArthur Cohen4-48/+126
gcc/rust/ChangeLog: * resolve/rust-forever-stack.hxx: Start using Rib::Definition for shadowable information. * resolve/rust-late-name-resolver-2.0.cc (next_node_id): New. (next_hir_id): New. (Late::setup_builtin_types): Improve builtin type setup. * resolve/rust-rib.cc (Rib::Definition::Definition): New constructor. (Rib::Definition::Shadowable): Likewise. (Rib::Definition::NonShadowable): Likewise. (Rib::Rib): Fix general constructor. (Rib::insert): Use Definition class. (Rib::get): Likewise. * resolve/rust-rib.h: New Definition class, new prototypes.
2024-03-26nr2.0: Start using newtype pattern for Usage and DeclarationArthur Cohen3-7/+30
gcc/rust/ChangeLog: * resolve/rust-name-resolution-context.cc (NameResolutionContext::map_usage): Use newtype pattern. (NameResolutionContext::lookup): Likewise. * resolve/rust-name-resolution-context.h (class Usage): New class. (class Definition): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Create instances of Usage and Definition.
2024-03-26backend: Use new name resolver where necessaryArthur Cohen4-11/+44
gcc/rust/ChangeLog: * backend/rust-compile-base.cc: Use new ImmutableNrCtx. * backend/rust-compile-context.h: Likewise. * backend/rust-compile-expr.cc: Likewise. * backend/rust-compile-item.cc: Likewise.
2024-03-26typecheck: Start using nr2.0 properlyArthur Cohen3-26/+105
Fetch the ImmutableNrCtx in order to access name resolver during typechecking. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Start fetching name resolution information in the typechecker. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. * typecheck/rust-hir-type-check-path.cc: Use nr 2.0.
2024-03-26nr2.0: Add lookup of resolved nodes.Arthur Cohen2-0/+16
gcc/rust/ChangeLog: * resolve/rust-name-resolution-context.cc (NameResolutionContext::lookup): Add lookup function. * resolve/rust-name-resolution-context.h: Include mappings and optional.
2024-03-26session manager: Init Immutable name resolver.Arthur Cohen1-0/+4
gcc/rust/ChangeLog: * rust-session-manager.cc (Session::compile_crate): Create an immutable view of the name resolution context.
2024-03-26session-manager: Dump name resolution pass.Arthur Cohen2-3/+28
gcc/rust/ChangeLog: * rust-session-manager.cc: Add files for dumping name resolution, call name resolution dump function. (Session::dump_name_resolution): New. * rust-session-manager.h: New declaration.
2024-03-26sesh: Add late name resolution 2.0Arthur Cohen2-6/+11
gcc/rust/ChangeLog: * rust-session-manager.cc (Session::compile_crate): Create name resolution context for Session::expansion and subsequent name resolution passes. (Session::expansion): Take name resolution context as a parameter instead. * rust-session-manager.h (Session::expansion): Fix declaration.
2024-03-26nr2.0: Add new ImmutableNameResolutionCtx class.Arthur Cohen3-0/+112
gcc/rust/ChangeLog: * Make-lang.in: Compile it. * resolve/rust-immutable-name-resolution-context.cc: New file. * resolve/rust-immutable-name-resolution-context.h: New file.
2024-03-24Merge commit '2f334bb12e3ba947714771408b9d49d398abb5df' into HEADThomas Schwinge36-1091/+2678
2024-03-24Placate clang-format re 'gcc/rust/lex/rust-lex.cc'Thomas Schwinge1-1/+2
Reformat the upstream GCC commit 61644aea34c4623d16273ff705f8b8b1ff2d87f0 "gccrs: tokenize Unicode identifiers" change to 'gcc/rust/lex/rust-lex.cc' to clang-format's liking. gcc/rust/ * lex/rust-lex.cc (is_identifier_start): Placate clang-format.
2024-03-22Merge commit '9f7afa99c67f039e43019ebd08d14a7f01e2d89c' into HEADThomas Schwinge186-3160/+7281
2024-03-22Merge commit 'cde6f1085b7027f6a42fdb71c786d422606a8765^' into HEADThomas Schwinge238-672/+2891
2024-03-22Merge commit '00dea7e8c41b672730d6e2c891b6012a83d8842c' into HEAD [#2284]Thomas Schwinge1-2/+2
2024-03-22Merge commit '00dea7e8c41b672730d6e2c891b6012a83d8842c^' into HEADThomas Schwinge202-1320/+10466
2024-03-22Merge commit 'a945c346f57ba40fc80c14ac59be0d43624e559d' into HEAD [#2842]Thomas Schwinge4745-4857/+4856
2024-03-22Merge commit 'a945c346f57ba40fc80c14ac59be0d43624e559d^' into HEADThomas Schwinge1608-126286/+154675
2024-03-22Merge commit '725fb3595622a4ad8cd078a42fab1c395cbf90cb' into HEAD [#1913, #2288]Thomas Schwinge1-0/+1
2024-03-22Merge commit 'f37c55c14bc1176ef9a15fe584fb6d1bf2e6162f^' into HEADThomas Schwinge5-503/+475
2024-03-21Split up rust-macro-builtins.ccjjasmine14-1020/+1316
Fixes issue #2855 gcc/rust/ChangeLog: * Make-lang.in: add new .o builds for new .cc files * expand/rust-cfg-strip.h (RUST_CFG_STRIP_H): Add include guards for rust-cfg-strip * expand/rust-macro-builtins.cc (make_macro_path_str): moved to new respective files (make_token): moved to new respective files (make_string): moved to new respective files (macro_end_token): moved to new respective files (try_extract_string_literal_from_fragment): moved to new respective files (try_expand_many_expr): moved to new respective files (parse_single_string_literal): moved to new respective files (source_relative_path): moved to new respective files (load_file_bytes): moved to new respective files (MacroBuiltin::assert_handler): moved to new respective files (MacroBuiltin::file_handler): moved to new respective files (MacroBuiltin::column_handler): moved to new respective files (MacroBuiltin::include_bytes_handler): moved to new respective files (MacroBuiltin::include_str_handler): moved to new respective files (MacroBuiltin::compile_error_handler): moved to new respective files (MacroBuiltin::concat_handler): moved to new respective files (MacroBuiltin::env_handler): moved to new respective files (MacroBuiltin::cfg_handler): moved to new respective files (MacroBuiltin::include_handler): moved to new respective files (MacroBuiltin::line_handler): moved to new respective files (MacroBuiltin::stringify_handler): moved to new respective files (struct FormatArgsInput): moved to new respective files (struct FormatArgsParseError): moved to new respective files (format_args_parse_arguments): moved to new respective files (MacroBuiltin::format_args_handler): moved to new respective files * expand/rust-macro-builtins.h (builtin_macro_from_string): merge tl::optional from master * expand/rust-macro-builtins-asm.cc: New file. * expand/rust-macro-builtins-format-args.cc: New file. * expand/rust-macro-builtins-helpers.cc: New file. * expand/rust-macro-builtins-helpers.h: New file. * expand/rust-macro-builtins-include.cc: New file. * expand/rust-macro-builtins-location.cc: New file. * expand/rust-macro-builtins-log-debug.cc: New file. * expand/rust-macro-builtins-test-bench.cc: New file. * expand/rust-macro-builtins-trait.cc: New file. * expand/rust-macro-builtins-utility.cc: New file.
2024-03-21Fix typoGuillaume Gomez1-1/+1
gcc/rust/ChangeLog: * expand/rust-derive.cc (DeriveVisitor::derive): Fix typo
2024-03-21Store visibility properly in ExternalTypeItemjjasmine2-3/+5
Fix issue 2897 gcc/rust/ChangeLog: * hir/rust-ast-lower-extern.h: Add translate_visiblity * hir/tree/rust-hir-item.h: Fix constructor of ExternalTypeItem
2024-03-21TyTy: Collect variance info from typesJakub Dupak1-4/+13
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Collect variance info from types. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-03-21TyTy: Variance analysis moduleJakub Dupak7-0/+975
gcc/rust/ChangeLog: * Make-lang.in: Add new .cc file. * rust-session-manager.cc (Session::compile_crate): Run analysis. * typecheck/rust-tyty-variance-analysis-private.h: New file. * typecheck/rust-tyty-variance-analysis.cc: New file. * typecheck/rust-tyty-variance-analysis.h: New file. * typecheck/rust-typecheck-context.cc (TypeCheckContext::get_variance_analysis_ctx): Variance analysis context. * typecheck/rust-hir-type-check.h (TypeCheckItem::visit): Variance analysis context. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-03-21TyTy: add common SubstitutionRef APIJakub Dupak1-0/+11
gcc/rust/ChangeLog: * typecheck/rust-tyty-subst.cc (SubstitutionRef::get_arg_at): Add unified API. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-03-19format-args: Only pass the format string to the parser.Arthur Cohen1-15/+22
This fixes an issue we had where the generated code ended with more static pieces than its rustc counterpart. gcc/rust/ChangeLog: * expand/rust-macro-builtins.cc (struct FormatArgsInput): Store the format_str as a string instead of an AST::Expr. (format_args_parse_arguments): Transform format_expr into a format string properly - add note for handling eager macro invocations later on. (MacroBuiltin::format_args_handler): Parse the correct input, append newline to format_str if necessary.