Commit Graph

32 Commits

Author SHA1 Message Date
Nathan Braswell
5cdaafebe2 Change lapply to optionally take in an explicit env, make it optional for vapply so they match, then tweak Y such that it threads the dynamic env through, then implement eta-reduction in the compiler backend. This provides about the same speedup again from the Y elimination, as it's kinda the other half for fully getting rid of Y such that there's just static recursive calls. fib.kp went from 1.7 -> 1.1 -> 0.5, and fib_let similarly. fib.kp is now faster than fib_manual, but just by a bit. 2022-04-17 01:52:01 -04:00
Nathan Braswell
1149363e62 Add debug_levels and turn off stack_traces by default, but save enough info about the last interaction with the top-level loop to enable re-running to problem spot with debugging on if it happens, and it works! This is the first step towards the opt/non-opt-wrap work while maintaining debugability 2022-04-09 00:45:58 -04:00
Nathan Braswell
0c554078bd Found the offending code for the infinate recursion, though not exactly why it happens. Minimal reproducer seemingly found 2022-03-20 20:50:39 -04:00
Nathan Braswell
1b220023bc Fix cond to not die on guarded errors, implement a new if in macro-style, port some more over to_compile.kp. Stopped just before 'vau, which seems to loop forever or somesuch 2022-03-13 15:11:30 -04:00
Nathan Braswell
d1b6e520f9 Added support for strings to array functions for evaluator (compiled is next) 2022-03-12 20:19:00 -05:00
Nathan Braswell
d87f292c1c Additional optimization using intset for env_stack, some small bugfixes regarding not making a marked_array out of components that errored, moved over a lot of code to to_compile.kp. 2022-03-10 01:06:44 -05:00
Nathan Braswell
a08415e1e6 Cleanup & some demo code for presentation 2022-03-08 15:55:59 -05:00
Nathan Braswell
7fed3a58f5 Added more to to_compile.kp and runtime started growing again - main bottleneck was the silly using lists as sets thing, changed the small-int uses of these to a new custom bitset and brought the time from 47s back down to 6s. There is a remaining hotspot where partial_eval_helper matches needed_for_progress vs the bitset, but that'll have to wait for tomorrow. Thinking of maintaining a env_stack bitset and adding a bitset_union_nonempty function. Note the new bitset does use some cons/car/cdr operations that'll be a bit different in Kraken, which I'll need to look at. Maybe when porting I can just use indexing if there's not a great way to unify them. 2022-03-08 02:54:26 -05:00
Nathan Braswell
bf1f81cdf3 Implement and and or. Looks like nil doesn't currently count as false, based false? and it seems to be avoided even with the compiled 'vcond, though it looks like it shouldn't (oh this is probs it being partially evaled ahead of time, isn't it?) Anyway, we might want to finish this and remove it from vcond too 2022-03-03 09:28:01 -05:00
Nathan Braswell
8cdf41826b Starting to port over & self-host! 2022-03-03 00:33:25 -05:00
Nathan Braswell
4a273c9ba2 Bigfix error infinite recursion, error printing, wrap_level not being in hash_comb, extend to_compile.kp a bit 2022-03-02 01:44:20 -05:00
Nathan Braswell
f8bab2ada5 I caught the Chicken compiler red handed, it's compiled version has zip change behavior part way through, caught in the act with some prints. Where it does so changes based on optimization level, which is a bad sign. Starting a (hopfully quick) port to more standard scheme - looking to support Chez and Gambit in addition to Chicken, with at least some commented out code if not some sort of conditional compilation. We're off to a roaring start with define-syntax broken in Gambit 4.9.3, from 2019, but there was a new version released last month that I think should fix it. 2022-02-22 02:19:17 -05:00
Nathan Braswell
58f3d7858e Rework the destructuring lambda in what I'm now calling the true-macro-style, so that helper functions don't close over the dynamic env and cause it to not partially evaluate away 2022-02-20 23:42:09 -05:00
Nathan Braswell
2874be3332 Fix the bug with de getting seperate dynamic envs, now unified but no opts for now (doing it seperetly was broken because of tyring to access it from inner closures. Also add a lot more runtime logging 2022-02-20 22:12:21 -05:00
Nathan Braswell
6cd9dd0831 Move over much more code, including the tricky destructuring lambda which revealed bug in the need_for_progress system - a call that takes in the dynamic env that failed and had to be re-constructed would set attempted on the call to true, but would not note the dynamic environment as one of the needed-for-progress idxs. Often I think it would be anyway, so this didn't come up too often, and of course finally revealed itself when doing nested let/lambda destructuring stuff. Fixed by having attempted record not just true or false, but in the case where it's a call that takes in the dynamic env, makes it that env's id, which gets added to the for_progress_idxs. 2022-02-19 00:14:36 -05:00
Nathan Braswell
dd2191f75d Made vapply and lapply primitives for efficiency/partial eval reasons. It means they can exist in emitted code without calling out to eval, which is good. to_compile.kp now both compiles and runs! Now to add more 2022-02-15 23:16:27 -05:00
Nathan Braswell
931dd9a8f5 Implement drop_redundent_veval and make veval properly re-partially-eval and update the env it's called with. Y combiner test added and works now, map still seems not to, about to look at it 2022-02-07 00:31:51 -05:00
Nathan Braswell
76065d1957 Implement veval and combiner_return_ok enhancements, now let4.3 behaves like the proper macro expansion. Compiling our test doesn't work though, it doesn't partial evalaute the vaus away as expected - changing let1 implementations does have an effect. Will need to investigate, as well as add support for compiling away veval 2022-02-05 12:14:13 -05:00
Nathan Braswell
a8f8f9df89 Removed check_for_symbols, which was a bad idea generally. Simplify into combiner_return_ok, and fix *eval bug* - it didn't check for any sort of combiner_return_ok like thing, even though it's doing the same thing as a function call basically, by changing the env something is evaluated in.
Also just re-write eval using the parital_eval wrapper, enforce it taking in total-values.

In the future, can allow more partial eval
        1) veval, returned from eval and posssibly others, essentailly (unwrap eval), which allows embedding partially-complete evals places without having to do something ugly like (eval (ensure_val partially_evaluated))
        2) Relax paramter is total-value to head-value and check for env_id inside it

Immediatly: Debug bad partial evaluation on main test cases & crash with list index out of range
2022-02-03 02:41:14 -05:00
Nathan Braswell
315ae20698 Clean up strip, have default memory allocation scale based on constants, added more until the next bug found, map seems not to be partially evaluating properly 2022-01-28 00:26:46 -05:00
Nathan Braswell
90750933fc Fixed the recursion! Memo has moved to just being the infinite recursion detector based on body and inner-env 2022-01-27 21:54:15 -05:00
Nathan Braswell
2746e1ca75 contains_symbols is/was exhibiting exponential behavior - probs memoizing or using needed_for_eval could fix it, but also it doesn't normally have to be called, so just doing that got us a 50x speedup or so 2022-01-26 23:43:50 -05:00
Nathan Braswell
3748610dea Can finally compile let! The memoization of partial_eval was allowing re-introduction of fake envs somehow. Temporarily disabled, also added a bunch of debugging aids like str_strip only printing envs in full the first time, need_value being passed through compile to fail faster, etc 2022-01-26 22:41:29 -05:00
Nathan Braswell
9bc658a1a4 Ah, found additional infinate recursion. In the process of fixing the second, trickier one, caused by compile & partial eval together. Should be fixed? but there's a nil coming out somewhere 2022-01-26 01:55:38 -05:00
Nathan Braswell
d4752eddb4 Fixed the bug! ctx has env in it, and was being returned upwards, messing up the environment of subsequently compiled things. The key is to make sure things that modify the environment (compiling functions) return the env it was passed in the ctx 2022-01-25 16:51:06 -05:00
Nathan Braswell
77c7a05a28 Hopefully fixed the new exponential behavior by piggybacking on a now more accurate needed-for-eval tracking (that hopefully didn't introduce it's own exponential behavior but might have), and other fixes. We still have the same weird problem though 2022-01-23 14:16:07 -05:00
Nathan Braswell
94e2d62a10 Ok, finished fixing check_for_env_id_in_result, now works up to before. Weirdly, we're now just back to the previous error, and I think I might have reintroduced exponential behavior with the env_id searching 2022-01-22 00:56:02 -05:00
Nathan Braswell
99926cdb7c check_for_env_id_in_result fixed, I had accidentally left it unimplemented. Bug with envs escaping when they weren't real fixed, and most everything works, but compiling lapply fails now 2022-01-22 00:19:10 -05:00
Nathan Braswell
6602ff3151 The refactor has either caught up, or is close, and is much faster.
Need to make partial_eval_helper able to fail though, so that it can fail in the now fallible compiler.

Squashed commit of the following:

commit 283150d1e19cf9f74bc32e9c554f5e041d53582d
Author: Nathan Braswell <miloignis@gmail.com>
Date:   Tue Jan 18 00:14:51 2022 -0500

    Another bugfix, I think now we're truely running into the partial-eval needs to be able to fail part

commit c62c228a1e89e7922850d2070bc046e5f80af5a5
Author: Nathan Braswell <miloignis@gmail.com>
Date:   Mon Jan 17 23:34:19 2022 -0500

    Fixed needed check, added note on needing to support failing partial eval

commit d480e486210dd5c7c4842e3a3d3e447dc7a5274e
Author: Nathan Braswell <miloignis@gmail.com>
Date:   Mon Jan 17 22:14:58 2022 -0500

    Fixed compilation bugs, added debugging prints to running.

commit fc4dc4d3170bf1ceb4cd934cff54dd9ce6c8713a
Author: Nathan Braswell <miloignis@gmail.com>
Date:   Mon Jan 17 17:28:29 2022 -0500

    The unique id / ctx refactor is starting to work, with all basic test cases compiling & partial evaling, but mis-compile bugs remaining
2022-01-18 00:36:42 -05:00
Nathan Braswell
6ef60c4cc6 I belive I fixed the bug revealed by the let definition - it was a similar thing where <comb>s were counted as values even if there were fake envs inside, and then thouse fake envs could be moved inside another env_stack and then later resolve to a wrong env, or at lest I think that's what was happening. The let test takes too long to run now - I killed it at 20 minutes and 48GB of RAM taken. Given that, it's now time to move on towards optimization 2022-01-07 22:08:29 -05:00
Nathan Braswell
b559bfdf90 Add note about compiling params meant for Vau & additional partial eval for that case to help in cases where it's legitimate. Eventually it should handle errors gracefully, but non-gracefully can be good enough for now. 2022-01-05 22:58:26 -05:00
Nathan Braswell
1aa9ca972a Fix & and error checking for compiling environments as code & value, add a todo for things deferred 2022-01-05 01:05:16 -05:00