Skip to content

Instantly share code, notes, and snippets.

@Kleidukos
Last active July 14, 2023 14:09
Show Gist options
  • Save Kleidukos/7a515867085e2ae8471e073272d1fc6f to your computer and use it in GitHub Desktop.
Save Kleidukos/7a515867085e2ae8471e073272d1fc6f to your computer and use it in GitHub Desktop.

x and x are not caught by the Reader + continuation-based guard that checks for duplicates, because duplicates are checked when going down the tree.

Since the two x are at the same level, I get those two as values (renamed, to return), but not in the Reader context.

-- https://github.com/Kleidukos/ProtoHaskell/blob/main/src/Compiler/Renamer.hs#L198-L205

renameBinds :: PhLocalBinds ParsedName -> Renamer (PhLocalBinds Name)
renameBinds localBinds = do
  let LocalBinds binds signatures = localBinds
  renamedBinds <- traverse (mapLocM renamePhBind) binds
  -- This is where the renamedBinds are returned, but the traverse does not catch same-level duplicates
  renamedSignatures <- traverse (mapLocM renameSig) signatures
  pure $
    LocalBinds renamedBinds renamedSignatures
module Snippet1 where
bar :: Int
bar =
let x = "lol"
x = "mdr"
in 3
{ modName = Just
( Located
( RealSrcSpan SrcSpanOneLine <snippet1> 2 10 18 ) "Snippet1"
)
, modDecls =
[ Located
( RealSrcSpan SrcSpanOneLine <snippet1> 4 5 15 )
( Signature
( TypeSig
( Name
{ sort = Internal
, occ = OccName
{ nameSpace = VarName
, occNameSrcSpan = RealSrcSpan SrcSpanOneLine <snippet1> 4 5 8
, nameFS = bar
}
, uniq = Unique RenameSection 5
}
)
( Located
( RealSrcSpan SrcSpanOneLine <snippet1> 4 12 15 )
( PhVarTy
( Name
{ sort = Internal
, occ = OccName
{ nameSpace = TcClsName
, occNameSrcSpan = RealSrcSpan SrcSpanOneLine <snippet1> 4 12 15
, nameFS = Int
}
, uniq = Unique RenameSection 6
}
)
)
)
)
)
, Located
( RealSrcSpan SrcSpanMultiLine <snippet1> 5 5 8 12 )
( Binding
( PatBind
( Located
( RealSrcSpan SrcSpanOneLine <snippet1> 5 5 8 )
( PVar
( Name
{ sort = Internal
, occ = OccName
{ nameSpace = VarName
, occNameSrcSpan = RealSrcSpan SrcSpanOneLine <snippet1> 5 5 8
, nameFS = bar
}
, uniq = Unique RenameSection 7
}
)
)
)
( Located
( RealSrcSpan SrcSpanMultiLine <snippet1> 5 9 8 12 )
( RHS
{ expr = Located
( RealSrcSpan SrcSpanMultiLine <snippet1> 6 7 8 12 )
( PhLet
( Located
( RealSrcSpan SrcSpanMultiLine <snippet1> 6 11 7 20 )
( LocalBinds
[ Located
( RealSrcSpan SrcSpanOneLine <snippet1> 6 11 20 )
( PatBind
( Located
( RealSrcSpan SrcSpanOneLine <snippet1> 6 11 12 )
( PVar
( Name
{ sort = Internal
, occ = OccName
{ nameSpace = VarName
, occNameSrcSpan = RealSrcSpan SrcSpanOneLine <snippet1> 6 11 12
, nameFS = x
}
, uniq = Unique RenameSection 8
}
)
)
)
( Located
( RealSrcSpan SrcSpanOneLine <snippet1> 6 13 20 )
( RHS
{ expr = Located
( RealSrcSpan SrcSpanOneLine <snippet1> 6 15 20 )
( PhLit
( LitString "lol" )
)
, localBinds = Located ( UnhelpfulSpan <no location info> )
( LocalBinds [] [] )
}
)
)
)
, Located
( RealSrcSpan SrcSpanOneLine <snippet1> 7 11 20 )
( PatBind
( Located
( RealSrcSpan SrcSpanOneLine <snippet1> 7 11 12 )
( PVar
( Name
{ sort = Internal
, occ = OccName
{ nameSpace = VarName
, occNameSrcSpan = RealSrcSpan SrcSpanOneLine <snippet1> 7 11 12
, nameFS = x
}
, uniq = Unique RenameSection 9
}
)
)
)
( Located
( RealSrcSpan SrcSpanOneLine <snippet1> 7 13 20 )
( RHS
{ expr = Located
( RealSrcSpan SrcSpanOneLine <snippet1> 7 15 20 )
( PhLit
( LitString "mdr" )
)
, localBinds = Located ( UnhelpfulSpan <no location info> )
( LocalBinds [] [] )
}
)
)
)
] []
)
)
( Located
( RealSrcSpan SrcSpanOneLine <snippet1> 8 11 12 )
( PhLit
( LitInt 3 )
)
)
)
, localBinds = Located ( UnhelpfulSpan <no location info> )
( LocalBinds [] [] )
}
)
)
)
)
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment