ChanServ changed the topic of #zig to: zig programming language | https://ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
dimenus has quit [Remote host closed the connection]
dimenus has joined #zig
<fengb> Yeah that’s a good point
_Vi has quit [Ping timeout: 252 seconds]
qazo has joined #zig
<dimenus> wow, i cannot believe how much sampling from an MSAA buffer costs in performance
<dimenus> (this is in Vulkan)
<dimenus> MSAA vs non-MSAA halves my framerate (but has barely any effect if I don't do any post processing)
<shakesoda> dimenus: even worse, the performance is vastly different between vendors
<dimenus> i think i'm overcreating buffers though, shouldn't need an MSAA buffer / render target per swapchain
<shakesoda> on some mobile hardware the msaa is full rate and you mostly have to worry about the resolve cost
<fengb> I’m actually happy that nobody is complaining about my leak detector. Literally slapped together without any forethought
<shakesoda> there's also all kinds of gotchas, like if you actually use the sample id in your shader then you get more pixel shader invocations (iirc you can avoid this, but i don't remember the details)
<dimenus> 5500 fps to 2700 fps from using MSAA
<dimenus> it's still faster than the GL clone, but nowhere near the 4x I originally had
<dimenus> in short, MSAA on a shader attachment is super expensive
<shakesoda> eh, the fps makes it sound a lot worse
<dimenus> yeah, my frame time is still ~0.5ms :P
<shakesoda> it's a bad relative difference, but that's still pretty dang fast :)
<dimenus> but the numbers!
<dimenus> this is obviously a simple game, but I love how Vulkan forces you out of the OO style
<shakesoda> good, oo style is an insanely bad habit for doing renderers
<shakesoda> i have to get on people's cases a lot for shooting themselves in the foot trying to abstract GL that way
<dimenus> i have barely any uniforms in this program, just a textures essentially
<dimenus> *just for textures
<shakesoda> i haven't got too many uniforms in general anymore, most stuff ends up in ubo/ssbos unless it truly needs to change per draw
<dimenus> this is on a RX550 btw
<dimenus> eer isn't a uniform a ubo?
<dimenus> or am i confused
<dimenus> Vulkan only has blocks, no standalone uniforms
<shakesoda> aye, i'm on GL
<shakesoda> vulkan renderer is a bit stillborn, haven't had the need to complete that project
mgxm has quit [Ping timeout: 260 seconds]
mgxm_ has joined #zig
mgxm_ is now known as mgxm
<dimenus> this project is about 5k lines so far
<shakesoda> when i think 5k lines and vulkan i think "ah, a triangle"
<shakesoda> :P
<dimenus> hah! it's not that bad. I'm not including the zig generated vulkan headers
<dimenus> if i do that it's 30k
<dimenus> that's including the cimports for a couple libraries though, not just vulkan
<shakesoda> 30k D:
<shakesoda> at least it's just generated code, i guess
<shakesoda> i think my entire engine currently amounts to something like 50k
<dimenus> how do you handle a uniform of arrays in gl, does it make a copy in the background and align them to 16 bytes?
<Snektron> Dimenus, its logical that fps is slower with MSAA of course
<Snektron> Especially considering 5500 fps on a 550 means youre not doing a lot
<dimenus> Snektron: agreed, but didn't think it would be 50%
mahmudov has quit [Ping timeout: 265 seconds]
<dimenus> without rendering to a shader attachment, it barely even hicked up when adding MSAA
<dimenus> *hiccuped
<Snektron> 4x msaa is rendering at 4 times higher resolution, so 50% is alright
<Snektron> This one time i changed one variable in my compute shader and doubled performance
<Snektron> Anyway, if youre not doing a lot of rendering, anything can have a large impact
<Snektron> Because the whole shader switching thing has a lot of overhead
<Snektron> Its probably more fair to test the difference when you render a lot of things
<shakesoda> dimenus: i have everything packed into vec4's to maintain 16 byte alignment without really doing anything special
<shakesoda> no magic
sean2 has quit [Ping timeout: 265 seconds]
<Snektron> In vulkan theres this nice feature called push constants
<Snektron> You can embed a shader variable directly in a command stream
<Snektron> Its really efficient for things that update every frame
<shakesoda> sounds like a regular uniform in gl?
<Snektron> Hm i dont know, depends on implementation
<Snektron> I expect opengl to do a staging buffer kind of thing in the background
<dimenus> Snektron: not sure if you missed some of the convo earlier, but the only uniform blocks i'm using are for textures / combined samplers
<dimenus> indices and small values all come of push constants
<dimenus> the other nice thing is that push constants are align(4)
<Snektron> Instead of align(16) you mean?
<dimenus> yep, I just wrapped uniform types in a struct and that solved the issue
<Snektron> Isnt any glsl value aligned by its size, up to 16 bytes
<dimenus> no, arrays are 16 regardless of size
<Snektron> I see
<dimenus> eg vec2 would be align(8) but vec2 foo[3] would be align(16)
<Snektron> Hm, i thought it rounded up
<dimenus> And MSAA is just overkill for a breakout clone, it's only rendering at 800x600 :D
<Snektron> dimenus, i assume you saw that im working on a zig generator from vk.xml
<dimenus> nice
<Snektron> Do you happen to have any feature requests?
<shakesoda> dimenus: think of the smooth edges you could have on the backgrounds!
<shakesoda> of course it's not overkill! ;)
<dimenus> no, i'm not an idea man and i don't work for a game dev company - so I don't really have a business case for Vulkan. I just wanted to try building the learnopengl.com breakout clone in zig/vulkan
<dimenus> and see how fast I could makme it
<dimenus> but i apprecate the thought, I'll let you know if I need something :)
<Snektron> Currently i mostly have default values for some struct fields (like sType), error sets instead if VkResult, more accurate pointer types, and stuff like that
<dimenus> those are all nice to haves, i went through the generated code and set a good chunk of defaults, but i haven't touched any code I don't need yet
<dimenus> default struct init is a really nice feature to have in a language with Vulkan's API
<Snektron> Doesn't matter if youre a professional game dev or not (im certainly not), just if you maybe thought "this would be useful"
<Snektron> Yeah, its mostly just about nice-to-haves
<Snektron> Stuff that cant be expressed in C but can in zig, and happens to be defined in vk.xml
<Snektron> Theres also information about optional types but i was told that its incorrect
<Snektron> Too bad
<dimenus> 50% performance was at 8x btw, definitely overkill for 800x600 :P
<shakesoda> 8x is always overkill :P
<fengb> I have an important question
<shakesoda> unless you've got some special needs, at least (i.e. msaa trick + additional msaa... but i haven't seen anyone do that in a while)
<fengb> How should the community name projects? Java likes to append 4j, Python prepends Py, etc
<fengb> We need a dumb standard
<shakesoda> i'm fine with zig-whatever or just nothing
<companion_cube> suffix with -zag
<shakesoda> zig-thing-zag
<companion_cube> (which means zig becomes zig-zag, badum-tss)
<companion_cube> yep
<shakesoda> i like the (old and now somewhat discouraged) love2d library naming scheme of "plausibly deniable sexual innuendo"
<shakesoda> alas, it has fallen out of favor
<companion_cube> like, weboob?
<shakesoda> usually a bit more subtle than that, although not always
<Snektron> Java also prepends j
<companion_cube> just suffix your project name with `.comptime`
<companion_cube> (or prefix?)
<pmwhite> comptime-websockets
<companion_cube> there's a ring to it, right?
<pmwhite> I'm not sure what I would think when I see that title. I don't want my program to require an internet connection while it compiles.
<pmwhite> It has google-ability going for it though.
<companion_cube> it'd be a private joke in the community, is all :p
rom1504 has quit [Ping timeout: 245 seconds]
rom1504 has joined #zig
return0e has joined #zig
return0e has quit [Ping timeout: 240 seconds]
seoushi has joined #zig
<seoushi> so I made a basic zig uild file based off the tetris project. It references the root source file main.zig. I want to start writing a lot of code but not nessiarly put anything in main.zig yet. If I import the file it seems like ti doesn't compile it till I reference the struct in the file. Is there a better way to just add files to the build script or something to force compilation? I can't seem to find any documentation on
<seoushi> build scripts.
<andrewrk> here's the issue for docs for the build system: https://github.com/ziglang/zig/issues/1519
<andrewrk> zig has lazy analysis, so you will have to reference things before they are checked by the compiler
<andrewrk> one thing you can do is to add unit tests
<seoushi> ok
<seoushi> thanks
<andrewrk> even something as simple as `test "stuff" { _ = foo; }` will now semantically analyze `foo` when you run `zig test file.zig`
<seoushi> is this true for libraries as well? or just executables? I would figure that libraries would evaulate everything marked with pub?
<andrewrk> exported symbols are entry points
<andrewrk> but a zig package to be used by other zig code is subject to the same lazy analysis rules
<andrewrk> this is an acknowledged issue, with open github issues related to it
<seoushi> ok
<andrewrk> note that any programming language that has generic functions suffers from this same problem. it's just that in zig, generic functions and regular functions are treated less differently
forgot-p1ssword has joined #zig
forgot-password has quit [Ping timeout: 268 seconds]
<andrewrk> fengb, yes, should be using the allocator parameter
<salotz> zig is an acronym for "zig is good" right?
<fengb> I think I found an actual leak
<andrewrk> nice
<andrewrk> salotz, actually it stands for Zag Isn't Good
<salotz> zig's evil twin
nofmal has joined #zig
<nofmal> hello, i just made a basic implementation of termios: https://pastebin.com/Bhwp4UPV
<nofmal> any feedback is appreciated
<andrewrk> nice work nofmal
<salotz> zag arches zig
<andrewrk> nofmal, it looks like termios is a POSIX standard, which means that it's a good candidate to go into lib/std/os.zig, following the pattern of the other functions there
<nofmal> yes. i've only tested it in my machine (linux x86_64)
<nofmal> is it available in *bsd too?
<fengb> `TERMIOS(4) BSD Kernel Interfaces Manual TERMIOS(4)`
<fengb> Seems like it
<nofmal> well either way i cannot be sure if it works perfectly in bsd
<nofmal> the only differences from what i've looked is that, in powerpc, the `NCCS` constant is 19 instead of 32
<nofmal> anything else is the same
nofmal75 has joined #zig
nofmal75 has quit [Remote host closed the connection]
<andrewrk> still, if you are considering submitting it as a pull request to zig, it should be structured in a way so that bsd programmers will be able to contribute to
nofmal14 has joined #zig
<andrewrk> (the structure of the existing things in std.os)
ajl has joined #zig
ajl has quit [Client Quit]
ajl has joined #zig
nofmal has quit [Ping timeout: 268 seconds]
ajl has quit [Client Quit]
nofmal14 has quit [Remote host closed the connection]
ajl has joined #zig
lunamn_ has joined #zig
ur5us has joined #zig
lunamn has quit [Ping timeout: 272 seconds]
dddddd has quit [Remote host closed the connection]
<ajl> A function in a C library is returning a value of type [*c]const u8. I believe that means a c style pointer to a const u8, and I think its actually a null terminated array of const u8. Is there any way to cast that array into a zig style []const u8 string?
<andrewrk> ajl, `[]const u8` needs to know the length. you can convert with std.mem.toSliceConst(u8, your_c_ptr)
<ajl> That was exactly what I was looking for. Thank you.
marmotini_ has joined #zig
marmotini_ has quit [Ping timeout: 265 seconds]
ur5us has quit [Ping timeout: 260 seconds]
marmotini_ has joined #zig
ajl has quit [Ping timeout: 265 seconds]
adamkowalski has joined #zig
return0e has joined #zig
ltriant has quit [Quit: leaving]
return0e has quit [Ping timeout: 268 seconds]
adamkowalski has quit [Remote host closed the connection]
adamkowalski has joined #zig
<adamkowalski> How do I include a file that is in the parent directory? when I did @import("../foo.zig"); I get an error 19: error: import of file outside package path: '../util/array_info.zig'
<adamkowalski> When I test by doing zig test src/main.zig everything passes however, it's only when trying to test files within the nested folder
jabb has joined #zig
jabb is now known as gruebite
<gruebite> heyo, i'm getting this when compiling master: zig_clang_cc1as_main.cpp:511:23: error: ‘Value’ may be used uninitialized in this function
<gruebite> clang version 9.0.1
<adamkowalski> whats your os?
<gruebite> linux
<gruebite> Linux zork 5.4.13-arch1-1 #1 SMP PREEMPT Fri, 17 Jan 2020 23:09:54 +0000 x86_64 GNU/Linux
<adamkowalski> hmm, i'm on arch and I'm running master build just fine. Did you run `pacman -Sy clang cmake gcc llvm lld`
<gruebite> yeah, good there. weird
<adamkowalski> how are you compiling? mkdir build; cd build; cmake -G Ninja ..; cmake --build .;
<adamkowalski> I also usually throw on a release flag
_whitelogger has joined #zig
<gruebite> got it working, thanks
<gruebite> is c"foo" still a thing? i'm getting an error and can't find any documentation
<shakesoda> gruebite: i think that was removed
<gruebite> thanks, yep
marmotini_ has quit [Remote host closed the connection]
marmotini_ has joined #zig
<gruebite> foo_struct.@"bar" is interesting. i do not anything for accessing it at runtime? for anonymous lists it would be useful for callee's to iterate over the struct members at compile time
<gruebite> runtime/compiletime
marmotini_ has quit [Ping timeout: 268 seconds]
<gruebite> can i purposefully disqualify const qualify if say... c code doesn't have a const function pointer?
<fengb> The nuclear option: @intToPtr(*T, @ptrToInt(ptr_const))
<gruebite> heh
<gruebite> for every function pointer D:
<gruebite> i'm dealing with an api that heavily uses function pointers (dynamic plugins, register callbacks all the time)
<gruebite> i had a patch file that just added consts everywhere but i don't like that solution
<gruebite> .create_func = @intToPtr([*c]fn(?*c_void, ?*c_void) callconv(.C) ?*c_void, @ptrToInt(test_constructor)),
<gruebite> beautiful
<gruebite> not 100% sure if that should be &test_constructor
forgot-p1ssword has quit [Ping timeout: 265 seconds]
<fengb> Oof
<fengb> I've never interfaced with C function pointers with Zig :/
adamkowalski has quit [Remote host closed the connection]
seoushi has quit [Ping timeout: 260 seconds]
<shakesoda> i had some mild trouble with it too, day 1 of trying zig
SimonN has quit [Remote host closed the connection]
sirnaysayer has quit [Quit: Lost terminal]
traviss has joined #zig
<traviss> does anyone know if there is already an issue for this? https://clbin.com/dEr0U
<traviss> it looks like the lhs of == between @Vector(4, usize) usize is being turned into @Vector(4, u64) inside a function but not outside of it
_Vi has joined #zig
return0e has joined #zig
bheads has quit [Quit: bheads]
bheads has joined #zig
eagle2com has joined #zig
_Vi has quit [Ping timeout: 260 seconds]
bav has joined #zig
Demos[m] has quit [Quit: User has been idle for 30+ days.]
<betawaffle> how does one define a function with is_var_args == true?
<betawaffle> does that just mean "has at least one argument with type `var`", or is it related to variable-length argument lists?
waleee-cl has joined #zig
forgot-password has joined #zig
<Snektron> traviss, i think boolean operators aren't implemented yet for vectors
<Snektron> or at least not properly
marmotini_ has joined #zig
eagle2com has quit [Read error: Connection reset by peer]
eagle2com has joined #zig
marmotini_ has quit [Ping timeout: 260 seconds]
doublex_ has joined #zig
doublex__ has quit [Ping timeout: 265 seconds]
dddddd has joined #zig
sean2 has joined #zig
sean2 has quit [Ping timeout: 265 seconds]
Snetry has quit [Ping timeout: 240 seconds]
bav has quit [Remote host closed the connection]
_Vi has joined #zig
Snetry has joined #zig
<traviss> Snektron, == does work for other vector types. in the example i linked, i can do `const v = v1 == v2` where v1 and v2 are @Vector(4, usize). the issue is when i try that inside a function. i think v1 gets interpreted as @Vector(4, u64) and there is a compiler error.
<traviss> also errors for isize. the error goes away if the vectors are declared as u64.
<Snektron> i see, i actually ran into that issue before too
<traviss> i couldn't find a github issue so i wanted to see there's already one created
<Snektron> i don't think so, but its related to https://github.com/ziglang/zig/issues/903#issuecomment-459508820
<traviss> ok thanks. i'll create one then.
<traviss> actually maybe i'll wait a bit to see if there's any other input on this
BaroqueLarouche has quit [Quit: Connection closed for inactivity]
decentpenguin has joined #zig
BaroqueLarouche has joined #zig
<andrewrk> gruebite, that file comes from upstream clang. it may need to be updated for 9.0.1
<andrewrk> as for function pointers what happens if you just try to corece the type rather than using inttoptr/ptrtoint?
<fengb> He mentioned needing to ditch the constness
<andrewrk> ah
<andrewrk> ditching constness looks ugly in zig ¯\_(ツ)_/¯
waleee-cl has quit [Quit: Connection closed for inactivity]
<fengb> https://godbolt.org/z/0J8K18 we could hide the ugliness 🙃
<andrewrk> nice work on finding and fixing BufMap value leak
<fengb> 👍 I hope this ref counting is good enough™ for now. I had to fix a few errors so my biggest fear is false negatives
Snetry has quit [Ping timeout: 252 seconds]
<fengb> For the builder, I think it'd be even better if it auto creates an arena so it always does the correct thing. But until we get the optional shrink, chaining arenas seems to degenerate a bit
<andrewrk> that makes sense
<andrewrk> ugh annoying time for sourcehut to shit the bed
<andrewrk> I'm pretty sure the only admin is on a plane to FOSDEM
<fengb> https://github.com/freebsd/pkg/issues/1802 possible workaround?
<fengb> Or does the source image depend on the package and we need an admin
dingenskirchen has quit [Read error: Connection reset by peer]
dingenskirchen has joined #zig
qazo has quit [Ping timeout: 268 seconds]
qazo has joined #zig
<andrewrk> let me try
dingenskirchen has quit [Read error: Connection reset by peer]
<andrewrk> it works but that means I have to do this: https://clbin.com/pskdo
dingenskirchen has joined #zig
<andrewrk> (which I'm going to do because it Just Works)
<andrewrk> imo the sr.ht script itself should do that
Snetry has joined #zig
Akuli has joined #zig
<andrewrk> thanks fengb
Snetry has quit [Ping timeout: 268 seconds]
<fengb> np
Snetry has joined #zig
<fengb> Oof, I just noticed that this is an antipattern: https://github.com/fengb/korwerdna/blob/master/src/wat.zig#L133
<fengb> The parseList needs to happen before assigning the arena
<Snektron> yeah, i've noticed a few cases in the std where theres a workaround for that
<fengb> I'm glad the leak detection is working :D
metaleap has joined #zig
dingenskirchen has quit [Quit: dingenskirchen]
<betawaffle> is it always safe to assume *c_void and usize are the same size? can i use either one for a field in an `extern struct`?
<andrewrk> zig target cpu/features already having a wider ecosystem impact: https://clbin.com/i3zFL
<andrewrk> betawaffle, yes, usize is defined to be the size of pointers
<betawaffle> when the package manager is a thing, is the std library going to be... uhh... pluggable?
<Snektron> I never understood why there are different types for size_t and intptr_t
<betawaffle> size_t is unsigned and intptr_t is signed, right?
<Snektron> you're thinking of ptrdiff_t
<Snektron> oh nevermind
<Snektron> theres also an uintptr_t
<andrewrk> I think there were once upon a time, systems that had pointers of different sizes than registers
<Snektron> because why not
decentpenguin has quit [Quit: decentpenguin]
<andrewrk> betawaffle, what use case specifically are you thinking of?
<betawaffle> andrewrk: this very moment, byo event loop?
<andrewrk> event loop is already pluggable
<betawaffle> oh?
<betawaffle> i suppose there are probably a lot of things like that, but there's no documentation yet
<andrewrk> yeah
<andrewrk> I was also considering whether making an event loop an interface would make sense. kinda like Allocator
phillyiscool has joined #zig
<betawaffle> i think that could be good, yeah
<companion_cube> (are event loops going to be composable as well? :p)
<betawaffle> speaking of interfaces... the documentation really needs to discuss them, at least a little
<phillyiscool> Something I'm curious about, if you want to libraries that are consumable from C using Zig, does this mean you can't use comptime (and possibly other Zig features)?
<betawaffle> because afaict, there are already a number of them in std, and i don't know what they are or how to use them
<companion_cube> amen to this betawaffle
<andrewrk> phillyiscool, only types that are compatible with the C ABI are available when exporting symbols
<betawaffle> what i want is to be able to have per-thread event loops
<andrewrk> betawaffle, that's already a thing too
<companion_cube> if you use zig with libuv and jemalloc… are you cheating? :D
<andrewrk> betawaffle, oops, spoke too soon. I think there are a couple problems to solve to make that work. but that's planned too
<andrewrk> the way zig does async functions makes this possible:
<andrewrk> switchToGuiThread();
<betawaffle> i want resume/suspend to have atomics be optional
tane has joined #zig
<fengb> Ah so do generators :P
<andrewrk> betawaffle, yes I've been thinking about that too
<andrewrk> you can use --single-threaded to avoid that, but it's a global setting
<phillyiscool> andrewrk Thanks. What do you recommend when you want to have both a C ABI and a "nicer" Zig API? Write a low-level C compatible layer and "wrap" that with Zig niceness?
<betawaffle> because sometimes you have your own locking wrapping the resume/suspend stuff
<andrewrk> phillyiscool, other way around. have a nice zig package api, and wrap it with a C compatible layer
<phillyiscool> How is that possible if the nice zig package depends on comptime? The C layer can't use that, right?
<andrewrk> the parameters of the exported function cannot. but the function implementation can call zig functions
<phillyiscool> Hm, ok thank you very much. I'm currently working on something where I do this. I haven't gotten to the point yet where I can have more feedback but hopefully I can share something soon.
<phillyiscool> Would love to write an article or something on this to share with the community once I've figured out how to do it.
<andrewrk> you can have pointers to zig types in exported functions
dingenskirchen has joined #zig
<companion_cube> why hello this is a void*
dingenskirchen has quit [Remote host closed the connection]
<andrewrk> better yet it can be a fwd struct decl
eagle2com has quit [Ping timeout: 268 seconds]
_Vi has quit [Ping timeout: 272 seconds]
phillyiscool has quit [Remote host closed the connection]
marmotini_ has joined #zig
qazo has quit [Ping timeout: 260 seconds]
dingenskirchen has joined #zig
ajl has joined #zig
ajl has quit [Client Quit]
<betawaffle> hmm... what's the "right" way to read errno in zig?
<andrewrk> you can see a lot of examples of this in std/os.zig
<andrewrk> without knowing any more about what you're doing, the right way might be contributing another function to os.zig
<betawaffle> it's a function that returns a file descriptor, or -1 + sets errno
<betawaffle> which is such a stupid interface, why do people suck
<andrewrk> ok so you're interfacing with a third party c library that messes with errno
<betawaffle> a system c library, but yes
<andrewrk> std.c.getErrno()
<andrewrk> oops
<andrewrk> std.c._errno()
<andrewrk> what is the function called?
<betawaffle> kqueue, don't judge me
<andrewrk> why not use std.os.kqueue?
<betawaffle> eh, ok will do
return0__ has quit [Ping timeout: 265 seconds]
<metaleap> ouf.. one day I'll have to bite the bullet and devise a "comptime-reflection querylang-eDSL-ish" to not hardcode traversing-whoppers like this one: https://gist.github.com/metaleap/782ae7e55f8fde4314c364de1cec82ed :D
<betawaffle> lolwat
<Snektron> what the fuck
<companion_cube> is this a predicate? :D
<metaleap> or am i missing some techniques
<metaleap> other than "no duck interfaces (yet)"?
<metaleap> (unless someone took a stab at that somewhere? havent searched tbh. std.meta is helpful but here wouldnt save all that much)
<betawaffle> you could definitely break that into functions
<metaleap> yeah there's even some structurual repetition of similar test-and-traverse paths 3x in there so, sure. thats the first step towards a comptime-reflection-queryer-lib/api/lang
<mq32> metaleap, that can be written much easier
<betawaffle> what you need is the equivilent of rust's `if let Variant(...) = ...` stuff
<metaleap> mq32: thats what i hoped! :P
<companion_cube> and use `return false;` early
<companion_cube> betawaffle: but you can do that here
<mq32> you are NOT required to switch on tagged unions
<mq32> var typeInfo = @typeInfo(T);i
<mq32> if(typeInfo != .Struct) return falsE;
<betawaffle> companion_cube: sure, i know
<mq32> typeInfo.Struct.…
<companion_cube> `const x = switch(…) x: { else => return false; .Struct => break 'x whatev}`?
<metaleap> companion_cube: if you look careful, i technically *do* in all cases where i *can*
<companion_cube> ah but you have some inline for… yeah
<mq32> metaleap, invert all conditions and fast-skip loops with continue
<gruebite> fengb: i like that function. mind if i use it?
<metaleap> mq32: great pointer with the union-switch-not-necessary, brain still shaped from go's type-switches
<metaleap> thatll make stuff more readable (continue instead of return of course)
<mq32> => your code will have probably a max indendt depth of 1
<mq32> *3
<Snektron> What do you even need this for
<companion_cube> that's what you'll have to expect if/when Zig gets contracts on generics :p
<companion_cube> `if isHashMap(T)
<companion_cube> `
<metaleap> Snektron: some json-ery (treat other-structs and hashmaps un-alike in un/marshaling)
<metaleap> daurnimator will probably be able to relate :D
return0e has quit [Remote host closed the connection]
<fengb> gruebite: sure, but I’m not sure which function you’re taking about
adamkowalski has joined #zig
<adamkowalski> how are you supposed to import zig files in a directory above you?
<adamkowalski>
<adamkowalski> ./src/lazy/graph.zig:3:24: error: import of file outside package path: '../eager.zig'
<adamkowalski> const CpuTensorUnion = @import("../eager.zig").CpuTensorUnion;
<adamkowalski> If I run zig test src/lazy/add.zig then I get this error. However, I run zig test src/main.zig which itself references lazy/add.zig then everything works fine
<andrewrk> adamkowalski, --main-pkg-path ..
<andrewrk> we're in a bit of a transition to packages, bear with me
<adamkowalski> thanks that works!
<adamkowalski> well it's not a big issue, my entire test suite runs in 0.08 seconds since zig is awesome
_Vi has joined #zig
wootehfoot has joined #zig
<metaleap> i think i'll write a general `fn doesTypeMatch(comptime T: type, comptime Spec: builtin.TypeInfo) bool` to ditch my above ad-hoc whopper.. let's see how that goes *giddy*
wootehfoot has quit [Read error: Connection reset by peer]
<gruebite> fengb: removeConst
marmotini_ has quit [Remote host closed the connection]
<fengb> Oh I added that as a small joke because it’s not as gross looking as it should be :P
<gruebite> yeah, it's better than what I was doing, more type safe
<andrewrk> better yet, fix the .h file upstream
waleee-cl has joined #zig
return0e has joined #zig
return0e_ has joined #zig
lunamn_ has quit [Ping timeout: 268 seconds]
lunamn has joined #zig
<gruebite> andrewrk: true. one is slower than the other, but they can certainly be done in parallel
marijnfs has joined #zig
mahmudov has joined #zig
seoushi has joined #zig
<seoushi> andrewrk: created my first working zig code last night. It's a pool data structure which might be useful in std. https://gist.github.com/seoushi/3301ab156a66cd9c255d9310d3ab2810 if it is I can work on figuring out a pull request for it
<gruebite> with @import must i include `.zig`?
<gruebite> docs say no, but compiling says yes
eagle2com has joined #zig
<SyrupThinker> There are these special imports for std and builtin but all others need the .zig extension the way I see it (because they are paths)
<andrewrk> wow, llvm 10 release candidate 1 already
<andrewrk> I better get this llvm10 branch passing tests
<SyrupThinker> *shrug* Or whatever extension the file has as long as it contains zig
<BaroqueLarouche> std and builtin are special, but you can set your own package path
<BaroqueLarouche> then you don't have to specify the file extension
<gruebite> cool
<SyrupThinker> Good to know, time to clean some stuff up
<gruebite> i feel like my conversion is wrong
<gruebite> in zig a function pointer does not need a "&" preceding the alias?
<gruebite> fn foo() {}; const bar = foo; // bar is a function pointer
return0e has quit []
<gruebite> am i correct?
eagle2com has quit [Ping timeout: 265 seconds]
<andrewrk> correct
<gruebite> is there some magic when passing it to C then? i've been doing `removeConst(&func_ptr)` but that's wrong, it should be `removeConst(func_ptr)` but it isn't treated as a pointer type
<gruebite> it's like a const reference that coerces to a const pointer?
forgot-password has quit [Quit: leaving]
<gruebite> basically: `@TypeInfo(func_ptr)` is not `.Pointer`
<andrewrk> gruebite, try this: std.debug.warn("{}\n", .{@typeInfo(@TypeOf(main))})
<gruebite> it's .Fn, so i cannot remove const easily when passing to C
<metaleap> i'm still bit new to mem-mgmt.. how does anyAllocator.shrink of some previously alloc'd bytes "return to the caller the just freed bytes"? i mean ..
<gruebite> fixing upstream seems like the *only* option
<metaleap> take Buffer.toOwnedSlice: "The caller owns the returned memory." and inside it calls allocator.shrink(). which becomes the result of toOwnedSlice..
<metaleap> so i call that and now "own" the memory but it was just freed so does that mean i need to put it somewhere STAT before it gets overwritten... it cant be on stack AFAIK
<gruebite> also, side note, what's the significance of capitalization convention regarding: @typeInfo and @TypeOf?
<metaleap> gruebite: convention is, `type`-typed expressions are uppercase
<metaleap> also goes for funcs that return `type`s (because thats how the generics work, eg. `std.ArrayList(T)`)
<andrewrk> gruebite, the pointer casting builtins work for functions as well as pointers
<gruebite> how do i get around "cast discards const qualifier"
<gruebite> using standard casts
<gruebite> doing this: `@ptrCast([*c]fn(?*c_void, ?*c_void) callconv(.C) ?*c_void, test_constructor)`
<andrewrk> you never need to type [*c] into your keyboard
<andrewrk> @ptrCast does not have the ability to strip `const`
<andrewrk> the nuclear option is @ptrToInt/@intToPtr
<gruebite> is that the nuclear or only option?
<gruebite> or both :D
<metaleap> so real-world example on my above mem-mgmt-newb question.. lets say a user-defined func, passed to some zig lib ("use this func to get say some id") to return a string. might be tempting for the implementer to use its own favorite allocator and a std.Buffer, then return `buf.toOwnedSlice()` which cleans up the buffer kinda. now the "caller owns" the returned string but also needs to free it (at some point) "from somewhere". so the caller needs to know the
<metaleap> user-code's allocator used, i guess?
<pmwhite> that would be a leaky abstraction, no?
<metaleap> how so
<metaleap> libs allowing "user-specified fn impls of certain signatures" isnt all that uncommon pattern in interface-less langs I'd have to presume?
adamkowalski has quit [Remote host closed the connection]
_Vi has quit [Ping timeout: 272 seconds]
<metaleap> guess i have to give an alloc (for the implementer to alloc his ret-value from but not free from.. hum) to such a sig, to keep things predictable
<pmwhite> Oh, I misunderstood your explanation I think.
_Vi has joined #zig
<pmwhite> Perhaps you don't actually want to return the owned version of the slice to the caller?
<metaleap> np.. somehow i tend to run into issues that defy clear problem description. might be a sign of garbled synapses :D
<pmwhite> I think I get your conundrum now, but of course I don't have the whole picture.
<gruebite> checking my sanity: `.create_func = @intToPtr(*fn(?*c_void, ?*c_void) callconv(.C) ?*c_void, @ptrToInt(test_constructor))` should work if `create_func` is defined by: GDCALLINGCONV void *(*create_func)(godot_object *, void *), where godot_object is void, and GDCALLINGCONV is __attribute__((sysv_abi))
<gruebite> test_constructor is `export fn test_constructor(obj: ?*c.godot_object, method_data: ?*c_void) callconv(.C) ?*c_void`
<gruebite> it's crashing godot, so something is off
<andrewrk> gruebite, `fn()void` is already a pointer. `*fn()void` is a double pointer
<Snektron> function point syntax is honestly kind of confusing
<Snektron> because its a pointer yet there is no star
<gruebite> removing it i get: error: expected type '[*c]fn(?*c_void, ?*c_void) callconv(.C) ?*c_void', found 'fn(?*c_void, ?*c_void) callconv(.C) ?*c_void'
<gruebite> yeah, so used to C and having to provide an asterisk
<gruebite> heh
<Snektron> ah, at least its nothing compared to c++ member function pointers
<gruebite> oof
<gruebite> yeah
occivink has quit [*.net *.split]
m6w6 has quit [*.net *.split]
m6w6_ has joined #zig
occivink has joined #zig
m6w6_ is now known as m6w6
return0e has joined #zig
jicksaw has quit [Ping timeout: 268 seconds]
jicksaw has joined #zig
<andrewrk> gruebite, it's expecting a double pointer then, so you do need the *
<gruebite> this is in cimport.zig: create_func: [*c]fn (?*godot_object, ?*c_void) callconv(.C) ?*const c_void,
marijnfs has quit [Remote host closed the connection]
return0e has quit [Ping timeout: 240 seconds]
<andrewrk> let me just take a look at godot and see
<gruebite> from: GDCALLINGCONV void *(*create_func)(godot_object *, void *);
<andrewrk> that does look like a double pointer to me
<andrewrk> which is weird
<gruebite> void *(*create_func)(void); would be a single pointer i thought?
<andrewrk> void (*create_func)(void); is a single pointer
marijnfs has joined #zig
<gruebite> void * is the return type
<andrewrk> oh right
<gruebite> C function pointers :D
<andrewrk> hmm that C translation needs to be audited
<gruebite> is this a bug? :D
<andrewrk> unclear
<Snektron> it might be in the same ballpack as the issue daurnimator ran into a few days ago
<Snektron> i can't find the issue but it was about `void (func)();`
<gruebite> i don't know where to look to change this translation, but i can make a change and test it
<Snektron> ah, #4289, which is already fixed
<gruebite> if [*c]fn is a double pointer in zig
<gruebite> then that translation is incorrect
<gruebite> also, c doesn't have a concept of const pointers to functions?
<andrewrk> I think there is a design flaw here
<gruebite> void (const *func)(void); would be it but i don't think that's allowed
<gruebite> void (*const func)(void); is just a constant pointer
<Snektron> const functions should be possible
<Snektron> const function pointers, that is
<andrewrk> I don't know how to solve this
<Snektron> isnt `void (*const func)(void);` what you want?
<gruebite> that's a pointer that must be initialized
<gruebite> or can't change what it's pointing to
<andrewrk> all function pointers can be considered const. that's an easy improvement to make in translate-c
<gruebite> what's the design flaw?
<Snektron> anyway gruebite, if you're writing C, i recommend using `typedef void (func)(void);` so you can use `const func*` and `func*`
<gruebite> ahh, yeah i do that when writing C
<andrewrk> gruebite, how to translate a C function pointer to zig
<gruebite> i'm just using existing C
<andrewrk> in C function pointers can be null
<gruebite> why not ?fn?
<andrewrk> maybe that's the solution. but it means function calls look like foo.?()
<Snektron> you could have `?extern fn` have a guaranteed abi layout
<gruebite> for C function
<gruebite> how does zig handle null function pointers?
<gruebite> if `fn` cannot be null without `?`
<Snektron> well, not
<andrewrk> in zig a null function pointer will have type `?fn()void`
<andrewrk> and it will require unwrapping before calling
<Snektron> which is to be expected
<gruebite> yeah
<andrewrk> I think that's right. function pointers should translate as ?fn rather than [*c]fn
Akuli has quit [Quit: Leaving]
<gruebite> i can make that change and test if i'm pointed in the right direction
<andrewrk> the const thing is also solved with this approach
<andrewrk> ok, this is not so bad. no design flaw after all
<Snektron> crisis averted
<Snektron> andrewrk, is `?fn() callconv(.C) void` already guaranteed to be the same as `void (*func)()`?
<andrewrk> yes
<gruebite> fork or pr?
<andrewrk> a pull request makes it easiest to merge, since there is integrated CI testing
<gruebite> i prefer pr
<Snektron> hold up
<gruebite> hol' up
<Snektron> I have the translate-c'd Vulkan headers here to compare against, and here function pointers are translated including optional
<Snektron> `pub const PFN_vkFreeFunction = ?fn (?*c_void, ?*c_void) callconv(.C) void;`
<gruebite> have any structs with function pointer definitions?
<Snektron> not directly, they're al typedeffed
<gruebite> the c code I have has no typedef function pointers
<gruebite> edge case?
<Snektron> seems like it
<andrewrk> next step is minimal repro
<gruebite> okay, so like test/translate_c.zig:455 looks like what it should do
<gruebite> added 16Dec2019
<gruebite> stumped now
<gruebite> the `= .{}` part?
<andrewrk> anonymous struct with methods
<andrewrk> maybe it helps to see the diff: https://github.com/ziglang/zig/pull/4331/files
<gruebite> basically closure
<gruebite> niiice
<gruebite> so i see a test case that matches the correct ?fn translation
<andrewrk> start with your C code that generates [*c]fn and try to reduce it until it is as small as possible
<metaleap> comptime-reflecting a func with one `var` arg and one fully-typed arg. BOTH result in `.Fn.args[i].arg_type` of `null`. by design?
<metaleap> ie. if both args are not `var`, both `...arg_type`s are not `null`. but just one `var`, all 2 `null`
<gruebite> got it
<gruebite> struct foo { __attribute__((sysv_abi)) void (*bar)(void); }; doesn't work
<gruebite> struct foo { void (*bar)(void); }; works
<metaleap> thx andrewrk will follow the issue
<andrewrk> gruebite, nice find. would you mind filing an issue?
<gruebite> yeah
<gruebite> if this is an easy fix, it'd be fun for me to do
<betawaffle> has anyone already suggested the ability to embed the fields from one type into another? something like usingnamespace, but for fields, rather than declarations
<andrewrk> it might involve adding a new calling convention to zig. the first step is understanding what does that attribute mean
<andrewrk> that would be easier than it sounds, however, it's likely just an enum value to llvm
Cadey has quit [Remote host closed the connection]
TheLemonMan has joined #zig
<TheLemonMan> gruebite, do you mind if I submit a PR to fix the translate-c problem?
<gruebite> go ahead :D
<gruebite> #4332 is the issue I just created
marijnfs_ has joined #zig
marijnfs has quit [Ping timeout: 265 seconds]
waleee-cl has quit [Quit: Connection closed for inactivity]
<andrewrk> hmm, I'm unable to get the behavior test that is failing in the llvm10 branch, to fail independent from the other tests
<gruebite> for passing C strings to C do I just do `"foo"` no special syntax?
<gruebite> used to be c"foo"
<andrewrk> gruebite, that's correct. string literals now are null terminated
<andrewrk> the coerce both into slices and null terminated pointers
<gruebite> nice
<gruebite> when the pointer is a [*c] pointer it will add the null?
<TheLemonMan> done! Hopefully it passes the CI checks
<gruebite> woo!
tane has quit [Quit: Leaving]
<andrewrk> oh, that's interesting. if I comment out the new_stack_call test then a seemingly unrelated test passes
<andrewrk> we might have to drop @newStackCall in 0.6.0
<Snektron> isn't it part of @call now anyway?
<TheLemonMan> yeah, it's quite unsafe as it's implemented right now
<andrewrk> it's flawed anyway: https://github.com/ziglang/zig/issues/3268
<Snektron> hm, this whole Vulkan thing turned out to be quite complicated
<Snektron> one thing i wanted to do was add a way to make using the function pointers a little less of a nuisance to set up
<Snektron> since you can either dispatch statically or dynamically
marijnfs has joined #zig
marijnfs_ has quit [Ping timeout: 260 seconds]
<TheLemonMan> andrewrk, what would be a nice API for a binary-search-in-slice function? I wanted to add one to the stdlib but I'm not sure about the API
<andrewrk> TheLemonMan, how about: fn binarySearch(comptime Elem: type, list: []const Elem, comptime lessThan: fn (lhs: T, rhs: T) bool) void
<andrewrk> s/T/Elem/
<Snektron> Why lessThan comptime here but not in sort.zig?
<andrewrk> it should be in sort too
<TheLemonMan> the predicate should take a single parameter as the element you're looking for is fixed
<andrewrk> ah right
<andrewrk> libc bsearch takes a predicate with 2 args
<andrewrk> how about: pub fn binarySearch(comptime Elem: type, list: []const Elem, item: Elem, comptime lessThan: fn (lhs: Elem, rhs: Elem) bool) void
<gruebite> yeah, how does the predicate know the fixed value?
<TheLemonMan> and the predicate should be able to return more than a bool, it's a full-fledged comparison operator with the usual {.gt,.eq,.lt}
<andrewrk> does it need that though? sorting doesn't need that
<gruebite> need a compare enum :P
<gruebite> Lt, Eq, Gt
<TheLemonMan> two args means you're passing the value to be searched
<andrewrk> if it needs it, that's std.math.Order
<Snektron> Until theres some kind of closure i think its better to pass in both arguments
<Snektron> makes it compatible with asc and desc too
<TheLemonMan> if you want to return a ?usize you need that, it's needed to handle the failure case
<andrewrk> with two args, it can be lessThan, because the code can swap the args order to find greater than
<andrewrk> oh yeah return vaule should be ?usize
metaleap has quit [Quit: Leaving]
<gruebite> what would be a failure case of a sort?
<andrewrk> I think it should be lessThan, and then the impl swaps lhs, rhs, to find greater than, and therefore also equal
<TheLemonMan> yeah, if we go for the two-args route then we can avoid the predicate
<TheLemonMan> gruebite, it's a binary search, the element you're searching for may not be there
<gruebite> ohhhh bsearch, not sort
<gruebite> do'h
<traviss> anyone have a build.zig i can look which installs a test artifact? i want a fixed path to my test exe which i can use to launch a debugger. something like zig-cache/bin/my_tests.
<TheLemonMan> the only downside is that you need one more call to the comparison function
<andrewrk> traviss, the default `zig init-exe` does that I believe (do that in an empty dir)
<andrewrk> oh that's a good point
<andrewrk> I'd be ok with either
<andrewrk> but the enum you're looking for is std.math.Order
<traviss> oh nice. i'm working from an 'init-lib'. i'll have a look.
<andrewrk> traviss, it's just exe.install();
<andrewrk> and the fn should be comptime, because zig is getting pretty hostile to runtime-known function pointers
<fengb> That function pointer fix is to delete a bunch of edge cases? lol
<pixelherodev> `might have to drop @newStackCall in 0.6.0` will there be a replacement?
<Snektron> @call
<traviss> this doesn't seem to work for a test created using `var main_tests = b.addTest("tests.zig");` i moved my main test into my root package directory. the only test binary i'm seeing is buried within zig-cache/o, not in zig-cache/bin or zig-cache/lib where i hoped.
<andrewrk> pixelherodev, inline assembly
<andrewrk> traviss, you want your test binary to get installed?
<pixelherodev> If it can be done with manual assembly, the compiler should be able to do it, no? Couldn't the implementation just be inline asm for the specific target?
<andrewrk> if you're trying to run it in a debugger, you have a few options:
<traviss> yes i want a fixed location for a debugging script
<TheLemonMan> you have to be extra careful even with inline asm, gcc and llvm don't like their sp being clobbered
<pixelherodev> Yes, but it's doable, and in some cases necessary
<pixelherodev> I don't think I've seen a single freestanding application that doesn't need it, for instance
<traviss> or if i can just get the path to the artifact, i can manually move it in build.zig
<TheLemonMan> of course it is, nobody stated otherwise
<andrewrk> pixelherodev, yes zig should be able to do it
<TheLemonMan> use a naked function to act as a trampoline and you should sidestep any trouble
<andrewrk> the problem is that it is getting dropped now, in the llvm10 branch, because the current implementation is no good. so if a more robust implementation can be completed by the master branch merge, then it will be available
<andrewrk> I'll try the naked function strategy before merging llvm10
jessermeyer has joined #zig
<jessermeyer> Are the semantics different between these two statements?
<jessermeyer> var d12_device: *ID3D12Device = undefined; var result = D3D12CreateDevice(null, D3D_FEATURE_LEVEL_12_1, &IID_ID3D12Device, @ptrCast(**c_void, &d12_device));
<jessermeyer> var d12_device: *ID3D12Device = undefined; var result = D3D12CreateDevice(null, D3D_FEATURE_LEVEL_12_1, &IID_ID3D12Device, &@ptrCast(*c_void, d12_device));
<jessermeyer> Both compile, but the first one is what works.
<andrewrk> yes
<jessermeyer> And by works, I mean the com init succeeds.
<Snektron> youre taking an address of a stack variable in the second case
<andrewrk> one of them is taking a pointer to a temporary; the other is taking a pointer to the variable
<jessermeyer> Huh, I have to think about that.
Snetry has quit [Ping timeout: 268 seconds]
Snetry has joined #zig
<jessermeyer> I'm amazed you both could parse that so quickly.
marijnfs_ has joined #zig
marijnfs has quit [Ping timeout: 272 seconds]
<andrewrk> I copy pasted it into vim and maximized the window
<fengb> I'm a little surprised a @ptrCast introduces a new variable. Does it also in C?
<jessermeyer> I think that's what's throwing me.
<Snektron> it would be weirder if it didn't
<jessermeyer> So it's causing a copy, or a move instruction?
<Snektron> the generated assembly is probably the same
<Snektron> semantically its causing a copy
<Snektron> or rather, a copy at a different point
<jessermeyer> So why does is it more natural to cause a copy to perform an interpretation?
<andrewrk> fengb, you can put & in front of any expression in zig
<jessermeyer> @ptrCast(comptime DestType: type, value: var) DestType
<jessermeyer> So, yeah, it has a return type (sort of obviously)
<jessermeyer> Which I guess is what Snek is referring to?
<jessermeyer> It's quite a mental task to go from Zig code to C code, back to back.
<Snektron> What i mean is, the result of @ptrCast is a temporary value, even though in code-terms its a no-op]
_Vi has quit [Ping timeout: 260 seconds]
<jessermeyer> Right. It's an actual function.
<Snektron> You can view it as such, yes
<jessermeyer> I mean, it's defined that way.
<jessermeyer> It may be useful to add a comment to this effect for its documentation, to ease the psyche from those coming from a C background.
<andrewrk> it's not an actual function
<andrewrk> builtin functions in zig are syntax
<Snektron> but it acts as an actual function
<andrewrk> in some ways
<Snektron> I understand why you think that way, even without a C background
<andrewrk> it can't be passed as a pointer
<andrewrk> it has to be called directly
<andrewrk> var x = @ptrCast; // error
<jessermeyer> Good distinction.
<jessermeyer> If not already, might be a good documentation addition =)
<Snektron> I think the important thing here is that functions in zig are call-by-value
<fengb> andrewrk: ah but not any expression... because double address && is parsing incorrectly 🙃
<Snektron> if @ptrCast would be call-by-reference, those cases would be equal
<jessermeyer> Right.
<jessermeyer> That was my null-hypothesis.
<andrewrk> feng, always keeping me honest
<fengb> I'm technically correct, the best kind of asshole
<jessermeyer> lol
<Snektron> by the way, are `(void**) a` and `&(void*) a` the same in c?
<jessermeyer> Maybe I'm not testing it correctly but
<jessermeyer> test_translate.c(31,19): error: cannot take the address of an rvalue of type 'void *'
<Snektron> ah, no
<jessermeyer> void** test = &(void*)device;
<Snektron> latter is not allowed since its not an lvalue
Snetry has quit [Ping timeout: 240 seconds]
Snetry has joined #zig
marijnfs has joined #zig
marijnfs_ has quit [Ping timeout: 268 seconds]
<traviss> anyone know how to get the path to a test artifact in build.zig created by `b.addTest("tests.zig")`. i'm looking for something like zig-cache/o/iAwVl8Fjwhfh.../test
<andrewrk> traviss, pass --verbose to `zig build`
<andrewrk> you can also use setExecCmd to make it run in a debugger
<andrewrk> which you could integrate with b.option
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
Snetry has quit [Ping timeout: 268 seconds]
<andrewrk> finally you can use setOutputDir, which is a bit unstable API and disables caching
<traviss> i was hoping to do this within build.zig, not externally. ok thanks i'll have a look at setOutputDir
<andrewrk> this is within build.zig
<andrewrk> it also looks like tests support being installed
Snetry has joined #zig
jessermeyer has quit [Remote host closed the connection]
marijnfs has quit [Ping timeout: 265 seconds]
_whitelogger has joined #zig
Snetry has quit [Ping timeout: 268 seconds]
Snetry has joined #zig