Skip to content

Commit

Permalink
chore(rust): rename EcmaModuleTask to ModuleTask (rolldown#2017)
Browse files Browse the repository at this point in the history
<!-- Thank you for contributing! -->

### Description

Gonna reuse this task to create `CssModule` too.

<!-- Please insert your description here and provide especially info
about the "what" this PR is solving -->
  • Loading branch information
hyf0 authored Aug 18, 2024
1 parent 88e1a41 commit 374cd3d
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 25 deletions.
10 changes: 4 additions & 6 deletions crates/rolldown/src/module_loader/mod.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
mod ecma_module_task;
pub mod module_loader;
mod runtime_ecma_module_task;
mod module_task;
mod runtime_module_task;
pub mod task_context;
mod task_result;

pub use module_loader::ModuleLoader;
use rolldown_error::BuildDiagnostic;

use self::{
runtime_ecma_module_task::RuntimeEcmaModuleTaskResult, task_result::NormalModuleTaskResult,
};
use self::{runtime_module_task::RuntimeModuleTaskResult, task_result::NormalModuleTaskResult};
pub enum Msg {
NormalModuleDone(NormalModuleTaskResult),
RuntimeNormalModuleDone(RuntimeEcmaModuleTaskResult),
RuntimeNormalModuleDone(RuntimeModuleTaskResult),
BuildErrors(Vec<BuildDiagnostic>),
Panics(anyhow::Error),
}
16 changes: 8 additions & 8 deletions crates/rolldown/src/module_loader/module_loader.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use super::ecma_module_task::{EcmaModuleTask, EcmaModuleTaskOwner};
use super::runtime_ecma_module_task::RuntimeEcmaModuleTask;
use super::module_task::{ModuleTask, ModuleTaskOwner};
use super::runtime_module_task::RuntimeModuleTask;
use super::task_context::TaskContextMeta;
use super::task_result::NormalModuleTaskResult;
use super::Msg;
use crate::module_loader::runtime_ecma_module_task::RuntimeEcmaModuleTaskResult;
use crate::module_loader::runtime_module_task::RuntimeModuleTaskResult;
use crate::module_loader::task_context::TaskContext;
use crate::runtime::{RuntimeModuleBrief, RUNTIME_MODULE_ID};
use crate::type_alias::IndexEcmaAst;
Expand Down Expand Up @@ -112,7 +112,7 @@ impl ModuleLoader {
let mut symbols = Symbols::default();
let runtime_id = intermediate_normal_modules.alloc_ecma_module_idx(&mut symbols);

let task = RuntimeEcmaModuleTask::new(runtime_id, tx_to_runtime_module);
let task = RuntimeModuleTask::new(runtime_id, tx_to_runtime_module);

#[cfg(target_family = "wasm")]
{
Expand Down Expand Up @@ -142,7 +142,7 @@ impl ModuleLoader {
fn try_spawn_new_task(
&mut self,
resolved_id: ResolvedId,
owner: Option<EcmaModuleTaskOwner>,
owner: Option<ModuleTaskOwner>,
) -> ModuleIdx {
match self.visited.entry(resolved_id.id.clone()) {
std::collections::hash_map::Entry::Occupied(visited) => *visited.get(),
Expand All @@ -169,7 +169,7 @@ impl ModuleLoader {
not_visited.insert(idx);
self.remaining += 1;

let task = EcmaModuleTask::new(Arc::clone(&self.shared_context), idx, resolved_id, owner);
let task = ModuleTask::new(Arc::clone(&self.shared_context), idx, resolved_id, owner);
#[cfg(target_family = "wasm")]
{
let handle = tokio::runtime::Handle::current();
Expand Down Expand Up @@ -243,7 +243,7 @@ impl ModuleLoader {
.zip(resolved_deps)
.map(|(raw_rec, info)| {
let ecma_module = module.as_ecma().unwrap();
let owner = EcmaModuleTaskOwner::new(
let owner = ModuleTaskOwner::new(
ecma_module.source.clone(),
ecma_module.stable_id.as_str().into(),
Span::new(raw_rec.module_request_start, raw_rec.module_request_end()),
Expand Down Expand Up @@ -272,7 +272,7 @@ impl ModuleLoader {
self.intermediate_normal_modules.modules[module_idx] = Some(module);
}
Msg::RuntimeNormalModuleDone(task_result) => {
let RuntimeEcmaModuleTaskResult { ast_symbols, mut module, runtime, ast } = task_result;
let RuntimeModuleTaskResult { ast_symbols, mut module, runtime, ast } = task_result;
let ast_idx = self.intermediate_normal_modules.index_ecma_ast.push((ast, module.idx));
module.ecma_ast_idx = Some(ast_idx);
self.intermediate_normal_modules.modules[self.runtime_id] = Some(module.into());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@ use crate::{
utils::{load_source::load_source, transform_source::transform_source},
};

pub struct EcmaModuleTaskOwner {
pub struct ModuleTaskOwner {
source: ArcStr,
importer_id: Rstr,
importee_span: Span,
}

impl EcmaModuleTaskOwner {
impl ModuleTaskOwner {
pub fn new(source: ArcStr, importer_id: Rstr, importee_span: Span) -> Self {
EcmaModuleTaskOwner { source, importer_id, importee_span }
ModuleTaskOwner { source, importer_id, importee_span }
}
}

pub struct EcmaModuleTask {
pub struct ModuleTask {
ctx: Arc<TaskContext>,
module_idx: ModuleIdx,
resolved_id: ResolvedId,
owner: Option<EcmaModuleTaskOwner>,
owner: Option<ModuleTaskOwner>,
errors: Vec<BuildDiagnostic>,
is_user_defined_entry: bool,
}

impl EcmaModuleTask {
impl ModuleTask {
pub fn new(
ctx: Arc<TaskContext>,
idx: ModuleIdx,
resolved_id: ResolvedId,
owner: Option<EcmaModuleTaskOwner>,
owner: Option<ModuleTaskOwner>,
) -> Self {
let is_user_defined_entry = owner.is_none();
Self { ctx, module_idx: idx, resolved_id, owner, errors: vec![], is_user_defined_entry }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ use crate::{
types::ast_symbols::AstSymbols,
utils::tweak_ast_for_scanning::tweak_ast_for_scanning,
};
pub struct RuntimeEcmaModuleTask {
pub struct RuntimeModuleTask {
tx: tokio::sync::mpsc::Sender<Msg>,
module_id: ModuleIdx,
errors: Vec<BuildDiagnostic>,
}

pub struct RuntimeEcmaModuleTaskResult {
pub struct RuntimeModuleTaskResult {
pub runtime: RuntimeModuleBrief,
pub ast_symbols: AstSymbols,
pub ast: EcmaAst,
Expand All @@ -37,7 +37,7 @@ pub struct MakeEcmaAstResult {
namespace_object_ref: SymbolRef,
}

impl RuntimeEcmaModuleTask {
impl RuntimeModuleTask {
pub fn new(id: ModuleIdx, tx: tokio::sync::mpsc::Sender<Msg>) -> Self {
Self { module_id: id, tx, errors: Vec::new() }
}
Expand Down Expand Up @@ -108,7 +108,7 @@ impl RuntimeEcmaModuleTask {
has_eval,
};

if let Err(_err) = self.tx.try_send(Msg::RuntimeNormalModuleDone(RuntimeEcmaModuleTaskResult {
if let Err(_err) = self.tx.try_send(Msg::RuntimeNormalModuleDone(RuntimeModuleTaskResult {
// warnings: self.warnings,
ast_symbols,
module,
Expand Down

0 comments on commit 374cd3d

Please sign in to comment.