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/
<frmdstryr> Can @setCold be made to work on if / switch branches?
<pixelherodev> I don't think so
<pixelherodev> I could be wrong, but I think @setCold(true) changes the used calling convention to coldcc
<pixelherodev> Which isn't something that can be done to branches without adding in a function call
<pixelherodev> Which has a greater cost than any gains would likely be anyways
<daurnimator> Does that mean we need a 'likely' builtin?
<mq32> daurnimator: i remember this topic i think
<pixelherodev> I don't think there's any practical way to do this anyways
<mq32> andrewrk said something about the "positive" branch is always preferred or something, i can't remember fully anymore, but there was something like that
<pixelherodev> There's no real optimization you can do as the compiler / assembler
<pixelherodev> That's why branch prediction exists
<daurnimator> pixelherodev: sure there is.
<pixelherodev> ... oh right yeah
<pixelherodev> It's been a long time since I've done any hand-written asm :P
<pixelherodev> Yeah, that seems to use a GNU extension
<Snektron> is likely/unlikely in assembly just swapping the branch cases?
<daurnimator> Snektron: its also a hint to the optimiser
darithorn has quit [Read error: Connection reset by peer]
<Snektron> yes, but i mean on an assembly level
<pixelherodev> That's the only thing I remember doing, but I never claimed to be a good asm optimizer :)
<daurnimator> Snektron: it may e.g. refactor the code so that the "likely" branch is assumed, and the "unlikely" branch is only branched on later and the work that the "likely" branch did is undone
<daurnimator> I recall there was lots of discussions around choices of instructions. particularly around when to prefer cmov
<mq32> pixelherodev: random thought on optimization
<mq32> but it's better to put the likely branch in the "jump not taken" part, so caches will not be violated as you continue with linear execution
<mq32> if you jump, you may instantly trigger a cache invalidation which should not happen with cache preheating from linear execution
dimenus has quit [Remote host closed the connection]
<fengb> LLVM also aggressively removes cmovs: https://reviews.llvm.org/D36858
<Cadey> how do i stringify an error?
<pixelherodev> `std.fmt.formatAlloc("{}", err)` I think?
<pixelherodev> Well
<pixelherodev> `std.fmt.formatAlloc(allocator, "{}", err)`?
<daurnimator> pixelherodev: no more varargs
<Cadey> i'll try that :+1:
<daurnimator> .{ err }
<Cadey> daurnimator: i'm using zig 0.5.0 atm
<daurnimator> In any case, are you looking for @errorName
<pixelherodev> daurnimator, ah right :P
* pixelherodev facepalms
<pixelherodev> Of course there's a built in for it :P
<Cadey> is there such a thing as an assert that works in release mode?
<daurnimator> Cadey: if (!x) @panic(...)
<Cadey> fair neough
<Cadey> enough*
lunamn has joined #zig
<Cadey> how do you use a fixed length array as a slice?
<Cadey> ah @bytesToSlice
hyu has joined #zig
<Cadey> nope
<pixelherodev> Cadey, have you tried `array[0..]`/
<pixelherodev> ?
<pixelherodev> You can take a slice of an array
<daurnimator> Cadey: &
ur5us has quit [Ping timeout: 245 seconds]
<daurnimator> IIRC taking the address of an array returns a slice.
<daurnimator> otherwise yeah, [0..]
<Cadey> yep that works too
<Cadey> thanks for the help, kinda rusty on zig lol
<daurnimator> <insert joke about Rust (the language)>
frmdstryr has quit [Remote host closed the connection]
frmdstryr has joined #zig
<Cadey> i love how small the compiler output is though
<Cadey> i just got a case where a binary was smaller than its source code
<Cadey> (webassembly)
hyu has quit [Quit: Leaving]
hyu has joined #zig
ur5us has joined #zig
deesix has quit [Ping timeout: 276 seconds]
deesix has joined #zig
hyu has quit [Quit: Leaving]
hyu has joined #zig
waleee-cl has quit [Quit: Connection closed for inactivity]
hyu has quit [Ping timeout: 252 seconds]
<stratact> <daurnimator> <insert joke about Rust (the language)>, "Rust programmer: Hey I thought a made a copy, where is the original? Compiler: Original? What are you talking about? :P"
merlyndmg has joined #zig
<daurnimator> stratact: the pun should be related to Cadey's "rusty on zig""
<Cadey> but seriously
<Cadey> holy crap zig uses almost no memory in webassembly
<Cadey> my cat clone uses 2 pages (128k), but that seems to be the minimum amount
<daurnimator> Cadey: time to figure out why its not smaller
<Cadey> ikr
<Cadey> i'm gonna go ramdiving
<Cadey> i may be able to cut it down to 1 page
<daurnimator> Cadey: try bloaty?
<daurnimator> WebAssembly is marked experimental. I have no idea if it works...
<andrewrk> Cadey, 0.5.0 has a really primitive allocator for wasm. It does not have the ability to free pages. fengb recently improved it, and it adds about 1K to the binary size
<Cadey> daurnimator: i'm not talking binary bloat
<Cadey> i'm talking runtime bloat
<andrewrk> a "cat" program shouldn't need to use heap allocation though, so you shouldn't have to pay that cost
<Cadey> right now it uses 2 pages of webassembly ram, however it seems to only do stuff in the first page of ram
<daurnimator> Cadey: oh. you shouldn't have any runtime allocations at all for a program like yours
<Cadey> yeah
<daurnimator> andrewrk: you beat me to it >.<
adamkowalski has joined #zig
<Cadey> that's why it's like 652 bytes of wasm binary lol
<Cadey> it looks like if i had a buffer of exactly 928 bytes, i could fit it all within one page of ram
<Cadey> let's do some science
<fengb> For some reason, LLVM doesn't strip out runtime buffers from the binary
<fengb> Running wasm-opt will fix that
<daurnimator> Cadey: that's not unreachable (short writes are possible)
<daurnimator> Cadey: also consider `fifo` instead; its essentially *built* for your usecase
<Cadey> awww, it looks like `(global (;0;) (mut i32) (i32.const 66656))` is preventing it from working in one page
<daurnimator> Cadey: but there's no allocations at all in your program.... are there some at startup for bss or something?
<fengb> That's the stack size
<Cadey> i think
<Cadey> let me go do some more looking in the wasm
<fengb> How do I get a length of a sentinel string?
<daurnimator> fengb: ah right. is that a constant size or derived from the entry point?
<daurnimator> fengb: std.mem.len?
<daurnimator> fengb: see also std.mem.toSlice (and toSliceConst)
<fengb> Ah thanks
<Cadey> daurnimator: nah i'm just yeeting a buffer from the stack: https://github.com/Xe/olin/blob/master/zig/src/cat.zig#L20
<fengb> LLVM pegs the wasm stack size at around 66K. I'm not sure why. It's not from any sane heuristic as far as I can tell: https://github.com/ziglang/zig/issues/3735
<daurnimator> Cadey: yes I know. use `std.fifo.LinearFifo(u8, .{ .Static = 2048 });` instead.
<andrewrk> daurnimator, why?
<daurnimator> andrewrk: it allows you to easily do a partial read after a partial write.
<andrewrk> ah
<andrewrk> we still have an issue with std.os.write not exposing partial writes
<andrewrk> Cadey, you might consider making a zig olin package: https://github.com/ziglang/zig/issues/3784
<andrewrk> this makes it so that the zig std lib can work, and application writes just have to put `pub const os = @import("cadey's olin package");` in their root source file
<Cadey> oh sweet
<andrewrk> then a cross platform cat app will work in olin, with that one line
<andrewrk> *application writers
<pixelherodev> olin?
<Cadey> pixelherodev: it's a part of my crazy webassembly functions as a service pipedream
<andrewrk> yeah Cadey you can look at pixelherodev's project for an example
adamkowalski has quit [Quit: Lost terminal]
<Cadey> for a live demo with that cat program: curl -X POST http://wasmcloud.kahless.cetacean.club:3002/invoke/sync'?name=eight-of-pentacles-17326' --data "hello world"
<fengb> Should we standardize an OS abstraction layer?
<fengb> A lot of these custom wasi functions are vaguely posix but not quite, and it feels bad that I'm sprinkling them all over os.zig
<Cadey> fengb: AFAIK that's what https://github.com/ziglang/zig/issues/3784 is
<fengb> Yes but I mean better documented and possibly split out. Right now I'm basically playing whackamole with compile errors
<Cadey> i'm also gonna be bringing wasi to olin at some point, i'm just unhappy with how limited wasi is
<Cadey> andrewrk: i might need to override the `_start` logic in the olin stuff, is it possible to do that from a bring-your-own-os context?
<andrewrk> fengb, I think the phase we're at now is exploration, and when we want to stabilize the std lib then it'll be time to standardize
<andrewrk> not sure what you mean about sprinkling wasi fns in os.zig, that file is pretty well matched to POSIX
<andrewrk> I'm guessing you have an upcoming PR?
<fengb> I mean every file now has a wasi special thing that looks almost posix like but not quite
<fengb> function*
<andrewrk> that makes sense- that's the job of os.zig is to make something that is almost posix, actually fit the posix abstraction layer
<daurnimator> Cadey: `n < buflen` -> partial reads don't mean EOF.
<fengb> Yeah, I've ended up copying over the error code mapping because I can't really reuse the existing stuff
<Cadey> daurnimator: they do in my unfortunate architectural mistakes :(
<daurnimator> andrewrk: then shouldn't we call it std.posix?
<fengb> It just looks gross and crosscuts a bunch of things >_>
<andrewrk> daurnimator, possibly
<daurnimator> or posixy? :P
<fengb> Didn't someone suggest pozig?
<daurnimator> yeah I recall something like that
<mikdusan> pozix works :)
<andrewrk> Cadey, re: entry point - that's not hooked up currently, but would be happy to add logic to https://github.com/ziglang/zig/blob/c3d8b1ffebb94d180c382bd74128d17dc21c1392/lib/std/special/start.zig#L21-L47 to support the "os package" having an entry point
<Cadey> interesting
<Cadey> i'm gonna go update my zig compiler to git head and play around with stuff
<Cadey> will need to update for the varargs -> tuples change
<Cadey> kinda wish there was `zig fix`, but that's a pipedream atm lol
<andrewrk> there have been a lot of breaking changes lately, happy to help if you run into something
<daurnimator> Cadey: zig fmt does that... but we haven't hooked it up for all changes
<Cadey> :+1:
<Cadey> i'll poke in here if i run into anything
<andrewrk> also I'm guessing you will probably be pleased with the new anonymous list and anonymous struct syntax
darithorn has joined #zig
<Cadey> it looks like the `len` member of http.Headers is gone
<Cadey> i think i can hack around it though
<daurnimator> hmm?
<andrewrk> you mean count() ? `toSlice().len`
<daurnimator> There never was one. but we should add a headers.count()
frmdstryr has quit [Remote host closed the connection]
<daurnimator> speaking of, I have a few commits pending for http.headers: https://github.com/daurnimator/zig/commits/h1/lib/std/http/headers.zig
<Cadey> oh wait
<Cadey> never mind
<Cadey> i misread a compiler error
<Cadey> it was a varargs -> tuple change
<Cadey> [master 4675670] zig: update to git master
<Cadey> 7 files changed, 14 insertions(+), 14 deletions(-)
<Cadey> only 14 changes needed
<daurnimator> andrewrk: to save me from doing a PR, could you cherry pick https://github.com/daurnimator/zig/commit/2545375e69459456bab4220608d0bc628ab18c57 into master?
<daurnimator> `git remote add daurnimator https://github.com/daurnimator/zig; git fetch daurnimator; git cherry-pick 2545375e69459456bab4220608d0bc628ab18c57`
<Cadey> or
<pixelherodev> Is valgrind supposed to work?
adamkowalski has joined #zig
<daurnimator> yes
<Cadey> andrewrk: is it normal for the zig low level warn support to assume that stdout is the same file descriptor?
<pixelherodev> So, hypothetically, if it shows heap allocated: 0, that's a mistake?
<pixelherodev> Out of date valgrind or something?
<daurnimator> Cadey: no
<adamkowalski> Can somebody help me figure out why my test is failing? I am trying to wrap an allocator with an arena inside of a struct rather then in the test block and this leads to the failure. Here is the code befire: https://pastebin.com/bTY3upgn and after: https://pastebin.com/Z3598Z2d
<daurnimator> pixelherodev: are you sure you allocated on the heap? :)
<adamkowalski> The test is on line 46
<Cadey> ah i see
<adamkowalski> and 55 respectively
<pixelherodev> daurnimator, I tried with both std.heap.page_allocator and std.heap.c_allocator
<daurnimator> pixelherodev: got a runnable snippet ?
<adamkowalski> andrewrk: I tried following the pattern I saw in the standard lib, where the struct stores the arena, and then every other field that needs to allocate starts as undefined. Is there a way to avoid that?
<pixelherodev> ... well... no?
<pixelherodev> daurnimator, I was trying to measure RAM usage of my LLVM parser
<daurnimator> adamkowalski: fails with what?
<adamkowalski> Test [1/2] test "constant"...
<adamkowalski> Tests failed. Use the following command to reproduce the failure:
<adamkowalski> /Users/adamkowalski/dev/compute_graph/zig-cache/o/Uq6Y9u9qiGiWmQpuKQs_i4S59Pnb0heE9yT-jS1Uo24oAInUwGAQ7odlrulmRgP-/test
<adamkowalski> I ran the command it shows and I get
<adamkowalski> Test [1/2] test "constant"...fish: '/Users/adamkowalski/dev/compute…' terminated by signal SIGSEGV (Address boundary error)
<daurnimator> adamkowalski: run under gdb and get a backtrace?
<adamkowalski> Alright i'll try that. I just think it's strange because the only change I made was where I wrap the allocator with the arena.
<daurnimator> adamkowalski: I'm just telling you what I'd do to debug the issue
<adamkowalski> thanks i'll do that!
<Cadey> how do i convert a null terminated array to a slice?
<Cadey> oh
<Cadey> they still have a .len member
<daurnimator> Cadey: mem.toSlice ?
<adamkowalski> * thread #1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=EXC_I386_GPFLT) * frame #0: 0x000000010001f497 test`std.heap.ArenaAllocator.alloc(allocator=0x00007ffeefbfeeb0, n=64, alignment=8) at heap.zig:490:42
<adamkowalski> daurnimator: I get a bad access when allocating, which doens't make senes
<adamkowalski> If I just pass the allocator directly to ArrayList rather then wrapping in an arena then doing &arena.allocator I can make it compile and run
<daurnimator> adamkowalski: `graph.constants = std.ArrayList(Constant(T)).init(&graph.arena.allocator);` that might be pointing to the arena on the stack
<mikdusan> yup
<adamkowalski> Ah, I thought it would be named return value optimization
<adamkowalski> Wouldn't it allocate at the callers memory
merlyndmg has quit [Ping timeout: 260 seconds]
<adamkowalski> daurnimator: so I have to allocate on the heap?
<adamkowalski> or pass in a pointer to the graph which the caller allocated on the stack and then set that?
<daurnimator> adamkowalski: sounds like you have a great example of why we need @resultLocation
<daurnimator> I recall there was an open proposal but I can't find it
<adamkowalski> What would you recommend for now?
<mikdusan> adamkowalski: you could change `pub fn init()` to require `init(self: @This(), ...)` and at callsite and at caller, do `var graph: Graph(f64) = undefined; graph.init(allocator);`
<adamkowalski> Is the way I had things originaly idiomatic?
<adamkowalski> The only issue I had with how I did things in the first version is that it assumed the allocator passed in was an arena because I want the entire graph to have the same lifetime
<adamkowalski> mikdusan: yeah I might do that, thanks! I prefer to avoid undefined if possible, but I supposed it's the most reasonable option here
<daurnimator> adamkowalski: yes you had idiomatic code and it should work (maybe with a @resultLocation() added) or error (which would be the `fixed`/`nocopy` proposal).
<mikdusan> adamkowalski: i've used that pattern to allow for both stack/heap choice for caller
<daurnimator> adamkowalski: mikdusan has give you a good workaround there: you should make a note in #2765 about your type of usecase
<adamkowalski> thanks! I'll use mikdusan's solution for now. daurnimator result location should give us the same benefit of being agnostic about stack/heap right. Since it's "return by value" so the caller decides where it is stored
<daurnimator> adamkowalski: it would let you do: `graph.constants = std.ArrayList(Constant(T)).init(&@resultLocation().arena.allocator);`
<Cadey> what is the stdlib zig way to grab data from stdin?
<daurnimator> what sort of data?
<Cadey> yes
<Cadey> bytes
<daurnimator> `const stream = &io.getStdin().inStream().stream; n = try stream.read(....)`
<adamkowalski> daurnimator: I think named return value optimization would be even cleaner. Since we already have a pattern wher init usually returns the struct
<adamkowalski> why is that different then saying if I have a variable which I later return, just store that at the callers memory instead
<adamkowalski> mikdusan: I tried your solution and it now compiles and runs just fine! Thanks. I guess my C++ background is failing me and I need to be more C like haha
<Cadey> andrewrk: i think the varargs patch broke the sample app :D
<Cadey> std.debug.warn("All your base are belong to us.\n"); no longer compiles
<pixelherodev> Almost got the test program emitting valid assembly for my LLVM backend! :D
<pixelherodev> Register allocation is good, basically just need to implement function calls (and register push / pops for them)
<Cadey> huh
<Cadey> it does look like the std.debug.warn code relies on a known file descriptor for stderr
<Cadey> unless i am doing this very wrong
<Cadey> which i might be
<Cadey> i am trying to do this:
<Cadey> pub var STDERR_FILENO: fd_t = resource.io_get_stderr();
<Cadey> (in the os definition)
<pixelherodev> It does require a FD, but you have to return it from os.open IIRC
<Cadey> /home/cadey/prefix/zig/lib/zig/std/io.zig:48:30: note: referenced here
<Cadey> return File.openHandle(os.STDERR_FILENO);
<Cadey> the compile error for that is "unable to evaluate constant expression"
<Cadey> is there a way to defer that expression evaluation to runtime?
muffindrake has quit [Ping timeout: 252 seconds]
<pixelherodev> What did you define fd_t as?
<Cadey> i32
<Cadey> which is also the return type of resource.io_get_stderr()
<pixelherodev> Right
<Cadey> its actual definition is `pub extern fn io_get_stderr() i32;` (because it's imported from the webassembly environment)
<Cadey> or is the fd_t distinct from i32?
<daurnimator> Cadey: have a look at the windows path
muffindrake has joined #zig
<daurnimator> it grabs it from the PEB
<Cadey> yeah, i think we might need to add a openHandle patch from the root module
traviss has quit [Quit: Leaving]
<daurnimator> Cadey: huh? the `io.getStderr()` is what would call `io_get_stderr`
<Cadey> er yes sorry
<Cadey> i'm getting tired
<Cadey> either way
<Cadey> i'm not seeing how to make io.getStderr call io_get_stderr
<Cadey> daurnimator: what am i missing?
<daurnimator> Cadey: https://github.com/ziglang/zig/blob/c3d8b1ffebb94d180c382bd74128d17dc21c1392/lib/std/io.zig#L45 <-- you would need an additional case here for your OS.
<Cadey> Ah
<Cadey> okay
<Cadey> ill do that in the morning
stratact has quit [Quit: Konversation terminated!]
<Cadey> thanks again daurnimator, andrewrk
<pixelherodev> Got a simple infinite loop generating :D
<adamkowalski> Is this a reasonable way to approach having polymorphic nodes inside of a compute graph? https://github.com/adam-r-kowalski/compute_graph/blob/master/src/main.zig
lunamn has quit [Ping timeout: 276 seconds]
lunamn has joined #zig
adamkowalski has quit [Ping timeout: 250 seconds]
marmotini_ has joined #zig
stratact has joined #zig
qbradley has quit [Remote host closed the connection]
darithorn has quit [Read error: Connection reset by peer]
<stratact> Hey folks, I have a philosophical question, why are allocated slices in the std library API hinted as Owned Slices?
sammich has quit [Read error: Connection reset by peer]
sammich has joined #zig
<daurnimator> 'hinted'?
<daurnimator> stratact: guessing at your question here: but the idea is that you *own* the returned slice, and are hence responsible for freeing it/cleaning up
ur5us has quit [Ping timeout: 245 seconds]
darithorn has joined #zig
<stratact> daurnimator: so just to understandd this correctly, in Zig you can't pass multiple copies of the allocated slice pointer around to other variables from the original pointer?
<pixelherodev> That's more of a standard library thing than a Zig thing
<pixelherodev> The values returned by some zag functions are *owned* by the caller
<pixelherodev> You can pass the pointer around as much as you want
<pixelherodev> But you're responsible to deallocate it
<pixelherodev> And once you do, every pointer to it is invalid
adamkowalski has joined #zig
marmotini_ has quit [Remote host closed the connection]
adamkowalski has quit [Ping timeout: 268 seconds]
<stratact> I see, so the Zig ownership model is programmer driven from the mind. Rust ownership model is driven by the compiler. That's the difference.
<stratact> I had a misconception, I thought ownership meant compiler driven only
<pixelherodev> It actually works! :D
<pixelherodev> Not just for an infinite loop
<pixelherodev> Wrote a simple entry point that utilizes inline asm to extract bootloader-provided pointers from registers
<pixelherodev> Added in a touch of optimization, and the generated code is now 100% identical to the handwritten version :D
<pixelherodev> (or at least it would be if I didn't deliberately change it to make it fit Zig more readily)
mahmudov has quit [Remote host closed the connection]
ltriant has quit [Read error: Connection reset by peer]
ltriant has joined #zig
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 250 seconds]
stratact has quit [Quit: Konversation terminated!]
ltriant has quit [Ping timeout: 276 seconds]
<fengb> #define O_CREAT (__WASI_OFLAGS_CREAT << 12)
<fengb> There's some weird bitshifting going on between the public definition and the mangled version
<fengb> The existing wasi defines O_CREATE = 1 which is __WASI_OFLAGS_CREAT
<bgiannan> stratact, there's a proposal for a notion of owned pointers in zig https://github.com/ziglang/zig/issues/3690
doublex_ has quit [Ping timeout: 276 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 240 seconds]
marmotini_ has joined #zig
<vegai> any thoughts on this worry on generics without RAII? https://lobste.rs/s/xhxcol/rust_is_fun#c_8aix5u
<vegai> I kinda feel that it's not a significantly worse problem than resource controlling usually is
<shakesoda> put a defer call for anything you need to clean up as per usual, and i'm not sure what generics have to do with it?
<shakesoda> certainly nothing you wouldn't usually expect and need to do for managing resources
<fengb> gingerBill (?) talks about how unknown lifetimes are a super rare problem
<fengb> So the easiest fix is: give the arraylist an arena
<fengb> It doesn't solve everything, but it simplifies a lot
<fengb> s/arraylist/container
<shakesoda> heh, latest nightly zig seems broken
<shakesoda> looks like an api changed and fmt wasn't updated too
<Snektron> yeah i've noticed it too
<Snektron> it segfaults in probe_stack.zig
<shakesoda> i'm getting build errors outright
<Snektron> oh, that not
<shakesoda> e.g. fmt.zig:97:13: error: type 'u8' does not support field access
<shakesoda> dunno what changed so i'm not sure what to change it to yet
<Snektron> are you on master?
<shakesoda> yeah, just grabbed the build a few minutes ago
<shakesoda> worst case i can use the one from the other day
<Snektron> i don't get it
<Snektron> how come i only get this now
<Snektron> oh, its an issue with my code
<Snektron> i probably allocated too much stack memory
<Snektron> yes
adamkowalski has joined #zig
<shakesoda> oh, zig isn't broken - the error message just sucked
<shakesoda> need to update anything that formats with .{args}
<shakesoda> this was just very much unclear
adamkowalski has quit [Ping timeout: 240 seconds]
_whitelogger has joined #zig
marmotini_ has quit [Remote host closed the connection]
ur5us has joined #zig
adamkowalski has joined #zig
doublex has joined #zig
ur5us has quit [Ping timeout: 245 seconds]
adamkowalski has quit [Ping timeout: 252 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 246 seconds]
MoGu has joined #zig
adamkowalski has joined #zig
MoGu has quit [Quit: MoGu]
Ichorio has joined #zig
MoGu has joined #zig
MoGu is now known as mogu
adamkowalski has quit [Ping timeout: 276 seconds]
mogu has quit [Remote host closed the connection]
mogu has joined #zig
<mq32> hey
<mq32> is peer type resolution for anonymous struct fixed for optionals on current master?
<mq32> i have a fn(val: ?Struct) and want to call that with
<mq32> fn(.{ … })
mogu has quit [Quit: Leaving]
darithorn has quit [Quit: Leaving]
mogu has joined #zig
lunamn has quit [Quit: leaving]
<Snektron> No
<mq32> okay :)
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 250 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 245 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 265 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 252 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 252 seconds]
Ichorio has quit [Ping timeout: 245 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 268 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 240 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 265 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 250 seconds]
adamkowalski has joined #zig
<daurnimator> andrewrk: https://opensource.googleblog.com/2019/12/announcing-google-summer-of-code-2020.html I want us to apply for gsoc this year
<daurnimator> I've already mentioned it to steph
marmotini_ has joined #zig
adamkowalski has quit [Ping timeout: 265 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 265 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 250 seconds]
marmotini_ has quit [Remote host closed the connection]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 245 seconds]
adamkowalski has joined #zig
adamkowalski has quit [Ping timeout: 276 seconds]
waleee-cl has joined #zig
frmdstryr has joined #zig
dimenus has joined #zig
dimenus has quit [Read error: Connection reset by peer]
<lupine> I was pointed at https://hexdocs.pm/zigler/Zigler.html today
<bgiannan> is .? equivalent to an unreachable?
<daurnimator> bgiannan: hmm? `x.?` is the same as: `if (x) |tmp| tmp else unreachable`
<bgiannan> rightm that's what i meant
<Cadey> andrewrk: daurnimator: i got it working!
<Cadey> $ cwa -main-func _start cat2.wasm
<Cadey> All your base are belong to us.
<mq32> cwa is a webassembly runner for the terminal?
<Cadey> for my olin environment, yes
<Cadey> but either way, it's more proof that the bring-your-own OS concept works
<mq32> olin?
<Cadey> https://github.com/Xe/olin it's kinda my playground for webassembly, it's used as a mediator between the outside world and a webassembly VM for a functions as a service project of mine
<mq32> hmm
<mq32> is there a library with C api out there to use web assembly in custom projects?
<mq32> would like to play around some day with that
<Cadey> it's kinda awkward to use, but https://github.com/wasmerio/wasmer-c-api
<mq32> have to take a look :)
<mq32> because i'd like to experiment using Wasm in a Zig based game project as a scripting API
<fengb> We’ve been talking about building a wasm interpreter in std
<mq32> :O
<mq32> so we can host wasm in wasm? :D
<Cadey> ...can we go deeper
<fengb> Existing WASI VMs aren’t very robust and Zig already has better cross platform support
<mq32> what is the difference between WASI and Wasm?
<Cadey> mq32: the difference between the linux syscall ABI and an amd64 CPU
traviss has joined #zig
<Cadey> how do i pass an arbitrary linker argument?
<bgiannan> What signature should have a custome `panic` function. https://ziglang.org/documentation/master/#panic talks about a std/special/panic.zig file but it does not seem to exist anymore
<daurnimator> `pub fn panic(msg: []const u8, error_return_trace: ?*builtin.StackTrace) noreturn {`
<mq32> Cadey: ah, so WASI is an interface to the outer world designed for wasm
<Cadey> mq32: yeah
<Cadey> it's an IO monad basically
<bgiannan> daurnimator, Cadey, thx
<mq32> Cadey: i've never understood the term "monad", it's explanations were always waay too theoretically for me
<Cadey> mq32: monads basically just order compuations so that things happen in a predictable order, this makes a lot more sense in the context of unordered environments like haskell
<daurnimator> mq32: imagine a functional language where everything is a pure function. input => output
<Cadey> without an IO monad the haskell compiler might do something odd like make a file write happen before its open
<daurnimator> mq32: now imagine how useless a language like that would be. how could you ever make a syscall when function input lead to function output and no side effects
<daurnimator> mq32: so you introduce the monad as an extra input and output. `NEWWORLDSTATE, y = foo(OLDWORLDSTATE, x)`
<fengb> Eh wasm has imports/exports defined in the spec. WASI just standardizes a bunch
<Cadey> ^
<Cadey> my stuff would use wasi but my stuff predates wasi lol
<fengb> It’s vaguely posix so it’s somewhat familiar
<Cadey> i don't like how wasi programs can't open network sockets personally
<fengb> But it’s also not very stable and nobody supports it very well
<Cadey> it's probably great for supporting the past though
<Cadey> my stuff uses URIs as file paths
<Cadey> this lets you do crazy things like HTTP with "filesystem" calls
<fengb> That sounds pretty cool. I’ve wondered how far “everything is a file” could be taken
<Cadey> that's one of the core parts of my experiments :D
<mq32> fengb: Look at Plan-9 to see that answer
<Cadey> making it as easy to access remote files as if they were local
<Cadey> er s/files/resources
<mq32> IRC? Files
<Cadey> https://github.com/Xe/olin/blob/master/zig/src/httptest.zig <-- an example of how the HTTP interface works
<mq32> Mouse? File. Keyboard? File. Screen? File.
<mq32> :D
<mq32> also, Plan-9 is network-transparent. Screen? Remote File.
adamkowalski has joined #zig
* mq32 should really try to use Plan-9 on one of his machines...
<fengb> Yeah I've wanted to tinker with Plan 9 but never had a chance to
<Cadey> my ultimate goal is to make an OS where the only way to run programs is via webassembly
<fengb> o_O
<companion_cube> micro kernel, but to the max
<Cadey> the OS would seamlessly translate the webassembly modules to native code kinda like IBM i
<Cadey> and run it all in ring 0 like TempleOS
<fengb> The other day I was talking about having wasm as the only userland executable
<Cadey> i actually have it somewhat working already with a kinda terrible wasm interpreter: https://christine.website/static/blog/xeos_h.png
<Cadey> (though this is in rust because the phil opperman tutorials are nice)
<mq32> Cadey: yeah that's a quite appealing idea
<mq32> also you never need a cross-compiler for that OS anymore
<mq32> everything is binary compatible
<Cadey> now you get it
<Cadey> it makes the underlying metal _irrelevant_
<Cadey> (to a point lol)
<Cadey> i've done some testing with my prototype as it is
<Cadey> and since i wrote the environment in pure go, it cross compiles to things like big-endian PPC64 and runs programs just fine
<Cadey> mind you webassembly is little-endian
<fengb> I'm also curious how hard it'd be to make a wasm processor
<mq32> so: zig/std.wasm
<mq32> :D
<Cadey> oh
<Cadey> if i had my way
<Cadey> it'd be `zig.wasm`
<Cadey> i'm working on a crazy idea a friend had to "bake" a filesystem into a webassembly module
<fengb> Once stage 2 is ready, it'll be zig.wasm :P
<daurnimator> wasm.zig
<mq32> @import("std").wasm was my intention
<Cadey> so you could distribute zig.wasm as a static webassembly binary and then instantly have a full compiler on any other machine
<Cadey> but that's a hell of a pipedream lol
<fengb> Cadey: that's on the pipeline for stage 2
<fengb> Self-hosting in the browser
<fengb> Fully cross-compiled self-hosting
<mq32> fengb: you are experienced with web, is it possible to generate a file with JS and push/download that to the user?
<Cadey> yes
<Cadey> <a href="data:application/octet-stream;charset=utf-16le;base64,//5mAG8AbwAgAGIAYQByAAoA">text file</a>
<mq32> ah okay
<Cadey> you might wanna set the download=foo.txt attribute too
<mq32> Cadey: if that pull request is your code: if (bits.STDIN_FILENO == undefined) <= this has no semantics
<Cadey> mq32: yeah i fixed it locally
<Cadey> updated the comment
traviss has quit [Remote host closed the connection]
<Cadey> i really do like how zig structs don't have private members
<fengb> `char sa_data[0];` is this a 0 dimension C array?
<mq32> fengb: It's a weird thing in C :D
<mq32> it is a common use of reading out-of-bounds
<daurnimator> its invalid C :)
<fengb> Oh yeah I do that in Zig too
<daurnimator> has to be at least [1] to be valid
Ichorio has joined #zig
Ichorio has quit [Ping timeout: 250 seconds]
msiism has joined #zig
Ichorio has joined #zig
<msiism> What, in rather general terms, is the development status of Zig? Is it good to go for a random “hobbyist” who'd like to go with a “better C”? Are there bindings for any GUI libraries yet?
belgin has joined #zig
<mq32> > What, in rather general terms, is the development status of Zig?
<mq32> it's quite usable. i've run into some problems with my projects, but i'm doing "special" stuff (embedded or low level)
<mq32> > Is it good to go for a random “hobbyist” who'd like to go with a “better C”?
<mq32> it's definitly worth a look, i really enjoy programming with zig and haven't started a hobby project that is not zig since i made my first project with it :D
<mq32> > Are there bindings for any GUI libraries yet?
<mq32> i'm not aware of that, but you can always use C headers that aren't macro-heavy directly from the langauge
<msiism> Thanks. That sounds quite good. I don't depend on GUI bindings at the moment and I guess they will pop up eventually.
<mq32> if you want to do game stuff, there's a pretty unfinished SDL2 binding to a more zig-style API by me :D
<mq32> </advertising>
<msiism> :) I'm not into gaming, sorry. The project I want to start next is creating a browser-independent bookmark manager.
<pixelherodev> Huh - that's an interesting idea
<msiism> For that purpose, it would be interesting to know if Zig has any libraries for processing structured data, like, e.g., JSON or TOML. But I'm not even sure that's really needed.
<mq32> there's a json parser in the stdlib
<msiism> Nice.
<companion_cube> next stop: CBOR
<companion_cube> the json for system programming :p
<gonz_> Is ityonemo/dnautics on IRC with another name? He wrote this neat layer for creating BEAM NIFs in zig.
<msiism> companion_cube: I see. Well, I think I like TOML more than JSON because it's more like INI on steroids. And I certainly like INI.
<companion_cube> I came to dislike TOML, I find it very unintuitive. Best human readable format, imho, is S-expressions
adamkowalski has quit [Read error: Connection reset by peer]
adamkowalski has joined #zig
<msiism> Hm... interesting. I'll have a look at that.
<belgin> ((((((s))))e))))x))))p)))s))))))
<companion_cube> belgin: same goes for json
<msiism> By the way, the webdesign of ziglang.org is really neat.
<companion_cube> {{[{'{]]}}}}
<mq32> companion_cube: i think you confused "human" and "computer" :D
<gonz_> S-expressions are much more readable than JSON
<gonz_> (or really any alternative)
<gonz_> Also trivially parsable
<companion_cube> mq32: I'm serious, it's simply more readable and editable than json
<companion_cube> you can have comments, you don't need quotes in random places
Ichorio has quit [Ping timeout: 245 seconds]
<mq32> i don't know. i hate pretty much dislike everything where i have to keep track of counters to know where i am located
<msiism> Well, in the end, a bookmark is basically just a URL with a human-readable name attached to it (and 2 or 3 other things). So, you could also just simply throw them all in a single text file with a blank line delimiting each bookmark block. Presenting them in a tree strcuture, for example, is an entirely different thing, so that file wouldn't need to refelct any of that.
<mq32> both json and sexprs have this counting thing
<mq32> xml isn't that bad because you can visually scan for end-tags
<companion_cube> indentation is enough
<companion_cube> but then, doesn't Zig also have tons of counting?
<scientes> you can just have a reader that properly formats it
<scientes> companion_cube, yes it does, that is why you use indentation
<companion_cube> same goes for S-exprs, really
<companion_cube> and it's easy since the format is so easy to parse
* scientes has read lisp and it is nutso
dddddd has joined #zig
<belgin> if you need something more complicated than key/value pairs in a text file, you should probably go with s-exps
<scientes> or JSON
<scientes> JSON isn't that bad
<mq32> companion_cube: that's why i try to reduce my scope depth, but i fail more often to do so in zig
<scientes> well, are numbers in JSON limited to 64-bit floats?
<gonz_> I think you'd have to come up with a better qualification than "has read Lisp" for your non-argument to make sense.
<scientes> if you look at real lisp code it is pretty nutsy
<scientes> gonz_, hell, whatever works
<companion_cube> json is full of quotes and doesn't have comments
<companion_cube> that's terrible for config
<scientes> most parsers allow comments
<companion_cube> but then it's not json ;)
<companion_cube> (the parsers I know don't allow comments; or for what it's worth, having several objects in one file)
<gonz_> I've written real Lisp code for years in several Lisps, saying it is "pretty nutsy" holds zero weight.
<companion_cube> S-expressions for config doesn't mean it's going to be as deep and complex as lisp
<scientes> why not just write a DSL
<scientes> they are not hard
<companion_cube> it's like comparing a bit of json to a big js codebase
<scientes> the problem is that languages are not very good at writing parsers
<mq32> why not just plain, simple key-value pairs with "key: value"? ^^
<mq32> it's even possible to sed such files
<scientes> mq32, that goes a long ways
<companion_cube> mq32: what if you need more?
<tgschultz> If you need something mroe complicated than k/v pairs in a text file you may be suffering from second-system effect.
<belgin> yeah, that too
<tgschultz> In a few python things I've written, I've just gone ahead and used python as the config file too.
<companion_cube> that sounds much worse
<mq32> Lua is also a quite nice config file language :D
<mq32> <companion_cube> mq32: what if you need more?
<mq32> use more files!
<companion_cube> so parsing sexprs is overkill, but using lua/python is not? wow :D
<belgin> you can even have tree structure in a list of k/v pairs
<mq32> companion_cube: lua has actually started as a config file language
<belgin> root/node1/node2: value
<belgin> you'd have to type a lot, but whatever
<mq32> belgin: yep
<belgin> get a better keyboard :D
<belgin> (if you don't like typing)
<companion_cube> belgin: that's what toml does, and I hate it
<companion_cube> anyway, I'll keep my tiny S-expr parser, thank you very much :p
<mq32> btw, i'm writign a config file and i now have the best config entry ever:
<mq32> hide-hidden: true
<belgin> does andrew want to make an alternative to llvm for zig?
<belgin> and by alternative i mean, no intermediate language?
<mq32> belgin: the long term plan is to remove llvm as a dependency
<belgin> cool
<pixelherodev> There's already a Zig IR, correct?
<pixelherodev> How hard would it be to add a `-emit zig-ir` option to the compiler?
<belgin> there is?
<companion_cube> (so in OCaml, we've gone from a ton of build systems using ocaml itself as a config language, to one build system with well restricted S-exprs for describing tasks, and it's amazing)
<belgin> an intermediate-intermediate language?
* pixelherodev shrugs
<pixelherodev> Well, there's ` --verbose-ir enable compiler debug output for Zig IR` so probably
<belgin> companion_cube, cool
<belgin> it's always nice to configure your build instructions in the same language as the rest of your program
<companion_cube> (it allows the build system to be portable, instead of people using shell all the time, and to have better parallelism \o/)
<companion_cube> nah it's the opposite there
<companion_cube> and tbh I like it
<pixelherodev> Shell is portable!
<belgin> ocaml isn't a lisp?
<pixelherodev> Most people are just bad at writing portable shell code
<companion_cube> no, it's a ML
<belgin> oh right
<companion_cube> pixelherodev: how does shell work on a normal windows?
<tgschultz> If the program is already in python, and the configuration is complicated enough to need program-like capabilities, then I may as well also do the config in python.
<tgschultz> That's my reasoning.
<pixelherodev> Back in the dreadful age in which I ran Windows, usually from C:\bin\sh
<companion_cube> sure, but then your config becomes a mess
<companion_cube> last thing I used that did that was, I think, pelican
<tgschultz> Only if you insist on writing messy code
<companion_cube> some day my blog broke
belgin has quit [Remote host closed the connection]
<companion_cube> (the thing is, then your whole API can be part of the config, not a big fan of that)
<tgschultz> Eh. It's better than second system effect in my opinion.
<companion_cube> having a well delineated config language that is easy to write or read isn't "second system effect" imho
<fengb> pixelherodev: Zig IR is meant to be internal details and not relied upon
<tgschultz> well, my opinion differs.
<companion_cube> 🤷
<pixelherodev> fengb, ah
<pixelherodev> Yeah, that figures
<fengb> I'd guess this wouldn't be stable until after stage 2
<gonz_> Ah, config/build systems. The tabs/spaces of tools.
<mq32> let's just enforce indentation in the json config file by "\t \t"
<companion_cube> if the first entry is `"strict": true` then it's "\t \r\t" instead
<andrewrk> pixelherodev, there's --emit llvm-ir
<mq32> companion_cube: the key must be separated from the value with a vertical tab
<fengb> The only white space allowed should be zero width spaces
<mq32> (obviously)
<mq32> Boolean("false")
<mq32> i love js :D
<companion_cube> the separator is \0
<companion_cube> key\0value
<mq32> and value is delimited by another \0?
<SyrupThinker> A leading comma is allowed, but not a trailing one
<companion_cube> mq32: no, by \n\r
<fengb> “\t\r\n” == false
<mq32> are we going to create malboge.cfg?
<mq32> companion_cube: sounds reasonable, that sequence is unlikely
<companion_cube> ✔
<andrewrk> IMO the most important requirement of a build system is that it works on everybody's system
<companion_cube> (yeah, that was the point there: avoid invoking unix commands as much as possible)
shakesoda has quit []
shakesoda has joined #zig
traviss has joined #zig
adamkowalski has quit [Quit: Lost terminal]
adamkowalski has joined #zig
dddddd has quit [Ping timeout: 240 seconds]
deesix has quit [Ping timeout: 252 seconds]
deesix has joined #zig
lunamn has joined #zig
<SyrupThinker> I'm currently doing #3864, "does invalid float literal. Add a `0` before the decimal point" sound good, or should I just use the invalid char error?
dddddd has joined #zig
<adamkowalski> I prefer the first, if we can make the errors more explicit it might be more helpful
<adamkowalski> Is there any way to have a tool which acts as a file watcher. Then whenever a file is changed, you figure out what tests would be impacted by those changes, and auto run them?
<Cadey> andrewrk: i tried making a patch for the "bring your own OS package" feature to customize the entrypoint, it seems that lld _insists_ on the entrypoint being _start for some reason. I added if (@hasDecl(root, "os") and @hasDecl(root.os, "entrypoint")) @export(root.os.entrypoint, wasm_freestanding_start, .Strong); to the is_wasm branch of zig/lib/std/special/start.zig around line 44, it seems that the
<Cadey> entrypoint constant i exported in my OS module (cwa_main) is being completely ignored by lld _unless_ i build the file as a shared library
wootehfoot has joined #zig
<andrewrk> Cadey, do you need to change the entry point from _start? I thought the point was just to run code before main() ?
<Cadey> andrewrk: i guess i can adapt my other code to compensate for the entrypoint being _start
<Cadey> i think i may have had a very fundamental misinterpretation of how processes work in C space
<Cadey> andrewrk: in C space, _start doesn't have a return value, does it?
<andrewrk> correct, it makes a syscall to exit
<Cadey> well
<Cadey> i need to add an exit syscall then lol
<andrewrk> otherwise the CPU will continue executing instructions after _start, which is probably going to trigger SIGILL
<Cadey> thanks again andrewrk
<andrewrk> "here, CPU try executing this random memory, you're gonna have a great time!"
<andrewrk> :)
<Cadey> andrewrk: where is getStdInHandle defined? I can't find it with grepping
<andrewrk> Cadey, Vexu is suggesting to add that function
<Cadey> ah okay
<Cadey> :+1:
<Cadey> oh i see now
<Cadey> will do
<andrewrk> hmm this might be the key to getting https://github.com/andrewrk/lua-in-the-browser working too
<andrewrk> as an alternative to emscripten, we could make the freestanding libc support os overrides as well. so you could provide e.g. printf as console.log
<Cadey> oh i typoed, crap
<Cadey> fixed
<fengb> I saw something about a WASI polyfill for browsers
msiism has left #zig [#zig]
<fengb> Should I just override the existing value? https://github.com/ziglang/zig/blob/master/lib/std/os/bits/wasi.zig#L187
mogu has quit [Ping timeout: 252 seconds]
lunamn_ has joined #zig
lunamn has quit [Ping timeout: 250 seconds]
<andrewrk> fengb, I don't understand, is our O_CREAT value incorrect for wasi?
<fengb> They define 2 of them, O_CREAT is the publicly exported one and __WASI_OFLAGS_CREAT, which matches the value that's currently in O_CREAT
adamkowalski has quit [Quit: Lost terminal]
<fengb> I don't know why there's a private version since its only usage is setting O_CREAT and a few redundant asserts
<fengb> Oh that's the value that gets sent to the syscall
ky0ko has joined #zig
darithorn has joined #zig
<fengb> So maybe I should rename the existing ones to OFLAGS_CREAT and redefine O_CREAT to match these headers? `OFLAGS_CREAT = 1; O_CREAT = OFLAGS_CREAT << 12;`
mahmudov has joined #zig
<andrewrk> I think __WASI_OFLAGS_CREAT should go into os/wasi.zig and O_CREAT in os/bits/wasi.zig should change to be the libc value
<andrewrk> os/bits/* tries to match the libc/posix layer
<fengb> Ah okay
<andrewrk> os/wasi.zig is wasi-specific stuff
<fengb> That works, thanks
<fengb> Sure, there aren't any constants in there currently so I wasn't sure
<andrewrk> what are you working on? sounds like you're doing something exciting
<fengb> Getting all the tests to compile in wasi
<fengb> So we can enable them in CI
<andrewrk> cool
<andrewrk> if you want to try to make incremental progress, feel free to disable a bunch of the tests for wasi (ideally with links to github issues), and that way we can have some coverage, and then work toward enabling more tests incrementally
<fengb> It's surprisingly not too bad. Although I might have spin out the last 10%
<fengb> Mostly using this as an excuse to learn more about wasi and syscalls :P
<andrewrk> out of curiosity, do you have a way to use a debugger when running wasi programs?
<andrewrk> with the ability to step, and inspect values and stuff
<andrewrk> I bet there's a way to do it with the browser's tools
<fengb> I've been using good old print debugging :P
<Cadey> AFAIK there's not really a good debugger for webassembly at all
<Cadey> i've been using printf debugging and ramdiving with xxd personally
<andrewrk> I bet it will happen soon though. which actually could be a pretty amazing way to debug logic
<andrewrk> even if your target isn't wasi, you could cross compile a unit test and use the browser's GUI for debugging
<andrewrk> that's gonna be a thing soon, I predict
<fengb> Browser debug isn't that great for wasm
<Cadey> a friend of mine in the go slack was working on some absolute insanity that involved writing every wasm instruction and its side effects to a postgres database
<fengb> I suppose it works with poking at raw memory, but it's really low level
<andrewrk> if people start using wasm more, browser debugging for wasm is going to be top tier
<andrewrk> it's inevitable
<fengb> I don't think there's real sourcemaps yet
* Cadey sunglasses
<Cadey> yes mister kelly
<Cadey> that worked better in my head
<andrewrk> lol
<andrewrk> but we need the ability to run wasm with file:/// !! I can't believe the people in charge fucked that up so hard
<fengb> Stacktraces aren't working for wasi yet so hunting down errors isn't really fun
<fengb> I should actually figure that piece out
<andrewrk> idk how debug info for wasm/wasi works
<Cadey> so a big part of the problem there fengb is that there's not a good story in wasm for getting the debuginfo from the binary
<Cadey> the webassembly environment i play with _does_ have stacktraces, but in the form of webassembly function numbers
<Cadey> which can drive you a bit mad
<Cadey> i should really add wasi support to olin >.>
<Snektron> I realized a while ago that theres a 32-bit version of web assembly
<Cadey> Snektron: that's the default one atm
<Cadey> however, it does have native 64 bit pointers
mforney has quit [Quit: quit]
<andrewrk> wasi barely has enough syscalls to do anything useful
<Cadey> er
mforney has joined #zig
<Cadey> 64 bit integers/floats
<Cadey> andrewrk: lol ikr
<Snektron> What is the point of having a language intended for sandboxing have a 32 and 64 bit version?
<andrewrk> Snektron, there's no 64 bit wasm yet
<Snektron> Oh
<Snektron> inb4 webapps larger than 4 GB
<Cadey> Snektron: i don't think that it's going to be a practical issue for a while
<fengb> We don't want to address 4 GB in the browser yet
<Snektron> Cadey, thats what they said about memory in the 90s
<andrewrk> it is kinda dumb that we need a compiler_rt function for 64 bit multiplication in wasm though
<Cadey> Snektron: yes, i'm aware of the irony
<Snektron> 640 kb is enough for everyone
<Cadey> actually
<Cadey> with zig and webassembly
<Cadey> 640k of ram (~10 pages) is probably enough for a lot of significant uses
<Snektron> andrewrk, can
<Snektron> can't a multiplication be emitted as a series of instructions instead of a call?
<andrewrk> shipping an extra ~50K of wasm just to implement 64 bit int multiplication, when the host CPU supports it natively
<Snektron> how is 64 bit multiply 50K
<andrewrk> Snektron, it can, but the compiler chooses to make some things calls, to avoid bloat
<andrewrk> idk I was just making that number up. I can measure it
<Snektron> i would expect such a multiply function to only be like 2 or 3 instructions at best
<Cadey> webassembly can be a cruel mistress
<fengb> Isn't it just applying FOIL?
<fengb> Remembering my long lost algebra 2
<andrewrk> what's the binary called to get wasm text from wasm binary?
<andrewrk> wasm equivalent of objdump -d
<Cadey> wasm2wat
<andrewrk> thx
<Cadey> np
<fengb> Squint a bit and pretend you're working in Lisp :P
<andrewrk> oh, wasm32 supports 64 bit multiplication
<andrewrk> OK
<Cadey> i64.mul i think
<andrewrk> I guess the only difference is the pointer size
<andrewrk> Snektron, ^
<companion_cube> so it's x32, really
<andrewrk> ah yeah nice analogy
<shakesoda> "webapps larger than 4gb" is a horrifying thing to read as soon as i get to the computer
<Snektron> ah yes, i just read it in the isa spec
<Cadey> lol i just realized
<andrewrk> ok but let's see how big 128 bit mul is then
<Cadey> the go limitation of array sizes being `int` is going to bite me if i try to use more than 2 GB of ram in my stuff
<Cadey> crap
<companion_cube> makes sense if all your apps are in the browser
<companion_cube> photoshop as a service, woo
<shakesoda> do not want
<Snektron> Cadey, i have an assignment on distributed sorting where i'm supposed to use MPI
<fengb> I think it'll have to exist if we want to compile LLVM in the browser
<Cadey> Snektron: MPI?
<Snektron> MPI can be used to send buffers between compute nodes
<andrewrk> not bad: https://clbin.com/7ZtPf yeah that looks like FOIL or something simple like that
<Snektron> except the size is an int of course
<Cadey> lol
<Snektron> A real pain
<andrewrk> a browser is just another OS layer, that evolved instead of being designed. one could imagine the future of browsers being a more intentionally designed second OS layer
<Cadey> actually, i don't think i will run into that issue
<andrewrk> better permission model that is more secure for users while allowing applications to do more powerful things
<Cadey> int is machine word in go
<Snektron> oh
<Snektron> I forgot how datatypes worked in go, its been a while
<Cadey> andrewrk: so basically we need the capability to guide the market to capabilities?
<andrewrk> IMO today's web should be a *third* OS layer, on top of this other one that I'm describing
<companion_cube> one could argue Windows also evolved, under the pressures of retrocompat
<Snektron> how come wasi i128 mul is so much code while x86 is https://godbolt.org/z/LLm3Gc
<Cadey> Snektron: RISC
<fengb> i128 doesn't exist natively in wasm
<andrewrk> Snektron, I think because wasi doesn't have 128 bit ints
<andrewrk> s/wasi/wasm/
<fengb> So it pretends to create one as 2x 64bits
<Snektron> i128 also doesn't exist on x86, yet it can be implemented using 64 bit ints as in the example i sent
<Cadey> huh
<Cadey> apparently C++'s wasm32 i28 multiplication is a bit more compact
<bgiannan> https://github.com/ziglang/zig/commit/c3d8b1ffebb94d180c382bd74128d17dc21c1392 ah great now i have like 200 loops to rewrite :)
<Snektron> Maybe it's the stack model that adds more bloat?
<Cadey> oh, i see
<Snektron> since a lot of the code is just swapping values around
<Cadey> it's the same output
<Cadey> the godbolt one just omits __multi3
<fengb> How does that x86 assembly work? I see nothing about 128 bits
<fengb> Oh wait that's just foil
<Cadey> i wonder how effective it would be to hand-translate the amd64 assembly to webassembly
<andrewrk> 256 bit multiplication: https://godbolt.org/z/Cz6ZCM
<andrewrk> forgot to put --release-fast on there
<andrewrk> that actuall doesn't look too bad
ur5us has joined #zig
<andrewrk> sorry bgiannan. for (list.toSlice()) |item| {}
<shakesoda> Snektron: i'm slightly surprised to see that i128 output is shorter on arm64 than x86_64
wootehfoot has quit [Read error: Connection reset by peer]
<fengb> In theory, we could add manual memory paging to wasm32 to break the 4GB barrier! 🙃
wootehfoot has joined #zig
<Cadey> fengb: hopefully we won't need to
<Cadey> interesting
<Cadey> it doesn't look like webassembly has unsigned integer support
<Cadey> i wonder if you can allocate past 2 GB of ram
<fengb> "Integers are not inherently signed or unsigned, their interpretation is determined by individual operations."
<Cadey> ah okay
wootehfoot has quit [Client Quit]
wootehfoot has joined #zig
<Snektron> shakesoda, arm has a special instruction for stuff like this
<Snektron> also, the destination of mul can be any register instead of just rax which also cleans up some things
FireFox317 has joined #zig
<FireFox317> andrewrk: I see you are working on the self-hosted-compiler again. Are you trying to get it to compile stuff again?
dimenus has joined #zig
<andrewrk> FireFox317, soon. I think I need to invest a little bit in std async io first
<andrewrk> I have an interesting change coming up soon
FireFox317 has quit [Ping timeout: 265 seconds]
<bgiannan> andrewrk, right, but i won't be able to search/replace since i use hashmaps iterators as well, so might take a while :)
dimenus has quit [Remote host closed the connection]
muffindrake has quit [Quit: muffindrake]
muffindrake has joined #zig
FireFox317 has joined #zig
ltriant has joined #zig
<frmdstryr> Does defer'ed code run when main is interrupted (SIGINT)?
<frmdstryr> I don't get why the streamserver seems to randomly error with address in use
<andrewrk> frmdstryr, no
<mq32> frmdstryr: no ,SIGINT is executed "out of band"
<andrewrk> address in use is a linux thing. it hangs on to addresses for something like 60 seconds by default
<andrewrk> I think if you clean up properly you can avoid this timeout being required
<andrewrk> there is also SOREUSEADDR which has its own problems
<frmdstryr> Can i set up a signal handler to call server.deinit() there?
<andrewrk> I mean, you *can*. I don't think that's how I would recommend solving it
<andrewrk> you'll also have this problem if your software crashes
<frmdstryr> well that i understand :)
<andrewrk> I think SO_REUSEADDR is probably appropriate while developing
<frmdstryr> but i'd like to be able to shutdown with sigint
<andrewrk> if you do this, probably the best way would be to have the sig int handler do something very minimal, such as set an atomic flag that your application will later check
<mq32> yeah, the atomic flag is probably the cleanest way
slice has joined #zig
<Cadey> andrewrk: which sha is the shasum in https://ziglang.org/download/index.json?
<mq32> Cadey: it's probably sha1
<mq32> as shasum (the command) does it by default
FireFox317 has quit [Ping timeout: 240 seconds]
<andrewrk> sha256
<Cadey> ah, cool
slice has quit [Quit: cya]
slice has joined #zig
<frmdstryr> What happens if I attempt to read past a slice's bounds?
<Snektron> depends on the compilation mode
<Snektron> debug/release-safe: panic, releas-fast: ub
wootehfoot has quit [Quit: Leaving]
<Cadey> frmdstryr: in all likelyhood, assume your program will crash
<fengb> Or worse, the slow drip of memory corruption
<Snektron> maybe it will just rm -rf --no-preserve-root /
<Snektron> while my friend was working with clang for his bachelors thesis, he made an "evil ub" mode
<Snektron> it would do stuff like that
<fengb> In my OS class, I'm pretty sure we had OOB access. It slowly corrupted the FAT12 system we worked on
<fengb> We convinced the TA to let us refresh the fs after every test case since we passed all the checks from a fresh start :P
<Cadey> is there a "noreturn" flag for zig functions?
<Cadey> ah, return type noreturn
lunamn_ has quit [Ping timeout: 252 seconds]
lunamn has joined #zig
msiism has joined #zig
<msiism> I'm reading Zig's docs and there's something I really can't wrap my head around (which happens quite often, actually): How can/Why do instructions like `break`, `continue`, `return` have a type?
<andrewrk> Cadey, thanks for the patch, merged :)
<Cadey> andrewrk: no problem, working on another one for overriding the exit() behavior
<andrewrk> Cadey, you can't provide os.exit?
<Cadey> andrewrk: you can with https://github.com/ziglang/zig/pull/3890
<andrewrk> Cadey, that one is already handled at the bottom with system.exit
<Cadey> ah
<andrewrk> this should work for nearly every function in that file
<Cadey> you can in fact do that
<Cadey> i'll close my PR
<andrewrk> yeah no worries, it's not super straightforward
<andrewrk> we don't have the package manager yet but once we do it'll be nice because you can provide an official olin package
<Cadey> yeah :D
<Cadey> oh, how should i handle the _start logic?
<Cadey> so that it calls root.os.system.exit() with the main() return val
<Cadey> kinda like wasi
<Cadey> actually, are functions data in zig?
<andrewrk> not sure what you mean
<andrewrk> msiism, they have the "noreturn" type
<andrewrk> which means that the value will never be accessed
<Cadey> andrewrk: i'd expect doing something like `return error.Unknown;` in fn main() in a zig program to return a nonzero exit code
<andrewrk> Cadey, it does; are you observing something else?
<Cadey> yes
<Cadey> i'm observing it not calling my custom exit function with the return code