aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2025-08-05gccrs: Refactor the ParamType to a BaseGeneric base-typePhilip Herron10-56/+82
In order to support const generics we need to abstract away some of the specific ParamType to a BaseGeneric type so we can easily reuse our existing substitution bits for const generics which will mean creating a TyTy::ConstType to wrap up the gcc tree but also represent a const inference and the const decl. gcc/rust/ChangeLog: * backend/rust-compile-intrinsic.cc (sizeof_handler): refactor types (op_with_overflow_inner): likewise (uninit_handler): likewise (move_val_init_handler): likewise * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): likewise * typecheck/rust-hir-trait-resolve.cc: likewise * typecheck/rust-hir-type-check-base.cc: likewise * typecheck/rust-hir-type-check-item.cc: likewise * typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::is_equal): likewise * typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::get_param_ty): likewise (SubstitutionArg::get_param_mapping): likewise (SubstitutionRef::prepare_higher_ranked_bounds): likewise (SubstitutionRef::monomorphize): likewise * typecheck/rust-tyty-subst.h (class BaseGeneric): new generic base * typecheck/rust-tyty.cc (VariantDef::clone): likewise (VariantDef::monomorphized_clone): refactor (ADTType::is_equal): likewise (FnType::is_equal): likewise (ParamType::ParamType): likewise * typecheck/rust-tyty.h (class ParamType): likewise (class BaseGeneric): new base class impl Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: simplify the is_eq on ADTTypePhilip Herron1-4/+1
We dont need to do this resolve we can just let the ParamType's sort this out. gcc/rust/ChangeLog: * typecheck/rust-tyty.cc (ADTType::is_equal): let param::is_eq do this (FnType::is_equal): remove whitespace Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Refactor substitution param mapping to be more abstractPhilip Herron4-27/+59
This is an initial patch required to refactor our generics code to be simpler and more abstract so we return the HIR::GenericParam in ParamMappings instead of assuming its a TypeParam so we can slowly introduce ConstGenericParam into this same flow. gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc: check for type param * typecheck/rust-tyty-subst.cc (SubstitutionParamMapping::SubstitutionParamMapping): return HIR::GenericParam base class (SubstitutionParamMapping::get_generic_param): likewise (SubstitutionParamMapping::get_type_representation): new helper (SubstitutionParamMapping::param_has_default_ty): check for param type (SubstitutionParamMapping::get_default_ty): likewise * typecheck/rust-tyty-subst.h: get the locus from the subst HIR::GenericParam now * typecheck/rust-tyty-variance-analysis.cc (GenericTyPerCrateCtx::debug_print_solutions): likwise (GenericTyVisitorCtx::process_type): likewise Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Fix ICE during const eval of const capacityPhilip Herron2-0/+9
We assert that struct expressions during code-gen must be of TyTy::ADTType but we can simply just check for this and return error_mark_node to make this safe. Fixes Rust-GCC#3960 gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): check for ADTType instead of assert gcc/testsuite/ChangeLog: * rust/compile/issue-3960.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Remove warning for unused `self` parameterRyutaro Okada23-26/+9
gcc/testsuite/ChangeLog: * rust/compile/auto_traits2.rs: emove warning for unused `self` parameter * rust/compile/derive-debug1.rs: emove warning for unused `self` parameter * rust/compile/derive_macro1.rs: Remove warning for unused `self` parameter * rust/compile/format_args_basic_expansion.rs: Remove warning for unused `self` parameter * rust/compile/format_args_extra_comma.rs: Remove warning for unused `self` parameter * rust/compile/issue-2043.rs: Remove warning for unused `self` parameter * rust/compile/issue-2166.rs: Remove warning for unused `self` parameter * rust/compile/issue-2238.rs: Remove warning for unused `self` parameter * rust/compile/issue-2907.rs: Remove warning for unused `self` parameter * rust/compile/min_specialization1.rs: Remove warning for unused `self` parameter * rust/compile/name_resolution2.rs: Remove warning for unused `self` parameter * rust/compile/name_resolution4.rs: Remove warning for unused `self` parameter * rust/compile/torture/generics29.rs: Remove warning for unused `self` parameter * rust/compile/torture/generics30.rs: Remove warning for unused `self` parameter * rust/compile/torture/traits3.rs: Remove warning for unused `self` parameter * rust/compile/torture/traits7.rs: Remove warning for unused `self` parameter * rust/execute/torture/impl_trait3.rs: Remove warning for unused `self` parameter * rust/execute/torture/min_specialization2.rs: Remove warning for unused `self` parameter * rust/execute/torture/trait10.rs: Remove warning for unused `self` parameter * rust/execute/torture/trait11.rs: Remove warning for unused `self` parameter * rust/execute/torture/trait12.rs: Remove warning for unused `self` parameter * rust/execute/torture/trait13.rs: Remove warning for unused `self` parameter * rust/execute/torture/trait9.rs: Remove warning for unused `self` parameter Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05gccrs: Do not warn about unused `self` parameterRyutaro Okada1-1/+3
gcc/rust/ChangeLog: * checks/lints/rust-lint-unused-var.cc (check_decl): Do not warn about unused `self` parameter. Signed-off-by: Ryutaro Okada <1015ryu88@gmail.com>
2025-08-05gccrs: desugar: Add base for desugaring while-let loopsArthur Cohen5-2/+289
gcc/rust/ChangeLog: * Make-lang.in: * ast/rust-expression-yeast.cc (ExpressionYeast::dispatch_loops): Call DesugarWhileLet. * ast/rust-desugar-while-let.cc: New file. * ast/rust-desugar-while-let.h: New file. gcc/testsuite/ChangeLog: * rust/compile/while_let1.rs: New test.
2025-08-05gccrs: Fix AttrInputMacro operator= overloading.Pierre-Emmanuel Patry2-3/+8
gcc/rust/ChangeLog: * ast/rust-ast.cc (AttrInputMacro::operator=): Add return type. * ast/rust-expr.h: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: desugar: Cleanup for-loop desugar implementation.Arthur Cohen2-21/+4
gcc/rust/ChangeLog: * ast/rust-desugar-for-loops.cc: Remove functions implemented in AST::Builder. * ast/rust-desugar-for-loops.h: Likewise.
2025-08-05gccrs: lower: Add assertions for desugared nodesArthur Cohen6-27/+25
gcc/rust/ChangeLog: * hir/rust-ast-lower-base.cc: Add rust_unreachable() when lowering desugared exprs. * hir/rust-ast-lower-base.h: Mention this. * hir/rust-ast-lower-block.h: Remove existing definitions. * hir/rust-ast-lower-expr.cc: Likewise. * hir/rust-ast-lower-expr.h: Likewise. * hir/rust-ast-lower.cc: Likewise.
2025-08-05gccrs: desugar: Add assertions for try-blocks and question-markArthur Cohen2-1/+4
gcc/rust/ChangeLog: * ast/rust-desugar-question-mark.cc (DesugarQuestionMark::go): Add assertion for the expr's type. * ast/rust-desugar-try-block.cc (DesugarTryBlock::go): Likewise.
2025-08-05gccrs: desugar: Add for-loop desugar to ExpressionYeastArthur Cohen5-51/+41
gcc/rust/ChangeLog: * ast/rust-desugar-for-loops.h: Adapt API and remove visitor. * ast/rust-desugar-for-loops.cc: Likewise. * ast/rust-expression-yeast.cc: Call DesugarForLoop. * ast/rust-expression-yeast.h: Declare dispatch_loops function. * rust-session-manager.cc (Session::expansion): Do not call for-loop desugar.
2025-08-05gccrs: hir: Add OffsetOf nodeArthur Cohen28-2/+177
gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.h (class OffsetOf): New. * hir/tree/rust-hir-expr.cc: Define its methods. * hir/tree/rust-hir-expr-abstract.h: Add ExprType::OffsetOf. * hir/tree/rust-hir-full-decls.h (class OffsetOf): Declare it. * backend/rust-compile-block.h: Add handling for OffsetOf. * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise. * backend/rust-compile-expr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.h (RUST_BIR_BUILDER_EXPR_H): Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h (RUST_PRIVACY_REPORTER_H): Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit): Likewise. * checks/errors/rust-hir-pattern-analysis.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/rust-hir-dump.h: Likewise. * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Likewise. * hir/tree/rust-hir-visitor.h: Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h (RUST_HIR_TYPE_CHECK_EXPR): Likewise. gcc/testsuite/ChangeLog: * rust/compile/offset_of2.rs: New test.
2025-08-05gccrs: expand: Add parser for offset_of!() and builtin resolution.Arthur Cohen9-4/+134
gcc/rust/ChangeLog: * Make-lang.in: Compile the offset_of handler. * lang.opt: Add -frust-assume-builtin-offset-of option. * ast/rust-ast.h: Add has_str() for const_TokenPtr. * expand/rust-macro-builtins.cc: Map offset_of as builtin. * expand/rust-macro-builtins.h: Declare it. * expand/rust-macro-expand.cc (MacroExpander::expand_invoc): Add hack for calling builtin offset_of!(). * resolve/rust-early-name-resolver-2.0.cc (Early::visit): Likewise. * expand/rust-macro-builtins-offset-of.cc: New file. gcc/testsuite/ChangeLog: * rust/compile/offset_of1.rs: New test.
2025-08-05gccrs: ast: Add OffsetOf nodeArthur Cohen15-2/+138
gcc/rust/ChangeLog: * ast/rust-ast.h: Add OffsetOf expression kind. * ast/rust-builtin-ast-nodes.h (class OffsetOf): Add node. * ast/rust-ast.cc: Define it. * ast/rust-ast-collector.cc: Add visitor for OffsetOf. * ast/rust-ast-collector.h: Likewise. * ast/rust-ast-visitor.cc: Likewise. * ast/rust-ast-visitor.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Likewise. * hir/rust-ast-lower-expr.h: Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: Likewise. * resolve/rust-early-name-resolver-2.0.cc: Likewise. * expand/rust-derive.h:
2025-08-05gccrs: Error message field member was not properly updatedPierre-Emmanuel Patry1-4/+4
gcc/rust/ChangeLog: * rust-diagnostics.h (struct Error): Add disambiguation. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Fix infinite loop with missing commaPierre-Emmanuel Patry2-1/+16
A missing comma between inline assembly templates did not throw an error and looped indefinitely. gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (parse_format_strings): Emit an error when expecting a comma. gcc/testsuite/ChangeLog: * rust/compile/issue-4006.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Fix semicolon after some namespacePierre-Emmanuel Patry5-9/+9
Remove namespace comment after classes and structs. gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-fact-collector.h: Remove spurious comment. * checks/errors/rust-feature.cc: Likewise. * util/optional.h: Likewise. * expand/rust-token-tree-desugar.cc (TokenTreeDesugar::visit): Remove semicolons on namespace. * expand/rust-token-tree-desugar.h: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: nr1.0: Remove rust/typecheck supportOwen Avery12-401/+119
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::TypeCheckBase): Remove initialization of resolver field. * typecheck/rust-hir-type-check-base.h (TypeCheckBase::resolver): Remove field. * typecheck/rust-hir-trait-resolve.cc: Remove "options.h" include. (TraitResolver::resolve_path_to_trait): Assume name resolution 2.0 is always enabled. * typecheck/rust-hir-type-check-enumitem.cc: Remove "options.h" include. (TypeCheckEnumItem::visit): Assume name resolution 2.0 is always enabled. * typecheck/rust-hir-type-check-expr.cc: Remove "options.h" include. (TypeCheckExpr::visit): Assume name resolution 2.0 is always enabled. (TypeCheckExpr::resolve_operator_overload): Likewise. (TypeCheckExpr::resolve_fn_trait_call): Likewise. * typecheck/rust-hir-type-check-implitem.cc: Remove "options.h" include. (TypeCheckImplItem::visit): Assume name resolution 2.0 is always enabled. * typecheck/rust-hir-type-check-item.cc: Remove "options.h" include. (TypeCheckItem::visit): Assume name resolution 2.0 is always enabled. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_root_path): Likewise. (TypeCheckExpr::resolve_segments): Likewise. * typecheck/rust-hir-type-check-pattern.cc: Remove "options.h" include. (TypeCheckPattern::visit): Assume name resolution 2.0 is always enabled. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. (ResolveWhereClauseItem::visit): Likewise. * typecheck/rust-hir-type-check.cc: Remove "options.h" include. (TraitItemReference::get_type_from_fn): Assume name resolution 2.0 is always enabled. * typecheck/rust-type-util.cc (query_type): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Add execute test for variable and identifiersPierre-Emmanuel Patry2-0/+47
gcc/testsuite/ChangeLog: * rust/execute/inline_asm_inout_ident.rs: New test. * rust/execute/inline_asm_inout_var.rs: New test. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Add input/output from inout and split in outPierre-Emmanuel Patry1-34/+71
Inline assembly was incomplete and input/output from inout or split in out were not handled. gcc/rust/ChangeLog: * backend/rust-compile-asm.cc (get_out_expr): Return valid output from an operand. (CompileAsm::asm_construct_outputs): Handle every output (get_in_expr): Return valid input from an operand. (CompileAsm::asm_construct_inputs): Handle every input Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Parse input and output expressionPierre-Emmanuel Patry1-7/+16
Previously inline assembly expected identifiers instead of expression. gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (parse_reg_operand_inout): Parse expressions and build split in out. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Add pretty hir dump for inline assemblyPierre-Emmanuel Patry3-11/+90
gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::visit): Dump inline assembly fields * hir/tree/rust-hir-expr.h: Add non const getter and avoid operand copy from getters. * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Use non const reference. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Add indexed positional argument support in asmPierre-Emmanuel Patry1-0/+5
gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (expand_inline_asm_strings): Handle transformation for indexed positional arguments. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-08-05gccrs: Implement compilation for SlicePattern against SliceType scrutineeYap Zhi Heng5-2/+114
006t.original output from compiling testsuite/rust/compile/match-slicepattern-slice.rs: ... RUSTTMP.3 = slice; if (RUSTTMP.3.len == 1 && *(RUSTTMP.3.data + 0 * 4) == 1) { { struct () RUSTTMP.4; { } goto <D.129>; } } if (RUSTTMP.3.len == 2 && *(RUSTTMP.3.data + 1 * 4) == 2) { { struct () RUSTTMP.5; { } goto <D.129>; } } if (1) { { struct () RUSTTMP.6; { } goto <D.129>; } } <D.129>:; ... gcc/rust/ChangeLog: * rust-backend.h: New slice_index_expression function. * rust-gcc.cc: Implementation of slice_index_expression to generate tree node for accessing slice elements. * backend/rust-compile-pattern.cc: Implement SlicePattern check expression & binding compilation against SliceType scrutinee. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05gccrs: Update SlicePattern typechecking against slice reference parentsYap Zhi Heng2-4/+19
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit(SlicePattern)): Add new type check case for SliceType wrapped in ReferenceType. * backend/rust-compile-pattern.cc: Adjusted the asserts accordingly for CompilePatternCheckExpr(SlicePattern) & CompilePatternBindings(SlicePattern). Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05gccrs: desugar: Handle try-blocksArthur Cohen5-1/+196
gcc/rust/ChangeLog: * Make-lang.in: Compile it. * ast/rust-expression-yeast.cc (ExpressionYeast::dispatch): Dispatch to try-block desugar. * ast/rust-desugar-try-block.cc: New file. * ast/rust-desugar-try-block.h: New file. gcc/testsuite/ChangeLog: * rust/compile/try_block1.rs: New test.
2025-08-05gccrs: ast: Add Expr::Kind::TryArthur Cohen2-1/+2
gcc/rust/ChangeLog: * ast/rust-ast.h: Add the new variant. * ast/rust-expr.h: Use it for TryExpr class.
2025-08-05gccrs: Handle IfLetExprConseqElse in DefaultResolverOwen Avery2-0/+8
This relies on the DefaultASTVisitor visitor for IfLetExprConseqElse performing a virtual call of the visitor for IfLetExpr, which doesn't hold when DefaultASTVisitor is generated by the X-macro-DSL-system I have in another patch. gcc/rust/ChangeLog: * resolve/rust-default-resolver.cc (DefaultResolver::visit): Add visitor for IfLetExprConseqElse. * resolve/rust-default-resolver.h (DefaultResolver::visit): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: ast: Visit block labels if they are presentArthur Cohen1-0/+5
gcc/rust/ChangeLog: * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Visit a block's loop label if it exists.
2025-08-05gccrs: desugar: Add desugar dispatch for all desugarsArthur Cohen6-56/+157
Since we are doing more and more "external" desugars, as in desugars that take a pointer and replace it with another one, rather than modifying it from within, having an external visitor dispatch to the proper desugar helps with code clarity. gcc/rust/ChangeLog: * Make-lang.in: Compile it. * rust-session-manager.cc: Call the expression desugar dispatcher. * ast/rust-desugar-question-mark.cc: Rework class API. * ast/rust-desugar-question-mark.h: Likewise. * ast/rust-expression-yeast.cc: New file. * ast/rust-expression-yeast.h: New file.
2025-08-05gccrs: chore: ast: Fix formatting in rust-expr.hArthur Cohen1-46/+43
gcc/rust/ChangeLog: * ast/rust-expr.h: Fix formatting.
2025-08-05gccrs: hir: Handle deferred const inference variablesArthur Cohen6-15/+67
gcc/rust/ChangeLog: * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Handle defered consts. * hir/tree/rust-hir-expr.cc (AnonConst::AnonConst): Likewise. (AnonConst::operator=): Likewise. * hir/tree/rust-hir-expr.h: Likewise. * hir/tree/rust-hir-visitor.cc (DefaultHIRVisitor::walk): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/deferred_const_inference.rs: New test.
2025-08-05gccrs: ast: Use AnonConst for array type sizesArthur Cohen6-28/+96
gcc/rust/ChangeLog: * ast/rust-expr.h: Add handling for deferred consts. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast.cc (AnonConst::as_string): Likewise. (ArrayType::as_string): Likewise. * ast/rust-type.h (class ArrayType): Use AnonConst for sizes. * parse/rust-parse-impl.h (Parser::parse_anon_const): New function. (Parser::parse_slice_or_array_type): Call it. * parse/rust-parse.h: Declare it.
2025-08-05gccrs: nr2.0: Handle glob imports of enum variants.Arthur Cohen6-19/+76
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Adapt for enums. (Early::finalize_glob_import): Likewise. * resolve/rust-early-name-resolver-2.0.h: Likewise. * resolve/rust-finalize-imports-2.0.cc (GlobbingVisitor::go): Likewise. (GlobbingVisitor::visit_module_container): New function. (GlobbingVisitor::visit_enum_container): New function. * resolve/rust-finalize-imports-2.0.h: Declare them. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Insert enums as potential containers. gcc/testsuite/ChangeLog: * rust/compile/glob_import_enum.rs: New test.
2025-08-05gccrs: mappings: Change mappings to allow other items as item containers.Arthur Cohen2-10/+12
This is important for importing enum variants as items. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::insert_ast_module): Rename to... (Mappings::insert_glob_container): ...this. (Mappings::lookup_ast_module): Rename to... (Mappings::lookup_glob_container): ...this. * util/rust-hir-map.h: Change declarations.
2025-08-05gccrs: Load modules during CfgStrip phaseOwen Avery2-30/+10
TopLevel would ignore just-loaded modules but Early and ExpandVisitor wouldn't. The latter would produce errors when it hit attributes which should have been indirectly CfgStrip'd away. gcc/rust/ChangeLog: * expand/rust-cfg-strip.cc (CfgStrip::visit): Load unloaded modules. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Assume modules have been loaded by CfgStrip. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Specialize ExpandVisitor::expand_macro_childrenOwen Avery2-30/+13
gcc/rust/ChangeLog: * expand/rust-expand-visitor.cc (ExpandVisitor::expand_inner_items): Adjust call to expand_macro_children. (ExpandVisitor::expand_inner_stmts): Likewise. (ExpandVisitor::visit): Likewise. * expand/rust-expand-visitor.h (ExpandVisitor::expand_macro_children): Take a pointer to member function instead of a std::function. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: fix bad monomophization of generic pathsPhilip Herron3-4/+477
When we have generic paths like T::foobar during codegen sometimes we need to enforce an extra lookup for this generic parameter type to the mono morphized underlying type. Fixes Rust-GCC#3915 Fixes Rust-GCC#1247 gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): do another lookup gcc/testsuite/ChangeLog: * rust/compile/issue-3915.rs: New test. * rust/execute/torture/sip-hasher.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Use MacroInvocLexer in AttributeParserOwen Avery2-31/+51
This should make it easier for us to handle attribute meta items of the form <SimplePath> '=' <Expression> where the expression isn't a literal. Some low hanging fruit remains here, but I think I should keep this patch small as I had some trouble debugging it as-is (see: Rust::Token::as_string vs Rust::Token::get_str vs Rust::AST::Token::as_string). gcc/rust/ChangeLog: * ast/rust-ast.cc: Include "rust-macro-invoc-lexer.h". (AttributeParser::~AttributeParser): Move function definition here. (AttributeParser::AttributeParser): Likewise and adjust member initialization. (AttributeParser::parse_meta_item_inner): Handle changes to peek_token. (AttributeParser::parse_literal): Likewise. (AttributeParser::parse_simple_path_segment): Likewise. (AttributeParser::parse_meta_item_seq): Handle changes to AttributeParser fields. (AttributeParser::peek_token): Move function definition here and wrap MacroInvocLexer. (AttributeParser::skip_token): Likewise. * ast/rust-macro.h (class MacroInvocLexer): Forward declare. (class Parser): Likewise. (AttributeParser::token_stream): Remove field. (AttributeParser::stream_pos): Likewise. (AttributeParser::lexer): New field. (AttributeParser::parser): Likewise. (AttributeParser::AttributeParser): Move definition to "rust-ast.cc". (AttributeParser::~AttributeParser): Likewise. (AttributeParser::peek_token): Likewise. (AttributeParser::skip_token): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: return error node when this fails during constexpr casePhilip Herron1-1/+2
Not adding the test case here we emit more errors than rustc for the error type node so its just noisy and dejagnu is being a pain. Fixes Rust-GCC#3933 gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): return error_mark_node Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Add initial support for deffered operator overload resolutionPhilip Herron10-19/+267
In the test case: fn test (len: usize) -> u64 { let mut i = 0; let mut out = 0; if i + 3 < len { out = 123; } out } The issue is to determine the correct type of 'i', out is simple because it hits a coercion site in the resturn position for u64. But 'i + 3', 'i' is an integer infer variable and the same for the literal '3'. So when it comes to resolving the type for the Add expression we hit the resolve the operator overload code and because of this: macro_rules! add_impl { ($($t:ty)*) => ($( impl Add for $t { type Output = $t; #[inline] #[rustc_inherit_overflow_checks] fn add(self, other: $t) -> $t { self + other } } )*) } add_impl! { usize u8 u16 u32 u64 u128 isize i8 i16 i32 i64 i128 f32 f64 } This means the resolution for 'i + 3' is ambigious because it could be any of these Add implementations. But because we unify against the '< len' where len is defined as usize later in the resolution we determine 'i' is actually a usize. Which means if we defer the resolution of this operator overload in the ambigious case we can simply resolve it at the end. Fixes Rust-GCC#3916 gcc/rust/ChangeLog: * hir/tree/rust-hir-expr.cc (OperatorExprMeta::OperatorExprMeta): track the rhs * hir/tree/rust-hir-expr.h: likewise * hir/tree/rust-hir-path.h: get rid of old comments * typecheck/rust-hir-trait-reference.cc (TraitReference::get_trait_substs): return references instead of copy * typecheck/rust-hir-trait-reference.h: update header * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::ResolveOpOverload): write ambigious operator overloads to a table and try to resolve it at the end * typecheck/rust-hir-type-check-expr.h: new static helper * typecheck/rust-hir-type-check.h (struct DeferredOpOverload): new model to defer resolution * typecheck/rust-typecheck-context.cc (TypeCheckContext::lookup_operator_overload): new (TypeCheckContext::compute_ambigious_op_overload): likewise (TypeCheckContext::compute_inference_variables): likewise gcc/testsuite/ChangeLog: * rust/compile/issue-3916.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Fix ICE with duplicate root item main functionPhilip Herron2-1/+10
Rust seems to allow duplicate HIR::Item 'main' functions but it needs to be a root item to be the true main entry point. This means we can use the canonical path to determine if this is a root one where its CrateName::main or CrateName::Module::main. Fixes Rust-GCC#3978 gcc/rust/ChangeLog: * backend/rust-compile-base.cc: check the canonical path gcc/testsuite/ChangeLog: * rust/compile/issue-3978.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Improve parsing of simple pathsOwen Avery4-67/+85
gcc/rust/ChangeLog: * parse/rust-parse-impl.h (Parser::parse_simple_path): Be more careful about skipping SCOPE_RESOLUTION tokens. (Parser::parse_simple_path_segment): Allow parsing from a starting offset. (Parser::parse_use_tree): Handle a non-skipped SCOPE_RESOLUTION token. * parse/rust-parse.h (Parser::parse_simple_path_segment): Add parameter for parsing from a starting offset. gcc/testsuite/ChangeLog: * rust/compile/parse_simple_path_fail_1.rs: New test. * rust/compile/parse_simple_path_fail_2.rs: New test. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-08-05gccrs: Add test case to show issue is fixedPhilip Herron1-0/+9
Fixes Rust-GCC#3524 gcc/testsuite/ChangeLog: * rust/compile/issue-3524.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: Reject loop in const/static contextlishin3-2/+16
gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Add a catch for const/static. gcc/testsuite/ChangeLog: * rust/compile/loop_constant_context.rs: New test. * rust/compile/issue-3618.rs: Signed-off-by: lishin <lishin1008@gmail.com>
2025-08-05gccrs: Implement compilation for SlicePattern matching against ArrayType ↵Yap Zhi Heng6-2/+127
scrutinee Example GIMPLE output from compiling testsuite/rust/compile/match-pattern-array.rs: ... a[0] = 0; a[1] = 1; RUSTTMP.3 = a; _1 = RUSTTMP.3[0]; _2 = _1 == 0; _3 = RUSTTMP.3[1]; _4 = _3 == 1; _5 = _2 & _4; if (_5 != 0) goto <D.122>; else goto <D.123>; <D.122>: { { } } goto <D.117>; } <D.123>: ... gcc/rust/ChangeLog: * rust-backend.h: New size_constant_expression function. * rust-gcc.cc: Implementation of size_constant_expression function to generate tree node for array access. * backend/rust-compile-pattern.h: Remove empty visits for SlicePattern. * backend/rust-compile-pattern.cc: Implement SlicePattern check expression & binding compilation against ArrayType scrutinee. Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05gccrs: Add size checking to SlicePatternYap Zhi Heng2-3/+25
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc(TypeCheckPattern::visit(SlicePattern)): Implement size checking for SlicePattern when type checking against array parent Signed-off-by: Yap Zhi Heng <yapzhhg@gmail.com>
2025-08-05gccrs: Add test case showing all derives working on enumPhilip Herron1-0/+465
We have more complex test cases already but this will close out this issue. Fixes Rust-GCC#2005 gcc/testsuite/ChangeLog: * rust/execute/torture/issue-2005.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-08-05gccrs: attributes: Add #[test] and #[simd_test]Arthur Cohen2-1/+8
gcc/rust/ChangeLog: * util/rust-attribute-values.h: Add declarations for them. * util/rust-attributes.cc: Add definitions.