rust/src/librustc_passes
bors d3ebd592d0 Auto merge of #69072 - ecstatic-morse:associated-items, r=petrochenkov
O(log n) lookup of associated items by name

Resolves #68957, in which compile time is quadratic in the number of associated items. This PR makes name lookup use binary search instead of a linear scan to improve its asymptotic performance. As a result, the pathological case from that issue now runs in 8 seconds on my local machine, as opposed to many minutes on the current stable.

Currently, method resolution must do a linear scan through all associated items of a type to find one with a certain name. This PR changes the result of the `associated_items` query to a data structure that preserves the definition order of associated items (which is used, e.g., for the layout of trait object vtables) while adding an index of those items sorted by (unhygienic) name. When doing name lookup, we first find all items with the same `Symbol` using binary search, then run hygienic comparison to find the one we are looking for. Ideally, this would be implemented using an insertion-order preserving, hash-based multi-map, but one is not readily available.

Someone who is more familiar with identifier hygiene could probably make this better by auditing the uses of the `AssociatedItems` interface. My goal was to preserve the current behavior exactly, even if it seemed strange (I left at least one FIXME to this effect). For example, some places use comparison with `ident.modern()` and some places use `tcx.hygienic_eq` which requires the `DefId` of the containing `impl`. I don't know whether those approaches are equivalent or which one should be preferred.
2020-02-20 22:44:01 +00:00
..
Cargo.toml Make librustc_infer compile. 2020-02-16 11:49:29 +01:00
check_attr.rs Rollup merge of #68554 - cjgillot:lang_items, r=Zoxc 2020-02-12 18:55:37 +09:00
check_const.rs Add a Hir wrapper type 2020-02-06 12:05:40 +01:00
dead.rs Invert control in struct_lint_level. 2020-02-11 19:47:40 +10:00
diagnostic_items.rs Normalise notes with the/is 2020-01-24 16:24:50 +00:00
entry.rs Add a Hir wrapper type 2020-02-06 12:05:40 +01:00
hir_stats.rs parser: merge fn grammars wrt. bodies & headers 2020-02-05 01:27:09 +01:00
intrinsicck.rs remove rustc_error_codes deps except in rustc_driver 2020-01-18 21:53:53 +01:00
lang_items.rs Move it all into rustc_hir. 2020-02-11 23:14:07 +01:00
layout_test.rs Remove rustc_hir reexports in rustc::hir. 2020-01-05 12:49:22 +01:00
lib.rs Move weak_lang_items checking to librustc_passes. 2020-02-11 23:13:03 +01:00
lib_features.rs remove rustc_error_codes deps except in rustc_driver 2020-01-18 21:53:53 +01:00
liveness.rs Run RustFmt 2020-02-11 19:49:01 +10:00
loops.rs remove rustc_error_codes deps except in rustc_driver 2020-01-18 21:53:53 +01:00
reachable.rs Make provided_trait_methods use impl Iterator 2020-02-08 14:37:40 +01:00
region.rs Fix broken link to the rustc guide 2020-02-20 17:34:10 +01:00
stability.rs Auto merge of #69072 - ecstatic-morse:associated-items, r=petrochenkov 2020-02-20 22:44:01 +00:00
upvars.rs Move upvars query to librustc_passes. 2020-01-29 19:43:36 +01:00
weak_lang_items.rs Merge rustc::middle::*lang_items. 2020-02-11 23:15:27 +01:00