Visitar URL original
feat(debug_info): add debug info for eliminated facade chunks (#7946) · rolldown/rolldown@ecac0af · GitHub
Skip to content

Commit ecac0af

Browse files
feat(debug_info): add debug info for eliminated facade chunks (#7946)
1 parent 9ed472f commit ecac0af

13 files changed

Lines changed: 172 additions & 9 deletions

File tree

‎crates/rolldown/src/ecmascript/ecma_generator.rs‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,10 @@ impl Generator for EcmaGenerator {
202202

203203
ctx.warnings.extend(warnings);
204204

205-
if ctx.options.experimental.is_attach_debug_info_full() && !ctx.chunk.create_reasons.is_empty()
206-
{
207-
source_joiner.prepend_source(format!("//! {}", ctx.chunk.create_reasons.join("\n//! ")));
205+
if ctx.options.experimental.is_attach_debug_info_full() && !ctx.chunk.debug_info.is_empty() {
206+
let debug_info_str =
207+
ctx.chunk.debug_info.iter().map(ToString::to_string).collect::<Vec<_>>().join("\n//! ");
208+
source_joiner.prepend_source(format!("//! {debug_info_str}"));
208209
}
209210

210211
let (content, map) = source_joiner.join();

‎crates/rolldown/src/stages/generate_stage/chunk_ext.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use arcstr::ArcStr;
22
use itertools::Itertools;
3-
use rolldown_common::{Chunk, ChunkReasonType, NormalizedBundlerOptions};
3+
use rolldown_common::{Chunk, ChunkDebugInfo, ChunkReasonType, NormalizedBundlerOptions};
44
use rolldown_utils::BitSet;
55

66
use crate::stages::link_stage::LinkStageOutput;
@@ -81,6 +81,6 @@ impl ChunkDebugExt for Chunk {
8181
}
8282
};
8383

84-
self.create_reasons.push(reason);
84+
self.debug_info.push(ChunkDebugInfo::CreateReason(reason));
8585
}
8686
}

‎crates/rolldown/src/stages/generate_stage/chunk_optimizer.rs‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use arcstr::ArcStr;
44
use itertools::Itertools;
55
use oxc_index::IndexVec;
66
use rolldown_common::{
7-
Chunk, ChunkIdx, ChunkKind, ChunkMeta, ChunkReasonType, Module, ModuleIdx,
7+
Chunk, ChunkDebugInfo, ChunkIdx, ChunkKind, ChunkMeta, ChunkReasonType, Module, ModuleIdx,
88
ModuleNamespaceIncludedReason, ModuleTable, PreserveEntrySignatures, RuntimeHelper, StmtInfos,
99
WrapKind,
1010
};
@@ -461,6 +461,21 @@ impl GenerateStage<'_> {
461461
.or_default()
462462
.insert(entry_module);
463463

464+
// Add debug info about eliminated facade chunk to target chunk
465+
if self.options.experimental.is_attach_debug_info_full() || self.options.devtools {
466+
let eliminated_chunk_name = chunk_graph.chunk_table[from_chunk_idx]
467+
.name
468+
.as_ref()
469+
.map_or_else(|| "unnamed".to_string(), ArcStr::to_string);
470+
let module_stable_id = module.stable_id.to_string();
471+
chunk_graph.chunk_table[target_chunk_idx].debug_info.push(
472+
ChunkDebugInfo::EliminatedFacadeChunk {
473+
chunk_name: eliminated_chunk_name,
474+
entry_module_id: module_stable_id,
475+
},
476+
);
477+
}
478+
464479
// For CJS modules, include the wrapper_ref (require_xxx) instead of namespace
465480
// and use ToEsm runtime helper instead of ExportAll
466481
if matches!(wrap_kind, WrapKind::Cjs | WrapKind::Esm) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"config": {
3+
"experimental": {
4+
"attachDebugInfo": "full"
5+
}
6+
},
7+
"configVariants": [
8+
{
9+
"chunkOptimization": false
10+
}
11+
]
12+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
---
2+
source: crates/rolldown_testing/src/integration_test.rs
3+
---
4+
# Assets
5+
6+
## main.js
7+
8+
```js
9+
//! User-defined Entry: [Entry-Module-Id: main.js] [Name: Some("main")]
10+
//! Eliminated Facade Chunk: [Chunk-Name: unnamed] [Entry-Module-Id: dynamic-b.js]
11+
//! Eliminated Facade Chunk: [Chunk-Name: unnamed] [Entry-Module-Id: dynamic-a.js]
12+
// HIDDEN [rolldown:runtime]
13+
//#region dynamic-a.js
14+
var dynamic_a_exports = /* @__PURE__ */ __exportAll({ a: () => a });
15+
const a = "dynamic-a";
16+
17+
//#endregion
18+
//#region dynamic-b.js
19+
var dynamic_b_exports = /* @__PURE__ */ __exportAll({ b: () => b });
20+
const b = "dynamic-b";
21+
22+
//#endregion
23+
//#region main.js
24+
Promise.resolve().then(() => dynamic_a_exports).then(console.log);
25+
Promise.resolve().then(() => dynamic_b_exports).then(console.log);
26+
console.log(a, b);
27+
28+
//#endregion
29+
```
30+
31+
# Variant: [chunk_optimization: false]
32+
33+
## Assets
34+
35+
### dynamic-a.js
36+
37+
```js
38+
//! Dynamic Entry: [Entry-Module-Id: dynamic-a.js] [Name: None]
39+
import { t as a } from "./dynamic-a2.js";
40+
41+
export { a };
42+
```
43+
44+
### dynamic-a2.js
45+
46+
```js
47+
//! Common Chunk: [Shared-By: main.js, dynamic-a.js]
48+
//#region dynamic-a.js
49+
const a = "dynamic-a";
50+
51+
//#endregion
52+
export { a as t };
53+
```
54+
55+
### dynamic-b.js
56+
57+
```js
58+
//! Dynamic Entry: [Entry-Module-Id: dynamic-b.js] [Name: None]
59+
import { t as b } from "./dynamic-b2.js";
60+
61+
export { b };
62+
```
63+
64+
### dynamic-b2.js
65+
66+
```js
67+
//! Common Chunk: [Shared-By: main.js, dynamic-b.js]
68+
//#region dynamic-b.js
69+
const b = "dynamic-b";
70+
71+
//#endregion
72+
export { b as t };
73+
```
74+
75+
### main.js
76+
77+
```js
78+
//! User-defined Entry: [Entry-Module-Id: main.js] [Name: Some("main")]
79+
import { t as a } from "./dynamic-a2.js";
80+
import { t as b } from "./dynamic-b2.js";
81+
82+
//#region main.js
83+
import("./dynamic-a.js").then(console.log);
84+
import("./dynamic-b.js").then(console.log);
85+
console.log(a, b);
86+
87+
//#endregion
88+
```
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const a = "dynamic-a";
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export const b = "dynamic-b";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Entry point that dynamically imports modules
2+
// The dynamic imports will be captured by manualCodeSplitting,
3+
// resulting in eliminated facade chunks
4+
import { a } from './dynamic-a.js'
5+
import { b } from './dynamic-b.js'
6+
import("./dynamic-a.js").then(console.log);
7+
import("./dynamic-b.js").then(console.log);
8+
9+
console.log(a, b)

‎crates/rolldown/tests/snapshots/integration_rolldown__filename_with_hash.snap‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,6 +4049,10 @@ expression: output
40494049
40504050
- main-!~{000}~.js => main-BtfNOhnu.js
40514051
4052+
# tests/rolldown/function/experimental/attach_debug_info/eliminated_facade_chunk
4053+
4054+
- main-!~{000}~.js => main-oZHjdmRw.js
4055+
40524056
# tests/rolldown/function/experimental/attach_debug_info/full
40534057
40544058
- A-!~{000}~.js => A-Dg0npFc7.js

‎crates/rolldown_common/src/chunk/mod.rs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ use crate::{
77
ChunkIdx, ChunkKind, FilenameTemplate, ImportRecordIdx, ModuleIdx, ModuleTable, NamedImport,
88
NormalModule, NormalizedBundlerOptions, OutputExports, PreserveEntrySignatures,
99
RenderedConcatenatedModuleParts, RollupPreRenderedChunk, RuntimeHelper, SymbolRef,
10-
chunk::types::{chunk_reason_type::ChunkReasonType, module_group::ModuleGroup},
10+
chunk::types::{
11+
chunk_debug_info::ChunkDebugInfo, chunk_reason_type::ChunkReasonType, module_group::ModuleGroup,
12+
},
1113
};
1214
pub mod chunk_table;
1315
pub mod types;
@@ -82,7 +84,7 @@ pub struct Chunk {
8284
pub import_symbol_from_external_modules: FxIndexSet<ModuleIdx>,
8385
pub exports_to_other_chunks: FxHashMap<SymbolRef, Vec<CompactStr>>,
8486
pub input_base: ArcStr,
85-
pub create_reasons: Vec<String>,
87+
pub debug_info: Vec<ChunkDebugInfo>,
8688
pub chunk_reason_type: Box<ChunkReasonType>,
8789
pub preserve_entry_signature: Option<PreserveEntrySignatures>,
8890
pub depended_runtime_helper: RuntimeHelper,

0 commit comments

Comments
 (0)