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/
<tgschultz> I heard you like PackedIntSlices, so I gave you the ability to slice PackedIntSlices, then I gave you the ability to cast PackedIntSlices to PackedIntSlices of different bit widths. I have no idea if that'll ever be useful.
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jjido has joined #zig
<tgschultz> local CI is running, will make a PR if/when it completes.
<tgschultz> are there any big endian systems in our CI? I ask because there's one half of one test I couldn't verify was correct, though I'm fairly confident it is.
<scientes> I'm getting a ppc64 system up and running right now
<scientes> tgschultz, but no, its just amd64 right now
<scientes> and ppc moved to little-endian because of issues
<scientes> just like arm started supporting unalignemed memory access because of issues
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
<daurnimator> Re: earlier memory trait interface discussion
<daurnimator> I'm starting planning on my general purpose allocator
<daurnimator> I'm finding myself wanting to know what size pages the parent allocator gives....
<daurnimator> If I hard code the assumption that there's only one page size per platform.... that would be wrong
<tgschultz> Why would you wrap another allocator instead of what DirectAllocator does, which is use each system's allocator directly? If you care about specifics like that, it seems like that's what you actually want, otherwise you'll just be making whatever allocator you're wrapping do it instead.
<daurnimator> tgschultz: because I'm trying to code a pooling allocator... that's the whole point
<tgschultz> can you define pooling in this context?
<daurnimator> It's pretty common to want to derive one allocator from another: in a way that you can then alloc *and* free out of the pool; but also free the whole pool at once
<daurnimator> - common in video games to have a per level allocator, that then has a per frame allocator
<daurnimator> - useful in http servers to have a per-request pool
<daurnimator> it's sort of a step up from an "arena" allocator; that can have individual allocations freed.
<tgschultz> ok, but by wrapping another allocator you're really saying "I don't want to know the details", that's kinda the definition of abstraction.
<daurnimator> tgschultz: not exactly
<daurnimator> tgschultz: it would work whether the parent allocator has feature X or not; for some traits, it just gets more expensive/requires extra processing. For other traits, it's a safety feature you miss out on.
<tgschultz> I think what I'd do, is have whoever is using the allocator just tell it what the parent allocator's page size is. If they want to use huge pages they can pass an allocator that uses huge pages and tell your allocator that it uses X sized pages.
<daurnimator> how would a user even know?
<tgschultz> they're the one passing the parent allocator, presumably they know what it does
<daurnimator> and what if the directallocator e.g. used 4k pages for small allocations; 2MB for larger allocations; and 1GB for certain other ones?
<daurnimator> for most allocators, it's an implementation detail what the page size is
<tgschultz> right, so if you care about that then you need to bypass the abstraction
<daurnimator> >.<
<tgschultz> Let me ask you this: if I were to tell your allocator the parent uses 2MB pages, what do you do with that information?
<daurnimator> tgschultz: then I know that trying to mprotect() a guard page after an 16K allocation won't work
<tgschultz> ok, but if you're calling mprotect you've already bypassed the abstraction
<daurnimator> ==> if I knew you did 4K pages, then for a 16K allocation, I might ask for 16+2*4=24K, and mprotect a guard page on either side.
<daurnimator> tgschultz: why/how is that passing the abstraction?
<tgschultz> because that is literally abstracted away by DirectAllocator!
<daurnimator> and I'm saying it shouldn't be! ==> page size should be a part of the Allocator interface!
<tgschultz> I disagree, because the whole point of DirectAllocator is to abstract away implementation details like this. Windows doesn't have mprotect, you'll have to call VirtualProtect instead, so you're already switching on OS. Why not just use VirtualAlloc/mmap directly instead of hiding the implementation details behind DirectAllocator and then trying to recover them?
<daurnimator> because then it wouldn't be a stacking allocator
<tgschultz> Alright, I'm going to pass you FixedBufferAllocator. Now you need to know the page size, and that mprotect doesn't exist for it, and possibly that it also won't actually free.
<tgschultz> I tihnk we're just going to have to agree to disagree on the right way to do this.
<daurnimator> why wouldn't mprotect exist for it??
<daurnimator> mprotect/VirtualProtect exist at the OS level
<tgschultz> what if it is less than a page in size?
<tgschultz> or only occupies part of a page at the beginning or end?
<tgschultz> now you're mprotecting data that doesn't belong to the allocator.
<daurnimator> huh?
<daurnimator> the stacking allocator allocates a page on either size. if the allocation it is fulfilling isn't page sized, then the extra space is padded with undefined
<daurnimator> the idea is to stop people from e.g. accidently running off the end of an array
<tgschultz> unless I'm mistaken, mprotect has page size granularity. If I pass you a FixedBufferAllocator wrapped around an arbitrary amount of bytes on the stack, there will be parts of its page that don't belong to it. If you're saying "you must pass at least 3 pages of memory, aligned on a page boundary" then again I have to ask what the point of allowing stacking on top of arbitrary allocators is.
<daurnimator> `std.mem.len(someptr)` ==> oops theres no null pointer ==> keeps going over undefined, potentially triggering valgrind immediately, but then eventually hits a guard page and the process gets terminated
<daurnimator> s/null pointer/null character/
<tgschultz> Like I said, I think we have to agree to disagree on this one
<daurnimator> on a different allocator topic
<daurnimator> I had the realisation that the Allocator interface is missing an important operation:
<daurnimator> reallocInPlace
<daurnimator> which is: try and grow the current allocation; but don't bother if you can't.
<daurnimator> andrewrk: ^
wootehfoot has quit [Read error: Connection reset by peer]
_whitelogger has joined #zig
* daurnimator needs to fix up linkedlist for work on allocator
<daurnimator> our existing linkedlist is more of a classic tail queue
<daurnimator> IIRC, "list": can be operated on without the "head". "queue" operations are on the head.
<emekankurumeh[m]> with the coroutine rewrite the type erase from promises will no longer be a thing, correct?
<emekankurumeh[m]> so how would one abstract over coroutines, for example, for a task scheduler?
<daurnimator> emekankurumeh[m]: maybe there's something in here for you? https://github.com/ziglang/zig/issues/1778#issuecomment-441351635
jevinskie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
scientes has quit [Ping timeout: 252 seconds]
<daurnimator> what is child_process's .llnode element for? doesn't seem to be accessed anywhere
jevinski_ has joined #zig
shritesh has quit [Quit: shritesh]
reductum has joined #zig
jevinskie has joined #zig
jevinski_ has quit [Ping timeout: 255 seconds]
reductum has quit [Quit: WeeChat 2.4]
<emekankurumeh[m]> zig is occasionally freezing up on me
<emekankurumeh[m]> the process just stops and task manger reports no cpu usage
<daurnimator> emekankurumeh[m]: what does strace say?
<emekankurumeh[m]> occasionally strace won't print anything either
<daurnimator> follow forks?
<emekankurumeh[m]> i'm on windows
<daurnimator> oh
<daurnimator> I'm amazed strace even exists on windows :P
<daurnimator> on windows I think you need to use process explorer? or possibly windbg
<daurnimator> it's been a while since I've even tries
<daurnimator> *tried
return0e has quit [Ping timeout: 246 seconds]
return0e_ has joined #zig
<emekankurumeh[m]> the bug disappears when i try to use gdb :/
<emekankurumeh[m]> unrelated. but is this code doing what i think it is? https://gist.github.com/emekoi/5a96469e46ab02eee31f2dc9018847b4
return0e has joined #zig
return0e_ has quit [Ping timeout: 258 seconds]
<emekankurumeh[m]> edit: can anyone explain to me why ContinuationStealing1 is so much faster than all the rest?
<emekankurumeh[m]> whoops, nevermind it seems doing it in a single thread is much faster than all the rest
<emekankurumeh[m]> but still, why does ContinuationStealing1 run with only 2 threads even though i spawn 4 extras ones?
jjido has joined #zig
<daurnimator> how do I get the exact size of something?
<daurnimator> (not the amount of space it takes up in an array: which is what @sizeOf returns; but the actual number of bytes used to store a single instance)
<daurnimator> also, how do you initialise an array of pointers to 0?
<daurnimator> `*MyType{null} ** len` fails with error: type '*MyType' does not support array initialization
rivten has joined #zig
dch has quit []
dch has joined #zig
strmpnk has quit []
strmpnk has joined #zig
tane has joined #zig
<tane> howdy
<tane> whoever put work into zig, it's awesome, thanks :)
nikki93 has quit []
nikki93 has joined #zig
<daurnimator> tane: andrewrk can take credit for most of it
neceve has joined #zig
<rivten> hello everybody :) quick question : yesterday I wrote some code that loads a dynamic library. By using the dynamic_library.zig std, I was able to dynamically load code on windows ! But the same code on my linux machine fails... From what I could trace, linux.mmap returns MAP_FAILED. Should I file a github issue or something ? i guess the mmap function should at least check for fail or not
dch has quit [Read error: Connection reset by peer]
dch has joined #zig
bugabinga has joined #zig
_whitelogger has quit [Remote host closed the connection]
_whitelogger has joined #zig
rivten has joined #zig
tgschultz has quit [Quit: Going offline, see ya! (www.adiirc.com)]
tgschultz has joined #zig
dembones has joined #zig
<rivten> hello again :) so after some time investigating about loading code dynamically on linux (which worked fine on win32), I discovered that indeed the load_dynamic_library test is disable on linux because it doesn't work (I'll investigate if I'm brave enough). In the meantime, since I'd like to advance on my project, I thought about just calling dlopen and dlsym on Linux. Is this possible to call them right now in zig even though there is https://github.com/ziglan
<rivten> g/zig/issues/2294 ? Or should I need to explicitely @cImport the linux header file and link with something on linux if I'd like to call these functions ? Thanks a lot :)
jjido has joined #zig
<dembones> I've been busy for the past month, so I'm catching up on commits, and am seeing Ben Noordhuis contributing. He's one of the libuv maintainers. I'm curious if that means there's a port of libuv to Zig in the works. Anyone know?
<dembones> btw, all y'all contributing, wow, that's a ton of commits!
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
tane has quit [Quit: Leaving]
<andrewrk> rivten, yes, you can link libc and use dlopen/dlsym
<andrewrk> that goes for just about anything in libc
<rivten> @andrewrk yep that's why i'm trying right :) recreating the LinuxDynLib example with dlopen is a fairly good exercice in Zig :p
<rivten> thanks for the help !
<andrewrk> no problem
<dembones> I finally read 0.3.0 release notes on concurrency, and it dawns on me that functionality provided by libuv is not needed. I was asking mainly because I really like the async I/O model that libuv facilitates; and it's dawning on me that this should be possible natively in zig, but I will need to play w it to understand.
dembones_ has joined #zig
* dembones_ finds sources for testFsWatch(). Ahhhhhhh ok.
SimonNa has quit [Remote host closed the connection]
<andrewrk> dembones, big focus of this release cycle is re-doing how coroutines work
<andrewrk> it's recommended to avoid that problem domain for another ~5 months
SimonNa has joined #zig
<andrewrk> but yes, once that work is complete, event-based I/O will be part of the std lib without anything like libuv needed
jjido has joined #zig
jjido has quit [Client Quit]
<dembones_> ok. that is nice to know
<andrewrk> you mentioned 0.3.0 release notes... you might want to now read the 0.4.0 release notes :)
dembones has quit [Disconnected by services]
dembones_ is now known as dembones
<dembones> LOL, yep. I did when they came out, but prob absorbed only a fraction
<rivten> also, is there a way to see the @cImport files so see the Zig types that are expected when using the functions for example ?
<andrewrk> rivten, --verbose-cimport
<rivten> nice ! did not know that. Thanks a lot
<andrewrk> no problem
<andrewrk> documentation is incomplete, so part of the point of this chat room is to make up for the difference
<andrewrk> you'll find nobody saying "RTFM" in here :)
<dembones> indeed, I've appreciated the kind treatment of n00bs first hand
<rivten> okok thanks :) I'm pretty new to zig, I have been able to figure out a few things on my own (compiler error were pretty great though), but now that I'm getting into weird territory (loading .so files and all that) I'm lost :p
<dembones> rivten, how new are you to calling dlopen in C?
<rivten> not full expert, I've seen code doing that and understands it. I was able to also reload code and switch DLL at runtime on windows with Zig. But that's mostly it ^^
shritesh has joined #zig
<rivten> finally got it working !!! feels so great ahah. Thanks everyone :)
<dembones> nice!
<dembones> I was in the process of porting https://gist.github.com/tailriver/30bf0c943325330b7b6a to zig to see how it might look
reductum has joined #zig
jjido has joined #zig
hoppetosse has quit [Ping timeout: 244 seconds]
<rivten> well dembones, I can give you the sample code I ended up with for the dlopen if you're interested :) I load a library that output sound and renders to a buffer, and I can modify that code, recompile it to a dll and have it change at runtime. All with Zig
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
shritesh has quit [Ping timeout: 248 seconds]
rivten has quit [Remote host closed the connection]
jjido has joined #zig
reductum has quit [Quit: WeeChat 2.4]
<squeek502> is there a way to print the name of the function that a function pointer points to?
tgschultz has quit [Ping timeout: 248 seconds]
tgschultz has joined #zig
tgschultz has quit [Ping timeout: 246 seconds]
porky11 has joined #zig
porky11 has quit [Client Quit]
jjido has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
tgschultz has joined #zig
cameris has quit [Quit: leaving]
jevinskie has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
jevinskie has joined #zig
<andrewrk> squeek502, yes if you're willing to use debug info
<andrewrk> it would be a bit of a hack
<andrewrk> what are you trying to do?
<squeek502> not a big deal, was trying to write a benchmark function that takes a function pointer and then prints the results along with the name of the function
<dembones> There's a few ways to get at the symbol table in the ELF. When I link to glibc, I use backtrace/backtrace_symbols.
<dembones> There's probably a way to do it on PE (windows) executables too, but I wouldn't know.
<squeek502> yeah if it takes that much effort then its not worth it, just writing a temporary benchmarking program
<andrewrk> there's some profiling integrations with llvm that I haven't looked into yet
<andrewrk> I believe this would make zig programs emit compatible output as the -fprofile-* flags of clang