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/
clktmr has quit [Ping timeout: 265 seconds]
<frmdstryr> Are there any modules for working with dates?
adamkowalski has joined #zig
<daurnimator> frmdstryr: not really. what operation are you after?
<adamkowalski> andrewrk: how do you handle random number seeds in Zig?
<daurnimator> adamkowalski: what do you mean?
<daurnimator> adamkowalski: just see std.rand
<adamkowalski> One of the biggest pain points in our current project is that random seeds are a global mutable variable in Python. You're allowed to set the random seed, but if you run multiple simulations in parallel they blow over each other and lead to non deterministic results. It makes unit testing extremely hard for random processes.
<daurnimator> adamkowalski: you can instantiate your own RNG. just seen std.rand...
<adamkowalski> Also there are many different machine learning libraries and they all use their own internal random number seed rather than using Pythons. So even if you do everything right, calling out to some other library may use a random seed under the hood and you can't touch it
<andrewrk> adamkowalski, https://ziglang.org/documentation/master/std/#std;crypto.randomBytes
<adamkowalski> The one i've seen do things correctly is Jax. Where seeds are "consumed" when using something like random.normal
<frmdstryr> timestamp to that date format
<daurnimator> var myrng = std.rand.Xoroshiro128.init(myseed); const myrandomnumber = myrng.random.int(u32);
<adamkowalski> that means the seed is not a global, but instead a local variable that you can create, and consume
<andrewrk> some of those errors could be cleaned up, it's not actually possible to get NoSpaceLeft from that function
<adamkowalski> if you want to use your random number seed more than once, you must call split on it, which gives you back two random seeds
<daurnimator> actually std.rand.Random is perfect to become a mixin!
<adamkowalski> now you pass one random seed to the random seed consumer, and can still use the second one down the road
<daurnimator> andrewrk: would you be happy to merge a mixin-ification of Random?
<andrewrk> daurnimator, I need to think really hard about mixins in general
<adamkowalski> So in zig you would create a a rng with std.rand.Xoroshiro128, then everything that wants to generate random numbers will take in a rng?
<adamkowalski> Sort of like an allocator
<andrewrk> adamkowalski, yes
<andrewrk> and std.crypto.randomBytes you would call once to get a seed from the OS
<adamkowalski> okay but libraries should never do that right? they will expect to receive everything from the client program. So you never have to worry about random numbers being generated behind your back that you can't control?
<adamkowalski> Also is Xoroshiro thread safe?
<adamkowalski> well if two threads both say rng.random.int(u3) what happens?
<daurnimator> hmmm... we define socklen_t as a u32. but it's a signed integer on both linux and windows
<daurnimator> andrewrk: ^ intentional?
<mikdusan> at least io_uring is sane and uses u32
<andrewrk> adamkowalski, yes I think best practice would be to accept a seed parameter. as for how much you need to worry about what goes on behind your back, that's something you have to think about when you decide whether to take on dependencies or not
<andrewrk> it is entirely possible for code that you have not vetted to do something silly
<andrewrk> I don't think zig is going to try to solve that problem. that's out of scope
<andrewrk> adamkowalski, generally, everything is thread-safe with respect to its own state, unless stated otherwise
<adamkowalski> Well it maybe not be possible to "solve" but I feel like Zig does a great job with allocators. At least by convention everybody who allocates takes an allocator so I know who will be doing that
<andrewrk> if something additionally claims to be thread-safe, such as a thread-safe queue, what it is saying is that it is additionally thread-safe with respect to the *same state*
<adamkowalski> So if we adopt a similar convention for random numbers I'll be really happy
ur5us has quit [Ping timeout: 245 seconds]
<andrewrk> adamkowalski, i'd be happy to add to the doc comments of std.crypto.randomBytes that it is advised to leave this call up to the application; libraries are encouraged to accept a seed parameter
<adamkowalski> I just don't want people calling random.normal(.{mean=0, standard_deviation=1})
<adamkowalski> they should alwauys have to pass in a resource which is responsible for the providing the random value
<adamkowalski> that also means for testing there need not be any randomness at all. You can make your random resource provide some mock value so you can assert things about your "random" process
<andrewrk> daurnimator, if negative values are always illegal then u32 is more correct. maybe even u31. but if an API wants to handle -1 in a certain way, e.g. mmap, then it would probably be better to use i32
<andrewrk> wait this is socklen_t? how colud that ever be negative?
<Snektron> Of course theres the Ziggurat random
<Snektron> andrewrk: for unix, i assume because either int is "the standard datatype", something returning a socklen_t can also return an error, or maybe because someone thought ints are faster
<Snektron> probably the first
ur5us has joined #zig
<andrewrk> zig has a better api than this though. the syscall gives us a usize, which we check for errors, then return E!socklen_t
<andrewrk> so we've successfully removed the possibility of negative values from the type
<mikdusan> daurnimator: archlinux I think is unsigned: https://gist.github.com/mikdusan/c617891678a75f4324cace030a6f8ebc
<daurnimator> mikdusan: ah interesting. then I see e.g. /usr/include/pcap/socket.h:58: typedef int socklen_t;
<mikdusan> also: /usr/include/bits/types.h:__STD_TYPE __U32_TYPE __socklen_t;
<Snektron> adamkowalski: that sounds like how the c++ random api works
<daurnimator> okay so lets go back a bit; I accidentally XY problem-ed
<daurnimator> on windows, connect() takes a DWORD i.e. i32 as the address length argument
<Snektron> I think <random> is a pretty solid part of the STL
<Snektron> like <chrono>
<daurnimator> should I 1. change socklen_t to i32 on windows? 2. "fix" the connect() signature?
<andrewrk> daurnimator, yeah fix the signature. negative values are invalid, right?
<andrewrk> so the signature is incorrect
<andrewrk> i32 and u32 have the same ABI
adamkowalski has quit [Quit: Lost terminal]
<daurnimator> k
qbradley has quit [Remote host closed the connection]
ur5us has quit [Ping timeout: 245 seconds]
ur5us has joined #zig
protty has joined #zig
<andrewrk> mikdusan, I'm gonna add IrInstruction::dump() so we can call it from gdb, it'll print the source location and the line from zig ir to stderr
adamkowalski has joined #zig
<Snektron> Im curious as to why Zig went for c-style c++ for the stage1 compiler
<andrewrk> "debug your application, not your c++ expertise"
<Snektron> Surely more c++ language features than just basic templates are useful
<andrewrk> in my experience, any attempt to utilize C++ features turns into meta programming real fast
<Snektron> I think a prime example of good features are namespaces and enum classes
<andrewrk> enum classes are probably fine
<Snektron> andrewrk: i dont really get it that often tbh, though i do agree that metaprogramming is messy
<companion_cube> isn't the stage1 compiler kind of throwaway anyway?
<andrewrk> companion_cube, nah, it's immortal: https://github.com/ziglang/zig/issues/853
<Snektron> Although most of my c++ programs are only a few thousand lines at best
<companion_cube> I feel like wasm could simplify that :p
<andrewrk> how?
<andrewrk> Snektron, enum classes look like what I should have been using all along
<companion_cube> compile self hosted to wasm
<companion_cube> boostrap from wasm anywhere
adamkowalski has quit [Ping timeout: 276 seconds]
<andrewrk> companion_cube, I think that issue might be worth reading for you, it addresses why this isn't viable
<companion_cube> (ocaml does that but from its own bytecode)
<Snektron> andrewrk: dislike template metaprogramming? Do i have the project for you: https://github.com/Snektron/HeadacheMachine
<Snektron> andrewrk: great ;)
<companion_cube> between reading wasm and reading C++, I'm not sure which one is the worst ;)
<andrewrk> mikdusan, wow. why didn't i do this years ago? https://clbin.com/7B9k6
lunamn has quit [Quit: leaving]
<Snektron> companion_cube: c'mon its not that bad
<Snektron> Though i don't have much wasm experience
adamkowalski has joined #zig
<companion_cube> 😂
<companion_cube> yeah ok, C++ is still better, but that's a bit sad :(
<andrewrk> one project I am interested in, eventually, is to have a bootstrapping repository, that gets you from machine code short enough to type into an editor (probably RISC-V?), to an assembler, to a simplistic C compiler, to a more advanced one, to a zig compiler, to self-hosted zig, to self-hosted zig built with self-hosted zig
<andrewrk> which can then cross compile for all the other targets
<companion_cube> why not replace "assembler+simplistic C compiler" with "simple lisp interpreter"? :)
adamkowalski has quit [Ping timeout: 276 seconds]
<Snektron> Even better: use brainfuck
<Snektron> andrewrk: how would that handle different architectures?
<protty> hey, if you have a `const T = extern struct { tail: u16, head: u16 }`will an atomic u16 store to tail potentially invalidate a `cmpxchg(@ptrCast(*u32, t_ptr))`?
<companion_cube> well, lisp is actually usable? :D
<daurnimator> andrewrk: https://github.com/oriansj/stage0
<andrewrk> protty, what do you mean by invalidate?
<fengb> Wasm is just a stack machine. It’s “simple”
<protty> like a `STORE(ptr, 1)` would make a `CAS(ptr, 0, 1)` fail
<companion_cube> the text representation of wasm isn't too bad, is it?
<fengb> Besides... the default text representation of wasm is s-exprs so it’s basically a lisp 🙃
<andrewrk> protty, you mena like if they were racing in 2 different threads?
<protty> yes
<daurnimator> protty: but also. why on earth are you using a realtime clock there
<daurnimator> should be monotonic
<andrewrk> yeah, oops I missed that
<andrewrk> goodness, is that how pthread_cond_timedwait is defined to work?
<andrewrk> looks like pthread_condattr_setclock lets you choose
adamkowalski has joined #zig
<daurnimator> wow. that's terrifying
<protty> 1) modeled it from an example defined here: https://www.ibm.com/support/knowledgecenter/ssw_ibm_i_73/apis/users_77.htm 2) according to std.time.Timer, CLOCK_MONOTONIC doesnt seem to be available everywhere (is this true?)
<andrewrk> protty, I believe that the cmpxchg can observe the modification to `tail`
<daurnimator> protty: CLOCK_MONOTONIC should be available everywhere. it's "optional" in posix, but AFAIK OSX was the last hold out, and fixed their shit in 2013 or so
<daurnimator> protty: the example there is probably from before OSX was updated; or they needed to support old OSX
<protty> i c
<andrewrk> wow, the example code from https://linux.die.net/man/3/pthread_cond_timedwait uses CLOCK_REALTIME
<daurnimator> protty: oh the example is just of timedwait. yeah as andrew found: see `man pthread_condattr_getclock`. I'm frankly amazed they allow non-monotonic
<andrewrk> me too
<andrewrk> protty, sorry, don't mean to gang up on you
<andrewrk> I'm more surprised by the pthread_cond_timedwait API than anything else
<daurnimator> yeah we're ganging up on the man page writers... and pthread designers :P
<protty> am just imagining changing the system clock to go back in time for your pthread_cond_timedwait() to wait even longer
<daurnimator> protty: yeah.. imaging fixing your system clock and having all sorts of programs hang until it got back to the (wrong)time that you fixed it
<andrewrk> or daylight savings time making all your apps freeze
<fengb> But shouldn’t dst apply an offset to system clock, not change it directly?
<daurnimator> fengb: depends if you hwclock is in UTC or local
<daurnimator> many people that dualboot windows will have it in local
<protty> having realize this, it definitely breaks the timeout guarantee in the `std.ResetEvent.wait()` doc comment
ForLoveOfCats has joined #zig
<ForLoveOfCats> What is the proper flags/commands to build the std docs with a build of master?
<mikdusan> andrewrk: indeed... debug/trace helpers ftw
<andrewrk> ForLoveOfCats, -femit-docs (and probably also -fno-emit-bin to save time)
<andrewrk> there's a lot about doc generation that is work-in-progress
<andrewrk> just fyi
<adamkowalski> andrewrk: do you have any tips for building something like std.testing.expect but that can tell you the differences between your structs? Each of my structs now has a custom equality checker like you recommended last time, so I just get a bool the evaluations to false when the test fails.
<andrewrk> adamkowalski, my tip would be to do the most straightforward thing you can think of
<ForLoveOfCats> That's what I thought but I'm having difficulty getting it to do anything, it expects an argument but the `--help` message doesn't specify what it wants. I tried passing it an empty dir (if it wants the output dir) and the std source dir but to no avail.
<adamkowalski> Would it be better to use reflection and check each field of the struct and see if they are different, and if they are then std.debug.warn("{} != {}", expected.field, actual.field)
<andrewrk> ForLoveOfCats, oh, it works in combination with build-exe, build-lib, build-obj, or test
<daurnimator> adamkowalski: isn't that what we do not?
<adamkowalski> If the field is a non primitive type then recursively do the check
<andrewrk> ForLoveOfCats, so, do your normal build, but also add -femit-docs
<daurnimator> s/not/now/
<adamkowalski> it is? I wasn't able to get std.testing.expectEqual to compile with my type
<adamkowalski> I didn't think I was doing anything too crazy. The fanciest types I have are hash maps and arrays of arrays of types
<adamkowalski> switch (@typeInfo(@typeOf(actual))) {
<adamkowalski> thats pretty awesome
<mikdusan> ForLoveOfCats: try this for std doc gen: `zig test lib/std/std.zig -femit-docs -fno-emit-bin --output-dir zig-cache` and then open zig-cache/docs/index.html
<adamkowalski> I'm gonna have to steal that somewhere
<adamkowalski> Ah I found the issue
<adamkowalski> for arrays it calls expectEqualSlices
<adamkowalski> which checks if expected[i] != actual[i]
<adamkowalski> but != only works for primitive types
<adamkowalski> so instead that should call expectEqual again right?
<ForLoveOfCats> No matter what I do it claims `Invalid argument: --femit-docs`
<ForLoveOfCats> including what was just suggested (direct copy paste)
<mikdusan> double dashes != single dash
<mikdusan> some args have single some double. sorry but that's how it is for now.
<ForLoveOfCats> its literally the same with just one dash
<ForLoveOfCats> `Invalid argument: -femit-docs`
<adamkowalski> Would you all accept a pull request to change that != to expectEqual? Or is there some reason why that would be a bad idea
<ForLoveOfCats> I tried both and just copy pasted the latter (where I used double dashes)
<mikdusan> ForLoveOfCats: what version of zig? might be old
<ForLoveOfCats> just pulled
<ForLoveOfCats> one moment
<ForLoveOfCats> 63300a21ddf4cfe209a39796c6d7ea7773e14fd6
<mikdusan> where is my exact command line with 63300a21ddf4cfe209a39796c6d7ea7773e14fd6:
<ForLoveOfCats> beg pardon?
<mikdusan> `zig test lib/std/std.zig -femit-docs -fno-emit-bin --output-dir zig-cache`
<mikdusan> s/where/here/
<ForLoveOfCats> Everything I've done has been on that commit
<mikdusan> zig --help | grep docs
<ForLoveOfCats> already did that with fzf
<ForLoveOfCats> I'm here because I couldn't figure it out
<mikdusan> ok. well i don't know what to say. at this point I must suspect you have a shell alias or wrong binary is found in path
<daurnimator> adamkowalski: yeah that would be an okay change
traviss has quit [Quit: Leaving]
<daurnimator> adamkowalski: though you'll need to figure out how to keep the error message useful
<ForLoveOfCats> oh ffs, it was an alias
<ForLoveOfCats> with all my testing I directly ran the binary but cp your line of course ran the 0.5.* build i have installed
<mikdusan> also in future you can do `zig version` which is a nice quick way to see commit it was built against
<daurnimator> adamkowalski: I think there's a meta.eql :)
<ForLoveOfCats> that wasn't the problem, if I were to have run version I would have run it on the right binary
<ForLoveOfCats> the --help message for this is not very clear
<ForLoveOfCats> probably just misinterpreting
<ForLoveOfCats> probably something like the -f* flags are expected to be run on a build/test
<adamkowalski> daurnimator: wouldn't the error message be taken care of by call to expectEqual?
protty has quit [Remote host closed the connection]
<daurnimator> adamkowalski: but that wouldn't be a useful error message
<daurnimator> adamkowalski: "expected 5 found 12" isn't useful: you want to know e.g. which index/offset it was at.
<adamkowalski> fair enough. i'm open to any proposed ideas
<adamkowalski> I think we need to seperate the checking of equality from printing
<daurnimator> adamkowalski: yes. as I said, see std.meta.eql
<adamkowalski> but even at the root of std.testing.expectEqual
<adamkowalski> wouldn't you have the same issue where only one field from the struct will show up
<adamkowalski> maybe we want to check if the struct is equal to the other, and if not then we want to print both structs and make the differences be green on expected, and red in actual
<adamkowalski> for arrays we can print the whole array (or print the "n" nearest items if the list is too long, and again mark with color the differences
<adamkowalski> speaking of which, how do custom types register a custom handler for std.debug.warn?
<adamkowalski> similar to overloading repr in python or ostream for c++
<mikdusan> adamkowalski: see lib/std/fmt.zig test "formatType max_depth"
<mikdusan> or test "custom"
<adamkowalski> oh just pub fn format
protty has joined #zig
stratact has joined #zig
reductum has quit [Quit: WeeChat 2.6]
<adamkowalski> Am I crazy or should I be able to use a Xoroshiro128 where a Random is expected?
muffindrake has quit [Ping timeout: 276 seconds]
<adamkowalski> I'm building out a simple normal distribution like so
protty has quit [Remote host closed the connection]
muffindrake has joined #zig
<adamkowalski> That test passes, but it feels like a hack
<daurnimator> adamkowalski: `const actual = normal.sample(&r.random);` is the correct way
<daurnimator> adamkowalski: if we swapped Random to a mixin you wouldn't need to do that
<adamkowalski> right, that would match the allocator style
<adamkowalski> is there a reason thats prefered to passing by var? then just checking the interface of the type at compile time
<adamkowalski> you get a virtual call then right
Ichorio_ has joined #zig
<adamkowalski> Or I guess it's just passing by pointer since it's mutable, not necessarily to signify dynamic dispatch
Ichorio has quit [Ping timeout: 245 seconds]
ForLoveOfCats has quit [Quit: Konversation terminated!]
<adamkowalski> How do you run all tests in my project? In source and all it's subdirectories
<adamkowalski> I tried zig test src/**/*.zig
chemist69 has quit [Ping timeout: 250 seconds]
chemist69 has joined #zig
<adamkowalski> I did this for now haha find src -name '*.zig' -exec zig test '{}' \;
<daurnimator> adamkowalski: you pass one zig file, and it recursively tests @import in the current package
urluck has quit [Ping timeout: 252 seconds]
urluck has joined #zig
stratact has quit [Quit: Konversation terminated!]
<adamkowalski> So you have to enumerate all the files you wish to test in that file? You can't just say grab all zig files and test them?
<adamkowalski> It seems like you could get in a situation where that gets out of sync
ur5us has quit [Ping timeout: 250 seconds]
<daurnimator> adamkowalski: but you would be using the code surely
<daurnimator> otherwise you're essentially asking "how do I test dead code"?
mikdusan has quit [Ping timeout: 265 seconds]
<adamkowalski> i'm asking how to test all the files in the project. I think a lot of people don't like that in CMake you have to list all your source files but they don't use the glob because it has issues
<adamkowalski> Most other languages provide a way to just say test this project. Is there something wrong with that? I'm open to learning something new
<adamkowalski> Or it should at least be possible to say zig test src/main.zig
<adamkowalski> Then even if main doesn't have tests itself, it should be the root and thus transitively include everything so that should kick off all tests right?
<adamkowalski> And about your dead code theory, some other languages have conventions that you seperate source and test files. So you have a test file which is not dead code but nobody includes it. It is purely there to hold tests
mikdusan has joined #zig
<adamkowalski> Interesting. So would have have a root source file and a root test file? And the root test file imports all other tests?
<adamkowalski> I feel like it would be awesome to have some of the core zig users write blog posts or document all these idioms somewhere. It's hard to know what is the common way to approach for dealing with these types of issues as somebody coming from the outsider
<adamkowalski> The documentation of the core language, the streams, and the road to 1.0 talk are all great, but it seems like there is a wealth of knowledge that you all have, which is undocumented, or at least I haven't been able to find it
ky0ko has quit [Remote host closed the connection]
traviss has joined #zig
adamkowalski has quit [Quit: Lost terminal]
<mq32> mikdusan: i've seen you closed 2938, now i'm interested in your new proposal :D
adamkowalski has joined #zig
LargeEpsilon has joined #zig
forgot-password has joined #zig
adamkowalski has quit [Quit: Lost terminal]
<forgot-password> The Ziguana earned a place on my Snowboard yesterday... Thanks for the sticker btw, mq32 :D
<mq32> nice!
<mq32> good morning forgot-password!
<mq32> i'm porting over C++ code to zig and it's quite interesting to see how some patters stay exactly the same
<mq32> and some other patterns don't work well at all
<forgot-password> morning
kapil_ has joined #zig
ur5us has joined #zig
Ichorio_ has quit [Ping timeout: 245 seconds]
Ichorio has joined #zig
<mq32> comptime is great to enforce contracts on code
<mq32> i have two structs: Properties and Bindings
<mq32> both structs must contain fields with exactly the same name
<mq32> also all fields in Bindings must have the type ?ID
<mq32> => write a comptime block that asserts all this and makes beautiful error messages
forgot-password has quit [Ping timeout: 250 seconds]
return0e has joined #zig
<daurnimator> I'm waiting for someone to write a protobuf thing
<bgiannan> Ži might, because right now i'm writing serialize/deserialize functions for all my types and its getting tiresome
<mq32> daurnimator: actual protobuf implementation or "zig general purpose serializer"?
<daurnimator> mq32: actual protobuf
<daurnimator> mq32: general purpose zig serialisers are pretty easy. did you see https://github.com/ziglang/zig/pull/3155 ?
<mq32> nah, but i can imagine that it's easy. just comptime all the code! :D
<bgiannan> the edge case i have is that with my inheritance implementation, nothing is ever holding pointers to the actual root struct of an "object"
<bgiannan> so at serialization i have to figure out the actual struct of the instance and write that
emekankurumeh[m] has quit [Remote host closed the connection]
mattmurr has quit [Remote host closed the connection]
fengb has quit [Read error: Connection reset by peer]
Snektron has quit [Remote host closed the connection]
Demos[m] has quit [Read error: Connection reset by peer]
D3zmodos has quit [Remote host closed the connection]
chr[m] has quit [Remote host closed the connection]
BitPuffin has quit [Read error: Connection reset by peer]
<mq32> btw, i started porting my UI system i talked about some time ago to zig :)
<mq32> i wonder how elegant my "property binding" system will be at the end
<mq32> `widget.get("left")` would be the zig code whereas the c++ version looks like `widget.left.get(&widget)`
<daurnimator> mq32: not `widget.get(.Left)`?
<mq32> could be an idea, i already require an enum with all possible properties anyways
<mq32> i think i'll gonna do that
<mq32> btw, what is the "right" standard for zig enums? .Caps or .small?
Demos[m] has joined #zig
<bgiannan> .Caps
<daurnimator> mq32: though.... what does .get do?
<daurnimator> and why is it not just widget.left
bjorob has joined #zig
BitPuffin has joined #zig
dtz has joined #zig
fengb has joined #zig
Snektron has joined #zig
D3zmodos has joined #zig
bjorob has quit [Ping timeout: 246 seconds]
ur5us has quit [Ping timeout: 240 seconds]
soulofdeveloper has joined #zig
kapil_ has quit [Quit: Connection closed for inactivity]
LargeEpsilon has quit [Ping timeout: 265 seconds]
soulofdeveloper has quit [Quit: Leaving]
Ichorio has quit [Ping timeout: 245 seconds]
LargeEpsilon has joined #zig
<bgiannan> should https://rr-project.org/ work with zig?
<mq32> daurnimator: because i have properties that are bindable
<mq32> which means i change the source of their value
<daurnimator> bgiannan: I don't know any reasons it wouldn't.... but I don't know
<daurnimator> mq32: ah k. I'd be curious to see the code when you're done
<mq32> yeah, me too :D
<mq32> zig allows a lot of nice stuff with comptime reflection for this use case
<mq32> translate enumeration value to string, compare string with field name, then check if field is currently bound, if not, return field value :D
<daurnimator> mq32: I thought you'd keep a struct of pointers to fields and just always follow the pointers (whether to local object or something else).
<mq32> no, i have two structs
<mq32> one containing the actual value
<mq32> and the other one containing a ?i32
<mq32> if the optional is set, a more or less complex lookup is done
vexu has joined #zig
<fengb> daurnimator: I started protobuf. I wanted to wait to see if we get struct tags
<fengb> Inventing my own hacky comptime dsl made me sad
<daurnimator> fengb: why can't you invent your own struct tags?
<daurnimator> e.g. if there is a field `foo` look for a const field `.tags.foo`
redj has quit [Quit: http://quassel-irc.org - Chat comfortably. Anywhere.]
redj has joined #zig
tav_ has joined #zig
tav_ is now known as tav
waleee-cl has joined #zig
<mq32> daurnimator: but if everything works out as i plan, we may have a small (and quite special) UI framework for zig
return0e_ has quit [Ping timeout: 268 seconds]
return0e_ has joined #zig
adamkowalski has joined #zig
<adamkowalski> Can anyone help me craft a regex for finding test cases? I'm trying to implement test nearest for vim-test. I've already got test file working, but I still need test nearest and test suite
<adamkowalski> Heres an example with how things work for haskell 'test': ['\v\s*describe\s"([^"]*)"', '\v^\s*it\s"([^"]*)".*$']
<tav> mq32: could you elaborate on "we may have a small (and quite special) UI framework for zig"? I'm looking for one, so be interested to hear more
<mq32> heh
<mq32> i've implemented a PoC in C++ some time ago, but i'm not happy with the implementation of that
<mq32> this version requires a separate executable and networking to work
<mq32> and i want to remove that restriction to make the API have the same commands, but in a "embedded" environment, so you can just start the UI system from your own thread/process
<adamkowalski> tav: Do you have any particular targets in mind? If you can compile to webassembly you can just leverage the dom?
<frmdstryr> Can I use @hasDecl on a module level?
<mq32> frmdstryr: "modules" are just structs
<mq32> so: yes
<frmdstryr> So how do i reference the current struct?
<mq32> @This()
<frmdstryr> Oh, thanks
<tav> mq32: neat! be great to see something like that in zig
<mq32> tav: it's built on a layouting engine with minimal styling (so it looks crap for the moment) and has a MMVMish approach
<mq32> so it's quite unusual for a UI system, but also cool to work with
<tav> adamkowalski: desktop + mobile + (ideally, also, but not requisite) web
* daurnimator has been hoping letoram will make something UI-wise for zig
<tav> mq32: being able to bind interpolated strings + basic expressions, in addition to variables would go a long way in making that more ergonomic, but besides that, nice ideas!
<fengb> daurnimator: parallel data structures lead to spaghettification. I know this is supposed to be generated code but I had hoped to keep it legible
<daurnimator> fengb: I read an article like 2 days ago that said how bad struct tags have been for the go ecosystem
<daurnimator> fengb: it was a comment somewhere in reply to https://www.arp242.net/go-last-resort.html#struct-tags
<companion_cube> becuase it's not namespaced?
<fengb> I feel like Java did a decent job with annotations
<fengb> It back references the source and injects pretty simple metadata
<companion_cube> I think rust's annotations are decent, iirc I got failures when typing them wrong
nairou has joined #zig
<nairou> The syntax Zig uses, in places like the for and while loops, where you have the condition in parentheses and then the actual value in vertical bars... Where does that syntax come from? I'd never seen it before Zig, and it isn't explained in the documentation, so I'm guessing it's familiar to the devs from somewhere.
<companion_cube> it's a mix of C and ruby/rust I'd say
<nairou> Rust had been my guess, only because it's mentioned frequently and I'm not familiar with it. I know C doesn't provide individual values for loops.
<nairou> The Zig documentation doesn't describe that part of the syntax (the part in vertical bars), so I had a hard time figuring out what was going on at first.
<companion_cube> it's typically to bind a variable
<companion_cube> (like, the variable to the pointer's content in a null check)
<nairou> Right
<daurnimator> Yeah the manual doesn't explain it as a concept; it's one of the things that I got confused about when I found zig
<nairou> Took a while, and looking at usage examples, for me to understand what it was
wilsonk has quit [Ping timeout: 268 seconds]
wilsonk has joined #zig
wilsonk has quit [Ping timeout: 268 seconds]
wilsonk has joined #zig
vexu has quit [Quit: WeeChat 2.6]
LargeEpsilon has quit [Ping timeout: 268 seconds]
<mq32> @andrewrk andrewrk added accepted and removed accepted labels on 1 May
<mq32> lol :D
<andrewrk> even my ambivalence is open source :)
<mq32> ^^
<mq32> i'm using camelCase for both enum members and struct fields
LargeEpsilon has joined #zig
LargeEpsilon has quit [Ping timeout: 276 seconds]
adamkowalski has quit [Quit: Lost terminal]
reductum has joined #zig
Akuli has joined #zig
return0e has quit []
wootehfoot has joined #zig
<andrewrk> fengb, can you elaborate on https://github.com/ziglang/zig/issues/3789#issuecomment-559198843? are you referring to how to figure out how many pages to free?
lunamn has joined #zig
vexu has joined #zig
<mq32> i am surprised that AutoHashMap actually just uses an .eql function for equality checking :D
<mq32> ah, no
<mq32> it uses meta.eql
<fengb> andrewrk: yeah, when doing a shrink(large, 1) followed by free(large), we lose track of its original size. Actually now that I'm typing it out, we can just free the excess on shrink
<fengb> This type of metadata is much easier to work with 👍
<andrewrk> fengb, zig allocators give the length on free
<andrewrk> or rather clients of zig allocators are required to give the length
<andrewrk> "safe" allocators should probably redundantly store this information to catch mistakes, but WasmPageAllocator is pretty low-level - probably GeneralPurposeDebugAllocator would use it as a backing allocator, and that's where the safety would be provided
<andrewrk> oh I think I see what you were saying
<fengb> Yes I meant that my old shrink() function just threw away the excess memory and never tracked it. But we can have a less bad shrink that actually returns the excess pages
<fengb> Sorry, have some implementation baggage because I stored the metadata differently :P
<andrewrk> btw I think it should be a goal of zig that the allocator interface provides a comptime alignment parameter to allocator implementations
qbradley has joined #zig
mahmudov has joined #zig
yorodm has joined #zig
yorodm has quit [Remote host closed the connection]
return0e_ has quit [Remote host closed the connection]
return0e has joined #zig
vvanholl_ has joined #zig
vvanholl_ has quit [Quit: Leaving]
mforney has joined #zig
nairou has quit [Remote host closed the connection]
Ichorio has joined #zig
ur5us has joined #zig
FireFox317 has joined #zig
LargeEpsilon has joined #zig
LargeEpsilon has quit [Ping timeout: 265 seconds]
ltriant has joined #zig
ur5us_ has joined #zig
ur5us has quit [Ping timeout: 245 seconds]
Akuli has quit [Quit: Leaving]
wootehfoot has quit [Quit: Leaving]
wootehfoot has joined #zig
<jonathon> Using https://godbolt.org/z/3ve3Vw for string concatentation, it looks like when used in a loop the allocator will continue to allocate and slowly grow memory use. Is there a good way to approach this, e.g. rather than using std.heap.direct_allocation? (I have tried an ArenaAllocator from https://ziglang.org/documentation/master/#Memory but while the concat'd string works within the Zig code it does something odd when I try to pass the resulting
<jonathon> string pointer to a C function.)
vexu has quit [Quit: WeeChat 2.6]
<andrewrk> jonathon, in general, when you concatenate strings, you have to think about where the memory will go
<andrewrk> you might look into using std.Buffer
FireFox317 has quit [Ping timeout: 276 seconds]
<jonathon> (reading)
<companion_cube> what we need here now is an irc bot 🙃
<mq32> companion_cube: !answer string_concatenation
<mq32> *laughing in bot*
<companion_cube> I was thinking of !stdlib std.Buffer, but well :p
<andrewrk> IRC bots are allowed in the channel under the condition that they are writtin in 100% zig, no libc
<andrewrk> :)
<mq32> andrewrk, can you explain this error?
<mq32> error: runtime cast to union 'Value' which has non-void fields
<companion_cube> andrewrk: heh, sounds like a challenge :D
<companion_cube> (although it's very hard nowadays, you typically want SSL)
<frmdstryr> Can I make a struct that can only be created using a specific function?
<jonathon> andrewrk: thanks for your continued patience. I've learned so much over the last few days, it's great. :D
<frmdstryr> Eg to make sure a calendar date cannot be created with invalid values
<andrewrk> mq32, you're trying to make a union value out of its tag value. but the tag value is runtime-known, so it might be one of the union fields that has data attached to it. But what would the data be, undefined? that would be an unsafe cast, so it's not allowed with coercion
<mq32> hm
<mq32> value is runtime known, but tag is comptime
<andrewrk> mq32, "runtime cast" in the compile error means zig thinks the tag is runtime known
<andrewrk> maybe try @compileLog(tag_value) and see what it says?
<andrewrk> frmdstryr, actually you can, I think. I wonder if that is possible by adding a dummy field with a default initialization value of @compileError("..."), and then in your init function you set the field to a void value
<andrewrk> mq32, hmm, can you reproduce this with a small test case?
<mq32> i can try
<mq32> i'm doing a lot of hick-hackery
<mq32> wildly converting from and to a tagged union
<mq32> yeah i had to enforce a lot of manual comptimes there
<andrewrk> if it's happening when the tag value is comptime known that seems like a bug to me
<andrewrk> jonathon, no problem. I want to point out - it seems tedious to have to care about such things as where memory of string concatenation will go. And indeed it is. It would be nice if the world had unlimited resources. But it doesn't
<andrewrk> other languages will let you solve a problem 95% very quickly, but then you hit a brick wall. zig is is the tortoise in the race; you move slower, but you can close that last 5% gap once you get there
<frmdstryr> andrewrk: That worked, thanks!
<mikdusan> on CI/windows `test/standalone/shared_library` passes. On my windows VM, it fails for me, not finding "mathtest.dll" and I'm at a loss to see how the test.exe would ever find it because it's in a sep zig-cache folder. any hints?
<jonathon> andrewrk: It's all needs a "paradigm shift" in my thinking. I have to consider that I actually need to specify what "thing" to store a "thing" in, rather than just have the programming language hide that and pass the values around (which it can happily do if it's GC-based). I've learned more about low-level programming over the last few days than I'd care to admit!
<jonathon> I'm finding Zig _way_ more accessible than plain C in this respect
<mikdusan> here is gist of output for windows shared_library failure: https://gist.github.com/mikdusan/4d90fde35d9f577b8d5f049bdf61382b
<andrewrk> mikdusan, I suspect something to do with the PATH environment varibale, and capitalization of it
<andrewrk> this code looks sketchy (I wrote it)
<andrewrk> happy to hear that jonathon. the good news is that these concepts are relevant beyond just the zig language, so you're investing in your own skillset
<mikdusan> andrewrk: thanks. a quick test hardcoding to my "PATH" worked around it
<mq32> andrewrk, you're on a merging spree right now? :D
<andrewrk> mq32, yes although I'm also trying to finish #3787, a bug fix branch that got bigger than expected
<mq32> "fix result location bugs" is the
<mq32> while(it) |item| {} thingy?
<andrewrk> can you link to a specific bug report? I'll try it in the branch
<mq32> err, hm
<mq32> good question, it was something about linked lists
<andrewrk> I'm hoping that in the self-hosted compiler, I can think about this from the ground up with a fresh start, and not have these bugs to begin with. Then once the self-hosted compiler is done, backport the way it works back to stage1
<andrewrk> if it's even comparable. idk. we'll see
<frmdstryr> Can zig test show code coverage?
<frmdstryr> Nice, thanks
<mq32> daurnimator: i can now show you usage of the binding system
<mq32> implementation will follow as soon as i'm confident that it doesn't suck :D
doublex_ has joined #zig
wootehfoot has quit [Quit: Leaving]
Ichorio has quit [Ping timeout: 245 seconds]
<mq32> andrewrk: does the zig-cache directory have a size limit?
<andrewrk> the cache system does no garbage collection yet
<mq32> okay
<andrewrk> it is safe to delete the directory to reclaim space
<mq32> i just wondered as my project cache is 0.5 GB right now
frmdstryr has quit [Remote host closed the connection]
ur5us_ has quit [Ping timeout: 240 seconds]
ur5us_ has joined #zig
mahmudov has quit [Remote host closed the connection]
<pixelherodev> Anything major happen over the last few days? Been a tad... preoccupied