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/
Flaminator has quit [Ping timeout: 246 seconds]
<diltsman> Why is this escaping me? Where is compiler-rt in the LLVM/Clang source tree?
<tbodt> compiler-rt is in a different git repo from llvm/clang
<tbodt> if that helps
<diltsman> I'm pretty sure that it is part of the source code when you download and build Clang.
<andrewrk> tbodt, they moved to a git monorepo
<tbodt> did not kow
<tbodt> *know
diltsman has quit [Ping timeout: 256 seconds]
vegecode has joined #zig
<vegecode> Hello, quick question. I have a table of function pointers that go at address 0 on a microcontroller. This table is the interrupt vectors.
<vegecode> I'm trying to provide a default definition for each vector, which should be a function pointer to a common default handler that loops endlessly
<vegecode> I would like for the user to be able to simply write their own function with the same name and have it take precedence over the default
<vegecode> I see that compiler-rt.zig uses the @export function to create a symbol in the table with weak linkage, but I can't create the array unless I have each function defined in the file. In that case, my @export function appears to be making a copy in the table with the same name but with ".0" appended. Any ideas?
<vegecode> Also, when I make my over-ride function, I get the error: exported symbol collision
<vegecode> it says the other symbol is in the @export but I have weak linkage selected so ?
<vegecode> A compile time weak attribute on functions would be nice. I wanted functionality similar to when you use a pragma to declare an interrupt like so:
fsateler has quit [Read error: Connection reset by peer]
<vegecode> __interrupt[NMI_INTERRUPT] void myNMIFunction(void), etc.
<vegecode> There's no dealing with imports, the compiler just does what needs to be done.
fsateler has joined #zig
<vegecode> Now the user will have to go to the startup code where the table is, locate the appropriate position, import their function into the startup code file, and stick it into the array.
<vegecode> That's not a huge burden or anything, but the standard way is pretty easy in comparison.
<vegecode> standard meaning the C way
<emekankurumeh[m]> tangentially related: https://github.com/ziglang/zig/issues/661
<andrewrk> vegecode, I definitely want to address this. I'm about to go to bed - would you mind filing an issue?
<vegecode> Sure thing. I will file one tomorrow. Thanks.
vegecode has quit [Quit: Page closed]
kristate has joined #zig
knebulae has quit [Ping timeout: 245 seconds]
knebulae has joined #zig
kristate has quit [Remote host closed the connection]
dewf has joined #zig
kristate has joined #zig
return0e has quit [Ping timeout: 272 seconds]
return0e has joined #zig
jjido has joined #zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Flaminator has joined #zig
kristate_ has joined #zig
kristate_ has quit [Remote host closed the connection]
kristate has quit [Read error: Connection reset by peer]
kristate has joined #zig
kristate_ has joined #zig
kristate has quit [Ping timeout: 245 seconds]
kristate_ has quit [Ping timeout: 252 seconds]
wink_ has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
wink_ has joined #zig
man213 has joined #zig
halosghost has joined #zig
mouldysammich has quit [Quit: WeeChat 1.9.1]
dewf has quit [Quit: Leaving]
man213 has quit [Ping timeout: 256 seconds]
<andrewrk> tgschultz, what's the expected behavior for std.meta.fields for `anyerror`? I'm in the middle of fixing https://github.com/ziglang/zig/issues/1936
darithorn has joined #zig
<tgschultz> that's a good question andrewrk. It can't very well be a an array of every possible usize can it...
<andrewrk> I made it a compile error for now
<tgschultz> so TypeInfo.ErrorSet.errors is now `?[]Error`? That was going to be something I'd suggest. I really can't think of a better way off hand.
<andrewrk> yes
<tgschultz> ok, looking at it I think meta.fields shouldn't even be enumerating errors like that, but that's something we can work out later.
<andrewrk> ok
<tgschultz> for one I think I'm using that behavior in a meta function I added for the interface PR: std.meta.isErrSubset, which verifies that one errorset is a subset of another for pre-type-erasure checking.
<andrewrk> that sounds like something that is caught up in the bigger design question of how to deal with error sets and interfaces at the same time
<andrewrk> I think the language (as opposed to userland) might want to get involved in that
<andrewrk> it would be a real shame to generate multiple versions of functions if the only thing different is the error set, since under the hood it's all just the same integer type
<andrewrk> if the userland code does reflection on the error set though, then that would make this not possible, since the logic could change depending on the error set type
Ichorio has joined #zig
<mikdusan> given `const items = []i32 { 4, 5, 3, 4, 0 };` is this sugar supposed to work? `for (items) |*value| {}` gives me `expected type '*i32', found '*const i32’`
<tgschultz> you don't need the *value, just |value| for const.
<tgschultz> |*value| means "I intend to mutate this". Just like it does with function calls: fn(a: MyStruct) vs fn(a: *MyStruct).
kotto has quit [Quit: WeeChat 2.1]
vramana has joined #zig
<mikdusan> this did the trick for me. sliced it. i need as ref because my items are heavy —> for (items[0..]) |*ref| {}
<andrewrk> mikdusan, it's a ref either way
<andrewrk> same as function parameters
<andrewrk> well it's not guaranteed to be a ref. zig is allowed to do it either way depending what's more efficient
<tgschultz> wait, you were able to slice a const and the slice members weren't considered const?
<andrewrk> without the * they look like function parameters - immutable but could secretly be const references
Akuli has joined #zig
<andrewrk> at least after no-copy semantics changes, doing * in a for/switch for performance reasons will be an anti pattern - it actually would reduce the optimizer's options
<tgschultz> yeah, but correct me if I'm wrong here: `const items = []i32 { .. };``items[0] = 10; //error` `(items[0..])[0] = 10; //also error`? so `for (items[0..]) |*ref|` should result in the same error as `for(items) |*ref|`?
<andrewrk> tgschultz, in your example, the for loops are identical, the type of ref in both cases is *const i32
<andrewrk> you can't get a mutable pointer/slice from a const pointer/slice
<andrewrk> without going through something like @ptrToInt and back
<Akuli> why to use a const pointer to i32, in any case? how would that be different from just an i32?
<Akuli> on a 64-bit system, the const pointer takes up more space on the stack as the i32?
<Akuli> s/as/than/
<andrewrk> if you wanted to be guaranteed to get the address of the element in the array
<Akuli> then why not just: for (array) |val, i| { ... }
<Akuli> hmm that takes up more stack space again
<andrewrk> it's not really about stack space
<Akuli> 4 bytes more, lel
<andrewrk> the main use case for |*value| is as tgschultz said - when you want to mutate it
<Akuli> but if it's a const pointer
<andrewrk> right. you probably want |value| instead in that case
<Akuli> :D ok
wilsonk has quit []
<Akuli> zig doesn't find a library that is in /lib (NOT /usr/lib), is this intended?
<andrewrk> is that a directory it should look in?
<Akuli> curses is installed there
<andrewrk> what distro is that?
<Akuli> devuan, based on debian
<andrewrk> are you interested in making a PR adding that dir? https://github.com/ziglang/zig/blob/master/std/build.zig#L375-L382
<Akuli> not right now, maybe later
<andrewrk> I think it would be reasonable to look in /lib/<triple> for linkSystemLibrary
<Akuli> hmm actually its in /lib/x86_64-linux-gnu
<Akuli> let me pull request this thing
<Akuli> what does line 365 do? if (is_nixos) return;
<Akuli> does "nixos" mean "unix-like operating system"?
<andrewrk> ah I see how that could be confusing. nixos is a distro that is handled separately because it has environment variables that explicitly list the lib dirs
<Akuli> ok
<andrewrk> Akuli, try to figure out what the order should be too. I'm sure it's defined somewhere
<andrewrk> e.g. should it be before or after /usr/lib in the search paths
Zaab1t has joined #zig
man213 has joined #zig
<Akuli> from my ld(1): "The linker uses the following search paths to locate required shared libraries: ... 7. The default directories, normally /lib and /usr/lib."
<Akuli> very useful
<andrewrk> maybe if you compile with -v or something it will print the linker command line
<Akuli> this prints some stuff: $ ld --verbose | grep SEARCH_DIR
<andrewrk> that's probably the answer
<andrewrk> can I see what that is for devuan?
<Akuli> SEARCH_DIR("=/usr/local/lib/x86_64-linux-gnu"); SEARCH_DIR("=/lib/x86_64-linux-gnu"); SEARCH_DIR("=/usr/lib/x86_64-linux-gnu"); SEARCH_DIR("=/usr/local/lib64"); SEARCH_DIR("=/lib64"); SEARCH_DIR("=/usr/lib64"); SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib"); SEARCH_DIR("=/usr/x86_64-linux-gnu/lib64"); SEARCH_DIR("=/usr/x86_64-linux-gnu/lib");
<Akuli> i would guess that /usr/local is first because that's where stuff installed from source go by default
<Akuli> and people would probably want to prefer that over whatever is in apt, if they have compiled the lib from source
<andrewrk> yeah. weird though that /usr/lib/x86_64-linux-gnu is before /usr/local/lib
<tgschultz> andrewrk, that's what I thought, so I'm confused how merely slicing items in mikdusan's example solved their problem.
<Akuli> :D
<andrewrk> Akuli, ugh, that's so messy. I'm tempted to try to get away with only adding /lib/<triple>
<Akuli> same
<andrewrk> tgschultz, I just tried your example and I got all the expected errors
<tgschultz> well that's good, at least it isn't a bug
<Akuli> wow pull request 2065
<Akuli> that's a lot of pull requests done in the past
<andrewrk> thanks Akuli - merged
<mikdusan> next time i’ll read the docs about pass-by-value parameters. i made grief for myself assuming a problem existed that Zig makes go away.
<andrewrk> after no-copy semantics work is done, this will be true: "Zig does no memory copying on your behalf. You can see where memory copying happens by looking for the assignment operator (`=`)."
jjido has joined #zig
wootehfoot has joined #zig
<Akuli> how do i check if a c pointer is null, and return an error if it is?
<andrewrk> if (ptr == c.NULL) return error.Foo;
<tgschultz> `if(c_pointer == null) return error.MyError;` or `const x = c_pointer orelse return error.MyError;`
<tgschultz> oh c.NULL
<tgschultz> right
<tgschultz> I suppose that means my second example doesn't work either.
<andrewrk> tgschultz, your examples will work if https://github.com/ziglang/zig/issues/1967 is implemented
<andrewrk> which I think is probably a good idea to do
DutchGh0st has joined #zig
<DutchGh0st> how do you pointer arithmatic on a pointer to a Zero Sized Type?
<DutchGh0st> like [*] void for example
<andrewrk> DutchGh0st, you can't, such pointers don't have an associated address
<tgschultz> I would agree. At least I can't think of a good reason not to do it.
<DutchGh0st> so how do you Iterate over a [N]void array then?
<DutchGh0st> how does the compiler do it? xD
<tgschultz> `for(array) |empty, i|` should work, no?
<DutchGh0st> it does
<tgschultz> as I recal that was Hejsil's clever way of implementing for over ranges.
<andrewrk> I guess pointer arithmetic for [*]void could just all be no-ops
<DutchGh0st> mh, so you can't convert the [*]void to [*]u8, ?
Ichorio has quit [Read error: Connection reset by peer]
<andrewrk> correct. perhaps you intended instead to use @OpaqueType ?
<tgschultz> if you're intending to do that, you probably want [*]c_void or [*]OpaqueType()?
<andrewrk> tgschultz, I wonder if we should rename c_void to `anyopaque`
<DutchGh0st> I checked how Rust handles ZST's on their Iterators for slice's, they convert the pointer to bytes, add the length of the slice, and on each iteration, decrement the end ptr , untill it equals the start ptr again
<andrewrk> I think daurnimator pointed out some issues related to this
<tgschultz> andrewrk, I wouldn't be opposed to it.
<andrewrk> I'll open a proposal
<andrewrk> I can't remember any non-C use cases off the top of my head but I remember there are some
<DutchGh0st> well, guess my ArrayVec can't support zst's then
<DutchGh0st> okey :3
<andrewrk> DutchGh0st, I think pointer arithmetic on [*]void can work, it will just all be no-ops
Ichorio has joined #zig
<andrewrk> can you file an issue?
<DutchGh0st> me?..
<tgschultz> well, I guess that isn't a very new idea.
<DutchGh0st> how do you get the offset of 2 [*] T's ?
Ichorio has quit [Read error: Connection reset by peer]
Ichorio has joined #zig
man213 has quit [Ping timeout: 256 seconds]
<andrewrk> you mean if they're in an array next to each other? @sizeOf
<DutchGh0st> noo
<DutchGh0st> but I have 2 [*] T's
<DutchGh0st> and I want to turn it into a []T, which should be possible
man213 has joined #zig
Akuli has quit [Quit: Leaving]
<andrewrk> that would only make sense if they were in an array next to each other
<DutchGh0st> https://pastebin.com/6cLzSMTs, in the build_iter() as_slice() method
Zaab1t has quit [Quit: bye bye friends]
<DutchGh0st> anyway, here's quite some implementation of an arrayvec, let me know what you think of it! :) https://github.com/DutchGhost/ArrayVec/blob/master/src/main.zig
<jjido> iter.next() returns a pointer?
<DutchGh0st> yeah
<DutchGh0st> I still have to write the draining Iterator, which would return the `owned` items
<DutchGh0st> notice that build_iter() is trying to return a type who's next method either returns *const .., or *..., its pointless to write 2 exactly the same structs where only the mutability is different
man213 has quit [Ping timeout: 256 seconds]
man213 has joined #zig
<andrewrk> stream starting https://www.twitch.tv/andrewrok/
wootehfoot has quit [Read error: Connection reset by peer]
DutchGh0st has quit [Quit: http://www.kiwiirc.com/ - A hand crafted IRC client]
halosghost has quit [Quit: WeeChat 2.4]
Ichorio has quit [Ping timeout: 255 seconds]
marmotini_ has joined #zig
<vramana> error: expected type '[]u8', found '[5]u8'add_symbol("tests", 0);
<vramana> error: expected type '[]u8', found '[5]u8'
<vramana> add_symbol("tests", 0);
<vramana> This is the error I am getting pass a string to a function. How can I fix this?
<vramana> chaning function signature from []u8 to []const u8 seems to have fixed the error.
man213 has quit [Ping timeout: 256 seconds]
Thalheim has quit [Quit: Lost terminal]
fsateler has quit [Ping timeout: 244 seconds]
Thalheim has joined #zig
marmotini_ has quit [Ping timeout: 250 seconds]
fsateler has joined #zig
Thalheim has quit [Remote host closed the connection]
Thalheim has joined #zig
Guest68277 has joined #zig
<andrewrk> vramana, string literals are stored in read-only static memory
<vramana> andrewrk: Okay. Thanks!
<andrewrk> GeneralPurposeDebugAllocator is coming along. I think it's going to be pretty useful
<vramana> andrewrk: I have been following zig for sometime. I wanted to learn how to write parsers for quite sometime. I was thinking of doing it in C++. But remembered that Zig is an alternative. So, I am trying it out today. I wish standard library functions are bit more discoverable with some documentation but it's just a minor annoyance.
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]