Skip to content

Commit 65a6e62

Browse files
committed
Revert "update native error reporter to use RefCells instead of Arc Mutex"
This reverts commit 406ee85.
1 parent 406ee85 commit 65a6e62

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

rust/cubetranspilers/src/error_reporter.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
use std::cell::RefCell;
1+
use std::sync::{Arc, Mutex};
22

33
use swc_core::common::errors::{DiagnosticBuilder, Emitter};
44

55
pub struct ErrorReporter {
6-
pub errors: RefCell<Vec<String>>,
7-
pub warnings: RefCell<Vec<String>>,
6+
pub errors: Arc<Mutex<Vec<String>>>,
7+
pub warnings: Arc<Mutex<Vec<String>>>,
88
}
99

1010
impl ErrorReporter {
11-
pub fn new(errors: RefCell<Vec<String>>, warnings: RefCell<Vec<String>>) -> Self {
11+
pub fn new(errors: Arc<Mutex<Vec<String>>>, warnings: Arc<Mutex<Vec<String>>>) -> Self {
1212
ErrorReporter { errors, warnings }
1313
}
1414
}
1515

1616
impl Default for ErrorReporter {
1717
fn default() -> Self {
1818
ErrorReporter {
19-
errors: RefCell::new(Vec::new()),
20-
warnings: RefCell::new(Vec::new()),
19+
errors: Arc::new(Mutex::new(Vec::new())),
20+
warnings: Arc::new(Mutex::new(Vec::new())),
2121
}
2222
}
2323
}
@@ -29,14 +29,16 @@ impl Emitter for ErrorReporter {
2929
| swc_core::common::errors::Level::Fatal
3030
| swc_core::common::errors::Level::PhaseFatal
3131
| swc_core::common::errors::Level::Error => {
32-
self.errors.borrow_mut().push(diagnostic.message());
32+
let mut errors = self.errors.lock().unwrap();
33+
errors.push(diagnostic.message());
3334
}
3435
swc_core::common::errors::Level::Warning
3536
| swc_core::common::errors::Level::Note
3637
| swc_core::common::errors::Level::Help
3738
| swc_core::common::errors::Level::Cancelled
3839
| swc_core::common::errors::Level::FailureNote => {
39-
self.warnings.borrow_mut().push(diagnostic.message());
40+
let mut warnings = self.warnings.lock().unwrap();
41+
warnings.push(diagnostic.message());
4042
}
4143
}
4244
}

rust/cubetranspilers/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ use crate::validation_transpiler::ValidationTransformVisitor;
55
use anyhow::{anyhow, Result};
66
use error_reporter::ErrorReporter;
77
use serde::{Deserialize, Serialize};
8-
use std::cell::RefCell;
98
use std::collections::{HashMap, HashSet};
9+
use std::sync::{Arc, Mutex};
1010
use swc_core::common::errors::{Handler, HandlerFlags};
1111
use swc_core::common::input::StringInput;
1212
use swc_core::common::sync::{Lrc, OnceCell};
@@ -57,7 +57,7 @@ pub fn run_transpilers(
5757
) -> Result<TransformResult> {
5858
let sm: Lrc<SourceMap> = Default::default();
5959
let sf = sm.new_source_file(
60-
Lrc::new(FileName::Custom(transform_config.file_name)),
60+
Arc::new(FileName::Custom(transform_config.file_name)),
6161
sources,
6262
);
6363

@@ -83,8 +83,8 @@ pub fn run_transpilers(
8383
source_file: sm_cell,
8484
};
8585

86-
let errors = RefCell::new(Vec::new());
87-
let warnings = RefCell::new(Vec::new());
86+
let errors = Arc::new(Mutex::new(Vec::new()));
87+
let warnings = Arc::new(Mutex::new(Vec::new()));
8888

8989
let reporter = Box::new(ErrorReporter::new(errors.clone(), warnings.clone()));
9090
let handler = Handler::with_emitter_and_flags(
@@ -127,8 +127,8 @@ pub fn run_transpilers(
127127
});
128128

129129
let output_code = generate_code(&program, &sm)?;
130-
let errors = errors.borrow().clone();
131-
let warnings = warnings.borrow().clone();
130+
let errors = errors.lock().unwrap().clone();
131+
let warnings = warnings.lock().unwrap().clone();
132132

133133
Ok(TransformResult {
134134
code: output_code,

0 commit comments

Comments
 (0)