Commit 6d0ffcc7 authored by Niklas Mischkulnig's avatar Niklas Mischkulnig Committed by Luke Sandberg

Upgrade to swc v33 (#81750)

So what do we need to do about https://github.com/swc-project/swc/pull/10813?

Not sure when we'd call `global_atom_store_gc()`

https://vercel.slack.com/archives/C03EWR7LGEN/p1752228740427529

The 2s-debounced gc calls didn't have a measurable effect on `next build --turbo`:
```
with gc:
  360.90s user 80.74s system 688% cpu 1:04.15 total
  357.24s user 82.61s system 664% cpu 1:06.23 total
without gc:
  360.51s user 80.48s system 698% cpu 1:03.16 total
  355.21s user 79.99s system 667% cpu 1:05.18 total
```

- [x] ~~Blocked on https://github.com/swc-project/swc/pull/10878~~
- [ ] https://github.com/swc-project/swc/issues/10930

Closes https://github.com/vercel/next.js/issues/81898
parent e5454172
This diff is collapsed.
...@@ -298,21 +298,25 @@ turbopack-trace-utils = { path = "turbopack/crates/turbopack-trace-utils" } ...@@ -298,21 +298,25 @@ turbopack-trace-utils = { path = "turbopack/crates/turbopack-trace-utils" }
turbopack-wasm = { path = "turbopack/crates/turbopack-wasm" } turbopack-wasm = { path = "turbopack/crates/turbopack-wasm" }
# SWC crates # SWC crates
swc_core = { version = "30.1.1", features = [ swc_core = { version = "34", features = [
"ecma_loader_lru", "ecma_loader_lru",
"ecma_loader_parking_lot", "ecma_loader_parking_lot",
"parallel_rayon", "parallel_rayon",
] } ] }
testing = { version = "14.0.0" } testing = "15.0.0"
# Keep consistent with preset_env_base through swc_core # Keep consistent with preset_env_base through swc_core
browserslist-rs = { version = "0.19.0" } browserslist-rs = "0.19.0"
mdxjs = "1.0.3" mdxjs = "1.0.3"
modularize_imports = { version = "0.90.0" } modularize_imports = "0.93.0"
styled_components = { version = "0.118.0" } styled_components = "0.121.0"
styled_jsx = { version = "0.94.0" } styled_jsx = "0.97.0"
swc_emotion = { version = "0.94.0" } swc_emotion = "0.97.0"
swc_relay = { version = "0.64.0" } swc_relay = "0.67.0"
react_remove_properties = "0.47.0"
remove_console = "0.48.0"
preset_env_base = "5.0.0"
# General Deps # General Deps
chromiumoxide = { version = "0.5.4", features = [ chromiumoxide = { version = "0.5.4", features = [
...@@ -435,6 +439,6 @@ webbrowser = "0.8.7" ...@@ -435,6 +439,6 @@ webbrowser = "0.8.7"
[patch.crates-io] [patch.crates-io]
hyper = { git = "https://github.com/bgw/hyper-rs.git", branch = "v1.6.0-with-macos-intel-miscompilation-workaround" } hyper = { git = "https://github.com/bgw/hyper-rs.git", branch = "v1.6.0-with-macos-intel-miscompilation-workaround" }
mdxjs = { git = "https://github.com/mischnic/mdxjs-rs.git", branch = "swc-core-32" }
lightningcss = { git = "https://github.com/parcel-bundler/lightningcss.git", branch = "mischnic/bump-browserslist" } lightningcss = { git = "https://github.com/parcel-bundler/lightningcss.git", branch = "mischnic/bump-browserslist" }
mdxjs = { git = "https://github.com/kdy1/mdxjs-rs.git", branch = "swc-core-30" }
parcel_selectors = { git = "https://github.com/parcel-bundler/lightningcss.git", branch = "mischnic/bump-browserslist" } parcel_selectors = { git = "https://github.com/parcel-bundler/lightningcss.git", branch = "mischnic/bump-browserslist" }
...@@ -81,6 +81,7 @@ swc_core = { workspace = true, features = [ ...@@ -81,6 +81,7 @@ swc_core = { workspace = true, features = [
"ecma_ast", "ecma_ast",
"ecma_ast_serde", "ecma_ast_serde",
"ecma_codegen", "ecma_codegen",
"ecma_helpers_inline",
"ecma_loader_lru", "ecma_loader_lru",
"ecma_loader_node", "ecma_loader_node",
"ecma_minifier", "ecma_minifier",
......
...@@ -70,7 +70,15 @@ static ALLOC: dhat::Alloc = dhat::Alloc; ...@@ -70,7 +70,15 @@ static ALLOC: dhat::Alloc = dhat::Alloc;
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
#[napi::module_init] #[napi::module_init]
fn init() { fn init() {
use std::panic::{set_hook, take_hook}; use std::{
cell::RefCell,
panic::{set_hook, take_hook},
time::{Duration, Instant},
};
thread_local! {
static LAST_SWC_ATOM_GC_TIME: RefCell<Option<Instant>> = const { RefCell::new(None) };
}
use tokio::runtime::Builder; use tokio::runtime::Builder;
use turbo_tasks::panic_hooks::handle_panic; use turbo_tasks::panic_hooks::handle_panic;
...@@ -87,6 +95,14 @@ fn init() { ...@@ -87,6 +95,14 @@ fn init() {
.on_thread_stop(|| { .on_thread_stop(|| {
TurboMalloc::thread_stop(); TurboMalloc::thread_stop();
}) })
.on_thread_park(|| {
LAST_SWC_ATOM_GC_TIME.with_borrow_mut(|cell| {
if cell.is_none_or(|t| t.elapsed() > Duration::from_secs(2)) {
swc_core::ecma::atoms::hstr::global_atom_store_gc();
*cell = Some(Instant::now());
}
});
})
.disable_lifo_slot() .disable_lifo_slot()
.build() .build()
.unwrap(); .unwrap();
......
use std::{ use std::{
cell::RefCell,
fs::{create_dir_all, write}, fs::{create_dir_all, write},
mem::forget, mem::forget,
path::{Path, PathBuf}, path::{Path, PathBuf},
...@@ -154,11 +155,23 @@ fn load_next_config() -> RcStr { ...@@ -154,11 +155,23 @@ fn load_next_config() -> RcStr {
} }
fn runtime() -> Runtime { fn runtime() -> Runtime {
thread_local! {
static LAST_SWC_ATOM_GC_TIME: RefCell<Option<Instant>> = const { RefCell::new(None) };
}
tokio::runtime::Builder::new_multi_thread() tokio::runtime::Builder::new_multi_thread()
.enable_all() .enable_all()
.on_thread_stop(|| { .on_thread_stop(|| {
turbo_tasks_malloc::TurboMalloc::thread_stop(); turbo_tasks_malloc::TurboMalloc::thread_stop();
}) })
.on_thread_park(|| {
LAST_SWC_ATOM_GC_TIME.with_borrow_mut(|cell| {
if cell.is_none_or(|t| t.elapsed() > Duration::from_secs(2)) {
swc_core::ecma::atoms::hstr::global_atom_store_gc();
*cell = Some(Instant::now());
}
});
})
.build() .build()
.context("Failed to build tokio runtime") .context("Failed to build tokio runtime")
.unwrap() .unwrap()
......
...@@ -16,6 +16,7 @@ next-api = { workspace = true } ...@@ -16,6 +16,7 @@ next-api = { workspace = true }
next-core = { workspace = true } next-core = { workspace = true }
num_cpus = "1.16.0" num_cpus = "1.16.0"
rand = { workspace = true, features = ["small_rng"] } rand = { workspace = true, features = ["small_rng"] }
swc_core = { workspace = true }
serde_json = { workspace = true } serde_json = { workspace = true }
tokio = { workspace = true, features = ["full"] } tokio = { workspace = true, features = ["full"] }
tokio-stream = "0.1.15" tokio-stream = "0.1.15"
......
use std::{convert::Infallible, str::FromStr, time::Instant}; use std::{
cell::RefCell,
convert::Infallible,
str::FromStr,
time::{Duration, Instant},
};
use next_api::project::{DefineEnv, ProjectOptions}; use next_api::project::{DefineEnv, ProjectOptions};
use next_build_test::{Strategy, main_inner}; use next_build_test::{Strategy, main_inner};
...@@ -70,12 +75,23 @@ fn main() { ...@@ -70,12 +75,23 @@ fn main() {
factor = 1; factor = 1;
} }
thread_local! {
static LAST_SWC_ATOM_GC_TIME: RefCell<Option<Instant>> = const { RefCell::new(None) };
}
tokio::runtime::Builder::new_multi_thread() tokio::runtime::Builder::new_multi_thread()
.enable_all() .enable_all()
.on_thread_stop(|| { .on_thread_stop(|| {
TurboMalloc::thread_stop(); TurboMalloc::thread_stop();
tracing::debug!("threads stopped"); tracing::debug!("threads stopped");
}) })
.on_thread_park(|| {
LAST_SWC_ATOM_GC_TIME.with_borrow_mut(|cell| {
if cell.is_none_or(|t| t.elapsed() > Duration::from_secs(2)) {
swc_core::ecma::atoms::hstr::global_atom_store_gc();
*cell = Some(Instant::now());
}
});
})
.build() .build()
.unwrap() .unwrap()
.block_on(async { .block_on(async {
......
...@@ -31,8 +31,8 @@ futures = { workspace = true } ...@@ -31,8 +31,8 @@ futures = { workspace = true }
thiserror = { workspace = true } thiserror = { workspace = true }
tracing = { workspace = true } tracing = { workspace = true }
rustc-hash = { workspace = true } rustc-hash = { workspace = true }
react_remove_properties = "0.44.0" react_remove_properties = { workspace = true }
remove_console = "0.45.0" remove_console = { workspace = true }
itertools = { workspace = true } itertools = { workspace = true }
percent-encoding = "2.3.1" percent-encoding = "2.3.1"
serde_path_to_error = { workspace = true } serde_path_to_error = { workspace = true }
......
...@@ -67,9 +67,9 @@ turbopack-ecmascript-plugins = { workspace = true, optional = true } ...@@ -67,9 +67,9 @@ turbopack-ecmascript-plugins = { workspace = true, optional = true }
turbo-rcstr = { workspace = true } turbo-rcstr = { workspace = true }
urlencoding = { workspace = true } urlencoding = { workspace = true }
react_remove_properties = "0.44.0" react_remove_properties = { workspace = true }
remove_console = "0.45.0" remove_console = { workspace = true }
preset_env_base = "4.0.0" preset_env_base = { workspace = true }
[dev-dependencies] [dev-dependencies]
swc_core = { workspace = true, features = ["testing_transform"] } swc_core = { workspace = true, features = ["testing_transform"] }
......
...@@ -142,10 +142,10 @@ describe('Error recovery app', () => { ...@@ -142,10 +142,10 @@ describe('Error recovery app', () => {
"description": "Parsing ecmascript source code failed", "description": "Parsing ecmascript source code failed",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/server/page.js (2:27) "source": "./app/server/page.js (2:26)
Parsing ecmascript source code failed Parsing ecmascript source code failed
> 2 | return <p>Hello world</p> > 2 | return <p>Hello world</p>
| ^", | ^",
"stack": [], "stack": [],
} }
`) `)
...@@ -160,7 +160,7 @@ describe('Error recovery app', () => { ...@@ -160,7 +160,7 @@ describe('Error recovery app', () => {
,-[2:1] ,-[2:1]
1 | export default function Page() { 1 | export default function Page() {
2 | return <p>Hello world</p> 2 | return <p>Hello world</p>
: ^ : ^
\`---- \`----
Caused by: Caused by:
Syntax Error Syntax Error
...@@ -206,10 +206,10 @@ describe('Error recovery app', () => { ...@@ -206,10 +206,10 @@ describe('Error recovery app', () => {
"description": "Parsing ecmascript source code failed", "description": "Parsing ecmascript source code failed",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/client/page.js (2:27) "source": "./app/client/page.js (2:26)
Parsing ecmascript source code failed Parsing ecmascript source code failed
> 2 | return <p>Hello world</p> > 2 | return <p>Hello world</p>
| ^", | ^",
"stack": [], "stack": [],
} }
`) `)
...@@ -224,7 +224,7 @@ describe('Error recovery app', () => { ...@@ -224,7 +224,7 @@ describe('Error recovery app', () => {
,-[2:1] ,-[2:1]
1 | export default function Page() { 1 | export default function Page() {
2 | return <p>Hello world</p> 2 | return <p>Hello world</p>
: ^ : ^
\`---- \`----
Caused by: Caused by:
Syntax Error Syntax Error
...@@ -619,10 +619,10 @@ describe('Error recovery app', () => { ...@@ -619,10 +619,10 @@ describe('Error recovery app', () => {
"description": "Parsing ecmascript source code failed", "description": "Parsing ecmascript source code failed",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (10:41) "source": "./index.js (10:39)
Parsing ecmascript source code failed Parsing ecmascript source code failed
> 10 | export default function FunctionNamed() { > 10 | export default function FunctionNamed() {
| ^", | ^",
"stack": [], "stack": [],
} }
`) `)
...@@ -636,7 +636,7 @@ describe('Error recovery app', () => { ...@@ -636,7 +636,7 @@ describe('Error recovery app', () => {
Error: x Expected '}', got '<eof>' Error: x Expected '}', got '<eof>'
,-[10:1] ,-[10:1]
10 | export default function FunctionNamed() { 10 | export default function FunctionNamed() {
: ^ : ^
\`---- \`----
Caused by: Caused by:
Syntax Error Syntax Error
...@@ -656,10 +656,10 @@ describe('Error recovery app', () => { ...@@ -656,10 +656,10 @@ describe('Error recovery app', () => {
"description": "Parsing ecmascript source code failed", "description": "Parsing ecmascript source code failed",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (10:41) "source": "./index.js (10:39)
Parsing ecmascript source code failed Parsing ecmascript source code failed
> 10 | export default function FunctionNamed() { > 10 | export default function FunctionNamed() {
| ^", | ^",
"stack": [], "stack": [],
} }
`) `)
...@@ -673,7 +673,7 @@ describe('Error recovery app', () => { ...@@ -673,7 +673,7 @@ describe('Error recovery app', () => {
Error: x Expected '}', got '<eof>' Error: x Expected '}', got '<eof>'
,-[10:1] ,-[10:1]
10 | export default function FunctionNamed() { 10 | export default function FunctionNamed() {
: ^ : ^
\`---- \`----
Caused by: Caused by:
Syntax Error Syntax Error
...@@ -1012,10 +1012,10 @@ describe('Error recovery app', () => { ...@@ -1012,10 +1012,10 @@ describe('Error recovery app', () => {
"description": "Parsing ecmascript source code failed", "description": "Parsing ecmascript source code failed",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./app/page.js (1:3) "source": "./app/page.js (1:2)
Parsing ecmascript source code failed Parsing ecmascript source code failed
> 1 | {{{ > 1 | {{{
| ^", | ^",
"stack": [], "stack": [],
} }
`) `)
...@@ -1029,7 +1029,7 @@ describe('Error recovery app', () => { ...@@ -1029,7 +1029,7 @@ describe('Error recovery app', () => {
Error: x Expected '}', got '<eof>' Error: x Expected '}', got '<eof>'
,---- ,----
1 | {{{ 1 | {{{
: ^ : ^
\`---- \`----
Caused by: Caused by:
Syntax Error", Syntax Error",
......
...@@ -840,10 +840,10 @@ describe('pages/ error recovery', () => { ...@@ -840,10 +840,10 @@ describe('pages/ error recovery', () => {
"description": "Parsing ecmascript source code failed", "description": "Parsing ecmascript source code failed",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (7:41) "source": "./index.js (7:39)
Parsing ecmascript source code failed Parsing ecmascript source code failed
> 7 | export default function FunctionNamed() { > 7 | export default function FunctionNamed() {
| ^", | ^",
"stack": [], "stack": [],
} }
`) `)
...@@ -886,7 +886,7 @@ describe('pages/ error recovery', () => { ...@@ -886,7 +886,7 @@ describe('pages/ error recovery', () => {
5 | throw Error('no ' + i) 5 | throw Error('no ' + i)
6 | }, 1000) 6 | }, 1000)
7 | export default function FunctionNamed() { 7 | export default function FunctionNamed() {
: ^ : ^
\`---- \`----
Caused by: Caused by:
Syntax Error Syntax Error
...@@ -908,10 +908,10 @@ describe('pages/ error recovery', () => { ...@@ -908,10 +908,10 @@ describe('pages/ error recovery', () => {
"description": "Parsing ecmascript source code failed", "description": "Parsing ecmascript source code failed",
"environmentLabel": null, "environmentLabel": null,
"label": "Build Error", "label": "Build Error",
"source": "./index.js (7:41) "source": "./index.js (7:39)
Parsing ecmascript source code failed Parsing ecmascript source code failed
> 7 | export default function FunctionNamed() { > 7 | export default function FunctionNamed() {
| ^", | ^",
"stack": [], "stack": [],
} }
`) `)
...@@ -954,7 +954,7 @@ describe('pages/ error recovery', () => { ...@@ -954,7 +954,7 @@ describe('pages/ error recovery', () => {
5 | throw Error('no ' + i) 5 | throw Error('no ' + i)
6 | }, 1000) 6 | }, 1000)
7 | export default function FunctionNamed() { 7 | export default function FunctionNamed() {
: ^ : ^
\`---- \`----
Caused by: Caused by:
Syntax Error Syntax Error
......
...@@ -41,7 +41,7 @@ describe('Custom _error', () => { ...@@ -41,7 +41,7 @@ describe('Custom _error', () => {
await retry(async () => { await retry(async () => {
// retry because the page might not be built yet // retry because the page might not be built yet
const html = await renderViaHTTP(appPort, '/404') const html = await renderViaHTTP(appPort, '/404')
expect(html).toContain('Unexpected token') expect(html).toContain('Unexpected eof')
expect(stderr).not.toMatch(customErrNo404Match) expect(stderr).not.toMatch(customErrNo404Match)
}) })
} finally { } finally {
......
...@@ -45,6 +45,7 @@ futures = { workspace = true } ...@@ -45,6 +45,7 @@ futures = { workspace = true }
owo-colors = { workspace = true } owo-colors = { workspace = true }
rustc-hash = { workspace = true } rustc-hash = { workspace = true }
serde = { workspace = true } serde = { workspace = true }
swc_core = { workspace = true }
tokio = { workspace = true, features = ["full"] } tokio = { workspace = true, features = ["full"] }
tracing = { workspace = true } tracing = { workspace = true }
tracing-subscriber = { workspace = true, features = ["json"] } tracing-subscriber = { workspace = true, features = ["json"] }
......
#![feature(future_join)] #![feature(future_join)]
#![feature(min_specialization)] #![feature(min_specialization)]
use std::path::Path; use std::{cell::RefCell, path::Path, time::Instant};
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use clap::Parser; use clap::Parser;
...@@ -22,16 +22,30 @@ use turbopack_trace_utils::{ ...@@ -22,16 +22,30 @@ use turbopack_trace_utils::{
static ALLOC: TurboMalloc = TurboMalloc; static ALLOC: TurboMalloc = TurboMalloc;
fn main() { fn main() {
let args = Arguments::parse(); thread_local! {
static LAST_SWC_ATOM_GC_TIME: RefCell<Option<Instant>> = const { RefCell::new(None) };
}
let mut rt = tokio::runtime::Builder::new_multi_thread(); let mut rt = tokio::runtime::Builder::new_multi_thread();
rt.enable_all().on_thread_stop(|| { rt.enable_all()
TurboMalloc::thread_stop(); .on_thread_stop(|| {
}); TurboMalloc::thread_stop();
})
.on_thread_park(|| {
LAST_SWC_ATOM_GC_TIME.with_borrow_mut(|cell| {
use std::time::Duration;
if cell.is_none_or(|t| t.elapsed() > Duration::from_secs(2)) {
swc_core::ecma::atoms::hstr::global_atom_store_gc();
*cell = Some(Instant::now());
}
});
});
#[cfg(not(codspeed))] #[cfg(not(codspeed))]
rt.disable_lifo_slot(); rt.disable_lifo_slot();
let args = Arguments::parse();
rt.build().unwrap().block_on(main_inner(args)).unwrap(); rt.build().unwrap().block_on(main_inner(args)).unwrap();
} }
......
...@@ -2062,6 +2062,8 @@ fn hygiene_rename_only( ...@@ -2062,6 +2062,8 @@ fn hygiene_rename_only(
} }
// Copied from `hygiene_with_config`'s HygieneRenamer, but added an `preserved_exports` // Copied from `hygiene_with_config`'s HygieneRenamer, but added an `preserved_exports`
impl swc_core::ecma::transforms::base::rename::Renamer for HygieneRenamer<'_> { impl swc_core::ecma::transforms::base::rename::Renamer for HygieneRenamer<'_> {
type Target = Atom;
const MANGLE: bool = false; const MANGLE: bool = false;
const RESET_N: bool = true; const RESET_N: bool = true;
......
...@@ -11,7 +11,7 @@ var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbo ...@@ -11,7 +11,7 @@ var __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbo
; ;
; ;
const StyledButton = /*#__PURE__*/ (0, __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$node_modules$2f40$emotion$2f$styled$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__["default"])("button", { const StyledButton = /*#__PURE__*/ (0, __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$node_modules$2f40$emotion$2f$styled$2f$index$2e$js__$5b$test$5d$__$28$ecmascript$29$__["default"])("button", {
target: "e14dbx1z0" target: "e6tdad40"
})("background:blue;"); })("background:blue;");
function ClassNameButton({ children }) { function ClassNameButton({ children }) {
return /*#__PURE__*/ (0, __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$node_modules$2f40$emotion$2f$react$2f$jsx$2d$dev$2d$runtime$2e$js__$5b$test$5d$__$28$ecmascript$29$__["jsxDEV"])("button", { return /*#__PURE__*/ (0, __TURBOPACK__imported__module__$5b$project$5d2f$turbopack$2f$crates$2f$turbopack$2d$tests$2f$tests$2f$snapshot$2f$node_modules$2f40$emotion$2f$react$2f$jsx$2d$dev$2d$runtime$2e$js__$5b$test$5d$__$28$ecmascript$29$__["jsxDEV"])("button", {
......
...@@ -22,7 +22,7 @@ turbo-tasks-fs = { workspace = true } ...@@ -22,7 +22,7 @@ turbo-tasks-fs = { workspace = true }
turbo-tasks-hash = { workspace = true } turbo-tasks-hash = { workspace = true }
turbopack-core = { workspace = true } turbopack-core = { workspace = true }
turbopack-ecmascript = { workspace = true } turbopack-ecmascript = { workspace = true }
wasmparser = "0.110.0" wasmparser = "0.235.0"
wat = "1.0.69" wat = "1.0.69"
[build-dependencies] [build-dependencies]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment