Skip to content
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

Using deno_ast in a project that contains swc_common -F concurrent breaks the build #219

Closed
alshdavid opened this issue Mar 9, 2024 · 3 comments · May be fixed by #250
Closed

Using deno_ast in a project that contains swc_common -F concurrent breaks the build #219

alshdavid opened this issue Mar 9, 2024 · 3 comments · May be fixed by #250

Comments

@alshdavid
Copy link

I am trying to use deno_ast in my project which also uses swc_common.

I am using it via swc_common = { version = "=0.33.18", features = ["concurrent"] }

With the concurrent feature enabled, the compiler throws:

error[E0277]: `Rc<RefCell<Vec<swc_common::errors::Diagnostic>>>` cannot be sent between threads safely
   --> /home/dalsh/.local/rust/cargo/registry/src/index.crates.io-6f17d22bba15001f/deno_ast-0.34.2/src/transpiling/mod.rs:280:46
    |
280 | impl crate::swc::common::errors::Emitter for DiagnosticCollector {
    |                                              ^^^^^^^^^^^^^^^^^^^ `Rc<RefCell<Vec<swc_common::errors::Diagnostic>>>` cannot be sent between threads safely
    |
    = help: within `DiagnosticCollector`, the trait `Send` is not implemented for `Rc<RefCell<Vec<swc_common::errors::Diagnostic>>>`
note: required because it appears within the type `DiagnosticCollector`
   --> /home/dalsh/.local/rust/cargo/registry/src/index.crates.io-6f17d22bba15001f/deno_ast-0.34.2/src/transpiling/mod.rs:266:8
    |
266 | struct DiagnosticCollector {
    |        ^^^^^^^^^^^^^^^^^^^
note: required by a bound in `swc_common::errors::Emitter`
   --> /home/dalsh/.local/rust/cargo/registry/src/index.crates.io-6f17d22bba15001f/swc_common-0.33.18/src/errors/emitter.rs:39:20
    |
39  | pub trait Emitter: crate::sync::Send {
    |                    ^^^^^^^^^^^^^^^^^ required by this bound in `Emitter` 

Is there any way around this?

@dsherret
Copy link
Member

Is there any way around this?

No, we don't support or want to carry that maintenance burden. Generally we prefer doing concurrent stuff at a higher level than within emit and it reduces the chance of running into an swc concurrency bug.

@alshdavid
Copy link
Author

I'm currently exploring the idea of compiling Deno (including deno_ast) to a dynamic library and consuming it within my main application using libloading.

That way the Deno dependencies can be compartmentalized within that dynamic library and the main project can remain unaffected. I haven't gotten around the issue of sharing types between the dynamic library and the main application

@dsherret
Copy link
Member

dsherret commented Apr 2, 2024

I'm not sure about a good solution there. I'd recommend disabling swc's concurrent option. That said, DiagnosticCollector seems simple enough, so a PR that adds a Sync implementation behind a compile flag seems like an ok thing to maintain if that's the only change required in deno_ast to enable this flag (basically, I'd rather not maintain concurrent, but if it's simple and something you'd like to maintain in deno_ast then feel free to submit a PR).

@dsherret dsherret closed this as not planned Won't fix, can't repro, duplicate, stale Apr 2, 2024
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 a pull request may close this issue.

2 participants