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/
glassofethanol has left #zig [#zig]
Ichorio has quit [Ping timeout: 246 seconds]
hobomatic has quit [Quit: Page closed]
ltriant has joined #zig
ltriant has quit [Ping timeout: 246 seconds]
fengb_ has joined #zig
<fengb_> I'm getting a comptime error with an if expression within a switch
<fengb_> Should this syntax be supported? I can work around it with break block but it feels a little kludgy
<daurnimator> fengb_: I think you need a cast on those comptime ints
<fengb_> Actually it's something else
tiehuis has joined #zig
<fengb_> It works if I replace the if condition with (true). Any expression inside bombs
<tiehuis> fengb_: specify the type of len, such as `const len: usize = ...`
<tiehuis> or cast the number literal as a usize, e.g. usize(2)
<fengb_> Still nothing
<fengb_> The literal is fine. It's the if cond expression it doesn't like
<tiehuis> it's probably because input is a runtime-known vlaue
<tiehuis> when you use true the expression is comptime known and the assignment works
<tiehuis> at least that's what it looks like to me from that snipper
<daurnimator> yeah same to me: you can't have a comptime value depend on a runtime value
<fengb_> I get that... but I'm not sure why this is comptime but the for loop in a different branch works just fine
<tiehuis> can you post the full code segment?
<daurnimator> fengb_: does this work? (use the correct type as necessary:) if (self.input[self.curr + 1] == '@') usize(2) else usize(1),
<fengb_> Oh hey yeah
<fengb_> So zig sees 2 constants and tries to comptime the conditional away?
<tiehuis> this issue may be related: https://github.com/ziglang/zig/issues/137
<daurnimator> fengb_: no. the `2` by itself is a comptime_int. your other branches you e.g. add it to a known int type, so the comptime gets casted away
<tiehuis> zig will likely analyze the branch as returning a comptime_int, try to compute the value but the branch is runtime-known so it emits an error
<tiehuis> when you use a cast it analyzes the branch as returning a usize which has a fixed size and works fines
<fengb_> Ah okay thanks
tiehuis has quit [Quit: WeeChat 2.4]
emekankurumeh[m] has joined #zig
<emekankurumeh[m]> does zig support compiling to arm cortex?
<daurnimator> emekankurumeh[m]: yes?
<daurnimator> emekankurumeh[m]: run `zig targets` and pick the relevant arm option for your processor.
<emekankurumeh[m]> would the target name be different from the processor name?
<daurnimator> emekankurumeh[m]: what is the processor name?
<daurnimator> emekankurumeh[m]: note that there are hundreds of different arm cortex varieties. all with different features
<daurnimator> emekankurumeh[m]: also note that arm has had a history of many different abis
<emekankurumeh[m]> the arm cortex m4
<daurnimator> and then you have the question of full arm vs thumb vs thumb2...
<daurnimator> emekankurumeh[m]: https://en.wikipedia.org/wiki/ARM_Cortex-M#Cortex-M4 => even within M4 you have multiple options. e.g. do you have an fpu?
<emekankurumeh[m]> it comes with an fpu
<emekankurumeh[m]> its the teensy 3.5 if that helps
<daurnimator> emekankurumeh[m]: so you have the arm-v7em architecture or thumb-v7em. you probably are freestanding. you probably want to use eabihf (hf = hard float)
<shritesh> For anyone interested: I got Zig talking to the DOM https://shritesh.github.io/zig-wasm-dom/
<emekankurumeh[m]> wait that is valid zig?
<hryx> amazing shritesh
<shritesh> That page is being generated by Zig (with some JS shim). It uses the @embedFile builtin to embed it's own source code. So technically it's a Zig/WASM quine
<shritesh> I intend to have the JS shim be autogenerated by the compiler
<tyler569> and I just booted a Linux kernel with a pure-zig userland! https://i.imgur.com/exEYP9H.png - let's just say it's a little minimal ^.^
<shritesh> tyler569: That's awesome!!!
<emekankurumeh[m]> ok, now i understand
<emekankurumeh[m]> the extern functions at the top are referencing symbols from the javascript side
<hryx> daaaaaang tyler569
<tyler569> it's not all that impressive, trust me :P, std.debug.warn oneliner basically
<tyler569> just gotta wrap it up in an initrd
<tyler569> grub config
<tyler569> boom
<fengb_> Hmm, is there a reason why for/else isn't for/catch?
<mikdusan> the `else` isn't an error and catch implies error
<shritesh> Next up: Virtual DOM in Zig
<fengb_> "When the else |x| syntax is present on a while expression, the while condition must have an Error Union Type."
<fengb_> Oh it mirrors if semantics for error unions
ltriant has joined #zig
ltriant has quit [Ping timeout: 255 seconds]
<hryx> ok, playing around with this failing allocator in the parser test. I understand it a little better now. Very cool way of getting thorough coverage!
<hryx> This tiny test I added has a maximum fail_index of 3. If I start the fail index counter at a number other than 0 I can test the Nth allocation
<hryx> allocations 0 and 3 always succeed, but 1 and 2 always fail
<hryx> (rather, the bytes freed != bytes allocated as andrew pointed earlier)
<hryx> Just dumping my findings here on the off chance it sparks any ideas. I'll continue sleuthing meantime!
<hryx> Er, there is no allocation #3. only 0 through 2. So only the first one succeeds, probably because all allocations fail, so nothing can get freed anyway
ltriant has joined #zig
ltriant has quit [Ping timeout: 268 seconds]
<daurnimator> do we have any coverage tools for zig?
<daurnimator> does gcov work?
tiehuis has joined #zig
<tiehuis> haven't tried gcov, but kcov worked well for me a while back
tiehuis has quit [Client Quit]
<hryx> Can anyone tell me which of these is more correct, between f1() and f2()? https://hastebin.com/raw/nurulufacu
<hryx> Or does it depend on the situation? Or are they equal?
tiehuis has joined #zig
tiehuis has quit [Client Quit]
fengb_ has quit [Quit: Page closed]
ltriant has joined #zig
ltriant has quit [Ping timeout: 255 seconds]
very-mediocre has joined #zig
ManDeJan has joined #zig
jjido has joined #zig
slugm has joined #zig
ltriant has joined #zig
ltriant has quit [Ping timeout: 245 seconds]
TheLemonMan has joined #zig
<TheLemonMan> is there a way to check if a given const is defined or not?
<very-mediocre> TheLemonMan: since all files are structs, you might be able to use @typeInfo
<TheLemonMan> I guess so, thanks very-mediocre
<TheLemonMan> Hello world from a cross-compiled Zig binary running on a rPI model A, so 32bit ARMv6
gunnarahlberg has joined #zig
Ichorio has joined #zig
gunnarahlberg has quit [Read error: Connection reset by peer]
ltriant has joined #zig
ltriant has quit [Ping timeout: 244 seconds]
ljmccarthy has joined #zig
<ljmccarthy> how can I create a static `[*]const ?[*]const u8` to pass to execve?
<ljmccarthy> something like: var argv = [*]const ?[*]const u8{"/bin/ls"};
<ljmccarthy> but that doesn't work - error: type '[*]const ?[*]const u8' does not support array initialization
<ljmccarthy> posixExecve seems to solve this problem using dynamic allocation
<TheLemonMan> const argv = []const []const u8{"/bin/ls"} ?
<ljmccarthy> you can't pass that to std.os.linux.execve() though
<ljmccarthy> maybe to simplify it
<ljmccarthy> how can you get a [*]const u8 from a string literal?
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<ljmccarthy> this seems to work: var arg : [*]const u8 = "hello\x00"[0..].ptr;
<ljmccarthy> as a function: fn cStringPtr(str: []const u8) [*]const u8 { return str.ptr; }
<ljmccarthy> ok I figured it out
<ljmccarthy> it's ugly though
<ljmccarthy> ([]const ?[*]const u8 { cStringPtr("hello\x00"), cStringPtr("world\x00") })[0..].ptr
<ljmccarthy> or use this to automatically add the nul terminator
<ljmccarthy> fn cStringLiteral(comptime str: []const u8) [*]const u8 { return (str ++ "\x00")[0..].ptr; }
jjido has joined #zig
jjido has quit [Client Quit]
<ljmccarthy> ok I wrote some nice comptime utilities to do this
<ljmccarthy> not sure if I'm reinventing something zig already has
<ljmccarthy> also it's not clear if it's valid to return the address of a comptime array I've allocated locally or not
mht has joined #zig
ltriant has joined #zig
ltriant has quit [Ping timeout: 250 seconds]
neceve has joined #zig
ljmccarthy has quit []
ManDeJan has quit [Ping timeout: 250 seconds]
Barabas has joined #zig
<Barabas> I'm trying to build zig (master) and it says: /usr/bin/ld: cannot find -ltinfo
<Barabas> On linux (mxlinux) and when I search for libtinfo in synapic it notes for libtinfo-dev:
<Barabas> This package contains the static library and symbolic link that developers using the low-level terminfo library will need. Packages should not build-depend on this package.
<Barabas> Is it fine to link against or not? I'm confused.
<Barabas> To be clear. It works when I install libtinfo-dev, so that's fine. I'm just confused. ^^
Barabas has quit [Ping timeout: 256 seconds]
mht has quit [Ping timeout: 250 seconds]
<bketelsen> shritesh: holy moly DOM access!
<shritesh> bketelsen: It's still too verbose. I've been studying how other ecosystems handle interop and I think I have a few good ideas to make Zig the best platform to write WASM for the browser.
<shritesh> But hey, it works :D
<bketelsen> i'm 100% here for this, would love to collaborate
<shritesh> That'd be awesome!
<bketelsen> what is the "document" in the first part of this line: "extern "document" fn query_selector(selector_ptr: [*]u8, selector_len: usize) usize;
<bketelsen> "
<bketelsen> is that a namespace?
<shritesh> That's a webassembly module name
<shritesh> By default it's "env" but I love namespaces
<bketelsen> oh interesting
<bketelsen> we should generate a full dom module from WebIDL
<shritesh> exactly. I think the compiler should do it alongside the generated WASM file
<shritesh> alos, those functions could be encapsulated better. But I just wanted to see how it'd work.
<shritesh> also*
<bketelsen> yeah it's easy to imagine a dom module that has all of the interop
<bketelsen> and a vdom module
<shritesh> That's next on my agenda.
<bketelsen> next hurdle - functions/events
<shritesh> Functions are going to be tricky as we don't have closures et. al, but javascript's Function constructor (a better and safer alternative to eval) might make things easier https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval#Do_not_ever_use_eval!
<shritesh> Event listeners can be attached at runtime to nodes.
<shritesh> Alsi, our work is easier because Zig has manual memory management and expects the programmer to dealloc. A lot of complexity in wasm-bindgen stems from having the compiler manually deallocate memory
<shritesh> 'also
<bketelsen> another question "return error.QuerySelectorError" <-- I don't see these errors actually defined anywhere
<bketelsen> is that a zig thing I don't know?
<shritesh> Zig maintains a global union of all errors
<bketelsen> thanks!
<shritesh> Anytime :)
<bgiannan> does wasm allow dom interaction now ?
<bketelsen> not directly
<bketelsen> the dom binding proposal is in progress, but not complete
<bgiannan> i see it's directly linked to the GC issue: https://github.com/WebAssembly/proposals/issues/16
<andrewrk> wow all sorts of exciting stuff going on in this channel
<shritesh> andrewrk: I won't stop until groovebasin can be written in Zig ;) I have been completely ignoring the browser until then.
ltriant has joined #zig
<shritesh> Also, a question: Why does a numeric counter before a while loop need explicit type annotation?
ltriant has quit [Ping timeout: 246 seconds]
halosghost has joined #zig
<shritesh> I think the compiler should figure out `var i = 0; while (i < 10) : (i += 1) {} `
slugm has quit [Remote host closed the connection]
slugm has joined #zig
ManDeJan has joined #zig
<andrewrk> there's an issue for that I think
<TheLemonMan> is there a way to download artifacts off the azure pipeline? I see #2296 is failing on osx but don't have access to that platform
<andrewrk> not that i'm aware of
<andrewrk> shritesh, related: https://github.com/ziglang/zig/issues/747 but that doesn't solve your example
<andrewrk> I think your example needs a type because how is it supposed to know the upper bound? you could have chosen anything instead of 10 and that's at some unknown future code
<andrewrk> it works if your code is comptime
<andrewrk> the other related issue is https://github.com/ziglang/zig/issues/137
<andrewrk> TheLemonMan, do you see the error output though?
<shritesh> Ah. Are these related? https://github.com/ziglang/zig/pull/2211 I've come across this pattern many times now.
<andrewrk> TheLemonMan, oh I see, it's error: invalid character: ')' which is unhelpful because you can't see the file contents
<andrewrk> I'll take a look on my macos laptop when I examine your pull request
<TheLemonMan> great, thank you
<andrewrk> shritesh, ah, yeah I haven't merged this because I want to understand why it can't be solved in a more generic way, it's not intended to have to explicitly write code for these types
<andrewrk> alright I need to have another day where I'm mostly offline
<andrewrk> next week/weekend is going to be crazy for me, and then I should be back in the swing of things the week after
<bketelsen> shritesh: it might be simple enough to do an event proxy on the JS side that calls zig functions
<bketelsen> maybe a proxy on the JS side and a dispatcher on the zig side
<shritesh> bketelsen: makes sense
<shritesh> Also, how we separate js / browser is an open question. We need to support nodejs-isms too.
fengb_ has joined #zig
<fengb_> I would like to port musl to wasm. Would I be biting off more than I can chew?
<shritesh> fengb_: Have you looked at https://github.com/CraneStation/wasi-sysroot ?
<shritesh> It'd be amazing if we had something native in Zig. It'd help tremendously with the WASI support.
<fengb_> Oh, I meant doing it inside of zig
<shritesh> Yes!!!
<fengb_> Yeah, I've been really annoyed by C tooling. And it seems like it might be easier to make zig work than clang
<fengb_> But I've never worked at such a low level before
<fengb_> Per https://github.com/WebAssembly/design/issues/519#issuecomment-175255932, musl should mostly just work and I'd need to stitch together the syscalls
<fengb_> Actually wasi looks like a much easier path. I can explore that
<shritesh> fengb_: There's already some groundwork in std. I'd be happy to help / collaborate.
<fengb_> I'm just piggybacking off your hard work :D
bketelsen has quit [Quit: Leaving]
bketelsen has joined #zig
jjido has joined #zig
very-mediocre has quit [Ping timeout: 256 seconds]
ltriant has joined #zig
ltriant has quit [Ping timeout: 246 seconds]
Barbas has joined #zig
gamester has joined #zig
fengb_ has quit [Quit: Page closed]
Sahnvour has joined #zig
Jenz has joined #zig
mht has joined #zig
Barbas has quit [Ping timeout: 256 seconds]
mht has quit [Quit: ZNC 1.6.6+deb1ubuntu0.1 - http://znc.in]
_whitelogger has joined #zig
mht has joined #zig
<bketelsen> had a fun pairing session with shritesh!
<bketelsen> we built an event proxy in JS and a dispatcher in Zig and wired them up nicely.
mht has quit [Quit: ZNC 1.6.6+deb1ubuntu0.1 - http://znc.in]
<shritesh> It was fun!
ltriant has quit [Ping timeout: 246 seconds]
<bketelsen> zig+wasm has legs. I think it's going to be a hit
mht has joined #zig
mht has quit [Client Quit]
mht has joined #zig
<shritesh> Next time, we'll be generalizing what we learned today
<shritesh> ...and probably come up with a nice looking library
<bketelsen> that's what I'm excited about
<bketelsen> the size of zig's binaries in wasm is a THING. <3
<shritesh> 13K / 5.6K gzipped
<shritesh> That includes a memory allocator
<bketelsen> in contrast, I'm used to seeing 7MB gzipped from Go's wasm output. That's a non-starter.
<bketelsen> I just have to learn to think in zig now.
<shritesh> This is before any of the minifiers provided by binaryen
<bketelsen> true, there's likely some optimization that can be done on the wasm before compression.
neceve has quit [Read error: Connection reset by peer]
<Sahnvour> andrewrk, sorry I was booked during the past days, please let me know if you have some time in the next few hours
keveman has joined #zig
slugm has quit [Remote host closed the connection]
slugm has joined #zig
keveman has quit [Ping timeout: 256 seconds]
keveman has joined #zig
<keveman> Question on inlining: I have a code snippet here: https://gist.github.com/keveman/9286301bbdfb76f4bfa249256fd363e1
<keveman> There is bar(), where a function marked inlined is called 2 times, and there is baz() where the same function is called 3 times..
<keveman> all calls are inlined in bar(), but none of the calls are inlined in baz()
<keveman> From the documentation page: "If the function cannot be inlined, it is a compile-time error.". I am wondering why I don't get a compiler error..
keveman has quit [Quit: Page closed]
<tgschultz> keveman, I don't have experience reading llvm output but it looks like neither case is inlined in your gist. However, I can confirm on godbolt that all cases are inlined.
keveman has joined #zig
<keveman> tgschultz, thanks. My bad, I was looking at the disassembly for my backend which is where I noticed that the first cast was inlined, the second was not
<keveman> you are right, in the llvm IR, both cases are not inlined..
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
<keveman> This makes me wonder about the guarantees for `inline` functions.. It seems like it's only a compiler error if the function *cannot* be inlined for some reason..
<keveman> If it indeed *can* be inlined, there is no compiler error, but it could still not be actually inlined, depending on some other criteria?
ltriant has joined #zig
<tgschultz> I have no idea. Could be that the LLVM IR is a pre-inlined representation and the inlining happens later. I don't work on the compiler itself so I'm just guessing.
ltriant has quit [Ping timeout: 246 seconds]
keveman has quit [Quit: Page closed]
forgot-password has joined #zig
jjido has quit [Quit: Textual IRC Client: www.textualapp.com]
<forgot-password> Hey guys, would somebody mind explaning why the setBit function (see https://godbolt.org/z/fx9W_c) generates as much assembly as it does?
<forgot-password> I would expect the @intCast to only be relevant at compile time. The shifts, ors and ands are single instructions so it doesn't add up to me
<forgot-password> Or is it related to runtime safety?
slugm_ has joined #zig
slugm has quit [Ping timeout: 244 seconds]
slugm_ has quit [Remote host closed the connection]
Jenz has quit [Ping timeout: 246 seconds]
<tgschultz> @intCast asserts that the cast doesn't cause overflow
<tgschultz> so it is a no-op in release-fast/small, but in debug/safe it checks
hio has quit [Quit: Connection closed for inactivity]
<forgot-password> tgschultz: Got it, thank you!
fengb_ has joined #zig
halosghost has quit [Quit: WeeChat 2.4]
forgot-password has quit [Quit: leaving]
ltriant has joined #zig
ltriant has quit [Ping timeout: 244 seconds]
<emekankurumeh[m]> did zig fmt ever have a feature for auto-converting line endings or did i just imagine that?
fengb_ has quit [Ping timeout: 256 seconds]
<hryx> emekankurumeh[m]: line endings other than LF are illegal at the encoding level, so I think the file would fail to parse before it ever gets to zig fmt
<hryx> in other words, non-LF line endings are invalid tokens and therefore can't be reformatted
<hryx> (sorry, re-reading your question closer: not sure if that ability existed previously)
<shritesh> I may have implemented that feature
<tgschultz> I thought I saw that feature was implemented recently, but don't take my word for it. It's one of the use cases for zig-fmt
<hryx> I certainly could be misremembering the conclusion of the original discussion
ltriant has joined #zig
Ichorio has quit [Ping timeout: 246 seconds]
fengb_ has joined #zig
<fengb_> Getting this error when trying to process_headers: /deps/zig/libc/process_headers.zig:279:25: error: container 'builtin.Arch' has no member called 'nios2'
Sahnvour has quit [Read error: Connection reset by peer]
knebulae has quit [Ping timeout: 268 seconds]
ltriant has quit [Ping timeout: 255 seconds]
hio has joined #zig