-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support concurrent swc_common
via feature
#250
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,35 @@ | ||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. | ||
|
||
use std::rc::Rc; | ||
|
||
use crate::swc::common::sync::Lrc; | ||
use crate::swc::common::SourceFile; | ||
|
||
use crate::ModuleSpecifier; | ||
|
||
#[derive(Clone, Default)] | ||
pub struct SourceMap { | ||
inner: Rc<crate::swc::common::SourceMap>, | ||
inner: Lrc<crate::swc::common::SourceMap>, | ||
} | ||
|
||
impl SourceMap { | ||
pub fn single(specifier: ModuleSpecifier, source: String) -> Self { | ||
let map = Self::default(); | ||
map | ||
.inner | ||
.new_source_file(Rc::new(swc_common::FileName::Url(specifier)), source); | ||
.new_source_file(Lrc::new(swc_common::FileName::Url(specifier)), source); | ||
map | ||
} | ||
|
||
pub fn inner(&self) -> &Rc<crate::swc::common::SourceMap> { | ||
pub fn inner(&self) -> &Lrc<crate::swc::common::SourceMap> { | ||
&self.inner | ||
} | ||
|
||
pub fn new_source_file( | ||
&self, | ||
specifier: ModuleSpecifier, | ||
source: String, | ||
) -> Rc<SourceFile> { | ||
) -> Lrc<SourceFile> { | ||
self | ||
.inner | ||
.new_source_file(Rc::new(swc_common::FileName::Url(specifier)), source) | ||
.new_source_file(Lrc::new(swc_common::FileName::Url(specifier)), source) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license. | ||
|
||
use std::borrow::Cow; | ||
use std::rc::Rc; | ||
use std::sync::Arc; | ||
|
||
use anyhow::Result; | ||
|
@@ -14,6 +13,7 @@ use crate::swc::ast::Program; | |
use crate::swc::common::chain; | ||
use crate::swc::common::comments::SingleThreadedComments; | ||
use crate::swc::common::errors::Diagnostic as SwcDiagnostic; | ||
use crate::swc::common::sync::{Lrc, Send, Sync}; | ||
use crate::swc::parser::error::SyntaxError; | ||
use crate::swc::transforms::fixer; | ||
use crate::swc::transforms::helpers; | ||
|
@@ -349,9 +349,12 @@ fn transpile( | |
|
||
#[derive(Default, Clone)] | ||
struct DiagnosticCollector { | ||
diagnostics_cell: Rc<RefCell<Vec<SwcDiagnostic>>>, | ||
diagnostics_cell: Lrc<RefCell<Vec<SwcDiagnostic>>>, | ||
} | ||
|
||
unsafe impl Send for DiagnosticCollector {} | ||
unsafe impl Sync for DiagnosticCollector {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can feature gate these, but without #[cfg(not(feature = "concurrent"))]
mod single {
pub use once_cell::unsync::{Lazy, OnceCell};
/// Dummy trait because swc_common is in single thread mode.
pub trait Send {}
/// Dummy trait because swc_common is in single thread mode.
pub trait Sync {}
impl<T> Send for T where T: ?Sized {}
impl<T> Sync for T where T: ?Sized {}
pub use std::{
cell::{
Ref as ReadGuard, RefMut as WriteGuard, RefMut as MappedWriteGuard,
RefMut as LockGuard, RefMut as MappedLockGuard,
},
rc::{Rc as Lrc, Weak},
};
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If someone is using |
||
|
||
impl DiagnosticCollector { | ||
pub fn into_handler(self) -> crate::swc::common::errors::Handler { | ||
crate::swc::common::errors::Handler::with_emitter( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As mentioned in #219 (comment) , I'm not sure this is a scenario we want to bother to support.
Do you really need this feature? How much faster have you found it? We've just started using separate threads per file. Maybe in bundling scenarios this is faster?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately, a number of swc libraries bake-in
swc_common
's concurrent feature and including any of them preventsdeno_ast
from compiling:swc_error_reporters
swc_bundler
swc_ecma_lints
swc_estree_compat
swc_node_bundler
swc_plugin_runner
i'm working from a fork of farm, which uses rayon for concurrent builds, and they benchmark against other bundlers using swc (e.g., rspack).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see. We can add a
concurrent
feature here, but no guarantee it's going to work in the future. It might be removed at any time due to the maintenance cost and you might have to contribute fixes to get it working again.