Description
Once #44904 is fixed, the next step is to start adding constraints. I think that the liveness constraints are the easiest to add. These come in two forms. The first part are the constraints that are due to active uses, and the other are constraints due to drops.
The basic idea is this:
- If at some point P a value V may be used again (excluding future drops):
- Then all lifetimes appearing in the type of V must be live at P.
- If at some point P a value V may be dropped:
- Then all lifetimes appearing in the type of V which are not marked as may-dangle must be live at P.
That said, I think that, for this first issue, we should basically just ignore the special case of drop. In fact, we are going to want to make a few further refinements as discussed here -- in particular extending this code to consider not only liveness, but also which values are initialized. Let's ignore all of that for now and just get the basics up and going.
As it happens, we have some existing code for computing which values are live, located here. Unfortunately, it has some limitations:
- First off, it doesn't distinguish drops from other uses, but let's ignore that for now.
- In the prototype, distinguishing drops is done by having two distinct bits that we track per variable.
- Second, it only computes the liveness at basic block boundaries.
- We're going to need finer-grained information.
- The liveness code has the kind of "classic" setup of computing overall defs and uses for the entire basic block, then applying those.
- In the prototype, we use a slightly different setup, where we
- have one big bit-set storing all the things that are live on entry to a basic block -- we don't store the things live on exit, we can easily recompute that by unioning together the preds
- have a function
walk()
that will tell you what is leave in between each action in a basic block:
I'm not sure if we want to take precisely the same approach with the liveness code or not. It's a convenient setup, in any case, since we can then re-use this same "simulate" code to compute the fixed-point and -- after the fixed-point is computed -- to find the live bits at any particular point within the basic block.
Anyway, I have to run now, so I'll try to write up more mentoring notes later on.