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/
deb303 has quit [Ping timeout: 240 seconds]
<kiedtl> Is it possible to make zig continue with the test suite even if one test block fails
<kiedtl> ?
deb303 has joined #zig
<mikdusan> unfortunately no we don't have any options for that
earnestly has quit [Ping timeout: 245 seconds]
plumm has quit [Quit: Textual IRC Client: www.textualapp.com]
notzmv has joined #zig
zenkuro has quit [Ping timeout: 240 seconds]
powerofzero has joined #zig
jeang3nie has joined #zig
<powerofzero> Is there a nice way to get the maximum (or minimum for signed integers) value of an integer type? Something like maxValue(usize)?
<andrewrk> powerofzero, std.math.maxInt(usize)
SLWW_ has joined #zig
<powerofzero> :facepalm: I saw that being used in ripgrep and assumed it was a c interop MAX_INT. Thanks!
SLWW has quit [Ping timeout: 268 seconds]
<kiedtl> You looked at a Rust project too see how to do something in Zig? I very be confuzzled
<powerofzero> No, I used ripgrep to search the standard library source code.
<powerofzero> (zig standard library)
<kiedtl> Oh, oh, ok
mikdusan has quit [Quit: WeeChat 3.0.1]
<marler8997> is there a proposal for successdefer that would allow errors inside the block?
mikdusan has joined #zig
powerofzero has quit [Ping timeout: 240 seconds]
jeang3nie has quit [Quit: WeeChat 3.1]
<andrewrk> I considered an equivalent to D's scope(success) and decided against it
<andrewrk> not sure if that's what you're referring to
<marler8997> yeah, I just had a use case where I wanted to do "try foo()" inside a defer, but it only makes sense on successdefer
<marler8997> since you can't do "try" inside a normal defer
<andrewrk> I think if you find a case where you would use an entire control flow language feature rarely, it should probably not be a language feature, better to use the existing language tools to model it
<kiedtl> Hm, can you nest functions in a test case?
<marler8997> andrewrk, here's the gist of what I'm doing: https://gist.github.com/marler8997/9d6a8e9aa53378388957e4c9824de525
<andrewrk> marler8997, I've found it pretty reasonable for this use case to just put the footer logic at the bottom without trying to defer it
<marler8997> will have to put it in all the return locations
<andrewrk> don't forget you also have labeled blocks
<andrewrk> foo: { ...; break :foo; } footer();
<marler8997> if we use labeled blocks, why have defer at all?
<andrewrk> defer and errdefer are clearly doing a lot of work to simplify resource management
<andrewrk> by contrast I don't see this proposed successdefer being very significant
<marler8997> I see, successdefer is not common enough to warrant the benefits of keeping init/defer code close together
<marler8997> I think in my case, using "defer foo catch unreachable" is better than using a labeled block
<marler8997> it just seems odd that I have to erase the error type
<lemmi> can't you just use normal defer and an if statement?
<marler8997> it's the "try" that causes the issue
<marler8997> you can't return errors in a defer block
<andrewrk> IMO you're doing it wrong trying to put fallible logic in a defer block
<andrewrk> put your fallible logic in the regular control flow
<marler8997> I agree with the way defer is currently designed, this only makes sense for a successdefer
<lemmi> how would successdefer help with the error return?
<marler8997> with successdefer, the block can return an error
<lemmi> i probably don't know how that should even look. i'm still thinking about something like if (canError()) { defer foo(); }
<marler8997> nah, defer if (something) try foo();
mikdusan1 has joined #zig
mikdusan is now known as Guest59538
Guest59538 has quit [Killed (card.freenode.net (Nickname regained by services))]
mikdusan1 is now known as mikdusan
<lemmi> oh, now i get it
xackus has joined #zig
<marler8997> nice
<lemmi> that almost took 10 minutes. wow :D
xackus__ has quit [Ping timeout: 240 seconds]
SLWW_ has quit [Read error: Connection reset by peer]
drp has quit [Remote host closed the connection]
drp has joined #zig
SLWW has joined #zig
di-wu has quit [Quit: Ping timeout (120 seconds)]
linear_cannon has quit [Read error: Connection reset by peer]
daex has quit [Ping timeout: 252 seconds]
daex has joined #zig
daex has quit [Ping timeout: 252 seconds]
<marler8997> andrewrk, I'm looking into win32/std integration and got some questions if you're available
<marler8997> first question, do we want to keep the "separate functions by dll" design in std?
<marler8997> second question, do we want to trim what's in the std library?
daex has joined #zig
sord937 has joined #zig
daex has quit [Ping timeout: 240 seconds]
daex has joined #zig
sord937 has quit [Ping timeout: 240 seconds]
cole-h has quit [Ping timeout: 240 seconds]
sord937 has joined #zig
SLWW_ has joined #zig
SLWW has quit [Ping timeout: 246 seconds]
xackus has quit [Ping timeout: 265 seconds]
waleee-cl has quit [Quit: Connection closed for inactivity]
sord937 has quit [Ping timeout: 240 seconds]
sord937 has joined #zig
johannes_ has joined #zig
dyeplexer has joined #zig
sord937 has quit [Ping timeout: 240 seconds]
sord937 has joined #zig
casaca has quit [Ping timeout: 246 seconds]
casaca has joined #zig
xackus has joined #zig
[wtf] has joined #zig
[wtf] has quit [Client Quit]
[wtf]1 has joined #zig
[wtf]1 is now known as [wtf]
earnestly has joined #zig
marijnfs has quit [Quit: WeeChat 2.8]
SLWW has joined #zig
SLWW_ has quit [Ping timeout: 268 seconds]
TheLemonMan has joined #zig
zenkuro has joined #zig
leon-p has joined #zig
ssiyad has joined #zig
jokoon has joined #zig
v0idify has quit [Remote host closed the connection]
v0idify has joined #zig
jokoon has quit [Read error: Connection reset by peer]
mokafolio has quit [Read error: Connection reset by peer]
moka has joined #zig
moka is now known as mokafolio
idxu has quit [Quit: ZNC - https://znc.in]
idxu has joined #zig
koakuma has quit [Ping timeout: 240 seconds]
pretty_dumm_guy has joined #zig
geertvl has joined #zig
zenkuro has quit [Ping timeout: 240 seconds]
zenkuro has joined #zig
Bernstein has joined #zig
johannes_ has quit [Quit: leaving]
SLWW_ has joined #zig
SLWW has quit [Ping timeout: 265 seconds]
aigoo has quit [Ping timeout: 250 seconds]
aigoo has joined #zig
klltkr has joined #zig
geertvl has quit [Quit: Connection closed]
meinside has quit [Quit: Connection closed for inactivity]
daex has quit [Ping timeout: 260 seconds]
drp has quit [Quit: Leaving]
waleee-cl has joined #zig
daex has joined #zig
TheLemonMan has joined #zig
ifreund has quit [Quit: WeeChat 3.1]
ifreund has joined #zig
ifreund has quit [Quit: WeeChat 3.1]
ifreund has joined #zig
ifreund has quit [Client Quit]
ifreund has joined #zig
cole-h has joined #zig
<kiedtl> How does one call a Zig function that returns a struct (not a struct pointer) from C? just `struct Foo f = zig_func(a, b, c);`?
ifreund has quit [Client Quit]
aerona has joined #zig
ifreund has joined #zig
<ikskuh> kiedtl: should fit, yeah
plumm has joined #zig
jokoon has joined #zig
pretty_dumm_guy has quit [Ping timeout: 240 seconds]
jokoon has quit [Quit: Leaving]
aigoo has quit [Ping timeout: 245 seconds]
Akuli has joined #zig
aigoo has joined #zig
dyeplexer has quit [Remote host closed the connection]
Zloudef has joined #zig
rxF has joined #zig
Sphax_ has joined #zig
mq32 has joined #zig
Sphax has quit [Ping timeout: 276 seconds]
torque has quit [Ping timeout: 276 seconds]
Cloudef has quit [Ping timeout: 276 seconds]
ikskuh has quit [Ping timeout: 276 seconds]
Zloudef is now known as Cloudef
notzmv has quit [Ping timeout: 240 seconds]
<kiedtl> Can you export a struct method for use by C code? I'm trying that but the linker can't seem to find the fuctions
<mq32> what name did you give the fn? did you reference the struct?
powerofzero has joined #zig
notzmv has joined #zig
Miaourt has quit [Quit: Bye!]
Miaourt has joined #zig
powerofzero has quit [Ping timeout: 260 seconds]
<kiedtl> mq32: `pub export fn foo_to_bar(foo: Foo) Bar {}`
<mq32> hm
<mq32> sounds about right
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
<kiedtl> `objdump -t libfoo.a` doesn't show the symbols I need, either
<kiedtl> so their not being exported at all
<kiedtl> weird
<kiedtl> I'll create some wrapper funcs for now :V
<mq32> can you share some more codE?
<kiedtl> neither methods are being found by the linker
<mq32> you have to reference RGB somewhere to instantiate it
<kiedtl> I'm not sure I follow you... I just use the struct in a regular function?
<kiedtl> oh nvm, I see
<kiedtl> Seems a bit silly imo. The compiler shouldn't be removing structs/methods marked with extern/export even if they aren't being used
<fengb> The opposite. The compiler won't even look at symbols that aren't referenced
Miaourt has quit [Quit: Bye!]
<kiedtl> oh, I see
Miaourt has joined #zig
pretty_dumm_guy has joined #zig
<andrewrk> it can be really handy to have this - for example if you don't depend on fork() then you don't pay for the extra symbols that are exported to make the linker deal with TLS having to do with fork safety
<companion_cube> Has anyone suggested a `lazy` keyword so that this would be opt in? It's a bit of a footgun
<companion_cube> Code looking all good until you start using it...
<andrewrk> I think the time has passed for casual language modification proposals
<ifreund> +1
<andrewrk> whole-file-astgen will be able to catch a lot of this stuff. it will be able to tell if you used `export` but it's not even possible to reference it
<andrewrk> so much so that people will be asking for sloppy mode, and the answer will be no
<companion_cube> So we're closer to a language spec? :)
[wtf] has quit [Quit: [wtf]]
powerofzero has joined #zig
<powerofzero> Is there a way to get stdout to be displayed as it happens from a test?
sord937 has quit [Quit: sord937]
<andrewrk> powerofzero, no but you might be interested in this accepted proposal: https://github.com/ziglang/zig/issues/5738
<mq32> andrewrk: stage2-nollvm will also have assemblers available, right?
<andrewrk> mq32, yes eventually, but that's a big project in and of itself
<mq32> yeah, no hurry!
<mq32> just curious
<andrewrk> here's another `zig test` proposal I opened just now: https://github.com/ziglang/zig/issues/8629
<andrewrk> somebody was asking about this the other day; can't remember who it was
notzmv has quit [Ping timeout: 252 seconds]
ssiyad has quit [Remote host closed the connection]
<mikdusan> kiedtl: fyi #8629 has been opened and related to your question: "Is it possible to make zig continue with the test suite even if one test block fails"
<andrewrk> thanks mikdusan!
<recalloc> i've been learning zig since the 24th, and I have to say: on the surface, it ticks just about every box that I had issue with C. The only issues I have so far are already being addressed in their own github issues
<andrewrk> :) we'll get there
SLWW_ has quit [Ping timeout: 268 seconds]
<andrewrk> the next thing we need is a fast, memory efficient compiler.
<g-w1> the progress is nice!
<g-w1> marler8997: why would you want an option to quit on the first failure?
<marler8997> to eliminate cascading failures
<marler8997> sometimes, the first error can cause a cascade of other failures that are just red herrings
<g-w1> makes sense
<g-w1> not sure i like it though, as you don't control the order of the tests (i think)
<marler8997> not sure you like an option to quit on first failure? or the proposal?
<g-w1> it quite make sense as you dont control the order
<g-w1> like if you get a red herring then it exits, you are now super confused
<marler8997> you wouldn't get a red herring because you would have exited before you got to it
<g-w1> the red herring as the first test
<marler8997> by "red herring", I was meaning, something that failed because of something else
<marler8997> there are other kinds of red herrings
<marler8997> but I was saying that this would eliminate red herrings that are caused by the initial failure, and continuing to run the tests instead of exiting
<marler8997> if a test failed and that's the only test you ran, I don't know how that test could be a red herring...?
<g-w1> hmm, maybe error.ZigTestFailed would let it continue, but panic would stop it?
<marler8997> I think an example would help. say test A is corrupts memory, and it causes test B to fail
<marler8997> if you exit on first failure, you would stop on test A, but if you would continue, it would go on to test B and say it failed as well, even though that test is not broken, it's only broken because test A corrupted it
<marler8997> so in this case, B is a red herring
ur5us__ has joined #zig
<marler8997> I see this sort of thing all the time in firmware, you see errors all over the place and it can be hard to track down the real initial error. Sometimes it can be good to tell the system to just quit on the first error so you don't have to play detective to figure out where things initially went wrong
<g-w1> ok cool, do you think my previous idea of returning an error would let it continue, but panicing would fail it would work?
Akuli has quit [Quit: Leaving]
<andrewrk> that's fine we can have a bail on first error CLI option for the test runner
<marler8997> .
<marler8997> andrewrk, what are your thoughts on splitting the windows bindings in std by the dll they appear in? Do we want to continue this route?
<andrewrk> did you find this issue already? https://github.com/ziglang/zig/issues/4426
<marler8997> will read
<marler8997> oh that one, yes I'm familair
<andrewrk> the split seems natural to me, are you advocating to change it?
<marler8997> with the generated bindings, we now have a good idea of how big a full set of win32 bindgs is: https://github.com/marlersoft/zigwin32/tree/main/src/win32
<marler8997> andrewrk, not necessarily, just wondering what your thoughts were on it
<marler8997> for example, I could put all the win32 bindings in a single file
<andrewrk> ah I see the nature of your question now
<marler8997> btw, full bindings is about 43 MB of source code
<andrewrk> haha let me run astgen on everything.zig :)
<marler8997> I didn't include everything.zig in that, 55MB including that :)
<marler8997> everything.zig more of an idea at the moment
<marler8997> it's 12 MB on its own!
<andrewrk> I think the goal should be to split it so that as much as possible remains unloaded if unneeded
<marler8997> so design the file structure by category/commonaility of use?
<andrewrk> I'm not even sure we would want this in the std lib? we can get by with a minimal set of bindings
<andrewrk> it would be a pretty useful third party package tho
<marler8997> now way, I don't think we should include the full set of bindings in std
<marler8997> I like your first option
notzmv has joined #zig
<marler8997> what I'm thinking is, we maintain a list of all the functions that std requires and/or wants to pull in
<marler8997> this would in turn pull in the types and constants it needs as well
<marler8997> I modify my tool to take this list and generate the std bindings and the "extended" bindings
<andrewrk> ah I see
<andrewrk> that's neat
<andrewrk> if it's a custom built thing for exactly what we need, probably all in a single file would be nice
<marler8997> so, I suppose std could maintain a list of functions it wants, and the files they would go into
<marler8997> or a single file
<marler8997> I'll start with a single file then, and go from there
<andrewrk> nice, everything.zig astgens without fail: https://clbin.com/i8WNZ
<marler8997> of course it does, I wrote it :)
<andrewrk> ah this is my draft stage2 branch
<andrewrk> check out those stats, it's pretty interesting
<marler8997> 7 MB of tokens !
<andrewrk> with the self-hosted compiler, that 19 MiB Total ZIR bytes is what gets cached for everything.zig, and then on subsequent builds, Source bytes remain unloaded on disk, and Tokens and AST Nodes do not get computed at all
<andrewrk> so we end up loading 20 MiB from disk instead of 27 MiB, and skip all the tokenization, parsing, and lowering to ZIR steps
<marler8997> ah I see, that's cool to see
<marler8997> what about zigwin32/api/internet_explorer? that's the next biggest one but includes more than just aliases
<andrewrk> internet_explorer.zig:967:28: error: enums do not support 'packed' or 'extern'; instead provide an explicit integer tag type
<andrewrk> I'm going to advocate for breaking the language soon to remove support for enums with aliased fields
<marler8997> aliased field?
<andrewrk> status quo: the only difference between extern enum(T) and enum(T) is that the extern enum(T) allows field aliases. you're actually unknowingly introducing complexity into the compilation by using extern enum and then not taking advantage of aliased fields
<andrewrk> the original motivation for allowing aliased fields was translate-c: https://github.com/ziglang/zig/issues/2115
<marler8997> what's a field alias though?
<andrewrk> I'm going to push back on this
<andrewrk> const Example = extern enum(c_int) { a = 1, b = 2, c = 1 }
<andrewrk> a and c are aliases
<marler8997> ah
<marler8997> so if I see multiple enum values with the same value, I should choose one?
<andrewrk> status quo: choose enum with an explicit int tag for ABI compatibility; only choose "extern enum" when you want to have aliased fields
<marler8997> but if/when enum aliases are removed completely?
<andrewrk> then I suggest to do something like this: const Example = enum(c_int) {a = 1, b = 2, pub const c: Example = .a;};
<andrewrk> here's the stats after s/extern enum/enum/: https://clbin.com/PdS8A
<marler8997> is the motivation behind removing aliases just because aliases are bad practice? Like, there's no reason to support them?
<andrewrk> they also complicate comptime reflection code trying to do stuff with enums
<andrewrk> for example if you try to use std.enums.directEnumArray with an extern enum it ends up being O(N^2) at comptime for some reason
<andrewrk> the existence of field aliases complicates stuff. defining enums to have a mapping bijection of fields to values makes them simpler and more useful
<marler8997> would the ".Foo" syntax work with "enum { pub const Foo = ... }" ?
<andrewrk> no
<marler8997> the reflection things is one of the issues I remember considering when I looked into @fieldAlias
<marler8997> my solution to that was to include them in a seperate list outside of normal fields
<marler8997> dang, there's 1577 instances of enum aliases in win32!
<andrewrk> and they're all legacy compatibility kludges
<marler8997> I can't argue with that
<marler8997> astnodes takes alot more memory in the internet_explorer example
<marler8997> my guess is it would be even higher percentage in implemenation code
<marler8997> the win32metadata project is done so weird btw, it also seems very unorganized and unplanned
<marler8997> they've made some commits that have broken things horribly in the metadata, so it seems like they have no real testing
<marler8997> for a project like this that has many users, I would think to employ a healthy amount of TDD but it's more like hacks on top of hacks
bitmapper has quit [Quit: Connection closed for inactivity]
<andrewrk> the ratio of (source bytes + tokens + ast nodes) / Total Zir bytes is nearly identical
<marler8997> I was just looking at source / ast
<marler8997> well, that's what my comment was about anyway
<andrewrk> yeah that's interesting too
<marler8997> I'm gonna have to go implement logic to detect and de-alias enums now...bleh
<andrewrk> oh snap this whole time I have forgot to count the main_tokens array into AST Nodes byte count
<andrewrk> marler8997, wait for the result of https://github.com/ziglang/zig/issues/2115
<marler8997> ok will do
<marler8997> you give good points about not including the aliases though
powerofzero has quit [Ping timeout: 240 seconds]
notzmv has quit [Ping timeout: 252 seconds]
karchnu has joined #zig
<karchnu> Hello. Is anyone has a usage example of std.event.Loop? Thanks!
<karchnu> I searched for it, I didn't find anything. The code isn't obvious, and tests are very limited.
<karchnu> And ziglearn chapter about it stopped explanations right before the event loop. :D
<karchnu> All I want to do is to implement a very small netcat, both connecting to a server and listening to any user input.
allan0 has quit [Ping timeout: 240 seconds]
allan0 has joined #zig
pretty_dumm_guy has quit [Quit: WeeChat 3.2-dev]
<marler8997> thats my version of netcat, coded to be simple
<karchnu> marler8997: perfect, thanks!
<karchnu> defer args = args[0..newArgsLen]; <- that's a nice one
<marler8997> lol, yeah that one's kind cool :)
ssiyad has joined #zig
<karchnu> it's working great, but from what I see in eventing/ you implement a lot of stuff to make it work