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/
<terinjokes> bummer. i don't know enough zig to send a PR for that issue myself
_whitelogger has joined #zig
_whitelogger has joined #zig
cameris has quit [Quit: leaving]
curtisf has joined #zig
hio has quit [Quit: Connection closed for inactivity]
<terinjokes> is it possible to call a c pointer function (eg, `[*c]extern fn()`)?
<terinjokes> I can use @ptrCast, unsure if there's a better way
kristoff_it has joined #zig
cloudhop has quit [Quit: Page closed]
return0e has quit [Ping timeout: 248 seconds]
return0e has joined #zig
kristoff_it has quit [Ping timeout: 245 seconds]
husho has joined #zig
I_Right_I has quit [Remote host closed the connection]
hio has joined #zig
curtisf has quit [Quit: Page closed]
_whitelogger has joined #zig
_whitelogger has joined #zig
hio has quit [*.net *.split]
daurnimator[m] has quit [*.net *.split]
hoppetosse has quit [*.net *.split]
return0e has quit [*.net *.split]
THFKA4 has quit [*.net *.split]
ijneb has quit [*.net *.split]
return0e has joined #zig
hio has joined #zig
hoppetosse has joined #zig
daurnimator[m] has joined #zig
THFKA4 has joined #zig
ijneb has joined #zig
Summertime has quit [Quit: Sunsetting.]
Summertime has joined #zig
hio has quit [Ping timeout: 252 seconds]
hio has joined #zig
<gonz_> https://pastebin.com/mVG5pZSN - Will this reliably reduce the size of the struct to whatever is inside of it? The output I get seems to indicate that were only getting the size of the u32.
<gonz_> Also, has anyone figured out a way to create phantom types in zig? I don't really know enough about the way to handle comptime to create them.
<gonz_> https://pastebin.com/4D81njBJ - Right, I guess you can just do them sort of like this.
porky11 has joined #zig
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 248 seconds]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 272 seconds]
porky11 has quit [Ping timeout: 248 seconds]
porky11 has joined #zig
_whitelogger has joined #zig
SimonNa has quit [Remote host closed the connection]
SimonNa has joined #zig
nrdmn has quit [Remote host closed the connection]
marijnfs has joined #zig
kristoff_it has joined #zig
_whitelogger has joined #zig
marijnfs_ has joined #zig
<marijnfs_> i'm trying to make the zigtriangle code work again
<marijnfs_> but std.os.path moved somewhere?
<mikdusan> std.fs
<marijnfs_> mikdusan: thanks, and how does the new [_] syntax work?
<marijnfs_> it's for runtime slices?
<mikdusan> it's syntax for array, and meant to differentiate from slices when array size is inferred
<mikdusan> so old inferred size might be `... = []{ u8(5), u8(10) }` but it looks too much like slice
<mikdusan> so instead of forcing someone to `[2]{ u8(5), u8(10) }` infer is still supported but now `[_]{ u8(5), u8(10) }`
<marijnfs_> mikdusan: ah i see
Akuli has joined #zig
marijnfs has quit [Quit: WeeChat 2.4]
<gonz_> Why am I seeing a lot of `munmap(NULL, 0)` when using `DirectAllocator`?
<gonz_> Is this something inherent to the allocator or am I doing something wrong? Or is it simply a nonissue?
<gonz_> I don't know enough about these system calls to know what's going on.
husho has quit [Ping timeout: 245 seconds]
<andrewrk> terinjokes, [*c]extern fn() is actually a double pointer
<andrewrk> you'll have to dereference it once then call it. foo.*()
<andrewrk> function pointers are already pointers
<andrewrk> gonz_, size of structs is not guaranteed. if you need guaranteed layout you can use packed or extern structs
<andrewrk> DirectAllocator is probably not the allocator you want. it directly calls mmap for every allocation and munmap for every free
<gonz_> Yeah was mostly wondering about these `munmap(NULL, 0)`
<andrewrk> oh, I see
<andrewrk> that seems fishy, worthy of investigation
<gonz_> Pretty much every allocation is followed by one of these and I'm guessing I just don't know enough about the system calls to know what's going
<andrewrk> probably a regression in this logic https://github.com/ziglang/zig/blob/7c5ceb0c4cdf5fafadd92b13048bc9878554abc4/std/heap.zig#L108-L134 has caused unnecessary munmap calls
<gonz_> https://pastebin.com/7P9E2yLa - Just to make sure, am I doing crazy things here?
<andrewrk> if that's a command line application you probably want to wrap that direct allocator with an arena allocator, but no, nothing crazy
marijnfs_ has quit [Ping timeout: 252 seconds]
marijnfs_ has joined #zig
<daurnimator> gonz_: can you print a stack trace from your munmap function?
<andrewrk> cloudhop, I'll take on your use case for the live coding stream next thursday
<andrewrk> e.g. fix the issues with zig that are holding you back
<marijnfs_> andrewrk: you mentioned copy elision is holding back things like tha package manager, how is that?
<daurnimator> :( https://savannah.gnu.org/bugs/index.php?56402 nano doesn't think zig is significant enough to include a syntax highligher
<Sahnvour> to be fair since the grammar is likely to change, their choice makes sense
* daurnimator adds a wikipedia article
<mikdusan> daurnimator: nice. it needs one.
<Sahnvour> getting an article for a new programming language to make it into wikipedia is another long road ...
<Sahnvour> the nim folks struggled for months/years with it
<daurnimator> andrewrk: what are the rights on the zig logo?
<daurnimator> Sahnvour: IMO best thing you can do is create a stub article and start the conversation
<Sahnvour> probably can't hurt to do this yeah
marijnfs_ has quit [Quit: WeeChat 2.3]
<scientes> Influenced by
<scientes> C, LLVM IR
<scientes> correcto
marijnfs has joined #zig
<scientes> don't get me started about Wikinazis
<scientes> its basically a big exercise in bikeshedding
<daurnimator> scientes: yep. I expect that will get deleted and undeleted 3 times over the next 6 months :P
very-mediocre has joined #zig
Tetralux has joined #zig
Tetralux_ has joined #zig
Tetralux__ has joined #zig
Tetralux__ has quit [Client Quit]
Tetralux__ has joined #zig
Tetralux has quit [Ping timeout: 256 seconds]
Tetralux__ has quit [Client Quit]
Tetralux has joined #zig
Tetralux_ has quit [Ping timeout: 256 seconds]
<Tetralux> Hey all
daex has joined #zig
<andrewrk> daurnimator, I think there was even a more complete wikipedia entry previously that got deleted
<andrewrk> hi Tetralux
<andrewrk> regarding the logo, uhh I'm not sure. what should the rights be?
<andrewrk> the only thing I would want to prevent is something like a fork of zig falsely claiming to be the upstream project
<marler8997_> trademark :)
<andrewrk> or you know, a web page claiming to be the official zig homepage but it's lying
<marler8997_> that's exactly what trademark is for
<andrewrk> ok sounds like that's the answer
<marler8997_> not sure if it applies to organizations though, might just be for companies
<donpdonp> speaking of identity, zig-lang does not show up on https://en.wikipedia.org/wiki/Zig
<andrewrk> marijnfs, it's because I want to rely on result location semantics (copy elision part 1) to re-do coroutines. and I want that coroutine rework for doing networking, just because I think it's really nice to have async/await syntax for networking operations. this enables writing "pipeline" style coding which I want for both self hosted compiler and package manager
<daurnimator> andrewrk: I searched for deleted articles and found nothing
<andrewrk> daurnimator, me too. I'm not sure what happened
<daurnimator> andrewrk: the logo needs to be documented as under an acceptable copyright notice
<daurnimator> wikipedia like cc-by-sa-4.0 or cc-by-4.0 or GFDL
<daurnimator> andrewrk: where *is* the source of the logo? I see that it's an SVG. could you just throw it into a repository ziglang/logo on github?
<andrewrk> yeah, help me pick a license
<andrewrk> cc-by-sa 4.0 seems fine
<scientes> +1 cc-by-sa 4.0, perhaps dual license GPL-2+
<scientes> but its kinda expensive at this point for that
<daurnimator> donpdonp: added.
<scientes> oh no dual licensing is more for documentation, where I like it better than CC
<daurnimator> FWIW the lua logo has its own copyright notice... https://www.lua.org/images/
<donpdonp> daurnimator: i see it. awesome.
<scientes> but logos are really about trademark, not copyright
<scientes> totally differn't things
<daurnimator> scientes: they are both. though logos usually fit under fair use
<scientes> There was a pedicure place that used the GNOME logo, and they were fine with it
<scientes> so in that case it is 100% trademark
<scientes> no confusion, no problem
<andrewrk> daurnimator, https://github.com/ziglang/logo
<andrewrk> my last name has an `e` between l and y
<daurnimator> Also, I'm happy to have just submitted #2688; I've been working on it for a few days: breaking the rule of "don't implement your own crypto" :P
<scientes> add the text of the license go github can automatically parse it
<scientes> in LICENSE
porky11 has quit [Ping timeout: 248 seconds]
<andrewrk> I gave up after 5 minutes looking for a plain test cc-by-sa 4.0 LICENSE file
<andrewrk> *plain text
<BitPuffin> Is there a nice way to return multiple values
<andrewrk> brilliant
<andrewrk> BitPuffin, not yet, your best bet is a struct
porky11 has joined #zig
<andrewrk> alright back to result location branch for me
<daurnimator> logo uploaded to wikipedia.
<BitPuffin> andrewrk: does anonymous work? I don't think I managed to figure that out
<andrewrk> Look for "Wikipedia"
<daurnimator> andrewrk: ah right. looks like that was in a deleted draft
lunamn has quit [Ping timeout: 272 seconds]
lunamn has joined #zig
porky11 has quit [Ping timeout: 248 seconds]
porky11 has joined #zig
<Tetralux> Question: Should release-safe print a stack trace when it hits unreachable code?
<Tetralux> It _should_, right?
<Tetralux> Only I have some code that works fine in debug and release-fast, but crashes in release-safe without a stack trace.
<scientes> paste the code
<Tetralux> Oh - and the non-crashing behavior behaves differently in zig 0.4 and the 'master' zip from ziglang.org! x'D
<scientes> it is impossible to have a perfectly safe language (Turing prooved that), so that is always possible
<scientes> but it may still be a fixable bug
<scientes> preferrably on godbolt.org
<Tetralux> I'll do that too
<scientes> and it would be nice to show the stack trace when you run it in gdb
<Tetralux> I'm on Windows x64.
<scientes> cause gdb should be able to get you a stack trace
<scientes> or lldb
<scientes> not sure if the windows debugger works, i'm not a windows person
<scientes> i know stack traces work, i just know nothing about the debug format with COFF
<Tetralux> In VS 2019, it points to roughly the right area in the file, but that's about it.
<Tetralux> Also
<Tetralux> Totally forgot about lldb XD
<Tetralux> But
<companion_cube> Turing din't prove that, it depends on the definition of "safe"
<Tetralux> That gives me no stack tracce.
<Tetralux> (lldb doesn't)
<scientes> companion_cube, i would say that the program never completing is not safe
<scientes> and should be UB (as it is in C++)
<Tetralux> (I'm guessing by UB, you mean, "the program may or may not crash" - like if you read uninitted memory.)
<Tetralux> But yes ;p
<scientes> crashing is much preferred to incorrect results
<marijnfs> andrewrk: cool, will await a live coding where all the new copy stuff gets explained!
<Tetralux> @scientes Agreed - though often incorrect results are unavoidable ime.
<companion_cube> scientes: that's a possible definition that does indeed preclude turing completeness
<companion_cube> but other definitions (like safe rust) are pretty valid too
<scientes> yep
<Tetralux> I don't really know how best to go about debugging this.
<scientes> yeah the stack trace is segfaulting
<Tetralux> Yeah - that's what I thought
<Tetralux> I tried to narrow it down to figure out if I could jury rig fix it
<Tetralux> But without being able to check variables... :^)
<Tetralux> I know nothing about COFF.
<Tetralux> So there isn't really anything I can even printf on.
<Tetralux> 'less I'm missing something obvious.
<Tetralux> I'm also interested as to why this code doesn't work the same on master.
<Tetralux> That seems bad.
<Tetralux> Normally, it should remove the '4', as it does on 0.4.0 debug mode
<scientes> you could bisect it
<scientes> but that would require you to set up a build environment
<scientes> FWIW I reproduced it in Linux
<Tetralux> I'm can't really do that on Windows... building LLVM...
<scientes> no you don't have to build llvm
<scientes> can can use these binaries http://releases.llvm.org/
<Tetralux> I have Clang 8 already - so presumably LLVM 8 too?
<scientes> yes
<Tetralux> OK
<Tetralux> I have no idea how to make Zig use it though.
<Tetralux> build.zig or env vars?
<scientes> there is documentation on the wiki
<scientes> but I don't know
<Tetralux> What would I be looking for if I bisect?
<Tetralux> Just who last fiddled with it? xD
<Tetralux> I'm not the biggest expert at git either XD
<scientes> well you git checkout 0.4.0, then git bisect good, then git checkout origin/master, then git bisect good
<scientes> and then it will lead you through it
<scientes> but you have to build it
<scientes> *git bisect bad for HEAD
<scientes> Tetralux, oh no, 0.4.0 is bad for me
<Tetralux> Bad in what way?
<scientes> it has the same problem
<scientes> with your code and --release-safe
<Tetralux> That's what I meant
<scientes> you have to have a bad and a good to use git bisect
<Tetralux> It happens on 0.4.0
<scientes> i thought you said otherwise
<Tetralux> Sorry - maybe I wasn't clear xD
<scientes> nah I'm distracted with programming
<Tetralux> There's two problems
<Tetralux> Debug mode on master behaves badly, and 0.4.0 debug mode behaves as it should
<Tetralux> release-safe on 0.4.0 is bad though.
<Tetralux> (First one removes too many items when it should only remove the '4')
<scientes> I can't reproduce it with debug mode on master
<Tetralux> (And second one crashes without stack trace.)
<Tetralux> I used master from ziglang.org if that helps.
<Tetralux> I guess that's fixed now?
<scientes> I'm not really looking into your code right now. you need a more reduced test case for that
<Tetralux> *shrug*
<scientes> well there is a bug there
<scientes> at least in that the stack trace code seg faults
<Tetralux> There's actually another bug as well
<Tetralux> Because if you search it for FIXME
<Tetralux> There's an if branch I don't need but have to have. x'D
<Tetralux> This is my feelings right now: Ó.Ó
<Tetralux> *grins*
<Tetralux> But no - the segfault - that's one I can't get past.
<Tetralux> The rest I can avoid for now.
<Sahnvour> Tetralux: to build zig from source on windows https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows
curtisf has joined #zig
<curtisf> Is there a convenient way to use a tagged union with anonymous structs as the fields? Like, how could I easily make a literal of the type `Op = union(enum) { Assign: struct { d: V, s: V, } }` ?
<Tetralux> Sahnvour: Ty (y)
<Tetralux> (PS: IRC noob here)
<Sahnvour> you're welcome
porky11 has quit [Ping timeout: 248 seconds]
porky11 has joined #zig
<Tetralux> Well
<Tetralux> I managed to build zig
<Tetralux> And tested every fifth commit for a while, before and after 0.4.0, and then every tenth commit until I needed LLVM 7.
<Tetralux> Every single commit does NOT have a stack trace on release-safe.
<Tetralux> Stupid question but... did release-safe EVER have a stack trace?
<emekankurumeh[m]> it should
<gamester> Tetralux: I commented out the asserts in your code and then I get "attempt to unwrap null". Turns out it's index.? in append.
<gamester> linux + master here
<gamester> well master from sometime yesterday
<Tetralux> So, it also commented out the assert for index != null and also got the attempt to unwrap null.
<Tetralux> I also*
<Tetralux> So I'm glad THAT is the same!
<gamester> But only on --release-safe. Even if I insert an explicit if (index == null) { std.debug.warn, std.os.exit ...} then it only hits this branch on release-safe
<Tetralux> Yeah - on debug or release-fast - everything goes just fine.
<Tetralux> Well
<Tetralux> master on release-fast is wrong
<Tetralux> but doesn't crash
<Tetralux> but master on debug mode is fine.
<Tetralux> Also
<Tetralux> gamester: Can you verify that if you remove the if (occupied) branch and check for if (!occupied) instead
<Tetralux> gamester: that it also doesn't work.
kristoff_it has quit [Ping timeout: 246 seconds]
<gamester> Tetralux: yeah I think so. Sorry I've been changing the code a bit, I'm in the flow. I've reduced the issue a lot. Also noticed some additional problems, maybe. does the allocator's create function guaranteed initialization? I don't know. But you don't initialize the buckets explicitly but that's not the source of the issue
very-mediocre has quit [Ping timeout: 256 seconds]
<gamester> Tetralux: I've reduced the problem, currently at this: https://pastebin.com/6mRntrHV
<gamester> just a single append
<gamester> run with --library c
<gamester> compile*
Akuli has quit [Quit: Leaving]
<gamester> Tetralux: actually I did the secureZero wrong
<gamester> Tetralux: the issue is that you don't initialize the buckets
<gamester> I just winged the secureZero lol, wasn't thinking. This works at least: std.mem.secureZero(Self, @ptrCast([*]Self, &self)[0..1]);
<marler8997_> Quick question, on the instructions to build llvm/clang from source (https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#posix)
<marler8997_> why does the example include -DCMAKE_PREFIX_PATH=$HOME/local in the LLVM example?
<marler8997_> I would think you would only need that argument when building clang, so clang could find LLVM, but why does llvm include it?
<gamester> Tetralux: So you'll noticed that in the paste that I sent you, if you fix the secureZero call, then both with and without --release-safe will work. If you remove the secureZero or leave it with the wrong slicing syntax, then with --release-safe you'll hit the null index problem
<gamester> Tetralux: but through this issue didn't you find an issue with a crashing stack trace? It looked like that to me, running the program through gdb. That's a bug.
<curtisf> Where are slice-literals allocated? On the stack? Where does their lifetime end? The end of the statement they're in? end of block? end of function?
<gamester> a slice is just a struct with a pointer and a length, so the same as with any struct. It's placed wherever you place it. There's no hidden allocation.
<curtisf> I mean if I write `x = f([]Obj{a(), b(), c()})` where is the array of 3 elements allocated? The expression doesn't say where it goes
<emekankurumeh[m]> I'm pretty sure that would be a compile error
<curtisf> hrm maybe this is only working because it's being evaluated at comptime
<emekankurumeh[m]> that would be an array not a slice, so that would go in the stack
<emekankurumeh[m]> nvm
<marijnfs> man the vulkan triangle code crashes my window manager
<marijnfs> that's some strong code
<gamester> vulkan, vulkan, vulkan.... shame on you
<gamester> that's vulkan for you
<andrewrk> curtisf, that's an array literal. the new syntax is `[_]Obj{a(), b(), c()}`. if it is known at compile time, it is allocated in the static const data section of the object file
<andrewrk> function call results are runtime known when not in a comptime context, so that will be a runtime-known array literal. those are allocated on the stack
<andrewrk> in the result location branch that I'm working on merging soon, array literals are not allocated anywhere; instead they directly instantiate the result location
<andrewrk> so if you were to, for example, do `some_pointer.* = [_]Obj{a(), b(), c()};` then the array literal would directly initialize some_pointer[0], some_pointer[1], and some_pointer[2]
<andrewrk> in your example you are passing the array literal to a function foo() as the first argument. the result location for parameters is the stack
<curtisf> ah, so I should be using `[_]`, didn't realize that. So how do I figure out how long slices/pointers to arrays remain valid? Is it always the end of the enclosing block? or can it be shortened because it will be emplaced somewhere with a shorter lifetime?
<andrewrk> curtisf, when you update to the latest master, yes
<Sahnvour> it's valid as long as the original data it is pointing to is
<andrewrk> the lifetime of something is always determined by the `var` or `const` declaration
<emekankurumeh[m]> are you going to do another round of PR after you merge the result location branch?
<andrewrk> emekankurumeh[m], yes
<andrewrk> at least one
<andrewrk> for automatically allocated parameters, the lifetime ends when the callee returns
<andrewrk> if you have an array you declared with `var` or `const` then it's the scope that the declaration is in
<andrewrk> donpdonp, I didn't realize you had gotten so far on your mastodon client project
<curtisf> OK. Thanks for explaining! I think what I'm doing is OK. For future learners I think it would be useful to have these rules written down somewhere in the manual with positive&negative examples
<andrewrk> curtisf, certainly. in fact I plan to do even better than that: have debug & release-safe modes reliably detect violations and produce crashes with useful messages
<curtisf> :)
karrick_ has joined #zig
karrick_ has quit [Remote host closed the connection]
<Tetralux> gamester: Oh man ty!
<gamester> np!
<Tetralux> gamester: So basically, the probably was that undefined != zeroing.
<Tetralux> That seems to be the lesson here.
<Tetralux> Right?
<Tetralux> Well - and a bug with release-safe stack traces.
jjido has joined #zig
<Tetralux> If so - I was actually aware of that point of uncertainty as I was writing init, but figured it would be okay because I'd find out later if it was full of junk.
<Tetralux> But then I found myself unable to debug it x'D
<Tetralux> It seems very unwiedly to have to slice a unknown-length pointer to Self and then pass that to a zeroing function for just ensuring that your variable is zeroed, considering that's normally what you want.
<donpdonp> andrewrk: hey thx! I made that page just yesterday. and thanks for Zig. :)
<gamester> Tetralux: well I introduced the init function for the Bucket. You were just calling allocator.create without initializing the resulting contents of the pointer
<Tetralux> Oh yeah
<Tetralux> I remember
<andrewrk> Tetralux, release-safe stack traces produces more complicated debug info, which zig's standard library isn't capable of understanding yet
<Tetralux> I actually had an init for it when I wrote it originally, but removed it because again - I figured I'd just discover if it wasn't zeroed later.
<gamester> Tetralux: well I don't remember the best way to zero things since I never need to. Usually you're more explicit than that. But I do think secureZero is how people do this.
<andrewrk> but it's something that can be improved
<andrewrk> secureZero is more to do with leaking sensitive data
<gamester> ah, between the fields
<andrewrk> Tetralux, for many types, such as structs, zig purposefully does not define a memory layout. this allows zig to put runtime safety check information in the spaces between fields
<andrewrk> this is how we have safety for accessing the wrong union field, for example
<andrewrk> if you were to memset a struct to zero you would mess up the safety information
<Tetralux> andrewrk: Okay - so - couple of things:
<Tetralux> andrewrk: RE debug info in release-safe: Ah, I see. I'm guessing then that using if (index == null) { ... } is better than assert(index != null) if you intend to use release-safe then.
<Tetralux> At least until you have a stack trace for it.
<andrewrk> assert(false); is defined to call the panic handler function in release-safe mode, and the default panic handler dumps a stack trace and then calls abort()
<Tetralux> Okay, so until the stack trace, using if (index == null) assert(false) then.
<andrewrk> it's better to use assert when assert is appropriate; the fact that stack traces lack debug info in release-safe mode is not really relevant in my opinion. you can override the default panic behavior if you don't like it
<Tetralux> Define appropriate.
<Tetralux> xD
<andrewrk> assert is defined simply as: fn assert(ok: bool) { if (!ok) unreachable; }
<Tetralux> Indeed it is.
<andrewrk> assert is appropriate when the condition being false is unreachable code
<Tetralux> I see.
<andrewrk> note that errors such as parse errors or "file not found" errors are not unreachable code
<andrewrk> they are in fact quite reachable
<gamester> yeah you should use assert for index != null except that you actually don't need to since that's what index.? does
<andrewrk> the less obvious it is that a code path is unreachable, the more helpful an assert will be
<Tetralux> So, since I tend to use assert to mean "tell me if this isn't true", and assert(index != null) is probably "reachable", I shouldn't use it like that.
<Tetralux> Okay
<Tetralux> There's a thing here
<andrewrk> if it's reachable, then you should handle the situation in some way. probably returning an error or reporting the situation to the user
<andrewrk> or panicking. that's sometimes quite reasonable
<Tetralux> In this case, index being null means the code is wrong.
<Tetralux> And that I need to fix it.
<Tetralux> Which is why I used assert.
<Tetralux> But
<andrewrk> gamester is correct though - if you were to do index.? that is a language-level assert that the index is not null
<Tetralux> Indeed.
<Tetralux> Makes sense.
<Tetralux> But my problem was multi-faceted.
<Tetralux> In this case.
<Tetralux> My create'd struct wasn't zeroed.
<gamester> yeah if the code is wrong when an assert would be untrue then using an assert is correct
<andrewrk> agreed ^
<Tetralux> Likewise.
<Tetralux> It seems like a bit of a corner case to me, perhaps.
<Tetralux> Because I was using it redundantly to index.?
<Tetralux> And because my struct wasn't zeroed properly, it was quite hard for me to determine what was actually happening
<Tetralux> because it didn't happen in a mode with a trace.
<Tetralux> Though, doing var thing = create(); thing.* = init() will help avoid that.
<Tetralux> I'm not used to there being copy elision like that :p
<Tetralux> Well - that's maybe not quite right, but hopefully you get what I mean xD
<Tetralux> Basically
gamester has quit [Remote host closed the connection]
gamester has joined #zig
<Tetralux> When programming exploratively, use the pattern of thing.* = Thing.init() which should hopefully get you a trace when something does go wrong
<gamester> marijnfs: the same thing happened to me. Hmmm
<Tetralux> Asserts are NOT compiled out of release-fast right?
gamester has quit [Remote host closed the connection]
<Tetralux> Apologises for babbling - thinking out loud. Don't mind me xD
<Tetralux> Oh right - I remember why I removed Bucket.init now: I was having trouble figuring out how I set the array fields to all zeroes.
<Tetralux> return Bucket{ .occupied = (an array of items all zeroes), ... }
<Tetralux> Is the idiomatic way to do that, to use mem.zero?
<Tetralux> (.occupied is [N]T)
<marijnfs> gamester: yeah i'm trying to pinpoints where it is
porky11 has quit [Quit: Leaving]
<andrewrk> Tetralux, you can create an array literal with all zeroes (or any pattern) like this: [1]i32{0} ** 100
Ichorio has joined #zig
<Sahnvour> Tetralux: you can assign a default value to occupied in the struct declaration, something like `occupied: [N]T = [_]{ 0 } ** N,`
<Sahnvour> andrew's syntax is more correct :p
<andrewrk> Sahnvour, yours looks correct to me too, and that's a good point about default struct field value
<andrewrk> oh, you forgot the T, I see it now :)
<curtisf> cls
curtisf has quit [Quit: Page closed]
<Sahnvour> yup
<Sahnvour> which makes me think, is the `: [NT]` required in this case ?
<Tetralux> Yep, I actually remembered I could do that just before I came back to read this. x'D
<Tetralux> Is `[_]{0} ** N` real syntax?
<Tetralux> Can you infer the eltype like that?
<Sahnvour> if you add T, it is, otherwise it's not
<Sahnvour> that's a typo on my side
<Tetralux> You mean [T]{0} ** N?
<scientes> [_] was added very recently
<Sahnvour> [_]T{0}**N
<Sahnvour> [_] means you let the compiler determine the size by the number of following elements in braces, iiuc
<Tetralux> Okay - so on 0.4.0, it's an error to use that to mean "infer the count please"
<Tetralux> Whereas on master it infers the count as you describe.
<Tetralux> But you can just omit it in both places and it also works.
<Tetralux> ie: .occupied = []T{0} ** N,
<Tetralux> (coerces to a fixed array)
<Tetralux> Also
<Tetralux> I just realised
<Tetralux> The data field isn't always integers right
<Tetralux> So
<Tetralux> I can't do
<Tetralux> thing.* = Bucket{ ..., .data = []T{0} ** N }
<Tetralux> because 0 isn't a T unless T is an integer.
<Tetralux> And for the same reason I can't default-struct-field-value it either.
<Tetralux> Right?
<Sahnvour> oh, you want to zero-initialize any type ?
<Tetralux> Well
<Tetralux> I suppose I can get away with 'undefined' there because I only read it if occupied is true
<Tetralux> But now you mention it
marijnfs_ has joined #zig
<Sahnvour> undefined seems like the good tool to use in that case
<Tetralux> Also FYI, I actually _have_ to use [_]bool{false}**N for default-struct-field-values.
<Tetralux> Without it, it doesn't coerce to a fixed array, like it would if you are creating a struct literal.
<Tetralux> That seems a little inconsistent.
<Tetralux> andrewrk: You mentioned that you cannot zero a struct because it will fudge with the safety. Can you elaborate on how that safety works, and what would happen if you _do_ zero it?
marijnfs_ has quit [Quit: WeeChat 2.4]
fengb has joined #zig
<fengb> I'm having trouble running tests on mac: https://gist.github.com/fengb/36b81ad1529ab5a082021201bb43587e
<fengb> Really weird thing: fd_t is the 4th reference so it seems to just disappear
<scientes> Tetralux, default values will take care of that use case
<Tetralux> scientes: It would, yeah. I do want to understand that though ;p
fengb has quit [Ping timeout: 256 seconds]
<Tetralux> Hey - I just want to say thanks for all the help. It is most appreciated!
<Tetralux> It helped quite a lot :p
<scientes> Tetralux, welcome!
<Tetralux> o7
gamester has joined #zig
<gamester> marijnfs: The issue seems to be in the .imageFormat or .imageColorSpace fields of VkSwapchainCreateInfoKHR
<gamester> I'm really surprised that the validation layers aren't detecting this
<gamester> I ported over my instance create logic to make sure I had working validation layers and they didn't complain, though I've yet to test them to make sure they're on
<gamester> well nvm, they are sending me informational messages so obv they're on
<marijnfs> gamester: yeah are all layers on actually?
<marijnfs> there are many
<marijnfs> so whats the fix?
<gamester> I'm not sure yet
<gamester> Don't know what the issue is
<Tetralux> gamester: Thanks for the help and your effort earlier! I appreciate it.
<gamester> no problem
<Tetralux> o7
<marijnfs> gamester: nice catch though, seems strange that any swapchain creation shouldnt be able to do that
<marijnfs> could be driver bug
<gamester> invalid enum value
<gamester> hmm but the format choosing logic is identical to mine
<marijnfs> gamester: i was printing availableFormats in chooseSwapSurfaceFormat, and it crashes in the fmt function
<marijnfs> maybe some memory is screwed up
<gamester> yeah
<marijnfs> gamester: when i run it in valgrind it goes crazy
<marijnfs> but actually i get a triangle!
<gamester> hah
<marijnfs> lots of writes in not alloced memory..
<gamester> wow how did I forget about valgrind
cyanmide has joined #zig
<gamester> marijnfs: details.deinit() shouldn't be there
<marijnfs> createCommandBuffers (main.zig:189)
<gamester> in querySwapChainSupport
<gamester> I think that's the issue. One wrongly placed 'free' is enough to get Vulkan to crash the OS' display manager! YES! PROGRESS!
<marijnfs> gamester: that actually fixes it, you da man
<gamester> andrew: ^
<gamester> andrewrk
<gamester> marijnfs: maybe you can do a pull request to vulkan triangle stuff? I don't know git
<gamester> just remember to free that struct elsewhere, and maybe this should be designed differently so this is less likely to happen
<marijnfs> gamester: sure i will
<marijnfs> gamester: you would almost want a defer to pass through a return, or attach it to the runtime lifetime of a variable
<gamester> Also the validation layers should 100% detect this, right? I'm going to sleep but this has to be fixed by them as well.
<gamester> maybe it is detected but the logic still goes through and we can't see the message cause the OS partly crashes
<gamester> maybe there is file logging
<marijnfs> gamester: yeah, anyway i created the pull request
<gamester> awesome!
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<marijnfs> it would be nice to have a lifetimedefer
<andrewrk> marijnfs, that's a destructor
<andrewrk> thanks for the PR
gamester has quit [Remote host closed the connection]
gamester has joined #zig
<gamester> ok I redirected stderr and indeed the issue is caught
<gamester> I should have done that from the start heh
<marijnfs> andrewrk: does zig have that?
<andrewrk> no
<andrewrk> you can just make one though. make a function to call when the variable's lifetime is ending, and then call it
<andrewrk> the bug here probably originated from porting c++ code (which does have destructors) to zig, and I made a mistake
<marijnfs> andrewrk: yeah, it would be nice if zig could pick up such mistakes
<gamester> not possible
<gamester> valgrind can!
<andrewrk> even the planned safety features would not have been able to catch this problem, since the type is extern and thus has a well-defined memory layout
<marijnfs> andrewrk: yeah it's a hard problem
<andrewrk> interacting with C APIs always has unsafety problems. that's true in rust as well, all this vulkan code would have `unsafe` keywords everywhere
<andrewrk> this is an area where zig can actually help a bit more than rust, since the seam between safe and unsafe is less rigid
<marijnfs> the proper debug support is really nice in zig
<marijnfs> does clangs memory sanitizer pick such things up?
<andrewrk> it was an invalid free you said? actually in this case the debug allocator I've been working on would have been able to catch it
<marijnfs> andrewrk: yeah was wondering aobut that
<andrewrk> we can test that claim
<marijnfs> is it finally finished:P
<gamester> the free wasn't invalid
<gamester> it was too early
<marijnfs> yeah its not a doubble free
<andrewrk> ah. so passing bogus pointer to vulkan
<marijnfs> yes, not even passing, just the info struct that is returned (and not to be used by vulkan) is already freed
<marijnfs> so it might just have some crazy values
<gamester> nah, it's the arrays in the struct that get freed
<gamester> so yes a bogus pointer
<andrewrk> I'm not sure about memory sanitizer. there is an open issue to investigate what integrating with that would look like
<andrewrk> there's also an issue about making stack allocations detect safety issues