Skip to content

Improve method resolution by using indexes - #4847

Merged
philberty merged 5 commits into
masterfrom
phil/method-resolution-perf
Sep 6, 2026
Merged

Improve method resolution by using indexes#4847
philberty merged 5 commits into
masterfrom
phil/method-resolution-perf

Conversation

@philberty

Copy link
Copy Markdown
Member

A set of patches to improve our method resolution

@philberty philberty added the core Issue related to the compilation of the `core` crate label Sep 4, 2026
@philberty
philberty force-pushed the phil/method-resolution-perf branch from f11f9ba to 3aa4156 Compare September 4, 2026 22:10
This is part 1 of more series of patches to improve method resolution perf
because its incredibly expensive operation. This changes it so that we try
predicates up front before looking up anything.

gcc/rust/ChangeLog:

	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): look at predicates first

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

	* typecheck/rust-hir-dot-operator.cc (MethodResolver::select): use sperate index
	* util/rust-hir-map.cc (Mappings::insert_hir_impl_block): new indexes
	* util/rust-hir-map.h: likewise

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

	* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): use trait index

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

	* typecheck/rust-hir-dot-operator.cc: use item name indexes
	* util/rust-hir-map.cc (Mappings::insert_hir_impl_block): new index
	(Mappings::insert_trait_item_mapping): likewise
	* util/rust-hir-map.h: likewise

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

I used a node-id mapping just out of handyness because the trait-impls or
impls to defid's uses the name resolver to NodeIds but to use DefId we need
to do an indexing pass at the end of hir lowering then to get the DefId
mappings.

gcc/rust/ChangeLog:

	* hir/rust-ast-lower-item.cc (register_adt_impl): remove
	(ASTLoweringItem::visit): likewise
	* rust-session-manager.cc (Session::compile_crate): call new indexer
	* typecheck/rust-hir-dot-operator.cc
	(MethodResolver::try_select_predicate_candidates): use indexes
	* typecheck/rust-hir-path-probe-expr.cc (PathProbeExpr::probe_adt_impls): likewise
	* typecheck/rust-hir-path-probe-impl-trait.cc
	(PathProbeImplTrait::process_trait_impl_items_for_candidates): likewise
	* typecheck/rust-hir-path-probe-type.cc (TypePathProbe::probe_adt): likewise
	* typecheck/rust-tyty-bounds.cc (TypeBoundsProbe::scan): likewise
	* util/rust-hir-map.cc (Mappings::Mappings): new indexer
	(Mappings::insert_hir_impl_block): likewise
	(Mappings::insert_adt_impl_mapping): likewise
	(Mappings::build_impl_indexes): likewise
	(Mappings::insert_trait_impl_mapping): likewise
	(Mappings::insert_trait_item_mapping): likewise
	* util/rust-hir-map.h: likewise

Signed-off-by: Philip Herron <herron.philip@googlemail.com>
@philberty
philberty force-pushed the phil/method-resolution-perf branch from 3aa4156 to abe8b0e Compare September 6, 2026 15:22
@philberty
philberty added this pull request to the merge queue Sep 6, 2026
Merged via the queue into master with commit 32c8403 Sep 6, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Issue related to the compilation of the `core` crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant