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/
wootehfoot has quit [Read error: Connection reset by peer]
mnoronha has joined #zig
mnoronha_ has joined #zig
mnoronha has quit [Ping timeout: 250 seconds]
Sonderblade has joined #zig
mnoronha_ has quit [Ping timeout: 250 seconds]
mnoronha_ has joined #zig
mnoronha_ has quit [Ping timeout: 268 seconds]
hio has quit [Quit: Connection closed for inactivity]
mnoronha_ has joined #zig
_whitelogger has joined #zig
jzelinskie has quit [Ping timeout: 268 seconds]
jzelinskie has joined #zig
mnoronha_ has quit [Ping timeout: 250 seconds]
_whitelogger has joined #zig
_whitelogger has joined #zig
<shritesh> andrewrk: I think the two PRs are ready.
Sonderblade has quit [Read error: Connection reset by peer]
richardanaya has joined #zig
<richardanaya> hey all
<richardanaya> i'm in a quest for very ideal language for web assembly
<richardanaya> i've been bouncing around almost every language that compiles down to wasm
<richardanaya> even inventing my own
<richardanaya> Zig looks like an interesting balance
_whitelogger has joined #zig
nore has quit [Ping timeout: 246 seconds]
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
mnoronha_ has joined #zig
mnoronha_ has quit [Ping timeout: 240 seconds]
richardanaya has quit [Ping timeout: 256 seconds]
nore has joined #zig
duncanvt has joined #zig
_whitelogger has joined #zig
ManDeJan has joined #zig
<andrewrk> shritesh, nice work - I'll work on merging your stuff in the morning
<andrewrk> good night
very-mediocre has joined #zig
<very-mediocre> Does zig elide branching if statements when the condition being tested is comptime-known?
hio has joined #zig
<presiden> very-mediocre, yes, https://godbolt.org/z/kJBqNf
<very-mediocre> didn't think to do that! Thanks
duncanvt has quit [Quit: Connection closed for inactivity]
<very-mediocre> I guess this should not pose a branching penalty then: https://github.com/ziglang/zig/issues/793#issuecomment-482927087
<very-mediocre> (mediocre attempt at EnumArray)
<companion_cube> is godbolt limited to C ABI functions?
ManDeJan has quit [Ping timeout: 252 seconds]
<very-mediocre> companion_cube: looks like it, if you remove `export` from `export fn...` there's no output
<companion_cube> yeah :/
<very-mediocre> `export` seems infectious, if you add a function `bar` that's exported, and you call `foo` inside it, you do get an output for `foo`
<very-mediocre> (which obviously makes sense)
<very-mediocre> I was away from zig for a while, months ago there was the idea floating around that zig could be like "comptime-eager" - as in infer the intent to have comptime execution in some cases
<very-mediocre> e.g. calling the `fn whatever(a: []const u8)` with a comptime-known value for param `a`, even though it's not labeled comptime in the function signature
<very-mediocre> has anything happened re:this?
_whitelogger has joined #zig
very-mediocre has joined #zig
<very-mediocre> Actually I'm dumb, this should be the same as my previous question about `if` statements [12:40] <very-mediocre> withdrawn!
<very-mediocre> (messages did not go through)
<very-mediocre> ok it is NOT the case https://godbolt.org/z/qyBGM0
<very-mediocre> I'm done spamming now. :)
<very-mediocre> please disregard, lots of mistakes
<very-mediocre> presiden was right. :)
very-mediocre has quit [Ping timeout: 256 seconds]
m6w6 has quit [Quit: https://m6w6.name]
m6w6 has joined #zig
very-mediocre has joined #zig
Ichorio has joined #zig
Sahnvour has joined #zig
Sahnvour has quit [Client Quit]
Sahnvour has joined #zig
gamester has joined #zig
<gamester> companion_cube, very-mediocre: you're literally just describing how Zig works, it has nothing to do with godbolt.
gamester has quit [Quit: Leaving]
marmotini_ has joined #zig
<very-mediocre> gamester you've misread, companion_cube was just asking about godbolt.
<very-mediocre> my questions were about zig, godbolt was used to provide answers
<very-mediocre> I concede I am extremely messy at writing on irc so I understand it's hard to follow.
marmotini_ has quit [Ping timeout: 264 seconds]
<Sahnvour> andrewrk, how is building with C source files supposed to work wrt. libc, especially on windows ? I'm trying to mix zig and C code on windows but the zig cc command line generated does not contain a path providing libc headers, and so they are not found
marmotini_ has joined #zig
marmotini_ has quit [Ping timeout: 252 seconds]
porky11 has joined #zig
porky11 has quit [Client Quit]
<scientes> Sahnvour, it probably just isn't tested on Windows yet, as it is a new feature
<scientes> Sahnvour, but on Linux it explicitly does _not_ link against libc
<scientes> so you have to do so manually
wootehfoot has joined #zig
Xe has joined #zig
Ichorio has quit [Ping timeout: 252 seconds]
<Xe> How would I get zig to import arbitrary functions from the environment in WebAssembly? I'm trying to get Zig working on top of an arbitrary WebAssembly runtime (https://github.com/Xe/olin) and I'm having trouble figuring out how to import extern functions.
<shritesh> The print function gets imported from the env
<Xe> shritesh: how would I pass a pointer,length string to the function?
ben_e has joined #zig
<Xe> oh i see
<shritesh> extern fn log_write(i32, *const u8, usize));
<shritesh> ignore the extra parens :D
Zaab1t has joined #zig
<Xe> how do i convert a zig string into a const u8 pointer?
<shritesh> you'd &str and str.len for the second and third args
<shritesh> const str = "hello world".
<shritesh> i shouldnt be typing from mobile. zig doesnt havd period stops.
<Xe> this fails build
<shritesh> Sorry the signature should have been extern fn log_write(level: i32, data: [*]const u8, len: usize) void;
<Xe> ah yep
<Xe> can you const a non-const string?
<Xe> or is const compile time only
<shritesh> A non-cost string pointer (u8 arrays) implicitly casts to a const pointer if that's what the function expects.
Zaabtop has joined #zig
<Xe> oh nice
Zaab1t has quit [Ping timeout: 255 seconds]
Zaabtop is now known as Zaab1t
<Xe> it works too
<shritesh> Nice
<shritesh> Xe, if you compile with --release-small, --release-fast or even --release-safe, the optimizations will turn on and the gas used might be even lower
meheleventyone has joined #zig
<Xe> (gas == number of instructions)
<shritesh> I am aware :)
<Xe> lol
<Xe> release-fast made it 5 instructions
<shritesh> Great!!!
meheleventyone has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
meheleventyone has joined #zig
<andrewrk> Sahnvour, you have to use `--library c` in order for libc headers to be in the include path
<andrewrk> scientes is incorrect; C source compilation is fully tested on windows in the main test suite
<scientes> oh, I should check
meheleventyone has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<daurnimator> andrewrk: how goes?
very-mediocre has quit [Ping timeout: 256 seconds]
<andrewrk> hi daurnimator
<daurnimator> andrewrk: you took the weekend off? :)
<andrewrk> that's one way to put it. I ran 16 miles yesterday
<daurnimator> intentionally I hope?
<andrewrk> haha
<daurnimator> vs "my car broke down in the middle of nowhere" :P
ben_e has quit [Ping timeout: 256 seconds]
<shritesh> andrewrk: What'll it take for wasm32 to be tier 2? ;)
<andrewrk> let's have a look
<Xe> how would I add my own OS interface to zig's standard lib?
<andrewrk> I think it's tier 2 now that your preliminary support patch is merged
<shritesh> Woo Hoo!!!
return0e has quit [Ping timeout: 250 seconds]
<andrewrk> wasm64 should probably be 4 though - afaik it's not standardized yet
<shritesh> Correct
return0e has joined #zig
<andrewrk> shritesh, to get to tier 1, I think we need to make a WASI interpreter :)
<shritesh> I'll work on that in two weeks after I graduate college :D
klltkr has quit [Quit: Leaving]
<Xe> andrewrk: how would I add an OS backend to zig's standard library? I already have function calls for things like file operations in a bit of a self-made webassembly environment.
<andrewrk> Xe, that's a great question. Let me think about that for a moment
<Xe> 👍
<andrewrk> what OS is it?
<Xe> it's not any OS in particular, though the semantics are unix-like: https://github.com/Xe/olin
very-mediocre has joined #zig
<andrewrk> cool, yeah this is the use case I need to consider
<shritesh> Oh wow. I remember this project. This blew my mind when I first saw it in Rust circles.
<Xe> shritesh: yeah, i'm still working on it. I've been kinda set back by life circumstances, but I want to push this into high gear now.
<andrewrk> Xe, so the status quo answer to your question is that you fork zig, add support for your OS (you can follow the "Zen" OS example), and then submit a pull request to upstream your changes
<Xe> andrewrk: awesome
<Xe> how do you qualify the type of a string?
<Xe> like of a size-independent string
<andrewrk> I don't currently have a solution to the use case of e.g. extending Zig with more operating systems without going through master branch / upstreaming process or maintaining a fork
<shritesh> andrewrk: submitted a PR to bump wasm tier
<andrewrk> Xe, zig doesn't have strings - what are you trying to do?
<andrewrk> shritesh, bump it up to where the other 2's are
<andrewrk> hmm this table is getting big. maybe we move the support table to ziglang.org and delete it from the readme, and then it will be easier to have more columns
<Sahnvour> andrewrk, thanks, how do I do the equivalent to `--library c` in a build file ?
<andrewrk> Sahnvour, artifact.linkSystemLibrary("c");
<Sahnvour> thanks
<Xe> andrewrk: so I have to keep track of the length of "strings" like in C?
<andrewrk> I'm not sure what you're asking
<Xe> i'm asking how do you make a function that passes a slice of any length with one function argument?
<daurnimator> andrewrk: any thoughts on the http headers PR?
<andrewrk> Xe, fn foo(data: []u8)
<Xe> then why isn't that working?
<andrewrk> I can't see your screen
<andrewrk> you're passing const data to a mutable slice
<andrewrk> try []const u8
<andrewrk> daurnimator, no, I haven't looked at it yet
<daurnimator> andrewrk: no problem. I started work on a hpack module too but ran out of time. might be a while before I get back to it
<Xe> i can put zig files in folders and the compiler doesn't have aay magic rules for them, right?
<Xe> any*
<Sahnvour> andrewrk, have you considered the case of header-only C libs ? What's the best way to use functions defined this way ? @cImport ?
<shritesh> Xe: Yes. You can change behaviors through command line options and Zig's build system (build.zig) if you want.
mnoronha_ has joined #zig
<shritesh> I think I'll try to add Zig support in https://webassembly.studio next
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
<Xe> oh, `zig test` doesn't work in wasm-freestanding-none
<Sahnvour> answering my own question, looks like translate-c should do just fine for header only libs
ben_e has joined #zig
<Xe> how do I encode an int64 value into base 10 UTF 8 bytes?
<Xe> i'm looking for the equivalent of https://godoc.org/strconv#Itoa
<scientes> Xe, fmt.digitToChar()
<scientes> Xe, and thats just ASCII bytes
<Xe> scientes: where is the documentation on that?
<scientes> Xe, there is no documentation for the std lib yet
<scientes> *std.fmt.digitToChar()
<Xe> is it expected for webassembly to not support error returns?
<Xe> and what should I do instead
<scientes> Xe, there is a difference between regular zig-internal functions, and extern functions
<scientes> extern functions don't support error unions
<Xe> for internal functions
<scientes> then you can use them
<scientes> Xe, errors are just values, they are not exceptions
<scientes> that is an llvm bug, not a zig bug
<scientes> but zig should work around it
<Xe> should i try zig master too?
<scientes> Xe, but that means your program crashed, that is only called by the panic handler
<scientes> in order to get backtraces on wasm that will have to be implemented in llvm
<Xe> it crashed at compile time?
<scientes> oh, no that is the linker
marmotini_ has joined #zig
<scientes> yeah try zig master, i know they have been working on this
<Xe> master works yeah
<scientes> if you panic however it will just hang
<shritesh> Xe, that should have been solved in master
<shritesh> You can also define your own `pub panic(..) noreturn` function in your code change the behavior of how panic is handled: https://github.com/ziglang/zig/blob/master/std/special/panic.zig
<shritesh> code to change*
ben_e has quit [Ping timeout: 256 seconds]
Zaab1t has quit [Quit: bye bye friends]
<Xe> shritesh: oh nice
<Xe> https://media.discordapp.net/attachments/140359933341204481/567040689234509824/image0.png optimizations shave 90% of the execution time of this program off
<shritesh> Compilers are wonderful
shritesh has quit [Quit: Segmentation Fault]
shritesh has joined #zig
mnoronha_ has quit [Ping timeout: 250 seconds]
nullheroes has joined #zig
mnoronha_ has joined #zig
nullheroes has quit [Quit: WeeChat 2.4]
nullheroes has joined #zig
mnoronha_ has quit [Ping timeout: 252 seconds]
mnoronha_ has joined #zig
marmotini_ has quit [Ping timeout: 246 seconds]
<shritesh> andrewrk: we need to figure out the wasm linking / imports story. In C/Rust, they are being done by attributes. https://clang.llvm.org/docs/AttributeReference.html#import-module and https://github.com/llvm/llvm-project/blob/master/llvm/test/CodeGen/WebAssembly/import-module.ll
<shritesh> `extern "module.name" fn import.name(..) ..` should work fine but I am clueless on how to implement that
<shritesh> and for wasi the module name will just be "wasi_unstable" for now and will later be namespaced to "wasi" when it reaches 1.0 or something
Jenz has joined #zig
<shritesh> Better worded question: Right now all extern functions get imported from "env" in wasm32. How would I make it import from whatever is in the string after `extern`?
<Jenz> (Noob question, I'm just trying to replace to chars in a string, what am I doing wrong?: https://paste.sr.ht/~jenz/be38c399cbee9c907978d9e3d5042213148e8b88)
<Jenz> (test fails, and val of `str` stays "hello", as everyone [in this channel] but me probably knows just by looking)
<shritesh> Jenz: I think you need to use mem.copy
<Jenz> shritesh: OK, thanks, I'll try that :D
<shritesh> `mem.copy(u8, str[2..4], replacement[0..]);` in line 8
mnoronha_ has quit [Ping timeout: 246 seconds]
<Jenz> Ooh, yes that worked, thanks a ton shritesh!
<shritesh> :)
mnoronha_ has joined #zig
<Jenz> But then, what did my `str[2..4] = replacement[0..];` do?
<shritesh> I'm confused as well.
<shritesh> When I try to run inside a comptime block, I get an `error: cannot assign to constant`. So maybe this is a compiler bug?
<Jenz> Seems like a weird place to place a compiler bug (stupidness intentional - initially an attempt at a joke)
<Jenz> (When your "joke" needs that much of an explanation, you know it's an absolute failure XD)
<very-mediocre> a slice is a pointer and a length; the left side evaluates to a pointer to one of the items in the `str` array, but then you're just pointing it elsewhere
<very-mediocre> imho. it's like doing `var ptr = str[2];` followed by `ptr = replacement[0];`
<Jenz> But str[2] refers to the u8 value, whilst str[2..4] refers to the pointers to the values in the array, not the actual values, doesn't it? That's why I thought setting those pointers to some other pointers (replacement[0..]) would change the actual values of the array `str`. Though clearly it did not
<scientes> <Jenz> But then, what did my `str[2..4] = replacement[0..];` do?
<scientes> yeah this doesn't work
<very-mediocre> Jenz you're right, my example should read `var ptr = &str[2]`
<Jenz> Oh ok
<Jenz> So the ptr is copied, kinda? (I'm probably using these terms wrong)
<very-mediocre> you're expressing a new pointer to an existing element
<very-mediocre> and then that pointer is being pointed at another element
<very-mediocre> so the first elemented being pointed to is no longer referenced
<very-mediocre> try this `str[2..4].ptr.* = replacement[0];`
<Jenz> Yeah, ok, thanks very-mediocre. I think I get it now (though I'm not sure if I actually do)
<very-mediocre> if you dereference on the left side, then you're expressing the actual content being pointed to, then when you do = you're assigning to that value
<Jenz> Huh, cleary you know what you're talking about. Thanks again for the extensive explanation. Though despite all the help, I don't get why str[2..4].ptr.* resolves to only one element
<very-mediocre> that's just by design, because a slice is really just a pointer to a single element, and a length
<Jenz> And I'm sorry for being so ignorant :) -- that's the reason I'm trying to understand now (and because I find zig absolutely awesome)
<very-mediocre> `str[2..4]` is a structure that contains 1. a pointer to str[2] and 2. length=2
<Jenz> "to str[2] and 2" ? I'd thought: "to str[2] and str[3]"
<very-mediocre> that's point #2
<very-mediocre> • pointer to str[2] and • length=2
<very-mediocre> and there's no need to be insecure, i'm pretty mediocre at zig too :)
<Jenz> Haha, then zig has sky-high standards
<Jenz> (Which I guess is true, having just looked at the std.mem implementation. And having followed zig for a while)
<shritesh> I think we all are. Except Andy lol
<very-mediocre> i'm super brain damaged from working with high level languages for 10 years
<very-mediocre> zig is the "no more excuses" moment for me to go back to lower level stuff
<Jenz> I've been "playing" (probably the most correct term for me) solely with high-level languages for like what, 4 years? not much, but for as long as I've been programming (I'm 17 now)
<Jenz> I'm young and foolish XD, but here's some proof that I somewhat understood the slices: https://paste.sr.ht/~jenz/7dfcd494f9778383304b3b9faa13dd4d62da6603
<Jenz> It works!
<very-mediocre> yeah, just to be clear that's good for understanding what's going on, but the more correct way to do that would be `for (replacement) |char, i| {str[2 + i] = char;}`
<Jenz> Which is pretty much the exact implementation of mem.copy
wootehfoot has quit [Read error: Connection reset by peer]
<very-mediocre> because we're dealing with bytes here, yes it'll be the same
<very-mediocre> but imagine you were replacing structs in an array of structs, then you'd want the `for` loop, which would let zig decide whether to actually make a copy or pass a pointer
<Jenz> Thanks again for the help, it was seriously clarifying
<very-mediocre> don't mention it, this is a pretty helpful place, andrewrk and others were very patient with me when i first joined here
* Jenz :)
mnoronha_ has quit [Ping timeout: 252 seconds]
mnoronha_ has joined #zig
very-mediocre has quit [Quit: Page closed]
wootehfoot has joined #zig
wootehfoot has quit [Client Quit]
wootehfoot has joined #zig
mnoronha_ has quit [Ping timeout: 255 seconds]
Jenz has quit [Ping timeout: 246 seconds]
mnoronha_ has joined #zig
<Xe> shritesh: how do you make zig call a webassembly trap instruction?
<shritesh> unreachable
<Xe> ah, thanks
<Xe> so i just make the panic handler in any .zig file?
<shritesh> Yes. You can only have at most one
Sahnvour has quit [Quit: Leaving]
<shritesh> Xe: does olin export all functions in the "env" module?
<Xe> yes, as a hack because rust didn't let me use an arbitrary name, it should also work with the `olin` module
<shritesh> Gotcha. I'm trying to get modules to work with Zig.
<shritesh> Do you have any thoughts on WASI?
<Xe> wasi isn't radical enough
<Xe> they limit things like file descriptors to the posix filesystem
<shritesh> Hmm
<Xe> also i seem to be segfaulting the compiler
mnoronha_ has quit [Ping timeout: 252 seconds]
wootehfoot has quit [Read error: Connection reset by peer]
<shritesh> Do you know what change caused it?
<Xe> not entirely sure
<Xe> i'm going to step through things one by one
<Xe> shritesh: the segfault is in this function: https://github.com/Xe/olin/blob/zig/zig/src/coi.zig#L36
<Xe> ubuntu is obscuring the core location
<shritesh> Looks like it's the panic function
<shritesh> If you compile with --verbose-ir it stops right as it's analyzing the panic function
<Xe> interesting
<shritesh> Don't take my word for it tho. I have been using the language for like 3 weeks.
<Xe> honestly i'm more happy that i've gotten this far with very little research and effort
<Xe> zig looks like the kind of compiler i've always wanted but never been able to make
<shritesh> According to Andy, it is no accident: https://twitter.com/andy_kelley/status/1116204730513068032
<Xe> hahahahaha
<Xe> i can see how that'd be super helpful
<Xe> i'm going to try and coax my machine to put the core into a place i can serve it via HTTP
mnoronha_ has joined #zig
<Xe> aha
<Xe> got it
<Xe> shritesh: i got the minimum crashing code down to this: https://xena.greedo.xeserv.us/files/mincrash.zig
<shritesh> It doesn't crash in release-fast
<Xe> that's interesting
<shritesh> pretty sure it has to do with debug / panic / something related to it
redj has quit [Read error: Connection reset by peer]
<shritesh> It doesn't crash in other architectures.
<shritesh> It's crashing at get_llvm_type<-ir_render_instruction<-codegen_build_and_link
<shritesh> Here's the stack trace blob:https://imgur.com/8bcef5b8-ed6b-4e07-9cbc-70dea8fb8790
<shritesh> Whoops: https://imgur.com/NKMYyMp
shritesh has quit [Quit: Segmentation Fault]
redj has joined #zig
shritesh has joined #zig
hio has quit [Quit: Connection closed for inactivity]
mnoronha_ has quit [Ping timeout: 246 seconds]