Skip to content

Commit

Permalink
always generate program wide unique names for top-level binders
Browse files Browse the repository at this point in the history
  • Loading branch information
csabahruska committed May 17, 2020
1 parent 1464dca commit d6c20a0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 2 additions & 0 deletions external-stg-util/src/Stg/Reconstruct.hs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ reconLocalBinder BinderMap{..} SBinder{..} = -- HINT: local binders only
, binderUnitId = bmUnitId
, binderModule = bmModule
, binderScope = LocalScope
, binderTopLevel = False
}

reconDataCon :: UnitId -> ModuleName -> TyCon -> SDataCon -> DataCon
Expand Down Expand Up @@ -110,6 +111,7 @@ mkTopBinder u m scope SBinder{..} =
, binderUnitId = u
, binderModule = m
, binderScope = scope
, binderTopLevel = True
}

reconModule :: SModule -> Module
Expand Down
16 changes: 13 additions & 3 deletions external-stg/Stg/Syntax.hs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ data Binder
, binderDetails :: !IdDetails
, binderUnitId :: !UnitId
, binderModule :: !ModuleName
, binderTopLevel :: !Bool
}
deriving (Eq, Ord, Generic, Show)

Expand All @@ -191,11 +192,20 @@ data Scope
| ForeignExported -- ^ visible for foreign libraries
deriving (Eq, Ord, Generic, Show)

tyConUniqueName :: TyCon -> Name
tyConUniqueName TyCon{..} = getUnitId tcUnitId <> "_" <> getModuleName tcModule <> "." <> tcName

dataConUniqueName :: DataCon -> Name
dataConUniqueName DataCon{..} = getUnitId dcUnitId <> "_" <> getModuleName dcModule <> "." <> dcName

binderUniqueName :: Binder -> Name
binderUniqueName Binder{..} = case binderScope of
LocalScope -> binderName <> BS8.pack ('.' : show u)
GlobalScope -> getUnitId binderUnitId <> "_" <> getModuleName binderModule <> "." <> binderName <> BS8.pack ('.' : show u)
_ -> getUnitId binderUnitId <> "_" <> getModuleName binderModule <> "." <> binderName
LocalScope -> if binderTopLevel
then getUnitId binderUnitId <> "_" <> getModuleName binderModule <> "." <> binderName <> BS8.pack ('.' : show u)
else binderName <> BS8.pack ('.' : show u)
GlobalScope -> getUnitId binderUnitId <> "_" <> getModuleName binderModule <> "." <> binderName <> BS8.pack ('.' : show u)
HaskellExported -> getUnitId binderUnitId <> "_" <> getModuleName binderModule <> "." <> binderName
ForeignExported -> getUnitId binderUnitId <> "_" <> getModuleName binderModule <> "." <> binderName
where
BinderId u = binderId

Expand Down

0 comments on commit d6c20a0

Please sign in to comment.