Phi missing predecessor in CFG

Bug #567082 reported by Matt Giuca
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mars
Fix Released
Critical
Matt Giuca

Bug Description

The following code results in an error "Phi missing predecessor in CFG" if you run twoswitch(Nothing, Nothing):

type Maybe(a):
    Nothing
    Just(a)

def twoswitch(x :: Maybe(a), y :: Maybe(a)) :: Int:
    switch x:
        case Nothing:
            switch y:
                case Nothing:
                    return 0
                case Just(m):
                    return 1
        case Just(m):
            return 2

There is flaw in the generation of the phi for the exit block in ast_cfg. reconcile_def_map is supposed to avoid generating a Phi if the variable is not bound in all predecessors. However, the PredMap for the variable "m" is:
{bbref(4): bound(m:2), bbref(7): bound(m:0)}
Note that unbound variables are supposed to have a mapping entry for each predecessor. 3 is a predecessor. "bbref(3): unbound" should be in the PredMap, not be omitted. (This would cause reconcile_def_map to avoid generating the phi at all, which is what we want, since the variable m can't be accessed from the exit block.)

This is caused by the fact that the variable m is not actually in-scope in block 3, and therefore it isn't considered "unbound" -- it is not considered to exist.

Related branches

Matt Giuca (mgiuca)
description: updated
Matt Giuca (mgiuca)
description: updated
Changed in mars:
importance: High → Critical
status: Incomplete → Triaged
Revision history for this message
Matt Giuca (mgiuca) wrote :

A (possibly dodgy) solution to this is to avoid any block-level scoped variables. If all variables are scoped to the function, then they will definitely appear in the PredMap.

This was not always the case, but as of newtypes branch, r1019, it is (bug #513638). The above example no longer breaks from that revision onwards.

Comment in ast_cfg explaining this, in newtypes r1038 (considered fixed).

Changed in mars:
status: Triaged → Fix Committed
Revision history for this message
Matt Giuca (mgiuca) wrote :

Merged to trunk, r1030.

Matt Giuca (mgiuca)
Changed in mars:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.