aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
AgeCommit message (Collapse)AuthorFilesLines
2024-08-01gccrs: borrowck: Fact collectorJakub Dupak2-0/+898
This is the main Polonius based logic which creates the information Polonius needs from BIR. It is largly guessed and rever engineered, so some aspects are probably wrong. gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-fact-collector.h: New file. * checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Enable fact collection. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-08-01gccrs: borrowck: Regions in BIRJakub Dupak8-275/+610
gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-place.h (struct Lifetime): Extended regions and loans. (struct Loan): Representation of loan (result of borrowing) * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Fix let stmt handling. * checks/errors/borrowck/rust-bir-builder-pattern.h: improved pattern translation * checks/errors/borrowck/rust-bir-builder-internal.h: region binding * checks/errors/borrowck/rust-bir-builder-expr-stmt.h (class ExprStmtBuilder): Region support. (class RenumberCtx): Region support. * checks/errors/borrowck/rust-bir-builder.h (class Builder): Region support. * checks/errors/borrowck/rust-bir-dump.cc (get_lifetime_name): Region support. (renumber_places): Region support. (Dump::go): Region support. (Dump::visit): Region support. (Dump::visit_lifetime): Region support. (Dump::visit_scope): Region support. * checks/errors/borrowck/rust-bir.h (class AbstractExpr): Region support. (struct Function): Region support. (class BorrowExpr): Region support. (class CallExpr): Region support. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-08-01gccrs: borrowck: extract regions from types using VAJakub Dupak3-19/+140
Biggybag on variance analysis to extract regions of fields from ADT regions. gcc/rust/ChangeLog: * typecheck/rust-tyty-variance-analysis-private.h (class FieldVisitorCtx): Region extraction. * typecheck/rust-tyty-variance-analysis.cc (query_field_regions): Region extraction. (FieldVisitorCtx::collect_regions): Region extraction. (FieldVisitorCtx::add_constraints_from_ty): Region extraction. (FieldVisitorCtx::add_constraints_from_region): Region extraction. (FieldVisitorCtx::add_constrints_from_param): Region extraction. * typecheck/rust-tyty-variance-analysis.h (query_field_regions): Region extraction. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-08-01gccrs: borrowck: Free region representationJakub Dupak1-0/+107
gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-free-region.h: New file. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-08-01gccrs: borrowck: Polonius FFIJakub Dupak6-0/+596
Rust part is not build and not invoked at this point. gcc/rust/ChangeLog: * checks/errors/borrowck/ffi-polonius/Cargo.toml: New file. * checks/errors/borrowck/ffi-polonius/src/gccrs_ffi.rs: New file. * checks/errors/borrowck/ffi-polonius/src/gccrs_ffi_generated.rs: New file. * checks/errors/borrowck/ffi-polonius/src/lib.rs: New file. * checks/errors/borrowck/polonius/rust-polonius-ffi.h: New file. * checks/errors/borrowck/polonius/rust-polonius.h: New file. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-08-01gccrs: borrowck: BIR: make BIR visitor constJakub Dupak4-22/+26
gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-dump.cc (Dump::visit): const visitor * checks/errors/borrowck/rust-bir-dump.h: const visitor * checks/errors/borrowck/rust-bir-visitor.h: const visitor * checks/errors/borrowck/rust-bir.h: const getter Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-08-01gccrs: borrowck: BIR: emit movesJakub Dupak7-80/+103
gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Emit moves. * checks/errors/borrowck/rust-bir-builder-internal.h: Emit moves. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Emit moves. * checks/errors/borrowck/rust-bir-dump.cc (Dump::visit_move_place): Emit moves. (Dump::visit): Emit moves. * checks/errors/borrowck/rust-bir-place.h (struct Place): Emit moves. * checks/errors/borrowck/rust-bir-visitor.h: Emit moves. * checks/errors/borrowck/rust-bir.h (enum class): Emit moves. (class AbstractExpr): Emit moves. (BasicBlock::is_terminated): Emit moves. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-08-01gccrs: borrowck: BIR: scope handlingJakub Dupak5-37/+188
gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::setup_loop): Loop handling. (ExprStmtBuilder::visit): Handle scopes. * checks/errors/borrowck/rust-bir-builder-internal.h (struct BuilderContext): Handle scopes. * checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Dump scopes. (Dump::visit): Add scopes dump. (Dump::indent): Add indentation logic. (Dump::visit_scope): Dump scope. * checks/errors/borrowck/rust-bir-dump.h: Dump methods. * checks/errors/borrowck/rust-bir-place.h (std::numeric_limits::max): Scope constants. (struct Scope): Scope representation. (class PlaceDB): Scope tracking. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-08-01gccrs: borrowck: BIR: Place tree traverse APIJakub Dupak1-0/+23
gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-place.h: Create place tree traverse API. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-08-01gccrs: borrowck: BIR: use callable APIJakub Dupak1-18/+5
gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Use callable API Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-08-01gccrs: borrowck: Unify BIR terminilogy (node->statement)Jakub Dupak8-59/+62
gcc/rust/ChangeLog: * checks/errors/borrowck/bir-design-notes.md (nodes): Rename node to statement. (Nodes): Rename node to statement. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Rename node to statement. * checks/errors/borrowck/rust-bir-builder-internal.h: Rename node to statement. * checks/errors/borrowck/rust-bir-builder.h: Rename node to statement. * checks/errors/borrowck/rust-bir-dump.cc (Dump::go): Rename node to statement. (Dump::visit): Rename node to statement. * checks/errors/borrowck/rust-bir-dump.h (class Dump): Rename node to statement. * checks/errors/borrowck/rust-bir-visitor.h (class Node): Rename node to statement. (class Statement): Rename node to statement. * checks/errors/borrowck/rust-bir.h (class Node): Rename node to statement. (class Statement): Rename node to statement. (class AbstractExpr): Rename node to statement. (struct Function): Rename node to statement. (struct BasicBlock): Rename node to statement. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-08-01gccrs: borrowck: Use rust-system.hJakub Dupak9-13/+10
Replace direct usage of system headers. gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-dump.cc: Use rust-system.h * checks/errors/borrowck/rust-bir-dump.h (RUST_BIR_DUMP_H): Use rust-system.h * checks/errors/borrowck/rust-bir-place.h (RUST_BIR_PLACE_H): Use rust-system.h * checks/errors/borrowck/rust-function-collector.h: Use rust-system.h * rust-system.h: Use rust-system.h * typecheck/rust-hir-type-check.h: Use rust-system.h * typecheck/rust-tyty-subst.cc: Use rust-system.h * typecheck/rust-tyty-subst.h: Use rust-system.h * typecheck/rust-tyty.h: Use rust-system.h Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-08-01gccrs: unify: Always coerce `!` to the target type.Arthur Cohen1-25/+11
Never can... never... exist, so it should always be coerced to the type it is being matched against. This is useful for breaking off of a loop from inside a match, or an if condition, for example. gcc/rust/ChangeLog: * typecheck/rust-unify.cc (UnifyRules::go): Always unify to `ltype` if we are matching against a `Never` in `rtype`. (UnifyRules::expect_never): Always unify to the expected type. gcc/testsuite/ChangeLog: * rust/compile/match-never-ltype.rs: New test. * rust/compile/match-never-rtype.rs: New test.
2024-08-01gccrs: Improve parsing of raw string literalsOwen Avery1-3/+18
gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_raw_string): Bring handling of edge cases to par with parse_raw_byte_string. gcc/testsuite/ChangeLog: * rust/compile/raw-string-loc.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-08-01gccrs: Avoid parsing const unsafe/extern functions as asyncOwen Avery1-2/+2
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_vis_item): Call parse_function instead of parse_async_item when finding UNSAFE or EXTERN_KW during lookahead. gcc/testsuite/ChangeLog: * rust/compile/func-const-unsafe.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-08-01gccrs: Recognize unstable as a builtin attributeOwen Avery2-1/+3
gcc/rust/ChangeLog: * util/rust-attribute-values.h (Attributes::UNSTABLE): New. * util/rust-attributes.cc (__definitions): Add Attributes::UNSTABLE. gcc/testsuite/ChangeLog: * rust/compile/unstable-fn.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-08-01gccrs: Recognize rustc_deprecated as a builtin attributeOwen Avery2-0/+2
gcc/rust/ChangeLog: * util/rust-attribute-values.h (Attributes::RUSTC_DEPRECATED): New. * util/rust-attributes.cc (__definitions): Add Attributes::RUSTC_DEPRECATED. gcc/testsuite/ChangeLog: * rust/compile/deprecated-fn.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-08-01gccrs: Improve parsing of raw byte string literalsOwen Avery1-4/+19
gcc/rust/ChangeLog: * lex/rust-lex.cc (Lexer::parse_raw_byte_string): Bring handling of edge cases to par with parse_byte_string. gcc/testsuite/ChangeLog: * rust/compile/raw-byte-string-loc.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-08-01gccrs: Change dfs function return type to support gcc 4.8Pierre-Emmanuel Patry2-4/+8
GCC 4.8 does not handle pair with references correctly. We need to use a properly typed struct instead. gcc/rust/ChangeLog: * resolve/rust-forever-stack.h: Change dfs function prototype and declare dfs return type structure. * resolve/rust-forever-stack.hxx: Adapt dfs function to the new return type. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-08-01gccrs: compile: resolve-path-ref: properly resolve nodeId with nr2.0Arthur Cohen2-44/+74
gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc: Attempt to resolve names also using new name resolution context. * backend/rust-compile-resolve-path.h: Add new declaration.
2024-08-01gccrs: Fix use rebind name resolution.Pierre-Emmanuel Patry2-48/+151
Name resolution for rebind were missing. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_glob): Change function prototype to use a reference instead. (TopLevel::handle_use_dec): Likewise. (TopLevel::handle_rebind): Add name resolution on rebind use declarations. (flatten_rebind): Change prototype to accept a pair of path/alias. (flatten_list): Adapt call to flatten_rebind. (flatten): Adapt call to flatten_rebind. (flatten_glob): Remove unused part. (TopLevel::visit): Add rebind resolution. * resolve/rust-toplevel-name-resolver-2.0.h: Adapt function prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-08-01gccrs: Add mappings for struct base and struct fieldsPierre-Emmanuel Patry2-0/+23
Definition/usage mapping during name resolution was missing. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add mapping implementation. * resolve/rust-late-name-resolver-2.0.h: Add function visitor prototype override. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-08-01gccrs: Fix quoted string formatPierre-Emmanuel Patry1-1/+1
This format dialog triggered a warning. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::handle_use_dec): Replace the string format %<%s%> with the proper %qs format. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-08-01gccrs: Prevent getting immutable context with classic nrPierre-Emmanuel Patry2-14/+17
Immutable name resolution context is not initialized when the classic name resolution is in use. It can therefore not be used, the getter would error out. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Only get immutable name resolution context when name resolution 2.0 is used. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-08-01gccrs: Update assignment operator with cratenumPierre-Emmanuel Patry1-0/+1
Crate number was not assigned with the other fields in the assignment operator overload of a CannonicalPath. gcc/rust/ChangeLog: * util/rust-canonical-path.h: Also assign crate number. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-08-01gccrs: Reinject Self parameter in new resolverPierre-Emmanuel Patry2-0/+24
The old resolver injected a Self generic parameter in order to help the trait solver. This is clearly sketchy at best and should be fixed in the future. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Add Self generic parameter injection and a warning. * resolve/rust-toplevel-name-resolver-2.0.h: Add function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-08-01gccrs: Use new name resolver to compile constant itemsPierre-Emmanuel Patry1-10/+26
Constant items were handled only by the old resolver, this lead to an ICE when using the new resolver on some rust code containing a constant item as the new and the old resolver cannot be used at the same time. gcc/rust/ChangeLog: * backend/rust-compile-item.cc (CompileItem::visit): Check the resolver flag and use the new one when required. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-08-01gccrs: Remove 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-08-01gccrs: Remove 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-08-01gccrs: Add 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-08-01gccrs: Struct 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-08-01gccrs: Change 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-08-01gccrs: Add 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-08-01gccrs: Unit 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-08-01gccrs: Values 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-08-01gccrs: Raw 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-08-01gccrs: Visit 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-08-01gccrs: Visit 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-08-01gccrs: Change 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-08-01gccrs: Add tuple struct constructor to value namespacePierre-Emmanuel Patry1-0/+3
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-08-01gccrs: Add 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-08-01gccrs: Make 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-08-01gccrs: Add 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-08-01gccrs: Shape 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-08-01gccrs: Add 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-08-01gccrs: Add 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-08-01gccrs: late: 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-08-01gccrs: Prevent 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-08-01gccrs: Change 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-08-01gccrs: Emit 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>