ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
<jfo> andrewrk: want to help me with a function signature?
<jfo> (or anybody :) )
<jfo> basically:
<jfo> var out: [5][5]u8 = undefined;
<jfo> var blocks = [5][5]u8{ "11111", "22222", "33333", "44444", "55555" };
<jfo> cp.transpose_blocks(out, blocks, 5);
<jfo> what would the signature of `transpose_blocks` be?
<andrewrk> jfo, yeah, give me an hour to travel home
<jfo> no worries, I'll be in bed by then but I'll email you !
Guest12636 is now known as dimenus
jfo has quit [Quit: Lost terminal]
<dimenus> andrewrk, i may need your assistance figuring out what a valid test would be in this case
<dimenus> not sure I have a handle on the test system yet
<andrewrk> ok
<andrewrk> dimenus, does the pattern in test/parsec.zig make sense?
<andrewrk> the input is c code, and the other args are strings expected to be found in the output
<dimenus> so they utilize the cinput you're saying?
<dimenus> some look like an equivalency test
<dimenus> or something of that osrt
<dimenus> eg, cases.add("noreturn attribute"
jfo has joined #zig
<GitHub128> [zig] thejoshwolfe pushed 1 new commit to master: https://git.io/vFK7f
<GitHub128> zig/master 1f28fcd Josh Wolfe: parsec supports C NULL to pointer implicit cast
brend0n has quit [Ping timeout: 268 seconds]
<GitHub150> [zig] thejoshwolfe pushed 1 new commit to master: https://git.io/vFK7N
<GitHub150> zig/master 57cd074 Josh Wolfe: parsec supports C comma operator
<dimenus> zig is so much caster in release mode
<dimenus> holy moley
<dimenus> *caster = faster
<dimenus> should have done a release build awhile ago
<andrewrk> dimenus, ha, how much?
<andrewrk> oh, that's mostly from llvm
<dimenus> no objective measurements at this point
<dimenus> but it's a bit
<dimenus> i spose i should consider that I'm at home now on much faster pc
<dimenus> back to the test, sorry I'm still slightly confused
<dimenus> andrewrk, if you and josh are on skype/discord/etc could i just join you for a second?>
<dimenus> that would probably be faster
jfo has quit [Ping timeout: 268 seconds]
jfo has joined #zig
cenomla has joined #zig
jfo has quit [Ping timeout: 248 seconds]
<GitHub183> [zig] andrewrk closed pull request #610: Fixed duplicate decl detection for typedefs/enums (master...parsec) https://git.io/vFKzm
<GitHub81> [zig] andrewrk pushed 4 new commits to master: https://git.io/vFKdl
<GitHub81> zig/master 98e3c79 dimenus: Fixed duplicate decl detection for typedefs/enums
<GitHub81> zig/master df07361 Andrew Kelley: Merge branch 'parsec' of https://github.com/dimenus/zig into dimenus-parsec
<GitHub81> zig/master 0373286 Andrew Kelley: add test case for previous commit
dimenus has quit [Quit: Leaving]
<GitHub75> [zig] thejoshwolfe pushed 1 new commit to master: https://git.io/vFKNi
<GitHub75> zig/master 4c2cdf6 Josh Wolfe: parsec supports more compound assign operators
<GitHub188> [zig] thejoshwolfe pushed 1 new commit to master: https://git.io/vFKxj
<GitHub188> zig/master 012ce14 Josh Wolfe: parsec supports post increment/decrement with used result
cenomla has quit [Quit: cenomla]
arBmind has joined #zig
_dev_zero has quit [Remote host closed the connection]
_dev_zero has joined #zig
_dev_zero has quit [Remote host closed the connection]
_dev_zero has joined #zig
arBmind has quit [Quit: Leaving.]
arBmind has joined #zig
arBmind has quit [Read error: Connection reset by peer]
arBmind has joined #zig
jfo has joined #zig
jfo has quit [Quit: Lost terminal]
dimenus has joined #zig
arBmind has quit [Ping timeout: 268 seconds]
<dimenus> i really like how in zig i can take a c pointer that I know the length of and just make a real array out of it
<ltr_> dimenus: still getting the errors of duplicate declarations
<ltr_> im going to post a comment in the issue
<dimenus> what header are you parsing?
<ltr_> uv.h
<ltr_> from libuv
<ltr_> im at work right now
<dimenus> ok
sparris has quit [Quit: Page closed]
arBmind has joined #zig
<dimenus> i can't replicate this on llvm6, going to test with 5 now
arBmind has quit [Quit: Leaving.]
<ltr_> may be is a bug on clang, dont know
arBmind has joined #zig
<andrewrk> ltr_, I think this is fixed, it works for me after dimenus's fix
<dimenus> yeah i can't replicate this at all
<dimenus> either windows or gnu
<dimenus> **msvc or gnu
<ltr_> uh
<dimenus> did you do a rebase pull or are you working off your own changes?
<ltr_> yes
<ltr_> i have no changes
<ltr_> let me recheck
<andrewrk> ltr_, I think we might have to implement unions for it to work
<dimenus> i'm still not getting duplicates in the output
<andrewrk> yeah I think the duplicates is fixed
<ltr_> 0.1.1.5029322a
<ltr_> thats the last version right?
<andrewrk> yes
<ltr_> can you compile github.com/aindigo/ziguv ?
<andrewrk> yes, except there is a bug in the code, that makes it segfault, and to fix the bug, we need union support
<dimenus> ah that's the bug
<ltr_> with the master version?
<dimenus> those are typedef interfaces
<dimenus> which i don't have working yet
<andrewrk> oh
<andrewrk> do you have a small test case that shows the problem for typedef interfaces?
<dimenus> yes i can build one
<ltr_> andrewrk: are you compiling with master? i cant get that proyect compiled
<andrewrk> ltr_, yes
<ltr_> weird im still getting duplicate definition, and i have the last version of master
<andrewrk> I'm trying to think of why that could be but I can't think of anything
<ltr_> wich version of libuv do you have?
<andrewrk> 1.15.0
<dimenus> andrewrk, you're building on linux while ltr_ is building on mingw
<dimenus> so all of those types are windows com interfaces
<dimenus> which don't exist on linux
<ltr_> no
<ltr_> im building on linux
<dimenus> hmmm
<dimenus> i may need to fire up a linux vm then
<ltr_> this damn ubuntu , im installing libuv from apt-get, the version i have is really old
<dimenus> use arch/antegros
<dimenus> or i think andrewrk uses nix
<ltr_> its the libuv version
<ltr_> now i have 1.10
<ltr_> 1.15*
<andrewrk> by the way, josh and I last night have the deflate function from zlib translating into zig
<andrewrk> it looks horrendous
<ltr_> lol why
<andrewrk> there are a bunch of automatic cleanups we can add
<ltr_> that was by hand?
<andrewrk> but, here's a start, if you're trying to port zlib, zig can get you partway there
<andrewrk> this is `zig parsec deflate.c`
<ltr_> andrewrk: quick question , how can i add a path in build.zig so zig can find libs?
<ltr_> to add a path to the linker to find libs
<andrewrk> ltr_, I believe we have builder.addLibPath(path: []const u8)
<andrewrk> but I think we should add that function to each build artifact, instead of globally
<ltr_> can you pass --library-path when doing zig build?
<andrewrk> no
<andrewrk> but you can make that an option using the build API
<ltr_> ok
<ltr_> another question who can i see where zig is looking for libs?
<ltr_> for the linker?
<andrewrk> --verbose-link
<ltr_> it is not finding anything in /usr/local/lib
<andrewrk> we don't look in /usr/local/lib by default I think
<ltr_> nor usr/lib
<ltr_> lld: error: unable to find library -luv
<andrewrk> ltr_, are you using zig build or calling zig directly? if the former, use --verbose
<ltr_> both
<ltr_> ill use verbose
<andrewrk> that tells you the zig command it's running. then you might find it easier to modify that command line and try different things
<ltr_> ok now i was able to compile ziguv
<andrewrk> ltr_, what did you have to change?
<ltr_> zig+libuv, but yeah core dump
<andrewrk> I left you a github comment
<ltr_> --library-path /usr/lib
<ltr_> i dont know where is looking for libs
<ltr_> verbose just tellme the command line it uses to invoke lld
<andrewrk> I need to revisit the build system. right now it's a proof of concept but as you can see all the use cases aren't handled well
<andrewrk> but it's important to the zig project, we want to improve it
<ltr_> yes but its really flexible as it is, you can add more use cases as diferent build.zig templates
<ltr_> imo
<andrewrk> yes I think the potential is good
<ltr_> you want to remove the & and then add it on the next line
<ltr_> that comment you leave in my code
<ltr_> you mean not to define loop as a pointer and add & to the uses?
<andrewrk> you're using the uv API wrong
<andrewrk> giving them an undefined pointer, but you want to give a valid pointer to (probably stack) memory
<andrewrk> but you can't since zig translates uv_loop_t as an opaque type
<ltr_> i get it
<ltr_> i cant alloc a uv_loop_t with zig
<andrewrk> right
<andrewrk> that's a problem with our parse-c code
<andrewrk> which I think is due to not having unions
<ltr_> what if i use jemalloc, should i be able to use it?
<ltr_> i thought that uv_loop_init was going to do the allocation, but right the user is responsable to clean their pointers
<andrewrk> the problem is not where the memory is, the problem is that zig was unable to translate uv_loop_t type
<dimenus> what part of the type is zig unable to translate?
<andrewrk> you can see warnings with `zig parsec --verbose-cimport foo.h`
<andrewrk> the warnings tell you what C code we couldn't translate
<andrewrk> unions would be the next biggest win
<dimenus> you've got that on your list right?
<andrewrk> yes
<andrewrk> we already have all the logic done, because enums contain a union in the implementation
<andrewrk> just need to do the work
arBmind has quit [Quit: Leaving.]
<andrewrk> dimenus, what was the other thing besides unions that I could look at to unblock you?
<dimenus> andrewrk, #462
<andrewrk> ah right. OK yeah that's a high prio issue too
<dimenus> the dll works internally without ever calling LLVMSetDLLStorageClass
<dimenus> but on truely 'exported' functions, we need to call that to make it visible in windows
<dimenus> there needs to be a way to differntiate between just an externally linked function and an exported function
<andrewrk> ah right
<dimenus> on linux i don't think that distinction matters
<dimenus> a symbol is a symbol
<dimenus> andrewrk, so this is interesting
<dimenus> i have a sample build.zig file that if i run zig build on cmd it just crashes
<dimenus> but if i run it in powershell within vs code
<dimenus> it gives me a proper error message
jfo has joined #zig
<andrewrk> hmm
<andrewrk> what kind of crash?
<dimenus> its the build system crashing
<dimenus> or doing something windows doesn't like at least
jfo has quit [Ping timeout: 255 seconds]
PV has joined #zig
<dimenus> andrewrk, trying to use 'addIncludePath()' within build.zig but it doesn't look like the list gets relayed to the compiler
<andrewrk> dimenus, probably a bug in std/build.zig
<dimenus> yeah i'm looking through it
<dimenus> but it's dense
<dimenus> lol
<andrewrk> LibExeObjStep represents a zig build target - an object, a library, or an executable. it has a reference to the builder struct
<andrewrk> TestStep represents running `zig test`. it has a reference to the Builder struct also
<dimenus> yep, the dir is populated on the LibExeObjStep
<dimenus> but not in makeZig
<dimenus> list is empty there so it gets dropped somewhere along the way
<andrewrk> we should add include_paths local to LibExeObjStep
<andrewrk> maybe you want 2 different objects to have 2 different include paths
<andrewrk> gdb lets you set a memory watch point. if you think the include_paths list is changing, you can but a memory watchpoint on e.g. the length field, then run the code, then the debugger will break when that memory address is changed
<andrewrk> I don't know if msvc supports this
<dimenus> all build.zig files end up calling build_runner.zig correct?
<andrewrk> it's the other way around - zig build compiles build_runner, which imports the user's build.zig
<dimenus> ah
<andrewrk> line 1 of std/special/build_runner.zig
<dimenus> so we codegen build_runner every time the compiler is called?
<andrewrk> every time you do `zig build`
<andrewrk> that's why it's slow
<andrewrk> but we can speed it up a lot
<andrewrk> we also codegen builtin.o and compiler-rt.o every time we make a library or executable (including a build.zig executable)
<andrewrk> those can be cached, and almost never change
<andrewrk> and then also if you don't modify build.zig, the build executable can be cached
<andrewrk> and then I also want to do other speed improvements to the compiler
<dimenus> do we store type information in exes at all?
<andrewrk> only debug info
<andrewrk> in general, types are a compile-time concept only
jfo has joined #zig
_dev_zero has quit [Remote host closed the connection]
_dev_zero has joined #zig
_dev_zero has quit [Remote host closed the connection]
_dev_zero has joined #zig
arBmind has joined #zig
<dimenus> andrewrk, i found the issue in build.zig
<dimenus> line 1209 in std/build.zig
<dimenus> loops over the builder rather than the step
<dimenus> is that intended? some of the loops are of the builder some are of the step
<andrewrk> dimenus, I think our line numbers aren't synced up
<andrewrk> I'm looking at 5029322aa127cd20a08740
<dimenus> ah, yeah i didn delete something else
<dimenus> for (builder.include_dirs.toSliceConst()) |include_path| {
<andrewrk> some stuff is global, for example looking at environment variables for C include paths, that makes sense
<andrewrk> yeah that's for global env vars
<andrewrk> but we should also add step-local include_paths
<dimenus> but, addIncludePath is defined on the LIbExeObjStep
<dimenus> not the builder
<andrewrk> oh
<andrewrk> dimenus, we add those to the line in self.appendCompileFlags
<andrewrk> oh it's only called from makeC
<andrewrk> yeah you found the problem
<andrewrk> nice
<dimenus> w/ clang you would pass -I building individual objects no?
<dimenus> so to me that would mean it would be most common to use it on LibExeObjStep
andrewrk has quit [Ping timeout: 260 seconds]
andrewrk has joined #zig
<andrewrk> I agree
<andrewrk> that should be the normal way to use the API
<jfo> base64.decode ignores newlines, is that correct?
<jfo> oooooh and
<jfo> I keep wanting to do something like
<jfo> const s:usize = %%file.getEndPos();
<jfo> var buf:[s]u8 = undefined;
<jfo> and I get `error: unable to evaluate constant expression`
<jfo> which I am not sure I fully understand
<GitHub59> [zig] andrewrk pushed 1 new commit to master: https://git.io/vFPUs
<GitHub59> zig/master 7a74dba Andrew Kelley: add docs for std.base64
<andrewrk> jfo, ^ I added docs to answer your question
<andrewrk> for the second thing: var buf:[s]u8 = undefined; riddle me this: where is the memory of buf stored?
<jfo> is this a comptime thing?
<jfo> also does that mean I need to sanitize my base64 input by stripping out invalid characters?
<andrewrk> did you figure out where the memory is stored?
<jfo> no
<jfo> :\
<dimenus> Microsoft has always considered VLAs in C to be a hack :P
<dimenus> although they should know a thing or two about hacks.....
<andrewrk> jfo, if you put something at global scope, it's in global static memory - allocated at *compile-time*. your .exe on disk has space for the memory
<andrewrk> if you put something in a function, it's on the stack
<andrewrk> if you call a function such as allocate() then it's on the heap, at least conceptually
<jfo> I was going to say stack but I thought that was too simple! bah
<andrewrk> stack frame sizes for each function are computed at compile-time. it would be a security vulnerability to increase the stack pointer by a runtime-known quantity
<andrewrk> so, knowing all this
<jfo> and file size is a runtime quantity
<andrewrk> how many bytes can zig use for the stack frame of your function, which has var buf: [s]u8 in it?
<jfo> limited only by the filesize which would be limited by the os if at all
<jfo> ... is a `test` block global scope?
<jfo> (mem wise, I know functionally it is not)
<andrewrk> test block is function scope
<andrewrk> each test is a function
<jfo> that is what I thought
<andrewrk> I don't know what you're talking about re: limits
<andrewrk> but zig can't compute a stack frame if the array length isn't known at compile time
<jfo> I just mean that if `s` is the filesize, then `s` could be as big as a file could be
<andrewrk> typically the entire stack is ~10MB
<dimenus> stack size on most platforms isn't very large, so you wouldn't say want to open a 10MB file on the stack
<dimenus> stack is for smaller buffers
<jfo> well, that's not what I'm trying to do, I just didn't understand the error message
<andrewrk> yes, and more importantly, it's for buffers for which the size is known to be bounded
<jfo> and now I do! ty
<jfo> also re: base64 fwiw zig's decoding implementation differs from the spec, such as it is: https://tools.ietf.org/html/rfc4648
<jfo> "Implementations MUST reject the encoded data if it contains
<jfo> characters outside the base alphabet when interpreting base-encoded
<jfo> data, unless the specification referring to this document explicitly
<jfo> states otherwise. Such specifications may instead state, as MIME
<jfo> does, that characters outside the base encoding alphabet should
<jfo> simply be ignored when interpreting data ("be liberal in what you
<jfo> accept"). Note that this means that any adjacent carriage return/
<jfo> line feed (CRLF) characters constitute "non-alphabet characters" and
<jfo> are ignored.
<jfo> :
<jfo> "
<andrewrk> that can be a separate function, to validate the data
<dimenus> jumping the stack guard page was a problem on linux recently
<andrewrk> dimenus, related: https://github.com/zig-lang/zig/issues/530
<jfo> andrewrk: want an issue on base64?
<andrewrk> sure
<jfo> ok will do. I think it's worth deciding whether you want to validate and reject or accept liberally and ignore
<dimenus> hah, goodbye alloca
<dimenus> #225
<dimenus> Microsoft just uses a heap allocator behind the scenes if the alloca size is too high
<dimenus> which introduces its own problems........
<andrewrk> yeah that's not a perfect solution
<dimenus> i like that you gave most of the std library the ability to accept another allocator behind the scenes
<dimenus> that's pretty cool
<dimenus> i did get my build.zig working btw, it's definitely slower than just invoking the compiler directly
<andrewrk> yeah, there's a lot of room for improvement
<andrewrk> we just need to do the work
<andrewrk> I want to be very careful about the caching and not have any false positives
cenomla has joined #zig