<g-w1>
the latter, but the self-hosted backends will have the low hanging optimisations
<daurnimator>
zags: which is to say: for a release build, you'll want to use LLVM with all its optimizations; but for debug builds and while working on the code, use the self-hosted backend
<zags>
yeah that's what I meant by switching to llvm for release builds
<zags>
cool beans
<zags>
there are important relwithdebinfo cases
<zags>
is optimized debug builds something that is/will be supported?
kbd has joined #zig
<daurnimator>
zags: even full release builds have proper debug info
<daurnimator>
(though things might be optimized out etc)
<zags>
oh ok, very nice
<zags>
yeah, we need to get proper backtraces from customers while having them run at full speed
kbd has quit [Client Quit]
<g-w1>
release-small and fast optimises it out?
<daurnimator>
g-w1: huh?
<justin_smith>
what I found counterintuitive is that "--release-debug" isn't the flag for dev builds - with no release flag you get unoptimized and debuggable, --release-debug is when you want optimizations but also debug info
<justin_smith>
or something like that
<daurnimator>
there is no --release-debug.... zig has Debug, ReleaseSmall, ReleaseSafe, ReleaseFast
<justin_smith>
sorry, I misremembered the flag
<daurnimator>
all of them come with debug info
<justin_smith>
daurnimator: right, but when I used --release-safe that was more optimized, and less friendly for debugging, than what I got when I used no --release-foo flag (the default, which I guess is how you get debug)
<daurnimator>
yes. release-safe is "go as fast as you can; but most undefined behaviour will be safely caught"
<daurnimator>
release-fast is "go as fast as you can; I understand that undefined behaviour may lead to nasal demons"
ur5us_ has quit [Ping timeout: 264 seconds]
zags has quit [Quit: leaving]
dddddd has quit [Ping timeout: 256 seconds]
kbd has joined #zig
Xatenev has joined #zig
ur5us_ has joined #zig
dddddd has joined #zig
cole-h has quit [Ping timeout: 246 seconds]
dddddd has quit [Ping timeout: 256 seconds]
nvmd has joined #zig
dddddd has joined #zig
leon-p has quit [Remote host closed the connection]
bitmapper has joined #zig
jukan has joined #zig
jukan_ has quit [Ping timeout: 246 seconds]
dddddd has quit [Ping timeout: 256 seconds]
dddddd has joined #zig
sebonirc has quit [Quit: sebonirc]
earnestly has quit [Ping timeout: 246 seconds]
wilsonk__ has joined #zig
SimonN has quit [Ping timeout: 265 seconds]
jukan has quit [Ping timeout: 264 seconds]
SimonN has joined #zig
dddddd has quit [Ping timeout: 256 seconds]
dddddd has joined #zig
xackus_ has joined #zig
xackus has quit [Ping timeout: 264 seconds]
notzmv has joined #zig
jukan has joined #zig
ur5us has joined #zig
ur5us_ has quit [Ping timeout: 264 seconds]
ur5us has quit [Ping timeout: 264 seconds]
<Xatenev>
hello
<Xatenev>
even with -O ReleaseFast a simple hello world application seems rather big compared to a c hello world
<Xatenev>
can I reduce it even more anyhow or is this the smallest it can get?
<Xatenev>
theres also -O ReleaseSmall but its still rather big.
<Xatenev>
I thought maybe this was due to llvm being used as compiler infrastructure but iirc clang is also using llvm and it also has a quite small binary size
<Xatenev>
it does still seem to have a bunch of strings in there related to runtime checking stuff .. hm
<daurnimator>
Xatenev: are you linking libc? -lc
<daurnimator>
Xatenev: also if you want a really small binary, consider overriding the panic handler
<Xatenev>
daurnimator, thank you, -lc does help a bit, its reducedf from 850 to 650 lines on godbolt
Xatenev has quit [Remote host closed the connection]
jukan has quit [Ping timeout: 260 seconds]
factormystic4 has joined #zig
factormystic has quit [Ping timeout: 240 seconds]
factormystic4 is now known as factormystic
_whitelogger has joined #zig
waleee-cl has quit [Quit: Connection closed for inactivity]
kbd has quit [Quit: My Mac Mini has gone to sleep. ZZZzzz…]
factormystic has quit [Ping timeout: 240 seconds]
gpanders has quit [Ping timeout: 264 seconds]
gpanders has joined #zig
decentpenguin has joined #zig
decentpenguin has quit [Ping timeout: 260 seconds]
sord937 has joined #zig
cole-h has joined #zig
factormystic has joined #zig
jukan has joined #zig
jukan has quit [Ping timeout: 246 seconds]
ur5us has joined #zig
factormystic has quit [Ping timeout: 240 seconds]
cole-h has quit [Ping timeout: 244 seconds]
factormystic has joined #zig
leon-p has joined #zig
ur5us has quit [Ping timeout: 260 seconds]
hnOsmium0001 has quit [Quit: Connection closed for inactivity]
dfrey has quit [Ping timeout: 265 seconds]
earnestly has joined #zig
xackus has joined #zig
xackus_ has quit [Ping timeout: 246 seconds]
siraben has quit [Quit: Bridge terminating on SIGTERM]
dtz has quit [Quit: Bridge terminating on SIGTERM]
ifreund_ has quit [Quit: Bridge terminating on SIGTERM]
ugla has quit [Quit: Bridge terminating on SIGTERM]
kameliya[m] has quit [Quit: Bridge terminating on SIGTERM]
BaroqueLarouche has quit [Quit: Bridge terminating on SIGTERM]
mtiljeset[m] has quit [Quit: Bridge terminating on SIGTERM]
ziguana[m] has quit [Quit: Bridge terminating on SIGTERM]
fengb has quit [Quit: Bridge terminating on SIGTERM]
jaens[m] has quit [Quit: Bridge terminating on SIGTERM]
vpzom has quit [Quit: Bridge terminating on SIGTERM]
protheory8-new-m has quit [Quit: Bridge terminating on SIGTERM]
Nypsie[m] has quit [Quit: Bridge terminating on SIGTERM]
motiejus has quit [Quit: Bridge terminating on SIGTERM]
pafmaf[m] has quit [Quit: Bridge terminating on SIGTERM]
BitPuffin has quit [Quit: Bridge terminating on SIGTERM]
Snektron has quit [Quit: Bridge terminating on SIGTERM]
midgard has quit [Ping timeout: 246 seconds]
midgard has joined #zig
Snektron has joined #zig
siraben has joined #zig
ugla has joined #zig
ifreund_ has joined #zig
dtz has joined #zig
jaens[m] has joined #zig
motiejus has joined #zig
BitPuffin has joined #zig
pafmaf[m] has joined #zig
kameliya[m] has joined #zig
mtiljeset[m] has joined #zig
Nypsie[m] has joined #zig
vpzom has joined #zig
fengb has joined #zig
protheory8-new-m has joined #zig
ziguana[m] has joined #zig
BaroqueLarouche has joined #zig
dmgk has joined #zig
gazler has joined #zig
hch has left #zig [#zig]
koko has joined #zig
koko has quit [Quit: Ping timeout (120 seconds)]
jukan has joined #zig
jukan has quit [Ping timeout: 246 seconds]
donniewest has joined #zig
cole-h has joined #zig
Ashpool has joined #zig
<Ashpool>
Can I have anonymous fields in a packed struct declaration (e.g. to force some padding here and there)?
<ikskuh>
Ashpool, no that's not possible
Akuli has joined #zig
<fengb>
Not anonymous, but you can insert auto zeroing fields: `packed struct { foo: u7, _pad: u1 = 0 }`
ed_t has joined #zig
<ed_t>
how would i handle this error?
<ed_t>
var list = ArrayList(i32).init(a);
<ed_t>
list.items[70] = 66;
LanceThePants has quit [Read error: Connection reset by peer]
sawzall has joined #zig
<fengb>
Are you trying to create a sparse array?
<ed_t>
at this point just learning
<ifreund>
you need to grow your ArrayList to at least 70 in length first
<ed_t>
if I was to create a sparse array what should I use (arrayHash maybe?)
<ed_t>
yes I know I need to grow the list NOT to get a runtime error. What I am trying to understand is how to catch it if I do?
<fengb>
You can't catch runtime errors
<fengb>
You need a preflight check
<ed_t>
I could use try and catch errors on the right side of the =, but it does not work on the left side
<ifreund>
there's no error that can be caught there
<ifreund>
errors are values returned from functions in zig
waleee-cl has joined #zig
<ifreund>
there's no function called in that snipped that returns an error
<dutchie>
you just have to check the length before you try indexing
<ifreund>
you are simply preforming an illegal operation which is safety-checked in "safe" build modes and undefined behavior in release fast/release small
<ed_t>
Test [1/1] test "std.ArrayList/ArrayListUnmanaged.insertSlice"... thread 130129 panic: index out of bounds
<ed_t>
list.items[70] = 66;
<ed_t>
that is what I would like to catch
<ifreund>
as I just said, there is no error to catch there
<ed_t>
so "index out of bounds" is not an error from a zig perspective
<ifreund>
it's a safety checked illegal operation
<ifreund>
which causes a panic in debug/release safe build modes
<ed_t>
and zig is not providing a way to catch this, unlike most other conditions
<g-w1>
catch it by checking it beforehand
tnorth has joined #zig
<ifreund>
no, you cannot handle illegal behavior
<ed_t>
g-wl yes I can do this list.items.len has the index limit.
<ifreund>
you just need to fix your code to not cause it, either by checking the lenght first or resizing the ArrayList
<ed_t>
its just not as clean as catching what should be a rare occurance
<ifreund>
this should never happen in correct code
<ifreund>
that's what illegal behavior means
<ifreund>
errors are for things that can occur despite the code being correct
<ifreund>
i.e. opening a file failing because there is no such file with the given name
<ed_t>
I understand what you are saying - been coding in many many languages for over 40 year. To me, as a zig newbee, this looks like a corner case that would be good to handle.
<ed_t>
for instance:
<ed_t>
var list = ArrayList(i32).initCapacity(a,74);
<ed_t>
list.items[70] = 66;
<ed_t>
I know the space is allocated but the arraylist is not grown...
<ifreund>
var list = ArrayList(i32).init(a); list.resize(74); list[70] = 66;
<dutchie>
(don't forget to `defer list.deinit();` too)
<ifreund>
you can also set items.len manually, though that is more error-prone
<companion_cube>
what does `list.resize(74)` put in the slots though?
<dutchie>
there's also list.expandToCapacity() and list.allocatedSlice()
<dutchie>
companion_cube: undefined
<companion_cube>
heh, fair enough
<ed_t>
(defer is the next line in the test sample) I will need to look at the code in lib/zig/std to understand just what is happening with resize etc. I would expect there should be a way to detect the undefined slots (eg list.items[40] where i have not set a value)
<ifreund>
it sounds like you want a HashMap tbh
<ifreund>
you can't detect if memory is `undefined` because the value could be literally anything in relase-fast/small build modes
<ifreund>
you could store an ArrayList of optional i32s ArrayList(?i32) but that wouldn't be as nice as a hashmap
<dutchie>
and you'll have to remember to initialise them to null
<ifreund>
^
<companion_cube>
dutchie: I like the approach of languages with closures though
<companion_cube>
you'd have `arr.resizeWith(42, |i| i*2);` or something like that
<companion_cube>
specify what to put in new slots
<dutchie>
there are some methods on ArrayList which let you copy stuff in
<dutchie>
otherwise zig prefers an explicit loop
<ifreund>
there's appendNTimes() for example
<ed_t>
zig test al_test.zig
<ed_t>
list.resize(71);
<ed_t>
./al_test.zig:13:13: error: type '@typeInfo(@typeInfo(@TypeOf(std.array_list.ArrayListAligned(i32,null).initCapacity)).Fn.return_type.?).ErrorUnion.error_set!std.array_list.ArrayListAligned(i32,null)' does not support field access
<dutchie>
you forgot a try somewhere
<ed_t>
why? know I am missing something very basic here
<ed_t>
ahh
<ifreund>
try list.resize(71);
<ed_t>
same thing with the try added
<dutchie>
initCapacity needs a try too
<g-w1>
no, list is an error union, when creating list, you forgot a try
<dutchie>
since it might run out of memory it returns an error union
tnorth has quit [Ping timeout: 260 seconds]
inet56 has joined #zig
inet56 has quit [Quit: Quit]
<ed_t>
thanks for help guys - learning a new language is always both a pita and fun...
<ifreund>
indeed, you're most welcome :)
kbd has joined #zig
hnOsmium0001 has joined #zig
dvaun has joined #zig
cole-h has quit [Quit: Goodbye]
cole-h has joined #zig
jukan has joined #zig
ZealousWombat has joined #zig
ZealousWombat has quit [Quit: Connection closed]
<Gliptic>
is there some established support/pattern for generating .zig files in build.zig and caching them when inputs don't change?
zags has joined #zig
<zags>
Hey. I'm taking a 32 byte piece of data as 64-char hex bytes from the command line. What's the best way to convert the hex string to a slice of 32 bytes?
<zags>
these hex conversions are so frequent, would be nice if std had them imo even if it's not much code
* ikskuh
loves the type system a lot
<ikskuh>
zags: i required them once ^^
<zags>
i do it all the time in various projects hah
<ikskuh>
but nobody prevents you from making a nice pr for std.fmt :)
<zags>
:)
<Ashpool>
Is there a way to declare a function that expects a generic type, e.g. a generic std.io.Writer?
<Ashpool>
as an argument.
<ikskuh>
use anytype
<ikskuh>
fn takesWriter(writer: anytype) !void
<zags>
So I take it std.fmt doesn't have a nice way to print arrays as hex strings?
<zags>
the other way around, that is
<ikskuh>
{h}
<ikskuh>
ah no
<ikskuh>
{x} and {X}
<ikskuh>
sorry :D
<zags>
ooooh nice
<zags>
std.debug.print("{X}\n", .{.bytes}); I added .bytes instead of bytes by mistake and it printed ".bytes".... how does that happen
<ikskuh>
because a enum literal doesn't have a X specifier
<ikskuh>
but using non-existing specifiers doesn't error
<zags>
right same if I do {}
tdeo has quit [Read error: Connection reset by peer]
tdeo has joined #zig
dddddd_ has joined #zig
dddddd has quit [Ping timeout: 256 seconds]
<ed_t>
are if always fully evaluated or does the evaluation stop when the result if fixed (conditional evaluation if I remember correctly)?
<ikskuh>
ed_t: zig will only semantically check branches if their result is either comptime-taken or runtime known
<ikskuh>
if(true) { } else { }
<ikskuh>
only the true-part will be analyzed
<ikskuh>
if(false) { } else { } is the other way round
<ed_t>
so what gets evaluated in if ( e1 and e2 and e3 )
<ikskuh>
if(runtime_value) { } else { } will analyze both
<ed_t>
when e1 is true and e2 is false
<ikskuh>
ed_t: is that related to if or boolean operators? :D
<ikskuh>
i think its the latter
<ikskuh>
and/or are guarantted to be short-circuited
<ikskuh>
so
<ikskuh>
f() and g() will run g() only when f() returns true
<ed_t>
thats what i was looking for. Thanks
<ikskuh>
note that you can recognize this by the fact that "and" and "or" are keywords and not symbol operators
<ikskuh>
everything that is control flow in zig is required to be a keyword
nvmd has quit [Ping timeout: 260 seconds]
nvmd has joined #zig
<dvaun>
I'm enjoying the conversation here and really dig Zig so far. Problem is I've never done much with manual memory management, allocators...does anyone have any favorite/recommended resources for playing around like this? :) if not I'll scour through lobsters, HN etc...
<justin_smith>
dvaun: something that helps a lot is using container structs like std.ArrayList and std.AutoHashMap which are parameterized with a type and allocator
<earnestly>
dvaun: Have you opened files before, network connections, etc? It's not a million miles from that, with the same lifetime considerations
<zags>
dvaun: I think it's best to just write a bunch of small programs to test things out, that's what I'm doing now. I haven't done manual mgmt in a while, so need to rediscover good idioms. Smart pointers and GC makes you lazy :D
<justin_smith>
oh, and definitely use "defer" with a deallocation after every explicit allocation (unless your allocation is returned / assigned to another scope)
<dvaun>
earnestly: yes, using higher languages e.g. C#, python
<dvaun>
zags: it's been a while since I've used any pointers ;)
<dvaun>
I did see that defer pattern. Thank you for the reminder.
<justin_smith>
I think that's a good comparison, but the gotcha is that the world is full of python programs that don't close their files properly, but the program is just accidentally used in such a way that the error is never visible
<ikskuh>
dvaun: memory is just a resource like files. you open/allocate, so you have to close/free the resource
<dvaun>
See, I've been considering playing with either Rust or Zig for some hobby projects and to get back into lower-level dev. It just seems fun and interesting compared to my work (which is primarily SQL atm so no real work on building tools etc...)
<justin_smith>
with allocations, this is more likely to be a showstopper
<earnestly>
dvaun: It's the same mental model. resources need to be aquired and then released. Opened files and sockets need to be closed, etc. Which thread has access to read/write, etc.
<dvaun>
that makes sense ikskuh and earnestly .
<dvaun>
back when I played with C++ in college I enjoyed going through Beej's guide...might try going through that again but with Zig and mess around.
<dvaun>
also looking at writing a simple allocator. Might look for an OS dev book to get fundamentals down again
<dvaun>
thanks for the suggestions everyone :)
<justin_smith>
dvaun: also with "zig test" you can get errors from allocated memory that isn't freed
<dvaun>
that's great
<dvaun>
You know what I really enjoy so far? Someone in the community created https://ziglang.org and it's been quite a nice walkthrough with the language features
<Nypsie[m]>
ziglang.org is the official website. Do you maybe mean ziglearn.org? :)
<dvaun>
yes! that :P
<zags>
embarrasing... how do I turn var r: u64 into a []const u8?
<zags>
using an api that takes the latter
<dvaun>
these are the questions/problems that I need to play around with and become comfortable with :P
<dvaun>
I need to figure out how to run Plex in linux while retaining gpu transcoding ability
<dvaun>
g-w1: ooh much appreciated!
<dvaun>
I was skipping around the nav on the main site...didn't click on the documentation link
<dvaun>
alright I'll retain the RTFM-esque questions for the foreseeable time...thanks
<zags>
dvaun: yeah vscode is highly recommended - just git clone the zig repo and open in vscode. Makes it super easy to navigate through the source.
<g-w1>
but I wouldn't use it. the auto docs tool is very old and there is a design flaw in it (lazy analysis).
<g-w1>
*wouldn't use the website
<dvaun>
zags: I have found the vscode integration to be quite nice for Zig in general. I got ZLS working by building from source (I don't have admin on this machine) and have been playing around since.
<zags>
yep, zls works great
<zags>
for the most part
<justin_smith>
is there a cloc or cloc workalike configured for zig?
<justin_smith>
maybe there's a file I can throw in /etc/ somewhere to make cloc count zig files
<justin_smith>
ikskuh: ahh, turns out I was using obsolete tools, thanks
ur5us_ has joined #zig
<dvaun>
interesting
<dvaun>
in std.os there is getRandomBytesDevURandom. Maybe this is a stupid question...is it safe to not check for the builtin.os.tag to be linux or bsd since it's assumed you'd only call it when in those OSes?
<ikskuh>
yes
<ikskuh>
it won't compile on other platforms
<dvaun>
ah, gotcha
<ikskuh>
if you need random, check out std.rand ;)
<dvaun>
oh, noted that openZ handles it
<dvaun>
nevermind
<ikskuh>
there is a Prng and a crypto provider
ur5us has quit [Ping timeout: 264 seconds]
<dvaun>
bouncing off that recommendation...(looking at the Random struct)...i really do like the `Self = @This()` idiom
<ikskuh>
:D
<dvaun>
brings me to thinking of a way to create some async functions which execute after returning something like e.g. a promise (thinking JavaScript here)
<dvaun>
overall Zig is much cleaner than C
<dvaun>
imo
<ikskuh>
we have that already :)
<ikskuh>
var promise = await someFunc();
<dvaun>
ooh boy that's better :)
<ikskuh>
var result = await promise;
<dvaun>
i can think of a fun use case
<dvaun>
like making some server which can optionally add guards and other checks to a request
<dvaun>
anyway, thanks for the input :D might practice by rewriting some other tools into Zig and seeing if tests pass
<ikskuh>
have fun :)
<dvaun>
crypto is always fun. Might look at xxhash
<ikskuh>
running tests with zig is always fun
<ikskuh>
btw, zigs crypto is pretty good already i think
<ikskuh>
we have a crypto pro contributor
<dvaun>
that's awesome!
<dvaun>
i'm no pro at any of these fields. I'm pretty new, only a few years under my belt
<dvaun>
they're just fun to read about :) I spend most of my time reading
<ikskuh>
you know libsodium?
<dvaun>
yes
<ikskuh>
frank is writing zig crypto libs as well
<ikskuh>
which is very cool
<dvaun>
was he the author of libsodium or nacl?
<g-w1>
yes
<dvaun>
sorry, I don't know big contributors by name
<dvaun>
i'm sure it exists, but it'd be neat to play with something similar to the DPAPI in windows for encrypting data and memory per user, process session etc.
<dvaun>
i'm not familiar with POSIX internals beyond the basics lol
<zags>
dvaun: windows is way ahead of the curve there, other os's offer various keychain apps
<zags>
stuff like libsecret is not fun in comparison
<ed_t>
what is zig trying to tell me here?
<ed_t>
error: variable of type 'type' must be const or comptime