ky0ko_ has quit [Remote host closed the connection]
aruniiird has joined #zig
ur5us has quit [Ping timeout: 240 seconds]
_Vi has joined #zig
cole-h has joined #zig
marnix has quit [Read error: Connection reset by peer]
marnix has joined #zig
cr1901_modern has quit [Quit: Leaving.]
cr1901_modern has joined #zig
_Vi has quit [Ping timeout: 265 seconds]
cr1901_modern has quit [Ping timeout: 246 seconds]
<protheory8-new-m>
Btw, should someone improve the error message when doing `std.Thread.spawn(self, self.fnName);`?
<protheory8-new-m>
Or is it fine?
st4ll1 has quit [Quit: WeeChat 2.9]
Stephie has quit [Quit: Fuck this shit, I'm out!]
Stephie has joined #zig
_Vi has joined #zig
craigo_ has quit [Ping timeout: 258 seconds]
cole-h has quit [Quit: Goodbye]
ur5us has joined #zig
<protheory8-new-m>
What I mean is if I do `std.Thread.spawn(self, self.fnName);`, it doesn't compile with an error in standard library, `std.Thread.spawn(self, StructName.fnName);` should be done instead. The error message for this isn't very good, but it's kind of fine
<pixelherodev>
andrewrk: most people would probably say that building 30 glibcs is itself weird ;P
<daurnimator>
those people haven't lived
<scientes>
^^^
<scientes>
if you are not breaking things you are not doing it correctly
marnix has joined #zig
BoilerOnAsurf has joined #zig
craigo has joined #zig
<BoilerOnAsurf>
Hi, can anyone explain why the pass by value/pass by reference decision has been left to the compiler? I'm just curious about the rationale, as I find this point ambiguos and it strikes me as weird given that is a pretty important decision and that zig aim to clarity.
<shakesoda>
well, the compiler has enough information about the target to make the right choice. i'm sure there's a longer form explanation from someone else though.
marnix has quit [Read error: Connection reset by peer]
<shakesoda>
afaik, it's really to prevent footgunning yourself with it, and it means passing a pointer is explicitly used when you need mutability
<daurnimator>
A better question might be: you can force pass-by-const-reference; but why can't you force pass-by-value?
<BoilerOnAsurf>
I'm an hyper newbie in zig, but to be honest I would rather have the possibility to footgun myself without having the compiler take this decision for me, even if its probably better than me at it.
* shakesoda
wonders about any cases that might be useful
<ikskuh>
BoilerOnASurf: wdym exactly?
<alexnask[m]>
I prefer this to passing `*const T` everywhere (and possibly having to use the size of T to pass either by value or by const ref in generic code)
<shakesoda>
BoilerOnASurf: well, for what gain? passing non-ptr is always immutable, so that's off the table, and the fast way to pass stuff can be determined without programmer input every time
<BoilerOnAsurf>
shakesoda: no gain at all probably
<shakesoda>
i'm also curious if there's a fuller explanation, but from actually using it, this hasn't come up as an issue (writing perf sensitive code, too)
<BoilerOnAsurf>
shakesoda: is not an issue at all, I get the pros of it, but would be great to hear the rationale anyway. This syntax seems to hide a detail, and that seems to be away from zig's aim (even if is in the user's best interest).
<BoilerOnAsurf>
alexnask[m]: maybe, but as it is there are two possible behaviours for the same syntax.
<alexnask[m]>
It can also introduce subtle footguns where an argument that is considered const can be mutated through another mutable ptr argument. (e.g. if you pass a mut ptr to a struct and a field of the struct that ends up being passed by const ptr and modify the struct, the second argument will be modified as well)
<alexnask[m]>
Theres an issue with an example of this but I cant find i atm
<daurnimator>
BoilerOnASurf: I suppose it came about organically: imagine has a huge (e.g. 4K) struct and want to take it as an argument. there is no way to take it *except* by reference
<shakesoda>
BoilerOnASurf: i don't think the spirit of "communicate intent precisely" is what exactly something gets compiled as in cases like this, especially when it serves several other purposes (e.g. reducing the amount one must remember, favoring reading, one obvious way to do things...)
<daurnimator>
so you end up with a rule of "its okay to change from by-value to by-reference"
<daurnimator>
it also comes down to calling conventions: different calling conventions pass different things...... differently
<shakesoda>
daurnimator: and often self-inconsistently, i.e. only first couple args in registers, the rest in stack
<shakesoda>
so the value passing ends up being a bit of a lie anyways
<daurnimator>
yep
<daurnimator>
so the idea of by-value => by-reference comes about pretty organically
<daurnimator>
and zig just put the rule in that you can't go the other way
* shakesoda
didn't think of it this way before
ur5us has quit [Ping timeout: 260 seconds]
<BoilerOnAsurf>
Yeah these are all valid points. There's a way to enforce a calling convention on a function for a given target? Again not suggesting anything and I don't need it, just curious.
<protheory8-new-m>
Or is the error supposed to be like that?
<alexnask[m]>
The stdlib code could do some checking and emit a better error
<alexnask[m]>
But you just need to replace self.fnName with fnName
<alexnask[m]>
self.fnName is a "bound fn", aka a function + the self parameter, here you want to pass self as the context (as you did) and the unbound fn
<protheory8-new-m>
I mean I know, I was thinking that an error message should be better
<alexnask[m]>
Yes, it could be better for sure, it just assumes you passed a Fn atm
<protheory8-new-m>
Is there a way to do `await` without the a function suspending or something like that?
<protheory8-new-m>
I do `await` inside `asyncMain` function, `asyncMain` suspends and the entire program exits
<protheory8-new-m>
> I do `await` inside `asyncMain` function, `asyncMain` suspends and the entire program exits
<protheory8-new-m>
How do I solve this? I was thinking about some kind of await that doesn't suspend, but that's kind of weird
<alexnask[m]>
await is fundamentally a suspend (+ a tail resume from the callee function to the caller when it is done)
<protheory8-new-m>
what am I supposed to do in that case then?
<alexnask[m]>
Im sorry, I dont quite get what your usecase is, afaict doing it the way that is shown in that example should be good enough, you can use `await` in amain and all the fns it calls
<protheory8-new-m>
I have something similar to the code in the example, but my code doesn't have resumes in main, it has them in other thread so `main` function returns earlier than any resumes can happen.
<alexnask[m]>
I see, would waiting on that thread in main not solve this?
<protheory8-new-m>
It would, but that thread never ends executing.
<fengb>
From a high level, your main needs to wait on whatever is outstanding. In most other systems, this is done by wiring it into the event loop that handles all of the resumes
sawzall has quit [Read error: Connection reset by peer]
sawzall has joined #zig
<leeward>
If that other thread never stops executing, it sounds like you don't want main to ever terminate. So waiting on the other thread is the way to go, no?
<companion_cube>
question from a friend: would Zig be extensible to add pre/postconditions on functions, for formal verification? :p
<leeward>
like contracts?
<companion_cube>
yeah, exactly like contracts
<leeward>
I wonder if the language actually has to be changed for that.
<companion_cube>
I think so, if you don't want to run them, just to analyse them at comptime
<leeward>
Extensible implies language support for language extensions.
<companion_cube>
alternatively, being expressive enough that the extension can be removed/processed purely in userland :)
<ikskuh>
you can probably do that
<ikskuh>
preconditions are just "if(!argMatchesCondition) @panic()"
<ikskuh>
and postconditions can probably be implemented as soon as @resultLocation() is a thing
<ikskuh>
which you validate in a defer
<companion_cube>
ahah nice
<ikskuh>
if you write a nice library, it will probably be super-readable
<fengb>
We need the comefrom statement 🙃
<companion_cube>
well, maybe we'll get the assertions after parameters, like in D? for emulating type bounds
<ikskuh>
why that? we can probably have a more extensible type system?
<companion_cube>
hmm, not following
<companion_cube>
I mean having `(…params) if … { … }` where the if is comptime, used to place restrictions on parameters
<ikskuh>
but why?
<ikskuh>
i can just write that in the method body itself
<ikskuh>
and be done
<companion_cube>
ah, I see.
<companion_cube>
right, since it's still executed at comptime…
<ikskuh>
yep
<companion_cube>
so the body itself is part of the type if it wants to
<ikskuh>
ah wait
<ikskuh>
no, i don't follow
<ikskuh>
we either have a strict enough type system already (except for @Int())
<ikskuh>
or it will be runtime checks anyway
casaca has quit [Ping timeout: 246 seconds]
xackus has quit [Ping timeout: 258 seconds]
cren has quit [Ping timeout: 256 seconds]
radgeRayden has joined #zig
a_chou has joined #zig
a_chou has quit [Client Quit]
a_chou has joined #zig
marnix has quit [Ping timeout: 240 seconds]
a_chou has quit [Quit: a_chou]
swills has quit [Quit: swills]
ofelas has quit [Ping timeout: 240 seconds]
swills has joined #zig
mahmudov has joined #zig
<mahmudov>
hi, i am getting ": CommandLine Error: Option 'mc-relax-all' registered more than once!" error with llvm 10.0.1 with "-DCMAKE_BUILD_TYPE=None -DCMAKE_INSTALL_PREFIX=/usr -DZIG_PREFER_CLANG_CPP_DYLIB=ON"
<blinghound>
Is there an easy way to add a signed int to an unsigned int without lots of casting?
<ikskuh>
no :D
<blinghound>
ahh ok, naughty inline function time
msingle has quit [Client Quit]
<scientes>
blinghound, inline functions are not naughty when everything is fastcc
msingle has joined #zig
<ikskuh>
scientes: inline in zig is enforced :)
<blinghound>
I mean naughty only in the way that I'm hiding all the unsafe casting behind it
<scientes>
ikskuh, no it isn't
<scientes>
the LLVM inliner cannot be converted however
<scientes>
*improved
<scientes>
that is the consensus
<ikskuh>
scientes: it is defined as enforced
<blinghound>
Aren't the functions inlined pre llvm?
<scientes>
blinghound, that would only be possible if you turned everything into a loop
cren has quit [Remote host closed the connection]
<scientes>
including recursion
<scientes>
which is something LLVM actually wanted to do and never got around to
<scientes>
but you only need to do it for recursion
<scientes>
that's why what you says makes no sense
<scientes>
if you inlined everything your code size would be massive
<scientes>
-funroll-loops
<ikskuh>
scientes: fun fact: zig has a keyword "inline" which enforces inlining ;)
<ikskuh>
which i was talking about
<ikskuh>
afaik it is already inlined in IR, not in llvm
<scientes>
ikskuh, ahh, no big deal---inline while works like that
<blinghound>
I didn't mean that all functions are inlined, just that functions marked with the inline keyword (possibly excluding recursion) are inlined at AST time
<leeward>
Is there a -f-inline-only-functions-larger-than-cache-line ? That seems like a good pessimization option.
<scientes>
leeward, the inliner is VERY complicated
<leeward>
scientes: it was a joke
<scientes>
oh yeah
<scientes>
"pessimization"
<leeward>
:P
<blinghound>
What would be the best way to add a negative number to an unsigned int?
<leeward>
subtract?
<blinghound>
the number could be positive too
<scientes>
blinghound, add a bit to the unsigned int making it signed
<leeward>
So...a signed number then?
<leeward>
Are you suggesting changing a u16 to an i17?
<blinghound>
I'm trying to find an easier way to add a signed number to an unsigned number
<blinghound>
without loads of casting or conditionals
sawzall has quit [Read error: Connection reset by peer]
sawzall has joined #zig
<blinghound>
maybe I'm being stupid, but if feels like there should be an easier way than: @intCast(u32, @as(i33, num) + other_num);
<leeward>
I'm not sure there is if you want to keep safety.
<blinghound>
yeah that's what I expected, I thought there might be a slightly more elegant @function
<andrewrk>
@as is supposed to be seen as effortless
<ikskuh>
andrewrk: how strong are you against a different syntax for @as?
<andrewrk>
not against it but I have put a lot of thought into it and could not come up with anything better
<ikskuh>
@ isn't the most convenient character to type
<alexnask[m]>
ikskuh What is it in German layout?
<ikskuh>
it's on AltGr+Q
<ikskuh>
(right alt)
<alexnask[m]>
>.>
<ikskuh>
andrewrk: i assume you thought about "expr as T", right?
<blinghound>
andrewrk would @as(u32, @as(i33, unsigned_num) + signed_num) be the best way?
<blinghound>
I understand the difficulties when we get so many benefits with the safety, I just wanted to make sure I was going about it the right way
<andrewrk>
ikskuh, zig actually had that syntax at one point :)
<ikskuh>
oh? so T(expr) was another iteration of that already?
<leeward>
What about (expr as T)?
st4ll1 has quit [Ping timeout: 256 seconds]
st4ll1 has joined #zig
<leeward>
ikskuh: How do you send e-mail? That's super inconvenient.
<ikskuh>
leeward: autocompletion and copy/paste :D
<leeward>
Mmm, I see an opportunity for an editor macro.
<ikskuh>
you mean key rebinding? :D
<leeward>
Or that.
<ikskuh>
has anyone here bound the compose key?
<leeward>
lemme check
<leeward>
nope
<companion_cube>
ikskuh: I have it on right-ctrl
<ikskuh>
i'm not alone \o/
<ikskuh>
caps lock is my key
<ikskuh>
ctrl-right is useful for gaming :D
<leeward>
Isn't caps lock where ctrl is supposed to be?
<companion_cube>
caps lock is for `escape` for me
<companion_cube>
useful for vim :p
<leeward>
My solution to that is to never install vim on anything ever.
<ikskuh>
compose allows funky things
<ikskuh>
ẍ
<fengb>
I never install vim
<fengb>
It just is
<leeward>
Wow, I don't even have vi installed on this machine.
<leeward>
I probably had to uninstall it.
<companion_cube>
leeward: blasphemy
<companion_cube>
ø
<ikskuh>
just install tilde!
<ikskuh>
or EDIT.COM
<leeward>
companion_cube: My editor religion is the best editor religion. All others are heathens. It's just the way it is.
<companion_cube>
exactly!
<companion_cube>
thanks for recognizing I'm right
<companion_cube>
and that all the others are wrong
marnix has quit [Ping timeout: 258 seconds]
<leeward>
I use the holy escape meta alt control shift, as stolen from the Gosling by the Stallman. I don't know what you're talking about.
metabulation has quit [Ping timeout: 240 seconds]
<leeward>
ooh, pinebook just arrived
<leeward>
Tonight is going to be busy.
<companion_cube>
time to install emacs on it?
bastienleonard has joined #zig
<leeward>
Exactly!
<leeward>
If only I didn't have to put another OS underneath it...mmm, bare metal emacs...
<leeward>
Then all I'd need is a decent editor.
ur5us has joined #zig
_Vi has quit [Ping timeout: 272 seconds]
metabulation has joined #zig
metabulation has quit [Ping timeout: 240 seconds]
cole-h has quit [Quit: Goodbye]
joey152 has joined #zig
Akuli has quit [Quit: Leaving]
bastienleonard has left #zig ["ERC (IRC client for Emacs 27.1)"]
<andrewrk>
I'm taking a couple days off. Take care everybody
<BaroqueLarouche>
Take care and rest well!
<leeward>
enjoy
<ikskuh>
andrewrk: enjoy!
blinghound has quit [Quit: Leaving]
<fengb>
Have fun!
metabulation has joined #zig
<ifreund>
o7
mahmudov has left #zig ["Leaving"]
msingle has quit [Ping timeout: 246 seconds]
metabulation has quit [Read error: Connection reset by peer]