Skip to content

feat(transformer/react-jsx): throw the pragma and pragmaFrag cannot be set when runtime is automatic error#1196

Merged
Boshen merged 13 commits into
oxc-project:mainfrom
Dunqing:feat/transformer/react-jsx/throws-pragma-error
Nov 10, 2023
Merged

feat(transformer/react-jsx): throw the pragma and pragmaFrag cannot be set when runtime is automatic error#1196
Boshen merged 13 commits into
oxc-project:mainfrom
Dunqing:feat/transformer/react-jsx/throws-pragma-error

Conversation

@Dunqing

@Dunqing Dunqing commented Nov 8, 2023

Copy link
Copy Markdown
Member

close: #1194

Here's a rough implementation of my idea of throwing an error.

@Boshen

Boshen commented Nov 8, 2023

Copy link
Copy Markdown
Member

Oh nice to see you are already working on this!

Can you use the same technique as how I'm doing it in the parser or semantic builder?

https://github.com/web-infra-dev/oxc/blob/7d85492a03e34fec11e27eae42db28a7c3f12e16/crates/oxc_semantic/src/builder.rs#L57C1-L58

Add this to ctx and push errors into it.

We don't want to change the visitor functions.

I think we don't need to abort early, just let it run and then abort the whole compilation pipeline when there is an error at the end, you can do this check inside the build function, and then make the build function return a Result.

@Dunqing

Dunqing commented Nov 8, 2023

Copy link
Copy Markdown
Member Author

Oh nice to see you are already working on this!

Can you use the same technique as how I'm doing it in the parser or semantic builder?

https://github.com/web-infra-dev/oxc/blob/7d85492a03e34fec11e27eae42db28a7c3f12e16/crates/oxc_semantic/src/builder.rs#L57C1-L58

Add this to ctx and push errors into it.

We don't want to change the visitor functions.

I think we don't need to abort early, just let it run and then abort the whole compilation pipeline when there is a error at then end, you can do this check inside the build function, and then make the build function return a Result.

OK, I will try soon

@github-actions github-actions Bot removed the A-ast Area - AST label Nov 8, 2023
@codspeed-hq

codspeed-hq Bot commented Nov 9, 2023

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #1196 will not alter performance

Comparing Dunqing:feat/transformer/react-jsx/throws-pragma-error (76f6ab3) with main (b65094b)

Summary

✅ 22 untouched benchmarks

@Dunqing Dunqing marked this pull request as ready for review November 9, 2023 14:35
Comment thread crates/oxc_transformer/src/lib.rs Outdated
@Boshen Boshen merged commit 8c624ab into oxc-project:main Nov 10, 2023
graphite-app Bot pushed a commit that referenced this pull request Jun 25, 2026
This avoids calling `Expression::span()` when wrapping an expression-bodied arrow function in a synthetic `ExpressionStatement`.

The parser already knows the expression body starts at the current token before parsing and ends at `prev_token_end` afterwards, so this can use `start_span()` / `end_span()` directly. That keeps the returned `Expression` in registers instead of materializing it on the stack just to call the generated `GetSpan` impl.

Before, the optimized parser assembly spilled the returned expression and called `Expression::span()`:

```asm
bl      parse_assignment_expression_or_higher_impl
mov     x20, x0
mov     x22, x1
strh    w21, [x19, #1196]
strb    w0, [sp, #16]
str     x1, [sp, #24]
add     x0, sp, #16
bl      GetSpan_for_Expression_span
...
str     x0, [x21]       ; ExpressionStatement span
strb    w20, [x21, #16] ; Expression tag
str     x22, [x21, #24] ; Expression payload
```

After, the span is built from parser token state and the expression result is written directly into the arena allocation:

```asm
ldr     x20, [x0, #816]  ; current token span before parse
...
bl      parse_assignment_expression_or_higher_impl
strh    w21, [x19, #1196]
ldr     w8, [x19, #1192] ; previous token end after parse
bfi     x20, x8, #32, #32
...
str     x20, [x21]      ; ExpressionStatement span
strb    w0, [x21, #16]  ; Expression tag
str     x1, [x21, #24]  ; Expression payload
```

This also reduced the first monomorphized parse_arrow_function_expression_body stack frame from 432 bytes to 416 bytes in my local release assembly.
camc314 added a commit that referenced this pull request Jul 3, 2026
This avoids calling `Expression::span()` when wrapping an expression-bodied arrow function in a synthetic `ExpressionStatement`.

The parser already knows the expression body starts at the current token before parsing and ends at `prev_token_end` afterwards, so this can use `start_span()` / `end_span()` directly. That keeps the returned `Expression` in registers instead of materializing it on the stack just to call the generated `GetSpan` impl.

Before, the optimized parser assembly spilled the returned expression and called `Expression::span()`:

```asm
bl      parse_assignment_expression_or_higher_impl
mov     x20, x0
mov     x22, x1
strh    w21, [x19, #1196]
strb    w0, [sp, #16]
str     x1, [sp, #24]
add     x0, sp, #16
bl      GetSpan_for_Expression_span
...
str     x0, [x21]       ; ExpressionStatement span
strb    w20, [x21, #16] ; Expression tag
str     x22, [x21, #24] ; Expression payload
```

After, the span is built from parser token state and the expression result is written directly into the arena allocation:

```asm
ldr     x20, [x0, #816]  ; current token span before parse
...
bl      parse_assignment_expression_or_higher_impl
strh    w21, [x19, #1196]
ldr     w8, [x19, #1192] ; previous token end after parse
bfi     x20, x8, #32, #32
...
str     x20, [x21]      ; ExpressionStatement span
strb    w0, [x21, #16]  ; Expression tag
str     x1, [x21, #24]  ; Expression payload
```

This also reduced the first monomorphized parse_arrow_function_expression_body stack frame from 432 bytes to 416 bytes in my local release assembly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(transformer): support throwing errors

2 participants