Skip to content

Commit

Permalink
fix bug in renaming let statements
Browse files Browse the repository at this point in the history
  • Loading branch information
bristermitten committed Oct 3, 2023
1 parent 46d0716 commit 4825d10
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 26 deletions.
Binary file modified build/Main.class
Binary file not shown.
3 changes: 1 addition & 2 deletions build/Main.core.elr
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ Main.x : Int
;
Main.main : IO ()
= let y_2 : Int
= Prelude.+ Main.x 1 in let z_3 : Int
= Prelude.+ y_2 1 in Prelude.println (Prelude.toString @Int z_3) }
= Prelude.+ Main.x 1 in Prelude.println (Prelude.toString @Int y_2) }
16 changes: 6 additions & 10 deletions build/Main.typed.elr
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@ let Main.main =
let y_2 = ((Prelude.(+) : Integer ->
Integer ->
Integer Main.x : Integer) : Integer ->
Integer 1 : Integer) : Integer in let z_3 = ((Prelude.(+) : Integer ->
Integer ->
Integer y_2 : Integer) : Integer ->
Integer 1 : Integer) : Integer in (Prelude.println : Text ->
IO Unit
((Prelude.toString : forall (a_4 : Type) .
a_4 ->
Text @Integer) : Text z_3 : Integer) : Text) : IO Unit
: IO Unit
: IO Unit
Integer 1 : Integer) : Integer in (Prelude.println : Text ->
IO Unit
((Prelude.toString : forall (a_3 : Type) .
a_3 ->
Text @Integer) : Text y_2 : Integer) : Text) : IO Unit
: IO Unit

4 changes: 2 additions & 2 deletions build/Prelude.core.elr
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module Prelude
{ Prelude.println : String -> IO ()
= Elara.Prim.elaraPrimitive @(String -> IO ()) "println"
;
Prelude.toString : forall (a_4 : Type). a_4 -> String
= Elara.Prim.elaraPrimitive @(a_4 -> String) "toString"
Prelude.toString : forall (a_3 : Type). a_3 -> String
= Elara.Prim.elaraPrimitive @(a_3 -> String) "toString"
;
Prelude.+ : Int -> Int -> Int
= Elara.Prim.elaraPrimitive @(Int -> Int -> Int) "+" }
12 changes: 6 additions & 6 deletions build/Prelude.typed.elr
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ let Prelude.println =
IO Unit


def Prelude.toString : forall (a_4 : Type) . a_4 -> Text
def Prelude.toString : forall (a_3 : Type) . a_3 -> Text
let Prelude.toString =
((Elara.Prim.elaraPrimitive : forall (a_0 : Type) . Text -> a_0 @a_4 ->
Text) : forall (a_4 : Type) .
a_4 ->
Text "toString" : Text) : forall (a_4 : Type) .
a_4 ->
((Elara.Prim.elaraPrimitive : forall (a_0 : Type) . Text -> a_0 @a_3 ->
Text) : forall (a_3 : Type) .
a_3 ->
Text "toString" : Text) : forall (a_3 : Type) .
a_3 ->
Text

def Prelude.(+) : Integer -> Integer -> Integer
Expand Down
6 changes: 3 additions & 3 deletions source.elr
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ let add2 = \x -> x + 2
let x = add2 1

let main =
let y = x + 1 in
let z = y + 1 in
println (toString z)
let y = x + 1
let z = y + 1
println (toString z)
8 changes: 5 additions & 3 deletions src/Elara/Rename.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import Polysemy.Reader hiding (Local)
import Polysemy.State
import Polysemy.State.Extra
import Polysemy.Utils (withModified)
import Print (debugPretty)
import TODO (todo)

data RenameError
Expand Down Expand Up @@ -515,11 +516,12 @@ desugarBlock (e@(Expr' (Let{})) :| []) = do
throw (BlockEndsWithLet e (fmap (view (_Unwrapped . unlocated . the @"body")) decl))
desugarBlock (e :| []) = renameExpr e
desugarBlock (Expr (Located l (Let n p val), a) :| xs) = do
xs' <- desugarBlock (fromList xs)
val' <- renameExpr val
a' <- (traverse (traverseOf (_Unwrapped . unlocated) (renameType False))) a
n' <- uniquify n
modify (the @"varNames" %~ Map.insert (n ^. unlocated) (Local n'))
val' <- renameExpr val

xs' <- withModified (the @"varNames" %~ Map.insert (n ^. unlocated) (Local n')) $ do
desugarBlock (fromList xs)
pure $ Expr (Located l (LetIn n' p val' xs'), a')
desugarBlock xs = do
let loc = spanningRegion' (xs <&> (^. _Unwrapped . _1 . sourceRegion))
Expand Down

0 comments on commit 4825d10

Please sign in to comment.