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/
<g-w1> i was thinking about it the wrong way, from the outside, not the inside. i had pub usingnamespace in mind
<andrewrk> ah
<g-w1> probably a brainfart, but any reason you can't just use bits.thing instead of just thing?
<g-w1> with s/usingnamespace/const bits =
cole-h has quit [Ping timeout: 246 seconds]
<andrewrk> the main use case that keeps usingnamespace alive is `pub usingnamespace foo;` in order to organize the public declarations of a file for a different file to import
eyepatchOwl has joined #zig
tnorth has quit [Ping timeout: 276 seconds]
<g-w1> ahh i see, thanks so much
<g-w1> yeah it seems like it can't be worked around witout meghans export default thing
<g-w1> which i am not a fan of
<andrewrk> https://clbin.com/sy28L back in business with incremental compilation
<kiedtl> How does one check if a call to @intCast would truncate bits?
<g-w1> num > 2 ^ bitsoftarget ?
<g-w1> wow we got the test harness compiling! yay
<g-w1> *you :)
<g-w1> does 2188324676 or 0x826f2f44 look fishy?
<g-w1> seems like a pointer addr right?
notzmv- has quit [Ping timeout: 240 seconds]
daex has quit [Ping timeout: 240 seconds]
daex_ has joined #zig
lonjil has quit [Ping timeout: 276 seconds]
lonjil has joined #zig
zenkuro has quit [Ping timeout: 252 seconds]
lonjil has quit [Ping timeout: 276 seconds]
lonjil has joined #zig
recalloc has joined #zig
earnestly has quit [Ping timeout: 246 seconds]
aengin has quit [Quit: Connection closed]
notzmv has joined #zig
recalloc has quit [Quit: leaving]
cole-h has joined #zig
wilsonk_ has joined #zig
wilsonk__ has joined #zig
wilsonk has quit [Ping timeout: 245 seconds]
wilsonk_ has quit [Ping timeout: 260 seconds]
<andrewrk> kiedtl, std.math.cast
<andrewrk> fun fact: stage1 is 78795 lines of code; stage2 is 118965
<mikdusan> just wait until the c-backend rewrites stage1 :)
clee has quit [Quit: brb]
<txdv> andrewrk: does it have more code because because of data oriented programming or because it has more features?
<mikdusan> +more code for memory management too
<andrewrk> it has more tests, more features, more backends, a self-hosted linker, and also part of stage1 is implemented in stage2 :)
<andrewrk> when you run `zig fmt` that's not touching any c++ code
eyepatchOwl has quit [Quit: Connection closed for inactivity]
<mikdusan> yeah true that; a visible feature entirely impl in stage2 is zig-cache
<andrewrk> also translate-c, zig cc, the linker driver
<andrewrk> CPU feature detection
<andrewrk> building glibc, musl, libcxx, libcxxabi, libunwind, libtsan
waleee-cl has quit [Quit: Connection closed for inactivity]
<txdv> it has so many more features and is only 119k lines of code compared to the old 78k?
<andrewrk> that's right, however it's also far from complete
<andrewrk> stage2 is still behind a feature flag
<txdv> In your last stream I saw that stage2 can compile an empty program, do you have a rough ETA when you will reach feature parity with stage1?
<andrewrk> I am now confident that we will be shipping stage2 rather than stage1 as the compiler by 0.9.0, in 7 months from now
<txdv> Compiling an empty program successfully is already a super huge step, having something working and adding incrementally features is so much easier.
<andrewrk> there are plenty of already passing test cases for stage2, but much remains to be done: https://github.com/ziglang/zig/tree/master/test/stage2
<andrewrk> I have major progress done in the stage2-whole-file-astgen branch, which is on a trajetory to merge within a few more days
<txdv> zig is really into TDD, they way you discard code and just reimplement everything until the tests run is awesome to watch
<txdv> or at least into tests :)
<andrewrk> TDD doesn't work for every kind of application/problem domain, but you'd be a fool to not do it for a compiler implementation :)
<mikdusan> someday I hope to see a clever test runner that can run through *in order* tests that follow zig's language specification, section by section
<mikdusan> the current langspec does that to a huge degree but I'm not sure how it will play out with aa formal spec
<mikdusan> *langref*
<txdv> I think that feature would be too concrete, something like returning the metadata of a testrun and then formatting the output accordingly utilizing a language spec would be more future proof
<andrewrk> mikdusan, that's a neat idea
rbino has quit [Ping timeout: 250 seconds]
leon-p has joined #zig
<cr1901_modern> I do like how Zig encourages me to write tests early because it'll optimize out my whole program if I don't use code :)
rbino has joined #zig
sord937 has joined #zig
<txdv> o yeah, it will just parse the syntax tree and see that you are not using it anywhere and not do anything at all with it :D
[wtf] has joined #zig
cole-h has quit [Ping timeout: 252 seconds]
hiljusti has joined #zig
earnestly has joined #zig
marijnfs has joined #zig
Bernstein has joined #zig
marijnfs has quit [Ping timeout: 250 seconds]
marijnfs has joined #zig
shachaf has quit [Ping timeout: 265 seconds]
aigoo has quit [Ping timeout: 246 seconds]
shachaf has joined #zig
aigoo has joined #zig
pretty_dumm_guy has joined #zig
haliucinas has quit [Ping timeout: 260 seconds]
haliucinas has joined #zig
hiljusti has quit [Ping timeout: 260 seconds]
di-wu has joined #zig
<betawaffle> i like how Go does testing, but i think Zig did it even better by allowing (and encouraging) tests to be colocated with the code they are testing
antaoiseach has joined #zig
<antaoiseach> hello folks, how do I print a 2-d matrix? I can print a 1-d array using a slice parameter, but I can't make the types match for the 2-d array. Here is what I have tried - https://paste.rs/HrB
<antaoiseach> Could someone please take a look at it? Thanks
<antaoiseach> :-)
<antaoiseach> Also, I am a bit unclear about if I should/can pass it by reference directly as a pointer - like so: &my_arr, but maybe I need to sort this slice param style out first.
<mikdusan> is your matrix always going to be based on `[3]i32` ?
<mikdusan> or more flexible like sometimes x3 somtimes x2
<antaoiseach> mikdusan: I don't like where this is going :D ... hahaha, just kidding
<antaoiseach> mikdusan: yeah, I was thinking flexible sizes
<antaoiseach> I checked the zig source too - but I find some uses of [][]const u8 in literal form, no other uses
<antaoiseach> Is it not possible to have an open-sized version?
<mikdusan> you can but it's always about storage
<antaoiseach> okay
<antaoiseach> right, so if I make the signature fn displayMatrix(comptime T: type, mat: *[2][3]T) void {
<antaoiseach> then it works (predictably), but isn't there a wat to elide the params so that I could pass in any size?
<antaoiseach> like for the 1d array
<antaoiseach> I don't mind not using slices, just raw pointers would be fine too
<mikdusan> the prob is the inside to be of unknown-length needs to be a slice and a slice needs some storage
<mikdusan> it might be better to comptime this
<mikdusan> like since you already have i32
<antaoiseach> I get what you're saying...
<antaoiseach> Hmm
<antaoiseach> So this is similar to what you're implying right? fn displayMatrix(comptime T: type, mat: [][3]T) void {
<antaoiseach> So this works, and I pass the arr in as arr[0..]
<antaoiseach> but the 3 is fixed
<antaoiseach> So in this case, would a nested List work? (I haven't reached Lists/stdlib yet)
<antaoiseach> mikdusan: sorry, I didn't get the comptime bit.. how do you mean?
<mikdusan> you already have first param as comptime, so let's pass the innermost array kind
<antaoiseach> checking
<antaoiseach> mikdusan: yes, I think that also works well enough, since the display function is still generic and the client should know the size anyway
<antaoiseach> Thank you!
<mikdusan> thus your fn accepts any number of rows at runtime, and cols is static. you'll get 1 specialized function for each comptime T
<mikdusan> unique comptime T
<antaoiseach> mikdusan: right, that makes sense..
<antaoiseach> so, again, just curious - suppose I have a List of List, would this slight problem not exist then?
<antaoiseach> (I could try it out, but I'm still working through the ziglearn site)
<mikdusan> a list of a list; because each row has a list, each row would need more than "oh it's an i32". need to know how many i32, in other words a length. simple arrays are tight and don't end with a length in their runtime data. their length is statically (comptime) known
<antaoiseach> mikdusan: right, so basically you're saying a List(List(i32)), say, would work because it has its length info encoded in it, right?
<mikdusan> yes that's the idea
<antaoiseach> mikdusan: Okay, that makes sense again. Thank you so much for you help1 :-)
<mikdusan> as a raw example, [][3]i32 you want to become [][]i32 so here's the data comparison:
<mikdusan> first one is a pointer to LEN of { a,b,c } and { a,b,c} is always 3-long .
<antaoiseach> right
<mikdusan> 2nd on is a pointer to LEN of { pointer to LEN of i }
<mikdusan> ah I messed that last bit up
<mikdusan> coffee please
<antaoiseach> Hahaha
<antaoiseach> so the second would be the len of a, which must be the len of b and c, right?
zenkuro has joined #zig
<antaoiseach> oh no, that would be reversed
<antaoiseach> Hmmm...
<mikdusan> fyi, you can think of a slice as a struct { ptr, len }
<antaoiseach> right ... a fat pointer, yeah/
<antaoiseach> ?
<antaoiseach> so we read it from right to left, or left to right?
<mikdusan> read nature left to right. where u see "[]" there is a pointer. and it has a runtime length
<antaoiseach> right
<antaoiseach> but if the row length is always fixed, why can't that length be inferred?
<antaoiseach> (assuming that the ptr for the first dimension is again a fat one)
<mikdusan> maybe I have this matrix rows/cols backwards in terminology. I was assuming for `[2][3]i32` it is 2 rows and in your code it is comptime known to have 2 rows, of 3
<mikdusan> and the fn we made, as runtime flexible for rows
<mikdusan> you can make it comptime for rows and cols if you want too
<antaoiseach> mikdusan: hah, why didn't I think of that? Lemme try that and get back
<antaoiseach> yes, displayMatrix([2][3]i32, matrix);
<antaoiseach> works fine if I change tha signature to: fn displayMatrix(comptime T: type, mat: T) void {
<antaoiseach> It does seem a bit weird - that signature, but it's fine I think
<mikdusan> there's a lot of ways to skin this cat; this one may be over the top because it's duck-type city:
<antaoiseach> Nice!
<antaoiseach> So the anytype one is checked at comptime or runtime?
<mikdusan> anytype is comptime
<antaoiseach> That's great!
<antaoiseach> I think I like this in terms of convenience though the signature does get a bit obscured - would have been nice to have a [][]T signature, but that's okay
<mikdusan> it will result in an explosion of displayMatrixGeneric functions, 1 each per whatever zig considers to be a unique type
<antaoiseach> hahaha.... yeah
<kiedtl> Can you get a mutable (non-const) pointer to an optional type after unwrapping it? Basically, I'd like to change ?Type to ?*Type
<antaoiseach> mikdusan: thank you so much for the help and the convo, man - it was very very helpful. :-)
<mikdusan> kiedtl: if you want to mutate after unwrapping, change `|uw_value|` to `|*uw_value|`
<antaoiseach> I'll get back to the tutorials now, and I'll be back with more scenarios! Cheers!
<kiedtl> mikdusan: Ah, thanks
antaoiseach has quit [Quit: leaving]
TheLemonMan has joined #zig
pretty_dumm_guy has quit [Quit: WeeChat 3.2-dev]
zenkuro has quit [Ping timeout: 252 seconds]
zenkuro has joined #zig
Biolunar has quit [Ping timeout: 260 seconds]
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
[wtf] has quit [Quit: [wtf]]
xackus has joined #zig
qbit has quit [Ping timeout: 260 seconds]
cole-h has joined #zig
qbit has joined #zig
Akuli has joined #zig
hiljusti has joined #zig
xackus_ has joined #zig
xackus__ has joined #zig
xackus has quit [Ping timeout: 240 seconds]
xackus_ has quit [Ping timeout: 240 seconds]
TheLemonMan has joined #zig
notzmv has quit [Ping timeout: 252 seconds]
hiljusti has quit [Ping timeout: 276 seconds]
marijnfs has quit [Ping timeout: 258 seconds]
wootehfoot has joined #zig
daex_ has quit [Ping timeout: 265 seconds]
daex has joined #zig
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
motersen has quit [Remote host closed the connection]
motersen has joined #zig
<andrewrk> mikdusan, peak RSS for stage2 to astgen all of the std lib, minus peak rss to print the --help menu, is 45 MiB
<andrewrk> it goes down to 18 MiB when the cache is warm
<andrewrk> a bit more efficient than stage1 ;)
<Nypsie> wow
waleee-cl has joined #zig
<mikdusan> we're going to be able to test on 32-bit hosts soon :)
notzmv has joined #zig
ovf has quit [Read error: Connection reset by peer]
eddyb[legacy] has quit [Ping timeout: 260 seconds]
eddyb[legacy] has joined #zig
ovf has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
Bernstein has quit [Remote host closed the connection]
<g-w1> is there a way to test the memory of stage1 "astgen"?
<g-w1> or would you have to hack stuff?
<ifreund> g-w1: afaict, "astgen" isn't as anywhere near as clearly separated in stage1
<g-w1> oh yea, iirc function types are Sema'd before the body is "astgened"
<g-w1> thats how functions that return comptime values execute in a comptime-only context
wootehfoot has joined #zig
<g-w1> i would suspect most of the memory is in sema
<mikdusan> most of the memory is comptime. I think even induction variables cause alloc on every iteration which are never freed
Anzh has joined #zig
wootehfoot has quit [Quit: Leaving]
eyepatchOwl has joined #zig
recalloc has joined #zig
patwid has quit [Ping timeout: 246 seconds]
allan0 has quit [Ping timeout: 246 seconds]
allan0 has joined #zig
patwid has joined #zig
cr1901_modern has left #zig [#zig]
<kiedtl> Are there any stdlib function for saturating arithmetic?
<kiedtl> that is, arithmetic functions that saturate instead of panicking/wrapping on an overflow
<mq32> not yet, no
<kiedtl> That's fine, it should be trivial to define
<kiedtl> If it were added, what stdlib module would it be in? std.math?
<mq32> there's a proposal for adding it as a language feature
<ifreund> kiedtl: It is planned to add language support for saturating arithmetic
<kiedtl> oh... interesing.
<kiedtl> that's a lot of operators
<eyepatchOwl> I personally don't like multi symbol operators.
<ifreund> I'm not totally sure if the operator or builtin variant is accepted
<eyepatchOwl> I can make some exceptions for particularly common ones like ++, but I don't like <*>. I think you might as well use keywords at that point.
<kiedtl> Given that we already have the +% -% *% etc operators, we may as well add +| -| etc.
<eyepatchOwl> +|= seem worth it to me.
<kiedtl> four more operator variants can't hurt :P
<kiedtl> well, eight
<eyepatchOwl> Not a fan of +%.
<eyepatchOwl> Or at least skeptical.
<andrewrk> it's not really up for debate
<companion_cube> proposal for floats operators to be +💩, /💩, etc.
<mq32> i mean, i needed wrapping operators twice yet
<kiedtl> companion_cube: why would separate operators for floats be needed?
<mq32> because they're a troll
sord937 has quit [Quit: sord937]
<companion_cube> well they're separate in OCaml :-)
<companion_cube> (it's weird at first but not that bad, after all they're an entirely different beast than integers)
<mq32> well, you cannot mix int and float in zig either, so i don't really care
<companion_cube> but yes, the 💩 emoji was indicating my non seriousness.
<andrewrk> I remembered why I've been using test2.zig for the last 2 weeks
<andrewrk> I cracked open test.zig today and found the test case that inspired the entire branch, and it passed!
<mq32> that looks quite cool
<andrewrk> also apparently C allows $ in identifiers? ok
<mq32> that's a good question…
<g-w1> andrewrk: thats amazing progress. when I try that I get this :( https://clbin.com/jrj6P
<g-w1> ive been trying to debug this over the past 2 days, but its pretty hard
<andrewrk> I just pushed something
<g-w1> 2 seconds late, new record
<andrewrk> lol I didn't push it til you spoke up
<g-w1> oh lol
<g-w1> https://clbin.com/rRSee still getting this <-
<g-w1> and its been that same over the past few days.
<g-w1> do you have anything special in your setup?
<andrewrk> print the decl_index, sema.owner_decl.name, and sema.owner_decl.namespace.file_scope.sub_file_path, and then run astgen for the file, and look at %decl_index in the file
<g-w1> sounds good, very happy to help :D
klltkr has quit [Quit: Textual IRC Client: www.textualapp.com]
<andrewrk> expected output is: test.zig:4:9: error: use of undeclared identifier 'thing1'
<andrewrk> that's what I get
<g-w1> hmm, not seeing a sema in scope
<andrewrk> zig should never make it to semantic analysis
<g-w1> this is in Module.scanDecl
<andrewrk> that's semantic analysis
<andrewrk> look at the call stack
<g-w1> ah, the same thing happens with just `pub fn main() void {}`
<g-w1> ok, lemme nuke the build, i feel like something weird is going on with cmake
<andrewrk> make sure your `zig version` is different since that's how it namespaces the cache, otherwise you might be looking at garbage cached ZIR data from an old commit
<recalloc> Forgive me if this is already answered somewhere, but what's the motivation for `while (cond) : (postloop)` over `for (init; cond; postloop)`
<g-w1> ohhhhhhhh, could it be globally cached?
<andrewrk> ZIR for the std lib is globally cached
<g-w1> that could be it, ok cool trying
<andrewrk> if you built with `zig build` after pulling there should be no problem though because it puts the commit sha into the version
<andrewrk> if you built with cmake I could see there being a problem
<g-w1> i built with cmake
<andrewrk> ok that explains it
<andrewrk> cmake doesn't figure out to re-run git
<g-w1> yayyyyyyyyyyy it works!!
<g-w1> thanks so much
<g-w1> time to play around with stuff
<andrewrk> the next thing I'm doing is getting the stage2 tests passing again
<andrewrk> looks like extern functions regressed
<g-w1> ok cool, if i see something up my alley ill try to fix
<g-w1> it does look like extern functions regressed
<andrewrk> recalloc, there is already variable initialization syntax, and there is already block syntax for limiting the lifetime of locals. no redundant feature for loop syntax needed
<recalloc> I see, thanks!
<ifreund> also, it's consistent with if statements
<andrewrk> {var i: usize = 0; while (i < 10) : (i += 1) { ... }}
<g-w1> what are your thoughts about the compitme call stack? tbh i find it kinda annoying and not that helpful.
<andrewrk> I'm guessing you mean the "referenced here" notes, not the comptime call stack
<g-w1> yea, the compile errors are verbose in the wrong ways a lot
<andrewrk> the comptime call stack is the only way to understand where the actual error is when e.g. you have a missing parameter to std.fmt.format
<g-w1> can't the compile error just tell you?
<ifreund> it would be really annoying if it didn't point at where you called fmt.format()
<andrewrk> the "referenced here" notes is a half ass attempt I made to solve a specific problem I ran into regarding async functions, in order to figure out why some compile error was happening. I don't intend to kludge it the same way
Akuli has quit [Quit: Leaving]
<g-w1> ok cool
patwid has quit [Ping timeout: 246 seconds]
<g-w1> it wouldn't make sense to switch the test cases to `pub fn main` from _start for now because it will eventually just go in test "thing" right?
<andrewrk> check my BRANCH_TODO file again ;)
<g-w1> nice, * get behavior tests passing for stage2 <- does this mean at least one?
patwid has joined #zig
<andrewrk> yeah the test runner and then move some of the standalone tests to be behavior tests
<g-w1> awesome, i think that will speed up dev time a lot
<andrewrk> even for stage1 it only takes 6 seconds to compile & run the behavior tests
<andrewrk> well for the native target anyway
notzmv has quit [Ping timeout: 260 seconds]