This is the first patch in a set intended to fully remove name
resolution 1.0. As such, it should leave name resolution 1.0 technically
available but broken.
Arthur Cohen [Tue, 20 May 2025 12:25:07 +0000 (14:25 +0200)]
gccrs: ast: reconstruct: Add base for reconstructing and asserting different IDs
gcc/rust/ChangeLog:
* ast/rust-ast.h (reconstruct): New function for calling the `reconstruct_*_impl` method
and asserting that the new NodeId is different, and then wrap it in a unique_ptr<T>.
(reconstruct_vec): Likewise, but for vectors of unique_ptr<T>
Owen Avery [Thu, 29 May 2025 21:04:46 +0000 (17:04 -0400)]
gccrs: nr2.0: Adjust resolution of modules
This prioritizes resolution in the language prelude over resolution as a
module.
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.hxx (ForeverStack::resolve_path):
Resolve final segments which point to modules.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Avoid inserting module names into ribs in the type namespace.
Owen Avery [Sat, 24 May 2025 15:51:29 +0000 (11:51 -0400)]
gccrs: nr2.0: Add more checks for alternate patterns
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc
(visit_identifier_as_pattern): Handle is_ref and is_mut.
(Late::visit): Likewise.
* resolve/rust-name-resolution-context.cc
(BindingLayer::insert_ident): Likewise.
(BindingLayer::bind_test): Handle changes to BindingLayer
fields.
(BindingLayer::merge): Likewise and emit more error messages.
* resolve/rust-name-resolution-context.h
(struct IdentifierMode): New.
(Binding::has_expected_bindings): New field.
(Binding::set): Rename field to...
(Binding::idents): ...here and convert from a set to a map.
(Binding::Binding): Initialize has_expected_bindings.
(BindingLayer::insert_ident): Adjust parameters.
Owen Avery [Mon, 16 Jun 2025 21:05:09 +0000 (17:05 -0400)]
gccrs: nr2.0: Adjust resolution of external crates
This ensures Session::load_extern_crate doesn't try to use the old name
resolver when nr2.0 is enabled, while also ensuring that nr2.0 handles
external crates.
gcc/rust/ChangeLog:
* resolve/rust-default-resolver.cc
(DefaultResolver::visit_extern_crate): New function.
(DefaultResolver::visit): New visitor function for ExternCrate.
* resolve/rust-default-resolver.h
(DefaultResolver::visit_extern_crate): New function.
(DefaultResolver::visit): New visitor function for ExternCrate.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::visit):
Adjust ExternCrate visitor and rename to...
(TopLevel::visit_extern_crate): ...here.
* resolve/rust-toplevel-name-resolver-2.0.h (TopLevel::visit):
Remove ExternCrate visitor override.
(TopLevel::visit_extern_crate): New function.
* rust-session-manager.cc (Session::load_extern_crate): Only run
name resolution 1.0 if name resolution 2.0 is disabled.
Zhi Heng [Thu, 26 Jun 2025 14:33:15 +0000 (22:33 +0800)]
gccrs: Implement type checking for ItemType::RANGED in TuplePattern
This patch implements the previously unimplemented type checking for RANGED item
type for TuplePattern, which serves as the start for implementing compilation of
RestPattern.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit(TuplePattern)):
Implement type checking for ItemType::RANGED.
Owen Avery [Mon, 23 Jun 2025 16:33:54 +0000 (12:33 -0400)]
gccrs: Fix scan-assembler regexp in recurse2.rs
gcc/testsuite/ChangeLog:
* rust/compile/macros/builtin/recurse2.rs: Match "abheyho\0" as
well as "abheyho", to handle slight differences in assembly
output for null-terminated strings.
Philip Herron [Mon, 23 Jun 2025 11:59:33 +0000 (12:59 +0100)]
gccrs: Fix bug with non compiled const decl
There was a sily bug where if you reorder this test case to declare A before B
this test would work but its meant to work in any order. So this fixes the bug
during code gen to fall back to our query compile system if this is needed.
Fixes Rust-GCC#3525
gcc/rust/ChangeLog:
* backend/rust-compile-resolve-path.cc: if this fails fall back to query compile
gcc/testsuite/ChangeLog:
* rust/compile/issue-3525.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Code for TupleStructPattern compilation previously only assumes that it is derived from
an enum. This commit adds a check for that, and compiles non-enum TupleStructPatterns
similarly to TuplePatterns if it is not an enum.
gcc/rust/ChangeLog:
* backend/rust-compile-pattern.cc(CompilePatternCheckExpr::visit(TupleStructPattern)):
Fix error thrown when compiling non-enum TupleStructPattern.
Philip Herron [Sat, 21 Jun 2025 14:40:50 +0000 (15:40 +0100)]
gccrs: Refactor marker builtin trait assembly
Rename assemble_sized_builtin to assemble_marker_builtins and reorganize
the type matching to properly handle function pointers and closures with
their associated traits (Fn, FnMut, FnOnce).
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-bounds.h: Rename method.
* typecheck/rust-tyty-bounds.cc: Refactor marker trait assembly
and add proper Fn trait handling for function types.
Philip Herron [Wed, 18 Jun 2025 17:25:14 +0000 (18:25 +0100)]
gccrs: Fix ICE when constant is missing and expression
This is an invalid test case and doesnt work with rustc, we dont fully pick
up the errors. Nr2 does handle this and puts out an extra good diagnostic
but the old NR doesnt so for now i added this to the exclude list and then
when we remove old name resolver this issue goes away.
Owen Avery [Mon, 16 Jun 2025 21:04:22 +0000 (17:04 -0400)]
gccrs: Adjust external crate lowering and type checking
The 2.0 name resolver is provided through
ImmutableNameResolutionContext after it is done being mutated. The
typechecker attempts to use ImmutableNameResolutionContext, so it needs
to be run after ImmutableNameResolutionContext has been initialized
(after all name resolution has been completed). Additionally, although I
haven't seen any issues with lowering AST to HIR before name resolution
2.0 is complete, it makes sense to perform all lowering in lockstep as
well.
gcc/rust/ChangeLog:
* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): Add
visitor for ExternCrate.
* hir/rust-ast-lower-item.h (ASTLoweringItem::visit): Likewise.
* rust-session-manager.cc (Session::load_extern_crate): Avoid
lowering or type resolving external crates here.
* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit):
Add visitor for ExternCrate.
* typecheck/rust-hir-type-check-item.h (TypeCheckItem::visit):
Replace empty definition with a declaration.
Philip Herron [Tue, 17 Jun 2025 10:32:21 +0000 (11:32 +0100)]
gccrs: Fix issues around PartialEq Eq Ord Partial Ord
There is still an issue with derive on PartialOrd but this adds good tests
and fixes a bug we had handling the default Rhs = Self generic type param
substitutions on the comparison traits.
gcc/rust/ChangeLog:
* typecheck/rust-tyty.cc (ParamType::handle_substitions): make this consistent
gcc/testsuite/ChangeLog:
* rust/compile/bug-with-default-generic.rs: New test.
* rust/execute/torture/partial-eq-1.rs: New test.
* rust/execute/torture/partial-eq-2.rs: New test.
* rust/execute/torture/partial-eq-3.rs: New test.
* rust/execute/torture/partial-eq-4.rs: New test.
* rust/execute/torture/partial-ord-1.rs: New test.
* rust/execute/torture/partial-ord-2.rs: New test.
* rust/execute/torture/partial-ord-3.rs: New test.
* rust/execute/torture/partial-ord-4.rs: New test.
* rust/execute/torture/partial-ord-5.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Zhi Heng [Fri, 13 Jun 2025 14:19:33 +0000 (22:19 +0800)]
gccrs: Implement name resolution for IdentifierPattern's subpattern
gcc/rust/ChangeLog:
* resolve/rust-ast-resolve-pattern.cc: Implement name resolution for
IdentifierPattern's subpattern.
* resolve/rust-late-name-resolver-2.0.cc: Ditto, but for nr2.
Owen Avery [Fri, 9 May 2025 18:37:55 +0000 (14:37 -0400)]
gccrs: nr2.0: Adjust lookup of associated items
gcc/rust/ChangeLog:
* resolve/rust-default-resolver.cc (DefaultResolver::visit):
Adjust scoping of trait definitions and their generic
parameters.
* resolve/rust-forever-stack.hxx (ForeverStack::get): Prevent
lookups inside TraitOrImpl ribs.
(ForeverStack::resolve_segments): Prevent lookups of the first
segment inside TraitOrImpl ribs.
Arthur Cohen [Tue, 27 May 2025 12:23:39 +0000 (14:23 +0200)]
gccrs: derive(Ord): Handle unit structs properly
gcc/rust/ChangeLog:
* expand/rust-derive-ord.cc (DeriveOrd::make_cmp_arms): Use new make_equal function.
(DeriveOrd::make_equal): New function.
(DeriveOrd::recursive_match): Handle the unit struct/tuple case.
* expand/rust-derive-ord.h: Declare make_equal.
Arthur Cohen [Tue, 22 Apr 2025 20:17:18 +0000 (22:17 +0200)]
gccrs: derive-cmp: Add EnumMatchBuilder class
gcc/rust/ChangeLog:
* expand/rust-derive-cmp-common.h (class EnumMatchBuilder): New helper class.
* expand/rust-derive-cmp-common.cc (EnumMatchBuilder::tuple): New function.
(EnumMatchBuilder::strukt): New function.
Arthur Cohen [Tue, 22 Apr 2025 18:03:16 +0000 (20:03 +0200)]
gccrs: derive(Ord): Add handling for ordering of discriminant values
gcc/rust/ChangeLog:
* expand/rust-derive-ord.cc (DeriveOrd::cmp_call): New function.
(DeriveOrd::recursive_match): Use it.
(DeriveOrd::visit_enum): Likewise.
* expand/rust-derive-ord.h: Declare it.
Arthur Cohen [Fri, 18 Apr 2025 16:30:19 +0000 (18:30 +0200)]
gccrs: derive(PartialEq): chore: Refactor using new SelfOther APIs
gcc/rust/ChangeLog:
* expand/rust-derive-cmp-common.cc (SelfOther::indexes): Fix formatting.
(SelfOther::fields): Make iterator const.
* expand/rust-derive-cmp-common.h (struct SelfOther): New declaration for indexes.
* expand/rust-derive-partial-eq.cc (DerivePartialEq::visit_tuple): Use the new API.
(DerivePartialEq::visit_struct): Likewise.
Arthur Cohen [Wed, 9 Apr 2025 09:18:06 +0000 (11:18 +0200)]
gccrs: derive: Add const generics when deriving impls
gcc/rust/ChangeLog:
* ast/rust-ast-builder.cc (Builder::new_const_param): New function.
* ast/rust-ast-builder.h (vec): New function for creating 3 elts vector.
* expand/rust-derive.cc: Use the new_const_param builder.
* ast/rust-path.h: Add get_default_value() method.
Zhi Heng [Sat, 7 Jun 2025 14:24:03 +0000 (22:24 +0800)]
gccrs: Support compilation of IdentifierPattern's subpatterns
gcc/rust/ChangeLog:
* backend/rust-compile-pattern.cc: Add CheckExpr compilation for
IdentifierPattern with subpattern.
* backend/rust-compile-pattern.h: Modify IdentifierPattern's
visit func to support the above.
* typecheck/rust-hir-type-check-pattern.cc: Add typechecking
support for the changes above.
Owen Avery [Thu, 15 May 2025 01:40:04 +0000 (21:40 -0400)]
gccrs: nr2.0: Fix closure parameter scoping
gcc/rust/ChangeLog:
* resolve/rust-default-resolver.cc
(DefaultResolver::visit_closure_params): New member function
definition.
(DefaultResolver::visit): New visiting function definition for
ClosureExpr called from visiting functions for ClosureExprInner
and ClosureExprInnerTyped.
* resolve/rust-default-resolver.h
(DefaultResolver::visit_closure_params): New member function
declaration.
(DefaultResolver::visit): New visiting function declaration for
ClosureExpr.
* resolve/rust-late-name-resolver-2.0.cc (add_captures): Remove
function.
(Late::visit): New visiting function definition for ClosureExpr,
remove visiting function definitions for ClosureExprInner and
ClosureExprInnerTyped.
(Late::visit_closure_params): New member function definition.
* resolve/rust-late-name-resolver-2.0.h (Late::visit): New
visiting function declaration for ClosureExpr, remove visiting
function declarations for ClosureExprInner and
ClosureExprInnerTyped.
(Late::visit_closure_params): New member function declaration.
Owen Avery [Sun, 18 May 2025 02:26:20 +0000 (22:26 -0400)]
gccrs: nr2.0: Adjust pub_restricted tests
gcc/testsuite/ChangeLog:
* rust/compile/nr2/exclude: Remove entries.
* rust/compile/pub_restricted_1.rs: Adjust expected error
messages and only run with name resolution 2.0 enabled.
* rust/compile/pub_restricted_2.rs: Likewise.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Use
visit_identifier_as_pattern to handle IdentifierPattern and
StructPatternFieldIdent.
(visit_identifier_as_pattern): New function.
Owen Avery [Fri, 2 May 2025 22:38:50 +0000 (18:38 -0400)]
gccrs: nr2.0: Separate out canonical path handling
This should improve our canonical path handling, without requiring
further tweaks to ForeverStack. This may also help if, in the future, we
have to move canonical path calculation to later compilation phases for
proper handling of generics.
gcc/rust/ChangeLog:
* backend/rust-compile-base.cc
(HIRCompileBase::compile_function): Since canonical paths
returned from nr2.0 now include the crate name, avoid prepending
the crate name again.
* resolve/rust-default-resolver.cc (DefaultResolver::visit): Add
Crate and EnumItem instance visitors, handle canonical path
context scoping.
* resolve/rust-default-resolver.h (DefaultResolver::visit): Add
Crate and EnumItem instance visitors.
* resolve/rust-early-name-resolver-2.0.cc (Early::go): Visit
instances of Crate using the virtual member function visit.
* resolve/rust-forever-stack.h
(ForeverStack::to_canonical_path): Remove function declaration.
* resolve/rust-forever-stack.hxx
(ForeverStack::to_canonical_path): Remove function definition.
* resolve/rust-late-name-resolver-2.0.cc (Late::go): Visit
instances of Crate using the virtual member function visit.
* resolve/rust-name-resolution-context.cc
(CanonicalPathRecordCrateRoot::as_path): New function definition.
(CanonicalPathRecordNormal::as_path): Likewise.
(CanonicalPathRecordLookup::as_path): Likewise.
(CanonicalPathRecordImpl::as_path): Likewise.
(CanonicalPathRecordTraitImpl::as_path): Likewise.
(NameResolutionContext::NameResolutionContext): Initialize
member variable canonical_ctx.
* resolve/rust-name-resolution-context.h: Include "rust-item.h".
(class NameResolutionContext): Forward declare class.
(class CanonicalPathRecord): New class.
(class CanonicalPathRecordWithParent): Likewise.
(class CanonicalPathRecordCrateRoot): Likewise.
(class CanonicalPathRecordNormal): Likewise.
(class CanonicalPathRecordLookup): Likewise.
(class CanonicalPathRecordImpl): Likewise.
(class CanonicalPathRecordTraitImpl): Likewise.
(class CanonicalPathCtx): Likewise.
(NameResolutionContext::canonical_ctx): New member variable.
(NameResolutionContext::to_canonical_path): New member function.
* resolve/rust-toplevel-name-resolver-2.0.cc (TopLevel::go):
Visit instances of Crate with the virtual member function visit.
(TopLevel::visit): Handle canonical path context scoping for
external crates, use DefaultResolver::visit when visiting
instances of StructStruct.
* util/rust-canonical-path.h (CanonicalPath::new_seg): Take path
parameter by-value, as a duplicate instance will be constructed
regardless.
Zhi Heng [Sat, 7 Jun 2025 14:30:25 +0000 (22:30 +0800)]
gccrs: Lower IdentifierPattern's to_bind to HIR
gcc/rust/ChangeLog:
* hir/rust-ast-lower-pattern.cc: Lower of IdentifierPattern's to_bind to HIR.
* hir/rust-hir-dump.cc: Update IdentifierPattern's dump to properly show to_bind's full
full properties.
Owen Avery [Fri, 16 May 2025 02:04:34 +0000 (22:04 -0400)]
gccrs: nr2.0: Catch Self in impl block self types
gcc/rust/ChangeLog:
* resolve/rust-default-resolver.cc (DefaultResolver::visit): Use
visit_impl_type to visit the self types of impl blocks.
* resolve/rust-default-resolver.h
(DefaultResolver::visit_impl_type): New member function
declaration.
* resolve/rust-late-name-resolver-2.0.cc (Late::Late):
Initialize member variable block_big_self.
(Late::visit_impl_type): New member function definition.
(Late::visit): Check for Self while inside impl block self
types.
* resolve/rust-late-name-resolver-2.0.h (Late::visit_impl_type):
New member function.
(Late::block_big_self): New member variable.
gcc/testsuite/ChangeLog:
* rust/compile/issue-3671.rs: Remove usage of Self.
* rust/compile/nr2/exclude: Remove issue-3671.rs.
* rust/compile/self-in-impl.rs: New test.
Owen Avery [Fri, 9 May 2025 00:44:47 +0000 (20:44 -0400)]
gccrs: nr2.0: Improve visibility path handling
gcc/rust/ChangeLog:
* resolve/rust-forever-stack.h
(enum ResolutionMode): New.
(ForeverStack::get): Add a private overload that takes a
starting node as a parameter.
(ForeverStack::resolve_path): Replace boolean parameter
has_opening_scope_resolution with ResolutionMode parameter mode.
* resolve/rust-forever-stack.hxx
(ForeverStack::resolve_path): Likewise.
(ForeverStack::get): Add a private overload that takes a
starting node as a parameter.
* resolve/rust-late-name-resolver-2.0.cc
(Late::visit): Add Visibility visitor.
* resolve/rust-late-name-resolver-2.0.h
(Late::visit): Likewise.
* resolve/rust-name-resolution-context.h
(NameResolutionContext::resolve_path): Rework overloading a bit
and accept ResolutionMode parameter.
Owen Avery [Wed, 4 Jun 2025 05:06:06 +0000 (01:06 -0400)]
gccrs: Make ConstantItem use Identifier
The change to ASTLoweringExternItem is necessary, since with this patch
Identifier can be implicitly converted to std::string.
gcc/rust/ChangeLog:
* ast/rust-ast-collector.cc (TokenCollector::visit): Handle
changed type of ConstantItem::identifier.
* ast/rust-ast.cc (ConstantItem::as_string): Likewise.
* ast/rust-ast.h (operator const std::string &): New member
function.
* ast/rust-item.h (ConstantItem::identifier): Change type from
std::string to Identifier.
(ConstantItem::ConstantItem): Handle changed type of identifier
field.
(ConstantItem::is_unnamed): Likewise.
(ConstantItem::get_identifier): Likewise.
* hir/rust-ast-lower-extern.h (ASTLoweringExternItem::visit):
Avoid discarding location of wildcard patterns.
* lex/rust-token.cc: Include "rust-ast.h".
(Token::make_identifier): Add overload accepting an Identifier
instance.
* lex/rust-token.h (class Identifier): Add forward declaration
in order to...
(Token::make_identifier): ...declare an overload for this static
member function.
Philip Herron [Tue, 20 May 2025 17:44:57 +0000 (18:44 +0100)]
gccrs: Always emit the error highest in the type hierarchy
The unify code was a bit dumb here where we always set emit_error to false for any
subtypes for example in comparing tuples we always emitted the whole tuple didnt
match the other tuple but really its much better to say expected bool got i32 because
the element types didn't match.
gcc/rust/ChangeLog:
* typecheck/rust-coercion.cc (TypeCoercionRules::coerce_unsized): dont emit error here
* typecheck/rust-unify.cc (UnifyRules::resolve_subtype): new helper to handle emit error
(UnifyRules::expect_adt): call resolve_subtype
(UnifyRules::expect_reference): likewise
(UnifyRules::expect_pointer): likewise
(UnifyRules::expect_array): likewise
(UnifyRules::expect_slice): likewise
(UnifyRules::expect_fndef): likewise
(UnifyRules::expect_fnptr): likewise
(UnifyRules::expect_tuple): likewise
(UnifyRules::expect_closure): likewise
(UnifyRules::expect_opaque): likeiwse
* typecheck/rust-unify.h: add new helper to header
gcc/testsuite/ChangeLog:
* rust/compile/traits9.rs: update errors
* rust/compile/unify-errors1.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Owen Avery [Thu, 15 May 2025 00:03:01 +0000 (20:03 -0400)]
gccrs: nr2.0: Fix IfLet pattern handling
gcc/rust/ChangeLog:
* resolve/rust-default-resolver.cc
(DefaultResolver::visit_if_let_patterns): New function
definition.
(DefaultResolver::visit): New IfLetExpr visitor definition.
* resolve/rust-default-resolver.h
(DefaultResolver::visit_if_let_patterns): New function
declaration.
(DefaultResolver::visit): New IfLetExpr visitor declaration.
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Remove
IfLetExpr visitor definition.
(Late::visit_if_let_patterns): New function definition.
* resolve/rust-late-name-resolver-2.0.h (Late::visit): Remove
IfLetExpr visitor declaration.
(Late::visit_if_let_patterns): New function declaration.
* resolve/rust-name-resolution-context.h (BindingSource::IfLet):
New enumerator.
Philip Herron [Mon, 19 May 2025 17:02:13 +0000 (18:02 +0100)]
gccrs: Initial support for Return Position Impl Trait
This is the initial patch for RPIT, we can build on this to handle the
more complex cases but there are enough distinct changes going on here
that it should just get merged now.
RPIT is really a sneaky generic so for example:
fn foo() -> impl Bar {
Baz
}
This is represented as: fn () -> OpaqueType Bar. But when we handle the
coercion site for Baz on impl Bar when we type resolve the function we
know that the underlying type is Baz. Note this function is _not_ generic
so its using this special OpaqueType and keeping track of the underlying type
in its ty_ref reference hir-id which will resolve to Baz.
This also means if we have a case where maybe this was in an if statement:
fn foo(a: i32) -> impl Bar {
if a > 10 {
Baz
} else {
Qux
}
}
The rules of impl Bar is that Baz is handled but Baz and Qux are different
underlying types so this is not allowed. The reason is impl traits are not
generic and although from a programmer perspective the callers dont know what
the underlying type is, the compiler _knows_ what it is. So really when
you call a function and get its return position impl trait the compiler knows
what to do and does all whats nessecary to handle calling functions using that
type etc.
gcc/rust/ChangeLog:
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): we need to resolve the
underlying type
* typecheck/rust-substitution-mapper.cc (SubstMapperInternal::visit): just clone
* typecheck/rust-tyty-call.cc (TypeCheckCallExpr::visit):
ensure we monomphize to get the underlying
* typecheck/rust-tyty.cc (BaseType::destructure): handle opaque types
(OpaqueType::resolve): this is much simpler now
(OpaqueType::handle_substitions): no longer needed
* typecheck/rust-tyty.h: update header
* typecheck/rust-unify.cc (UnifyRules::expect_opaque): unify rules for opaque
gcc/testsuite/ChangeLog:
* rust/compile/bad-rpit1.rs: New test.
* rust/execute/torture/impl_rpit1.rs: New test.
* rust/execute/torture/impl_rpit2.rs: New test.
* rust/execute/torture/impl_rpit3.rs: New test.
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Mon, 26 May 2025 18:30:45 +0000 (19:30 +0100)]
gccrs: Fix non canonical type bug with tuples
When working on rpit we needed to change to use a monomorphized clone of
the result of function calls. This ended up causing a verify gimple issue
with tuples because:
fn test<A, B>(a: A, b: B) -> (A, B)
When passing for example:
let a = test::<i32, i32> (123, 456) -> (A=i32, B=i32)
The resulting gimple types became:
const struct (A=i32, B=i32) vs struct (i32, i32)
We removed the VIEW_CONVERT_EXPR support to auto fix this stuff a good
while ago because it hides these kinds of issues because the type hasher
included the A=i32, B=i32 vs the i32, i32 name so updating this to use
get_name instead keeps the naming the same as well as the fields meaning
these types are 100% equivilant and therefore no conversion is required.
This only occurs because tuples are not named types we should really add
more rust specific info on our gimple TYPES.
gcc/rust/ChangeLog:
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): use get_name
* typecheck/rust-tyty.cc (TupleType::get_name): likewise
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Mon, 19 May 2025 16:42:17 +0000 (17:42 +0100)]
gccrs: Remove unneeded clones untill we have an arena allocator for these tmps
Cloning inference variables is very expensive because it means we are indirectly
creating an implicit new inference variable added to the reference chain.
gcc/rust/ChangeLog:
* checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::check_base_type_privacy):
no need for unreachable here
* typecheck/rust-unify.cc (UnifyRules::commit): dont clone infer vars
(UnifyRules::expect_inference_variable): likewise
Signed-off-by: Philip Herron <herron.philip@googlemail.com>
Philip Herron [Mon, 19 May 2025 16:55:53 +0000 (17:55 +0100)]
gccrs: refactor default infer vars to be its own function
This is just a simple refactor to pull all the logic outside of the
closure which makes it more readable.
gcc/rust/ChangeLog:
* typecheck/rust-hir-type-check.h: new function
* typecheck/rust-typecheck-context.cc (TypeCheckContext::compute_inference_variables):
call the new helper
(TypeCheckContext::compute_infer_var): refactored code
Signed-off-by: Philip Herron <herron.philip@googlemail.com>