From 24d983908b5a70d69febc54033ffa0de137233a2 Mon Sep 17 00:00:00 2001 From: lab Date: Sun, 6 Sep 2026 14:17:14 +0700 Subject: [PATCH 1/2] fix(rust): map a Zig standard-library map to std::collections::HashMap (+5) (Refs #3373) --- .trinity/seals/TriGraph.json | 2 +- .trinity/seals/TriHtml.json | 2 +- .trinity/seals/TriLru.json | 2 +- .trinity/seals/TriMsgpack.json | 2 +- .trinity/seals/TriSet.json | 2 +- .trinity/seals/TriTrie.json | 2 +- .trinity/seals/TriXml.json | 2 +- .trinity/seals/api_sdk_contract.json | 4 +- .trinity/seals/ast.json | 2 +- .trinity/seals/collections_TriLru.json | 4 +- .trinity/seals/collections_TriSet.json | 4 +- .trinity/seals/compiler_ast.json | 4 +- .trinity/seals/encoding_TriHtml.json | 4 +- .trinity/seals/encoding_TriMsgpack.json | 4 +- .trinity/seals/encoding_TriXml.json | 4 +- .trinity/seals/graph_TriGraph.json | 4 +- .trinity/seals/sdk_contract.json | 2 +- .trinity/seals/trees_TriTrie.json | 4 +- .trinity/seals/zig_codegen.json | 2 +- .trinity/seals/zig_zig_codegen.json | 4 +- bootstrap/src/compiler.rs | 88 ++++++++++++++++--- bootstrap/stage0/FROZEN_HASH | 2 +- ...-09-06-a-zig-map-reaches-rustc-verbatim.md | 16 ++++ 23 files changed, 121 insertions(+), 45 deletions(-) create mode 100644 docs/now/2026-09-06-a-zig-map-reaches-rustc-verbatim.md diff --git a/.trinity/seals/TriGraph.json b/.trinity/seals/TriGraph.json index 9e9de7ff39..72c0e7223b 100644 --- a/.trinity/seals/TriGraph.json +++ b/.trinity/seals/TriGraph.json @@ -1,6 +1,6 @@ { "gen_hash_c": "sha256:e211780c0b7bbd8a861e059d0708e5bea52674ead30efcaa1eebcfdd16cf51dc", - "gen_hash_rust": "sha256:97397057eab14046c0a4327554771e1b2096e05c6ec590d54fef76268cf9f0b3", + "gen_hash_rust": "sha256:a21c1de6323c0a5301195c9b479469b20273ec5e8ffe093ea8863676aacbce1f", "gen_hash_verilog": "sha256:c0bd9cddefce72cfb629855f772f6a0d31cf7b538c6132d8a16859dc17becdf7", "gen_hash_zig": "sha256:444d15ecc025e0b172fc8594054a13177a0e5496a32390d4261857b5ef804f90", "module": "TriGraph", diff --git a/.trinity/seals/TriHtml.json b/.trinity/seals/TriHtml.json index dafd370667..957bee959e 100644 --- a/.trinity/seals/TriHtml.json +++ b/.trinity/seals/TriHtml.json @@ -1,6 +1,6 @@ { "gen_hash_c": "sha256:1f8b30b7f71c2bcdcdf216fe8dacbf6f68f3e22f9d8f075c289f3c3beb856c45", - "gen_hash_rust": "sha256:223e31bf32dcb00bfec3685414e5859a63256c1903d2abf8c47d79c3855d6d59", + "gen_hash_rust": "sha256:5120100890657113985b5476a8fc395a72b81a1277b7a1ae9b0ff6bf0f68adb1", "gen_hash_verilog": "sha256:1fa7df852949de5a53c7814c90ff93ae0c4849656379383f877f562d98f06fc2", "gen_hash_zig": "sha256:c7ed13bb6e091bcedf263a647fa5a434899da8246b96e6427fa04d4797268e7f", "module": "TriHtml", diff --git a/.trinity/seals/TriLru.json b/.trinity/seals/TriLru.json index ad49f33718..fef6452954 100644 --- a/.trinity/seals/TriLru.json +++ b/.trinity/seals/TriLru.json @@ -1,6 +1,6 @@ { "gen_hash_c": "sha256:947ed3a8df75a4a9ee4c54311c70b9edda1739216d72be28f3cfdaf80958303d", - "gen_hash_rust": "sha256:c07ab86a7de321ce47095f951e5bc07bc5d3b3f22fa03822694a65c47a08fc0d", + "gen_hash_rust": "sha256:9102ac246ade61f92cd79840980dab11b75512a086a587d32d2fb2081204f174", "gen_hash_verilog": "sha256:ebf3050832135b9ec9b6e2480889eabd422468317d7d06e3efa054d06df833cc", "gen_hash_zig": "sha256:db41d91af86d45b14de051a11a9259b1534b93caa7e01d2c3c4ca2abe0607f5d", "module": "TriLru", diff --git a/.trinity/seals/TriMsgpack.json b/.trinity/seals/TriMsgpack.json index dc4f86ed72..ebf2b76eb9 100644 --- a/.trinity/seals/TriMsgpack.json +++ b/.trinity/seals/TriMsgpack.json @@ -1,6 +1,6 @@ { "gen_hash_c": "sha256:2069e8885ebe9049617e38a4e2d0f2a50f59570bb50cd29ee0981e3b17a96027", - "gen_hash_rust": "sha256:300a3d600a5b55835279ca4a4d58056198e8df63d5556596d64d6dad6dd7b235", + "gen_hash_rust": "sha256:2fc88453916cd34b97a77f7d030cb60286932edd3ee44893dd3ef29e8a482200", "gen_hash_verilog": "sha256:f70c08c4cd1f900cc223d58ee2e550d3b02ad321144a659f3dcc4cb1452be32b", "gen_hash_zig": "sha256:04a9c694d50297efa8ed0f1d74eaa7f47b8fe92557e52454ed75a7c885c896c1", "module": "TriMsgpack", diff --git a/.trinity/seals/TriSet.json b/.trinity/seals/TriSet.json index 2f9d3fd55a..1e213693b6 100644 --- a/.trinity/seals/TriSet.json +++ b/.trinity/seals/TriSet.json @@ -1,6 +1,6 @@ { "gen_hash_c": "sha256:9613b7c8f320bac36af110397bf7b0d1e290b0c2f86783209c1b4f40962784c4", - "gen_hash_rust": "sha256:ab38e31fb8d7d8ec8b37ded2cd1ce6718a64f1efa7b51a709ebfe3be9b6a22da", + "gen_hash_rust": "sha256:48a66ec67d9eae55810826dd2a5fb14c48a0bb091cd0164d293a7aa8d8da470f", "gen_hash_verilog": "sha256:a3f2edcb48986f07d75d8b5ec7e39b7308b6823f508a8bbcf4d84f1cb9d7e6a5", "gen_hash_zig": "sha256:3c40e78d01506a92d08946933a7d75abb7a8aabc3bec4df03d9389c19f5a974d", "module": "TriSet", diff --git a/.trinity/seals/TriTrie.json b/.trinity/seals/TriTrie.json index de4b0d2b4d..8fd342655b 100644 --- a/.trinity/seals/TriTrie.json +++ b/.trinity/seals/TriTrie.json @@ -1,6 +1,6 @@ { "gen_hash_c": "sha256:dbaea551a83dbeb3302415612fe55402f9f9c24bad77a0abc7903fa5149669ec", - "gen_hash_rust": "sha256:57c99ffb2c2dae8b836b14976be847691c2bdc36a4317c045a5e7e0c69e83878", + "gen_hash_rust": "sha256:7ce3d8fbeab2e3ebd0653ef061b0444712702bb96063dcad96a8f15d1cc94e26", "gen_hash_verilog": "sha256:92be6269928168a86cd2289199bb784ce3383d193966de87fce0e460437de5e9", "gen_hash_zig": "sha256:e87caaa2882c44de5510f6e1cbe09afd29ba4443ddc9a7b57a3a6645b3372c43", "module": "TriTrie", diff --git a/.trinity/seals/TriXml.json b/.trinity/seals/TriXml.json index e7bc09819f..70dcf046b6 100644 --- a/.trinity/seals/TriXml.json +++ b/.trinity/seals/TriXml.json @@ -1,6 +1,6 @@ { "gen_hash_c": "sha256:c13021e282c10254a2f161577c55e506fb096dff8740997d2ff8dbb6a2bf7683", - "gen_hash_rust": "sha256:8472efbec7b2f13cd2c5733556cd19a5e5c717a28d81a094cc754bda1341a291", + "gen_hash_rust": "sha256:45236f8613780705b2580a7223c49fee5b621b40ac51d878b60ec3dcd6074547", "gen_hash_verilog": "sha256:ef20a47e3fc1296bda60734bbe0b8255375a7c35752327385c1b586c354f863b", "gen_hash_zig": "sha256:d82f497edfa15ea7da4c2c48aa7abab230377ead54e73c6145ca40a660290c76", "module": "TriXml", diff --git a/.trinity/seals/api_sdk_contract.json b/.trinity/seals/api_sdk_contract.json index aafa25dd72..41043f7e9f 100644 --- a/.trinity/seals/api_sdk_contract.json +++ b/.trinity/seals/api_sdk_contract.json @@ -1,11 +1,11 @@ { "gen_hash_c": "sha256:2a18047c89fb2af3255fe5066f1c35cbba5410cca19598a0fc6c1b0e35ef13a0", - "gen_hash_rust": "sha256:28b5de014c24859a2f74e0893707a535295ec8719815f4968bb49098376943e9", + "gen_hash_rust": "sha256:8980aeccf629d1dd914cbbd02c717ff0ab08e53b7a72d4c88623c92c04f7c0a9", "gen_hash_verilog": "sha256:9bc46f2772e60e074704356e9bb38868a7f263f3cfe251e30a106b82ed41edc3", "gen_hash_zig": "sha256:e05074e18d030ac66115f4bd3d65efa2e6a2f76bcd7b27499577d8d47934eb69", "module": "sdk_contract", "ring": 12, - "sealed_at": "2026-09-06T04:36:42Z", + "sealed_at": "2026-09-06T07:17:01Z", "sealed_by": "t27c-bootstrap@0.2.0", "spec_hash": "sha256:67b126ee510d34e78677d12e64b2b2aacf9951410adc6f3338018101e0e112c0", "spec_path": "specs/api/sdk_contract.t27" diff --git a/.trinity/seals/ast.json b/.trinity/seals/ast.json index fa95d09f20..71140a4d7b 100644 --- a/.trinity/seals/ast.json +++ b/.trinity/seals/ast.json @@ -1,6 +1,6 @@ { "gen_hash_c": "sha256:fbc813ecf388fc2f9e49d10409608df2cc50cf36339be1b0caf580759b70bc54", - "gen_hash_rust": "sha256:cf796b2c39fc159ff964232c2feb3e679f46d71c67f88e4085a41496e131d824", + "gen_hash_rust": "sha256:e1895409c636130f9fec6a7b48f812cf1cd8c29bfc99c454f8b7085d53c9058a", "gen_hash_verilog": "sha256:13ea818e724f76ac3ef3b457c21d71c31b7b264c3d6c2eee30dc61229eb1eb41", "gen_hash_zig": "sha256:bdd1ec462b75bcb51ac79de0aefbf275aa1e9d13c755d5049dc418561c642d49", "module": "ast", diff --git a/.trinity/seals/collections_TriLru.json b/.trinity/seals/collections_TriLru.json index 4be4266e50..02f362a268 100644 --- a/.trinity/seals/collections_TriLru.json +++ b/.trinity/seals/collections_TriLru.json @@ -1,11 +1,11 @@ { "gen_hash_c": "sha256:947ed3a8df75a4a9ee4c54311c70b9edda1739216d72be28f3cfdaf80958303d", - "gen_hash_rust": "sha256:c07ab86a7de321ce47095f951e5bc07bc5d3b3f22fa03822694a65c47a08fc0d", + "gen_hash_rust": "sha256:9102ac246ade61f92cd79840980dab11b75512a086a587d32d2fb2081204f174", "gen_hash_verilog": "sha256:ebf3050832135b9ec9b6e2480889eabd422468317d7d06e3efa054d06df833cc", "gen_hash_zig": "sha256:db41d91af86d45b14de051a11a9259b1534b93caa7e01d2c3c4ca2abe0607f5d", "module": "TriLru", "ring": 12, - "sealed_at": "2026-09-05T02:40:53Z", + "sealed_at": "2026-09-06T07:17:01Z", "sealed_by": "t27c-bootstrap@0.2.0", "spec_hash": "sha256:d42e1ac02e6c07db9accf712b9f83035a8257e7c5c15d691a2da4bdcccc3faf6", "spec_path": "specs/tri/collections/lru.t27" diff --git a/.trinity/seals/collections_TriSet.json b/.trinity/seals/collections_TriSet.json index 03db8f7e78..2e222fcf46 100644 --- a/.trinity/seals/collections_TriSet.json +++ b/.trinity/seals/collections_TriSet.json @@ -1,11 +1,11 @@ { "gen_hash_c": "sha256:9613b7c8f320bac36af110397bf7b0d1e290b0c2f86783209c1b4f40962784c4", - "gen_hash_rust": "sha256:ab38e31fb8d7d8ec8b37ded2cd1ce6718a64f1efa7b51a709ebfe3be9b6a22da", + "gen_hash_rust": "sha256:48a66ec67d9eae55810826dd2a5fb14c48a0bb091cd0164d293a7aa8d8da470f", "gen_hash_verilog": "sha256:a3f2edcb48986f07d75d8b5ec7e39b7308b6823f508a8bbcf4d84f1cb9d7e6a5", "gen_hash_zig": "sha256:3c40e78d01506a92d08946933a7d75abb7a8aabc3bec4df03d9389c19f5a974d", "module": "TriSet", "ring": 12, - "sealed_at": "2026-09-06T02:45:08Z", + "sealed_at": "2026-09-06T07:17:01Z", "sealed_by": "t27c-bootstrap@0.2.0", "spec_hash": "sha256:b4efcdd7ff229ef26b03587176dbb0f75351666de1e6c689597be0322349e3dd", "spec_path": "specs/tri/collections/set.t27" diff --git a/.trinity/seals/compiler_ast.json b/.trinity/seals/compiler_ast.json index 80bbc2051e..f22ba08905 100644 --- a/.trinity/seals/compiler_ast.json +++ b/.trinity/seals/compiler_ast.json @@ -1,11 +1,11 @@ { "gen_hash_c": "sha256:fbc813ecf388fc2f9e49d10409608df2cc50cf36339be1b0caf580759b70bc54", - "gen_hash_rust": "sha256:cf796b2c39fc159ff964232c2feb3e679f46d71c67f88e4085a41496e131d824", + "gen_hash_rust": "sha256:e1895409c636130f9fec6a7b48f812cf1cd8c29bfc99c454f8b7085d53c9058a", "gen_hash_verilog": "sha256:13ea818e724f76ac3ef3b457c21d71c31b7b264c3d6c2eee30dc61229eb1eb41", "gen_hash_zig": "sha256:bdd1ec462b75bcb51ac79de0aefbf275aa1e9d13c755d5049dc418561c642d49", "module": "ast", "ring": 12, - "sealed_at": "2026-09-06T04:36:41Z", + "sealed_at": "2026-09-06T07:17:01Z", "sealed_by": "t27c-bootstrap@0.2.0", "spec_hash": "sha256:28bfcdf211a0360991fe8d89dc376440d2144b936e030f81e0b5794a1c0eeb00", "spec_path": "compiler/ast.t27" diff --git a/.trinity/seals/encoding_TriHtml.json b/.trinity/seals/encoding_TriHtml.json index 8ea815a1b8..fe22f93aac 100644 --- a/.trinity/seals/encoding_TriHtml.json +++ b/.trinity/seals/encoding_TriHtml.json @@ -1,11 +1,11 @@ { "gen_hash_c": "sha256:1f8b30b7f71c2bcdcdf216fe8dacbf6f68f3e22f9d8f075c289f3c3beb856c45", - "gen_hash_rust": "sha256:223e31bf32dcb00bfec3685414e5859a63256c1903d2abf8c47d79c3855d6d59", + "gen_hash_rust": "sha256:5120100890657113985b5476a8fc395a72b81a1277b7a1ae9b0ff6bf0f68adb1", "gen_hash_verilog": "sha256:1fa7df852949de5a53c7814c90ff93ae0c4849656379383f877f562d98f06fc2", "gen_hash_zig": "sha256:c7ed13bb6e091bcedf263a647fa5a434899da8246b96e6427fa04d4797268e7f", "module": "TriHtml", "ring": 12, - "sealed_at": "2026-09-06T05:46:33Z", + "sealed_at": "2026-09-06T07:17:01Z", "sealed_by": "t27c-bootstrap@0.2.0", "spec_hash": "sha256:025959391860663c194a10874f66af7dd8da26f8597f5bee89be66a283a66f60", "spec_path": "specs/tri/encoding/html.t27" diff --git a/.trinity/seals/encoding_TriMsgpack.json b/.trinity/seals/encoding_TriMsgpack.json index a56a47a5ac..0e1d8169ca 100644 --- a/.trinity/seals/encoding_TriMsgpack.json +++ b/.trinity/seals/encoding_TriMsgpack.json @@ -1,11 +1,11 @@ { "gen_hash_c": "sha256:2069e8885ebe9049617e38a4e2d0f2a50f59570bb50cd29ee0981e3b17a96027", - "gen_hash_rust": "sha256:300a3d600a5b55835279ca4a4d58056198e8df63d5556596d64d6dad6dd7b235", + "gen_hash_rust": "sha256:2fc88453916cd34b97a77f7d030cb60286932edd3ee44893dd3ef29e8a482200", "gen_hash_verilog": "sha256:f70c08c4cd1f900cc223d58ee2e550d3b02ad321144a659f3dcc4cb1452be32b", "gen_hash_zig": "sha256:04a9c694d50297efa8ed0f1d74eaa7f47b8fe92557e52454ed75a7c885c896c1", "module": "TriMsgpack", "ring": 12, - "sealed_at": "2026-09-05T09:02:10Z", + "sealed_at": "2026-09-06T07:17:01Z", "sealed_by": "t27c-bootstrap@0.2.0", "spec_hash": "sha256:eb6c433fe01f1e6b9fd3a83a79c6575f3e1431b8cccfd78ac6d8db6d0e699eea", "spec_path": "specs/tri/encoding/msgpack.t27" diff --git a/.trinity/seals/encoding_TriXml.json b/.trinity/seals/encoding_TriXml.json index 40e685bf4f..f8173c0d53 100644 --- a/.trinity/seals/encoding_TriXml.json +++ b/.trinity/seals/encoding_TriXml.json @@ -1,11 +1,11 @@ { "gen_hash_c": "sha256:c13021e282c10254a2f161577c55e506fb096dff8740997d2ff8dbb6a2bf7683", - "gen_hash_rust": "sha256:8472efbec7b2f13cd2c5733556cd19a5e5c717a28d81a094cc754bda1341a291", + "gen_hash_rust": "sha256:45236f8613780705b2580a7223c49fee5b621b40ac51d878b60ec3dcd6074547", "gen_hash_verilog": "sha256:ef20a47e3fc1296bda60734bbe0b8255375a7c35752327385c1b586c354f863b", "gen_hash_zig": "sha256:d82f497edfa15ea7da4c2c48aa7abab230377ead54e73c6145ca40a660290c76", "module": "TriXml", "ring": 12, - "sealed_at": "2026-09-06T05:46:33Z", + "sealed_at": "2026-09-06T07:17:01Z", "sealed_by": "t27c-bootstrap@0.2.0", "spec_hash": "sha256:2cd1d3d51078f14f5dd0f53741536884c599975ebb005381d679a5c2542b1000", "spec_path": "specs/tri/encoding/xml.t27" diff --git a/.trinity/seals/graph_TriGraph.json b/.trinity/seals/graph_TriGraph.json index d4d654c857..2780ca5e5b 100644 --- a/.trinity/seals/graph_TriGraph.json +++ b/.trinity/seals/graph_TriGraph.json @@ -1,11 +1,11 @@ { "gen_hash_c": "sha256:e211780c0b7bbd8a861e059d0708e5bea52674ead30efcaa1eebcfdd16cf51dc", - "gen_hash_rust": "sha256:97397057eab14046c0a4327554771e1b2096e05c6ec590d54fef76268cf9f0b3", + "gen_hash_rust": "sha256:a21c1de6323c0a5301195c9b479469b20273ec5e8ffe093ea8863676aacbce1f", "gen_hash_verilog": "sha256:c0bd9cddefce72cfb629855f772f6a0d31cf7b538c6132d8a16859dc17becdf7", "gen_hash_zig": "sha256:444d15ecc025e0b172fc8594054a13177a0e5496a32390d4261857b5ef804f90", "module": "TriGraph", "ring": 12, - "sealed_at": "2026-09-05T02:40:54Z", + "sealed_at": "2026-09-06T07:17:01Z", "sealed_by": "t27c-bootstrap@0.2.0", "spec_hash": "sha256:121f7a349ba5b7b672b90a9f372f575e9530ef68756c687660ed6ef029278fc5", "spec_path": "specs/tri/graph/graph.t27" diff --git a/.trinity/seals/sdk_contract.json b/.trinity/seals/sdk_contract.json index fdfd3076ed..206927de4f 100644 --- a/.trinity/seals/sdk_contract.json +++ b/.trinity/seals/sdk_contract.json @@ -1,6 +1,6 @@ { "gen_hash_c": "sha256:2a18047c89fb2af3255fe5066f1c35cbba5410cca19598a0fc6c1b0e35ef13a0", - "gen_hash_rust": "sha256:28b5de014c24859a2f74e0893707a535295ec8719815f4968bb49098376943e9", + "gen_hash_rust": "sha256:8980aeccf629d1dd914cbbd02c717ff0ab08e53b7a72d4c88623c92c04f7c0a9", "gen_hash_verilog": "sha256:9bc46f2772e60e074704356e9bb38868a7f263f3cfe251e30a106b82ed41edc3", "gen_hash_zig": "sha256:e05074e18d030ac66115f4bd3d65efa2e6a2f76bcd7b27499577d8d47934eb69", "module": "sdk_contract", diff --git a/.trinity/seals/trees_TriTrie.json b/.trinity/seals/trees_TriTrie.json index d44bf2d9c9..dd5ea0e616 100644 --- a/.trinity/seals/trees_TriTrie.json +++ b/.trinity/seals/trees_TriTrie.json @@ -1,11 +1,11 @@ { "gen_hash_c": "sha256:dbaea551a83dbeb3302415612fe55402f9f9c24bad77a0abc7903fa5149669ec", - "gen_hash_rust": "sha256:57c99ffb2c2dae8b836b14976be847691c2bdc36a4317c045a5e7e0c69e83878", + "gen_hash_rust": "sha256:7ce3d8fbeab2e3ebd0653ef061b0444712702bb96063dcad96a8f15d1cc94e26", "gen_hash_verilog": "sha256:92be6269928168a86cd2289199bb784ce3383d193966de87fce0e460437de5e9", "gen_hash_zig": "sha256:e87caaa2882c44de5510f6e1cbe09afd29ba4443ddc9a7b57a3a6645b3372c43", "module": "TriTrie", "ring": 12, - "sealed_at": "2026-09-05T02:40:54Z", + "sealed_at": "2026-09-06T07:17:01Z", "sealed_by": "t27c-bootstrap@0.2.0", "spec_hash": "sha256:b0439804871b40fdec6d6bd98dfe3f658e7a091e0f7d378d5d9b78999a5335de", "spec_path": "specs/tri/trees/trie.t27" diff --git a/.trinity/seals/zig_codegen.json b/.trinity/seals/zig_codegen.json index 412f330815..0107d1a40c 100644 --- a/.trinity/seals/zig_codegen.json +++ b/.trinity/seals/zig_codegen.json @@ -1,6 +1,6 @@ { "gen_hash_c": "sha256:be1cb9a8eb5bb8c80f63aa8db98b7ed69273a0c4e3e09a62d0fc7efec4bd11b5", - "gen_hash_rust": "sha256:e15dece9fa8a21f5f634603ef780b497e1bcba0659237d1a6497b8327d78bc1e", + "gen_hash_rust": "sha256:2d422d58b346eb22364a64839b0c48fdef43c9f1a57abd9931e324fe06efdfc2", "gen_hash_verilog": "sha256:281e5bf4b4bf860712ca54c2b0d173ba6ee0fc6f96043e8c243e9f3e1291a8f1", "gen_hash_zig": "sha256:e0de552c5b497d45d640bb9ac9664b1ba515a9d44a2bb280921ffdab5b9fd0f6", "module": "zig_codegen", diff --git a/.trinity/seals/zig_zig_codegen.json b/.trinity/seals/zig_zig_codegen.json index 947f320fab..bf6ca529bb 100644 --- a/.trinity/seals/zig_zig_codegen.json +++ b/.trinity/seals/zig_zig_codegen.json @@ -1,11 +1,11 @@ { "gen_hash_c": "sha256:be1cb9a8eb5bb8c80f63aa8db98b7ed69273a0c4e3e09a62d0fc7efec4bd11b5", - "gen_hash_rust": "sha256:e15dece9fa8a21f5f634603ef780b497e1bcba0659237d1a6497b8327d78bc1e", + "gen_hash_rust": "sha256:2d422d58b346eb22364a64839b0c48fdef43c9f1a57abd9931e324fe06efdfc2", "gen_hash_verilog": "sha256:281e5bf4b4bf860712ca54c2b0d173ba6ee0fc6f96043e8c243e9f3e1291a8f1", "gen_hash_zig": "sha256:e0de552c5b497d45d640bb9ac9664b1ba515a9d44a2bb280921ffdab5b9fd0f6", "module": "zig_codegen", "ring": 12, - "sealed_at": "2026-09-06T04:36:41Z", + "sealed_at": "2026-09-06T07:17:01Z", "sealed_by": "t27c-bootstrap@0.2.0", "spec_hash": "sha256:face91b2c4dda278c97006286cdbd18e00e2a2d01e9288eeb0d6520aa47f7fce", "spec_path": "compiler/codegen/zig/codegen.t27" diff --git a/bootstrap/src/compiler.rs b/bootstrap/src/compiler.rs index 1f3ad920c5..8f2a22f024 100644 --- a/bootstrap/src/compiler.rs +++ b/bootstrap/src/compiler.rs @@ -24612,6 +24612,29 @@ impl RustCodegen { }) } + /// Split a comma-separated type list, honouring nesting. + /// + /// A naive `split(',')` cuts `Map, T` into `Map` and ` T`, which is + /// worse than the input. Shared by the tuple arm and the map arm so the two cannot + /// disagree about what a comma means. + fn split_type_list(inner: &str) -> Vec { + let mut parts: Vec = Vec::new(); + let (mut depth, mut start) = (0i32, 0usize); + for (i, c) in inner.char_indices() { + match c { + '<' | '[' | '(' => depth += 1, + '>' | ']' | ')' => depth -= 1, + ',' if depth == 0 => { + parts.push(inner[start..i].to_string()); + start = i + c.len_utf8(); + } + _ => {} + } + } + parts.push(inner[start..].to_string()); + parts + } + /// Is this emitted Rust type `Copy`? /// /// Deliberately a CLOSED list of primitives plus `&'static str` and fixed-size arrays @@ -24651,6 +24674,56 @@ impl RustCodegen { (t, false) }; + // A Zig standard-library MAP, which eight corpus fields declare as their type: + // + // "std.StringHashMap([]const u8)" 5 fields + // "std.HashMap(K, V)" 3 fields + // + // The type is written as a QUOTED STRING in the spec; the compiler strips the + // quotes and emits the content, so rustc received `std.StringHashMap(...)`, which + // is not Rust. `StringHashMap` keys by string, so its Rust equivalent names the + // key type the Zig form leaves implicit. + // + // Anchored on the WHOLE type string. `std.math.`, `std.mem.` and the rest appear + // only in expression position and never reach this function, but an unanchored + // match would be a rule about a prefix rather than about a type. + if let Some(rest) = base_type.strip_prefix("std.StringHashMap(") { + if let Some(v) = rest.strip_suffix(')') { + // ARITY. `StringHashMap` takes exactly one argument; without this guard + // `std.StringHashMap(K, V)` emitted `HashMap` -- three type + // arguments, which is not Rust. A wrong arity now falls through to the + // default and rustc says so loudly, which is the honest outcome. + let args = Self::split_type_list(v); + if args.len() == 1 { + // The KEY type is whatever this emitter maps `[]const u8` to, not a + // hardcoded `String`. Zig's `StringHashMap` keys by `[]const u8`, and + // writing `String` here made two spellings of the same intent produce + // incompatible Rust: `std.StringHashMap(u32)` gave + // `HashMap` while `std.HashMap([]const u8, u32)` gave + // `HashMap<&'static str, u32>`. One emitter, one answer. + let key = Self::t27_type_to_rust("[]const u8"); + let out = format!( + "std::collections::HashMap<{key}, {}>", + Self::t27_type_to_rust(args[0].trim()) + ); + return if is_optional { format!("Option<{out}>") } else { out }; + } + } + } + if let Some(rest) = base_type.strip_prefix("std.HashMap(") { + if let Some(kv) = rest.strip_suffix(')') { + let parts = Self::split_type_list(kv); + if parts.len() == 2 { + let out = format!( + "std::collections::HashMap<{}, {}>", + Self::t27_type_to_rust(parts[0].trim()), + Self::t27_type_to_rust(parts[1].trim()) + ); + return if is_optional { format!("Option<{out}>") } else { out }; + } + } + } + // A TUPLE maps element by element. Without this arm `(A, B)` fell through to // the default and was emitted verbatim, so an inner `[]f32` -- which every other // position maps to `Vec` -- reached rustc as `[]f32`. The rule existed and @@ -24660,20 +24733,7 @@ impl RustCodegen { // `Map` and produce something worse than the input. if base_type.starts_with('(') && base_type.ends_with(')') && base_type.len() > 2 { let inner = &base_type[1..base_type.len() - 1]; - let mut parts: Vec = Vec::new(); - let (mut depth, mut start) = (0i32, 0usize); - for (i, c) in inner.char_indices() { - match c { - '<' | '[' | '(' => depth += 1, - '>' | ']' | ')' => depth -= 1, - ',' if depth == 0 => { - parts.push(inner[start..i].to_string()); - start = i + c.len_utf8(); - } - _ => {} - } - } - parts.push(inner[start..].to_string()); + let parts = Self::split_type_list(inner); // A one-element "tuple" is a parenthesised type, not a tuple, and Rust writes // it without the comma. Emitting `(T,)` there would change the type. let mapped: Vec = parts diff --git a/bootstrap/stage0/FROZEN_HASH b/bootstrap/stage0/FROZEN_HASH index d6364266c6..5bedc5a596 100644 --- a/bootstrap/stage0/FROZEN_HASH +++ b/bootstrap/stage0/FROZEN_HASH @@ -1 +1 @@ -23f03e8a97d5588d06cdb84d3e59baa03c5474d9a28ef361f9bc26bd9b72f6d1 bootstrap/src/compiler.rs +dd9bd7a42930b68b04304878abbea32ee9a9cd661f9bee80303ae1636caf2c7e bootstrap/src/compiler.rs diff --git a/docs/now/2026-09-06-a-zig-map-reaches-rustc-verbatim.md b/docs/now/2026-09-06-a-zig-map-reaches-rustc-verbatim.md new file mode 100644 index 0000000000..ecb21f7f70 --- /dev/null +++ b/docs/now/2026-09-06-a-zig-map-reaches-rustc-verbatim.md @@ -0,0 +1,16 @@ +# NOW -- A Zig standard-library map reaches rustc verbatim (2026-09-06) + +## A Zig map declared as a type (Refs #3373) + +- Eight corpus fields declare their type as a quoted string holding a Zig map. The compiler + strips the quotes and emits the content, so rustc received `std.StringHashMap(...)`. +- Two arms map them to `std::collections::HashMap`, with the element types mapped + recursively and a depth-aware comma split shared with the tuple arm. +- Measured: **352 to 357**, zero regressions -- exactly the five specs priced in #3370. +- An adversarial pass over this change found two defects IN IT, both fixed before shipping: + no arity guard, so `std.StringHashMap(K, V)` emitted three type arguments; and two + spellings of one intent disagreeing, `String` against `&'static str`. The key type is + now whatever this emitter maps `[]const u8` to. Re-measured: still 357. +- A third finding was checked against the previous binary and is pre-existing: + `std.HashMap(K, V) extra` becomes `*mut ()` on the old binary too. +- The price was quoted to the owner before the work and matched it exactly: five specs. From e7153c4015c33aa171773201965f2ad2fa72eefd Mon Sep 17 00:00:00 2001 From: lab Date: Sun, 6 Sep 2026 14:33:05 +0700 Subject: [PATCH 2/2] fix(rust): decline a malformed map argument list rather than emit half a type (Refs #3373) --- bootstrap/src/compiler.rs | 41 ++++++++++++++++--- bootstrap/stage0/FROZEN_HASH | 2 +- ...-09-06-a-zig-map-reaches-rustc-verbatim.md | 9 ++++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/bootstrap/src/compiler.rs b/bootstrap/src/compiler.rs index 8f2a22f024..40af386757 100644 --- a/bootstrap/src/compiler.rs +++ b/bootstrap/src/compiler.rs @@ -24617,13 +24617,22 @@ impl RustCodegen { /// A naive `split(',')` cuts `Map, T` into `Map` and ` T`, which is /// worse than the input. Shared by the tuple arm and the map arm so the two cannot /// disagree about what a comma means. - fn split_type_list(inner: &str) -> Vec { + fn split_type_list(inner: &str) -> Option> { let mut parts: Vec = Vec::new(); let (mut depth, mut start) = (0i32, 0usize); for (i, c) in inner.char_indices() { match c { '<' | '[' | '(' => depth += 1, - '>' | ']' | ')' => depth -= 1, + // `->` is a `-` then a `>`, and counting that `>` as a close drove depth + // NEGATIVE on `fn(A) -> B`, making the split silently wrong rather than + // absent. A list that does not balance is not one this function can answer + // about, and None is the honest reply. + '>' | ']' | ')' => { + depth -= 1; + if depth < 0 { + return None; + } + } ',' if depth == 0 => { parts.push(inner[start..i].to_string()); start = i + c.len_utf8(); @@ -24631,8 +24640,17 @@ impl RustCodegen { _ => {} } } + if depth != 0 { + return None; + } parts.push(inner[start..].to_string()); - parts + // An EMPTY argument is not an argument. `std.StringHashMap()` split to one empty + // string, passed a `len() == 1` guard and emitted `HashMap<&'static str, >`, + // which is not Rust: the guard counted commas where it meant to count types. + if parts.iter().any(|q| q.trim().is_empty()) { + return None; + } + Some(parts) } /// Is this emitted Rust type `Copy`? @@ -24693,7 +24711,7 @@ impl RustCodegen { // `std.StringHashMap(K, V)` emitted `HashMap` -- three type // arguments, which is not Rust. A wrong arity now falls through to the // default and rustc says so loudly, which is the honest outcome. - let args = Self::split_type_list(v); + let args = Self::split_type_list(v).unwrap_or_default(); if args.len() == 1 { // The KEY type is whatever this emitter maps `[]const u8` to, not a // hardcoded `String`. Zig's `StringHashMap` keys by `[]const u8`, and @@ -24712,7 +24730,7 @@ impl RustCodegen { } if let Some(rest) = base_type.strip_prefix("std.HashMap(") { if let Some(kv) = rest.strip_suffix(')') { - let parts = Self::split_type_list(kv); + let parts = Self::split_type_list(kv).unwrap_or_default(); if parts.len() == 2 { let out = format!( "std::collections::HashMap<{}, {}>", @@ -24733,7 +24751,18 @@ impl RustCodegen { // `Map` and produce something worse than the input. if base_type.starts_with('(') && base_type.ends_with(')') && base_type.len() > 2 { let inner = &base_type[1..base_type.len() - 1]; - let parts = Self::split_type_list(inner); + let parts = match Self::split_type_list(inner) { + Some(p) => p, + // Malformed inside a tuple: leave it exactly as written, which is what + // this position did before the arm existed. rustc then says so loudly. + None => { + return if is_optional { + format!("Option<{base_type}>") + } else { + base_type.to_string() + } + } + }; // A one-element "tuple" is a parenthesised type, not a tuple, and Rust writes // it without the comma. Emitting `(T,)` there would change the type. let mapped: Vec = parts diff --git a/bootstrap/stage0/FROZEN_HASH b/bootstrap/stage0/FROZEN_HASH index 5bedc5a596..0543a1f840 100644 --- a/bootstrap/stage0/FROZEN_HASH +++ b/bootstrap/stage0/FROZEN_HASH @@ -1 +1 @@ -dd9bd7a42930b68b04304878abbea32ee9a9cd661f9bee80303ae1636caf2c7e bootstrap/src/compiler.rs +5b05ef6357a7139dbc16bd60977eda9294eecb01f9d2d3be58c8816796e418cc bootstrap/src/compiler.rs diff --git a/docs/now/2026-09-06-a-zig-map-reaches-rustc-verbatim.md b/docs/now/2026-09-06-a-zig-map-reaches-rustc-verbatim.md index ecb21f7f70..e9c73c6015 100644 --- a/docs/now/2026-09-06-a-zig-map-reaches-rustc-verbatim.md +++ b/docs/now/2026-09-06-a-zig-map-reaches-rustc-verbatim.md @@ -14,3 +14,12 @@ - A third finding was checked against the previous binary and is pre-existing: `std.HashMap(K, V) extra` becomes `*mut ()` on the old binary too. - The price was quoted to the owner before the work and matched it exactly: five specs. +- The adversarial pass found two MORE defects after the first repair, and both were mine: + an empty argument list passed the arity guard and emitted `HashMap<&'static str, >`, and + `split_type_list` drove depth negative on `->` inside an argument, so `fn(A) -> B` split + wrongly rather than being declined. +- Both fixed by making the split PARTIAL: it returns None on an unbalanced list and on any + empty argument, and every caller then leaves the type exactly as written so rustc + complains loudly. Re-measured a third time: still 357, zero regressions. +- Four of ten claims from that pass were mine to fix; one was refuted; one was confirmed + pre-existing by running the OLD binary on the same input.