aboutsummaryrefslogtreecommitdiff
path: root/gcc
AgeCommit message (Collapse)AuthorFilesLines
2024-11-20FnParam cloning now keeps projectionsPierre-Emmanuel Patry2-1/+6
FnParam type where monomorphized during cloning. gcc/rust/ChangeLog: * typecheck/rust-tyty.h: Reverse monomorphization during cloning and make a new function to explicitly monomorphize. * typecheck/rust-tyty.cc: Use monomorphization when required. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-11-20Fix Generic type retrievalPierre-Emmanuel Patry4-20/+25
gcc/rust/ChangeLog: * hir/rust-ast-lower-type.cc (ASTLowerGenericParam::visit): Forward an optional to the constructor. * hir/tree/rust-hir-item.cc (TypeParam::TypeParam): Use an optional in the constructor. (TypeParam::operator=): Ensure the TypeParam has a type properly. (TypeParam::get_type_mappings): Likewise. * hir/tree/rust-hir-item.h: Wrap the type smart pointer into an optional. * hir/tree/rust-hir.cc (TypeParam::as_string): Unwrap optional type correctly. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-11-20Fixes some tests appearing with a moved variantPierre-Emmanuel Patry13-66/+189
A variant being moved lead to a null being created and a segfault later down the line. gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Call getter instead of size function. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Only check privacy if the type is present. * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): Use an optional. * hir/tree/rust-hir-generic-param.h: Assert type before getting it. * hir/tree/rust-hir-item.h: Assert pointers before dereference, fix has_type condition. * hir/tree/rust-hir-path.h: Add more assertions. * hir/tree/rust-hir-stmt.cc: Change constructor with optionals. * hir/tree/rust-hir-stmt.h: Use optionals over smart pointers to emphasize these fields might be missing. * hir/tree/rust-hir.cc (LetStmt::as_string): Use getters. * typecheck/rust-hir-type-check-expr.cc: Clone structures to prevent parent's fields from being nulled by the move operation. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Use optionals. * typecheck/rust-tyty.cc: Likewise. * typecheck/rust-tyty.h: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-11-20Refactor hir to avoid raw pointers and unneeded fwdPierre-Emmanuel Patry36-3442/+5214
Refactor the hir tree files to remove raw pointer usage and most forward declarations. Move implementation out of headers and split headers into smaller and more manageable units. gcc/rust/ChangeLog: * Make-lang.in: Add new files. * hir/tree/rust-hir-item.h: Move Item definition and remove implementations to their corresponding cc file. * hir/tree/rust-hir-expr.h: Move implementation to the corresponding cc file. * hir/tree/rust-hir-path.h: Likewise. * hir/tree/rust-hir-pattern.h: Likewise. * hir/tree/rust-hir-stmt.h: Likewise. * hir/tree/rust-hir-type.h: Likewise. * hir/tree/rust-hir-visitor.h: Likewise. * hir/tree/rust-hir.h: Likewise. * hir/tree/rust-hir.cc (Crate::Crate): Add implementations from Crate and remove ConstGenericParam implementations to move them to their own file. * hir/tree/rust-hir-attrs.h: New file. * hir/tree/rust-hir-bound-abstract.h: New file. * hir/tree/rust-hir-bound.h: New file. * hir/tree/rust-hir-expr-abstract.h: New file. * hir/tree/rust-hir-expr.cc: New file. * hir/tree/rust-hir-generic-param.cc: New file. * hir/tree/rust-hir-generic-param.h: New file. * hir/tree/rust-hir-item.cc: New file. * hir/tree/rust-hir-literal.h: New file. * hir/tree/rust-hir-node.h: New file. * hir/tree/rust-hir-path.cc: New file. * hir/tree/rust-hir-pattern-abstract.h: New file. * hir/tree/rust-hir-simple-path.h: New file. * hir/tree/rust-hir-stmt.cc: New file. * hir/tree/rust-hir-trait-bound.h: New file. * hir/tree/rust-hir-type-abstract.cc: New file. * hir/tree/rust-hir-type-abstract.h: New file. * hir/tree/rust-hir-type-no-bounds.h: New file. * hir/tree/rust-hir-type.cc: New file. * hir/tree/rust-hir-visibility.h: New file. * hir/tree/rust-hir-visitable.h: New file. * checks/lints/rust-lint-marklive.h: Use References. * hir/rust-ast-lower-expr.cc (ASTLoweringExpr::visit): Reformat vectors. * hir/rust-hir-dump.cc (Dump::visit): Use reference. * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::resolve): Use references. * typecheck/rust-tyty-bounds.cc: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-11-20Refactor HIR with optionals, references & newtypesPierre-Emmanuel Patry19-112/+122
The HIR made heavy use of pair and other unamed types which can be difficult to read. gcc/rust/ChangeLog: * backend/rust-compile-base.cc: Use FnParam getter. * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise. * backend/rust-compile-intrinsic.cc: Likewise. * backend/rust-compile-type.cc: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::visit): Only visit childrens if not missing. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Use a reference instead of a raw pointer. * hir/tree/rust-hir-expr.h: Add presence function for return expression. * hir/tree/rust-hir-item.h: Remove take_param_name. * hir/tree/rust-hir.h: Make mapping getter const. * typecheck/rust-hir-dot-operator.cc (MethodResolver::Select): Use getter. * typecheck/rust-hir-type-check-expr.cc: Likewise. * typecheck/rust-hir-type-check-implitem.cc: Use FnParam vector instead of std::pair of Pattern and BaseType. * typecheck/rust-hir-type-check-item.cc: Likewise. * typecheck/rust-hir-type-check.cc: Likewise. * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Use getters. (TypeCheckMethodCallExpr::check): Likewise. * typecheck/rust-tyty-cmp.h: Likewise. * typecheck/rust-tyty.cc: Use FnParam. * typecheck/rust-tyty.h (class FnParam): Add FnParam to handle function parameters instead of handling std::pairs. * typecheck/rust-unify.cc (UnifyRules::expect_fndef): Use getters. (UnifyRules::expect_fnptr): Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-11-20Refactor HIR to reduce the amount of raw pointersPierre-Emmanuel Patry78-1461/+1382
Attempt to use references and smart pointers whenever possible. gcc/rust/ChangeLog: * backend/rust-compile-base.cc (HIRCompileBase::compile_function_body): Remove usage of get function to retrieve a raw pointer. * backend/rust-compile-base.h: Change API usage from raw pointer to a reference. * backend/rust-compile-block.cc (CompileBlock::compile): Likewise. (CompileBlock::visit): Likewise. (CompileConditionalBlocks::visit): Likewise. * backend/rust-compile-block.h: Likewise. * backend/rust-compile-expr.cc (CompileExpr::Compile): Likewise. (CompileExpr::visit): Likewise. (check_match_scrutinee): Likewise. (CompileExpr::array_value_expr): Likewise. (CompileExpr::array_copied_expr): Likewise. (CompileExpr::generate_closure_function): Likewise. (CompileExpr::generate_possible_fn_trait_call): Likewise. * backend/rust-compile-expr.h: Likewise. * backend/rust-compile-fnparam.cc (CompileFnParam::compile): Likewise. (CompileFnParam::visit): Likewise. * backend/rust-compile-fnparam.h: Likewise. * backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise. * backend/rust-compile-intrinsic.cc (compile_fn_params): Likewise. * backend/rust-compile-item.cc (CompileItem::visit): Likewise. * backend/rust-compile-pattern.cc (CompilePatternCheckExpr::visit): Likewise. (compile_range_pattern_bound): Likewise. (CompilePatternBindings::visit): Likewise. (CompilePatternLet::visit): Likewise. * backend/rust-compile-pattern.h: Likewise. * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Likewise. (HIRCompileBase::query_compile): Likewise. * backend/rust-compile-stmt.cc (CompileStmt::visit): Likewise. * backend/rust-compile-struct-field-expr.cc (CompileStructExprField::Compile): Likewise. (CompileStructExprField::visit): Likewise. * backend/rust-compile-struct-field-expr.h: Likewise. * backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise. * backend/rust-compile-var-decl.h: Likewise. * backend/rust-compile.cc: Likewise. * backend/rust-mangle-v0.cc (v0_inherent_or_trait_impl_path): Likewise. * checks/errors/borrowck/rust-bir-builder-expr-stmt.cc (ExprStmtBuilder::visit): Likewise. * checks/errors/borrowck/rust-bir-builder-lazyboolexpr.h: Likewise. * checks/errors/borrowck/rust-bir-builder-pattern.h: Likewise. * checks/errors/borrowck/rust-bir-builder-struct.h: Likewise. * checks/errors/borrowck/rust-bir-builder.h: Likewise. * checks/errors/borrowck/rust-function-collector.h: Likewise. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_type_privacy): Likewise. (PrivacyReporter::visit): Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/privacy/rust-reachability.cc (ReachabilityVisitor::visit): 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. * checks/lints/rust-lint-marklive.h: Likewise. * hir/rust-hir-dump.cc (Dump::visit): Likewise. * hir/tree/rust-hir-expr.h: Likewise. * hir/tree/rust-hir-item.h: Likewise. * hir/tree/rust-hir-path.h: Likewise. * hir/tree/rust-hir-pattern.h: Likewise. * hir/tree/rust-hir-stmt.h: Likewise. * hir/tree/rust-hir-type.h: Likewise. * hir/tree/rust-hir.h: Likewise. * typecheck/rust-autoderef.cc: 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_impl_item_candidate): Likewise. (PathProbeImplTrait::process_trait_impl_items_for_candidates): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): Likewise. (TraitItemReference::resolve_item): Likewise. * typecheck/rust-hir-type-check-base.cc: Likewise. * typecheck/rust-hir-type-check-base.h: Likewise. * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::Resolve): Likewise. (TypeCheckEnumItem::visit): Likewise. * typecheck/rust-hir-type-check-enumitem.h: Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::Resolve): Likewise. (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_fn_trait_call): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckTopLevelExternItem::Resolve): Likewise. (TypeCheckTopLevelExternItem::visit): Likewise. (TypeCheckImplItem::visit): Likewise. (TypeCheckImplItemWithTrait::visit): Likewise. * typecheck/rust-hir-type-check-implitem.h: Likewise. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. (TypeCheckItem::resolve_impl_item): Likewise. (TypeCheckItem::resolve_impl_block_substitutions): Likewise. (TypeCheckItem::resolve_impl_block_self): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_segments): Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::Resolve): Likewise. (TypeCheckPattern::visit): Likewise. (ClosureParamInfer::Resolve): Likewise. (ClosureParamInfer::visit): Likewise. * typecheck/rust-hir-type-check-pattern.h: Likewise. * typecheck/rust-hir-type-check-stmt.cc (TypeCheckStmt::Resolve): Likewise. (TypeCheckStmt::visit): Likewise. * typecheck/rust-hir-type-check-stmt.h: Likewise. * typecheck/rust-hir-type-check-struct-field.h: Likewise. * typecheck/rust-hir-type-check-struct.cc (TypeCheckStructExpr::TypeCheckStructExpr): Likewise. (TypeCheckStructExpr::Resolve): Likewise. (TypeCheckStructExpr::resolve): Likewise. (TypeCheckStructExpr::visit): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckResolveGenericArguments::resolve): Likewise. (TypeCheckType::Resolve): Likewise. (TypeCheckType::visit): Likewise. (TypeCheckType::resolve_root_path): Likewise. (TypeResolveGenericParam::Resolve): Likewise. (TypeResolveGenericParam::visit): Likewise. (ResolveWhereClauseItem::visit): Likewise. * typecheck/rust-hir-type-check-type.h: Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-hir-type-check.h: Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * typecheck/rust-typecheck-context.cc (TypeCheckContextItem::TypeCheckContextItem): Likewise. * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Likewise. (TypeCheckBase::get_predicate_from_bound): Likewise. * typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit): Likewise. (TypeCheckMethodCallExpr::go): Likewise. (TypeCheckMethodCallExpr::check): Likewise. * typecheck/rust-tyty-subst.cc: Likewise. * typecheck/rust-tyty.cc (BaseType::monomorphized_clone): Likewise. (VariantDef::VariantDef): Remove copy constructor. (VariantDef::operator=): Change to move operator. (VariantDef::get_discriminant): Replace return type to a reference instead of a reference to a unique pointer. (VariantDef::clone): Change to references. (VariantDef::monomorphized_clone): Likewise. (FnType::as_string): Likewise. (FnType::clone): Likewise. * typecheck/rust-tyty.h: Likewise. * util/rust-hir-map.cc (Mappings::insert_hir_impl_block): Likewise. * backend/rust-compile-asm.cc: Use a reference instead of the raw pointer value. * checks/errors/borrowck/rust-bir-builder-pattern.cc: Use references. * checks/errors/rust-hir-pattern-analysis.cc: Likewise. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2024-11-14Improve handling of static items in toplevel 2.0Owen Avery1-6/+3
gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Use DefaultResolver::visit and avoid a call to Identifier::as_string while handling instances of StaticItem. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-11-14Push ribs by kind rather than by valueOwen Avery4-14/+17
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h (ForeverStack::push): Accept argument of type Rib::Kind rather than Rib. * resolve/rust-forever-stack.hxx (ForeverStack::push): Likewise. * resolve/rust-name-resolution-context.cc (NameResolutionContext::scoped): Likewise. * resolve/rust-name-resolution-context.h (NameResolutionContext::scoped): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-11-12gccrs: Fix bad handling for recursive type queryPhilip Herron6-8/+175
When resolving a type like this which is generic it causes the argument substitution to go through bounds checking which is expected. But this can call a type bounds probe which again calls a type query which will be on the Impl Type on an impl block which can result in a recursive type query which does eventually get caught and errors correctly. But this then triggers some old error diagnositcs which are not valid error codes but old error messages we used to catch simple errors very early on which do not apply for this senario. Fixes Rust-GCC#2905 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::resolve_impl_block_substitutions): dont check for unconstrained when the self is not resolved * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): remove bad debug error diagnostic * typecheck/rust-tyty-subst.cc: likewise gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/issue-2905-1.rs: New test. * rust/compile/issue-2905-2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-11-07asm: Fix clang warningsArthur Cohen5-20/+17
Fixes a couple of warnings thrown by clang, with mismatched class/struct usages and unused members. gcc/rust/ChangeLog: * ast/rust-expr.h: Remove invalid usage of `struct`. * backend/rust-compile-asm.h: Remove unused `translated` member. * backend/rust-compile-asm.cc (CompileAsm::CompileAsm): Remove usage of `translated` member. * checks/errors/rust-unsafe-checker.h: Mark visitor as `override`. * hir/tree/rust-hir-expr.h (struct AnonConst): Remove unused `locus` member.
2024-11-07typecheck: Remove unused parameter in TyTyCheckCallExprArthur Cohen1-3/+1
gcc/rust/ChangeLog: * typecheck/rust-tyty-call.h: Remove unused context member.
2024-11-07hir: Mark AttrVec::get_outer_attrs as overrideArthur Cohen1-1/+1
gcc/rust/ChangeLog: * hir/tree/rust-hir.h: Add override qualifier to overriden method.
2024-11-06gccrs: add test case to show issue is fixedPhilip Herron3-8/+40
The original test case 1773 has been moved to a new issue 3242 which is still open and test-case is skipped. The original issue in 1773 is fixed so this will close out that issue Fixes Rust-Gcc#1773 gcc/testsuite/ChangeLog: * rust/compile/issue-1773.rs: new test case * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/issue-3242.rs: old test ranamed to match issue. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-11-06Improve handling of implicit Self parameter in ASTOwen Avery9-57/+21
gcc/rust/ChangeLog: * ast/rust-item.h (Trait::self_param): Add. (Trait::Trait): Initialize self_param. (Trait::operator=): Copy self_param. (Trait::insert_implicit_self): Remove. (Trait::get_implicit_self): Add. * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Make sure implicit self is still lowered to HIR. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Adjust handling of implicit self. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Add commit to Trait visitor mentioning that implicit self is not visited. * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Remove call to Trait::insert_implicit_self. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. * rust/link/generic_function_0.rs: No longer expect failure. * rust/link/trait_import_0.rs: Likewise. * rust/link/trait_import_1.rs (trait Sized): Add. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-11-05gccrs: fix typechecking of Fn trait calls using ADT typesPhilip Herron4-4/+72
Fixes RustGcc#2953 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): fix the ty_id gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle these * rust/compile/issue-2953-1.rs: New test. * rust/compile/issue-2953-2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-11-05gccrs: fix ICE for placeholder which is not setupPhilip Herron1-1/+11
We can have a case where the placeholder is not configred and the can_resolve check is not detecting this case which can lead to ICE. gcc/rust/ChangeLog: * typecheck/rust-tyty.cc (PlaceholderType::can_resolve): check for empty mappings Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-11-05Reorganize the CPU feature detectionAntoni Boucher2-97/+96
Move the code from i386-rust.cc to i386-rust-and-jit.inc so that it can be reused by libgccjit. gcc/ChangeLog: * config/i386/i386-rust-and-jit.inc: New file. * config/i386/i386-rust.cc: Move code to i386-rust-and-jit.inc.
2024-11-05Use name resolver 2.0 for module descendance checksOwen Avery3-7/+53
gcc/rust/ChangeLog: * checks/errors/privacy/rust-privacy-reporter.cc: Include rust-immutable-name-resolution-context.h. (is_child_module): Use ForeverStack::is_module_descendant if name resolution 2.0 is enabled. * resolve/rust-forever-stack.h (ForeverStack::is_module_descendant): Add. (ForeverStack::dfs_node): Add. * resolve/rust-forever-stack.hxx (ForeverStack::dfs_rib): Use ForeverStack::dfs_node. (ForeverStack::dfs_node): Add. (ForeverStack::is_module_descendant): Add. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-11-05Use name resolver 2.0 in VisibilityResolverOwen Avery1-1/+20
gcc/rust/ChangeLog: * checks/errors/privacy/rust-visibility-resolver.cc: Add includes. (VisibilityResolver::resolve_module_path): Use name resolver 2.0 (when enabled) to lookup path resolutions. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-11-04gccrs: fix bad type inference on local patternsPhilip Herron3-1/+12
We do not need to inject inference variables on generic patterns with generic blocks. This will just cause unconstrained inference variables as they may not unify against something. Fixes Rust-GCC#2323 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): dont infer here gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/issue-2323.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-11-04Improve handling of struct expressions in nr2.0Owen Avery2-2/+12
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Handle StructExprStruct and use ForeverStack::resolve_path instead of ForeverStack::get to resolve struct expression paths. * resolve/rust-late-name-resolver-2.0.h (Late::visit): Handle StructExprStruct. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-11-01Remove usage of Resolver::get_builtin_typesOwen Avery3-13/+9
gcc/rust/ChangeLog: * backend/rust-compile-context.cc (Context::setup_builtins): Use TypeCheckContext::get_builtins instead of Resolver::get_builtin_types, TypeCheckContext::lookup_type_by_node_id, and TypeCheckContext::lookup_type. * typecheck/rust-hir-type-check.h (TypeCheckContext::get_builtins): Add. * typecheck/rust-typecheck-context.cc (TypeCheckContext::get_builtins): Add. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-11-01gccrs: fix bad type inferencing on path'sPhilip Herron3-8/+25
This catch to inject inference variables into generic paths was a catch all 'hack' that we needed before we handled generics correctly as we do now. Fixes #3009 gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): remove hack gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/issue-3009.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-11-01Make TyTy::TupleType::get_unit_type cache its return valueOwen Avery10-44/+31
This removes a usage of Resolver::get_unit_type_node_id in rust-hir-type-check-expr.cc (the HIR::TupleExpr overload of TypeCheckExpr::visit). gcc/rust/ChangeLog: * typecheck/rust-tyty.cc (TupleType::get_unit_type): Remove parameter, cache return value. * typecheck/rust-tyty.h (TupleType::get_unit_type): Remove parameter. * resolve/rust-late-name-resolver-2.0.cc (Late::setup_builtin_types): Adjust calls to get_unit_type. * resolve/rust-name-resolver.cc (Resolver::generate_builtins): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): 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-stmt.cc (TypeCheckStmt::visit): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-11-01gccrs: add test case to show method resolution is workingPhilip Herron2-0/+145
The issue here was that the impl block for Cell<T> defines that T must have the bound of Copy implemented. But simultaneously if you do an deref you get direct access to the unsafe cell which also defines a get method so these are two valid ways of accessing the method in question but when Copy is implementet the simplest case is prefered so it does resolve to Cell<T>::get. Fixes #3033 gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr can't handle this * rust/compile/issue-3033.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-10-29Resolve SelfParam in name resolution 2.0Owen Avery3-4/+13
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Handle SelfParam. * resolve/rust-late-name-resolver-2.0.h (Late::visit): Likewise. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-29Use name resolution 2.0 in TraitResolverOwen Avery2-4/+22
gcc/rust/ChangeLog: * typecheck/rust-hir-trait-resolve.cc: Add includes. (TraitResolver::resolve_path_to_trait): Use name resolution 2.0 resolver when enabled. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-28rust: Desugar IfLet* into MatchExprMarc Poulhiès32-477/+260
Replace the "regular" AST->HIR lowering for IfLet* with a desugaring into a MatchExpr. Desugar a simple if let: if let Some(y) = some_value { bar(); } into: match some_value { Some(y) => {bar();}, _ => () } Same applies for IfLetExprConseqElse (if let with an else block). Desugar: if let Some(y) = some_value { bar(); } else { baz(); } into: match some_value { Some(y) => {bar();}, _ => {baz();} } Fixes https://github.com/Rust-GCC/gccrs/issues/1177 gcc/rust/ChangeLog: * backend/rust-compile-block.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * 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: 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: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * hir/rust-ast-lower-block.h (ASTLoweringIfLetBlock::translate): Change return type. * hir/rust-ast-lower.cc (ASTLoweringIfLetBlock::desugar_iflet): New. (ASTLoweringIfLetBlock::visit(AST::IfLetExpr &)): Adjust and use desugar_iflet. * hir/rust-ast-lower.h: Add comment. * hir/rust-hir-dump.cc (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/rust-hir-dump.h (Dump::do_ifletexpr): Remove. (Dump::visit(IfLetExpr&)): Remove. (Dump::visit(IfLetExprConseqElse&)): Remove. * hir/tree/rust-hir-expr.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-full-decls.h (class IfLetExpr): Remove. (class IfLetExprConseqElse): Remove. * hir/tree/rust-hir-visitor.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * hir/tree/rust-hir.cc (IfLetExpr::as_string): Remove. (IfLetExprConseqElse::as_string): Remove. (IfLetExpr::accept_vis): Remove. (IfLetExprConseqElse::accept_vis): Remove. * hir/tree/rust-hir.h: Adjust after removal of HIR::IfLetExpr and HIR::IfLetExprConseqElse. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. * typecheck/rust-hir-type-check-expr.h: Likewise. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::visit (IfLetExpr &)): Remove. (PatternChecker::visit (IfLetExprConseqElse &)): Remove. * checks/errors/rust-hir-pattern-analysis.h (visit(IfLetExpr &)): Remove. (visit(IfLetExprConseqElse &)): Remove. gcc/testsuite/ChangeLog: * rust/compile/if_let_expr.rs: Adjust. * rust/compile/if_let_expr_simple.rs: New test. * rust/compile/iflet.rs: New test. * rust/execute/torture/iflet.rs: New test. * rust/compile/nr2/exclude: Add iflet.rs and if_let_expr_simple.rs Signed-off-by: Marc Poulhiès <dkm@kataplop.net>
2024-10-28Fix name resolution 2.0 definition lookups in unsafe checkerOwen Avery2-10/+38
gcc/rust/ChangeLog: * checks/errors/rust-unsafe-checker.cc: Add includes. (UnsafeChecker::visit): Use 2.0 version of resolver when name resolution 2.0 is enabled. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-28Improve path handling while testing name resolution 2.0Owen Avery2-14/+9
gcc/testsuite/ChangeLog: * rust/compile/nr2/compile.exp: Handle paths using "file join" and "file split". * rust/compile/nr2/exclude: Remove debug-diagnostics-on.rs. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-28Use name resolver 2.0 in CompileTraitItemOwen Avery1-4/+32
gcc/rust/ChangeLog: * backend/rust-compile-implitem.cc (CompileTraitItem::visit): Use name resolver 2.0 (when enabled) to obtain canonical paths for instances of TraitItemConst and TraitItemFunc. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-28Use name resolution 2.0 in TraitItemReferenceOwen Avery1-2/+21
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check.cc: Add includes. (TraitItemReference::get_type_from_fn): Use ForeverStack::to_canonical_path when name resolution 2.0 is enabled. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-28Rename some PathIdentSegment functionsOwen Avery2-15/+24
This makes PathIdentSegment more similar to other classes used to represent path segments. gcc/rust/ChangeLog: * ast/rust-path.h (PathIdentSegment::is_super_segment): Rename to... (PathIdentSegment::is_super_path_seg): ...here. (PathIdentSegment::is_crate_segment): Rename to... (PathIdentSegment::is_crate_path_seg): ...here. (PathIdentSegment::is_lower_self): Rename to... (PathIdentSegment::is_lower_self_seg): ...here. (PathIdentSegment::is_big_self): Rename to... (PathIdentSegment::is_big_self_seg): ...here. (PathExprSegment::is_super_path_seg): Handle renames. (PathExprSegment::is_crate_path_seg): Likewise. (PathExprSegment::is_lower_self_seg): Likewise. (TypePathSegment::is_crate_path_seg): Likewise. (TypePathSegment::is_super_path_seg): Likewise. (TypePathSegment::is_big_self_seg): Likewise. (TypePathSegment::is_lower_self_seg): Likewise. * ast/rust-ast-collector.cc (TokenCollector::visit): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-27Add a newline to the end of nr2/excludeOwen Avery1-1/+2
gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Add trailing newline along with comment. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-27Fix variable shadowing in late resolution 2.0Owen Avery2-5/+8
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Visit the initialization expressions of let statements before visiting their patterns. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-27Insert trait names during toplevel resolution 2.0Owen Avery1-0/+3
gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Insert trait names into the type namespace. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-25gccrs: Fix bad recursive operator overload callPhilip Herron6-6/+134
When we are typechecking the impl block for DerefMut for &mut T the implementation follows the usual operator overload check but this ended up just resolving directly to the Trait definition which ends up being recursive which we usually handle. The issue we had is that a dereference call can be for either the DEREF or DEREF_MUT lang item here it was looking for a recurisve call to the DEREF lang item but we were in the DEREF_MUT lang item so this case was not accounted for. Fixes #3032 gcc/rust/ChangeLog: * typecheck/rust-hir-trait-reference.h: new get locus helper * typecheck/rust-hir-trait-resolve.cc (AssociatedImplTrait::get_locus): implemention * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::resolve_operator_overload): fix overload gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: nr2 cant handle this * rust/compile/issue-3032-1.rs: New test. * rust/compile/issue-3032-2.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2024-10-24Handle external static items in toplevel resolver 2.0Owen Avery2-0/+8
gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Handle ExternalStaticItem. * resolve/rust-toplevel-name-resolver-2.0.h (TopLevel::visit): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-24Use name resolver 2.0 in pattern checkerOwen Avery1-1/+15
gcc/rust/ChangeLog: * checks/errors/rust-hir-pattern-analysis.cc: Add includes. (PatternChecker::visit): Use name resolver 2.0 when enabled. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-24Use name resolver 2.0 for compiling break/continueOwen Avery1-4/+37
gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (CompileExpr::visit): Use name resolver 2.0 to lookup label definitions for break and continue statements when name resolution 2.0 is enabled. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-24Use name resolver 2.0 in const checkerOwen Avery2-4/+15
gcc/rust/ChangeLog: * checks/errors/rust-const-checker.cc: Add includes. (ConstChecker::visit): Use name resolver 2.0 to lookup function definitions when name resolution 2.0 is enabled. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-24Load unloaded modules during toplevel resolution 2.0Owen Avery2-1/+11
This may load conditionally compiled modules too eagerly. gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Load unloaded modules before attempting to visit their items. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove issue-1089.rs. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-24Make const references to ForeverStack more usefulOwen Avery2-4/+102
gcc/rust/ChangeLog: * resolve/rust-forever-stack.h (ForeverStack::to_canonical_path): Make const. (ForeverStack::to_rib): Add const overload. (ForeverStack::reverse_iter): Add const overloads. (ForeverStack::ConstDfsResult): Add. (ForeverStack::dfs): Add const overload. (ForeverStack::dfs_rib): Likewise. * resolve/rust-forever-stack.hxx (ForeverStack::reverse_iter): Add const overloads. (ForeverStack::dfs): Add const overload. (ForeverStack::to_canonical_path): Make const. (ForeverStack::dfs_rib): Likewise. (ForeverStack::to_rib): Add const overload. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-17Use name resolver 2.0 in MarkLiveOwen Avery1-4/+27
gcc/rust/ChangeLog: * checks/lints/rust-lint-marklive.cc (MarkLive::visit_path_segment): Use name resolver 2.0 when enabled. (MarkLive::visit): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-17Handle const generic parameters during resolution 2.0Owen Avery2-0/+9
gcc/rust/ChangeLog: * resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit): Handle ConstGenericParam. * resolve/rust-toplevel-name-resolver-2.0.h (TopLevel::visit): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-17Disambiguate generic args during name resolution 2.0Owen Avery2-0/+34
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Visit GenericArgs and GenericArg, the former because the latter involves a non-virtual member function call. * resolve/rust-late-name-resolver-2.0.h (Late::visit): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-17Fix compiler error on ast wrong implicit construct push_backbadumbatish1-1/+2
gcc/rust/ChangeLog: * expand/rust-macro-builtins-asm.cc (parse_reg_operand_in): Fix compiler error on ast wrong implicit construct push_back
2024-10-17Provide input operand for gccrsbadumbatish5-14/+56
gcc/rust/ChangeLog: * backend/rust-compile-asm.cc (CompileAsm::asm_construct_inputs): Provide input operand for gccrs * expand/rust-macro-builtins-asm.cc (parse_reg_operand_in): Move expr to In (expand_inline_asm_strings): Add comments to debug strings gcc/testsuite/ChangeLog: * rust/compile/inline_asm_parse_operand.rs: Remove inout, functionality not supported. Remove redundant {} * rust/execute/torture/inline_asm_mov_x_5_ARM.rs: Add operand in * rust/execute/torture/inline_asm_mov_x_5_x86_64.rs: Likewise
2024-10-16Use name resolver 2.0 during pattern typecheckingOwen Avery3-8/+26
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-pattern.cc: Add includes. (TypeCheckPattern::visit): Use name resolver 2.0 if enabled. * resolve/rust-name-resolution-context.cc (NameResolutionContext::lookup): Make const qualified. * resolve/rust-name-resolution-context.h (NameResolutionContext::lookup): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2024-10-16Allow identifiers and paths to reference types during nr2.0Owen Avery2-15/+24
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Allow IdentifierExpr and PathInExpression to reference types as well as values, remove ability for IdentifierExpr to reference labels. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>