00:01:34 | * | Vladar quit (Remote host closed the connection) |
00:21:13 | FromDiscord_ | <bevo> @Kiloneie you have quite a few videos on your youtube chan |
00:21:13 | FromDiscord_ | <bevo> I'll watch your Nim ones if they're post-beginner to intermediatte |
00:22:53 | * | shomodj quit (Quit: My MacBook has gone to sleep. ZZZzzz…) |
00:24:54 | * | laaron quit (Remote host closed the connection) |
00:27:34 | * | laaron joined #nim |
00:27:51 | * | rayman22201 quit (Quit: Connection closed for inactivity) |
01:03:27 | * | ng0_ joined #nim |
01:06:12 | * | ng0 quit (Ping timeout: 260 seconds) |
01:07:49 | * | laaron quit (Quit: ZNC 1.7.1 - https://znc.in) |
01:09:32 | * | laaron joined #nim |
01:16:47 | * | stefanos82 quit (Quit: Quitting for now...) |
01:24:14 | * | ng0_ quit (Quit: Alexa, when is the end of world?) |
02:01:30 | FromDiscord_ | <treeform> I use Nim in production. It's great. It's faster python that prevents typos. |
02:01:51 | FromDiscord_ | <treeform> The only issues I had are with openssl. |
02:02:01 | FromDiscord_ | <treeform> But I had those with python too |
02:02:08 | FromDiscord_ | <treeform> I hate ssl |
02:02:58 | FromDiscord_ | <treeform> Lack of libs has not stopped me. I like writing my low level libs |
02:03:52 | FromDiscord_ | <treeform> @slymilano do you have something sepesific? |
02:10:16 | * | noeontheend joined #nim |
02:11:09 | * | noeontheend quit (Remote host closed the connection) |
02:35:33 | FromGitter | <awr1> "prevents typos" i chuckled |
02:37:10 | * | rayman22201 joined #nim |
02:49:55 | * | dddddd quit (Remote host closed the connection) |
02:54:24 | * | laaron quit (Quit: ZNC 1.7.1 - https://znc.in) |
02:55:15 | * | laaron joined #nim |
03:02:07 | * | lritter quit (Ping timeout: 245 seconds) |
03:03:06 | * | lritter joined #nim |
03:17:19 | FromDiscord_ | <Shield> I'm not sure if I understand correctly, but I thought strings were copied by value, I'm using gc:regions, I have an object A that holds a string, I used withScratchRegion to create object B with a different string, then I used A = B to see what happens |
03:18:35 | FromDiscord_ | <Shield> withScratchRegion should deallocate the temporary memregion, so I expected that the string in A would be deep copied, but when I check the address of the string in both A and B, they're the same, why is that? |
03:24:07 | * | nif quit (Quit: ...) |
03:24:16 | * | nif_ joined #nim |
03:27:13 | * | nif_ quit (Client Quit) |
03:27:21 | * | nif joined #nim |
03:28:27 | * | laaron quit (Quit: ZNC 1.7.1 - https://znc.in) |
03:28:52 | * | laaron joined #nim |
03:31:18 | FromDiscord_ | <Shield> http://ix.io/1Rbo |
03:33:31 | leorize[m] | you only copied the reference to an Entity object |
03:33:48 | leorize[m] | ofc it would point to the same address, hence the same string |
03:36:01 | FromDiscord_ | <Shield> it's not that, I expected the string to exist in the scratch region, then get deallocated at the end of the block |
03:37:08 | leorize[m] | deallocation never means override that region with zeros :p |
03:40:03 | leorize[m] | as long as the memory region is unused it should still be accessible |
03:42:29 | FromDiscord_ | <Shield> oh wow, it's not returning memory to the system |
03:44:45 | * | aq60 quit (Remote host closed the connection) |
03:45:09 | rayman22201 | I think if you use -d:useMalloc it will. But I could be remembering incorrectly. |
03:46:22 | rayman22201 | Nim doesn't like to give memory back to the OS. It might need that memory again 😛 |
03:52:00 | FromDiscord_ | <Shield> using useMalloc doesn't change a thing, while allocating manually and deallocating does give back memory |
03:58:06 | FromDiscord_ | <Shield> I think there's a difference between c_malloc and emalloc in the gc file if useMalloc isn't freeing memory |
03:58:24 | FromDiscord_ | <Shield> whelp, back to manual memory management |
03:58:28 | * | laaron quit (Remote host closed the connection) |
04:00:29 | * | laaron joined #nim |
04:04:07 | FromGitter | <bevo009> @leorize[m] ⏎ I installed your nvim plugin on wsl and got some strange behaviour ⏎ I tested it in Vimter on vscode(which utilizes nvim) and also nvim on Cmder ⏎ It's hiding lines and blocks like below ⏎ I have to jump to the next line and hit b, then they display ... [https://gitter.im/nim-lang/Nim?at=5d4e42371dadc42a1143920a] |
04:13:06 | rayman22201 | @Shield why not newruntime? |
04:19:00 | FromDiscord_ | <Shield> I'm still confused about newruntime, things said in the blog posts end up different from what people are discussing |
04:19:15 | FromDiscord_ | <Shield> I think the comment on gc:regions was misleading |
04:21:02 | rayman22201 | Which comment? |
04:21:37 | FromDiscord_ | <Shield> "# "Stack GC" for embedded devices or ultra performance requirements." |
04:22:27 | rayman22201 | That's correct. And it has been used for that exact purpose |
04:24:30 | leorize[m] | @bevo009 it's code folding |
04:24:45 | rayman22201 | Not giving memory back to the OS is a performance optimization. Getting memory from the OS is slow. It's a trade-off between higher memory footprint and speed. |
04:26:06 | leorize[m] | @bevo009 see `:h fold` (iirc) for details on how to work with it |
04:26:46 | FromGitter | <bevo009> is there a line I can put in my init.nvim to disable that? |
04:26:56 | leorize[m] | if you dislike auto code folding, `:set nofoldenable` should do |
04:29:00 | FromDiscord_ | <Shield> the problem with not releasing memory back to the system, is that if you allocate really fast, it will never reuse memory and will end up consuming the whole memory and holding it, unless you enforce a full collect after every use, which can still get out of hand, gc:regions suffers from the same fate |
04:29:00 | FromDiscord_ | <Shield> this is relevant for servers with small memory, if you have too many connections or serve big files, there's no way to get that memory back without killing the program or killing the thread (I didn't confirm this yet) |
04:30:06 | FromGitter | <bevo009> I actually was going to ask if that was a code-folding feature, but I couldn't find an obvious way to toggle it |
04:30:18 | FromGitter | <bevo009> Thanks, that line worked perfect :) |
04:30:50 | rayman22201 | Gc:regions specifically gives control over reusing memory. Don't use a scratch region. Explicitly make one and reuse it. |
04:33:43 | leorize[m] | @Shield: deallocAll(MemRegion) will free a region |
04:35:06 | FromDiscord_ | <Shield> the scratch region was a test, the problem still persists, the server for example will use memory enough to for the ongoing connections, so one spike in traffic leads to the program keeping that memory until you restart it |
04:35:39 | leorize[m] | weird, withScratchRegion should have freed the region |
04:36:30 | FromDiscord_ | <Shield> there's a lot of string generation and copying, so reaching the memory cap isn't implausible |
04:36:59 | rayman22201 | It's possible that it was freed and the memory just happened to not be overwritten yet. |
04:37:14 | leorize[m] | hmm, how did you know that withScratchRegion didn't release the memory? |
04:37:57 | FromDiscord_ | <Shield> it doesn't release it to the system, as rayman22201 said, Nim refuses to give it back to the system |
04:38:18 | FromDiscord_ | <Shield> otherwise I'd get a sigfault with that example |
04:38:22 | leorize[m] | it does according to the code for it |
04:38:32 | leorize[m] | oh, segfault if not guaranteed |
04:38:36 | leorize[m] | is* |
04:38:51 | rayman22201 | You would not necessarily get a segfault. Exactly |
04:39:01 | leorize[m] | a fair share of use-after-free survived for a reason |
04:39:22 | rayman22201 | leorize[m] knows more about the impl than I do. |
04:39:35 | FromDiscord_ | <Shield> you should check osalloc.nim to get the full picture |
04:40:07 | FromDiscord_ | <Shield> deallocAll doesn't give memory to the system, it frees it for the program itself |
04:40:35 | leorize[m] | use -d:useMalloc |
04:40:38 | leorize[m] | that'll do |
04:41:13 | FromDiscord_ | <Shield> I tried, it doesn't for some reason |
04:41:35 | leorize[m] | although at one point someone should try to make the gc release the memory to the os |
04:41:39 | rayman22201 | I think that is a bug actually. -d:usemalloc should work |
04:42:12 | leorize[m] | @Shield segfault is not a good indicator |
04:43:32 | FromDiscord_ | <Shield> I wish you can use gc:regions with the normal gc, as a good middle ground to manual MM, sometimes you want to nuke a whole page of memory and be sure that it's released to the os |
04:43:55 | rayman22201 | A better indicator is strace to see the matching alloc and free calls |
04:44:00 | FromDiscord_ | <Shield> I see the general memory use of the program not just segfault |
04:44:06 | FromGitter | <bevo009> @leorize[m] ⏎ Sorry to bug you again ⏎ I get this line in the console whenever I exit nvim: ⏎ nimsuggest instance for project: `/c/a/nim/01/' exited with exitcode: 0 ⏎ Can I make that silent somehow? ... [https://gitter.im/nim-lang/Nim?at=5d4e4b959507182477b0cdd6] |
04:45:00 | leorize[m] | it'd require some work from me, but is it that annoying? |
04:45:14 | FromGitter | <bevo009> Well, not if it requires work |
04:45:32 | FromGitter | <bevo009> I thought there might be a verbosity line there |
04:45:39 | leorize[m] | well "work" = one conditional to hide it :p |
04:47:20 | rayman22201 | @Shield your point about not freeing memory back to the OS is a good one. It has been brought up before. Nim takes a very greedy approach in general. |
04:47:45 | leorize[m] | @Shield weird, can you try modifying gc_regions.nim to hook onto osDeallocPages in the useMalloc branch? |
04:48:40 | leorize[m] | add a printf "free" should be enough |
04:51:14 | FromDiscord_ | <Shield> this what I found in osalloc.nim |
04:52:02 | FromDiscord_ | <Shield> according to Microsoft, 0 is the only correct value for MEM_RELEASE: This means that the OS has some different view over how big the block is that we want to free! So, we cannot reliably release the memory back to Windows :-(. We have to live with MEM_DECOMMIT instead. Well that used to be the case but MEM_DECOMMIT fragments the address space heavily, so we now treat Windows as a strange unmap target. |
04:54:52 | FromDiscord_ | <Shield> it's strange |
04:55:32 | rayman22201 | @Shield: you are on Windows? |
04:55:39 | FromDiscord_ | <Shield> yeah |
04:55:58 | rayman22201 | Ahhh. I assumed Linux. Interesting |
04:56:36 | FromDiscord_ | <Shield> the weird thing is, using pointers and (de)allocating memory works fine, it does give it back to the os |
04:57:13 | FromDiscord_ | <Shield> if it's using malloc for both manual and gc, why is the result different? |
05:02:57 | rayman22201 | It shouldn't be different. Something weird is going on I think. |
05:04:08 | * | solitudesf joined #nim |
05:06:55 | FromDiscord_ | <Shield> the weird thing is that, in gc:regions, useMalloc defines efree, but it's never called, what gets called is c_free, which isn't defined in a file I see, replacing it doesn't change anything |
05:07:45 | FromDiscord_ | <Shield> the little things that drive you insane |
05:14:19 | FromDiscord_ | <Shield> oh wow, no wonder useMalloc doesn't matter, c_free is basically efree, it gets called directly in regions |
05:14:34 | FromDiscord_ | <Shield> malloc efree* |
05:14:41 | * | vlad1777d joined #nim |
05:20:23 | * | narimiran joined #nim |
05:23:22 | FromDiscord_ | <Shield> the comment says "We have to live with MEM_DECOMMIT instead" but it actually uses MEM_RELEASE |
05:23:36 | FromDiscord_ | <Shield> there's no change |
05:27:34 | * | narimiran quit (Remote host closed the connection) |
05:59:59 | FromDiscord_ | <Shield> this doesn't make sense at all, I tried to limit the variables, it seems that deallocateAll works when you call it inside the block "withRegion", but not outside it, the only difference inside or outside Try |
06:00:37 | FromDiscord_ | <Shield> why would try affect this? |
06:07:16 | * | solitudesf quit (Ping timeout: 272 seconds) |
06:27:01 | FromGitter | <alehander42> Zevv, i agree with vindaar |
06:27:09 | FromGitter | <alehander42> if possible, save those procs in some data structure |
06:27:20 | FromGitter | <alehander42> and use only keys for them in Patt i guess |
06:28:39 | * | freddy92 joined #nim |
06:31:33 | Zevv | yeah that was my idea, but later I realized I probably dont need to serialize procs here. My goal is to be able to provide a library of reusable peg patterns as building blocks. But inside this lib it does not mak sense to have code blocks embedded, thats typically only done in the final peg. |
06:31:38 | FromDiscord_ | <Shield> actually, deallocAll(region) doesn't work, only deallocAll() does, and it has be within the withRegion block, outside it doesn't work, if you do it multiple times and ignore the previous way for the initial allocations, memory usage will revert to the last correct way, this implies some nesting happening |
06:31:46 | FromDiscord_ | <Shield> it's just bizzar |
06:32:01 | FromDiscord_ | <Shield> anybody else on windows to try it? |
06:32:08 | * | fredrik92 quit (Ping timeout: 245 seconds) |
06:32:29 | Zevv | so now I manaually build the Ast for my data structures that quotedo/getast is not able to, and that seems to work so far. Next step would be to see how I can put this back into my macros to generate Nim code from them. |
06:32:32 | * | lritter quit (Ping timeout: 245 seconds) |
06:40:35 | * | laaron quit (Remote host closed the connection) |
06:43:47 | * | laaron joined #nim |
06:57:56 | * | joshbaptiste quit (Ping timeout: 272 seconds) |
07:00:00 | * | gmpreussner quit (Quit: kthxbye) |
07:04:23 | FromDiscord_ | <Shield> http://ix.io/1Rc2 |
07:04:36 | * | gmpreussner joined #nim |
07:06:02 | FromDiscord_ | <Shield> I'm out of ideas, not sure if I should open an issue |
07:07:20 | leorize | probably you should |
07:09:10 | FromDiscord_ | <Shield> I'm waiting for somebody else to try it in case it's win7 fucking up, os specific issues are no fun |
07:18:36 | FromGitter | <bevo009> You want that code you linked to compiled? |
07:20:01 | FromGitter | <bevo009> If so, it compiles on cmd-Win10. But, I haven't really been following this |
07:20:43 | leorize | @Shield it's hard to monitor RAM usage on *nix though |
07:21:07 | leorize | but I do see munmap calls |
07:22:08 | leorize | @Shield it's like what you described |
07:22:24 | leorize | I only see munmap calls when deallocAll is called within the region |
07:24:35 | * | joshbaptiste joined #nim |
07:25:57 | FromDiscord_ | <Shield> but why is that? deallocAll is basically tlRegion.deallocAll(), I suspect it's either try block or the variable swap with tlRegion |
07:26:04 | FromDiscord_ | <Shield> I can't make sense of ot |
07:26:07 | FromDiscord_ | <Shield> it* |
07:28:05 | leorize | probably time to read the generated C code |
07:28:40 | leorize | I think I get the idea now |
07:29:12 | leorize | @Shield found the prob |
07:29:18 | leorize | see withRegion template |
07:29:29 | leorize | there's a line commented in the `finally` branch |
07:29:33 | leorize | that's the problem |
07:30:55 | leorize | Araq: can you explain why was this commented away? https://github.com/nim-lang/Nim/blob/0e4a8bfb289d707909069e72ca24efd2a074a5f1/lib/system/gc_regions.nim#L111 |
07:31:29 | FromDiscord_ | <Shield> what does it do? the problem is that deallocAll only works within the region, outside the block it doesn't work |
07:31:48 | leorize | MemRegion is an object |
07:32:09 | leorize | it's copied around |
07:32:21 | leorize | that line didn't copy the memregion back, so you can't free it |
07:34:30 | FromDiscord_ | <Shield> lemme double check, but withScratchRegion has the same problem |
07:35:33 | leorize | see withScratchRegion for explaination |
07:35:48 | leorize | it's appear that even Araq assumed that MemRegion have reference semantics... |
07:37:29 | FromDiscord_ | <Shield> you are right |
07:37:38 | FromDiscord_ | <Shield> uncommenting that line makes it work as expected |
07:40:42 | FromDiscord_ | <Shield> I can't believe I've spent a whole night to debug a commented line |
07:43:46 | leorize | that's why you should always read the source several times :P |
07:43:52 | leorize | preferably when you're wide awake |
07:45:33 | FromDiscord_ | <Shield> I even glanced over memRegion to see of copying semantics was correct... |
07:45:41 | FromDiscord_ | <Shield> if* |
07:46:50 | FromDiscord_ | <Shield> thanks for the help btw |
07:47:09 | leorize | np |
07:47:20 | leorize | are you going to fix it? |
07:47:25 | leorize | although not sure why it was commented |
07:50:33 | FromDiscord_ | <Shield> you mean a pr? |
07:50:37 | leorize | yea |
07:51:47 | FromDiscord_ | <Shield> I'm not using git, if you can't push it, I'll wait for Araq |
07:53:04 | leorize | I'm gonna open a PR and see why if uncommenting that breaks anything |
07:54:21 | FromDiscord_ | <Shield> you need to add "scratch = tlRegion" before https://github.com/nim-lang/Nim/blob/0e4a8bfb289d707909069e72ca24efd2a074a5f1/lib/system/gc_regions.nim#L286 |
07:54:35 | leorize | yep, I know |
07:54:37 | FromDiscord_ | <Shield> now both withRegion and withScratchRegion work as intended |
07:59:21 | FromDiscord_ | <Shield> I wonder if that swaping is generating garbage in the main region |
08:06:44 | * | rayman22201 quit (Quit: Connection closed for inactivity) |
08:11:31 | FromDiscord_ | <Shield> no, but printing debug strings was |
08:27:13 | * | Trustable joined #nim |
08:32:09 | FromDiscord_ | <Shield> more memory fun time http://ix.io/1Rcb/nim |
08:33:00 | FromDiscord_ | <Shield> I suspected this would happen, not even a deepcopy help |
08:36:00 | FromGitter | <zacharycarter> @Vindaar: nested objects aren't as straightforward as we thought - couple of things... ⏎ 1) The `genGetProc` macro calls `getVarNode` and most likely a nested object isn't going to be a `var` - to handle this I am now generating two get procs `getVarFoo` and `getFoo` and it will be up to the user to call the correct one |
08:37:27 | FromGitter | <zacharycarter> 2) The second problem is that inside the `genGetProc` we call some variation of `getNode` and pass in vmargs as well as an index. Since our nested object isn't an argument in the args passed to the VM, it's nested inside one of them - simply calling the `getFoo` proc we produce will not work |
08:40:04 | leorize | @Shield: the only way to do so is to allocate `a` outside of the region, then do some voodoo magic to copy the string buffer over |
08:40:56 | FromGitter | <zacharycarter> but I think I have a fix for this |
08:43:24 | FromDiscord_ | <Shield> the problem is that all memory functions are applied to the current memory region alone, this is why I suggested the ability to have two memory regions at the same time without one overriding the calls of the other |
08:45:36 | FromDiscord_ | <Shield> I don't think voodoo would work on this, how can you even communicate to the target memregion that it needs to grow/reallocate? |
08:53:03 | leorize | have 2 memregion |
08:53:07 | leorize | one for that string |
08:53:29 | leorize | and one's the scratch itself |
08:54:00 | FromGitter | <zacharycarter> wewt |
08:54:03 | leorize | then just `let bLen = b.len; withRegion(aRegion): a = newString(b.len)` |
08:54:05 | FromGitter | <zacharycarter> got the get proc working for nested objects |
08:54:36 | leorize | then scope to the outer region and start copying with copyMem |
08:54:43 | leorize | "easy" :P |
08:56:13 | FromGitter | <zacharycarter> so now you can call either `getVarFoo` or `getFoo` and you'll either get back a `var` or a `let` basically |
08:56:25 | FromGitter | <zacharycarter> well not a `let` but an immutable instance of `Foo` |
08:56:42 | FromDiscord_ | <Shield> I was trying that with pointers and failed miserably, and apparently, it's impossible to use index access on ptr string, p[][0] doesn't work, something needs to be done about '[]' |
08:56:56 | FromGitter | <zacharycarter> we could go back to `->` |
08:57:16 | FromGitter | <zacharycarter> wait - why doesn't p[][0] work? |
08:57:26 | FromGitter | <zacharycarter> strings are implemented w/ seqs right? that should totally work... |
08:57:55 | leorize | @Shield wait a bit, I'll try to write an example |
08:57:55 | FromDiscord_ | <Shield> it doesn't, because [] to deference is interfeering with [] for table access |
08:58:41 | leorize | I don't think you're doing it right... |
08:58:46 | FromGitter | <zacharycarter> this works |
08:58:56 | FromGitter | <zacharycarter> ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5d4e87505178a7247660dafc] |
08:59:14 | FromDiscord_ | <Shield> that would be helpful @leorize |
08:59:37 | FromGitter | <zacharycarter> prints `ptring` |
09:02:50 | leorize | @Shield http://ix.io/1Rcm/nim |
09:03:10 | leorize | ofc you can also just do a for loop copy instead of copyMem |
09:03:27 | FromGitter | <zacharycarter> Shield: once you've mastered memory regions - would you mind writing a blog post about them maybe? |
09:03:48 | FromGitter | <zacharycarter> and what problems you were able to solve using them? |
09:04:12 | leorize | @Shield it's even simpler |
09:04:21 | leorize | just a = b inside that withRegion block lol |
09:05:39 | FromGitter | <zacharycarter> @Vindaar - would you be cool with me writing up a blog post about these macros / how I'm going to be using them in my game? |
09:05:51 | FromGitter | <zacharycarter> I will credit you as the author :) |
09:05:57 | FromGitter | <zacharycarter> not of the blog post but the macros haha |
09:05:58 | leorize | I can see that gc:regions is an interesting gc |
09:06:57 | FromGitter | <zacharycarter> leorize: I think it's just not very well documented, and the folks that understand it enough to know how to use it and how it's useful are too busy to dispense that knowledge |
09:07:09 | FromGitter | <zacharycarter> also - not insinuating that yuuou and Shield aren't busy :P |
09:07:42 | FromGitter | <zacharycarter> I played around with it a little bit about a year ago but couldn't make heads or tails of how to use it - the example code I found on the forums compiled, but then I was left scratching my head - like okay, what did I just do? |
09:08:42 | leorize | @Shield this is interesting... https://github.com/nim-lang/Nim/blob/0e4a8bfb289d707909069e72ca24efd2a074a5f1/lib/system/gc_regions.nim#L94 |
09:09:10 | shashlick | Will be great if we can just regions to fix the dll issue |
09:09:36 | FromGitter | <zacharycarter> well - I'm hopeful that Araq (or someone else) will investigate the stack issue with Nim HCR |
09:09:59 | leorize | shashlick: technically you can |
09:10:17 | FromGitter | <zacharycarter> because if that's easily fixed and is the main pain point of all the problems people are experiencing with HCR (big ifs I know) - then HCR will be very useful |
09:10:21 | FromGitter | <zacharycarter> obviously |
09:10:37 | FromDiscord_ | <Shield> region is pretty straight forward, what isn't clear is what does "=" and "deepcopy" and "shallowcopy" means for each types, once you have complex objects with nested stuff, you're in for a fun time |
09:12:30 | leorize | `=` being broken for string is a bug I think |
09:12:42 | leorize | regions was designed with that in mind |
09:12:59 | leorize | a pointer to the region that created the string is there |
09:15:48 | FromDiscord_ | <Shield> I've yet to understand why it segfaulted in the first place, and how did your solution work, and more importantly, what effects does it have on the region |
09:16:39 | FromDiscord_ | <Shield> I've noticed that you have to use nested regions to avoid polluting the main region |
09:16:56 | leorize | you can't capture the main region actually |
09:17:00 | leorize | or I'd have already used that |
09:17:21 | leorize | so here's my speculation of how this works |
09:17:46 | leorize | when you assign `a = b` in the scratch region, a new string is created for a |
09:18:04 | FromDiscord_ | <Shield> even an echo $ & is enough to fill a region with no way to free it without nuking the whole thing |
09:18:29 | leorize | since the current region is the scratch one, this also causes a's memory to be held by the region |
09:18:47 | leorize | then when you free it you lost everything |
09:18:52 | leorize | which is why you get segfault |
09:19:36 | leorize | by nesting the region, I make sure that a's memory will be owned by a region that'd still be alive |
09:20:26 | shashlick | I agree we need good docs explaining how to use regions |
09:20:56 | FromDiscord_ | <Shield> I see, I just deallocated aRegion and got a segfault |
09:22:05 | leorize | I think the default main region was intended to be a feature |
09:22:34 | leorize | but it might causes more problems than it solves |
09:22:36 | FromDiscord_ | <Shield> this would be useful for dlls if you're careful which memory gets to persist |
09:22:50 | FromDiscord_ | <Shield> the problem is, how do you copy stuff between regions |
09:23:04 | leorize | nest them, that's how |
09:23:30 | leorize | you can just copy them actually |
09:24:00 | leorize | just make sure that you are in the target region before you copy |
09:24:06 | FromGitter | <zacharycarter> there's also - `joinRegion` - but it's inside a `when false` block |
09:24:38 | FromDiscord_ | <Shield> ix.io/1Rcp/nim |
09:25:45 | leorize | that's the problem |
09:25:49 | FromGitter | <alehander42> i cant understand |
09:25:51 | leorize | you can't capture the main region |
09:25:55 | FromGitter | <alehander42> you dont seem to copy it to the main region |
09:25:56 | leorize | so you can't scope back to it |
09:27:18 | leorize | maybe there should be a proc that returns the current region? |
09:27:58 | FromDiscord_ | <Shield> that's irrelevant, you can drop the hidden main region and use yours from the beginnig, or just add a * to tlRegion to make it public |
09:28:32 | FromDiscord_ | <Shield> the problem is how do you transfer a variable to the wanted region and make sure it lives there |
09:28:51 | leorize | deepCopy it while you're in the wanted region? |
09:28:53 | FromDiscord_ | <Shield> it got tricky for 1 string, imagine a nested object |
09:36:19 | FromGitter | <mratsim> you can’t mix regions with normal code right? |
09:36:54 | FromGitter | <mratsim> Using regions would be helpful for a memory pool/object pool for the low-level details of my multithreading runtime |
09:38:15 | FromGitter | <mratsim> uh, I wasn’t aware of the MemRegion type :O |
09:40:01 | FromDiscord_ | <Shield> no you can't, and that's the problem, you can only write to one and only region, the only solution here would be turning allocators into function pointers, instead of everything working in one exact region |
09:41:03 | FromDiscord_ | <Shield> declaring a variable in one region and assigning something to it in another leads to a bad time |
09:41:04 | leorize | well but since you can read from any region, copying is trivial |
09:41:54 | FromDiscord_ | <Shield> I can't get it to work |
09:42:12 | leorize | any example? |
09:43:38 | * | Vladar joined #nim |
09:44:02 | * | shomodj joined #nim |
09:47:13 | FromDiscord_ | <Shield> your own, try to move a from aRegion to the main region, I'm using a third variable for swapping and getting errors |
09:49:46 | FromDiscord_ | <Shield> the solution would be making newObj, newSeq.... take a region argument, so they can reallocate correctly |
09:51:14 | leorize | here's how you move it to the main region |
09:51:18 | leorize | `a = a` |
09:51:20 | leorize | done |
09:52:41 | leorize | though I think at this point betting on newruntime is better than gc:regions |
09:53:10 | FromDiscord_ | <Shield> ix.io/1Rcw/nim |
09:54:00 | leorize | that copyMem is incorrect |
09:54:34 | leorize | also you introduced an another `var c` in the `withRegion` blok |
09:54:35 | leorize | block* |
09:54:51 | leorize | ofc once you got out of it you won't get the `c` you wanted |
09:55:16 | leorize | also newString is not necessary |
09:55:50 | leorize | http://ix.io/1RcA/nim |
09:56:08 | leorize | that's a simplified way to copy things to the main region |
09:58:13 | FromDiscord_ | <Shield> http://ix.io/1RcB/nim |
09:58:41 | FromDiscord_ | <Shield> the real voodoo magic is, why does a = a even work |
09:59:17 | leorize | please note that `a.addr` is the address to the variable `a` on the stack |
09:59:51 | leorize | you'd want `a[0].addr` or `a.cstring` instead |
10:00:10 | FromDiscord_ | <Shield> yeah I noticed that |
10:00:53 | FromDiscord_ | <Shield> so it does make a copy, the question is why and how |
10:01:34 | leorize | so with the "old" runtime, move optimization for string and seq don't exist |
10:01:40 | leorize | every assignment is a copy |
10:01:46 | leorize | even if you self-assign |
10:02:55 | leorize | I just merely exploited this fact to get things to the main region |
10:03:27 | FromGitter | <zacharycarter> nested objects work with the generated setResult procs now - did a similar thing where I have `setObject` and `setInnerObject` since the set inner proc shouldn't call setResult and should instead return a PNode |
10:03:40 | FromDiscord_ | <Shield> I was doing some tests with objects and got some weird results between "=" and deepcopy, it's simply unreliable, regions isn't as helpful as it should be |
10:04:16 | leorize | it's underdeveloped |
10:04:46 | leorize | the majority of the code has been untouched for ≈3yrs |
10:05:26 | leorize | can I have your tests? |
10:08:46 | FromGitter | <zacharycarter> https://gist.github.com/zacharycarter/71bc76ec1a7f24ed76eacc350d9969d9 |
10:08:54 | FromGitter | <zacharycarter> gist of how this looks and works |
10:09:02 | FromDiscord_ | <Shield> I doubt there's much to do in regions itself, the problem is that anything related to memory happens in the current region reguardless where the variable actually exist, and passing things between region results a random crash |
10:09:31 | * | krux02 joined #nim |
10:11:05 | leorize | yea, region needs some kind of write tracking to ward off possible cross region mutation |
10:11:18 | leorize | although that might have actually existed |
10:11:37 | leorize | iirc there were "memory regions" concept in Nim |
10:11:46 | FromGitter | <mratsim> no, write-tracking and escape analysis was something araq always wanted to do and never found the time for |
10:12:10 | leorize | you can mark a pointer as belonging to a specified region and you won't be able to trade them around |
10:12:29 | FromGitter | <mratsim> yes, it was removed because too unergonomic: https://forum.nim-lang.org/t/3158 |
10:15:34 | * | solitudesf joined #nim |
10:17:05 | FromDiscord_ | <Shield> interesting |
10:18:40 | FromDiscord_ | <Shield> regions will be somehow usable if you can copy variables cross regions safely, because otherwise, it's an all or nothing memory manager |
10:21:11 | FromDiscord_ | <Shield> anybody wants to tackle this? |
10:23:31 | * | dddddd joined #nim |
10:28:07 | leorize | the infrastructure seems to be there already |
10:29:32 | * | endragor joined #nim |
10:29:36 | * | stefanos82 joined #nim |
10:30:19 | leorize | but with how the gc runtime is designed, copying is certainly not easy |
10:30:38 | FromDiscord_ | <Shield> btw, using deepcopy instead of "=" for both a=b and a=a seems to make it work when a is an object with a ref to string, with "=" you need to do it the hard way |
10:31:01 | leorize | ofc |
10:31:12 | leorize | with `=` you're only coping the `ref` |
10:31:22 | leorize | deepCopy reconstruct any `ref` |
10:31:36 | leorize | copying* |
10:32:22 | leorize | doing regions is kinda like using threads in Nim |
10:32:40 | leorize | you have to be aware of when a deepCopy is required |
10:32:48 | leorize | or else your ref just die |
10:32:59 | FromDiscord_ | <Shield> is the tradoff even worth it anymore? this needs to be more efficient |
10:33:28 | leorize | the more efficient variant is known as `newruntime` |
10:33:44 | leorize | it abandons the gc entirely :P |
10:33:53 | FromGitter | <mratsim> only for owned ref |
10:34:10 | leorize | but the heap is now shared |
10:34:12 | leorize | so less copying neede |
10:34:16 | leorize | needed* |
10:34:19 | FromGitter | <mratsim> but i didn’t try them yet :P, well Araq said that linked lists worked with owned refs so mmmmh |
10:34:33 | * | endragor quit (Ping timeout: 268 seconds) |
10:34:35 | FromDiscord_ | <Shield> newruntime seems scary |
10:34:54 | leorize | I can't really recommend newruntime until the `=move` change is sorted out |
10:34:59 | FromGitter | <mratsim> it needs brave explorers to defuse the land mines |
10:35:42 | leorize | I've defused several of them |
10:35:44 | * | endragor joined #nim |
10:35:48 | FromDiscord_ | <Shield> regions kinda solved the problem with server and returning memory, but dll is still a problem |
10:36:10 | FromGitter | <mratsim> What are you using newruntime for leorize? |
10:36:24 | leorize | others are even trying newruntime as their default mode :P |
10:37:02 | leorize | @mratsim: nothing much, I'm just experimenting and benchmarking |
10:37:18 | leorize | found several trivial bugs that way |
10:37:37 | FromDiscord_ | <Shield> which file contains it? |
10:37:49 | leorize | new runtime? |
10:38:00 | FromDiscord_ | <Shield> yeah |
10:38:01 | leorize | lib/core/seqs.nim |
10:38:04 | leorize | lib/core/strs.nim |
10:38:09 | leorize | the rest is in the compiler |
10:38:21 | leorize | new runtime is a huge codegen change |
10:39:04 | leorize | oh lib/core/allocators.nim also |
10:39:40 | leorize | and runtime_v2.nim |
10:40:45 | leorize | well any attempt with newruntime should be armed with -d:useMalloc and valgrind |
10:41:24 | leorize | newruntime is really stressing the destructors system |
10:42:43 | FromGitter | <mratsim> ugh, there is no pthread_barrier_t on OSX :/ so much for being posix compliant … https://blog.albertarmea.com/post/47089939939/using-pthreadbarrier-on-mac-os-x |
10:43:51 | FromGitter | <alehander42> how often does the `=` happen |
10:43:57 | FromGitter | <alehander42> `=sink` thing * |
10:44:10 | FromGitter | <alehander42> and yeah , does valgrind work well? |
10:44:28 | FromGitter | <alehander42> i wanted to run my newly ported-to-c-backend binary |
10:44:29 | FromGitter | <alehander42> under it |
10:44:32 | leorize | @mratsim: if you're interested in Nim's threadpool, check this out: https://github.com/yglukhov/threadpools |
10:44:35 | FromGitter | <alehander42> but afaik i have to use some skiplists |
10:44:58 | leorize | that's going to be the next threadpool I think |
10:45:14 | FromGitter | <mratsim> Yeah, I know yglukhov threadpools but there is no load balancing |
10:45:15 | leorize | that was* |
10:45:28 | FromDiscord_ | <Kiloneie> Did anyone use this site to train Nim ? https://exercism.io/my/tracks/nim |
10:45:53 | leorize | @alehander42: valgrind works if you -d:useMalloc (according to Araq anyway, never tried myself) |
10:46:41 | FromGitter | <mratsim> it’s fairly recent @Kiloneie, it was setup by one of the community members about 9 months ago iirc |
10:46:51 | leorize | damn, Nim is big on exercism now |
10:47:03 | leorize | when I first started there were like 10 tasks? |
10:48:58 | FromGitter | <mratsim> but Yardanico disappeared :P |
10:49:08 | FromDiscord_ | <Kiloneie> first 2 side exercises really streched my brain yesterday xD... i have not coded this much since i was 15 trying to do a WAY too ambitious game in Game Maker, i really want to finish it one day... |
10:50:20 | FromDiscord_ | <Shield> will the newruntime replace gc for good? I've spent too long trying to figure out each gc.. |
10:50:41 | FromGitter | <mratsim> The issues with games is that you also have the sound, graphics, AI, input and art/music to manage |
10:50:43 | FromDiscord_ | <Shield> and I've yet to tackle multithreading and dll plugin system |
10:50:53 | leorize | probably |
10:50:56 | FromGitter | <mratsim> No, it will be opt-in |
10:51:04 | FromGitter | <mratsim> defautl seq and strings will use newruntime |
10:51:05 | leorize | it's still an experiment |
10:51:24 | FromGitter | <mratsim> user object will use newruntime if tagged “type Foo = owned ref object" |
10:51:38 | FromGitter | <mratsim> and use GC if tagged “Foo = ref object" |
10:51:50 | leorize | eh, that's not how newruntime works? |
10:52:48 | FromGitter | <mratsim> is it? that’s what it said at the bottom of the RFC: https://github.com/nim-lang/RFCs/issues/144 |
10:53:28 | leorize | you can't take in bits by bits |
10:53:40 | leorize | either you adopt the entire thing with --newruntime |
10:53:44 | leorize | or you don't |
10:53:56 | leorize | if you can slowly migrate then it'd be the default by now :P |
10:54:08 | FromDiscord_ | <Shield> let's hope it doesn't break existing libraries, it seems that a lot of people stop updating libraries, what a shame |
10:54:09 | FromGitter | <mratsim> mmm, the RFC says that you need to tag your types with “owned” otherwise they work as before |
10:54:35 | leorize | > use a switch like --newruntime and needs to use owned annotations |
10:54:46 | FromDiscord_ | <Shield> somehow godot bindings is the most up to date library |
10:55:03 | leorize | @Shield migration is simple |
10:55:08 | FromDiscord_ | <Shield> for games I mean |
10:55:19 | leorize | and the change is staged for nim v2 |
10:55:32 | leorize | so if you don't update your library by then it probably won't compile :P |
10:55:35 | FromGitter | <mratsim> But Godot bindings are used by a commercial company |
10:56:35 | FromDiscord_ | <Shield> I also see some libraries that are neither included in nimble.directory nor has the Nim tag so finding them is up to pure chance |
10:57:21 | FromGitter | <alehander42> @mratsim leorize is right, i think the "work as before" is about the newruntime again |
10:57:31 | FromGitter | <alehander42> i guess, using some form of refcount |
10:57:52 | FromDiscord_ | <Shield> isn't it too soon to spend effort on v2 features when v1 still yet to happen? |
10:58:05 | FromDiscord_ | <Kiloneie> Well it's no suprise Godot bindings are the most up to date. Who doesn't like games and game coding(as a coder) ? Godot is the best 2D engine right now and growing really fast, support will only go higher. |
10:58:59 | leorize | @Shield technically v1 is already complete |
10:59:26 | leorize | but then Araq wants to have newruntime as part of v1 so... |
10:59:29 | FromDiscord_ | <Shield> it's undergoing changes |
11:00:19 | leorize | ah, some last changes til v1 https://github.com/nim-lang/Nim/issues?q=is%3Aopen+is%3Aissue+milestone%3Av1 |
11:00:29 | FromDiscord_ | <Shield> Godot was fine and dandy until I've read its source code, dictionaries everywhere, calling stuff using strings, strings everywhere, callbacks everywhere, it was a nightmare |
11:00:48 | FromGitter | <mratsim> I think we should have v1 with the current GC. |
11:01:04 | leorize | that's the plan |
11:01:08 | * | krux02 quit (Remote host closed the connection) |
11:01:11 | FromGitter | <mratsim> newruntime is too much of a change |
11:01:22 | leorize | and looks like newruntime has been taken off the list |
11:01:29 | FromDiscord_ | <Shield> I feel that nim is wasted on it, the only reason I'd use godot would be easy porting to multiple platforms, if you're using nim, that means you're doing the compiling yourself |
11:01:41 | FromDiscord_ | <Shield> and you're locked to whatever you can compile on |
11:01:50 | FromDiscord_ | <Kiloneie> Wait what is this new runtime is supposed to do ? |
11:01:54 | leorize | @mratsim it was going to be included as --newruntime for experimentation |
11:02:06 | FromGitter | <mratsim> ah yeah then OK |
11:02:11 | leorize | iirc Araq wanted it to be functional enought |
11:02:24 | FromDiscord_ | <Kiloneie> Idk GDscript is way slower than Nim, and a lot of people hate c++, therefore if you really need some crazy calculations, it would be great. |
11:02:30 | leorize | then probably with all the blockers around he dropped it from v1 |
11:04:57 | FromDiscord_ | <Shield> gdscript is slow, but also well integrated, you realise that get_node is doing a full look up in the node's children, using the string name, and calling godot functions is like hitting a speed bump |
11:05:15 | leorize | at least with godot you can read the source code |
11:05:28 | FromDiscord_ | <Shield> last time I checked, if you want to change a field, you need to asign the whole object, like what |
11:05:40 | leorize | who knows what horror lies in Unity |
11:07:41 | FromGitter | <alehander42> i guess new-runtime can still come as |
11:07:42 | FromDiscord_ | <Shield> I rather have updated sfml libraries and bindings for physics and other cool libraries, and a tiled importer |
11:07:46 | FromGitter | <alehander42> --experimental-runtime |
11:07:47 | FromGitter | <alehander42> or something |
11:08:05 | FromGitter | <alehander42> its in the codebase anyway, it doesnt make sense to completely hide it |
11:08:24 | FromDiscord_ | <Shield> I tried to make bindings for dragonbones runtime, but the bastards locked the export features behind signing up |
11:08:53 | FromDiscord_ | <tomku> would it still be practical to use nim in godot for self-contained modules like pathfinding? |
11:08:56 | leorize | @alehander42: it's still there, just that blockers for it won't block v1 anymore |
11:10:30 | FromDiscord_ | <Shield> godot has A* and navmesh tho, both are in C++ |
11:10:49 | FromGitter | <alehander42> of course |
11:12:25 | FromDiscord_ | <Shield> but yeah, anything is practical as long as you don't call godot functions that much, and you need to cache any call, and be careful about exessive copying |
11:12:57 | leorize | Araq: https://github.com/nim-lang/Nim/issues/11217 <- so you decided to keep `=sink`? |
11:13:01 | FromDiscord_ | <Shield> personally I just dropped it instead of hacking around the engine, I mean, it's open source, whatever feature you like you can steal and make it better |
11:13:10 | Araq | leorize: yep |
11:13:31 | leorize | yay, less rewrites |
11:13:31 | Araq | the competition is strong, can't affort a 3% overhead |
11:13:42 | FromDiscord_ | <Shield> because somebody tried to push a PR to avoid using dumb dictionaries and speeding the engine dramatically, but they refused |
11:14:34 | leorize | Araq: so what's your final solution for the self-assignment problem? |
11:14:42 | leorize | just special casing it? |
11:14:53 | FromDiscord_ | <tomku> gotcha. are there any game engines in nim ecosystem that are acutally alive and maintained? |
11:16:01 | * | endragor quit (Remote host closed the connection) |
11:16:01 | leorize | write games, don't write engines :) |
11:16:52 | FromDiscord_ | <Shield> there are a couple that I couldn't even compile, but I'd rather avoid engines, for 2d games, you really only need basic drawing functions |
11:16:59 | * | shomodj quit (Quit: My MacBook has gone to sleep. ZZZzzz…) |
11:17:04 | Araq | leorize: self assign is a copy |
11:17:38 | FromDiscord_ | <Shield> and for 3d, the best option is Unreal, unity is trash, every gdc talk is about how they fight the engine |
11:17:56 | * | endragor joined #nim |
11:18:25 | Araq | Unreal seemed pretty bloated and they have their own C++ variant with a GC and stuff |
11:19:17 | FromDiscord_ | <Shield> still faster and more professional than unity, but they're pushing blueprint spaghetti too much |
11:19:19 | FromDiscord_ | <tomku> i use UE4 at work and am not a huge fan of c++, nim looks like a perfect language for me to do some gamedev on a side |
11:19:49 | FromDiscord_ | <tomku> but I kinda don't want to roll my own tech in yet another language if you catch my drift |
11:20:23 | leorize | https://github.com/Vladar4/nimgame2 <- this is a quite functional game engine the last time I checked |
11:23:02 | FromGitter | <alehander42> what happened with unity'c "custom C# fast as C++" |
11:23:09 | FromDiscord_ | <Shield> use what satisfies your need, you trade time for performance and vice versa, but really, how hard is it when you have tons of libraries? you can piggy back other editors |
11:24:50 | FromDiscord_ | <Shield> https://www.youtube.com/watch?v=mQ2KTRn4BMI |
11:25:33 | FromGitter | <Vindaar> @zacharycarter great to hear it's working! And hell yeah, write a blog post! And it's not like I wrote all of it. :) Give me credit for the stuff I actually wrote ;) |
11:25:50 | * | solitudesf quit (Ping timeout: 272 seconds) |
11:27:26 | leorize | @Shield my god that title is depressing |
11:27:44 | * | endragor quit (Remote host closed the connection) |
11:27:58 | * | endragor joined #nim |
11:28:02 | FromDiscord_ | <Shield> if nim can run on android somehow without the disgusting sdk I'll never look at an engine ever again, because porting is the only thing that actually made people switch to engines, everything else is workable |
11:28:37 | FromDiscord_ | <Shield> it is, and those are professionals with access to unity source code |
11:28:58 | leorize | https://forum.nim-lang.org/t/4840 |
11:29:07 | FromDiscord_ | <Shield> it's funny how they had to expose an existing function to get a decent speed up |
11:33:31 | FromDiscord_ | <Shield> @Ieorize that's the project that should be backed by a comercial company, all it needs is a graphic library, I'm curious if sdl2 works |
11:34:48 | leorize | it's leorize with a lowercase `l` :p |
11:39:19 | leorize | I kinda want to make an android app, but then you can't easily build a decent gui without java |
11:41:39 | leorize | I guess I can do a karax-based app |
11:41:41 | leorize | this is one of those times where all those bloated web features are actually useful |
11:45:48 | FromDiscord_ | <Shield> webgl works surprisingly well on android, and imgui is your best bet |
11:45:50 | * | PMunch joined #nim |
11:46:17 | FromDiscord_ | <Shield> I don't know who thought java was the best choice for an os |
11:46:57 | leorize | to be fair, when android came out, most mobile devs know java (thanks to j2me) |
11:47:13 | leorize | and everyone was learning java at that point |
11:47:28 | leorize | so it's a good move to quickly build an ecosystem |
11:47:38 | FromGitter | <alehander42> yeah, they didnt really had a good alternative back then |
11:47:45 | FromGitter | <alehander42> what could they use, c++ |
11:48:00 | FromGitter | <alehander42> for userland apps* |
11:48:18 | leorize | not to mention how the big smartphone OS Symbian has a stupid C++ API that doesn't conform with the standard |
11:48:40 | FromGitter | <alehander42> leorize, how can you remember symbian |
11:48:54 | leorize | kinda shy everyone away back then |
11:49:01 | FromGitter | <alehander42> aren't you .. younger than it |
11:49:03 | FromDiscord_ | <Shield> at least windows is less shitty in that reguard |
11:49:08 | FromGitter | <alehander42> almost |
11:49:26 | leorize | @alehander42: I was die hard nokia user :) |
11:49:39 | FromGitter | <alehander42> well, windows tried to push .NET with mostly c# code |
11:49:40 | FromGitter | <alehander42> for user apps |
11:49:44 | FromGitter | <alehander42> i dont see the difference |
11:50:03 | FromGitter | <alehander42> now for games, i was under the impression one can use c/c++ with NDK on android |
11:50:05 | leorize | windows mobile wasn't using C# I think? |
11:50:06 | FromGitter | <alehander42> so whats the issue |
11:50:32 | leorize | Android native APIs are extremely limited |
11:50:44 | FromDiscord_ | <Shield> windows mobile now is basically like desktop |
11:51:13 | FromDiscord_ | <Shield> visual studio is a bloated mess tho |
11:51:14 | FromGitter | <alehander42> it seems both c++/c# were possible for win mobile |
11:51:25 | FromDiscord_ | <Shield> yeah |
11:52:02 | FromGitter | <alehander42> well, its too bad native apis are limited: i guess hard to support stable native API-s across all the hardware? |
11:52:13 | FromGitter | <alehander42> which doesnt sound right |
11:52:16 | leorize | even BBOS was mostly java |
11:52:18 | FromGitter | <alehander42> so it must be somethign else |
11:52:31 | leorize | @alehander42: NDK was added as an afterthought |
11:52:43 | leorize | java is the superior language on android |
11:52:49 | leorize | but since java is slow |
11:52:51 | FromGitter | <alehander42> ok, but e.g. what does unity and other engines use |
11:53:14 | FromDiscord_ | <Shield> hardware got faster and software got slower |
11:54:04 | leorize | that moment when phones having 4gb of ram is not enough |
11:54:28 | FromGitter | <alehander42> phones stopped being phones long ago |
11:54:38 | FromDiscord_ | <Kiloneie> hardware is running ahead since AMD caught up and got ahead, Samsung will be using RDNA mobile in like 2 years |
11:54:40 | FromGitter | <alehander42> they are just smaller touchscreen-based laptops |
11:55:29 | FromDiscord_ | <Shield> 8 cores became the norms yet they still manage to make it stutter |
12:00:24 | FromGitter | <bevo009> FFI question, could I include a C++ third party library? (fmt) Is it possible? |
12:00:38 | leorize | yes, it is |
12:00:52 | leorize | you'd have to write the wrapper though |
12:01:05 | leorize | c2nim should be able to do a decent amount of them for you however |
12:01:11 | FromGitter | <bevo009> What I would use in a minimal working .cpp file is this: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5d4eb207bb5364334c07e850] |
12:02:49 | leorize | `importcpp: "fmt::print(@)"` |
12:03:08 | leorize | then change the proc name to something that's a valid Nim identifier |
12:04:32 | FromDiscord_ | <Kiloneie> Operator overload is freaking cool. |
12:04:45 | Araq | here I am ... wondering about linefmt vs lineCg |
12:04:48 | FromGitter | <bevo009> "fmt::print(@)" ... what does the `@` do? |
12:04:54 | Araq | turns out ... they are the same |
12:05:13 | Araq | and people want an 'alias' feature. madness :P |
12:06:29 | leorize | @bevo009 https://nim-lang.org/docs/manual.html#importcpp-pragma-importcpp-for-procs |
12:07:54 | FromDiscord_ | <Kiloneie> Is there a link that has the most useful pragmas in one place ? I am not at that understanding yet. |
12:08:11 | FromGitter | <bevo009> yeah I've been reading that, trying to make sense of it |
12:09:32 | FromDiscord_ | <Kiloneie> Oh man this sucks, i did first challenge of Hello World on Exercism, then the 2 side ones, then did Two Fer second main exercise, now i can't do anything until someone reviews my code... bollocks. |
12:09:37 | FromGitter | <bevo009> that formatstr: cstring can't be right for C++ though |
12:12:34 | * | ng0 joined #nim |
12:13:37 | FromGitter | <bevo009> ```code paste, see link``` ⏎ ⏎ file not recognized: File format not recognized [https://gitter.im/nim-lang/Nim?at=5d4eb4f1c87a0963e747351c] |
12:23:23 | Araq | don't wrap format, we have 'strformat' which is superior |
12:26:40 | FromGitter | <bevo009> I do use strformat |
12:26:56 | FromGitter | <bevo009> I just want to get this working so I know how to do it |
12:27:33 | FromGitter | <bevo009> Should I use (.link: instead? |
12:27:44 | FromGitter | <bevo009> {.limk: |
12:27:52 | FromGitter | <bevo009> ahh the typos |
12:28:17 | FromDiscord_ | <Kiloneie> Why won't this reverse ? https://play.nim-lang.org/#ix=1RdL |
12:28:17 | FromDiscord_ | <Kiloneie> I thought i saw this working somewhere... |
12:28:41 | FromGitter | <bevo009> The compiler isn't really giving me clues which part(s) are wrong |
12:30:34 | FromGitter | <bevo009> I'm thinking it's "/c/h/format.cc" because it's already in quotes |
12:31:25 | FromDiscord_ | <Kiloneie> Okay this works: https://play.nim-lang.org/#ix=1RdQ |
12:31:26 | FromDiscord_ | <Kiloneie> BUT, why doesn't my previous one do anything ? |
12:32:20 | FromDiscord_ | <Shield> it can only count up |
12:32:40 | FromDiscord_ | <Shield> it fails on counting down and exists the for loop |
12:33:14 | FromDiscord_ | <Kiloneie> OH well, i guess that's why countdown exists D: |
12:54:56 | FromDiscord_ | <Shield> I'd like to confirm, is useMalloc only available for gc regions and none right? the default gc doesn't use it? |
13:05:01 | Araq | I can't remember |
13:05:19 | Araq | for emscripten it's also used or something |
13:11:13 | * | joki1337 joined #nim |
13:19:15 | * | joki1337 quit (Quit: leaving) |
13:25:02 | * | joki1337 joined #nim |
13:42:54 | FromGitter | <bevo009> Success! :D ⏎ ⏎ ```code paste, see link``` ⏎ ⏎ nim cpp -r "/c/a/nim/nimcpp/01/a4.nim" ... [https://gitter.im/nim-lang/Nim?at=5d4ec9dd4e17537f520960df] |
13:43:30 | FromGitter | <bevo009> I did some knucklehead mistakes before that though |
13:46:01 | FromGitter | <bevo009> If I wanted to add more headers, can I just comma-separate them, or does each one nead a header: line |
13:46:49 | leorize | you can {.emit.} them if you feel like it :P |
13:46:56 | leorize | typically a proc only have one header |
13:47:15 | FromGitter | <bevo009> Ok I saw that, I'll try it |
13:47:22 | leorize | so I believe the compiler is only equipped to deal with one per symbol |
13:47:31 | FromGitter | <bevo009> Thanks for the tips leorize |
13:48:40 | FromGitter | <bevo009> the {.emit would follow indented after the proc? |
13:49:21 | leorize | no, just like in C, emit at the top |
13:49:32 | Araq | don't use emit, .header support multiple lines |
13:49:37 | Araq | header: """ |
13:49:45 | Araq | #include "foo.h" |
13:49:50 | Araq | #include "bar.h" |
13:49:51 | Araq | """ |
13:50:12 | Araq | however, it's super rare that you need that since a symbol can only really be in one header |
13:53:52 | FromGitter | <bevo009> I think some features of fmt might need format.cc plus their header |
13:54:21 | FromGitter | <bevo009> I mostly use print and format though, I'll just make separate procs |
13:54:57 | FromGitter | <bevo009> Way cool that it works, once I stopped making mistakes, like compiling with c :) |
14:09:41 | FromGitter | <bevo009> ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5d4ed0254e17537f52098b2d] |
14:09:55 | FromGitter | <bevo009> That compiles, just for a test. |
14:10:02 | FromGitter | <bevo009> Thanks Arak! |
14:10:04 | FromGitter | <zacharycarter> extremely quick write up on those macros - https://gist.github.com/zacharycarter/50064c3cf93c58af1663e91e7fdce758 |
14:13:45 | FromGitter | <deech> Dumb question, how I do prevent the compiler from spitting out all those "Hint:" and "CC"" lines? Couldn't find a quiet mode in the command line switches |
14:14:20 | FromGitter | <bevo009> --verbosity:0 --hints:off |
14:14:30 | FromGitter | <deech> Thanks! |
14:14:58 | FromGitter | <bevo009> Glad to help :) |
14:17:17 | FromGitter | <bevo009> @zacharycarter so NimScript > Wren? |
14:18:15 | FromGitter | <zacharycarter> well - I haven't benchmarked NimScript vs Wren or anything like that - but NimScript is a subset of Nim so you can use the same type definitions which is nice |
14:18:44 | FromGitter | <zacharycarter> also, Wren has features I'm probably never going to use - like fibers and it's also object oriented to a degree |
14:18:59 | FromGitter | <zacharycarter> I think Wren is fine - it's just I think it's nicer to be able to leverage what Nim already has builtin |
14:19:21 | FromGitter | <alehander42> wren was by the |
14:19:46 | FromGitter | <alehander42> crafting interpeters nystrom guy right |
14:19:52 | FromGitter | <bevo009> Last time I checked you looked set to go with Wren |
14:20:00 | FromGitter | <bevo009> It looks quite good |
14:20:10 | FromGitter | <zacharycarter> well yeah - that was a few days ago |
14:20:21 | FromGitter | <zacharycarter> and I was - but then I got help from Vindaar on this macro |
14:20:33 | FromGitter | <zacharycarter> this was my main blocker from using NimScript, which was my goto |
14:20:56 | FromGitter | <zacharycarter> well actually working HCR is my goto, but until HCR has all the kinks worked out NimScript was my primary fallback |
14:21:16 | FromGitter | <zacharycarter> I did manage to figure out how to do the same thing with Wren - it's not difficult, but it's definitely more verbose than what these macros allow for |
14:22:56 | FromGitter | <alehander42> what you need is probably working nimrtl stdlib? |
14:23:12 | FromGitter | <alehander42> did you hit a purely hcr problem |
14:23:21 | livcd | when do we use #nim-offtopic ? :-) |
14:23:35 | FromGitter | <zacharycarter> I guess when you're not talking about Nim |
14:24:03 | FromGitter | <zacharycarter> @alehander42 - I was getting errors when using hcr about memory being read from beyond the top of the stack |
14:24:30 | FromGitter | <zacharycarter> it was suggested that perhaps the pointer to the top / bottom of the stack were off when HCR was in use |
14:24:38 | FromGitter | <zacharycarter> and that it's the reason HCR is blowing up for folks |
14:24:46 | shashlick | Nice work guys, this is awesome |
14:24:48 | FromGitter | <zacharycarter> but I don't know how to investigate if that's the case nor how to fix it if it is |
14:25:10 | FromGitter | <alehander42> it doesnt sound too bad but no idea if people work on it |
14:25:13 | FromGitter | <alehander42> does it have an issue |
14:27:31 | livcd | I'd like to get into gaming and making addons. Sounds like a nice hobby to have. |
14:28:12 | FromGitter | <zacharycarter> kind of - I filed an issue about the bug I was encountering while using HCR, and the Dr. Memory output I included in the issue has this error in it |
14:28:27 | FromGitter | <zacharycarter> by this error I mean an error about memory being read from beyond the top of the stack |
14:28:43 | FromGitter | <zacharycarter> but I don't think any formal investigation has gone into determining if that's actually the issue or not (pointer to top of stack being incorrect) |
14:31:08 | FromGitter | <bevo009> Is there much/any overhead or negative effect compiling to cpp rather than c? |
14:31:52 | Araq | cpp is slower to compiler but produces better code since we can map Nim's exceptions to C++'s |
14:32:37 | FromGitter | <bevo009> Order of magnitude slower to compile, or just a little? |
14:33:28 | Araq | I never noticed the difference |
14:33:38 | FromGitter | <bevo009> cool, thanks |
14:34:45 | * | clyybber joined #nim |
14:36:06 | * | nsf joined #nim |
14:36:47 | * | HP-YC9 joined #nim |
14:45:28 | * | laaron- joined #nim |
14:45:41 | * | laaron quit (Quit: ZNC 1.7.1 - https://znc.in) |
14:46:03 | * | laaron- quit (Remote host closed the connection) |
14:46:27 | * | laaron joined #nim |
14:46:49 | FromGitter | <alehander42> btw my hoby lang finally got a small c backend : i totally forgot about exceptions and the backend being cpp |
14:47:35 | FromGitter | <alehander42> which reminds me: |
14:47:44 | FromGitter | <alehander42> does nim cpp new runtime use malloc/free in c++ |
14:48:38 | * | leorize quit (Quit: WeeChat 2.4) |
14:50:46 | * | joki1337 quit () |
14:54:40 | * | rayman22201 joined #nim |
14:55:09 | * | leorize joined #nim |
14:59:09 | Araq | when you use -d:useMalloc |
15:10:43 | FromGitter | <deech> What should we use instead of `debug`? |
15:11:06 | * | NimBot joined #nim |
15:12:17 | * | solitudesf joined #nim |
15:14:20 | * | shomodj joined #nim |
15:34:44 | Araq | echo n ? |
15:37:28 | * | PMunch quit (Remote host closed the connection) |
15:38:19 | FromGitter | <deech> Yeah, sorry. I kept seeing deprecation warnings on debug but it turns out that's a false warning. |
15:48:09 | * | Trustable quit (Remote host closed the connection) |
15:48:40 | * | clyybber quit (Quit: WeeChat 2.5) |
15:50:43 | FromGitter | <deech> Araq, was disallowing variants in const a conscious design decision? |
15:53:23 | * | joshbaptiste quit (Ping timeout: 245 seconds) |
15:53:31 | * | HP-YC9 quit (Remote host closed the connection) |
15:53:42 | * | HP-YC9 joined #nim |
16:01:01 | Araq | yeah but we will allow it soon |
16:01:14 | Araq | since C got an update and does support named union fields now |
16:01:25 | Araq | though I'm not sure about C++... |
16:21:19 | * | nsf quit (Quit: WeeChat 2.4) |
16:21:26 | * | joshbaptiste joined #nim |
16:27:34 | * | vlad1777d quit (Ping timeout: 244 seconds) |
16:36:53 | * | HP-YC9 quit (Remote host closed the connection) |
16:37:04 | * | HP-YC9 joined #nim |
16:40:53 | * | sentreen quit (Ping timeout: 245 seconds) |
16:41:04 | * | endragor quit (Remote host closed the connection) |
16:46:18 | * | joshbaptiste quit (Ping timeout: 272 seconds) |
16:52:33 | Zevv | hooray, const variants! \o/ |
16:57:35 | FromGitter | <deech> At least Visual Studio seem to support them.https://docs.microsoft.com/en-us/cpp/cpp/unions?view=vs-2019#using-unions |
16:59:12 | FromGitter | <mratsim> Why is TLS emulation on by default on OSX? |
17:06:03 | Zevv | btw, given consts variants are not supported, should this not give an error instead of silently compile: https://play.nim-lang.org/#ix=1Rfo |
17:10:16 | FromGitter | <deech> Yeah, that's the same issue as the one you reported on macros. |
17:12:25 | Araq | Zevv: I fixed it in a PR but it breaks existing code |
17:12:44 | Araq | so instead we will support const object variants properly and not break the code |
17:13:36 | Zevv | that is nice |
17:13:53 | Zevv | deech: I did? :) |
17:24:06 | FromGitter | <deech> Zevv, oops I thought it was https://github.com/nim-lang/Nim/issues/11862. |
17:24:53 | FromGitter | <deech> In any case on my branch your Playground example compiles and evaluates to `0x5647643fd5a0@[[kOneone = 3], [kTwotwo = 0]]`. |
17:25:42 | * | joshbaptiste joined #nim |
17:25:52 | Zevv | exactly, it compiles but silently gives wrong results |
17:26:39 | FromGitter | <deech> Araq, the PR doesn't break all existing code, it also stops bad constructs like: `let a, b {.compileTime.} = foo()`. |
17:27:28 | Zevv | And if you change it into https://play.nim-lang.org/#ix=1Rfr you get [[kOneone = 0], [kTwotwo = 6]] :) |
17:27:34 | FromGitter | <deech> It just tries to enforce that access to compile time values at runtime has to be mediated by a const which I think is far easier to reason about especially for larger programs that lean on metaprogramming a lot. |
17:28:47 | * | lritter joined #nim |
17:28:58 | Zevv | that makes sense, would also disallow my second example probly? Assign a .compileTime. proc result to a let |
17:30:02 | FromGitter | <deech> Yeah if it gets merged you'd need to do `let a {.compileTime.} = newThings(); const A = a`. |
17:30:11 | * | joshbaptiste quit (Ping timeout: 268 seconds) |
17:31:05 | FromGitter | <deech> But still it wouldn't work in your particular case as object variants don't currently cross over from compile to runtime even in my PR. |
17:32:08 | Zevv | sure |
17:32:35 | FromGitter | <deech> Remove the discriminators and it'll work, you would also be able to do just: `const A = newThings()`. |
17:32:50 | Zevv | of course, that would be the way to go. |
17:34:32 | Zevv | I've been fiddling with this over the last few days with some help from #nim, but I'm still not where I want to be. I now manually ast-ize my data structures to be able to get them into a const, but now I need to get this const data structure back into a macro in order to generate my nim code AST from it. |
17:35:16 | Zevv | I now handle each object variant kind case specificly to generate only the allowed fields for that kind, which works although it is a bit cumbersome |
17:47:05 | * | nsf joined #nim |
17:54:44 | * | joshbaptiste joined #nim |
18:05:10 | * | sentreen joined #nim |
18:16:35 | FromGitter | <awr1> does mac os seriously not have thread-local storage |
18:18:21 | Araq | it used to lack it |
18:19:21 | FromGitter | <awr1> https://stackoverflow.com/a/29929949/10444138 |
18:19:22 | FromGitter | <awr1> hm |
18:23:02 | FromGitter | <mratsim> well hunting TLS emulation issues is a pain ... |
18:23:57 | FromGitter | <awr1> i'll have to admit i'm flying blind when it comes to any sort of macOS development, if for lack of owning a mac |
18:24:34 | FromGitter | <mratsim> I spent my afternoon fixing dumb MacOS things |
18:25:36 | FromGitter | <mratsim> 1) lack of pthread_barrier ⏎ 2) Trying to understand a bug that was in fact linked to Nim TLS while I was using raw pthread ⏎ 3) Trying to do a perf comparison with a C++ lib but realizing that the C++ stdlib on Mac is missing aligned_alloc :/ |
18:25:37 | * | HP-YC9 quit (Remote host closed the connection) |
18:26:44 | * | HP-YC9 joined #nim |
18:31:04 | Araq | OSX also has a really low limit on the number of possible threads iirc, it's garbage |
18:32:31 | FromGitter | <deech> Are there any plans for Nim green threads or does each `spawn` kick off an OS thread? |
18:33:04 | Araq | 'spawn' never did that, it schedules a task to be run on the thread pool |
18:33:14 | * | joki1337 joined #nim |
18:33:24 | FromGitter | <mratsim> you have the coro module if you want lightweight threads |
18:34:16 | FromGitter | <deech> Yes you're right, sorry, is the thread pool a set of OS threads? |
18:34:20 | * | joki1337 quit (Client Quit) |
18:34:29 | FromGitter | <mratsim> yes |
18:35:18 | FromGitter | <mratsim> If you want better lightweight threads that might be a good start: http://www.1024cores.net/home/lock-free-algorithms/tricks/fibers |
18:36:24 | FromGitter | <deech> That explains why 20,000+ calls to `spawn` ground the process to a halt. |
18:37:16 | FromGitter | <deech> I was benchmarking Nim against https://docs.rs/rayon/1.1.0/rayon/. The latter is a pretty amazing library. |
18:44:31 | FromGitter | <mratsim> rayon also uses OS threads |
18:46:18 | FromGitter | <mratsim> you can try my POC, it has a scheduler so it doesn’t swamp the OS with threads: https://github.com/mratsim/weave/blob/master/e04_channel_based_work_stealing/async_internal.nim#L155-L175 |
18:47:04 | FromGitter | <mratsim> It scales to billions of spawn https://github.com/mratsim/weave/blob/master/e04_channel_based_work_stealing/tests/fib.nim#L17 (since fibonacci is 2^n) |
18:49:41 | FromGitter | <deech> Oh very nice! |
18:49:48 | Araq | mratsim: are you aware of https://thetechsolo.wordpress.com/2016/08/28/scaling-to-thousands-of-threads/ ? |
18:58:04 | FromGitter | <deech> @mratsim Do it rely on GC? |
18:58:36 | FromGitter | <deech> s/Do/Does/ ...sigh. |
19:14:18 | FromGitter | <zacharycarter> anyone know how I pretty print w/ nim-gdb? |
19:15:47 | FromGitter | <zacharycarter> nevermind I just needed to look at the python source |
19:31:16 | FromGitter | <zacharycarter> Hmm having trouble getting it working on windows, doh well |
19:35:56 | FromGitter | <mratsim> @deech no no GC |
19:36:13 | * | joki1337 joined #nim |
19:37:11 | FromGitter | <mratsim> @Araq no but it’s about threads for blocking IO while I’m doing things for compute |
19:39:21 | FromGitter | <zacharycarter> attempting to look more into the hcr issue |
19:42:12 | * | joki1337 quit () |
19:43:15 | FromGitter | <zacharycarter> gdb apparently doesn't like windows paths though and won't resolve the nim-gdb.py file location |
19:49:25 | * | HP-YC9 quit (Remote host closed the connection) |
19:49:34 | * | HP-YC9 joined #nim |
19:54:56 | * | HP-YC9 quit (Remote host closed the connection) |
19:55:04 | * | HP-YC9 joined #nim |
19:55:54 | * | clyybber joined #nim |
19:56:20 | * | HP-YC9 quit (Remote host closed the connection) |
19:56:43 | * | nif quit (Quit: ...) |
19:56:54 | * | nif joined #nim |
19:58:35 | FromGitter | <zacharycarter> I got it working - first thing I notice in relation to the issue I posted is that `failedAssertImpl_W9cjVocn1tjhW7p7xohJj6A` is not in the `modules` table in nimhcr which makes sense based on the error I'm getting. so it looks like `hcrRegisterProc` is never getting called for `failedAssertImpl` |
19:59:24 | * | HP-YC9 joined #nim |
20:06:51 | Zevv | you fixed your hcr problem? |
20:09:49 | FromGitter | <zacharycarter> no - I'm just looking more into it |
20:10:15 | FromGitter | <zacharycarter> I'm now trying to do - `discard nimhcr.hcrRegisterProc("""C:\Users\carte\nimcache\demo_d/stdlib_assertions.nim.c.dll""", "failedAssertImpl_W9cjVocn1tjhW7p7xohJj6A", failedAssertImpl)` in my program because this is the lookup into the `modules` table that nimhcr is failing on - but that doesn't work either |
20:12:14 | Zevv | you should ask Zah I guess |
20:13:10 | clyybber | or onqtam when he's here |
20:14:10 | FromGitter | <zacharycarter> yeah - I"m guessing when `hcrRegisterProc` is called in the C codegen - it's not getting called for this particular proc |
20:14:59 | Zevv | I tried to look in to this a few weeks ago, but I quickly got lost |
20:15:09 | * | krux02 joined #nim |
20:15:53 | FromGitter | <Varriount> @mratsim I'm somewhat skeptical of that post... From what I've seen, as the number of threads go up, the number of context switches increase, which cause more and more time to be wasted pausing one thread and resuming another. |
20:18:31 | FromGitter | <Varriount> Additionally, you have problems like this: https://web.archive.org/web/20150214094736/https://corbinsimpson.com/entries/take-a-bow.html |
20:21:10 | FromGitter | <mratsim> which post? |
20:21:40 | FromGitter | <mratsim> the one from the techsolo? |
20:24:12 | FromGitter | <mratsim> I’m not sure, their techniques require changing the ulimit of threads. Also it rely on the kernel thread scheduler which uses fair scheduling and optimizes for latency. In userspace often it makes more sense to optimize for throughput |
20:24:20 | FromGitter | <mratsim> (well maybe not for a web server) |
20:25:17 | FromGitter | <zacharycarter> hmm it looks like normally when `hcrGetProc` is called there is a check preceding the invocation that checks `isReloadable` - but there is one place where `hcrGetProc` is called that this check is absent from |
20:25:45 | FromGitter | <zacharycarter> I'm checking now to see whether `failedAssertImpl` passes the `isReloadable` check - if it doesn't I will add that `isReloadable` check and see what happens |
20:33:48 | FromGitter | <zacharycarter> well - it does pass the check so hmm |
20:42:07 | * | kungtotte quit (Quit: WeeChat 2.5) |
20:42:50 | FromGitter | <zacharycarter> actually it doesn't pass the check |
20:43:17 | FromGitter | <zacharycarter> because I guess for the module it's being called for `hcrOn` is set to false |
20:43:45 | FromGitter | <mratsim> Were case object with a bool instead of an enum tested @Araq? ⏎ ⏎ ```code paste, see link``` [https://gitter.im/nim-lang/Nim?at=5d4f2c81d03a7c63e6050d0e] |
20:47:42 | clyybber | mratsim: A bool is an enum, so they should have been |
20:52:06 | * | HP-YC9 quit (Remote host closed the connection) |
20:52:14 | * | HP-YC9 joined #nim |
21:01:00 | krux02 | bool is not 100% enum |
21:01:28 | krux02 | internally it is of type ``tyBool`` not ``tyEnum`` therefore it is different |
21:04:15 | clyybber | krux02: May I ask why it is that way? |
21:04:20 | clyybber | Because of if ? |
21:04:44 | krux02 | might be |
21:20:48 | * | Vladar quit (Remote host closed the connection) |
21:25:03 | * | HP-YC9 quit (Remote host closed the connection) |
21:25:11 | * | HP-YC9 joined #nim |
21:29:46 | * | HP-YC9 quit (Remote host closed the connection) |
21:29:55 | * | HP-YC9 joined #nim |
21:33:55 | FromDiscord_ | <Shield> and suddenly, regions works as expected, you don't need the a=a hack, if A belongs to region X, and B belongs to region Y, then all you need to do is to call A = B in region X while it's nested in region Y |
21:34:41 | FromDiscord_ | <Shield> I'm seeing weird memory usage, but that may be due withRegion copying MemRegion |
21:35:39 | FromDiscord_ | <Shield> also you should either expose tlRegion or do everything you need in your own (call it Main if you want) |
21:36:52 | FromDiscord_ | <Shield> this is better than trying to rewrite stdlib to take an optional MemRegion argument for every object |
21:40:31 | FromDiscord_ | <Shield> the real trick here is how to avoid polluting main region without deallocating the whole region, since even an echo causes a bunch of strings to live forever in your current Memregion |
21:41:05 | FromDiscord_ | <Shield> any ideas? |
21:46:19 | * | joshbaptiste quit (Ping timeout: 246 seconds) |
21:51:04 | Araq | mratsim: tested for what? they were used in sockets for years |
21:57:35 | FromGitter | <mratsim> just wanted to know if it was possible to use them |
22:02:26 | rayman22201 | @shield: sorry, I had to take off last night. Glad you got regions working. Was a bug fix / PR required to fix it? |
22:06:08 | rayman22201 | @Shield: I would probably not ever use the main region. I would always define explicit regions, and switch between them often. One of the quirks of regions is that you have to be careful / explicit about the active region. This is either a disadvantage or an advantage depending on how you feel about that. |
22:08:14 | rayman22201 | on a tangent, I hate to say it, because I like gc:regions, but you should try newruntime. It is newer and more experimental, but it's more actively developed, so you may get better support from the core devs. |
22:09:06 | FromGitter | <zacharycarter> okay - found out some more information about the HCR error I encountered around `failedAssertImpl` |
22:11:00 | FromGitter | <zacharycarter> in `cgen.nim` there is a proc: `genProcNoForward` - inside this proc C code is generated to call `hcrGetProc` for `failledAssertImpl`. Prior to this code being generated, there is a check for: `isReloadable` which takes in the module the symbol resides in as well as the symbol itself |
22:11:23 | * | solitudesf quit (Ping timeout: 268 seconds) |
22:11:52 | FromGitter | <zacharycarter> when this is called for let's say `system.nim` the check fails because inside `isReloadable` the module is checked to see if `hcrOn` is true / false. if it is false then `isReloadable` will in turn return false |
22:13:09 | FromGitter | <zacharycarter> however, this proc gets called for `failedAssertImpl` with the main module that I'm compiling, and `hcrOn` is set to true there - thus a `hcrGetProc` call is generated however `hcrRegisterProc` was never called for `failedAssertImpl` |
22:19:24 | * | joshbaptiste joined #nim |
22:22:14 | FromDiscord_ | <Shield> @rayman22201 I need some clear documentation to know how to handle newruntime |
22:24:04 | * | joshbaptiste quit (Ping timeout: 244 seconds) |
22:27:07 | FromDiscord_ | <Shield> I'm spending time on regions because I want full control on what to deallocate and what to keep without going full manual, and with a little function you can add partial deallocation, this would be amazing for a realtime app |
22:27:34 | FromDiscord_ | <Shield> yes a PR/fix was required |
22:28:36 | FromDiscord_ | <Shield> now I have 2 problems, if stdlib does any funny allocations, that will be unaccounted for, which happens to be true |
22:29:07 | * | joshbaptiste joined #nim |
22:29:50 | rayman22201 | Those funny allocations in the stdlib may be bugs, but IDK if you want to spend time to track that down. |
22:30:16 | FromDiscord_ | <Shield> the second problem is, I'm running a test and the program is reserving a minimum memory that isn't shown with the getTotalMem or any other function, I'm not sure why |
22:30:38 | FromDiscord_ | <Shield> but at least that memory gets reused so it's not that bad |
22:30:40 | FromGitter | <zacharycarter> https://github.com/nim-lang/Nim/blob/devel/doc/destructors.rst |
22:30:42 | FromGitter | <zacharycarter> might help |
22:31:10 | rayman22201 | also this: https://github.com/nim-lang/RFCs/issues/144 |
22:31:18 | FromDiscord_ | <Shield> I still see the potential in regions |
22:31:34 | * | shomodj quit (Quit: My MacBook has gone to sleep. ZZZzzz…) |
22:31:40 | rayman22201 | newruntime is a cross between (a better version of) C++ uniquePtr and the Rust borrow checker. |
22:32:12 | rayman22201 | newruntime will also have better stdlib support, since Araq is putting a lot of time into it. |
22:32:49 | rayman22201 | The documentation is definitely not good yet (but it's not good for regions either) |
22:33:08 | Araq | I'm updating the spec while you're talking :P |
22:33:16 | FromDiscord_ | <Shield> @zacharycarter thanks, I'll give it a read |
22:33:44 | Araq | I consider regions to be a deadend because the memory overhead can easily be a factor of 2 or more |
22:34:27 | FromDiscord_ | <Shield> but doesn't newruntime do automatic deallocation when the lifetime of an object ends? what if you want to defer deallocation or do it in chunks? |
22:34:49 | rayman22201 | That's what pools are for. The same thing you would do in any language. |
22:35:21 | FromGitter | <zacharycarter> np |
22:35:52 | Araq | well you can use regions, destructors are the most flexible tool, make subobject destructors trivial and use the region's destructor to free multiple objects in one go |
22:36:13 | Araq | so we are getting the most flexible tool and you can pick your poison. |
22:37:11 | rayman22201 | The lifetime of an object is tied to it's a parent. So you make a pool (or "region" :-P) that hands out objects, then destroy it when you are done. The destructor will make sure child objects are properly freed as well. |
22:37:25 | FromDiscord_ | <Shield> which poison will be less deadly with stdlib tho? 😛 |
22:37:53 | FromGitter | <zacharycarter> @onqtam - whenever you are next around, if you could ping me about an HCR issue (if you still ever work on it) I would appreciate it! |
22:38:19 | Araq | Shield: stdlib is betting on --newruntime |
22:39:24 | FromDiscord_ | <Shield> I see, is there a way to ref/unref something? how can you extend the life of an object? |
22:39:52 | clyybber | Araq: In the new spec can you leave the possibility open to change where destructors get inserted? As in at the end of proc vs end of scope vs end of branch? |
22:40:13 | clyybber | Oh god english |
22:40:14 | Araq | clyybber: that's already part of the spec |
22:40:25 | Araq | and I only change the =sink vs =move wordings |
22:40:44 | Araq | well |
22:40:53 | FromDiscord_ | <Shield> well, if it works across dlls, I'm all for it |
22:40:54 | Araq | we have end of scope vs end of proc. |
22:41:30 | clyybber | Araq: Ok |
22:41:33 | Araq | Shield: GC_ref/unref will be available, we need it for async |
22:41:58 | clyybber | Araq: Btw, how about not disallowing x = x but just making it a no-op? |
22:42:30 | Araq | clyybber: yeah, good point |
22:42:39 | clyybber | And for cases where we can't prove there will be no self assign just wrap the `=move`/`=` in an if clause |
22:42:42 | Araq | could be useful for template expansions |
22:43:15 | Araq | clyybber: the plan is to not use =sink but = for potential self assignments |
22:44:37 | clyybber | Araq: Yeah, but wdyt about just wrapping =sink in an if statement and clarifying in the spec that all self assignments are no-ops? |
22:47:42 | Araq | how would that look like? |
22:48:47 | Araq | tbh my 'select' example works with --newruntime and I'm not sure why |
22:48:55 | clyybber | var x = someFunctionThatMightReturnOneOfItsSinkArguments(x, y) |
22:49:04 | clyybber | would get transformed to: |
22:49:19 | clyybber | var :temp |
22:49:36 | clyybber | :temp = someFunctionThatMight... |
22:49:45 | clyybber | if x != :temp: |
22:49:53 | Araq | `=sink`(x, select(true, |
22:49:53 | Araq | let blitTmp = x |
22:49:53 | Araq | wasMoved(x) |
22:49:55 | Araq | blitTmp, |
22:49:58 | Araq | let blitTmp = y |
22:49:59 | Araq | wasMoved(y) |
22:50:01 | Araq | blitTmp)) |
22:50:03 | Araq | is what the compiler produces for |
22:50:10 | Araq | x = select(true, x, y) |
22:50:18 | Araq | so ... it "just" works |
22:50:33 | clyybber | Araq: What is :temp? |
22:50:55 | clyybber | We gotta make sure select is only executed once |
22:51:09 | Araq | look at the transformed code |
22:51:14 | Araq | it is only called once |
22:51:23 | clyybber | But what is :temp? |
22:51:47 | Araq | there is no :temp |
22:52:09 | Araq | there are temps for x and y but the transformation is so clever (?) that it works out |
22:52:16 | clyybber | Oh, damnit, I mentally concatenated my code and your code |
22:52:51 | clyybber | Araq: Ah, thats due to cooldomes destructiveMoveVar |
22:53:12 | Araq | so what... it works |
22:54:21 | Araq | Shield: yes it works better with DLLs. And with web assembly. And for Python and C++ interop. |
22:55:52 | Araq | we solved every problem. We can even have good compat with a tracing GC technology. |
22:56:28 | clyybber | Araq: Lets assume x is pointing to some resource. The `=sink` call without a check for self assignment will still `=destroy` x and then perhaps the x will point at null? |
22:59:57 | clyybber | Wait, but we do have self assign checks in =sink |
23:01:51 | * | nsf quit (Quit: WeeChat 2.4) |
23:05:06 | clyybber | Araq: Wait, it "just works".. But that also means we leak. |
23:05:19 | clyybber | The above case leaks |
23:05:54 | clyybber | Because either the resource pointed at by `y` or by `x` will not get destroyed |
23:06:29 | clyybber | Assuming wasMoved nils its argument |
23:06:35 | Araq | it's late but I removed the builtin self-checks and it still works |
23:06:49 | Araq | for reasons that escape me, oh wait |
23:06:58 | Araq | string literals are never freed, ugh. |
23:07:11 | clyybber | Yeah. |
23:07:44 | * | stefanos82 quit (Quit: Quitting for now...) |
23:08:51 | clyybber | Araq: Well, so WDYT about moving the self-check out of `=sink` and to an if case encapsulating `=sink` when there is a potential self assign? |
23:09:47 | Araq | so far everything I tried works |
23:10:04 | Araq | remember that 'sink' parameters are destroyed inside 'select' too, so nothing leaks |
23:11:08 | clyybber | Araq: How can sink parameters be destroyed inside select? |
23:11:21 | clyybber | I thought you want the caller responsible for destroying? |
23:11:30 | Araq | for =move, yes. |
23:11:40 | Araq | for =sink the design was different |
23:12:19 | clyybber | Araq: It works because even when you =sink a string literal, it stays a string literal. So you have to `=` to get a non-literal string. |
23:12:41 | Araq | I did 'var x = "abc" & param' now |
23:12:56 | Araq | no literal strings, no crashes, no leaks. |
23:13:03 | clyybber | Araq: But that can only work when we have branch or in this case scope based destructor injection. So I dont get why it works now. |
23:13:38 | clyybber | Araq: Ugh, your branch doesn't have move for strings yet, right? |
23:13:52 | Araq | because inside 'select' there are also 'wasMoved' calls |
23:14:03 | Araq | as well as destructor injections |
23:14:10 | Araq | so that it works out |
23:14:16 | clyybber | Araq: But the destructors are injected at the end of the proc right? |
23:14:21 | Araq | yes |
23:14:27 | * | Jesin quit (Quit: Leaving) |
23:14:31 | clyybber | So we destroy x even when we return it |
23:14:49 | Araq | when we return it, it is 'wasMoved' |
23:14:59 | clyybber | Oh |
23:15:01 | Araq | so we disarm its destructor |
23:15:03 | clyybber | Nice haha |
23:15:18 | Araq | and that's why everything works out. |
23:15:27 | Araq | and devel DOES move strings already |
23:15:35 | Araq | how do you think these bugs got reported? |
23:15:38 | Araq | :P |
23:15:42 | clyybber | Hehe |
23:15:46 | Araq | but I need to sleep now, good night. |
23:15:50 | clyybber | Good night |
23:16:09 | * | clyybber quit (Quit: WeeChat 2.5) |
23:16:35 | * | krux02_ joined #nim |
23:16:53 | * | Jesin joined #nim |
23:19:31 | * | ng0 quit (Quit: Alexa, when is the end of world?) |
23:19:39 | * | clyybber joined #nim |
23:19:53 | clyybber | Araq: Ugh, if you are still here, I found an issue |
23:20:08 | Araq | yes? |
23:20:47 | clyybber | In the caller scope, we still need to `=destroy` x or y |
23:20:52 | * | krux02 quit (Ping timeout: 272 seconds) |
23:21:08 | FromGitter | <zacharycarter> is it possible to iterate over an objects fields inside a template - or can you only do this in a macro? |
23:21:43 | clyybber | Araq: And either we generate wasMoved(x), wasMoved(y) at the callsite, causing a leak |
23:21:50 | clyybber | or we dont, and we get a double free |
23:22:00 | Araq | look at what I wrote |
23:22:05 | clyybber | Because sink parameters aren't passed by reference |
23:22:15 | Araq | we produce wasMoved(x), wasMoved(y) |
23:22:23 | clyybber | Araq: But that must leak? |
23:22:26 | clyybber | How the fuck |
23:22:34 | Araq | it doesn't leak. |
23:22:45 | clyybber | Ah |
23:22:56 | Araq | both x and y's ownership is transferred to 'select' |
23:22:58 | clyybber | Because wasMoved(x) gets called before assigning to x |
23:23:01 | clyybber | I got it |
23:23:14 | Araq | yeah, it's super tricky |
23:23:23 | clyybber | Araq: Haha, looks like cooldome solved all problems before we even realized :D |
23:23:28 | Araq | I'm not sure it always works |
23:23:42 | Araq | hey, I also wrote this code :P |
23:24:14 | clyybber | Araq: Oh, right. The destructiveMoveVar isn't even needed |
23:24:40 | clyybber | then you solved problems before you wrongly realized they were there :D |
23:25:15 | Araq | well good night |
23:25:23 | clyybber | Good night |
23:25:35 | * | clyybber quit (Quit: WeeChat 2.5) |
23:33:10 | * | steshaw_ joined #nim |
23:36:58 | * | steshaw_ quit (Client Quit) |
23:37:25 | * | steshaw_ joined #nim |
23:45:48 | FromDiscord_ | <Shield> >Objects that contain pointers that point to the same object are not supported by Nim's model |
23:45:48 | FromDiscord_ | <Shield> is that a feature or a bug |
23:58:29 | FromGitter | <Varriount> Shield: what do you mean? |