Philip Herron [Thu, 27 Mar 2025 17:27:56 +0000 (17:27 +0000)]
gccrs: Fix ICE during const expr eval on array expressions
Array expressions are still getting turned into VIEW_CONVERT_EXPR's becuase
TYPE_MAIN_VARIANT is not set so then we might as well reuse the type-hasher
to sort this out.
Fixes Rust-GCC#3588
gcc/rust/ChangeLog:
* backend/rust-compile-context.h: only push named types
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): run the type hasher
gcc/testsuite/ChangeLog:
* rust/compile/issue-3588.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Lowercase self suffix with path was not resolved properly, this should
point to the module right before.
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.hxx: Add a new specialized function
to retrieve the last "real" segment depending on the namespace.
* resolve/rust-forever-stack.h: Add new function prototype.
* resolve/rust-early-name-resolver-2.0.cc (Early::finalize_rebind_import):
Set declared name according to the selected segment, if there is a self
suffix in the use declaration then select the previous segment.
Philip Herron [Thu, 27 Mar 2025 15:15:08 +0000 (15:15 +0000)]
gccrs: Give the builtin unit struct an actual locus
This has been a pet peeve of mine for a while because the gimple never
emitted the struct () name properly it was always empty which for record
types they always require a real locus or they dont get a proper name.
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc (HIRCompileBase::unit_expression): pass ctx
* backend/rust-compile-base.h: cant be static
* backend/rust-compile-intrinsic.cc (try_handler_inner): pass ctx
* backend/rust-compile-type.cc
(TyTyResolveCompile::get_unit_type): update to grab the first locus
(TyTyResolveCompile::visit): pass ctx
* backend/rust-compile-type.h: likewise
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Thu, 27 Mar 2025 12:04:41 +0000 (12:04 +0000)]
gccrs: Fix ICE when compiling block expressions in array capacity
We need to reuse the existing compile_constant_item helper which handles
the case if this is a simple expression, fn-call or a block expression.
The patch extracts out this helper as a static method so this can be used
in more places.
Philip Herron [Wed, 26 Mar 2025 19:00:41 +0000 (19:00 +0000)]
gccrs: Add check for super traits being implemented by Self
We need to recursively check the super traits of the predicate the Self
type is trying to implement. Otherwise its cannot implement it.
Fixes Rust-GCC#3553
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::resolve_impl_block_substitutions):
Track the polarity
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::validate_type_implements_this):
new validator
* typecheck/rust-tyty.h: new prototypes
gcc/testsuite/ChangeLog:
* rust/compile/issue-3553.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Wed, 26 Mar 2025 17:11:36 +0000 (17:11 +0000)]
gccrs: Fix ICE when array elements are not a value
We need to check for error_mark_node when doing adjustments from coercion
sites otherwise we hit assetions as part of the coercion. That fixes the
ICE but the reason for the error_mark_node is because the array element
value.
Fixes Rust-GCC#3567
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::array_value_expr): add value chk for array expr
gcc/testsuite/ChangeLog:
* rust/compile/issue-3567.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Wed, 26 Mar 2025 14:05:03 +0000 (14:05 +0000)]
gccrs: fix unconstrained infer vars on generic associated type
The trick here is that when Bar::test is resolved it resolves to the
trait method:
fn <Bar<i32>, T> (placeholder) -> placeholder
Which is fine so we need to setup the associated types for Bar<i32> which
means looking up the associated impl block then setting up the projection
of A = T so it becomes:
The issue is that the binding of the generics was still T so this caused
inference variables to be injected again but unlinked. A possible tweak
would be that we are substituting again with new infer vars to actually
just unify them enplace so they are all part of the chain. This still
might be needed but lets hold off for now.
So basically when we are Path probing we dont allow GAT's to generate new
inference vars because they wont be bound to this current segment which
just causes confusion.
Fixes Rust-GCC#3242
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-reference.h: add default infer arg
* typecheck/rust-hir-trait-resolve.cc: dont add new infer vars
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): dont infer
gcc/testsuite/ChangeLog:
* rust/compile/issue-3242.rs: no longer skip the test
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Owen Avery [Tue, 25 Mar 2025 22:18:21 +0000 (18:18 -0400)]
Fix validation of constant items
gcc/rust/ChangeLog:
* checks/errors/rust-ast-validation.cc
(ASTValidation::visit): Allow constant items lacking expressions
if and only if they're associated with a trait definition, not a
trait implementation.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3541-1.rs: New test.
* rust/compile/issue-3541-2.rs: Likewise.
Arthur Cohen [Mon, 24 Mar 2025 14:32:51 +0000 (15:32 +0100)]
rust: Lower minimum supported Rust version to 1.49
gcc/rust/ChangeLog:
* checks/errors/borrowck/ffi-polonius/Cargo.lock: Regenerate.
* checks/errors/borrowck/ffi-polonius/Cargo.toml: Update to use source patching instead of
vendoring, lower edition to 2018.
* checks/errors/borrowck/ffi-polonius/vendor/log/Cargo.toml: Change edition to 2018.
* checks/errors/borrowck/ffi-polonius/vendor/log/src/lib.rs: Remove uses of unstable
feature.
* checks/errors/borrowck/ffi-polonius/.cargo/config.toml: Removed.
libgrust/ChangeLog:
* libformat_parser/Makefile.am: Avoid using --config as it is unsupported by cargo 1.49.
* libformat_parser/Makefile.in: Regenerate.
* libformat_parser/generic_format_parser/src/lib.rs: Use extension trait for missing
features.
* libformat_parser/src/lib.rs: Likewise.
* libformat_parser/.cargo/config: Moved to...
* libformat_parser/.cargo/config.toml: ...here.
Owen Avery [Thu, 20 Mar 2025 16:17:20 +0000 (12:17 -0400)]
nr2.0: Fix test const_generics_3.rs
gcc/testsuite/ChangeLog:
* rust/compile/const_generics_3.rs: Modify test to run with name
resolution 2.0 only and to handle the absence of a bogus
resolution error.
* rust/compile/nr2/exclude: Remove const_generics_3.rs.
Those tests are coming from libcore and module inlining was wrong, in
libcore there was a use declaration to import those modules which was
missing here.
Function could not be found and triggered an error message.
gcc/testsuite/ChangeLog:
* rust/compile/feature_rust_attri0.rs: Add extern
function declaration and change name to printf.
* rust/compile/nr2/exclude: Remove now passing test from exclusion
list.
Sam James [Mon, 17 Mar 2025 17:17:43 +0000 (17:17 +0000)]
ci: disable network
Disable network access via 'unshare' in two CI workflows to catch issues
like PR119333 where importing polonius meant bootstrap tried to pull crates
from the internet.
ChangeLog:
PR rust/119333
* .github/workflows/bootstrap.yml: Disable network via 'unshare'.
* .github/workflows/ccpp.yml: Ditto.
Philip Herron [Sat, 22 Mar 2025 17:40:48 +0000 (17:40 +0000)]
gccrs: support generic super traits recursively
In order to handle generic super traits on any trait bound we need to ensure
we track the TypeBoundPredicate as part of the TraitReference instead of just
the raw TraitReferences because these will have any applied generics enplace.
Then for any TypeBoundPredicate it takes a copy of the super traits because
this is the usage of a TraitBound and we can apply generics which then need
to be recursively applied up the chain of super predicates.
The main tweak is around TypeBoundPredicate::lookup_associated_item because
we need to associate the predicate with the item we are looking up so the caller
can respect the generics correctly as well.
Fixes Rust-GCC#3502
gcc/rust/ChangeLog:
* typecheck/rust-hir-path-probe.cc: update call
* typecheck/rust-hir-trait-reference.cc (TraitReference::lookup_trait_item): track predicate
(TraitReference::is_equal): likewise
(TraitReference::is_object_safe): likewise
(TraitReference::satisfies_bound): likewise
* typecheck/rust-hir-trait-reference.h: likewise
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_trait): likewise
* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::TypeBoundPredicate): track super traits
(TypeBoundPredicate::operator=): likewise
(TypeBoundPredicate::apply_generic_arguments): ensure we apply to super predicates
(TypeBoundPredicateItem::operator=): take copy of parent predicate
(TypeBoundPredicateItem::error): pass error instead of nullptr
(TypeBoundPredicateItem::is_error): update to no longer check for nullptr
(TypeBoundPredicateItem::get_parent): updated
(TypeBoundPredicateItem::get_tyty_for_receiver): likewise
(TypeBoundPredicate::get_associated_type_items): likewise
* typecheck/rust-tyty-bounds.h (class TypeBoundPredicateItem): move
* typecheck/rust-tyty-subst.cc: flag to handle placeholder Self on traits
* typecheck/rust-tyty-subst.h (class TypeBoundPredicateItem): likewise
* typecheck/rust-tyty.h (class TypeBoundPredicateItem): refactored
gcc/testsuite/ChangeLog:
* rust/execute/torture/issue-3502.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Arthur Cohen [Tue, 18 Mar 2025 10:39:54 +0000 (11:39 +0100)]
polonius: Vendor Rust dependencies
This fixes PR #119333 by allowing our borrow-checker interface to be built
offline. This was already done for our components in libgrust/, but had never been
done for the borrow-checker.
* checks/errors/borrowck/ffi-polonius/.cargo/config.toml: New file, force vendored deps.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/.cargo-checksum.json: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/CODE_OF_CONDUCT.md: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/Cargo.toml: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/LICENSE-APACHE: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/LICENSE-MIT: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/README.md: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/RELEASES.md: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/examples/borrow_check.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/examples/graspan1.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/src/join.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/src/lib.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/src/map.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/src/test.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/datafrog/src/treefrog.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/.cargo-checksum.json: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/CHANGELOG.md: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/Cargo.toml: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/LICENSE-APACHE: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/LICENSE-MIT: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/README.md: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/benches/value.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/src/__private_api.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/src/kv/error.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/src/kv/key.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/src/kv/mod.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/src/kv/source.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/src/kv/value.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/src/lib.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/src/macros.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/src/serde.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/log/triagebot.toml: New file.
* checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/.cargo-checksum.json: New file.
* checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/Cargo.toml: New file.
* checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/README.md: New file.
* checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/facts.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/lib.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/output/datafrog_opt.rs:
New file.
* checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/output/initialization.rs:
New file.
* checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/output/liveness.rs:
New file.
* checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/output/location_insensitive.rs:
New file.
* checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/output/mod.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/polonius-engine/src/output/naive.rs: New file.
* checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/.cargo-checksum.json: New file.
* checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/CODE_OF_CONDUCT.md: New file.
* checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/Cargo.toml: New file.
* checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/LICENSE-APACHE: New file.
* checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/LICENSE-MIT: New file.
* checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/README.md: New file.
* checks/errors/borrowck/ffi-polonius/vendor/rustc-hash/src/lib.rs: New file.
Owen Avery [Wed, 19 Mar 2025 00:28:25 +0000 (20:28 -0400)]
nr2.0: Adjust indentifier expression handling
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Make sure to return early after a resolution
error, improve the resolution error message, fix a typo, handle
ambiguous resolutions, and remove an old comment.
Owen Avery [Sun, 9 Feb 2025 08:28:43 +0000 (03:28 -0500)]
nr2.0: Adjust visitors for struct expressions
gcc/rust/ChangeLog:
* ast/rust-ast-visitor.cc
(DefaultASTVisitor::visit): Make sure to always visit the struct
name.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Avoid visiting the struct name twice.
Owen Avery [Sun, 9 Feb 2025 20:16:59 +0000 (15:16 -0500)]
nr2.0: Fix test self-path2.rs
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-path.cc
(ResolvePath::resolve_path): Adjust the error message for a lower
self segment in the middle of a path.
* resolve/rust-ast-resolve-type.cc
(ResolveRelativeTypePath::go): Likewise.
Liam Naddell [Tue, 11 Feb 2025 21:42:41 +0000 (16:42 -0500)]
Fix modules with same name as builtins causing ICE (#3315)
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h (ForeverStack): Add a dedicated prelude node for
the Language prelude
* resolve/rust-forever-stack.hxx (ForeverStack): Add support code for the
prelude node
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Move
language prelude builtins to the prelude context
* resolve/rust-name-resolution-context.cc
(NameResolutionContext::scoped): Add code for handling
the prelude corner case
* resolve/rust-rib.h (Rib::Kind): Add a special Prelude rib type
gcc/testsuite/ChangeLog:
* rust/compile/issue-3315-1.rs: Add test for module with same name
as builtin
* rust/compile/issue-3315-2.rs: Test with utilization of i32
type
* rust/compile/nr2/exclude: issue-3315-2.rs Does not work with
NR2.0
Add a function to get the crate number from node id
gcc/rust/ChangeLog:
* util/rust-hir-map.cc (Mappings::lookup_crate_num): Add function to
retrieve crate number from it's node id.
(Mappings::node_is_crate): change function with call to
lookup_crate_num to avoid looping through all crates.
(Mappings::insert_ast_crate): Populate node id to crate number map.
* util/rust-hir-map.h: Change function prototype.
Import mapping was relying on resolve_path which in turn relies on
the cursor function. This means the mapping resolver should be called
from the correct scope instead of being called from the crate scope.
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc (Early::Early): Move the
top level visitor from the function scope to attributes.
(Early::go): Remove top level visitor creation and adapt calling code.
Remove call to mapping resolution and import finalization.
(Early::finalize_simple_import): Move the finalization from it's
visitor.
(Early::finalize_glob_import): Likewise.
(Early::finalize_rebind_import): Likewise.
(Early::visit): Add mapping resolution and finalization in
UseDeclaration visitor function.
* resolve/rust-finalize-imports-2.0.cc (finalize_simple_import): Move
function.
(finalize_glob_import): Likewise.
(finalize_rebind_import): Likewise.
(FinalizeImports::visit): Remove call to finalizers.
* resolve/rust-early-name-resolver-2.0.h (class Early): Add top level
attribute.
* resolve/rust-finalize-imports-2.0.h: Add function prototypes.
* resolve/rust-toplevel-name-resolver-2.0.h: Change getter return type
to reference.
Philip Herron [Wed, 12 Mar 2025 17:03:25 +0000 (17:03 +0000)]
gccrs: check for recursion trait cycle with bounds checks
We need to be careful when doing bounds check as to not create a recusive
trait resolution. This patch checks for that case and fixes a bad type
is equal check on ADT Types which was caught with a regression here.
Fixes Rust-GCC#3126
gcc/rust/ChangeLog:
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::ResolveHirItem): new helper
* typecheck/rust-hir-trait-resolve.h: add helper prototype
* typecheck/rust-type-util.cc (query_type): add debug
* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): check for recursion
* typecheck/rust-tyty.cc (VariantDef::is_equal): fix is equal check
gcc/testsuite/ChangeLog:
* rust/execute/torture/issue-3126.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Enum variants shouldn't be accessed directly even from within an enum.
This commit keeps the provenance for enum variants definition so we
can skip them when resolving a value within an enum definition.
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h: Add new function to insert enum
variants and add argument to resolver's get function to explicitely
skip enum variants.
* resolve/rust-forever-stack.hxx: Update function
definitions.
* resolve/rust-name-resolution-context.cc (NameResolutionContext::insert_variant):
Add function to insert enum variants.
* resolve/rust-name-resolution-context.h: Add function's prototype.
* resolve/rust-rib.cc (Rib::Definition::Definition): Add new boolean to
hint at enum variant provenance.
(Rib::Definition::is_variant): New getter for variant status.
(Rib::Definition::Shadowable): Update constructor to opt out of enum
variants.
(Rib::Definition::Globbed): Likewise.
(Rib::Definition::NonShadowable): Change constructor to forward enum
variant provenance status.
* resolve/rust-rib.h: Update function prototypes.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::insert_enum_variant_or_error_out):
Add function to insert enum variants in the name resolver.
(TopLevel::visit): Update several enum variant's visitor function
with the new enum variant name resolving code.
* resolve/rust-toplevel-name-resolver-2.0.h: Update function
prototypes.
Owen Avery [Tue, 18 Feb 2025 08:56:33 +0000 (03:56 -0500)]
nr2.0: Set the node id of the root node
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h
(ForeverStack::ForeverStack): Set the node id of the root node
to that of the current crate.
* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Use the node id of the root
node during resolution of crate segments.
Arthur Cohen [Mon, 24 Feb 2025 12:09:17 +0000 (13:09 +0100)]
expansion: Correctly expand $crate metavar
gcc/rust/ChangeLog:
* expand/rust-macro-expand.cc: Use new SubstituteCtx API.
* expand/rust-macro-expand.h: Likewise.
* expand/rust-macro-substitute-ctx.cc: Implement proper expansion of $crate.
* expand/rust-macro-substitute-ctx.h: Adapt APIs to take macro definition when
substituting.
* util/rust-hir-map.cc (Mappings::insert_macro_def): Store crate information when
inserting macro definition in mappings.
(Mappings::lookup_macro_def_crate): New.
* util/rust-hir-map.h: Adapt mappings to store crate in which macros were defined.
gcc/testsuite/ChangeLog:
* rust/execute/crate-metavar1.rs: New test.
* rust/compile/crate-metavar1.rs: New test.
Owen Avery [Tue, 18 Feb 2025 08:06:09 +0000 (03:06 -0500)]
nr2.0: Make sure PathInExpression is default resolved
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Call DefaultResolver::visit earlier, in order to
ensure it is called even if Late::visit returns early.
* expand/rust-macro-builtins-include.cc: Include
rust-session-manager.h.
* expand/rust-macro-builtins-utility.cc: Likewise.
* lex/rust-lex.cc: Include rust-edition.h instead of
rust-session-manager.h.
(Lexer::classify_keyword): Use get_rust_edition instead of
Session and CompileOptions.
* parse/rust-parse-impl.h: Include rust-edition.h instead of
rust-session-manager.h.
(Parser::parse_async_item): Use get_rust_edition instead of
Session and CompileOptions.
* checks/errors/rust-feature.h: Include rust-edition.h instead
of rust-session-manager.h.
(class Feature): Use Rust::Edition instead of
Rust::CompileOptions::Edition.
Arthur Cohen [Thu, 23 Jan 2025 11:44:33 +0000 (11:44 +0000)]
lower: Error out when lowering ErrorPropagationExpr
Adapt functions for lowering nodes that should never reach the lowering phase to cause an
unreachable, and mark them as final so as it not possible to override them in other visitors.
gcc/rust/ChangeLog:
* hir/rust-ast-lower-base.cc: Adapt functions for ErrorPropagationExpr and MacroInvocation.
* hir/rust-ast-lower-base.h: Mark them as final.
* hir/rust-ast-lower-expr.cc: Remove previous definition for those overrides.
* hir/rust-ast-lower-expr.h: Likewise.
Owen Avery [Sun, 9 Feb 2025 08:02:58 +0000 (03:02 -0500)]
nr2.0: Handle lang item type path segments
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Stop when hitting a lang
item segment.
(ForeverStack::resolve_segments): Resolve lang item segments.
(ForeverStacl::resolve_path): Handle single segment lang item
paths and add comment.
* util/rust-unwrap-segment.cc
(unwrap_segment_get_lang_item): Add.
* util/rust-unwrap-segment.h
(unwrap_segment_get_lang_item): Add.
Owen Avery [Wed, 19 Feb 2025 02:20:45 +0000 (21:20 -0500)]
nr2.0: Implement macro_use for modules
gcc/rust/ChangeLog:
* resolve/rust-early-name-resolver-2.0.cc:
Include rust-attribute-values.h.
(Early::visit): If a module has a macro_use attribute, avoid
pushing a new textual macro scope.
Arthur Cohen [Fri, 20 Dec 2024 18:00:48 +0000 (18:00 +0000)]
hir-dump: Fix more segfaults in the HIR dump
gcc/rust/ChangeLog:
* hir/rust-hir-dump.cc: Check unique_ptr members are present before
visiting them.
* hir/tree/rust-hir-path.h: Add `has_{type, trait}` methods to
QualifiedPathInType.
Arthur Cohen [Thu, 20 Feb 2025 17:01:28 +0000 (17:01 +0000)]
derive(Hash): Add implementation.
gcc/rust/ChangeLog:
* Make-lang.in: Compile it.
* expand/rust-derive.cc (DeriveVisitor::derive): Call it.
* expand/rust-derive-hash.cc: New file.
* expand/rust-derive-hash.h: New file.
gcc/testsuite/ChangeLog:
* rust/compile/derive-hash1.rs: New test.
* rust/compile/nr2/exclude: Add testcase to exclusion list.
Owen Avery [Sat, 22 Feb 2025 00:07:59 +0000 (19:07 -0500)]
Fix expansion of macros inside modules
gcc/rust/ChangeLog:
* expand/rust-expand-visitor.cc
(ExpandVisitor::visit): Override DefaultASTVisitor in order to
expand a module's items, rather than directly visit them.
* expand/rust-expand-visitor.h
(ExpandVisitor::visit): Add override.
gcc/testsuite/ChangeLog:
* rust/compile/macros/mbe/macro-expand-module.rs: New test.
Arthur Cohen [Tue, 4 Feb 2025 08:58:14 +0000 (09:58 +0100)]
expand: Allow built-in derives to generate multiple items
gcc/rust/ChangeLog:
* expand/rust-derive.cc (DeriveVisitor::derive): Return a vector of items.
* expand/rust-derive.h: Change return type.
* expand/rust-expand-visitor.cc: Insert all generated items into the AST.
Arthur Cohen [Thu, 30 Jan 2025 13:41:11 +0000 (14:41 +0100)]
derive(PartialEq): Add partial implementation
We are still missing some deriving for enums, as part of our codegen and nameres for rebinding struct
field patterns is missing.
gcc/rust/ChangeLog:
* expand/rust-derive-partial-eq.cc: New file.
* expand/rust-derive-partial-eq.h: New file.
* expand/rust-derive.cc (DeriveVisitor::derive): Call them.
* Make-lang.in: Compile them.
gcc/testsuite/ChangeLog:
* rust/compile/derive-eq-invalid.rs: Mark PartialEq def as a lang item.
* rust/compile/derive-partialeq1.rs: New test.
* rust/execute/torture/derive-partialeq1.rs: New test.
* rust/compile/nr2/exclude: Exclude all of them.
Arthur Cohen [Thu, 30 Jan 2025 13:56:37 +0000 (14:56 +0100)]
ast-builder: Improve function generation.
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc (Builder::block): Change return type.
(Builder::loop): Use new APIs.
* ast/rust-ast-builder.h: Change return type of block functions.
Owen Avery [Tue, 4 Feb 2025 10:53:10 +0000 (05:53 -0500)]
nr2.0: Run DefaultResolver::visit on PathInExpression
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): When visiting a PathInExpression instance, call
into DefaultResolver::visit, ensuring generic arguments are
visited.
Owen Avery [Tue, 18 Feb 2025 07:03:56 +0000 (02:03 -0500)]
nr2.0: Fix issue with external crates
gcc/rust/ChangeLog:
* resolve/rust-toplevel-name-resolver-2.0.cc
(TopLevel::visit): When visiting an external crate declaration,
handle failed crate name lookups. This can happen when
Session::load_extern_crate fails to load a crate during the
CfgStrip phase.
Owen Avery [Tue, 4 Feb 2025 10:02:38 +0000 (05:02 -0500)]
nr2.0: Resolve paths which start with Self
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.hxx
(ForeverStack::find_starting_point): Be more careful about
applying ForeverStack::find_closest_module.
(ForeverStack::resolve_segments): Allow traversal into parent
nodes when not in a module node or root node, which
ForeverStack::find_starting_point previously made moot through
use of ForeverStack::find_closest_module. Also, when a child
node lookup fails when resolving in the type namespace, attempt
a rib lookup as a fallback.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Avoid throwing a resolution error for type paths
when the typechecker may be able to finish the resolution. Also,
throw an error when a resolution is ambiguous.
Philip Herron [Sat, 15 Feb 2025 21:22:16 +0000 (21:22 +0000)]
gccrs: Add name resolution and HIR lowering for ImplTraitType's
Our AST has ImplTraitType for multiple bounds and a singular
ImplTraitTypeOneBound, this patch desugars these into a simple
HIR::ImplTraitType. It also does the name resolution for this.
Philip Herron [Thu, 13 Feb 2025 17:45:09 +0000 (17:45 +0000)]
gccrs: self paths are patterns but we dont have mappings for it
With simple patterns we dont introduce any more inference varaibles as
they are already declared in a specific way. This would only lead to
more unconstrained inference varaibles than is required.
Philip Herron [Thu, 13 Feb 2025 17:01:31 +0000 (17:01 +0000)]
gccrs: fix name resolution for generics where type param is declared later
Rust allows you to use generics within type bounds when they are declared
later on. This changes the name resolution to walk the genric params
in two passes to ensure the type parameters are setup before drilling down
into the type parameters
This issue has exposed another type checking issue which needs fixed in
a subseqent patch.
Addresses Rust-GCC#3022
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-item.cc (ResolveTraitItems::visit): use new api
(ResolveItem::visit): likewise
(ResolveExternItem::visit): likewise
* resolve/rust-ast-resolve-stmt.h: likewise
* resolve/rust-ast-resolve-type.h (class ResolveGenericParam): remove
(class ResolveGenericParams): added new api
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Wed, 12 Feb 2025 16:44:55 +0000 (16:44 +0000)]
gccrs: remove name resolution inserts from type-path
We resolve path segments and inserted their resolution into the name
resolution space which was an old hack to use this as information in
code-gen/check-passes in order to help things move forward but this is
not nessecary
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::visit): remove name resolution info
(TypeCheckType::resolve_root_path): likewise
* typecheck/rust-hir-type-check-type.h: likewise
Signed-off-by: Philip Herron <herron.philip@googlemail.com>