Skip to content

Commit

Permalink
Cache constraint set in solver state
Browse files Browse the repository at this point in the history
This way we don't need to recompute it all the time and it runs much
faster.
  • Loading branch information
edwinb committed Mar 22, 2015
1 parent 83ff2b6 commit 9dc7105
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Idris/Core/Constraints.hs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ data SolverState =
, domainStore :: M.Map Var ( Domain
, S.Set ConstraintFC -- constraints that effected this variable
)
, cons_lhs :: M.Map Var (S.Set ConstraintFC)
, cons_rhs :: M.Map Var (S.Set ConstraintFC)
}

data Queue = Queue [ConstraintFC] (S.Set UConstraint)
Expand Down Expand Up @@ -60,6 +62,8 @@ solve maxUniverseLevel ucs =
, v <- varsIn c
]
]
, cons_lhs = constraintsLHS
, cons_rhs = constraintsRHS
}

lhs (ULT (UVar x) _) = Just (Var x)
Expand Down Expand Up @@ -175,8 +179,9 @@ solve maxUniverseLevel ucs =

-- | add all constraints (with the given var on the lhs) to the queue
addToQueueLHS :: MonadState SolverState m => UConstraint -> Var -> m ()
addToQueueLHS thisCons var =
case M.lookup var constraintsLHS of
addToQueueLHS thisCons var = do
clhs <- gets cons_lhs
case M.lookup var clhs of
Nothing -> return ()
Just cs -> do
Queue list set <- gets queue
Expand All @@ -189,8 +194,9 @@ solve maxUniverseLevel ucs =

-- | add all constraints (with the given var on the rhs) to the queue
addToQueueRHS :: MonadState SolverState m => UConstraint -> Var -> m ()
addToQueueRHS thisCons var =
case M.lookup var constraintsRHS of
addToQueueRHS thisCons var = do
crhs <- gets cons_rhs
case M.lookup var crhs of
Nothing -> return ()
Just cs -> do
Queue list set <- gets queue
Expand Down

0 comments on commit 9dc7105

Please sign in to comment.