ChanServ changed the topic of #zig to: zig programming language | ziglang.org | be excellent to each other | channel logs: https://irclog.whitequark.org/zig/
<hryx> I just tried to compile something with `zig build-exe` and got "unreachable" and SIGABRT. Is that an internal compiler error I should report somehow?
<MajorLag> compiler asserts are always bugs, but are you sure it wasn't an unreachable in comptime code? Issues can be reported github: https://github.com/zig-lang/zig/issues
<hryx> I have no expressions with the `comptime` keyword, but I'm not sure
<andrewrk> I think it's a bug
<MajorLag> the standard library does, but if you ran into one it's probably still a big
<MajorLag> *bug
<andrewrk> zig_unreachable() in the c++ code prints "unreachable" and then aborts
<hryx> sounds like what I saw
<hryx> I can open an issue with a link to a gist if that's the best way to report
<andrewrk> that would be appreciated
<hryx> I think I've narrowed it down to a pub fn defined inside an enum type
<hryx> will make an issue shortly
JinShil has joined #zig
<achambe> btw andrewrk https://github.com/openbsd/src/blob/master/sys/kern/syscalls.master - parsing that file gives most of the needed syscalls, I think only a few differ from linux
<achambe> actually wait, theres a better file somewhere
<andrewrk> nice
<achambe> convincing openbsd people to use zig might be a challenge - just sell bounds checking as a new mitigation :D
<andrewrk> ha!
<andrewrk> does openbsd have a stable syscall interface?
<andrewrk> as opposed to darwin where we have to make calls through libSystem
<achambe> stablish
<andrewrk> so we could cross compile static binaries
<achambe> that works
<achambe> they just don't guarantee stability for every 6 month release.
<achambe> even though in practice go went 18 months with no problems
<andrewrk> hmmm, that's much shorter turnover compared to linux
<andrewrk> is libc the recommended syscall API?
<achambe> not sure tbh. I know they actually prefer people to use the system allocator though
<achambe> because it has randomisation and other system wide settings
<andrewrk> and that is exposed through libc?
<achambe> yeah
<achambe> just malloc or w.e.
<achambe> but doing syscalls yourself works
<achambe> its what myrddin is doing currently
<andrewrk> MajorLag, for #931 are you providing --libc-lib-dir?
<MajorLag> I think I did try that, one sec
<GitHub29> [zig] andrewrk pushed 1 new commit to master: https://git.io/vpOD9
<GitHub29> zig/master 1c41f1c Andrew Kelley: better error reporting for missing libc on windows...
<andrewrk> let me know if that doesn't solve the problem
<MajorLag> I don't think it will, but I'll give it a try when it finishes building. Here's my commandline: zig build-exe test.zig --msvc-lib-dir E:\Experimental\VC\BuildTools\lib\x64\ --kernel32-lib-dir E:\Experimental\VC\BuildTools\umlib\x64\ --libc-lib-dir E:\Experimental\VC\BuildTools\ucrtlib\x64\ && test.exe
<MajorLag> process monitor appears to confirm that all libraries were found, but it still exits 1
<andrewrk> I'll try running this on windows
<MajorLag> looks like it writes the object files just before exiting.
<andrewrk> no error message?
<MajorLag> nope
<MajorLag> my only clue that it fails is not running the exe after
<MajorLag> checking errorlevel confirms it exits 1
<hryx> Here are those compiler issues (I actually stumbled on a compiler segfault as well):
<andrewrk> thanks!
<hryx> noo proob!
<andrewrk> hryx, ah, one more thing -
<andrewrk> once you are hitting compile errors, and you want to get some fixes, you're going to need the latest code
<andrewrk> there have already been a lot of bug fixes since 0.2.0
<MajorLag> return switch (*self.x) {
<hryx> Good call -- luckily I had no problem compiling Zig on linux so I can use that going forward
<andrewrk> you can also use the CI builds of master branch for linux and windows, but sadly we don't have them available for macos yet
<hryx> I tried looking for the CI artifacts before but totally failed. Where would I find them?
<hryx> @MajorLag if I understand, my code would be invalid anyway (dereferencing something which is not a pointer in the line you posted) but I assume the compiler should error instead of crash
<hryx> Wonderful, thanks for the links
<MajorLag> You're correct, it should. I thought for a minute you were misinterpreting a program segfault as a compiler issue, but I can confirm it does crash the compiler
<hryx> Cool cool. Related, if I remove the * the compiler complains: "error: unable to infer expression type"
<hryx> pointing to the `switch` keyword
<hryx> Curious what I'm doing wrong there
<andrewrk> there's an issue for this somewhere. fix it by casting one of the values to a type
<hryx> Ok, great
<GitHub109> [zig] andrewrk pushed 1 new commit to master: https://git.io/vpOyc
<GitHub109> zig/master 25dff91 Andrew Kelley: fix windows build broken by previous commit...
<andrewrk> MajorLag, I'm trying to reproduce your issue
<MajorLag> sorry I can't make it easier. You'd need to not have VS installed as far as I can tell.
<andrewrk> I think get_windows_sdk is succeeding for you
<andrewrk> when it should be failing because sdk->version10.length is 0
<MajorLag> when I pass it all the paths, it doesn't look like it's looking for the SDK registry entries, which is what I'd expect.
<andrewrk> it's also looking for --libc-include-dir and not finding it, and so then calling get_windows_sdk, which is succeeding, but then version10.len is 0
<MajorLag> providing --libc-include-dir doesn't seem to change anything in process monitor
<andrewrk> it exits with -1 status?
<MajorLag> it exists with 1, yeah
<MajorLag> zig build-exe test.zig --msvc-lib-dir E:\Experimental\VC\BuildTools\lib\x64\ --kernel32-lib-dir E:\Experimental\VC\BuildTools\umlib\x64\ --libc-lib-dir E:\Experimental\VC\BuildTools\ucrtlib\x64\ --libc-include-dir E:\Experimental\VC\BuildTools\ucrt && test.exe
<MajorLag> echo %ERRORLEVEL%
<MajorLag> 1
<andrewrk> I get that, but I also get linker errors before that
<MajorLag> I'm not. I've updated to the latest artifact.
<andrewrk> MajorLag, I disabled all the functions in os.cpp that find the paths of things so that they all return ErrorFileNotFound
<andrewrk> and I manually specify all the cli args just like you do above
<MajorLag> huh
<andrewrk> and it works, with %ERRORLEVEL% 0
<MajorLag> is there anything it looks for outside of the SDK?
<andrewrk> the linker error was when I specified VC\Lib instead of VC\Lib\amd64
<andrewrk> my command line: bin\zig.exe build-exe test.zig --library c --libc-include-dir "C:\Program Files (x86)\Windows Kits\10\Include\10.0.10240.0\ucrt" --msvc-lib-dir "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\Lib\amd64" --libc-lib-dir "C:\Program Files (x86)\Windows Kits\10\Lib\10.0.10240.0\ucrt\x64" --kernel32-lib-dir "C:\Program Files (x86)\Windows Kits\8.1\Lib\winv6.3\um\x64"
<MajorLag> oh, interesting.
<MajorLag> I didn't have --library c
<MajorLag> adding it produces some dll errors, but that's reasonable.
<MajorLag> and those errors are from running the exe, so that makes sense
<GitHub78> [zig] andrewrk pushed 1 new commit to master: https://git.io/vpOSs
<GitHub78> zig/master 75328e3 Andrew Kelley: exit(1) instead of abort() for file not found
<MajorLag> and the dll errors are for missing debug dlls, so --release-fast produces a working exe. Thanks andrewrk.
<andrewrk> np
hryx has left #zig [#zig]
Braedon has joined #zig
<Braedon> How do you check if a float is infinity?
<Braedon> In zig that is
<Braedon> Found it haha xD
cenomla has joined #zig
hryx has joined #zig
<achambe> andrewrk: one of the problems when your language isn't self hosted, you spend all your time working in C++
<achambe> the problem when your language is self hosted, you spend all your time making it nicer for writing compilers by accident :P
Braedon has quit [Ping timeout: 260 seconds]
<achambe> I'm super curious how a zig lua bindings set, and a zig sqlite bindings set would look
<achambe> e.g. if comptime reflection would let you generate a binding
<achambe> etc
relatingdata has joined #zig
<GitHub124> [zig] andrewrk pushed 1 new commit to master: https://git.io/vpOQr
<GitHub124> zig/master 8503eff Andrew Kelley: add compile error for invalid deref on switch target...
<andrewrk> hryx, sorry about the compiler bug. fixed now ^
<MajorLag> speaking of bugs
<andrewrk> yes, MajorLag?
<hryx> nice fast fix andrewrk! Finally, I can continue to dereference things which aren't pointers in peace
<andrewrk> haha
<MajorLag> Sorry, taking longer to type up the issue than I thought it would.
<MajorLag> #948
<andrewrk> I'm gonna save this for a weekday evening and try to make some more progress on concurrency and stuff
cenomla has quit [Quit: cenomla]
<MajorLag> ok. I'm going to go to bed and try real hard to stay awake at work tomorrow.
<andrewrk> I'm with you on that
cenomla has joined #zig
cenomla has quit [Client Quit]
cenomla has joined #zig
<MajorLag> fyi: occurs using << operator too, not just the intrinsic.
<MajorLag> for instance: `var x: u64 = ~u64(0) << 16` produces an undefined result.
<MajorLag> but separate it into two lines and it works.
<andrewrk> I figured out why writing a lock-free doubly linked list is hard
<andrewrk> because it's not a solved problem yet
<andrewrk> I don't think there are even any research papers that do it
cenomla has quit [Quit: cenomla]
qazo has quit [Ping timeout: 240 seconds]
<relatingdata> there was a major improvement to atomic locking that was talked about at the brisbane sunday coders club I think its was william from redhat, but my memory might not be quiet accurate!
<andrewrk> I found the paper by Maged Michael
relatingdata has quit [Quit: Page closed]
tiehuis has joined #zig
<andrewrk> ugh, this paper wants you to stuff 2 usizes and a u2 into a usize
<andrewrk> this doesn't solve the problem at all
<tiehuis> pretty sure i've solved all the float printing issues in release modes now
<andrewrk> wow
<tiehuis> just needed a single float-mode change in hpNormalize in errol
<andrewrk> I have a windows laptop in front of me, want me to look into the appveyor failure?
<andrewrk> or was that it?
<tiehuis> that'd be helpful, thanks
<tiehuis> i was in the middle of setting up a windows vm but build tools are slow to install
<tiehuis> i believe the issue is different for the windows failure, but may as well wait for appveyor to finish this current build to confirm
<andrewrk> oh wow it's in compiler-rt
<andrewrk> line 45 of udivmod.zig
<tiehuis> that is unexpected
<andrewrk> from line 325 of errol/index.zig
<andrewrk> const lf = u64((low / pow19...
<andrewrk> val is 1.5231400000000000e+29
<andrewrk> which is one of the test cases
<andrewrk> looking at this compiler-rt code, it's quite puzzling, because we're in an if statement that checked that d[low] == 0, and then we divide by it - so it's like we know we're dividing by zero ? weird
<andrewrk> let me double check compiler-rt from llvm
<andrewrk> yeah, same thing
<tiehuis> looks seemingly impossible to hit that
<tiehuis> DoubleInt
<andrewrk> it's because the errol code does a u128 divided by a u128
<andrewrk> let me make sure u128(1e19) is working
<andrewrk> yeah that part is fine
tiehuis has quit [Quit: WeeChat 2.1]
<GitHub168> [zig] andrewchambers closed pull request #941: Openbsd ci (master...openbsd_ci) https://git.io/vpOLf
relatingdata has joined #zig
relatingdata has quit [Quit: Page closed]
davr0s has joined #zig
qazo has joined #zig
JinShil has quit [Quit: Leaving]
qazo has quit [Ping timeout: 240 seconds]
qazo has joined #zig
Braedon has joined #zig
<Braedon> Wow I just found an inverse square algorithm that has an accuracy of 7.023769248702945e-10. For the record doom has 1.886557159257603e-6 for the same set of numbers
<Braedon> And it only runs 8% slower
xkern has joined #zig
qazo has quit [Ping timeout: 264 seconds]
Braedon has quit [Ping timeout: 260 seconds]
qazo has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
qazo has quit [Read error: Connection reset by peer]
<alexnask> Thank god for translate-c :P
xkern has quit [Quit: Leaving.]
noonien has joined #zig
davr0s has joined #zig
return0e has joined #zig
xkern has joined #zig
xkern has quit [Quit: Leaving.]
cenomla has joined #zig
steveno_ has joined #zig
cenomla has quit [Quit: cenomla]
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
Dodo has joined #zig
<Dodo> is this a good implementation of a 'Once' Iterator, 'Repeat' Iterator, and a 'Take' Iterator? https://github.com/DutchGhost/Zigerator/blob/master/src/main.zig#L26
<Dodo> where Once will only..iterate once, Repeat repeats forever, and Take takes the first n items
btbytes has joined #zig
<alexnask> @Dodo, Once looks ok, although you could have a consumed: bool + item: T instead of an item: ?T if you want to be able to make it resetable at some point
<alexnask> Take looks good
<alexnask> I don't see why repeat stores item as ?T instead of T
<alexnask> But apart from that, looks fine
<Dodo> oh, uhm
<Dodo> let me fix that
<Dodo> mh, what function should be nice to have as well?
<Dodo> skip() and nth() maybe
<Dodo> nth(n) is actually just skip(n).next()
<Dodo> and fold() ...
Dodo has quit [Quit: Page closed]
steveno_ has quit [Ping timeout: 265 seconds]
<GitHub175> [zig] andrewrk pushed 1 new commit to master: https://git.io/vp3j9
<GitHub175> zig/master 89a4c37 Andrew Kelley: fix bigint twos complement implementation...
steveno_ has joined #zig
davr0s has joined #zig
Dodo has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<Dodo> alexnask, look, chaining Iterators kind of works now: https://github.com/DutchGhost/Zigerator/blob/master/src/main.zig#L434
<Dodo> which is nice :)
<Dodo> plus, if you now make you're own Iterator, you should be able to call all those functions
<alexnask> Right, I thought of doing it that way the other day we were discussing about it but I wanted to directly return the &Iterator (which is not possible)
<alexnask> This is fine though, you just get the .it field when needed :)
<Dodo> yeah hahaha
<alexnask> Have you thought about how you are going to handle bidirectional iterators btw?
<Dodo> bidirectional?
<Dodo> mhh
<Dodo> maybe another function just like .next()
<Dodo> but .next_back()
<Dodo> and have a .rev() function on Iterator or something?
<Dodo> or have a similar idea like Iterator, but then with DoubleEnded Iterator,
<alexnask> Right, you could have an optional prevFn etc.
davr0s has joined #zig
<Dodo> and have all structs have another field, .it_rev maybe?
<alexnask> I think that's cleaner
<Dodo> but omg how large is the file going to be?
<alexnask> Evvey double ended/bidirectional iterator is an iterator though
<Dodo> yeahhh
<Dodo> do we have some kind of inheritance?
<alexnask> Nope, zig just has plain structs
<alexnask> You can fake it like we faked interfaces
<alexnask> So I think you could do some thing where all iterators that are bidirectional only have a bidirectional iterator field
<alexnask> But that field can either be casted directly to an Iterator or have a method that turns it into an Iterator
<Dodo> mhh
<alexnask> Basically, if you have a 'const A = struct { field1: usize};'
<alexnask> and 'const B = struct { field1: usize, field2: []u8, };
<alexnask> Every &B can be turned into an &A
<andrewrk> not true
<andrewrk> you'll need to have A be a field of B or vice versa
<alexnask> really?
<alexnask> Sure, I was going to say it's better to be explicit
<andrewrk> zig reserves the right to re-order struct fields
<alexnask> Aaah, right
<andrewrk> and add secret fields for debugging purposes
<andrewrk> I'm planning on having debug mode purposefully re-order fields so that one does not accidentally rely on this behavior
<Dodo> can we enforce that a type has a method at compile time?
<alexnask> Yes, I can see how C people would fall into that
<alexnask> @Dodo I don't think so
<andrewrk> Dodo, you can call it. if it doesn't exist, you'll get a compile error
<andrewrk> it's planned for @reflect to tell you about member functions of structs
<andrewrk> that's not implemented yet
<Dodo> so in Iterator, there is this function 'next_fn' , and on each struct we say something like ' .it = Iter {.next_fn = next}'
<alexnask> @andrewrk I was actually about to get started on @reflect
<andrewrk> oh neat
<Dodo> what if we also add a 'next_back_fn',
<alexnask> Although I guess it's going to take me a long time to finish
<Dodo> does that have to be filled in for all types that have an Iter field?
<alexnask> (Or rather, the @reify part)
<Dodo> or can you just leave it empty?
<alexnask> You can make it nullable
<alexnask> And fill it in with null in structs that don't provide it
<alexnask> But
<Dodo> but that costs something at runtime?..
<alexnask> I would suggest you make a new DoubleEndedIterator
<alexnask> That has an Iterator field
<alexnask> + the extra fn pointers
<alexnask> @Dodo No, its zero cost
<Dodo> mh yeah
<alexnask> Because a fn is a pointer
<Dodo> well, here we go :3
<andrewrk> here's an example of one way to do something similar: https://github.com/zig-lang/zig/blob/master/std/zig/ast.zig
<Dodo> I should make this into 2 files
<Dodo> actually 3, one for Iterator, one for DoubleEndedIterator, and one for main
<alexnask> @andrewrk Does LLVM actually shuffle struct fields in practice or do you plan on adding optimizations in the zig IR?
<alexnask> I mean, optimizations that rely on rearranging the field order
cenomla has joined #zig
<alexnask> @Dodo You can also use test blocks instead of a main function if you the package is intended to be a library :)
<Dodo> mh yeah
<andrewrk> LLVM supports packed and C ABI for structs. so zig would be doing something on top of that
<Dodo> how does importhing files work?
<alexnask> Ok, good to know, I've never targetted LLVM before, I usually just dump C :P
<Dodo> becouse DoubleEndedIterator needs Iterator, but some structs in Iterator.zig also need DoubleEndedIterator
<Dodo> *importing
<alexnask> I don't think cyclical imports are an issue but I could be wrong
<andrewrk> top level declarations are order independent and we have lazy evaluation
<Dodo> how do I import everything from a file?
<andrewrk> so we have deterministic builds, and as long as there is no actual circular dependency, such as a struct embedded in itself, everything is fine
<alexnask> const namespace = @import("some_relative_file.zig");
<Dodo> but then all the functions and structs must be prefixed with 'namespace' ?
Ichorio has joined #zig
<alexnask> Or you can 'use @import("...")'
<andrewrk> correct
btbytes has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
btbytes has joined #zig
<andrewrk> consider that what would previously be your "namespace" in C, you can make an actual namespace in zig. so for example if you're opengl, and all your functions are prefixed with gl, such as glSwapBuffer
<andrewrk> const gl = @import("gl.zig"); gl.swapBuffer()
<Dodo> can you also import ALL things ?
<Dodo> so you just could call swapBuffer() for example?
<andrewrk> yes, with alexnask's example above
<andrewrk> this comes with an inherent penalty on compilation speed, and the code reader's ability to discover where a symbol comes from
<andrewrk> code reader being a human
<Dodo> so in main.zig I would say 'use @import("Iterator.zig");' ?
<alexnask> Yup, then all pub symbols are available in the global namespace
<alexnask> Or w/e we're supposed to call it
<Dodo> all pub symbols
<Dodo> guess I didn't make them public...
<alexnask> Time to copy paste a bunch of "pub" :P
<andrewrk> :%s/^fn\>/pub /g
<andrewrk> done
<Dodo> do returned structs also need to be pub?
<alexnask> you mean as in 'pub fn foo() type { return struct { ... }; }'
<alexnask> You only need to pub any fn or variable you want to expose through @import
<alexnask> The pub is not an attribute of the struct, it's just the visibility of the symbol
<Dodo> oh yeah
<Dodo> wohoo it builds again
<alexnask> :D
<Dodo> mh, DoubleEndedIterator can have a field like this 'const Self = Iterator(T)', right?
<alexnask> sure, using 'Self' is pretty misleading though, I would expect Self == DoubleEndedIterator(T)
<Dodo> fair enough
jjido has joined #zig
<Dodo> okey this is verry verbose assert(zipped.next() == Tuple(usize, usize) {.t1 = 6, .t2 = 0})
<Dodo> build-in tuples would be greate ^^
jjido has quit [Client Quit]
jjido has joined #zig
cenomla has quit [Quit: cenomla]
<andrewrk> I've decided on removing var args and adding built in tuples
<Dodo> \o/
<Dodo> how do I assert on something that is ?T, to test if it's some value?
<SimonNa> Instead of templated functions with variable arguments, one would then have one compile-time type variable that can then be instantiated with any length and types? That sounds clean then
<Dodo> so like assert(maybe == ?10) or whatever
<andrewrk> SimonNa, the length and types would be compile time known and the values of each thing would be runtime known
<andrewrk> std.debug.warn("int: {} string: {}\n", [an_int, a_string]);
<SimonNa> yeah, I assume it would instantiate a function for every different tuple
<SimonNa> surely, in each instantiated function, the exact type of the tuple is then known (number of entries, fixed type for each entry)
<alexnask> Yes
<alexnask> All this is known with varargs atm too
<alexnask> @andrewrk Would you be opposed with @reflect being renamed to @typeInfo?
<andrewrk> alexnask, sounds fine to me. at the end of the day the name of the function is trivial to change and independent from the hard problem of implementing it
<alexnask> Good, @typeInfo it is, I think it's clearer than @reflect, @reflect sounds like it should work on any definition
<MajorLag> oh good, you've already fixed the comtime shifting bug. that'll save me a bit of hassle.
<andrewrk> MajorLag, trying to stay awake at work @_@
<Dodo> error: no member named 'next_back' in struct 'Iterator(usize)'
<Dodo> ugh, guess my current idea doesnt quite work
<andrewrk> Dodo, the use case you're working on sounds interesting, but I think there are a few other use cases I'm focusing on first in the roadmap
<andrewrk> so you might be working against the grain a little bit
<Dodo> ah yeah
<Dodo> well, I'm really not familiar with Zig yet, and this seemed a challenging thing to do
<andrewrk> you know? like maybe we go ahead and support some kind of trait or interface in 0.4.0, and then what you're doing has a clear answer
<Dodo> so Im trying to understand how it all works and such
<andrewrk> fair enough
<Dodo> and I've never implemented Iterators from scratch, so that's also something I wanted to do
<Dodo> but trait/interface like support would be really cool!
<andrewrk> yeah. I just want to make sure that it does not overcomplicated the language
<andrewrk> simplicity is kinda the only thing we have going vs rust
<Dodo> in a way interfaces could make things easier, also for things like equality testing
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
steveno_ has quit [Remote host closed the connection]
<MajorLag> One thing about doing interfaces the way zig does now: it is obvious how it works. I think I like that more than I dislike the extra verbosity.
<alexnask> The idiomatic way to make interfaces requires that the definition of the implementation type includes a field of the interface type
<alexnask> This is a downside imho, but it can be worked around as is (with some more metaprogramming)
<alexnask> (Basically, the interface here is a pair of pointers, one to the implementation object and one to a automatically comptime-generated vtable)
<Dodo> but here's the thing, handwritten vtables and metaprogramming might be more clear,
<Dodo> but it's also hard if you've never done it, like me
<alexnask> I know, I'm not saying people should be doing it as is :P
<alexnask> Ideally, you would just have a vtable_gen call that generates a vtable from the description (tuples of name, function type)
<alexnask> Then your interface type is a pointer to that vtable type
<alexnask> + whatever way you chose to store your objects (or just a pointer)
<alexnask> That way of doing this allows you both to write new types with no interface field that work seamlessly with existing interfaces
<alexnask> And to write new interfaces that work seamlessly with existing types
<Dodo> but doing it by hand maybe makes you think more on how to do things, so thats a good thing I guess?
<alexnask> Sure, you still write your interface by hand, you just let the compiler make a vtable for every type of object that uses your interface ;)
<alexnask> Anyway, it's a design decision for sure, I'm just saying the way I've seen interfaces defined in zig is not unique and you can actually get some extra advantages doing it other ways
<Dodo> https://github.com/DutchGhost/Zigerator/blob/master/src/Iterator.zig#L49 <-- would that imply that a DoubleEndedIterator is also an Iterator?
<MajorLag> Well, let's lay out the issues we're trying to solve in the current implemetnation. From my perspective, the only one that's been an issue is that sometimes I make a copy of an interface instead of taking a pointer to it. In my own code I now prefix interface members with _ and have a interfaceName() fn return a pointer to it. I suppose having to name the interface component when passing it could also be counted as an issue, but I don't th
<MajorLag> nk it is a big one: `square_actor.actor().addAction(repeat_action.action());`. What else?
<alexnask> you should probably do 'const Iter = Iterator(T);' then define an 'it: Iter,' field
<alexnask> @MajorLag Well for one implementing your interfaces this way would completely remove the need to grab a field from your implementation type
<alexnask> Instead, you would initialize an interface object with 'Interface.init(whatever_value_implements_my_interface)'
<MajorLag> Implementing them what way?
<alexnask> Basically, an interface type would be a pointer to a vtable + whatever storage policy you decide on for your objects
<Dodo> what does this '@reify' (feature??) do?
<alexnask> For example, you could have a small buffer in your interface type and copy objects in there, or store them on the heap if they are bigger than the buffer
<alexnask> In this example, I store a usize I get from @ptrToInt
<alexnask> @Dodo @reify would allow you to describe a type in a struct (constructed at comptime) and get an actual type back
<Dodo> describe a type?
<alexnask> @typeInfo/@reflect (currently writing that) would return that description struct from a type
<MajorLag> I don't really see how `Iterator(usize).from(iter)` is better than `iter.iterator()` or even the current standard `iter.iterator` though.
<alexnask> @Dodo take a look at that issue, it explains it pretty well
<alexnask> @MajorLag it's not about the syntax, the key point is that the implementation type is completely detached from the interface
<alexnask> RepeatIterator(T) does not need to know about Iterator(T)
<alexnask> You could take a package written by another person that provides a struct with a 'fn next() usize'
<alexnask> And that struct could be passed to Iterator(usize).init
<alexnask> fn next(&Self) usize **
<Dodo> one thing I wondered is, keeping a 'it: Iterator(sometype)' is some overhead, right?
<alexnask> In every implementation type you mean?
<Dodo> well yeah
<alexnask> Yes, it is some overhead although I wouldn't worry about it
<Dodo> now each struct has to have it
<alexnask> What you could do is store an it: &Iterator(sometype) in every struct
<alexnask> And initialize it with a pointer to a comptime Iterator(sometype)
<alexnask> That should make the compiler generate a vtable in the binary, then you keep the reference to that static vtable at runtime instead of packing the whole vtable in every implementation type
<Dodo> this is somewhat magic to be honestly :3
<alexnask> I'm not 100% it would work but you can try it, the change is pretty trevial
<alexnask> every it: Iterator(...) becomes it: &Iterator(...)
<alexnask> and every .it = Iterator(...) { ... } becomes .it = &comptime Iterator(...) { ... }
<alexnask> even better, it: &const Iterator(...)
<alexnask> @Dodo This is basically what C++ does for virtual methods
<Dodo> \Zig\itertools\src\main.zig:93:22: error: type '&&const Iterator(usize)' does not support field access <--- changing 'it: Iter' to 'it: &const Iter'
<alexnask> I assume this happens someplace you take a pointer to an it field then call a function on it?
<MajorLag> is Iterator() returning a type, as its naming convention suggests?
<alexnask> Yes, it returns a vtable type in Dodo's case
<Dodo> var once = &Once(usize).init(10).it; <-- thats where I create it
<MajorLag> You can't take a pointer to a type. What you end up with is a type that is a pointer to the type. `const Type = usize; const PType = &Type;` => &Type == &usize
<alexnask> it is of type '&const Iterator(usize)'
<alexnask> Woops
<MajorLag> This ambiguity is one of the things meant to be addressed in pointer reform
<alexnask> @MajorLag That's what I was trying to do with my suggestion, &const Iterator(usize) is supposed to be "const pointer to the iterator(usize) vtable" type
<alexnask> Not a pointer to the iterator(usize) type, if that makes sense
<MajorLag> So you mean for .it to hold a type? Not be an instance of a type?
<alexnask> no, .it is supposed to be an instance of type 'const pointer to Iterator(usize)'
<MajorLag> Makes sense, but you need to point it at an instance then.
<alexnask> Right
<alexnask> Can you not initialize an Iterator(T) at comptime then initialize .it to be a pointer to that?
jjido has joined #zig
<alexnask> Self { .it = &comptime Iterator(T) { .next_fn = next } }
<MajorLag> I think that would work.
<alexnask> Right, that was my suggestiong to Dodo :p
<MajorLag> So maybe I misunderstood what was going on
<alexnask> I think his code broke because he is taking references to .it and calling functions
<alexnask> Although I thought the dot field access worked no matter the level of indirection
<MajorLag> I'm fairly sure just the one.
<alexnask> Well issue solved then, he's missing a dereference somewhere ;)
<alexnask> This part looks fine
<Dodo> so how should I create the 'once' Iterator?
<alexnask> I think the issue is in main.zig line 93, now you have to use (*once).next() which is ugly :/
<alexnask> 'var once = &Once(usize).init(10).it;
<alexnask> ' should work, it's just a &&const Iterator(usize) now
<Dodo> but calling next crashes the whole thing
<Dodo> or should next() take an &const Iterator(T) ?
<alexnask> Iterator(T).next should take self: &const Self
<alexnask> next() should take &const Iter
<alexnask> And I still don't know if it will work after that :p
<alexnask> But I think it should
<Dodo> error: cannot assign to constant
<alexnask> Where from?
<alexnask> Actually this change is a bit more invloved than I thought, you should probably revert
<alexnask> Also, it doesn't make sense since Iterator(...) only has one function
<alexnask> So you aren't actually saving anything (should have though of that in the first place)
<alexnask> If you had 6-7 function pointers in there it would probably make sense
<alexnask> @andrewrk What is a BoundFn?
<MajorLag> I think it is just an fn inside a struct/union/enum namespace
<alexnask> Thanks!
<Dodo> oh Im only defining next(),
<Dodo> things like .map() and .enumerate() dont count?
<alexnask> @Dodo I mean you have one function pointer stored in the Iterator(T)
<alexnask> So the size overhead of an it: Iterator(...) is the same as an it: &Iterator(...)
<alexnask> (1 pointer)
<Dodo> all this trouble hahaha
<alexnask> And you get 1 less indirection so it's actually better :p
<alexnask> Yup my bad
<alexnask> :D
<Dodo> mine as well
<Dodo> anyway, I need to go!
<Dodo> thanks for all the explanation and help! :D
<Dodo> byye, have a good evening!
<alexnask> No problem, have a nice day/evening/whatever time it is in <insert timezone>
<Dodo> The Netherlands,
<Dodo> 22:02 atm
<alexnask> Well, have a good evening then ;)
<Dodo> what zone are you in?
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<alexnask> UTC+2
<alexnask> I live in Greece :)
<Dodo> oh, also evening
<Dodo> have a nice evening!
Dodo has quit [Quit: Page closed]
<andrewrk> alexnask, it's @typeOf(struct_instance.method)
<alexnask> @andrewrk Gotcha, so @typeOf(StructType.method) is Fn right?
<andrewrk> correct
davr0s has joined #zig
return0e has quit [Read error: Connection reset by peer]
btbytes has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
return0e_ has joined #zig
qazo has joined #zig
Ichorio has quit [Ping timeout: 240 seconds]
<GitHub199> [zig] andrewrk pushed 1 new commit to master: https://git.io/vpsiE
<GitHub199> zig/master 15bf0c1 Andrew Kelley: fix interaction between defer and labeled break...
jjido_ has joined #zig
jjido_ has quit [Client Quit]
btbytes has joined #zig
davr0s has quit [Quit: My MacBook Pro has gone to sleep. ZZZzzz…]
<achambe> something I was thinking about, how errdefer vs crashing introduces lots of new untested code paths into code
<achambe> and tactics for making them tested.
<achambe> best I have come up with fault injection and simulations
<achambe> https://www.youtube.com/watch?v=4fFDFbi3toc <- related in terms of "software should be perfect" and how to test those cases.
noonien has quit [Quit: Connection closed for inactivity]
btbytes has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]