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/
_whitelogger has joined #zig
Bekwnn has quit [Remote host closed the connection]
daex has quit [Ping timeout: 264 seconds]
daex has joined #zig
reductum has joined #zig
dingenskirchen has joined #zig
adamkowalski has joined #zig
<adamkowalski> do we have a trait or anything that will let me check if something is a float?
adamkowalski has quit [Quit: Lost terminal]
mokafolio has joined #zig
return0e has joined #zig
daex has quit [Ping timeout: 250 seconds]
return0e_ has quit [Ping timeout: 240 seconds]
daex has joined #zig
return0e_ has joined #zig
return0e has quit [Ping timeout: 250 seconds]
_whitelogger has joined #zig
_Vi has joined #zig
slowtyper has quit [Quit: WeeChat 2.7.1]
reductum has quit [Quit: WeeChat 2.7.1]
ur5us has joined #zig
_Vi has quit [Ping timeout: 246 seconds]
slowtyper has joined #zig
jjido has joined #zig
marijnfs has joined #zig
ur5us has quit [Ping timeout: 246 seconds]
mokafolio has quit [Ping timeout: 246 seconds]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
traviss has joined #zig
mokafolio has joined #zig
<traviss> you could do a switch on @typeInfo(@TypeOf(somevar)). for a float it will be: TypeInfo{ .Float = Float{ .bits = 32 } }
<marijnfs> I have a struct with function pointers that I set, how can I still use the syntactic sure where i can call the function like a method and the first 'self' argument is set?
<traviss> adamkowalski this works too: std.meta.trait.is(.Float)(@TypeOf(somevar))
TheLemonMan has joined #zig
dddddd has quit [Ping timeout: 250 seconds]
waleee-cl has joined #zig
jjido has joined #zig
tane has joined #zig
jjido has quit [Client Quit]
scientes has joined #zig
marijnfs_ has joined #zig
daex_ has joined #zig
daex has quit [Ping timeout: 240 seconds]
daex_ has quit [Ping timeout: 250 seconds]
marijnfs1 has joined #zig
marijnfs_ has quit [Ping timeout: 264 seconds]
daex has joined #zig
jjido has joined #zig
daex has quit [Ping timeout: 264 seconds]
jjido has quit [Client Quit]
daex has joined #zig
_Vi has joined #zig
zfoo has quit [Read error: Connection reset by peer]
mokafolio has quit [Quit: Bye Bye!]
mokafolio has joined #zig
marijnfs_ has joined #zig
marijnfs has quit [Ping timeout: 250 seconds]
ifreund has joined #zig
marijnfs1 has quit [Ping timeout: 256 seconds]
marijnfs has joined #zig
jjido has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
SyrupThinker has quit [Quit: Gateway shutdown]
dddddd has joined #zig
jjido has joined #zig
<marijnfs> hmm i'm trying to figure out a pattern
<marijnfs> I'm working on my event queue, and there is a base event type. Then there are specialized types that embed a base type and set appropriate function pointers (kinda like allocators).
<marijnfs> But I'm not sure how to manage the memory for those guys
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
slowtyper has quit [Quit: WeeChat 2.7.1]
FireFox317 has joined #zig
marijnfs1 has joined #zig
marijnfs has quit [Ping timeout: 264 seconds]
ugi has joined #zig
<ugi> hello everyone, i have a question about referencing the struct type idenfifier inside the same struct
<ugi> i need this to create a valid init method for the struct, but the struct is generic, so it can not be defined at top level
<ugi> is there a solution for this?
<ugi> ah i see
<ugi> thank you for the answer!
<fengb> marijnfs: if all the types are defined up-front, simplest way is to use a union
<marijnfs1> fengb: thanks i'll check it out.
<fengb> Or you can go the allocator route and define an interface with FPs
<marijnfs1> FPs?
<marijnfs1> of function pointers
<fengb> function pointers yeah
<marijnfs1> yeah i was doing that, but how do you make a nice interface. The init function should take an allocator?
<marijnfs1> return a pointer to it's type?
<fengb> Look at how allocators are implemented
<fengb> Use a child struct, break out with @fieldParentPtr to find the rest of the data
<marijnfs1> fengb: yeah I was using that pattern. However somewhere you want to create these structs and manage them.
<marijnfs1> ideally the deinit of the super method releases it but that's not really possible i think
<fengb> If the total number of implementations is known ahead of time, I'd recommend just using a union. It'll be similar to how C unions or functional languages handle polymorphic dispatching
<fengb> Preferably tagged union
<marijnfs1> fengb: hmm interesting
<fengb> https://github.com/ziglang/zig/blob/master/lib/std/c/ast.zig#L320 might be a better example since it actually does stuff differently
<marijnfs1> could a struct free itself? like if it has an allocator do .free(@This())
<fengb> Generally we use deinit()
<fengb> And yes it's possible, but I'm not sure if it's a common pattern to do so
<marijnfs1> fengb: yeah i see deinit used to release resources managed by the struct. But not the struct itself
SyrupThinker has joined #zig
<bsrd> Is it possible to mutate Strings with Zig?
<fengb> []u8 is mutable but []const u8 is not. Literals are generally stored as []const u8
<shakesoda> yeah you just have to copy into something mutable
<fengb> You can do something like `var foo = "hello world".*;` That makes a mutable copy
<shakesoda> i revisited my file copying problem now that it's morning and i'm not half asleep and it was solved in ~5 minutes, heh
<shakesoda> i'm not entirely sure what i expected to happen with the original approach, but the brain was definitely not working.
<fengb> Your subconscious thought about it for 8 hours
<bsrd> Thanks ^^
<fengb> bsrd: be careful passing it around though. Immutable strings are allocated in the data section so they're always valid, but mutable strings have lifetimes that must be manually managed
SyrupThinker has quit [Quit: ZNC 1.7.5 - https://znc.in]
<fengb> Literals are allocated in the data section*. Not all immutables are >_>
SyrupThinker has joined #zig
<TheLemonMan> read-only data is usually stashed in the rodata segment (only on systems using the ELF format)
<shakesoda> fengb: my subconscious can't think about something for 8 hours any better than the regular one could
<shakesoda> besides that, I'm almost certain it'd have been thinking about the book I was reading instead.
ugi has quit [Quit: Leaving]
Akuli has joined #zig
<andrewrk> TheLemonMan, can I send you a patch to try?
<andrewrk> it should solve undefined symbol when linking: __tls_get_addr #4748
<TheLemonMan> sure
<TheLemonMan> you can also try it yourself by running it on top of #4731
<andrewrk> sure I'll do that as well. it's the glibc-add-ld branch
<TheLemonMan> you didn't update link.cpp at all?
<andrewrk> nope. glibc has .abilist files for ld, the update_glibc script just wasn't looking at them
<andrewrk> I'm running tests locally with this branch, and then also the branch with 4731 merged in, if tests pass then I'll merge into master
<andrewrk> btw if you didn't hear it's looking like llvm 10 will release on monday
<andrewrk> my goal is to have all zig ci ready by then (using rc5)
<TheLemonMan> but we need a fake ld.so...
<TheLemonMan> eh fuck LLVM10, because of https://bugs.llvm.org/show_bug.cgi?id=44870 I cannot compile anything
<ifreund> how do I access something inside an unnamed union in a c struct?
<andrewrk> TheLemonMan, using your system package manager? they'll probably put a patch in for you to make it work
<andrewrk> for zig development purposes, for the next couple weeks one will likely need a source build of llvm 10 to contribute to zig
<TheLemonMan> of course, I'm not a caveman (nor I have a CPU that's powerful enough)
<scientes> TheLemonMan, CPU isn't the problem, it is disk space and ram
<scientes> with CPU you can just leave it running overnight
<TheLemonMan> picking the right name for ld.so is tricky, it should be either 'ld-<glibc version>.so' or 'ld-linux-x86-64.so.2'
<scientes> I did a LLVM bisect on a 5-year-old laptop overnight
<TheLemonMan> scientes, with ThinLTO disabled I don't hit any OOM error during the build
<scientes> you don't have to build it if you run Debian
<andrewrk> TheLemonMan, regarding ld.so, I do not think there is a problem, because we already carefully choose the dynamic linker path name based on the target. whether the symbols are exposed in a .so file named ld.so or another doesn't matter, they're provided at runtime
<TheLemonMan> that's what I do, but https://bugs.llvm.org/show_bug.cgi?id=44870 means I'm SOL 'till they fix the problem
* scientes didn't read the scrollback
<scientes> ugggh, they said they would not use github issues, and now they are using them...
<TheLemonMan> andrewrk, I'm worried about .so built from Zig and linked by another toolchain
<TheLemonMan> if you add a VER_NEEDED for 'ld.so' that doesn't exist you'll get a nasty error
<andrewrk> oh is this the "SONAME" concept?
<TheLemonMan> I hope they migrate to github issues, I think andrewrk is getting tired of relaying my bug reports to the LLVM devs :P
<TheLemonMan> good question, I think VERNEED sections refer to the file name rather than the soname
<TheLemonMan> ok it refers to the soname, I stand corrected
<andrewrk> oh, derp, glibc.cpp has a list of libs and ld is not in it
<TheLemonMan> readelf on ld-2.28.so says `Library soname: [ld-linux-x86-64.so.2]`
<andrewrk> right I see, so instead of e.g. ld.so.2, we need to name it ld-linux-x86-64.so.2
<andrewrk> I wonder if we can use std.Target.standardDynamicLinkerPath
<ifreund> ah, it's called unnamed_158 it seems. That number's going to change if the imports change right?
<andrewrk> ifreund, yeah that's not reliable. I think there is an open issue for this
<andrewrk> TheLemonMan, do you happen to have any non-x86 ld.so files lying around that we could learn what the SONAME is?
<TheLemonMan> nope, sorry
<ifreund> andrewrk: found https://github.com/ziglang/zig/issues/4043 and gave it a thumbs up
jjido has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
forgot-password has joined #zig
<forgot-password> When compiling to wasm32-freestanding, do I need something other than mark my functions with `export` for them to show up in JavaScript?
<fengb> export should be enough
_Vi has quit [Ping timeout: 246 seconds]
<forgot-password> Hm, weird my exports object only contains `memory` and `_start`
<fengb> Can you inspect the generated wasm file with wasm2wat?
<forgot-password> Sure, let me find out where I can get that first
<forgot-password> While I'm waiting for that to finish: When I run `zig build --verbose-<anything>` I don't get any output. Is that right?
<fengb> zig build uses your build.zig args parser, not the compiler ones
<forgot-password> I see
<andrewrk> stage1 compiler: https://i.imgur.com/zXWAQKb.png
<andrewrk> mikdusan, ^
<mq32> :D
<mikdusan> awww he cute
<forgot-password> fengb, here's the output from wasm2wat: https://hastebin.com/getidahozu.zig
<andrewrk> forgot-password, which are you using? build-obj build-lib build-exe
<fengb> Hmm, build-exe doesn't export anything but maybe that's intended?
<forgot-password> I ran Builder.addExecutable, should I use a library?
<fengb> Web wasm files are considered libraries yeah
<forgot-password> Makes sense now that you say it
<fengb> build-lib works as you'd expect
<fengb> wasi is the only really supported executable atm. Maybe wasm32-freestanding should disable build-exe?
<forgot-password> Works now, thanks a lot :)
<andrewrk> fengb, maybe. I'm not sure. at least zig should help make the situation more clear
<andrewrk> doesn't wasm - even freestanding - have the concept of a main entry point?
<andrewrk> TheLemonMan, https://github.com/ziglang/zig/commit/7438d0fc31f70b3a6d19e1da9a4e3f7918fc9d66 makes that test pass for me regarding __tls_get_addr
<andrewrk> does the commit look ok?
<TheLemonMan> aye
<andrewrk> ok, I'll merge this into master (along with your debug.zig fixes) once the tests pass
<TheLemonMan> the next problem is: when start_windows_tls.zig is included in a library all the exported variables are output in the .h file
<andrewrk> hmmmmm
<TheLemonMan> and that trips several asserts in the gen_h thing
<andrewrk> maybe it's time to stop advertising this feature, disable it by default, and then add it in self-hosted only
<andrewrk> (then advertise the feature when it actually works)
<TheLemonMan> is anyone using the header-generation feature at all?
<shakesoda> I've been considering it
jjido has joined #zig
<andrewrk> I don't really want to support header-generation in stage1
<fengb> So start does exist in wasm, but it's meant for "module init", not the traditional "_start"
<andrewrk> fengb, oh right. I got confused by that
<ifreund> hey, is there a way to work around translate_c errors like these until the bugs are fixed? https://paste.rs/Yqa
<ifreund> can I manually translate some of the functions? where would I put those?
<TheLemonMan> define xkb_map_new_from_names yourself
<andrewrk> ifreund, you can always make your own .h file, #include stuff there, expose some macros, and then @cImport that file
<ifreund> alright, will give it a try
marijnfs1 has quit [Quit: Lost terminal]
marijnfs has joined #zig
<TheLemonMan> andrewrk, is #1265 accepted or still in the limbo?
adamkowalski has joined #zig
<TheLemonMan> and should `foo() catch |_| { ... }` warn that `_` is unused?
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<andrewrk> I'll resolve that for you right now
ugi has joined #zig
<andrewrk> TheLemonMan, there ya go
<marijnfs> why does the std.buffer.size give len() - 1
<marijnfs> can't i have an empty buffer?
<andrewrk> marijnfs, because it maintains a sentinel null byte. perhaps you want std.ArrayList(u8) instead of std.Buffer
<marijnfs> ah yeah and the buffer init needs the sentinel to be there already i guess
<marijnfs> shouldn't it take a [:0] or something then?
<marijnfs> ow wait it reserves the space. Then how do I get a buffer without a size
<marijnfs> i get a integer overflow when calling span because the buffer is empty. I will investigate
adamkowalski has quit [Ping timeout: 256 seconds]
<forgot-password> When I use a custom panic handler, how do I make sure it doesn't call itself? If I don't add an unreachable to the end, the compiler complains that is not of type `noreturn`, but `void`.
<marijnfs> the init() in std.Buffer is a bit strange to me
<marijnfs> it uses mem.copy but targets self.list.items which should be from the arraylist. however this has one more element than input buffer so it will copy too much no?
<marijnfs> at least that looks to be causing my issue
<marijnfs> though i'm not sure
<andrewrk> forgot-password, you'll have to deal with that possibility in your handler. you can look at how the default panic handler does this for inspiration
<andrewrk> TheLemonMan just landed an improvement to this exact situation an hour ago
<forgot-password> Awesome, thank you :)
<andrewrk> I'm planning to stream today
<BaroqueLarouche> continuing game dev ?
<ifreund> cool, I watch a bit of the stuff on youtube but haven't caught one live yet
<ifreund> s/ch/ched/
recombinant has joined #zig
<andrewrk> let me think about the topic for a moment
adamkowalski has joined #zig
<fengb> `self.instance.memory[start + offset .. start + offset + length];` this won't auto coerce into `*[length]u8`
<fengb> Is the best workaround to do `self.instance.memory[start + offset..][0..length]`?
<fengb> Length is comptime
adamkowalski has quit [Ping timeout: 250 seconds]
<andrewrk> yeah that's the best thing we have right now
<andrewrk> I'm going to open a proposal to change slicing to [offset,len]
<andrewrk> that would be a really annoying change
<andrewrk> but it has to be considered
<fengb> Oh yeah are you still considering to slice by length instead of by end?
<fengb> Doh I'm slow :P
slowtyper has joined #zig
ur5us has joined #zig
CommunistWolf is now known as veggies
veggies is now known as CommunistWolf
marijnfs1 has joined #zig
marijnfs has quit [Ping timeout: 250 seconds]
FireFox317 has quit [Remote host closed the connection]
<forgot-password> Is it currently possible to have a custom handler for debug.warn?
<TheLemonMan> no
<andrewrk> forgot-password, the plan for that is https://github.com/ziglang/zig/issues/2586
_Vi has joined #zig
<TheLemonMan> the windows build seems stuck, again
adamkowalski has joined #zig
<marijnfs1> how do i make a [:0]u8 out of a string constant
<andrewrk> I'll run a local build
<andrewrk> lld: error: undefined symbol: _tls_index
<andrewrk> marijnfs1, string literals already can coerce to `[:0]const u8`. if you want a mutable one you have to decide where to put the memory
<TheLemonMan> yeah, you have to include start_windows_tls.zig even for DLLs
<TheLemonMan> and then you'll hit the gen_h problems I told you before
<andrewrk> ah, I merged prematurely
<TheLemonMan> well I didn't know what to do about that, generating the header by hand is maybe the only viable alternative
FireFox317 has joined #zig
<FireFox317> andrewrk, what time will you be streaming?
<andrewrk> TheLemonMan, want to send me your diff and i'll take it from there? will just disable gen-h by default and update ziglang.org to not claim this feature
<andrewrk> I'm guessing it's a small patch to start.zig?
<TheLemonMan> yep, copy the @import from WinMainCRTStartup into _DllMainCRTStartup
<andrewrk> ok
<andrewrk> I should look into https://github.com/ziglang/zig/issues/3237 while I'm at it
<andrewrk> FireFox317, 18:30 EST which is in 50 minutes from now
<FireFox317> nice :)
<TheLemonMan> Windows has a lot of entry points, WinMain DllMain wWinMain wDllMain WinMainCRTStartup DllMainCRTStartup and I'm pretty sure there are even more
ur5us has quit [Quit: Leaving]
marijnfs has joined #zig
<ifreund> down to my last error, but I can't seem to figure out how to work around translate c here as it's not an error with something I'm directly using https://paste.rs/lpy
<ifreund> it's from a header that is imported by one of the headers I import
marijnfs_ has quit [Ping timeout: 250 seconds]
Akuli has quit [Quit: Leaving]
<marijnfs1> nice late night stream
<ifreund> alternatively, if someone could give me a pointer on how to fix https://github.com/ziglang/zig/issues/4686 I could try that
<andrewrk> I know what the stream topic will be
<BaroqueLarouche> cool!
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
ur5us has joined #zig
<ifreund> why aren't variable length arrays just translated to c pointers?
<andrewrk> c var args functions? that's not really how it works, some of the args might be in registers
<ifreund> this is just field of a struct
* andrewrk about to start streaming
<marijnfs1> you can send a reminder on youtube i think
<ifreund> like that `uint64_t modifiers[];` should be `modifiers: [*c]u64,` right?
forgot-password has quit [Quit: leaving]
recombinant has quit [Quit: Leaving]
FireFox317 has quit [Quit: Leaving]
UgiDesu has joined #zig
ugi has quit [Ping timeout: 256 seconds]
<ifreund> ok no, it's a good bit weirder than that https://en.cppreference.com/w/c/language/struct
<ifreund> this is why I'm using zig not c :D
<mq32> <ifreund> like that `uint64_t modifiers[];` should be `modifiers: [*c]u64,` right?
<mq32> this should be [*]u64
<mq32> not c pointer
<mq32> you know that it's an array, not a pointer-to-one
mmx8705 has joined #zig
jmiven_ has joined #zig
mmx870 has quit [Quit: Ping timeout (120 seconds)]
jmiven has quit [Ping timeout: 246 seconds]
mmx8705 is now known as mmx870
ur5us has quit [Ping timeout: 260 seconds]
_Vi has quit [Ping timeout: 246 seconds]
<ifreund> true
<ifreund> yeah I think it does work, I was initially thinking the fact that it's a flexible array made things different, but for the purposes of linking at least it's just a pointer
jzelinskie has quit [Ping timeout: 246 seconds]
dtz has quit [Ping timeout: 246 seconds]
lqd has quit [Ping timeout: 246 seconds]
lqd_ has joined #zig
<fengb> Oh it’s a struct vararray? Zig doesn’t support that :/
jzelinskie has joined #zig
<fengb> One way to emulate it is defining it as `modifiers: [1]u64` and accessing with `@ptrCast([*]u64, &foo.modifiers)`
<ifreund> all I need to do is link to it, I just changed the c header to read `uint64_t *modifiers;` and it compiled/seems to run fine
<fengb> But that’s probably broken because the data is stored inside the struct, not as a pointer
<ifreund> yeah i see what you mean
marijnfs has quit [Quit: Lost terminal]
adamkowalski has quit [Ping timeout: 240 seconds]