ChanServ changed the topic of #zig to: zig programming language | | be excellent to each other | channel logs:
return0e has quit [Ping timeout: 245 seconds]
return0e has joined #zig
_whitelogger has joined #zig
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 248 seconds]
<fengb> expectEqual works better if the literal is on the right side
laaron has quit [Remote host closed the connection]
laaron has joined #zig
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 245 seconds]
daurnimator has quit [Read error: Connection reset by peer]
shritesh has joined #zig
oats has left #zig ["WeeChat 2.5"]
daurnimator has joined #zig
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 272 seconds]
nero57 has joined #zig
kristoff_it has joined #zig
tridactyla has joined #zig
kristoff_it has quit [Ping timeout: 272 seconds]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 246 seconds]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 245 seconds]
laaron has quit [Remote host closed the connection]
laaron has joined #zig
darithorn has quit [Quit: Leaving]
nero57 has quit [Ping timeout: 260 seconds]
abbiya has joined #zig
andersfr has joined #zig
andersfr has quit []
nero57 has joined #zig
<bgiannan> ?iset
<bgiannan> arf
nero57 has quit [Ping timeout: 260 seconds]
laaron- has joined #zig
laaron has quit [Remote host closed the connection]
<earnestly> Is it possible to build software with zig without having to use the build.zig mechanism?
<gonz_> earnestly: `zig build-{exe,obj,lib}`
<earnestly> I was hoping that was the case, thanks
nero57 has joined #zig
<earnestly> The --name compile option seems to have a .o or .h implicitly added to the name given, is there a way to prevent this?
avoidr has quit [Quit: leaving]
ntgg has joined #zig
<earnestly> The build-exe option says it can take a source input or object, however if you supply it with object files it attempts to read them as if they were files
<earnestly> I.e. hello.o:1:1: error: invalid character: '\x7f'
samtebbs has joined #zig
<bgiannan> How can i convert a float to an array of u8 ?
<samtebbs> bgiannan: huh
<samtebbs> That conversion doesn't make sense to me, feel free to explain
<bgiannan> it's a rng program i'm trying to rewrite in zig
ntgg has quit [Ping timeout: 272 seconds]
<bgiannan> hum maybe i'm misreading it actually
<bgiannan> yeah i am
FireFox317 has joined #zig
<samtebbs> Do you want to extract the bits from the float and put them in an array as a u8?
<bgiannan> that's what i though but reading the algorithm again that's not what it does
laaron- has quit [Remote host closed the connection]
<earnestly> Is there a way to prevent zig from creating a ~/.local/share/zig directory?
laaron has joined #zig
donpdonp has quit [Read error: Connection reset by peer]
<nero57> If a Mutex is declared as global variable, does it mean it does not need to be destroyed?
<samtebbs> earnestly: Do you know what created it? I.e you installing it, compiling etc.
<earnestly> samtebbs: when using zig build-obj
FireFox317 has quit [Ping timeout: 245 seconds]
<samtebbs> Hmm I'm not sure. It seems to be creating it even if I turn caching off
<earnestly> Yeah, although you won't get the cached bits that also live under that tree
tav has joined #zig
<earnestly> samtebbs: Although a more pressing issue is perhaps zig build-exe foo.o failing as it attempts to read foo.o as a text file
<samtebbs> earnestly: That is expected behaviour. You should use --object for oject files
<samtebbs> zig build-exe --object foo.o
<earnestly> samtebbs: That creates a foo.root.o file though
<earnestly> samtebbs: Ah hm
<earnestly> samtebbs: Oh well it works, I must have done something wrong the last time I tried this. Perhaps it was some issue with caching
<gonz_> I've never used a compiler that has options that aren't confusing as shit
<samtebbs> earnestly: Could you paste your build commands here? I don't see that. I'm using `zig build-obj hello.zig; zig build-exe --object hello.o --name hello` and don't see anything out of the ordinary
<samtebbs> By "I don't see that" I'm referring to the weird root file thing :p
<earnestly> samtebbs: Yeah it was probably due to the cache and/or already having objects in the directory
<earnestly> samtebbs: Oh, it may have actually been when using -lib as --object is not documented for compile options
<earnestly> So I probably tried it with -lib instead
<earnestly> At least, the documentation is not very clear to me, the lack of a manual is also a bit sore
<earnestly> I'm going to assume from now on that all options apply and aren't related necessarily to the subcommand itself, just to the various phases implicit within each one
<gonz_> I think the current users of zig are the ones who'll have to write the manuals
<gonz_> I think everyone will have to get comfortable with that prospect
<gonz_> People who aren't up for that have probably adopted the language too early for their tastes
<gonz_> Generally speaking it seems to me we need more people who cover ground in raw usage in every area + cartographers than we need prospective language designers
redj has quit [Ping timeout: 258 seconds]
<earnestly> samtebbs: The creation of HOME/.local/share/zig seems implicit, through createRandomOutputPath
<earnestly> samtebbs: Which is used as part of the renderToLlvm function
<earnestly> I left a comment on the bug report regarding how hardcoding HOME/.local/share is not exactly correct, but that seems to be the rub of it as it stands
<earnestly> There's no way to disable this behaviour, but at least the caching can be turned off
<gonz_> Is it not using `$XDG_DATA_HOME`?
<earnestly> gonz_: Do you know if zig's build-exe and co. are incremental? I.e. only rebuilding objects when necessary
<earnestly> gonz_: Indeed it is not
<gonz_> No, I don't really know much about it
<gonz_> It should be incremental and be using all the hashed directories you get
<gonz_> but more than that, /shrug
<earnestly> Hm, fair enough
<gonz_> This should be an easy issue
<gonz_> we'll just have to have it check for XDG stuff
<gonz_> it's probably useful to do an overhaul
<gonz_> and for build artifacts you would expect XDG_CACHE
<earnestly> Yeah for sure
<earnestly> Although the XBDS is a bit of an odd duck. It was never really intended to be used outside of XDG (now fdo), hence the "base" qualifier. It's really unsuitable for compilers and languages since they have the concept of /bin /lib and so on. Ideally the author would have seen the symmetry between /usr/local and ~/.local and simply replicated the FHS under that point
<gonz_> I guess I've come to like it because it gives some semblance of order
<earnestly> But oh well. So in other words I don't mind how people use it, bikeshedding where files should go, to what location. In future I likely wouldn't notice usage of .local either, but it shows up now as I don't use that location
<earnestly> gonz_: Yeah exactly
<gonz_> I don't use Linux at the moment but if I did I would prefer XDG dirs rather than stray dot dirs everywhere
<gonz_> IIRC skype and a bunch of other apps don't care one bit
<earnestly> gonz_: I have my own idea of where to take it, at least something I'll use locally, and that's this:
<earnestly> gonz_: Yeah, I made an archlinux wiki article on XDG and all the programs that support it, and other alternatives
<earnestly> Which could be a useful place to look
<gonz_> FWIW after skimming your idea I guess I prefer it
<earnestly> gonz_: Apparently skype supports XDG since 0.8:
redj has joined #zig
<gonz_> Oh, hang on, I knew I recognized your nick from somewhere
<gonz_> I used to hang out in #archlinux as well
<earnestly> gonz_: The spec hardcodes HOME/.local to address concerns that openssh devs had, also because I wanted to bypass the problem DJB talked about sarcastically in (see COMPILEDFREGISTRY)
<earnestly> (Those concerns being not knowing where the configs are, if they can be moved around arbitrarily)
<gonz_> Everything is such a rabbit hole :D
<earnestly> Of our own making ;p
nero57 has quit [Ping timeout: 260 seconds]
SimonNa has quit [Ping timeout: 244 seconds]
SimonNa has joined #zig
SimonN has joined #zig
SimonNa has quit [Ping timeout: 245 seconds]
abbiya has quit [Quit: abbiya]
FireFox317 has joined #zig
avoidr has joined #zig
<bgiannan> is there an idiomatic way of using c-like flags ? (i.e. FLAG_A | FLAG_B | ...)
<mq32> make a struct with pub comptime_int s and `use` it?
<bgiannan> i was thinking of having an enum for possible flags
<bgiannan> but then it would have been nice to enforce the fact that the flag can only be composed with members of that enum
<bgiannan> btw why comptime_int?
<mq32> because it's size isn't specified => casts into any int type
<fengb> I usually do a packed struct with bitfields
Tetralux has quit [Ping timeout: 248 seconds]
porky11 has joined #zig
waleee-cl has joined #zig
avoidr has quit [Remote host closed the connection]
avoidr has joined #zig
<bgiannan> is the path given to @import relative to where the zig command is ran?
<bgiannan> or to something else
FireFox317 has quit [Ping timeout: 272 seconds]
<fengb> Should be relative to the file that’s doing the importing
FireFox317 has joined #zig
FireFox317 has quit [Remote host closed the connection]
halosghost has joined #zig
FireFox317 has joined #zig
oats has joined #zig
Tetralux has joined #zig
Akuli has joined #zig
nero57 has joined #zig
mrkishi has joined #zig
<dingenskirchen> is it possible to modify a struct's fields from methods "attached" to it?
<mrkishi> hey, folks. sorry to bring up a worn out issue, but have accessibility concerns been taken into account on the tabs vs spaces issues? I've recently read up on that and asked about it to my legally blind friend and, to my surprise, they also find spaces harder to work with.
<dingenskirchen> thinking about it, probably not, but there's bound to be an alternative mechanism for that
<andrewrk> mrkishi, you're welcome to discuss on It's off topic here
<mrkishi> sorry about that.
<andrewrk> no problem
<nero57> What is the easist way to clone a pointer? such as `[] const T`
laaron has quit [Quit: ZNC 1.7.1 -]
FireFox317 has quit [Ping timeout: 245 seconds]
<andrewrk> nero57, perhaps std.mem.copy?
laaron has joined #zig
<earnestly> "cloning pointers" makes me think of aliasing
<nero57> I want to clone the memory content of the pointer
<Tetralux> std.mem.copy, std.mem.dupe.
<nero57> I want clone the memory content pointed by the pointer
<nero57> Let me try the std.mem.dupe
<companion_cube> mrkishi: apparently some blind programmers like spaces…
<mikdusan> some light humor: a 10 sec code review by "Bret Hart":
<mrkishi> companion_cube: I'm by no means an expert, was just curious if that was considered. let's not derail the channel; I didn't know it was off-topic when I asked that.
FireFox317 has joined #zig
<samtebbs> dingenskirchen: If by "attached" you mean namespaced within it, then you could pass a pointer to that method as `self` and modify it that way?
samtebbs has quit [Remote host closed the connection]
<dingenskirchen> perhaps a bit better phrased as an example of what i'm trying to do:
<Tetralux> Replace `self: Foo` with `self: *Foo`
<Tetralux> You will then be able to mutate it.
<Tetralux> We call those kind of functions "member functions" btw :p
<dingenskirchen> that works, many thanks ^^
<Tetralux> o7
<Tetralux> If you have a fn that declares a buffer of bytes, and then passes a slice of that buffer to another fn, which returns a slice, and that slice was sliced from the slice you passed in, is that returned slice allocated in the same stack frame as the original buffer?
<fengb> A slice is just a pointer + Len
<andrewrk> Tetralux, yes. slices are just references to data that is somewhere else
<Tetralux> No no. I mean the slice itself.
<andrewrk> you can think of slices as primitive types the same as an integer. I don't think the answer to your question is observable in any way
<andrewrk> you can tell where buf2's memory is because it is where the `var` is
<Tetralux> Okay yeah.
<Tetralux> That's what I was interested in.
Tetralux has quit [Read error: Connection reset by peer]
Tetralux has joined #zig
<Tetralux> It's like I did 'var buf2: *[]u8 = undefined; g(buf, &buf2);'
<Tetralux> And then &buf2 is used to return the return value.
dimenus has quit [Quit: Leaving]
marler8997_1 has joined #zig
<Tetralux> I ask because I was wondering if it was more efficient to have g return an index and then buf[0..index] or just return a slice from g.
<Tetralux> I'm also assuming then that if g returned ?[]u8, the optional would be on f's stack as well.
<Tetralux> (along with the slice itself.)
marler899726 has quit [Remote host closed the connection]
<fengb> async foo() returns the actual frame, but anyframe and @frame() are pointers?
laaron has quit [Remote host closed the connection]
<FireFox317> andrewrk: I'm trying to solve issue #3099 (comptime bitcast) and I figured out (using zig-ir) that at some point it is doing `ResolveResult(bitcast(ty=u8))`. This causes the result location to be set to `Foo*`. Should it be allowed to resolve the result of a bitcast using `IrInstructionResolveResult`? Maybe you could point me in some direction
laaron has joined #zig
<andrewrk> fengb, @Frame(func) is not a pointer, but anyframe is
<andrewrk> *@Frame(func) casts to anyframe
<fengb> What about @frame() inside the function?
<andrewrk> that returns type *@Frame(func)
<fengb> Ah okay, thanks :)
<andrewrk> FireFox317, I'm sorry I'd have to do the same thing you're doing to figure out the answer. I don't have any guidance to offer
<FireFox317> Yeah makes sense actually, because you opened the issue xd
<Tetralux> Q: Does Zig have RTTI?
<FireFox317> I should probably start with a simpler bug anyways.
<Tetralux> Or is it all comptime-only?
<andrewrk> Tetralux, there is no run-time type information, but you can get the information using comptime reflection
<Tetralux> I have a fn that I want to be able to pass an arbitrary type to, and then store that type in an heterogenous array so that I can process each one according to it's type.
<fengb> You could use an opaque pointer and a enum for the type
<Tetralux> Problem is, it can be an arbitrary type.
<Tetralux> So I'm essentially reduced to a *void.
<Tetralux> But then I don't know what type it is to actually process it.
<Tetralux> I'd rather it was statically known anyway for speed
<Tetralux> But I haven't got there yet xD
<fengb> You could build a comptime array with ++
<fengb> That wouldn't work with arbitrary types though...
<Tetralux> Essentially, I'm writing a format encoder. You queue up things to encode, and then you effectively iterator over the encoder to get the bytes out of it.
<Tetralux> But it can encode arbitrary types, provided they have the necessary fields / member functions.
<fengb> Could it take an array of function pointers?
<Tetralux> Ugh.
<fengb> Sounds like some dynamic dispatch is needed
<Tetralux> I want to avoid virtual function calls.
<fengb> Then all the types need to be known at comptime and it can't be completely arbitrary
<fengb> I actually do something of the sort:
<Tetralux> That's the thing though.
<Tetralux> They are _known_ at comptime.
<fengb> But I made it mandatory to define into the struct itself
<fengb> So what I did was comptime duck typing
<fengb> And the array is generated from a struct definition
<nero57> `[] const u8` is a slice or a pointer type?
<Tetralux> It's a slice, but that's considered a kind of pointer in Zig.
<mrkishi> andrewrk: do all PRs need issues or can simple ones be discussed in-place? it'd be nice for to include a timestamp for the benefit of master
<fengb> Slices are fat pointers
<Tetralux> .. in that they are struct{ptr: [*]u8, len: usize}
laaron has quit [Quit: ZNC 1.7.1 -]
FireFox317 has quit [Ping timeout: 246 seconds]
laaron has joined #zig
<nero57> This is my function:```export fn handle_msg(msg: [*]const u8) void { var mstr = util.cstrToSlice(msg); if (mstr) |str| { var p = json.Parser.init(allocator, false); defer p.deinit(); var tree = p.parse(str) catch unreachable; defer {tree.deinit();warn("deinit\n");} var root = tree.root; var act = root
<nero57> .Object.get("act").?.value.String; if (mem.eql(u8, act, "play")) { var path = root.Object.get("path").?.value.String; warn("path addr {}\n", @ptrToInt(path.ptr)); if (scanMp3TrackTime(path)) |t| { playInWorker(path); } else |err| switch (err) { else
<nero57> => {}, } } } else { warn("recv null message\n"); } playInTask(&rptCtx);}```Why is the content pointed by the local variable `path` not destroyed?
<nero57> sorry, so disordered
<nero57> Why is the content pointed by the local variable `path` not destroyed?
transfusion has joined #zig
FireFox317 has joined #zig
FireFox317 has quit [Remote host closed the connection]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 258 seconds]
nero57 has quit [Remote host closed the connection]
<andrewrk> mrkishi, feel free to open a PR for that
casaca has quit [Ping timeout: 272 seconds]
jackhalford[m] has joined #zig
casaca has joined #zig
<jackhalford[m]> Hello all, It looks like I finally got irc to work correctly
<dingenskirchen> looks like it.
<halosghost> :D
<dingenskirchen> hi
<Tetralux> Greetings, fellow human.
<jackhalford[m]> First of all thanks for the great language, I'm finding systems programming to be fun again!
<fengb> o/
casaca has quit [Ping timeout: 245 seconds]
jackhalford[m] is now known as jzck
casaca has joined #zig
<andrewrk> oh hey jzck, I've been loosly following your kernel project
<jzck> yes, I had an influx of stars after you started following me ^^ I've been porting my code from rust for a while and I've finally reached feature parity. I'm much happier with the zig version, it's simpler and more readable.
<andrewrk> happy to hear that
<jzck> although I did copy quite a bit from zen/clashos, my next goal is to write a virtio-block driver in zig 🙂
<andrewrk> one of my goals is to have clashos improved to the point that it is a simple game I can demo at handmade seattle in november
<andrewrk> I might take a few weeks out of the 0.6.0 release cycle to accomplish that
<jzck> very cool, I see zig's already on the frontpage
laaron has quit [Remote host closed the connection]
laaron has joined #zig
THFKA4 has joined #zig
<Tetralux> Does the stdlib have a FIFO buffer?
return0e has quit [Remote host closed the connection]
casaca has quit [Ping timeout: 245 seconds]
casaca has joined #zig
return0e has joined #zig
return0e has quit [Remote host closed the connection]
<andrewrk> a double linked list? std.TailQueue
casaca has quit [Ping timeout: 246 seconds]
casaca has joined #zig
<Tetralux> Thanks!
return0e has joined #zig
<Tetralux> How do you cast a @Frame(f) to anyframe->void?
<andrewrk> `*@Frame(f)` casts to `anyframe->void` when the return type of `f` is `void`
<Tetralux> And @Frame(f) casts to anyframe->bool if f returns bool?
<andrewrk> no, but *@Frame(f) does
<Tetralux> I'm trying to put a newly 'async'd frame into a queue.
<fengb> Is there a way to detect whether a frame is alive?
<Tetralux> tailQueueSlot.*.data = async f();
porky11 has quit [Ping timeout: 250 seconds]
<andrewrk> fengb, no but that could be proposed. the data is available under the hood
<Tetralux> I'm essentially trying to heap allocate the frame but putting it into a queue that's on the heap.
<fengb> Alright, I can write something up
<fengb> It's mostly useful for generators but I've also been using a sentinel value
<andrewrk> Tetralux, the compiler rejects this for a good reason - if that's a queue of anyframe->T, which is a pointer type, those queue items will be pointing to async frames. which will be allocated where exactly?
<andrewrk> fengb, I could see that helping cleanup too
<Tetralux> Ah, I see.
<Tetralux> The anyframe->bool's are not actually frames.
<Tetralux> They are pointers to frames.
<andrewrk> yes
<fengb> Ah okay, I'll write something up
<andrewrk> Tetralux, in order for it to be not a pointer, the function has to be known. because the local vars, params, return value, are in the frame
Ichorio has joined #zig
<Tetralux> Makes sense.
<Tetralux> I started with the queue elements being @Frame(f), but f is polymorphic :)
<Tetralux> f(self: *Self, item: var) bool
<Tetralux> Is there a way provide the args that you want to pass to the generic fn so that you can get it's @Frame?
<Tetralux> I'm not sure that's a good way to use this whole mechanism though.
porky11 has joined #zig
<andrewrk> that's a bit broken at the moment. I think it will be @typeOf(foo(a, b, c)) but this currently will have side effects
<andrewrk> or rather @typeOf(async foo(a, b, c))
<Tetralux> When I tried it, my first thought was to do @Frame(f, arg1, arg2)
<Tetralux> FWIW.
<andrewrk> interesting. that's not a bad idea
<Tetralux> Symmetric with @inlineCall & friends :3
<andrewrk> I'm really missing zig's union safety right now. trying to figure out where this union value is getting corrupted after making modifications to stage1
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 246 seconds]
<Tetralux> Data breakpoints ftw
porky11 has quit [Ping timeout: 264 seconds]
<andrewrk> I know where the data is incorrect, but not where it is known to be correct. I tried using gdb's reverse-continue feature but it tripped over some AVX instructions in libc
ntgg has joined #zig
<Tetralux> The AstNodes don't have serial numbers do they...
<Tetralux> If they did, you could set a breakpoint in the set_serial fn when the serial is the one you know gets corrupted.
<andrewrk> it would be ConstExprValue not AstNode in this case
<andrewrk> that strategy for debugging would be possible with a bit of setup work
<andrewrk> I would resort to it if quicker methods didn't pan out
<Tetralux> I haven't used Zig enough to know if it mitigates the need for that method of debugging.
waleee-cl has quit [Quit: Connection closed for inactivity]
<andrewrk> it would solve my problem right now because I would get a stack trace of where the union field gets corrupted
<Tetralux> I'm curious how many bugs you feel like were discovered immediately because it was written in Zig (stage2)
<andrewrk> there's 3 or 4 extremely common bugs that I hit all the time in C and C++ that are completely eliminated in zig
<Tetralux> Any that would have taken hours to debug? xP
<Sahnvour> +1 for data breakpoints, and +2 for unique ids in internal structs ... really helpful for debugging
<Tetralux> Sahnvour: I wonder if we could have @dataBreakpoint(x) (where x is a pointer)
<Sahnvour> is there a benefit over setting the data breakpoint from inside a debugger ?
Akuli has quit [Quit: Leaving]
<Tetralux> Probably that the breakpoint you want to set depends on the current state of the program.
<Tetralux> But I haven't personally needed to use databreaks enough to know clearly.
<Tetralux> Well - more like I haven't needed to use them enough to remember the circumstances of them clearly, but still .xD
<Sahnvour> I don't see a usecase where it would be useful outside of a debugger, but running arbitrary code when the value at a particular address changes can make for great application-specific debugging tools
halosghost has quit [Quit: WeeChat 2.5]
laaron has quit [Remote host closed the connection]
laaron has joined #zig
Ichorio has quit [Ping timeout: 264 seconds]
scientes has joined #zig
ntgg has quit [Ping timeout: 246 seconds]
jrudolph has quit []
kristoff_it has joined #zig
rom1504 has quit [Ping timeout: 252 seconds]
<fengb> I accidentally called a suspending function without async and got a confusing error message: "resumed an async function which already returned"
<andrewrk> calling a suspending function without async is allowed. it's the same thing as `await async foo()`
<fengb> Yeah but it died with that error message
<fengb> I didn't resume it or anything
<fengb> Lemme toss up a localized example
<fengb> I'm not sure how it's returning, or how it's resuming since the code isn't doing either correctly
<andrewrk> fengb, oh, this is a bug that specifically has to do with zig test
<fengb> Ah okay
<Tetralux> How do you do that closure thing again?
earnestly has quit [Ping timeout: 248 seconds]
rom1504 has joined #zig
jrudolph has joined #zig
<andrewrk> once I get a bit further on async/await stuff in the std lib, tests that do async stuff will Just Work
<fengb> Ah I see
<fengb> Since I don't have a resume strategy, what is that supposed to do?
<andrewrk> if test were correctly async, the test would hang
<fengb> I converted it to `_ = async foo()` and it's working as I had expected
<fengb> My suspend point is the last statement. I'm still fiddling with a generator pattern
<fengb> Oh since I don't await, this function isn't async
<fengb> nvm I figured it out heh