Skip to content
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

Merged
merged 10 commits into from
Apr 18, 2024
Merged

Conversation

eldritchconundrum
Copy link
Collaborator

No description provided.

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 ->
Copy link
Owner

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
Copy link
Owner

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

Copy link
Collaborator Author

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.

@eldritchconundrum eldritchconundrum merged commit fccde20 into master Apr 18, 2024
2 checks passed
@eldritchconundrum eldritchconundrum deleted the peephole-optim branch April 18, 2024 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants