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/
lunamn has quit [Ping timeout: 240 seconds]
lunamn has joined #zig
ur5us has quit [Ping timeout: 245 seconds]
lunamn has quit [Ping timeout: 268 seconds]
nickster has joined #zig
lunamn has joined #zig
<andrewrk> on stream, we got to successfully assembling hello_world.s directly into an x86_64 ELF binary and running it :)
<daurnimator> andrewrk: I wasn't able to watch the stream; but are you writing it as an executable or a library?
<andrewrk> at such an early stage of a project there is no difference
ur5us has joined #zig
<emekankurumeh[m]> instead of pinned fields, has relative pointer types been discussed?
<shachaf> The video is pretty low-resolution -- is it just a thing where it takes a while to encode?
<shachaf> (Is the code up somewhere?)
<shachaf> Aha.
<emekankurumeh[m]> i.e. a pointer that is just an offset into the struct where another field resides
<emekankurumeh[m]> these would be then safe to copy
<pixelherodev> Is it possible to have a member shared in a tagged union?
<pixelherodev> e.g. a struct that's always valid + the tagged union?
<pixelherodev> Besides the obvious "nest tagged union in a struct"
<daurnimator> pixelherodev: I hit the same question in capnp
<andrewrk> shachaf, yes it takes about 20 min before the hd res version comes online
<traviss> i posted my advent zig code too: https://github.com/travisstaloch/advocode2019 . day 3 in 75 lines using AutoHashMap :)
<fengb> I used a 2d array. Took up 10GB lol
<traviss> heh. i tried similar but gave up as i kept going out of bounds.
<fengb> I crashed the stack first. Then I crashed the heap too
<traviss> i liked how easy getting a set intersection was. iterate over all the points in map a and then
<traviss> if (b.get(key)) |_| _ = try res.put(ak, {});
<fengb> Probably should have switched but nah, whatโ€™s the point of having unlimited memory if I donโ€™t use it
<traviss> s/ak/key
<Snektron> I first checked what the min and max bounds were
<Snektron> Then i used a stack array of (2^24)^2 = 32 MB
mahmudov has quit [Remote host closed the connection]
ky0ko51 has joined #zig
ky0ko has quit [Disconnected by services]
ky0ko51 is now known as ky0ko
reductum has quit [Quit: WeeChat 2.6]
ky0ko has quit [Ping timeout: 268 seconds]
lunamn has quit [Ping timeout: 250 seconds]
lunamn has joined #zig
muffindrake has quit [Ping timeout: 276 seconds]
muffindrake has joined #zig
IntoxicatedHippo has joined #zig
IntoxicatedHippo has quit [Quit: Leaving]
ky0ko has joined #zig
lunamn has quit [Ping timeout: 240 seconds]
lunamn has joined #zig
leeward has joined #zig
<leeward> Does anyone know an easy way to get `zig build test` to stick its output somewhere other than zig-cache/o/somegobbledygook/?
<leeward> I tried changing tests.output-dir, but it had no effect.
lunamn has quit [Ping timeout: 276 seconds]
lunamn has joined #zig
lunamn has quit [Ping timeout: 276 seconds]
qbradley has joined #zig
lunamn has joined #zig
adamkowalski has joined #zig
ur5us has quit [Ping timeout: 245 seconds]
ltriant has quit [Ping timeout: 250 seconds]
return0e_ has joined #zig
return0e has quit [Ping timeout: 265 seconds]
adamkowalski has quit [Ping timeout: 268 seconds]
marmotini_ has joined #zig
adamkowalski has joined #zig
marmotini_ has quit [Remote host closed the connection]
<Snektron> leeward, theres a function in build.zig to do that
qbradley has quit [Ping timeout: 260 seconds]
ky0ko has quit [Ping timeout: 265 seconds]
<leeward> Snektron: which?
<adamkowalski> Is there something you all can recommend for me here? I have two minimal code snippets https://pastebin.com/k1LvEsxM and https://pastebin.com/fyFEJppy
<adamkowalski> In the first I have a struct which has a generic type T. Because T is now in scope, I can have a member function which takes in a struct which uses that type T as well as a value which is of the same type
<adamkowalski> This makes the test code nice and clean
<adamkowalski> In the second case however, I cannot do the same because I try to make it into a free function. I have to pass the type explictly and then I can use it further on in the arguments. It makes the API much more clunky
<adamkowalski> The solution I've thought of is to make the function accept parameters by var, then use introspection to check if the types match, but that makes the functions much more verbose
<adamkowalski> Any ideas?
<adamkowalski> I would like for everything to be a free function so I don't have to cram everything into the struct just to avoid writing the type down explicitly for every function
leeward has quit [Quit: *Poof*]
adamkowalski has quit [Quit: Lost terminal]
<mikdusan> letoram: `zig build ...` is going to create various artifacts that go in hash'd dir names, but the _install_ artifacts dir is somewhat configurable
<mikdusan> leeward ^^
<Snektron> leeward, i think its `exe.setOutputDir`
<Snektron> can you combine that with the testing functionality?
<traviss> adamkowalski how does this look? https://pastebin.com/pD0kmS32
marler8997 has quit [Ping timeout: 265 seconds]
pixelherodev has quit [*.net *.split]
cow-orker has quit [*.net *.split]
so has quit [*.net *.split]
cow-orker has joined #zig
pixelherodev has joined #zig
so has joined #zig
so has quit [Max SendQ exceeded]
<Snektron> I made this nice c++ implementation of yesterdays AOC which i wanted to share
so has joined #zig
<mq32> you can probbaly also output the result as a compile error :D
lunamn has quit [Ping timeout: 268 seconds]
lunamn has joined #zig
<Snektron> That's what it does
<mq32> oh
<mq32> neat :D
return0e has joined #zig
mforney has quit [Quit: quit]
lunamn has quit [Quit: Lost terminal]
FireFox317 has joined #zig
FireFox317 has quit [Remote host closed the connection]
mforney has joined #zig
mixi has quit [Quit: mixi]
mixi has joined #zig
hio has quit [Quit: Connection closed for inactivity]
<mq32> hm, can someone help me out?
<mq32> i get the following error:
<mq32> error: struct 'tilemap.Node' depends on itself
<mq32> hm
<mq32> seems like the array type isn't lazy enough...
<mq32> is there already a bug report for this? using "[2][2]?*T" does not work, but "?*T" does
ltriant has joined #zig
ltriant has quit [Ping timeout: 250 seconds]
<daurnimator> andrewrk: watching the stream now: re: Q&A: I think a good instream.scan() requires a peek stream.
return0e has quit [Ping timeout: 250 seconds]
return0e has joined #zig
kapil_ has joined #zig
dimenus has quit [Ping timeout: 250 seconds]
dimenus has joined #zig
dimenus has quit [Ping timeout: 240 seconds]
FSX has quit [*.net *.split]
bkleiner has quit [*.net *.split]
tbodt has quit [*.net *.split]
tbodt has joined #zig
FSX has joined #zig
bkleiner has joined #zig
FSX has quit [*.net *.split]
bkleiner has quit [*.net *.split]
tbodt has quit [*.net *.split]
bkleiner has joined #zig
FSX has joined #zig
tbodt has joined #zig
waleee-cl has joined #zig
dimenus has joined #zig
<dimenus> is it possible in zig to create a type that has functions that point to different functions based on a passed in comptime value?
<dimenus> the scenario i'm thinking here is a graphics frontend that points to either vulkan or opengl
<andrewrk> dimenus, yes
<andrewrk> pub const foo = if (x) a else b; //option 1
<dimenus> that's basically what i have, but it doesn't work at the callsite
<dimenus> i'm sure i'm butchering something though
mahmudov has joined #zig
<Snektron> I made a pr for some changes to sort.zig
<dimenus> andrewrk: https://bpaste.net/show/325UK
<Snektron> i would rather make a VulkanBackend and an OpenGlBackend (for example)
<Snektron> And then return that from Backend
<dimenus> yeah, good point
<andrewrk> yeah put some logic in the BackendContext function
<dimenus> i had a brain fart, my bad guys. I thin using function pointers is probably too C like here. better to return a regular struct with functions with similar names
<andrewrk> that sounds much better
<andrewrk> zig is allergic to runtime-known function pointers
<dimenus> yeah, that would require having completely common function signatures
<dimenus> which is bleh
<Snektron> andrewrk: one this i was wondering about is whether std.sort.min/max should return ?T in case the slice is empty
<Snektron> s/this/thing
Akuli has joined #zig
<andrewrk> Snektron, I could see there being value in any of the following APIs: * provide default value as parameter, return is T * assert len > 0, return is T * allow len 0, return is ?T
<Snektron> I suppose version 1 is encompassed by version 3
<Snektron> and version 2 is equal to version 1 and a `.?`
<Snektron> suppose a function `f` is `fn(a: i32) ?i32` and one writes `f(x).?`
<andrewrk> I think I like the ? version, because you can get the first version with `orelse` and the second version with `.?`
<Snektron> Would `f` internally still return whether the call was successful?
<Snektron> or does that depend on wether `f` gets inlined in that expression?
<andrewrk> that would be up to the optimizer. high chance that it could figure it out
<andrewrk> let's try a godbolt example
qbradley has joined #zig
<Snektron> huh
<andrewrk> even release-safe mode was able to figure it out
<Snektron> great
<Snektron> take a look at my example though
<andrewrk> looking
<andrewrk> what am I looking for here?
<Snektron> Why does the function return what it does when b = 0
<andrewrk> oh I see, that branch should in theory be eliminated
<Snektron> i suppose it isn't perfect though
<Snektron> also, why exactlky is it accessing the stack in the b != 0 part?
<andrewrk> if you replace `null` with `unreachable` then llvm figures it out. so yeah there's room for improvement here
<andrewrk> zig could help too, if we wanted to try that. for example zig could generate a specialization of div where returning null is unreachable, since the callsite has .?
<andrewrk> but I don't think such an optimization belongs in stage1
<Snektron> I suppose to optimize that it would need to look at the entire expression including expressions in called functions
<Snektron> maybe .? should be a special case though, but i agree that thats maybe too much for now
<Snektron> I am still wondering about the stack part though
<andrewrk> I think that's a constant to represent `@as(?i32, null)`
<andrewrk> llvm didn't figure out to inline it
<Snektron> hm, odd
<Snektron> Anyway i'll make the changes to std.sort.min and max
<andrewrk> yeah especially strange because the constant is all zeroes. that's pretty easy to inline
<Snektron> also strange how eax is first stored to [rsp - 8], and then loaded again
<Snektron> peephole optimization should have taken care of that
<andrewrk> I guess llvm is not magic after all :)
<Snektron> certainly not, but this case should be rather trivial
<andrewrk> I think it's safe to say that this case will be solved in the future. there's nothing fundamentally preventing it from working
qbradley has quit [Ping timeout: 260 seconds]
<andrewrk> emekankurumeh[m], I'm going to finally unblock #2598 for you
return0e has quit []
<Snektron> alright, i've made min/max return ?T,
<Snektron> i've also added argMin and argMax, these return the index of the min/max item instead of the item itself
FireFox317 has joined #zig
traviss has quit [Remote host closed the connection]
FireFox317 has quit [Ping timeout: 265 seconds]
<dimenus> man, debugging c++ is just not fun
FireFox317 has joined #zig
<andrewrk> dimenus, true that. one thing I've learned is that it's worth it to invest in debug infrastructure
<andrewrk> if you're debugging some zig internals, I should teach you the new debug stuff I added
<dimenus> nah, vulkan examples from sascha willems (but I will take you up on that at some point)
<frmdstryr> Could zig do just in time compiling? It'd be awesome to have something like ipython to test code on the fly/embed and debug
<andrewrk> nope, zig is an Ahead Of Time compiler
<dimenus> zig's type information makes for a nice api, i can store the type in my resource pool to ensure that there's no stomping on other buffers or memory corruption (well much less of a risk anyway)
lunamn has joined #zig
<Snektron> frmdstryr: i usually use `zig run`
<Snektron> at least, thats what i've been using for aoc
<Snektron> dimenus: if you have Vulkan problems, i could try to answer those as well. I have some amount of experience.
<FireFox317> andrewrk, another stream today? :))) It's so fun to see you coding xd
<andrewrk> FireFox317, not today, but maybe some more zasm this weekend :)
wootehfoot has joined #zig
<FireFox317> hahah no problem man! Appreciate your streams yesterday and the day before :^)
<andrewrk> that was so fun to get hello_world.s assembling directly into an ELF binary and running it
<andrewrk> that's full bootstrap, baby! no C++, no LLVM
<bgiannan> i'd like to do something for each case of an enum, can i iterate over it somehow ?
<Snektron> yeah, see @typeInfo
<bgiannan> ah great thx
<stratact> Oh, I would love to have this so badly: https://github.com/ziglang/zig/issues/2931
<andrewrk> stratact, I just marked it contributor friendly
reductum has joined #zig
<stratact> andrewrk: alright, I'll take it. I guess better to do something about it than wait ;)
<FireFox317> andrewrk: the new code in start.zig doesn't work for freestanding/clashos, you mind adjusting it? I'm getting errors that it is trying to find root.main and system.exit etc. I'm not sure what the correct thing to do will be regarding freestanding, that's why i'm asking
return0e_ has quit [Ping timeout: 240 seconds]
ltriant has joined #zig
return0e has joined #zig
<FireFox317> still working on a PR btw, but uni is time consuming :)
ltriant has quit [Ping timeout: 250 seconds]
lunamn has quit [Ping timeout: 250 seconds]
<andrewrk> FireFox317, yeah, taking a look
lunamn has joined #zig
<dimenus> Snektron, thanks. I'll keep that in mind. Atm I'm building the learnopengl.com breakout game but in Zig & Vulkan
<dimenus> probably use libsoundio for sound instead of irrklang as well
<andrewrk> FireFox317, I have local tests running, should have fix pushed soon
<andrewrk> pixelherodev, this might be a breaking change for your use case, but hopefully in a good way. if you were relying on your _start symbol being found for your custom os app, you'll want to use the new `other` OS rather than `freestanding`
<stratact> hahaha, what did I get myself into? I started watching a youtube video about TUIs with Miguel de Icaza (the GNOME creator) speaking, to help me learn terminfo a bit better, and as brilliant as that guy is, the first thing he is says is creating these UIs is "relatively painful" and "very annoying" ... ๐Ÿ˜„๐Ÿ˜„๐Ÿ˜„
<andrewrk> I mean if your entry point was _start it will continue to work the same but if you were using `pub fn main` then this will affect you
<andrewrk> stratact, personally, I'd start with reading the lua implementation and understanding what they're doing. it seemed like the "data" component of it was most of the code, the actual logic was just a couple functions
<stratact> Fair enough, I should take advantage of daurnimator's existing work. I let curiousity get the best of me.
<FireFox317> andrewrk: Thanks!
lunamn has quit [Ping timeout: 240 seconds]
<andrewrk> stratact, well geez I wouldn't put it that way. if you were inspired to learn stuff, that's great
<stratact> Ah, thank you. Well that's part of my strategy is just to get into unfamiliar terrirority and learn how it works, so it takes away the uncertainty/fear.
lunamn has joined #zig
<andrewrk> good plan
<stratact> I need to find material that ressonates with me though. Reading the details in the very detailed man page for terminfo makes it hard for me to jump into, so I'm looking for prerequisite material to make it easier to reference
<stratact> With all that said, I still very much would love to have a curses lib for Zig and use it for a project.
marmotini has joined #zig
<dimenus> andrewrk: does this look like it should be valid zig? https://bpaste.net/show/JEAOM
<dimenus> i'm hitting the else branch unexpectedly
lunamn has quit [Ping timeout: 265 seconds]
<dimenus> here's the full struct https://bpaste.net/show/HJB6K
lunamn has joined #zig
<andrewrk> dimenus, you're missing comptime on backend_type
<andrewrk> so the switch is not comptime
<dimenus> thank you sir
<andrewrk> one way to diagnose this is to put comptime in the switch target expression, it would have said "unable to evaluate constant expression" and that would be a clue
<andrewrk> FireFox317, fix pushed to master
marmotini_ has joined #zig
marmotini_ has quit [Remote host closed the connection]
ur5us has joined #zig
marmotini has quit [Remote host closed the connection]
ky0ko has joined #zig
<andrewrk> frmdstryr, huh, actually llvm does seem to be able to understand zig's interface pattern: https://godbolt.org/z/avZe7Z
<andrewrk> it even figures it out with --release-safe
<andrewrk> oh no!! it's the std.mem.copy
clktmr has joined #zig
<andrewrk> frmdstryr, in your experiment, try removing all the std.mem.copy and replace with @memcpy
<Sahnvour_> andrewrk: is @memcpy based on a llvm intrinsic ?
<andrewrk> yes
<andrewrk> I wonder if this is us hitting https://github.com/ziglang/zig/issues/561
return0e_ has joined #zig
return0e_ has quit [Client Quit]
ur5us_ has joined #zig
ur5us has quit [Ping timeout: 245 seconds]
<dimenus> is this idiomatic zig or abuse of var? https://bpaste.net/show/T2AO2
<andrewrk> hmm nvm about @memcpy. everything is fine: https://godbolt.org/z/XpA-g-
<andrewrk> dimenus, personally I would accept the element type as a parameter. have a look at std/mem.zig for examples
<dimenus> i had it that way at first and changed it just to test :D
<dimenus> what do we really need var for?
<andrewrk> std.fmt.format
<andrewrk> the "context" variable when spawning a therad
ltriant has joined #zig
<dimenus> yeah, the callsite is still super simple `try ctx.createBufferFromSlice(.Vertex, f32, vertices);`
<andrewrk> and then you can delete all your meta code
<dimenus> a bit more typing in exchange for less complexity :P
<andrewrk> that's a tradeoff zig is generally happy to make
<Sahnvour_> good to see std.mem.copy can be easily optimized too, phew
<Sahnvour_> do we have access to optimization reports using llvm as a lib ? https://clang.llvm.org/docs/UsersManual.html#options-to-emit-optimization-reports
FireFox317 has quit [Ping timeout: 250 seconds]
return0e has quit [Ping timeout: 250 seconds]
return0e has joined #zig
<andrewrk> Sahnvour_, I haven't played with that yet
ur5us_ has quit [Read error: Connection reset by peer]
ur5us_ has joined #zig
<fengb> Hey, who runs the unofficial zig store?
<andrewrk> wilsonk,
<fengb> andrewrk: wrt llvm snippet, did it unroll the stream and buffer into a constant?
<andrewrk> yes
mforney has quit [Quit: quit]
mforney has joined #zig
vexu has joined #zig
<pixelherodev> andrewrk, what commit / PR am I looking at?
ur5us__ has joined #zig
<andrewrk> 10e172b1d77619469653b0521d8f65604fa549c7
<andrewrk> pixelherodev, looking at Indomitable, I think it does not affect you, since your entry point is `start`
<andrewrk> so, nothign to see here
ur5us_ has quit [Ping timeout: 265 seconds]
<pixelherodev> Looking at that commit I don't think it should affect that regardless
Akuli has quit [Quit: Leaving]
<pixelherodev> Either way, that _start is only exported if root file doesn't have _start
<pixelherodev> Now, it's not exported regardless
<pixelherodev> The practical difference to me is that there isn't an unused function _start being optimized out
<andrewrk> `export` guarantees that it is considered "used"
<pixelherodev> Ah right - either way it doesn't matter
<pixelherodev> It wasn't being used, so its presence isn't a concern
<pixelherodev> If I rename to _start, nothing will happen (except that there will no longer be an entry pointer since my linker script expects `start`)
<daurnimator> stratact: are you frmdstryr?
<daurnimator> oh wait no. frmdstryr is frmdstryr
<daurnimator> frmdstryr: could you try with https://github.com/daurnimator/zig/tree/stream-mixin ?
<frmdstryr> yea give me a sec
<daurnimator> stratact: terminfo is pretty simple.... just have a go at porting that lua file?
dimenus has quit [Ping timeout: 265 seconds]
<frmdstryr> daurnimator: that changed the api? no member inStream
<frmdstryr> 913447424 bytes (913 MB, 871 MiB) copied, 9.6256 s, 94.9 MB/s
<frmdstryr> const in_stream = &std.io.BufferedInStream(File).init(conn.file);
<frmdstryr> I like that better than the other way
wootehfoot has quit [Read error: Connection reset by peer]
kapil_ has quit [Quit: Connection closed for inactivity]
<daurnimator> frmdstryr: suprising that its not as fast.... what does perf say? Could you do a flame graph?
qbradley has joined #zig
protty has joined #zig
<daurnimator> frmdstryr: oh also, you don't have to take the address of it
plumm has joined #zig
<daurnimator> not sure if that will make a difference
<plumm> andrewrk: is there any reason `fmt.ParseUnsinedError` is private? I wan't to merge error sets with it
clktmr has quit [Ping timeout: 240 seconds]
vexu has quit [Quit: WeeChat 2.6]
<andrewrk> plumm, it's public now
<andrewrk> thx
<fengb> Hmm, I think I'm starting to understand why int ranges are important
<lupine> bruteforcing day 4 was fast
traviss has joined #zig
<plumm> andrewrk: are compile errors the go-to debug tool? I wonder if instead of telling me the file & which errors I don't have merged into my set, could it just tell me which set I'm missing (if there is one); is that reasonable ?