Skip to content

Commit

Permalink
doc: Document debugging tips (#214)
Browse files Browse the repository at this point in the history
  • Loading branch information
kdy1 committed Nov 5, 2022
1 parent 76f55ca commit 56ae129
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
1 change: 1 addition & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# These are supported funding model platforms

github: kdy1
open_collective: stc
30 changes: 30 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,36 @@ It will dump type information to a `foo.swc-stderr` file.
Look at it, and if it's wrong, adjust the Rust source code, and run `./scripts/check.sh` to verify if your fix is correct.
If you are done, please file a pull request on GitHub.

### Directories for testing

See [the readme of the file analyzer](./crates/stc_ts_file_analyzer/) for more details.

### Debugging tips

#### `print_backtrace()`

If you think some code should not be invoked but seems like it's invoked, you can use `print_backtrace()`.
It will automatically exclude useless items from the stack trace.

#### Matching over `Type`

To avoid performance drop caused by cloning, stc uses `Type::Arc` to share memory.
But there's a downside for this - you have to call `normalize()` while matching.

e.g.

```rust
match ty.normalize() {
}
```

Note that this is different from `self.normalize(ty)` of `Analyzer`, which is used to expand special types like references, queries, mapped, etc..

#### Finding problematic code

Look at the `context:` in the error output, and search it from repository using substring of the context.
e.g. `tried to assign to a template type` means the error comes from https://github.com/dudykr/stc/blob/1c73ce5fa87ec789ead108c5c6876e8089b1e5de/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs#L2208

### Updating performance stats

You can run `./scripts/release-time.sh` from `./crates/stc_ts_type_checker` to update timing stats file.
Expand Down
1 change: 1 addition & 0 deletions cspell.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"dedup",
"dejavu",
"deps",
"dudykr",
"elems",
"fastpath",
"fxhash",
Expand Down

0 comments on commit 56ae129

Please sign in to comment.