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/
fifty-six has joined #zig
<THFKA4> i can't find it, so i must be misremembering something
<pixelherodev> WendigoJaeger, ... how?!
<pixelherodev> No seriously though, how does it work? :)
<WendigoJaeger> mGBA can load ELF and has a GDB server builtin
<pixelherodev> Some sort of integration with the emulator combined with debug info exposed to the IDE?
<pixelherodev> Ag
<pixelherodev> Ah*
<pixelherodev> That's still insanely cool
<pixelherodev> Nice work!
<WendigoJaeger> thanks!
<pixelherodev> On a semi-related note, anyone know how much work it is to write a GDB server?
<blueberrypie> huh pretty cool
<WendigoJaeger> pixelherodev: dunno
fifty-six has quit [Ping timeout: 260 seconds]
<pixelherodev> There a good way to refer to a structure member from an instance of that type?
<pixelherodev> e.g. if I have `a` of type `A`, and `A` contains `const i = blahblahblah;`, there a way to refer to A.i given just `a`?
<daurnimator> `@typeOf(a).i` ?
<pixelherodev> I literally just tried that.
<pixelherodev> It worked.
<pixelherodev> :P
<pixelherodev> But no, it's @TypeOf(a) now
<pixelherodev> But yeah that works
<pixelherodev> `if (err == @TypeOf(backend_allocator).AllocationError.NoMoreRoom)` Hmm
<pixelherodev> Seems a bit long-winded, but eh
<pixelherodev> Better than saving a reference to the type just for this
<pixelherodev> .... huh. Well this is weird. If you do `const a = @import()` *within a function's scope* and then refer to a private member, it's valid.
<pixelherodev> The weirdest part is that if I have `var a = @import("blah.zig").init(blah);` where blah.zig has a private member named whocares and blah.init returns an object of type blah (@This()), `@TypeOf(a).whocares is a valid access
<pixelherodev> s/valid/invalid
<pixelherodev> *But*, if you store the type as `const b = @import("blah.zig");var a = b.init(blah);` then *the exact same access line* is valid
<frmdstryr> Is there a way to get the path of the current file, like python's `__file__`?
<frmdstryr> Nvm @embedFile works with relative paths
<pixelherodev> ___file___ wouldn't be useful in that scenario anyways
<pixelherodev> Well
<pixelherodev> I mean, I *guess*, since @embedFile is comptime
<pixelherodev> That does provide for an intriguing idea of comptime-*only* Zig
<pixelherodev> Which leaves basically just an interpreted / scripting language
<pixelherodev> If there was an "instantaneous" compiler for that (the intended debug compiler perhaps?), I'd use that in a heartbeat over e.g. Bash
<pixelherodev> (not that I use bash all that much as is; I try to stick to POSIX-compatible shell code)
<pixelherodev> Is there a way to make structure functions fully private?
<pixelherodev> By the Java definition of private
<pixelherodev> Such that other structure functions can call it, but outside code cannot?
<pixelherodev> I want to hide implementation details to ensure that client code doesn't become reliant on highly volatile (in the sense of constantly changing, not the technical sense) functions
<fengb> Java private can still be called via reflection ๐Ÿ™ƒ
<pixelherodev> The fact that Java has a lot of flaws isn't germane to this discussion.
<pixelherodev> Weird idea thought thing I just had: I know there was a discussion on adding integer properties, but what if there was e.g. a "power of two" property? Such that a runtime value can be of a type requiring a power of two?
<pixelherodev> Or a more generic "power_of(n)" property
<pixelherodev> This would be a pretty simple thing to check for
<pixelherodev> The only valid operation on it would be multiplying by n
<pixelherodev> Example use case: hashmap at present uses `assert(math.isPowerOfTwo(new_capacity))`
<pixelherodev> It's called in three ways: 16, the previous capacity * 2, and `math.ceilPowerOfTwo(usize, expected * 5 / 3)`
<pixelherodev> Such a property would allow for the assertion to be removed and one less point of runtime failure
<daurnimator> pixelherodev: I've thought about that..... and you end up wanting functions for all sorts of limitations on values
<pixelherodev> Such as?
<daurnimator> e.g. why only power of two? we already have `min` and `max` on the way. But why not `multiple_of_3` and `prime`?
<pixelherodev> Because prime is utterly impractical
<pixelherodev> Power of is effectively trivial
<pixelherodev> multiple of 3 would be power_of(3)
<pixelherodev> Power of two *specifically* has the further added advantage of requiring less memory
<daurnimator> multiple != power.
<pixelherodev> Though power_of(n) could probably have an optimized in-memory representation, power of 2 would be easiest in that you'd need to store the power
<pixelherodev> Ah right
<pixelherodev> again, power of is trivial and has practical advantages both in the standard library and in compiled binaries
<pixelherodev> Generally, I think if it's trivial and doesn't have any real downside it's worth it
<pixelherodev> Though adding in a hundred trivial features would be problematic too...
<pixelherodev> Ooh, better idea
<pixelherodev> Implementing such types *within the language*
<pixelherodev> Instead of in the compiler
<pixelherodev> At the very least, if used at compile time, that could be useful
<daurnimator> isn't only power of two vaguely efficient? and others not?
<pixelherodev> Right, but I'm saying a power of two
<daurnimator> you said `power_of(n)`
<pixelherodev> As a hypothetical extension
<pixelherodev> The main idea was just Po2
cshenton has joined #zig
<cshenton> I'm writing a vector math lib and have run into an issue. I have a generic vector type with a cross product method that compile errors when called on a non 3d vector. For some reason, calling std.testing.allEqual on an unrelated operation is causing that method to get hit even when I don't call it so my code won't compile.
<cshenton> Can I conditionally declare a member function to get around this?
<fengb> Ah thatโ€™s probably the typeInfo bug:
<cshenton> Yep allEqual does a switch on typeInfo so that's not surprising.
<cshenton> So it's a bug and I should work around, I'm not fundamentally doing things incorrectly?
<daurnimator> yeah. its been known about for a while. I recall that @memberCount was kept in existence because it worked without this issue while `@typeInfo(x).XYZ.fields.len` didn't.
<cshenton> I'm thinking I should actually just remove that compileError for now, since I use @typeInfo on my vector types for some other stuff (automatically formatting an opengl vertex buffer)
<cshenton> Unrelated, the argument signature for a non mutating member method is `self: *const Self`, not `self: Self` right?
<fengb> self: Self is preferred. Zig will probably pass a const pointer under the hood, but it may pass by value if itโ€™s faster
<daurnimator> pixelherodev: btw, my reply on #2428 is sort of for you
<pixelherodev> Could've pinged me there :P
<pixelherodev> To respond though:
<pixelherodev> Yes, I mentioned in that thread that they could be closed and modified afterwards
<pixelherodev> The question was whether to return an error if someone closes it and then tries accessing it without opening it
<pixelherodev> The answer that was decided upon was "no."
<pixelherodev> If someone does this deliberately, that's on them. See https://github.com/ziglang/zig/issues/2428#issuecomment-568099362
<cshenton> Has anyone had issues with `inline` on generic structs? I'm getting an 'unable to inline' compiler error on a pretty innocuous vector add method.
<cshenton> Specifically, if I copy paste the code inside the generic struct, the compiler does not complain about inlining.
<cshenton> oof, you're not going to like this. That error only occurs when I call `expectEqual`, not if I manually `expect` on each field
<cshenton> Going to file a bug
cshenton has quit [Remote host closed the connection]
lygaret has joined #zig
cshenton has joined #zig
dimenus has quit [Remote host closed the connection]
<Snektron> `for (@typeInfo(Direction).Enum.fields) |dir| {`
<Snektron> that should work right?
<Snektron> im getting `values of type 'std.builtin.EnumField' must be comptime known, but index value is runtime known`
<pixelherodev> `inline for`?
<Snektron> seems to be it, thanks
<pixelherodev> np
<cshenton> This is a fun one https://github.com/ziglang/zig/issues/3958, inlining fails but only if the method is not called but @typeInfo has analysed it.
<pixelherodev> But
<pixelherodev> But in that case it doesn't need inlining
<pixelherodev> Ah
<pixelherodev> I suspect this is a duplicate
cshenton has quit [Remote host closed the connection]
cshenton has joined #zig
<cshenton> Yeah I referenced that issue in mine, but I thought I'd make a new issue since it's not immediately obvious they're related.
lygaret has quit [Quit: Leaving.]
<cshenton> And also for discoverability for people with the same problem.
cshenton has quit [Remote host closed the connection]
nephele has quit [Ping timeout: 248 seconds]
nephele has joined #zig
adamkowalski has joined #zig
protty has quit [Remote host closed the connection]
muffindrake has quit [Ping timeout: 246 seconds]
muffindrake has joined #zig
<adamkowalski> :q
<adamkowalski> whoops
adamkowalski has quit [Quit: Lost terminal]
scientes has quit [Quit: ZNC 1.7.5+deb1 - https://znc.in]
dingenskirchen has quit [Ping timeout: 248 seconds]
frmdstryr has quit [Remote host closed the connection]
<pixelherodev> ah, the delightful feeling of auditing 3KLOC :P
<pixelherodev> There a better way to check bytes from bits than `(bits + if (bits % 8 != 0) @as(u8, 8) else 0) / 8)`?
<pixelherodev> It's better than the way I had it earlier, but it still looks *wrong* (even though I'm 99% certain it's accurate)
<pixelherodev> With a line like `var a = []u8 { a(), b() };`, is there any guarantee that a will be called before b?
lygaret has joined #zig
<pixelherodev> and yes I realize that would be a name collision
_whitelogger has joined #zig
leeward has quit [Disconnected by services]
leeward has joined #zig
lunamn has quit [Ping timeout: 265 seconds]
_whitelogger has joined #zig
_whitelogger has joined #zig
_whitelogger has joined #zig
_whitelogger has joined #zig
D3zmodos has joined #zig
<D3zmodos> Am I missing something obvious here? If I try to switch on a runtime value where all the branches result in comptime values, I get a compiler error... https://hastebin.com/imoqexumiv.cpp
<pixelherodev> Compiler bug\
<pixelherodev> Integer literals are implicitly of type comptime_int
<pixelherodev> If you change any of those branches to be `@as(u8, val)` it should work\
<pixelherodev> As is, bar is being given the type comptime_int
<pixelherodev> Which isn't a type a runtime value can have
<pixelherodev> If you change e.g. `0 => 10` into `0 => @as(u8, 10)`, it'll result in the switch expression gaining type u8
<pixelherodev> Setting the type of bar to u8 manually won't help either, because the switch expression would still have the wrong type
<pixelherodev> D3zmodos, hope this helps!
<D3zmodos> aaaah ok yes that makes sense. I guess I'd just assumed that comptime_int would be automatically resolved to a runtime type as necessary. Thanks pixelherodev !
<pixelherodev> No problem!
<pixelherodev> I think it's *supposed* to be automatically resolved, but that's not yet implemented
lygaret has quit [Quit: Leaving.]
darithorn has quit [Quit: Leaving]
dingenskirchen has joined #zig
scientes has joined #zig
daex has quit [Ping timeout: 240 seconds]
daex has joined #zig
dddddd has quit [Ping timeout: 260 seconds]
dingenskirchen has quit [Quit: dingenskirchen]
dingenskirchen has joined #zig
cshenton has joined #zig
<cshenton> If I wanted to get my head around the codebase with a view to fixing https://github.com/ziglang/zig/issues/3893 where should I start?
cshenton has quit [Remote host closed the connection]
wootehfoot has joined #zig
wootehfoot has quit [Remote host closed the connection]
wootehfoot has joined #zig
nephele has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
daex has quit [Ping timeout: 265 seconds]
daex has joined #zig
SyrupThinker has quit [Quit: ZNC 1.7.4 - https://znc.in]
SyrupThinker has joined #zig
_whitelogger has joined #zig
_whitelogger has joined #zig
benjif has joined #zig
SyrupThinker has quit [Quit: ZNC 1.7.5 - https://znc.in]
SyrupThinker has joined #zig
clktmr has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
clktmr has quit [Quit: ZNC 1.7.5 - https://znc.in]
clktmr has joined #zig
clktmr has quit [Client Quit]
clktmr has joined #zig
frmdstryr has joined #zig
wootehfoot has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
fifty-six has joined #zig
<fifty-six> Do if expressions require comptime bools?
<fengb> I was also planning on taking a deeper look
<Snektron> When i took a deeper look i got scared by ir.zig
<Snektron> Every once in a while i run into a zig issue of which i think its really weird that it exists
<Snektron> For example, int literal type resolution works on switch expressions if you annotate the return type: `const a: i32 = switch ...`
<Snektron> But it fails if you put a ternary expression inside the switch
<Snektron> err, i meant ir.cpp
clktmr has quit [Quit: ZNC 1.7.5 - https://znc.in]
clktmr has joined #zig
dddddd has joined #zig
SimonNa has quit [Remote host closed the connection]
fifty-six has quit [Remote host closed the connection]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 258 seconds]
darithorn has joined #zig
adamkowalski has joined #zig
<andrewrk> Snektron, a 30K line c++ file never hurt anyone :P
casaca has quit [Ping timeout: 240 seconds]
casaca has joined #zig
<adamkowalski> is this the recommended way to run all tests? https://github.com/adam-r-kowalski/compute_graph/blob/master/src/main.zig#L1
<andrewrk> adamkowalski, yes, at least for now
<adamkowalski> okay thanks! and when defining my public API should I just do a pub const name = @import("name");
<andrewrk> dingenskirchen, the addNullByte issue is fixed, https://github.com/ziglang/zig/pull/3940 is merged
<adamkowalski> that way people can just import the main file and get access to everything that I want exposed?
<adamkowalski> it seems like that is what the standard is doing
MarquisdeFalbala has joined #zig
<andrewrk> yes the way your package will expose an API is via a "root" file, so you'll need one file that exposes everything that you want to be in your API
<andrewrk> sentinels should feel pretty ergonomic to use now
<adamkowalski> I like that. Is there any benefit to scoping imports to a test case? https://github.com/adam-r-kowalski/compute_graph/blob/master/src/session.zig#L133
<adamkowalski> I was thinking that if I do that the compile times will be faster because other tests that don't need those imports won't even look at them
<andrewrk> zig is already pretty lazy, I don't think it will make a difference
<adamkowalski> Yeah and the compiler already seems really fast. I feel like 90% of the time is spent in generating code using LLVM. At least that's what the terminal output sugests
<adamkowalski> I'm curious if we can get similar speeds to something like D if bypass LLVM for non release builds
fifty-six has joined #zig
<fifty-six> Sorry to bother but how do you debug a zig build failing because of `broken LLVM module found: Call parameter type does not match function signature!`
TheLemonMan has joined #zig
<TheLemonMan> yo andrewrk, is the proposal in #1917 still accepted?
<TheLemonMan> because I need weak refs for the PIE patchset and am gonna dust off the branch where I've implemented @externWeak
<TheLemonMan> I'm still not 100% sold on introducing a new builtin, I'd just slap `weak` on VarDecl and make `&` return `?*T` pointers for such variables
muffindrake has left #zig [#zig]
dewf has joined #zig
Aransentin has joined #zig
fifty-six has quit [Ping timeout: 260 seconds]
adamkowalski has quit [Quit: Lost terminal]
<andrewrk> TheLemonMan, I'm about to hop on a plane, but let me take a look
<andrewrk> @externWeak is a lot easier to automatically rewrite users' code if we end up changing it to something else later
<andrewrk> the proposal is still planned, yes
<TheLemonMan> roger that, I'll send a PR later
Akuli has joined #zig
<Aransentin> Writing an win32+user32 file for zig, and I have some ideas for a "cleanup" of the API. Tell me if my ideas are dumb:
<Aransentin> Trash the confusing naming scheme, i.e. no more LPCSTR and just `[*:0]const u8` everywhere. Same for the opaque types: HINSTANCE -> *InstanceStrip the polish notation from the arguments and struct members and rename them to zig style: e.g. "lpClassName" -> class_nameReplace integer arguments/return values with enums of the same size when it makes
<Aransentin> sense; e.g. "dwExStyle" in CreateWindowExA should be an `extern enum(u32)` with the valid arguments instead of a DWORD.Wrap the raw win32 API calls in zig functions that take e.g. slices and translate them to pointer-and-length arguments, error codes to Zig errors, and perhaps converts unicode strings to UTF16 like Windows wants.
<Aransentin> Whoops the newlines got stripped out there...
<Aransentin> sorry about that. Lemme try again :)
<Aransentin> Strip the polish notation from the arguments and struct members and rename them to zig style: e.g. "lpClassName" -> class_name
<Aransentin> Trash the confusing naming scheme, i.e. no more LPCSTR and just `[*:0]const u8` everywhere. Same for the opaque types: HINSTANCE -> *Instance
<Aransentin> Replace integer arguments/return values with enums of the same size when it makes sense; e.g. "dwExStyle" in CreateWindowExA should be an `extern enum(u32)` with the valid arguments instead of a DWORD.
<Aransentin> Wrap the raw win32 API calls in zig functions that take e.g. slices and translate them to pointer-and-length arguments, error codes to Zig errors, and perhaps converts unicode strings to UTF16 like Windows wants.
<Aransentin> ... and by "Polish notation" I meant Hungarian notation ๐Ÿ˜–
clktmr has quit [Quit: ZNC 1.7.5 - https://znc.in]
clktmr has joined #zig
<TheLemonMan> changing the names is not so wise IMO as that makes the existing documentation (and MSDN) hard to follow
<Aransentin> Ah, yeah. Maybe I can change it for the Zig wrappers, and not the "real" functions.
<Snektron> <andrewrk "Snektron, a 30K line c++ file ne"> My largest c++ project wasnt even a quarter of that in total
<Aransentin> To be fair the win32 docs are kinda terrible anyways. Try reading this, for example: https://docs.microsoft.com/en-us/windows/win32/api/wsipv6ok/nf-wsipv6ok-wsaasyncgethostbyname
<Snektron> Aransentin, maybe its best to create sone wrapper API that uses the current functionality
<Snektron> That was my plan for something else
<Snektron> <Snektron "My largest c++ project wasnt eve"> Though i have a sneaking suspicion some of it could maybe be improved by utilizing more of c++
<Snektron> Of ir.cpp, that is
Wallbraker has quit [Ping timeout: 268 seconds]
MarquisdeFalbala has quit [Remote host closed the connection]
Pistahh has quit [Quit: leaving]
Pistahh has joined #zig
dewf has left #zig ["Leaving"]
Akuli has quit [Quit: Leaving]
clktmr has quit [Quit: ZNC 1.7.5 - https://znc.in]
clktmr has joined #zig
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
<daurnimator> ooo, I wonder if thelemonman is writing a loader in zig...
<daurnimator> andrewrk: FWIW the pie executables I know are files that are simultaenously executables and libraries. The most famous one being /lib64/ld-linux-x86-64.so.2 the second most famous one being /usr/lib/libc.so.6
<daurnimator> ==> try running those as executables :)
<pixelherodev> "This is the gcompat ELF interpreter stub. You are not meant to run this directly."
<pixelherodev> :P
<daurnimator> pixelherodev: sure..... but thats still weird: you just executed a library
<pixelherodev> I've made libraries like this before
<pixelherodev> It's not overly difficult
<daurnimator> correct. but it requires -fpie doesn't it?
<pixelherodev> IIRC yeah
<pixelherodev> It's been at least a year since I played with that
<daurnimator> pixelherodev: I am essentially replying to https://github.com/ziglang/zig/pull/3960#issuecomment-568201862