Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Convert from L1 to L2, adding region constructs.
Synopsis
- data FullEnv
- type TiM a = ExceptT Failure (StateT InferState PassM) a
- type InferState = Map LocVar UnifyLoc
- type Result = (Exp2, Ty2, [Constraint])
- data UnifyLoc
- data Failure
- data Dest
- = SingleDest LocVar
- | TupleDest [Dest]
- | NoDest
- fresh :: TiM LocVar
- freshUnifyLoc :: TiM UnifyLoc
- finalUnifyLoc :: LocVar -> TiM UnifyLoc
- fixLoc :: LocVar -> TiM UnifyLoc
- freshLocVar :: String -> PassM LocVar
- finalLocVar :: LocVar -> TiM LocVar
- assocLoc :: LocVar -> UnifyLoc -> TiM ()
- finishExp :: Exp2 -> TiM Exp2
- prim :: Prim Ty1 -> PassM (Prim Ty2)
- emptyEnv :: FullEnv
- unify :: LocVar -> LocVar -> TiM a -> TiM a -> TiM a
- inferLocs :: Prog1 -> PassM Prog2
- inferExp :: FullEnv -> Exp1 -> Dest -> TiM Result
- inferExp' :: FullEnv -> Exp1 -> [LocVar] -> Dest -> TiM (Exp2, Ty2)
- convertFunTy :: ([Ty1], Ty1, Bool) -> PassM (ArrowTy2 Ty2)
- copyOutOfOrderPacked :: Prog1 -> PassM Prog1
- fixRANs :: Prog2 -> PassM Prog2
- removeAliasesForCopyCalls :: Prog1 -> PassM Prog1
Documentation
Combine the different kinds of contextual information in-scope.
type TiM a = ExceptT Failure (StateT InferState PassM) a Source #
The location inference monad is a stack of ExceptT and StateT.
type InferState = Map LocVar UnifyLoc Source #
The state of the inference procedure is a map from location variable
to UnifyLoc
, which is explained below.
This is a bit awkward, since after inference is done we have to make another
pass over the AST to update all the LocVar
s. One refactoring that would
make this less awkward would be to make a type-level distinction between
LocVar
s that occur before and after this pass.
Also, it would be more efficient to use mutable state directly for this,
or possibly some more sophisticated union find thing.
type Result = (Exp2, Ty2, [Constraint]) Source #
The result type for this pass. Return a new expression and its type, which includes/implies its location.
A location is either fixed or fresh. Two fixed locations cannot unify.
Destination can be a single location var, a tuple of destinations, or nothing (for scalar values)
Instances
Out Dest Source # | |
Generic Dest Source # | |
Show Dest Source # | |
type Rep Dest Source # | |
Defined in Gibbon.Passes.InferLocations type Rep Dest = D1 ('MetaData "Dest" "Gibbon.Passes.InferLocations" "gibbon-0.3-inplace" 'False) (C1 ('MetaCons "SingleDest" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 LocVar)) :+: (C1 ('MetaCons "TupleDest" 'PrefixI 'False) (S1 ('MetaSel ('Nothing :: Maybe Symbol) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [Dest])) :+: C1 ('MetaCons "NoDest" 'PrefixI 'False) (U1 :: Type -> Type))) |
finishExp :: Exp2 -> TiM Exp2 Source #
Transforms an expression by updating all locations to their final mapping as a result of unification.
unify :: LocVar -> LocVar -> TiM a -> TiM a -> TiM a Source #
Unify is a conditional form that takes a "success branch" and "failure branch". In the case of failure, it makes no change to the store. In the case of success, the new equalities are placed in the store before executing the success branch.
inferExp :: FullEnv -> Exp1 -> Dest -> TiM Result Source #
We proceed in a destination-passing style given the target region into which we must produce the resulting value.
inferExp' :: FullEnv -> Exp1 -> [LocVar] -> Dest -> TiM (Exp2, Ty2) Source #
Wrap the inferExp procedure, and consume all remaining constraints
convertFunTy :: ([Ty1], Ty1, Bool) -> PassM (ArrowTy2 Ty2) Source #
This helper exemplifies the simplicity of our current approach. If we assume output regions are disjoint from input ones, then we can instantiate an L1 function type into a polymorphic L2 one, mechanically.