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/
fengb has joined #zig
<fengb> Hey I'm starting to attempt translating C into Zig. Any ideas why Zig considers this opaque? https://github.com/fengb/fundude/blob/master/src/cpu.h#L40
<fengb> Hmm... every bit struct is opaque
<fengb> src/cpu.h:19:11: warning: struct cpu_flags demoted to opaque type - has bitfield
<fengb> Is this a difficult edge case to handle? Or is zig not handling it at all?
<scientes> fengb, opaque types are types where the size is not known
<scientes> so they can only be referred to by reference
<scientes> its used in C to minimize the size of an exported ABI
<daurnimator> scientes: is that a non sequitur? .... in the case here it just looks like bit fields are NYI
<scientes> oh yeah I realized I'm looking at C
<scientes> I guess zig doesn't know how to deal with bit fields yet
<scientes> its a gnu extension
<scientes> but zig has bit fields
<daurnimator> huh? bit fields aren't a GNU extension to C
<scientes> yes they are
<scientes> Whether atomic types are permitted for bit-fields (C11 6.7.2.1).
<scientes> oh, they made it into C11
<daurnimator> they're in C90
<scientes> but they were a gnu extension before that :)
<scientes> damn
<daurnimator> ?
<scientes> you are right
<scientes> it just seemed so funky i assumed it was a gnu extension
<fengb> So my question is... should I try implementing it? Or am I barking up the wrong tree
<scientes> and it isn't in K&R C either
<daurnimator> fengb: you probably need to add it to translate-c
* scientes wonders if the LLVM api has enough information to deal with those
<scientes> or if zig is re-implementing the DataLayout llvm class
<scientes> daurnimator, that's clang
<fengb> daurnimator: I see. I'm a little afraid this would be beyond me so maybe I should remove the bitfields
<scientes> zig doesn't link to clang
<daurnimator> scientes: yes it does
<scientes> or does it?
<daurnimator> scientes: translate-c is literally done by linking to libclang
<scientes> yeah but that is a utility
<scientes> but does cImport also use clang?
<daurnimator> scientes: yes
<daurnimator> @cImport and translate-c use the same routines
<scientes> yeah its probably just an oversight, because zig also has bitfields
<scientes> there are alot of those in zig right now
<scientes> stuff that just isn't implemented
<daurnimator> yep. though usually they're called out with a TODO
<daurnimator> in any case, the solution is to write the missing pieces
<fengb> There's actually an issue to convert these into comments
<fengb> So it's more obvious why it's missing rather than digging out a warning
<daurnimator> fengb: indeed. there's also a project to rewrite translate-c in zig
<fengb> In this case, it might be quite difficult. You can have uint32 : 1, uint16 : 1, etc. in C and they should all be u1 in Zig
<fengb> And the padding... I don't understand how padding works
<fengb> Oh hey look at that. I think I'll take a stab at this
<scientes> fengb, if it requires a bunch of cpp, the style is to wrap it to a c api
<scientes> in zig_llvm.cpp
fengb has quit [Ping timeout: 256 seconds]
scientes has quit [Ping timeout: 257 seconds]
knebulae has quit [Read error: Connection reset by peer]
kristoff_it has joined #zig
kristoff_it has quit [Remote host closed the connection]
jevinskie has joined #zig
Aransentin_ has quit []
avoidr has quit [Quit: leaving]
return0e_ has quit [Remote host closed the connection]
_whitelogger has joined #zig
tdc has quit [Quit: Leaving]
jjido has joined #zig
return0e has joined #zig
heitzmann has quit [Quit: WeeChat 2.4]
heitzmann has joined #zig
marijnfs has joined #zig
knebulae has joined #zig
<tgschultz> I think interface reform mark 3 is going to be the one. I've just got one more docgen test to fix and then a little cleanup and the remaining problems will be down to #2501, #2487, and #2515.
gonzus has joined #zig
<gonzus> Hello. I just sent this PR: https://github.com/ziglang/zig/pull/2530
<gonzus> I would like to know if this is something of interest or not, to know if I should keep working on this.
<tgschultz> gonzus: andrewrk is on vacation for a few days, so it may be a bit before you get a response on that.
<gonzus> Ah, cool. I will keep working on this anyway then, I am having fun... :-p
fengb has joined #zig
scientes has joined #zig
<fengb> Is there a way to make a "strict" typedef? Where it throws an error if the comptime reference isn't correct
scientes has quit [Remote host closed the connection]
wilsonk has joined #zig
scientes has joined #zig
diginet_ has joined #zig
dembones_ has joined #zig
tyler569_ has joined #zig
tyler569 has quit [*.net *.split]
SimonNa has quit [*.net *.split]
andrewrk has quit [*.net *.split]
edr has quit [*.net *.split]
dembones has quit [*.net *.split]
rain1 has quit [*.net *.split]
squeek502 has quit [*.net *.split]
uso_ has quit [*.net *.split]
diginet has quit [*.net *.split]
diginet_ is now known as diginet
wilsonk|2 has quit [*.net *.split]
Thalheim has quit [*.net *.split]
adsr has quit [*.net *.split]
so has quit [*.net *.split]
SimonNa has joined #zig
jevinskie has quit [Ping timeout: 246 seconds]
rain1 has joined #zig
Thalheim has joined #zig
jevinskie has joined #zig
gonzus has quit [Ping timeout: 256 seconds]
fengb has quit [Ping timeout: 256 seconds]
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
Aransentin has quit []
return0e has quit [Ping timeout: 268 seconds]
scientes has quit [Remote host closed the connection]
scientes has joined #zig
return0e has joined #zig
marijnfs has quit [Read error: Connection reset by peer]
jevinskie has quit [Ping timeout: 245 seconds]
jevinskie has joined #zig
so has joined #zig
avoidr has joined #zig
jevinskie has quit [Ping timeout: 258 seconds]
jevinskie has joined #zig
<emekankurumeh[m]> what do you mean by comptime reference?
<jjido> I imagine fengb wants to put constraints on which types are allowed.
<scientes> jjido, what do you mean?
<scientes> jjido, some platforms are not going to support 128-bit types for example
<jjido> I mean macros taking type argument
<scientes> again, i need some context
jevinskie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
meheleventyone has joined #zig
scientes has quit [Ping timeout: 245 seconds]
<donpdonp> std.Buffer feels like it started with the idea of a trailing null, then dropped that idea but not all the code got updated.
<donpdonp> pub fn len(self: *const Buffer) usize { return self.list.len - 1; // assumes a trailing null byte
<donpdonp> yet Buffer.initSize(allocator,0) does not appent a null byte to list, so len() crashes
<donpdonp> BufferZero would be a better name, with a new Buffer that is clean of null business.
Aransentin has joined #zig
scientes has joined #zig
<donpdonp> hmm initSize does reallloc to (0+1) so might not be buggy after all, but im getting an intoverflow.
return0e has quit [Read error: Connection reset by peer]
Zaab1t has joined #zig
meheleventyone has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Zaab1t has quit [Client Quit]
wootehfoot has joined #zig
Zaab1t has joined #zig
Aransentin has quit [Quit: Page closed]
Zaab1t has quit [Remote host closed the connection]
redj has quit [Read error: Connection reset by peer]
redj has joined #zig
jjido_ has joined #zig
jjido has quit []
return0e has joined #zig
jjido_ is now known as jjido
kristoff_it has joined #zig
kristoff_it has quit [Remote host closed the connection]
<tgschultz> scientes, I think what's being discussed is like the @distinct proposal. like, my function takes an x,y, and z, bu those must be in meters so I create a new type called Meter that's the same as float in reality, but not for type checking.
<scientes> oh yeah that is good idea, C has that
<scientes> can't you do that with a struct however?
return0e has quit [Ping timeout: 272 seconds]
<scientes> Linux depends on that to make uid's distinct for examples, its very important for avoiding security problems
<tgschultz> yeah, but you'll have to treat it as a struct and access members.
<scientes> cause I would like to minimize the number of crazy features in zig
<tgschultz> I'm in the same boat
<scientes> like @This() is kinda for the lazy
<scientes> and is confusing
<tgschultz> @This() is absolutely required, because you can't call a type by name in its own definition if it isn't top-level
<scientes> oh I C
<tgschultz> and also a lot of generated types don't even have names.
<tgschultz> they're just `return struct {...`
<scientes> maybe we could somehow hack the struct thing to work
<tgschultz> If we could, I'm not at all opposed to dropping @This(). I don't enjoy the boilerplate of `pub const Self = @This()` on things.
<scientes> cause i find it excessive that you have to name a union in c, and then the member
<scientes> well it makes it clearer what is going on that way...
<scientes> how about anonymous structs to solve this problem https://stackoverflow.com/a/14248127/8890015
<scientes> oh no that doesn't do it
return0e has joined #zig
Sahnvour has joined #zig
<emekankurumeh[m]> doesn't zig have a distinct "typeID" for all it's types?
<scientes> emekankurumeh[m], no, all ints have the same typeID
<emekankurumeh[m]> but ints have a different typeID than say floats, correct?
<scientes> yes
<scientes> how about if a struct only has one member, you can leave off the name, and then it will magically work like we want?
<scientes> that is pretty hacky
<scientes> yeah @distinct seems best
<emekankurumeh[m]> creating structs seems to indicate that "allocating" typeIDs is somewhat trivial, so could a distinct builtin just allocate a new typeID with the same underlying type?
<scientes> emekankurumeh[m], all structs have the same zig type ID, and it isn't trivial, in fact LLVM is going to change how it works in the future with pointers
<scientes> emekankurumeh[m], but sometimes you want stuff to implicitely cast
<scientes> the problem we are talking about is bikeshedding about the syntax
<emekankurumeh[m]> i thought zig had its own typeID system.
<scientes> it does
<scientes> but that doesn't mean it doesn't use LLVM"s as well
wootehfoot has quit [Read error: Connection reset by peer]
<donpdonp> $ zig test src/oneFile.zig is actually convenient enough to use. #winning
<emekankurumeh[m]> but why would this need to extend to llvm as well@
<scientes> it doesn't
<scientes> nor does it in clang
<scientes> the real issue here however is not the compiler
<scientes> its a bikeshedding issue
<scientes> god i hate autotools
<emekankurumeh[m]> hmmm, since the proposal wasn't accepted yet I thought there was some other issue with distinct types
<scientes> emekankurumeh[m], there is a lot of work to do
<scientes> please contribute
<scientes> but maybe start on something a little less involved first
<scientes> like something user-space
<scientes> emekankurumeh[m], it would probably keep the same TypeID so that the compiler doesn't break
<scientes> but gain a new internal field special for type-checking
Sahnvour has quit [Ping timeout: 272 seconds]
Aransentin has joined #zig
Sahnvour has joined #zig
marijnfs has joined #zig
<marijnfs> hi, i'm trying to find in the documentation what the ! means for return values? Does it mean an error can be thrown?
<jjido> it separates return type from error set
<scientes> > Does it mean an error can be thrown?
<scientes> yes
<scientes> that's exactly what i means
<scientes> marijnfs, realize that errors in zig are just syntactic sugar
<scientes> they are implemented with multiple argument returns
<scientes> so more like the Linux kernel, than c++
<emekankurumeh[m]> I don't think it should be too hard. I've done some work on the compiler before and it wasn't too bad
<emekankurumeh[m]> i should probably wait until the proposal is accepted though
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<marijnfs> scientes: thanks, yeah its nice that its clear about that
hio has joined #zig
<marijnfs> it.peek().?.id
<marijnfs> what's that question mark in a member call
<scientes> its dereferencing the pointer
<scientes> sorry
<scientes> no, it is unwrapping an optional
<scientes> and assuring that it isn't null
<scientes> (if it is null that is UB)
<marijnfs> scientes: I see, so you could dereference directly also? but thats risky?
<scientes> no, it is a compiler error to do that
<scientes> but .? is also risky
<scientes> it is UB
<scientes> marijnfs, optionals are differn't types, and you can't use them until you unwrap them
<scientes> if you want to do it safe, you have to use if (optional) |unwrapped| { do_with_unwrapped(unwrapped);}
<emekankurumeh[m]> marinjfs, it means the same thing as `optional orelse unreachable`
<scientes> or if you don't want to have to indent all your code, unwrapped = if (optional) |u| u else throw error.ENOENT;
<scientes> or something like that
<scientes> wait there is no throw
<scientes> just return error.ENOENT
<scientes> oh i forgot about orelse
<scientes> which is the same as ? : gnu extension in C
<emekankurumeh[m]> hearing about all these c extensions makes me wish I never tried writing portable code
<scientes> emekankurumeh[m], well the gnu extensions are quite portable now, as gcc and clang support them
<scientes> and the propritary compilers are all becoming clang-based
<emekankurumeh[m]> really?
<emekankurumeh[m]> is icc clang based, as well?
<scientes> i think both arm and ibm's propritary compilers are now clang-based, microsoft is the last holdout, but have integrated clang into vscode
<scientes> no icc is not
<Sahnvour> not being microsoft compliant can hardly be called portable
<scientes> Sahnvour, oh god the warning i got from *clang* on windows the other day
<scientes> tells you not to use open()
<scientes> and instead _open()
<Sahnvour> I wish I could use clang on windows :-)
<scientes> why not?
<via> scientes: what gnu extension involves ? : ?
<scientes> via, its a gnu extension to leave out the middle
<via> huh
<scientes> which makes it identical to zig's orelse
<Sahnvour> I don't do C++ outside work anymore, and we're using msvc; but clang is coming in fast these years to be honest, so soon™
<via> cool
<scientes> Sahnvour, just start porting it
<scientes> support two compilers is good for any code-base
<Sahnvour> we do actually, but not on windows
<marijnfs> I see, optionals are quite useful i think, but a bit strange as well
<Sahnvour> probably not a really big change to have the codebase support it; it's more of an infrastructure thing
<marijnfs> but you can test if they are set by a simple if right?
<emekankurumeh[m]> clang on windows works fine, doesn't it?
<scientes> marijnfs, they are also an optimization, as it allows the "nonnull" attribute to be set
<Sahnvour> emekankurumeh[m], totally fine, they did awesome job
<scientes> emekankurumeh[m], it builds chrome
<scientes> emekankurumeh[m], zig on windows is built using llvm+clang (of course)
<emekankurumeh[m]> really?
<Sahnvour> actually no, it's built with msvc
<emekankurumeh[m]> i thought the city used msvc
<scientes> well yeah
<scientes> oh yeah, but zig applications
<scientes> sorry there is a distinction
<Sahnvour> yep, zig itselfs embeds clang, and is using llvm
<scientes> stage1 builds with gcc clang or msvc
<emekankurumeh[m]> well I guess you could make the that case because stage 1 is zig and c/c++ code, linked using zig
<tgschultz> when did --assembly get removed? how am I supposed to add an asm file now? build.zig?
<scientes> tgschultz, try passing it as a c file
marijnfs_ has joined #zig
<scientes> ahh i always wondered what the difference between .S and .s was
marijnfs has quit [Ping timeout: 272 seconds]
<marijnfs_> is there a compiler directive to print the members of a variable? Like, i imported some c-header and want to see whats available
jjido has joined #zig
marijnfs has joined #zig
marijnfs_ has quit [Ping timeout: 245 seconds]
jevinskie has joined #zig
Sahnvour has quit [Read error: Connection reset by peer]
marijnfs_ has joined #zig
marijnfs has quit [Ping timeout: 257 seconds]
adsr has joined #zig
marijnfs_ has quit [Ping timeout: 248 seconds]
marijnfs has joined #zig
return0e has quit [Ping timeout: 272 seconds]
return0e has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
mikdusan has quit [Ping timeout: 258 seconds]
return0e has quit []
return0e has joined #zig
marijnfs_ has joined #zig
marijnfs has quit [Ping timeout: 246 seconds]
marijnfs has joined #zig
marijnfs_ has quit [Ping timeout: 248 seconds]
marijnfs_ has joined #zig
marijnfs_ has quit [Remote host closed the connection]
marijnfs has quit [Ping timeout: 272 seconds]
mikdusan has joined #zig