Skip to content

refactor: remove redirect_to in exports info #11023

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 1 addition & 26 deletions crates/rspack_core/src/exports/export_info_setter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::collections::hash_map::Entry;
use rspack_util::atom::Atom;

use super::{ExportInfoData, ExportInfoTargetValue, Inlinable, UsageFilterFnTy, UsageState};
use crate::{DependencyId, ExportsInfo, ExportsInfoData, ModuleGraph, Nullable, RuntimeSpec};
use crate::{DependencyId, ExportsInfo, Nullable, RuntimeSpec};

impl ExportInfoData {
pub fn reset_provide_info(&mut self) {
Expand Down Expand Up @@ -212,31 +212,6 @@ impl ExportInfoData {
changed
}

pub fn create_nested_exports_info(&mut self, mg: &mut ModuleGraph) -> ExportsInfo {
if self.exports_info_owned() {
return self
.exports_info()
.expect("should have exports_info when exports_info is true");
}

self.set_exports_info_owned(true);
let new_exports_info = ExportsInfoData::default();
let new_exports_info_id = new_exports_info.id();

self.set_exports_info_owned(true);
self.set_exports_info(Some(new_exports_info_id));

mg.set_exports_info(new_exports_info_id, new_exports_info);
new_exports_info_id.set_has_provide_info(mg);
let old_exports_info = self.exports_info();
if let Some(exports_info) = old_exports_info {
exports_info
.as_data_mut(mg)
.set_redirect_name_to(Some(new_exports_info_id));
}
new_exports_info_id
}

pub fn set_has_use_info(&mut self, nested_exports_info: &mut Vec<ExportsInfo>) {
if !self.has_use_in_runtime_info() {
self.set_has_use_in_runtime_info(true);
Expand Down
129 changes: 42 additions & 87 deletions crates/rspack_core/src/exports/exports_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ impl ExportsInfo {
.side_effects_only_info_mut()
.reset_provide_info();
exports_info.other_exports_info_mut().reset_provide_info();
if let Some(redirect_to) = exports_info.redirect_to() {
redirect_to.reset_provide_info(mg);
}
}

/// # Panic
Expand All @@ -59,16 +56,12 @@ impl ExportsInfo {
export_info.set_can_mangle_provide(Some(true));
}
}
if let Some(redirect) = exports_info.redirect_to() {
redirect.set_has_provide_info(mg);
} else {
let other_exports_info = exports_info.other_exports_info_mut();
if other_exports_info.provided().is_none() {
other_exports_info.set_provided(Some(ExportProvided::NotProvided));
}
if other_exports_info.can_mangle_provide().is_none() {
other_exports_info.set_can_mangle_provide(Some(true));
}
let other_exports_info = exports_info.other_exports_info_mut();
if other_exports_info.provided().is_none() {
other_exports_info.set_provided(Some(ExportProvided::NotProvided));
}
if other_exports_info.can_mangle_provide().is_none() {
other_exports_info.set_can_mangle_provide(Some(true));
}
}

Expand Down Expand Up @@ -117,34 +110,24 @@ impl ExportsInfo {
}
}

if let Some(redirect_to) = exports_info.redirect_to() {
changed |= redirect_to.set_unknown_exports_provided(
mg,
can_mangle,
exclude_exports,
target_key,
target_module,
priority,
);
} else {
let other_exports_info_data = exports_info.other_exports_info_mut();
if !matches!(
other_exports_info_data.provided(),
Some(ExportProvided::Provided | ExportProvided::Unknown)
) {
other_exports_info_data.set_provided(Some(ExportProvided::Unknown));
changed = true;
}
let other_exports_info_data = exports_info.other_exports_info_mut();
if !matches!(
other_exports_info_data.provided(),
Some(ExportProvided::Provided | ExportProvided::Unknown)
) {
other_exports_info_data.set_provided(Some(ExportProvided::Unknown));
changed = true;
}

if let Some(target_key) = target_key {
other_exports_info_data.set_target(Some(target_key), target_module, None, priority);
}
if let Some(target_key) = target_key {
other_exports_info_data.set_target(Some(target_key), target_module, None, priority);
}

if !can_mangle && other_exports_info_data.can_mangle_provide() != Some(false) {
other_exports_info_data.set_can_mangle_provide(Some(false));
changed = true;
}
if !can_mangle && other_exports_info_data.can_mangle_provide() != Some(false) {
other_exports_info_data.set_can_mangle_provide(Some(false));
changed = true;
}

changed
}

Expand All @@ -153,9 +136,6 @@ impl ExportsInfo {
if let Some(export_info) = exports_info.named_exports(name) {
return export_info.id();
}
if let Some(redirect) = exports_info.redirect_to() {
return redirect.get_export_info(mg, name);
}

let other_export_info = exports_info.other_exports_info();
let new_info = ExportInfoData::new(*self, Some(name.clone()), Some(other_export_info));
Expand All @@ -173,14 +153,10 @@ impl ExportsInfo {
exports_info
.side_effects_only_info_mut()
.set_has_use_info(&mut nested_exports_info);
if let Some(redirect) = exports_info.redirect_to() {
redirect.set_has_use_info(mg);
} else {
let other_exports_info = exports_info.other_exports_info_mut();
other_exports_info.set_has_use_info(&mut nested_exports_info);
if other_exports_info.can_mangle_use().is_none() {
other_exports_info.set_can_mangle_use(Some(true));
}
let other_exports_info = exports_info.other_exports_info_mut();
other_exports_info.set_has_use_info(&mut nested_exports_info);
if other_exports_info.can_mangle_use().is_none() {
other_exports_info.set_can_mangle_use(Some(true));
}

for nested_exports_info in nested_exports_info {
Expand All @@ -195,17 +171,12 @@ impl ExportsInfo {
let flag = export_info.set_used_without_info(runtime);
changed |= flag;
}
if let Some(redirect_to) = exports_info.redirect_to() {
let flag = redirect_to.set_used_without_info(mg, runtime);
changed |= flag;
} else {
let other_exports_info = exports_info.other_exports_info_mut();
let flag = other_exports_info.set_used(UsageState::NoInfo, None);
changed |= flag;
if other_exports_info.can_mangle_use() != Some(false) {
other_exports_info.set_can_mangle_use(Some(false));
changed = true;
}
let other_exports_info = exports_info.other_exports_info_mut();
let flag = other_exports_info.set_used(UsageState::NoInfo, None);
changed |= flag;
if other_exports_info.can_mangle_use() != Some(false) {
other_exports_info.set_can_mangle_use(Some(false));
changed = true;
}
changed
}
Expand Down Expand Up @@ -238,23 +209,17 @@ impl ExportsInfo {
changed = true;
}
}
if let Some(redirect_to) = exports_info.redirect_to() {
if redirect_to.set_used_in_unknown_way(mg, runtime) {
changed = true;
}
} else {
let other_exports_info = exports_info.other_exports_info_mut();
if other_exports_info.set_used_conditionally(
Box::new(|value| value < &UsageState::Unknown),
UsageState::Unknown,
runtime,
) {
changed = true;
}
if other_exports_info.can_mangle_use() != Some(false) {
other_exports_info.set_can_mangle_use(Some(false));
changed = true;
}
let other_exports_info = exports_info.other_exports_info_mut();
if other_exports_info.set_used_conditionally(
Box::new(|value| value < &UsageState::Unknown),
UsageState::Unknown,
runtime,
) {
changed = true;
}
if other_exports_info.can_mangle_use() != Some(false) {
other_exports_info.set_can_mangle_use(Some(false));
changed = true;
}
changed
}
Expand All @@ -274,7 +239,6 @@ pub struct ExportsInfoData {
other_exports_info: ExportInfoData,

side_effects_only_info: ExportInfoData,
redirect_to: Option<ExportsInfo>,
id: ExportsInfo,
}

Expand All @@ -285,7 +249,6 @@ impl Default for ExportsInfoData {
exports: BTreeMap::default(),
other_exports_info: ExportInfoData::new(id, None, None),
side_effects_only_info: ExportInfoData::new(id, Some("*side effects only*".into()), None),
redirect_to: None,
id,
}
}
Expand All @@ -296,10 +259,6 @@ impl ExportsInfoData {
self.id
}

pub fn redirect_to(&self) -> Option<ExportsInfo> {
self.redirect_to
}

pub fn other_exports_info(&self) -> &ExportInfoData {
&self.other_exports_info
}
Expand Down Expand Up @@ -331,8 +290,4 @@ impl ExportsInfoData {
pub fn exports_mut(&mut self) -> &mut BTreeMap<Atom, ExportInfoData> {
&mut self.exports
}

pub fn set_redirect_to(&mut self, id: Option<ExportsInfo>) {
self.redirect_to = id;
}
}
Loading
Loading