Skip to content

Commit

Permalink
feat(es/transforms): Allocate stacks dynamically (#8867)
Browse files Browse the repository at this point in the history
**Description:**

 - This PR introduces an in-tree testing system for Deno.
 - This PR adds `stacker` cargo-feature to `swc_ecma_utils`.

**Related issue:**

 - #1627
 - Closes #8840
  • Loading branch information
kdy1 committed Apr 16, 2024
1 parent 81a57fd commit a1c5415
Show file tree
Hide file tree
Showing 25 changed files with 5,569 additions and 104 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -683,10 +683,15 @@ jobs:
cargo test -p swc_ecma_minifier --features concurrent
- name: Run cargo test (all features)
if: matrix.settings.crate == 'swc_ecma_parser' || matrix.settings.crate == 'swc_ecma_loader' || matrix.settings.crate == 'swc_ecma_transforms'
if: matrix.settings.crate == 'swc_ecma_parser' || matrix.settings.crate == 'swc_ecma_loader'
run: |
cargo test -p ${{ matrix.settings.crate }} --all-features
- name: Run cargo test (transforms with stacker)
if: matrix.settings.crate == 'swc_ecma_transforms'
run: |
cargo test -p ${{ matrix.settings.crate }} --all-features --features swc_ecma_utils/stacker
- name: Run cargo test (concurrent)
if: runner.os == 'Linux' && matrix.settings.crate != 'swc_ecma_minifier'
shell: bash
Expand Down
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions crates/swc_core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ common_plugin_transform = [
css_plugin_transform = ["common_plugin_transform", "__css_plugin_transform"]
ecma_plugin_transform = ["common_plugin_transform", "__ecma_plugin_transform"]

# Use `stacker` to avoid stack overflow.
stacker = ["swc_ecma_parser/stacker", "swc_ecma_utils/stacker"]

# Host features to enable plugin `runner` runtime.
# native feature is for the host environment does not have, or cannot access
# to the wasm runtime (i.e cli, or @swc/core node bindings).
Expand Down
6 changes: 5 additions & 1 deletion crates/swc_ecma_minifier/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::time::Instant;
use rustc_hash::FxHashSet;
use swc_common::{util::take::Take, Mark, Span, Spanned, DUMMY_SP};
use swc_ecma_ast::*;
use swc_ecma_utils::{ModuleItemLike, StmtLike, Value};
use swc_ecma_utils::{stack_size::maybe_grow_default, ModuleItemLike, StmtLike, Value};
use swc_ecma_visit::{noop_visit_type, visit_obj_and_computed, Visit, VisitWith};

pub(crate) mod base54;
Expand Down Expand Up @@ -510,6 +510,10 @@ impl Visit for EvalFinder {

visit_obj_and_computed!();

fn visit_expr(&mut self, n: &Expr) {
maybe_grow_default(|| n.visit_children_with(self));
}

fn visit_ident(&mut self, i: &Ident) {
if i.sym == "eval" {
self.found = true;
Expand Down
55 changes: 55 additions & 0 deletions crates/swc_ecma_transforms/tests/deno.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#![cfg(all(
feature = "swc_ecma_transforms_proposal",
feature = "swc_ecma_transforms_typescript",
))]
use std::path::PathBuf;

use swc_common::{chain, Mark};
use swc_ecma_parser::Syntax;
use swc_ecma_transforms::{fixer, helpers::inject_helpers, hygiene, resolver};
use swc_ecma_transforms_proposal::{
decorator_2022_03::decorator_2022_03,
explicit_resource_management::explicit_resource_management,
};
use swc_ecma_transforms_testing::test_fixture;
use swc_ecma_transforms_typescript::typescript;

#[testing::fixture("tests/fixture/deno/**/input.ts")]
fn stack_overflow(input: PathBuf) {
run_test(input);
}

fn run_test(input: PathBuf) {
let output = input.with_file_name("output.js");

test_fixture(
Syntax::Typescript(Default::default()),
&|_tester| {
let unresolved_mark = Mark::new();
let top_level_mark = Mark::new();

chain!(
resolver(unresolved_mark, top_level_mark, true),
decorator_2022_03(),
explicit_resource_management(),
inject_helpers(top_level_mark),
typescript(
typescript::Config {
verbatim_module_syntax: false,
import_not_used_as_values: typescript::ImportsNotUsedAsValues::Remove,
no_empty_export: true,
import_export_assign_config:
typescript::TsImportExportAssignConfig::Preserve,
ts_enum_is_mutable: true,
},
top_level_mark
),
fixer(None),
hygiene(),
)
},
&input,
&output,
Default::default(),
)
}
Loading

0 comments on commit a1c5415

Please sign in to comment.