diff options
| author | 2025-04-30 20:30:39 -0400 | |
|---|---|---|
| committer | 2025-04-30 20:30:39 -0400 | |
| commit | 10048b0d31d0db923ae39c6bbd67139ed6252f6f (patch) | |
| tree | 65df1666aacd102f59b4ac0844ccc7f7ddda91db /NEWS.md | |
| parent | Setup variants for all allocating modules (diff) | |
| download | zg-10048b0d31d0db923ae39c6bbd67139ed6252f6f.tar.gz zg-10048b0d31d0db923ae39c6bbd67139ed6252f6f.tar.xz zg-10048b0d31d0db923ae39c6bbd67139ed6252f6f.zip | |
Allocation Failure Tests
These turned up an excessive amount of allocations in CanonData and
CompatData, which have been reduced to two through the somewhat
squirrely use of 'magic numbers'.
There are now allocation tests for every allocated structure in the
library, and they run to completion in a reasonable amount of time.
So, that's nice.
Diffstat (limited to 'NEWS.md')
| -rw-r--r-- | NEWS.md | 115 |
1 files changed, 101 insertions, 14 deletions
| @@ -4,24 +4,56 @@ | |||
| 4 | 4 | ||
| 5 | This is the first minor point release since Sam Atman (me) took over | 5 | This is the first minor point release since Sam Atman (me) took over |
| 6 | maintenance of `zg` from the inimitable José Colon, aka | 6 | maintenance of `zg` from the inimitable José Colon, aka |
| 7 | @dude_the_builder. | 7 | @dude_the_builder. We're all grateful for everything he's done for |
| 8 | the Zig community. | ||
| 8 | 9 | ||
| 9 | As it's a fairly complex project, I'm adding a NEWS.md so that users | 10 | The changes are fairly large, and most user code will need to be updated. |
| 10 | have a place to check for changes. | 11 | The result is substantially streamlined and easier to use, and updating |
| 12 | will mainly take place around importing, creating, and deinitializing. | ||
| 11 | 13 | ||
| 12 | ### Data is Unmanaged | 14 | ### The Great Renaming |
| 13 | 15 | ||
| 14 | This is the biggest change. Prior to `v0.14`, all structs which need | 16 | The most obvious change is on the surface API: more than half of the modules |
| 15 | heap allocation no longer have a copy of their allocator. It was felt | 17 | have been renamed. There are no user-facing modules with `Data` in the name, |
| 16 | that this was redundant, especially when several such structures were | 18 | and some abbreviations have been spelled in full. |
| 17 | in use, and it reflects a general trend in the standard library toward | 19 | |
| 18 | fewer managed data structures. | 20 | ### No More Separation of Data and Functionality |
| 21 | |||
| 22 | It is no longer necessary to separately create, for example, a `GraphemeData` | ||
| 23 | structure, in order to use the functionality provided by the `grapheme` | ||
| 24 | module. | ||
| 25 | |||
| 26 | Instead there's just `Graphemes`, and the same for a couple of other modules | ||
| 27 | which worked the same way. This means that the cases where functionality | ||
| 28 | was provided by a wrapped pointer is not provided directly from the struct | ||
| 29 | with the necessary data. | ||
| 30 | |||
| 31 | This would make user structs larger in some cases, while eliminating a | ||
| 32 | pointer chase. If that isn't a desirable trade off for your code, | ||
| 33 | read on. | ||
| 34 | |||
| 35 | ### All Allocated Data is Unmanaged | ||
| 36 | |||
| 37 | Prior to `v0.14`, all structs which need heap allocation no longer | ||
| 38 | have a copy of their allocator. We felt that this was redundant, | ||
| 39 | especially when several such structures were in use, and it reflects | ||
| 40 | a general trend in the standard library toward fewer managed data | ||
| 41 | structures. | ||
| 19 | 42 | ||
| 20 | Getting up to speed is a matter of passing the allocator to `deinit`. | 43 | Getting up to speed is a matter of passing the allocator to `deinit`. |
| 21 | 44 | ||
| 22 | This change comes courtesy of [lch361](https://lch361.net), in his | 45 | This change comes courtesy of [lch361](https://lch361.net), in his |
| 23 | first contribution to the repo. Thanks Lich! | 46 | first contribution to the repo. Thanks Lich! |
| 24 | 47 | ||
| 48 | ### DisplayWidth and CaseFolding Can Share Data | ||
| 49 | |||
| 50 | Both of these modules use another module to get the job done, `Graphemes` | ||
| 51 | for `DisplayWidth`, and `Normalize` for `CaseFolding`. | ||
| 52 | |||
| 53 | It is now possible to initialize them with a borrowed copy of those | ||
| 54 | modules, to make it simpler to write code which also needs the base | ||
| 55 | modules. | ||
| 56 | |||
| 25 | ### Grapheme Iterator Creation | 57 | ### Grapheme Iterator Creation |
| 26 | 58 | ||
| 27 | This is a modest streamlining of how a grapheme iterator is created. | 59 | This is a modest streamlining of how a grapheme iterator is created. |
| @@ -37,10 +69,65 @@ var iter = grapheme.Iterator.init("🤘🏻some rad string! 🤘🏿", &gd); | |||
| 37 | Now: | 69 | Now: |
| 38 | 70 | ||
| 39 | ```zig | 71 | ```zig |
| 40 | const gd = try grapheme.GraphemeData.init(allocator); | 72 | const graphemes = try Graphemes.init(allocator); |
| 41 | defer gd.deinit(allocator); | 73 | defer graphemes.deinit(allocator); |
| 42 | var iter = gd.iterator("🤘🏻some rad string! 🤘🏿"); | 74 | var iter = graphemes.iterator("🤘🏻some rad string! 🤘🏿"); |
| 43 | ``` | 75 | ``` |
| 44 | 76 | ||
| 45 | You can still make an iterator with `grapheme.Iterator.init`, but the | 77 | It remains possible to use |
| 46 | second argument has to be `&gd.gd`. | 78 | |
| 79 | ```zig | ||
| 80 | var iter = Graphemes.Iterator.init("stri̵̢̡̡̡̨̧̡̨̡̡̡̨̫̗̗̱̳̼̖͚͉̩̬̬͚̟̣̮̬̙̖̗͇̮͓̻̫͍͎͉͎̹̩̗͖͈̙̻̭̝̭̼̙̯̪͚̙͉͎͎͖̥̹͈̫͍̹͓̘̙͎͖̝̦͎̤̼̹͕͈̪̙̪̯̯͙̝͈͕̬̪̗̭͎͖̟͚̦̣̘͙̞̮̹̙͚̼̤̟͉̭͔̩͍͔͈̯͎̘͎̭̥̖̜͙̖̖͍̼͙͎͚̦̮̹̞̺͍̳̖̹̼̲̠̩̰̳͂̌̈́̓̄͋̇̎͜͜͠ͅͅͅͅng", &graphemes); | ||
| 81 | ``` | ||
| 82 | |||
| 83 | If one were to prefer doing so. | ||
| 84 | |||
| 85 | ### Initialization vs. Setup | ||
| 86 | |||
| 87 | Every allocating module now has both an `init` function, which | ||
| 88 | returns the created struct, and a `setup` function. The latter | ||
| 89 | takes a mutable pointer, and an `Allocator`, returning | ||
| 90 | `Allocator.Error!void`. | ||
| 91 | |||
| 92 | So those who might prefer a single-pointer home for such modules | ||
| 93 | can allocate the struct on the heap with `allocator.create`, or | ||
| 94 | add a pointer field to some other struct, then use `setup` to | ||
| 95 | populate it. | ||
| 96 | |||
| 97 | In the process, the various spurious reader and decompression errors | ||
| 98 | have been turned `unreachable`, leaving only `error.OutOfMemory`. | ||
| 99 | Encountering any of the other errors would indicate an internal problem, | ||
| 100 | so we no longer make user code deal with that unlikely event. | ||
| 101 | |||
| 102 | ### New DisplayWidth options | ||
| 103 | |||
| 104 | A `DisplayWidth` can now be compiled to treat `c0` and `c1` control codes | ||
| 105 | as having a width. Canonically, terminals don't print them, so they would | ||
| 106 | have a width of 0. However, some applications (`vim` for example) need to | ||
| 107 | escape control codes to make them visible. Setting these options will let | ||
| 108 | `DisplayWidth` return the correct widths when this is done. | ||
| 109 | |||
| 110 | ### Unicode 16.0 | ||
| 111 | |||
| 112 | This updates `zg` to use the latest Unicode edition. This should be | ||
| 113 | the only change which will change behavior of user code, other than through | ||
| 114 | the use of the new `DisplayWidth` options. | ||
| 115 | |||
| 116 | ### Tests | ||
| 117 | |||
| 118 | Is is now possible to run all the tests, not just the `unicode-test` subset. | ||
| 119 | Accordingly, that step is removed, and `zig build test` runs everything. | ||
| 120 | |||
| 121 | #### Allocations Tested | ||
| 122 | |||
| 123 | Every allocate-able now has a `checkAllAllocationFailures` test. This | ||
| 124 | process turned up two bugs. Also discovered were 8,663 allocations which | ||
| 125 | were reduced to two, these were also being individually freed on deinit. | ||
| 126 | So that's nice. | ||
| 127 | |||
| 128 | #### That's It! | ||
| 129 | |||
| 130 | I hope you find converting over `zg v0.13` code to be fairly painless and | ||
| 131 | straightforward. There should be no need to make changes of this magnitude | ||
| 132 | in the future. | ||
| 133 | |||