Skip to content

Commit

Permalink
Merge pull request #3565 from ncave/rust
Browse files Browse the repository at this point in the history
[Rust] Fixed recursive lambda captured idents cloning
  • Loading branch information
ncave authored Oct 24, 2023
2 parents d60e3a9 + 7ad8c48 commit 4af4c49
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/Fable.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

#### Rust

* Fixed recursive lambda captured idents cloning (by @ncave)

## 4.4.0 - 2023-10-24

### Changed
Expand Down
13 changes: 10 additions & 3 deletions src/Fable.Transforms/Rust/Fable2Rust.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3269,7 +3269,6 @@ module Util =
makeLibCall com ctx None "Native" ("fix" + argCount) fixCallArgs
else
fnBody
let closureExpr = mkClosureExpr true fnDecl fnBody
let cloneStmts =
// clone captured idents (in move closures)
// skip non-local idents (e.g. module let bindings)
Expand All @@ -3283,8 +3282,16 @@ module Util =
letExpr |> mkSemiStmt)
|> Seq.toList
let closureExpr =
if List.isEmpty cloneStmts then closureExpr
else mkStmtBlockExpr (cloneStmts @ [closureExpr |> mkExprStmt])
if List.isEmpty cloneStmts then
mkClosureExpr true fnDecl fnBody
else
let fnBody =
// additional captured idents cloning for recursive lambdas
if isRecursive && not isTailRec then
mkStmtBlockExpr (cloneStmts @ [fnBody |> mkExprStmt])
else fnBody
let closureExpr = mkClosureExpr true fnDecl fnBody
mkStmtBlockExpr (cloneStmts @ [closureExpr |> mkExprStmt])
let funcWrap = getLibraryImportName com ctx "Native" ("Func" + argCount)
makeCall [funcWrap; "new"] None [closureExpr]

Expand Down

0 comments on commit 4af4c49

Please sign in to comment.