Skip to content

rule_order: canonicalise layer declarations to one normal form - #1275

Merged
samoht merged 4 commits into
mainfrom
layer-canonical
Sep 19, 2026
Merged

samoht merged 4 commits into
mainfrom
layer-canonical

Conversation

@samoht

@samoht samoht commented Sep 19, 2026 •

Copy link
Copy Markdown
Owner

The canonical projection was not confluent for layer declarations: Tailwind's preflight, whose layers are declared in one @layer a, b; statement, read apart from tw's block-by-block sheet though the two render the same. It now writes one @layer <names>; statement per conditional-free run, each a.b path expanded to a then a.b, and puts the run's style-only blocks in rank order. Nothing is hoisted across a conditional group that declares a layer. A fuzz suite pins convergence and idempotence, and a Css_compare case pins the preflight shape.

Two sheets that establish the same layer order in the same places project to
two different canonical strings, because the optimizer folds an empty layer
block into a trailing declaration while the pin logic splits a leading
multi-name statement. The canonical projection then reports the two
render-equal sheets as a difference; Tailwind's preflight, whose layers are
declared in one statement, reads apart from tw's block-by-block sheet.

The projection is a canonical form, so it must be confluent: one output per
class of sheets that render alike. Read each block as runs separated by a
barrier, a statement that is not a layer itself but declares a layer below it,
such as an @media holding an @layer or an @import with a layer, whose
contribution depends on its condition. Within a run, write every layer name the
run introduces, each a.b path expanded to a and a.b, once as one
`@layer <names>;` statement at the run's first name-bearing construct, drop the
run's other declarations and empty blocks, and put its style-only blocks in
rank order. The order is unchanged and nothing crosses a barrier.

The fuzz suite pins the two properties: respellings of one order converge, and
projecting the projection changes nothing.
@samoht samoht changed the title layer canonical rule_order: canonicalise layer declarations to one normal form Sep 19, 2026
@samoht
samoht merged commit 3f68775 into main Sep 19, 2026
6 checks passed
@samoht
samoht deleted the layer-canonical branch September 19, 2026 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant