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/
adamkowalski has quit [Quit: Lost terminal]
<pixelherodev> Wait is that
<pixelherodev> Did someone *finish* self-hosted translate-c?!
kristoff_it has joined #zig
_whitelogger has joined #zig
mahmudov has quit [Remote host closed the connection]
cshenton has joined #zig
<andrewrk> it's great because even though it's a lot of lines of code, it's the kind that's easy to review & merge
<kristoff_it> hey all, I'm finally in a good place with my Redis client. If anybody is writing a webapp, please take it for a spin and let me know what you think. It requires a build of Redis from the unstable branch until Redis 6 will be released, but I guess that's not a big deal for the people here :D
darithorn has quit [Remote host closed the connection]
Guest99598 is now known as dimenus
<dimenus> is the [*c] family of types still useful now that we have sentinels?
<pixelherodev> I think so
<pixelherodev> Though I can't remember under what circumstances, I think I was using C pointers for something...
<fengb> dimenus: yes it means the pointer is ambiguous whether it’s a single pointer or array pointer
<fengb> And... it should only be used from translate-c. Real APIs shouldn’t be that bad
<pixelherodev> Oh yeah - and e.g. translate-c will produce code using C pointers, because the sentinel isn't actually known
<pixelherodev> Only from translate-c *or code built over translated code*
<fengb> Code built over translated code can be more correct
<dimenus> yeah, i re-translated my glfw bindings, but translate-c didn't generate correct code
<dimenus> need to file a bug report
GrooveStomp has quit [Quit: GrooveStomp]
<fengb> e.g. `**argv` is ambiguous but we know it’s probably `[*][*]argv`
<dimenus> yeah
<pixelherodev> Here's a weird bug: iterating at comptime over a structure type's members for automatic argument parsing, where all args are stored in a structure `settings` with a base type AppSettings. If the type is bool, set it to true (defaults for all bools are false). If the type is optional slice of constant u8s, read the next argument and use that. If the structure contains *one* optional string, this works fine. Add a second, and the compiler has an integer
<pixelherodev> overflow in the inline while loop used for processing
<pixelherodev> Just for the sake of testing, added a few extras, but any number > 1, and it fails
<andrewrk> kristoff_it, this looks like some high quality work :)
<kristoff_it> andrewrk: hope so, it definitely took a lot of effort :D but I also had a lot of fun. Zig is amazing.
<andrewrk> :)
<andrewrk> I'm working towards getting async I/O in std lib more generally stable and usable
<fengb> Fancy structs too
<fengb> Anon
<daurnimator> translate-c in zig is going to be so much better :D
adamkowalski has joined #zig
<daurnimator> not least because of the safety features that it will introduce. translate-c crashes have always been quite opaque to me
<andrewrk> the failed-to-translate-things-as-comments feature alone will be really nice
<andrewrk> // could not translate the following macro: unable to tokenize C code: unbalanced paren
<andrewrk> / #define foo (a,
kristoff_it has quit [Ping timeout: 252 seconds]
<adamkowalski> andrewrk: is this expected? I have three different versions of the same function. I have three diferent values that I store into a static array, and into a array list, and with no list at all just as three different variables. Then I print the values one by one. I get different results with the array list then with the other mechanisms.
<adamkowalski> I labeled the functions topologicalSort, topologicalSort2, topologicalSort3.
cshenton has quit [Remote host closed the connection]
<adamkowalski> I get the correct answer with topologicalSort and topologicalSort2. But the values are corrupt with topologicalSort3. Is there something weird with storing tagged unions in heap allocated arrays
adamkowalski has quit [Ping timeout: 246 seconds]
tines9 has quit [Ping timeout: 252 seconds]
nephele_ has joined #zig
adamkowalski has joined #zig
nephele has quit [Ping timeout: 248 seconds]
tines9 has joined #zig
adamkowalski has quit [Ping timeout: 245 seconds]
lunamn_ has joined #zig
lunamn has quit [Ping timeout: 245 seconds]
mq32 has quit [Ping timeout: 265 seconds]
lunamn_ has quit [Ping timeout: 268 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 268 seconds]
lunamn has joined #zig
muffindrake has quit [Ping timeout: 246 seconds]
muffindrake has joined #zig
layneson has quit [Quit: Leaving]
lunamn has quit [Ping timeout: 258 seconds]
lunamn has joined #zig
lunamn has quit [Ping timeout: 245 seconds]
lunamn has joined #zig
ltriant has quit [Quit: leaving]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 252 seconds]
darithorn has joined #zig
jaredmm has quit [Remote host closed the connection]
jaredmm has joined #zig
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 258 seconds]
ur5us_ has quit [Ping timeout: 248 seconds]
jaredmm has quit [Quit: Bouncin']
jaredmm has joined #zig
lunamn has quit [Ping timeout: 245 seconds]
marmotini_ has joined #zig
lunamn has joined #zig
lunamn has quit [Ping timeout: 246 seconds]
nephele_ is now known as nephele
lunamn has joined #zig
leeward has quit [Disconnected by services]
leeward has joined #zig
<leeward> I'm trying to replace a C library with a Zig implementation, and having difficulty matching the C API with the generated header file. The main issues are generating size_t as the type of a parameter and using a typedef for an opaque struct.
<leeward> It would be nice if it put doc comments into the generated header at function prototypes too.
adamkowalski has joined #zig
<daurnimator> leeward: what is the size_t issue?
knebulae has quit [Read error: Connection reset by peer]
<leeward> daurnimator: If I have an exported function that returns usize, the generated .h file has it returning uintptr_t.
<leeward> That doesn't seem incorrect, given what Zig's usize is, but I would like a way to use size_t.
marmotini_ has quit [Remote host closed the connection]
doublex_ has joined #zig
doublex__ has quit [Ping timeout: 250 seconds]
dddddd has quit [Remote host closed the connection]
<daurnimator> leeward: isn't uintptr_t just as correct?
<daurnimator> leeward: uintptr_t is: "an unsigned integer type with the property that any valid pointer to void can be converted to this type, then converted back to pointer to void, and the result will compare equal to the original pointer"
tdeo has quit [Remote host closed the connection]
tdeo has joined #zig
marmotini_ has joined #zig
marmotini_ has quit [Remote host closed the connection]
return0e has joined #zig
return0__ has quit [Ping timeout: 268 seconds]
adamkowalski has quit [Ping timeout: 246 seconds]
adamkowalski has joined #zig
ur5us_ has joined #zig
adamkowalski has quit [Ping timeout: 268 seconds]
qazo has joined #zig
adamkowalski has joined #zig
return0e_ has joined #zig
return0e has quit [Read error: Connection reset by peer]
adamkowalski has quit [Ping timeout: 248 seconds]
darithorn has quit [Quit: Leaving]
qazo has quit [Quit: ...]
SimonNa has quit [Remote host closed the connection]
jokoon has joined #zig
jjido has joined #zig
FireFox317 has joined #zig
nephele has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
nephele has joined #zig
marmotini_ has joined #zig
ur5us_ has quit [Ping timeout: 248 seconds]
tyler569 has quit [Ping timeout: 250 seconds]
return0e has joined #zig
tyler569 has joined #zig
lunamn has quit [Ping timeout: 258 seconds]
lunamn has joined #zig
benjif has joined #zig
lunamn_ has joined #zig
lunamn has quit [Ping timeout: 248 seconds]
lunamn_ has quit [Ping timeout: 258 seconds]
mq32 has joined #zig
lunamn has joined #zig
M-ou-se_ is now known as M-ou-se
metnel has joined #zig
FireFox317 has quit [Remote host closed the connection]
knebulae has joined #zig
qazo has joined #zig
lunamn has quit [Quit: leaving]
jjido has quit [Quit: Connection closed for inactivity]
nephele has quit [Remote host closed the connection]
nephele has joined #zig
cshenton has joined #zig
<cshenton> Ran into a compiler bug: https://github.com/ziglang/zig/issues/3937 , what is the correct way to load to/from a Vector type from a slice/array of the same type?
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 268 seconds]
frmdstryr has quit [Remote host closed the connection]
cshenton has quit [Remote host closed the connection]
metnel has left #zig ["weechat"]
metnel has joined #zig
D3zmodos has quit [Ping timeout: 246 seconds]
BitPuffin has quit [Ping timeout: 248 seconds]
Demos[m] has quit [Ping timeout: 246 seconds]
fengb has quit [Ping timeout: 245 seconds]
aperezdc has quit [Ping timeout: 245 seconds]
dtz has quit [Ping timeout: 245 seconds]
vegai has quit [Ping timeout: 248 seconds]
emekankurumeh[m] has quit [Ping timeout: 240 seconds]
Snektron has quit [Ping timeout: 264 seconds]
dddddd has joined #zig
blueberrypie has joined #zig
fengb has joined #zig
<fengb> cshenton: literals should work — vec = [4]f32{0, 0, 0, 0}
<fengb> Bug there is that you can’t coerce a slice into an array
fengb has quit [Ping timeout: 248 seconds]
fengb has joined #zig
<fengb> The syntax you’re using there is actually trying to set a slice as an element in an array
return0e_ has quit [Read error: Connection reset by peer]
return0e_ has joined #zig
leeward has quit [Disconnected by services]
leeward has joined #zig
<leeward> daurnimator: Right, uintptr_t isn't wrong, it's just not what I want for code clarity purposes. Part of the reason to choose types in an API is documentation. I can wrap the generated .h file with something nice, but that's fragile. It's not a huge deal, but being able to control what goes in there would be useful.
<leeward> I guess this depends on how important a use case exporting to C is. Is it the goal to be able to take most C libraries and rewrite them in Zig as drop-in replacements? Is it ok to wrap up Zig's generated interface in handwritten headers for C programmers to use? There might be some advantage to generating headers from Zig that are as small as possible if the interface is intended to be documented elsewhere.
<dimenus> where does the value of eg '*[3][*:0]const u8' point to? the data itself?
waleee-cl has joined #zig
<mq32> this should point to an area of mutable 24 byte grouped in 8 bytes which present a pointer-to-many const u8s
fengb has quit [Quit: killed]
D3zmodos has joined #zig
cshenton has joined #zig
<cshenton> fengb: In the actual code I don't have access to the literals, ended up solving it with a function that uses an inline loop to put the data from the slice into an array
<cshenton> Then assigned the array to a vector (which automatically casts).
<cshenton> Now have something in Zig within 20% of Julia's performance on saxpy, which is my go to example for SIMD stuff.
fengb has joined #zig
<fengb> I think there’s an issue to allow slices to cast into arrays to fix this problem
adamkowalski has joined #zig
frmdstryr has joined #zig
<frmdstryr> Does returning a struct always return a copy?
<mq32> frmdstryr: it actually *never* returns a copy
<mq32> there is now result location semantics that guarantee that returning a struct will emplace it in the result location
<frmdstryr> How recently?
cshenton has quit [Remote host closed the connection]
adamkowalski has quit [Ping timeout: 252 seconds]
<frmdstryr> I'm trying to make an init fn that uses `var self = SomeStruct` then returns `self` but it seems to break any pointers
adamkowalski has joined #zig
<mq32> oh, that's a good question
<mq32> i think result location was the major feature of 0.5
hoppetosse has quit [Quit: Quit]
aperezdc has joined #zig
Demos[m] has joined #zig
BitPuffin has joined #zig
dtz has joined #zig
vegai has joined #zig
Snektron has joined #zig
<fengb> Result location only works when returning directly into that memory space — e.g. return Struct{}
<frmdstryr> It works in the example but in my actual code it blows up every time, id' expect that to not memcpy
marmotini_ has quit [Remote host closed the connection]
<fengb> Returning anything that’s a separate variable is currently not guaranteed to be no copy. But LLVM might optimize it to be no copy
<frmdstryr> Is there an issue for this?
<fengb> Yeah that won’t work with current semantics. You’ll need https://github.com/ziglang/zig/issues/2765
<adamkowalski> fengb: I've got a really strange issue I was hoping you could take a look at
<fengb> There’s also discussion about recognizing arbitrary result locations but that’s just in brainstorming phase
<adamkowalski> I wrote four tests that I think do something identical. 3 out of four of them give the correct answer, but one looks like the memory starts pointing to something very strange
<adamkowalski> The four functions are called topologicalSort - topologicalSort4
<adamkowalski> the topologicalSort3 gives a different result from the rest. can you take a quick look and see if i'm crazy, or is this something deeper
vegai has quit [Read error: Connection reset by peer]
fengb has quit [Read error: Connection reset by peer]
Snektron has quit [Remote host closed the connection]
aperezdc has quit [Write error: Connection reset by peer]
Demos[m] has quit [Write error: Connection reset by peer]
D3zmodos has quit [Remote host closed the connection]
BitPuffin has quit [Remote host closed the connection]
dtz has quit [Remote host closed the connection]
<gonz_> `Assertion failed at D:\a\1\s\src\analyze.cpp:416 in get_abi_alignment. This is a bug in the Zig compiler.`
<gonz_> What's the usual recourse in these situations?
<gonz_> Ah, something about this was fixed 2 days ago
<gonz_> downloading a new version fixed it
D3zmodos has joined #zig
adamkowalski has quit [Quit: Lost terminal]
fengb has joined #zig
<fengb> Hmm, I think you've stumbled upon result location's footgun
<fengb> Lemme see if I can find the root
<fengb> You made a copy in Sort4 so it fixed the problem: `const input_0 = inputs[0];`
<gonz_> I'm trying to sort out my win32 bindings for latest zig and it was just blowing up without much explanation
<gonz_> Ohh, nevermind
<fengb> Yeah it does that :P
<fengb> The memory is overriding o_O
<fengb> adamkowalski: pointer to stack memory^
<frmdstryr> Zig should make an explicit stack allocator
<frmdstryr> that makes pointers that are not normal pointers
aperezdc has joined #zig
dtz has joined #zig
Demos[m] has joined #zig
BitPuffin has joined #zig
vegai has joined #zig
Snektron has joined #zig
adamkowalski has joined #zig
<adamkowalski> fengb: thanks! so is this another result location situation? I'm used to being able to return a std::array in c++
<adamkowalski> I guess i'm really confused about the semantics of Zig still. When is it okay to return something on the stack and when is it not
<adamkowalski> If you have a method which returns a struct by value, it usually does copy ellision. We use that pattern everywhere with init methodds
<tdeo> []T is just a pointer and a length, which is different from an [N]T
<frmdstryr> Returning creates a copy
<frmdstryr> So any pointers are then invalid
<adamkowalski> tdeo: so should you never return []T since that is probably a "non owning view" into somebody else's array?
<adamkowalski> is the correct behavior to just return an ArrayList then?
<tdeo> you can take an allocator parameter and return an owned []T allocated with it (i think)
<fengb> You can't return pointers into stack memory, and slices are just fancy pointers
<tdeo> if it's always length 2 then you can return a [2]T
<tdeo> which is owned
<adamkowalski> unfortunately it's variable length
<adamkowalski> it represents an arbitrary operation which can have N inputs, but only 1 output so far
<tdeo> yeah, i think the correct way then is to take an allocator and return a []T allocated with it
<tdeo> (or you can take an allocated slice?)
<fengb> Other idea: pass in the result slice and return the updated length
<adamkowalski> I might do the take an allocator and return an allocated slice approach
<adamkowalski> Is that the recommended approach over ArrayList though?
<fengb> There's also setting up the struct as an array internally, and returning a slice into that array
<adamkowalski> and then just the caller has to know that they need to defer allocator.destroy(slice)
<fengb> That might actually be the best
<adamkowalski> can you elaborate on that
<adamkowalski> the lifetime of everything should be tied to the graph as much as possible during the creation of operations
<adamkowalski> but then there is a second lifetime for actually evaluating the values
<adamkowalski> that will typically happen within a "session" and can live much shorter then the graph itself
urluck has joined #zig
<adamkowalski> fengb I really like that idea actually, thanks! I'll just do that. It will make the caller not have to think about lifetimes
<fengb> 👍
<adamkowalski> By the way, do you all like the naming i've chosen? So far i'm kindof stealing the names from TensorFlow because I thought it would be the simplest for people transitioning
<adamkowalski> But I was debating renaming the session to "executor" or something that tells you it's the thing responsible for actually evaluating
<adamkowalski> it could also be called an interpreter I guess
SimonNa has joined #zig
return0e has quit []
jokoon has quit [Read error: Connection reset by peer]
<adamkowalski> fengb: I tried your solution and now all four test produce the same output, thanks!
wootehfoot has joined #zig
darithorn has joined #zig
adamkowalski has quit [Ping timeout: 268 seconds]
adamkowalski has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
<SyrupThinker> Ouch https://godbolt.org/z/X4qmpc
<SyrupThinker> Not good when you run your compile in the bg
<SyrupThinker> I wonder whether anyerror!noreturn makes sense in the first place
jokoon has joined #zig
wootehfoot has joined #zig
lunamn has joined #zig
plumm has joined #zig
<plumm> andrewrk: is there anything like @field for struct declarations? I want to be able to access constants at compile time
<mikdusan> ok since when is C++ able to infer template arguments for template functions. jesus.
<fengb> There's https://ziglang.org/documentation/master/#hasDecl but not @decl hmm
ur5us_ has joined #zig
<mikdusan> std.meta.declarations() and declarationInfo()
adamkowalski has quit [Ping timeout: 265 seconds]
schme245 has joined #zig
<andrewrk> plumm, @field
<andrewrk> it does `a.b` syntax except `b` is a comptime string
FireFox317 has joined #zig
<plumm> ok im not sure why that didnt work for me back when i tried it
<dingenskirchen> std.cstr.addNullByte has some odd behavior, at least unexpected for me: when it returns a null-terminated slice from one that didn't contain any 0s before, the return value ends with two 0s, one at len-1 and another one at len. the size, however, increases by one
<andrewrk> dingenskirchen, sounds like a recent regression, let me take a look.
Akuli has joined #zig
<andrewrk> hmm the implementation looks good to me
<andrewrk> ah I see the problem
<plumm> andrewrk: is there any way @field can fail to see a decl? I have an anonymous struct with a pub const field and @field is failing to find it
<andrewrk> perhaps you are passing an instance rather than a type as the first parameter
<plumm> im not :(
<plumm> omg ok nvm
<plumm> u were right smh
<dingenskirchen> folks on discord report that the last assertion fails on commit 13cdc137e
<dingenskirchen> changing the implementation to not add zeroes makes it behave as I expected: https://godbolt.org/z/xwa2Xa
<plumm> I pushed an update to zig-json-decode to allow for alternative json key names: https://github.com/haze/zig-json-decode
wilsonk has quit [Ping timeout: 265 seconds]
<andrewrk> dingenskirchen, I have some improvements to sentinel-terminated pointers in progress which will fix this
<dingenskirchen> ^^
wootehfoot has quit [Read error: Connection reset by peer]
wilsonk has joined #zig
schme245 has quit [Remote host closed the connection]
FireFox317 has quit [Remote host closed the connection]
schme245 has joined #zig
FireFox317 has joined #zig
FireFox317 has quit [Remote host closed the connection]
schme245 has quit [Ping timeout: 268 seconds]
<andrewrk> dingenskirchen, I don't have time to finish it today, but it's about half done: https://github.com/ziglang/zig/pull/3940
Akuli has quit [Quit: Leaving]
<WendigoJaeger> plumm: this a valid use case that tags/attributes (meaning C# style attribute) would helpfor alternative key names https://github.com/ziglang/zig/issues/1099
<plumm> WendigoJaeger: haha yeah, I just needed something that worked for master for the lsp im working on
<WendigoJaeger> lsp?
<WendigoJaeger> like language server ?
adamkowalski has joined #zig
<plumm> yes
<plumm> I didn't want to litter my code with autogenerated structs that didn't conform to the naming convention so I added that as a workaround until something like tags were implemented
<WendigoJaeger> I intend to push hard for that feature, if I wouldn't have to write a custom IDL ever again that would be great
* mq32 cries a bit.
<mq32> why does every modern website tries to be smart?
<mq32> i want to read that github discussion above, but it just "ends" some times
<mq32> because the content of the conversation is loaded piecewice with javascript
<mq32> and my internet connection is bad enough that every request takes more time than it would've taken when the website would be html-only for the important parts
<fengb> I forgot how terribad cross platform usually is. I can't figure out how to get mimalloc to compile to wasm
ur5us_ has quit [Remote host closed the connection]
ur5us_ has joined #zig
lygaret has joined #zig
dimenus has quit [Remote host closed the connection]
<lygaret> hi all, is it possible to run comptime code in a different target than the compilation target? I'm trying to run forward a bit with the gba stuff that was posted to reddit last week, and wanting to write some comptime resource loader code that can read a png and json file and end up embedding a formatted byte array in the final binary, but my (admitedly simple) attempts just complain that zig can't find a libc for the target (Zig is unable
<lygaret> to provide a libc for the chosen target 'thumbv4t-unknown-unknown'.)
<lygaret> which makes sense if I were trying to embed libpng in the final build, but I just want to use it at comptime
dimenus has joined #zig
<mq32> lygaret, you cannot run libc-code at comptime
<mq32> only stuff in pure zig without side effects can be run
<lygaret> aaaaah, ok; so, assuming I could write zig code that decoded an image (ala the json lib in std), it could work with @embedFile, but no using extant libs for that?
<daurnimator> yes
<daurnimator> ideally you'd write a library for e.g. PNG parsing and it would work at both comptime or runtime and it wouldn't care when it was called.
<lygaret> ok, that makes sense
<lygaret> is code gen something people are doing with build.zig? I'm having a hard time finding info on the various options there, but I keep seeing little references to it
<lygaret> thank you for your help, btw
<daurnimator> what do you mean by "codegen"?
<lygaret> so
<lygaret> what I'd like to do is take a png image of tiles, and generate a structure of tile data
<lygaret> I now realize I could probably do it with comptime if I wrote a pure zig png decoder
<lygaret> (or convert to xcf or whatever ahead of time)
<dimenus> am i having a brain fart tonight? is this not valid zig? https://bpaste.net/show/D4TLI
<lygaret> but could I for example generate c files as part of build.zig that then get cIncluded, using something like png2gba (which generates c arrays from png files for gba dev)
<daurnimator> lygaret: yeah you could do that
<daurnimator> dimenus: your `if` has `return` and a `;` but the `else` doesn't
<daurnimator> dimenus: also you have a space instead of an underscore between CPU ONLY\
<dimenus> wow, thanks daurnimator
<dimenus> sorry :(
mq32 has quit [Quit: Winke winke!]
<lygaret> @daurnimator, do you have examples of running tools during build.zig? I'm having a hard time finding build examples, but I'm likely just looking in the right places
SimonNa has quit [Remote host closed the connection]
lygaret has quit [Quit: Leaving.]