Skip to content

Commit

Permalink
Merge branch 'main' into refactor/logging-runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoyun authored Jul 31, 2024
2 parents ad8cff2 + e4d6a23 commit 1bfb06b
Show file tree
Hide file tree
Showing 55 changed files with 508 additions and 164 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@ jobs:
- name: Check Dependency Version
if: steps.changes.outputs.src == 'true'
run: pnpm run check-dependency-version


lint-website:
name: Lint and format website
Expand Down Expand Up @@ -316,7 +315,8 @@ jobs:
echo 'debug = false' >> Cargo.toml
- name: Run test
run: cargo test --workspace -- --nocapture
# reason for excluding https://github.com/napi-rs/napi-rs/issues/2200
run: cargo test --workspace --exclude rspack_binding_options --exclude rspack_node -- --nocapture

run_benchmark:
name: Run benchmark
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/rspack_collections/src/ukey.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ where
<Item as DatabaseItem>::ItemUkey: Eq + Hash + Debug,
{
pub fn add(&mut self, item: Item) -> &mut Item {
debug_assert!(self.inner.get(&item.ukey()).is_none());
debug_assert!(!self.inner.contains_key(&item.ukey()));
let ukey = item.ukey();
self.inner.entry(ukey).or_insert(item)
}
Expand Down
12 changes: 6 additions & 6 deletions crates/rspack_core/src/build_chunk_graph/code_splitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1014,10 +1014,10 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
.chunk_group_by_ukey
.expect_get_mut(&cgi.chunk_group);

if chunk_group
#[allow(clippy::map_entry)]
if !chunk_group
.module_pre_order_indices
.get(&item.module)
.is_none()
.contains_key(&item.module)
{
chunk_group
.module_pre_order_indices
Expand Down Expand Up @@ -1058,10 +1058,10 @@ Or do you want to use the entrypoints '{name}' and '{runtime}' independently on
.chunk_group_by_ukey
.expect_get_mut(&cgi.chunk_group);

if chunk_group
#[allow(clippy::map_entry)]
if !chunk_group
.module_post_order_indices
.get(&item.module)
.is_none()
.contains_key(&item.module)
{
chunk_group
.module_post_order_indices
Expand Down
5 changes: 2 additions & 3 deletions crates/rspack_core/src/chunk_graph/chunk_graph_chunk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,9 @@ impl ChunkGraph {
old_module_id: &ModuleIdentifier,
new_module_id: &ModuleIdentifier,
) {
if self
if !self
.chunk_graph_module_by_module_identifier
.get(new_module_id)
.is_none()
.contains_key(new_module_id)
{
let new_chunk_graph_module = ChunkGraphModule::new();
self
Expand Down
12 changes: 6 additions & 6 deletions crates/rspack_core/src/compiler/compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -602,9 +602,9 @@ impl Compilation {
/// Get sorted errors based on the factors as follows in order:
/// - module identifier
/// - error offset
/// Rspack assumes for each offset, there is only one error.
/// However, when it comes to the case that there are multiple errors with the same offset,
/// the order of these errors will not be guaranteed.
/// Rspack assumes for each offset, there is only one error.
/// However, when it comes to the case that there are multiple errors with the same offset,
/// the order of these errors will not be guaranteed.
pub fn get_errors_sorted(&self) -> impl Iterator<Item = &Diagnostic> {
let get_offset = |d: &dyn rspack_error::miette::Diagnostic| {
d.labels()
Expand All @@ -630,9 +630,9 @@ impl Compilation {
/// Get sorted warnings based on the factors as follows in order:
/// - module identifier
/// - error offset
/// Rspack assumes for each offset, there is only one error.
/// However, when it comes to the case that there are multiple errors with the same offset,
/// the order of these errors will not be guaranteed.
/// Rspack assumes for each offset, there is only one error.
/// However, when it comes to the case that there are multiple errors with the same offset,
/// the order of these errors will not be guaranteed.
pub fn get_warnings_sorted(&self) -> impl Iterator<Item = &Diagnostic> {
let get_offset = |d: &dyn rspack_error::miette::Diagnostic| {
d.labels()
Expand Down
6 changes: 1 addition & 5 deletions crates/rspack_core/src/compiler/module_executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,7 @@ impl ModuleExecutor {
make_artifact.diagnostics = Default::default();
make_artifact.has_module_graph_change = false;

make_artifact = if let Ok(artifact) = update_module_graph(compilation, make_artifact, params) {
artifact
} else {
MakeArtifact::default()
};
make_artifact = update_module_graph(compilation, make_artifact, params).unwrap_or_default();

let mut ctx = MakeTaskContext::new(compilation, make_artifact);
let (event_sender, event_receiver) = unbounded_channel();
Expand Down
17 changes: 4 additions & 13 deletions crates/rspack_core/src/exports_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,7 @@ impl ExportsInfoId {
}

pub fn is_export_provided(&self, names: &[Atom], mg: &ModuleGraph) -> Option<ExportProvided> {
let Some(name) = names.first() else {
return None;
};
let name = names.first()?;
let info = self.get_read_only_export_info(name, mg);
if let Some(exports_info) = info.exports_info
&& names.len() > 1
Expand Down Expand Up @@ -256,9 +254,7 @@ impl ExportsInfoId {
if names.len() == 1 {
return Some(export_info);
}
let Some(exports_info) = export_info.exports_info else {
return None;
};
let exports_info = export_info.exports_info?;
exports_info.get_read_only_export_info_recursive(&names[1..], mg)
}

Expand Down Expand Up @@ -456,10 +452,7 @@ impl ExportsInfoId {
return Some(UsedName::Vec(names));
}
let export_info = self.get_read_only_export_info(&names[0], mg);
let x = export_info.get_used_name(Some(&names[0]), runtime);
let Some(x) = x else {
return None;
};
let x = export_info.get_used_name(Some(&names[0]), runtime)?;
let names_len = names.len();
let mut arr = if x == names[0] && names.len() == 1 {
names.clone()
Expand All @@ -473,9 +466,7 @@ impl ExportsInfoId {
&& export_info.get_used(runtime) == UsageState::OnlyPropertiesUsed
{
let nested = exports_info.get_used_name(mg, runtime, UsedName::Vec(names[1..].to_vec()));
let Some(nested) = nested else {
return None;
};
let nested = nested?;
arr.extend(match nested {
UsedName::Str(name) => vec![name],
UsedName::Vec(names) => names,
Expand Down
1 change: 0 additions & 1 deletion crates/rspack_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#![feature(anonymous_lifetime_in_impl_trait)]
#![feature(hash_raw_entry)]
#![feature(option_get_or_insert_default)]
#![feature(slice_group_by)]

use std::{fmt, sync::Arc};
mod dependencies_block;
Expand Down
4 changes: 2 additions & 2 deletions crates/rspack_core/src/module_factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ impl ModuleFactoryCreateData {
}

pub fn add_file_dependencies(&mut self, files: impl IntoIterator<Item = PathBuf>) {
self.file_dependencies.extend(files.into_iter());
self.file_dependencies.extend(files);
}

pub fn add_context_dependency(&mut self, context: PathBuf) {
self.context_dependencies.insert(context);
}

pub fn add_context_dependencies(&mut self, contexts: impl IntoIterator<Item = PathBuf>) {
self.context_dependencies.extend(contexts.into_iter());
self.context_dependencies.extend(contexts);
}

pub fn add_missing_dependency(&mut self, missing: PathBuf) {
Expand Down
4 changes: 1 addition & 3 deletions crates/rspack_core/src/module_graph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,7 @@ impl<'a> ModuleGraph<'a> {
connection_id: &ConnectionId,
force: bool,
) -> Option<BuildDependency> {
let Some(connection) = self.connection_by_connection_id(connection_id) else {
return None;
};
let connection = self.connection_by_connection_id(connection_id)?;
let module_identifier = *connection.module_identifier();
let original_module_identifier = connection.original_module_identifier;
let dependency_id = connection.dependency_id;
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_core/src/update_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::hash::Hasher;

use crate::{Compilation, RuntimeSpec};

#[allow(dead_code)]
pub struct UpdateHashContext<'a> {
pub compilation: &'a Compilation,
pub runtime: Option<&'a RuntimeSpec>,
Expand Down
3 changes: 3 additions & 0 deletions crates/rspack_fs_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ rspack_napi = { path = "../rspack_napi" }

[build-dependencies]
napi-build = { workspace = true }

[lints.rust]
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(node)'] }
3 changes: 3 additions & 0 deletions crates/rspack_loader_runner/src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ pub(crate) mod test {

use super::{Loader, LoaderItem};

#[allow(dead_code)]
pub(crate) struct Custom;

#[async_trait::async_trait]
Expand All @@ -243,6 +244,7 @@ pub(crate) mod test {
}
}

#[allow(dead_code)]
pub(crate) struct Custom2;
#[async_trait::async_trait]
impl Loader<()> for Custom2 {}
Expand All @@ -252,6 +254,7 @@ pub(crate) mod test {
}
}

#[allow(dead_code)]
pub(crate) struct Builtin;
#[async_trait::async_trait]
impl Loader<()> for Builtin {}
Expand Down
8 changes: 1 addition & 7 deletions crates/rspack_loader_swc/src/compiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -525,13 +525,7 @@ impl SwcCompiler {
Ok(r) => r,
Err(_err) => {
// Load original source map if possible
match read_file_sourcemap(data_url) {
Ok(v) => v,
Err(_) => {
// tracing::error!("failed to read input source map: {:?}", err);
None
}
}
read_file_sourcemap(data_url).unwrap_or(None)
}
}
};
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_macros_test/tests/runtime_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use rspack_core::{rspack_sources::Source, Compilation};
use rspack_error::Result;
use rspack_macros::impl_runtime_module;

#[allow(dead_code)]
#[test]
fn with_generic() {
#[impl_runtime_module]
Expand Down
6 changes: 3 additions & 3 deletions crates/rspack_plugin_javascript/src/ast/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ fn module_type_to_is_module(value: &ModuleType) -> IsModule {

/// Why this helper function design like this?
/// 1. `swc_ecma_parser` could return ast with some errors which are recoverable
/// or warning (though swc defined them as errors), but the parser at here should
/// be non-error-tolerant.
/// or warning (though swc defined them as errors), but the parser at here should
/// be non-error-tolerant.
///
/// 2. We can't convert to [rspack_error::Error] at this point, because there is
/// no `path` and `source`
/// no `path` and `source`
pub fn parse_js(
fm: Arc<SourceFile>,
target: EsVersion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,9 +189,7 @@ impl Dependency for CommonJsExportRequireDependency {
let Some(name) = self.names.first() else {
unreachable!();
};
let Some(from) = mg.connection_by_dependency(&self.id) else {
return None;
};
let from = mg.connection_by_dependency(&self.id)?;
Some(ExportsSpec {
exports: ExportsOfExportsSpec::Array(vec![ExportNameOrSpec::ExportSpec(ExportSpec {
name: name.to_owned(),
Expand All @@ -208,9 +206,7 @@ impl Dependency for CommonJsExportRequireDependency {
..Default::default()
})
} else if self.names.is_empty() {
let Some(from) = mg.connection_by_dependency(&self.id) else {
return None;
};
let from = mg.connection_by_dependency(&self.id)?;
if let Some(reexport_info) = self.get_star_reexports(mg, None, from.module_identifier()) {
Some(ExportsSpec {
exports: ExportsOfExportsSpec::Array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -921,9 +921,7 @@ impl HarmonyExportImportedSpecifierDependency {
&potential_conflicts.names[potential_conflicts.names_slice
..potential_conflicts.dependency_indices[potential_conflicts.dependency_index]],
);
let Some(imported_module) = module_graph.get_module_by_dependency_id(&self.id) else {
return None;
};
let imported_module = module_graph.get_module_by_dependency_id(&self.id)?;
let exports_info = module_graph.get_exports_info(&imported_module.identifier());
let mut conflicts: IndexMap<&str, Vec<&Atom>, BuildHasherDefault<FxHasher>> =
IndexMap::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,10 +207,7 @@ pub fn harmony_import_dependency_get_linking_error<T: ModuleDependency>(
additional_msg: String,
should_error: bool,
) -> Option<Diagnostic> {
let Some(imported_module) = module_graph.get_module_by_dependency_id(module_dependency.id())
else {
return None;
};
let imported_module = module_graph.get_module_by_dependency_id(module_dependency.id())?;
if !imported_module.get_diagnostics().is_empty() {
return None;
}
Expand Down
1 change: 1 addition & 0 deletions crates/rspack_plugin_javascript/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#![feature(if_let_guard)]
#![feature(let_chains)]
#![feature(box_patterns)]
#![feature(trait_upcasting)]
#![recursion_limit = "256"]

pub mod ast;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn get_member_expression_info<E: ExprLike>(
None => is_module_exports_member_expr_start(expr),
};
expr.as_member().and_then(|expr: &MemberExpr| {
let Some(members) = parser
let members = parser
.get_member_expression_info(expr, AllowedMemberTypes::Expression)
.and_then(|info| match info {
MemberExpressionInfo::Call(_) => None,
Expand All @@ -44,10 +44,7 @@ fn get_member_expression_info<E: ExprLike>(
.skip(if is_module_exports_start { 1 } else { 0 })
.map(|n| n.to_owned())
.collect::<Vec<_>>()
})
else {
return None;
};
})?;
match expr.obj {
box Expr::Call(_) => Some(members),
box Expr::Ident(_) => Some(members),
Expand Down Expand Up @@ -378,11 +375,7 @@ impl JavascriptParserPlugin for CommonJsExportsParserPlugin {

let handle_remaining = |parser: &mut JavascriptParser, base: ExportsBase| {
let is_module_exports_start = matches!(base, ExportsBase::ModuleExports);
let Some(remaining) =
get_member_expression_info(parser, left_expr, Some(is_module_exports_start))
else {
return None;
};
let remaining = get_member_expression_info(parser, left_expr, Some(is_module_exports_start))?;

if (remaining.is_empty() || remaining.first().is_some_and(|i| i != "__esModule"))
&& parser.is_require_call_expr(&assign_expr.right)
Expand Down
Loading

0 comments on commit 1bfb06b

Please sign in to comment.