@@ -402,7 +402,7 @@ let rec private transformDecisionTargets (com: IFableCompiler) (ctx: Context) ac
402
402
| ( idents, expr):: tail ->
403
403
let ctx , idents =
404
404
( idents, ( ctx, [])) ||> List.foldBack ( fun ident ( ctx , idents ) ->
405
- let ctx , ident = putArgInScope com ctx ident
405
+ let ctx , ident = putIdentInScope com ctx ident None
406
406
ctx, ident:: idents)
407
407
let! expr = transformExpr com ctx expr
408
408
return ! transformDecisionTargets com ctx (( idents, expr):: acc) tail
@@ -534,7 +534,7 @@ let private transformExpr (com: IFableCompiler) (ctx: Context) fsExpr =
534
534
| FSharpExprPatterns.FastIntegerForLoop( start, limit, body, isUp) ->
535
535
let r = makeRangeFrom fsExpr
536
536
match body with
537
- | FSharpExprPatterns.Lambda ( PutArgInScope com ctx ( newContext, ident), body) ->
537
+ | FSharpExprPatterns.Lambda ( PutIdentInScope com ctx ( newContext, ident), body) ->
538
538
let! start = transformExpr com ctx start
539
539
let! limit = transformExpr com ctx limit
540
540
let! body = transformExpr com newContext body
@@ -595,7 +595,7 @@ let private transformExpr (com: IFableCompiler) (ctx: Context) fsExpr =
595
595
let! value = transformExpr com ctx value
596
596
let typ = makeType ctx.GenericArgs createEvent.Type
597
597
let value = makeCallFrom com ctx ( makeRangeFrom createEvent) typ Seq.empty ( Some value) [] event
598
- let ctx , ident = putBindingInScope com ctx var value
598
+ let ctx , ident = putIdentInScope com ctx var ( Some value)
599
599
let! body = transformExpr com ctx body
600
600
return Fable.Let( ident, value, body)
601
601
@@ -605,7 +605,7 @@ let private transformExpr (com: IFableCompiler) (ctx: Context) fsExpr =
605
605
return ! transformExpr com ctx body
606
606
else
607
607
let! value = transformExpr com ctx value
608
- let ctx , ident = putBindingInScope com ctx var value
608
+ let ctx , ident = putIdentInScope com ctx var ( Some value)
609
609
let! body = transformExpr com ctx body
610
610
match value with
611
611
| Fable.Import( info, t, r) when not info.IsCompilerGenerated ->
@@ -621,7 +621,7 @@ let private transformExpr (com: IFableCompiler) (ctx: Context) fsExpr =
621
621
// First get a context containing all idents and use it compile the values
622
622
let ctx , idents =
623
623
( recBindings, ( ctx, []))
624
- ||> List.foldBack ( fun ( PutArgInScope com ctx ( newContext , ident ), _ ) ( ctx , idents ) ->
624
+ ||> List.foldBack ( fun ( PutIdentInScope com ctx ( newContext , ident ), _ ) ( ctx , idents ) ->
625
625
( newContext, ident:: idents))
626
626
let _ , bindingExprs = List.unzip recBindings
627
627
let! exprs = transformExprList com ctx bindingExprs
@@ -1508,6 +1508,22 @@ type FableCompiler(com: Compiler) =
1508
1508
{ ident with Name = sanitizedName }
1509
1509
else ident
1510
1510
1511
+ let rec foldArgs acc = function
1512
+ | argIdent:: restArgIdents, argExpr:: restArgExprs ->
1513
+ foldArgs (( argIdent, argExpr):: acc) ( restArgIdents, restArgExprs)
1514
+ | ( argIdent: Fable.Ident):: restArgIdents, [] ->
1515
+ foldArgs (( argIdent, Fable.Value( Fable.NewOption( None, argIdent.Type), None)):: acc) ( restArgIdents, [])
1516
+ | [], _ -> List.rev acc
1517
+
1518
+ let ctx , bindings =
1519
+ (( ctx, []), foldArgs [] ( inExpr.Args, args)) ||> List.fold ( fun ( ctx , bindings ) ( argId , arg ) ->
1520
+ let argId = resolveIdent ctx argId
1521
+ // Change type and mark argId as compiler-generated so Fable also
1522
+ // tries to inline it in DEBUG mode (some patterns depend on this)
1523
+ let argId = { argId with Type = arg.Type; IsCompilerGenerated = true }
1524
+ let ctx = { ctx with Scope = ( None, argId, Some arg):: ctx.Scope }
1525
+ ctx, ( argId, arg):: bindings)
1526
+
1511
1527
let rec resolveGenArg ( ctx : Context ) = function
1512
1528
| Fable.GenericParam name as v ->
1513
1529
match Map.tryFind name ctx.GenericArgs with
@@ -1517,19 +1533,32 @@ type FableCompiler(com: Compiler) =
1517
1533
1518
1534
let rec resolveExpr ctx expr =
1519
1535
expr |> visitFromOutsideIn ( function
1520
- // Resolve idents
1536
+ // Resolve bindings
1537
+ | Fable.Let( i, v, b) ->
1538
+ let i = resolveIdent ctx i
1539
+ let v = resolveExpr ctx v
1540
+ let ctx = { ctx with Scope = ( None, i, Some v):: ctx.Scope }
1541
+ Fable.Let( i, v, resolveExpr ctx b) |> Some
1542
+
1543
+ | Fable.LetRec( bindings, b) ->
1544
+ let ctx , bindings =
1545
+ (( ctx, bindings), bindings) ||> List.fold( fun ( ctx , bindings ) ( i , e ) ->
1546
+ let i = resolveIdent ctx i
1547
+ let e = resolveExpr ctx e
1548
+ { ctx with Scope = ( None, i, Some e):: ctx.Scope }, ( i, e):: bindings)
1549
+ Fable.LetRec( List.rev bindings, resolveExpr ctx b) |> Some
1550
+
1551
+ // Resolve idents in other expressions
1521
1552
| Fable.IdentExpr i -> Fable.IdentExpr( resolveIdent ctx i) |> Some
1522
1553
| Fable.Lambda( arg, b, n) -> Fable.Lambda( resolveIdent ctx arg, resolveExpr ctx b, n) |> Some
1523
1554
| Fable.Delegate( args, b, n) -> Fable.Delegate( List.map ( resolveIdent ctx) args, resolveExpr ctx b, n) |> Some
1524
1555
| Fable.DecisionTree( e, targets) -> Fable.DecisionTree( resolveExpr ctx e, targets |> List.map( fun ( idents , e ) -> List.map ( resolveIdent ctx) idents, resolveExpr ctx e)) |> Some
1525
- | Fable.Let( i, v, b) -> Fable.Let( resolveIdent ctx i, resolveExpr ctx v, resolveExpr ctx b) |> Some
1526
- | Fable.LetRec( bindings, b) -> Fable.LetRec( bindings |> List.map( fun ( i , e ) -> resolveIdent ctx i, resolveExpr ctx e), resolveExpr ctx b) |> Some
1527
1556
| Fable.ForLoop( i, s, l, b, u, r) -> Fable.ForLoop( resolveIdent ctx i, resolveExpr ctx s, resolveExpr ctx l, resolveExpr ctx b, u, r) |> Some
1528
1557
| Fable.TryCatch( b, c, d, r) -> Fable.TryCatch( resolveExpr ctx b, ( c |> Option.map ( fun ( i , e ) -> resolveIdent ctx i, resolveExpr ctx e)), ( d |> Option.map ( resolveExpr ctx)), r) |> Some
1529
1558
| Fable.ObjectExpr( members, t, baseCall) ->
1530
1559
let members = members |> List.map ( fun m ->
1531
1560
{ m with Args = List.map ( resolveIdent ctx) m.Args
1532
- Body = resolveExpr ctx m.Body })
1561
+ Body = resolveExpr ctx m.Body })
1533
1562
Fable.ObjectExpr( members, resolveGenArg ctx t, baseCall |> Option.map ( resolveExpr ctx)) |> Some
1534
1563
1535
1564
// Resolve imports. TODO: add test
@@ -1595,21 +1624,6 @@ type FableCompiler(com: Compiler) =
1595
1624
1596
1625
| _ -> None)
1597
1626
1598
- let rec foldArgs acc = function
1599
- | argIdent:: restArgIdents, argExpr:: restArgExprs ->
1600
- foldArgs (( argIdent, argExpr):: acc) ( restArgIdents, restArgExprs)
1601
- | ( argIdent: Fable.Ident):: restArgIdents, [] ->
1602
- foldArgs (( argIdent, Fable.Value( Fable.NewOption( None, argIdent.Type), None)):: acc) ( restArgIdents, [])
1603
- | [], _ -> List.rev acc
1604
-
1605
- let bindings =
1606
- ([], foldArgs [] ( inExpr.Args, args)) ||> List.fold ( fun bindings ( argId , arg ) ->
1607
- let argId = resolveIdent ctx argId
1608
- // Change type and mark argId as compiler-generated so Fable also
1609
- // tries to inline it in DEBUG mode (some patterns depend on this)
1610
- let argId = { argId with Type = arg.Type; IsCompilerGenerated = true }
1611
- ( argId, arg):: bindings)
1612
-
1613
1627
let ctx = { ctx with ScopeInlineArgs = ctx.ScopeInlineArgs @ bindings }
1614
1628
bindings, resolveExpr ctx inExpr.Body
1615
1629
@@ -1661,7 +1675,7 @@ let getInlineExprs fileName (declarations: FSharpImplementationFileDeclaration l
1661
1675
1662
1676
let ctx , idents =
1663
1677
(( ctx, []), List.concat argIds) ||> List.fold ( fun ( ctx , idents ) argId ->
1664
- let ctx , ident = putArgInScope com ctx argId
1678
+ let ctx , ident = putIdentInScope com ctx argId None
1665
1679
ctx, ident:: idents)
1666
1680
1667
1681
{ Args = List.rev idents
0 commit comments