rzvxa
d8ad321687
refactor(semantic): make control flow generation optional. ( #3737 )
...
For maximum backward compatibility, we generate CFG by default.
Note: It can't be done with a simple method since lifetimes make it impossible(at least without unsafe trickery) I've tried to do it without a macro but it was just unintuitive.
2024-06-18 15:59:38 +00:00
rzvxa
0537d298db
refactor(cfg)!: move control flow to its own crate. ( #3728 )
2024-06-18 15:59:29 +00:00
Ali Rezvani
e148a32ce3
fix(semantic/cfg): correct unreachability propagation in try-finally. ( #3667 )
...
closes #3663
[oxlint-ecosystem-ci](https://github.com/rzvxa/oxlint-ecosystem-ci/actions/runs/9511509383/job/26217870705 )
From this:

To this:

Since try-finally (without a catch) wouldn't join after finalization.
2024-06-14 14:39:20 +08:00
rzvxa
9c31ed9178
feat(semantic/cfg): propagate unreachable edges through subgraphs. ( #3648 )
...
From this:

To this:

2024-06-13 08:34:12 +00:00
Ali Rezvani
d9c5b33394
feat(semantic/cfg): add Condition instruction. ( #3567 )
2024-06-13 16:17:24 +08:00
rzvxa
f2dfd667df
feat(semantic/cfg): add iteration instructions. ( #3566 )
2024-06-13 07:36:20 +00:00
rzvxa
defef057e1
improvement(semantic/cfg): better control flow for switch statements. ( #3547 )
...
There was an issue similar to the one in loops see #3451 to #3453
2024-06-13 07:36:18 +00:00
rzvxa
9b3097147e
improvement(semantic/cfg): rework error path. ( #3519 )
...
This PR aims to provide a more accurate error/finalization flow, I've nuked the old error path approach and rewrote it with more versatility in mind.
We used to visit the finalizer block twice and create 2 sets of AstNodes/Basic Blocks for them, This was there to differentiate between the error path finalizer and success path one. There is no longer a need for having 2 separate sets of nodes to do this differentiation.
As for the error path now we have 2 kinds of them, Everything is attached to an error block - even if it is not in a try-catch statement - this results in a lot of extra edges to keep track of these "Implicit" error blocks but I believe in future it can help us to track cross block error paths, For example, we can dynamically attach and cache the implicit error block of a function to its call site error path (either implicit or explicit).
2024-06-13 07:36:16 +00:00
Boshen
f6752b482f
feat!(ast): make Trivias clonable by adding Arc ( #3638 )
...
This makes `Trivias` cloneable and stops us from using `Rc::new` and
`Rc::clone` everywhere.
`Trivias` is rarely cloned so an `Arc` should suffice.
2024-06-12 13:16:10 +08:00
Dunqing
5793ff1986
refactor(transformer): replace &’a Trivias with Rc<Trivias> ( #3580 )
...
`Transformer` needs to borrow `Trivias`.
8be1cc8052 (r1630711060)
2024-06-11 13:23:41 +08:00
rzvxa
3c7ee85ce4
improvement(semantic/cfg): better break and continue flow. ( #3462 )
...
This PR adds a new edge type called `Jump` to distinguish between normal edges and jumps.
There is also a control flow context which is used to keep track of cfg scopes and labels. It replaces the old `preserve_state` and `restore_state`.
It corrects some mistakes - such as labeled blocks especially labeled continue which wasn't easy to implement with the old approach - in the old control flow but other than that it is mostly refactored to have a more declarative API instead of a procedural approach.
2024-06-06 07:55:31 +00:00
rzvxa
91c999546c
improvement(semantic/cfg): better control flow for DoWhileStatements. ( #3452 )
...
similar to #3451
2024-06-06 05:41:06 +00:00
rzvxa
0012094188
improvement(semantic/cfg): better control flow for WhileStatements. ( #3451 )
...
Fixes a simple cfg issue, previously it wouldn't follow the body subgraph correctly.
2024-06-06 05:41:04 +00:00
rzvxa
209a99d49f
improvement(semantic/cfg): rework basic blocks. ( #3381 )
...
I've replaced the `BasicBlockElement` with an `Instruction` type which would keep both the instruction kind and its associated AstNodeId.
I also removed the register scheme in the control flow in favor of a simpler approach using explicit enums.
https://github.com/oxc-project/oxc/pull/3381#issuecomment-2126622774
2024-06-06 05:41:01 +00:00
mysteryven
5e06298ec2
fix(linter): memorize visited block id in neighbors_filtered_by_edge_weight ( #3407 )
...
closes : #3396
we visit the same node too many times, I picked some result from run require-render-return rule on [timeserieseexploere.js](https://github.com/elastic/kibana/blob/main/x-pack/plugins/ml/public/application/timeseriesexplorer/timeseriesexplorer.js )
```bash
NodeIndex(64): 368640,
NodeIndex(67): 737280,
NodeIndex(70): 2949120,
NodeIndex(73): 5971968,
NodeIndex(76): 11943936,
NodeIndex(43): 184320,
NodeIndex(71): 2985984,
NodeIndex(65): 368640,
NodeIndex(68): 1474560,
NodeIndex(74): 5971968,
NodeIndex(77): 23887872,
NodeIndex(44): 184320,
NodeIndex(41): 73728,
NodeIndex(35): 36864,
NodeIndex(66): 737280,
NodeIndex(69): 1474560,
NodeIndex(72): 2985984,
NodeIndex(75): 11943936,
```
2024-05-26 08:11:48 +00:00
Boshen
de75fb2942
refactor: compile less test binaries to speed up CI ( #3414 )
...
The semantic crate currently compiles 5 binaries for integration test, this PR merges them into one.
2024-05-26 07:21:44 +00:00
Boshen
893af230c0
refactor: clean up more diagnostics usages
2024-05-12 21:46:03 +08:00
Boshen
dbde5b3a04
refactor(diagnostics): remove export of miette
2024-05-12 11:46:48 +08:00
Ali Rezvani
20f643063e
improvement(semantic/cfg): add explicit break block element. ( #3223 )
...
Works similar to how `throw` is working but is done for `break` statements.
2024-05-10 22:22:30 +08:00
Ali Rezvani
5e36e0d575
fix(semantic): add cfg nodes for ConditionalExpressions. ( #3127 )
...
It is done similarly to how `IfStatement`s are structured at the moment.
2024-05-10 22:16:55 +08:00
renovate[bot]
56a0db8621
chore(deps): update dependency rust to v1.78.0 ( #3151 )
2024-05-03 00:01:42 +08:00
Boshen
84c43c8282
fix(semantic): correctly resolve identifiers inside catch parameter initializers ( #3050 )
...
closes #2499
2024-04-21 23:53:38 +08:00
Boshen
1f7033e7ab
fix(semantic): correctly resolve identifiers inside parameter initializers ( #3046 )
...
close : #2644
This fixes function parameters. I think we need an extra AST node to fix catch parameters, which will be the next PR.
2024-04-21 23:38:31 +08:00
Don Isaac
1ea24ea0a7
fix(semantic): symbols inside functions and classes incorrectly flagged as exported ( #2896 )
...
# What This PR Does
Symbols declared inside exported functions and classes were being
incorrectly flagged with `SymbolFlags::Export`.
For example,
```ts
export function foo<T>(a: T) {
let b = String(a)
return b
}
```
`T`, `a`, and `b` were all flagged as exported.
## Further Work
It doesn't seem like exported enums and interfaces are being included in
`ModuleRecord`. Am I looking in the wrong place, or are they actually
missing?
2024-04-05 23:01:27 +08:00
Don Isaac
d3eb1c3318
fix(semantic): flag function expressions with SymbolFlags::Function ( #2891 )
...
# What This PR Does
Consider the following code snippet
```js
const x = function y () {{
```
`y` will now be flagged with `SymbolFlags::Function`. This follow's
tsc's behavior.
- [Example in OXC
Playground](https://oxc-project.github.io/oxc/playground/?code=3YCAAICagICAgICAgICxG0qZRraXZOpcCHVsSRwDq2kRR0HprsTfRRT5WMw%2Ff2epoIA%3D )
- [Example in TypeScript AST
Viewer](https://ts-ast-viewer.com/#code/MYewdgzgLgBAHjAvDAZgVzMKBLcMCeAFAJQwDeAvgFBA )
2024-04-03 10:42:11 +08:00
Dunqing
947a9f05e8
fix(semantic): missing SymbolFlags::Export when identifier used in ExportDefaultDeclaration ( #2837 )
2024-03-27 14:13:25 +08:00
Boshen
4f9dd98a97
feat(span): remove From<String> and From<Cow> API because they create memory leak ( #2628 )
...
closes #2621
2024-03-06 20:38:21 +08:00
Dunqing
1519b9000b
fix(semantic): incorrect scope for switch statement ( #2513 )
...
close : #2501
2024-02-26 22:54:19 +08:00
Boshen
be6b8b7ce6
[BREAKING CHANGE] Change Atom to Atom<'a> to make it safe ( #2497 )
...
Part of #2295
This PR splits the `Atom` type into `Atom<'a>` and `CompactString`.
All the AST node strings now use `Atom<'a>` instead of `Atom` to signify
it belongs to the arena.
It is now up to the user to select which form of the string to use.
This PR essentially removes the really unsafe code
93742f89e9/crates/oxc_span/src/atom.rs (L98-L107)
which can lead to

2024-02-26 19:34:40 +08:00
Dunqing
4c2e2bdf61
fix(semantic): add export symbol flag to identifiers in export declarations ( #2508 )
...
Related PR: #2335
2024-02-26 15:48:05 +08:00
Boshen
fba66dcc75
fix(linter): improve import/no-named-as-default ( #2494 )
2024-02-25 21:24:08 +08:00
Dunqing
40e9541cec
feat(semantic): add export binding for ExportDefaultDeclarations in module record ( #2329 )
2024-02-06 22:01:16 +08:00
Dunqing
cb17a83f4f
fix(semantic): remove ignore cases ( #2300 )
2024-02-04 22:40:41 +08:00
Tzvi Melamed
f4674f33b2
fix(oxc_semantic): Handle short-circuiting operators in CFG ( #2252 )
...
Closes #2239
2024-02-01 21:04:28 +08:00
Tzvi Melamed
73ccf8a4da
fix(oxc_semantic): proper traversal of try statements ( #2250 )
...
Closes #2227
2024-02-01 20:46:38 +08:00
Tzvi Melamed
e561457683
feat(semantic): track cfg index per ast node ( #2210 )
...
This allows looking up a cfg index from an ast node in a semantics
return. This allows later passes to better make use of the cfg.
2024-02-01 13:27:20 +08:00
Boshen
87b9978859
refactor: move all miette usages to oxc_diagnostics
2024-01-28 16:52:16 +08:00
Boshen
fc1592bc97
refactor(semantic): remove all #[dead_code[ from tester
2024-01-25 20:27:46 +08:00
Boshen
889837704c
feat(semantic): cfg prototype ( #2019 )
...
Co-authored-by: U9G <git@u9g.dev>
2024-01-25 20:19:35 +08:00
Dunqing
6c5b22f728
refactor(semantic): improve ClassTable implmention and merge properties and methods to elements ( #1902 )
2024-01-05 18:38:51 +08:00
IWANABETHATGUY
4bbc977971
chore: upgrade rustc toolchain to stable 1.75.0 ( #1853 )
...
ref:
https://blog.rust-lang.org/2023/12/28/Rust-1.75.0.html
2023-12-29 12:20:51 +08:00
Dunqing
ca04312130
feat(semantic): add ClassTable ( #1793 )
2023-12-25 23:59:35 +08:00
Dunqing
edc6fa4830
feat(semantic): add SymbolFlags::Function for FunctionDeclaration ( #1713 )
...
Co-authored-by: Boshen <boshenc@gmail.com>
2023-12-18 11:26:33 +08:00
Boshen
128406a8ab
Rust v1.74.0 ( #1357 )
2023-11-16 15:21:45 +00:00
Don Isaac
b4b39b8aa6
test(semantic): add scoping test cases ( #954 )
...
Add test cases to `oxc_semantic` that check scope flag behavior.
Also contains these tweaks:
- fix: allow disabling `with_module` on `SourceType`
- refactor: move `SymbolTester` to a separate file
- chore: add `Expect` trait & implement it on `SymbolTester`
2023-10-03 18:16:01 +13:00
Boshen
9ff12a9696
feat(linter): eslint-plugin-import/no-self-import ( #878 )
...
closes #440 #441
2023-09-10 00:12:26 +08:00
Boshen
ee54575ec1
feat(linter): add runner for import-plugin ( #858 )
2023-09-06 14:54:19 +08:00
Boshen
2f48bdf26f
fix(parser,semantic): make semantic own Trivias ( #711 )
...
closes #708
Making the parser return Rc<Trivias> is not a good API, and ideally
`Semantic` should just own `Trivias` so it can process or mutate it.
2023-08-10 15:30:32 +08:00
Don Isaac
38fb4c296a
test(semantic): test harness ( #679 )
...
A test harness for checking results of semantic analysis.
I got tired of writing ad-hoc test cases when finding bugs in semantic
analysis, so I made this.
2023-08-07 10:43:05 +08:00