about summary refs log tree commit diff
path: root/compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2023-02-16 12:06:36 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2023-02-17 22:24:34 +1100
commitc8237db3eed2c91c14ce46b482b3d479a39d328d (patch)
treee99c61c1267e35d7bc1e6e03528989178490745f /compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp
parent9d5cf0f0bf2f241c2d7a6250ad7f8e3a7dbf3d95 (diff)
downloadrust-c8237db3eed2c91c14ce46b482b3d479a39d328d.tar.gz
rust-c8237db3eed2c91c14ce46b482b3d479a39d328d.zip
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.
Diffstat (limited to 'compiler/rustc_llvm/llvm-wrapper/CoverageMappingWrapper.cpp')
0 files changed, 0 insertions, 0 deletions