Skip to content

Sema: cap depth of value printing in type names #19682

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2024

Conversation

mlugg
Copy link
Member

@mlugg mlugg commented Apr 17, 2024

Certain types (notably, std.ComptimeStringMap) were resulting in excessively long type names when instantiated, which in turn resulted in excessively long symbol names. These are problematic for two reasons:

  • Symbol names are sometimes read by humans -- they ought to be readable.
  • Some other applications (looking at you, xcode) trip on very long symbol names.

To work around this for now, we cap the depth of value printing at 1, as opposed to the normal 3. This doesn't guarantee anything -- there could still be, for instance, an incredibly long aggregate -- but it works around the issue in practice for the time being.

Certain types (notably, `std.ComptimeStringMap`) were resulting in excessively
long type names when instantiated, which in turn resulted in excessively long
symbol names. These are problematic for two reasons:

* Symbol names are sometimes read by humans -- they ought to be readable.
* Some other applications (looking at you, xcode) trip on very long symbol names.

To work around this for now, we cap the depth of value printing at 1, as opposed
to the normal 3. This doesn't guarantee anything -- there could still be, for
instance, an incredibly long aggregate -- but it works around the issue in
practice for the time being.
@andrewrk andrewrk enabled auto-merge (rebase) April 18, 2024 01:08
@mitchellh
Copy link
Contributor

mitchellh commented Apr 18, 2024

I can confirm that this fixes Ghostty's build issues from main.

@andrewrk andrewrk merged commit 21a6a1b into ziglang:master Apr 18, 2024
@travisstaloch
Copy link
Contributor

travisstaloch commented Apr 18, 2024

@mlugg would it be helpful to have a different version of std.ComptimeStringMap which takes only a single type param and moves the kvs_list param to an init() method? That way, std.ComptimeStringMap(T) would return a struct with well defined fields in a more standard fashion. I believe this would make its type name much shorter.

I mention because I've just been working on that here. Currently i've got all the original tests passing and also added initRuntime(allocator) and getPartial(str) methods.

travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch makes ComptimeStringMap accept only a single type parameter
and return a known struct type instead of an anonymous struct.  initial
motivation for these changes was to reduce the 'very long type names'
issue described here ziglang#19682.

* move `kvs_list` param from type param to an `init()` param
* adds new public methods which i'm not sure belong but have left in for
  now incase they are deemed useful.
  * `getPartial(str)`, `getIndexPartial(str)`, `initRuntime(allocator)`,
    `deinit(allocator)`
  * includes test coverage for all
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch makes ComptimeStringMap accept only a single type parameter
and return a known struct type instead of an anonymous struct.  initial
motivation for these changes was to reduce the 'very long type names'
issue described here ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.ComptimeStringMap(T).init(kvs_list);`

* move `kvs_list` param from type param to an `init()` param
* adds new public methods which i'm not sure belong but have left in for
  now incase they are deemed useful.
  * `getPartial(str)`, `getIndexPartial(str)`, `initRuntime(allocator)`,
    `deinit(allocator)`
  * includes test coverage for all
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch makes ComptimeStringMap accept only a single type parameter
and return a known struct type instead of an anonymous struct.  initial
motivation for these changes was to reduce the 'very long type names'
issue described here ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.ComptimeStringMap(T).init(kvs_list);`

* move `kvs_list` param from type param to an `init()` param
* adds new public convenience helpers `keys()` and `values()`
* adds new public methods which i'm not sure belong but have left in for
  now incase they are deemed useful.
  * `getPartial(str)`, `getIndexPartial(str)`, `initRuntime(allocator)`,
    `deinit(allocator)`
  * includes test coverage for all
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch makes ComptimeStringMap accept only a single type parameter
and return a known struct type instead of an anonymous struct.  initial
motivation for these changes was to reduce the 'very long type names'
issue described here ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.ComptimeStringMap(T).init(kvs_list);`

* move `kvs_list` param from type param to an `init()` param
* adds new public convenience helpers `keys()` and `values()`
* adds new public methods which i'm not sure belong but have left in for
  now incase they are deemed useful.
  * `getPartial(str)`, `getIndexPartial(str)`, `initRuntime(allocator)`,
    `deinit(allocator)`
  * includes test coverage for all
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full
    poop output in link above.
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch renames ComptimeStringMap to StaticStringMap, makes it
accept only a single type parameter, and return a known struct type
instead of an anonymous struct.  initial motivation for these changes
was to reduce the 'very long type names' issue described here
ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.ComptimeStringMap(T).initComptime(kvs_list);`

* move `kvs_list` param from type param to an `initComptime()` param
* adds new public convenience helpers `keys()` and `values()`
* adds new public methods which i'm not sure belong but have left in for
  now incase they are deemed useful.
  * `getPartial(str)`, `getIndexPartial(str)`, `init(allocator)`,
    `deinit(allocator)`
  * includes test coverage for all
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full
    poop output in link above.
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch renames ComptimeStringMap to StaticStringMap, makes it
accept only a single type parameter, and return a known struct type
instead of an anonymous struct.  initial motivation for these changes
was to reduce the 'very long type names' issue described here
ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.StaticStringMap(T).initComptime(kvs_list);`

* move `kvs_list` param from type param to an `initComptime()` param
* adds new public convenience helpers `keys()` and `values()`
* adds new public methods which i'm not sure belong but have left in for
  now incase they are deemed useful.
  * `getPartial(str)`, `getIndexPartial(str)`, `init(allocator)`,
    `deinit(allocator)`
  * includes test coverage for all
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full
    poop output in link above.
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch renames ComptimeStringMap to StaticStringMap, makes it
accept only a single type parameter, and return a known struct type
instead of an anonymous struct.  initial motivation for these changes
was to reduce the 'very long type names' issue described here
ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.StaticStringMap(T).initComptime(kvs_list);`

* move `kvs_list` param from type param to an `initComptime()` param
* adds new public convenience helpers `keys()` and `values()`
* adds new public methods which i'm not sure belong but have left in for
  now incase they are deemed useful.
  * `getPartial(str)`, `getIndexPartial(str)`, `initRuntime(allocator)`,
    `deinit(allocator)`
  * includes test coverage for all
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full
    poop output in link above.
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch renames ComptimeStringMap to StaticStringMap, makes it
accept only a single type parameter, and return a known struct type
instead of an anonymous struct.  initial motivation for these changes
was to reduce the 'very long type names' issue described here
ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.StaticStringMap(T).initComptime(kvs_list);`

* move `kvs_list` param from type param to an `initComptime()` param
* adds new public convenience helpers `keys()` and `values()`
* adds new public methods which i'm not sure belong but have left in for
  now incase they are deemed useful.
  * `getPartial(str)`, `getIndexPartial(str)`, `initRuntime(allocator)`,
    `deinit(allocator)`
  * includes test coverage for all
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full
    poop output in link above.
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch renames ComptimeStringMap to StaticStringMap, makes it
accept only a single type parameter, and return a known struct type
instead of an anonymous struct.  initial motivation for these changes
was to reduce the 'very long type names' issue described here
ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.StaticStringMap(T).initComptime(kvs_list);`

* move `kvs_list` param from type param to an `initComptime()` param
* adds new public convenience helpers `keys()` and `values()`
* adds new public methods which i'm not sure belong but have left in for
  now incase they are deemed useful.
  * `getPartial(str)`, `getIndexPartial(str)`, `initRuntime(allocator)`,
    `deinit(allocator)`
  * includes test coverage for all
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full
    poop output in link above.
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch renames ComptimeStringMap to StaticStringMap, makes it
accept only a single type parameter, and return a known struct type
instead of an anonymous struct.  initial motivation for these changes
was to reduce the 'very long type names' issue described here
ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.StaticStringMap(T).initComptime(kvs_list);`

* move `kvs_list` param from type param to an `initComptime()` param
* adds new public convenience helpers `keys()` and `values()`
* adds new public methods which i'm not sure belong but have left in for
  now incase they are deemed useful.
  * `getPartial(str)`, `getIndexPartial(str)`, `initRuntime(allocator)`,
    `deinit(allocator)`
  * includes test coverage for all
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full
    poop output in link above.
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch renames ComptimeStringMap to StaticStringMap, makes it
accept only a single type parameter, and return a known struct type
instead of an anonymous struct.  initial motivation for these changes
was to reduce the 'very long type names' issue described here
ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.StaticStringMap(T).initComptime(kvs_list);`

* move `kvs_list` param from type param to an `initComptime()` param
* adds new public convenience helpers `keys()` and `values()`
* adds new public methods which i'm not sure belong but have left in for
  now incase they are deemed useful.
  * `getPartial(str)`, `getIndexPartial(str)`, `initRuntime(allocator)`,
    `deinit(allocator)`
  * includes test coverage for all
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full
    poop output in link above.
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch renames ComptimeStringMap to StaticStringMap, makes it
accept only a single type parameter, and return a known struct type
instead of an anonymous struct.  initial motivation for these changes
was to reduce the 'very long type names' issue described here
ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.StaticStringMap(T).initComptime(kvs_list);`

* move `kvs_list` param from type param to an `initComptime()` param
* new public methods
  * `keys()`, `values()` helpers
	* `init(allocator)`, `deinit(allocator)` for runtime data
  * `getLongestPrefix(str)`, `getLongestPrefixIndex(str)` - i'm not sure
     these belong but have left in for now incase they are deemed useful
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed a speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full
    output in link above.
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 21, 2024
this patch renames ComptimeStringMap to StaticStringMap, makes it
accept only a single type parameter, and return a known struct type
instead of an anonymous struct.  initial motivation for these changes
was to reduce the 'very long type names' issue described here
ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.StaticStringMap(T).initComptime(kvs_list);`

* move `kvs_list` param from type param to an `initComptime()` param
* new public methods
  * `keys()`, `values()` helpers
  * `init(allocator)`, `deinit(allocator)` for runtime data
  * `getLongestPrefix(str)`, `getLongestPrefixIndex(str)` - i'm not sure
     these belong but have left in for now incase they are deemed useful
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed a speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full
    output in link above.
travisstaloch added a commit to travisstaloch/zig that referenced this pull request Apr 22, 2024
this patch renames ComptimeStringMap to StaticStringMap, makes it
accept only a single type parameter, and return a known struct type
instead of an anonymous struct.  initial motivation for these changes
was to reduce the 'very long type names' issue described here
ziglang#19682.

this breaks the previous API.  users will now need to write:
`const map = std.StaticStringMap(T).initComptime(kvs_list);`

* move `kvs_list` param from type param to an `initComptime()` param
* new public methods
  * `keys()`, `values()` helpers
  * `init(allocator)`, `deinit(allocator)` for runtime data
  * `getLongestPrefix(str)`, `getLongestPrefixIndex(str)` - i'm not sure
     these belong but have left in for now incase they are deemed useful
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed a speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full
    output in link above.
andrewrk pushed a commit that referenced this pull request Apr 22, 2024
this patch renames ComptimeStringMap to StaticStringMap, makes it
accept only a single type parameter, and return a known struct type
instead of an anonymous struct.  initial motivation for these changes
was to reduce the 'very long type names' issue described here
#19682.

this breaks the previous API.  users will now need to write:
`const map = std.StaticStringMap(T).initComptime(kvs_list);`

* move `kvs_list` param from type param to an `initComptime()` param
* new public methods
  * `keys()`, `values()` helpers
  * `init(allocator)`, `deinit(allocator)` for runtime data
  * `getLongestPrefix(str)`, `getLongestPrefixIndex(str)` - i'm not sure
     these belong but have left in for now incase they are deemed useful
* performance notes:
  * i posted some benchmarking results here:
    https://github.com/travisstaloch/comptime-string-map-revised/issues/1
  * i noticed a speedup reducing the size of the struct from 48 to 32
    bytes and thus use u32s instead of usize for all length fields
  * i noticed speedup storing KVs as a struct of arrays
  * latest benchmark shows these wall_time improvements for
    debug/safe/small/fast builds: -6.6% / -10.2% / -19.1% / -8.9%. full
    output in link above.
@mlugg mlugg deleted the cap-type-name-value-depth branch May 18, 2025 20:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants