2021-03-15 19:00:00 -05:00
|
|
|
1| |// compile-flags: -Zinline-mir
|
|
|
|
2| |
|
|
|
|
3| |use std::fmt::Display;
|
|
|
|
4| |
|
|
|
|
5| 1|fn main() {
|
|
|
|
6| 1| permutations(&['a', 'b', 'c']);
|
|
|
|
7| 1|}
|
|
|
|
8| |
|
|
|
|
9| |#[inline(always)]
|
|
|
|
10| 1|fn permutations<T: Copy + Display>(xs: &[T]) {
|
|
|
|
11| 1| let mut ys = xs.to_owned();
|
|
|
|
12| 1| permutate(&mut ys, 0);
|
|
|
|
13| 1|}
|
|
|
|
14| |
|
|
|
|
15| 16|fn permutate<T: Copy + Display>(xs: &mut [T], k: usize) {
|
|
|
|
16| 16| let n = length(xs);
|
|
|
|
17| 16| if k == n {
|
|
|
|
18| 6| display(xs);
|
|
|
|
19| 10| } else if k < n {
|
|
|
|
20| 15| for i in k..n {
|
|
|
|
^10
|
|
|
|
21| 15| swap(xs, i, k);
|
|
|
|
22| 15| permutate(xs, k + 1);
|
|
|
|
23| 15| swap(xs, i, k);
|
|
|
|
24| 15| }
|
|
|
|
25| 0| } else {
|
|
|
|
26| 0| error();
|
|
|
|
27| 0| }
|
|
|
|
28| 16|}
|
|
|
|
29| |
|
|
|
|
30| 16|fn length<T>(xs: &[T]) -> usize {
|
|
|
|
31| 16| xs.len()
|
|
|
|
32| 16|}
|
|
|
|
33| |
|
|
|
|
34| |#[inline]
|
|
|
|
35| 30|fn swap<T: Copy>(xs: &mut [T], i: usize, j: usize) {
|
|
|
|
36| 30| let t = xs[i];
|
|
|
|
37| 30| xs[i] = xs[j];
|
|
|
|
38| 30| xs[j] = t;
|
|
|
|
39| 30|}
|
|
|
|
40| |
|
|
|
|
41| 6|fn display<T: Display>(xs: &[T]) {
|
2021-11-19 10:29:29 -06:00
|
|
|
42| 24| for x in xs {
|
|
|
|
^18
|
2021-03-15 19:00:00 -05:00
|
|
|
43| 18| print!("{}", x);
|
|
|
|
44| 18| }
|
|
|
|
45| 6| println!();
|
|
|
|
46| 6|}
|
|
|
|
47| |
|
|
|
|
48| |#[inline(always)]
|
Translate counters from Rust 1-based to LLVM 0-based counter ids
A colleague contacted me and asked why Rust's counters start at 1, when
Clangs appear to start at 0. There is a reason why Rust's internal
counters start at 1 (see the docs), and I tried to keep them consistent
when codegenned to LLVM's coverage mapping format. LLVM should be
tolerant of missing counters, but as my colleague pointed out,
`llvm-cov` will silently fail to generate a coverage report for a
function based on LLVM's assumption that the counters are 0-based.
See:
https://github.com/llvm/llvm-project/blob/main/llvm/lib/ProfileData/Coverage/CoverageMapping.cpp#L170
Apparently, if, for example, a function has no branches, it would have
exactly 1 counter. `CounterValues.size()` would be 1, and (with the
1-based index), the counter ID would be 1. This would fail the check
and abort reporting coverage for the function.
It turns out that by correcting for this during coverage map generation,
by subtracting 1 from the Rust Counter ID (both when generating the
counter increment intrinsic call, and when adding counters to the map),
some uncovered functions (including in tests) now appear covered! This
corrects the coverage for a few tests!
2021-04-02 02:08:48 -05:00
|
|
|
49| 0|fn error() {
|
|
|
|
50| 0| panic!("error");
|
|
|
|
51| 0|}
|
2021-03-15 19:00:00 -05:00
|
|
|
|