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/
mikdusan has quit [Quit: WeeChat 2.6]
zags has quit [Quit: leaving]
mikdusan has joined #zig
gazler__ has joined #zig
xyproto has quit [Ping timeout: 258 seconds]
gazler_ has quit [Ping timeout: 264 seconds]
ur5us has quit [Ping timeout: 264 seconds]
nycex has quit [*.net *.split]
v0idify has quit [*.net *.split]
xyproto has joined #zig
ur5us has joined #zig
nycex has joined #zig
v0idify has joined #zig
nycex has quit [Remote host closed the connection]
nycex has joined #zig
nycex has quit [Remote host closed the connection]
nycex has joined #zig
gazler has joined #zig
gazler__ has quit [Read error: Connection reset by peer]
nycex has quit [Remote host closed the connection]
nycex has joined #zig
nycex has quit [Remote host closed the connection]
nycex has joined #zig
sebonirc has quit [Quit: sebonirc]
nycex has quit [Remote host closed the connection]
nycex has joined #zig
nycex has quit [Remote host closed the connection]
nycex has joined #zig
xackus_ has joined #zig
xackus has quit [Ping timeout: 256 seconds]
slact has quit [Ping timeout: 265 seconds]
nycex has quit [Remote host closed the connection]
nycex has joined #zig
jukan has quit [Ping timeout: 265 seconds]
jukan has joined #zig
jukan has quit [Ping timeout: 240 seconds]
jukan has joined #zig
nycex has quit [Remote host closed the connection]
nycex has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
midgard has quit [Read error: Connection reset by peer]
midgard has joined #zig
nycex has quit [Remote host closed the connection]
nycex has joined #zig
nycex has quit [Remote host closed the connection]
nycex has joined #zig
jukan_ has joined #zig
ur5us has joined #zig
jukan has quit [Ping timeout: 240 seconds]
nycex has quit [Quit: Quit]
nycex has joined #zig
nycex has quit [Remote host closed the connection]
nycex- has joined #zig
rtpg has joined #zig
nycex- has quit [Remote host closed the connection]
nycex has joined #zig
ur5us has quit [Ping timeout: 264 seconds]
cole-h has quit [Ping timeout: 265 seconds]
lucid_0x80 has joined #zig
sord937 has joined #zig
waleee-cl has quit [Quit: Connection closed for inactivity]
decentpenguin has quit [Read error: Connection reset by peer]
decentpenguin has joined #zig
jukan has joined #zig
nycex has quit [Remote host closed the connection]
nycex has joined #zig
jukan_ has quit [Ping timeout: 246 seconds]
allan0 has joined #zig
tnorth has joined #zig
drawkula has joined #zig
yeti has quit [Ping timeout: 256 seconds]
drawkula is now known as yeti
kbd has quit [Quit: My Mac Mini has gone to sleep. ZZZzzz…]
slact has joined #zig
Nypsie[m] has quit [*.net *.split]
ifreund_ has quit [*.net *.split]
jaens[m] has quit [*.net *.split]
bgiannan has quit [*.net *.split]
oats has quit [*.net *.split]
ovf has quit [*.net *.split]
eddyb[legacy] has quit [*.net *.split]
drvirgilio has quit [*.net *.split]
ifreund_ has joined #zig
ovf has joined #zig
jaens[m] has joined #zig
Nypsie[m] has joined #zig
eddyb[legacy] has joined #zig
oats has joined #zig
drvirgilio has joined #zig
bgiannan has joined #zig
halbeno has quit [Remote host closed the connection]
kameliya[m] has quit [Ping timeout: 240 seconds]
Nypsie[m] has quit [Ping timeout: 242 seconds]
ifreund_ has quit [Ping timeout: 242 seconds]
vpzom has quit [Ping timeout: 240 seconds]
pafmaf[m] has quit [Ping timeout: 240 seconds]
jaens[m] has quit [Ping timeout: 258 seconds]
halbeno has joined #zig
Miaourt has quit [Quit: Bye!]
ziguana[m] has quit [Ping timeout: 246 seconds]
Snektron has quit [Ping timeout: 244 seconds]
BitPuffin has quit [Ping timeout: 244 seconds]
mtiljeset[m] has quit [Ping timeout: 240 seconds]
protheory8-new-m has quit [Ping timeout: 240 seconds]
ugla has quit [Ping timeout: 240 seconds]
fengb has quit [Ping timeout: 240 seconds]
siraben has quit [Ping timeout: 240 seconds]
BaroqueLarouche has quit [Ping timeout: 260 seconds]
dtz has quit [Ping timeout: 268 seconds]
Miaourt has joined #zig
jukan has quit [Ping timeout: 260 seconds]
hnOsmium0001 has quit [Quit: Connection closed for inactivity]
jukan has joined #zig
fengb has joined #zig
jukan has quit [Ping timeout: 240 seconds]
BitPuffin has joined #zig
ugla has joined #zig
ifreund_ has joined #zig
jaens[m] has joined #zig
siraben has joined #zig
dtz has joined #zig
Snektron has joined #zig
ziguana[m] has joined #zig
protheory8-new-m has joined #zig
Nypsie[m] has joined #zig
jzck has joined #zig
mtiljeset[m] has joined #zig
kameliya[m] has joined #zig
BaroqueLarouche has joined #zig
D3zmodos has joined #zig
pafmaf[m] has joined #zig
Demos[m] has joined #zig
vpzom has joined #zig
rinfo has quit [Ping timeout: 246 seconds]
rinfo has joined #zig
jukan has joined #zig
tnorth has quit [Quit: Konversation terminated!]
jukan has quit [Ping timeout: 258 seconds]
xackus_ has quit [Ping timeout: 264 seconds]
xackus_ has joined #zig
vcarvalho has joined #zig
bfredl has joined #zig
haliucinas has quit [Remote host closed the connection]
haliucinas has joined #zig
ifreund has quit [Quit: WeeChat 3.0]
ifreund has joined #zig
GrooveStomp has quit [Remote host closed the connection]
jukan has joined #zig
jukan has quit [Ping timeout: 256 seconds]
vcarvalho has quit [Quit: WeeChat 2.9]
vcarvalho has joined #zig
Akuli has joined #zig
hch has quit [Ping timeout: 256 seconds]
hch has joined #zig
TheLemonMan has joined #zig
v0idify has quit [Remote host closed the connection]
v0idify has joined #zig
xackus_ has quit [Ping timeout: 240 seconds]
jukan has joined #zig
jukan has quit [Ping timeout: 260 seconds]
waleee-cl has joined #zig
donniewest has joined #zig
bsrd has quit [Quit: WeeChat 3.0]
bsrd has joined #zig
jzck has quit [Quit: Idle for 30+ days]
D3zmodos has quit [Quit: Idle for 30+ days]
Demos[m] has quit [Quit: Idle for 30+ days]
jukan has joined #zig
hnOsmium0001 has joined #zig
nvmd has joined #zig
kbd has joined #zig
jukan_ has joined #zig
jukan has quit [Ping timeout: 265 seconds]
GrooveStomp has joined #zig
vcarvalho has quit [Quit: WeeChat 2.9]
GrooveStomp has quit [Client Quit]
GrooveStomp has joined #zig
vcarvalho has joined #zig
midgard has quit [Ping timeout: 265 seconds]
cole-h has joined #zig
dumenci has joined #zig
lucid_0x80 has quit [Ping timeout: 265 seconds]
LanceThePants has quit [Read error: Connection reset by peer]
LanceThePants has joined #zig
midgard has joined #zig
a_chou has joined #zig
<justin_smith> in the docs, it says "A for expression can be used to iterate over the elements of a slice, array, or tuple" - I assume in this case "tuple" (not mentioned elsewhere in the docs) refers to an anonymous struct, which is indexed by number but type-heterogenous?
<g-w1> a tuple is something like this: .{ "thing", .diff_type }
<g-w1> you use it in std.debug.print as the second arg
wootehfoot has joined #zig
<justin_smith> g-w1: OK - right - the docs call those anonymous structs, and tuples are only meantioned in that one place
<Gliptic> anonymous structs are a bit more general as the fields can have names (don't think for works on those?)
<justin_smith> Gliptic: oh, yeah that would make sense
<justin_smith> Gliptic: oh right, what for is mentioning isn't "anonymous struct literal", it's "anonymous list literal", I misidentified that
<justin_smith> (I've used all of these in my code, just wasn't super clear on the terminology)
jjido has joined #zig
<ifreund> I think the terminology could probably use work
dumenci has quit [Ping timeout: 256 seconds]
<justin_smith> suddenly I'm curious if I could use type inferred list literals instead of real types for the weird helper types I sometimes need to glue together different parts of my code...
v0idify has quit [Remote host closed the connection]
v0idify has joined #zig
evbo has joined #zig
frett27_ has joined #zig
leon-p has quit [Quit: leaving]
cole-h has quit [Ping timeout: 246 seconds]
ur5us has joined #zig
marijnfs has joined #zig
<marijnfs> I'm trying to deserialize into a tagged union
<marijnfs> @TagType gives me the enum type right?
<marijnfs> how do I get a specific union type
<g-w1> wdym? @TypeOf?
<marijnfs> it i have t: T = union(enum), does @TagType(T) give me the enum?
<g-w1> yes
<g-w1> For a union, returns the enum type that is used to store the tag value.
jukan_ has quit [Ping timeout: 264 seconds]
<marijnfs> and how do i create the appropriate enum type itself?
<marijnfs> say I have the enum only
<ifreund> @TagType(T) is the enum type
<marijnfs> and how do I 'fill in' the union type?
jukan has joined #zig
<ifreund> marijnfs: you're probably looking for @unionInit()
<marijnfs> I want to initialize it undefined, and then fill it in given deserialization
<marijnfs> hmm
<g-w1> maybe it would be easier to just do enum(MyUnion)?
<g-w1> *union(MyEnum)
<marijnfs> ifreund: but thats with comptime enum
<ifreund> I have an example deserializing a tagged union here: https://github.com/ifreund/zig-wayland/blob/master/src/common_core.zig#L103
<g-w1> you cant do it an runtime, types are a comptime only idea
<ifreund> beware: theres a lot of meta programming though, this function is the backbone of my wayland scanner
<marijnfs> ok inline for over Union fields?
<marijnfs> yeah that would create runtime code indeed
<ifreund> yup
<marijnfs> how do i distinquish between C and zig union?
<marijnfs> I happen to have a c-union, and it trigger the .Union case
<ifreund> marijnfs: the TypeInfo.Union.container_layout
<ifreund> er just layout I think
<ifreund> if you have an extern union you may be able to get away without the inline for as they have a well-defined memory layout
<marijnfs> thanks, i'll have a look
<marijnfs> ' runtime cast to union 'Request' which has non-void fields'
<marijnfs> what does that mean
<ifreund> not sure tbh, do you have the code somewhere?
<marijnfs> ifreund: indeed, an extern 'c' union is easier, it's just some memory I copy with length @SizeOf right?
<ifreund> extern unions cant be tagged though :/
<marijnfs> in src/node.zig is my code basically, under deserialize_msg
<marijnfs> ifreund: then I guess thats not what i have
<ifreund> marijnfs: this is where you need to be using @unionInit() https://github.com/marijnfs/zig-nng/blob/4cc6b8af0799d951539ced37536dc6ba3bd4133e/src/node.zig#L347
<marijnfs> oww
<marijnfs> yeah nice spotting
<ifreund> this is foo.bar = 4; instead of foo = .{ .bar = 5 }
<ifreund> (the second is what @unionInit() does)
<marijnfs> ah thats a nice explanation
<marijnfs> i'm getting the hang of this language:P
<ifreund> :)
<marijnfs> yuup works:)
<marijnfs> t = @unionInit(T, name, try deserialise_msg(FieldType, msg));
<marijnfs> it's still remarkable it compiles
<ifreund> comptime does feel like magic some times
<andrewrk> don't worry the magic feeling will go away when the bugs are fixed :)
<marijnfs> i'm sure there aren't any:P
<TheLemonMan> you're not looking hard enough :^)
<andrewrk> howdy TheLemonMan
<ifreund> take for example that dispatcher function for my wayland scanner, the equivalent C code in libwayland is something like twice as long and the equivalent rust is even longer
sord937 has quit [Quit: sord937]
<andrewrk> you might be interested to know I'm working on the parts of self-hosted right now that are the impossible-to-maintain parts of stage1 and I think it's going well! would value your opinion though if you wanted to have a look
<ifreund> also the C one is at least has separate implementations for the client and server side, so make that 4 times as long. Not sure about the rust one
<TheLemonMan> yo andrewrk, what's cooking in zig land?
<TheLemonMan> I'm quite busy these days :\ I wish I had enough time for some serious work
<andrewrk> ifreund, you might be interested in this related accepted proposal: https://github.com/ziglang/zig/issues/7224
<andrewrk> summary: switch (my_tagged_union) { inline else => |comptime_known_payload| { ... } }
<ifreund> andrewrk: yeah I saw that one and it looks quite handy, would replace the inline for/if (field_type == runtime_value) pattern I guess
<ifreund> I wonder if the generated code would be better or not
<andrewrk> it certainly would in unoptimized builds
<andrewrk> because it would generate a switch instead of a for loop
<andrewrk> in a way, this is our alternative to OOP features in the language
<ifreund> well the inline for/if pattern gets unrolled to a series of ifs not?
<andrewrk> yes inline for will unroll into a series of if; switch with inlined cases turns into (probably) a jump table
<TheLemonMan> andrewrk, wrt #7847 what's the generated ZIR w/o that patch applied?
<ifreund> yeah I really like how that will clean up those maunal dispatch switches in stage2 (and in river)
<ifreund> thinking of link.File in particular
<marijnfs> so with that you can just to inline case switches?
<ifreund> once #7224 is implemented yeah
<marijnfs> that would be nice
<ifreund> andrewrk: by the way, please don't forget about #131 when implementing globals in stage2 :)
<andrewrk> TheLemonMan, a compile error that says "TODO: implement this" but if you put a dummy instruction then it looks like this: https://clbin.com/xgXBP
<andrewrk> the store_to_block_ptr is a dummy there just to show you
<andrewrk> ifreund, thanks for the reminder, this is actually a great time to implement that in stage2
<marijnfs> how to I turn a var t: T to a []u8? The size should be known right?
<ifreund> marijnfs: mem.bytesAsSlice maybe? there's some function to do that
<andrewrk> TheLemonMan, the short summary is that astgen will now notice when expr() does not actually use a result location pointer, and fix up the zir to be value-based instead. thanks to the tree structure of the zir this ends up being clean and reasonably straightforward
<andrewrk> then the semantic analysis phase has a simplified job to do based on this zir that is either value based or pointer based but not both
<ifreund> andrewrk: yeah, I tried for a weekend to hack partial support for #131 into stage1 and failed pretty throughly. It's really something that is best designed for from the beginning
<ifreund> marijnfs: std.mem.toBytes
<ifreund> or mem.asBytes() depending on if you want a value or pointer
<ifreund> both just wrap a @ptrCast(), if you need to care about endianness you need a different function
sebonirc has joined #zig
<marijnfs> ah asBytes might be it
<andrewrk> I'm imagining a function StructOfArray `fn(T: type) type {}` that takes a struct and is essentially ArrayList where multiple fields share the same capacity
<andrewrk> so that each field of the struct gets its own array, but the length and capacity is shared
<andrewrk> you would use it if you ever had multiple fields of a struct be ArrayListUnmanaged where the intent was to share the same length and capacity
<justin_smith> ats2 uses an extended type system to detect resource leaks. similar to how the possibility of returning an error is a part of the type sig that gets transitively applied to callers, the fact that a resource is allocated becomes an annotation on the type, and it needs to be added to the caller's return type too, unless they dispose of the resource
<ifreund> hmm, you could make it use a single allocation too if you wanted
<justin_smith> I think that would be a cool feature, if we could make it mix elegantly with existing syntax
<andrewrk> ifreund, hmm do you think that would be valuable?
<ifreund> andrewrk: depends on the length of the arrays I think
<ifreund> like when they are small a single allocation would be better I imagine
<andrewrk> oh I see, yeah even if you wanted to leave room to grow for each array, you could still have it be 1 allocation
<ifreund> exactly
<andrewrk> well I have a Real Actual Use Case for this abstraction in stage2
SimonNa has quit [Ping timeout: 256 seconds]
SimonN has joined #zig
<ifreund> well I'm already procrastinating on so many things, maybe I'll write one real quick
<ifreund> good thing we have @Type() now to make this possible
<andrewrk> sweet
<ifreund> MultiArrayList?
<andrewrk> sounds good to me
<andrewrk> it wouldn't be purely for optimization too; it would make error handling & resource management easier since you wouldn't have to clean up when some fields succeeded the realloc but others didn't
<andrewrk> pretty easy to justify using this abstraction IMO
<ifreund> yeah I definitely see the use case
<ifreund> the other way to approach this is to have a single array of structs instead of parallel arrays
<andrewrk> yeah, but the use case I have right now is that later I want to pass a slice of only 1 of the field to something
<andrewrk> I need to pass a []*Inst to resolvePeerTypes
<ifreund> makes sense
<andrewrk> imagine implementing this abstraction in C lmaooo
<ifreund> oh hmm I'm not sure you can make this without #6709
<ifreund> at least not with the API I was imagining
<andrewrk> here's a hint: fn MultiArrayList(comptime S: type) type { return struct { untyped_data: align(@alignOf(S)) u8, len: usize, capacity: usize }; }
<ifreund> how does access look though? just by index?
wootehfoot has quit [Read error: Connection reset by peer]
<ifreund> I mean selecting which array to access
<andrewrk> fn items(self: *Self, comptime field: FieldEnum) []FieldType(field) {...}
<ifreund> Ok yeah that works
<andrewrk> IMO this is preferable to #6709 in terms of debugging and how the source location matches up with the actual source location
<andrewrk> you can still follow the control flow with simple function calls
<andrewrk> what API were you imagining tho?
<ifreund> I was initially thinking of something where the fields of the input struct were also fields of the output struct but slices of their former types
<ifreund> I don't think that's actually better though
<andrewrk> I think part of the idea here is to have the memory footprint of the struct be ideal
zags has joined #zig
<ifreund> yup, which that breaks
<ifreund> I'll make an unmanaged too then
<andrewrk> feel free to *only* make an unmanaged one if you want... I almost think the unmanaged variants of data structures have a nicer API
<andrewrk> static initialization for one
<ifreund> yeah I really like just being able to .{} init them
<zags> var x: [_]u8 = .{0x65, 0xbb, 0xcc}; was surprised that didn't work, shouldn't zig be able to infer size here? I'm porting a bunch of literals from c++ and would like to avoid setting size on everything.
<ifreund> been meaning to switch river over to them entirely but haven't found th time yet
<andrewrk> plus it encourages the ensureCapacity / appendAssumeCapacity pattern, which is nice
<ifreund> maybe we should consider changing the naming conventions such that we have ArrayList() and ArrayListManaged()
<ifreund> making "unmanaged" the default
<fengb> zags: [_]u8{0x65, 0xbb, 0xcc}
<andrewrk> zags, zig wants to know the type of x before it evaluates the initialization expression
<fengb> `var x = [_]u8{0x65, 0xbb, 0xcc};`
<andrewrk> (unless you use type inference)
<fengb> The infer expression only exists on a literal, you were putting it in a type declaration
<zags> ok, syntax still confuses an old c++ programmer :) Thanks, that worked
<ifreund> yay, we already have std.meta.FieldEnum :)
<andrewrk> thank daurnimator for that I believe
<zags> var x: [_]u8 = .{0x65, 0xbb, 0xcc};
<zags> still curious why zig doesn't know the type here
<zags> it's a grammar technical reason?
<g-w1> its a tuple of comptime int i think
<fengb> Zig doesn't have partial type inference. [_]u8 is not a valid type declaration
<ifreund> indeed, thanks daurnimator :)
<zags> the reason I'm confused fengb, is that var xy = [_:0]u8{0x65, 0xbb, 0xcc}; does work
<zags> so _:0 works, _ doesn't
<zags> that's a bit confusing
<fengb> `[_:0]u8{0x65, 0xbb, 0xcc}` this is a literal definition, not a type declaration
<fengb> Zig doesn't understand when you try using `[_]u8` as a type
<zags> var a = [_] u8{0x65, 0xbb, 0xcc};
<fengb> Because it doesn't exist in the grammar
<zags> var b = [_:0]u8{0x65, 0xbb, 0xcc};
<fengb> The full literal expression is `[_]T{ ... }`
<zags> so putting those two aside, it's surprising it doesn't work, that's all :D
<zags> I'll try to understand the difference, thanks
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
<zags> makes sense now, last question - does the std library have a portable dynamic library loading facility?
<zags> so I don't have to do platform specific dlopen/LoadLibrary and all that jazz, preferably pick correct extension and such
* zags discovers DynLib
Akuli has quit [Quit: Leaving]
vcarvalho has quit [Remote host closed the connection]
<zags> const lock_init = if (builtin.single_threaded) {} else false;
<zags> found that pattern in the std lib, seem like
<zags> const lock_init = if (!builtin.single_threaded) false;
<zags> would work as well
<ifreund> nope, {} is void
<zags> is there a reason for doing it the first way, beyond someone finding it more readable?
<zags> ifreund: i get void in the second case as well when I tried
<ifreund> oh interesting
<ifreund> I definitely find the first more readable
<zags> I see, that might be the reason then :)
<zags> hm, seen some userland ideas for closures, but how is deallocation going to work without gc/raii/etc ?
<zags> maybe a boehmgc allocator could be useful for those cases, unless there's a robust pattern I'm not seeing
frmdstryr has joined #zig
<ifreund> arenas can be useful for stuff where the lifetime management is too annoying
<ifreund> if you have bounds on the lifetime that is
<ifreund> kinda depends on your use-case for closures I think
<zags> yeah, not sure yet, buf async stuff in boost for instance, it would get hairy without smart pointers :D
<zags> haven't looked much at async networking in zig yet
<zags> (in terms of completion handlers, if there's anything like it)
donniewest has quit [Quit: WeeChat 3.0]
<fengb> You can probably make a ref-counted closure
<frmdstryr> How can I access type of a "Held" mutex now?
<zags> fengb: yeah. One more question, can page_allocator work with hugepages?
<zags> I know this can be a bit annoying to implement on windows, SeLockMemoryPrivilege etc
<zags> (reason this is done is to reduce tlb cache pressure)
<zags> Doesn't look like heap.zig utilize any MEM_LARGE_PAGES options
jukan_ has joined #zig
jukan has quit [Ping timeout: 260 seconds]
frmdstryr has left #zig ["Konversation terminated!"]
ur5us has quit [Quit: Leaving]
nvmd has quit [Ping timeout: 265 seconds]
nvmd has joined #zig
a_chou has quit [Ping timeout: 256 seconds]
<ifreund> looks like I may have caused zig to get packaged for CRUX :D https://0x0.st/-iFF.txt
nvmd has quit [Ping timeout: 265 seconds]
nvmd has joined #zig
frett27_ has quit [Ping timeout: 272 seconds]