00:00:09 | disruptek | varriount: i thought about it and i think you could do that builder pattern with a global, maybe. |
00:01:34 | disruptek | i can't quite figure it out, though. |
00:02:42 | disruptek | i was trying to make a twice: that's similar to once: but executes only the second time through. but i'm failing, so i guess it's not what i thought it was. |
00:04:05 | * | SenasOzys quit (Ping timeout: 240 seconds) |
00:07:38 | FromDiscord | <Varriount> disruptek: A "twice"? |
00:25:25 | * | krux02_ quit (Remote host closed the connection) |
00:31:26 | disruptek | it's similar to once: |
00:33:35 | * | aenesidemus_ quit (Read error: Connection reset by peer) |
00:42:37 | * | Vladar quit (Remote host closed the connection) |
00:59:41 | * | Tlongir joined #nim |
01:11:48 | * | apahl quit (Ping timeout: 244 seconds) |
01:13:57 | * | apahl joined #nim |
01:18:24 | * | maier joined #nim |
01:23:38 | * | maier quit (Ping timeout: 264 seconds) |
01:28:52 | * | Tongir joined #nim |
01:30:52 | * | NimBot joined #nim |
01:31:24 | * | Tlongir quit (Ping timeout: 256 seconds) |
02:00:04 | * | audiofile quit (Quit: Default Quit Message) |
02:28:14 | * | vicfred_ joined #nim |
02:28:53 | * | voltist6 joined #nim |
02:30:49 | * | vicfred quit (Ping timeout: 264 seconds) |
02:30:49 | * | voltist quit (Ping timeout: 264 seconds) |
02:30:50 | * | voltist6 is now known as voltist |
02:58:57 | * | muffindrake quit (Ping timeout: 260 seconds) |
02:59:26 | FromDiscord | <tomck> Is there any way to import a module with parameters? |
02:59:30 | FromDiscord | <tomck> I have some code which uses a Table |
02:59:39 | FromDiscord | <tomck> but for testing purposes, it's convenient to use an OrderedTable instead |
02:59:55 | FromDiscord | <tomck> for the actual implementation, though, it works better without ordering |
03:00:15 | FromDiscord | <tomck> So can i declare a type to use 'by default', and allow the test code to change that? |
03:00:25 | FromDiscord | <tomck> what's the 'nim way' to accomplish this? |
03:01:10 | * | muffindrake joined #nim |
03:02:06 | leorize | @tomck a type alias would be a good bet |
03:02:18 | FromDiscord | <tomck> yes, can i alter that on import though? |
03:02:36 | leorize | ah, then you can't |
03:02:51 | FromDiscord | <tomck> sent a code paste, see https://play.nim-lang.org/#ix=2t0Y |
03:03:09 | FromDiscord | <tomck> sent a code paste, see https://play.nim-lang.org/#ix=2t0Z |
03:03:20 | FromDiscord | <tomck> (edit) 'https://play.nim-lang.org/#ix=2t0Z' => 'https://play.nim-lang.org/#ix=2t10' |
03:03:25 | leorize | what are you trying to do, though? |
03:03:34 | leorize | and no, we don't support that |
03:04:14 | FromDiscord | <tomck> i have some code which uses a TAble |
03:04:22 | FromDiscord | <tomck> but for testing, it's better to use an OrderedTable |
03:04:35 | FromDiscord | <tomck> since then i get deterministic output given the same input |
03:04:47 | FromDiscord | <tomck> (whereas with a Table it's not defined what order you loop over the keys) |
03:05:01 | FromDiscord | <tomck> but i don't want to make my implementation use an OrderedTable just so that it's convenient to test |
03:05:33 | leorize | I would advice against that sort of testing |
03:05:45 | FromDiscord | <tomck> what do you mean |
03:05:59 | leorize | since with that you're basically testing if your implementation work correctly when you use OrderedTable |
03:06:08 | FromDiscord | <tomck> i'm fine with that |
03:06:18 | leorize | if you want to use Table in practice, you should test with Table instead |
03:06:30 | FromDiscord | <tomck> yes, but it makes it basically impossible to test that |
03:06:42 | leorize | what exactly are you testing? |
03:06:46 | FromDiscord | <tomck> b/c the output it produces is ordered |
03:07:02 | FromDiscord | <tomck> i mean, it shouldn't matter, but a JS code generator for some IR i have |
03:07:12 | FromDiscord | <tomck> So i have some IR, and i want to generate javascript |
03:07:40 | FromDiscord | <tomck> It spits out function declarations + other code |
03:07:58 | FromDiscord | <tomck> with a Table, the order of these function declarations is undefined - which is fine in practice |
03:09:45 | leorize | yes? |
03:09:57 | FromGitter | <wltsmrz> I'm trying to achieve something like this: https://play.nim-lang.org/#ix=2t11 |
03:10:05 | FromDiscord | <tomck> that's it |
03:10:11 | FromGitter | <wltsmrz> Except that I don't want to err on compile if thing() isn't actually used |
03:10:22 | FromGitter | <wltsmrz> Is there a convenient way to replace the function body with {.fatal.} ? |
03:10:47 | FromDiscord | <tomck> the order is undefined which is fine in practice, but for when i want to test, it's pretty much impossible to verify without re-parsing the javascript & doing some really complex assertions |
03:11:11 | FromDiscord | <tomck> the javascript it produces runs the same though, regardless of function order |
03:11:16 | FromDiscord | <tomck> it's just a different string |
03:12:12 | leorize | so basically you wanted to verify that the IR produces the same JS everytime? |
03:13:59 | leorize | @wltsmrz looks like you found an overflow within the compiler with that snippet, please report :) |
03:16:21 | FromGitter | <wltsmrz> I'm not sure.. in my particular case, the function is imported from C and then I'd get a fatal error regardless of whether it's used (pretty sure). This may be normal behavior |
03:17:39 | leorize | https://play.nim-lang.org/#ix=2t13 |
03:17:46 | * | cyraxjoe quit (Quit: I'm out!) |
03:17:49 | leorize | it's not a normal behavior :) |
03:19:20 | * | maier joined #nim |
03:20:41 | * | cyraxjoe joined #nim |
03:24:19 | * | maier quit (Ping timeout: 246 seconds) |
03:26:56 | * | sagax quit (Excess Flood) |
03:27:49 | * | hecanjog quit (Ping timeout: 264 seconds) |
03:28:16 | * | hecanjog joined #nim |
03:28:24 | FromDiscord | <tomck> leorize: yes, but when actually running i don't care about trivial things like order of the functions |
03:34:06 | * | vicfred_ quit (Quit: Leaving) |
03:58:27 | * | oprypin quit (Ping timeout: 260 seconds) |
03:59:04 | * | oprypin joined #nim |
04:06:01 | * | supakeen quit (Quit: WeeChat 2.8) |
04:06:41 | * | supakeen joined #nim |
04:06:58 | * | lritter joined #nim |
04:07:47 | FromDiscord | <Zachary Carter> tomck: you could use a define when compiling your tests and check that in the module |
04:09:41 | FromDiscord | <Zachary Carter> but uh - I agree with leorize - it'd be better to test with the actual data structure you plan on using in a non-test path and figure out how to adapt your test case |
04:10:11 | FromDiscord | <Zachary Carter> I can't imagine it being that difficult - couldn't you just sort the entries in the table before performing your checks? |
04:11:59 | shashlick | @Rika - https://github.com/zedeus/nimagemagick/pull/1 |
04:12:00 | disbot | ➥ Upgrade to latest nimterop |
04:15:31 | FromDiscord | <tomck> @Zachary Carter no, the sorting is all within the implementation, it just accepts some IR and spits out a string |
04:15:36 | FromDiscord | <tomck> How does a define work? |
04:15:51 | FromDiscord | <Zachary Carter> `nim c -d:yourDefineHere test.c` |
04:16:42 | FromDiscord | <Zachary Carter> sent a code paste, see https://play.nim-lang.org/#ix=2t1a |
04:17:05 | FromDiscord | <Zachary Carter> (edit) 'test.c`' => 'test.nim`' |
04:17:48 | FromDiscord | <Zachary Carter> you could also potentially use a template |
04:19:36 | FromDiscord | <tomck> cool, i didn't know that - can i define stuff within nim, before importing? |
04:20:05 | leorize | you can, but it won't work like you'd expect |
04:20:08 | leorize | nim is not C :P |
04:21:05 | FromDiscord | <Zachary Carter> I'd use templates if you want to do things similar to what you'd use C's preprocessor directives for |
04:21:50 | * | narimiran joined #nim |
04:22:29 | FromDiscord | <tomck> how do i define stuff within nim? will it work with an include? |
04:22:44 | FromDiscord | <tomck> or how can i use templates to do that? |
04:22:49 | leorize | {.define: symbolHere.} |
04:22:58 | leorize | use it as a statement |
04:23:12 | leorize | it's only undeprecated on latest devel |
04:24:46 | FromDiscord | <tomck> sent a code paste, see https://play.nim-lang.org/#ix=2t1c |
04:25:15 | * | vicfred joined #nim |
04:25:16 | leorize | only if you import tables before the include |
04:25:18 | leorize | but yes |
04:26:55 | FromDiscord | <tomck> brill, thanks |
04:28:07 | leorize | I'm a bit skeptical of the way you do tests |
04:28:33 | leorize | but if it works, it works I guess |
04:29:33 | FromDiscord | <tomck> it's in a separate file, built as a separate binary, idc about dodginess when it's so constrained to a single file |
04:30:43 | FromDiscord | <tomck> plus the whole orderedtable/table thing might result in some really niche errors that get passed the test, but it's way better than nothing, and the alternative is to introduce a bunch more complexity / maybe even a javascript parser, which is gonna need its own set of tests |
04:33:55 | FromDiscord | <tomck> this include thing seems to work, that's cool |
04:34:00 | FromDiscord | <tomck> nim's pretty expressive turns out# |
04:34:08 | FromDiscord | <Zachary Carter> sent a code paste, see https://paste.rs/D4C |
04:34:16 | FromDiscord | <Zachary Carter> err you don't need the dirty |
04:34:41 | FromDiscord | <Zachary Carter> (edit) 'https://play.nim-lang.org/#ix=2t1g' => 'https://play.nim-lang.org/#ix=2t1f' |
04:35:14 | FromDiscord | <tomck> how does MyTable get into the module i'm testing? i don't understand |
04:35:59 | FromDiscord | <Zachary Carter> I was just showing how you could vary the type definition at compile time |
04:36:30 | FromDiscord | <Zachary Carter> not solving the import issue - you'd have to import or include that module |
04:36:53 | FromDiscord | <Zachary Carter> and if you rely on import the symbol needs to be exported |
04:38:57 | voltist | Hmm interesting messages from Freenode "voltist6 is not a registered nickname ... You're now known as voltist" |
04:39:03 | voltist | I never changed my nick |
04:39:28 | FromDiscord | <Zachary Carter> do you have six sessions open in freenode? |
04:39:38 | FromDiscord | <Zachary Carter> if someone already has your nick it will just append a number to it I think |
04:39:51 | FromDiscord | <Zachary Carter> (edit) 'if someone ... already' => 'if someonelogged in' |
04:40:00 | FromDiscord | <Zachary Carter> anyways - back to vulkan stuff |
04:40:07 | voltist | Huh, interesting |
04:40:19 | * | vicfred quit (Quit: Leaving) |
04:40:36 | voltist | I'm logged in 24/7 so must be someone else trying to connect |
04:46:45 | silvernode[m] | is there a way to have getAppFilename() to not return the full path and instead only print the name of the file? |
04:47:32 | FromDiscord | <Zachary Carter> you can call splitPath on it |
04:47:58 | FromDiscord | <Zachary Carter> https://nim-lang.org/docs/os.html#splitPath%2Cstring |
04:48:46 | silvernode[m] | <FromDiscord "<Zachary Carter> you can call sp"> I figured I'd have to go that route, thanks for the reply. |
04:50:38 | FromDiscord | <Zachary Carter> np |
05:02:10 | leorize | either way a splitPath() would have to be done, since getAppFilename() get the data from the OS, which is usually a full path |
05:16:43 | * | zacts joined #nim |
05:20:11 | * | maier joined #nim |
05:24:35 | * | sagax joined #nim |
05:25:30 | * | maier quit (Ping timeout: 256 seconds) |
05:31:12 | * | apahl quit (Ping timeout: 260 seconds) |
05:31:35 | * | maier joined #nim |
05:32:16 | * | apahl joined #nim |
05:32:45 | voltist | Is there a proc to check the system bitdepth for ints? |
05:51:20 | * | solitudesf joined #nim |
05:52:49 | FromDiscord | <lqdev> @Zachary Carter in your example, the if should be a when because you can't use if with types |
05:53:29 | FromDiscord | <Zachary Carter> in which example? |
05:54:07 | FromDiscord | <lqdev> the one with createTableImpl above |
05:54:12 | FromDiscord | <Zachary Carter> well it works and compiles |
05:54:20 | FromDiscord | <Zachary Carter> I'm not defining any type in the template |
05:54:20 | FromDiscord | <lqdev> oh? |
05:54:31 | FromDiscord | <lqdev> that's kind of weird |
05:54:47 | FromDiscord | <lqdev> the template expands to an if statement no? |
05:54:50 | FromDiscord | <Zachary Carter> but yes you could do that to when |
05:55:11 | FromDiscord | <Zachary Carter> (edit) 'to when' => 'too with `when`' |
05:55:48 | FromDiscord | <Zachary Carter> oh yeah - you're right sorry |
05:56:08 | FromDiscord | <Zachary Carter> and does expand to a conditional |
05:56:15 | FromDiscord | <Zachary Carter> I'm sleepy |
05:56:36 | FromDiscord | <Zachary Carter> but I don't think it matters - I don't think that person is going to use a template 🙂 |
05:57:03 | FromDiscord | <lqdev> sure thing, just pointing out a thing i noticed :) |
05:58:08 | FromDiscord | <Zachary Carter> yeah - thanks for doing that just in case I confused anyone else haha |
06:26:56 | * | zacts quit (Ping timeout: 246 seconds) |
06:30:12 | * | PMunch joined #nim |
06:49:05 | * | Vladar joined #nim |
06:49:18 | * | Vladar quit (Client Quit) |
06:50:03 | * | Vladar joined #nim |
07:01:04 | * | endragor joined #nim |
07:05:48 | Prestige | PMunch: welcome back |
07:06:15 | Prestige | Btw the day you left, I added the hot config reloading into nimdow |
07:18:24 | PMunch | Oh cool |
07:18:34 | PMunch | Guess I'll have to daily drive it then as I promised :) |
07:18:42 | PMunch | And thanks for the welcome :) |
07:21:25 | FromGitter | <alehander92> wow PMunch is alive |
07:21:26 | Prestige | There are some issues with programs I don't really use, been working on solving those problems |
07:21:36 | PMunch | alehander92, hooray! |
07:22:14 | Zevv | hee the munch is back! |
07:22:20 | FromGitter | <alehander92> did you go to russia or somethjing |
07:22:32 | FromGitter | <alehander92> did you fight a war |
07:22:46 | FromDiscord | <Rika> 😮 pmunch is back |
07:24:18 | PMunch | Haha, no I just went on vacation |
07:24:35 | PMunch | But in tents and log cabins in the mountains, so not a whole lot of internet :P |
07:29:05 | PMunch | Huh, I've got a badge on GitHub saying I've contributed code to the "Arctic code vault" neat! |
07:29:35 | PMunch | Oh nice, Nim is in the vault :) |
07:31:38 | FromGitter | <alehander92> many of your own repos |
07:31:41 | FromGitter | <alehander92> might be there as well |
07:31:42 | FromGitter | <alehander92> iirc |
07:32:25 | PMunch | I tried to figure out, but couldn't find a way to see all repos I've contributed to in the vault.. |
07:33:28 | PMunch | Ah "[...] we took a snapshot of all active public repositories on GitHub to archive in the vault." so probably quite a few of my projects then :P |
07:43:34 | Prestige | PMunch: there's a new key binding you'll want to set in the config, for hot reloading. It's all documented in the wiki |
07:55:28 | PMunch | Great, I'll look into it :) |
07:56:14 | FromDiscord | <Varriount> PMunch: Just think, all your best and worst code, conserved in the Arctic |
07:56:52 | FromDiscord | <Varriount> What will future readers think? |
07:58:27 | PMunch | Does the vault contain git blame information? |
08:00:04 | PMunch | We joke that cobolt and fortran are ancient technologies that some poor person has to maintain somewhere. Imagine being the unlucky fellow who in thousands of years finds the vault and is tasked by his job to maintain some old node infrastructure :P |
08:01:04 | FromDiscord | <Varriount> Imagine, back then people had to tell computers what to do using _written text_! |
08:02:01 | FromDiscord | <Rika> now, we just think |
08:03:15 | FromDiscord | <lqdev> 🤔 |
08:05:01 | FromDiscord | <Varriount> Nah, at some point computers will just anticipate what we want. |
08:05:27 | FromDiscord | <Varriount> Think Asimov's "I, Robot" |
08:05:46 | FromDiscord | <Varriount> Specifically, the last couple of stories. |
08:07:59 | voltist | Any ways to optimize compiled nim beyond -d:release, -d:danger, using clang or LTO? |
08:08:00 | * | sagax quit (Remote host closed the connection) |
08:08:23 | FromDiscord | <Rika> still too slow after those? or just curious? |
08:08:31 | Yardanico | voltist: clang with lto and pgo |
08:08:44 | Yardanico | also -d:release is not needed if you already have -d:danger |
08:08:46 | Yardanico | (on 1.2+) |
08:09:07 | voltist | lto and pgo with clang actually make it slower :/ |
08:09:09 | PMunch | Possibly --gc:arc as well |
08:09:17 | Yardanico | voltist: are you sure you did PGO correctly? |
08:09:38 | Yardanico | also try just PGO without LTO |
08:09:50 | voltist | I used `--cc:clang --passC:"-flto -fprofile-instr-generate" --passL:"-flto -fprofile-instr-generate"` |
08:09:56 | Yardanico | yes, that's the first step |
08:10:01 | Yardanico | and then you need to run it on your data |
08:10:04 | Yardanico | it'll generate profiling data |
08:10:09 | Yardanico | and then you compile it again with that profile data |
08:10:18 | Yardanico | https://forum.nim-lang.org/t/6295 |
08:10:56 | Yardanico | the first PGO build is slow because it's made for collecting profiling data |
08:11:10 | Yardanico | but when you use that data to make a final PGO build, it can result in much better performance |
08:11:34 | Yardanico | Nim compiler with just PGO (without LTO since PGO + LTO for some reason breaks it) gets around 15-25% perf boost |
08:11:37 | alehander92 | guys again |
08:11:41 | alehander92 | https://blog.repl.it/langjam |
08:11:53 | alehander92 | does anyone want to join ( i need to find a second mate :D ) |
08:11:59 | Yardanico | I'm not interested in creating a new language :P |
08:12:01 | Yardanico | nim is good enough |
08:12:45 | alehander92 | i mostly like the fun of designing something extreme |
08:12:54 | alehander92 | it can be a dsl |
08:12:59 | alehander92 | or something way out there |
08:13:18 | PMunch | Ooh, maybe I should submit stacklang v2 |
08:13:21 | alehander92 | (but yeah disclaimer : conflict of interest :D ) |
08:13:44 | alehander92 | PMunch the problem is they require a team of two |
08:13:56 | alehander92 | i also wanted to just do something in several days but ugh |
08:14:08 | voltist | Yardanico: Wow massive performance boost even without merging multiple runs |
08:14:12 | Yardanico | :P |
08:14:13 | voltist | Thanks for pointing that out |
08:14:18 | PMunch | I'm sure I could find someone crazy enough to co-sign my entry :P |
08:14:18 | Yardanico | how much roughly? |
08:15:02 | voltist | About 40% |
08:15:10 | Yardanico | nice |
08:15:13 | voltist | From one test |
08:15:17 | Yardanico | and people ask "why nim compiles to C?" :P |
08:15:27 | Yardanico | yeah, if you have a lot of different datasets, it's better to run the program on them all |
08:15:36 | Yardanico | run all of your tests, run the actual workload, etc |
08:15:51 | Yardanico | and based on this profiling data the compiler will actually know which functions are used the most |
08:15:55 | Yardanico | without making assumptions |
08:16:00 | Yardanico | so it could inline/etc |
08:16:05 | PMunch | Huh, how have I never heard of this before :S |
08:16:32 | voltist | That sounds like magic and I love it |
08:17:28 | Yardanico | I didn't try to do PGO with GCC since it's a bit harder |
08:17:37 | Yardanico | e.g. it outputs the profiling data in the folder with C files for some reason |
08:17:40 | Yardanico | not in the folder with the binary |
08:17:55 | Yardanico | but yeah, even Nim compiler gets 15-25% perf boost as I said |
08:18:01 | Yardanico | depending on the program it can be much more |
08:20:07 | PMunch | Could we ship a script to build that version? |
08:20:13 | Yardanico | PMunch: I have one, but it's very hackish |
08:20:27 | Yardanico | need to ask leorize :P |
08:20:37 | Yardanico | maybe we could even get nightlies with PGO lol |
08:20:52 | PMunch | Hmm, I mean the Nim compiler is already really fast. But it would be interesting, especially for things like inim, to have an even faster version. |
08:20:56 | Yardanico | https://github.com/Yardanico/nim-snippets/blob/master/compile_nim_pgo.sh I basically use arraymancer, npeg + npeg (orc), compiler + compiler (arc) to get the profiling data |
08:20:57 | voltist | What do you mean version? Like a helper for LTO and PGO? |
08:21:12 | Yardanico | voltist: no, we have binary releases of nim |
08:21:15 | Yardanico | e.g. on nightlies, etc |
08:21:20 | Yardanico | and we could compile them with PGO |
08:21:31 | voltist | Oh right |
08:21:38 | Yardanico | I also added arc to the profiling so the ARC routines are also optimized |
08:21:47 | Yardanico | like DFA/destructor injection/etc |
08:22:00 | PMunch | I tend to build with choosenim, it would be interesting if the script for building a PGO version was included so that you could build that version for yourself |
08:22:23 | Yardanico | nim c --compileOnly -d:danger tests/tests_cpu.nim with normal nim takes for me ~3.1 seconds |
08:22:26 | Yardanico | that's from arraymancer repo |
08:22:31 | voltist | I feel compelled to build myself a little helper/manager script to manage profile data and wrap commands now |
08:23:04 | Yardanico | well you can actually specify output filename for .profraw data |
08:23:31 | Yardanico | with LLVM_PROFILE_FILE env variable |
08:23:51 | PMunch | Hmm, I guess I could build a PGO version that is based on my repos |
08:24:01 | PMunch | So I would have a Nim compiler optimised for my code :P |
08:24:06 | voltist | Yeah but then merging and stuff |
08:24:11 | voltist | PMunch: :) |
08:24:29 | voltist | Opulent |
08:24:37 | PMunch | Haha :P |
08:24:59 | Yardanico | and now nim compiler with PGO, and same arraymancer command takes ~2.86s |
08:25:04 | Yardanico | it depends on the project really |
08:25:12 | Yardanico | but it is surely faster |
08:25:18 | Yardanico | for free |
08:25:34 | voltist | How does one generate data for libraries like arraymancer? |
08:25:40 | PMunch | Would be interesting to throw it a bunch of macro-heavy projects and see if you can get some improvements there |
08:25:49 | Yardanico | voltist: nonon, I didn't generate it for arraymancer |
08:25:57 | Yardanico | I used arraymancer for profiling data for the compiler |
08:26:04 | Yardanico | just compile all the tests |
08:26:09 | PMunch | voltist: https://github.com/Yardanico/nim-snippets/blob/master/compile_nim_pgo.sh#L14-L17 |
08:26:13 | Yardanico | PMunch: well maybe I should add nimly in the mix |
08:26:17 | Yardanico | it's really VM heavy |
08:26:28 | PMunch | You need a test file that uses the library to generate the profiling information |
08:26:36 | PMunch | That would be cool |
08:26:52 | PMunch | I guess the more stuff you add the less the speedup would be for a certain project |
08:26:56 | Yardanico | maybe I should just write a small Nim tool instead of this script :) |
08:26:59 | * | Vladar quit (Ping timeout: 256 seconds) |
08:27:06 | Yardanico | PMunch: well IDK, maybe not |
08:27:14 | Yardanico | I guess most of libraries have the same hot paths in the compiler |
08:27:23 | Yardanico | unless generic/concept/macro heavy |
08:27:26 | PMunch | Unless the compiler does some really silly assumptions |
08:27:33 | PMunch | Hmm, I guess that's true |
08:27:46 | PMunch | Maybe try to run it on the important packages list |
08:27:48 | voltist | So if I run the profiler on my code which uses arraymancer, then it should optimize its procs as well as long as I use them? |
08:27:57 | Yardanico | voltist: yes |
08:28:02 | voltist | Coolio |
08:28:03 | Yardanico | but you already did, no? |
08:28:22 | Yardanico | all nim libraries are compiled statically in the binary |
08:28:22 | voltist | Yep |
08:28:25 | Yardanico | so PGO will optimize everything |
08:28:32 | voltist | Right got it |
08:28:32 | Yardanico | not limited to your code |
08:28:36 | Yardanico | but also other libs or even stdlib |
08:29:23 | Yardanico | PGO is actually a very powerful thing |
08:29:28 | Yardanico | Google Chrome uses it since 2016 |
08:29:29 | PMunch | voltist, basically the compiler will do a bunch of assumptions about what parts you use the most and thus inline them or do other tricks with them. What this does is take those assumptions and replace them with actual measurements so that the compiler knows, based on your project, what the things to optimise for should be. |
08:29:48 | Yardanico | yeah, if you're developing one big project, it can help a lot |
08:29:52 | Yardanico | https://blog.chromium.org/2016/10/making-chrome-on-windows-faster-with-pgo.html |
08:29:56 | voltist | PMunch: That makes sense yeah |
08:30:10 | Yardanico | it's just that nim compiler is relatively small so we can easily compile it with PGO |
08:30:14 | voltist | I was not expecting it to be a windows thing as well? |
08:30:17 | Yardanico | compiling chrome(ium) with PGO will take hours and hours |
08:30:22 | Yardanico | voltist: it's not limited to any architecture/OS |
08:30:28 | Yardanico | https://en.wikipedia.org/wiki/Profile-guided_optimization |
08:30:35 | PMunch | Hours and hours? |
08:30:46 | PMunch | Does it have functions with millions of arguments or something? :P |
08:30:59 | Yardanico | it has millions of LOC |
08:31:13 | Yardanico | "There is support for building Firefox using PGO.[7] Even though PGO is effective, it has not been widely adopted by software projects, due to its tedious dual-compilation model." |
08:31:16 | voltist | Just a different process for compiling with pgo on windows as opposed to GNU/Linux I presume? |
08:31:20 | Yardanico | no, why? |
08:31:30 | Yardanico | well, if you use VCC the arguments will be different, sure |
08:31:44 | * | Vladar joined #nim |
08:31:44 | Yardanico | buth gcc/clang/vcc all support LTO/PGO |
08:31:49 | Yardanico | https://docs.microsoft.com/en-us/cpp/build/profile-guided-optimizations?view=vs-2019 |
08:32:03 | PMunch | Yardanico, I was just joking. My millions of arguments procedure is the only time I've seen the Nim compiler spend more than a couple minutes on compiling anything :P |
08:32:12 | voltist | Cool |
08:33:13 | Yardanico | nim compiler itself is pretty small compared to others so doing a PGO build is easier |
08:33:24 | Yardanico | also of course I showed the --compileOnly, but in reality I profile without it |
08:33:32 | Yardanico | so the C backend also gets optimized |
08:35:24 | Yardanico | but really I should probably try to investigate why PGO + LTO breaks nim compiler |
08:35:29 | Yardanico | with clang |
08:37:24 | Yardanico | also CPython can be compiled with PGO (because it really makes much more difference for interpreted languages) |
08:40:03 | Yardanico | oh hmm LTO + PGO seems to be working now, maybe it was a clang bug |
08:40:06 | Yardanico | but for some reason it's slower :P |
08:45:26 | voltist | Wow, quality star identification in a 3500x2500 image in 0.35 seconds! |
08:45:30 | FromDiscord | <kodkuce> how to write from 10..1 |
08:45:36 | voltist | PGO is my new favorite thing |
08:45:41 | FromDiscord | <kodkuce> ```↵for n in 10..0:↵ echo n ↵``` |
08:45:45 | FromDiscord | <kodkuce> does not work |
08:45:46 | PMunch | "for i in countdown(10, 1)" |
08:45:56 | FromDiscord | <kodkuce> ok |
08:46:16 | PMunch | I guess you can omit the parenthesis as well |
08:46:18 | FromDiscord | <flywind> Can I boot nim temp with command `koch temp js test.nim`? |
08:46:32 | PMunch | Or do something like "for i in 10.countdown 0" |
08:46:59 | Yardanico | @flywind yes you can do that |
08:47:01 | Yardanico | koch temp is smart |
08:47:13 | Yardanico | if you specify "js", it'll compile full compiler without -d:leanCompiler flag |
08:47:36 | Yardanico | https://github.com/nim-lang/Nim/blob/devel/koch.nim#L484 |
08:47:44 | FromDiscord | <flywind> Thanks, But I got: |
08:47:46 | FromDiscord | <flywind> D:\qqpcmgr\desktop\Nim\compiler\docgen.nim(170, 23) Error: type mismatch: got <AbsoluteDir> but expected 'AbsoluteDir = distinct string'↵FAILURE |
08:47:48 | PMunch | Yardanico, I created an issue for the leading zero in exponents thing in the tests repo you mentioned: https://github.com/iarna/toml-spec-tests/issues/4 |
08:47:49 | disbot | ➥ spec-float-5 is explicitly forbidden in the spec |
08:48:01 | Yardanico | PMunch: wdym? |
08:48:20 | Yardanico | it is supported I think |
08:48:23 | PMunch | Nope |
08:48:27 | Yardanico | @flywind that usually comes when it's using the wrong stdlib |
08:48:33 | Yardanico | I don't know the solution to this, sorry |
08:48:38 | Yardanico | maybe you can specify the other stdlib path |
08:48:40 | Yardanico | PMunch: hm |
08:48:43 | PMunch | Exponents are to be parsed as integers in TOML, and integers can't have leading zeros |
08:48:55 | PMunch | So it shouldn't be allowed |
08:49:05 | Yardanico | "Leading zeroes in exponent parts of floats are permitted." |
08:49:08 | Yardanico | https://github.com/toml-lang/toml/blob/master/CHANGELOG.md#100-rc1--2020-04-01 |
08:49:26 | PMunch | Ooh |
08:49:34 | PMunch | Wait, I checked the latest version as well |
08:49:54 | Yardanico | "An exponent part is an E (upper or lower case) followed by an integer part (which follows the same rules as decimal integer values but may include leading zeros)." |
08:49:56 | Yardanico | maybe not the last one? |
08:50:02 | Yardanico | https://github.com/toml-lang/toml/blob/master/toml.md#float |
08:50:09 | PMunch | Aah, they added "but may include leading zeros" |
08:50:38 | Yardanico | yeah, we also need to fix multiline parser in parsetoml |
08:50:46 | Yardanico | it fails on some tests because of incorrect assumptions |
08:51:19 | PMunch | TBH the entire parser infrastructure there is a bit brittle.. |
08:51:22 | Yardanico | yeah |
08:51:45 | Yardanico | basically this fails for the parsetoml |
08:51:47 | Yardanico | str = ''''That,' she said, 'is still pointless.'''' |
08:52:04 | Yardanico | spec-string-literal-multiline-4.toml |
08:52:07 | PMunch | It was nice when it was written, but tagging on all the changes to the TOML spec meant that it got quite messy.. |
08:52:19 | Yardanico | that string should result in |
08:52:22 | Yardanico | 'That,' she said, 'is still pointless.' |
08:52:22 | PMunch | Oh really? |
08:52:26 | Yardanico | yes it does |
08:52:46 | Yardanico | because parsetoml just assumes that if there are 3 delimiters - it's the end of the string |
08:52:54 | Yardanico | and in this string there are four '''' at the end |
08:52:55 | PMunch | Oooh |
08:53:08 | PMunch | Hmm |
08:53:24 | PMunch | That might be a hard one to fix actually |
08:53:30 | Yardanico | here https://github.com/NimParsers/parsetoml/blob/master/src/parsetoml.nim#L387 |
08:53:38 | Yardanico | I almost fixed it last time, but it was quite hacky :) |
08:54:30 | Yardanico | oh I gues I didn't really save it |
08:54:35 | * | nikita` joined #nim |
08:54:53 | Yardanico | basically I used the assumption that we can have at most 5 delimiters at the end of the string |
08:54:55 | PMunch | It's really annoying that there isn't a comprehensive testsuite for TOML.. |
08:54:56 | Yardanico | since with 6 it would be invalid |
08:55:03 | Yardanico | PMunch: that repo is a pretty good one |
08:55:21 | Yardanico | I actually added them straight to the repo in https://github.com/Yardanico/parsetoml/tree/add-tests |
08:55:29 | Yardanico | https://github.com/Yardanico/parsetoml/blob/add-tests/tests/runner.nim |
08:55:51 | PMunch | They should probably be added as a sub-module |
08:55:53 | Yardanico | yeah |
08:55:57 | Yardanico | or just optional |
08:56:00 | Yardanico | cloned when needed to test |
08:56:06 | Yardanico | the array-inline-nested and table-inline-nested fail because of recursion by the way |
08:56:09 | PMunch | That is of course another option |
08:56:18 | Yardanico | it' |
08:56:25 | PMunch | Just do the git pull in the runner.nim code |
08:56:28 | Yardanico | it's basically [[[[[[[[[[[[[[[[[[[[[[[[[.......]]]]]]]]]]]]]]]]]]]]]]]]] |
08:56:33 | Yardanico | an empty array like that |
08:56:39 | Yardanico | but it's not a big deal since no one would actually write it like that |
08:57:05 | PMunch | Because of recursion? Does it break the stack? |
08:57:44 | Yardanico | PMunch: well yes |
08:57:48 | Yardanico | Error: call depth limit reached in a debug build (2000 function calls). You can change it with -d:nimCallDepthLimit=<int> but really try to avoid deep recursions instead. |
08:58:05 | Yardanico | parseValue -> parseArray -> parseValue -> parseArray |
08:58:19 | Yardanico | it works with call depth limit of 10000 |
08:58:34 | Yardanico | or actually even with 3000 |
08:58:38 | Yardanico | but it's not a big deal really |
08:58:59 | Yardanico | and it doesn't seem to fail with -d:danger |
08:59:03 | Yardanico | maybe the C compiler does TCO and stuff |
09:00:30 | PMunch | The Nim compiler in debug mode sets a hard limit. I think with -d:danger it will just run and let the stack overflow and cause some kind of SEGFAULT or something |
09:00:42 | Yardanico | well there's no segfault |
09:00:47 | Yardanico | it actually passes |
09:00:55 | Yardanico | one thing I didn't add to tests is validation :) |
09:00:55 | PMunch | Well because 3000 isn't enough to break the stack |
09:01:00 | Yardanico | nonono |
09:01:04 | Yardanico | I didn't set a depth limit this time |
09:01:18 | PMunch | Yeah, but -d:danger removes the depth limit entirely I think |
09:01:24 | PMunch | It's only there for debug builds |
09:01:27 | PMunch | I think |
09:01:32 | Yardanico | well, anyway, it actually works with -d:danger |
09:01:39 | PMunch | -d:release should also work fine |
09:01:39 | Yardanico | e.g. I can echo the parsed node |
09:01:47 | PMunch | Yeah, that's to be expected |
09:02:03 | Yardanico | we should probably convert all the .yaml in that test suite to .json for easier parsing |
09:02:06 | Yardanico | to validate |
09:02:12 | PMunch | But if you had one that was sufficiently nested (or if you reduce your stack to be really small) it would actually break |
09:02:26 | PMunch | Hmm, probably |
09:03:09 | PMunch | Why are some of them JSON by the way? |
09:03:14 | PMunch | And some YAML? |
09:03:24 | Yardanico | no, all of them are yaml and toml |
09:03:27 | Yardanico | toml for parsing and yaml for validation |
09:03:34 | PMunch | Yeah |
09:03:39 | Yardanico | I just said that it would be easier to convert yaml to json than to use NimYAML |
09:03:45 | PMunch | But there are a couple in there that are JSON for validation |
09:03:53 | Yardanico | oh I see yes |
09:03:58 | PMunch | E.g. this one: https://github.com/iarna/toml-spec-tests/blob/latest/values/spec-date-local-1.json |
09:04:04 | Yardanico | yeah, a bit weird |
09:04:16 | PMunch | Might be copied over from the burnt sushi one |
09:04:35 | PMunch | I guess we could just run it and copy the JSON output for all the tests that pass |
09:04:40 | PMunch | And then just manually recreate the rest |
09:04:54 | Yardanico | there are tools to convert yaml to jsonm |
09:05:17 | Yardanico | nimyaml can do it :) |
09:05:23 | Yardanico | i think |
09:05:30 | Yardanico | yeah, https://nimyaml.org/yaml.tojson.html |
09:05:31 | PMunch | Yeah but the JSON format used by BurntSushi and this one is a special structure |
09:05:58 | PMunch | You see they have a "type" and a "value" field in an object |
09:06:09 | PMunch | To distinguish e.g. a date from a string |
09:06:15 | PMunch | Because TOML has more types than jSON |
09:06:49 | PMunch | I wish TOML had those nice railway diagrams that JSON does |
09:07:59 | PMunch | I created a flow diagram for a part of the spec, it's not a pretty thing :P |
09:11:10 | PMunch | https://uploads.peterme.net/tomlvalues.png |
09:11:38 | PMunch | This is basically anything that's not a string or an array/object |
09:13:01 | Yardanico | just make a npeg parser for toml :P |
09:13:06 | Yardanico | it can make graphs too |
09:13:35 | PMunch | I know, such a cool feature! |
09:13:39 | * | ehmry joined #nim |
09:13:53 | * | Tlanger joined #nim |
09:16:25 | * | Tongir quit (Ping timeout: 264 seconds) |
09:19:01 | Zevv | stop that |
09:19:12 | Zevv | don't go toml |
09:19:18 | PMunch | Huh? |
09:19:49 | Zevv | it's a pain to parse with npeg, really |
09:19:50 | PMunch | I'm not using TOML for anything at the moment, but we should have a parser for it in Nim |
09:20:06 | Zevv | oh wait toml |
09:20:15 | FromDiscord | <lqdev> Zevv: why? |
09:20:22 | Zevv | nah I'm confusing with something else |
09:20:30 | Zevv | this might be doable, except the indenting still is kind of tricky |
09:21:05 | FromDiscord | <lqdev> i don't think toml is indentation sensitive |
09:21:33 | Zevv | I might give it a go then, while waiting on the crawlingly slow progress of disrupteks CPS mess |
09:21:35 | PMunch | It isn't |
09:21:42 | FromDiscord | <lqdev> really tho anything with indentation is difficult to parse with PEGs overall |
09:21:45 | PMunch | Haha :P |
09:22:02 | Zevv | someone find me a test suite of toml docuemnts? |
09:22:16 | FromDiscord | <lqdev> though *maybe* if npeg had support for custom matchers... |
09:22:16 | PMunch | https://github.com/iarna/toml-spec-tests |
09:22:21 | Zevv | that was too easy :) |
09:22:49 | PMunch | There's also this: https://github.com/BurntSushi/toml-test |
09:23:03 | PMunch | But it's a bit older |
09:23:08 | Zevv | so, parsing toml into JSonNodes, does that make sense? |
09:23:16 | Zevv | or does it need its own AST |
09:23:38 | PMunch | Well, if you look at the BurntSushi repo you can see how they parse in into Json nodes |
09:24:13 | PMunch | Essentially TOML has a couple more types, actually only dates I think, so it requires objects to specify whether it's a string or a date |
09:24:33 | PMunch | And it uses these objects for anything |
09:26:54 | * | Vladar quit (Ping timeout: 256 seconds) |
09:27:13 | Zevv | lqdev: npg *has* support for custom matchers |
09:30:02 | alehander92 | hmm |
09:33:36 | PMunch | Hmm, nimpretty should really support wrapping doc-comments |
09:33:47 | * | Vladar joined #nim |
09:37:07 | FromDiscord | <lqdev> Zevv: like, matching using a custom proc? |
09:37:18 | FromDiscord | <lqdev> show me the part in docs |
09:39:02 | Zevv | "Note: The Nim code block is running within the NPeg parser context and in theory could access to its internal state - this could be used to create custom validator/matcher functions that can inspect the subject string, do lookahead or lookback, and adjust the subject index to consume input. At the time of writing, NPeg lacks a formal API or interface for this though, and I am not sure yet what this should look |
09:39:08 | Zevv | like - If you are interested in doing this, contact me so we can discuss the details." :) |
09:40:11 | FromDiscord | <lqdev> it has support but no API :) |
09:40:32 | Zevv | well, and I don't support it |
09:40:38 | Zevv | unsupported support |
09:40:41 | FromDiscord | <lqdev> not like i need it, i was just curious |
09:41:28 | FromDiscord | <lqdev> i don't use for bigger projects as i find that it's harder to wrap my head around than recursive descent + AST building |
09:41:52 | FromDiscord | <lqdev> s/use/use it/ |
09:42:09 | Zevv | neither do I |
09:42:33 | Zevv | I use it mostly for quick protoing stuff |
09:42:39 | FromDiscord | <lqdev> same |
09:42:49 | Zevv | actually, it kind of sucks |
09:42:51 | Zevv | but don't tell anyone |
09:42:56 | Zevv | the drawings make up for it |
09:43:22 | FromDiscord | <lqdev> i know it sucks :( |
09:43:48 | FromDiscord | <lqdev> its main drawback is that AST building is hard |
09:44:49 | Zevv | true. |
10:33:19 | * | sagax joined #nim |
10:38:40 | FromDiscord | <Zachary Carter> @mratsim - I'm playing around with weave and the background service feature - wondering, is there any way to wait for multiple `Pending`s? |
10:41:41 | FromDiscord | <mratsim> You loop on multiple until one isReady() |
10:42:02 | FromDiscord | <mratsim> it's not async so there is actually no special pooling to ask from the OS |
10:42:38 | FromDiscord | <Zachary Carter> gotcha thanks |
10:50:29 | * | arecacea1 quit (Remote host closed the connection) |
10:50:53 | * | arecacea1 joined #nim |
10:52:39 | FromDiscord | <hugogranstrom> I'm wrapping a C library that gives me the option to allocate the C-object either on the stack or heap (with the hint that stack-allocated objects are faster). As I'm wrapping it in a Nim object it could potentially be passed around between procs and it feels like I don't want it allocated on a random stack then. Should I go for the heap allocation instead? |
10:54:06 | * | maier quit (Ping timeout: 256 seconds) |
10:56:10 | * | rockcavera joined #nim |
11:10:03 | * | maier joined #nim |
11:11:09 | FromDiscord | <Recruit_main707> there should be no issue i think, although if the object is bigger than `sizeof(float) * 3` nim will optimize it and pass it by reference, you can avoid it by adding the `{.bycopy.}` pragma to it (maybe its relevant for your case) |
11:15:36 | FromDiscord | <hugogranstrom> @Recruit_main707 Right! I forgot to mention that the library returns a pointer to the stack-allocated C-object so just the pointer would be copied then with the `{.bycopy.}`? But the underlying data isn't copied, that's the troubling part (if it is an issue, that is) |
11:16:15 | FromDiscord | <mratsim> not an issue |
11:16:37 | FromDiscord | <mratsim> if the library expect this opaque pointer just use it |
11:17:05 | FromDiscord | <hugogranstrom> So even though it is allocated on the stack in a proc it doesn't disappear when we exit it (and returns the pointer)? |
11:19:14 | * | Vladar quit (Remote host closed the connection) |
11:21:07 | FromDiscord | <mratsim> it disappears when the proc that allocated it exists |
11:21:11 | FromDiscord | <mratsim> exits* |
11:21:19 | FromDiscord | <mratsim> but it's available in any child proc |
11:22:57 | FromDiscord | <mratsim> sent a code paste, see https://play.nim-lang.org/#ix=2t3u |
11:23:59 | FromDiscord | <mratsim> compile with --passC:-fsanitize=address and --passL:-fsanitize=address to have memory tracking and ensure you don't do buffer overflow |
11:24:14 | FromDiscord | <mratsim> but even without, wrong use will trigger stack smashing protection |
11:24:16 | FromDiscord | <hugogranstrom> It sounds a bit troublesome then as I do things like ```proc `+`(a, b: WrapperType): WrapperType = ↵allocate_stack(c_var) ↵perform_c_stuff(c_var, a.data, b.data)↵result = wrap(c_var)``` |
11:24:34 | * | Vladar joined #nim |
11:25:14 | FromDiscord | <mratsim> that won't work, `+` needs to be a template in that case or the WrapperType needs to be on the heap |
11:27:03 | FromDiscord | <hugogranstrom> OK, then I better use the heap allocated version it seems like 🙂 I can't force the user to use templates instead of procs after all |
11:27:50 | FromDiscord | <mratsim> For libraries that combine multiple functions at once, they will be interested in stack alloc |
11:28:29 | FromDiscord | <mratsim> I expect that the differenc ein performance will be significant, like from 2x ~ 3x minimum but it can go well into the 10x ranges |
11:28:47 | FromDiscord | <hugogranstrom> Let's say the user specifies a proc like: ```proc f(x: WrapperType): WrapperType =↵x ^ 2``` |
11:29:58 | FromDiscord | <hugogranstrom> No matter how I implement `^` it will be stack allocated in `f` but we can't return it to the outside? |
11:30:02 | FromDiscord | <mratsim> The alternative is to write a memory pool |
11:30:25 | FromDiscord | <mratsim> yes, because at the end of the function the previous stack will be restored |
11:30:35 | FromDiscord | <hugogranstrom> Ouch that's a pretty hefty performance drop :/ |
11:30:42 | FromDiscord | <mratsim> or an object pool if your types are always the same size |
11:31:42 | FromDiscord | <mratsim> benchmark it, you'll know, but I suppoe doing multiple additions is expected, so you will have memory overhead |
11:31:49 | FromDiscord | <hugogranstrom> A memory pool for my Nim-type or for the C-type I get a pointer to? |
11:31:50 | FromDiscord | <mratsim> this is similar to strutils and intermediate allocation |
11:32:50 | FromDiscord | <hugogranstrom> Hmm... Perhaps forcing the user to use templates instead of proc's isn't such a bad idea after all 😅 |
11:33:13 | FromDiscord | <mratsim> if an object pool is enough and there is only ever a single owner of a memory location (i.e. you don't alias) you can use this as a base: https://github.com/mratsim/weave/blob/master/weave/memory/persistacks.nim |
11:33:19 | FromDiscord | <mratsim> this is a very simple object pool |
11:33:41 | FromDiscord | <mratsim> you just need to have a `=destroy` = recycle |
11:33:55 | FromDiscord | <hugogranstrom> I'm afraid I have zero control over how the C library handles this sadly :/ |
11:34:07 | FromDiscord | <hugogranstrom> I just get a pointer |
11:34:22 | FromDiscord | <mratsim> I xpect the lib as an object pool inside |
11:34:27 | FromDiscord | <mratsim> but benchmark. |
11:34:43 | FromDiscord | <mratsim> do 100000 sums in a loop on stack or on heap and look what happens |
11:35:04 | FromDiscord | <mratsim> and highlight those limitations in your README |
11:35:50 | FromDiscord | <hugogranstrom> I hope so. Yes I will do some benchmarking 😄 |
11:36:34 | FromDiscord | <mratsim> Note that whatever you learn there will be super useful for: parser/json parsing/csv parsing (we need to allocate temporary a lot for working on strings or converting them to numbers), autograd and intermediate tensor, functional programming (lots of intermediate transformation if not optimized from the start, i.e. sequtils or strutils) |
11:37:22 | FromDiscord | <hugogranstrom> Oh yeah that's for sure, learning is a thrill 🙂 |
11:38:03 | FromDiscord | <hugogranstrom> Allocation is both a blessing and a limitation really depending on what you do |
11:38:06 | FromDiscord | <hugogranstrom> Thank you very much Mamy! 🙂 |
11:44:49 | * | krux02 joined #nim |
12:06:01 | * | supakeen quit (Quit: WeeChat 2.8) |
12:06:33 | * | supakeen joined #nim |
12:23:02 | * | dulsi_ joined #nim |
12:25:34 | * | dulsi quit (Ping timeout: 260 seconds) |
12:28:03 | * | NimBot joined #nim |
12:33:44 | PMunch | Prestige, is that a pipe or a cane in your GitHub avatar? |
12:39:25 | Yardanico | PMunch: PMunch |
12:39:25 | Yardanico | ' |
12:39:28 | Yardanico | sorry |
12:39:30 | Yardanico | didn't mean to do that |
12:40:52 | PMunch | Haha :P |
12:41:34 | FromGitter | <sealmove> how to do shift-reduce with npeg? |
12:43:03 | Yardanico | what's that? :D |
12:51:25 | PMunch | Hmm, that's annoying: https://play.nim-lang.org/#ix=2t40 |
12:52:15 | Yardanico | what exactly? |
12:52:16 | PMunch | `first` and `second` here are indistinguishable, even though Nim users would read `first` as a type declaration kind of thing, while `second` looks like a list of assignments.. |
12:52:48 | Yardanico | well, for me they're the same :P |
12:53:36 | PMunch | Essentially I want to support something like this: https://play.nim-lang.org/#ix=2t41 |
12:54:04 | PMunch | In a DSL, but now I have no good way of distinguishing a category from an assignment with a type declaration |
12:55:30 | PMunch | Apart from checking the key in every category with only a single assignment and try to determine if the key is a type |
13:00:45 | FromDiscord | <kodkuce> 1 question about async, if i write a proc that just for loops tough list and gives result back, and i want to use it in some async function do i have to declare it too async or its pointless cuz there is no real blocking ? |
13:01:01 | Yardanico | it's pointless |
13:01:11 | Yardanico | there is blocking of course, but it would be not noticeable in 99% of cases |
13:01:23 | Yardanico | any CPU-bound work is blocking |
13:01:37 | PMunch | Eh, it depends |
13:02:01 | Yardanico | well, depends on how much load there is, yes |
13:02:10 | Yardanico | but even the tiniest CPU work *is* technically blocking |
13:02:14 | PMunch | If you have a lot of iterations and you want to e.g. listen for user input "at the same time" then implementing it as an async might give you what you want |
13:02:17 | FromDiscord | <kodkuce> ye right if i have list of 1m and shitty cpu |
13:02:33 | FromDiscord | <kodkuce> but i have list of 1000max and just check 1 field |
13:02:37 | PMunch | But in that case you're better off doing the work on a separate thread |
13:02:38 | Yardanico | it's okay |
13:02:44 | Yardanico | yeah |
13:03:15 | PMunch | Yeah it would still block, so the throughput would be the same, but latency could be worse. |
13:04:37 | PMunch | Say you want to loop through a million entries, if the user wants to quit after 1000 and it ran in a blocking way then you're screwed. But if it was async and checked every time it got control whether or not it was supposed to carry on then you would be able to take user input to quit the async procedure "while" running |
13:04:44 | FromDiscord | <kodkuce> sent a code paste, see https://play.nim-lang.org/#ix=2t46 |
13:05:00 | Yardanico | why would you want it to be a future? |
13:05:02 | Yardanico | it doesn't have to be |
13:05:11 | PMunch | Notice the "at the same time" and "while" in quotes, it's interleaved, but it would appear to happen at the same time for the user |
13:05:15 | Yardanico | it won't matter for you as we said :) |
13:05:51 | PMunch | Ah, you need to await something to hand control back to the loop |
13:06:12 | PMunch | I'm not sure if async in Nim supports just yielding without awaiting anything.. |
13:06:30 | PMunch | It definitely should IMO, but I'm not sure if it actually does |
13:06:51 | Yardanico | @kodkuce something like https://play.nim-lang.org/#ix=2t47 should work |
13:06:56 | Yardanico | async macro can implicitly add Future type |
13:07:00 | Yardanico | or I mixed that up, hm |
13:07:11 | Yardanico | try https://play.nim-lang.org/#ix=2t48 |
13:07:26 | Yardanico | but really, you don't have to make it async |
13:09:13 | FromDiscord | <kodkuce> ok |
13:09:17 | FromDiscord | <kodkuce> (edit) 'ok ... ' => 'okty' |
13:11:39 | PMunch | Or alternatively keep a data structure that is easier to index than looping through a list |
13:11:45 | PMunch | Maybe even just a bitset? |
13:12:34 | Yardanico | btw, I noticed that https://github.com/nim-lang/Nim/blob/master/lib/pure/colors.nim uses binary search over an array for matching color name -> color |
13:12:41 | Yardanico | is that more efficient than a table (or a string table even)? |
13:13:04 | Yardanico | ah nvm it's just legacy I think |
13:13:10 | Yardanico | that binary search code is there since 11 years ago |
13:13:32 | PMunch | Potentially faster |
13:13:44 | Yardanico | what if you make the table at compile-time? |
13:13:46 | PMunch | Or well, it still has to do string compares. So probably not |
13:14:13 | PMunch | Yeah, a compile-time generated table would probably be faster |
13:14:31 | PMunch | Faster yet would be a trie I think |
13:15:17 | PMunch | https://nim-lang.org/docs/critbits.html |
13:16:16 | Yardanico | wow |
13:16:36 | Yardanico | although there doesn't seem to be a way to make one at compile-time efficiently? |
13:16:41 | Yardanico | you just gotta do static: incl. a lot of stuff? |
13:17:07 | FromDiscord | <kodkuce> ye my data structure is atm horor but its my first time at wrting this matchmaking thingy so just want to finish it, next game will have better for sure 🙂 |
13:20:00 | PMunch | It likely won't matter much unless you're doing a whole lot of colour name lookups.. |
13:20:13 | Yardanico | I just was curious :) |
13:20:21 | PMunch | But a way to compile-time make a string trie data structure would be cool |
13:21:06 | Yardanico | so a trie would be faster instead of a table? |
13:21:11 | Yardanico | for e.g. string -> string lookup |
13:21:19 | Yardanico | if mappings are known at compile-time |
13:21:39 | PMunch | I wrote a compile-time huffman coding of sprites for the Arduboy, that was pretty cool |
13:21:50 | PMunch | It could be faster |
13:22:41 | PMunch | Basically the benefit of a trie is that you scan the string character by character and simply choose branches of the data structure until you hit a leaf. It could terminate early, and be quite cache efficient |
13:23:16 | PMunch | But calculating a hash and directly going to a place in memory is also super fast, so it would probably only matter for very high volume lookups |
13:23:27 | PMunch | But the trie approach requires less memory |
13:23:42 | Yardanico | oh I get the trie thing |
13:23:44 | PMunch | Because you only store the data and structure required, there are no empty buckets |
13:23:47 | Yardanico | it's like some hand-written parsers |
13:23:52 | Yardanico | which check char-by-char for keywords |
13:23:55 | PMunch | Yeah, pretty much |
13:24:11 | Yardanico | the crafting interpreters book used that approach for C implementation of the parser :) |
13:25:16 | PMunch | Say you have pasta, pasterami, tomato, and pizza in a trie. The first would be check if it's a p or a t, then if it is an i or the sequence ast, and then a check for erami or a to determine what it is |
13:25:43 | Yardanico | yeah, seems pretty clear :) |
13:25:50 | Yardanico | I guess the algorithm itself to do that is harder, but I get the idea |
13:26:07 | Yardanico | seems to be this paper |
13:26:07 | Yardanico | https://www.imperialviolet.org/binary/critbit.pdf |
13:26:28 | PMunch | Eh, it's not that hard |
13:46:08 | * | vicfred joined #nim |
13:54:20 | skrylar[m] | i seem to recall araq was in to critbits |
13:54:30 | FromDiscord | <kodkuce> https://play.nim-lang.org/#ix=2t4o , can somone explain me about what locks does it complain ? |
13:59:17 | * | lritter quit (Quit: Leaving) |
14:07:07 | Yardanico | it doesn't complain about locks |
14:07:23 | Yardanico | https://play.nim-lang.org/#ix=2t4C fixed version |
14:07:27 | Yardanico | you're passing proc itself to these procedures |
14:07:36 | * | Trustable joined #nim |
14:07:37 | Yardanico | but you should call them, they return Future and you pass that to asyncCheck or waitFor |
14:07:59 | Yardanico | the error tells you that it got a proc as an argument |
14:08:02 | Yardanico | but it expected a Future |
14:10:45 | * | MightyJoe joined #nim |
14:11:00 | FromDiscord | <kodkuce> oh |
14:11:02 | FromDiscord | <kodkuce> ye sorry |
14:11:37 | * | cyraxjoe quit (Ping timeout: 264 seconds) |
14:14:34 | * | def- quit (Ping timeout: 265 seconds) |
14:14:37 | * | def-- joined #nim |
14:15:01 | * | def-- is now known as def- |
14:19:27 | * | SenasOzys joined #nim |
14:21:38 | * | screens is now known as screens_ |
14:24:58 | FromDiscord | <Clyybber> sup |
14:25:03 | FromDiscord | <Clyybber> PMunch: You're back! |
14:32:56 | * | ForumUpdaterBot quit (Remote host closed the connection) |
14:33:03 | * | ForumUpdaterBot joined #nim |
14:33:25 | Yardanico | https://forum.nim-lang.org/t/6637 |
14:38:45 | FromDiscord | <Zachary Carter> @mratsim - I might be doing something incorrect but I'm running into some errors using devel and weave |
14:38:59 | FromDiscord | <Zachary Carter> I can throw up some example code if you want to see |
14:42:26 | FromDiscord | <Clyybber> @Zachary Carter are you using weave with vulkan? |
14:42:41 | * | aenesidemus joined #nim |
14:47:24 | FromDiscord | <Zachary Carter> going to try |
14:47:40 | FromDiscord | <Zachary Carter> but I might just end up writing my own, simpler, job system if I can't get weave working |
14:53:18 | FromDiscord | <Clyybber> are you going to go the framegraph route? |
14:57:22 | FromDiscord | <Zachary Carter> that's the plan |
14:57:41 | FromDiscord | <Clyybber> nice! |
15:07:01 | FromDiscord | <kodkuce> hmm var players: seq[Player] = repeat( Player(empty:true), 5 ) , it does not create a new player for each slot it just copy ref of same so when i change 1 i change all 😦 |
15:07:13 | Yardanico | yes as I said before |
15:07:22 | Yardanico | so just use two more lines of code |
15:07:24 | Yardanico | it's not such a big deal :) |
15:07:42 | FromDiscord | <kodkuce> me crys inside xD |
15:09:06 | ForumUpdaterBot | New thread by Wearetherock: Syntax for copy instance of object and update some attribute, see https://forum.nim-lang.org/t/6638 |
15:13:40 | * | audiofile joined #nim |
15:19:22 | * | maier quit (Ping timeout: 246 seconds) |
15:20:44 | * | audiofile quit (Quit: Default Quit Message) |
15:38:20 | * | waleee-cl joined #nim |
15:46:05 | * | audiofile joined #nim |
15:49:06 | * | oriba joined #nim |
15:52:09 | * | oriba quit (Client Quit) |
15:55:57 | Yardanico | streaming some random stuff because I don't have any ideas for projects :P |
15:55:58 | Yardanico | ~ystream |
15:55:58 | disbot | ystream: 11Stream at https://twitch.tv/yardanico, voice chat either on Mumble (mumble://uberalles.mumbl.io/) or in Discord (https://discord.com/invite/ezDFDw2) -- Yardanico |
15:56:34 | livcd | Yardanico: why not continue on your sciter wrapper? :P |
15:56:38 | Yardanico | not now :P |
15:57:00 | livcd | If you want I could sponsor you a license |
15:57:15 | supakeen | I should continue my urwid port. |
15:57:16 | Yardanico | well the license is not really needed for most stuff :) |
15:57:31 | supakeen | One of these days I shall find the time! |
15:57:44 | livcd | But you would have access to sources. Maybe it would make life easier |
16:04:52 | FromDiscord | <UnnoTed> i'm hoping that the Sciter wrapper continues too as i lack enough knowledge in C/C++ to write a wrapper, i'm currently using Go with Sciter but the binary is getting huge (45mb) |
16:05:38 | FromDiscord | <Rika> you've tried all you can to make the binary smaller? |
16:09:03 | livcd | Rika: you would sacrifice startup time if you would have tried it all :X |
16:09:32 | FromDiscord | <Rika> yeah, well, |
16:09:33 | FromDiscord | <Rika> yeah |
16:09:38 | FromDiscord | <Rika> got nothing to say |
16:10:49 | livcd | :D |
16:11:48 | FromDiscord | <Rika> maybe the sciter wrapper can be made via nimterop |
16:11:53 | Yardanico | it's not about that |
16:11:57 | Yardanico | it's already made with nimterop |
16:12:00 | Yardanico | it's about making a high-level wrapper |
16:12:06 | Yardanico | the low-level wrapper is already useable |
16:13:30 | livcd | Interesting. Did you just run nimterop for the lowlevel wrapper? |
16:13:37 | Yardanico | no, there's more work of course |
16:13:43 | Yardanico | I copied a lot of stuff from the old sciter wrapper |
16:13:46 | Yardanico | but also modernized that stuff a bit |
16:17:02 | FromDiscord | <Rika> yardanico: ah, i see, i didnt know, sorry |
16:17:47 | shashlick | Rika - did you get to see the imagemagick wrapper |
16:19:50 | FromDiscord | <Rika> yes |
16:19:51 | FromDiscord | <Rika> uh |
16:20:05 | FromDiscord | <Rika> it doesnt work and i do not kknow why |
16:20:25 | FromDiscord | <Rika> i'm currently doing something else right now so ill tell you what i get in a bit |
16:20:42 | shashlick | okay let me know |
16:22:54 | Prestige | PMunch: it's a cane |
16:42:18 | * | krux02 quit (Remote host closed the connection) |
17:05:25 | FromDiscord | <Zachary Carter> is there any way to have the compiler inform you when a sink parameter, that is used afterwards, results in a copy? |
17:06:09 | Yardanico | it does that by default |
17:06:13 | Yardanico | performance hint |
17:10:51 | FromDiscord | <Zachary Carter> hmm okay - let me test |
17:12:11 | FromDiscord | <Zachary Carter> Yardanico: is there some flag I need to enable to get performance hints? |
17:12:18 | FromDiscord | <Zachary Carter> because it's not working for me |
17:12:19 | Yardanico | no, it should be enabled by default |
17:12:22 | Yardanico | at least in devel |
17:12:55 | FromDiscord | <Zachary Carter> weird |
17:13:53 | FromDiscord | <Recruit_main707> nim always disagrees with gcc on pointer size even when its the mingw installation it downloads (and works) |
17:14:09 | Yardanico | well that means the nim assumes you use a different arch |
17:14:12 | Yardanico | try --cpu:i386 explicitly |
17:14:16 | Yardanico | or --cpu:amd64 |
17:14:24 | FromDiscord | <Recruit_main707> sorry. when i run finish.exe |
17:15:42 | FromDiscord | <Zachary Carter> oh I think I know why it's not complaining |
17:15:51 | FromDiscord | <Zachary Carter> because I'm doing `sink var T` |
17:15:55 | FromDiscord | <Zachary Carter> which doesn't make sense... |
17:15:57 | Yardanico | lol |
17:16:16 | FromDiscord | <Zachary Carter> the compiler should tell me I'm stupid |
17:16:33 | FromDiscord | <Zachary Carter> `compiler: Araq says you stupid!` |
17:16:45 | FromDiscord | <Zachary Carter> hope that didn't ping him lol |
17:16:46 | * | maier joined #nim |
17:17:02 | Yardanico | it will :P |
17:17:04 | FromDiscord | <Recruit_main707> probably did |
17:21:42 | * | maier quit (Ping timeout: 256 seconds) |
17:28:25 | FromDiscord | <Recruit_main707> lmao i just slapped my own mingw installation into the dist folder and it worked fine |
17:39:16 | Zevv | well well well |
17:49:46 | disruptek | speak to me, nimions. |
17:51:44 | FromDiscord | <Clyybber> @Zachary Carter Yard: I don't think so |
17:51:48 | FromDiscord | <Clyybber> I think Araq disabled it |
17:51:52 | FromDiscord | <Clyybber> lemme check |
17:52:19 | FromDiscord | <Clyybber> yeah you have to have hint:performance:on |
17:53:23 | disruptek | PMunch: wb, are you okay? |
17:54:26 | FromDiscord | <Zachary Carter> wb PMunch! |
17:56:17 | * | endragor_ joined #nim |
17:58:46 | * | endragor quit (Ping timeout: 260 seconds) |
18:00:54 | * | dzamo joined #nim |
18:02:24 | * | dzamo quit (Client Quit) |
18:07:21 | disruptek | There have been 348 failed login attempts since your last successful login. 🤦 |
18:07:26 | disruptek | WHAT IS MY PASSWORD? |
18:08:17 | FromDiscord | <Clyybber> ~password is bentleyisagoodboy |
18:08:18 | disbot | password: 11bentleyisagoodboy |
18:08:33 | disruptek | There have been 349 failed login attempts since your last successful login. |
18:09:02 | FromDiscord | <Rika> are you sure this isnt you in the future trying to log in |
18:09:21 | disruptek | why would the future me want to talk to you? |
18:09:30 | FromDiscord | <Clyybber> gatem |
18:10:30 | FromDiscord | <Rika> lmao |
18:12:09 | disruptek | that came out wrong. what i meant was, |
18:12:15 | disruptek | i don't want to talk to you in the future. |
18:12:55 | disruptek | i spoke to you in the past. it wasn't that great. |
18:13:28 | leorize | Yardanico: eh, PGO is overrated |
18:13:32 | FromDiscord | <Rika> lol |
18:13:34 | Yardanico | leorize: why? |
18:14:02 | leorize | because you end up optimizing for your test cases instead of real world usage |
18:14:07 | Yardanico | yes |
18:14:14 | Yardanico | but your usage can be "real world usage" |
18:14:20 | leorize | autopgo is better in this aspect |
18:14:35 | leorize | it's a form of lightweight instrumentation |
18:14:52 | leorize | so you can use it in conjunction with your real world workload |
18:15:10 | Yardanico | can't find a single article about autopgo lol |
18:15:19 | leorize | autopdo <- I think that's what it's called |
18:15:26 | leorize | it's google tech that clear linux uses |
18:15:31 | Yardanico | still :D |
18:15:33 | FromDiscord | <Rika> unfortunate name |
18:15:38 | FromDiscord | <Rika> very unfortunate name |
18:15:44 | Yardanico | but anyway I think that PGO is still good |
18:15:49 | Yardanico | it can be helpful in a lot of cases |
18:16:02 | leorize | I think PGO distracts users from the real fix |
18:16:14 | * | dzamo joined #nim |
18:16:32 | leorize | the point of instrumentation is that you know where to micro-optimize to gain better perf overall |
18:17:18 | leorize | you can see firefox as a prime example of how pgo can only ever help you score high in benchmarks |
18:19:21 | * | kungtotte quit (Read error: Connection reset by peer) |
18:19:36 | * | kungtotte joined #nim |
18:19:40 | leorize | PGO is not bad, don't get me wrong, but it's crucial to remember that it's a tool to help you optimize your written code, not a "free performance" optimization as many tries to use it as |
18:20:35 | leorize | ah, the tech is called autofdo |
18:20:49 | leorize | google seems to have dropped it |
18:21:35 | * | dzamo left #nim ("Good Bye") |
18:25:00 | * | dulsi_ is now known as dulsi |
18:25:13 | shashlick | @Rika - made another update based on feedback from zedeus |
18:25:49 | FromDiscord | <Rika> okay ill look |
18:26:02 | FromDiscord | <Rika> when i can... still doing something |
18:26:17 | disruptek | i don't believe it. |
18:28:42 | Yardanico | i wrote something cursed |
18:30:14 | Yardanico | https://play.nim-lang.org/#ix=2t6a |
18:36:32 | * | sschwarzer joined #nim |
18:37:20 | sschwarzer | I just created my first macro: https://play.nim-lang.org/#ix=2t6i . Any feedback? Suggestions for improvements? |
18:39:04 | disruptek | sschwarzer: i got a macro i want written that i couldn't impl myself. maybe you can give it a shot? |
18:39:13 | Yardanico | lol |
18:39:19 | FromDiscord | <Rika> 👀 |
18:39:23 | sschwarzer | disruptek: *lol* |
18:39:31 | disruptek | dafuq is so funny about that? |
18:39:53 | sschwarzer | disruptek: I thought you were joking. |
18:40:17 | sschwarzer | I mean I _could_ try it if it's not super-difficult. |
18:40:21 | Yardanico | he is joking |
18:40:24 | disruptek | i want a twice: block. the first time it is encountered, it is ignored. the second time, the twice: block is run. simple. |
18:40:34 | sschwarzer | But hey, if you say you couldn't implement it ... :-D |
18:40:58 | disruptek | i thought it was as simple as `block: once: break; body`. i was wrong. |
18:41:00 | sschwarzer | Yardanico: probably it's something unsolvable ;) |
18:41:25 | disruptek | it should be solvable. |
18:44:00 | disruptek | i spend a lot of time writing nim, but that doesn't mean i'm any good at it. look at rika, for example. |
18:44:07 | sschwarzer | disruptek: Can you explain this a bit more, maybe with an example? (would make sense in the Nim playground) |
18:44:11 | FromDiscord | <Rika> exactly |
18:44:56 | FromDiscord | <Recruit_main707> lel |
18:44:56 | sschwarzer | disruptek: Sounds like it needs some state during the _runtime_ of the macro (if I understood the task correctly). |
18:45:05 | sschwarzer | i. e. a flag |
18:45:35 | sschwarzer | I mean "runtime of the macro" = "time when the compiled code generated by the macro runs" |
18:46:07 | Zevv | disruptek: tell me |
18:46:15 | Zevv | what is new |
18:46:41 | disruptek | sschwarzer: https://play.nim-lang.org/#ix=2t6k |
18:46:55 | disruptek | Zevv: i'm writing an issue to track a new rewrite impl. |
18:47:20 | Zevv | the old one is beyond salvaging? |
18:47:21 | disruptek | really tired of dealing with this impl that shouldn't even exist. |
18:47:22 | Zevv | a total loss? |
18:47:25 | disruptek | no, but. |
18:47:27 | Zevv | fair enough |
18:48:02 | leorize | disruptek: https://play.nim-lang.org/#ix=2t6m |
18:48:37 | disruptek | why can it not be impl with once? |
18:49:04 | disruptek | please pr it to fusion. fusion loves untested novel code. |
18:49:18 | sschwarzer | disruptek: So in the first iteration you want to execute the `once` block and in the second iteration the `twice` block? |
18:50:23 | disruptek | yeah. |
18:51:28 | sschwarzer | Zevv: Would it be possible to store the `count` in your template in some closure instead of making it global? |
18:51:44 | sschwarzer | So you could have different once/twice uses |
18:51:54 | disruptek | you already do. |
18:52:00 | sschwarzer | e. g. in different procs |
18:52:05 | disruptek | the global is hygenic; it's gensym'd. |
18:52:18 | Zevv | sschwarzer: talking about which code? |
18:52:26 | disruptek | a closure would evaporate. |
18:52:27 | sschwarzer | disruptek: oh, I see, it's in each inlining of the template |
18:52:42 | disruptek | Zevv: he's confusing you for leorize. |
18:52:49 | Zevv | ah I often have that |
18:53:12 | sschwarzer | disruptek, Zevv: yes, I did confuse you/them |
18:53:14 | Zevv | we're both bright and charismatic |
18:53:18 | Zevv | so no wonder |
18:53:26 | sschwarzer | Zevv: That's awesome ;) |
18:53:30 | Zevv | yes, we are |
18:53:30 | leorize | disruptek: once doesn't work because it would run everytime after `twice` |
18:53:51 | sschwarzer | Zevv: By the way, I really like your Nim t-shirt you posted. :-D |
18:54:01 | disruptek | i don't get it. |
18:54:06 | Zevv | sschwarzer: thanks :) |
18:54:44 | sschwarzer | I really like Monty Python and have the movie on DVD. :) |
18:54:55 | leorize | disruptek: https://play.nim-lang.org/#ix=2t6p |
18:54:58 | Zevv | so at least *someone* gets it |
18:55:46 | * | krux02 joined #nim |
18:56:00 | leorize | for the exact semantics that you want a counter is the simplest implementation |
18:56:34 | disruptek | actually, this works fine. |
18:56:42 | sschwarzer | leorize: wouldn't a bool suffice? |
18:56:44 | disruptek | https://play.nim-lang.org/#ix=2t6q |
18:57:05 | sschwarzer | leorize: like "already executed" vs. "not yet executed"? |
18:57:12 | * | nikita` quit (Quit: leaving) |
18:59:50 | FromDiscord | <brainproxy> in my `proc foo*(a: cstring): cstring {.exportc.} =` after building the cstring I intend to return I'd like to allocate memory not managed by Nim's gc, copy/put the cstring in there and return the pointer. In other words, I want caller to be responsible for freeing the memory |
18:59:58 | disruptek | bbiab, i'm getting tired of eating rotten milk with a fork. |
19:00:25 | FromDiscord | <brainproxy> > eating rotten milk with a fork↵sounds awful |
19:00:48 | leorize | depends on how you built the cstring |
19:01:04 | leorize | if you build it from scratch using `alloc` and friends then it's unmanaged |
19:01:21 | leorize | however the string cannot be freed by C's free() since Nim has it's own allocator |
19:02:09 | FromDiscord | <brainproxy> right, so the cstring came from an intermediate step of passing `$a` to some other proc then `.cstring`'ing its return |
19:02:37 | FromDiscord | <brainproxy> basically I want to effectively return a cstring that Nim won't collect |
19:03:05 | leorize | you will need to allocate your own storage for the cstring in that case |
19:03:15 | FromDiscord | <brainproxy> right, I'm asking how to do that, I have no idea |
19:03:26 | FromDiscord | <brainproxy> I found this: https://www.mail-archive.com/[email protected]/msg18309.html |
19:03:31 | leorize | how do you want the cstring to be freed? |
19:03:47 | leorize | hmm, I never knew that we have a mailing list |
19:04:02 | FromDiscord | <brainproxy> foo will be part of a library compiled to `.a` and then statically linked by other C |
19:04:12 | FromDiscord | <brainproxy> so C caller should free |
19:04:43 | leorize | then you will need to allocate the storage via malloc |
19:05:11 | FromDiscord | <brainproxy> example? (I'm a Nim novice, no experience with C / C++) |
19:06:03 | FromDiscord | <brainproxy> can that be done in the body of `foo` or are you saying that C caller will have to allocate with malloc and tell foo about that memory? |
19:06:21 | leorize | it depends on how you would want to design your api |
19:06:43 | leorize | though taking a cstring without a length is bad practice |
19:07:17 | FromDiscord | <brainproxy> I'm just working with what I've been dealt |
19:07:23 | FromDiscord | <brainproxy> it's a wrapper |
19:07:37 | * | sschwarzer quit (Quit: leaving) |
19:07:45 | leorize | what are you wrapping? |
19:08:03 | * | nikita` joined #nim |
19:08:08 | FromDiscord | <brainproxy> another C library |
19:08:40 | leorize | typically you'd want to take the buffer size of the cstring so that you don't accidentally end up in buffer overflow |
19:09:20 | leorize | do you need to use any of Nim's strutils? |
19:11:15 | leorize | if you don't then it's as easy as just allocating a new buffer and copy the cstring over |
19:11:24 | leorize | then you can pass it to any C library that you'd like |
19:11:42 | Yardanico | but the caller should free it |
19:13:23 | Yardanico | https://github.com/nim-lang/Nim/issues/15154 found this while working on nimpylib lol |
19:13:25 | disbot | ➥ Internal compiler error when providing 'nil' for a proc argument in a generic procedure with two arguments ; snippet at 12https://play.nim-lang.org/#ix=2t6C |
19:16:36 | FromDiscord | <brainproxy> sent a code paste, see https://play.nim-lang.org/#ix=2t6F |
19:16:39 | FromDiscord | <brainproxy> I tried that, seems to work |
19:17:11 | * | maier joined #nim |
19:21:48 | leorize | ah no, that's not how :P |
19:21:59 | * | pulux joined #nim |
19:22:11 | * | maier quit (Ping timeout: 240 seconds) |
19:22:19 | leorize | I need some more information on what this api of yours do |
19:23:50 | leorize | C have strdup/strndup for string duplication if you need that |
19:25:16 | FromDiscord | <brainproxy> foo takes a cstring, converts to a nim string, calls another nim proc used to calculate a hash which is returned as a string; foo then converts to cstring and returns it↵↵the twist being, as above, I want to allocate memory size of the cstring to be returned and return that pointer, so that Nim's gc won't collect it and the caller is responsible for freeing it |
19:25:35 | FromDiscord | <brainproxy> (edit) 'that' => 'a' |
19:25:39 | Yardanico | just malloc the result value then |
19:25:41 | FromDiscord | <brainproxy> (edit) 'foo takes a cstring, converts to a nim string, calls another nim proc used to calculate a hash which is returned as a string; foo then converts to cstring and returns it↵↵the twist being, as above, I want to allocate memory size of the cstring to be returned and return a pointer, so that Nim's gc won't collect it and the ... caller' => 'foo takes a cstring, converts to a nim string, calls another nim proc used to calculate |
19:25:42 | FromDiscord | <Ricky Spanish> seeing unquoted $ symbols as part of the syntax triggers me for some reason, makes me want to use nim more to overcome my fear |
19:25:52 | Yardanico | ? |
19:25:55 | Yardanico | wdym |
19:26:11 | FromDiscord | <brainproxy> > just malloc the result value then↵I don't know how to do that, I was attempting with `create` above, what is the right way? |
19:26:37 | FromDiscord | <lqdev> nope |
19:26:51 | Yardanico | easiest way is |
19:27:09 | leorize | the fear of bash xd |
19:27:11 | FromDiscord | <lqdev> you need to do `cast[cstring](alloc0(myStr.len))` |
19:27:14 | Yardanico | no |
19:27:20 | Yardanico | it might not work |
19:27:28 | FromDiscord | <lqdev> why? |
19:27:29 | Yardanico | it'll only work if you compile with -d:useMalloc |
19:27:37 | leorize | they need to use malloc |
19:27:38 | Yardanico | because malloc has some metadata on it's own |
19:27:39 | FromDiscord | <lqdev> oh right |
19:27:42 | Yardanico | @brainproxy import system/ansi_c |
19:27:46 | Yardanico | and then use c_malloc |
19:27:49 | FromDiscord | <lqdev> because nim has a different allocator |
19:27:57 | leorize | Yardanico: I'm not sure if that's public API |
19:28:03 | Yardanico | it can be used as one :P |
19:28:07 | FromDiscord | <brainproxy> https://nim-lang.org/docs/ansi_c.html↵404 |
19:28:10 | Yardanico | just copy the procs from here https://github.com/nim-lang/Nim/blob/devel/lib/system/ansi_c.nim#L142 |
19:28:53 | leorize | don't push people into using private API, or you will spend time wondering why does changing private APIs suddenly make things not work |
19:29:02 | Yardanico | leorize: I didn't push lol |
19:29:12 | Yardanico | it just seemed as an easier way instead of duplicating stuff :P |
19:29:36 | leorize | we might want to spin that off into a module just for cinterop :P |
19:29:43 | leorize | or we can add more things to cstrutils |
19:29:45 | Yardanico | fwiw that c_malloc is there for 11 years |
19:29:47 | leorize | not sure which is better |
19:29:57 | Yardanico | although it was in lib/ansi_c |
19:30:22 | Yardanico | yeah, I think it would be better to add a new module for some C interop procedures |
19:30:26 | FromDiscord | <lqdev> cstrutils is a thing? |
19:30:27 | Yardanico | also import/export cstrutils there :P |
19:30:28 | Yardanico | yes |
19:30:35 | FromDiscord | <lqdev> docs? |
19:30:36 | Yardanico | it's quite smol |
19:30:36 | Yardanico | https://nim-lang.org/docs/cstrutils.html |
19:30:46 | leorize | cstrutils is pretty basic |
19:31:10 | FromDiscord | <lqdev> interesting |
19:31:15 | Yardanico | I mean a lot of strutils procs can be ported to cstrutils easily |
19:31:18 | Yardanico | just 1:1 really |
19:31:40 | leorize | there just isn't a need for those tbh |
19:31:49 | FromDiscord | <brainproxy> `let str = c_malloc(c_strlen(hash))`↵like that? |
19:31:59 | FromDiscord | <lqdev> damn there are way too many stdlib modules that aren't documented in https://nim-lang.org/docs/lib.html |
19:32:04 | FromDiscord | <lqdev> @brainproxy yes |
19:32:08 | Yardanico | cstrutils is in that file |
19:32:09 | Yardanico | @lqdev |
19:32:11 | Yardanico | https://nim-lang.org/docs/lib.html#pure-libraries-string-handling |
19:32:14 | Yardanico | literally first entry here |
19:32:22 | FromDiscord | <lqdev> oh didn't notice |
19:32:23 | Yardanico | I don't think there are many undocumented stdlib modules |
19:32:28 | FromDiscord | <lqdev> but my statement still applies |
19:32:30 | Yardanico | "punycode Implements a representation of Unicode with the limited ASCII character subset." |
19:32:32 | leorize | it's just hard to actually find them |
19:32:34 | FromDiscord | <brainproxy> okay, sorry for such simple questions, but then how do I copy the string into what I allocated? |
19:32:36 | FromDiscord | <lqdev> there are *some* less important ones |
19:32:40 | Yardanico | which ones? |
19:33:00 | Yardanico | there was some work done on adding more stdlib modules to the lib index |
19:33:01 | FromDiscord | <brainproxy> `str[] = hash` doesn't seem to work |
19:33:03 | leorize | @brainproxy you will want to have `foo` take a length as well |
19:33:11 | * | Prestige quit (Quit: Prestige) |
19:33:19 | FromDiscord | <lqdev> @brainproxy `copyMem(destStr[0].addr, srcStr[0].addr, srcStr.len)` |
19:33:32 | leorize | it's dangerous to do strlen() on a cstring without knowing whether it's NUL-terminated |
19:34:29 | FromDiscord | <brainproxy> sounds like good advice, I'll have to ask other team members if that's going to be feasible |
19:35:00 | leorize | make sure they sanitize their inputs so that no NUL can sneak in and truncate the string |
19:35:50 | * | Prestige joined #nim |
19:36:50 | leorize | and it's kinda weird that you'd return a hash as a string... |
19:37:56 | FromDiscord | <brainproxy> https://tenor.com/view/confused-ihave-no-idea-what-im-doing-gif-5948461 |
19:38:11 | FromDiscord | <brainproxy> having trouble getting the copyMem thing to work |
19:38:34 | leorize | but for those it's as easy as `result = cast[cstring](malloc(srcStr.len + 1)); copyMem(result, srcStr.cstring, srcStr.len), result[srcStr.len] = '\0'` |
19:38:52 | leorize | I'll write you a small example |
19:40:06 | * | tiorock joined #nim |
19:40:06 | * | tiorock quit (Changing host) |
19:40:06 | * | tiorock joined #nim |
19:40:06 | * | rockcavera quit (Killed (verne.freenode.net (Nickname regained by services))) |
19:40:06 | * | tiorock is now known as rockcavera |
19:40:26 | FromDiscord | <brainproxy> sent a code paste, see https://play.nim-lang.org/#ix=2t6M |
19:42:41 | disruptek | i'd say that rotten milk is an acquired taste, but i think truthfully, it's only something that, like, norwegians enjoy. |
19:42:56 | leorize | @brainproxy: https://play.nim-lang.org/#ix=2t6N |
19:44:12 | FromDiscord | <brainproxy> do I need to define c_malloc as in example or I can just import system/ansi_c? |
19:44:19 | Yardanico | better define it |
19:44:26 | Yardanico | ansi_c is undocumented internal API :) |
19:50:02 | FromDiscord | <brainproxy> okay, working, though I had to `import system/ansi_c`↵↵If I instead define the proc as in the example I get a compiler error |
19:50:07 | Yardanico | what error? |
19:50:11 | FromDiscord | <brainproxy> could just be a typo in the example, not sure |
19:50:53 | FromDiscord | <brainproxy> ```↵Undefined symbols for architecture x86_64:↵ "_c_malloc", referenced from:↵``` |
19:51:03 | Yardanico | are you sure it was exactly |
19:51:04 | Yardanico | proc c_malloc(size: csize_t): pointer {.importc, header: "<stdlib.h>".} |
19:51:05 | Yardanico | ? |
19:51:11 | Yardanico | ah right |
19:51:19 | Yardanico | do it like |
19:51:20 | Yardanico | proc c_malloc(size: csize_t): pointer {.importc: "malloc", header: "<stdlib.h>".} |
19:51:43 | Yardanico | same as in ansi_c when I linked you the code |
19:51:47 | Yardanico | https://github.com/nim-lang/Nim/blob/devel/lib/system/ansi_c.nim#L142 |
19:52:00 | FromDiscord | <brainproxy> works great, thanks so much! |
20:03:41 | FromGitter | <iffy> @dom96 do you have a plan for when the next choosenim release will be? Anything I can do to help? |
20:04:46 | FromDiscord | <Varriount> @brainproxy Your spirit animal is a floating Shiba Inu? |
20:05:53 | FromDiscord | <brainproxy> more like a role model than a spirit animal |
20:13:45 | FromDiscord | <kodkuce> i horror coded some stuff and now its starting to pile atop each other, am so close to finish risk is high 🙂 |
20:19:51 | FromDiscord | <exelotl> I wish I was a floating shiba inu |
20:20:00 | FromDiscord | <kodkuce> i survived , huh, i think my matchmaking serwer works now, learn a lot how to not *!$%** code for next time |
20:20:13 | FromDiscord | <kodkuce> why floating? |
20:20:30 | FromDiscord | <kodkuce> isent int shiba inu better? |
20:20:48 | FromDiscord | <exelotl> arbitrary precision shiba inu |
20:21:40 | Zevv | PMunch: they call it a spec, but parsing toml from that doc is not trivial |
20:30:16 | FromDiscord | <Zachary Carter> is there a way to change the name of the binary produced by nimble install? I tried setting the `out` switch in `config.nims` but it seems to have had no efect |
20:30:19 | FromDiscord | <Zachary Carter> (edit) 'efect' => 'effect' |
20:31:24 | FromDiscord | <Zachary Carter> oh I see there's an open feature for this - https://github.com/nim-lang/nimble/issues/515 |
20:31:25 | disbot | ➥ [Feature] Allow specifying name for the binary in binary packages |
20:31:55 | FromDiscord | <Zachary Carter> (edit) 'feature' => 'issue' |
20:35:01 | * | narimiran quit (Ping timeout: 264 seconds) |
20:49:55 | FromDiscord | <Recruit_main707> sent a code paste, see https://play.nim-lang.org/#ix=2t7b |
20:55:05 | FromDiscord | <Shucks> Isn't working for me either. Mentioned it some time ago ;p |
20:56:16 | FromDiscord | <Shucks> adding it to the local project nim.cfg works |
20:56:49 | FromDiscord | <Shucks> well, the gccpath line. |
21:02:00 | * | noonien joined #nim |
21:04:37 | * | endragor_ quit (Remote host closed the connection) |
21:05:05 | * | endragor joined #nim |
21:09:10 | * | Jesin quit (Quit: Leaving) |
21:09:23 | * | endragor quit (Ping timeout: 240 seconds) |
21:12:13 | * | solitudesf quit (Ping timeout: 264 seconds) |
21:14:20 | * | Tlongir joined #nim |
21:15:28 | * | Trustable quit (Remote host closed the connection) |
21:15:41 | * | casaca quit (Remote host closed the connection) |
21:16:02 | * | Tlanger quit (Ping timeout: 265 seconds) |
21:16:05 | * | casaca joined #nim |
21:18:03 | * | maier joined #nim |
21:19:42 | * | Vladar quit (Quit: Leaving) |
21:23:10 | * | maier quit (Ping timeout: 256 seconds) |
21:24:21 | * | Jesin joined #nim |
21:32:07 | * | Tlongir quit (Ping timeout: 246 seconds) |
21:40:55 | * | Tlongir joined #nim |
21:52:08 | * | endragor joined #nim |
21:53:11 | FromDiscord | <Varriount> Shucks: I'll be honest, the only time I've cross-compiled on Windows was targeting 32-bit windows when running 64-bit |
21:53:51 | FromDiscord | <Varriount> And that's usually done by just downloading Mingw targetting 32-bit windows. |
21:57:19 | * | endragor quit (Ping timeout: 246 seconds) |
21:57:27 | disruptek | Zevv: your tests pass, now that i've rewritten them. 😉 |
22:19:46 | * | endragor joined #nim |
22:24:49 | * | endragor quit (Ping timeout: 264 seconds) |
22:28:00 | leorize | rust is making my life hard on musl libc... |
22:28:54 | leorize | so much that I might consider migrating my system from musl back to glibc |
22:29:51 | FromDiscord | <Zachary Carter> I have an `arc` question... Let's say I have a main driver program that is loading a shared library (also compiled with `arc`) |
22:29:56 | FromDiscord | <Varriount> leorize: Rust? |
22:30:54 | FromDiscord | <Zachary Carter> sent a code paste, see https://play.nim-lang.org/#ix=2t7O |
22:31:05 | FromDiscord | <Zachary Carter> in the body of the function - bar is initialized to some value |
22:31:08 | leorize | yea, I'm on gentoo, and firefox and alacritty need rust |
22:31:29 | leorize | let just say that rust has never been made to properly support a system with musl libc as the main libc |
22:32:08 | FromDiscord | <Zachary Carter> how can I make this work with `--gc:arc` or can I? Do I just need to use `cstring ` and `copyMem`? |
22:32:46 | leorize | @Zachary even easier: compile both of them with -d:useMalloc |
22:32:49 | leorize | now you can pass memory seamlessly between the two |
22:33:30 | FromDiscord | <Varriount> leorize: Do you know where Nim stores the refcount to an object? |
22:33:34 | leorize | you will have to give up Nim's TSLF allocator, but for most cases this shouldn't negatively impact performance |
22:34:05 | leorize | @Varriount look at system/arc.nim |
22:34:39 | FromDiscord | <Varriount> leorize: Also, doesn't that assumes that the two pieces (program and shared library) are using the same malloc implementation? |
22:34:55 | FromDiscord | <Varriount> (the same version of glibc/etc) |
22:35:03 | FromDiscord | <Zachary Carter> hmmm - I may just have to write my own allocators then |
22:35:09 | leorize | both of them will dynamically link against glibc |
22:35:21 | leorize | or whatever libc that's on the system |
22:35:40 | FromDiscord | <Varriount> @Zachary Carter Is malloc not available? |
22:35:53 | FromDiscord | <Zachary Carter> no it is - but I'm worried about memory fragmentation |
22:36:04 | leorize | you can use libnimrtl |
22:36:14 | leorize | that's the alternative way |
22:36:24 | FromDiscord | <Zachary Carter> that works with `--gc:arc`? |
22:36:33 | leorize | yes, it will contain the allocator |
22:36:43 | FromDiscord | <Zachary Carter> gotcha |
22:36:49 | FromDiscord | <Zachary Carter> eh maybe implementating my own allocators won't be the worst thing in the world |
22:37:31 | leorize | you will most likely create a worse performing allocator |
22:37:38 | FromDiscord | <Zachary Carter> well I'll just use malloc |
22:37:39 | FromDiscord | <Varriount> http://www.mingw.org/wiki/Interoperability_of_Libraries_Created_by_Different_Compiler_Brands |
22:38:18 | FromDiscord | <Varriount> I believe that's also the reason why Python requires C extensions to be compiled using the same version of visual studio. |
22:38:51 | FromDiscord | <Zachary Carter> I think I'm just going to wrap malloc so I can do leak detection |
22:38:57 | leorize | seems to not be a problem for this case |
22:39:23 | leorize | just do -d:useMalloc, then sanitizers will just work |
22:39:35 | leorize | as well as valgrind, if you want to go that route |
22:39:42 | FromDiscord | <Varriount> Ah, here's what I was looking for: https://devblogs.microsoft.com/oldnewthing/20060915-04/?p=29723 |
22:39:59 | FromDiscord | <Zachary Carter> I've run into weird issues with asan and plugins |
22:40:28 | FromDiscord | <Varriount> I know symbol resolution works differently on Linux though |
22:41:19 | FromDiscord | <Zachary Carter> Okay I'm doing something stupid |
22:41:28 | leorize | this pretty much sums up why linux distros exist lol |
22:42:06 | leorize | and yea, on linux we invented this "symbol versioning" thing to "fix" the issue |
22:42:14 | leorize | it's terrible, but at least it works |
22:42:45 | FromDiscord | <Varriount> leorize: It's not that, it was something to do with DLLs being able to "see" symbols that other DLLs have loaded. |
22:42:52 | FromDiscord | <Varriount> On Linux |
22:43:27 | leorize | it's differences in how symbol binding is done |
22:44:30 | FromDiscord | <Varriount> Like, I believe the nimrtl shared library could technically be abandoned on Linux (the implementation would have to change, but its possible, whereas it's impossible on Windows) |
22:44:37 | FromDiscord | <Zachary Carter> https://gist.github.com/zacharycarter/f4ce2497eead09afd5704d5ee774d274 |
22:44:47 | FromDiscord | <Varriount> (edit) '(the' => '(Nim's runtimee' |
22:44:59 | leorize | nah, you'd still need nimrtl on linux |
22:45:06 | leorize | the shared state of the allocator matters too |
22:45:51 | leorize | most allocator maintain a graph containing the blocks they acquired from the operating system |
22:45:51 | FromDiscord | <Zachary Carter> my app just hangs when I call `unloadLib` |
22:46:32 | FromDiscord | <Varriount> Or maybe its that DLLs can access symbols provided by the executable? |
22:47:07 | FromDiscord | <Varriount> @Zachary Carter What currently happens when you compile & run everything? |
22:47:24 | leorize | @Zachary you need examples that actually compiles, or else it's hard to help :P |
22:48:11 | FromDiscord | <Zachary Carter> @Varriount the application just hangs and eats cpu when I unload the shared library |
22:48:19 | FromDiscord | <Zachary Carter> I can edit that into a minimal working example |
22:49:25 | FromDiscord | <Varriount> @Zachary Carter What OS are you on? |
22:49:30 | FromDiscord | <Zachary Carter> macOS |
22:51:27 | * | endragor joined #nim |
22:57:48 | FromDiscord | <Zachary Carter> leorize @Varriount - should compile now https://gist.github.com/zacharycarter/f4ce2497eead09afd5704d5ee774d274 |
23:00:04 | * | endragor quit (Ping timeout: 256 seconds) |
23:00:16 | FromDiscord | <Zachary Carter> just fixed the shared library extension for linux |
23:06:56 | FromDiscord | <Zachary Carter> ahhh |
23:07:18 | * | NimBot joined #nim |
23:09:42 | FromDiscord | <Zachary Carter> effing mac |
23:13:33 | leorize | looks like you found a test case for our tlsEmulation :p |
23:13:46 | FromDiscord | <Zachary Carter> 😄 |
23:14:26 | FromDiscord | <Zachary Carter> well I should have just put that flag in by default |
23:14:44 | FromDiscord | <Zachary Carter> because every time I've had an issue with threading on macOS that's always been 4raq's first suggestion |
23:14:53 | FromDiscord | <Zachary Carter> so I should have known better 😛 |
23:15:24 | leorize | dunno, maybe we should toggle that off for mac :P |
23:15:38 | leorize | when does mac have native thread var again? |
23:16:01 | * | endragor joined #nim |
23:16:03 | FromDiscord | <Zachary Carter> I think it already does |
23:16:12 | FromDiscord | <Zachary Carter> oh you mean what version |
23:16:26 | * | Guest8511 quit (Ping timeout: 256 seconds) |
23:16:29 | FromDiscord | <Zachary Carter> XCode 8 |
23:16:31 | FromDiscord | <Zachary Carter> is when it arrived |
23:16:47 | FromDiscord | <Zachary Carter> https://stackoverflow.com/questions/28094794/why-does-apple-clang-disallow-c11-thread-local-when-official-clang-supports/29929949#29929949 |
23:17:58 | * | dadada joined #nim |
23:18:22 | * | dadada is now known as Guest3540 |
23:18:56 | * | maier joined #nim |
23:24:13 | * | maier quit (Ping timeout: 264 seconds) |
23:25:31 | * | endragor quit (Ping timeout: 246 seconds) |
23:55:57 | * | krux02_ joined #nim |
23:58:23 | * | krux02 quit (Ping timeout: 244 seconds) |