-
Notifications
You must be signed in to change notification settings - Fork 147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prefix names of inlined functions #958
Conversation
diff --git a/clash-lib/src/Clash/Normalize/Transformations.hs b/clash-lib/src/Clash/Normalize/Transformations.hs
index 84cfcbe7..cadb0cf1 100644
--- a/clash-lib/src/Clash/Normalize/Transformations.hs
+++ b/clash-lib/src/Clash/Normalize/Transformations.hs
@@ -1722,9 +1722,9 @@ recToLetRec (TransformContext is0 []) e = do
= and (zipWith (eqArg tcm) args args2)
eqApp _ _ _ _ = False
- eqArg _ v1 v2@(Var {})
+ eqArg _ v1 v2@(stripTicks -> Var {})
= v1 == v2
- eqArg tcm v1 v2@(collectArgs -> (Data _, args'))
+ eqArg tcm v1 v2@(collectArgs . stripTicks -> (Data _, args'))
| let t1 = termType tcm v1
, let t2 = termType tcm v2
, t1 == t2 , t1 == t2 Fixes The gist of the above fix is that the |
Your ability to conjure fixes out of thin air never ceases to amaze 👍 |
The name conflicts are a result in not being in normal form, I'm seeing:
i.e. a nested-letbinding. Haven't figured out why |
Okay, it's not diff --git a/clash-lib/src/Clash/Normalize/Transformations.hs b/clash-lib/src/Clash/Normalize/Transformations.hs
index 84cfcbe7..860ea32b 100644
--- a/clash-lib/src/Clash/Normalize/Transformations.hs
+++ b/clash-lib/src/Clash/Normalize/Transformations.hs
@@ -715,7 +715,7 @@ nonRepANF _ e = return e
-- the body is a variable-reference.
topLet :: HasCallStack => NormRewrite
topLet (TransformContext is0 ctx) e
- | all (\c -> isLambdaBodyCtx c || isTickCtx c) ctx && not (isLet e)
+ | all (\c -> isLambdaBodyCtx c || isTickCtx c) ctx && not (isLet e) && not (isTick e)
= do
untranslatable <- isUntranslatable False e
if untranslatable
@@ -723,6 +723,9 @@ topLet (TransformContext is0 ctx) e
else do tcm <- Lens.view tcCache
argId <- mkTmBinderFor is0 tcm (mkUnsafeSystemName "result" 0) e
changed (Letrec [(argId, e)] (Var argId))
+ where
+ isTick Tick {} = True
+ isTick _ = False
topLet (TransformContext is0 ctx) e@(Letrec binds body)
| all (\c -> isLambdaBodyCtx c || isTickCtx c) ctx |
And finally, diff --git a/clash-lib/src/Clash/Netlist/Util.hs b/clash-lib/src/Clash/Netlist/Util.hs
index 7cadafed..a727bfbd 100644
--- a/clash-lib/src/Clash/Netlist/Util.hs
+++ b/clash-lib/src/Clash/Netlist/Util.hs
@@ -70,13 +70,13 @@ import Clash.Core.Subst
extendInScopeIdList, mkSubst, substTm)
import Clash.Core.Term
(Alt, LetBinding, Pat (..), Term (..), TickInfo (..), NameMod (..),
- collectArgsTicks)
+ collectArgsTicks, collectTicks)
import Clash.Core.TyCon
(TyConName, TyConMap, tyConDataCons)
import Clash.Core.Type (Type (..), TypeView (..),
coreView1, splitTyConAppM, tyView, TyVar)
import Clash.Core.Util
- (collectBndrs, stripTicks, substArgTys, termType, tyLitShow)
+ (collectBndrs, stripTicks, substArgTys, termType, tyLitShow, mkTicks)
import Clash.Core.Var
(Id, Var (..), mkLocalId, modifyVarName, Attr')
import Clash.Core.VarEnv
@@ -129,9 +129,9 @@ splitNormalized
-> Term
-> (Either String ([Id],[LetBinding],Id))
splitNormalized tcm expr = case collectBndrs expr of
- (args,Letrec xes e)
+ (args,collectTicks -> (Letrec xes e,ticks))
| (tmArgs,[]) <- partitionEithers args -> case stripTicks e of
- Var v -> Right (tmArgs,xes,v)
+ Var v -> Right (tmArgs,map (second (`mkTicks` ticks)) xes,v)
_ -> Left ($(curLoc) ++ "Not in normal form: res not simple var")
| otherwise -> Left ($(curLoc) ++ "Not in normal form: tyArgs")
_ -> |
b079ff1
to
197eefb
Compare
@@ -129,9 +129,9 @@ splitNormalized | |||
-> Term | |||
-> (Either String ([Id],[LetBinding],Id)) | |||
splitNormalized tcm expr = case collectBndrs expr of | |||
(args,Letrec xes e) | |||
(args, collectTicks -> (Letrec xes e, ticks)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is: ticks can wrap any term, so any time you match on a term you should make sure that
- it either has no ticks
- or to call
collectTicks
This seems like an impossible thing to do correctly, so ideally I'd like to see a solution where the compiler forces us to handle ticks. Could we think about this please? (Not for this PR though.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Core logic looks good. Please remove debugging statements.
clash-lib/src/Clash/Normalize.hs
Outdated
@@ -19,6 +19,9 @@ | |||
|
|||
module Clash.Normalize where | |||
|
|||
import Debug.Trace -- TODO |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO? :P
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should have more random TODOs scattered in the code. After all, our work is never done 😉
clash-lib/src/Clash/Normalize.hs
Outdated
@@ -323,6 +331,7 @@ flattenCallTree (CBranch (nm,(nm',sp,inl,tm)) used) = do | |||
_ -> do | |||
-- To have a cheap `appProp` transformation we need to | |||
-- deshadow, see also Note [AppProp no-shadow invariant] | |||
-- TODO Tick inline? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you mean with "tick inline"?
, "\nRun with '-fclash-inline-limit=N' to increase" | ||
, " the inlining limit to N." | ||
]) | ||
(return e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should spend some time on building a quasiquoter.. (Again, not for this PR.)
@@ -399,9 +401,16 @@ inlineNonRep (TransformContext localScope _) e@(Case scrut altsTy alts) | |||
case (nonRepScrut, bodyMaybe) of | |||
(True,Just (_,_,_,scrutBody0)) -> do | |||
Monad.when noException (zoomExtra (addNewInline f cf)) | |||
|
|||
traceM $ "inlineNonRep: " <> (Text.unpack . nameOcc $ varName f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^
@@ -968,8 +980,13 @@ inlineWorkFree (TransformContext localScope _) e@(collectArgsTicks -> (Var f,arg | |||
if isRecBndr | |||
then return e | |||
else do | |||
-- See Note [AppProp no-shadow invariant] | |||
changed (mkApps (mkTicks (deShadowTerm localScope body) ticks) args) | |||
traceM $ "inlineWorkFree: " <> (Text.unpack . nameOcc $ varName f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^
-- TODO This currently doesn't change clashing names when a | ||
-- tick is added, causing tests like LambdaDrop to fail. | ||
|
||
traceM $ "inlineSmall: " <> (Text.unpack . nameOcc $ varName f) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^
-- | A tick to prefix an inlined expression with it's original name. | ||
-- |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An example would be nice here
@@ -356,11 +357,18 @@ force :: Heap -> Stack -> Id -> Maybe State | |||
force (Heap gh g@(GPureHeap gbl) h ids is) k x' = case lookupVarEnv x' h of | |||
Nothing -> case lookupVarEnv x' gbl of | |||
Just e | isGlobalId x' | |||
-> Just (Heap gh (GPureHeap (delVarEnv gbl x')) h ids is,GUpdate x':k,e) | |||
-> let e' = tickExpr e | |||
in do traceM $ "force: " <> (Text.unpack . nameOcc $ varName x') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of these traces will be removed for the final PR I assume?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, I thought this was the final PR.
197eefb
to
973c794
Compare
Identifiers which are assigned an inlined function now have a prefix with the name of the function that was inlined. This makes it clearer what the provinence of an assigment is in HDL.
d96bb55
to
ac1dd7c
Compare
Identifiers which are assigned an inlined function now have a
prefix with the name of the function that was inlined. This makes
it clearer what the provinence of an assigment is in HDL.