Commit graph

29 commits

Author SHA1 Message Date
Boshen
8a788b8f4b feat(parser)!: Build ModuleRecord directly in parser (#7546)
This has the benefit of:

* expose dynamic import / import meta info from parser
* 1 less ast shallow in semantic builder
* no ast walk in oxc's module lexer
* some more benefits coming soon
2024-11-29 14:50:42 +00:00
Boshen
4740642926
chore(semantic): rename examples/simple.rs to examples/semantic.rs 2024-11-12 11:55:58 +08:00
Boshen
435a89c6e4 refactor(oxc): remove useless allocator.alloc(program) calls (#6571) 2024-10-15 02:21:20 +00:00
Boshen
520096030a refactor(oxc)!: remove passing Trivias around (#6446)
part of #6426
2024-10-11 06:09:25 +00:00
Boshen
2b7be08af4 feat(ast)! add source_text to Program (#6444) 2024-10-11 04:13:41 +00:00
DonIsaac
40932f79b1 refactor(cfg): use IndexVec for storing basic blocks (#6323)
Use an `IndexVec` when storing basic blocks. This makes the link between nodes in `.graph` and elements of `.basic_blocks` more clear. I had to rename `BasicBlockId` to `BlockNodeId` to avoid a name collision. I wasn't sure what else to name the `Idx` type for the basic blocks vec.
2024-10-07 19:28:40 -04:00
DonIsaac
95ca01ccc1 refactor(cfg)!: make BasicBlock::unreachable private (#6321)
Protect `unreachable` property of basic blocks in preparation of upcoming
refactors. This is technically a breaking change.
2024-10-07 15:13:56 +00:00
camchenry
2b17003e0b perf(linter, prettier, diagnostics): use FxHashMap instead of std::collections::HashMap (#5993)
Using `FxHashMap` is faster than `HashMap` in many cases, especially for hashing-heavy workloads. This change improves the performance of the linter, prettier, and diagnostics crates by using `FxHashMap` instead of `std::collections::HashMap`.
2024-09-23 16:29:05 +00:00
DonIsaac
3d13c6d1f9 refactor(semantic): impl IntoIterator for &AstNodes (#5873)
Simple quality-of-life change.
2024-09-19 03:22:29 +00:00
Boshen
b06052501a refactor(semantic)!: remove source_type argument from SemanticBuilder::new (#5553)
Realized we can get the source type from the AST.

The next PR will introduce `unambiguous` to `SourceType` and directly set `Program::source_type` to either `script` or `module`.
2024-09-06 16:40:10 +00:00
Boshen
3ae94b8801
refactor(semantic): change build_module_record to accept &Path instead of PathBuf 2024-08-30 12:24:49 +08:00
Boshen
7cc2bbd293
chore(semantic): print errors from examples/simple.rs 2024-08-23 22:57:26 +08:00
DonIsaac
0a01a4729a docs(semantic): improve documentation (#4850) 2024-08-13 02:14:07 +00:00
overlookmotel
d79b60afc4 example(semantic): examples print parser errors (#4405)
Examples for `Semantic` print parser errors if parsing fails.
2024-07-22 11:05:03 +00:00
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
Boshen
982e6f08df chore: make println and eprintln opt-in (#3712)
I noticed accidental `println` can be merged, which isn't really nice.
2024-06-17 10:40:34 +00:00
rzvxa
9c31ed9178 feat(semantic/cfg): propagate unreachable edges through subgraphs. (#3648)
From this:

![Screenshot 2024-06-12 230152](https://github.com/oxc-project/oxc/assets/3788964/b489cee8-62ec-4483-9c9b-6e3d9858fec2)

To this:

![Screenshot 2024-06-12 230031](https://github.com/oxc-project/oxc/assets/3788964/674a6e42-5311-4ca6-940b-65d8e3ccc0f4)
2024-06-13 08:34:12 +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
61bae74f76 improvement(semantic/cfg): better CFG API (#3472) 2024-06-06 07:55:37 +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
rzvxa
78e6326e48 refactor(semantic/cfg): alias petgraph's NodeIndex as BasicBlockId. (#3380)
Hides petgraph's general `NodeIndex` type behind `BasicBlockId`.
2024-05-22 03:09:38 +00:00
Boshen
a2c173de57
refactor: remove panic! from examples (#2454)
relates #2308
2024-02-20 16:18:39 +08:00
Tzvi Melamed
27681951e1
feat(oxc_semantic): Improve sample visualization (#2251)
1. add a `test.js` file to the project root:

```js
class A extends B {
  constructor() {
    try {
      super();
    } finally {
      this.a;
    }
  }
}
```

2. run:

```bash
$ cargo run -p oxc_semantic --example simple
   Compiling oxc_semantic v0.5.0 (/home/tzvipm/src/github.com/tzvipm/oxc/crates/oxc_semantic)
    Finished dev [unoptimized + debuginfo] target(s) in 32.07s
     Running `target/debug/examples/simple`
Wrote AST to: test.ast.txt
Wrote CFG blocks to: test.cfg.txt
Wrote CFG dot diagram to: test.dot
```

3. resulting graph from .dot file:


![image](https://github.com/TzviPM/oxc/assets/1950680/7163deaa-ab75-4bed-a093-946e2d6d2206)
2024-02-01 12:55:56 +00: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
Dunqing
972be831e9
fix(semantic): fix incorrect semantic example (#2198) 2024-01-29 06:48:47 +00:00
Boshen
889837704c
feat(semantic): cfg prototype (#2019)
Co-authored-by: U9G <git@u9g.dev>
2024-01-25 20:19:35 +08:00