oxc/tasks/coverage
Boshen 2064ae9e0a refactor(parser,diagnostic): one diagnostic struct to eliminate monomorphization of generic types (#3214)
part of #3213

We should only have one diagnostic struct instead 353 copies of them, so we don't end up choking LLVM with 50k lines of the same code due to monomorphization.

If the proposed approach is good, then I'll start writing a codemod to turn all the existing structs to plain functions.

---

Background:

Using `--timings`, we see `oxc_linter` is slow on codegen (the purple part).

![image](https://github.com/zkat/miette/assets/1430279/c1df4f7d-90ef-4c0f-9956-2ec3194db7ca)

The crate currently contains 353 miette errors. [cargo-llvm-lines](https://github.com/dtolnay/cargo-llvm-lines) displays

```
cargo llvm-lines -p oxc_linter --lib --release

  Lines                 Copies               Function name
  -----                 ------               -------------
  830350                33438                (TOTAL)
   29252 (3.5%,  3.5%)    808 (2.4%,  2.4%)  <alloc::boxed::Box<T,A> as core::ops::drop::Drop>::drop
   23298 (2.8%,  6.3%)    353 (1.1%,  3.5%)  miette::eyreish::error::object_downcast
   19062 (2.3%,  8.6%)    706 (2.1%,  5.6%)  core::error::Error::type_id
   12610 (1.5%, 10.1%)     65 (0.2%,  5.8%)  alloc::raw_vec::RawVec<T,A>::grow_amortized
   12002 (1.4%, 11.6%)    706 (2.1%,  7.9%)  miette::eyreish::ptr::Own<T>::boxed
    9215 (1.1%, 12.7%)    115 (0.3%,  8.2%)  core::iter::traits::iterator::Iterator::try_fold
    9150 (1.1%, 13.8%)      1 (0.0%,  8.2%)  oxc_linter::rules::RuleEnum::read_json
    8825 (1.1%, 14.9%)    353 (1.1%,  9.3%)  <miette::eyreish::error::ErrorImpl<E> as core::error::Error>::source
    8822 (1.1%, 15.9%)    353 (1.1%, 10.3%)  miette::eyreish::error::<impl miette::eyreish::Report>::construct
    8119 (1.0%, 16.9%)    353 (1.1%, 11.4%)  miette::eyreish::error::object_ref
    8119 (1.0%, 17.9%)    353 (1.1%, 12.5%)  miette::eyreish::error::object_ref_stderr
    7413 (0.9%, 18.8%)    353 (1.1%, 13.5%)  <miette::eyreish::error::ErrorImpl<E> as core::fmt::Display>::fmt
    7413 (0.9%, 19.7%)    353 (1.1%, 14.6%)  miette::eyreish::ptr::Own<T>::new
    6669 (0.8%, 20.5%)     39 (0.1%, 14.7%)  alloc::raw_vec::RawVec<T,A>::try_allocate_in
    6173 (0.7%, 21.2%)    353 (1.1%, 15.7%)  miette::eyreish::error::<impl miette::eyreish::Report>::from_std
    6027 (0.7%, 21.9%)     70 (0.2%, 16.0%)  <alloc::vec::Vec<T> as alloc::vec::spec_from_iter_nested::SpecFromIterNested<T,I>>::from_iter
    6001 (0.7%, 22.7%)    353 (1.1%, 17.0%)  miette::eyreish::error::object_drop
    6001 (0.7%, 23.4%)    353 (1.1%, 18.1%)  miette::eyreish::error::object_drop_front
    5648 (0.7%, 24.1%)    353 (1.1%, 19.1%)  <miette::eyreish::error::ErrorImpl<E> as core::fmt::Debug>::fmt
```

It's totalling more than 50k llvm lines, and is putting pressure on rustc codegen (the purple part on `oxc_linter` in the image above.

---

It's pretty obvious by looking at https://github.com/zkat/miette/blob/main/src/eyreish/error.rs, the generics can expand out to lots of code.
2024-05-11 04:56:22 +00:00
..
misc fix(parser): fix failed to parse JSXChild after JSXEmptyExpression (#2726) 2024-03-15 13:39:20 +08:00
src refactor(parser,diagnostic): one diagnostic struct to eliminate monomorphization of generic types (#3214) 2024-05-11 04:56:22 +00:00
Cargo.toml refactor(coverage): replace yaml parsing with saphyr (#3144) 2024-04-30 22:49:39 +08:00
codegen_babel.snap chore: update babel repo (#3205) 2024-05-08 20:15:15 +08:00
codegen_misc.snap fix(parser): fix failed to parse JSXChild after JSXEmptyExpression (#2726) 2024-03-15 13:39:20 +08:00
codegen_runtime_test262.snap
codegen_sourcemap.snap chore: update babel repo (#3205) 2024-05-08 20:15:15 +08:00
codegen_test262.snap feat(Codegen): Improve codegen (#2460) 2024-02-21 14:41:57 +08:00
codegen_typescript.snap feat(Codegen): Improve codegen (#2460) 2024-02-21 14:41:57 +08:00
minifier_babel.snap
minifier_test262.snap
parser_babel.snap fix(parser): correctly parse cls.fn<C> = x (#3208) 2024-05-09 10:23:45 +08:00
parser_misc.snap fix(parser): fix failed to parse JSXChild after JSXEmptyExpression (#2726) 2024-03-15 13:39:20 +08:00
parser_test262.snap chore(parser): make sure all span.end >= span.start (#2681) 2024-03-11 19:49:51 +08:00
parser_typescript.snap feat(semantic): report namespace related errors (#3093) 2024-04-25 14:01:58 +08:00
prettier_babel.snap chore: update babel repo (#3205) 2024-05-08 20:15:15 +08:00
prettier_misc.snap fix(parser): fix failed to parse JSXChild after JSXEmptyExpression (#2726) 2024-03-15 13:39:20 +08:00
prettier_test262.snap fix(prettier): print bare import (#2633) 2024-03-07 14:03:20 +08:00
prettier_typescript.snap feat(prettier/ts): better conformance (#2721) 2024-03-20 18:59:49 +08:00
README.md
transformer_babel.snap chore: update babel repo (#3205) 2024-05-08 20:15:15 +08:00
transformer_misc.snap feat(coverage): add transformer to prevent crashes (#2970) 2024-04-14 18:52:51 +08:00
transformer_test262.snap feat(coverage): add transformer to prevent crashes (#2970) 2024-04-14 18:52:51 +08:00
transformer_typescript.snap feat(coverage): add transformer to prevent crashes (#2970) 2024-04-14 18:52:51 +08:00

Coverage

The parser is tested against test262, babel and TypeScript for conformance.

Note: tests against regexp are disabled for now.

Clone the test files beforehand:

git submodule update --init

Development

# full run
cargo coverage
cargo coverage js # for test262
cargo coverage babel # for babel
cargo coverage ts # for typescript

# run in watch
cargo watch -x 'coverage js'

# filter for a file path
cargo watch -x 'coverage js --filter filter-file-path'