rust/compiler
Nicholas Nethercote c8237db3ee Clarify iterator interners.
There are two traits, `InternAs` and `InternIteratorElement`. I found
them confusing to use, particularly this:
```
pub fn mk_tup<I: InternAs<Ty<'tcx>, Ty<'tcx>>>(self, iter: I) -> I::Output {
    iter.intern_with(|ts| self.intern_tup(ts))
}
```
where I thought there might have been two levels of interning going on
(there isn't) due to the `intern_with`/`InternAs` + `intern_tup` naming.

And then I found the actual traits and impls themselves *very*
confusing.
- `InternAs` has a single impl, for iterators, with four type variables.
- `InternAs` is only implemented for iterators because it wouldn't
  really make sense to implement for any other type. And you can't
  really understand the trait without seeing that single impl, which is
  suspicious.
- `InternAs` is basically just a wrapper for `InternIteratorElement`
  which does all the actual work.
- Neither trait actually does any interning. They just have `Intern` in
  their name because they are used *by* interning code.
- There are no comments.

So this commit improves things.
- It removes `InternAs` completely. This makes the `mk_*` function
  signatures slightly more verbose -- two trait bounds instead of one --
  but much easier to read, because you only need to understand one trait
  instead of two.
- It renames `InternIteratorElement` as `CollectAndApply`. Likewise, it
  renames its method `intern_with` as `collect_and_apply`. These names
  describe better what's going on: we collect the iterator elements into
  a slice and then apply a function to the slice.
- It adds comments, making clear that all this is all there just to
  provide an optimized version of `f(&iter.collect::<Vec<_>>())`.

It took me a couple of attempts to come up with this commit. My initial
attempt kept `InternAs` around, but renamed things and added comments,
and I wasn't happy with it. I think this version is much better. The
resulting code is shorter, despite the addition of the comments.
2023-02-17 22:24:34 +11:00
..
rustc Add a new rustc_driver dylib to rexport rustc_driver_impl 2023-02-02 07:34:41 +01:00
rustc_abi Rollup merge of #107163 - mikebenfield:parameters-pr, r=TaKO8Ki 2023-02-15 12:24:54 +05:30
rustc_apfloat compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
rustc_arena compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
rustc_ast rustc_ast: Merge impls and reorder methods for attributes and meta items 2023-02-11 23:23:17 +04:00
rustc_ast_lowering Better label for illegal impl trait types 2023-02-14 23:12:27 +00:00
rustc_ast_passes Rollup merge of #107489 - compiler-errors:non_lifetime_binders, r=cjgillot 2023-02-17 00:19:34 +01:00
rustc_ast_pretty Expand const-if-const trait bounds correctly 2023-02-07 21:00:12 +00:00
rustc_attr Add feature gate for non_lifetime_binders 2023-02-16 03:39:58 +00:00
rustc_baked_icu_data update ICU4X to 1.1.0 2023-02-04 22:28:59 +01:00
rustc_borrowck Replace mk_foo calls with infer_foo where possible. 2023-02-17 22:24:31 +11:00
rustc_builtin_macros Replace some thens with some then_somes 2023-02-16 15:26:03 +00:00
rustc_codegen_cranelift Replace mk_foo calls with infer_foo where possible. 2023-02-17 22:24:31 +11:00
rustc_codegen_gcc s/eval_usize/eval_target_usize/ for clarity 2023-02-14 08:51:19 +00:00
rustc_codegen_llvm remove bound_type_of query; make type_of return EarlyBinder; change type_of in metadata 2023-02-16 17:05:56 -07:00
rustc_codegen_ssa Rollup merge of #108086 - alexcrichton:wasm-relaxed-simd-feature, r=eholk 2023-02-17 00:19:36 +01:00
rustc_const_eval Replace mk_foo calls with infer_foo where possible. 2023-02-17 22:24:31 +11:00
rustc_data_structures if $c:expr { Some($r:expr) } else { None } =>> $c.then(|| $r) 2023-02-16 15:26:00 +00:00
rustc_driver Remove unneeded extern crate 2023-02-02 07:47:39 +01:00
rustc_driver_impl Remove save-analysis. 2023-02-16 15:14:45 +11:00
rustc_error_codes Add extended error message for E0523 2023-02-06 06:58:30 -05:00
rustc_error_messages Remove save-analysis. 2023-02-16 15:14:45 +11:00
rustc_errors Rollup merge of #108090 - WaffleLapkin:if_not_now_then_when…, r=oli-obk 2023-02-16 17:51:25 +01:00
rustc_expand Replace some thens with some then_somes 2023-02-16 15:26:03 +00:00
rustc_feature Rollup merge of #107489 - compiler-errors:non_lifetime_binders, r=cjgillot 2023-02-17 00:19:34 +01:00
rustc_fs_util Remove useless borrows and derefs 2022-12-01 17:34:43 +00:00
rustc_graphviz Fix uninlined_format_args for some compiler crates 2023-01-05 19:01:12 +01:00
rustc_hir if $c:expr { Some($r:expr) } else { None } =>> $c.then(|| $r) 2023-02-16 15:26:00 +00:00
rustc_hir_analysis Replace mk_foo calls with infer_foo where possible. 2023-02-17 22:24:31 +11:00
rustc_hir_pretty Use Mutability::{is_mut, is_not} 2023-01-30 12:26:26 +00:00
rustc_hir_typeck Remove the InternIteratorElement impl for &'a T. 2023-02-17 22:24:34 +11:00
rustc_incremental incremental: migrate diagnostics 2023-01-30 17:11:35 +00:00
rustc_index Fix IndexVec::drain_enumerated 2023-01-19 15:25:33 +00:00
rustc_infer Auto merge of #107753 - kylematsuda:type-of, r=BoxyUwU 2023-02-17 04:45:15 +00:00
rustc_interface Move provider fields back to rustc_query_impl 2023-02-16 14:55:05 +01:00
rustc_lexer Remove double spaces after dots in comments 2023-01-17 08:09:33 +00:00
rustc_lint Auto merge of #107753 - kylematsuda:type-of, r=BoxyUwU 2023-02-17 04:45:15 +00:00
rustc_lint_defs Extend BYTE_SLICE_IN_PACKED_STRUCT_WITH_DERIVE. 2023-02-09 11:47:12 +11:00
rustc_llvm Update the minimum external LLVM to 14 2023-02-10 16:06:25 -08:00
rustc_log Rollup merge of #107895 - matthiaskrgr:cl, r=compiler-errors 2023-02-11 17:18:44 +01:00
rustc_macros Use derive attributes for uninteresting traversals 2023-02-14 15:09:40 +00:00
rustc_metadata Replace mk_foo calls with infer_foo where possible. 2023-02-17 22:24:31 +11:00
rustc_middle Clarify iterator interners. 2023-02-17 22:24:34 +11:00
rustc_mir_build remove bound_type_of query; make type_of return EarlyBinder; change type_of in metadata 2023-02-16 17:05:56 -07:00
rustc_mir_dataflow Replace some thens with some then_somes 2023-02-16 15:26:03 +00:00
rustc_mir_transform Replace mk_foo calls with infer_foo where possible. 2023-02-17 22:24:31 +11:00
rustc_monomorphize remove bound_type_of query; make type_of return EarlyBinder; change type_of in metadata 2023-02-16 17:05:56 -07:00
rustc_parse Replace some thens with some then_somes 2023-02-16 15:26:03 +00:00
rustc_parse_format Replace some thens with some then_somes 2023-02-16 15:26:03 +00:00
rustc_passes Auto merge of #107753 - kylematsuda:type-of, r=BoxyUwU 2023-02-17 04:45:15 +00:00
rustc_plugin_impl
rustc_privacy Auto merge of #107753 - kylematsuda:type-of, r=BoxyUwU 2023-02-17 04:45:15 +00:00
rustc_query_impl Move provider fields back to rustc_query_impl 2023-02-16 14:55:05 +01:00
rustc_query_system Auto merge of #107833 - Zoxc:arena-query-clean, r=cjgillot 2023-02-16 22:10:10 +00:00
rustc_resolve Rollup merge of #107489 - compiler-errors:non_lifetime_binders, r=cjgillot 2023-02-17 00:19:34 +01:00
rustc_serialize compiler: remove unnecessary imports and qualified paths 2022-12-10 18:45:34 +01:00
rustc_session Rollup merge of #107489 - compiler-errors:non_lifetime_binders, r=cjgillot 2023-02-17 00:19:34 +01:00
rustc_smir
rustc_span Rollup merge of #107489 - compiler-errors:non_lifetime_binders, r=cjgillot 2023-02-17 00:19:34 +01:00
rustc_symbol_mangling Remove the InternIteratorElement impl for &'a T. 2023-02-17 22:24:34 +11:00
rustc_target Rollup merge of #107968 - ian-h-chamberlain:feature/3ds-enable-thread-local, r=Nilstrieb 2023-02-15 12:24:55 +05:30
rustc_trait_selection Remove the InternIteratorElement impl for &'a T. 2023-02-17 22:24:34 +11:00
rustc_traits remove bound_type_of query; make type_of return EarlyBinder; change type_of in metadata 2023-02-16 17:05:56 -07:00
rustc_transmute s/eval_usize/eval_target_usize/ for clarity 2023-02-14 08:51:19 +00:00
rustc_ty_utils Remove the InternIteratorElement impl for &'a T. 2023-02-17 22:24:34 +11:00
rustc_type_ir Clarify iterator interners. 2023-02-17 22:24:34 +11:00