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/
mikdusan has joined #zig
<THFKA4> sounds good, thanks
utzig has quit [Ping timeout: 240 seconds]
<THFKA4> opened 3412
<THFKA4> will try to do it, but no promises. don't think it's urgent either way.
doublex_ has joined #zig
doublex has quit [Read error: Connection reset by peer]
waleee-cl has quit [Quit: Connection closed for inactivity]
doesntgolf has joined #zig
hryx has quit []
doublex has joined #zig
doublex_ has quit [Ping timeout: 240 seconds]
doublex has quit [Read error: Connection reset by peer]
doublex has joined #zig
doublex has quit [Read error: Connection reset by peer]
doublex has joined #zig
dimenus has quit [Ping timeout: 252 seconds]
doublex has quit [Read error: Connection reset by peer]
n_1-c_k has quit [Read error: Connection reset by peer]
doublex_ has joined #zig
n_1-c_k has joined #zig
doublex_ has quit [Read error: Connection reset by peer]
doublex has joined #zig
jicksaw has quit [Quit: ZNC is kill]
jicksaw has joined #zig
_whitelogger has joined #zig
doublex has quit [Ping timeout: 265 seconds]
doublex has joined #zig
gruebite has joined #zig
<gruebite> yo
chemist69 has quit [Ping timeout: 246 seconds]
chemist69 has joined #zig
<andrewrk> hi gruebite
doesntgolf has quit [Read error: Connection reset by peer]
mahmudov has quit [Ping timeout: 240 seconds]
<gruebite> man, i was here a while ago. i'm glad to see zig progressing
ltriant has quit [Quit: leaving]
mahmudov has joined #zig
n_1-c_k has quit [Read error: Connection reset by peer]
n_1-c_k has joined #zig
tdc has quit [Ping timeout: 268 seconds]
<mq32> hey
<mq32> is there a way to check if a file exists?
<mq32> (except for "open the file for reading, then close it again")
ave_ has joined #zig
tdc has joined #zig
<lunamn_> mq32: std.fs.File.access?
<mq32> lunamn_, yeah i found that as well, but it's a bit clunky to use
<mq32> var exists = blk: { std.fs.File.access(x) catch break :blk false; break :blk true; };
<mq32> is my current approach
<lunamn_> sounds about right, handling wise
tdc has quit [Ping timeout: 250 seconds]
<mq32> hey, anyone here experienced with raw socket programming in windows? i'm having some weird behaviour here…
allan0 has joined #zig
abbiya has joined #zig
utzig has joined #zig
squeek502 has joined #zig
<telemach> What's the common technique in Zig for situations where I would do a closure in other languages?
abbiya has quit [Quit: abbiya]
waleee-cl has joined #zig
<mq32> telemach, it depends on what you use the closure for
<mq32> if you only pass the closure "down" the callstack, just use a function pointer + context-variable
<mikdusan> mq32: here's one without the block -> `var exists = if (std.fs.File.access("/etc/passwd")) |_| true else |_| false;`
<mikdusan> and on a related note this works but i'm not sure if it's a syntactic bug: `var exists = if (std.fs.File.access("/etc/passwd")) true else |_| false;`
<mq32> hmm
<mq32> i tried something pretty similar
<mq32> maybe i messed it up :D
<mikdusan> well the docs say "The else and |err| capture is strictly required" so i think the former is correct:
<mikdusan> *latter
<mikdusan> `var exists = if (std.fs.File.access("/etc/passwd")) true else |_| false;`
<mq32> yeah, i tried to use it with if(call) { … } else |err| { }
<mq32> i think ^^
<mq32> but gonna try it later with your if-else-solution
<mikdusan> yeah as soon as braces are used the expression-as-result is no longer available
samtebbs has joined #zig
<mq32> yeah but the code i want to do is just
<mq32> if(exists(path)) { stuff(); }
<mikdusan> then `if (std.fs.File.access("/etc/passwd") { stuff(); } else |_| {}`
<mikdusan> forgot a paren there.
<mq32> yeah that should work
<mq32> i can't try it right now, still at work :D
samtebbs has quit [Ping timeout: 240 seconds]
doublex has quit [Read error: Connection reset by peer]
doublex has joined #zig
<daurnimator> mq32: checking if a file exists is almost always wrong
<daurnimator> mq32: what are you going to do with it if it *does* exist?
<daurnimator> and what are you going to do if it doesn't?
<mq32> i load 3d models (foo.obj) and if a (foo.ppm) exists, i'm going to load that file
<mq32> if not, i'm just not even trying to load the file, because it will fail anyways
n_1-c_k has quit [Read error: Connection reset by peer]
tdc has joined #zig
n_1-c_k has joined #zig
<mq32> and daurnimator, i knew that question would emerge :D
<fengb> You can just try loading the file. Checking existence adds a superfluous slow step that may be a race condition — e.g. if the file was deleted after the existence check
<mq32> yeah
<mq32> but i don't like the semantic of "hey, let's load that image file, but it failed with 'file does not exist'" so that's totally okay
<daurnimator> you should just open both files, and then process them
<mq32> and what if the one does not exist ;)
<mq32> it's a legal state that only one of the two files exist
<daurnimator> then don't continue with the 2nd?
<mq32> the semantics i want to do is:
<mq32> load_file_a();
<mq32> if(file_b_exists()) load_file_b();
<fengb> But if b gets deleted after your check, that logic fails anyway
<fengb> And if you properly check it, then it’s redundant
<mq32> <fengb> But if b gets deleted after your check, that logic fails anyway
<mq32> this is something i don't consider in this usecase
<mq32> it's not some "dynamic" data or something but static
<mq32> and the whole program will be broken if one of those files is deleted
<mq32> but yeah, the double check is probably redundant
<fengb> File systems are concurrent unless you guarantee the OS can’t run anything?
<mq32> yeah, true
<mq32> but: who does: "./program &; rm *"
<fengb> I’ve accidentally removed my user directory while running programs before... I got bigger things to worry about but at least my Zig program won’t crash :P
<daurnimator> I more often run into permissions issues
<daurnimator> e.g. the file exists, and is writable, but not by the correct user/program
<daurnimator> or something like that
<daurnimator> its better to just *do the thing* and get an error, then try and see if it might error
<daurnimator> cause it could error anyway...
<fengb> Tangential aside: what would the OS do if the physical device is unreadable?
<daurnimator> There are very few legitimate reasons to use access(); one example is checking to see if a file is in cache or already built.
<mq32> hm
<daurnimator> fengb: depends how unreadable. sometimes EIO. sometimes kill process. sometimes kill whole kernel.
<daurnimator> also depends on how you were reading. e.g. read() can return EIO but reading from an mmap()d file can't
mahmudov has quit [Read error: Connection reset by peer]
<mq32> it's really time to have to autogen docs
<mq32> will be much easier to find out what errors can actually happen
<mq32> does File.open() distinct between "does not exist", "is a directory" and "permission errors"?
<daurnimator> mq32: I would expect it propagates an errno-mapped value
<daurnimator> i.e. yes. but I haven't checked.
<fengb> Autogen errorsets is so amazing. Probably my biggest problem with Go just magically solved
<mq32> hm, yeah. i could check that
<mq32> but for now it's okay, is just a temporary solution anyways :D
<fengb> Andrew’s latest tweet shows inferred errorsets
FireFox317 has joined #zig
<mq32> yeah, it's awesome :)
* mq32 is quite hyped already
tdc has quit [Quit: Leaving]
mahmudov has joined #zig
MajorLag has joined #zig
programi1 has joined #zig
\u has joined #zig
via_ has joined #zig
jicksaw has quit [Ping timeout: 268 seconds]
fgenesis has quit [Ping timeout: 268 seconds]
tgschultz has quit [Ping timeout: 268 seconds]
via has quit [Ping timeout: 268 seconds]
SquantMuts has quit [Ping timeout: 268 seconds]
Sahnvour has quit [Ping timeout: 268 seconds]
josuah has quit [Ping timeout: 268 seconds]
meowray has quit [Ping timeout: 268 seconds]
tdeo has quit [Ping timeout: 268 seconds]
mmx870 has quit [Ping timeout: 268 seconds]
programisto has quit [Ping timeout: 268 seconds]
johnLate has quit [Ping timeout: 268 seconds]
tralamazza has quit [Ping timeout: 268 seconds]
johnLate_ has joined #zig
FireFox317 has quit [Ping timeout: 250 seconds]
MajorLag is now known as tgschultz
mmx870 has joined #zig
Sahnvour has joined #zig
jicksaw has joined #zig
FireFox317 has joined #zig
kenaryn has joined #zig
<kenaryn> Hello, do you know whether there are design patterns interesting to apply in Zig or is the language too immature and versatile at the moment to adopt one?
<andrewrk> mq32, whether a file exists is not a simple boolean
<mq32> andrewrk, can you elaborate that?
ave_ has quit [Quit: Connection closed for inactivity]
<andrewrk> there are a few ways it can fail, such as running out of file descriptors. then you don't know whether the file exists or not
<andrewrk> for example, say a user has a file called "config.ini" and inside it says `no_delete_home_folder=true` but the default is to delete home folder. now your program wants to check if there are any configuration settings. you access config.ini and get ENFILE, and incorrectly conclude the file does not exist, and wipe the home directory
<andrewrk> generally, you should directly try to open the file and then handle failure, rather than checking whether it exists
<mq32> yeah it's just weird that "having an error" is a expected thing
<mq32> because it will be the default then
<andrewrk> what will be the default?
<mq32> error.FileNotFound would be my default case then
<mq32> because having the file is optional
<mq32> it's just unusual for me to have an error case as the default :D
<andrewrk> ah I see. but from the perspective of how you're interacting with the operating system, this is perfect. you want exactly that syscall, and you want to handle the file not found response
<mq32> yeah
\u is now known as meowray
mahmudov has quit [Remote host closed the connection]
via_ is now known as via
gruebite has quit [Ping timeout: 240 seconds]
<FireFox317> andrewrk: regarding #3410, do you also want the parameter name of a type inside the docs? Ex: std.mem.compare: `fn compare(T: type, var, var) var`
<andrewrk> FireFox317, I'm not sure I understand the question
<andrewrk> btw if you're looking for a more straightforward issue, this one is good: https://github.com/ziglang/zig/issues/3404
<Snektron> The docs work is looking good
porky11 has joined #zig
<andrewrk> thanks :)
<Snektron> One thing i always miss in langauge documentation tools is the ability to navigate to a page without looking it up
<Snektron> for example zigdocs.ext/std/os/File.html would be useful
<THFKA4> member VS + MSDN?
<THFKA4> you could click class names and go straight to docs, done decades ago
<Snektron> but that's something different right, that is on the site self and is just about adding cross references
<andrewrk> Snektron, key strokes to get to fs.File docs: `sFile<enter>`
<andrewrk> I'm not sure I understand what you're suggesting
<Snektron> I see how the url's are generated now, and the actual path of the item is encoded in the url
<Snektron> What i mean is with for example Doxygen, url's are just random gibberish
<Snektron> and it makes it really hard to find stuff
<FireFox317> andrewrk: see the images in this gist: https://gist.github.com/FireFox317/f1bc2b64055a8eea09cc15ce5d673db3. I implemented part of #3410 and as you can see all the functions in mem have `T: type`, but that T is maybe unnecesarry?
<andrewrk> FireFox317, the T is useful, there could be multiple type params
<dingenskirchen> I'm running into some errors while trying to build master branch. make runs without complaint until the "Linking CXX executable zig0" stage, at which point ld errors out with a bunch of missing references to names under clang::, even though I did install the relevant clang-devel package. All version requirements mentioned in README match.
porky11 has quit [Ping timeout: 250 seconds]
<andrewrk> dingenskirchen, can you double check that your cmake command succeeded?
porky11 has joined #zig
<dingenskirchen> ah, thanks. It says "Could NOT find CLANG (missing: CLANG_LIBRARIES)". Guess that explains how make didn't find them either
marmotini_ has joined #zig
<FireFox317> andrewrk: Okay, but we probably also want the parameter names of the generic parameters right? I.e: `fn compare(T: type, lhs: var, rhs: var)`
<andrewrk> FireFox317, yes
<andrewrk> the names are even more useful in this case
rjtobin has joined #zig
<dingenskirchen> where does cmake expect the files to be? the package I have places them under /usr/include/clang and /clang-c.
<andrewrk> I see that you're using a package. what OS/distribution is that?
<andrewrk> the cmake build script uses llvm-config to find clang. that appears to not be working on your system for some reason
<dingenskirchen> I'm on openSUSE Tumbleweed. Currently using the packages from https://build.opensuse.org/project/show/devel:tools:compiler because LLVM9 is not in the main repos yet
<n_1-c_k> I might have trouble similar to dingenskirchen's, in that I have an llvm-config-9 but not an llvm-config. This is debian unstable. My build fails with "undefined reference to symbol 'exp2f@@GLIBC_2.27'".
<andrewrk> your options are: (1) fix your system package so that llvm-config works (2) build llvm/clang 9 from source (3) (if applicable) improve zig's cmakelists.txt to support this system
<andrewrk> n_1-c_k, zig looks for llvm-config-9 before llvm-config
<n_1-c_k> andrewrk, oh, my hope flickers! I'll paste my build failure...
Akuli has joined #zig
<andrewrk> n_1-c_k, this looks like your system failing to put -lm on the command line for linking libc. seems to be a debian issue
<n_1-c_k> andrewrk, thanks
doublex has quit [Ping timeout: 250 seconds]
<andrewrk> FireFox317, I'm going to make an adjustment to struct field printing, to have it do a more "verbose" style for fields, and print all the doc comments rather than just the first line
<andrewrk> stratact, I haven't forgotten about you
<FireFox317> Ah jup indeed, markdown instead of shortDescMarkdown
<andrewrk> FireFox317, these docs are starting to look pretty good, eh?
<FireFox317> Yeah for sure! A lot of progress is being made. I almost finished #3410
<andrewrk> one thing I haven't figured out how to do: when you are scrolled down, then click a link, and then use the browser's back button, everything works *except* the page is scrolled to the top instead of the previous location
<FireFox317> Ah jup haha, that is a funny one
<andrewrk> I think it's actually the browser's fault
<andrewrk> it should be activating the previous scroll position *after* laying out the DOM onhashchange
mahmudov has joined #zig
<FireFox317> andrewrk: How much effort should I put into trying to get the parameter names of var args functions?
<FireFox317> I'm currently at the point where it renders all the function parameter names, including paramter names for `var` types.
<andrewrk> FireFox317, the names of parameters should be attached to the astNode objects
<andrewrk> because they will be the same for all generic instantiations
<andrewrk> similar to how doc commects are emitted in the dump
<andrewrk> this will make the names available for generic functions as well as the instantiations
<FireFox317> Hmm yes, that makes sense. Currently I implemented it by adding the name to the "args" object in the types array, but I will try to do what you suggested
<FireFox317> Then maybe the name of struct field should also come from the astNode objects?
<andrewrk> yes, for the same reason
<andrewrk> I'll do instantiated generic functions soon
<FireFox317> Okay, I will try to change that
<dingenskirchen> so, I've identified the first problem: my package, for some reason, consolidates all clang9 .so's into a single file, so Findclang.cmake couldn't pick the individual ones up. Circumvented that by pointing the file at libclang-cpp.so instead.
<andrewrk> FireFox317, struct types should include a "src" for the decl_node, which can be used to find field names, and field src nodes. but the "type" of struct fields still needs to be given as part of the type, because this can be different
<dingenskirchen> as "first problem" indicates, there's more where this came from: while zig0 links successfully now, I'm hitting a snag when it tries to build libuserland: "CommandLine Error: Option 'mc-relax-all' registered more than once!"
<dingenskirchen> This is apparently related to having more than one libLLVM linked to your file (https://github.com/ziglang/zig/issues/67) but I'm not linking statically, and lld only lists one instance of lLLVM
<FireFox317> Yes indeed, thanks for the clarification
<mikdusan> dingenskirchen: there is a WIP for handling the 3 major flavors of llvm library builds:
<dingenskirchen> >If CLANG_LINK_CLANG_DYLIB (available since clang 9) is ON, libclang-cpp.so instead of libclang*.so will be linked. It currently does not work because zig_cpp/libembedded_lld_lib.a has global constructors that conflict with libclang-cpp.so
<dingenskirchen> Seems as if I need to build from source then since it's built as one .so for me
<dingenskirchen> Thank you for the link!
<andrewrk> dingenskirchen, zig's cmake script should be improved to support libclang-cpp.so, if there is a reliable way to detect it
doublex has joined #zig
<mps> is there vim syntax plugin for zig somewhere
<mps> andrewrk: thanks, I should look one dir up, sorry for asking such obvious thing
<andrewrk> no worries :)
Ichorio has joined #zig
lunamn has joined #zig
lunamn_ has quit [Ping timeout: 240 seconds]
marmotini has joined #zig
marmotini_ has quit [Ping timeout: 240 seconds]
clktmr has joined #zig
<mq32> hey
<mq32> is there a way to get the "current zig build from CI" without having to parse https://ziglang.org/download/ ?
<mq32> thanks <3
<mq32> now i can hack myself a "zig-update" script :)
<andrewrk> FireFox317, how's it going over there? I want to make sure I'm not clobbering you
<FireFox317> andrewrk: I will show you my progress in a PR, one moment.
<FireFox317> Just want to add one more thing quickly
<andrewrk> FireFox317, I'm thinking we display the functions in the functions section as normal syntax, you know, like `fn foo(arg: type) type`, but still in table format with short desc to the right
<andrewrk> this will simplify some of the js logic and probably look better anyway
<FireFox317> Yes indeed, the same as how it is rendered on the page that you will go to when you click on the function name
<andrewrk> FireFox317, thanks, I'll try not to step on your toes - let me know when it's ready for merge
Akuli has quit [Quit: Leaving]
marmotini has quit [Remote host closed the connection]
<FireFox317> andrewrk: regarding my PR, it means that I can get rid of the AstNode *decl_ref in FnTypeParamInfo, right?
wootehfoot has joined #zig
<andrewrk> FireFox317, yes
<andrewrk> if you have to change anything in that header type, it's a smell
<andrewrk> not necessarily wrong, but worth double checking
<andrewrk> *in that header file. specifically for the purposes of doc generation
<FireFox317> Jup, sounds logical :)
<stratact> andrewrk: I appreciate it. I'm just doing other hobbies atm.
<FireFox317> andrewrk: I don't get it. Is it about the struct fields or the parameter names?
benjamin-l has joined #zig
<andrewrk> FireFox317, both struct fields and parameter names need to be solved the same way: via ast nodes
moo has joined #zig
wootehfoot has quit [Ping timeout: 240 seconds]
benjamin-l has quit [Ping timeout: 268 seconds]
<FireFox317> Hmm, I thought I am doing that right now. Because I only store the "src" as a index in the astNodes array
<nrdmn> Why would I use (*const [1]u8)(&x)[0..]) instead of ([_]u8{x})[0..]?
<andrewrk> FireFox317, anal_dump_struct_field is called from every type instance, causing the src field to be emitted N times. instead this src field should be part of the ast node for containers, causing it to be emitted 1 time
utzig has quit [Quit: leaving]
<andrewrk> nrdmn, the latter is creating a new storage location, the former is referencing an existing storage location
<andrewrk> where is the [_]u8{x} array stored? it depends on context
<andrewrk> FireFox317, consider the ArrayList items field
<andrewrk> if you have ArrayList(i32) and ArrayList(u64), there is only 1 ast node they share for the field
<andrewrk> having both of them refer to it is redundant data
<nrdmn> andrewrk: What's a "storage location" in this context? I assumed the compiler would compile both variants into the same instructions
<andrewrk> nrdmn, array literals have to live somewhere in memory. the former construct does not have an array literal
<FireFox317> andrewrk: Okay, yes. I think I get it now
ltriant has joined #zig
<nrdmn> hmm.. okay, thanks
<andrewrk> FireFox317, the struct type -> decl_node -> [field_node]. field_node -> {name, docs}
<andrewrk> it's equivalent for parameter names
<andrewrk> and parameter doc comments
<FireFox317> And the former is what I'm doing now, and the latter is how it should be right?
<FireFox317> No, nvm
<andrewrk> this thing is all one concept: " struct type -> decl_node -> [field_node]. field_node -> {name, docs}"
<andrewrk> this would be a lot easier with whiteboard markers
<FireFox317> Hahah, jup indeed
doublex has quit [Ping timeout: 240 seconds]
kenaryn has quit [Quit: WeeChat 2.3]
doublex has joined #zig
doublex_ has joined #zig
doublex has quit [Read error: Connection reset by peer]
<FireFox317> andrewrk: So how do I then get this AstNodeContainerDecl to go into the astnodes list? Because currently it is not in there..
<andrewrk> FireFox317, in anal_dump_type() for ZigTypeIdStruct, you need to add jw_object_field(jw, "src"); with AstNode *decl_node; from the struct ZigTypeStruct
doublex_ has quit [Read error: Connection reset by peer]
<andrewrk> this will cause the node to be referenced, causing it to go into the astNodes list
doublex has joined #zig
<andrewrk> so instead of each field pointing to each field node, only the struct itself points to the struct decl node
<andrewrk> and then the struct ast node can list its field ast nodes
<andrewrk> make sense?
<andrewrk> you'll need to add that in anal_dump_node, look for NodeTypeContainerDecl and list the field nodes
<FireFox317> Thanks for the help man, appreciate it! I'm learning a lot. I'm pretty sure I understand it now xD
<andrewrk> no problem, it's easy to help when I can see your WIP code
porky11 has quit [Ping timeout: 245 seconds]
<FireFox317> So the struct ast node gets an array called "fields" with field_node objects in there. Like this?: "fields" : [ { "name" : "name", "docs": "some docs"}, {....} ] Or: "fields" : [<index_into_astnodes_pointing_to_a_field_ast_node>, ...]
<andrewrk> FireFox317, the latter
moo has quit [Read error: Connection reset by peer]
<FireFox317> But that means that I have to call anal_dump_node_ref from within anal_dump_node, and that causes problems because anal_dump_node_ref can change the size of the astnodes list right?
<FireFox317> Wait, i just have to be sure that I first add the fields to the astNodes list and then the struct ast node
<andrewrk> FireFox317, it's no problem, the list can grow while iterating over it
<andrewrk> I don't think you need to do anything special
<FireFox317> Hmm, I think that jw_int isn't working in anal_dump_node
<FireFox317> This assert is failing:
<FireFox317> assert(jw->state[jw->state_index] == JsonWriterStateValue);
<andrewrk> FireFox317, have a look at the stack trace, you probably forgot jw_array_elem or jw_object_field
<mps> andrewrk: we have zig in alpine https://git.alpinelinux.org/aports/tree/testing/zig
<andrewrk> nice work mps
<andrewrk> mps, this makes me want to solve https://github.com/ziglang/zig/issues/2084
<mps> thanks, but you helped me a lot
rjtobin has quit [Ping timeout: 250 seconds]
<andrewrk> the alpine package might actually be OK if it is dynamically linking musl
<mps> and daurnimator which PKGBUILD I looked
dimenus has joined #zig
<mps> well, it is in testing for now, and patches are welcome
<FireFox317> andrewrk, THANKS! Damn, I forgot the jw_array_elem and was stuck on that for half an our :(
<FireFox317> hour*
<andrewrk> FireFox317, this is an instance where the stack traces actually point exactly to the problem :)
<andrewrk> for semantic analysis it can be a lot more complicated
Ichorio has quit [Ping timeout: 264 seconds]
<FireFox317> Okay, I'm gonna call it a day. Thanks for the help andrew! It turned out a bit harder than expected, but I think I can finish it tomorrow :)
Ichorio has joined #zig
FireFox317 has quit [Ping timeout: 264 seconds]
FireFox317 has joined #zig
FireFox317 has quit [Remote host closed the connection]