karrick_ has quit [Remote host closed the connection]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 244 seconds]
nglicophik has joined #zig
nglicophik has quit [Ping timeout: 248 seconds]
rjtobin has joined #zig
kristoff_it has joined #zig
belgin has joined #zig
<belgin>
why hello there
<belgin>
does zig work without llvm?
<diltsman>
Zig uses LLVM as the backend to do optimization and code generation.
kristoff_it has quit [Ping timeout: 246 seconds]
<belgin>
are you planning on implementing zig's own backend?
<diltsman>
I doubt that there are plans for that as that is a huge undertaking to make one that generates good code. andrewrk would know better than I do.
<hryx>
hi belgin, welcome. right now zig depends on LLVM 100%. zig may add additional backends that LLVM doesn't have in the future -- that has been discussed a bit
<diltsman>
Besides, using LLVM as a backend means that code generation is supported for any target that LLVM has.
<belgin>
ok thanks
<hryx>
belgin: if you have a use case for not using LLVM, of course please do share -- the community is often very interested in addressing less common cases
<laaron>
hi, zig not use system libc on my archlinux default. I found argument `--libc [file]`, but what is the file format?
<emekankurumeh[m]>
you can use `zig libc > libc.txt` to get a libc file
<belgin>
hryx, llvm is slow
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
<belgin>
i guess it's too early to consider compilation speed at this point, but i suggest it's a nice thing to keep in mind
<hryx>
belgin: slow compared to what?
<hryx>
additionally LLVM supports a large number of targets, which is an important goal for zig
<belgin>
i was compiling a small zig program and it took like 2 seconds on debug, even with the cache thingy
<belgin>
but maybe a 1mloc program will also take 2 seconds, in which case it's ok
<hryx>
fast debug builds are a goal of zig's. do you have a link to your program (and maybe your hardware)?
<belgin>
that's cool! let me see if i can reproduce it
<belgin>
oh yeah, i've been meaning to ask, do i need visual studio to run zig on windows?
<hryx>
good question - I think emekankurumeh[m] can help answer that. there has been a lot of work this week on mingw-w64 (I'm not totally sure if that would affect it)
<laaron>
thanks, i got a syslibc.cfg, but when use `--libc syslibc.cfg`, seems no affect, the executable binary still a static linked.
<belgin>
laaron, have you tried putting the .so of the libc in there?
<andrewrk>
laaron, what is your system libc?
<laaron>
glibc, install via package manager
<andrewrk>
belgin, no you do not need msvc to run zig on windows
<belgin>
thanks
<laaron>
belgin, no custom libc.so, it in default search path /usr/lib/libc.so, i think
<belgin>
hryx, i can't reproduce it, sorry for wasting your time
<belgin>
it's under a second now
GrooveStomp has joined #zig
<andrewrk>
laaron, can you test something for me? `llc --version | grep Default`
<andrewrk>
llc would be provided from an llvm package
<andrewrk>
but now I wonder if arch has patched llvm to make this so, or if a source build would do the same thing
<andrewrk>
laaron, and `zig targets | grep native` ?
kristoff_it has joined #zig
<laaron>
x86_64 (native)
<laaron>
linux (native)
<laaron>
gnu (native)
<laaron>
2.17 (native)
<laaron>
x86_64-linux-gnu (native)
<andrewrk>
ok zig is correctly identifying glibc as your target. you must be saying that 2.17 is incorrect, yes?
<andrewrk>
hmm no you said that the binary is statically linked. I don't understand how this would be
<andrewrk>
oh, are you linking against libc? zig does not link against libc by default
<andrewrk>
can I see your build.zig or your zig command line?
<laaron>
when zig will link against libc, this maybe the problem, my code is simple empty, `const std = @import("std"); pub fn main() void {}`
<andrewrk>
laaron, this program has no dependency on libc
<andrewrk>
if you wish to force it, you may do so with `--library c`
kristoff_it has quit [Ping timeout: 244 seconds]
<laaron>
i see, thanks. another error when use `--library c`
<laaron>
full command: `zig build-exe --libc ./syslibc.cfg -dynamic --verbose-link --verbose-cc --cache off --library c a.zig`
<laaron>
lld: error: unable to find library -lgcc
<hryx>
belgin: hey no worries at all
kristoff_it has joined #zig
<andrewrk>
laaron, the --libc advice was incorrect
<belgin>
hey, andrewrk, i just wanted to say your talk at the recurse center has been very inspirational for me, thank you for opening my eyes
<andrewrk>
sorry, I mean, you do not need --libc
<andrewrk>
also don't pass -dynamic or --cache off
<andrewrk>
why are you overriding all these defaults? the defaults are good
<andrewrk>
`zig build-exe a.zig` is correct
kristoff_it has quit [Ping timeout: 258 seconds]
<andrewrk>
if you want it to be linked against libc for some reason (why?), `zig build-exe a.zig --library c`
<andrewrk>
thanks belgin
<andrewrk>
there is a second talk
<andrewrk>
if you're interested
<belgin>
i know, i haven't seen that one yet
<laaron>
yeap, works. only `--libc` and `--library c` conflict
<laaron>
so i think it's mean `--libc` for custom libc, `--library c-or-other` for system libraries, right?
<andrewrk>
correct
rjtobin has quit [Quit: Leaving]
_whitelogger has joined #zig
kristoff_it has joined #zig
<wilsonk__>
andrewrk: how do you emit .ll code again? -mllvm -emit-llvm doesn't seem to work
kristoff_it has quit [Ping timeout: 268 seconds]
<wilsonk__>
hmm, or maybe you aren't on anymore...kinda late Friday over there ;)
<daurnimator>
andrewrk: hmm? why not the shortening feature? (it's in the same message as the title, so its not like it's an extra message)
<wilsonk__>
oh, nvm I suppose -emit-llvm-ir is the correct option. my bad
<daurnimator>
fgenesis: why do you get pinged?
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 248 seconds]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 245 seconds]
GrooveStomp has quit [Ping timeout: 272 seconds]
MH026 has quit [Remote host closed the connection]
<hryx>
the URL shortening is both unexpected and perhaps a minor privacy violation: it sends your text to a third party service (is.gd) automatically without consent. I think users on chat could be rightly surprised by that
<via>
stepping through with gdb, i can see the prints doing std.mem.copy's of the bytes, and the outstream pos gets incremented, the outstream's slice len gets incremented, but nothing gets put into the slice but nulls
<marijnfs>
maybe resetting the stream resets everything?
andersfr has joined #zig
<marijnfs>
just guessing
<via>
it just sets pos=0, but it doesn't matter, i do the printing after the reset
<via>
i mean by the time it gets to the warn()ing of the slice, its just null bytes. even stepping through the print() function, once its done with output(), the slice bytes are null (but len incremented)
<mikdusan>
`ret.buf = undefined` then what does `ret.buf[0..]` mean?
<[[]]>
ffddr: Title "const TypeId = @import(\"builtin\").TypeId; fn init_zeroes(comptime T: type) T - Pastebin.com" Shortened < https://is.gd/2olPjx >
<Tetralux_>
via: ret.buf is undefined isn't it?
Tetralux has quit [Ping timeout: 248 seconds]
Tetralux_ is now known as Tetralux
<via>
but its an array, its just the bytes that are undefined, right?
<Tetralux>
via: Ah yeah.
<via>
i suppose i'm also asking, is this the right way to instantiate that struct -- buf is allocated as part of the struct on the stack of the caller to init(), right?
<via>
it has a stack-looking address in gdb
<Tetralux>
Yeah - [N]T arrays are inline to the struct.
<Tetralux>
So @sizeOf(Console) should be > 1024.
<ffddr>
maybe there is some better way to get zero initialzied struct in comptime?
<Tetralux>
ffddr: Give all fields a default value of zero and then use const x = T{};
<Tetralux>
i.e: Same as C++... :")
<ffddr>
Tetralux unfortunately its C struct came from .h file, some of them are quite large
<Tetralux>
If you use an editor with multiple cursors, you could match the ':' for each field and type it that way.
<Tetralux>
Or, you can memset.
<Tetralux>
You can't memset a Zig struct apparently because of hidden safety stuff
<Tetralux>
But you can an extern struct I believe
<via>
i'm not really sure that the undefined assignments are the issue here -- i was using more or less the same process with a buf and SliceOutStream successfully before moving it into a struct
<ffddr>
Hm, could I? I tried but it always crashed the compiler - I guess its because I cant use pointers on comptime
<Tetralux>
via: Yeah - I don't think it should be.
<Tetralux>
via: But it's not clear to me what the problem is from a cursory glance.
<via>
i'll gist some gdb output to make the weirdness more clear
<andrewrk>
andersfr, you can also send patches to the mailing list. the "retard" comment is not appreciated
<husho>
can zig compiler compile c++ code?
<Tetralux>
husho: With libclang IIRC.
<andrewrk>
husho, I have not put testing into compiling C++ code but it should work
<[[]]>
via: Title "gist:15ebaf533a677cb4058da45d63cedbf8 · GitHub" Shortened < https://is.gd/QcM0Yk >
Ichorio has quit [Ping timeout: 264 seconds]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ffddr has quit [Remote host closed the connection]
<mikdusan>
via: i think issue is that init uses a stack var for console and outstream stores a slice (pointer) to that buffer
<via>
i was assuming that the struct (and thus buf?) was allocated on the caller's stack frame, though if not that would make sense
<via>
whats the best way to do what i'm doing? using an allocator doesn't feel like it should be necessary, i want it stack allocated
<via>
that also seems like a pretty easy thing to do without realizing it if so, it'd be great if the compiler would catch that, thats very unsafe
kristoff_it has joined #zig
<mikdusan>
i can't answer for best; need to find a place after init() to initialize outstream. 2-stage init. or if your process() is a 1-time gig, put it before outstream.reset()
very-mediocre has quit [Read error: Connection reset by peer]
<andrewrk>
andersfr, good question. there is currently not but that is now planned
<andrewrk>
andersfr, in general @import("builtin") has all the information about the target, and it's missing that information, but should be added
<andrewrk>
you can see the contents with `zig builtin`
<andersfr>
I think it should be possible to determine the level of support as well. Pretty sure LLVM exposes this in its target information
kristoff_it has quit [Ping timeout: 245 seconds]
<andrewrk>
what does that mean, level of support?
<via>
mikdusan: i guess i'm confused as to why that would be different -- the space for both buf and the stream are allocated as part of the struct. init() for the stream isn't actually allocating anything right?
<[[]]>
andrewrk: Title "ability to specify target CPU features · Issue #2883 · ziglang/zig · GitHub" Shortened < https://is.gd/MIMrtS >
<andersfr>
andrewrk looks good
<mikdusan>
via: SliceOutStream stores a pointer to `init()` stack frame `ret.buf`; then it is returned, and the frame vanishes. yet outstream still has that pointer.
<via>
is ret.buf not the Console struct's buf?
<mikdusan>
via: i'll add comment to your gist in a moment...
<via>
i suppose, when you slicify an array, does that do a stack frame allocation of the slice's metadata? and if so, i'm wondering if there's a way to do this in init(). especially since there's room for the slice in the stream in my struct
<via>
i imagine i could directly assign outstream.slice, but that feels super hacky
<mikdusan>
via: i added comment to your orig gist. that's my understanding of the issue.
<via>
yeah, the reason i am structuring it this way in the first place is because of the lack of that feature you're referring to for the time being
<mikdusan>
yup!
<via>
but still, there's got to be a way to do this with just my Console init() function, without having to do the slice creation in main or process
<mikdusan>
i guess you could change the nature of init() and pass it a pointer. so callsite does `var console: Console = undefined; console.init();` as now it has a pointer to its storage.
<via>
is there any plan for the compiler to be aware of (and error for) returning pointers to stuff allocated on the stack like that?
<mikdusan>
i think there is an issue discussing that. let me see if i can find it
<[[]]>
mikdusan: Title "result location: ability to refer to the return result location before the `return` statement · Issue #2765 · ziglang/zig · GitHub" Shortened < https://is.gd/kTk4g6 >
<[[]]>
via: Title "gist:5601df999e08953ab65d597db4cb792f · GitHub" Shortened < https://is.gd/60TbRH >
<via>
e.g. store a slice in the struct too
<mikdusan>
because no matter what, `ret` and field `ret.buf` is on init() stack frame.
<via>
but if i understand the issues, its all about doing copy elision instead of what i assume is currently a memcpy? if not, i don't understand how pretty much half the std library works, its all about returning structs from init
<via>
init isn't returning a pointer to a struct, its returning something that i assume gets copied into the caller's stack allocated struct
<mikdusan>
most of std library init()'s do a `return SomeType { ... };` directly and this is copy-elided. but putting it in a stack var first, then returning that var, you end up copying from stack-var to call-site storage.
<via>
yeah, but point is its still copied
<via>
so i get that its not optimal, but it should still work
<andrewrk>
also note that it probably gets elided in optimized builds, but zig can't guarantee that according to the semantics (until that linked issue is solved)
<mikdusan>
i'm piss poor at explaining things; but maybe this helps. this would be bad: `var buf: [1024]u8 = undefined; var p = &buf; return p;` because we let the address of stack storage escape
<mikdusan>
and that's essentially what is happening with your code
<via>
sure, but in that gist i pasted, "p" is in the struct
<via>
and i'm returning the struct, which should get copied in entirety (buf, _buf, outstream, byte for byte) right?
<via>
oh, i guess _buf would be pointing to the stack allocated one, and not the destination one -_-
<mikdusan>
outstream.slice.ptr will be copied. and so will _buf.ptr
<mikdusan>
right
<mikdusan>
this kind of issue only comes up with you have a self-referential struct
<mikdusan>
*when
<via>
well, bummer. thank you
andersfr has quit []
very-mediocre has quit [Read error: Connection reset by peer]
very-mediocre has joined #zig
kristoff_it has joined #zig
Akuli has joined #zig
kristoff_it has quit [Ping timeout: 268 seconds]
commander has joined #zig
ffddr has joined #zig
<ffddr>
what does this `error: cast discards const qualifier` error means in the context of function pointer cast? I got it from `@ptrCast([*c]lws_callback_function, callback_http);`.
shritesh has quit []
brakmic has quit [Read error: Connection reset by peer]
<andrewrk>
don't cast something to a C pointer
<andrewrk>
there's never a reason to do that
<ffddr>
I need to pass a function pointer to a struct with `callback: [*c]lws_callback_function`
<andrewrk>
you're missing `extern` on your callback function
<ffddr>
`error: expected type '[*c]extern fn(?*.cimport:1:20.struct_lws, .cimport:1:20.enum_lws_callback_reasons, ?*c_void, ?*c_void, usize) c_int', found 'extern fn(?*.cimport:1:20.struct_lws, .cimport:1:20.enum_lws_callback_reasons, ?*c_void, ?*c_void, usize) c_int'`
brakmic has quit [Client Quit]
brakmic has joined #zig
<ffddr>
`p.callback = &@ptrCast(lws_callback_function, callback_http);` <- this compiles, but looks like its pointer of a pointer :(
<ffddr>
`p.callback = @intToPtr([*c]lws_callback_function, @ptrToInt(callback_http));` works (and callback is actually callable), but it doesnt work on compiletime (not sure that it could)
<andrewrk>
[*c]extern fn (...) is a double pointer, which seems like something got translated incorrectly
<andrewrk>
do you know where this type is declared in the .h file?
<[[]]>
ffddr: Title "libwebsockets/vhost.c at 3c1eb97537b41d615f52bc2965c54df661381a6b · warmcat/libwebsockets · GitHub" Shortened < https://is.gd/BuD1ay >
kristoff_it has quit [Ping timeout: 244 seconds]
<ffddr>
Hm, why I can @ptrCast on comptime, but cant @ptrToInt?
<andrewrk>
ffddr, I pushed c0489abcdba to master to fix this
<ffddr>
wow!
<ffddr>
@ptrToInt hack is not needed anymore, but I am still trying to figure out why I cant store pointer as int on comptime? the error: `error: cannot store runtime value in compile time variable`
<andrewrk>
is the pointer address known at comptime?
<andrewrk>
for global variables and functions the address is computed during linking, so it can participate in some comptime expressions, but the integer value is not available for comptime computations
<ffddr>
actually I am not sure, its that extern fn pointer. But I thought that @ptrCast and @ptrToInt have same restrictions
<ffddr>
` p.callback = callback_http;` it works now!
<andrewrk>
good
<fgenesis>
07:30 < daurnimator> fgenesis: why do you get pinged?
<fgenesis>
my client (irssi) triggers a hilight every time the bot sends a message like this
<ffddr>
I think I got the difference between @ptrCast and @ptrToInt - @ptrCast can be somehow lazy evaluated with link-time known variables, while @intToPtr cant, right?
<fgenesis>
maybe because it's this out-of-channel message style, dunno
MH026 has joined #zig
<andrewrk>
ffddr, right
<andrewrk>
well even @intToPtr can get a bit lazier
<ffddr>
wow, it all really works, that callback is actually receiving some network messages! Thanks again :)
<andrewrk>
great, happy hacking
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 258 seconds]
rjtobin has joined #zig
ffddr has quit [Remote host closed the connection]
very-mediocre has joined #zig
andersfr has joined #zig
andersfr has quit [Remote host closed the connection]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 248 seconds]
tgschultz has quit [Ping timeout: 252 seconds]
tgschultz has joined #zig
andersfr has joined #zig
tgschultz has quit [Ping timeout: 268 seconds]
tgschultz has joined #zig
very-mediocre has quit [Read error: Connection reset by peer]
kristoff_it has joined #zig
very-mediocre has joined #zig
andersfr has quit [Remote host closed the connection]
kristoff_it has quit [Ping timeout: 245 seconds]
MajorLag has joined #zig
tgschultz has quit [Ping timeout: 245 seconds]
MajorLag has quit [Ping timeout: 244 seconds]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 246 seconds]
kristoff_it has joined #zig
andersfr has joined #zig
kristoff_it has quit [Ping timeout: 245 seconds]
andersfr has quit [Remote host closed the connection]
very-mediocre has quit [Read error: Connection reset by peer]
andersfr has joined #zig
brakmic has quit [Read error: Connection reset by peer]
<ntgg>
I want to use https://github.com/Hejsil/zig-clap do I just clone the directory to somewhere on my computer then do exe.addPackagePath(...) or is there a better way to do this?
<[[]]>
ntgg: Title "GitHub - Hejsil/zig-clap: Simple command line argument parsing library" Shortened < https://is.gd/ZjG2PJ >
<emekankurumeh[m]>
that's the status quo, but a package manger is planned.
<Tetralux>
I'd suggest you make a vendor dir in your project and put it in there.
nifker was kicked from #zig by ChanServ [Banned: disrespect !T 1w]
andersfr has quit []
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 245 seconds]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 246 seconds]
kristoff_it has joined #zig
jjido has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
ltr- has joined #zig
Cadey has joined #zig
brakmic has quit []
<hryx>
damn. just spent a while working on a struct casting proposal, but I think it's flawed
kristoff_it has quit [Ping timeout: 248 seconds]
<scientes>
heh, it took andrew 3 trys to get something on copy elision
<hryx>
The only real use case I had was supporting int/float literals in anonymous struct literals. But I'm pretty sure that's already inherently covered in that proposal
<hryx>
scientes: what do you mean? you mean iterating over the proposal?
<scientes>
i'm just saying you don't have to succeed every time
<hryx>
true :>
<hryx>
But I think my original idea isn't fundamentally justifiable, nor necessary
<hryx>
Looking back, I think my proposal boils down to "make structs totally duck typed". which is cool, but I don't see a real use case for it yet
<hryx>
and it has tons of problems to work out
<scientes>
ewwww
<scientes>
well I would have to see it
<scientes>
do you mean structs, or stuct literals?
<hryx>
scientes: I'll make a gist and post it here, even though I don't like it anymore
<scientes>
so the unicode literals patch is stalled because the compiler is crashing