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/
shritesh has joined #zig
return0e_ has quit [Read error: Connection reset by peer]
return0e has joined #zig
<shachaf> I wonder whether the best thing you can reasonably do with X11 is use Xlib to get a GL context and then interact with the server yourself.
<shachaf> Apparently people do that with xcb?
vramana has joined #zig
<daurnimator> shachaf: yeah you can do that with xcb
Aruseus has quit [Remote host closed the connection]
scientes has quit [Ping timeout: 250 seconds]
hio has joined #zig
jevinskie has joined #zig
qazo has quit [Ping timeout: 246 seconds]
return0e_ has joined #zig
return0e has quit [Ping timeout: 250 seconds]
vramana has quit [Quit: Connection closed for inactivity]
<hryx> Are error identities specific to the sets to which they belong? In other words, does `SomeErrorSet.OutOfMemory == DifferentErrorSet.OutOfMemory`?
<daurnimator> hryx: should be true.
<hryx> thanks daurnimator
<hryx> So equal names means equal error values?
<hryx> I know that's true for the global error set, but then again it one global set
<andrewrk> shachaf, you can do it without xcb too. xcb introduces a blocking API which is not actually how it works
<andrewrk> I have some code to talk to the x11 server using zig's async/await but it's one of the things that motivated the upcoming rewrite
<andrewrk> hryx, yes that's correct
<hryx> Interesting, so two errors named SomeError in two different error sets, from two different libraries, will be equal to one another?
return0e_ has quit [Ping timeout: 258 seconds]
<hryx> I like the convenience, but I also wonder if it could cause issues
return0e has joined #zig
<daurnimator> hryx: the whole point is so that e.g. the same OutOfMemory is shared by all libraries
<hryx> daurnimator: alternative approach: that library function's error set is merged with std.mem.Allocator.Error
<hryx> but maybe that would only work when errors (error values) are already defined in stdlib
<hryx> I might be overthinking this of course :>
<hio> Can I use Zig to compile to Wasm today and call my javascript functions, passing stuff around? I dont see anything in the documentation about this
<shachaf> andrewrk: Yes, I don't particular want to use xcb, I just meant that non-Xlib code can be used together with Xlib for GLX.
<andrewrk> hio, wasm is rapidly evolving during this release cycle. cc shritesh
<andrewrk> I'll make an issue you can track for web assembly documentation
<hio> ok cool
<daurnimator> shachaf: so... why do you want to use GLX?
<shachaf> What are my alternatives?
<daurnimator> shachaf: to acheive what?
<shachaf> Showing things on the screen, using the GPU.
<daurnimator> shachaf: AFAIK, you mainly should just be talking EGL. with different setup functions for X11 vs wayland vs arcan vs android, etc.
<shachaf> I don't know much about EGL. Does it change anything?
<daurnimator> shachaf: change from?
<shachaf> Any of the above about GLX.
<shachaf> It looks like it's pretty new.
<daurnimator> shachaf: IIRC, it's always been the main API on e.g. android. It's only with wayland that it gained mindshare on desktop
<shachaf> But I'm not using Android or Wayland.
<daurnimator> shachaf: so? EGL is the only thing that works everywhere..
<shachaf> I'm confused. I'm writing a program that runs on X11, so it has to use a bunch of Xlib/xcb functions (or speak the X protocol) anyway. So presumably my program isn't portable to Android without some work.
<daurnimator> shachaf: not really after setup
<daurnimator> shachaf: you use xlib functions (or implement yourself) to create a window and get a EGL context for it. then just use EGL (you may very well still need to speak X11 for e.g. input)
ltriant has quit [Quit: leaving]
jevinskie has quit [Ping timeout: 276 seconds]
<hio> emekankurumeh[m]: can you tell me the command to invoke for compilation to wasm?
<hio> ok it's "zig build-obj --release-small -target wasm32-linux ./zigdom.zig" but it has a bunch of errors, e.g std.heap.wasm_allocator doesnt exist apparently
forgot-password has joined #zig
<forgot-password> Hi guys, I'm attempting to play around with writing inline assemby in zig, but it fails to compile on macOS 10.14.4 (Intel processor).
<forgot-password> Here's a godbolt link (where it successfully compiles, I put the error at the bottom) https://godbolt.org/z/EY9-g5
<forgot-password> When I use popcntq I get the same error.
tracernz has quit [Read error: Connection reset by peer]
strmpnk has quit [Read error: Connection reset by peer]
dch has quit [Read error: Connection reset by peer]
l1x has quit [Ping timeout: 240 seconds]
tracernz has joined #zig
dch has joined #zig
strmpnk has joined #zig
l1x has joined #zig
scientes has joined #zig
<tgschultz> I don't think #2225 was really fixed, or at least there's a similar issue still out there as random.shuffle isn't working right at comptime.
<tgschultz> also there might be an issue with Windows DirectAllocator and large alignments on Windows. Still haven't entirely ruled out my own code though.
<tgschultz> rand.zig:273:38: error: index 6386405521297833532 outside slice of size 2500
forgot-password has quit [Quit: leaving]
<emekankurumeh[m]> hio: you can use the wasm32-freestanding-none or wasm32-freestanding-wasi targets
<shritesh> hio: Do you still have the issue?
vramana has joined #zig
<vramana> I am looking at the Zig Tokenizer particular how it parses strings https://github.com/ziglang/zig/blob/master/std/zig/tokenizer.zig#L621-L638 How does it parse "\"" correctly? The way I understand the code it will only parse till "\" and conclude that's the string.
<vramana> How does it ignore the escaped double quote?
tdc has quit [Quit: Leaving]
<shritesh> hio: I have updated the instructions on that repo with information about the wasm_allocator needing Zig master and the command to compile the binary
wootehfoot has joined #zig
Sahnvour has joined #zig
halosghost has joined #zig
scientes has quit [Ping timeout: 258 seconds]
dch has quit []
ysgard has joined #zig
dch has joined #zig
<tyler569> anyone know why we have to explicitly define error sets? I feel like it would be simpler to just have the error {} construct act like a C enum and define the constants, then guarantee they're globally unique across a compilation and let the error return type always be (what we today write as) anyerror!T.
<tyler569> that way we don't make the symbol names a million characters long from type deduction of every error, and you also never have to worry about naming error sets
<tyler569> (in my view the fewer things I have to name the better)
<tyler569> and every !u32 is the same, which aids consistency
<tgschultz> It was like that before error sets were introduced. What error sets buy us is the ability to know, at compile time, if every possible error case was handled.
<tyler569> mmm that's a good point, feels like that could be accomplished by a seperate analysis apart from types, but adding complexity there to remove from somewhere else feels only nebulously better
<tyler569> what I find myself doing in practice is just defining a set at the top of my file with all the errors I use and then not thinking about it again, which is why I'm thinking about this
<tgschultz> I think there's an open issue discussing the problems error sets have introduced and possible solutions.
<tyler569> feels like excess friction
<tyler569> ah ok, I'll look for it
<tyler569> thanks for the info!
<tgschultz> Personally I just rely on inference except when that doesn't work, or in interfaces.
l1x has quit []
<tyler569> yeah yeah
l1x has joined #zig
<Sahnvour> do you have tips about how to have non totally optimized-out asm output on godbolt ? apaprently exporting my function is not enough to keep it
<tgschultz> it isn't unoptimized by default?
<tyler569> I just find it annoying to come up with that throwaway name (AllMyErrors? SubsystemError? ugh) and I also do a lot of asm reading so the symbols annoy me on that level :P
<tyler569> Are you marking functions `export`? Zig totally ignores functions it can prove aren't used
<Sahnvour> it shouldn't as it is allocating, and producing an output mixed with a fake input parameter (to my exported function)
<tyler569> you can even put a compile error in a function that isn't used, it'll just happily ignore it
<Sahnvour> woops, I wrote `extern` instead of `export`...
meheleventyone has joined #zig
very-mediocre has joined #zig
nikki93 has quit []
nikki93 has joined #zig
meheleventyone has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Barabas has joined #zig
ysgard has quit [Ping timeout: 264 seconds]
<andrewrk> tgschultz, I think LemonBoy might have fixed it in the PR I just merged
<andrewrk> oops I was scrolled up. responding to <tgschultz> rand.zig:273:38: error: index 6386405521297833532 outside slice of size 2500
<tgschultz> I got what you were referencing regardless
<andrewrk> tyler569, have you tried using error set inference?
<tgschultz> I'll rerun the test case when I get home.
<tgschultz> regarding the DirectAllocator thing, I'm pretty sure that's my code that's the problem and its allocating a lot more than I expect it to.
<andrewrk> if you don't have any (direct or indirect) recursion, you can typically get away with not declaring any explicit error sets
<andrewrk> tgschultz, you're talking about #2357?
<tgschultz> not directly. earlier (when I mentioned the rand issue) I mentioned a possible issue with Windows DirectAllocator and large alignment, but I'm now pretty sure its behaving correctly and I'm actually allocating too much memory.
<tyler569> oh I see andrew, I was under the impression that inference only worked on errors that were predefined in error{} blocks - I see that's not the case. That resolves my frustration!
<andrewrk> tyler569, glad to hear it. it's also planned to make it work with recursion, but for now you have to use an explicit error set for that case
<andrewrk> the other time that explicit error sets help is for generic code
<andrewrk> maybe this error isn't possible on linux but it is on windows, but you still need it to be in the set
<Sahnvour> tgschultz, what's the issue with DirectAllocator ? I saw you fixed properly the HeapFree thing
TheLemonMan has joined #zig
yawryck has joined #zig
<TheLemonMan> all the debuggers seem to hate the non-power-of-8 types, nice
<andrewrk> TheLemonMan, to follow up on your question about @setGlobalLinkage - looks like the function is still available
<TheLemonMan> is it? I got a compile error when trying to use it
<andrewrk> hmm you're right, apparently it's still in the docs but has been deleted. this is a bit of a mess, I'm opening an issue
<TheLemonMan> but anyway the weak linkage you've used is pretty useless for the purpose of #2354 since extern_weak is needed to detect if a symbol is unavailable... but that opens another can of worms because using that linkage causes symbols to be null and pointers do not have allowzero...
<andrewrk> ah this is relevant: https://github.com/ziglang/zig/issues/1917
<TheLemonMan> the bottom line is, let's hope for the best and hope the linker/loader combo provides it for us
<TheLemonMan> oh right, I must've missed that ticked
<TheLemonMan> tgschultz, your problem with the shr has been fixed, your code triggered some nasty UB heh
<andrewrk> TheLemonMan, once #1917 is implemented, that would solve the use case you're talking about right?
<TheLemonMan> andrewrk, yeah but it's not really a blocker since llvm & gcc emit that symbol in most of the cases
<andrewrk> ok
<TheLemonMan> andrewrk, (wrt #2318) I've just noticed you edited the last comment to say the osx failure is unrelated
<tgschultz> Sahnvour, I don't believe there is an issue. I was getting out of memory for DirectAllocator using large alignments, but I think its because the code actually is trying to allocate too much. Adding a counter showed that between alignment adjustments and the actual allocations I was in the 35GB range.
<TheLemonMan> I will edit the code to use @alignOf so that the PR is ready to go
<andrewrk> TheLemonMan, sounds good
<andrewrk> by the way have you seen the userland translate-c stuff?
<tgschultz> Thanks, TheLemonMan.
<andrewrk> I have another commit coming along in that regard
<andrewrk> at this point the C++ translate-c implementation is deprecated and I want to put effort into the self-hosted one
<andrewrk> give me another 10 minutes and the path will be extra clear
<TheLemonMan> I did, but only after I've pushed #2345 so please don't hate me for writing more C++ :P
<andrewrk> no worries
mbarkhau has joined #zig
<TheLemonMan> the reason I didn't use @alignOf is because the whole decision process about whether to emit an aligncast or not is based on llvm's getTypeAlign and that's ABI (and target?) dependent
scientes has joined #zig
<andrewrk> ahh hmm let me consider that
very-mediocre has quit [Ping timeout: 256 seconds]
ysgard has joined #zig
<andrewrk> I think the first priority of translate-c is that the generated code will for sure work
<andrewrk> after that milestone is achieved we can look into annotations or other strategies for cleaning up the output
<andrewrk> so with that in mind, I'm fine with @alignCast having to participate in every @ptrCast if necessary
<andrewrk> we could also augment the C pointer rules such that alignment casts are implicit, and are safety-checked
<andrewrk> that might be our best bet
<andrewrk> since that's how C pointers work
<andrewrk> and the point of C pointers is to make translate-c more seamless
<TheLemonMan> sounds good to me, I'll amend the PR
<TheLemonMan> andrewrk, next question for you, why the overflow-aware builtins do not return an optional type? the return-by-ref is quite awkward if compared with unpacking-ifs
<andrewrk> TheLemonMan, before I answer that - have a look at src-self-hosted/translate_c.zig after the commit I just pushed to master, and try out `zig translate-c-2 foo.c`
<andrewrk> hryx, conflict warning: I changed a lot of lines of std.zig.parser, but the only thing it did is make the return value of parse a *Tree rather than Tree
<andrewrk> TheLemonMan, hmm I think those builtins might have been made before zig had optionals. I think a proposal to change them to use optionals makes sense
<andrewrk> in the proposal let's look at the use cases in the standard library and tests and see what the code would look like with optionals and make sure it looks good
<andrewrk> I didn't hook up tests for the self-hosted translate-c yet
<squeek502> tgschultz, note that DirectAllocator on Windows doesn't free unused bytes on large alignments, so the same allocations will use more memory on Windows than POSIX, see https://github.com/ziglang/zig/issues/2306#issuecomment-486147133
<tgschultz> yes, I'm aware. That wasn't the problem though, the problem turned out to be simple: during a rewrite of the test I forgot to actually free memory between the 10000 iterations.
<shritesh> andrewrk: I can work on the documentation for WASM (#2358). Where should it go? langref?
<hryx> andrewrk: Thanks for the heads up. It won't be much longer till I open a PR, so conflicts shouldn't get out of hand
<squeek502> ah ok :)
<hryx> (the parser is feature complete but has bugs still)
<Sahnvour> so I'm wondering squeek502 tgschultz ... shouldn't DirectAllocator use VirtualAlloc instead of HeapAlloc? I think that would be closer to the posix behaviour
<tgschultz> I've been thinking that as well, but HeapAlloc is a lot more efficient when used in general purpose situations. Personal opinion: we should switch to VirtualAlloc and implement a malloc-like general purpose allocator that wraps DirectAllocator.
<tgschultz> though pursonally I have little use for a general purpose allocator.
<andrewrk> shritesh, yes I think web assembly deserves a section in the lang ref
<TheLemonMan> andrewrk, translate-c-2 prints a nice TODO string, nice heh
<andrewrk> TheLemonMan, yep - errors are hooked up though if you do a C compile error
<andrewrk> so it's a start
<andrewrk> tgschultz, that makes a lot of sense - that's the idea of the GeneralPurposeDebugAllocator I've been working on. windows will gain leak detection, use-after-free protection, etc
<andrewrk> as well as consistent behavior and performance across platforms
<Sahnvour> I'm under the impression that one might use DirectAllocator and expect it to be page-oriented, which it is not on windows
<Sahnvour> don't know if that makes much difference in practice though
<andrewrk> I agree Sahnvour
<ysgard> I'm trying to write up an SDL2 program using zig, and came across a problem I don't know how to solve. I'm using IMG_Load from SDL_Image.h, which returns an *SDL_Surface. To do that I have to @cImport the SDL_Image.h.
<ysgard> But that results in a conflict, because SDL_Image itself imports SDL.h, and that results in a duplicate declaration of SDL_Surface that zig's c import doesn't like
<ysgard> error: expected type '[*c].cimport:2:11.struct_SDL_Surface', found '[*c].cimport:3:13.struct_SDL_Surface'
<ysgard> if (c.SDL_SetColorKey(sprite_surface, true, 0x000000ff) != 0) {
<scientes> ysgard, there should be include guards in SDL.h
<scientes> you could add #pragma once to the top of SDL.h
<scientes> oh i c, so they are identical, but c import is namespacing them too much
<ysgard> There's an #ifndef SDL_h_ guard
<ysgard> in SDL.h
<andrewrk> ysgard, how many @cImports do you have in your entire project?
<ysgard> Just two
<andrewrk> specifically the recommendation to have 1
<ysgard> const c = @cImport({ @cInclude("SDL2/SDL.h"); });
<ysgard> const img = @cImport({ @cInclude("SDL2/SDL_Image.h"); });
<scientes> that would result in differn't types
<scientes> for the same type
<ysgard> Oooooh I see, thank you scientes!
<andrewrk> ysgard, here's a pattern I follow for this: https://github.com/andrewrk/tetris/blob/master/src/c.zig
<ysgard> Oh, interesting - so if you don't assign the result of @cImport, the c functions just get imported into the local namespace?
<scientes> no, for that you would have to use use
<scientes> oh that is what that does
<ysgard> Sorry, that's what I meant, if you use 'use' instead of assigning the result
<ysgard> That's nice, I don't have to preface everything as long as I'm willing to make sure nothing collides
<ysgard> (if I understand this right, sorry, total zig newbie here)
<ysgard> Thank you andrewk :)
<scientes> yep that is correct
<andrewrk> ysgard, that's correct. please note it's generally recommended to avoid `use` except for situations like this where you want to manage the public API of a file
<ysgard> Gotcha!
<Sahnvour> andrewrk, what's the current state of linking against C library on windows ? I get a bunch of undefined symbols for __imp_GetCurrentProcessId and friends
<andrewrk> Sahnvour, I thought that was working and tested
<andrewrk> are you talking about --library c?
<Sahnvour> yes
<Sahnvour> via a build.zig
<andrewrk> the self hosted compiler links libc and gets built on windows during the test suite
<Sahnvour> maybe I missed something, I just added my_exe.linkSystemLibrary("c); is that correct ?
<andrewrk> yes
<Sahnvour> maybe my code using the c_allocator wants symbols that are not used by the self hosted compiler, thus hiding an issue?
<tgschultz> you know those bugs where the symptoms tell you it's something really stupid you did, but you can't see it and spend a lot of time narrowing down exactly where it is only to find out it is indeed really stupid and you just wasted half an hour? I've just fixed about four of those. I think I may want to give up programming for today.
<scientes> tgschultz, I've run into a bunch of those with LLVM
<scientes> specifically not including a datalayout
<Sahnvour> if only it was always just half an hour tgschultz
<shritesh> andrewrk: The generated langref looks very different on my machine. Does it depend on anything linux specific?
<andrewrk> Sahnvour, hmm, I'm interested in helping you troubleshoot this but right now I need to go do some chores
<Sahnvour> no problem
<shritesh> Found it. It runs the linux assembly example and breaks the remaining of the document layout
<tgschultz> at least the results were worth it: https://pastebin.com/8h6KMntg
wilsonk has quit [Read error: Connection reset by peer]
wilsonk has joined #zig
halosghost has quit [Quit: WeeChat 2.4]
<shritesh> turns out, it skips it but doesn't close the opened tags. Submitted a PR to fix that.
<squeek502> andrewrk, still planning on streaming today?
<andrewrk> squeek502, if I have time it will be at 19:00 EST (1.5 hrs from now)
<squeek502> sounds good :)
slugm has joined #zig
slugm has quit [Remote host closed the connection]
<tgschultz> TheLemonMan, andrewrk, confirming the issue with comptime random.shuffle seems to be resolved now.
<TheLemonMan> awesome, let's hope there are no more bugs in the shr implementation heh
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
<yawryck> Hi guys! Can I bother you with a noob question?
wilsonk has quit [Ping timeout: 255 seconds]
<shritesh> yawryck: Many of us are beginners too. How can we help?
<yawryck> I want to get a feel of the language
<shritesh> Have you tried it out yet?
<yawryck> I want to solve some typical problems from sites such as topcoder
<yawryck> usually the easiest way to deal with them is to receive input from stdin
<yawryck> but I'm struggling to parse input
<yawryck> is there a scanf equivalent in zig?
<yawryck> something that could read an integer
<shritesh> There's std.fmt.parseInt
<shritesh> I don't think you can directly read an int. You need to first read a string and parse it
<andrewrk> have a look at some of the advent of code solutions
<yawryck> I saw some but they pasted the input inside a variable
<andrewrk> looks like Hejsil's has a scan feature that he used
wilsonk has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
<yawryck> thanks guys!
<yawryck> they look more complicated than they could be but I think I could adapt them to something simpler
<yawryck> memory allocators look like an overkill for this type of things. I'll try to use the stack hoping that will make my life easier
<shritesh> yawryck: std.heap.FixedBufferAllocator will let you do exactly that.
<scientes> it gives space in the .bss segment
fengb has joined #zig
fengb has quit [Client Quit]
Barabas has quit [Ping timeout: 256 seconds]
ysgard has quit [Ping timeout: 240 seconds]
<andrewrk> I don't think I'm going to have time to stream today, still cleaning for my out of town guest
<emekankurumeh[m]> Sahnvour: are you using msvc or mingw?
<Sahnvour> msvc
Sahnvour has quit [Quit: Leaving]