Skip to content

Commit 9d39037

Browse files
authored
fix: [Rust] Update hashing and datetime tests (#4613)
1 parent 8e0fe91 commit 9d39037

41 files changed

Lines changed: 4102 additions & 808 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/Fable.Transforms/FableTransforms.fs

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,46 @@ module Fable.Transforms.FableTransforms
33
open Fable
44
open Fable.AST.Fable
55

6+
let private walkCapturedIdents (f: string -> bool) expr =
7+
let exprs = FSharp.Collections.ResizeArray [| struct (false, expr) |]
8+
let mutable index = 0
9+
let mutable found = false
10+
11+
while not found && index < exprs.Count do
12+
let struct (isClosure, expr) = exprs[index]
13+
index <- index + 1
14+
15+
match expr with
16+
| IdentExpr ident when isClosure -> found <- f ident.Name
17+
| Lambda(_, body, _) -> exprs.Add(struct (true, body))
18+
| Delegate(_, body, _, _) -> exprs.Add(struct (true, body))
19+
| ObjectExpr(members, _, baseCall) ->
20+
members
21+
|> List.iter (fun memberDecl -> exprs.Add(struct (true, memberDecl.Body)))
22+
23+
baseCall
24+
|> Option.iter (fun baseCall -> exprs.Add(struct (isClosure, baseCall)))
25+
| e ->
26+
getSubExpressions e
27+
|> List.iter (fun subExpr -> exprs.Add(struct (isClosure, subExpr)))
28+
29+
found
30+
31+
let getCapturedNames expr =
32+
let capturedNames = System.Collections.Generic.HashSet<string>()
33+
34+
walkCapturedIdents
35+
(fun identName ->
36+
capturedNames.Add(identName) |> ignore
37+
false
38+
)
39+
expr
40+
|> ignore
41+
42+
capturedNames |> Seq.toList
43+
644
let isIdentCaptured identName expr =
7-
let rec loop isClosure exprs =
8-
match exprs with
9-
| [] -> false
10-
| expr :: restExprs ->
11-
match expr with
12-
| IdentExpr i when i.Name = identName -> isClosure || loop isClosure restExprs
13-
| Lambda(_, body, _) -> loop true [ body ] || loop isClosure restExprs
14-
| Delegate(_, body, _, _) -> loop true [ body ] || loop isClosure restExprs
15-
| ObjectExpr(members, _, baseCall) ->
16-
let memberExprs = members |> List.map (fun m -> m.Body)
17-
loop true memberExprs || loop isClosure (Option.toList baseCall @ restExprs)
18-
| e ->
19-
let sub = getSubExpressions e
20-
loop isClosure (sub @ restExprs)
21-
22-
loop false [ expr ]
45+
walkCapturedIdents (fun candidate -> candidate = identName) expr
2346

2447
let isTailRecursive identName expr =
2548
let mutable isTailRec = true

src/Fable.Transforms/FableTransforms.fsi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ open Fable
44
open Fable.AST.Fable
55

66
val isIdentCaptured: identName: string -> expr: Expr -> bool
7+
val getCapturedNames: expr: Expr -> string list
78
val isTailRecursive: identName: string -> expr: Expr -> bool * bool
89
val countReferencesUntil: limit: int -> identName: string -> body: Expr -> int
910
val replaceValues: replacements: Map<string, Expr> -> expr: Expr -> Expr

0 commit comments

Comments
 (0)