-
-
Notifications
You must be signed in to change notification settings - Fork 36
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
Peephole optims, var scoping (fixes #153) #349
Conversation
src/rewriter.fs
Outdated
| Decl (ty, [declElt]), (Expr (FunCall (Op "=", [Var name2; init2])) as assign2) | ||
when declElt.name.Name = name2.Name | ||
&& not (exprUsesIdentName init2 declElt.name.Name) | ||
&& declElt.init |> Option.defaultValue (Int (0, "")) |> isPure -> |
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.
Can be written as:
declElt.init |> Option.map isPure |> Option.defaultValue true
or shorter:
declElt.init |> Option.forall isPure
let exprUsesIdentName expr identName = | ||
let mutable idents = [] | ||
let collectLocalUses _ = function | ||
| Var v as e -> idents <- v :: idents; 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.
Consider replacing idents with a boolean, if you just want to know if we've found identName
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 it might be more useful to return the names, in case we want to search multiple names without visiting the tree multiple times.
No description provided.