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/
marmotini_ has quit [Ping timeout: 240 seconds]
qazo has joined #zig
dimenus has quit [Remote host closed the connection]
mahmudov has quit [Remote host closed the connection]
<BaroqueLarouche> I'm being given some love to zigimg since I mentioned it in the last stream, getting close to have PCX support in: https://github.com/mlarouche/zigimg/commit/5e3f469d288baf1baa2bbf46b762a72166bedbbb
<BaroqueLarouche> Next format: NetPbm (from mq32
<BaroqueLarouche> and PNG
dddddd has quit [Ping timeout: 260 seconds]
lunamn_ has joined #zig
<alexnask> Looks like I can't avoid copy pasting for every argument count in vtable generation unless I'm missing something
lunamn has quit [Ping timeout: 255 seconds]
shritesh has joined #zig
shritesh has quit [Remote host closed the connection]
alexnask has quit [Ping timeout: 260 seconds]
marmotini_ has joined #zig
marmotini_ has quit [Ping timeout: 260 seconds]
LER0ever has joined #zig
waleee-cl has quit [Quit: Connection closed for inactivity]
<pixelherodev> Is it just me or does `zig fmt` occasionally move DocComments into the wrong place? :(
ur5us has quit [Ping timeout: 240 seconds]
<fengb> Yeah :(
<pixelherodev> Is there a way to do a parseInt to an integer whose size is not comptime known other than `inline-for`ing over a range of integers, comparing them, and then passing the comptime integer to parseInt?
<pixelherodev> I suppose I could just use u64 and assume it'll never be larger...
<Snektron> Pixelherodev, you can achieve that with a custom parseInt
<Snektron> Or maybe you can parse with type comptime_int
ur5us has joined #zig
LER0ever has quit [Ping timeout: 265 seconds]
LER0ever has joined #zig
FireFox317 has quit [Ping timeout: 265 seconds]
LER0ever has quit [Ping timeout: 260 seconds]
LER0ever has joined #zig
Sahnvour has quit [Ping timeout: 265 seconds]
<mq32> <BaroqueLarouche> Next format: NetPbm (from mq32
<mq32> neat!
<mq32> I'll take a closer look at your library, maybe even add some more obscure formats to it :D
CommunistWolf has quit [Ping timeout: 245 seconds]
CommunistWolf has joined #zig
return0e_ has joined #zig
CommunistWolf has quit [Ping timeout: 248 seconds]
LakeByTheWoods has joined #zig
CommunistWolf has joined #zig
alexnask has joined #zig
ur5us has quit [Ping timeout: 240 seconds]
marmotin_ has joined #zig
marmotin_ has quit [Remote host closed the connection]
<alexnask> BaroqueLarouche is the code you linked in the issue public in some repo? I would be interested in tinkering with it and possibly fixing the compiler error.
ur5us has joined #zig
ur5us has quit [Ping timeout: 248 seconds]
LakeByTheWoods has quit [Remote host closed the connection]
marmotini_ has joined #zig
waleee-cl has joined #zig
marmotini_ has quit [Remote host closed the connection]
<mq32> > try args.@"1".create(AllocT);
<mq32> this looks quite crazy
<mq32> alexnask: made you a small review, std.interface looks quite awesome :)
Cadey is now known as Xena
Xena is now known as Cadance
Cadance is now known as JohnMadden
JohnMadden is now known as shadowh511
shadowh511 is now known as Cadey
<alexnask> mq32, In a good or bad way? ;)
<mq32> the crazy thing? kinda a bad way, but i understand that we cannot make that better atm
<mq32> but the whole PR/interface stuff is nice, i like it!
<alexnask> Thanks for the review, this is still pretty early on, I will add lots of docs, tests etc
<mq32> yeah i missed that in your PR todo list :D
tane has joined #zig
<alexnask> Pretty sure my destroy call is technically incorrect atm (docs say that destroy should take return value of create or a pointer to the same address with the same alignment)
<mq32> i think my proposed change would be correct
<alexnask> Not sure if using 'alloc' and 'free' would be valid though, alignment info will be lost during type erasure
<alexnask> hmm
<mq32> you probably have to store the alignment as well
<alexnask> Yes I think so too
<mq32> but i really like the idea that this interface implementation is using fat pointers
<mq32> instead of storing a vtable per object
<alexnask> Pretty bummed I cant avoid copy pasting a closure per argument count
<alexnask> In the vtable generation
<mq32> yeah
<mq32> i think it would also be helpful if @Type() could create a struct type
<alexnask> I believe aggregate types will not be supported
<mq32> yeah, me too
<mq32> and i can understand why
<mq32> oh man
<mq32> i got the wildest bug right now
<mq32> hacking on my toy language, now this happend:
epmills has joined #zig
<mq32> var global; for(x in [1,2,3]) { } // compiles
<mq32> for(x in [1,2,3]) { } var global; // doesn't compile
<alexnask> Should it? :P (assuming there is no newline in between)
<mq32> yes
<mq32> the code generation fails as it looses track of temporary variables :D
epmills has quit [Client Quit]
<BaroqueLarouche> alexnask: My project with COM usage is not public yet, but I could strip out the Wwise parts from it and put it in a repo
<BaroqueLarouche> mq32: Love hearing that you will be willing to contribute in the future 🙂 Also, do you mind that I use MIT license in my code since yours was zlib ?
<mq32> nah, just go for it
<BaroqueLarouche> thanks :)
<mq32> ^= store this and quote it if someone wants to nag you about licence stuff
epmills has joined #zig
epmills has quit [Client Quit]
<alexnask> I think I will just store the alignment and keep the erased pointer since the requirement is just a pointer with the same address and alignment
<mq32> neat
mikdusan has quit [Ping timeout: 265 seconds]
mikdusan has joined #zig
<fengb> Maybe try replacing one of the existing interfaces... like rng? :P
<mq32> fengb: if i read the PR comment right, that's the plan
<alexnask> Hmm, running into the 'cannot assign to constant' bugt with tuple concatenation too now
<alexnask> weird
<alexnask> var a: usize = 100;
<alexnask> try iface_instance.call("otherFn", .{a}); // works
<alexnask> try iface_instance.call("otherFn", .{100}); // error
<mq32> what about .{@as(usize, 100)} ?
<alexnask> That errors too, as well as const a = 100; and const a: usize = 100;
<alexnask> So it appears to error when a value is comptime known
<alexnask> I will make some isolated testcases, and open an issue (and work on that one)
<mq32> <3
_Vi has quit [Ping timeout: 240 seconds]
<fengb> Yeah you assume I can read
<mq32> :D
<fengb> In big endian, if I use a union, would the pointers line up across different sizes?
<mq32> unions don't guarantee anything
<mq32> or do you mean extern/packed unions?
<fengb> Packed yeah
metaleap has joined #zig
<fengb> Little endian is nice since they naturally line up
<mq32> yeah
<fengb> I guess I can just get a pointer to the field and let LLVM realize it's a noop
<alexnask> What do you mean 'line up'? I feel like I'm having a major brainfart :P
<fengb> Probably the most correct solution :P
<fengb> In `packed union { A: u8, b: u32, c: u64 }, the addresses of all the fields are guaranteed to be identical
<fengb> ... for little endian
<alexnask> Ah, gotcha
<fengb> So it's a noop for me to cast between the pointers
<fengb> Not sure if that's the case in big endian
<fengb> And if it isn't, there will probably be bugs, cause who uses big endian!
<alexnask> I pushed a commit and it didnt update my PR, weird
<fengb> Github is having some issues
<alexnask> Ty
<alexnask> Time to dive into compiler internals to fix this concatenation bug
<mq32> go go go!
<BaroqueLarouche> just DO IT
dddddd has joined #zig
_Vi has joined #zig
waleee-cl has quit [Quit: Connection closed for inactivity]
waleee-cl has joined #zig
<terinjokes> I use big endian from time to time…
<mq32> has somebody experience with the hashmap type?
<mq32> i wonder what the excapt semantics of "put" and "putNoClobber" are
<andrewrk> mq32, those functions have doc comments
<mq32> so i get the old value back if there was any?
<mq32> i'm just not used to such an interface
<metaleap> mq32: can be handy if the old value needs to be free()d / deinited etc
<mq32> i would've expect an error if i try to replace an already existing key
<metaleap> mq32: often not. half of my hashmap uses are "set of foo"
<andrewrk> mq32, look at the return types and doc comments of both those functions
<mq32> hmm
<mq32> i understand
<mq32> would it be welcome to modify the hashmap so it would allow a putOrError() ?
FireFox317 has joined #zig
<mq32> oh. found a compiler bug ^^
<mq32> semantic analysis runs into an endless loop
<andrewrk> you should just use put() and return error.WhateverYouWant if the value is not null
<mq32> but that would be a different semantic
<mq32> it would override the existing key if i had an old value
<mq32> instead of not replacing that value
<mq32> the error would happen post-mutation
<andrewrk> mq32, oh, I think you want getOrPut
<mq32> ah okay
<mq32> i think it's still useful to have a function putOrFail as it's a common use case (at least for me)
<andrewrk> I suspect you will need access to the previous value in case of failure in which case you want getOrPut
<andrewrk> e.g. if you were reporting the error to a user you would say "error that already exists, previous value was foo"
<mq32> in my concrete usecase i would error out with "function X was already defined"
<andrewrk> wouldn't you want error.FunctionAlreadyDefined rather than e.g. error.PutWouldClobberHashMapItem
<mq32> yes, but that would be catch |err| switch { error.PutWouldClobberHashMapItem => return error.FunctionAlreadyDefined, else => return err, };
nepugia has joined #zig
<andrewrk> shorter: if (gop.found_existing) return error.FunctionAlreadyDefined
<mq32> + one new variable for each function i want to insert into the map
<mq32> or i could create a new struct into a thing that is a map + my single function i need
<mq32> i narrowed down a problem in the lazy value analysis
<mq32> were there any fixes regarding this in the last days?
<fengb> `try self.push([4]u8, @ptrCast(*[4]u8, top_ptr).*);` -- `error: expected type 'void', found '@TypeOf(execution.push).ReturnType.ErrorSet'`
<fengb> Am I doing something really stupid?
<fengb> Without the try, it gives me `error: expression value is ignored`
<fengb> Oh! This function doesn't have an error
<fengb> Really confusing error message :/
<mq32> fengb: i've read "try self.push(" and just thought: what do you want to do with my code? :D
return0e_ has quit [Ping timeout: 240 seconds]
<mq32> error "narrowed" down and reported
<mq32> also found two workarounds
Snetry has quit [Quit: left Freenode]
tane has quit [Quit: Leaving]
Snetry has joined #zig
Akuli has joined #zig
mokafolio has quit [Ping timeout: 272 seconds]
FireFox317 has quit [Ping timeout: 240 seconds]
FireFox317 has joined #zig
mahmudov has joined #zig
_Vi has quit [Ping timeout: 248 seconds]
_whitelogger has joined #zig
frmdstryr has quit [Quit: Konversation terminated!]
frmdstryr has joined #zig
araspik has joined #zig
<fengb> Oh I’m pretty sure it’s due to recursive comptime functions
<fengb> I had the same problem with my generator branch
<andrewrk> I forget, why does start code need to do TLS initialization even when --single-threaded ?
<mq32> fengb: but interestingly it helps to introduce a inbetween function
<andrewrk> I think TheLemonMan knows
<andrewrk> I think that should be documented in a comment right where it's tempting to wrap TLS initialization with `if (builtin.single_threaded)`
<andrewrk> oh right. because of god damn errno on dragonflybsd
_Vi has joined #zig
<fengb> `zig run` sticks stuff in the global cache?
<andrewrk> nearly any compilation is going to need libcompiler_rt.a and libc.a
<andrewrk> (libc.a has memcpy, memset, etc which are always possibly called by llvm codegen)
<andrewrk> oh and yes zig run uses the global cache for the exe file as well
ur5us has joined #zig
dwdv has joined #zig
<fengb> Is there a standard way of cleaning the cache?
<andrewrk> rm -rf
<andrewrk> it's planned to do its own garbage collection with a config file specifying the size limit. that's not implemented yet
<fengb> Ah okay that works
FireFox317 has quit [Ping timeout: 258 seconds]
<fengb> If I have a non-native pointer alignment, will Zig / LLVM be smart enough to translate that properly? e.g. *align(4) u64
r4pr0n has joined #zig
<andrewrk> yes
<andrewrk> that's well-defined and works as you would expect
<fengb> Great! 👍
<fengb> I remember your unsafe Rust article and was a little worried
<fengb> That some day, my VM might run on non-x86 lol
<r4pr0n> hey, i saw it is possible to ignore an error in zig, by doing "_ = functionthatreturnserror()", but is that also possible if the function returns something? i don't care what happens when it errors, it might as well be undefined behaviour and segfault or something
<andrewrk> r4pr0n, `_ = ...` does not allow discarding an error
<andrewrk> it sounds like you are looking for `foo() catch unreachable;`
<andrewrk> if you want to additionally discard the (non-error) return value it would be `_ = foo() catch unreachable;`
FireFox317 has joined #zig
<andrewrk> you might also consider `foo() catch @panic("unexpected error")` which is still defined behavior in non-safe release builds
<r4pr0n> yeah, i just wanted to not handle the error at all, so it would be easier to read the outputted assembly, because i'm kinda new to that and wanted to experiment a little
araspik has quit [Ping timeout: 260 seconds]
<r4pr0n> but i guess a catch unreachable would also work
<r4pr0n> thank you regardless
<andrewrk> you could also do `catch undefined` which would give you an undefined value if an error occurred. that's not undefined behavior, unless you do certain things on the undefined value such as branch
<andrewrk> good luck. debug mode assembly is a bit noisy
<andrewrk> lots of runtime safety checks happening
<r4pr0n> yeah, i'll actually use release mode small or fast because of that
<r4pr0n> what i'm programming won't actually be used, i just thought it would be nice to teach myself assembly a little more by doing stuff in zig and looking at the resulting assembly
<andrewrk> note that in release-small and release-fast, the optimizer is allowed to notice `catch unreachable` and assume that the error path is not possible, and delete the code that would produce an error
frmdstryr has quit [Remote host closed the connection]
<r4pr0n> oh okay, thanks for the tip :)
frmdstryr has joined #zig
<alexnask> I always feel so stupid when it takes me 3 hours debugging an issue only to finally fix it with a single line of code >.>
<andrewrk> it's a sign that the code you're editing has footguns
<alexnask> I'm still struggling with the compiler internals :P
<andrewrk> mikdusan has written a lot of helpful info about that topic
<mikdusan> I wish I had more time to give that doc the attention it deserves
<mikdusan> is there a lang'ism for `@TypeOf(.enum_literal)` or is that just how one gets the type?
<andrewrk> that's how you'd get it. I would imagine that being quite rare
<andrewrk> mikdusan, actually, this should work: @Type(.EnumLiteral)
<andrewrk> that will require an improvement to ir.cpp because @Type does not properly set up a result location
<andrewrk> workaround is @Type(std.builtin.TypeInfo.EnumLiteral)
<mikdusan> still a TODO. no sweat
frmdstryr has quit [Read error: Connection reset by peer]
<mikdusan> I actually may have a good case for a formal tuple (or pack) type
<andrewrk> nice
<mikdusan> consider: a format interface where .enum_literals are used for meta marking:
<mikdusan> s/interface/api/
<mikdusan> format("hello {}\n", .{ .fill='.', .center=20, .high, .info, "world" });
<mikdusan> note: both standalone items (like an anon array literal), and EnumLiteral=value items (like anon struct literal)
<mikdusan> this would permit me to strip-out post-functionality of fill/align from the format string,
<mikdusan> and apply ANSI color directives
<andrewrk> taking this one step further, how about no format string
<mikdusan> yup, that's a very strong possibility
<andrewrk> format(.{"hello ", .{ .fill='.', .center =20, .high, .info}, "world"});
<mikdusan> this so far is pretty compact `"this is a number {+10.4f%}", .{ .high, .info, 1000 }`
<mikdusan> and if a elit was really neded, it could be api-escaped, ".{ .escape. .I_AM_A_LEGIT_VALUE }"
Akuli has quit [Quit: Leaving]
<andrewrk> I do like the idea of terminal escaping by default when using std.log (replaces std.debug.warn in #2586) and the output is a terminal, but also somehow building terminal coloring into format strings
<mikdusan> the existing anon-struct-lit mechanism falls apart because... well a formal tuple/pack doesn't care about repetitions. hell, it might even allow empty commas .{ one,,,3 } and let the context choose to ignore or make relevant
<andrewrk> I think integrating terminal colors into formatted printing would require adding more parameters to the output function
<r4pr0n> is it possible to disable optimizations for a single block?
dingenskirchen has quit [Remote host closed the connection]
dingenskirchen has joined #zig
<andrewrk> r4pr0n, that's planned as part of https://github.com/ziglang/zig/issues/978
<andrewrk> the llvm-based compiler will only have function granularity
<r4pr0n> oh great, but will setRuntimeSafety be completly replaced by this? i can imagine a situation where you want to enable safety checks but not disable optimization
<BaroqueLarouche> while working at Ubisoft Montreal, I abused so much of `#pragma optimize("", off)`
FireFox317 has quit [Ping timeout: 265 seconds]
<andrewrk> r4pr0n, that's release-safe mode
<andrewrk> @setMode(.ReleaseSafe); // https://ziglang.org/documentation/master/#ReleaseSafe
FireFox317 has joined #zig
<r4pr0n> uh
<r4pr0n> yes, but i meant block-wise safety
<mikdusan> andrewrk: here's a simple comparison of mix vs. tuple-everything. tuple-everything could be very powerful, supporting styles or simply nested tuples. maybe we need a splat operator is in order but that overlaps with ++ syntax
metaleap has quit [Quit: Leaving]
<andrewrk> r4pr0n, safety has block-wise granularity, but an llvm-based compiler has function granularity for optimizations
<mq32> mikdusan, does that work though? it would require duplicate named entries in a tuple
<r4pr0n> oh, nvm, i understand the functionality of optimizeFor wrong
<mikdusan> mq32: by tuple I mean really generic tuples that don't care about repetitions
<mq32> ah!
<mq32> not sure if i like that, complicates a lot of things
<mikdusan> like?
<mq32> how do i access the tuple items?
<mq32> meta.fields?
<mq32> and will that remove the possibility for something like "tuple.info"?
<mikdusan> i don't think it fits into any existing type
<mikdusan> well except array I suppose
<mq32> array of classic tuples :D
<mikdusan> each item would be a union{ value: var, ev: struct { enum_literal: EnumLiteral, value: var }}
<mikdusan> hmm maybe I can hack this into stage1 and see if it flies
<mq32> C++20 is moving a lot of directions
<companion_cube> woo for modules, at least
<mq32> semi-whoo
<mq32> doesn't seem like they fixed the real problems with that :d
<alexnask> woo for designated initializers, at least ;)
<alexnask> and ranges
<mq32> yeah designated initializers
<mq32> like ... C99 had :D
<mq32> 21 years now
<alexnask> :D
<mikdusan> question is - when did gcc first begin supporting it
marmotini_ has joined #zig
FireFox317 has quit [Ping timeout: 258 seconds]
<alexnask> gcc has some very cool extensions of designated initializers
<alexnask> like: int widths[] = { [0 ... 9] = 1, [10 ... 99] = 2, [100] = 3 };
<mq32> ah yeah
<alexnask> Or the alternate syntax: struct point p = { y: yvalue, x: xvalue };
<alexnask> :P
<mikdusan> is that still supported?
<alexnask> Ah no it seems it's obsolete
<mikdusan> "Labeled Elements in Initializers"
epmills has joined #zig
epmills has quit [Client Quit]
ur5us has quit [Ping timeout: 260 seconds]
daurnimator has quit [Read error: Connection reset by peer]
mokafolio has joined #zig
dingenskirchen has quit [Quit: dingenskirchen]
mahmudov has quit [Remote host closed the connection]
ur5us has joined #zig