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 quit [Quit: Segmentation Fault]
<wilsonk> is there a way to override a "std" imported definition by a newer defiinition in a locally imported file? ie. I have a definition that overrides the sleep funcition and just want my new definition to take precedence, but I keep getting an override error
<wilsonk> I know I could just rename my function but I actually have dozens of these errors and don't want to rename everything!
mnoronha_ has joined #zig
<Xe> how do I turn an int64 into a string kind of like the libc function itoa?
shritesh has joined #zig
<shritesh> Xe: You can write to a buffer with fmt.bufPrint
<shritesh> ...and for the other way around, it's fmt.parseInt
<Xe> shritesh: is a buffer some u8 slice?
<shritesh> Here's an example that might be useful for interfacing with strings and parsing ints across wasm boundary: https://gist.github.com/shritesh/315f002a4481c33131b7be8942d94b2e
<shritesh> Xe: It's a u8 slice where it can write to.
mnoronha_ has quit [Ping timeout: 240 seconds]
<Xe> shritesh: +1 thanks
<shritesh> That's what the gist does too +1 ;)
<Xe> shritesh: how would I create a u8 slice of n bytes where n is some dynamically derived value?
<shritesh> That requires dynamic allocation.
<shritesh> do you know the upper bound?
<Xe> say 2048 bytes as the max
<shritesh> Create a max_len sized array and slice into it using array[0..n]
<Xe> like this? var arr: [2048]u8;
<shritesh> Yes. Prolly set it as undefined
<shritesh> Also, writing a WasmAllocator that uses `mem.grow` and `mem.size` wasm instructions is on my todo list.
mnoronha_ has joined #zig
<Xe> shritesh: how do I convert an i32 to a usize?
mnoronha_ has quit [Ping timeout: 268 seconds]
<Xe> ah, @intCast(usize, i32val)
<shritesh> Probably @intCast or @bitCast https://ziglang.org/documentation/master/#Builtin-Functions
mnoronha_ has joined #zig
<scientes> Xe, you may, or may now, want to do a @bitCast(u32) first
<scientes> *may not
<scientes> or @bitCast(usize depending
<scientes> Xe, it is just about twos-complement
<scientes> what you want to happen with signed numbers
<Xe> a negative number should never be able to get there
<scientes> then use @intCast(usize
<Xe> :+1:
mikdusan has quit [Ping timeout: 246 seconds]
mikdusan has joined #zig
hio has joined #zig
<wilsonk> scientes: you around?
<scientes> wilsonk, yeah, why?
<wilsonk> just wondering if there is a way to use a specific definition in an @imported file over another @imported file?
<scientes> yes!
<wilsonk> ie. it is defined twice so I keep getting an error
<scientes> just use two two @cImport()s
<scientes> to keep the conflicting headers separate
<wilsonk> so they will namespace uniquely?
<scientes> that's something c cant do
<scientes> see the const c
<scientes> c is just a variable
<scientes> but in zig variables are namespaces
<wilsonk> hmm, but then I would have to access via a unique namespace, yes? so @import("std/os/time") as time and then time.sleep and @import("./time") as mytime and then mytime.sleep?
<scientes> yep
<wilsonk> ok. I get that but the problem I am having is that I am @importing a file from someone else's library that confilicts with dozens of definitions in std. So now I would have to go through dozens (maybe over a hundred) calls and namespace all of them? UGH
<scientes> nono
<scientes> you don't "import as"
<scientes> you import to a variable
<scientes> and they can be nested, like std.debug.assert()
<scientes> you only have to namespace the new conflicting library
<scientes> const comeguyslibrary = @cImport({@cInclude("awesomelib.h");})
<wilsonk> oh, I think I see what you are saying
<scientes> and that cImport exists seperate from any other, it starts with a clear environment (even absent of libc)
<wilsonk> right, ok. Let me try that way
<scientes> it will still have __X86_64__ defined, but that is about it
<scientes> actually it probably doesn't
<scientes> home/shawn/git/zig/s.zig:7:23: error: container '.cimport:2:11' has no member called '__X86_64__'
<scientes> yeah that is probably a bug
<scientes> cause libraries depend on that
<scientes> oh i spelled it wrong
<wilsonk> heh
<scientes> yeah zig is just using clang now
mnoronha_ has quit [Ping timeout: 264 seconds]
ltriant has joined #zig
mnoronha_ has joined #zig
mnoronha_ has quit [Ping timeout: 250 seconds]
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
ManDeJan has joined #zig
<ManDeJan> Can I forward a pack of parameters to another function?
<ManDeJan> In C++ you have pack expansion, is there something similar in Zig?
<hryx> ManDeJan: I don't think there is
<ManDeJan> I think I could make a helper function that has a giant switch case for every length of argument pack
<ManDeJan> But that is not desirable :P
<hryx> ManDeJan: search found Josh talking about param expansion here: https://github.com/ziglang/zig/issues/522#issuecomment-336458612
<hryx> although I don't think it's quite what you were describing
<hryx> ManDeJan: I believe what you want will be solved by the anonymous container proposal: https://github.com/ziglang/zig/issues/208#issuecomment-440504195
<hryx> aka the not tuples proposal
<ManDeJan> Thanks!
<ManDeJan> Interesting discussions
marmotini_ has joined #zig
ltriant has quit [Quit: leaving]
mnoronha_ has joined #zig
mnoronha_ has quit [Ping timeout: 246 seconds]
mnoronha_ has joined #zig
mnoronha_ has quit [Ping timeout: 252 seconds]
marmotini_ has quit [Remote host closed the connection]
hobomatic has joined #zig
marmotini_ has joined #zig
marmotini_ has quit [Read error: Connection reset by peer]
marmotini_ has joined #zig
marmotini has joined #zig
marmotini_ has quit [Ping timeout: 268 seconds]
hobomatic has quit [Ping timeout: 256 seconds]
hobomatic has joined #zig
mnoronha_ has joined #zig
hobomatic has quit [Ping timeout: 256 seconds]
very-mediocre has joined #zig
marmotini_ has joined #zig
halosghost has joined #zig
marmotini has quit [Ping timeout: 252 seconds]
<very-mediocre> and not in line with the no-shadowing principle of zig
marmotini_ has quit [Ping timeout: 246 seconds]
marmotini_ has joined #zig
<shritesh> That looks like expected behavior as structs are namespaces too. OTOH, I wonder if there is no way to access the outer function from the inner namespace.
mnoronha_ has quit [Ping timeout: 255 seconds]
<tgschultz> see ralted issue #1836
marmotini_ has quit [Ping timeout: 240 seconds]
<very-mediocre> tgschultz: I think I disagree with the proposed remedy in #1836. shritesh is right that structs have like a namespace aspect
<very-mediocre> the real problem imho is calling such functions from within the struct using the unqualified name
<very-mediocre> even in high level languages you would write `this.func()`
<very-mediocre> rather than the ambiguous `func()`
ManDeJan has quit [Ping timeout: 255 seconds]
<tgschultz> the issue is a bit different in #1836, in that both names are in the same namespace.
<very-mediocre> yeah you're right, my bad
<very-mediocre> confused it with something i read in #678 which seems to be the relevant place
mnoronha_ has joined #zig
halosghost is now known as halos
halos is now known as halo
wink_ has joined #zig
bketelsen has joined #zig
<very-mediocre> good catch
<tgschultz> isn't that the same as #705?
<daurnimator> very-mediocre: your earlier one seems a copy of https://github.com/ziglang/zig/issues/678 to me (now that files are structs).
<daurnimator> tgschultz: yes. though the info in there seems incorrect now.
<tgschultz> andrewrk: I'm pretty sure this should error because we're evaluating compileError on the result of a runtime expression, but I think it could error with an error indicating that as the problem instead of erroring with the compileError statement... if that makes sense: https://gist.github.com/tgschultz/236290d87d6103fdd111e5c46ab645ce
very-mediocre has quit [Ping timeout: 256 seconds]
TheLemonMan has joined #zig
scientes has quit [Ping timeout: 252 seconds]
<TheLemonMan> any idea on how to have a function use the C ABI without being marked with `export`?
scientes has joined #zig
<TheLemonMan> and do you have any pointers about C-string <-> slice conversions?
<scientes> TheLemonMan, its just an array
<scientes> oh it isn't
<scientes> TheLemonMan, probably use mem.cpy()
mnoronha_ has quit [Ping timeout: 268 seconds]
<daurnimator> TheLemonMan: 'extern'?
<TheLemonMan> yeah, I mixed up `extern` and `export`... but I just wanted to affect the ABI and not the visibility
Ichorio has joined #zig
niftynei has quit [Quit: ZNC - http://znc.in]
niftynei has joined #zig
<wilsonk> TheLemonMan: can you just force that with the stdcallcc convention? Is that what you mean? "stdcallcc fn myfunc() void {}"
Akuli has joined #zig
<TheLemonMan> I guess so, the documentation is a bit hand-wavy about what it does
<daurnimator> oh we only support stdcallcc? what about all the other calling conventions out there?
meheleventyone has joined #zig
<wilsonk> I am not sure if that is the only one supported, but it should be trivial to add the others (I think), as LLVM outputs the specified convention in bitcode.
<wilsonk> I haven't looked at how Zig is handling things though
<wilsonk> hmm...looks like there is some commented out code for 'coldcc' and 'nakedcc' conventions, so perhaps ask Andrew? Might be some pragmatic reason that was removed and other conventions aren't supported
<wilsonk> https://github.com/ziglang/zig/issues/462 might answer your questions TheLemonMan
redj has quit [Read error: Connection reset by peer]
very-mediocre has joined #zig
<very-mediocre> daurnimator: "your earlier one seems a copy of https://github.com/ziglang/zig/issues/678 to me (now that files are structs)." -- indeed.
meheleventyone has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
very-mediocre has quit [Quit: Leaving]
very-mediocre has joined #zig
mnoronha_ has joined #zig
<TheLemonMan> wilsonk, more or less, I guess @export() can be used to hide the function
Jenz has joined #zig
Ichorio has quit [Read error: Connection reset by peer]
mnoronha_ has quit [Ping timeout: 255 seconds]
Ichorio has joined #zig
Zaab1t has joined #zig
marmotini_ has joined #zig
hobomaic has joined #zig
mnoronha_ has joined #zig
Jenz has quit [Ping timeout: 252 seconds]
mnoronha_ has quit [Ping timeout: 246 seconds]
mnoronha_ has joined #zig
very-mediocre has quit [Ping timeout: 256 seconds]
scientes has quit [Ping timeout: 245 seconds]
TheLemonMan has quit [Quit: "It's now safe to turn off your computer."]
Zaab1t has quit [Remote host closed the connection]
jjido has joined #zig
Akuli has quit [Quit: Leaving]
Ichorio has quit [Ping timeout: 264 seconds]
<shritesh> andrewrk: I'm taking a stab at #2274. Is it acceptable to introduce a new field (lib_name or wasm_module_name) to ZigFn?
<andrewrk> yes it is, but don't we already have lib_name?
<andrewrk> hmm it's in the TldFn
<shritesh> Yeah, I don't think codegen has access to it
<andrewrk> that represents the "top level declaration"
<andrewrk> do what you need to do, and I'll help clean up the branch before we merge
halo has quit [Quit: WeeChat 2.4]
<shritesh> Thanks. After this we will be in parity with (and IMO have a better semantics than) C and Rust for WASM
<andrewrk> great
knebulae has joined #zig
mnoronha_ has quit [Ping timeout: 246 seconds]
mnoronha_ has joined #zig
mnoronha_ has quit [Ping timeout: 250 seconds]
gamester has joined #zig
gamester has left #zig ["Leaving"]
<shritesh> andrewrk: PR is ready
<andrewrk> I see it
<andrewrk> shritesh, did you inspect the LLVM IR with --verbose-llvm-ir to make sure it looks good?
<shritesh> Yep. `attributes #1 = { nobuiltin nounwind "wasm-import-module"="wasm" }`
<andrewrk> rgeat
<andrewrk> looks good, merged!
<shritesh> Thanks!!!
<shritesh> Now all three of the WASI environments (wasmtimer, wasmer and lucent?) can run wasi binaries created by Zig out of the box.
<shritesh> wasmtime*
marmotini_ has quit [Remote host closed the connection]
dembones has joined #zig
<hobomaic> cool!
hobomaic is now known as hobomatic
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<andrewrk> nice work shritesh
<shritesh> Thank you. Next comes the WasmAllocator
<andrewrk> I realized yesterday that zig can now be use to make node modules
<andrewrk> node supports wasm, zig supports wasm, just run your zig build before npm publish
<shritesh> Yes!!!
<hryx> dang
<andrewrk> it's going to be a low-volume week for me as far as commits to zig - I'm writing my talk for next tuesday at philly ETE conference - which will be recorded
<hryx> awesome!
mnoronha_ has joined #zig
<mikdusan> 👍
<shritesh> nice
mnoronha_ has quit [Quit: Ping timeout (120 seconds)]
mnoronha_ has joined #zig
mnoronha_ has quit [Ping timeout: 250 seconds]
<shritesh> Should I not be able to do `const foo = extern fn bar(i32) i32;` at the top level and call `foo(0)` in some other function later?
<andrewrk> right now function declarations are not expressions, but you can do `extern fn bar(i32) i32; const foo = bar;`
<andrewrk> actually I think that `extern fn bar(i32) i32` is an expression that evaluates to a `type` which is the function prototype
<shritesh> hmm
<andrewrk> I do think there may be some room for improvement here
<andrewrk> the meaning of `extern` is overloaded right now
<hryx> shritesh: here is an old and weird and long proposal I made about func decls as expressions https://github.com/ziglang/zig/issues/1717
<hryx> in case you're curious
<shritesh> @"llvm.wasm.memory.size.i32"(0) is a gnarly looking function name :D
<andrewrk> this issue will help: https://github.com/ziglang/zig/issues/661
<shritesh> alright
<Xe> shritesh: thank you for making zig's webassembly support better, you are actively making it easier for me to do amazingly satanic things based on unix first principles
<shritesh> Xe: My goal is to never have to write JS or C ever again and I'm contributing my part
<Xe> it's appreciated
<andrewrk> shritesh, we're going to have to talk about that - we can leave that in for now but it's an accident than you can reference any LLVM builtin with @"" syntax
<andrewrk> there are ways that could be problematic
<shritesh> Definitely.
<shritesh> Xe: ^_^
<andrewrk> I won't pull the rug out from you though, if I change it I'll make sure your use case is still solved
<shritesh> we need to make sure nvptx (CUDA) works too.
<andrewrk> good point
ltriant has joined #zig
<Xe> are the LLVM intrinsics absolutely needed to emit a `grow_memory` instruction?
shritesh has quit [Read error: Connection reset by peer]
<andrewrk> I believe so
shritesh has joined #zig
<shritesh> Both clang and rustc have builtins to do that
<andrewrk> Xe, btw the crash you found, is because support for disabling error return traces in debug mode is not implemented, but it's required for wasm
<andrewrk> we just need to implement a couple of llvm ir things and then it will be fixed
<shritesh> Ah. So release mode should fix it
<andrewrk> yeah - though I would use the work "workaround" :)
<shritesh> Yes. I think I saw rust do something with backtraces. Lemme check
<andrewrk> shritesh, the problem is in get_safety_crash_err_fn, it assumest the first parameter is the error return trace. we simply have to check if that's disabled and omit that parameter
<andrewrk> let me see if I can just fix it real quick
<shritesh> Gotcha. I was looking at how or if rust does backtraces in wasm
<andrewrk> I don't think we pass that. the reason error return traces don't work is lack of the return address builtin
<andrewrk> that's also why the stack traces of GeneralPurposeDebugAllocator wouldn't work on WASI either
<shritesh> ah
<andrewrk> but yeah if rust gets stack traces working on web assembly targets, that would be a good clue to see if there could be a way
<shritesh> So much in the was{m,i} world is in flux and undocumented. I have way too much W3C CG meeting minutes, commit history and github discussion in the last few days lol
<shritesh> *read way
<Xe> it's really version 0