<joey152>
I am getting a compile error with: 1 << i
<joey152>
where i is a u32
<joey152>
error: LHS of shift must be a fixed-width integer type, or RHS must be compile-time known
<joey152>
ive tried @intCast(u32, 1) << i
<joey152>
but I get error: expected type 'u5', found 'u32'
<ikskuh>
yeah
<ikskuh>
zig doesn#t allow you shifting with int sizes that is possible out-of-bounds
<ikskuh>
so you have to use @intCast on your shift distance
<joey152>
oh ic
<fengb>
It’s UB in C. u32 <<32 is a nop on x86, but other archs can clear the register instead
<joey152>
so I'm supposed to cast the i to a u5
<fengb>
Yep
<joey152>
thanks
chapl has joined #zig
ur5us has quit [Ping timeout: 244 seconds]
<oats>
is there only one syntax for tagged enum literals?
<oats>
Enum{ .Variant = foo }
xackus has quit [Read error: Connection reset by peer]
xackus_ has joined #zig
SimonNa has joined #zig
wozeparrot has quit [Quit: Connection closed for inactivity]
slurpie has joined #zig
<andrewrk>
async I/O is shaping up
<chapl>
Explain. :D
<andrewrk>
we have behavior tests with --test-evented-io passing on all CI test targets except freebsd
<andrewrk>
it's about time to enable CI testing of async I/O
<fengb>
Oh wow
<chapl>
On all CI test targets... Does that include Windows? IIRC, Windows wasn't initially supported
<andrewrk>
windows has behavior tests passing with evented I/O and file system integration
<chapl>
Wowzers! Good to hear
<chapl>
andrewrk: Would it be reasonable to implement varint and varlong encoding into the std lib? Like, just providing it as neat little batteries included feature?
<andrewrk>
what is that, a big integer implementation?
<chapl>
Fiddling a lot with Minecraft's protocol and I just figured that I have to do a lot of varint encoding
<chapl>
Never heard of VarInts?
<shachaf>
There are a lot of different kinds of varints so if you're implementing some format you'll probably have to reimplement it anyway.
<chapl>
Yeah, there's the protobuf way and something called zigzag. I don't know a lot about VarInts. And I actually don't know what Minecraft uses.
<ikskuh>
yeah, true
<ikskuh>
zigzag will be helpful i think
<ikskuh>
varint is "encode smaller values with less bytes"
aerona has joined #zig
<mikdusan>
but what's the largest value?
<ikskuh>
in theory: none
<ikskuh>
for the varint encoding i use in dunstblick it's 32 bit (encoded as 5 byte)
<mikdusan>
ok so bigint that's efficient at the tiny-end
<chapl>
Is there VarInt encoding with no particular style? We've covered zigzag and protobuf. Is there a 'none'-style? Or is zigzag the canonical?
<chapl>
"LEB128 or Little Endian Base 128 is a form of variable-length code compression used to store an arbitrarily large integer in a small number of bytes. " Interesting
<chapl>
Gonna go ahead and try decode the handshake packet the Minecraft client sends.
<mikdusan>
extra points for making Zero and Ziggy ziguana skins
<chapl>
Yo that'd be dope :D
<chapl>
Implementing a Minecraft limbo server and when you join, you're gonna wear a Ziggy skin!
<chapl>
lol
<andrewrk>
there's a LEB128 decoder in the debug info parser
<chapl>
I'm not familiar with LEB128. Is it another term for VarInt?
<fengb>
Varint is a generic term. LEB128 is a specific algorithm
<chapl>
Oh, alright
<chapl>
Thank you for elaborating
<fengb>
Protobuf’s zigzag is another varint but pretty sure it’s not LEB128 compatible
<oats>
while trying to implement a recursive formatter too
<oats>
yeah, so I've got a recursive data structure for an AST
<oats>
I was trying to implement format() so it could be printed nicely, but on any case that needs to recurse to format a sub-expression, the Semantic Analysis step asplodes
<chapl>
Is there a difference using io.getStdOut().outStream().print() vs std.debug.warn()?
<andrewrk>
quite a few. stdout vs stderr. default evented/blocking mode when async I/O is enabled. whether there is a mutex protecting writes.
<chapl>
Which would you recommend then?
<chapl>
The most canonical one
<chapl>
Like basic output. Like you were doing some form of logs
<andrewrk>
those two things are different use cases: basic output vs logs
<chapl>
Console only
<chapl>
I'd just go with std.debug.warn
<andrewrk>
if you were implementing `ls` or `find` you would use stdout
<chapl>
so io.getStdOut() then
nephele_ has joined #zig
<andrewrk>
you should look into buffering the output as well. there is std.io.BufferedOutStream to help with this
nephele has quit [Ping timeout: 246 seconds]
nephele_ is now known as nephele
<chapl>
Alright, clarification time. I implementing a limbo server, in Zig, for Minecraft. A limbo server is basically a server you can put players on while they wait for something to happen. Maybe getting moved onto another server, waiting for a queue to dequeue... It's a timeless space where you can basically do nothing. You just wait. I'd like to print incoming packets and whenever a player connects or disconnects.
<chapl>
Now, I'm wondering what to use. Either std.debug.warn or io.getStdOut().outStream().print(). I'm not doing file-based logs. It's console only.
<chapl>
I'm implementing*
<andrewrk>
in this case probably std.debug.warn is appropriate
<andrewrk>
yes, it's the milestone on the side bar
<chapl>
I just figured that out lol
<chapl>
Sorry
<chapl>
And 'move std.debug.warn to std.log.warn' seems like a really good idea
marijnfs_ has joined #zig
<chapl>
Now, I noticed that there is something like '@setCold()'. I did read what it does. It marks a function as cold, implying it not getting called frequently. But what does the compiler under the hood? @andrewrk
<chapl>
do under the hood*
<chapl>
I should stop writing that fast
marijnfs has quit [Ping timeout: 246 seconds]
dddddd has quit [Remote host closed the connection]
<foobles>
chapl I just read the compiler internals, and it just adds an LLVM attribute to the function
<foobles>
Attribute::Cold, which is just handled by LLVM
<chapl>
Oh, ok
<chapl>
Thank you!
<chapl>
So. Kinda trivial. When to accept an allocator as argument? I'm having troubles figuring out when to use allocators and when not. I'd like to stick to stack mem but I feel like that's wrong to do. And yes, I know, generally accept an allocator when you're developing a lib. But that's not very helpful.
<fengb>
If you don’t need an allocator, don’t use one
<chapl>
But what's the criteria???
<fengb>
Stack is always better, unless you need to control lifetimes
<foobles>
yeah, any time in other languages where you would use the heap or something
<pmwhite>
yeah, it's not wrong to stick to stack memory if its the best thing to do.
<foobles>
but its better to use stack is possible
<foobles>
and dont use an alloca allocator ;P
<fengb>
Things like returning dynamic data. You can’t return that on the stack
<fengb>
Arbitrary strings, creating things from parsing, etc
<chapl>
I have a struct called NetworkConfig, and it is actually a file which resides in the same directory. It will be read by the server I'm currently implementing. The file uses the JSON format so at some point I have to call readFileAlloc. That's all danty. Now I don't know whether to accept an allocator first hand, when calling the type's init() fn, or when I call let's say readFromFile().
<chapl>
I'm using a page allocator
<pmwhite>
Either way would be fine I think. It depends on whether you want to allow the user of that API to use different allocators on multiple readFromFile calls.
<pmwhite>
If you take the allocator inside init(), then you should probably also have a deinit function that de-allocates any memory that you used during the lifetime of the NetworkConfig object.
<chapl>
The file reading process is the only case where I would need an allocator to be passed. So requiring the allocator when reading the file seems more reasonable
xackus has joined #zig
<pmwhite>
If you receive it in readFromFile, then its up to the person who called that file to deallocate the memory, since NetworkConfig will have no idea what allocator was used to allocate each piece of memory, so it will have no idea how to free it.
xackus_ has quit [Ping timeout: 240 seconds]
<chapl>
I don't. I'd like to have a cheatsheet for something like this. But there's none.
<chapl>
I don't know.*
<pmwhite>
There are too many cases to cover for their to be a cheatsheet. I'm no expert here, but my thinking is that experience will give one an intuition for what to do. I think the kind of question you're asking is typical of the kind of problems you have to solve all the time. That is, every situation is going to call for a different solution.
ur5us has joined #zig
<pmwhite>
I would think the allocator should be received in the init function, since then NetworkConfig can abstract all the memory allocation and deallocation with a deinit function. Otherwise, the caller of readFromFile will have to reach inside the NetworkConfig to deallocate the JSON data itself.
<chapl>
Seems reasonable
<chapl>
Thank you!
Snetry has quit [Ping timeout: 244 seconds]
Snetry has joined #zig
knebulae has quit [Read error: Connection reset by peer]
<chapl>
pmwhite: Still there?
waleee-cl has quit [Quit: Connection closed for inactivity]
joey152 has quit [Remote host closed the connection]
<pmwhite>
Yeah
benjif has quit [Ping timeout: 265 seconds]
<chapl>
It got resolved :D
<chapl>
gtg
chapl has quit [Quit: leaving]
dimenus has joined #zig
dimenus has quit [Ping timeout: 265 seconds]
ur5us has quit [Ping timeout: 260 seconds]
benjif has joined #zig
benjif has quit [Ping timeout: 260 seconds]
aerona has quit [Remote host closed the connection]
<daurnimator>
foobles: that's fine. on the PR you can also click on a reviewer at the top right
<daurnimator>
often projects set up multiple "teams" so that you would e.g. request a review from someone in the "stage1" team
<daurnimator>
andrewrk: ^ do you think we're at a point yet where that makes sense?
<andrewrk>
I think github's suggested reviewers feature is quite accurate
<daurnimator>
andrewrk: its accurate... but I always feel a bit odd just picking someone
<andrewrk>
foobles, generally, it's reasonable to repeat a request for review or other attention every so often if you don't get any attention
<foobles>
ok thank you!
<foobles>
very good to know :)
<daurnimator>
and e.g. should you request multiple people? or just one?
<andrewrk>
zig is at the point right now where pull requests have outpaced the available time to spend on merging them. I'm working on getting some funding for more paid full time developers to close this gap, but there will be a period of time now where the number of open PRs grows
<andrewrk>
growing pains
<foobles>
just wait until the `1000+` open PRs :)
<daurnimator>
andrewrk: would you like me to merge PRs that e.g. 1. are for the std library and 2. aren't from myself?
<andrewrk>
let me consider that and get back to you
<andrewrk>
right now your access controls are intended for issue labeling
<foobles>
huh, there are not any suggested reviewers. it's just empty
<daurnimator>
andrewrk: FYI github also supports a special file called "CODE_OWNERS" which lets you specify which files/directories can be approved/merge by which people.
<andrewrk>
yeah it sorts by commit counts of commits that touched that file
<andrewrk>
in the last 300 commits
<foobles>
huh, cool
<foobles>
heh, superjoe
chapl has joined #zig
_whitelogger has joined #zig
Kingsquee has joined #zig
<andrewrk>
tbh the easiest workaround is to edit the ir.cpp code to add the coercion
riba has joined #zig
chapl has quit [Quit: Lost terminal]
chapl has joined #zig
<chapl>
Just before I head to bed: andrewrk, I'm willing to give you 10 bucks on demand via PayPal if you resolve the LEB128 encoding issue in 24 hours. Up for the challenge? :D
<chapl>
Up to the challenge*
<daurnimator>
andrewrk: I was looking for a workaround (e.g. some series of casts) that would allow the code to work with the 0.6.0 release
<daurnimator>
chapl: his bribe-rate is higher than that :P
<chapl>
Man I really need this feature and I don't jack shit about it D: I'd implement it myself but I to dumb for this
<daurnimator>
^ that's how andrew earns his living
<chapl>
"Your sponsorship will not be matched at this time.
<chapl>
"
xackus has quit [Ping timeout: 246 seconds]
<daurnimator>
chapl: oh? where did you see that?
<chapl>
On GitHub. I don't know what it's trying to tell me. I can sponsor nevertheless. Gonna sponsor you and andrewrk. Now I know it was a good decision to cancel my amazon prime subscription. :P
<chapl>
(tada) You’re sponsoring daurnimator
<chapl>
(tada) You’re sponsoring andrewrk
<chapl>
Yaayy
metaleap has joined #zig
<chapl>
Oh and I just noticed, the new Zig logo is now being used! Awesome! Looks real neat
mokafolio has quit [Remote host closed the connection]
mokafolio has joined #zig
dddddd has joined #zig
return0e has quit [Remote host closed the connection]
return0e has joined #zig
return0e has quit [Ping timeout: 256 seconds]
return0e has joined #zig
return0e has quit [Remote host closed the connection]
drasko has joined #zig
riba has quit [Ping timeout: 265 seconds]
alexnask_ has joined #zig
alexnask has quit [Ping timeout: 272 seconds]
ifreund has quit [Ping timeout: 256 seconds]
ifreund has joined #zig
pystub has joined #zig
riba has joined #zig
return0e has joined #zig
dingenskirchen has quit [Quit: dingenskirchen]
riba has quit [Ping timeout: 272 seconds]
dingenskirchen has joined #zig
_whitelogger has joined #zig
Kingsquee has quit [Quit: Konversation terminated!]
return0e_ has joined #zig
return0e_ has quit [Remote host closed the connection]
return0e_ has joined #zig
return0e has quit []
alexnask_ is now known as alexnask
drasko has quit [Ping timeout: 272 seconds]
frett27_ has joined #zig
frett27 has quit [Ping timeout: 256 seconds]
klltkr_ has joined #zig
drasko has joined #zig
dingenskirchen has quit [Remote host closed the connection]
dingenskirchen has joined #zig
wootehfoot has quit [Read error: Connection reset by peer]
decentpenguin has joined #zig
drasko has quit [Ping timeout: 272 seconds]
drasko has joined #zig
sanaris has joined #zig
decentpenguin has quit [Quit: decentpenguin]
<pmwhite>
ya know, zig is pretty well-suited for a wayland wrapper that provides non-trivial value. I'm currently working with the linux-dmabuf interface. To create a wl_buffer, one has to register a listener and send a request. The wl_buffer is received in the listener. A zig interface could suspend when the request is sent, and resume inside the listener.
<pmwhite>
The C API usually uses the `wayland-scanner` program to generate client code for. I bet something similar could be done at comptime directly from the xml file that describes protocol extensions.
<ifreund>
hmm that would be pretty neat
<ifreund>
i know tdeo has been working on a zig implementation of the protocol as well
<pmwhite>
does he got a repo somewhere?
<ifreund>
hmm, did some snooping around on github but couldn't find it
st4ll1 has quit [Ping timeout: 260 seconds]
cole-h has joined #zig
<blueberrypie7>
"This is a bug in the Zig compiler" ... so how do i go about finding the bug i triggered so it can be fixed? https://pastebin.com/RSkjZJAK
<blueberrypie7>
i suppose i'll need a debug build of zig?
<alexnask>
The stack trace would be useful, otherwise some stripped down testcase that triggers the bug
<tdeo>
pmwhite: i don't think a clean request/response stuff happens enough to really have an interface like that
<alexnask>
Oh wow this is worse than I thought :p It looks like the same issue to me yes, some wrong generation of union(enums)
<blueberrypie7>
ok i'll add the code to the issue
<tdeo>
what are you doing with linux-dmabuf though? usually only mesa uses that extension directly
<tdeo>
linux-dmabuf *does* make it so i can actually use accelerated graphics without libwayland on non-nvidia systems though, with a bit of boilerplate for allocating buffers i think
<tdeo>
and same with dri3 on x11 (also non-nvidia systems...)
<alexnask>
autocad startup is so slow...
chaplchapl has joined #zig
<pmwhite>
tdeo: I didn't know it was Mesa-only...I thought that was the case for the wl-drm extension, and that linux-dmabuf was what I was supposed to use instead.
Cogitri has quit [Ping timeout: 256 seconds]
<tdeo>
well, it isn't mesa-only, it's just that usually mesa uses it on behalf of you
<pmwhite>
Yeah, that's what I meant.
<chapl>
I read Mesa and suddenly I think of Black Mesa. Gman's coming for you. Prepare for unforeseen consequences.
<oats>
what's the difference between io.OutStream and fs.File.OutStream?
<oats>
oh wait nvm, silly question :P
foobles has joined #zig
<oats>
is it possible to set up an OutStream that writes to a growable string? like an ArrayList(u8)
<tdeo>
ArrayList(u8).outStream() :)
<pmwhite>
tdeo: emersion on the wayland channel has just enlightened me, so now I'm no longer clueless, lol.
<tdeo>
what are you working on with wayland?
<oats>
tdeo: they've thought of (almost) everything
<fengb>
It actually took awhile to add that >_>
<pmwhite>
tdeo: terminal emulator at the moment. I'm also building a weird opinionated GUI library, so I'm just making random widgets when I feel like it. Sort of hoping to make some graphic design tools as well.
<tdeo>
nice, sounds pretty interesting
<oats>
has anyone had trouble writing a recursive .format() function? Mine sends the compiler into an infinite Semantic Analysis death loop...
drasko has quit [Ping timeout: 244 seconds]
kevsmith has joined #zig
<oats>
I've got this recursive type representing an AST, and I thought I'd write a .format() pretty printer for it. Trying to compile it though, the compiler seems stuck on the Semantic Analysis step, the numbers growing without end
chaplchapl has quit [Remote host closed the connection]
chapl has quit [Remote host closed the connection]
<tdeo>
i'm not sure if anyone can help without seeing some of the code
<oats>
I wonder if the compiler is caught on trying to resolve the type of out_stream somehow or something
<tdeo>
.Negative and .Not from unary are always recursive
<tdeo>
or not?
<oats>
yeah, they're recursive
<tdeo>
nah i misread `self: Expr` as `expr: Self`
<oats>
gotcha
<tdeo>
then assumed since zig doesn't allow shadowing (which is nice) that expr was recursing
<tdeo>
(unconditionally)
<oats>
yeah, I get a bit annoyed sometimes, but no shadowing has saved me from doing silly things more than once
<blueberrypie7>
soo... if i've got a slice of bytes and I know for certain that those bytes the slice refers to can be safely cast to some struct how would i do so?
<tdeo>
@bitCast or @ptrCast
<blueberrypie7>
ah thanks didn't know about ptrcast
<tdeo>
oats: yeah i don't know what's happening here either... it's probably a bug in the compiler
<tdeo>
or
<tdeo>
it really is recursive, because every single format call has to be partially evaluated at comptime
<tdeo>
and every one of those partial evaluations partially evaluates a function that recurses
<oats>
mmmmmm
<oats>
that could be
<oats>
k then, I'll just write my own pretty printer :<
<oats>
469273
<oats>
ignore that :P
<oats>
totally not a misplaced 2fa code
<alexnask>
blueberrypie7, You shoould use a packed struct though, technically the compiler is allowed to rearrange struct fields unless it is extern or packed
_Vi has joined #zig
Patrice_ has joined #zig
frett27_ has quit [Ping timeout: 260 seconds]
benjif has joined #zig
drasko has joined #zig
slurpie has joined #zig
kristoff_it has joined #zig
demizer has joined #zig
Chris660 has joined #zig
drasko has quit [Ping timeout: 272 seconds]
waleee-cl has joined #zig
xackus has joined #zig
foobles has quit [Ping timeout: 245 seconds]
drasko has joined #zig
reductum has joined #zig
return0e_ has quit []
return0e has joined #zig
pltrz has joined #zig
<pltrz>
!join #gomux:mautrix.org
<pltrz>
!join #gomux:maunium.net
<ikskuh>
i think you should use
<ikskuh>
/join #gomux:maunium.net
<pltrz>
oh derp on several levels. sorry for the spam folks
<sanaris>
Hey guys, do you have anything new, something like newsfeed or digest "what's new in Zig"
<ifreund>
sanaris: well there's the changelog every release
<ifreund>
a "this week/month in zig" blog post series would be nice though
<ifreund>
i just stalk the github repo to stay up to date myself
<andrewrk>
it would be a nice service for someone to provide to do a "this week in zig" email or something like that
<andrewrk>
I'm at full capacity, I definitely can't take on this task
<ifreund>
yeah totally understandable
<sarmonsiill>
would be awesome with some kind of letter like that