Skip to content

Commit

Permalink
Clean up.
Browse files Browse the repository at this point in the history
  • Loading branch information
thealmarty committed Mar 17, 2023
1 parent 105f7a8 commit 7e34fcd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
Expand Up @@ -203,13 +203,13 @@ collectArgs expr
mkApps :: Term tyname name uni fun ann
-> ArgOrderWithAnn tyname name uni fun ann
-> Term tyname name uni fun ann
mkApps f ((MkTermArg tmArg,ann) : args) = mkApps (Apply ann f tmArg) args
mkApps f ((MkTypeArg tyArg,ann) : args) = mkApps (TyInst ann f tyArg) args
mkApps f [] = f
mkApps f ((MkTermArg tmArg, ann) : args) = mkApps (Apply ann f tmArg) args
mkApps f ((MkTypeArg tyArg, ann) : args) = mkApps (TyInst ann f tyArg) args
mkApps f [] = f

enoughArgs :: Arity -> ArgOrder tyname name uni fun ann -> Bool
enoughArgs [] (_argsOrder:_as) = True
enoughArgs (_arity:_) [] = False
enoughArgs [] (_argsOrder:_as) = True -- over-application
enoughArgs (_arity:_) [] = False -- under-application
enoughArgs [] [] = True
enoughArgs lamOrder argsOrder =
-- start comparing from the end because there may be over-application
Expand All @@ -234,6 +234,7 @@ inlineSat appTerm@(Apply _varAnn _fun _arg) = do
case maybeVarInfo of
-- the variable is not in the map that contains all the in-scope functions, this shouldn't
-- happen? TODO maybe error out instead?
-- Have checked that with the current tests it doesn't happen
Nothing -> forMOf termSubterms appTerm inlineSat
Just varInfo -> do
if enoughArgs (arity varInfo) (map fst args) then
Expand All @@ -243,7 +244,7 @@ inlineSat appTerm@(Apply _varAnn _fun _arg) = do
else forMOf termSubterms appTerm inlineSat
-- if the term being applied is not a `Var`, don't inline, but keep checking
v -> forMOf termSubterms v inlineSat -- keep checking all subterms
inlineSat tyInstTerm@(TyInst varAnn fun arg) = do
inlineSat tyInstTerm@(TyInst _varAnn _fun _arg) = do
-- collect all the arguments of the term being applied to
let argsAppliedTo = fst $ collectArgs tyInstTerm
args = snd $ collectArgs tyInstTerm
Expand Down
Expand Up @@ -229,8 +229,9 @@ processSingleBinding
-> Binding tyname name uni fun ann -- ^ The binding.
-> InlineM tyname name uni fun ann (Maybe (Binding tyname name uni fun ann))
processSingleBinding body = \case
-- when the let binding is a function type AND it's not unconditionally inlined, we add it to
-- the `CalledVarEnv` and consider whether we want to inline at the call site.
-- The let binding is a function type here.
-- If it's not unconditionally inlined, we add it to the `CalledVarEnv`
-- and consider whether we want to inline at the call site.
TermBind ann s v@(VarDecl _ n (TyFun _ _tyArg _tyBody)) rhs -> do
-- we want to do unconditional inline if possible
maybeRhs' <- maybeAddSubst body ann s n rhs
Expand All @@ -241,8 +242,8 @@ processSingleBinding body = \case
let
varLamOrder = fst $ computeArity rhs
bodyToCheck = snd $ computeArity rhs
-- add the function to `CalledVarEnv`, because we may want to inline this at the
-- call site. We don't remove the binding because we decide *at the call site*
-- add the function to `CalledVarEnv`, because we may want to inline this.
-- We don't remove the binding because we decide *at the call site*
-- whether we want to inline, and it may be called more than once.
void $ modify' $ extendCalled n (MkCalledVarInfo rhs varLamOrder bodyToCheck)
pure $ Just $ TermBind ann s v rhsProcess
Expand Down

0 comments on commit 7e34fcd

Please sign in to comment.