ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
mal`` has quit [Quit: Leaving]
mal`` has joined #zig
dbandstra2 has quit [Quit: Page closed]
nicolaslekoala has quit [Remote host closed the connection]
<andrewrk>
we will have the c++ compiler forever and it must always be able to build the self hosted compiler. this keeps our bootstrapping process O(1)
<andrewrk>
also, the self-hosted compiler shares some c++ code with it, because we use LLVM which is a C++ API
dbandstra has joined #zig
darithorn_ has quit [Remote host closed the connection]
nicolaslekoala has quit [Read error: Connection reset by peer]
l1x has quit [*.net *.split]
epsyloN has quit [*.net *.split]
edr has quit [*.net *.split]
saolsen has quit [*.net *.split]
chandlore_ has quit [*.net *.split]
darithorn has quit [Quit: Leaving]
darithorn has joined #zig
darithorn has quit [Remote host closed the connection]
dbandstra has quit [Quit: Leaving]
darithorn has joined #zig
dbandstra has joined #zig
<GitHub1>
[zig] andrewrk opened pull request #1032: use * for pointer type instead of & (master...pointer-reform) https://git.io/vhcz6
<dbandstra>
can someone give me a basic pointer or two? i just started playing with zig last night and i'm struggling with a few things
<dbandstra>
two questions (why can i return a struct by value, and why do i get a compile error lower down)
<andrewrk>
I'm also happy to answer questions :) looking at your gist now
<dbandstra>
ok i think i bookmarked that article but i will give it a read thanks
<andrewrk>
dbandstra, returning a struct by value - currently this does a memcpy to copy the result to the caller, however the optimizer can sometimes elide the copy. we also have a plan to have well-defined copy-eliding semantics so that you can get a guarantee about the return value not being copied. https://github.com/ziglang/zig/issues/287
<andrewrk>
as for the compile error in your gist, I believe that is a bug and I will look into that right now
<andrewrk>
oh, actually I think this is working as designed
<andrewrk>
when you put the * in the |*person| you're asking for a mutable pointer
<andrewrk>
so you can take out the * and it builds fine
<dbandstra>
does that still return a reference to the Person object from the global array?
<dbandstra>
|person| doesn't copy it out?
<andrewrk>
I think you can return &person
<andrewrk>
let me double check
<andrewrk>
oh, and you can implicitly cast T to &const T, so return person is the same as return &person
<andrewrk>
in answer to your other comment, you can also implicitly cast T to ?T
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
<dbandstra>
i guess things are changing a lot at the moment hehe
<dbandstra>
what i'm really troubleshooting is a weird runtime crash in a little game i'm making, but i'm going to slow down a bit, do some more reading
<dbandstra>
feels like i'm returning a pointer to a stack local
<andrewrk>
in your gist?
darithorn has quit [Quit: Leaving]
davr0s has joined #zig
<dbandstra>
yeah
<dbandstra>
oh no it was outside of that, in some code i didn't represent in the gist
<dbandstra>
i was allowed to do an assignment where left hand side was a pointer and right hand side was not.. that's where the stack local crash was happening
<dbandstra>
i still don't know how to write the findPersonByAge function so that it returns a pointer to the original array item, where the array is const
chandlore_ has joined #zig
saolsen has joined #zig
edr has joined #zig
epsyloN has joined #zig
l1x has joined #zig
<dbandstra>
what i mean is in this:
<dbandstra>
var pointer: &const i32 = undefined;
<dbandstra>
pointer = value;
<dbandstra>
const value: i32 = 1;
<dbandstra>
the last line seems to coerce to `pointer = &value;`
<dbandstra>
is that intentional?
<dbandstra>
guess c++ references do that too... phew
dbandstra has quit [Ping timeout: 260 seconds]
dbandstra has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
davr0s has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Hejsil has joined #zig
dbandstra has quit [Ping timeout: 248 seconds]
<Hejsil>
dbandstra, idk what andrewrk means that |*something| captures by mutable pointer. It should really just capture by pointer of same mutability as the slice: https://pastebin.com/raw/1F5hxPxc
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
nicolaslekoala has joined #zig
davr0s has joined #zig
isaachier has joined #zig
<isaachier>
thanks andrewrk for the explanation. i definitely see the benefit to writing a compiler in pure zig now.
<isaachier>
on a separate note, i was writing some zig code yesterday and noticed there is no easy way to iterate through an array list and deinit the elements. i understand i can use an arena allocator, but why does `toSlice` act like `toSliceConst`?
<isaachier>
also, why does the array list deinit take `&const Self` as its arg, vs. buffer's deinit takes `&Self` as its arg.
<isaachier>
or i should actually say buffer's deinit takes `&Buffer`.
hinst has quit [Quit: No Ping reply in 180 seconds.]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
hinst has joined #zig
isaachier has quit [Quit: Page closed]
nicolaslekoala_ has joined #zig
bheads_ has quit [Read error: Connection reset by peer]
<nicolaslekoala_>
What happens if I create an undefined []u8 variable, defer alloc.free, try to allocate memory and the allocation fails?
nicolaslekoala_ has quit [Ping timeout: 244 seconds]
<Hejsil>
nicolaslekoala_ the same as if you try to dealloc a uninitialize pointer in C
return0e_ has joined #zig
davr0s has joined #zig
return0e has quit [Ping timeout: 256 seconds]
Hejsil has quit [Ping timeout: 260 seconds]
return0e_ has quit [Remote host closed the connection]
return0e has joined #zig
bheads has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<nicolaslekoala>
#1030 looked like a nice first issue to learn a bit about the code base. I coded a small fix that disables zig fmt on all files that start with // zig fmt: skip (and that only reads the first 16 chars at first, to avoid loading large files in memory). Can anyone take a look at it? Or should I just send a pull request? It's up at github.com/d1adev/zig/tree/fmt-guard
davr0s has joined #zig
bheads_ has joined #zig
Hejsil has joined #zig
<Hejsil>
nicolaslekoala, you can just open a PR. If something isn't right, someone is sure to request a change :)
bheads has quit [Ping timeout: 244 seconds]
Hejsil has quit [Ping timeout: 260 seconds]
<GitHub90>
[zig] d1adev opened pull request #1033: Add a format guard (master...fmt-guard) https://git.io/vhC8k
darithorn has joined #zig
bheads__ has joined #zig
bheads_ has quit [Ping timeout: 244 seconds]
<andrewrk>
dbandstra, I think Hejsil is right that there is a compiler bug here. What you're trying to do is definitely supposed to be possible, and the * in |*| is supposed to make the thing a pointer, not necessarily mutable
<andrewrk>
maybe I should close IRC after I get past a certain point of sleepiness :)
<GitHub134>
zig/master a3d7a80 Andrew Kelley: appveyor: remove llvm 5.0.1 from cache
<GitHub134>
zig/master 081072d Andrew Kelley: docs: add missing builtin to langref syntax coloring
davr0s has joined #zig
clownpriest has joined #zig
lvarela has joined #zig
bheads_ has joined #zig
bheads__ has quit [Ping timeout: 256 seconds]
Hejsil has joined #zig
clownpriest has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
return0e has quit [Ping timeout: 244 seconds]
return0e has joined #zig
clownpriest has joined #zig
return0e has quit [Read error: Connection reset by peer]
return0e has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
dbandstra2 has joined #zig
isaachier has joined #zig
<isaachier>
Any ideas about the ArrayList anomaly I mentioned above?
isaachier has quit [Client Quit]
<Hejsil>
isaachier, Well ArrayList.deinit doesn't modify the state of the struct, so taking const pointer makes sense
<andrewrk>
isaachier, Buffer deinit could take a const ptr
<Hejsil>
^ Was about to write that lol
<andrewrk>
that being said, I'm considering that it may be idiomatic to have deinit functions end with self.* = undefined;
<andrewrk>
this would be a no-op in release and in debug mode write 0xaa's (same as initializing a variable to undefined), or potentially more advanced debug safety ideas
<Hejsil>
zig-fmt-pointer-reform-2 was the branch that updates to newest syntax yes?
<andrewrk>
yes, this will translate all address-of and pointer-type nodes to *
<andrewrk>
so you would then have to fix all the address-of instances
<andrewrk>
Hejsil, what was the unattached doc comment? did it look like it should be attached?
<Hejsil>
No, it was a doc comment on out commented code
<Hejsil>
So it makes sense it wasn't attached :)
quc has joined #zig
<andrewrk>
Hejsil, the problem I'm getting with std-meta-rebased right now is that we're doing @typeInfo(error) and the implementation is trying to populate the []Error slice but that doesn't make sense for that type
<andrewrk>
I think we need a different way to represent the global error set in TypeInfo
<Hejsil>
Hmmm
<Hejsil>
Ye, we probably can't use @typeInfo to get all errors in the global error set can we?
<andrewrk>
correct
<Hejsil>
So @errorName have to stay
<Hejsil>
Idk if I tried to remove it
<andrewrk>
you did not
<Hejsil>
Good job me!
<andrewrk>
here's my proposed new definition of builtin.TypeInfo.ErrorSet: https://clbin.com/gKvZK
<andrewrk>
that way @typeInfo(error) == TypeInfo.ErrorSet
<Hejsil>
Looks good
<Hejsil>
Looking over all the formatted code is amazing
<andrewrk>
you like it? :)
<Hejsil>
Love it!
<Hejsil>
Though, my aligned imports are gone :(
<Hejsil>
Ooh wel
<andrewrk>
I think that's an unfortunate downside, but the plus side is that not-aligned things are more diff friendly
<Hejsil>
Now we just need fmt on build
<Hejsil>
Is there a plan for having fmt available from the stage 1 compiler... Somehow?
<andrewrk>
I have an idea if we wanted to do that
<andrewrk>
we would do it the same as how we do zig test and zig build - have std/special/fmt_runner.zig and we would just build zig fmt on demand and then run it as a child process
<Hejsil>
That works
<andrewrk>
once the self hosted compiler is up to par though we would delete this, because end users wouldn't have any use for stage 1
<Hejsil>
Agreed
<Hejsil>
Stage 1 is just the only usable compiler, so it would be nice if we could use fmt from it :)
<andrewrk>
agreed
<andrewrk>
now that I'm thinking about it more, I think it would be worth it
<andrewrk>
especially because we could use it as a suggestion for
<andrewrk>
...for hard tabs and windows newlines
<andrewrk>
"just run zig fmt"
<Hejsil>
People would still complain though
<Hejsil>
But it's better
<andrewrk>
true
<Hejsil>
Looking forward to newline and tap discussions for years to come
<andrewrk>
that would be ironic since the goal is to just pick a side so that people can stop discussing
<Hejsil>
I'm all in for, "just pick a side"
<Hejsil>
It makes life easier
<Hejsil>
I do prefer "Struct {" over "Struct{" though :)
<Hejsil>
But with "Struct.{" comming up, I get my way >:)
<Hejsil>
It really want's to put arrays with one element on "1" line
<Hejsil>
Even if the element is big and have trailing comma
<andrewrk>
that looks like a mistake specific to multiline strings
<andrewrk>
oh, that's a line comment. oops
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
return0e has quit [Read error: No route to host]
return0e has joined #zig
quc has quit [Ping timeout: 240 seconds]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Hejsil has quit [Ping timeout: 260 seconds]
davr0s has joined #zig
clownpriest has joined #zig
<clownpriest>
"evaluation exceeded 1000 backwards branches" is this saying that a compile time function eval is too long? if so, how do i tell the compiler it's ok?
<nicolaslekoala>
@setBranchEvalQuota(number)
<nicolaslekoala>
@setEvalBranchQuota, sorry
<clownpriest>
thank you
<clownpriest>
where would i put this call?
<clownpriest>
placing it before the function which causes it (or at the beginning of main()) doesnt work
darithorn has quit [Quit: Leaving]
<nicolaslekoala>
Put it inside comptime {}
clownpriest has quit [Ping timeout: 268 seconds]
stereosteve has joined #zig
<andrewrk>
the compile error you get if you put it at the wrong place tells you where to put it - the bottom of the "called from here" stack
stereosteve has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
dbandstra2_ has joined #zig
dbandstra2 has quit [Ping timeout: 260 seconds]
strmpnk has joined #zig
dbandstra2_ is now known as dbandstra2
return0e has quit [Ping timeout: 260 seconds]
dbandstra2 has quit [Quit: Page closed]
return0e has joined #zig
dbandstra has joined #zig
return0e has quit [Read error: Connection reset by peer]
clownpriest has joined #zig
clownpriest has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
clownpriest has joined #zig
<clownpriest>
fmt.bufPrint throws an "exceeded 1000 backwards branches" error, even though it's a vararg function (i.e. can't increase evalbranchquota in a comptime block)
<clownpriest>
any chance there's some existing resources on string formatting in zig? or are we not there yet
<andrewrk>
you have to put the setEvalBranchQuota at the top of the comptime stack. so probably the same scope that you're calling bufPrint in
<andrewrk>
resources? you mean like documentation?
<clownpriest>
yeah
<clownpriest>
in addition to the base docs
<andrewrk>
not yet. the roadmap for that is self-hosted compiler, then auto generated HTML docs, then I'll put some effort into adding doc comments
<clownpriest>
cool
<clownpriest>
what do you mean by comptime stack?
clownpriest has quit [Read error: Connection reset by peer]
<andrewrk>
the first compile-time expression starts the block quota. every function call from then on is counted against the quota
<andrewrk>
so you have to put the quota in the root comptime expression
clownpriest has joined #zig
<clownpriest>
sorry, internet died
<andrewrk>
no worries, the channel is logged
<clownpriest>
thank you! i will have to return to this later, about to board plane
<clownpriest>
just want to say thank you for making zig tho, it has been so sorely missing from the language landscape
<andrewrk>
:)
clownpriest has quit [Client Quit]
clownpriest has joined #zig
clownpriest has quit [Quit: My Mac has gone to sleep. ZZZzzz…]
clownpriest has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]