ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
kristate has joined #zig
darithorn has quit [Remote host closed the connection]
MajorLag has quit [Ping timeout: 250 seconds]
companion_cube has quit [Ping timeout: 245 seconds]
MajorLag has joined #zig
MajorLag has quit [Ping timeout: 250 seconds]
MajorLag has joined #zig
<emekankurumeh[m]> andrewrk: is there a possible of large enough projects being "adopted" by the zig organization?
<andrewrk> emekankurumeh[m], explain?
<emekankurumeh[m]> the zig organization on github?
<andrewrk> I don't understand your question
<emekankurumeh[m]> by "adopted" i mean become official similar to how some python packages are adopted into the standard library.
<andrewrk> are you talking about the GitHub ziglang organization, or the Zig Standard Library?
<emekankurumeh[m]> well that was a bad question. i originally mean the the github organization.
kristate has quit [Remote host closed the connection]
darithorn has joined #zig
kristate has joined #zig
kristate has quit [Ping timeout: 259 seconds]
kristate has joined #zig
kristate has quit [Remote host closed the connection]
kristate has joined #zig
<andrewrk> emekankurumeh[m], the scope of the ziglang github organization - I don't really have a good answer to that question. right now I see it as "the reference zig implementation, specification, and tools (vim syntax, vscode syntax, etc) that zig team members are willing to maintain"
xtreak has joined #zig
MajorLag has quit [Ping timeout: 257 seconds]
<daurnimator> also should contain e.g. the zig homepage
MajorLag has joined #zig
very-mediocre has joined #zig
jevinskie has joined #zig
<suirad> i could have sworn std.debug.assertError was a thing. how do I assert an error is raised inside a test?
schme245 has joined #zig
<andrewrk> std.testing.expectError(expected_error, actual_value)
<suirad> andrewrk: ahh okay. i saw std.testing around but glossed over it assuming it was std.debug stuff
<andrewrk> assert() in normal code; std.testing in test code
schme245 has quit [Ping timeout: 246 seconds]
<suirad> im wrapping up an idea I had for ensuring returned pointers are not pointing to variables in the current frame
<andrewrk> sounds interesting
<suirad> alright its done. should work for any arch that has a downward growing stack. however determining what direction the stack grows and working for either would be trivial to add.
<andrewrk> neat!
<andrewrk> what about if it puts a pointer somewhere such as a global, or writes through a pointer parameter
<andrewrk> you need some kind of escape analysis
<daurnimator> andrewrk: there's no guarntee that you detect everything
<daurnimator> andrewrk: but you can avoid common/easy mistakes
<suirad> if you could potentially send a pointer to a global or anywhere inappropriate, the safe return would still detect it. it just checks if what was passed in is in the current stack frame, then returns it back to the caller or an error.
<suirad> so something like: global_var = stack_var; would change to: global_var = safeReturn(@typeOf(stack_var), stack_var); and it would detect it. but only for the frame its called in.
<suirad> another neat thing is that you can defer the safeReturn check. So if you initialize your return variable, you can immediately defer the safeReturn call and be sure your return value will always be checked.
xtreak has quit [Remote host closed the connection]
xtreak has joined #zig
schme245 has joined #zig
xtreak has quit [Remote host closed the connection]
xtreak has joined #zig
xtreak has quit []
darithorn has quit [Remote host closed the connection]
<andrewrk> suirad, isn't system programming fun? :)
<andrewrk> alright, got C pointers merged, and now I'm back on track with daily issue quotas
<andrewrk> knebulae, C pointers are merged into master. this was your biggest pain point I believe when trying to use @cImport. and it should be solved now
schme245 has quit [Ping timeout: 244 seconds]
tiehuis has joined #zig
<tiehuis> happy to see the c pointer change, will be very nice to not have to type ptrCast everywhere now
<tiehuis> also quick note but now we have a dedicated c pointer type i wonder if it'd be worthwhile allowing an implicit cast from zig arrays to c pointers
<tiehuis> a particular use case is in gmp, which typedefs an mpz_t as a 1 item array to avoid having to take the address everywhere
<tiehuis> not sure how widespread this technique is and how it would affect other places negatively so i'll sit on it for a bit and see
<tiehuis> doing `&a[0]` isn't a big deal anyway right now
tiehuis has quit [Client Quit]
very-mediocre has quit [Ping timeout: 256 seconds]
<knebulae> @andrewrk: You are a saint. I had the longest day, and I am about to have another. I will look at this later this afternoon / early evening.
Ichorio has joined #zig
forgot-password has joined #zig
very-mediocre has joined #zig
jethron has joined #zig
schme245 has joined #zig
schme245 has quit [Remote host closed the connection]
kristate has quit [Remote host closed the connection]
<knebulae> @euantor: nothing is sacred
jevinskie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
forgot-password has quit [Quit: leaving]
aiwakura has quit [Quit: The Lounge - https://thelounge.github.io]
forgot-password has joined #zig
<forgot-password> Is it possible to set the active tag of a union? Like this: https://pastebin.com/aMhmhBwh
<MajorLag> forgot-password: yes, but it is a hack. andrewrk says there's going to be a builtin function for it. Hold on, I'll dig up the code
<MajorLag> also, did you see my note yesterday about comptime struct fields?
<forgot-password> I'm not exactly sure, but I read a few answers to my question in the irc log
<MajorLag> I linked to some code I wrote a while back in a gist that did what I think you wanted, https://gist.github.com/tgschultz/e168cffd69003e4c788b6fd2ab1aea9e
<forgot-password> Oh I didn't see *that* message of yours, but I'll check it out now, thank you :)
<MajorLag> you have to work with it a bit differently than a normal struct, but it should compile to the same code.
<MajorLag> I would have added that to std.meta except that @unionInit is a better solution, whenever it gets added.
<forgot-password> It's basically a linked list of structs, right?
<forgot-password> I'm referring to the link from yesterday
<MajorLag> no, there's no linking, it's recursively embedding structs. In the end, it will have the same memory layout and access as a normal struct.
<MajorLag> not recursively, I guess. just a chain of embedded structs. It's early, haven't had my tea.
<MajorLag> each struct in the chain has one field that is the previous struct and one field that is the actual data.
<forgot-password> I am aware of that, I just phrased it badly
schme245 has joined #zig
<MajorLag> ok
<MajorLag> I think I dreamed it up as a solution to "given a json file, at comptime create a struct that matches".
<very-mediocre> MajorLag: that's an interesting approach. I tried something like that to emulate polymorphism, but ran into a dead end (can't remember what it was exactly).
<very-mediocre> wanted to specify the union type as the param in a function, but then you'd unbox it to get the specialized instance
<very-mediocre> zig has changed a lot since then and I've been away, I wonder if that would be feasible now. The gears in my head are spinning again. :]
<MajorLag> Sounds like there's some things Hejsil and I have added to std.meta that might come in handy, like retreiving the payload type of a union field from an enum, and various conveniences for type metadata.
<very-mediocre> Hm, I think the limitation was the inability to build the "base class" union throughout the codebase
<very-mediocre> as in, being able to define structs later and add them to the union
<very-mediocre> e.g. union called Shape, with 2 fields (`contents` and `next`) and later you might define, say, Circle and "append" that as the second field of Shape, and so on, recursively
<very-mediocre> This is all probably useless, but fun as I currently have no use case for zig (professionally I'm stuck with PHP and JS for now...)
<MajorLag> Yeah, the fundamental limitation would be that there's such thing as a global comptime var. If there were, you could theoretically keep mutating it similar to how the pseudo-struct works, replacing the type each time a new ShapeType is evaluated. The issue with implementing that would probably be that everything dependant on that global variable type has to be re-evaluated every time you change it for it to work li
<MajorLag> ike a better way to solve that.
<very-mediocre> I thought I was being clever, since unions are in a sense polymorphic and with comptime, you could add "interface" functionality upon boxing/unboxing, but yeah, immutability poses an insurmountable wall.
<very-mediocre> And you wouldn't need allocation since it's recursive. Alas.
jevinskie has joined #zig
MajorLag has quit [Ping timeout: 250 seconds]
MajorLag has joined #zig
gamester has joined #zig
<gamester> andrewrk: vulkan has plenty of functions that take a pointer + length where C pointers would be ideal. For example, you might need to call vkQueueSubmit. That takes 1 or more VkSubmitInfo and it's easier to just create 1 rather than an array of 1. However, it gets better. Inside the VkSubmitInfo struct you have .waitSemaphoreCount and .pWaitSemaphores and you'll want to write ".pWaitSemaphores = &self.image_available_semaphore" but in other cases
<gamester> you'll want want to pass an array. There's endless examples of this in Vulkan. But outside of vulkan maybe rare.
<gamester> vkWaitForFences(device, 1, &frame.fence)
forgot-password has quit [Quit: leaving]
<gamester> though I do agree with labeling c pointers as something not to be used
halosghost has joined #zig
gamester has quit [Quit: Konversation terminated!]
forgot-password has joined #zig
Ichorio_ has joined #zig
Ichorio has quit [Ping timeout: 268 seconds]
jevinskie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Ichorio_ has quit [Ping timeout: 250 seconds]
forgot-password has quit [Quit: leaving]
jethron has quit [Remote host closed the connection]
halosghost has quit [Read error: Connection reset by peer]
halosghost has joined #zig
schme245 has quit [Remote host closed the connection]
trohs has joined #zig
very-mediocre has quit [Ping timeout: 256 seconds]
jevinskie has joined #zig
schme245 has joined #zig
<andrewrk> alright let's get some of these pull requests merged
MajorLag has quit [Ping timeout: 250 seconds]
MajorLag has joined #zig
jevinskie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Zaab1t has joined #zig
<schme245> what is the in-memory representation of `?u32`? is there some way that I can investigate these things myself through Zig without reading the compiler code?
<andrewrk> schme245, there is no guarantee on the layout of optionals
<andrewrk> if you want to know out of curiosity, you can do something like this: https://gist.github.com/andrewrk/5684434a2a8d4cbb08bb0d855c4f2ada
<andrewrk> or actually we can even use godbolt for that now I think
<bwb_> wait. ya'll got godbold.org support
<bwb_> woah
<bwb_> ( andrewrk oh, hai, it bbrittain)
<andrewrk> hey :)
<schme245> huh, are there no unsigned ints in LLVM IR?
<andrewrk> schme245, correct - just signed/unsigned instructions
<schme245> interesting!
<schme245> so right now, `?u32` looks like a struct with a `i32` and an `i1` bitflag, correct?
<andrewrk> correct
<schme245> so here's what I'm curious about: what will the size of that struct be?
<schme245> cause there is no way the `i1` will actually take 1 bit, right?
<andrewrk> right. and the i32 needs to be aligned to 4 bytes (imagine if this struct were in an array)
<andrewrk> @sizeOf(i1) == 1. and then the struct gets 3 bytes of padding at the end, for a total of 8 bytes
<schme245> so there is a 2x overhead of using optionals for u32?
<andrewrk> yes
<andrewrk> note a few things though
<schme245> alright, that clears it up, thanks!
Akuli has joined #zig
<andrewrk> if you use that type in a function and turn on optimizations, llvm knows how to break apart the struct into its logical components and just do the most efficient thing
<andrewrk> if you use it as a return type, (once copy elision branch is done) the non-null bit goes into a separate channel
<andrewrk> so really where it matters is if you put it into an array, or if you put it into a struct and allocate a lot of them
<schme245> when you say "separate channel", is that a figure of speech or an actual LLVM/compiler thing?
<schme245> just trying to figure out what I can Google for :D
<andrewrk> figure of speech. I mean the return type would actually be i1 and the optional payload would be passed as a secret pointer parameter
<schme245> gotcha
<andrewrk> and if at the callsite used `orelse` for example, there was never really a ?u32 in memory; the i1 was used for the branch and the function wrote the result directly to the callsite's memory
<schme245> that's cool!
<andrewrk> which is important semantically, if you cansider that in ?T , T could be a struct, and you'd have the guarantee in the function implementation that you're directly instantiating the memory of the callsite, and you could even rely on having struct fields point to each other, etc
<andrewrk> (note we do not have this guarantee in status quo zig)
<schme245> on the same note: would a `const A = packed struct { a: u1, b: u1, c: u1, };` have a size of 3 bytes, due to alignment/padding etc? or will it be 1 byte?
<andrewrk> 1 byte
<schme245> oooh nice, so you can use a packed struct instead of a u8 for bitflags?
<andrewrk> correct
<schme245> awesome, thanks for taking the time to explain these things andrewrk, appreciate it
<andrewrk> no problem! I hope you will stick around and teach the next generation :)
Ichorio has joined #zig
Flaminator has quit [Disconnected by services]
a_chou has joined #zig
a_chou has quit [Client Quit]
a_chou has joined #zig
a_chou has quit [Client Quit]
a_chou has joined #zig
a_chou has quit [Client Quit]
a_chou has joined #zig
a_chou has quit [Client Quit]
a_chou has joined #zig
a_chou has quit [Client Quit]
a_chou has joined #zig
a_chou has quit [Client Quit]
darithorn has joined #zig
hio has joined #zig
darithorn has quit [Remote host closed the connection]
trohs has quit []
darithorn has joined #zig
Flaminator has joined #zig
schme245 has quit [Remote host closed the connection]
halosghost is now known as duckhunt
duckhunt is now known as hg
Akuli has quit [Quit: Leaving]
hg has quit [Quit: WeeChat 2.3]
Zaab1t has quit [Quit: bye bye friends]
schme245 has joined #zig
Zaab1t has joined #zig
knebulae has quit [Remote host closed the connection]
Ichorio has quit [Ping timeout: 245 seconds]
darithorn has quit [Remote host closed the connection]
Zaab1t has quit [Quit: bye bye friends]