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/
<Snektron> very nice
<daurnimator> andrewrk: I assume you saw the error(s) I hit when swapping out the return type of toSlice?
<andrewrk> I appreciate your enthusiasm, trying out a branch that doesn't even have these check boxes done :) but yeah I wouldn't expect it to work until I add those test cases and fix whatever issues come up
<Snektron> What sentinel syntax got implemented in the end?
<Snektron> [123 :0]u8?
<daurnimator> andrewrk: none of the unticked boxes seemed relevant to the errors I hit :)
<Snektron> Ah yes
<andrewrk> daurnimator, "Take advantage of null terminated pointers in the standard library"
<Snektron> Also:
<Snektron> i think argv is officially null-terminated
<Snektron> not only the elements, but also argv itself
<daurnimator> Snektron: likewise environ
<daurnimator> at least they are on linux.... not 100% sure about other platforms
<Snektron> yeah, so already a nice use case
<Snektron> Does this mean that c string syntax will be deprecated btw? considering they can now be expressed as `const c_str: [_:0] = "i like pythons";`
<daurnimator> Snektron: yep. you'll see the PR already has that done
<andrewrk> not only deprecated, it's completely removed
<andrewrk> to fix your code, simply delete the letter `c`
<daurnimator> and sometimes suffix a .*
<Snektron> so all strings now get a sentinel by defailt?
<daurnimator> Snektron: yep
<andrewrk> daurnimator, no, not for upgrading C string literals. they were already pointers
<daurnimator> andrewrk: oh okay
<andrewrk> this is in preparation for another breaking change... removing the type ceorcion from array values to const slices. you'll have to use &
<Snektron> What if you want to circumvent automatic sentinels?
<pixelherodev> "all strings now sentineled by default" :(
<andrewrk> I promise you this change will be strictly more convenient for you
<Snektron> no doubt; just wondering about intricacies
<andrewrk> you could circumvent automatic sentinels with a comptime function call
<andrewrk> in case it isn't perfectly clear: string literals still cast to `[]const u8`
<andrewrk> but now they *also* cast to `[*:0]const u8`
karrick has joined #zig
<pixelherodev> "you could circumvent automatic sentinels with a comptime function call"?
karrick has quit [Remote host closed the connection]
<andrewrk> sure, for example, you could make a function called `s`, used like this: `s("foo")` and returns `[]const u8` based on a new array in memory with no sentinel. zig would figure out the original string literal is not used and only include the non-terminated one in the binary
<andrewrk> this is also how you would implement, for example, decoded strings as string literals
<daurnimator> andrewrk: actually that's something I'm never sure about with zig: what is the lifetime for things like that
<andrewrk> the answer is comptime garbage collection
<daurnimator> also things like: `&io.BufferSlice(&mybuffer).stream` -> isn't that BufferSlice itself going out of scope and hence the address is invalid?
<pixelherodev> decoded?
<Snektron> Also i thing i was wondering about: Does llvm do autovectorization with Zig?
<Snektron> i just saw my counting sort implementation go from slow to fast when i switched to clang from gcc
<daurnimator> pixelherodev: I guess: `Base64.decode("stringliteral")` -> the decode can happen at comptime and hence you want the result in the binary, not the source string
<pixelherodev> ah
<daurnimator> (also that example is terrible... sorry :P)
<andrewrk> Snektron, yes it does
<andrewrk> daurnimator, if you take the address of an element/field of a comptime value, that is still referencing the base
<andrewrk> @fieldParentPtr works at comptime
<daurnimator> andrewrk: but not at runtime? that feels a little foot-gun-y
<andrewrk> ?
quetzalb has quit [Ping timeout: 260 seconds]
<andrewrk> @fieldParentPtr has no relation to comptime/runtime, the abstraction holds
<daurnimator> --> taking address at compile time? works fine; lifetime is safe. taking address at runtime: better make sure its valid.
<andrewrk> it's the same thing. the difference is that the lifetime of a comptime const is immortal
<andrewrk> you could also have an immortal runtime object. for example if you put it in the stack frame of main()
<daurnimator> andrewrk: is the `&io.BufferSlice(&mybuffer).stream` pattern safe?
<protty> un-ironically a cool way to say static
<andrewrk> daurnimator, well we have this issue open for that: https://github.com/ziglang/zig/issues/591 but there's planned safety to catch this
<daurnimator> andrewrk: okay, so that *isn't* safe? glad I removed them all then (in my upcoming mixin PR)
<andrewrk> I'm not sure what you're asking
<andrewrk> to me "safe" means "impossible to invoke undefined behavior"
<andrewrk> your question doesn't have enough information (I'd need a full test case) to evaluate whether this is true or false
<daurnimator> andrewrk: the standard library is full of that unsafe pattern. e.g. https://github.com/ziglang/zig/compare/master...daurnimator:stream-mixin#diff-708e6cd00a3602833a869843e685878bL716
<andrewrk> there's 2 ways for this pattern to go wrong
<andrewrk> (1) forgetting the &, which is #591
dima_lanski has quit [Remote host closed the connection]
<andrewrk> (2) otherwise obtaining an, e.g. *Allocator which some code does @fieldParentPtr on it, but in fact, it had a different parent than the one asserted. (1) is just causing this (2) thing to happen
<andrewrk> both planned to have safety panics
<andrewrk> regardless of the mixin thing, this pattern is still relevant. it's how intrusive linked lists work, for example
<daurnimator> andrewrk: okay yeah. was just suprising to see how pervasive the mistake is even in the standard library
<daurnimator> --> and also how we seem to luck out and have it work
<andrewrk> what mistake are you talking about?
<daurnimator> what I just linked to....
<andrewrk> I'm aware of 0 instances of the mistake in #591 occuring in the std lib
<daurnimator> `var buf_stream = &io.BufferOutStream.init(&buf).stream;`
<andrewrk> that is valid
<andrewrk> the mistake is omitting the &
<daurnimator> how is that valid? `io.BufferOutStream` has two members: .buffer and .stream.
<daurnimator> the stream uses `const self = @fieldParentPtr(BufferOutStream, "stream", out_stream);` to get back to the BufferOutStream
<andrewrk> what's the problem?
<protty> does doing `var x = &T{.y=z}` where z is runtime known create a temporary T and store the address of that in x?
<daurnimator> andrewrk: where does the BufferOutStream live?
<daurnimator> `var bo = io.BufferOutStream.init(&buf); const buf_stream = &bo.stream;` -> that would be safe.
<andrewrk> protty, yes. the memory will be in the current stack frame.
<daurnimator> but without `bo` being in scope, isn't it unsafe?
<pixelherodev> Taking the address of a temporary
<daurnimator> right: `&io.BufferOutStream.init(&buf).stream;` is taking the address of a temporary.
<daurnimator> is taking the address of a temporary allowed?
<andrewrk> daurnimator, yes
<pixelherodev> At the very least, *returning* that address is bad, right?
<andrewrk> pixelherodev, correct
<pixelherodev> But it's valid within the stack frame in question?
<daurnimator> andrewrk: so temporaries are valid until.... the next }?
<andrewrk> correct
<pixelherodev> Interesting
<andrewrk> daurnimator, yes
<dbandstra> news to me as well hehe
<daurnimator> news to me... and suprising
<andrewrk> the exception is if the value is comptime known. then it's a pointer to comptime const data
<andrewrk> which, if you think about it, is why it's OK to return a string literal
<protty> so something like:
<protty> `const x: *const T = &T{}` will have x point to a const memory region?
<andrewrk> well in this case it will be a no-op. but if you make that 1 element or more, then yes
<protty> makes sense
<daurnimator> `const buffer_out_stream = &io.BufferOutStream.init(&buffer);` // is the temporary mutable? --> is it a `*io.BufferOutStream` or a `*const io.BufferOutStream`?
Cucumbas has quit [Read error: Connection reset by peer]
<andrewrk> & gives you exactly the mutability of the thing you're referring to
<andrewrk> whether it's a temporary or not doesn't enter into it
<daurnimator> uhhhhh
<andrewrk> wait, I'm wrong, it does enter into it. that's a good question
<mikdusan> andrewrk: if there was no address of tmp taken, is compiler free (and can zig/llvm today do it) to use the same tmp storage in a next statement in same block?
<andrewrk> mikdusan, the lifetime is until the end-of-scope
Cucumbas has joined #zig
<andrewrk> but note that some scopes are not explicitly represented with { }
<andrewrk> when taking the address of a temporary, the lifetime gains the same lifetime as the result location that accepts the reference to the temporary
<andrewrk> so in daurnimator's example above, the lifetime of the temporary that got its address taken, is the lifetime of buffer_out_stream
<andrewrk> btw I would be open to proposals about this. I was just trying to answer questions about status quo
<mikdusan> got it. i had just assumed that `warn("{}\n", a+b); warn("{}\n", c+d);` would/could use same temp storage
Cucumbas has quit [Read error: Connection reset by peer]
<andrewrk> for integers, I don't think there is even a concept of the storage for a+b or c+d
Cucumbas has joined #zig
<andrewrk> but maybe your example could have foo() and bar() as the parameter to warn
<andrewrk> with a struct return type
<andrewrk> in these cases, the result location is a temporary result location created by the parameter. the scope is the parameter expression. so yes zig is free to reuse the same temp storage
<andrewrk> each parameter to a function is a new result location
<dbandstra> news to me as well hehe
<dbandstra> whoops wrong window :|
<andrewrk> my argument for having the ability to take the address of a temporary is that it's actually safer than the alternative
<pixelherodev> Seconded
<pixelherodev> Though it's a bit unusual, that's not bad
<pixelherodev> I think "unusual, but in a good way" might be a good way of summing up Zig :)
dbandstra has quit [Ping timeout: 240 seconds]
<mikdusan> I wish github let me choose to which hat to wear { contributor, owner } so that I can choose when all these fancy buttons (which I don't want to use by mistake) show up
Cucumbas has quit [Ping timeout: 240 seconds]
Cucumbas has joined #zig
lunamn has quit [Quit: leaving]
protty has quit [Remote host closed the connection]
stratact has joined #zig
<stratact> What an adventure I had... well glad to be fully set up again and back here
<daurnimator> stratact: go on.....
<stratact> long story, but I'll trim it down as best as I can. I originally got fed up with FreeBSD due to lack of care with updating the drm-kmod drivers to 5.0 for 12.X to support my AMD GPU cards. So I tried OpenBSD, which updated them to 4.19. Surprisingly it's the only open source OS in existence that makes installing and setting things up the easiest. The disadvantage to it, is it's security focused features make it noticeably slow and they have a "I
<stratact> Know Better Than You" design in some things like their ports system, which limits flexibility. So then there is NetBSD... overall out of the BSDs, it's the most flexible and the most friendly (even the developers will welcome you), BUT... NetBSD folks are only interested in mostly supporting non-mainstream hardware or very old and low powered devices. So then I thought okay... go back to Linux... and I did, back to Slackware which architecturely was
<stratact> the most BSD-ish besides Gentoo... well doing a UEFI + ZFS root setup for was a pain in the m***** f****** booty. After exhausting all of my options I talked to my local FreeBSD and he suggested just get an NVidia card, so I did, I ordered one from a local Best Buy online and have it delivered same day, reinstalled FreeBSD 12.1 with Nvidia drivers and my gosh, it was the most painless setup I've ever encountered... things just worked out of the box.
<daurnimator> That sounds backwards
<daurnimator> Worst thing I ever did was put an nvidia card in my linux desktop. So many bugs in the nvidia closed source driver; and no recourse. Swap it out for anything AMD and it runs like a dream
<stratact> That's the thing, amdgpu works best for Linux, however it's different with FreeBSD. With FreeBSD there is very little kernel updates and ABI breakages which take away from Linux's nvidia problem.
<stratact> The nvidia drivers aren't open source sure, but I don't have to worry about breakages.
<stratact> Surprisingly enough using amdgpu on FreeBSD is the most painful, which is the opposite for Linux
<daurnimator> stratact: uefi+zfs root shouldn't be too hard on linux...
<daurnimator> I think grub has some issues... but the workarounds are known. Alternatively, just use rEFInd
<stratact> daurnimator: I was using refind... it's just I didn't understand Slackware's mkinitrd system and it was not happy to install symlinks from the initrd-tree in the fat32 partition...
<daurnimator> stratact: then don't use slackware? :P
<stratact> Correcto! :)
<daurnimator> but I mean.... I would have swapped over to e.g. Arch; not gone out and bought a different graphics card :P
<stratact> nonetheless, I'm sure my story was interesting, no?
<daurnimator> sure
<daurnimator> so you're back on freebsd?
<stratact> Yeah
<stratact> My lesson here was, "when in Rome, do what the Romans do"
nomadgamma has quit [Quit: Leaving]
reductum has quit [Quit: WeeChat 2.6]
<pixelherodev> It's not too difficult to "trick" refind into accepting unusual initrd names
<pixelherodev> I literally wrote a script to update the initramfs on Gentoo that duplicated the produced files with names rEFInd understands
<pixelherodev> Like, three lines tops, everything started "just working"
<pixelherodev> On a different note, never try updating a Gentoo system that's been off for years
<pixelherodev> It's a pain in the ass
<andrewrk> c'mon github, I'm trying to get shit done
<mikdusan> ok so I'm not the only one
<andrewrk> I've got 3 issues typed out in vim, ready to go
<daurnimator> indeed. I'm also having trouble with docker not pulling right now
<daurnimator> I wonder if one of the cloud providers/cdns is failing
<andrewrk> the type of argv actually looks kinda nice: [*:null]const ?[*:0]const u8
<andrewrk> it's a bit noisy, but I mean, consider what a diagram explaining how argv is organized in memory would look like
<mikdusan> nice, null terminated slice of byte=0 terminated byte slices
muffindrake has quit [Ping timeout: 250 seconds]
ur5us has quit [Ping timeout: 250 seconds]
<pixelherodev> I think you mean, pointer to unknown number of pointers to byte=0 terminate byte slices, with a null as the last entry ;)
<pixelherodev> Wait... actually, with the new syntax, I'm no longer 100% sure
<pixelherodev> drats
muffindrake has joined #zig
<andrewrk> I think you both said the same thing
<mikdusan> it looks good. tells me what the sentry types are.
<andrewrk> it would be neat if we could propose some kind of extension to .h files which could add this additional type information, in some backwards compatible way
<andrewrk> we could start sending upstream PRs to c libraries, and if it got popular enough, then even C compilers would gain optional warnings for this
<daurnimator> I think theres a proposal open for that :)
<daurnimator> #2457
<pixelherodev> andrewrk, pointer != slice
<andrewrk> pixelherodev, ah, I didn't notice that you said slice
<andrewrk> slice syntax omits the length
chemist69 has quit [Ping timeout: 276 seconds]
chemist69 has joined #zig
adamkowalski has joined #zig
<adamkowalski> andrewrk: what are your thoughts on allowing unicode characters in code, especially for things like function names and variables names. One of the things I loved about Julia was that they allowed this. For somebody who spends all day dealing with a math heavy domain, being able to write things down exactly as they appear in the textbooks increases readability and communication between developers. They
<adamkowalski> can instantly see the mapping from your code to the equations you were trying to implement where greek letters are extremely common
<pixelherodev> IMO the biggest problem with Unicode code is that the set of allowed characters is a lot harder to define
<pixelherodev> Unless you decide that anything that's non-ASCII is allowed and will never be used by the language itself or something I suppose
Cucumbas has quit [Read error: Connection reset by peer]
Cucumbas has joined #zig
<daurnimator> adamkowalski: you can, just put it in @""
<pixelherodev> ...wat
<pixelherodev> So is it just me or are zig 0.4 and newer broken on godbolt?
<daurnimator> pixelherodev: assembly output seemed to stop working around the 0.5 release. no one seems to have figured out why
<pixelherodev> :(
<adamkowalski> Hmm what benefit is there of having the @""? Why not just be able to write it directly?
<andrewrk> daurnimator, someone did and it's a really simple fix: https://github.com/mattgodbolt/compiler-explorer/issues/1689
<adamkowalski> pixelherodev: in Julia you can just type backslash like so \omega
<adamkowalski> you can write your loss function like so \sqrt(mean((y - y\hat)^2))
<adamkowalski> then it turns the sqrt, and hat into the greek symbols
<adamkowalski> obviously it's not needed, but it's kindof nice when reading it
<adamkowalski> you just write tab and the editor replaces the \omega with the greek letter
<pixelherodev> Ah, passing in the extension :P
<daurnimator> andrewrk: looks like you're ready for merging? :)
<andrewrk> just about. gonna let my windows computer finish running tests so that I can bypass CI
<daurnimator> andrewrk: did you want to try making the change to mem.toSlice again?
<andrewrk> daurnimator, about to push that
<adamkowalski> andrewrk: I saw your latest stream today. If you start generating machine code directly do you think it will ever be viable to bypass llvm even for optimized builds? Keep everything under the control of Zig, and target new platforms that maybe llvm doesn't support
<andrewrk> adamkowalski, yes that is another possible use case - basic support for targets that llvm does not support
<mikdusan> 6502 here we come
<andrewrk> yeah!
<adamkowalski> That would be great, you could probably become one of the first languages that can literarly deploy everywhere, from phones, laptops, webassembly. To things like aws lambda or even big supercomputers like cray
<adamkowalski> Has there already been any work done on deploying to aws lambda, azure cloud functions, or anything of that nature?
<andrewrk> isn't that just x86_64?
<adamkowalski> I'm not sure, if thats all it is thats awesome. I'll have to try it out soon
<adamkowalski> I've made a lot more progress on my project. I'm writing out the equality explicitly like you mentioned, and just moving things along. Hopefully I'll be able to replace some of our Python code in production soon and I can see how simple it is to deploy to web services
<hspak> For AWS Lambda at least, any static x86_64 binary will run. You should be able to follow this for Zig: https://aws.amazon.com/blogs/opensource/rust-runtime-for-aws-lambda/
<andrewrk> daurnimator, pushed
<andrewrk> yeah zig is great at making static binaries. you have to try extra hard to *not* get a static binary
<adamkowalski> hspak: thanks I'll follow that!
<hspak> Actually, that post is showing off some lambda crate that makes running rust on lambda easier. I'm sure there's a better resource, but you can definitely run Zig in Lambda. People were running Rust in lambda before it was supported
<andrewrk> even if you need a c library for that, you can use -target x86_64-linux-musl and still get a static binary
<pixelherodev> Which is really awesome :)
<pixelherodev> Currently, I have a total binary size of ~100KB :D
<daurnimator> adamkowalski: need http server first
<mikdusan> `fn toSliceConst(comptime T: type, comptime sentry: T, ptr: [*:sentry]const T) [:sentry]const T {...}`
<daurnimator> andrewrk: is there a cast from [*c]u8 to [*:0]const u8?
<mikdusan> is there a way to get sentry from a type
<daurnimator> mikdusan: its in @typeInfo IIRC
<emekankurumeh[m]> if i implement an unaccepted feature request is there any reason to think that it would be more likely to be accepted?
<daurnimator> emekankurumeh[m]: not particularly; unless the concerns were about being e.g. "too complex" or "too much work"
<andrewrk> emekankurumeh[m], which one?
<daurnimator> that said, I've done it before: easier to talk about pros/cons when you have an implementation in front of you
<emekankurumeh[m]> 1214
<andrewrk> ah. that one i'm not ready to address yet. probably a PR would sit for a long time, or be closed until the proposal is settled
<andrewrk> I understand it's a popular proposal
<emekankurumeh[m]> hmm, i second thought i may be able to come up with a workaround for my specific use case
<emekankurumeh[m]> can generic functions return extern structs?
<daurnimator> emekankurumeh[m]: yes
Cucumbas has quit [Remote host closed the connection]
<emekankurumeh[m]> since when could _ be a struct field?!
<stratact> andrewrk: I have a question, I was mentioning Zig to an OpenBSD user and his impression of making wrapping of unsigned integers undefined was "harsh" because it would make it harder to implement cryptographic features like in C. What would be your opinion on this matter? Just for my curiousity.
<emekankurumeh[m]> just use the wrap-around operators...
<stratact> ah awesome, thank you
<stratact> Somehow I must of missed that due to skimming the documentation last time I was learning Zig.
<emekankurumeh[m]> well i worked around the lack of struct embedding by turning my structs into generic functions and using `_` as a field to
<emekankurumeh[m]> "hide" them in other structs
<daurnimator> emekankurumeh[m]: struct { usingnamespace struct{} }
<emekankurumeh[m]> the issue is that i need the fields not declarations
<emekankurumeh[m]> i'm writing a wrapper for a COM api so i need to define the vtables manually
<emekankurumeh[m]> i came up with this: http://ix.io/22ND
<daurnimator> emekankurumeh[m]: interesting. and you're writing these out manually for each COM thing?
<emekankurumeh[m]> it's not to bad, i'm mostly just cleaning up some stuff from translate-c bc windows is crazy and zig chokes on all the redefinitions in windows headers
mahmudov has joined #zig
<daurnimator> andrewrk: can you give me permission to restart CI runs? lately azure devops seems to have random failures
LargeEpsilon has joined #zig
<andrewrk> daurnimator, step 1 is you need a username on Azure
<daurnimator> andrewrk: i'm signed in with quae at daurnimator.com
THFKA4 has quit [Ping timeout: 276 seconds]
<daurnimator> andrewrk: wooo :)
<andrewrk> and now bring on the PRs
<daurnimator> Easy or hard ones? :)
adamkowalski has quit [Quit: leaving]
<daurnimator> #3769, #3764, #3762, #3715, #3714 should be easy
ur5us has joined #zig
mikdusan1 has joined #zig
mikdusan has quit [Ping timeout: 276 seconds]
<andrewrk> daurnimator, btw I don't generally require people to rebase their PRs if they were ready to merge before; I'm happy to do such work
<daurnimator> andrewrk: what about when there is a material difference though. e.g. on the environ PR I just said that on, all the types in the PR need to be redone
<andrewrk> draft for 30+ days? sounds like they should re-open when they want something merged
<daurnimator> andrewrk: but also... your time is valuble. its better for all of us if you spend time reviewing rather than fixing up someone's low priority PR
<andrewrk> I guess that's true
<daurnimator> What do you think about adding milestone for some useful zig goals, e.g. "easy to create a linux kernel module"?
<andrewrk> daurnimator, I've been using the "Projects" feature for stuff like that: https://github.com/ziglang/zig/projects
<andrewrk> that example in particular, I think would be valuable as a community maintained third party project
<andrewrk> the progress towards the goal would be measured in the complexity of the README file of a hello world linux kernel module
<daurnimator> andrewrk: right now its measured in the TODOs of https://gist.github.com/daurnimator/6518ece625b9c5f143ac51274b9dacfe
FireFox317 has joined #zig
<daurnimator> (for which https://github.com/ziglang/zig/issues/3754 is the biggest annoyance btw..... if you want to put your bug solving hat on :) )
<andrewrk> nice, that's a good resource
<andrewrk> daurnimator, personally I want to fully invest in self-hosted translate-c rather than fix bugs in the C++ one
<daurnimator> andrewrk: the reason I was thinking milestones over projects is that when you go to an issue page, it tells you the milestones it belongs to
<andrewrk> it also tells you the project
<daurnimator> oh? I haven't noticed then
<daurnimator> ah k, great :)
<andrewrk> I'd be OK with "Non-Kludgy Linux Kernel Module" as a project
<daurnimator> k. will do
<daurnimator> Column ideas: "blockers" "nice to have" "enhancements"
<andrewrk> sure, go nuts
<andrewrk> none of that is going to make people work faster though :P
<daurnimator> andrewrk: good to have an idea of what working on a given issue may accomplish. also for anyone watching, knowing when a good time to try out zig for their purpose is
<mq32> hey
<mq32> is there a safe way of casting ints to enums?
<andrewrk> daurnimator, yeah I think it's a good idea. I was just poking fun at the columns
<mq32> or do i have to do this myself?
<andrewrk> mq32, if you were to name this builtin, what would you call it?
<FireFox317> xd
<mq32> hm. we already have @intToEnum, maybe "fn @tryIntToEnum(comptime T: type, value: @enumType(T)) ?T"
<andrewrk> ahh I see what you are after
<mq32> safe deserialization
<andrewrk> there might be something in meta
<mq32> i really have to download the docs for each zig version when i'm updating...
<andrewrk> std.meta.intToEnum
<mq32> online help just doesn't cut it
<andrewrk> yeah generated docs are WIP
<mq32> mostly because of the file size :D
<andrewrk> hm. I would have made it optional, not an error union
<mq32> it just doesn't load on a mobile connection
<mq32> it's kinda expected that it fails to convert :D
<andrewrk> yeah you can sort of get a sense of when it makes sense to use an optional rather than an error union, based on the following 2 clues: (1) there is only 1 error in the error set. (2) the error is not something that would make sense to show to a user
<andrewrk> "InvalidEnumTag" is some kind of internal programming thing, it doesn't really have to do with operating a computer
FireFox317 has quit [Remote host closed the connection]
<andrewrk> vs OutOfMemory, InvalidCharacter, or NetworkUnreachable
<daurnimator> andrewrk: btw, is now a good time to walk you through the fifo code?
<andrewrk> sorry, it's real close to my bed time and I want to play video games for a few minutes
<daurnimator> k. what you playing?
<andrewrk> Noita
<mq32> oh, Noita is nice
<mq32> burn some Oil!
allan0 has quit [Ping timeout: 265 seconds]
<daurnimator> btw, still not able to re-trigger an azure build
LargeEpsilon has quit [Ping timeout: 265 seconds]
LargeEpsilon has joined #zig
FireFox317 has joined #zig
_whitelogger has joined #zig
<FireFox317> If i look at the generated llvm-ir, it is doing a memcpy `call void @llvm.memcpy.p0i8.p0i8.i64(i8* align 4 %11, i8* align 4 bitcast (%"?testStruct"* @9 to i8*), i64 16, i1 false), !dbg !536` and i think this align 4 is not correct here
return0e has joined #zig
<andrewrk> FireFox317, that align 4 describes the alignment of %11 and @9, so you can check where those come from to see if they have proper align attributes
<andrewrk> good night
<FireFox317> Thanks andrew, good night!
<daurnimator> andrewrk: https://ziglang.org/documentation/master <== link opens for download in firefox
ur5us has quit [Ping timeout: 250 seconds]
<daurnimator> So has anyone managed to come up with a better callback solution than what I had the other week?
LargeEpsilon has quit [Ping timeout: 240 seconds]
tines9_ has joined #zig
tines9 has quit [Remote host closed the connection]
LargeEpsilon has joined #zig
return0__ has joined #zig
stratact_ has joined #zig
return0e_ has quit [Read error: Connection reset by peer]
stratact has quit [Remote host closed the connection]
mikdusan1 has quit [Ping timeout: 240 seconds]
SquantMuts has quit [Ping timeout: 240 seconds]
jokoon has quit [Quit: jokoon]
syscall0 has quit [Remote host closed the connection]
nikoala has joined #zig
m4ge123 has left #zig [#zig]
Flaminator has joined #zig
knebulae has joined #zig
<Snektron> Callback solution for what?
<daurnimator> Snektron: A zero-overhead way to pass optional callbacks to a generic. https://godbolt.org/z/v6UWcX is the only thing that I got to work
<frmdstryr> Can zig to forward type declarations?
<frmdstryr> do*
<daurnimator> frmdstryr: you don't need to: zig is lazy
<frmdstryr> So I can just define an empty struct and populate it in another file?
<daurnimator> no
<daurnimator> you have to populate immediately
<daurnimator> but the things you reference... don't have to exist yet
<daurnimator> const Foo = struct { x: Bar }; const Bar = struct { y: u8 }; // this works
<frmdstryr> What if Bar is in another file?
<fengb> Import and use it
<fengb> You can have circular imports if you’re feeling extra edgy:P
<frmdstryr> But then it still needs to know what to import
<mq32> fengb: I#ve even seen some circular usingnamespace in the wild
<frmdstryr> Can i just assign a "var" field in a struct? that takes whatever is put there
<fengb> What are you trying to do?
<mq32> no, you need different types for that
<frmdstryr> Trying to learn zig by porting a web framework
<frmdstryr> The router must be able to map a rule to a request handler
<frmdstryr> request handlers can be defined whenever
<fengb> That should be a function pointer right?
<mq32> sounds like a classic usecase for function pointers
<fengb> Or an interface type of sorts
<frmdstryr> Yes but it looks like zig doesn't have interfaces yet?
<fengb> We do kinda. std.mem.allocator is are most common one
<fengb> It’s a userland pattern
daex has quit [Ping timeout: 265 seconds]
<frmdstryr> Can I cast a buffer to a struct?
daex has joined #zig
<mq32> kindaish
<frmdstryr> What I really want is a union that can be modified at comptime before it's first used
<mq32> you can @bitCast types to convert their binary represenatation, but that is rarely used
<mq32> use generics
<mq32> fn MyBadOptional(comptime T: type) type { return union(enum) { none: void, some: T }; }
<frmdstryr> but I can't store a generic in a stuct unless I know the type ahead of time
<mq32> what do you want to achieve in the end?
<frmdstryr> store struct + context to populate the struct
<frmdstryr> wheither neither are known until the user adds them to the routing table
<mq32> hm
<mq32> you can use a generic function
<mq32> on your routing table
<mq32> routingTable.addSome(T, T { … });
<frmdstryr> Can a hashmap store a dynamic type?
<frmdstryr> How would I then save that and pull it back
<frmdstryr> See the issue?
<mq32> you can always store a pointer
<mq32> have an interface with a release-function that will delete the allocated object
<frmdstryr> Whats the type for a generic pointer?
<frmdstryr> *void ?
<mq32> a pointer to your interface type
<mq32> so if you would like to have a list of different "routers", you would have a common interface Router and an implementation that does this:
<mq32> struct { router: Router, i: i32, j: i32 };
<mq32> and you can use @fieldParentPTr to get from "struct.router" to a pointer to your struct type
mahmudov has quit [Remote host closed the connection]
<frmdstryr> So zig basically has inheritance but it's reversed?
waleee-cl has joined #zig
<mq32> nah, not quite
<mq32> look at how std.mem.Allocator works
<mq32> you can use that for a kind of inheritance, yews
<mq32> but it's a userspace concept, you can built a lot of stuff with that
<frmdstryr> Just uses callback functions?
<frmdstryr> Oh, I see in std.heap.zig
<frmdstryr> So what happens with fieldParentPtr if you pass in something whoms parent is not the proper type?
<fengb> Undefined behavior
<fengb> It's doing a bad pointer offset and reaching outside of the struct
<fengb> It would be doing*
<frmdstryr> So by passing the nested struct instead of the "parent" the compiler is losing information it could use to validate that or does it already detect it?
<fengb> I think there's a task to investigating making it safe, but right now there's no check
<frmdstryr> #591
<muffindrake> So string literals are null-terminated now?
<mq32> seems so
Cucumbas has joined #zig
<fengb> They are for compatibility reasons. 99% of zig code shouldn't actually care
<mq32> i really like the sentinel-pointer-stuff
<mq32> i have the strong feeling that this stuff will also open a lot of neat options we didn't thought of yet
stratact_ is now known as stratact
<fengb> It basically allows us to remove C string literals, since all string literals are compatible now. Other than that, Zig code doesn't touch the null and it doesn't show up in the length
<fengb> Unless you're using the new sentinel slicing of course >_>
<mq32> yep, that's neat :)
<mq32> that also means we can interface with C strings much much simpler
<Flaminator> So it stores string literals with a \0 at the end now?
LargeEpsilon has quit [Ping timeout: 240 seconds]
Akuli has joined #zig
lukeholder has joined #zig
return0e has quit [Remote host closed the connection]
jonathon has quit [Remote host closed the connection]
Cucumbas has quit [Remote host closed the connection]
jonathon has joined #zig
lukeholder has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
FireFox317 has quit [Ping timeout: 245 seconds]
Cucumbas has joined #zig
Cucumbas has quit [Remote host closed the connection]
dimenus has joined #zig
<dimenus> andrewrk: in cd37c1, did you mean to remove functionality? You took away the `readFileAllocAligned` that doesn't require a dir
<andrewrk> dimenus, yes, use std.fs.Dir.cwd().readFileAllocAligned
<dimenus> ah, got it
<andrewrk> there is room in the API to add a function that asserts that the parameter is absolute and does not require a directory, but this function works for both
<andrewrk> and it being here encourages people to think in terms of open directory handles, which is not what people are used to but it's the correct way to avoid race conditions
<andrewrk> WASI doesn't even have the absolute path version; you must use a directory handle
nairou has joined #zig
<nairou> Silly question... ziglang.org has great reference documentation for the language, but where do I find a reference for the std lib? I don't see that in the documentation.
<tgschultz> nairou: We get that a lot. The answer is that the stdlib is highly unstable and hasn't been worth documenting. However, I believe the intention is that 0.6.0 release will have documentation generated from source doc-comments at least.
adamkowalski has joined #zig
<nairou> Good to know. What is the current process for using it then? For example, I'm trying to learn the language by going through last year's Advent Of Code, and the first thing I need to do is read from a file... I've been searching for how to do that. :-)
<adamkowalski> andrewrk: if you have some time could you take a look at https://www.youtube.com/watch?v=OcUXjk7DFvU
<fengb> We have some "secret" docs that aren't linked because it's incomplete https://ziglang.org/documentation/master/std/
<adamkowalski> It's about a project called Zygote which is a source to source automatic differentiation library. Similar to the kind of thing I was talking about earlier. They demonstrate how it's implemented and more importantly some of the practical implications of what you can do with machine learning
<adamkowalski> Would it be possible to implement something like this in Zig? They are able to hook into the compiler and write libraries that take all code and move it to the gpu for example
<nairou> Sweet, that works. Thanks!
<adamkowalski> or turn all floats into f16 so that you can take advantage of the latest advances in gpus/tpus
<adamkowalski> they also let you add a "hook" before any function is called so you can do non standard interpretation like taking derivatives
<adamkowalski> If you don't like it can you suggest what path you recommend I go down in Zig when trying to implment it for myself?
<andrewrk> nairou, I think zig's std lib facilites for text processing input are not to the convenience level of "scanf" yet. maybe someone wants to do submit a PR for such an API over the next few days before dec 1? :)
<andrewrk> if you're willing to read the entire input into memory, you can get pretty far std.mem.separate and std.mem.tokenize
<andrewrk> adamkowalski, I'd be happy to advise on how to solve this use case, but I don't understand what you're trying to do. you can't just swap out floats for f16's, you'll break everybody's code
<nairou> Reading the entire file is good enough for now, I'll check those out. Thanks!
mahmudov has joined #zig
<adamkowalski> andrewrk: well the premise is that if you have a library that was written for the cpu and it is using f64 or f32 and now you want to leverage it on the gpu. You want to use f16 because you can do more floating ops per second, and we don't need the precision in neural networks. So you want to reinterpret all floats as f16 or even quantized i8 within a particular scope
<adamkowalski> But thats not even the important thing. The main point of that library is automatic differentiation. It is usually a one function API called gradient which gives you the gradient vector of a particular function with respect to some parameters
<adamkowalski> They talk in this video (which I strongly recommend, the speaker is very entertaining) about the drawbacks of the current approaches
<adamkowalski> Right now in Python with PyTorch or TensorFlow you record all the operations (plus, mul, sub, whatever) on a tape, which then you can play back using the chain rule to take the derivatives. But this ends up acting like an interpreter and is really slow
mahmudov has quit [Read error: Connection reset by peer]
<adamkowalski> Zygotes approach is to hook into the compiler and actually do a source to source transformation of your code so you get to use all the optimizations that llvm has to offer, even on your backwards pass
waleee-cl has quit [Quit: Connection closed for inactivity]
mahmudov has joined #zig
<adamkowalski> so it's a "compile time function" which takes in your source code and returns source code which generates the derivative
<andrewrk> zig is a DSL for machine code. if you want some other kind of API or DSL you have to build it on top of zig, rather than hacking up the semantics of zig to match a different DSL
<adamkowalski> right, I figured that this was not the approach you wanted to take. So I figured I would get some feedback from you so I can design the library that works in the way it's intended for zig
<adamkowalski> Fundamentally all of these libraries are building up a computation graph. They seperate the description of the operations to be done from the operations themselves. This way they can operate on the graph and take derivatives, or offload work to other nodes or accelerators
<andrewrk> based on my limited understanding of this: you need a declarative API for this, and you need a dependency on an optimizing compiler. julia has an optimizing compiler in the runtime. zig has no runtime
<adamkowalski> So should I just explicitly build up a graph? Sort of like an ast but at runtime?
<andrewrk> yes
<adamkowalski> in C++ the approach I tried to take was expression templates, so I was trying to build a graph using templates and then using meta programming to transform the templates into something new
<andrewrk> if your ast is compile-time known information, then this can be a build step
<adamkowalski> that way all the work was happening at compile time
<adamkowalski> the main problem I ran into was control flow
<adamkowalski> I think thats why in Python they tried making the graph at runtime
<adamkowalski> You mentioned I could hook into an optimizer at runtime? Does zig expose anything like that? I know that TensorFlow actually had to reimplement many optimization passes themselves
<andrewrk> you can give yourself a nice API, and use it in a tool that runs during your build, generating zig code which you then compile. that's one option
nairou has quit [Quit: Leaving]
<adamkowalski> Hmm that makes sense, so then the generated zig code will still get compiled.
<adamkowalski> What do you think about building out a tensor type (nd array where 0d is scalar, 1d is vector, 2d is matrix, 3d is ?) that is completely lazy
jmiven has quit [Quit: bye]
<adamkowalski> so rather then actually storing data inside itself, it just records the work it would have done
<adamkowalski> only when you actually do something like printing or differentiating you actually force work to happen and it looks through the computation graph and figures out how to actually do something
jmiven has joined #zig
adamkowalski has quit [Quit: Lost terminal]
ofelas has quit [Quit: shutdown -h now]
lunamn has joined #zig
<andrewrk> when doing this kind of abstraction, put the type enum id as the field default value, so that at the initialization site, you don't need redundant info, and can't get it wrong
riba has joined #zig
wootehfoot has joined #zig
THFKA4 has joined #zig
Cucumbas has joined #zig
LargeEpsilon has joined #zig
FireFox317 has joined #zig
LargeEpsilon has quit [Ping timeout: 240 seconds]
mikdusan has joined #zig
<andrewrk> argh, I think there was a regression in s3cmd or something, the docs have content-type application/octet-stream now
Cucumbas has quit [Remote host closed the connection]
Akuli has quit [Quit: Leaving]
<mq32> i'm on the wrong foot when working with zig right now.
<mq32> halted the kernel project, continued working on another one
<mq32> first line of code: "not implemented yet"
reductum has joined #zig
<mq32> at least it was something that could be fixed easily :)
kapil_ has quit [Quit: Connection closed for inactivity]
dimenus has quit [Read error: Connection reset by peer]
Ichorio has joined #zig
riba has quit [Ping timeout: 276 seconds]
<mikdusan> azure/CI windows: what a drag
<mq32> 20 minutes later: This is a bug in the Zig compiler.
<mq32> dang!
<andrewrk> mikdusan, it would be really nice if the log printed during the run, and if it at least told us why it didn't finish
<andrewrk> also nice, thanks for rebasing the ConstExprValue PR
<mikdusan> does your azure access let you "ctrl-c" a job?
<mikdusan> like i mean literally (not some GUI button)
<mikdusan> because here's the log of a windows "cancelled":
<andrewrk> I don't have any kind of command line access if that's what you're asking
<mikdusan> --> 136/1252 parker.test "std-native-ReleaseFast-c-multi std.ThreadParker"...^C
<mikdusan> i mean someone literally hit ctrl-C.
<andrewrk> hmmmmmmmmm
<mikdusan> azure overcommit mitigation: attach to terminal manually, hit ctrl-C. oh my.
<andrewrk> that might literally be what it is...
<andrewrk> ahhh. ZigValue is a much better name for this type
<andrewrk> this is a breath of fresh air
<mikdusan> oh wow you committed it. nice.
<mikdusan> s/commited/merged/
<andrewrk> hold on to your butts. master branch is about to become a firehose
<andrewrk> I don't need the CI, I have every operating system on my desk
<andrewrk> mikdusan, we could probably merge x_void with const_void_val (also in CodeGen struct)
<mikdusan> will take a look
<mikdusan> should I move const_zero_byte into the intern struct as well?
<mikdusan> struct intern_values {}
<andrewrk> yep that should be good too
<mq32> andrewrk: is the "wrong field type assignment bug" fixed already?
<mq32> or did you reintroduce it with the anonymous struct changes?
<mq32> no, the one with LLVM code in the error message
<mq32> when doing invalid type assignment of a field
<mq32> struct { a: A } {.a= B{}}
<andrewrk> I have a branch in progress on that one
<mq32> ah okay
<mq32> so i don't have to report that again
<mq32> just ran into it :D
urluck has quit [Ping timeout: 250 seconds]
<mq32> need to get some sleep
FireFox317 has quit [Ping timeout: 268 seconds]
<andrewrk> fengb, what do you think about replacing std.heap.WasmAllocator with zee_alloc?
<mikdusan> andrewrk: I'll probably do a supplemental to #3774 to update interning stats that show up in -fmem-report for code that refs const_void_val/const_zero_byte
<andrewrk> mikdusan, sounds good, feel free to merge when you feel it's ready
<fengb> andrewrk: that'd be pretty cool but I haven't tested it pretty thoroughly
<andrewrk> don't you use it for fun dude?
<andrewrk> uh, let me put some punctuation in there, lol
<fengb> I do but I make like 3 allocations total
<andrewrk> don't you use it for FunDude?
<andrewrk> ah ok. well... we do need something that provides a map/unmap API on top of wasm's global state
urluck has joined #zig
<andrewrk> in theory we should be able to create a nice allocator fuzz tester and run it on any allocator
<fengb> Yeah I was thinking about that
<fengb> The current wasm allocator needs the memory to be a special state. I've coded zee_alloc to depend only on the response of the LLVM function so it's mostly stateless
<fengb> I actually pulled that in and found a few performance bottlenecks :)
<andrewrk> hmm if you ran this test for any duration of time, it's probably ready for this phase of std lib
<andrewrk> I'd like to delete std.heap.wasm_allocator and make std.heap.direct_allocator be a global instance of wee_alloc
<fengb> I also added some tuning knobs because I wasn't sure which direction I wanted to go. The defaults are pretty heavily weighted towards a tiny footprint
<andrewrk> I think that's a good default for wasm
<fengb> Like even reimplementing some stdlib functions to get rid of some debugging output in release-safe
<andrewrk> further modifications can always look at std.builtin.mode
<andrewrk> oh even in release-safe you wanted small? that's interesting. I thought that wasm was a good use case for ReleaseFast and ReleaseSmall actually
<fengb> I couldn't turn off safety in fundude because it's not well tested. But I wanted to tune the allocator separately
<andrewrk> that makes sense
<andrewrk> I'm plannig to allow changing the build mode per scope (and note that files are scopes)
<fengb> Anyway... I think zee_alloc "works", and it might even be usable as a generic allocator
<fengb> But I'm not confident it's performant or anything
<andrewrk> yeah that's fine for now though :)
<andrewrk> std lib is not at production grade yet, it's at proof of concept status
<fengb> I think it'd make the most sense to expose wasm_page_allocator
<andrewrk> aahh now that sounds like what I'm looking for
<fengb> It's only multiples of 64K and no unmap (per spec)
<andrewrk> oh that's nice since wasm is single threaded, you can rely on no TOCTOU races with those intrinsics
<andrewrk> (Time Of Check, Time Of Use)
<andrewrk> oh, wasm has no unmap?
<fengb> Not yet
<andrewrk> that's lame
<fengb> No idea where the proposal is right now
<andrewrk> you can't give a smaller size to grow?
<fengb> Nope, it's only 64K chunks
<fengb> Multiples of 64K
<andrewrk> what's this other parameter? "initial size"? I don't understand
<fengb> Good question
<andrewrk> get good, webassembly
<andrewrk> we need to be able to free memory
<fengb> Clang has __builtin_wasm_mem_grow(int32_t imm, size_t delta)
<fengb> All hardcoded to 0 as well
ur5us has joined #zig
<andrewrk> it's not so bad - we need the wasm_page_allocator to re-use pages
<fengb> Ah that'd be neat
<fengb> So I think the base wasm allocator should be a shared page allocator. Unfortunately it only responds in 64k chunks so we need something to sit on top to be usable
ltriant has joined #zig
ur5us has quit [Remote host closed the connection]
<andrewrk> I don't think we do - std.mem.page_size is 64k on wasm
ur5us has joined #zig
<andrewrk> std.heap.direct_allocator is expected to give std.mem.page_size chunks
<fengb> Oh really?
<fengb> So if I ask it for 4B, it's just wasting a bunch?
<andrewrk> yeah totally, you really shouldn't use direct_allocator for stuff
<andrewrk> it's good as a backing allocator for ArenaAllocator
<fengb> Ah okay, then we can just do the page allocation style
<andrewrk> I think it should be renamed to std.heap.page_allocator
<andrewrk> maybe that will give people a better idea
<andrewrk> I'm going to propose that
<fengb> We'll still need to to store "free" pages. I can take a look later tonight
<fengb> 👍
ur5us has quit [Remote host closed the connection]
<andrewrk> so the memory starts at address 0?
<andrewrk> I hope that grow intrinsic is returning a nonzero number... otherwise our null pointers have to take up an extra 4 bytes on wasm
<andrewrk> s/null pointers/optional pointers/
mahmudov has quit [Remote host closed the connection]
quetzalb has joined #zig
<fengb> It returns total number of previous pages
<fengb> I'm pretty sure stack memory is considered a page so it should be !0
<andrewrk> good
<fengb> But it could be -1
ur5us has joined #zig
<andrewrk> fengb, one more question, do you care about wasmtime vs wasmer? I haven't really messed with either
stratact has quit [Quit: Konversation terminated!]
<fengb> I chose whatever was easiest lol
<fengb> I don't know which is better, but there seems to be a little rivalry going on
<andrewrk> zig actually has a lot to offer in that space as well - the guy mentioned that they didn't support freebsd, but if we did one we'd be using our cross platform std lib abstractions
<andrewrk> zig's would be slower - the point wouldn't be perf or jit or anything, just that we should take advantage of our cross platform std lib
<andrewrk> and then be able to run tests without other dependencies
wootehfoot has quit [Read error: Connection reset by peer]
<andrewrk> not allowing shadowing just saved my ass big time
<emekankurumeh[m]> how?
dimenus has joined #zig
<andrewrk> I refactored a struct field to be a global variable, and it clobbered a local variable name without me noticing until the compile error
<daurnimator> andrewrk: oh I had an idea: the new `var` as a comptime struct member: its modifyable right?
<daurnimator> I can probably come up with a callback pattern using it :D
<andrewrk> it's modifiable but it forces the entire struct to always be comptime known
<andrewrk> anonymous struct literals do not have this restriction, however
<daurnimator> Also I had an idea triggered by a chat with gingerbill: what if struct literals had their own type: `comptime_structliteral`
<daurnimator> `@typeOf(.{.foo = 42)` == comptime_structliteral
<andrewrk> ah, yeah, that's essentially how it already works
<daurnimator> similar to how we have comptime_int that casts to an integer that can fit it; a comptime_strucliteral would cast to a struct with members that match up
<andrewrk> yeah it already is supposed to do that (there's a "TODO" compile error if you trigger it)
quetzalb has quit [Remote host closed the connection]
<daurnimator> You should also be able to e.g. access a comptime_structliteral member: `(.{.foo = 42}).foo` would be a comptime_int 42
<andrewrk> I'm pretty sure that already works
<daurnimator> oh? cool if so :)
<andrewrk> and doesn't have to be comptime
<andrewrk> yeah anon struct literals are hella useful
<daurnimator> andrewrk: did you see https://godbolt.org/z/v6UWcX ? and do you have any suggestions on how to fix it? (idea: 0-overhead optional callbacks)
<daurnimator> "fix" meaning make less ugly
<andrewrk> I clicked the link, but I'm gonna prioritize PRs over thinking about this
Ichorio has quit [Ping timeout: 245 seconds]