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/
<daurnimator> why do we only support Linux 3.16+
<daurnimator> which is to ask: what feature do we depend on that was introduced in 3.16?
<lunamn> is it expected to have compiler crashes from wrongly using @typeInfo and @typeOf?
<daurnimator> lunamn: the compiler should never crash: that would be a bug
<lunamn> daurnimator: thanks! so I'd assume its best to write an issue for it?
<daurnimator> lunamn: yep. just do a search to make sure it's not already supported. include a minimal test case if you can.
<daurnimator> uh s/supported/reported/
athaudia has joined #zig
<tgschultz> I've run Zig on a 2.6 kernel before (as a test after we started distributing statically compiled binaries). I don't remember anything breaking but I didn't exactly push it.
<scientes> that won't work after arm64 was merged
<scientes> well, 2.6 is a huge amount of time, so maybe the later ones
<scientes> But I don't really see a use-case for that
<scientes> Unless you really want 2.4, which is a much smaller kernel
<scientes> yeah, noone is support 2.4 either
<daurnimator> scientes: RHEL 6 uses 2.6.32
<scientes> yeah but rhel 8 was released
<daurnimator> which is still a common distro for many enterprise users
<scientes> and rhel6 doesn't even have systemd
<daurnimator> RHEL 6 is supported until 2020; and most gov/telecom companies will remain on it until then
<scientes> it does have cgroups however
<daurnimator> the question is: is there any reason zig wouldn't work on that kernel?
<daurnimator> and if so, why does our support table only say linux 3.16+
jevinskie has joined #zig
<scientes> I just don't think we should work like that
<scientes> software goes forwards
<daurnimator> scientes: I'd love to be able to use zig in a work context. but this is the sort of thing that potentially stands in the way
<scientes> if there is a business case, someone can always backport stuff
<scientes> thats the way Red Hat works
<daurnimator> that only works when *you* are the red hat customer
<daurnimator> it doesn't work when you're contracted to write software to run under redhat
<scientes> daurnimator, well, the language will never depend
<scientes> and the stdlib needs alot of work, this is the least of its problems
<scientes> so bring this up when you actually have a problem
<scientes> google runs all their software at HEAD
<scientes> clinging to old version is just not productive
<shachaf> My software only runs on Linux 5.1+.
<shachaf> Speaking of format, I implemented Zig-style format in C: <http://slbkbs.org/tmp/fmt.txt>. It's great.
<shachaf> I kind of wish I was using a language that didn't need so many hacks to do that, though.
<scientes> what hacks?
<shachaf> It's as bad as you might imagine.
<scientes> "elegent code" is a stupid idea
<scientes> its often taken way too far
<scientes> by people that aren't reading what the compiler actually produces
<torque> <scientes> google runs all their software at HEAD <-- google doing something is indeed a very compelling argument not to do that same thing
<scientes> haha
scientes has quit [Ping timeout: 255 seconds]
jevinskie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jevinskie has joined #zig
qazo has quit [Ping timeout: 252 seconds]
jevinskie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jevinskie has joined #zig
<bgiannan> Hey there. Did anyone considered writing something on https://learnxinyminutes.com/ for zig?
<emekankurumeh[m]> i considered it, but ended up getting distracted by other stuff
<emekankurumeh[m]> if you decide to do so, i would get andrewrk to check it first
<bgiannan> i'm in no way qualified to do so, was just wondering if something was being worked on
jjido has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jjido has joined #zig
rivten has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<mikdusan> re: issue #2481. i am not a windows user, but in this blog they talk about WSL 2 which actually uses linux kernel code and will soon be released. it seems that will solve the issue of missing linux kernel syscalls
avoidr has quit [Quit: leaving]
kristoff_it has joined #zig
<euantor> mikdusan: I believe they're going to support WSL 1 for a while. It sounds like WSL 2 uses Hyper-V to run, which makes it a non-starter for people who have to use tools like VMWare I believe as you can't run 2 different hypervisors on the same system. I certainly saw some people in comments complaing they'd be stuck on the current version
Zaab1t has joined #zig
rivten has quit [Ping timeout: 256 seconds]
rivten has joined #zig
Zaab1t has quit [Quit: bye bye friends]
xtreak has joined #zig
scientes has joined #zig
jevinskie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
xtreak_ has joined #zig
xtreak has quit [Ping timeout: 268 seconds]
Xe has joined #zig
<Xe> i've successfully moved to montreal now \o/
<Xe> once my home gets internet/a table/a desk I'm gonna work on the zig+olin PR
halosghost has joined #zig
xtreak_ has quit []
ryanworl has joined #zig
ryanworl has quit [Quit: Page closed]
<kristoff_it> where can I learn more about alignment? I'm in this weird situation where I - mostly - understand the basics (i.e. ~ word-aligned operations run faster) but I don't know enough to make my program do what I want (or, actually, if what I want is reasonable). More precisely in my cuckoofilter program I want to support different bucket sizes (think of it as a hash map if you're not familiar with the concept) and I think that good alignment for
<kristoff_it> these buckets might improve performance, but I don't know how to make that happen. So right now I have a struct field that - via generics - can be [][4]u8, [][4]u16, or [][2]u32, but I'm forced to declare it as [] align(1) T
<kristoff_it> so my question is: am I trying to do wrong things? if now, where can I learn how to do it?
<kristoff_it> *if not
<tgschultz> what is forcing you to use align(1)?
<kristoff_it> my init function takes a []u8 and uses @bytesToSlice
<kristoff_it> I'm doing that because I assumed I could hide the knowledge of what a bucket is from the user
<tgschultz> that was going to be my next question.
<kristoff_it> and now that you're making me say it, the two things kinda seem at odds
<kristoff_it> haha
<tgschultz> yeah, if you take []Bucket, you can ensure proper alignment with the allocator: allocator.alloc(Bucket, num_of_buckets);
<tgschultz> or even the stack: var buckets: [100]Bucket = undefined;
<kristoff_it> ok understood. So I should make an init that takes an allocator, and one that can accept a slice, but it has to be of Buckets. Makes sense, one is standard, while the other is a more advanced interface. I was originally not trying to make use of an allocator because after the initial one, no other allocations need to happen
<andrewrk> kristoff_it, you can also annotate your function that takes bytes like this: []align(@alignOf(Bucket)) u8
<kristoff_it> I tried going that route
<kristoff_it> but then I don't know how to proceed to make @bytesToSlice produce what I want
<kristoff_it> or something along those lines
<andrewrk> @bytesToSlice and @sliceToBytes should preserve alignment
<tgschultz> you don't need to make an allocator version of init, you can let the user handle it. Expose Bucket within the returned struct (pub const Bucket...) and the user can just call allocate with that type.
<kristoff_it> tgschultz: understood, thanks. I'll try to fiddle a little more with the other thing, just out of curiosity, and maybe post here the point where I get stuck, but then I'll probably go with your suggestion
<tgschultz> I do something similar in http://zig.tgschultz.com/object_store.zig
<andrewrk> I figured out my -cc1as problem from yesterday: https://github.com/NixOS/nixpkgs/issues/61501
<andrewrk> this is yet another example of how system dependencies are problematic
<donpdonp> c.read returns an isize, and I've checked it for being >0. how can I get a usize? @intCast doesnt want to convert it
<tgschultz> @intCast should convert it as long as it is >=0. What doesn't it like about it?
rivten has quit [Ping timeout: 256 seconds]
avoidr has joined #zig
wootehfoot has joined #zig
<donpdonp> hmm i guess its something I did. I went to look at the error again and it compiles now
<kristoff_it> uhmm, exposing Bucket makes initializing memory ugly, is there a better way than this?
<kristoff_it> var memory = []cuckoo.Filter8.Bucket{cuckoo.Filter8.Bucket{0, 0, 0, 0}} ** 256;
<tgschultz> var memory: [256]cuckoo.Filter8.Bucket = undefined; if don't care about it being zeroed. If you do, then: for(@sliceToBytes(&memory)) |*b| b.* = 0;
<tgschultz> an alternative is to add a function to the struct that returns [1]cuckoo.Filter8.Bucket set to 0: var memory: cuckoo.Filter8.Bucket.zero() ** 256;
qazo has joined #zig
<tgschultz> or even one that returns a whole array if given a comptime length: var memory = cuckoo.Filter8.Bucket.array(256); I suppose it depends on how often you expect to need to do that as to how convenient you need that use case to be.
wilsonk|3 has joined #zig
scientes has quit [Ping timeout: 245 seconds]
wilsonk has quit [Ping timeout: 246 seconds]
kristoff_it has quit [Ping timeout: 268 seconds]
kristoff_it has joined #zig
<kristoff_it> tgschultz: thanks for the suggestions. not sure how trivial this stuff seems from your PoW, but I had a hard time in the past trying to explain people how to use correctly cuckoo filters, and now that I have the opportunity of coming up with a decent interface, I want to make it as easy as possible to do the right thing
<kristoff_it> a function that takes a comptime number seems great actually, I'm not (fully) thinking with portals yet haha
<kristoff_it> I've also found another way: I can create for each bucket type a uN in type with @IntType(), have the user create a slice out of it and then do in my init @bytesToSlice(@sliceToBytes()) and get the right alignment.
<kristoff_it> your way is less convoluted though
<kristoff_it> uN int type with*
meheleventyone has joined #zig
lunamn has quit [Quit: leaving]
<kristoff_it> question: [] align(4) u8 means that the pointer of each element in the slice is aling(4), not just the first one right? It then also means that there are 3 bytes of padding between each element to ensure that, right?
Tetralux has joined #zig
meheleventyone has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
lunamn has joined #zig
<tgschultz> no, [] align(4) T means that the pointer to the first T is aligned to a multiple of 4
<tgschultz> align follows the thing it is aligning: *align(x) T aligns the pointer
DutchGh0st has joined #zig
<tgschultz> I don't think there is currently a way to express what you describe other than padding a struct.
<DutchGh0st> hiii
<DutchGh0st> Im getting an error: "expected type 'builtin.TypeId', found 'type' "
<tgschultz> DutchGh0st, is that unexpected?
<DutchGh0st> while Im switching on the typeinfo , it happens with the Struct case
<tgschultz> @typeInfo returns a union(TypeId)
<tgschultz> so you're switching on the TypeId, not the type
<tgschultz> oh, I see
<DutchGh0st> it was what you said, yep
<DutchGh0st> gotta grab typeid instead of typeinfo there
<tgschultz> except you're supposed to be able to do that with unions aren't you?
<tgschultz> oh wait, nevermind. I probably made the same mental mistake you did. Problem isn't in the switch(), but in the body of it.
<kristoff_it> tgschultz: thanks again, I was actually hoping my assumption was wrong. Good.
<DutchGh0st> woot
<DutchGh0st> you can import your own main.zig
<DutchGh0st> in main.zig xD
<tgschultz> you can instantiate it to
<DutchGh0st> instantiate?
<tgschultz> const main = @import("main.zig"); var a = main{}; @typeOf(a) == main;
<tgschultz> if you're now asking "why would I want to do that?", I don't have an answer.
<DutchGh0st> someone posted that on reddit
<DutchGh0st> and I was like "gotta rebuild in zig"
<tgschultz> it's more straightforward in zig. as usual.
<DutchGh0st> turns out yes
<tgschultz> since struct == namespace, you could just wrap that bottom bit in a struct and inspect that.
<DutchGh0st> yeahh I guess
<DutchGh0st> reee
<DutchGh0st> actually you could abstract it away maybe
<DutchGh0st> with std.meta
<DutchGh0st> hold my beer
<DutchGh0st> nah ya cant
<DutchGh0st> :(
<tgschultz> really? something like for(std.meta.definitions(@import(namespace.zig))) |def| debug.warn("{} ", def.name); doesn't work?
<DutchGh0st> error: no member named 'defs' in union 'builtin.TypeInfo ....
<DutchGh0st> std.meta.definitions doesnt exist btw
<DutchGh0st> Im making one :3
<DutchGh0st> because it would save some boilerplate
<tgschultz> no, there is one...
<tgschultz> meta.zig line 163
<DutchGh0st> OH
<tgschultz> definitions works on a type directly
<DutchGh0st> I was looking in std/meta
<tgschultz> andrewrk: `zig build-exe dos.zig -target i386-freestanding-none --release-fast` produces a file with an ELF header?
<DutchGh0st> whoa, I like how this returntype is defined: https://github.com/ziglang/zig/blob/0.4.0/std/meta.zig#L235
<DutchGh0st> its just like "oohh yeah whatever you passed in, we'll figure out whatever we need to pass back to you"
<kristoff_it> lmao
<DutchGh0st> thats hacks xD
<kristoff_it> it's like all the things that new programmers try to do that kinda make sense but don't actually work for various reasons
<kristoff_it> except that if it makes sense, here it works
<hryx> that return type is just a beautiful story unto itself
<DutchGh0st> we need @reify()
<tgschultz> I disagree. I've come around to the opinion that @reify would be more trouble than it is worth.
<kristoff_it> what is it supposed to do?
<tgschultz> It's the opposite of @typeInfo. given an instance of a typeInfo struct it would create a type from it.
<tgschultz> I believe that particular return type magic was Hejsil's.
<tgschultz> but if you work with the metaprogramming long enough you'll come up with similar things. Like, in Pseudo-Struct I use a recursively defined return type.
<tgschultz> and std.mem.asBytes uses a function to match the constness of whatever is passed to it.
<DutchGh0st> I did that too at one point
<DutchGh0st> there for example
<tgschultz> yep, pretty much exactly like that
<kristoff_it> wow that was an interesting read
<DutchGh0st> why doesn't that print anything?
<tgschultz> they aren't public
<tgschultz> just a guess
<DutchGh0st> but I can print def.name
<DutchGh0st> If I comment line 11, I get
<DutchGh0st> "hello\nworld\n"
<DutchGh0st> when I dont comment line 11, I get nothing
<tgschultz> there's a compiler assert if you don't comment out that line
<tgschultz> meta doesn't care if a def is public I guess, but meta.trait does
<donpdonp> see a switch statement for a function return type just blew my mind a bit.
<DutchGh0st> a compiler assert?
<DutchGh0st> lol
<DutchGh0st> Wellll thats a bug then
<tgschultz> weird, it seems convinced that .Var is a rutime value
<tgschultz> even though it is of type `type`, so it can't be.
<andrewrk> huh, zig already supports capturing the expression value for the `else` prong of a switch. I forgot I did that
<DutchGh0st> doesnt work?
<andrewrk> tgschultz, yes, generally ELF is what people want for build-exe in freestanding. do you have another use case?
<tgschultz> dos
<tgschultz> but it doesn't prodce an ELF in debug from what I can tell
<andrewrk> that is surprising, how are you checking?
<andrewrk> elf files start with "\x7fELF"
<tgschultz> No, I'm mistaken. I checked with a hex editor and it is ELF in both modes. just dumping the raw bytes to the console doesn't show that in the debug case for some reason though.
scientes has joined #zig
<tgschultz> probably the debug case happens to contain backspaces or home or something in it shortly after
<andrewrk> hmm I have never considered the use case of targeting DOS
<tgschultz> neat, I'm breaking new ground.
<andrewrk> if it's important to you and you're willing to sort of take ownership of the feature, you can add a new OS target
<tgschultz> I was considering it, depending on how things went. I'm curious if I could use zig to make a protected mode dos game.
<andrewrk> it might be nice to allow extending targets without having to commit to upstream zig, but for now that's how it works
<tgschultz> from what little is available on the subject, LLVM probably won't get along well with real mode.
<andrewrk> I think github user @jayschwa might share this use case
<andrewrk> I talked to him in person yesterday; he's working on restoring some kind of doom-era game that he bought the rights to
<andrewrk> catacombs
<tgschultz> my kinda guy
<tgschultz> he bought the rights to catacomb3d? Nice.
<tgschultz> it was pre-wolf3d carmack, IIRC
<andrewrk> yeah that's right
<tgschultz> well, if I can prove the concept to myself I'm planning on streaming it. I've been wanting to stream some game dev for a while, but my other projects aren't suitable for a variety of reasons and I've wanted to make a dos game since I first read Tricks of the Game Programming Gurus as a kid.
<andrewrk> sounds interesting
<DutchGh0st> mhh
<DutchGh0st> how do I set full debugmode in gdb?
qazo has quit [Quit: leaving]
<DutchGh0st> because I want to figure out why @typeName(def.data.Var) crashes the compiler
<andrewrk> DutchGh0st, I don't know what full debugmode is, but if you run the zig command using gdb, the back trace should be a pretty big clue about why it's crashing
<hryx> one of the regulars at my monthly game dev meetup is making DOS games. so I assume it's still alive as a hobby (?) target especially for games
<DutchGh0st> Assertion failed. This is a bug in the Zig compiler.???:?:?: 0x8704029 in ??? (???)???:?:?: 0x86c8494 in ??? (???)???:?:?: 0xe18a51f in ??? (???)
jayschwa has joined #zig
<andrewrk> is that one of the release builds from ziglang.org/download?
<andrewrk> you can build a debug version of zig from source
<DutchGh0st> its one I downloaded
<DutchGh0st> and it happens in release 0.4 too
<DutchGh0st> and 0.3 as well
<tgschultz> ir.cpp:10427:0
<tgschultz> assert(const_val->data.x_type != nullptr);
<DutchGh0st> uh oh
qazo has joined #zig
<tgschultz> nothing about this code makes me think it would be unable to resolve the type though, so this is mysterious
<tgschultz> huh, const_val.type == 0x3266750
<tgschultz> oh wait, that's a pointer, not an id
<jayschwa> yes, I am interested in using Zig for a DOS game. Catacomb 3D was originally 16-bit realmode, but I've removed almost all the assembly and self-modifying code, and hoping to get it working as 32-bit protected mode "soon". I think I did compile a "hello world" program using Zig and ran it in DOS a few months ago, but I'll need to dig around for that experiment.
<tgschultz> if you find that, I'd be interested in having a look if you don't mind.
<tgschultz> So with this bug the type is known to be ZigTypeIdMetaType with ResolveStatusUnstarted.
<jayschwa> if I can find it and get it working again, I'll post it in a gist.
<tgschultz> cool, I'd appreciate it.
<DutchGh0st> but I gotta go now
<DutchGh0st> goodluck hunting the bug down! I made an issue on github, I really wonder what the cause is!
DutchGh0st has quit [Remote host closed the connection]
kristoff_it has quit [Ping timeout: 245 seconds]
jevinskie has joined #zig
jjido has joined #zig
<tgschultz> DutchGh0st, best guess with this bug is that @typeName expects the type to have been resolved, but for some reason it isn't.
<tgschultz> my knowledge of compiler internals is still weak
jevinskie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jevinskie has joined #zig
jevinskie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
kristoff_it has joined #zig
kristoff_it has quit [Ping timeout: 268 seconds]
halosghost has quit [Quit: WeeChat 2.4]
wootehfoot has quit [Read error: Connection reset by peer]
scientes has quit [Ping timeout: 258 seconds]
jayschwa has quit [Quit: Page closed]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
scientes has joined #zig
lunamn has quit [Quit: leaving]
hio has quit [Quit: Connection closed for inactivity]
<andrewrk> switching on error sets just got much better
<hryx> :O
<hryx> très bon
triplefox has joined #zig
<triplefox> i would like to use zig as a build system for lua(i.e. compiling the lua executable from the standard 5.3.5 distribution). i'll do other things with it later but is there a good reference for just that?
<mikdusan> 5,001 commits
stratact has joined #zig
<hryx> sup triplefox
<triplefox> hello pal
<daurnimator> triplefox: build system is completely undocumented at this point
<daurnimator> triplefox: but lua should be pretty easy: build the core as a library by just adding all the .c files except lua.c and luac.c
<triplefox> daurnimator: hmm, i think i get it