aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/util/rust-hir-map.cc
AgeCommit message (Collapse)AuthorFilesLines
14 daysgccrs: Change lookup_ast_item's return typePierre-Emmanuel Patry1-5/+4
Wrap the function's return type within an optional. gcc/rust/ChangeLog: * metadata/rust-export-metadata.cc (ExportContext::emit_trait): Adapt call site to the new return type. (ExportContext::emit_function): Likewise. (ExportContext::emit_macro): Likewise. * util/rust-hir-map.cc (Mappings::lookup_ast_item): Change the function's return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_visibility's return typePierre-Emmanuel Patry1-5/+4
Wrap the return type within an optional. gcc/rust/ChangeLog: * checks/errors/privacy/rust-privacy-reporter.cc: Change call site to accomodate new return type. * checks/errors/privacy/rust-pub-restricted-visitor.cc: Likewise. * util/rust-hir-map.cc (Mappings::lookup_visibility): Change the function's return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_macro_invocation's return typePierre-Emmanuel Patry1-6/+4
Wrap the function's return type within an optional and remove the out reference argument. gcc/rust/ChangeLog: * expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Adapt the function call to match its new prototype. * resolve/rust-early-name-resolver-2.0.cc (Early::insert_once): Likewise. (Early::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. * util/rust-hir-map.cc (Mappings::lookup_macro_invocation): Change the function's return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_macro_def return typePierre-Emmanuel Patry1-5/+4
Wrap the function's return type within an optional. gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::insert_once): Change call site to accomodate the new return type. (Early::visit): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Likewise. * util/rust-hir-map.cc (Mappings::lookup_macro_def): Change the function's return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_hir_pattern return typePierre-Emmanuel Patry1-3/+3
Wrap the function's return type within an optional in order to differentiate between a null pointer and a missing value. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::insert_hir_pattern): Change call site in order to accomodate new return type. (Mappings::lookup_hir_pattern): Change the function's return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_hir_struct_field return typePierre-Emmanuel Patry1-3/+3
Wrap the function's return type within an optional to differentiate between a null pointer and a missing value. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::insert_hir_struct_field): Change call site to accomodate new return type. (Mappings::lookup_hir_struct_field): Change the function's return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_hir_self_param return typePierre-Emmanuel Patry1-3/+3
Wrap the function's return type within an optional in order to differentiate null pointers from missing value. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::insert_hir_self_param): Adapt call site to new return type. (Mappings::lookup_hir_self_param): Change the function's return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_hir_param return type with optionalPierre-Emmanuel Patry1-3/+3
Wrap the function's return type within an optional to differentiate between a null ppointer and a missing value. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::insert_hir_param): Change call site to accomodate new return type. (Mappings::lookup_hir_param): Change the function's return type. * util/rust-hir-map.h: Updat ethe function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_hir_smt's return type with optionalPierre-Emmanuel Patry1-4/+4
Wrap the function's return type within an optional in order to differentiate missing values from null pointers. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::insert_hir_stmt): Change call site to accomodate new return type. (Mappings::lookup_hir_stmt): Change the function's return type. (Mappings::resolve_nodeid_to_stmt): Adapt call site to new return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_hir_type return type with an optionalPierre-Emmanuel Patry1-3/+3
Wrap the function's return type with an optional in order to tell appart a null pointer from a missing value. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::insert_hir_type): Change call site to accomodate the new return type. (Mappings::lookup_hir_type): Change the function's return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_hir_generic_param return typePierre-Emmanuel Patry1-3/+3
Wrap the function's return type with an optional. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::insert_hir_generic_param): Change call site to accomodate the new return type. (Mappings::lookup_hir_generic_param): Wrap the function's return type with an optional. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_hir_path_expr_seg return typePierre-Emmanuel Patry1-3/+3
Make the function's return type optional in order to differentiate between null pointers and missing value. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::insert_hir_path_expr_seg): Change call site to accomodate the new return type. (Mappings::lookup_hir_path_expr_seg): Wrap the function's return type with an optional. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_hir_expr return type to optionalPierre-Emmanuel Patry1-2/+2
Wrap the function's return type with an optional in order to differentiate missing values from null pointers. gcc/rust/ChangeLog: * backend/rust-mangle-v0.cc (v0_path): Adapt call site to new returned type. * util/rust-hir-map.cc (Mappings::lookup_hir_expr): Change the function's return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_hir_implitem return typePierre-Emmanuel Patry1-9/+5
Wrap the return type within an optional. Now return the parent id within a pair instead of taking an out reference. gcc/rust/ChangeLog: * backend/rust-compile-item.cc (CompileItem::visit): Change call site to accept new return type. * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Likewise. * backend/rust-mangle-v0.cc (v0_path): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise. (MarkLive::visit): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * util/rust-hir-map.cc (Mappings::insert_hir_implitem): Likewise. (Mappings::lookup_hir_implitem): Change return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change return type to optional in get_lang_itemPierre-Emmanuel Patry1-6/+4
Wrap the function's return type with an optional. gcc/rust/ChangeLog: * typecheck/rust-autoderef.cc: Adapt calling code to new return type. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_operator_overload): Likewise. * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_builtin_candidate): Likewise. * typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): Likewise. * util/rust-hir-map.cc (Mappings::get_lang_item): Change return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_module function return typePierre-Emmanuel Patry1-3/+3
Wrap the return type into an optional. gcc/rust/ChangeLog: * checks/errors/privacy/rust-visibility-resolver.cc: Update function call to match the new return type. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. * util/rust-hir-map.cc (Mappings::insert_module): Likewise. (Mappings::lookup_module): Change the function's return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_hir_extern_item return typePierre-Emmanuel Patry1-7/+5
Wrap the return type with an optional and make the return type a pair with the parent hid. gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Adapt code around new return type. * checks/errors/rust-const-checker.cc (ConstChecker::check_function_call): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::check_use_of_static): Likewise. (UnsafeChecker::check_function_call): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * util/rust-hir-map.cc (Mappings::insert_hir_extern_item): Likewise. (Mappings::lookup_hir_extern_item): Change return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change return type of lookup trait defid functions.Pierre-Emmanuel Patry1-5/+5
Wrap the return type with an optional. gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address): Update code around lookup return type. * typecheck/rust-tyty-bounds.cc (TypeCheckBase::get_predicate_from_bound): Likewise. * typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): Likewise. * util/rust-hir-map.cc (Mappings::insert_defid_mapping): Likewise. (Mappings::lookup_trait_item_defid): Update return type with an optional. (Mappings::get_lang_item): Likewise. * util/rust-hir-map.h: Update the functions prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_local_defid return type to optionalPierre-Emmanuel Patry1-6/+6
Make the API more convenient by changing the function's return type. We can now differentiate between a stored null pointer and a missing value. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::insert_defid_mapping): Adapt call to new return type. (Mappings::insert_local_defid_mapping): Likewise. (Mappings::lookup_local_defid): Change return type to wrap it with an optional. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change return type of lookup_defidPierre-Emmanuel Patry1-4/+4
Change the return type to an optional. gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address): Change calling code to accomodate new return type. * checks/errors/privacy/rust-privacy-reporter.cc: Likewise. * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::get_marker_predicate): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_builtin_candidate): Likewise. * typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): Likewise. * util/rust-hir-map.cc (Mappings::lookup_defid): Change function's return type. * util/rust-hir-map.h: Update function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change crate name retrieval function return typesPierre-Emmanuel Patry1-10/+6
Change their return type to a const reference in order to avoid copies when possible. Also wrap this new return type into an optional. gcc/rust/ChangeLog: * checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Adapt the code to the new return types. * resolve/rust-ast-resolve.cc (NameResolution::go): Likewise. * util/rust-hir-map.cc (Mappings::get_crate_name): Change return type to const string reference optional. (Mappings::get_current_crate_name): Likewise. * util/rust-hir-map.h: Update function prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change crate_num_to_nodeid return typePierre-Emmanuel Patry1-5/+4
Change the function's return type to an optional. gcc/rust/ChangeLog: * resolve/rust-ast-resolve-toplevel.h: Adapt the code to the new return type. * rust-session-manager.cc (Session::load_extern_crate): Likewise. * util/rust-hir-map.cc (Mappings::crate_num_to_nodeid): Change the return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change return type of lookup_crate_namePierre-Emmanuel Patry1-8/+4
Change the function's return type to use an optional. gcc/rust/ChangeLog: * resolve/rust-ast-resolve-toplevel.h: Adapt the code to the new return type. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Likewise. * rust-session-manager.cc (Session::load_extern_crate): Likewise. * util/rust-hir-map.cc (Mappings::lookup_crate_name): Change the return type to an optional. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change return type of lookup_impl_block_typePierre-Emmanuel Patry1-5/+4
Change the return type to an optional. gcc/rust/ChangeLog: * typecheck/rust-type-util.cc (query_type): Adapt code to accomodate the new return type. * util/rust-hir-map.cc (Mappings::lookup_impl_block_type): Change the function's return type and remove the out pointer argument. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change return type for lookup_hir_impl_blockPierre-Emmanuel Patry1-3/+3
Change the return type to an optiona. This allows to differentiate between missing hir impl block and null pointers. gcc/rust/ChangeLog: * typecheck/rust-type-util.cc (query_type): Change call to the function in order to accomodate the new return type. * util/rust-hir-map.cc (Mappings::lookup_hir_impl_block): Change the function's return type to an optional. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change return type of lookup_hir_extern_blockPierre-Emmanuel Patry1-3/+3
Change the return type to an optional in order to easily differentiate between a null pointer and an missing value. gcc/rust/ChangeLog: * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::check_function_call): Adapt function call to new return type. * typecheck/rust-type-util.cc (query_type): Likewise. * util/rust-hir-map.cc (Mappings::insert_hir_extern_block): Likewise. (Mappings::lookup_hir_extern_block): Change return type to an optional. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change return type of lookup_hir_trait_itemPierre-Emmanuel Patry1-3/+3
Change the return type to an optional instead of returning a null pointer. This allows easier tracking of rogue null pointers in the map. This commit also fixes a bug in trait associated function mangling, the function was using an already invalidated pointer. gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Adapt return type to new optional. * backend/rust-mangle-v0.cc (v0_function_path): Change prototype to use the generic arguments vector instead of the whole HIR function. (v0_path): Fix a bug with a null pointer being used to create the trait function mangling. * util/rust-hir-map.cc (Mappings::insert_hir_trait_item): Adapt code to new return type. (Mappings::lookup_hir_trait_item): Change the return type of the function to an optional. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change return type for lookup_hir_item to optionalPierre-Emmanuel Patry1-4/+3
gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Adapt function call to new return type. * backend/rust-mangle-v0.cc (v0_path): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::check_function_call): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::check_use_of_static): Likewise. (UnsafeChecker::check_function_call): Likewise. (UnsafeChecker::check_function_attr): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise. (MarkLive::visit): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * util/rust-hir-map.cc (Mappings::insert_hir_item): Likewise. (Mappings::lookup_hir_item): Change function return type to use optional. * util/rust-hir-map.h: Update function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change return type of resolve_nodeid_to_stmtPierre-Emmanuel Patry1-6/+4
Change the return type to an optional. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::resolve_nodeid_to_stmt): Change the return type and remove pointer out argument. * util/rust-hir-map.h: Update function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_hir_to_node return type to optionalPierre-Emmanuel Patry1-5/+4
Optional are more convenient to use and avoid uninitialized data. gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::generate_closure_function): Adapt code for new optional return type. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy): Likewise. * util/rust-hir-map.cc (Mappings::lookup_hir_to_node): Change return type to an optional. * util/rust-hir-map.h: Adapt function prototype with the new return type. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change lookup_node_to_hir return type to optionalPierre-Emmanuel Patry1-5/+4
Previous API was using a boolean and a pointer, this was not practical and could be replaced with an optional. gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Change call to use the returned optional. (CompileExpr::generate_closure_function): Likewise. * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Likewise. * backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise. * backend/rust-mangle-v0.cc (v0_path): Likewise. * checks/errors/privacy/rust-visibility-resolver.cc: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::visit): Likewise. (MarkLive::visit_path_segment): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. (ResolveWhereClauseItem::visit): Likewise. * util/rust-hir-map.cc (Mappings::lookup_node_to_hir): Return an optional instead of a boolean. * util/rust-hir-map.h: Change function prototype to match the new return type. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
14 daysgccrs: Change singleton returned type to a referencePierre-Emmanuel Patry1-6/+3
We do not need a raw pointer for this singleton, nor we need having it on the heap through a smart pointer. gcc/rust/ChangeLog: * ast/rust-ast.h: Change dereference from a pointer to a reference accessor. * 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-type.h: Likewise. * backend/rust-compile-base.cc (HIRCompileBase::resolve_method_address): Likewise. * backend/rust-compile-context.h: Likewise. * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise. (CompileExpr::generate_closure_function): Likewise. * backend/rust-compile-extern.h: Likewise. * backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise. * backend/rust-compile-intrinsic.cc (Intrinsics::compile): Likewise. * backend/rust-compile-item.cc (CompileItem::visit): Likewise. * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Likewise. (HIRCompileBase::query_compile): Likewise. * backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise. (TyTyResolveCompile::create_dyn_obj_record): Likewise. * backend/rust-compile.cc (HIRCompileBase::coerce_to_dyn_object): Likewise. * backend/rust-mangle-v0.cc (v0_path): Likewise. (v0_mangle_item): Likewise. * checks/errors/borrowck/rust-borrow-checker.cc (BorrowChecker::go): Likewise. * checks/errors/privacy/rust-privacy-check.cc (Resolver::resolve): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::ConstChecker): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::UnsafeChecker): Likewise. * checks/lints/rust-lint-marklive-base.h: Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::go): Likewise. (MarkLive::visit): Likewise. (MarkLive::visit_path_segment): Likewise. * checks/lints/rust-lint-marklive.h: Likewise. * checks/lints/rust-lint-scan-deadcode.h: Likewise. * expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Likewise. * expand/rust-macro-expand.h (struct MacroExpander): Change mapping from pointer to a reference. * expand/rust-proc-macro.cc (BangProcMacro::BangProcMacro): Replace pointer accessor with reference accessor. (AttributeProcMacro::AttributeProcMacro): Likewise. (CustomDeriveProcMacro::CustomDeriveProcMacro): Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::lower_lifetime): Likewise. (ASTLoweringBase::lower_loop_label): Likewise. (ASTLoweringBase::lower_path_expr_seg): Likewise. (ASTLoweringBase::lower_self): Likewise. (ASTLoweringBase::handle_lang_item_attribute): Likewise. (ASTLoweringBase::lower_extern_block): Likewise. (ASTLoweringBase::lower_macro_definition): Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-block.h: Likewise. * hir/rust-ast-lower-enumitem.h: Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::translate): Likewise. (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-extern.h: Likewise. * hir/rust-ast-lower-implitem.cc (ASTLowerImplItem::translate): Likewise. (ASTLowerImplItem::visit): Likewise. (ASTLowerTraitItem::translate): Likewise. (ASTLowerTraitItem::visit): Likewise. * hir/rust-ast-lower-item.cc (ASTLoweringItem::translate): Likewise. (ASTLoweringItem::visit): Likewise. (ASTLoweringSimplePath::lower): Likewise. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::translate): Likewise. (ASTLoweringPattern::visit): Likewise. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::translate): Likewise. (ASTLoweringStmt::visit): Likewise. * hir/rust-ast-lower-struct-field-expr.h: Likewise. * hir/rust-ast-lower-type.cc (ASTLowerTypePath::visit): Likewise. (ASTLowerQualifiedPathInType::visit): Likewise. (ASTLoweringType::translate): Likewise. (ASTLoweringType::visit): Likewise. (ASTLowerGenericParam::translate): Likewise. (ASTLowerGenericParam::visit): Likewise. (ASTLoweringTypeBounds::translate): Likewise. (ASTLoweringTypeBounds::visit): Likewise. (ASTLowerWhereClauseItem::translate): Likewise. (ASTLowerWhereClauseItem::visit): Likewise. * hir/rust-ast-lower.cc (ASTLowering::go): Likewise. (ASTLoweringBlock::visit): Likewise. (ASTLoweringIfBlock::visit): Likewise. (ASTLoweringIfLetBlock::visit): Likewise. (ASTLowerStructExprField::visit): Likewise. (ASTLoweringExprWithBlock::visit): Likewise. (ASTLowerPathInExpression::visit): Likewise. (ASTLoweringBase::lower_qual_path_type): Likewise. (ASTLowerQualPathInExpression::visit): Likewise. * metadata/rust-export-metadata.cc (ExportContext::emit_trait): Likewise. (ExportContext::emit_function): Likewise. (ExportContext::emit_macro): Likewise. (PublicInterface::PublicInterface): Likewise. (PublicInterface::expected_metadata_filename): Likewise. * metadata/rust-export-metadata.h: Likewise. * resolve/rust-ast-resolve-base.h: Likewise. * resolve/rust-ast-resolve-implitem.h: Likewise. * resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): Likewise. (ResolveItem::visit): Likewise. (ResolveExternItem::visit): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise. * resolve/rust-ast-resolve-stmt.h: Likewise. * resolve/rust-ast-resolve-toplevel.h: Likewise. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. (ResolveTypeToCanonicalPath::visit): Likewise. * resolve/rust-ast-resolve-type.h: Likewise. * resolve/rust-ast-resolve.cc (NameResolution::NameResolution): Likewise. (NameResolution::go): Likewise. * resolve/rust-ast-resolve.h: Likewise. * resolve/rust-early-name-resolver-2.0.cc (Early::visit_attributes): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::EarlyNameResolver): Likewise. * resolve/rust-late-name-resolver-2.0.cc (next_node_id): Likewise. (next_hir_id): Likewise. * resolve/rust-name-resolution-context.cc (NameResolutionContext::NameResolutionContext): Likewise. * resolve/rust-name-resolver.cc (Resolver::Resolver): Likewise. (Resolver::generate_builtins): Likewise. (Resolver::setup_builtin): Likewise. * resolve/rust-name-resolver.h: Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Likewise. (TopLevel::handle_use_glob): Likewise. * rust-session-manager.cc (Session::get_instance): Likewise. (Session::handle_input_files): Likewise. (Session::handle_crate_name): Likewise. (Session::compile_crate): Likewise. (Session::load_extern_crate): Likewise. * rust-session-manager.h: Likewise. * typecheck/rust-autoderef.cc (Adjuster::try_unsize_type): Likewise. * typecheck/rust-coercion.cc (TypeCoercionRules::do_coercion): Likewise. (TypeCoercionRules::coerce_unsafe_ptr): Likewise. (TypeCoercionRules::coerce_borrowed_pointer): Likewise. (TypeCoercionRules::coerce_unsized): Likewise. * typecheck/rust-coercion.h: Likewise. * typecheck/rust-hir-dot-operator.cc (MethodResolver::select): Likewise. * typecheck/rust-hir-inherent-impl-overlap.h: Likewise. * typecheck/rust-hir-path-probe.cc (PathProbeType::process_enum_item_for_candiates): Likewise. (PathProbeType::process_impl_items_for_candidates): Likewise. (PathProbeImplTrait::process_trait_impl_items_for_candidates): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait): Likewise. (TraitItemReference::get_parent_trait_mappings): Likewise. * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::resolve_literal): Likewise. (TypeCheckBase::get_marker_predicate): Likewise. * typecheck/rust-hir-type-check-base.h: Likewise. * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_operator_overload): Likewise. (TypeCheckExpr::resolve_fn_trait_call): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::visit): Likewise. (TypeCheckImplItem::visit): Likewise. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Likewise. (TypeCheckExpr::resolve_segments): Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::emit_pattern_size_error): Likewise. (ClosureParamInfer::Resolve): Likewise. * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): Likewise. (TypeCheckType::resolve_root_path): Likewise. (TypeResolveGenericParam::visit): Likewise. (ResolveWhereClauseItem::visit): Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * typecheck/rust-typecheck-context.cc (TypeCheckContext::compute_inference_variables): Likewise. * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Likewise. (TypeBoundsProbe::assemble_builtin_candidate): Likewise. (TypeCheckBase::get_predicate_from_bound): Likewise. * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise. (TypeCheckMethodCallExpr::check): Likewise. * typecheck/rust-tyty-call.h: Likewise. * typecheck/rust-tyty-cmp.h: Likewise. * typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::override_context): Likewise. (SubstitutionRef::monomorphize): Likewise. * typecheck/rust-tyty-util.cc (TyVar::get_implicit_infer_var): Likewise. (TyVar::monomorphized_clone): Likewise. (TyWithLocation::TyWithLocation): Likewise. * typecheck/rust-tyty.cc (BaseType::satisfies_bound): Likewise. (InferType::clone): Likewise. (ADTType::handle_substitions): Likewise. (TupleType::handle_substitions): Likewise. (FnType::handle_substitions): Likewise. (ClosureType::setup_fn_once_output): Likewise. (ArrayType::handle_substitions): Likewise. (SliceType::handle_substitions): Likewise. (ReferenceType::handle_substitions): Likewise. (PointerType::handle_substitions): Likewise. (ParamType::handle_substitions): Likewise. * typecheck/rust-tyty.h: Likewise. * typecheck/rust-unify.cc (UnifyRules::UnifyRules): Likewise. (UnifyRules::commit): Likewise. * util/rust-hir-map.cc: Change getter return type to a reference. * util/rust-hir-map.h: Update function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-01-02Update copyright years.Jakub Jelinek1-1/+1
2024-08-01gccrs: Add name resolution for on globbing use declPierre-Emmanuel Patry1-0/+19
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: Clean BiMap to use tl::optional for lookupsSourabh Jaiswal1-1/+1
gcc/rust/Changelog: * expand/rust-expand-visitor.cc (ExpandVisitor::expand_inner_items): Adjust to use has_value () (ExpandVisitor::expand_inner_stmts): Likewise * expand/rust-macro-builtins.cc (builtin_macro_from_string): Likewise (make_macro_path_str): Likewise * util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise * util/rust-lang-item.cc (LangItem::Parse): Adjust to return tl::optional (LangItem::toString) Likewise * util/rust-token-converter.cc (handle_suffix): Adjust to use value.or () (from_literal) Likewise * util/bi-map.h (BiMap::lookup): Adjust to use tl::optional for lookups Signed-off-by: Sourabh Jaiswal <sourabhrj31@gmail.com>
2024-08-01gccrs: lang-items: Make lang items enum stronger, rename class, cleanup ns.Arthur Cohen1-4/+3
gcc/rust/ChangeLog: * util/rust-lang-item.h (class RustLangItem): Renamed to... (class LangItem): ...this. Rename ItemType enum to Kind * util/rust-lang-item.cc: Rename methods to use new class name. * backend/rust-compile-expr.cc (CompileExpr::visit): Use new lang-item API. (CompileExpr::resolve_operator_overload): Likewise. * backend/rust-compile-expr.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_lang_item_attribute): Likewise. * typecheck/rust-autoderef.cc (Adjuster::try_deref_type): Likewise. (AutoderefCycle::cycle): Likewise. * typecheck/rust-autoderef.h: Likewise. * typecheck/rust-hir-type-bounds.h: Likewise. * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::get_marker_predicate): Likewise. * typecheck/rust-hir-type-check-base.h: Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::visit): Likewise. * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_sized_builtin): Likewise. (TypeBoundsProbe::assemble_builtin_candidate): Likewise. (TypeCheckBase::get_predicate_from_bound): Likewise. * typecheck/rust-tyty.cc (ClosureType::setup_fn_once_output): Likewise. * util/rust-hir-map.cc (Mappings::get_lang_item): Likewise. (Mappings::lookup_trait_item_lang_item): Likewise. * util/rust-hir-map.h: Likewise.
2024-01-16gccrs: hir: Rename get_pattern_mappings methodJakub Dupak1-2/+2
Unify with the name used in Expr to allow convenient template over everything that has mappings. gcc/rust/ChangeLog: * backend/rust-compile-base.cc: Rename method. * backend/rust-compile-expr.cc (sort_tuple_patterns): Rename method. * backend/rust-compile-pattern.cc (CompilePatternCaseLabelExpr::visit): Rename method. (CompilePatternBindings::visit): Rename method. (CompilePatternLet::visit): Rename method. * backend/rust-compile-stmt.cc (CompileStmt::visit): Rename method. * backend/rust-compile-var-decl.h: Rename method. * hir/rust-ast-lower-pattern.cc (ASTLoweringPattern::translate): Rename method. * hir/rust-hir-dump.cc (Dump::visit): Rename method. * hir/tree/rust-hir-path.h: Rename method. * hir/tree/rust-hir-pattern.h: Rename method. * hir/tree/rust-hir.h: Rename method. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::Resolve): Rename method. (TypeCheckPattern::visit): Rename method. (ClosureParamInfer::visit): Rename method. * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::visit): Rename method. * util/rust-hir-map.cc (Mappings::insert_hir_pattern): Rename method. Signed-off-by: Jakub Dupak <dev@jakubdupak.com>
2024-01-16gccrs: Unify raw attribute valuesPierre-Emmanuel Patry1-1/+3
Attribute values were used as raw string, this is error prone and makes renaming harder. Using a constexpr instead will leverage the power of the compiler and emit an error when an incorrect builtin attribute value is used. gcc/rust/ChangeLog: * ast/rust-ast.cc (Attribute::check_cfg_predicate): Change raw string to constexpr call. (Attribute::separate_cfg_attrs): Likewise. * backend/rust-compile-base.cc (should_mangle_item): Likewise. (HIRCompileBase::setup_fndecl): Likewise. (HIRCompileBase::handle_cold_attribute_on_fndecl): Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (find_proc_macro_attribute): Likewise. * checks/errors/rust-unsafe-checker.cc (check_target_attr): Likewise. * expand/rust-cfg-strip.cc (fails_cfg): Likewise. (fails_cfg_with_expand): Likewise. (expand_cfg_attrs): Likewise. * expand/rust-macro-builtins.cc: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::handle_outer_attributes): Likewise. (ASTLoweringBase::lower_macro_definition): Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * parse/rust-parse-impl.h (Parser::parse_doc_comment): Likewise. * parse/rust-parse.cc (extract_module_path): Likewise. * resolve/rust-early-name-resolver.cc (is_macro_use_module): Likewise. (EarlyNameResolver::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (is_macro_export): Likwise. * rust-session-manager.cc (Session::injection): Likewise. * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): Likewise. * util/rust-attributes.cc (is_proc_macro_type): Likewise. (AttributeChecker::check_attribute): Likewise. (AttributeChecker::visit): Likewise. * util/rust-hir-map.cc (Mappings::insert_macro_def): Likewise. * util/rust-attribute-values.h: New file. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Change proc macro mapping definition insertionPierre-Emmanuel Patry1-9/+9
Since the node id already is contained into the proc macro we may omit it from the function arguments. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::insert_derive_proc_macro_def): Change the function body to fetch the node id from the macro parameter. (Mappings::insert_bang_proc_macro_def): Likewise. (Mappings::insert_attribute_proc_macro_def): Likewise. * util/rust-hir-map.h: Update the function's prototype by removing the node id from the list of arguments. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Change proc macro definition lookup to optionalsPierre-Emmanuel Patry1-15/+12
Continue changing the api to use optionals instead of bools and double pointers. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::lookup_derive_proc_macro_def): Update function to accomodate new signature. (Mappings::lookup_bang_proc_macro_def): Likewise. (Mappings::lookup_attribute_proc_macro_def): Likewise. * util/rust-hir-map.h: Update function signatures. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Use optional for proc macro invocation lookupPierre-Emmanuel Patry1-18/+12
The old interface for those mappings was clunky at best. Now we can use the optional structure to return a reference to the instance. gcc/rust/ChangeLog: * expand/rust-macro-expand.h (struct MacroExpander): Update lookup function prototypes. * util/rust-hir-map.cc (Mappings::lookup_derive_proc_macro_invocation): Update lookup function according to new signature. (Mappings::lookup_bang_proc_macro_invocation): Likewise. (Mappings::lookup_attribute_proc_macro_invocation): Likewise. * util/rust-hir-map.h: Update function prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: resolver: Refactor assertionPierre-Emmanuel Patry1-0/+3
Change the condition with rust_unreachable to an assertion. This will keep the code clean and concise. Some styling issues appeared during review, this commit make the code more readable. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Change to assertion. * util/rust-hir-map.cc (Mappings::lookup_derive_proc_macros): Add empty line. (Mappings::lookup_bang_proc_macros): Likewise. (Mappings::lookup_attribute_proc_macros): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Move extern crate resolvingPierre-Emmanuel Patry1-21/+14
Move extern crate resolving under the extern crate declaration instead of doing it under the crate's root as extern crates are not resolved by the top level resolver. gcc/rust/ChangeLog: * metadata/rust-extern-crate.cc (ExternCrate::ExternCrate): Update definition to allow Extern crate with no content (pure proc macros). (ExternCrate::ok): Panic on no content. (ExternCrate::load): Likewise. * metadata/rust-extern-crate.h: Update prototypes. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go): Remove macro resolution. (TopLevel::visit): Likewise. * resolve/rust-toplevel-name-resolver-2.0.h: Add visit prototype for extern crate. * rust-session-manager.cc (Session::load_extern_crate): Adapt content depending on the loaded crate's content. * util/rust-hir-map.cc (Mappings::lookup_derive_proc_macros): Change return type to optional because it is way more convenient. (Mappings::lookup_bang_proc_macros): Likewise. (Mappings::lookup_attribute_proc_macros): Likewise. * util/rust-hir-map.h: Update function prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Move proc macro definition to mappingsPierre-Emmanuel Patry1-26/+22
This commit moves the procedural macros loaded definition from outside the AST to the mappings. This means most getters/setters around the mappings had to be changed. This commit also introduces the top level visit of those mappings instead of visiting the Crate ast members. gcc/rust/ChangeLog: * ast/rust-ast.h (class BangProcMacro): Move class from here to rust-proc-macro.h. Also remove related functions. (class AttributeProcMacro): Likewise. (class CustomDeriveProcMacro): Likewise. (struct Crate): Remove proc macro vector members. * expand/rust-macro-expand.h (struct MacroExpander): Change the type to the newly created classes. * expand/rust-proc-macro.cc (BangProcMacro::BangProcMacro): Add constructor implementation. (AttributeProcMacro::AttributeProcMacro): Likewise. (CustomDeriveProcMacro::CustomDeriveProcMacro): Likewise. * expand/rust-proc-macro.h (class BangProcMacro): Move class to here. (class AttributeProcMacro): Likewise. (class CustomDeriveProcMacro): Likewise. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go): Change top level visitor to check mappings instead * rust-session-manager.cc (Session::load_extern_crate): Add back macro collection to mappings. * util/rust-hir-map.cc (Mappings::insert_derive_proc_macros): Update getter signature with new types. (Mappings::insert_bang_proc_macros): Likewise. (Mappings::insert_attribute_proc_macros): Likewise. (Mappings::lookup_derive_proc_macros): Likewise. (Mappings::lookup_bang_proc_macros): Likewise. (Mappings::lookup_attribute_proc_macros): Likewise. (Mappings::insert_derive_proc_macro_def): Likewise. (Mappings::insert_bang_proc_macro_def): Likewise. (Mappings::insert_attribute_proc_macro_def): Likewise. (Mappings::lookup_derive_proc_macro_def): Likewise. (Mappings::lookup_bang_proc_macro_def): Likewise. (Mappings::lookup_attribute_proc_macro_def): Likewise. (Mappings::insert_derive_proc_macro_invocation): Likewise. (Mappings::lookup_derive_proc_macro_invocation): Likewise. (Mappings::insert_bang_proc_macro_invocation): Likewise. (Mappings::lookup_bang_proc_macro_invocation): Likewise. (Mappings::insert_attribute_proc_macro_invocation): Likewise. (Mappings::lookup_attribute_proc_macro_invocation): Likewise. * util/rust-hir-map.h: Update function prototypes as well as map types. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: Add punycode encoding to v0 manglingRaiki Tamura1-2/+2
gcc/rust/ChangeLog: * backend/rust-mangle.cc (v0_add_identifier): Added punycode encoding (v0_mangle_item): Likewise. * lex/rust-lex.cc (assert_source_content): Change type (test_buffer_input_source): Change type (test_file_input_source): Change type * resolve/rust-ast-resolve-toplevel.h: fix typo * rust-session-manager.cc (Session::load_extern_crate): fix typo * util/rust-canonical-path.h: fix typo * util/rust-hir-map.cc (NodeMapping::get_error): fix typo (Mappings::Mappings): fix typo * util/rust-mapping-common.h (UNKNOWN_CREATENUM): fix typo (UNKNOWN_CRATENUM): Change 0 to UINT32_MAX Signed-off-by: Raiki Tamura <tamaron1203@gmail.com>
2024-01-16gccrs: Begin enforcing Sized properly and support anti traits like ?SizedPhilip Herron1-7/+14
Sized is implicitly applied to every generic type parameter apart from the implicit Self type parameter on traits, as that would cause a recursive bound and would make Traits unable to be appied to unsized types. In order to keep everything happy this means we also need to support the anti trait bound '?' so that Sized can be removed properly. The full Sized rules are not completely implemented here. Slice's and Str's are currently marked as Sized but there is a small regression here that looks like a more general bug which should be fixed on its own as part of #2443. There is a big testsuite update here to pull in the Sized lang item. Note this lays the bound's ground work so we can start supporting Drop trait properly which needs tackled very soon. Fixes: #2375 Addresses: #2443 gcc/rust/ChangeLog: * expand/rust-proc-macro.cc (literal_from_string): update Lexer constructor (tokenstream_from_string): likewise * lex/rust-lex.cc (Lexer::Lexer): likewise * lex/rust-lex.h: pass through Linemap * parse/rust-cfg-parser.cc (parse_cfg_option): likewise * rust-session-manager.cc (Session::load_extern_crate): likewise * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): dont apply Sized on self * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::get_marker_predicate): new * typecheck/rust-hir-type-check-base.h: add prototype * typecheck/rust-hir-type-check-type.cc (TypeResolveGenericParam::Resolve): apply Sized (TypeResolveGenericParam::visit): likewise * typecheck/rust-hir-type-check-type.h: update prototypes * typecheck/rust-typecheck-context.cc: remove bad assertions * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::assemble_sized_builtin): cleanup (TypeCheckBase::get_predicate_from_bound): apply sized rules properly * util/rust-hir-map.cc (Mappings::lookup_trait_item_lang_item): helpers (Mappings::get_lang_item): likewise * util/rust-hir-map.h: likewise * util/rust-token-converter.cc (from_ident): update lexer ctor (from_punct): likewise gcc/testsuite/ChangeLog: * rust/compile/bounds1.rs: Apply sized trait * rust/compile/canonical_paths1.rs: likewise * rust/compile/cast_generics.rs: likewise * rust/compile/closure_no_type_anno.rs: likewise * rust/compile/complex_qualified_path_in_expr.rs: likewise * rust/compile/const-issue1440.rs: likewise * rust/compile/const_generics_1.rs: likewise * rust/compile/const_generics_8.rs: likewise * rust/compile/derive_macro1.rs: likewise * rust/compile/derive_macro3.rs: likewise * rust/compile/derive_macro4.rs: likewise * rust/compile/derive_macro6.rs: likewise * rust/compile/expected_type_args2.rs: likewise * rust/compile/expected_type_args3.rs: likewise * rust/compile/generics1.rs: likewise * rust/compile/generics11.rs: likewise * rust/compile/generics12.rs: likewise * rust/compile/generics2.rs: likewise * rust/compile/generics3.rs: likewise * rust/compile/generics4.rs: likewise * rust/compile/generics6.rs: likewise * rust/compile/generics7.rs: likewise * rust/compile/generics8.rs: likewise * rust/compile/if_let_expr.rs: likewise * rust/compile/issue-1005.rs: likewise * rust/compile/issue-1019.rs: likewise * rust/compile/issue-1031.rs: likewise * rust/compile/issue-1034.rs: likewise * rust/compile/issue-1128.rs: likewise * rust/compile/issue-1129-2.rs: likewise * rust/compile/issue-1130.rs: likewise * rust/compile/issue-1131.rs: likewise * rust/compile/issue-1165.rs: likewise * rust/compile/issue-1173.rs: likewise * rust/compile/issue-1235.rs: likewise * rust/compile/issue-1237.rs: likewise * rust/compile/issue-1289.rs: likewise * rust/compile/issue-1383.rs: likewise * rust/compile/issue-1447.rs: likewise * rust/compile/issue-1589.rs: likewise * rust/compile/issue-1725-1.rs: likewise * rust/compile/issue-1725-2.rs: likewise * rust/compile/issue-1773.rs: likewise * rust/compile/issue-1786.rs: likewise * rust/compile/issue-1893.rs: likewise * rust/compile/issue-1901.rs: likewise * rust/compile/issue-1930.rs: likewise * rust/compile/issue-1981.rs: likewise * rust/compile/issue-2019-1.rs: likewise * rust/compile/issue-2019-2.rs: likewise * rust/compile/issue-2019-3.rs: likewise * rust/compile/issue-2036.rs: likewise * rust/compile/issue-2037.rs: likewise * rust/compile/issue-2070.rs: likewise * rust/compile/issue-2105.rs: likewise * rust/compile/issue-2106.rs: likewise * rust/compile/issue-2135.rs: likewise * rust/compile/issue-2136-1.rs: likewise * rust/compile/issue-2136-2.rs: likewise * rust/compile/issue-2139.rs: likewise * rust/compile/issue-2142.rs: likewise * rust/compile/issue-2165.rs: likewise * rust/compile/issue-2166.rs: likewise * rust/compile/issue-2190-1.rs: likewise * rust/compile/issue-2190-2.rs: likewise * rust/compile/issue-2195.rs: likewise * rust/compile/issue-2238.rs: likewise * rust/compile/issue-2304.rs: likewise * rust/compile/issue-850.rs: likewise * rust/compile/issue-855.rs: likewise * rust/compile/issue-925.rs: likewise * rust/compile/macro-issue1400.rs: likewise * rust/compile/macro20.rs: likewise * rust/compile/macro23.rs: likewise * rust/compile/macro40.rs: likewise * rust/compile/macro54.rs: likewise * rust/compile/name_resolution2.rs: likewise * rust/compile/name_resolution4.rs: likewise * rust/compile/nested_generic.rs: likewise * rust/compile/parse_associated_type_as_generic_arg.rs: likewise * rust/compile/parse_associated_type_as_generic_arg2.rs: likewise * rust/compile/parse_associated_type_as_generic_arg3.rs: likewise * rust/compile/parse_complex_generic_application.rs: likewise * rust/compile/parse_complex_generic_application2.rs: likewise * rust/compile/path_as_generic_arg.rs: likewise * rust/compile/privacy4.rs: likewise * rust/compile/privacy6.rs: likewise * rust/compile/sizeof-stray-infer-var-bug.rs: likewise * rust/compile/stmt_with_block_dot.rs: likewise * rust/compile/torture/associated_types1.rs: likewise * rust/compile/torture/forward_decl_5.rs: likewise * rust/compile/torture/generics1.rs: likewise * rust/compile/torture/generics10.rs: likewise * rust/compile/torture/generics11.rs: likewise * rust/compile/torture/generics12.rs: likewise * rust/compile/torture/generics13.rs: likewise * rust/compile/torture/generics14.rs: likewise * rust/compile/torture/generics15.rs: likewise * rust/compile/torture/generics16.rs: likewise * rust/compile/torture/generics17.rs: likewise * rust/compile/torture/generics18.rs: likewise * rust/compile/torture/generics19.rs: likewise * rust/compile/torture/generics2.rs: likewise * rust/compile/torture/generics20.rs: likewise * rust/compile/torture/generics21.rs: likewise * rust/compile/torture/generics22.rs: likewise * rust/compile/torture/generics23.rs: likewise * rust/compile/torture/generics24.rs: likewise * rust/compile/torture/generics25.rs: likewise * rust/compile/torture/generics26.rs: likewise * rust/compile/torture/generics27.rs: likewise * rust/compile/torture/generics28.rs: likewise * rust/compile/torture/generics29.rs: likewise * rust/compile/torture/generics3.rs: likewise * rust/compile/torture/generics30.rs: likewise * rust/compile/torture/generics31.rs: likewise * rust/compile/torture/generics32.rs: likewise * rust/compile/torture/generics4.rs: likewise * rust/compile/torture/generics5.rs: likewise * rust/compile/torture/generics6.rs: likewise * rust/compile/torture/generics7.rs: likewise * rust/compile/torture/generics8.rs: likewise * rust/compile/torture/generics9.rs: likewise * rust/compile/torture/intrinsics-2.rs: likewise * rust/compile/torture/intrinsics-6.rs: likewise * rust/compile/torture/intrinsics-7.rs: likewise * rust/compile/torture/intrinsics-8.rs: likewise * rust/compile/torture/issue-1024.rs: likewise * rust/compile/torture/issue-1075.rs: likewise * rust/compile/torture/issue-1432.rs: likewise * rust/compile/torture/issue-1555.rs: likewise * rust/compile/torture/issue-368.rs: likewise * rust/compile/torture/issue-808.rs: likewise * rust/compile/torture/issue-862.rs: likewise * rust/compile/torture/issue-893-2.rs: likewise * rust/compile/torture/issue-893.rs: likewise * rust/compile/torture/must_use2.rs: likewise * rust/compile/torture/nested_fn2.rs: likewise * rust/compile/torture/phantom_data.rs: likewise * rust/compile/torture/range-lang-item1.rs: likewise * rust/compile/torture/traits1.rs: likewise * rust/compile/torture/traits11.rs: likewise * rust/compile/torture/traits12.rs: likewise * rust/compile/torture/traits13.rs: likewise * rust/compile/torture/traits14.rs: likewise * rust/compile/torture/traits15.rs: likewise * rust/compile/torture/traits16.rs: likewise * rust/compile/torture/traits17.rs: likewise * rust/compile/torture/traits18.rs: likewise * rust/compile/torture/traits19.rs: likewise * rust/compile/torture/traits2.rs: likewise * rust/compile/torture/traits3.rs: likewise * rust/compile/torture/traits4.rs: likewise * rust/compile/torture/traits5.rs: likewise * rust/compile/torture/traits6.rs: likewise * rust/compile/torture/traits7.rs: likewise * rust/compile/torture/traits8.rs: likewise * rust/compile/torture/traits9.rs: likewise * rust/compile/torture/transmute-size-check-1.rs: likewise * rust/compile/torture/transmute1.rs: likewise * rust/compile/torture/uninit-intrinsic-1.rs: likewise * rust/compile/torture/utf8_identifiers.rs: likewise * rust/compile/traits1.rs: likewise * rust/compile/traits10.rs: likewise * rust/compile/traits11.rs: likewise * rust/compile/traits12.rs: likewise * rust/compile/traits2.rs: likewise * rust/compile/traits3.rs: likewise * rust/compile/traits4.rs: likewise * rust/compile/traits5.rs: likewise * rust/compile/traits6.rs: likewise * rust/compile/traits7.rs: likewise * rust/compile/traits8.rs: likewise * rust/compile/traits9.rs: likewise * rust/compile/type-bindings1.rs: likewise * rust/compile/unconstrained_type_param.rs: likewise * rust/compile/unsafe10.rs: likewise * rust/execute/torture/closure1.rs: likewise * rust/execute/torture/closure2.rs: likewise * rust/execute/torture/closure3.rs: likewise * rust/execute/torture/closure4.rs: likewise * rust/execute/torture/coercion1.rs: likewise * rust/execute/torture/coercion2.rs: likewise * rust/execute/torture/coercion3.rs: likewise * rust/execute/torture/copy_nonoverlapping1.rs: likewise * rust/execute/torture/derive_macro1.rs: likewise * rust/execute/torture/derive_macro3.rs: likewise * rust/execute/torture/derive_macro4.rs: likewise * rust/execute/torture/index1.rs: likewise * rust/execute/torture/issue-1120.rs: likewise * rust/execute/torture/issue-1133.rs: likewise * rust/execute/torture/issue-1198.rs: likewise * rust/execute/torture/issue-1232.rs: likewise * rust/execute/torture/issue-1249.rs: likewise * rust/execute/torture/issue-1436.rs: likewise * rust/execute/torture/issue-1496.rs: likewise * rust/execute/torture/issue-1720-2.rs: likewise * rust/execute/torture/issue-1720.rs: likewise * rust/execute/torture/issue-2052.rs: likewise * rust/execute/torture/issue-2179.rs: likewise * rust/execute/torture/issue-2180.rs: likewise * rust/execute/torture/issue-2236.rs: likewise * rust/execute/torture/issue-647.rs: likewise * rust/execute/torture/issue-845.rs: likewise * rust/execute/torture/issue-851.rs: likewise * rust/execute/torture/issue-858.rs: likewise * rust/execute/torture/macros23.rs: likewise * rust/execute/torture/macros28.rs: likewise * rust/execute/torture/method2.rs: likewise * rust/execute/torture/method3.rs: likewise * rust/execute/torture/method4.rs: likewise * rust/execute/torture/operator_overload_1.rs: likewise * rust/execute/torture/operator_overload_10.rs: likewise * rust/execute/torture/operator_overload_11.rs: likewise * rust/execute/torture/operator_overload_12.rs: likewise * rust/execute/torture/operator_overload_2.rs: likewise * rust/execute/torture/operator_overload_3.rs: likewise * rust/execute/torture/operator_overload_4.rs: likewise * rust/execute/torture/operator_overload_5.rs: likewise * rust/execute/torture/operator_overload_6.rs: likewise * rust/execute/torture/operator_overload_7.rs: likewise * rust/execute/torture/operator_overload_8.rs: likewise * rust/execute/torture/operator_overload_9.rs: likewise * rust/execute/torture/prefetch_data.rs: likewise * rust/execute/torture/ref-pattern2.rs: likewise * rust/execute/torture/slice-magic.rs: likewise * rust/execute/torture/slice-magic2.rs: likewise * rust/execute/torture/slice1.rs: likewise * rust/execute/torture/str-layout1.rs: likewise * rust/execute/torture/trait1.rs: likewise * rust/execute/torture/trait10.rs: likewise * rust/execute/torture/trait11.rs: likewise * rust/execute/torture/trait12.rs: likewise * rust/execute/torture/trait13.rs: likewise * rust/execute/torture/trait2.rs: likewise * rust/execute/torture/trait3.rs: likewise * rust/execute/torture/trait4.rs: likewise * rust/execute/torture/trait5.rs: likewise * rust/execute/torture/trait6.rs: likewise * rust/execute/torture/trait7.rs: likewise * rust/execute/torture/trait8.rs: likewise * rust/execute/torture/trait9.rs: likewise * rust/execute/torture/transmute1.rs: likewise * rust/execute/torture/wrapping_op1.rs: likewise * rust/execute/torture/wrapping_op2.rs: likewise * rust/link/generic_function_0.rs: likewise * rust/link/generic_function_1.rs: likewise * rust/compile/issue-2375.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16gccrs: Track trait bound polarity properlyPhilip Herron1-1/+1
Trait bounds can have three forms in Rust the regular trait bound, '!' the negative trait bound to enforice that this trait must not be implmented and '?' the anti trait bound to remove this bound. This patch extends our Polarity enum to include the Anti trait bound and updates the HIR lowering code to track this properly. Addresses #2443 gcc/rust/ChangeLog: * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): use new BoundPolarity enum * hir/rust-ast-lower-type.cc (ASTLoweringTypeBounds::visit): likewise * hir/rust-hir-dump.cc (BoundPolarityString): new helper (Dump::visit): update hir dump * hir/tree/rust-hir-item.h (class ImplBlock): likewise * hir/tree/rust-hir-type.h (class TraitBound): likewise * hir/tree/rust-hir.cc (TraitBound::as_string): fix as string * util/rust-common.h (enum Polarity): add new anti bound (enum BoundPolarity): likewise * util/rust-hir-map.cc (Mappings::Mappings): update naming Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-01-16gccrs: Remove Location typedefOwen Avery1-1/+1
gcc/rust/ChangeLog: * rust-location.h (typedef Location): Remove. * expand/rust-proc-macro.cc (register_callback): Replace Location constructor with UNDEF_LOCATION. * ast/rust-ast-collector.h: Replace Location with location_t. * checks/errors/privacy/rust-privacy-reporter.cc: Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/privacy/rust-pub-restricted-visitor.cc: Likewise. * checks/errors/privacy/rust-pub-restricted-visitor.h: Likewise. * checks/errors/rust-feature-gate.cc: Likewise. * checks/errors/rust-feature-gate.h: Likewise. * metadata/rust-imports.h: Likewise. * resolve/rust-ast-resolve-path.h: Likewise. * resolve/rust-name-resolver.h: Likewise. * rust-backend.h: Likewise. * rust-diagnostics.h: Likewise. * rust-gcc.cc: Likewise. * rust-linemap.h: Likewise. * util/rust-attributes.cc: Likewise. * util/rust-hir-map.cc: Likewise. * util/rust-hir-map.h: Likewise. * util/rust-token-converter.cc: Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-01-16gccrs: resolve: Remove ProcMacroInvocable interfacePierre-Emmanuel Patry1-6/+6
Since all identifiers in attributes are converted to SimplePath, this common interface is no longer required. gcc/rust/ChangeLog: * ast/rust-ast.h (class Identifier): Remove interface inheritance. (class SimplePath): Likewise. * expand/rust-expand-visitor.cc (get_traits_to_derive): Change return type. (derive_item): Update according to get_traits_to_derive return type. (expand_item_attribute): Likewise. (ExpandVisitor::expand_inner_stmts): Likewise. * expand/rust-macro-expand.h (struct MacroExpander): Likewise. * util/rust-hir-map.cc (Mappings::insert_derive_proc_macro_invocation): Change input type to SimplePath. (Mappings::lookup_derive_proc_macro_invocation): Likewise. (Mappings::insert_attribute_proc_macro_invocation): Likewise. (Mappings::lookup_attribute_proc_macro_invocation): Likewise. * util/rust-hir-map.h: Likewise with function prototypes. * util/rust-proc-macro-invocation.h: Removed. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-01-16gccrs: resolve: Add mappings for proc macros and resolvingPierre-Emmanuel Patry1-21/+85
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>