omena-transform-passes 0.2.0

Transform pass registry and DAG planner for Omena CSS
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
//! Transform pass execution over source text and explicit workspace context.
//!
//! The executor is the mutation boundary for ordered transform plans. It applies
//! registered pass kinds, records provenance outcomes, and preserves semantic
//! removal evidence for downstream query and consumer surfaces.

use omena_parser::StyleDialect;
use omena_transform_cst::TransformPassKind;

use super::{
    cascade_proof::{
        collect_cascade_proof_obligations_for_pass_input, summarize_cascade_proof_obligations,
    },
    outcome::{mutation_outcome, no_change_outcome, planned_only_outcome},
    planner::{plan_transform_passes, transform_pass_kind_from_id},
    provenance::{derive_transform_mutation_spans, provenance_derivation_forest_from_outcomes},
};
use crate::model::{
    TransformExecutionContextV0, TransformExecutionSummaryV0, TransformPassRuntimeStatus,
};
use crate::registry::{
    add_css_vendor_prefixes, combine_css_shorthands, compress_css_colors,
    compress_css_is_where_selectors, compress_css_numbers,
    css_module_composes_resolutions_for_source, dedupe_exact_css_rules,
    evaluate_dead_media_branch_rules, evaluate_static_media_rules, evaluate_static_supports_rules,
    flatten_css_layers, flatten_css_scopes, inline_css_imports, lower_css_color_function,
    lower_css_color_mix, lower_css_light_dark, lower_css_logical_to_physical,
    lower_css_oklab_oklch, merge_adjacent_same_block_css_selectors,
    merge_adjacent_same_selector_css_rules, normalize_css_string_quotes, normalize_css_units,
    normalize_css_whitespace, reachable_class_names_with_composes_exports, reduce_css_calc,
    remove_empty_css_rules, resolve_css_module_composes, resolve_static_css_modules_values,
    rewrite_css_module_class_names, route_design_token_values, strip_css_comments,
    strip_css_url_quotes, substitute_static_css_custom_properties,
    tree_shake_css_class_rules_with_removals, tree_shake_css_custom_properties_with_removals,
    tree_shake_css_keyframes_with_removals, tree_shake_css_modules_values_with_removals,
    unwrap_css_nesting,
};

pub fn execute_transform_passes_on_source(
    source: &str,
    requested: &[TransformPassKind],
) -> TransformExecutionSummaryV0 {
    execute_transform_passes_on_source_with_dialect(source, StyleDialect::Css, requested)
}

pub fn execute_transform_passes_on_source_with_dialect(
    source: &str,
    dialect: StyleDialect,
    requested: &[TransformPassKind],
) -> TransformExecutionSummaryV0 {
    let context = TransformExecutionContextV0::default();
    execute_transform_passes_on_source_with_dialect_and_context(
        source, dialect, requested, &context,
    )
}

#[cfg(feature = "lawvere-trace")]
pub fn execute_transform_passes_on_source_with_lawvere_trace(
    source: &str,
    requested: &[TransformPassKind],
) -> (
    TransformExecutionSummaryV0,
    omena_lawvere::LawvereModelTraceV0,
) {
    execute_transform_passes_on_source_with_lawvere_trace_and_dialect(
        source,
        StyleDialect::Css,
        requested,
    )
}

#[cfg(feature = "lawvere-trace")]
pub fn execute_transform_passes_on_source_with_lawvere_trace_and_dialect(
    source: &str,
    dialect: StyleDialect,
    requested: &[TransformPassKind],
) -> (
    TransformExecutionSummaryV0,
    omena_lawvere::LawvereModelTraceV0,
) {
    let summary = execute_transform_passes_on_source_with_dialect(source, dialect, requested);
    let trace = omena_lawvere::trace_lawvere_model_v0(requested, summary.ordered_pass_ids.clone());
    (summary, trace)
}

#[cfg(feature = "lawvere-trace")]
pub fn evaluate_lawvere_reorderability_with_differential_corpus(
    left: TransformPassKind,
    right: TransformPassKind,
    fixtures: &[&str],
) -> (
    omena_lawvere::ReorderabilityCertificateV0,
    omena_lawvere::LawvereDifferentialCommutativityWitnessV0,
) {
    let cases = fixtures
        .iter()
        .enumerate()
        .map(|(index, source)| {
            let left_first = execute_transform_passes_on_source(source, &[left]);
            let left_then_right =
                execute_transform_passes_on_source(&left_first.output_css, &[right]);
            let right_first = execute_transform_passes_on_source(source, &[right]);
            let right_then_left =
                execute_transform_passes_on_source(&right_first.output_css, &[left]);
            let left_then_right_mutation_count =
                left_first.mutation_count + left_then_right.mutation_count;
            let right_then_left_mutation_count =
                right_first.mutation_count + right_then_left.mutation_count;

            omena_lawvere::LawvereDifferentialCommutativityCaseV0 {
                label: format!("fixture-{index}"),
                input_css: (*source).to_string(),
                left_then_right_css: left_then_right.output_css.clone(),
                right_then_left_css: right_then_left.output_css.clone(),
                left_then_right_mutation_count,
                right_then_left_mutation_count,
                equal_output: left_then_right.output_css == right_then_left.output_css,
            }
        })
        .collect::<Vec<_>>();
    let witness = omena_lawvere::lawvere_differential_commutativity_witness_v0(left, right, cases);
    let certificate =
        omena_lawvere::reorderability_certificate_from_differential_v0(left, right, &witness);
    (certificate, witness)
}

pub fn execute_transform_passes_on_source_with_dialect_and_context(
    source: &str,
    dialect: StyleDialect,
    requested: &[TransformPassKind],
    context: &TransformExecutionContextV0,
) -> TransformExecutionSummaryV0 {
    let pass_plan = plan_transform_passes(requested);
    let requested_pass_ids = requested.iter().map(|pass| pass.id()).collect::<Vec<_>>();
    let ordered_pass_ids = pass_plan.ordered_pass_ids.clone();
    let reachable_class_names = reachable_class_names_with_composes_exports(
        source,
        dialect,
        &context.reachable_class_names,
        &context.css_module_composes_resolutions,
    );
    let mut output_css = source.to_string();
    let mut outcomes = Vec::new();
    let mut css_module_evaluation = None;
    let mut css_import_inlines = Vec::new();
    let mut css_module_composes_exports = Vec::new();
    let mut design_token_routes = Vec::new();
    let mut semantic_removals = Vec::new();
    let mut outcome_mutation_spans = Vec::new();
    let mut cascade_proof_obligations = Vec::new();

    macro_rules! apply_mutation_pass {
        ($pass_id:expr, $input_byte_len:expr, $run:expr, $detail:literal) => {{
            let (next_css, mutation_count) = $run;
            let outcome = mutation_outcome(
                $pass_id,
                $input_byte_len,
                next_css.len(),
                mutation_count,
                $detail,
            );
            output_css = next_css;
            outcome
        }};
    }

    macro_rules! planned_only_pass {
        ($pass_id:expr, $input_byte_len:expr, $detail:literal) => {
            planned_only_outcome($pass_id, $input_byte_len, output_css.len(), $detail)
        };
    }

    for pass_id in &ordered_pass_ids {
        let pass = transform_pass_kind_from_id(pass_id);
        let pass_input_css = output_css.clone();
        let input_byte_len = output_css.len();
        cascade_proof_obligations.extend(collect_cascade_proof_obligations_for_pass_input(
            pass_id,
            pass,
            &pass_input_css,
            dialect,
            context,
        ));
        let outcome = match pass {
            Some(TransformPassKind::WhitespaceStrip) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    normalize_css_whitespace(&output_css, dialect),
                    "normalized lexer trivia where adjacent token boundaries remain unambiguous"
                )
            }
            Some(TransformPassKind::CommentStrip) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    strip_css_comments(&output_css, dialect),
                    "removed CSS block comments outside string literals"
                )
            }
            Some(TransformPassKind::NumberCompression) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    compress_css_numbers(&output_css, dialect),
                    "compressed lexer numeric tokens without touching identifiers or strings"
                )
            }
            Some(TransformPassKind::UnitNormalization) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    normalize_css_units(&output_css, dialect),
                    "normalized zero length units and known CSS unit casing inside declaration contexts"
                )
            }
            Some(TransformPassKind::ColorCompression) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    compress_css_colors(&output_css, dialect),
                    "compressed static declaration color values and hex color tokens"
                )
            }
            Some(TransformPassKind::UrlQuoteStrip) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    strip_css_url_quotes(&output_css, dialect),
                    "stripped quotes from safe url() string arguments"
                )
            }
            Some(TransformPassKind::StringQuoteNormalize) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    normalize_css_string_quotes(&output_css, dialect),
                    "normalized safe CSS string tokens, declaration-scoped font family strings, and static font keyword aliases"
                )
            }
            Some(TransformPassKind::SelectorIsWhereCompression) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    compress_css_is_where_selectors(&output_css, dialect),
                    "compressed :is/:where selector functions and keyframe selector aliases only when matching semantics are preserved"
                )
            }
            Some(TransformPassKind::ShorthandCombining) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    combine_css_shorthands(&output_css, dialect),
                    "combined safe shorthand declarations and adjacent longhands only with cascade-preserving proofs"
                )
            }
            Some(TransformPassKind::RuleDeduplication) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    dedupe_exact_css_rules(&output_css, dialect),
                    "removed cascade-safe duplicate ordinary rules while preserving the final occurrence"
                )
            }
            Some(TransformPassKind::RuleMerging) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    merge_adjacent_same_selector_css_rules(&output_css, dialect),
                    "merged adjacent same-selector ordinary rule runs without reordering declarations"
                )
            }
            Some(TransformPassKind::SelectorMerging) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    merge_adjacent_same_block_css_selectors(&output_css, dialect),
                    "merged adjacent ordinary rule runs with identical declaration blocks"
                )
            }
            Some(TransformPassKind::VendorPrefixing) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    add_css_vendor_prefixes(&output_css, dialect),
                    "inserted conservative vendor-prefixed declaration synonyms when absent"
                )
            }
            Some(TransformPassKind::LightDarkLowering) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    lower_css_light_dark(&output_css, dialect),
                    "lowered light-dark() color references into dark media branches"
                )
            }
            Some(TransformPassKind::ColorMixLowering) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    lower_css_color_mix(&output_css, dialect),
                    "lowered static srgb color-mix() references with static color operands"
                )
            }
            Some(TransformPassKind::OklchOklabLowering) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    lower_css_oklab_oklch(&output_css, dialect),
                    "lowered in-gamut oklab()/oklch() color references to srgb"
                )
            }
            Some(TransformPassKind::ColorFunctionLowering) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    lower_css_color_function(&output_css, dialect),
                    "lowered static color(...) references with static channels"
                )
            }
            Some(TransformPassKind::LogicalToPhysical) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    lower_css_logical_to_physical(&output_css, dialect),
                    "lowered logical properties only under static horizontal writing direction"
                )
            }
            Some(TransformPassKind::NestingUnwrap) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    unwrap_css_nesting(&output_css, dialect),
                    "unwrapped nested ordinary rules and conditional group rules"
                )
            }
            Some(TransformPassKind::ScopeFlatten) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    flatten_css_scopes(&output_css, dialect),
                    "flattened only @scope candidates accepted by the cascade scope-flatten proof"
                )
            }
            Some(TransformPassKind::LayerFlatten) if context.closed_style_world => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    flatten_css_layers(&output_css, dialect, true),
                    "flattened only @layer candidates accepted by the closed-bundle cascade proof"
                )
            }
            Some(TransformPassKind::LayerFlatten) => {
                planned_only_pass!(
                    pass_id,
                    input_byte_len,
                    "requires an explicit closed-style-world bundle witness before mutation"
                )
            }
            Some(TransformPassKind::SupportsStaticEval) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    evaluate_static_supports_rules(&output_css, dialect),
                    "evaluated simple @supports branches with cascade supports-static witness"
                )
            }
            Some(TransformPassKind::MediaStaticEval) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    evaluate_static_media_rules(&output_css, dialect),
                    "evaluated literal @media all/not all branches and normalized simple min/max media ranges"
                )
            }
            Some(TransformPassKind::DeadMediaBranchRemoval) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    evaluate_dead_media_branch_rules(&output_css, dialect, context),
                    "removed dead @media branches through the static cascade witness evaluator"
                )
            }
            Some(TransformPassKind::DeadSupportsBranchRemoval) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    evaluate_static_supports_rules(&output_css, dialect),
                    "removed dead @supports branches through the static cascade witness evaluator"
                )
            }
            Some(TransformPassKind::ScssModuleEvaluate)
                if matches!(dialect, StyleDialect::Scss | StyleDialect::Sass) =>
            {
                if let Some(evaluation) = context.scss_module_evaluation.as_ref() {
                    let mutation_count = usize::from(output_css != evaluation.evaluated_css);
                    let next_css = evaluation.evaluated_css.clone();
                    let outcome = mutation_outcome(
                        pass_id,
                        input_byte_len,
                        next_css.len(),
                        mutation_count,
                        "applied explicit SCSS module evaluation output from the evaluator boundary",
                    );
                    output_css = next_css;
                    css_module_evaluation = Some(evaluation.clone());
                    outcome
                } else {
                    planned_only_pass!(
                        pass_id,
                        input_byte_len,
                        "requires explicit SCSS evaluator output before mutation"
                    )
                }
            }
            Some(TransformPassKind::ScssModuleEvaluate) => {
                planned_only_pass!(
                    pass_id,
                    input_byte_len,
                    "requires explicit SCSS evaluator output before mutation"
                )
            }
            Some(TransformPassKind::LessModuleEvaluate) if dialect == StyleDialect::Less => {
                if let Some(evaluation) = context.less_module_evaluation.as_ref() {
                    let mutation_count = usize::from(output_css != evaluation.evaluated_css);
                    let next_css = evaluation.evaluated_css.clone();
                    let outcome = mutation_outcome(
                        pass_id,
                        input_byte_len,
                        next_css.len(),
                        mutation_count,
                        "applied explicit Less module evaluation output from the evaluator boundary",
                    );
                    output_css = next_css;
                    css_module_evaluation = Some(evaluation.clone());
                    outcome
                } else {
                    planned_only_pass!(
                        pass_id,
                        input_byte_len,
                        "requires explicit Less evaluator output before mutation"
                    )
                }
            }
            Some(TransformPassKind::LessModuleEvaluate) => {
                planned_only_pass!(
                    pass_id,
                    input_byte_len,
                    "requires explicit Less evaluator output before mutation"
                )
            }
            Some(TransformPassKind::ImportInline)
                if dialect == StyleDialect::Less || !context.import_inlines.is_empty() =>
            {
                let (next_css, mutation_count) =
                    inline_css_imports(&output_css, dialect, &context.import_inlines);
                let outcome = mutation_outcome(
                    pass_id,
                    input_byte_len,
                    next_css.len(),
                    mutation_count,
                    "replaced resolved @import directives and optional Less imports",
                );
                output_css = next_css;
                css_import_inlines = context.import_inlines.clone();
                outcome
            }
            Some(TransformPassKind::ImportInline) => {
                planned_only_pass!(
                    pass_id,
                    input_byte_len,
                    "requires explicit resolved import replacements before mutation"
                )
            }
            Some(TransformPassKind::ResolveCssModulesComposes) => {
                let resolutions = css_module_composes_resolutions_for_source(
                    &output_css,
                    dialect,
                    &context.css_module_composes_resolutions,
                );
                if resolutions.is_empty() {
                    planned_only_pass!(
                        pass_id,
                        input_byte_len,
                        "requires CSS Modules composes declarations or an explicit export set before mutation"
                    )
                } else {
                    let (next_css, mutation_count) =
                        resolve_css_module_composes(&output_css, dialect, &resolutions);
                    let outcome = mutation_outcome(
                        pass_id,
                        input_byte_len,
                        next_css.len(),
                        mutation_count,
                        "removed resolved CSS Modules composes declarations using an explicit export set",
                    );
                    output_css = next_css;
                    css_module_composes_exports = resolutions;
                    outcome
                }
            }
            Some(TransformPassKind::DesignTokenRouting)
                if !context.design_token_routes.is_empty() =>
            {
                let (next_css, mutation_count) =
                    route_design_token_values(&output_css, dialect, &context.design_token_routes);
                let outcome = mutation_outcome(
                    pass_id,
                    input_byte_len,
                    next_css.len(),
                    mutation_count,
                    "routed whole-value design-token references through explicit bridge token routes",
                );
                output_css = next_css;
                design_token_routes = context.design_token_routes.clone();
                outcome
            }
            Some(TransformPassKind::DesignTokenRouting) => {
                planned_only_pass!(
                    pass_id,
                    input_byte_len,
                    "requires explicit bridge design-token routes before mutation"
                )
            }
            Some(TransformPassKind::HashCssModuleClassNames)
                if !context.class_name_rewrites.is_empty() =>
            {
                let (next_css, mutation_count) = rewrite_css_module_class_names(
                    &output_css,
                    dialect,
                    &context.class_name_rewrites,
                );
                let outcome = mutation_outcome(
                    pass_id,
                    input_byte_len,
                    next_css.len(),
                    mutation_count,
                    "rewrote CSS Modules class selectors through an explicit selector identity map",
                );
                output_css = next_css;
                outcome
            }
            Some(TransformPassKind::HashCssModuleClassNames) => {
                planned_only_pass!(
                    pass_id,
                    input_byte_len,
                    "requires an explicit selector identity map before mutation"
                )
            }
            Some(TransformPassKind::TreeShakeClass) if context.closed_style_world => {
                let (next_css, removals) = tree_shake_css_class_rules_with_removals(
                    &output_css,
                    dialect,
                    &reachable_class_names,
                );
                let mutation_count = removals.len();
                let outcome = mutation_outcome(
                    pass_id,
                    input_byte_len,
                    next_css.len(),
                    mutation_count,
                    "removed unreachable class-owned selector rules under an explicit closed-style-world reachability context",
                );
                output_css = next_css;
                semantic_removals.extend(
                    removals
                        .into_iter()
                        .map(|removal| removal.into_public(pass_id)),
                );
                outcome
            }
            Some(TransformPassKind::TreeShakeClass) => {
                planned_only_pass!(
                    pass_id,
                    input_byte_len,
                    "requires an explicit closed-style-world reachability context before mutation"
                )
            }
            Some(TransformPassKind::TreeShakeKeyframes) if context.closed_style_world => {
                let (next_css, removals) = tree_shake_css_keyframes_with_removals(
                    &output_css,
                    dialect,
                    &context.reachable_keyframe_names,
                    &reachable_class_names,
                );
                let mutation_count = removals.len();
                let outcome = mutation_outcome(
                    pass_id,
                    input_byte_len,
                    next_css.len(),
                    mutation_count,
                    "removed unreferenced @keyframes under an explicit closed-style-world reachability context",
                );
                output_css = next_css;
                semantic_removals.extend(
                    removals
                        .into_iter()
                        .map(|removal| removal.into_public(pass_id)),
                );
                outcome
            }
            Some(TransformPassKind::TreeShakeKeyframes) => {
                planned_only_pass!(
                    pass_id,
                    input_byte_len,
                    "requires an explicit closed-style-world reachability context before mutation"
                )
            }
            Some(TransformPassKind::TreeShakeValue) if context.closed_style_world => {
                let (next_css, removals) = tree_shake_css_modules_values_with_removals(
                    &output_css,
                    dialect,
                    &context.reachable_value_names,
                    &context.reachable_keyframe_names,
                    &reachable_class_names,
                );
                let mutation_count = removals.len();
                let outcome = mutation_outcome(
                    pass_id,
                    input_byte_len,
                    next_css.len(),
                    mutation_count,
                    "removed unreachable local CSS Modules @value declarations under an explicit closed-style-world reachability context",
                );
                output_css = next_css;
                semantic_removals.extend(
                    removals
                        .into_iter()
                        .map(|removal| removal.into_public(pass_id)),
                );
                outcome
            }
            Some(TransformPassKind::TreeShakeValue) => {
                planned_only_pass!(
                    pass_id,
                    input_byte_len,
                    "requires an explicit closed-style-world reachability context before mutation"
                )
            }
            Some(TransformPassKind::TreeShakeCustomProperty) if context.closed_style_world => {
                let (next_css, removals) = tree_shake_css_custom_properties_with_removals(
                    &output_css,
                    dialect,
                    &context.reachable_custom_property_names,
                    &context.reachable_keyframe_names,
                    &reachable_class_names,
                );
                let mutation_count = removals.len();
                let outcome = mutation_outcome(
                    pass_id,
                    input_byte_len,
                    next_css.len(),
                    mutation_count,
                    "removed unreachable custom-property declarations under an explicit closed-style-world reachability context",
                );
                output_css = next_css;
                semantic_removals.extend(
                    removals
                        .into_iter()
                        .map(|removal| removal.into_public(pass_id)),
                );
                outcome
            }
            Some(TransformPassKind::TreeShakeCustomProperty) => {
                planned_only_pass!(
                    pass_id,
                    input_byte_len,
                    "requires an explicit closed-style-world reachability context before mutation"
                )
            }
            Some(TransformPassKind::ValueResolution) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    resolve_static_css_modules_values(
                        &output_css,
                        dialect,
                        &context.css_module_value_resolutions,
                    ),
                    "resolved whole-value references from unique local literal CSS Modules @value declarations"
                )
            }
            Some(TransformPassKind::StaticVarSubstitution) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    substitute_static_css_custom_properties(&output_css, dialect),
                    "resolved whole-value var() references from unique static :root custom properties"
                )
            }
            Some(TransformPassKind::CalcReduction) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    reduce_css_calc(&output_css, dialect),
                    "reduced whole-value CSS math functions with static same-unit arithmetic and identity operations"
                )
            }
            Some(TransformPassKind::EmptyRuleRemoval) => {
                apply_mutation_pass!(
                    pass_id,
                    input_byte_len,
                    remove_empty_css_rules(&output_css, dialect),
                    "removed ordinary empty rules with no comments or at-rule semantics"
                )
            }
            Some(TransformPassKind::PrintCss) => no_change_outcome(
                pass_id,
                input_byte_len,
                output_css.len(),
                "observed final emission boundary",
            ),
            None => {
                planned_only_pass!(pass_id, input_byte_len, "unknown pass id in execution plan")
            }
        };
        outcome_mutation_spans.push(derive_transform_mutation_spans(
            &pass_input_css,
            &output_css,
        ));
        outcomes.push(outcome);
    }

    let executed_pass_ids = outcomes
        .iter()
        .filter(|outcome| outcome.status != TransformPassRuntimeStatus::PlannedOnly)
        .map(|outcome| outcome.pass_id)
        .collect::<Vec<_>>();
    let planned_only_pass_ids = outcomes
        .iter()
        .filter(|outcome| outcome.status == TransformPassRuntimeStatus::PlannedOnly)
        .map(|outcome| outcome.pass_id)
        .collect::<Vec<_>>();
    let mutation_count = outcomes
        .iter()
        .map(|outcome| outcome.mutation_count)
        .sum::<usize>();
    let provenance_preserved = outcomes.iter().all(|outcome| outcome.provenance_preserved);
    let provenance_derivation_forest =
        provenance_derivation_forest_from_outcomes(&outcomes, &outcome_mutation_spans);
    let cascade_proof_obligations = summarize_cascade_proof_obligations(cascade_proof_obligations);
    let output_byte_len = output_css.len();

    TransformExecutionSummaryV0 {
        schema_version: "0",
        product: "omena-transform-passes.execution",
        input_byte_len: source.len(),
        output_byte_len,
        requested_pass_ids,
        ordered_pass_ids,
        executed_pass_ids,
        planned_only_pass_ids,
        mutation_count,
        provenance_preserved,
        output_css,
        css_module_evaluation,
        css_import_inlines,
        css_module_composes_exports,
        design_token_routes,
        semantic_removals,
        cascade_proof_obligations,
        provenance_derivation_forest,
        outcomes,
        pass_plan,
    }
}