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/
utzig has quit [Quit: leaving]
<andrewrk> squeek502, what flags do you need?
<squeek502> --export-dynamic or explicit --export=luaopen_package maybe
<squeek502> the lua C functions aren't being exported
<squeek502> (the luaopen_ functions that is, which aren't called internally)
hio has quit [Quit: Connection closed for inactivity]
ijneb has quit [Quit: Lost terminal]
ijneb has joined #zig
<scientes> I wish it was easier to spot globals in functions
<scientes> I am always scared a function reads or writes to a global
<scientes> at least zig doesn't allow shadowing
ijneb has quit [Quit: ZNC 1.6.5+deb1+deb9u1 - http://znc.in]
ijneb has joined #zig
Ichorio_ has joined #zig
Ichorio has quit [Ping timeout: 248 seconds]
Jezza__ has joined #zig
Ichorio_ has quit [Ping timeout: 248 seconds]
Jezza__ has quit [Ping timeout: 248 seconds]
<squeek502> andrewrk, nvm forgot that you had removed loadlib.c/liolib.c from build.zig to deal with missing filesystem functions, that was the cause of the missing exports, not any linker flags
<andrewrk> scientes, an IDE would be able to highlight that information
<scientes> but it requires a full IDE
<scientes> not just syntax highlighting
<scientes> that is fine
<andrewrk> although it would be difficult to distinguish between e.g. `std` and the kind of thing you're talking about
<andrewrk> maybe a mutable global variable?
<scientes> yes
<scientes> consts are fine
<husho> what's the compiler's performance situation looks like
<husho> I tried building very small wasm program and it took a while
<scientes> --release-fast is considerably slower
<husho> default is debug right?
<scientes> yes
<husho> i just used "build" sub command
<scientes> the compiler also takes huge amounts of memory
<squeek502> first build is typically slower than subsequent builds
<scientes> squeek502, that is because of the new build caching
<scientes> this is quite good
<scientes> although i think i might have broken it....hopefully i reproduce that in the future, with changing the zig binary
<andrewrk> husho, compiler performance won't really be tracked/measurable until self-hosted is what we're shipping. that's a few release cycles away
<husho> do you have fixed release cycle like rust or you ship it when you feel like things are done or whatever
<scientes> husho, its tied to llvm release cycle
<andrewrk> yeah at least until 1.0, we release roughly 1 week after llvm's major releases, which is every 6 months
<andrewrk> I think after 1.0 it will depend on known bugs, but that's to be determined
<husho> thanks for answers, keep up the good work
<emekankurumeh[m]> ======================
tridactyla has quit [Remote host closed the connection]
reductum has joined #zig
squiddle_bit has quit [Quit: WeeChat 1.9.1]
tridactyla has joined #zig
reductum has quit [Quit: WeeChat 2.4]
_whitelogger has joined #zig
husho has quit [Ping timeout: 256 seconds]
cameris has joined #zig
mrkishi has quit [Quit: leaving]
mrkishi has joined #zig
neceve has joined #zig
alexander92 has joined #zig
Sahnvour has joined #zig
squeek502 has quit [Ping timeout: 258 seconds]
marmotini_ has joined #zig
Ichorio has joined #zig
squeek502 has joined #zig
<alexander92> does zig have shared memory allocators
<alexander92> also does it have a similar resource system
<alexander92> e.g. the same way i can pass allocators
<alexander92> can i pass e.g. network/os "interfaces"
<alexander92> so e.g. one part of my program uses just local stuff
<alexander92> but other uses a "distributed" or "cloud" filesystem with the same api
<alexander92> or depending on test/prod env
<alexander92> or is this something that is easy to achieve just using alternative imports
marijnfs has joined #zig
<marijnfs> i'm trying to call sort but keep getting 'cast expression expects exactly one parameter'
marmotini_ has quit [Ping timeout: 245 seconds]
alexander92 has quit [Ping timeout: 248 seconds]
Ichorio_ has joined #zig
Ichorio has quit [Ping timeout: 248 seconds]
very-mediocre has joined #zig
mrkishi has quit [Ping timeout: 252 seconds]
neceve has quit [Ping timeout: 246 seconds]
neceve has joined #zig
wootehfoot has joined #zig
Akuli has joined #zig
marmotini_ has joined #zig
Ichorio_ has quit [Ping timeout: 248 seconds]
SamTebbs33 has joined #zig
<SamTebbs33> andrewrk: Thanks for the review on #2639. I'm not sure how to go about adding some tests to that file since the syntax in it all seems to be valid
<SamTebbs33> Whereas my patch only affects invalid code
<Sahnvour> SamTebbs33: if you want to test compile errors, you can add a test case in test/compile_errors.zig
<Sahnvour> and run `zig build test-compile-errors` to test it
<SamTebbs33> Sahnvour: cheers :)
<SamTebbs33> Does anyone know why it's not possible to do a ~ on a comptime_int?
husho has joined #zig
<SamTebbs33> It means you can't do something like `const foo = ~0b101` which really seems like something you should be able to do
mbarkhau has joined #zig
<mbarkhau> is there an example somewhere how to pass an ArrayList to a function ?
<mbarkhau> same question for HashMap
<mbarkhau> best usage code I can find is the tests in the standard library, but afaict none of those are using them as parameters
<Sahnvour> SamTebbs33: ~ is a bitwise operattion, and comptime_ints do not have a bitsize before they are casted down to a sized int type
<Sahnvour> mbarkhau: something like `fn foo(list: *ArrayList(u32)) void {` ?
<Sahnvour> SamTebbs33: since they can represent really big number, there's no way for zig to know what you intend to do and the resulting type, instead you can try for example `~u8(0b101)`
<mbarkhau> Sahnvour, it works! thanks
<mbarkhau> parsing compiler errors is an aquired skill I guess...
Zaab1t has joined #zig
<cameris> some C algorithms use the LSB of a pointer to encode some property of the target. Is that even possible in zig? I guess thats what @ptrToInt and @intToPtr are for?
porky11 has joined #zig
<SamTebbs33> Sahnvour: That makes sense, thanks
<Sahnvour> cameris: yes, you can do that
<Sahnvour> mbarkhau: are you familiar with how generics work in zig ? https://ziglang.org/documentation/master/#Generic-Data-Structures
<Sahnvour> once you get it it's pretty simple to use and reason about
very-mediocre has quit [Ping timeout: 256 seconds]
neceve has quit [Ping timeout: 272 seconds]
husho has quit [Ping timeout: 256 seconds]
curtisf has joined #zig
Sahnvour has quit [Quit: WeeChat 2.4]
marler8997 has joined #zig
<marler8997> It's been a couple years but it looks like Zig is alot further along now. I'm converting my Audio Synthesis program to Zig and it's been going well.
kristoff_it has joined #zig
RagingDave has joined #zig
hio has joined #zig
RagingDave has quit [Remote host closed the connection]
<curtisf> I'm new to zig. What's the best way to compare two comptime `[]u8` for equality?
<scientes> mem.eql curtisf
<shritesh> Why does an else block require a named break explicitly? I think the compiler can figure it out.
<scientes> it doesn't?
<scientes> what do you mean?
<shritesh> Returning values from an else block in a while/else expression
<shritesh> I get “break expression outside loop”
<scientes> oh i see
<scientes> yeah that makes sense
<shritesh> Also forgive my weird variable naming. I was working on the docs.
<scientes> oh, i've had test cases that use a variable named "true". I've done far woorse
<scientes> in C that is
<scientes> also, you can't name a variable "linux" in either gcc or clang
<shritesh> The docs are littered with `else blk: { }`
<scientes> allowing it to be implied would be nice
<scientes> it would be nice if i could create a c label in zig, so that i could use asm goto
<scientes> but i guess my needs would require expanding llvm
<curtisf> is it possible for a function's return type to depend on comptime argument? e.g., a function that returns a `Alpha` when the first argument is comptime `"alpha"` but `Beta` when the first argument is comptime `"beta"`? It looks like no but it seems like this would be a useful feature, though I can see it leading to some fairly hard to read code
<scientes> curtisf, yeah, just set the return type to "var"
<scientes> and then you get duck typing
<scientes> or you can also take a "comptime T: type" argument, and then have your function return T
<scientes> also functions can return types
<scientes> although those are actually just comptime functions
<curtisf> I think `var` is what I want, I didn't see that mentioned in the docs anywhere. I didn't want to have a comptime T because then you'd need to write `(Alpha, "alpha")`, `(Beta, "beta")`
<scientes> the latter is actually more zig-like
<scientes> that is very common in the std lib
<curtisf> I see. I'm trying to work around the lack of `@reify` or something like it for the moment and make "getters" and "setters" where repeating the type seems redundant to me (since what I really want is just to have a struct field)
marmotini has joined #zig
Zaab1t has quit [Remote host closed the connection]
<tgschultz> you cannot use `var` as a return type, but return types can be expressions yeilding a type.
marmotini_ has quit [Ping timeout: 248 seconds]
<tgschultz> so: like `fn foo(a: var) @typeOf(a)`. Or even a switch statement or comptime evaluatable function
<scientes> woah
<scientes> still not sure why....
<curtisf> ooo, that's cool.
<curtisf> The reason I'm interested in doing this is so that you can have a "parser generator" that's written in Zig -- no source code generation required
Akuli has quit [Quit: Leaving]
gustav_o has joined #zig
marmotini has quit [Ping timeout: 246 seconds]
<marijnfs> how are you supposed to call std.sort?
<marijnfs> i keep getting some 'cast expression' error
<scientes> you need to pass it a function
<scientes> mem.compare might work, but not always
<cameris> https://pastebin.com/C5aWeUeL , could somebody help me understand where alinged pointers are useful? I can't see a diffrence or am I using it wrong?
jjido has joined #zig
<marijnfs> scientes: i made a cmp function, but the error seems to start somewhere else
<marijnfs> i call it sort(f64, vals[0..], cmp);
<marijnfs> with fn cmp(ll: f64, rr: f64) bool
<gustav_o> hi everyone, I get an “unable to evaluate constant expression” when trying to iterate and warn(it_str) using a for-loop in build.zig, do you know what I’m doing wrong?
<marijnfs> error: cast expression expects exactly one parameter
<marijnfs> i'm trying to make sense of what that says
<gustav_o> marijnfs: could you paste the code?
<jjido> How do you write a cast? Isn’t it one of the @ directives?
<marijnfs> gustav_o: shit i just realised i was called std.sort, not std.sort.sort
<marijnfs> somehow that creates that strange error
<marijnfs> ok next problem, i get an integer overflow in the sort function:/
<marijnfs> and i'm not sorting integers
<marijnfs> so must be index
<tgschultz> marijnfs: the error is because all namespaces in zig are structs. std.sort is therefore a struct, meaning `std.sort(...)` looks like a cast to the compiler.
<tgschultz> where is the integer overflow? if it is in sort.zig, what line?
<marijnfs> tgschultz: thanks, makes sense i guess, maybe a nicer error would somehow be nice
<marijnfs> yeah so in sort:504
<marijnfs> mem.rotate(T, items[range.start..range.end], range.length() - count);
<marijnfs> somehow that overflows
<tgschultz> that casting syntax may go away in favor of an @ function.
<tgschultz> best guess is range.length is going to be 0 and count is > 0.
<marijnfs> i'm sorting 4 million floats that are not exactly random but close to it
<marijnfs> with a asc function
<marijnfs> just doing insertionSort does work
<tgschultz> could be a bug in std.sort.sort. It is absurdly complicated.
<scientes> marijnfs, post your code on godbolt.org
<andrewrk> scientes, I think you can appreciate this: https://gist.github.com/andrewrk/878747405f7e4d8dcd709087622512c9
<andrewrk> a little demo of the result location changes in my copy-elision-3 branch
<scientes> there is alot there and I can't say I can see it all without some narrative (and looking at the generated assembly, which I am now), but it looks good
<scientes> oh yes, the static doesn't ever get copied
<andrewrk> you can sort of see the differences just by doing ctrl+f "memcpy"
hio has quit [Quit: Connection closed for inactivity]
<andrewrk> looking at the zig code, idea here being you can follow the "result location" from the variable declaration or return statement all the way down the expression tree
<andrewrk> you'll notice that for example the calls to bar1() and bar2() directly initialize the `bar` field of the variable `runtime`, even though they are buried under a function call, struct initialization, and if expression
<scientes> yeah that is really slick
<andrewrk> C already has this, but what zig brings to the table is it all works with comptime
<scientes> well that didn't demo that
<andrewrk> and it's semantically guaranteed. I don't know whether that's true for C
<andrewrk> yeah, notice that there's no code generated for `static`
<scientes> oh i see
<scientes> that comptime is IMPORTANT
<andrewrk> yeah
<scientes> cause gcc and clang have forward constant propagation
<scientes> but it is nothing compared to comptime
<andrewrk> zig analysis starts to generate runtime code for e.g. struct initialization, but when it gets done if it finds out everything is comptime known, it elides the runtime instructions
<andrewrk> so that had to get slightly more complicated. but it's not so bad, the existing Scope abstraction was enough
<andrewrk> anyway it's more analysis in zig code, less analysis in llvm code, so hopefully we can see a slight speedup
<scientes> So gcc has range switch statements, which they expose as a c extension
<scientes> however clang does that outside of llvm, which was kinda dumb
<andrewrk> oh I have this working with switch too, can demo that if you like
<scientes> putting that in llvm proper would benifit both zig and clang
<scientes> andrewrk, really!
<andrewrk> that's for integers, but I can show a struct example
<scientes> switches are not easy to deal with in llvm, because of the PHI nodes
<scientes> but that is a comptime switch
<andrewrk> ah I gotta run, can demo some more later. or you can play with the branch if curious
<andrewrk> but yeah the same "peer result location" mechanism that I made for, e.g if expressions, generalizes to N prongs, so it works for switch
<scientes> what about ranged switches?
<andrewrk> yeah works fine, they're emitted as ifs before the switchbr
<scientes> Its a long ways out, but I would like to get those into llvm, because C (GNU extension) already needs them
<andrewrk> all the range checks first as if-else chains, then the switchbr
<scientes> yeah that can't be optimized properly
<scientes> however
<andrewrk> ah well let me know if you get that into llvm and I'll happily update zig's codegen :D
<andrewrk> ttyl
<scientes> have a nice saturday night
<gustav_o> oh… the fact that warn() can’t print a string without format is a bit confusing