Commit graph

61 commits

Author SHA1 Message Date
rzvxa
fff9da319d fix(ast, ast_codegen): use generate_derive instead of visitable for generating span derives. (#4747)
follow-up to #4735
I was accidentally using the old code to filter the viable target types to derive. It means before this PR we were still using the `#[ast(visit)]` for this purpose.
2024-08-08 17:06:48 +00:00
rzvxa
abe8202ba8 refactor(ast_codegen): declutter the main file. (#4744)
same as #4741
2024-08-08 16:38:13 +00:00
overlookmotel
7345f68d9e refactor(ast_codegen): remove Generator::name and Pass::name methods (#4764)
Remove `Generator::name` and `Pass::name` methods. All impls for these methods return a string identical to the struct name, so can set return value of `Runner::name` in `define_generator!` and `define_pass!` macros instead.
2024-08-08 15:39:10 +00:00
overlookmotel
d32fb6f5c5 refactor(ast_codegen): re-order imports (#4763)
Move imports to top of file in `generators/mod.rs`, just for consistency.
2024-08-08 15:39:09 +00:00
overlookmotel
80046d1144 refactor(ast_codegen): consistent endl! position (#4762)
Pure refactor (style nit). Place `endl!()` macro calls in consistent position throughout codegen.
2024-08-08 15:39:08 +00:00
overlookmotel
2dea0caae0 refactor(ast_codegen): consistent import order (#4761)
Pure refactor. Alter import order in generated code to consistent order - `std`, external crates, `crate`, `super`.
2024-08-08 15:24:45 +00:00
overlookmotel
790c551c5e refactor(ast_codegen): simplify derive_get_span generator (#4757)
Simplify `derive_get_span` generator that was introduced in #4735. No change to functionality, just aiming for greater readability.

In particular:

* Move defining idents/tokens which are specific to `GetSpan` / `GetSpanMut` into those specific generators, rather than branching on `MUT` later on.
* Remove `const MUT` param.
* Remove the confusing pairs of closures and functions both called `derive_enum` / `derive_struct`.
* Inline function which generates the impls - prioritizing readability over DRY code.
2024-08-08 10:47:37 +00:00
overlookmotel
f36500a2bd refactor(ast_codegen): flatten code (#4743)
A bit of code style simplification after #4731. Remove unnecessary nesting and rename some vars for consistency.
2024-08-07 22:32:07 +00:00
rzvxa
aeed29f248 chore(ci): generate .generated_ast_watch_list.yml (#4737)
closes #4699

I also did some reordering to the code so it is easier to follow.
2024-08-07 22:11:34 +00:00
rzvxa
2218340f2b refactor(ast, ast_codegen): use generate_derive for implementing GetSpan and GetSpanMut traits. (#4735) 2024-08-07 22:07:33 +00:00
rzvxa
579b797cc5 refactor(ast): use type identifier instead of CloneIn::Cloned GAT. (#4738)
After https://github.com/oxc-project/oxc/pull/4731#discussion_r1707526289, I realized that I'm using `Self::Cloned` for enum derives. It was from my earlier attempts to resolve lifetime issues.
2024-08-07 21:23:23 +00:00
rzvxa
ec0b4cbdaa feat(ast_codegen): add derive_clone_in generator. (#4731)
Follow-on after #4276, related to #4284.
2024-08-07 20:29:06 +00:00
rzvxa
2e91ad6c4e feat(ast_codegen): support for generate_derive marker. (#4728)
Follow-on after #4276, related to #4284.
2024-08-07 17:38:13 +00:00
overlookmotel
06efae6e4c refactor(ast_codegen): reorder imports (#4709)
Pure refactor. Reorder imports to clarify what's an external crate and what's a local module.
2024-08-06 20:38:42 +00:00
overlookmotel
654a6e67fa refactor(ast_codegen): list input files explicitly (#4708)
List inputs to the codegen explicitly. This is less DRY, but I think it has the advantage of being more obvious - for #4704.
2024-08-06 19:14:05 +00:00
overlookmotel
07607d3e94 feat(ast_codegen, span): process Span through ast_codegen (#4703)
Add `#[ast]` attr to `Span`.

Due to how AST codegen works, this necessitates putting the type def in a separate file. https://github.com/oxc-project/oxc/pull/4696#issuecomment-2271781995
2024-08-06 18:22:22 +00:00
rzvxa
125c5fd8ed feat(ast_codegen, span): process SourceType through ast_codegen. (#4696) 2024-08-06 17:42:12 +00:00
rzvxa
82e2f6b924 feat(ast_codegen): process AST-related syntax types. (#4694) 2024-08-06 17:14:35 +00:00
rzvxa
b04dc3d026 refactor(ast_codegen): disallow implicit enum discriminants on #[ast] types. (#4690) 2024-08-06 17:14:33 +00:00
rzvxa
1690a57ed3 refactor(ast_codegen): move away from RType in generators. (#4682)
This PR introduces `EarlyCtx` and `LateCtx` in place of the old `CodegenCtx`, Early passes operate at the AST level while generators and other late passes operate on the schema.

It will also replace the confusing `RType` name with something more idiomatic ~~(open for suggestions, I haven't found a good name yet)~~ I've named it `AstType` and dropped the `R` prefix for `REnum` and `RStruct`.

There are some qualities of life improvements too, Things like `to_type_elide` can be used to simplify the code.

Related to #4442 (and can potentially mark it "close as fixed").
2024-08-06 17:14:31 +00:00
rzvxa
49d5196e57 test(ast): fix assert_layouts.rs offset tests on 32bit platforms. (#4620) 2024-08-03 14:37:30 +00:00
rzvxa
0c52c0db02 feat(ast_codegen): add alignment and size data to the schema. (#4615)
This PR generates the layouts in the schema but doesn't use it to reorder.
2024-08-03 12:43:10 +00:00
rzvxa
bcfa2978e7 fix(ast_codegen): detect "complex" type wrappers (#4617)
Detect types such as `Cell<Option<ScopeId>>` and mark them as such! We didn't used to use this method for these options but now we have to check all types to calculate their layouts which means we need to process them correctly(instead of falling to their inner value).
2024-08-03 12:11:34 +00:00
overlookmotel
54047e021c feat(ast): GetSpanMut trait (#4609)
Closes #4606.

Introduce `GetSpanMut` trait and implement it on all AST node types.

This has to be a separate trait, rather than adding `span_mut` method to `GetSpan` because `AstKind` implements `GetSpan`, and it only has an immutable `&` ref to AST node it contains.
2024-08-02 11:50:24 +00:00
rzvxa
f39e759a53 refactor(ast_codegen): abstract passes and generators behind Runner trait. (#4556) 2024-08-02 00:08:05 +00:00
rzvxa
abc88363d7 fix(ast_codegen): create output path if doesn't exist. (#4555) 2024-08-02 00:08:02 +00:00
rzvxa
65c411eea1 feat(ast_codegen): add normalize_with to create errors from options. (#4554) 2024-08-02 00:07:59 +00:00
rzvxa
e736a5478c refactor(ast_codegen): cleanup schema generated by ast_codegen. (#4403) 2024-08-02 00:07:56 +00:00
rzvxa
26c6e80354 refactor(ast_codegen): cleanup ast_codegen. (#4392) 2024-08-02 00:07:53 +00:00
rzvxa
8685932c0b refactor(ast_codegen): use stringify for generators names. (#4388)
The generator name is always the same as its identifier so this PR changes all `"<generator_ident>"` to `stringify!(<generator_ident>)`
2024-08-02 00:07:50 +00:00
DonIsaac
c6a11bed1d docs(ast): auto-generate doc comments for AstBuilder methods (#4471)
# What This PR Does

Modifies `ast_codegen` to auto-generate rustdoc comments for generated `AstBuilder` methods. As we add more doc comments to AST node fields, the generated documentation will get better.

![image](https://github.com/user-attachments/assets/d27f0d53-38dd-4ba8-93e0-ffaf5c8e6809)
2024-07-29 15:50:28 +00:00
Dunqing
2477330440 feat(ast): add AstKind::TSExportAssignment (#4501)
part of #4488
2024-07-27 04:55:02 +00:00
Dunqing
aaee07e170 feat(ast): add AstKind::AssignmentTargetPattern, AstKind::ArrayAssignmentTarget and AstKind::ObjectAssignmentTarget (#4456)
close: #4435
2024-07-25 09:32:33 +00:00
overlookmotel
9c5d2f9d6a refactor(ast/builder): use Box::new_in over .into_in (#4428)
In `AstBuilder`'s `alloc_*` methods, use `Box::new_in` instead of `.into_in`. This is more explicit, so I feel easier to understand. It may also make life easier for compiler by not requiring it to perform type coercion.
2024-07-24 16:34:32 +00:00
rzvxa
7a3e92591f refactor(ast_codegen): better visit marker parsing. (#4371)
closes #4281
2024-07-20 17:07:24 +00:00
rzvxa
d345b84a72 feat(ast): add #[ast] attribute to non-visited AST types. (#4309)
Mark everything mentioned in https://github.com/oxc-project/oxc/pull/3815#issuecomment-2186736258 as AST.

We now error on the occurrence of non-ast items in the source of truth. It doesn't make sure that all fields and variants are `#[ast]` and therefore `repr_stable` but there are only a handful of non-AST types used here(mainly Atom and Span). Since we don't have access to the external types we can't make sure of it unless we find a way to const assert it.

The best we can do until then is to check all field/variant types to be either `#[ast]` or in a white list. I can add this check to the codegen in an upcoming PR.
2024-07-20 12:22:26 +00:00
rzvxa
5f1c7ecad7 refactor(ast): rename the visited_node marker to ast. (#4289)
closes #4282
I went with `#[ast(visit)]` but we can change it to 2 separate markers as suggested by @overlookmotel in the issue.
2024-07-20 12:02:25 +00:00
overlookmotel
1458d81268 refactor(visit): add #[inline] to empty functions (#4330)
Add `#[inline]` to empty default implementations of `enter_node` etc. Hopefully compiler will inline them automatically within Oxc even cross-crate because we compile with LTO, but maybe not for external consumers who don't use LTO.
2024-07-17 17:10:36 +00:00
Dunqing
1108f2a700 fix(semantic): resolve references to the incorrect symbol (#4280)
close: #3799
related: #3863
2024-07-17 02:50:48 +00:00
Dunqing
af4dc0112e feat(ast): align ts ast scope with typescript (#4253)
close: #3969
close: #2023

We need to add scope according to [this](d8086f14b6/src/compiler/binder.ts (L3883-L3962)). There are still some ASTs that need to be added to the scope.

---

Context from @Boshen:

Before this whole journey of fixing symbols and scopes I asked @Dunqing to debug through binder.ts via a debugger to fully understand how it does resolution.

We then agreed to align the implementation so that when a problem occurs, we can debug through both implementations and find where our problem is.

tsc doesn't have a specification, so we need to align with the reference implementation instead.
2024-07-17 02:50:47 +00:00
overlookmotel
2c7bb9f6c8 refactor(ast): pass final ScopeFlags into visit_function (#4283)
We have a strange workaround for `visit_function` where we pass in `ScopeFlags`, to support creating the scope inside `Function`, but setting different flags for `MethodDefinition`s.

Previously `visit_function` took `Option<ScopeFlags>` and then did `flags.unwrap_or(ScopeFlags::empty()) | ScopeFlags::Function` to it. Personally, I found this confusing. When I was looking at `MethodDefinition`, I was wondering "It's a function, why doesn't it set Function flag too?"

This changes makes it more explicit and clear what `ScopeFlags` everything has.
2024-07-16 07:22:07 +00:00
Boshen
a71787572e
chore: remove unsafe_code = "warn" rust lint
Feels too verbose as we already have unsafe comment turned on
2024-07-15 10:39:08 +08:00
rzvxa
aab7aaaa06 refactor(ast/visit): fire node events as the outermost one. (#4203)
I'm going to be AFK today(till about 9 PM UTC). Meanwhile, I Didn't want to be a blocker so here we go.
It would fix the #4200 merge if you guys find it in the correct order otherwise feel free to close it.
2024-07-12 03:27:59 +00:00
Boshen
8c54a2f1ed fix(tasks/ast_codegen): run cargo fmt synchronously (#4181)
relates #4152

This is my wild guess, because it works in my other script 143685deb1/xtask/src/main.rs (L21)
2024-07-11 02:59:30 +00:00
rzvxa
67fe75ec6c feat(ast, ast_codegen): pass the scope_id to the enter_scope event. (#4168) 2024-07-10 15:19:23 +00:00
rzvxa
3ba7cfed1f feat(ast_codegen): add #[visit(enter_before)] hint. (#4147)
Closes #4142

I can split it into 2 PRs but it seems pointless. Let me know if you guys disagree with me.
2024-07-10 14:02:29 +00:00
rzvxa
0b433108be feat(ast_codegen): add cli arguments to use with oxc_ast_codegen executable. (#4117)
```
Usage: oxc_ast_codegen [--dry-run] [--no-fmt] [--schema=ARG]

Available options:
        --dry-run     Runs all generators but won't write anything down.
        --no-fmt      Don't run cargo fmt at the end
        --schema=ARG  Path of output `schema.json`.
    -h, --help        Prints help information
```
2024-07-09 03:42:11 +00:00
rzvxa
6db630fab3 refactor(ast_codegen): cleanup usages of the generated outputs. (#4116) 2024-07-09 03:42:05 +00:00
rzvxa
91c792a2ce feat(ast_codegen): add ast builder generator. (#4098) 2024-07-09 00:47:23 +00:00
rzvxa
aa585d31e1
fix(ast_codegen, ast): visit ExpressionArrayElement as Expression. (#4061)
hotfix for #4060

I just added an edge case, We can come back to it later on and make it a
standard in our codegen.

The diff is big because it causes the code to reorder, The edge case
generated code doesn't follow the order in which they are defined in the
source of truth(eg `js.rs`)
2024-07-06 00:29:36 +08:00