aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust
AgeCommit message (Collapse)AuthorFilesLines
2025-01-28ast: Add Path::is_lang_item()Arthur Cohen1-0/+2
gcc/rust/ChangeLog: * ast/rust-path.h: New function.
2025-01-28marklive: Fix handling for lang item PathInExpressions.Arthur Cohen1-4/+12
gcc/rust/ChangeLog: * checks/lints/rust-lint-marklive.cc (MarkLive::visit): Adapt to lang items.
2025-01-28hir: Adapt visitors to lang item PathInExpressionsArthur Cohen2-15/+85
gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (ResolvePathRef::visit): Adapt visitor to lang item HIR::PathInExpressions. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise.
2025-01-28hir: Add LangItem paths to PathPattern classArthur Cohen3-8/+104
gcc/rust/ChangeLog: * hir/tree/rust-hir-path.h: Adapt PathPattern to accept lang-item paths. * hir/tree/rust-hir-path.cc: Assert we are dealing with a segmented path, create lang-item constructors. * hir/tree/rust-hir.cc (PathPattern::convert_to_simple_path): Likewise.
2025-01-28ast: More visitors to allow lang item paths in expressionsArthur Cohen7-35/+53
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Adapt visitor to lang item PathInExpressions. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * expand/rust-cfg-strip.cc (CfgStrip::visit): Likewise. * expand/rust-expand-visitor.cc (ExpandVisitor::visit): Likewise. * hir/rust-ast-lower.cc (ASTLoweringExprWithBlock::visit): Likewise. (ASTLowerPathInExpression::visit): Likewise. * resolve/rust-ast-resolve-path.cc (ResolvePath::resolve_path): Likewise. * resolve/rust-early-name-resolver.cc (EarlyNameResolver::visit): Likewise.
2025-01-28lang-items: Add LangItem::IsEnumVariantArthur Cohen2-1/+13
gcc/rust/ChangeLog: * util/rust-lang-item.cc (LangItem::IsEnumVariant): New function. * util/rust-lang-item.h: Declare it.
2025-01-28mappings: Improve error message for get_lang_item_nodeArthur Cohen1-2/+2
gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::get_lang_item_node): Better formatting when a lang item does not exist when it should.
2025-01-28lang-items: Collect enum variants as lang itemsArthur Cohen2-0/+10
gcc/rust/ChangeLog: * ast/rust-collect-lang-items.h: Declare visitor. * ast/rust-collect-lang-items.cc (CollectLangItems::visit): New.
2025-01-28gccrs: catch missing guard for optional resultPhilip Herron1-5/+2
When we lookup here it returns an optional which can lead to a crash because it needs a guard if it has a value. gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): add guard gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: these tests now work it seems Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-01-28Infer crate name after file openingDylan Gardner2-29/+34
Fixes #3129. gcc/rust/ChangeLog: * rust-session-manager.cc (Session::handle_crate_name): Remove crate name inference (Session::compile_crate): Add crate name inference and error if inferred name is empty. Remove CompileOptions::get_instance () that returned a local copy of the options. Rename crate_name_changed to crate_name_found to match semantics. (rust_crate_name_validation_test): Test inferring ".rs" name * rust-session-manager.h: Modify handle_crate_name definition to include filename.
2025-01-24Add captures for ClosureExprInnerTyped with nr2Pierre-Emmanuel Patry2-2/+16
Captures were only processed for regular ClosureExprInner. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add ClosureExprInnerTyped visit implementation. (add_captures): Add a function to avoid code duplication. * resolve/rust-late-name-resolver-2.0.h: Add function prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-01-24Add environment capture to NR2Pierre-Emmanuel Patry6-1/+61
The compiler was still relying on NR1 for closure captures when using nr2 even though the resolver was not used and thus it's state empty. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add environment collection. * resolve/rust-late-name-resolver-2.0.h: Add function prototype. * resolve/rust-name-resolver.cc (Resolver::get_captures): Add assertion to prevent NR2 usage with nr1 capture functions. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Use nr2 captures. * util/rust-hir-map.cc (Mappings::add_capture): Add function to register capture for a given closure. (Mappings::lookup_captures): Add a function to lookup all captures available for a given closure. * util/rust-hir-map.h: Add function prototypes. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-01-23Check for type paths nr2.0 can't handle yetOwen Avery1-0/+8
Some of our tests only work with name resolution 2.0 because the latter misinterprets type paths. This change should cause the compiler to error out if it would otherwise misinterpret a type path. A fix for type path resolution isn't included in this comment, since doing so would make it harder to track the meaningfulness of test regressions. gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Error out if a type path has multiple segments, as we currently ignore every segment except the last. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Add entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-01-23backend: Allow anything as a match scrutineeArthur Cohen1-5/+1
gcc/rust/ChangeLog: * backend/rust-compile-expr.cc (check_match_scrutinee): Allow anything to be used as a match scrutinee, not just ADTs.
2025-01-21lang-items: Add Result and Try lang itemsArthur Cohen2-0/+20
gcc/rust/ChangeLog: * util/rust-lang-item.h: Add handling for Result::Ok, Result::Err, Try, Try::into_result, Try::from_ok, Try::from_err. * util/rust-lang-item.cc: Likewise. gcc/testsuite/ChangeLog: * rust/compile/try-trait.rs: New test.
2025-01-21Fix rust breakage with nr2Pierre-Emmanuel Patry6-40/+141
Nr2 did not emit the correct error message for break identifier "rust". gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add "rust" identifier detection akin to nr1. (funny_ice_finalizer): Copy ICE finalizer from nr1. * resolve/rust-late-name-resolver-2.0.h: Add funny_error member context state. * Make-lang.in: Add new translation unit for new ice finalizer. * resolve/rust-ast-resolve-expr.cc: Move ice finalizer to it's own file. * resolve/rust-ice-finalizer.cc: New file. * resolve/rust-ice-finalizer.h: New file. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove break-rust3.rs from exclude list. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
2025-01-21derive(Copy): Improve bounds when deriving CopyArthur Cohen1-2/+7
gcc/rust/ChangeLog: * expand/rust-derive-copy.cc: Always add an extra Copy bound on generic Copy impls.
2025-01-21derive(Clone): Use lang item bounds on AssertParamIsCopyArthur Cohen1-6/+5
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::visit_union): Use lang items for Copy and Sized bounds. gcc/testsuite/ChangeLog: * rust/compile/derive_macro6.rs: Add lang item attribute to Copy trait.
2025-01-21derive(Clone): Add Clone bound on generated impl blocksArthur Cohen1-6/+11
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc: Add extra bound when deriving generic Clone
2025-01-21ast-builder: Add extra parameter for TypeParam builderArthur Cohen2-2/+8
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::new_type_param): Add optional extra trait bounds. * ast/rust-ast-builder.h: Likewise.
2025-01-21hir-dump: Improve handling of typepathsegments that are lang items.Arthur Cohen1-1/+4
gcc/rust/ChangeLog: * hir/rust-hir-dump.cc (Dump::do_typepathsegment): Add handling for lang items.
2025-01-21lang-item:Add LangItem::Kind::RECEIVERlishin2-0/+2
Add and implement a lang item (receiver) in source code. gcc/rust/ChangeLog: * util/rust-lang-item.cc: Add receiver to map. * util/rust-lang-item.h: Define LangItem::Kind::RECEIVER. gcc/testsuite/ChangeLog: * rust/compile/issue-2954.rs: New test. Signed-off-by: lishin <lishin1008@gmail.com>
2025-01-21typecheck: Add basic handling for applying auto trait boundsArthur Cohen4-5/+28
gcc/rust/ChangeLog: * hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Register auto traits in mappings. * util/rust-hir-map.cc (Mappings::insert_auto_trait): New. (Mappings::get_auto_traits): New. * util/rust-hir-map.h: Declare them. * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): Add auto trait bounds when scanning. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Some parts of nr2.0 can't handle auto traits yet. * rust/compile/auto_traits3.rs: Removed in favor of... * rust/compile/auto_traits2.rs: ...this one. * rust/compile/auto_traits4.rs: New test.
2025-01-21typecheck: Separate assemble_builtin_candidate in twoArthur Cohen2-3/+10
This paves the way for adding trait bounds that aren't necessarily Sized. gcc/rust/ChangeLog: * typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::add_trait_bound): New function. * typecheck/rust-hir-type-bounds.h: Declare it. (TypeBoundsProbe::assemble_builtin_candidate): Call into add_trait_bound.
2025-01-20nr2.0: late: Better format PathInExpression resolutionArthur Cohen1-12/+6
gcc/rust/ChangeLog: * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Improve formatting.
2025-01-20derive(Clone): Implement derive clone for enum struct variantsArthur Cohen1-7/+78
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::clone_enum_struct): New function for deriving enum struct variants. (DeriveClone::visit_enum): Call into the new function. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: * rust/compile/derive_clone_enum1.rs: New test. * rust/compile/derive_clone_enum2.rs: New test. * rust/compile/derive_clone_enum3.rs: New test. * rust/execute/torture/derive_clone_enum1.rs: New test.
2025-01-20derive(Clone): Implement clone for enum tuple variantsArthur Cohen2-4/+66
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::variant_match_path): New function. (DeriveClone::clone_enum_identifier): Rename. (DeriveClone::clone_enum_tuple): New function. (DeriveClone::visit_enum): Visit tuple variants properly. * expand/rust-derive-clone.h: Declare new functions.
2025-01-20ast-builder: Add new methods for building structsArthur Cohen2-2/+15
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc: Add new methods for constructing struct exprs. * ast/rust-ast-builder.h: Mention how to build tuple expressions.
2025-01-20derive(Clone): Add deriving of simple enum variantsArthur Cohen2-2/+53
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc: Clone enum identifier variants properly * expand/rust-derive-clone.h: Declare new functions used.
2025-01-20derive(Clone): Add note about Clone::clone()Arthur Cohen1-4/+10
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::clone_call): Mention using `clone_fn` lang item in the future.
2025-01-20derive(Clone): Use lang item for PhantomData in CloneArthur Cohen1-1/+1
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::visit_union): Create a lang item path instead of a regular path.
2025-01-20ast-builder: Add new methods around type paths.Arthur Cohen2-3/+67
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc: New functions. * ast/rust-ast-builder.h: Declare them.
2025-01-20derive(Copy): Use copy lang item when deriving Copy.Arthur Cohen1-6/+2
gcc/rust/ChangeLog: * expand/rust-derive-copy.cc: Use lang item path.
2025-01-20derive(Clone): Manually generate AssertParamIsCopy struct for unionsArthur Cohen1-4/+34
gcc/rust/ChangeLog: * expand/rust-derive-clone.cc (DeriveClone::visit_union): Manually generate the struct used for asserting a union implements Copy.
2025-01-20builder: Allow generating struct statementsArthur Cohen2-0/+46
gcc/rust/ChangeLog: * ast/rust-ast-builder.cc (Builder::struct_struct): New function. * ast/rust-ast-builder.h (vec): New function.
2025-01-16ast-collector: Fix tuple struct pattern collectionArthur Cohen1-4/+1
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Visit tuple pattern items as separated by commas.
2025-01-16ast-collector: Adapt to lang item type path segmentsArthur Cohen1-8/+15
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Fix collector to better handle lang item type path segments.
2025-01-16mappings: Add get_lang_item_nodeArthur Cohen2-0/+11
This method errors out if the lang item has not been declared yet. gcc/rust/ChangeLog: * util/rust-hir-map.cc (Mappings::get_lang_item_node): New. * util/rust-hir-map.h: New function.
2025-01-16lang-item: Add LangItem::PrettyStringArthur Cohen2-0/+7
Which formats a lang item as it appears in source code. gcc/rust/ChangeLog: * util/rust-lang-item.cc (LangItem::PrettyString): New. * util/rust-lang-item.h: New.
2025-01-16lang-items: Collect struct lang items.Arthur Cohen2-0/+10
gcc/rust/ChangeLog: * ast/rust-collect-lang-items.cc (CollectLangItems::visit): New. * ast/rust-collect-lang-items.h: New.
2025-01-16lower: Properly lower non-generic lang item type path segments.Arthur Cohen1-26/+14
gcc/rust/ChangeLog: * hir/rust-ast-lower-type.cc (ASTLowerTypePath::visit): Adapt code to lang item type path segments.
2025-01-16tychk: resolve lang item type paths properlyArthur Cohen1-9/+17
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Adapt code to handle lang item type paths.
2025-01-16ast: Refactor how lang item paths are handled.Arthur Cohen26-546/+311
Lang item typepaths were not handled properly, and required a complete overhaul. All old classes that concerned lang item paths are now modified to use a simpler version of `AST::LangItemPath`, which has been removed. TypePath segments can now be lang items, as this is requied for having generic lang item paths such as PhantomData<T>. gcc/rust/ChangeLog: * ast/rust-path.h: Rework how lang item paths are represented. * ast/rust-path.cc: Likewise. * ast/rust-item.h: Likewise. * ast/rust-ast.cc: Likewise. * ast/rust-ast-collector.cc: Adapt to new lang item path system. * ast/rust-ast-collector.h: Likewise. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Likewise. * ast/rust-ast-visitor.h: Likewise. * expand/rust-derive-copy.cc: Likewise. * expand/rust-derive.h: Likewise. * hir/rust-ast-lower-base.cc (ASTLoweringBase::visit): Likewise. * hir/rust-ast-lower-base.h: Likewise. * hir/rust-ast-lower-type.cc (ASTLowerTypePath::translate): Likewise. (ASTLowerTypePath::visit): Likewise. * hir/rust-ast-lower-type.h: Likewise. * resolve/rust-ast-resolve-base.cc (ResolverBase::visit): Likewise. * resolve/rust-ast-resolve-base.h: Likewise. * resolve/rust-ast-resolve-item.cc (ResolveItem::visit): Likewise. * resolve/rust-ast-resolve-type.h: Likewise. * resolve/rust-ast-resolve-type.cc (ResolveRelativeTypePath::go): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise. * resolve/rust-late-name-resolver-2.0.h: Likewise. * hir/tree/rust-hir-path.cc (TypePathSegment::TypePathSegment): Likewise. (TypePathSegmentGeneric::TypePathSegmentGeneric): Likewise. * hir/tree/rust-hir-path.h: Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. * ast/rust-ast-builder.cc: Likewise. * ast/rust-ast-builder.h: Likewise.
2025-01-16collect-lang-items: Display attribute upon error finding itArthur Cohen1-1/+2
gcc/rust/ChangeLog: * ast/rust-collect-lang-items.cc (get_lang_item_attr): Show unknown attribute upon error.
2025-01-16attributes: Add #[derive] as a built-in attributeArthur Cohen2-0/+2
gcc/rust/ChangeLog: * util/rust-attribute-values.h: Declare new attribute value. * util/rust-attributes.cc: Use it.
2025-01-16ast: Fix warning about copy elision for moved exprArthur Cohen1-1/+1
gcc/rust/ChangeLog: * ast/rust-ast.cc (BlockExpr::normalize_tail_expr): Remove overzealous std::move
2025-01-13Remove dead code related to external functionsOwen Avery9-451/+0
gcc/rust/ChangeLog: * ast/rust-ast-collector.cc (TokenCollector::visit): Remove visitor for NamedFunctionParam. * ast/rust-ast-collector.h (TokenCollector::visit): Likewise. * ast/rust-ast-full-decls.h (class NamedFunctionParam): Remove forward declaration. * ast/rust-ast-visitor.cc (DefaultASTVisitor::visit): Remove visitor for NamedFunctionParam. * ast/rust-ast-visitor.h (DefaultASTVisitor::visit): Likewise. * ast/rust-ast.cc (NamedFunctionParam::as_string): Remove. * ast/rust-item.h (class NamedFunctionParam): Remove. (class ExternalFunctionItem): Remove. * parse/rust-parse-impl.h (Parser::parse_named_function_param): Remove. (Parser::parse_named_function_params): Remove. * parse/rust-parse.h (Parser::parse_named_function_param): Remove. (Parser::parse_named_function_params): Remove. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-01-13nr2.0: Early resolve pending eager macro invocationsOwen Avery1-0/+4
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::visit): Resolve the pending eager invocations inside builtin macro invocations. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
2025-01-13gccrs: Add missing name resolution to static items in blocksPhilip Herron4-0/+29
We need to add name resolution and hir lowering for items as part of blocks in order to typecheck and compile them correctly. Fixes Rust-GCC#3350 gcc/rust/ChangeLog: * hir/rust-ast-lower-stmt.cc (ASTLoweringStmt::visit): hir lowering * hir/rust-ast-lower-stmt.h: likewise * resolve/rust-ast-resolve-stmt.cc (ResolveStmt::visit): name resolution * resolve/rust-ast-resolve-stmt.h: likewise gcc/testsuite/ChangeLog: * rust/compile/issue-3350.rs: New test. Signed-off-by: Philip Herron <herron.philip@googlemail.com>
2025-01-10Revert "gcc/rust/ChangeLog:"CohenArthur3-11/+6
This reverts commit 600fd806b8821ea24103ea0f31d666077245c6b7.