Skip to content

fix(awk): visit for-in keys in gawk's storage order - #2588

Merged
chaliy merged 1 commit into
mainfrom
claude/project-thread-1mku65
Oct 7, 2026
Merged

chaliy merged 1 commit into
mainfrom
claude/project-thread-1mku65

Conversation

@chaliy

@chaliy chaliy commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Requested by Михайло · project thread

What changed

for (k in a) without PROCINFO["sorted_in"] (and with @unsorted) now visits keys in the order gawk 5.2 does. The new awk/order.rs models gawk's three array kinds and picks one from the first key stored, the way gawk does:

  • Integer arrays. When the first key is a non-negative integer, integers are listed in ascending order. Other keys come first, and so do sparse integers past gawk's waste threshold.
  • Negative-integer arrays. These use gawk's two-per-bucket integer hash.
  • String arrays. These use the sdbm hash with gawk's prime table sizes and growth rule. New entries go to the head of their bucket, and listing walks the buckets in order.

Why

Before this change, unsorted loops printed numeric keys ascending and then the other keys sorted by bytes. Scripts that print for (k in a) output, and the expected outputs written for them, follow Debian awk's order. This was the last gawk case the Debian-oracle bench failed after #2583.

Before / After

$ awk 'BEGIN { a["engineering"]; a["marketing"]; a["sales"]; a["support"]; for (k in a) print k }'
before: engineering marketing sales support
after:  marketing support sales engineering      (same as gawk 5.2.1)

Debian-oracle awk set (260 cases): 93.8% → 94.2% lenient. Every gawk case now passes; the 15 left all call mawk by name and expect its dialect (L-AWK-004).

Risk

  • Low. Only the visiting order of unsorted loops changes, and every key is still visited exactly once (tested up to 5000 keys).
  • After delete, gawk's order also depends on keys that were removed, and this change does not model that. L-AWK-001 is narrowed to that case.

Checklist

  • Tests added or updated (order::tests: hash order against a gawk golden, integer ordering, mixed keys, integer-key classification, coverage of every key)
  • Backward compatibility considered (only the unsorted order changes; knowledge and L-AWK-001 updated)

https://claude.ai/code/session_01VscpEzxtqpCKx5eRMpywNj


Generated by Claude Code

Unsorted for (k in a) now models gawk's cint/int/str arrays, so loops
print like Debian awk. All gawk cases in the Debian-oracle awk set pass.

Claude-Session: https://claude.ai/code/session_01VscpEzxtqpCKx5eRMpywNj
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Preview URL Updated (UTC)
✅ Deployment successful!
View logs
bashkit 233cc05 Commit Preview URL

Branch Preview URL
Oct 07 2026, 07:21 PM

@chaliy
chaliy merged commit 6b5b650 into main Oct 7, 2026
44 checks passed
@chaliy
chaliy deleted the claude/project-thread-1mku65 branch October 7, 2026 19:58
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