Commit Graph

20 Commits

Author SHA1 Message Date
Kartik Agaram 377b00b045 4265
Standardize use of type ingredients some more.
2018-06-17 19:53:52 -07:00
Kartik K. Agaram 504292f6f1 4106 2017-11-03 18:01:59 -07:00
Kartik K. Agaram 514f0e34aa 4089
Clean up how we reclaim local scopes.

It used to work like this (commit 3216):

  1. Update refcounts of products after every instruction, EXCEPT:

      a) when instruction is a non-primitive and the callee starts with
      'local-scope' (because it's already not decremented in 'return')

    OR:

      b) when instruction is primitive 'next-ingredient' or
      'next-ingredient-without-typechecking', and its result is saved to a
      variable in the default space (because it's already incremented at
      the time of the call)

  2. If a function starts with 'local-scope', force it to be reclaimed
  before each return. However, since locals may be returned, *very
  carefully* don't reclaim those. (See the logic in the old `escaping`
  and `should_update_refcount` functions.)

However, this approach had issues. We needed two separate commands for
'local-scope' (reclaim locals on exit) and 'new-default-space'
(programmer takes charge of reclaiming locals). The hard-coded
reclamation duplicated refcounting logic. In addition to adding
complexity, this implementation failed to work if a function overwrites
default-space after setting up a local-scope (the old default-space is
leaked). It also fails in the presence of continuations. Calling a
continuation more than once was guaranteed to corrupt memory (commit
3986).

After this commit, reclaiming local scopes now works like this:

  Update refcounts of products for every PRIMITIVE instruction.
  For non-primitive instructions, all the work happens in the `return`
  instruction:
    increment refcount of ingredients to `return`
      (unless -- one last bit of ugliness -- they aren't saved in the
      caller)
    decrement the refcount of the default-space
      use existing infrastructure for reclaiming as necessary
      if reclaiming default-space, first decrement refcount of each
      local
        again, use existing infrastructure for reclaiming as necessary

This commit (finally!) completes the bulk[1] of step 2 of the plan in
commit 3991. It was very hard until I gave up trying to tweak the
existing implementation and just test-drove layer 43 from scratch.

[1] There's still potential for memory corruption if we abuse
`default-space`. I should probably try to add warnings about that at
some point (todo in layer 45).
2017-10-22 23:48:03 -07:00
Kartik K. Agaram 85553e522c 3747 2017-02-07 00:25:27 -08:00
Kartik K. Agaram 3c4c9c0807 3744
Undo 3743. Really any time we create new instructions from whole cloth
during rewriting or transform, the whole notion of 'original name' goes
out the window. Pointless trying to fight that fact of life.
2017-02-07 00:07:16 -08:00
Kartik K. Agaram d9e39b3b1c 3743
One way to ensure we always set old_name is to create a method to
initialize names as opposed to just assigning them.

Still not ideal because we still assign directly most of the time, so
it's easy to forget.
2017-02-07 00:05:38 -08:00
Kartik K. Agaram cfa5a9f887 3692
If we're automatically passing ingredients to 'append' through 'to-text'
if its first ingredient is text, we don't need to pass that first
ingredient itself through 'to-text'.
2016-11-25 22:17:39 -08:00
Kartik K. Agaram d8509b4175 3555 2016-10-22 16:10:23 -07:00
Kartik K. Agaram e939023612 3553
Tag all transforms as idempotent or not.
I'd fallen off this wagon.
I might even be getting it wrong. Something a type system should
automatically verify.
2016-10-22 12:16:02 -07:00
Kartik K. Agaram 6c96a437ce 3522 2016-10-19 22:10:35 -07:00
Kartik K. Agaram 5813bcfc7d 3520
Drop a few debug prints. Hopefully now we need never duplicate trace
statements and can instead just dump them to screen.

I'll soon need the ability to selectively dump traces for a specific
label.
2016-10-18 10:44:40 -07:00
Kartik K. Agaram a0331a9b0e 3390 2016-09-17 13:00:39 -07:00
Kartik K. Agaram 760f683f27 3389 2016-09-17 12:55:10 -07:00
Kartik K. Agaram 7a84094adb 3385 2016-09-17 10:28:25 -07:00
Kartik K. Agaram d52406ccd9 3381 2016-09-17 00:46:03 -07:00
Kartik K. Agaram 78c5020531 3374 2016-09-16 23:57:55 -07:00
Kartik K. Agaram 864cbf9d0c 3368
Decouple layer 61 test from layer 62 dependency.
2016-09-15 17:43:10 -07:00
Kartik K. Agaram b75d9d456c 3365 - create strings out of arbitrary types
The implementation is quite hacky. Let's see how future needs develop
before we try to clean it up.
2016-09-15 14:04:22 -07:00
Kartik K. Agaram d63cddeac0 3364 2016-09-15 13:23:00 -07:00
Kartik K. Agaram eb45abde2f 3359 2016-09-15 11:48:01 -07:00