@zigc/lib 0.16.0-test.1 → 0.17.0-dev.131

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (352) hide show
  1. package/LICENSE +19 -0
  2. package/c/fcntl.zig +6 -1
  3. package/c/inttypes.zig +0 -10
  4. package/c/math.zig +138 -114
  5. package/c/pthread.zig +57 -0
  6. package/c/search.zig +1 -27
  7. package/c/stdlib/drand48.zig +0 -57
  8. package/c/stdlib.zig +0 -100
  9. package/c/string.zig +20 -7
  10. package/c/strings.zig +0 -38
  11. package/c/stropts.zig +17 -0
  12. package/c/unistd.zig +27 -26
  13. package/c/wchar.zig +10 -0
  14. package/c.zig +3 -2
  15. package/compiler/aro/aro/Attribute/names.zig +604 -589
  16. package/compiler/aro/aro/Attribute.zig +202 -116
  17. package/compiler/aro/aro/Builtins/common.zig +874 -863
  18. package/compiler/aro/aro/Builtins/eval.zig +15 -7
  19. package/compiler/aro/aro/Builtins.zig +0 -1
  20. package/compiler/aro/aro/CodeGen.zig +8 -7
  21. package/compiler/aro/aro/Compilation.zig +137 -111
  22. package/compiler/aro/aro/Diagnostics.zig +21 -17
  23. package/compiler/aro/aro/Driver/GCCDetector.zig +635 -0
  24. package/compiler/aro/aro/Driver.zig +138 -63
  25. package/compiler/aro/aro/LangOpts.zig +12 -2
  26. package/compiler/aro/aro/Parser/Diagnostic.zig +79 -19
  27. package/compiler/aro/aro/Parser.zig +352 -153
  28. package/compiler/aro/aro/Pragma.zig +3 -2
  29. package/compiler/aro/aro/Preprocessor/Diagnostic.zig +21 -0
  30. package/compiler/aro/aro/Preprocessor.zig +136 -62
  31. package/compiler/aro/aro/Target.zig +17 -12
  32. package/compiler/aro/aro/Tokenizer.zig +31 -14
  33. package/compiler/aro/aro/Toolchain.zig +4 -7
  34. package/compiler/aro/aro/Tree.zig +178 -148
  35. package/compiler/aro/aro/TypeStore.zig +82 -24
  36. package/compiler/aro/aro/Value.zig +13 -17
  37. package/compiler/aro/aro/features.zig +1 -0
  38. package/compiler/aro/aro/pragmas/message.zig +3 -2
  39. package/compiler/aro/aro/pragmas/once.zig +0 -1
  40. package/compiler/aro/aro/record_layout.zig +3 -3
  41. package/compiler/aro/aro/text_literal.zig +3 -2
  42. package/compiler/aro/assembly_backend/x86_64.zig +7 -8
  43. package/compiler/aro/backend/Assembly.zig +1 -2
  44. package/compiler/aro/backend/Interner.zig +2 -2
  45. package/compiler/aro/backend/Ir.zig +100 -92
  46. package/compiler/aro/include/ptrcheck.h +49 -0
  47. package/compiler/aro/main.zig +26 -10
  48. package/compiler/build_runner.zig +1 -2
  49. package/compiler/objdump.zig +93 -0
  50. package/compiler/reduce/Walk.zig +7 -7
  51. package/compiler/reduce.zig +5 -1
  52. package/compiler/resinator/compile.zig +2 -2
  53. package/compiler/resinator/main.zig +7 -1
  54. package/compiler/resinator/preprocess.zig +1 -3
  55. package/compiler/std-docs.zig +8 -1
  56. package/compiler/test_runner.zig +194 -62
  57. package/compiler/translate-c/MacroTranslator.zig +80 -11
  58. package/compiler/translate-c/PatternList.zig +1 -9
  59. package/compiler/translate-c/Scope.zig +43 -6
  60. package/compiler/translate-c/Translator.zig +369 -127
  61. package/compiler/translate-c/ast.zig +19 -11
  62. package/compiler/translate-c/main.zig +76 -17
  63. package/compiler_rt/cos.zig +140 -53
  64. package/compiler_rt/divmodei4.zig +40 -17
  65. package/compiler_rt/exp.zig +1 -6
  66. package/compiler_rt/exp2.zig +1 -6
  67. package/compiler_rt/exp_f128.zig +377 -0
  68. package/compiler_rt/fabs.zig +0 -2
  69. package/compiler_rt/fma.zig +0 -2
  70. package/compiler_rt/fmax.zig +0 -2
  71. package/compiler_rt/fmin.zig +0 -2
  72. package/compiler_rt/fmod.zig +0 -2
  73. package/compiler_rt/limb64.zig +1127 -0
  74. package/compiler_rt/log.zig +0 -2
  75. package/compiler_rt/log10.zig +0 -2
  76. package/compiler_rt/log2.zig +0 -2
  77. package/compiler_rt/long_double.zig +37 -0
  78. package/compiler_rt/mulXi3.zig +1 -1
  79. package/compiler_rt/mulo.zig +6 -1
  80. package/compiler_rt/rem_pio2l.zig +173 -0
  81. package/compiler_rt/round.zig +0 -2
  82. package/compiler_rt/sin.zig +139 -56
  83. package/compiler_rt/sincos.zig +277 -72
  84. package/compiler_rt/sqrt.zig +0 -2
  85. package/compiler_rt/ssp.zig +1 -1
  86. package/compiler_rt/tan.zig +117 -48
  87. package/compiler_rt/trig.zig +256 -6
  88. package/compiler_rt/trunc.zig +0 -2
  89. package/compiler_rt/udivmodei4.zig +28 -0
  90. package/compiler_rt.zig +2 -0
  91. package/fuzzer.zig +857 -307
  92. package/libc/musl/arch/mipsn32/syscall_arch.h +35 -32
  93. package/libc/musl/src/math/pow.c +343 -0
  94. package/package.json +1 -1
  95. package/std/Build/Cache.zig +6 -6
  96. package/std/Build/Fuzz.zig +6 -19
  97. package/std/Build/Module.zig +1 -1
  98. package/std/Build/Step/CheckObject.zig +3 -3
  99. package/std/Build/Step/Compile.zig +18 -1
  100. package/std/Build/Step/ConfigHeader.zig +49 -33
  101. package/std/Build/Step/InstallArtifact.zig +18 -0
  102. package/std/Build/Step/Run.zig +538 -89
  103. package/std/Build/Step/TranslateC.zig +0 -6
  104. package/std/Build/Step.zig +10 -19
  105. package/std/Build/WebServer.zig +31 -19
  106. package/std/Build/abi.zig +47 -11
  107. package/std/Build.zig +17 -17
  108. package/std/Io/Dir.zig +7 -2
  109. package/std/Io/Dispatch.zig +5 -13
  110. package/std/Io/File/Reader.zig +3 -1
  111. package/std/Io/File/Writer.zig +8 -6
  112. package/std/Io/File.zig +1 -0
  113. package/std/Io/Kqueue.zig +2 -2
  114. package/std/Io/Reader.zig +8 -9
  115. package/std/Io/Semaphore.zig +112 -17
  116. package/std/Io/Terminal.zig +1 -1
  117. package/std/Io/Threaded.zig +352 -180
  118. package/std/Io/Uring.zig +15 -16
  119. package/std/Io/Writer.zig +46 -42
  120. package/std/Io/net.zig +11 -11
  121. package/std/Io.zig +1052 -20
  122. package/std/SemanticVersion.zig +1 -1
  123. package/std/Target/Query.zig +2 -2
  124. package/std/Target.zig +53 -7
  125. package/std/Thread.zig +8 -3
  126. package/std/array_hash_map.zig +105 -573
  127. package/std/array_list.zig +22 -31
  128. package/std/bit_set.zig +22 -6
  129. package/std/builtin/assembly.zig +68 -0
  130. package/std/builtin.zig +4 -0
  131. package/std/c/haiku.zig +3 -0
  132. package/std/c/serenity.zig +1 -6
  133. package/std/c.zig +106 -24
  134. package/std/compress/flate/Compress.zig +3 -3
  135. package/std/compress/flate/Decompress.zig +2 -3
  136. package/std/compress/zstd/Decompress.zig +2 -4
  137. package/std/crypto/Certificate/Bundle.zig +15 -1
  138. package/std/crypto/Certificate.zig +13 -1
  139. package/std/crypto/ascon.zig +75 -33
  140. package/std/crypto/codecs/asn1/Oid.zig +12 -1
  141. package/std/crypto/codecs/asn1.zig +33 -18
  142. package/std/crypto/codecs/base64_hex_ct.zig +16 -8
  143. package/std/crypto/ml_kem.zig +2 -9
  144. package/std/crypto/tls/Client.zig +79 -4
  145. package/std/crypto/tls.zig +1 -1
  146. package/std/crypto.zig +1 -0
  147. package/std/debug/Dwarf.zig +29 -9
  148. package/std/debug/Info.zig +4 -0
  149. package/std/debug/MachOFile.zig +46 -8
  150. package/std/debug/Pdb.zig +540 -37
  151. package/std/debug/SelfInfo/Elf.zig +19 -18
  152. package/std/debug/SelfInfo/MachO.zig +18 -7
  153. package/std/debug/SelfInfo/Windows.zig +138 -36
  154. package/std/debug.zig +181 -66
  155. package/std/enums.zig +25 -19
  156. package/std/fmt.zig +8 -3
  157. package/std/fs/path.zig +6 -4
  158. package/std/heap/ArenaAllocator.zig +145 -154
  159. package/std/heap/BufferFirstAllocator.zig +165 -0
  160. package/std/heap/debug_allocator.zig +7 -7
  161. package/std/heap.zig +2 -126
  162. package/std/http/Client.zig +31 -30
  163. package/std/http.zig +14 -13
  164. package/std/json/Scanner.zig +2 -2
  165. package/std/json/Stringify.zig +3 -3
  166. package/std/json/dynamic.zig +4 -4
  167. package/std/math/big/int.zig +16 -17
  168. package/std/mem/Allocator.zig +4 -5
  169. package/std/mem.zig +48 -0
  170. package/std/os/emscripten.zig +2 -18
  171. package/std/os/linux/IoUring.zig +2 -0
  172. package/std/os/linux/aarch64.zig +41 -12
  173. package/std/os/linux/arc.zig +173 -0
  174. package/std/os/linux/arm.zig +41 -12
  175. package/std/os/linux/hexagon.zig +33 -11
  176. package/std/os/linux/loongarch32.zig +41 -13
  177. package/std/os/linux/loongarch64.zig +41 -12
  178. package/std/os/linux/m68k.zig +41 -13
  179. package/std/os/linux/mips.zig +67 -36
  180. package/std/os/linux/mips64.zig +60 -29
  181. package/std/os/linux/mipsn32.zig +60 -29
  182. package/std/os/linux/or1k.zig +41 -12
  183. package/std/os/linux/powerpc.zig +41 -12
  184. package/std/os/linux/powerpc64.zig +41 -12
  185. package/std/os/linux/riscv32.zig +41 -12
  186. package/std/os/linux/riscv64.zig +41 -12
  187. package/std/os/linux/s390x.zig +44 -7
  188. package/std/os/linux/sparc64.zig +83 -52
  189. package/std/os/linux/thumb.zig +52 -36
  190. package/std/os/linux/x32.zig +41 -12
  191. package/std/os/linux/x86.zig +42 -13
  192. package/std/os/linux/x86_64.zig +41 -12
  193. package/std/os/linux.zig +419 -438
  194. package/std/os/uefi/tables/boot_services.zig +9 -8
  195. package/std/os/windows.zig +2 -2
  196. package/std/os.zig +41 -0
  197. package/std/pdb.zig +143 -4
  198. package/std/posix.zig +6 -12
  199. package/std/priority_dequeue.zig +13 -12
  200. package/std/priority_queue.zig +5 -4
  201. package/std/process/Child.zig +1 -1
  202. package/std/process/Environ.zig +1 -1
  203. package/std/process.zig +1 -1
  204. package/std/sort.zig +3 -3
  205. package/std/start.zig +17 -4
  206. package/std/std.zig +19 -6
  207. package/std/testing/FailingAllocator.zig +4 -4
  208. package/std/testing/Smith.zig +37 -2
  209. package/std/zig/Ast/Render.zig +187 -459
  210. package/std/zig/Ast.zig +0 -4
  211. package/std/zig/AstGen.zig +86 -103
  212. package/std/zig/AstRlAnnotate.zig +0 -11
  213. package/std/zig/AstSmith.zig +2602 -0
  214. package/std/zig/BuiltinFn.zig +0 -32
  215. package/std/zig/Client.zig +8 -3
  216. package/std/zig/LibCInstallation.zig +4 -3
  217. package/std/zig/Parse.zig +90 -81
  218. package/std/zig/Server.zig +26 -0
  219. package/std/zig/WindowsSdk.zig +13 -13
  220. package/std/zig/Zir.zig +66 -62
  221. package/std/zig/ZonGen.zig +6 -5
  222. package/std/zig/c_translation/helpers.zig +14 -9
  223. package/std/zig/llvm/Builder.zig +119 -60
  224. package/std/zig/system.zig +20 -4
  225. package/std/zig/tokenizer.zig +2 -1
  226. package/std/zig.zig +7 -10
  227. package/std/zip.zig +5 -5
  228. package/zig.h +340 -1
  229. package/compiler/aro/aro/Driver/Filesystem.zig +0 -241
  230. package/libc/mingw/complex/cabs.c +0 -48
  231. package/libc/mingw/complex/cabsf.c +0 -48
  232. package/libc/mingw/complex/cacos.c +0 -50
  233. package/libc/mingw/complex/cacosf.c +0 -50
  234. package/libc/mingw/complex/carg.c +0 -48
  235. package/libc/mingw/complex/cargf.c +0 -48
  236. package/libc/mingw/complex/casin.c +0 -50
  237. package/libc/mingw/complex/casinf.c +0 -50
  238. package/libc/mingw/complex/catan.c +0 -50
  239. package/libc/mingw/complex/catanf.c +0 -50
  240. package/libc/mingw/complex/ccos.c +0 -50
  241. package/libc/mingw/complex/ccosf.c +0 -50
  242. package/libc/mingw/complex/cexp.c +0 -48
  243. package/libc/mingw/complex/cexpf.c +0 -48
  244. package/libc/mingw/complex/cimag.c +0 -48
  245. package/libc/mingw/complex/cimagf.c +0 -48
  246. package/libc/mingw/complex/clog.c +0 -48
  247. package/libc/mingw/complex/clog10.c +0 -49
  248. package/libc/mingw/complex/clog10f.c +0 -49
  249. package/libc/mingw/complex/clogf.c +0 -48
  250. package/libc/mingw/complex/conj.c +0 -48
  251. package/libc/mingw/complex/conjf.c +0 -48
  252. package/libc/mingw/complex/cpow.c +0 -48
  253. package/libc/mingw/complex/cpowf.c +0 -48
  254. package/libc/mingw/complex/cproj.c +0 -48
  255. package/libc/mingw/complex/cprojf.c +0 -48
  256. package/libc/mingw/complex/creal.c +0 -48
  257. package/libc/mingw/complex/crealf.c +0 -48
  258. package/libc/mingw/complex/csin.c +0 -50
  259. package/libc/mingw/complex/csinf.c +0 -50
  260. package/libc/mingw/complex/csqrt.c +0 -48
  261. package/libc/mingw/complex/csqrtf.c +0 -48
  262. package/libc/mingw/complex/ctan.c +0 -50
  263. package/libc/mingw/complex/ctanf.c +0 -50
  264. package/libc/mingw/math/arm/s_rint.c +0 -86
  265. package/libc/mingw/math/arm/s_rintf.c +0 -51
  266. package/libc/mingw/math/arm/sincos.S +0 -30
  267. package/libc/mingw/math/arm-common/sincosl.c +0 -13
  268. package/libc/mingw/math/arm64/rint.c +0 -12
  269. package/libc/mingw/math/arm64/rintf.c +0 -12
  270. package/libc/mingw/math/arm64/sincos.S +0 -32
  271. package/libc/mingw/math/bsd_private_base.h +0 -148
  272. package/libc/mingw/math/fdiml.c +0 -24
  273. package/libc/mingw/math/frexpf.c +0 -13
  274. package/libc/mingw/math/frexpl.c +0 -71
  275. package/libc/mingw/math/x86/acosf.c +0 -29
  276. package/libc/mingw/math/x86/atanf.c +0 -23
  277. package/libc/mingw/math/x86/atanl.c +0 -18
  278. package/libc/mingw/math/x86/cos.def.h +0 -65
  279. package/libc/mingw/math/x86/cosl.c +0 -46
  280. package/libc/mingw/math/x86/cosl_internal.S +0 -55
  281. package/libc/mingw/math/x86/ldexp.c +0 -23
  282. package/libc/mingw/math/x86/scalbn.S +0 -41
  283. package/libc/mingw/math/x86/scalbnf.S +0 -40
  284. package/libc/mingw/math/x86/sin.def.h +0 -65
  285. package/libc/mingw/math/x86/sinl.c +0 -46
  286. package/libc/mingw/math/x86/sinl_internal.S +0 -58
  287. package/libc/mingw/math/x86/tanl.S +0 -62
  288. package/libc/mingw/misc/btowc.c +0 -28
  289. package/libc/mingw/misc/wcstof.c +0 -66
  290. package/libc/mingw/misc/wcstoimax.c +0 -132
  291. package/libc/mingw/misc/wcstoumax.c +0 -126
  292. package/libc/mingw/misc/wctob.c +0 -29
  293. package/libc/mingw/misc/winbs_uint64.c +0 -6
  294. package/libc/mingw/misc/winbs_ulong.c +0 -6
  295. package/libc/mingw/misc/winbs_ushort.c +0 -6
  296. package/libc/mingw/stdio/_Exit.c +0 -10
  297. package/libc/mingw/stdio/_findfirst64i32.c +0 -21
  298. package/libc/mingw/stdio/_findnext64i32.c +0 -21
  299. package/libc/mingw/stdio/_fstat64i32.c +0 -37
  300. package/libc/mingw/stdio/_stat64i32.c +0 -37
  301. package/libc/mingw/stdio/_wfindfirst64i32.c +0 -21
  302. package/libc/mingw/stdio/_wfindnext64i32.c +0 -21
  303. package/libc/mingw/stdio/_wstat64i32.c +0 -37
  304. package/libc/mingw/winpthreads/spinlock.c +0 -82
  305. package/libc/musl/src/legacy/isastream.c +0 -7
  306. package/libc/musl/src/legacy/valloc.c +0 -8
  307. package/libc/musl/src/linux/tee.c +0 -8
  308. package/libc/musl/src/math/__cosl.c +0 -96
  309. package/libc/musl/src/math/__sinl.c +0 -78
  310. package/libc/musl/src/math/__tanl.c +0 -143
  311. package/libc/musl/src/math/aarch64/lrint.c +0 -10
  312. package/libc/musl/src/math/aarch64/lrintf.c +0 -10
  313. package/libc/musl/src/math/aarch64/rintf.c +0 -7
  314. package/libc/musl/src/math/cosl.c +0 -39
  315. package/libc/musl/src/math/fdim.c +0 -10
  316. package/libc/musl/src/math/fdimf.c +0 -10
  317. package/libc/musl/src/math/fdiml.c +0 -18
  318. package/libc/musl/src/math/finite.c +0 -7
  319. package/libc/musl/src/math/finitef.c +0 -7
  320. package/libc/musl/src/math/frexp.c +0 -23
  321. package/libc/musl/src/math/frexpf.c +0 -23
  322. package/libc/musl/src/math/frexpl.c +0 -29
  323. package/libc/musl/src/math/i386/lrint.c +0 -8
  324. package/libc/musl/src/math/i386/lrintf.c +0 -8
  325. package/libc/musl/src/math/i386/rintf.c +0 -7
  326. package/libc/musl/src/math/lrint.c +0 -72
  327. package/libc/musl/src/math/lrintf.c +0 -8
  328. package/libc/musl/src/math/powerpc64/lrint.c +0 -16
  329. package/libc/musl/src/math/powerpc64/lrintf.c +0 -16
  330. package/libc/musl/src/math/rintf.c +0 -30
  331. package/libc/musl/src/math/s390x/rintf.c +0 -15
  332. package/libc/musl/src/math/sincosl.c +0 -60
  333. package/libc/musl/src/math/sinl.c +0 -41
  334. package/libc/musl/src/math/tanl.c +0 -29
  335. package/libc/musl/src/math/x32/lrint.s +0 -5
  336. package/libc/musl/src/math/x32/lrintf.s +0 -5
  337. package/libc/musl/src/math/x86_64/lrint.c +0 -8
  338. package/libc/musl/src/math/x86_64/lrintf.c +0 -8
  339. package/libc/musl/src/string/strdup.c +0 -10
  340. package/libc/musl/src/string/strndup.c +0 -12
  341. package/libc/musl/src/string/wcsdup.c +0 -10
  342. package/libc/musl/src/thread/pthread_spin_destroy.c +0 -6
  343. package/libc/musl/src/thread/pthread_spin_init.c +0 -6
  344. package/libc/musl/src/thread/pthread_spin_lock.c +0 -8
  345. package/libc/musl/src/thread/pthread_spin_trylock.c +0 -7
  346. package/libc/musl/src/thread/pthread_spin_unlock.c +0 -7
  347. package/libc/musl/src/unistd/dup2.c +0 -20
  348. package/libc/musl/src/unistd/dup3.c +0 -26
  349. package/libc/wasi/libc-bottom-half/sources/reallocarray.c +0 -14
  350. package/libc/wasi/thread-stub/pthread_spin_lock.c +0 -8
  351. package/libc/wasi/thread-stub/pthread_spin_trylock.c +0 -8
  352. package/libc/wasi/thread-stub/pthread_spin_unlock.c +0 -7
@@ -12,27 +12,15 @@ const hash_map = @This();
12
12
  /// An `ArrayHashMap` with default hash and equal functions.
13
13
  ///
14
14
  /// See `AutoContext` for a description of the hash and equal implementations.
15
- pub fn AutoArrayHashMap(comptime K: type, comptime V: type) type {
15
+ pub fn Auto(comptime K: type, comptime V: type) type {
16
16
  return ArrayHashMap(K, V, AutoContext(K), !autoEqlIsCheap(K));
17
17
  }
18
18
 
19
- /// An `ArrayHashMapUnmanaged` with default hash and equal functions.
20
- ///
21
- /// See `AutoContext` for a description of the hash and equal implementations.
22
- pub fn AutoArrayHashMapUnmanaged(comptime K: type, comptime V: type) type {
23
- return ArrayHashMapUnmanaged(K, V, AutoContext(K), !autoEqlIsCheap(K));
24
- }
25
-
26
19
  /// An `ArrayHashMap` with strings as keys.
27
- pub fn StringArrayHashMap(comptime V: type) type {
20
+ pub fn String(comptime V: type) type {
28
21
  return ArrayHashMap([]const u8, V, StringContext, true);
29
22
  }
30
23
 
31
- /// An `ArrayHashMapUnmanaged` with strings as keys.
32
- pub fn StringArrayHashMapUnmanaged(comptime V: type) type {
33
- return ArrayHashMapUnmanaged([]const u8, V, StringContext, true);
34
- }
35
-
36
24
  pub const StringContext = struct {
37
25
  pub fn hash(self: @This(), s: []const u8) u32 {
38
26
  _ = self;
@@ -53,454 +41,8 @@ pub fn hashString(s: []const u8) u32 {
53
41
  return @truncate(std.hash.Wyhash.hash(0, s));
54
42
  }
55
43
 
56
- /// Deprecated in favor of `ArrayHashMapWithAllocator` (no code changes needed)
57
- /// or `ArrayHashMapUnmanaged` (will need to update callsites to pass an
58
- /// allocator). After Zig 0.14.0 is released, `ArrayHashMapWithAllocator` will
59
- /// be removed and `ArrayHashMapUnmanaged` will be a deprecated alias. After
60
- /// Zig 0.15.0 is released, the deprecated alias `ArrayHashMapUnmanaged` will
61
- /// be removed.
62
- pub const ArrayHashMap = ArrayHashMapWithAllocator;
63
-
64
- /// A hash table of keys and values, each stored sequentially.
65
- ///
66
- /// Insertion order is preserved. In general, this data structure supports the same
67
- /// operations as `std.ArrayList`.
68
- ///
69
- /// Deletion operations:
70
- /// * `swapRemove` - O(1)
71
- /// * `orderedRemove` - O(N)
72
- ///
73
- /// Modifying the hash map while iterating is allowed, however, one must understand
74
- /// the (well defined) behavior when mixing insertions and deletions with iteration.
75
- ///
76
- /// See `ArrayHashMapUnmanaged` for a variant of this data structure that accepts an
77
- /// `Allocator` as a parameter when needed rather than storing it.
78
- pub fn ArrayHashMapWithAllocator(
79
- comptime K: type,
80
- comptime V: type,
81
- /// A namespace that provides these two functions:
82
- /// * `pub fn hash(self, K) u32`
83
- /// * `pub fn eql(self, K, K, usize) bool`
84
- ///
85
- /// The final `usize` in the `eql` function represents the index of the key
86
- /// that's already inside the map.
87
- comptime Context: type,
88
- /// When `false`, this data structure is biased towards cheap `eql`
89
- /// functions and avoids storing each key's hash in the table. Setting
90
- /// `store_hash` to `true` incurs more memory cost but limits `eql` to
91
- /// being called only once per insertion/deletion (provided there are no
92
- /// hash collisions).
93
- comptime store_hash: bool,
94
- ) type {
95
- return struct {
96
- unmanaged: Unmanaged,
97
- allocator: Allocator,
98
- ctx: Context,
99
-
100
- /// The ArrayHashMapUnmanaged type using the same settings as this managed map.
101
- pub const Unmanaged = ArrayHashMapUnmanaged(K, V, Context, store_hash);
102
-
103
- /// Pointers to a key and value in the backing store of this map.
104
- /// Modifying the key is allowed only if it does not change the hash.
105
- /// Modifying the value is allowed.
106
- /// Entry pointers become invalid whenever this ArrayHashMap is modified,
107
- /// unless `ensureTotalCapacity`/`ensureUnusedCapacity` was previously used.
108
- pub const Entry = Unmanaged.Entry;
109
-
110
- /// A KV pair which has been copied out of the backing store
111
- pub const KV = Unmanaged.KV;
112
-
113
- /// The Data type used for the MultiArrayList backing this map
114
- pub const Data = Unmanaged.Data;
115
- /// The MultiArrayList type backing this map
116
- pub const DataList = Unmanaged.DataList;
117
-
118
- /// The stored hash type, either u32 or void.
119
- pub const Hash = Unmanaged.Hash;
120
-
121
- /// getOrPut variants return this structure, with pointers
122
- /// to the backing store and a flag to indicate whether an
123
- /// existing entry was found.
124
- /// Modifying the key is allowed only if it does not change the hash.
125
- /// Modifying the value is allowed.
126
- /// Entry pointers become invalid whenever this ArrayHashMap is modified,
127
- /// unless `ensureTotalCapacity`/`ensureUnusedCapacity` was previously used.
128
- pub const GetOrPutResult = Unmanaged.GetOrPutResult;
129
-
130
- /// An Iterator over Entry pointers.
131
- pub const Iterator = Unmanaged.Iterator;
132
-
133
- const Self = @This();
134
-
135
- /// Create an ArrayHashMap instance which will use a specified allocator.
136
- pub fn init(allocator: Allocator) Self {
137
- if (@sizeOf(Context) != 0)
138
- @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call initContext instead.");
139
- return initContext(allocator, undefined);
140
- }
141
- pub fn initContext(allocator: Allocator, ctx: Context) Self {
142
- return .{
143
- .unmanaged = .empty,
144
- .allocator = allocator,
145
- .ctx = ctx,
146
- };
147
- }
148
-
149
- /// Frees the backing allocation and leaves the map in an undefined state.
150
- /// Note that this does not free keys or values. You must take care of that
151
- /// before calling this function, if it is needed.
152
- pub fn deinit(self: *Self) void {
153
- self.unmanaged.deinit(self.allocator);
154
- self.* = undefined;
155
- }
156
-
157
- /// Puts the hash map into a state where any method call that would
158
- /// cause an existing key or value pointer to become invalidated will
159
- /// instead trigger an assertion.
160
- ///
161
- /// An additional call to `lockPointers` in such state also triggers an
162
- /// assertion.
163
- ///
164
- /// `unlockPointers` returns the hash map to the previous state.
165
- pub fn lockPointers(self: *Self) void {
166
- self.unmanaged.lockPointers();
167
- }
168
-
169
- /// Undoes a call to `lockPointers`.
170
- pub fn unlockPointers(self: *Self) void {
171
- self.unmanaged.unlockPointers();
172
- }
173
-
174
- /// Clears the map but retains the backing allocation for future use.
175
- pub fn clearRetainingCapacity(self: *Self) void {
176
- return self.unmanaged.clearRetainingCapacity();
177
- }
178
-
179
- /// Clears the map and releases the backing allocation
180
- pub fn clearAndFree(self: *Self) void {
181
- return self.unmanaged.clearAndFree(self.allocator);
182
- }
183
-
184
- /// Returns the number of KV pairs stored in this map.
185
- pub fn count(self: Self) usize {
186
- return self.unmanaged.count();
187
- }
188
-
189
- /// Returns the backing array of keys in this map. Modifying the map may
190
- /// invalidate this array. Modifying this array in a way that changes
191
- /// key hashes or key equality puts the map into an unusable state until
192
- /// `reIndex` is called.
193
- pub fn keys(self: Self) []K {
194
- return self.unmanaged.keys();
195
- }
196
- /// Returns the backing array of values in this map. Modifying the map
197
- /// may invalidate this array. It is permitted to modify the values in
198
- /// this array.
199
- pub fn values(self: Self) []V {
200
- return self.unmanaged.values();
201
- }
202
-
203
- /// Returns an iterator over the pairs in this map.
204
- /// Modifying the map may invalidate this iterator.
205
- pub fn iterator(self: *const Self) Iterator {
206
- return self.unmanaged.iterator();
207
- }
208
-
209
- /// If key exists this function cannot fail.
210
- /// If there is an existing item with `key`, then the result
211
- /// `Entry` pointer points to it, and found_existing is true.
212
- /// Otherwise, puts a new item with undefined value, and
213
- /// the `Entry` pointer points to it. Caller should then initialize
214
- /// the value (but not the key).
215
- pub fn getOrPut(self: *Self, key: K) !GetOrPutResult {
216
- return self.unmanaged.getOrPutContext(self.allocator, key, self.ctx);
217
- }
218
- pub fn getOrPutAdapted(self: *Self, key: anytype, ctx: anytype) !GetOrPutResult {
219
- return self.unmanaged.getOrPutContextAdapted(self.allocator, key, ctx, self.ctx);
220
- }
221
-
222
- /// If there is an existing item with `key`, then the result
223
- /// `Entry` pointer points to it, and found_existing is true.
224
- /// Otherwise, puts a new item with undefined value, and
225
- /// the `Entry` pointer points to it. Caller should then initialize
226
- /// the value (but not the key).
227
- /// If a new entry needs to be stored, this function asserts there
228
- /// is enough capacity to store it.
229
- pub fn getOrPutAssumeCapacity(self: *Self, key: K) GetOrPutResult {
230
- return self.unmanaged.getOrPutAssumeCapacityContext(key, self.ctx);
231
- }
232
- pub fn getOrPutAssumeCapacityAdapted(self: *Self, key: anytype, ctx: anytype) GetOrPutResult {
233
- return self.unmanaged.getOrPutAssumeCapacityAdapted(key, ctx);
234
- }
235
- pub fn getOrPutValue(self: *Self, key: K, value: V) !GetOrPutResult {
236
- return self.unmanaged.getOrPutValueContext(self.allocator, key, value, self.ctx);
237
- }
238
-
239
- /// Increases capacity, guaranteeing that insertions up until the
240
- /// `expected_count` will not cause an allocation, and therefore cannot fail.
241
- pub fn ensureTotalCapacity(self: *Self, new_capacity: usize) !void {
242
- return self.unmanaged.ensureTotalCapacityContext(self.allocator, new_capacity, self.ctx);
243
- }
244
-
245
- /// Increases capacity, guaranteeing that insertions up until
246
- /// `additional_count` **more** items will not cause an allocation, and
247
- /// therefore cannot fail.
248
- pub fn ensureUnusedCapacity(self: *Self, additional_count: usize) !void {
249
- return self.unmanaged.ensureUnusedCapacityContext(self.allocator, additional_count, self.ctx);
250
- }
251
-
252
- /// Returns the number of total elements which may be present before it is
253
- /// no longer guaranteed that no allocations will be performed.
254
- pub fn capacity(self: Self) usize {
255
- return self.unmanaged.capacity();
256
- }
257
-
258
- /// Clobbers any existing data. To detect if a put would clobber
259
- /// existing data, see `getOrPut`.
260
- pub fn put(self: *Self, key: K, value: V) !void {
261
- return self.unmanaged.putContext(self.allocator, key, value, self.ctx);
262
- }
263
-
264
- /// Inserts a key-value pair into the hash map, asserting that no previous
265
- /// entry with the same key is already present
266
- pub fn putNoClobber(self: *Self, key: K, value: V) !void {
267
- return self.unmanaged.putNoClobberContext(self.allocator, key, value, self.ctx);
268
- }
269
-
270
- /// Asserts there is enough capacity to store the new key-value pair.
271
- /// Clobbers any existing data. To detect if a put would clobber
272
- /// existing data, see `getOrPutAssumeCapacity`.
273
- pub fn putAssumeCapacity(self: *Self, key: K, value: V) void {
274
- return self.unmanaged.putAssumeCapacityContext(key, value, self.ctx);
275
- }
276
-
277
- /// Asserts there is enough capacity to store the new key-value pair.
278
- /// Asserts that it does not clobber any existing data.
279
- /// To detect if a put would clobber existing data, see `getOrPutAssumeCapacity`.
280
- pub fn putAssumeCapacityNoClobber(self: *Self, key: K, value: V) void {
281
- return self.unmanaged.putAssumeCapacityNoClobberContext(key, value, self.ctx);
282
- }
283
-
284
- /// Inserts a new `Entry` into the hash map, returning the previous one, if any.
285
- pub fn fetchPut(self: *Self, key: K, value: V) !?KV {
286
- return self.unmanaged.fetchPutContext(self.allocator, key, value, self.ctx);
287
- }
288
-
289
- /// Inserts a new `Entry` into the hash map, returning the previous one, if any.
290
- /// If insertion happuns, asserts there is enough capacity without allocating.
291
- pub fn fetchPutAssumeCapacity(self: *Self, key: K, value: V) ?KV {
292
- return self.unmanaged.fetchPutAssumeCapacityContext(key, value, self.ctx);
293
- }
294
-
295
- /// Finds pointers to the key and value storage associated with a key.
296
- pub fn getEntry(self: Self, key: K) ?Entry {
297
- return self.unmanaged.getEntryContext(key, self.ctx);
298
- }
299
- pub fn getEntryAdapted(self: Self, key: anytype, ctx: anytype) ?Entry {
300
- return self.unmanaged.getEntryAdapted(key, ctx);
301
- }
302
-
303
- /// Finds the index in the `entries` array where a key is stored
304
- pub fn getIndex(self: Self, key: K) ?usize {
305
- return self.unmanaged.getIndexContext(key, self.ctx);
306
- }
307
- pub fn getIndexAdapted(self: Self, key: anytype, ctx: anytype) ?usize {
308
- return self.unmanaged.getIndexAdapted(key, ctx);
309
- }
310
-
311
- /// Find the value associated with a key
312
- pub fn get(self: Self, key: K) ?V {
313
- return self.unmanaged.getContext(key, self.ctx);
314
- }
315
- pub fn getAdapted(self: Self, key: anytype, ctx: anytype) ?V {
316
- return self.unmanaged.getAdapted(key, ctx);
317
- }
318
-
319
- /// Find a pointer to the value associated with a key
320
- pub fn getPtr(self: Self, key: K) ?*V {
321
- return self.unmanaged.getPtrContext(key, self.ctx);
322
- }
323
- pub fn getPtrAdapted(self: Self, key: anytype, ctx: anytype) ?*V {
324
- return self.unmanaged.getPtrAdapted(key, ctx);
325
- }
326
-
327
- /// Find the actual key associated with an adapted key
328
- pub fn getKey(self: Self, key: K) ?K {
329
- return self.unmanaged.getKeyContext(key, self.ctx);
330
- }
331
- pub fn getKeyAdapted(self: Self, key: anytype, ctx: anytype) ?K {
332
- return self.unmanaged.getKeyAdapted(key, ctx);
333
- }
334
-
335
- /// Find a pointer to the actual key associated with an adapted key
336
- pub fn getKeyPtr(self: Self, key: K) ?*K {
337
- return self.unmanaged.getKeyPtrContext(key, self.ctx);
338
- }
339
- pub fn getKeyPtrAdapted(self: Self, key: anytype, ctx: anytype) ?*K {
340
- return self.unmanaged.getKeyPtrAdapted(key, ctx);
341
- }
342
-
343
- /// Check whether a key is stored in the map
344
- pub fn contains(self: Self, key: K) bool {
345
- return self.unmanaged.containsContext(key, self.ctx);
346
- }
347
- pub fn containsAdapted(self: Self, key: anytype, ctx: anytype) bool {
348
- return self.unmanaged.containsAdapted(key, ctx);
349
- }
350
-
351
- /// If there is an `Entry` with a matching key, it is deleted from
352
- /// the hash map, and then returned from this function. The entry is
353
- /// removed from the underlying array by swapping it with the last
354
- /// element.
355
- pub fn fetchSwapRemove(self: *Self, key: K) ?KV {
356
- return self.unmanaged.fetchSwapRemoveContext(key, self.ctx);
357
- }
358
- pub fn fetchSwapRemoveAdapted(self: *Self, key: anytype, ctx: anytype) ?KV {
359
- return self.unmanaged.fetchSwapRemoveContextAdapted(key, ctx, self.ctx);
360
- }
361
-
362
- /// If there is an `Entry` with a matching key, it is deleted from
363
- /// the hash map, and then returned from this function. The entry is
364
- /// removed from the underlying array by shifting all elements forward
365
- /// thereby maintaining the current ordering.
366
- pub fn fetchOrderedRemove(self: *Self, key: K) ?KV {
367
- return self.unmanaged.fetchOrderedRemoveContext(key, self.ctx);
368
- }
369
- pub fn fetchOrderedRemoveAdapted(self: *Self, key: anytype, ctx: anytype) ?KV {
370
- return self.unmanaged.fetchOrderedRemoveContextAdapted(key, ctx, self.ctx);
371
- }
372
-
373
- /// If there is an `Entry` with a matching key, it is deleted from
374
- /// the hash map. The entry is removed from the underlying array
375
- /// by swapping it with the last element. Returns true if an entry
376
- /// was removed, false otherwise.
377
- pub fn swapRemove(self: *Self, key: K) bool {
378
- return self.unmanaged.swapRemoveContext(key, self.ctx);
379
- }
380
- pub fn swapRemoveAdapted(self: *Self, key: anytype, ctx: anytype) bool {
381
- return self.unmanaged.swapRemoveContextAdapted(key, ctx, self.ctx);
382
- }
383
-
384
- /// If there is an `Entry` with a matching key, it is deleted from
385
- /// the hash map. The entry is removed from the underlying array
386
- /// by shifting all elements forward, thereby maintaining the
387
- /// current ordering. Returns true if an entry was removed, false otherwise.
388
- pub fn orderedRemove(self: *Self, key: K) bool {
389
- return self.unmanaged.orderedRemoveContext(key, self.ctx);
390
- }
391
- pub fn orderedRemoveAdapted(self: *Self, key: anytype, ctx: anytype) bool {
392
- return self.unmanaged.orderedRemoveContextAdapted(key, ctx, self.ctx);
393
- }
394
-
395
- /// Deletes the item at the specified index in `entries` from
396
- /// the hash map. The entry is removed from the underlying array
397
- /// by swapping it with the last element.
398
- pub fn swapRemoveAt(self: *Self, index: usize) void {
399
- self.unmanaged.swapRemoveAtContext(index, self.ctx);
400
- }
401
-
402
- /// Deletes the item at the specified index in `entries` from
403
- /// the hash map. The entry is removed from the underlying array
404
- /// by shifting all elements forward, thereby maintaining the
405
- /// current ordering.
406
- pub fn orderedRemoveAt(self: *Self, index: usize) void {
407
- self.unmanaged.orderedRemoveAtContext(index, self.ctx);
408
- }
409
-
410
- /// Create a copy of the hash map which can be modified separately.
411
- /// The copy uses the same context and allocator as this instance.
412
- pub fn clone(self: Self) !Self {
413
- var other = try self.unmanaged.cloneContext(self.allocator, self.ctx);
414
- return other.promoteContext(self.allocator, self.ctx);
415
- }
416
- /// Create a copy of the hash map which can be modified separately.
417
- /// The copy uses the same context as this instance, but the specified
418
- /// allocator.
419
- pub fn cloneWithAllocator(self: Self, allocator: Allocator) !Self {
420
- var other = try self.unmanaged.cloneContext(allocator, self.ctx);
421
- return other.promoteContext(allocator, self.ctx);
422
- }
423
- /// Create a copy of the hash map which can be modified separately.
424
- /// The copy uses the same allocator as this instance, but the
425
- /// specified context.
426
- pub fn cloneWithContext(self: Self, ctx: anytype) !ArrayHashMap(K, V, @TypeOf(ctx), store_hash) {
427
- var other = try self.unmanaged.cloneContext(self.allocator, ctx);
428
- return other.promoteContext(self.allocator, ctx);
429
- }
430
- /// Create a copy of the hash map which can be modified separately.
431
- /// The copy uses the specified allocator and context.
432
- pub fn cloneWithAllocatorAndContext(self: Self, allocator: Allocator, ctx: anytype) !ArrayHashMap(K, V, @TypeOf(ctx), store_hash) {
433
- var other = try self.unmanaged.cloneContext(allocator, ctx);
434
- return other.promoteContext(allocator, ctx);
435
- }
436
-
437
- /// Set the map to an empty state, making deinitialization a no-op, and
438
- /// returning a copy of the original.
439
- pub fn move(self: *Self) Self {
440
- self.unmanaged.pointer_stability.assertUnlocked();
441
- const result = self.*;
442
- self.unmanaged = .empty;
443
- return result;
444
- }
445
-
446
- /// Recomputes stored hashes and rebuilds the key indexes. If the
447
- /// underlying keys have been modified directly, call this method to
448
- /// recompute the denormalized metadata necessary for the operation of
449
- /// the methods of this map that lookup entries by key.
450
- ///
451
- /// One use case for this is directly calling `entries.resize()` to grow
452
- /// the underlying storage, and then setting the `keys` and `values`
453
- /// directly without going through the methods of this map.
454
- ///
455
- /// The time complexity of this operation is O(n).
456
- pub fn reIndex(self: *Self) !void {
457
- return self.unmanaged.reIndexContext(self.allocator, self.ctx);
458
- }
459
-
460
- /// Sorts the entries and then rebuilds the index.
461
- /// `sort_ctx` must have this method:
462
- /// `fn lessThan(ctx: @TypeOf(ctx), a_index: usize, b_index: usize) bool`
463
- /// Uses a stable sorting algorithm.
464
- pub fn sort(self: *Self, sort_ctx: anytype) void {
465
- return self.unmanaged.sortContext(sort_ctx, self.ctx);
466
- }
467
-
468
- /// Sorts the entries and then rebuilds the index.
469
- /// `sort_ctx` must have this method:
470
- /// `fn lessThan(ctx: @TypeOf(ctx), a_index: usize, b_index: usize) bool`
471
- /// Uses an unstable sorting algorithm.
472
- pub fn sortUnstable(self: *Self, sort_ctx: anytype) void {
473
- return self.unmanaged.sortUnstableContext(sort_ctx, self.ctx);
474
- }
475
-
476
- /// Shrinks the underlying `Entry` array to `new_len` elements and
477
- /// discards any associated index entries. Keeps capacity the same.
478
- ///
479
- /// Asserts the discarded entries remain initialized and capable of
480
- /// performing hash and equality checks. Any deinitialization of
481
- /// discarded entries must take place *after* calling this function.
482
- pub fn shrinkRetainingCapacity(self: *Self, new_len: usize) void {
483
- return self.unmanaged.shrinkRetainingCapacityContext(new_len, self.ctx);
484
- }
485
-
486
- /// Shrinks the underlying `Entry` array to `new_len` elements and
487
- /// discards any associated index entries. Reduces allocated capacity.
488
- ///
489
- /// Asserts the discarded entries remain initialized and capable of
490
- /// performing hash and equality checks. It is a bug to call this
491
- /// function if the discarded entries require deinitialization. For
492
- /// that use case, `shrinkRetainingCapacity` can be used instead.
493
- pub fn shrinkAndFree(self: *Self, new_len: usize) void {
494
- return self.unmanaged.shrinkAndFreeContext(self.allocator, new_len, self.ctx);
495
- }
496
-
497
- /// Removes the last inserted `Entry` in the hash map and returns it if count is nonzero.
498
- /// Otherwise returns null.
499
- pub fn pop(self: *Self) ?KV {
500
- return self.unmanaged.popContext(self.ctx);
501
- }
502
- };
503
- }
44
+ /// Deprecated; use `Custom`.
45
+ pub const ArrayHashMap = Custom;
504
46
 
505
47
  /// A hash table of keys and values, each stored sequentially.
506
48
  ///
@@ -522,11 +64,11 @@ pub fn ArrayHashMapWithAllocator(
522
64
  ///
523
65
  /// This type is designed to have low overhead for small numbers of entries. When
524
66
  /// `store_hash` is `false` and the number of entries in the map is less than 9,
525
- /// the overhead cost of using `ArrayHashMapUnmanaged` rather than `std.ArrayList` is
67
+ /// the overhead cost of using `ArrayHashMap` rather than `std.ArrayList` is
526
68
  /// only a single pointer-sized integer.
527
69
  ///
528
70
  /// Default initialization of this struct is deprecated; use `.empty` instead.
529
- pub fn ArrayHashMapUnmanaged(
71
+ pub fn Custom(
530
72
  comptime K: type,
531
73
  comptime V: type,
532
74
  /// A namespace that provides these two functions:
@@ -605,9 +147,6 @@ pub fn ArrayHashMapUnmanaged(
605
147
  index: usize,
606
148
  };
607
149
 
608
- /// The ArrayHashMap type using the same settings as this managed map.
609
- pub const Managed = ArrayHashMap(K, V, Context, store_hash);
610
-
611
150
  /// Some functions require a context only if hashes are not stored.
612
151
  /// To keep the api simple, this type is only used internally.
613
152
  const ByIndexContext = if (store_hash) void else Context;
@@ -626,21 +165,6 @@ pub fn ArrayHashMapUnmanaged(
626
165
 
627
166
  const Oom = Allocator.Error;
628
167
 
629
- /// Convert from an unmanaged map to a managed map. After calling this,
630
- /// the promoted map should no longer be used.
631
- pub fn promote(self: Self, gpa: Allocator) Managed {
632
- if (@sizeOf(Context) != 0)
633
- @compileError("Cannot infer context " ++ @typeName(Context) ++ ", call promoteContext instead.");
634
- return self.promoteContext(gpa, undefined);
635
- }
636
- pub fn promoteContext(self: Self, gpa: Allocator, ctx: Context) Managed {
637
- return .{
638
- .unmanaged = self,
639
- .allocator = gpa,
640
- .ctx = ctx,
641
- };
642
- }
643
-
644
168
  pub fn init(gpa: Allocator, key_list: []const K, value_list: []const V) Oom!Self {
645
169
  var self: Self = .{};
646
170
  errdefer self.deinit(gpa);
@@ -756,8 +280,7 @@ pub fn ArrayHashMapUnmanaged(
756
280
  if (it.index >= it.len) return null;
757
281
  const result = Entry{
758
282
  .key_ptr = &it.keys[it.index],
759
- // workaround for #6974
760
- .value_ptr = if (@sizeOf(*V) == 0) undefined else &it.values[it.index],
283
+ .value_ptr = &it.values[it.index],
761
284
  };
762
285
  it.index += 1;
763
286
  return result;
@@ -799,8 +322,7 @@ pub fn ArrayHashMapUnmanaged(
799
322
  const slice = self.entries.slice();
800
323
  return GetOrPutResult{
801
324
  .key_ptr = &slice.items(.key)[index],
802
- // workaround for #6974
803
- .value_ptr = if (@sizeOf(*V) == 0) undefined else &slice.items(.value)[index],
325
+ .value_ptr = &slice.items(.value)[index],
804
326
  .found_existing = true,
805
327
  .index = index,
806
328
  };
@@ -845,8 +367,7 @@ pub fn ArrayHashMapUnmanaged(
845
367
  if (hashes_array[i] == h and checkedEql(ctx, key, item_key.*, i)) {
846
368
  return GetOrPutResult{
847
369
  .key_ptr = item_key,
848
- // workaround for #6974
849
- .value_ptr = if (@sizeOf(*V) == 0) undefined else &slice.items(.value)[i],
370
+ .value_ptr = &slice.items(.value)[i],
850
371
  .found_existing = true,
851
372
  .index = i,
852
373
  };
@@ -859,8 +380,7 @@ pub fn ArrayHashMapUnmanaged(
859
380
 
860
381
  return GetOrPutResult{
861
382
  .key_ptr = &keys_array.ptr[index],
862
- // workaround for #6974
863
- .value_ptr = if (@sizeOf(*V) == 0) undefined else &slice.items(.value).ptr[index],
383
+ .value_ptr = &slice.items(.value).ptr[index],
864
384
  .found_existing = false,
865
385
  .index = index,
866
386
  };
@@ -1045,8 +565,7 @@ pub fn ArrayHashMapUnmanaged(
1045
565
  const slice = self.entries.slice();
1046
566
  return Entry{
1047
567
  .key_ptr = &slice.items(.key)[index],
1048
- // workaround for #6974
1049
- .value_ptr = if (@sizeOf(*V) == 0) undefined else &slice.items(.value)[index],
568
+ .value_ptr = &slice.items(.value)[index],
1050
569
  };
1051
570
  }
1052
571
 
@@ -1110,8 +629,7 @@ pub fn ArrayHashMapUnmanaged(
1110
629
  }
1111
630
  pub fn getPtrAdapted(self: Self, key: anytype, ctx: anytype) ?*V {
1112
631
  const index = self.getIndexAdapted(key, ctx) orelse return null;
1113
- // workaround for #6974
1114
- return if (@sizeOf(*V) == 0) @as(*V, undefined) else &self.values()[index];
632
+ return &self.values()[index];
1115
633
  }
1116
634
 
1117
635
  /// Find the actual key associated with an adapted key
@@ -1790,8 +1308,7 @@ pub fn ArrayHashMapUnmanaged(
1790
1308
  return .{
1791
1309
  .found_existing = false,
1792
1310
  .key_ptr = &keys_array.ptr[new_index],
1793
- // workaround for #6974
1794
- .value_ptr = if (@sizeOf(*V) == 0) undefined else &values_array.ptr[new_index],
1311
+ .value_ptr = &values_array.ptr[new_index],
1795
1312
  .index = new_index,
1796
1313
  };
1797
1314
  }
@@ -1804,8 +1321,7 @@ pub fn ArrayHashMapUnmanaged(
1804
1321
  return .{
1805
1322
  .found_existing = true,
1806
1323
  .key_ptr = &keys_array[slot_data.entry_index],
1807
- // workaround for #6974
1808
- .value_ptr = if (@sizeOf(*V) == 0) undefined else &values_array[slot_data.entry_index],
1324
+ .value_ptr = &values_array[slot_data.entry_index],
1809
1325
  .index = slot_data.entry_index,
1810
1326
  };
1811
1327
  }
@@ -1846,8 +1362,7 @@ pub fn ArrayHashMapUnmanaged(
1846
1362
  return .{
1847
1363
  .found_existing = false,
1848
1364
  .key_ptr = &keys_array.ptr[new_index],
1849
- // workaround for #6974
1850
- .value_ptr = if (@sizeOf(*V) == 0) undefined else &values_array.ptr[new_index],
1365
+ .value_ptr = &values_array.ptr[new_index],
1851
1366
  .index = new_index,
1852
1367
  };
1853
1368
  }
@@ -2189,35 +1704,37 @@ const IndexHeader = struct {
2189
1704
  };
2190
1705
 
2191
1706
  test "basic hash map usage" {
2192
- var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
2193
- defer map.deinit();
1707
+ const gpa = testing.allocator;
2194
1708
 
2195
- try testing.expect((try map.fetchPut(1, 11)) == null);
2196
- try testing.expect((try map.fetchPut(2, 22)) == null);
2197
- try testing.expect((try map.fetchPut(3, 33)) == null);
2198
- try testing.expect((try map.fetchPut(4, 44)) == null);
1709
+ var map: Auto(i32, i32) = .empty;
1710
+ defer map.deinit(gpa);
1711
+
1712
+ try testing.expect((try map.fetchPut(gpa, 1, 11)) == null);
1713
+ try testing.expect((try map.fetchPut(gpa, 2, 22)) == null);
1714
+ try testing.expect((try map.fetchPut(gpa, 3, 33)) == null);
1715
+ try testing.expect((try map.fetchPut(gpa, 4, 44)) == null);
2199
1716
 
2200
- try map.putNoClobber(5, 55);
2201
- try testing.expect((try map.fetchPut(5, 66)).?.value == 55);
2202
- try testing.expect((try map.fetchPut(5, 55)).?.value == 66);
1717
+ try map.putNoClobber(gpa, 5, 55);
1718
+ try testing.expect((try map.fetchPut(gpa, 5, 66)).?.value == 55);
1719
+ try testing.expect((try map.fetchPut(gpa, 5, 55)).?.value == 66);
2203
1720
 
2204
- const gop1 = try map.getOrPut(5);
1721
+ const gop1 = try map.getOrPut(gpa, 5);
2205
1722
  try testing.expect(gop1.found_existing == true);
2206
1723
  try testing.expect(gop1.value_ptr.* == 55);
2207
1724
  try testing.expect(gop1.index == 4);
2208
1725
  gop1.value_ptr.* = 77;
2209
1726
  try testing.expect(map.getEntry(5).?.value_ptr.* == 77);
2210
1727
 
2211
- const gop2 = try map.getOrPut(99);
1728
+ const gop2 = try map.getOrPut(gpa, 99);
2212
1729
  try testing.expect(gop2.found_existing == false);
2213
1730
  try testing.expect(gop2.index == 5);
2214
1731
  gop2.value_ptr.* = 42;
2215
1732
  try testing.expect(map.getEntry(99).?.value_ptr.* == 42);
2216
1733
 
2217
- const gop3 = try map.getOrPutValue(5, 5);
1734
+ const gop3 = try map.getOrPutValue(gpa, 5, 5);
2218
1735
  try testing.expect(gop3.value_ptr.* == 77);
2219
1736
 
2220
- const gop4 = try map.getOrPutValue(100, 41);
1737
+ const gop4 = try map.getOrPutValue(gpa, 100, 41);
2221
1738
  try testing.expect(gop4.value_ptr.* == 41);
2222
1739
 
2223
1740
  try testing.expect(map.contains(2));
@@ -2234,7 +1751,7 @@ test "basic hash map usage" {
2234
1751
 
2235
1752
  // Since we've used `swapRemove` above, the index of this entry should remain unchanged.
2236
1753
  try testing.expect(map.getIndex(100).? == 1);
2237
- const gop5 = try map.getOrPut(5);
1754
+ const gop5 = try map.getOrPut(gpa, 5);
2238
1755
  try testing.expect(gop5.found_existing == true);
2239
1756
  try testing.expect(gop5.value_ptr.* == 77);
2240
1757
  try testing.expect(gop5.index == 4);
@@ -2247,7 +1764,7 @@ test "basic hash map usage" {
2247
1764
  try testing.expect(map.orderedRemove(100) == false);
2248
1765
  try testing.expect(map.getEntry(100) == null);
2249
1766
  try testing.expect(map.get(100) == null);
2250
- const gop6 = try map.getOrPut(5);
1767
+ const gop6 = try map.getOrPut(gpa, 5);
2251
1768
  try testing.expect(gop6.found_existing == true);
2252
1769
  try testing.expect(gop6.value_ptr.* == 77);
2253
1770
  try testing.expect(gop6.index == 3);
@@ -2256,15 +1773,17 @@ test "basic hash map usage" {
2256
1773
  }
2257
1774
 
2258
1775
  test "iterator hash map" {
2259
- var reset_map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
2260
- defer reset_map.deinit();
1776
+ const gpa = testing.allocator;
1777
+
1778
+ var reset_map: Auto(i32, i32) = .empty;
1779
+ defer reset_map.deinit(gpa);
2261
1780
 
2262
1781
  // test ensureTotalCapacity with a 0 parameter
2263
- try reset_map.ensureTotalCapacity(0);
1782
+ try reset_map.ensureTotalCapacity(gpa, 0);
2264
1783
 
2265
- try reset_map.putNoClobber(0, 11);
2266
- try reset_map.putNoClobber(1, 22);
2267
- try reset_map.putNoClobber(2, 33);
1784
+ try reset_map.putNoClobber(gpa, 0, 11);
1785
+ try reset_map.putNoClobber(gpa, 1, 22);
1786
+ try reset_map.putNoClobber(gpa, 2, 33);
2268
1787
 
2269
1788
  const keys = [_]i32{
2270
1789
  0, 2, 1,
@@ -2312,10 +1831,12 @@ test "iterator hash map" {
2312
1831
  }
2313
1832
 
2314
1833
  test "ensure capacity" {
2315
- var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
2316
- defer map.deinit();
1834
+ const gpa = testing.allocator;
2317
1835
 
2318
- try map.ensureTotalCapacity(20);
1836
+ var map: Auto(i32, i32) = .empty;
1837
+ defer map.deinit(gpa);
1838
+
1839
+ try map.ensureTotalCapacity(gpa, 20);
2319
1840
  const initial_capacity = map.capacity();
2320
1841
  try testing.expect(initial_capacity >= 20);
2321
1842
  var i: i32 = 0;
@@ -2329,23 +1850,25 @@ test "ensure capacity" {
2329
1850
  test "ensure capacity leak" {
2330
1851
  try testing.checkAllAllocationFailures(std.testing.allocator, struct {
2331
1852
  pub fn f(allocator: Allocator) !void {
2332
- var map = AutoArrayHashMap(i32, i32).init(allocator);
2333
- defer map.deinit();
1853
+ var map: Auto(i32, i32) = .empty;
1854
+ defer map.deinit(allocator);
2334
1855
 
2335
1856
  var i: i32 = 0;
2336
1857
  // put more than `linear_scan_max` in so index_header gets allocated.
2337
- while (i <= 20) : (i += 1) try map.put(i, i);
1858
+ while (i <= 20) : (i += 1) try map.put(allocator, i, i);
2338
1859
  }
2339
1860
  }.f, .{});
2340
1861
  }
2341
1862
 
2342
1863
  test "big map" {
2343
- var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
2344
- defer map.deinit();
1864
+ const gpa = testing.allocator;
1865
+
1866
+ var map: Auto(i32, i32) = .empty;
1867
+ defer map.deinit(gpa);
2345
1868
 
2346
1869
  var i: i32 = 0;
2347
1870
  while (i < 8) : (i += 1) {
2348
- try map.put(i, i + 10);
1871
+ try map.put(gpa, i, i + 10);
2349
1872
  }
2350
1873
 
2351
1874
  i = 0;
@@ -2358,7 +1881,7 @@ test "big map" {
2358
1881
 
2359
1882
  i = 4;
2360
1883
  while (i < 12) : (i += 1) {
2361
- try map.put(i, i + 12);
1884
+ try map.put(gpa, i, i + 12);
2362
1885
  }
2363
1886
 
2364
1887
  i = 0;
@@ -2393,17 +1916,19 @@ test "big map" {
2393
1916
  }
2394
1917
 
2395
1918
  test "clone" {
2396
- var original = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
2397
- defer original.deinit();
1919
+ const gpa = testing.allocator;
1920
+
1921
+ var original: Auto(i32, i32) = .empty;
1922
+ defer original.deinit(gpa);
2398
1923
 
2399
1924
  // put more than `linear_scan_max` so we can test that the index header is properly cloned
2400
1925
  var i: u8 = 0;
2401
1926
  while (i < 10) : (i += 1) {
2402
- try original.putNoClobber(i, i * 10);
1927
+ try original.putNoClobber(gpa, i, i * 10);
2403
1928
  }
2404
1929
 
2405
- var copy = try original.clone();
2406
- defer copy.deinit();
1930
+ var copy = try original.clone(gpa);
1931
+ defer copy.deinit(gpa);
2407
1932
 
2408
1933
  i = 0;
2409
1934
  while (i < 10) : (i += 1) {
@@ -2419,16 +1944,18 @@ test "clone" {
2419
1944
  }
2420
1945
 
2421
1946
  test "shrink" {
2422
- var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
2423
- defer map.deinit();
1947
+ const gpa = testing.allocator;
1948
+
1949
+ var map: Auto(i32, i32) = .empty;
1950
+ defer map.deinit(gpa);
2424
1951
 
2425
1952
  // This test is more interesting if we insert enough entries to allocate the index header.
2426
1953
  const num_entries = 200;
2427
1954
  var i: i32 = 0;
2428
1955
  while (i < num_entries) : (i += 1)
2429
- try testing.expect((try map.fetchPut(i, i * 10)) == null);
1956
+ try testing.expect((try map.fetchPut(gpa, i, i * 10)) == null);
2430
1957
 
2431
- try testing.expect(map.unmanaged.index_header != null);
1958
+ try testing.expect(map.index_header != null);
2432
1959
  try testing.expect(map.count() == num_entries);
2433
1960
 
2434
1961
  // Test `shrinkRetainingCapacity`.
@@ -2437,7 +1964,7 @@ test "shrink" {
2437
1964
  try testing.expect(map.capacity() >= num_entries);
2438
1965
  i = 0;
2439
1966
  while (i < num_entries) : (i += 1) {
2440
- const gop = try map.getOrPut(i);
1967
+ const gop = try map.getOrPut(gpa, i);
2441
1968
  if (i < 17) {
2442
1969
  try testing.expect(gop.found_existing == true);
2443
1970
  try testing.expect(gop.value_ptr.* == i * 10);
@@ -2445,12 +1972,12 @@ test "shrink" {
2445
1972
  }
2446
1973
 
2447
1974
  // Test `shrinkAndFree`.
2448
- map.shrinkAndFree(15);
1975
+ map.shrinkAndFree(gpa, 15);
2449
1976
  try testing.expect(map.count() == 15);
2450
1977
  try testing.expect(map.capacity() == 15);
2451
1978
  i = 0;
2452
1979
  while (i < num_entries) : (i += 1) {
2453
- const gop = try map.getOrPut(i);
1980
+ const gop = try map.getOrPut(gpa, i);
2454
1981
  if (i < 15) {
2455
1982
  try testing.expect(gop.found_existing == true);
2456
1983
  try testing.expect(gop.value_ptr.* == i * 10);
@@ -2459,15 +1986,17 @@ test "shrink" {
2459
1986
  }
2460
1987
 
2461
1988
  test "pop()" {
2462
- var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
2463
- defer map.deinit();
1989
+ const gpa = testing.allocator;
1990
+
1991
+ var map: Auto(i32, i32) = .empty;
1992
+ defer map.deinit(gpa);
2464
1993
 
2465
1994
  // Insert just enough entries so that the map expands. Afterwards,
2466
1995
  // pop all entries out of the map.
2467
1996
 
2468
1997
  var i: i32 = 0;
2469
1998
  while (i < 9) : (i += 1) {
2470
- try testing.expect((try map.fetchPut(i, i)) == null);
1999
+ try testing.expect((try map.fetchPut(gpa, i, i)) == null);
2471
2000
  }
2472
2001
 
2473
2002
  while (map.pop()) |pop| {
@@ -2479,31 +2008,33 @@ test "pop()" {
2479
2008
  }
2480
2009
 
2481
2010
  test "reIndex" {
2482
- var map = ArrayHashMap(i32, i32, AutoContext(i32), true).init(std.testing.allocator);
2483
- defer map.deinit();
2011
+ const gpa = testing.allocator;
2012
+
2013
+ var map: Custom(i32, i32, AutoContext(i32), true) = .empty;
2014
+ defer map.deinit(gpa);
2484
2015
 
2485
2016
  // Populate via the API.
2486
2017
  const num_indexed_entries = 200;
2487
2018
  var i: i32 = 0;
2488
2019
  while (i < num_indexed_entries) : (i += 1)
2489
- try testing.expect((try map.fetchPut(i, i * 10)) == null);
2020
+ try testing.expect((try map.fetchPut(gpa, i, i * 10)) == null);
2490
2021
 
2491
2022
  // Make sure we allocated an index header.
2492
- try testing.expect(map.unmanaged.index_header != null);
2023
+ try testing.expect(map.index_header != null);
2493
2024
 
2494
2025
  // Now write to the arrays directly.
2495
2026
  const num_unindexed_entries = 20;
2496
- try map.unmanaged.entries.resize(std.testing.allocator, num_indexed_entries + num_unindexed_entries);
2027
+ try map.entries.resize(std.testing.allocator, num_indexed_entries + num_unindexed_entries);
2497
2028
  for (map.keys()[num_indexed_entries..], map.values()[num_indexed_entries..], num_indexed_entries..) |*key, *value, j| {
2498
2029
  key.* = @intCast(j);
2499
2030
  value.* = @intCast(j * 10);
2500
2031
  }
2501
2032
 
2502
2033
  // After reindexing, we should see everything.
2503
- try map.reIndex();
2034
+ try map.reIndex(gpa);
2504
2035
  i = 0;
2505
2036
  while (i < num_indexed_entries + num_unindexed_entries) : (i += 1) {
2506
- const gop = try map.getOrPut(i);
2037
+ const gop = try map.getOrPut(gpa, i);
2507
2038
  try testing.expect(gop.found_existing == true);
2508
2039
  try testing.expect(gop.value_ptr.* == i * 10);
2509
2040
  try testing.expect(gop.index == i);
@@ -2511,23 +2042,20 @@ test "reIndex" {
2511
2042
  }
2512
2043
 
2513
2044
  test "auto store_hash" {
2514
- const HasCheapEql = AutoArrayHashMap(i32, i32);
2515
- const HasExpensiveEql = AutoArrayHashMap([32]i32, i32);
2045
+ const HasCheapEql = Auto(i32, i32);
2046
+ const HasExpensiveEql = Auto([32]i32, i32);
2516
2047
  try testing.expect(@FieldType(HasCheapEql.Data, "hash") == void);
2517
2048
  try testing.expect(@FieldType(HasExpensiveEql.Data, "hash") != void);
2518
-
2519
- const HasCheapEqlUn = AutoArrayHashMapUnmanaged(i32, i32);
2520
- const HasExpensiveEqlUn = AutoArrayHashMapUnmanaged([32]i32, i32);
2521
- try testing.expect(@FieldType(HasCheapEqlUn.Data, "hash") == void);
2522
- try testing.expect(@FieldType(HasExpensiveEqlUn.Data, "hash") != void);
2523
2049
  }
2524
2050
 
2525
2051
  test "sort" {
2526
- var map = AutoArrayHashMap(i32, i32).init(std.testing.allocator);
2527
- defer map.deinit();
2052
+ const gpa = testing.allocator;
2053
+
2054
+ var map: Auto(i32, i32) = .empty;
2055
+ defer map.deinit(gpa);
2528
2056
 
2529
2057
  for ([_]i32{ 8, 3, 12, 10, 2, 4, 9, 5, 6, 13, 14, 15, 16, 1, 11, 17, 7 }) |x| {
2530
- try map.put(x, x * 3);
2058
+ try map.put(gpa, x, x * 3);
2531
2059
  }
2532
2060
 
2533
2061
  const C = struct {
@@ -2549,15 +2077,17 @@ test "sort" {
2549
2077
  }
2550
2078
 
2551
2079
  test "0 sized key" {
2552
- var map = AutoArrayHashMap(u0, i32).init(std.testing.allocator);
2553
- defer map.deinit();
2080
+ const gpa = testing.allocator;
2081
+
2082
+ var map: Auto(u0, i32) = .empty;
2083
+ defer map.deinit(gpa);
2554
2084
 
2555
2085
  try testing.expectEqual(map.get(0), null);
2556
2086
 
2557
- try map.put(0, 5);
2087
+ try map.put(gpa, 0, 5);
2558
2088
  try testing.expectEqual(map.get(0), 5);
2559
2089
 
2560
- try map.put(0, 10);
2090
+ try map.put(gpa, 0, 10);
2561
2091
  try testing.expectEqual(map.get(0), 10);
2562
2092
 
2563
2093
  try testing.expectEqual(map.swapRemove(0), true);
@@ -2565,12 +2095,14 @@ test "0 sized key" {
2565
2095
  }
2566
2096
 
2567
2097
  test "0 sized key and 0 sized value" {
2568
- var map = AutoArrayHashMap(u0, u0).init(std.testing.allocator);
2569
- defer map.deinit();
2098
+ const gpa = testing.allocator;
2099
+
2100
+ var map: Auto(u0, u0) = .empty;
2101
+ defer map.deinit(gpa);
2570
2102
 
2571
2103
  try testing.expectEqual(map.get(0), null);
2572
2104
 
2573
- try map.put(0, 0);
2105
+ try map.put(gpa, 0, 0);
2574
2106
  try testing.expectEqual(map.get(0), 0);
2575
2107
 
2576
2108
  try testing.expectEqual(map.swapRemove(0), true);
@@ -2580,7 +2112,7 @@ test "0 sized key and 0 sized value" {
2580
2112
  test "setKey storehash true" {
2581
2113
  const gpa = std.testing.allocator;
2582
2114
 
2583
- var map: ArrayHashMapUnmanaged(i32, i32, AutoContext(i32), true) = .empty;
2115
+ var map: ArrayHashMap(i32, i32, AutoContext(i32), true) = .empty;
2584
2116
  defer map.deinit(gpa);
2585
2117
 
2586
2118
  try map.put(gpa, 12, 34);
@@ -2596,7 +2128,7 @@ test "setKey storehash true" {
2596
2128
  test "setKey storehash false" {
2597
2129
  const gpa = std.testing.allocator;
2598
2130
 
2599
- var map: ArrayHashMapUnmanaged(i32, i32, AutoContext(i32), false) = .empty;
2131
+ var map: ArrayHashMap(i32, i32, AutoContext(i32), false) = .empty;
2600
2132
  defer map.deinit(gpa);
2601
2133
 
2602
2134
  try map.put(gpa, 12, 34);
@@ -2691,7 +2223,7 @@ pub fn getAutoHashStratFn(comptime K: type, comptime Context: type, comptime str
2691
2223
  test "orderedRemoveAtMany" {
2692
2224
  const gpa = testing.allocator;
2693
2225
 
2694
- var map: AutoArrayHashMapUnmanaged(usize, void) = .empty;
2226
+ var map: Auto(usize, void) = .empty;
2695
2227
  defer map.deinit(gpa);
2696
2228
 
2697
2229
  for (0..10) |n| {