zig icon indicating copy to clipboard operation
zig copied to clipboard

std: json.parseFromValue()

Open thejoshwolfe opened this issue 1 year ago • 3 comments

To support this case: https://github.com/ziglang/zig/pull/15705#issuecomment-1551800247

Adding a parseFromValue() including a custom parse function means that we can parse complex json documents with polymorphic objects by using custom code to determine which union item things should be. See test "polymorphic parsing" for an example.

thejoshwolfe avatar Jun 08 '23 15:06 thejoshwolfe

@matu3ba are you game to add these to compiler-rt?

error: ld.lld: undefined symbol: __fixkfti
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/0bbda7e5a922a3ea118795e1c05547cb/test.o:(json.static.sliceToInt__anon_338634)
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/0bbda7e5a922a3ea118795e1c05547cb/test.o:(json.static.sliceToInt__anon_338637)
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/0bbda7e5a922a3ea118795e1c05547cb/test.o:(json.static.sliceToInt__anon_408252)
    note: referenced 4 more times
    note: did you mean: __fixdfti
    note: defined in: /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-global-cache/o/ef3f74ff72425e6d13da4960cdf5bcea/libcompiler_rt.a(/home/ci/actions-runner4/_work/zig/zig/build-debug/zig-global-cache/o/ef3f74ff72425e6d13da4960cdf5bcea/libcompiler_rt.a.o)
error: ld.lld: undefined symbol: __floattikf
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/0bbda7e5a922a3ea118795e1c05547cb/test.o:(json.static.sliceToInt__anon_338634)
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/0bbda7e5a922a3ea118795e1c05547cb/test.o:(json.static.sliceToInt__anon_338637)
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/0bbda7e5a922a3ea118795e1c05547cb/test.o:(json.static.sliceToInt__anon_408252)
    note: referenced 4 more times
    note: did you mean: __floatdikf
    note: defined in: /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-global-cache/o/ef3f74ff72425e6d13da4960cdf5bcea/libcompiler_rt.a(/home/ci/actions-runner4/_work/zig/zig/build-debug/zig-global-cache/o/ef3f74ff72425e6d13da4960cdf5bcea/libcompiler_rt.a.o)
error: ld.lld: undefined symbol: __fixkfti
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/48ca3e919f051135866e6be20173b64a/test.o:(json.static.sliceToInt__anon_339383)
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/48ca3e919f051135866e6be20173b64a/test.o:(json.static.sliceToInt__anon_339386)
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/48ca3e919f051135866e6be20173b64a/test.o:(json.static.sliceToInt__anon_409855)
    note: referenced 4 more times
    note: did you mean: __fixdfti
    note: defined in: /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-global-cache/o/fad0680e4c1f1f4f99e0d70bfdb69649/libcompiler_rt.a(/home/ci/actions-runner4/_work/zig/zig/build-debug/zig-global-cache/o/fad0680e4c1f1f4f99e0d70bfdb69649/libcompiler_rt.a.o)
error: ld.lld: undefined symbol: __floattikf
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/48ca3e919f051135866e6be20173b64a/test.o:(json.static.sliceToInt__anon_339383)
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/48ca3e919f051135866e6be20173b64a/test.o:(json.static.sliceToInt__anon_339386)
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/48ca3e919f051135866e6be20173b64a/test.o:(json.static.sliceToInt__anon_409855)
    note: referenced 4 more times
    note: did you mean: __floatdikf
    note: defined in: /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-global-cache/o/fad0680e4c1f1f4f99e0d70bfdb69649/libcompiler_rt.a(/home/ci/actions-runner4/_work/zig/zig/build-debug/zig-global-cache/o/fad0680e4c1f1f4f99e0d70bfdb69649/libcompiler_rt.a.o)
error: ld.lld: undefined symbol: __fixkfti
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/0cf188cbe557c55227e6d700651ae764/test.o:(json.static.sliceToInt__anon_339431)
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/0cf188cbe557c55227e6d700651ae764/test.o:(json.static.sliceToInt__anon_339434)
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/0cf188cbe557c55227e6d700651ae764/test.o:(json.static.sliceToInt__anon_409755)
    note: referenced 4 more times
    note: did you mean: __fixdfti
    note: defined in: /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-global-cache/o/d5aa95aa68752008508c1fa05de1ed32/libcompiler_rt.a(/home/ci/actions-runner4/_work/zig/zig/build-debug/zig-global-cache/o/d5aa95aa68752008508c1fa05de1ed32/libcompiler_rt.a.o)
error: ld.lld: undefined symbol: __floattikf
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/0cf188cbe557c55227e6d700651ae764/test.o:(json.static.sliceToInt__anon_339431)
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/0cf188cbe557c55227e6d700651ae764/test.o:(json.static.sliceToInt__anon_339434)
    note: referenced by static.zig:746 (/home/ci/actions-runner4/_work/zig/zig/lib/std/json/static.zig:746)
    note:               /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-local-cache/o/0cf188cbe557c55227e6d700651ae764/test.o:(json.static.sliceToInt__anon_409755)
    note: referenced 4 more times
    note: did you mean: __floatdikf
    note: defined in: /home/ci/actions-runner4/_work/zig/zig/build-debug/zig-global-cache/o/d5aa95aa68752008508c1fa05de1ed32/libcompiler_rt.a(/home/ci/actions-runner4/_work/zig/zig/build-debug/zig-global-cache/o/d5aa95aa68752008508c1fa05de1ed32/libcompiler_rt.a.o)

andrewrk avatar Jun 15 '23 18:06 andrewrk

are you game to add these to compiler-rt?

Can do. I wonder though, why I am unable to find search results to the ppc runtime abi functions and the only results are inside libgcc __fixkfti. This looks like libgcc doing their own abi thing without documenting it or PPC(64) docs being aweful to search.

Those two are used as PPC64 aliases: __fixkfti, __floattikf here.

TODO for docs: add assumptions about long double being 128IEEE (-mabi=ibmlongdouble -mlong-double-128) instead of spaghetti code https://developers.redhat.com/articles/2023/05/16/benefits-fedora-38-long-double-transition-ppc64le#how_to_transition_to_ieee_128_bit_long_double

UPDATE: Tracking issue for PPC is #16057. I'll fill status and make the tracking issue more readable in the next days.

matu3ba avatar Jun 15 '23 20:06 matu3ba

@thejoshwolfe Can you rebase on top of ~~#16054 to check, if the fix works correctly~~ master to get a green CI?

~~Otherwise, I'll try to poke it with valgrind later today.~~

matu3ba avatar Jun 16 '23 11:06 matu3ba

@matu3ba you can test locally. Run the std lib tests with the appropriate -target parameter and then run with QEMU.

andrewrk avatar Jun 16 '23 19:06 andrewrk

@matu3ba the names are still not correct on powerpc64le-linux-musl and powerpc-linux-musl.

undefined symbol: __fixtfti
undefined symbol: __floattitf
undefined symbol: __fixtfti
undefined symbol: __floattitf

andrewrk avatar Jun 17 '23 19:06 andrewrk

the names are still not correct on powerpc64le-linux-musl and powerpc-linux-musl.

First of all, sorry for the inconvenience. I should have waited the full libstd test suite. It would be very nice, if there would be a target filter to speed things up (prompt also showed up arm stuff). But I should have used -Dtest-filter=[string].

Also, reminder to myself: Dont do PRs at 2am and wait for CI/test suite.

I suspect LLVM does not use kf functions for those 2 targets and uses the regular ones instead.

UPDATE: Works now at least for the 2 use cases:

./deb/bin/zig test lib/std/json/static_test.zig -target powerpc-linux-musl --test-cmd qemu-ppc --test-cmd-bin
./deb/bin/zig test lib/std/json/dynamic_test.zig -target powerpc-linux-musl --test-cmd qemu-ppc --test-cmd-bin
./deb/bin/zig test lib/std/json/static_test.zig -target powerpc64le-linux-musl --test-cmd qemu-ppc64le --test-cmd-bin
./deb/bin/zig test lib/std/json/dynamic_test.zig -target powerpc64le-linux-musl --test-cmd qemu-ppc64le --test-cmd-bin

I'll run the complete test suite run over night locally.

matu3ba avatar Jun 17 '23 21:06 matu3ba

I'm going to see if I can get the CI to pass even if I have to leave the one test behind. Enabling the test can turn into its own PR, but I'd like to get the features in this PR merged in time for 0.11.

thejoshwolfe avatar Jun 18 '23 16:06 thejoshwolfe

The function doesn't seem to be reachable via std.json.parseFromValue(), https://github.com/ziglang/zig/blob/9d66481e3df35b54275373a685e765a4bcebd712/lib/std/json.zig#L85-L91

llogick avatar Jun 23 '23 23:06 llogick

The function doesn't seem to be reachable via std.json.parseFromValue(),

Oops! Good catch. Fixed in https://github.com/ziglang/zig/pull/16194

thejoshwolfe avatar Jun 25 '23 03:06 thejoshwolfe