Skip to content

Typecheck improvements for libcore - #4816

Merged
philberty merged 17 commits into
masterfrom
phil/libcore-dev
Aug 30, 2026
Merged

Typecheck improvements for libcore#4816
philberty merged 17 commits into
masterfrom
phil/libcore-dev

Conversation

@philberty

@philberty philberty commented Aug 23, 2026

Copy link
Copy Markdown
Member

This is a patch serious to improve type checking for libcore. Major fix was to separate function body and signature
resolution.

@philberty philberty changed the title Phil/libcore dev Phil/libcore dev WIP Aug 23, 2026
Fixes #4814

gcc/rust/ChangeLog:

	* hir/rust-hir-dump.cc (Dump::do_typepathfunction): add guard

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
This is just a general improvement so we can filter trait probing to not
look at the whole crate.

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-item.cc (ASTLoweringItem::visit): add mapping
	* rust-session-manager.cc (Session::compile_crate): make sure nr context is ready
	* typecheck/rust-hir-path-probe.cc
	(PathProbeImplTrait::process_trait_impl_items_for_candidates): use the new filter
	* util/rust-hir-map.cc (Mappings::insert_trait_impl_mapping): new helper
	* util/rust-hir-map.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
This means we can do some pre filtering instead of scanning the crate.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-dot-operator.cc (MethodResolver::MethodResolver): new optional filter
	(MethodResolver::Probe): likewise
	(MethodResolver::try_select_predicate_candidates): likewise
	(MethodResolver::select): likewise
	* typecheck/rust-hir-dot-operator.h: likewise
	* typecheck/rust-hir-type-check-expr.cc: pass lang item trait
	* util/rust-hir-map.cc: new helper to scan implblocks
	* util/rust-hir-map.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-bounds.h: optional trait arg
	* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::TypeBoundsProbe): likewise
	(TypeBoundsProbe::Probe): likewise
	(TypeBoundsProbe::is_bound_satisfied_for_type): use specified trait
	(TypeBoundsProbe::scan): try to scan for indexed traits

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

	* typecheck/rust-tyty-bounds.cc (TypeBoundPredicate::validate_type_implements_this): filter

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
The code used to work by accident that the type bounds probe already setup
the type checked trait before hand so the lookup's just worked by accident.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): dp trait lookup
	* typecheck/rust-tyty.cc (BaseType::satisfies_bound): add filter

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

	* typecheck/rust-type-util.cc (lookup_associated_impl_block): add filter
	(normalize_projection): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

	* typecheck/rust-hir-path-probe.cc (PathProbeType::Probe): filter

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

	* hir/rust-ast-lower-item.cc (register_adt_impl): new mappings
	(ASTLoweringItem::visit): tracker function
	* typecheck/rust-hir-path-probe.cc (PathProbeType::process_impl_items_for_candidates):
	iterator
	* util/rust-hir-map.cc (Mappings::insert_adt_impl_mapping): helper
	* util/rust-hir-map.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

	* Make-lang.in: new object
	* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_associated_type): helper
	* typecheck/rust-hir-type-check-type.h: new interface
	* typecheck/rust-hir-path-probe-type.cc: New file.
	* typecheck/rust-hir-path-probe-type.h: New file.

gcc/testsuite/ChangeLog:

	* rust/compile/issue-4166.rs:

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

	* Make-lang.in: new object
	* backend/rust-compile-base.cc: refactor
	* backend/rust-compile-drop.cc: likewise
	* backend/rust-compile-resolve-path.cc: likewise
	* typecheck/rust-hir-path-probe.cc (PathProbeImplTrait::PathProbeImplTrait): likewise
	(PathProbeImplTrait::Probe): likewise
	(PathProbeImplTrait::process_trait_impl_items_for_candidates): likewise
	* typecheck/rust-hir-path-probe.h (class PathProbeImplTrait): likewise
	* typecheck/rust-hir-path-probe-impl-trait.cc: New file.
	* typecheck/rust-hir-path-probe-impl-trait.h: New file.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
…Expr

gcc/rust/ChangeLog:

	* Make-lang.in: new object
	* typecheck/rust-hir-path-probe.cc (PathProbeType::PathProbeType): refactor
	(PathProbeType::Probe): likewise
	(PathProbeType::visit): likewise
	(PathProbeType::process_enum_item_for_candiates): likewise
	(PathProbeType::process_impl_items_for_candidates): likewise
	(PathProbeType::process_impl_item_candidate): likewise
	(PathProbeType::is_receiver_generic): likewise
	* typecheck/rust-hir-path-probe.h (class PathProbeType): likewise
	* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): likewise
	* typecheck/rust-hir-path-probe-expr.cc: New file.
	* typecheck/rust-hir-path-probe-expr.h: New file.

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
…geted

The logic is much like PathProbeType but we are looking for fns/const exprs
since we dont care about types in that path. We should really prefer trait
position items where we can but there was regressions there which we can
revisit later.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-path-probe-expr.cc (PathProbeExpr::Probe): simpler interface
	(PathProbeExpr::probe): based of the receiver
	(PathProbeExpr::visit): no longer needed
	(PathProbeExpr::probe_adt_impls): new probe
	(PathProbeExpr::probe_fallback_impls): fallback to iterate impls
	(PathProbeExpr::process_enum_item_for_candiates): removed
	(PathProbeExpr::process_enum_item_for_candidates): likewise
	(PathProbeExpr::process_impl_items_for_candidates): likewise
	(PathProbeExpr::process_impl_item_candidate): likewise
	(PathProbeExpr::probe_bounds): fall back to the impl iter
	(PathProbeExpr::insert_candidate): acumulate
	* typecheck/rust-hir-path-probe-expr.h (class PathProbeExpr): new interface
	* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::TypeCheckExpr): likewise
	* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_segments): likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
We can do a defid check and possibly early return for mismatches on adt's.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-dot-operator.cc:

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
We currently alawys resolve function body and signiture together this
seperates the two concepts so we can change query type if a fn is not
resolved to only query the signiture and not start the cascade of resolving
body calling others etc.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): seperate
	(TypeCheckImplItem::resolve_function_signature): likewise
	* typecheck/rust-hir-type-check-implitem.h: seperate
	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): likewise
	(TypeCheckItem::resolve_function_signature): likewise
	* typecheck/rust-hir-type-check-item.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
This builds upon the previous patch to seperate fn hir item body and
signiture resolution to stop crate cascades.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit):
	check need to resolve body
	* typecheck/rust-hir-type-check-implitem.h: new resolve sig
	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::Resolve): check recursion
	(TypeCheckItem::ResolveFunctionSignature): new helper
	(TypeCheckItem::ResolveImplBlockSelf): missing lifetime pin
	(TypeCheckItem::visit): likewise
	* typecheck/rust-hir-type-check-item.h: new helper
	* typecheck/rust-hir-type-check.h: track function body pending
	* typecheck/rust-type-util.cc (query_type): track associated self
	(normalize_projection): check compatable
	* typecheck/rust-typecheck-context.cc (TypeCheckContext::mark_function_body_pending):
	marker to make sure body gets resolved later
	(TypeCheckContext::clear_function_body_pending): clear market
	(TypeCheckContext::function_body_pending): new set

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
gcc/rust/ChangeLog:

	* typecheck/rust-hir-trait-reference.cc (TraitItemReference::get_tyty): early guard
	(TraitReference::resolve_default_function_bodies): new body resolver
	* typecheck/rust-hir-trait-reference.h: new prototypes
	* typecheck/rust-hir-trait-resolve.cc (TraitItemReference::on_resolved): resolve body
	(TraitItemReference::resolve_default_function_body): likewise
	(TraitItemReference::resolve_item): clearing pending
	* typecheck/rust-hir-type-check-item.cc (TypeCheckItem::ResolveTraitSignature): new
	(TypeCheckItem::resolve_trait): likewise
	(TypeCheckItem::visit): likewise
	* typecheck/rust-hir-type-check-item.h: likewise
	* typecheck/rust-type-util.cc (query_type): get signiture

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
@philberty philberty changed the title Phil/libcore dev WIP Typecheck improvements for libcore Aug 30, 2026
@philberty
philberty added this pull request to the merge queue Aug 30, 2026
Merged via the queue into master with commit bb00634 Aug 30, 2026
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant