Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Solcore/Backend/EmitHull.hs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ findConstructor :: [MastContractDecl] -> Maybe MastFunDef
findConstructor = go
where
go [] = Nothing
go (MastCFunDecl d : _) | mastFunName d == "start" = Just d
go (MastCFunDecl d : _) | mastFunName d == deployerName = Just d
go (_ : ds) = go ds

-----------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions src/Solcore/Backend/Mast.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Solcore.Backend.Mast where
-}

import Common.Pretty
import Data.String
import Language.Yul (YulBlock)
import Solcore.Frontend.Pretty.SolcorePretty ()
import Solcore.Frontend.Syntax.Contract (DataTy (..), Import (..))
Expand All @@ -16,6 +17,9 @@ import Solcore.Frontend.Syntax.Stmt (Literal (..))
import Solcore.Frontend.Syntax.Ty (Ty (..), Tyvar (..))
import Solcore.Primitives.Primitives (word)

deployerName :: Name
deployerName = fromString "_start"

-----------------------------------------------------------------------
-- Types: no TyVar, no Meta — only type constructors
-----------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions src/Solcore/Backend/MastEval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ expIsPure pureFuns (MastCond e1 e2 e3) =
-----------------------------------------------------------------------

-- | Remove unused functions from a compilation unit.
-- 'start' and 'main' are always considered roots (entry points).
-- deployer and 'main' are always considered roots (entry points).
eliminateDeadCode :: MastCompUnit -> MastCompUnit
eliminateDeadCode cu = cu {mastTopDecls = map elimTopDecl (mastTopDecls cu)}
where
Expand All @@ -504,12 +504,12 @@ eliminateDeadCode cu = cu {mastTopDecls = map elimTopDecl (mastTopDecls cu)}
isUsedDecl (MastCMutualDecl ds) = any isUsedDecl ds
isUsedDecl (MastCDataDecl _) = True

-- | Find all functions reachable from root functions ('start', 'main')
-- | Find all functions reachable from root functions
findUsedFunctions :: MastContract -> Set.Set Name
findUsedFunctions c = go initialRoots initialRoots
where
-- Root functions that are always considered used
rootNames = Set.fromList [Name "start", Name "main"]
rootNames = Set.fromList [deployerName, Name "main"]

-- Start with roots that actually exist in the contract
initialRoots = Set.intersection rootNames allFunNames
Expand Down
5 changes: 2 additions & 3 deletions src/Solcore/Backend/Specialise.hs
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,7 @@ specialiseTopDecl (TContr (Contract name args decls)) = withLocalState do
getSpecialisedDecls
-- Deployer code
modify (\st -> st {specTable = emptyTable})
-- let deployerName = Name (pretty name <> "$Deployer")
mStart <- specEntryOpt "start"
mStart <- specEntryOpt deployerName
deployDecls <- case mStart of
Just {} -> do
depDecls <- getSpecialisedDecls
Expand Down Expand Up @@ -258,7 +257,7 @@ specEntry name = do
pure mres

-- | Like 'specEntry' but silently returns Nothing when the name is absent.
-- Use for optional entry points (e.g. "start") that may not exist when
-- Use for optional entry points (e.g. deployer) that may not exist when
-- contract dispatch generation is disabled.
specEntryOpt :: Name -> SM (Maybe Name)
specEntryOpt name = withLocalState do
Expand Down
3 changes: 2 additions & 1 deletion src/Solcore/Desugarer/ContractDispatch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import Data.Set (Set)
import Data.Set qualified as Set
import Language.Yul
import Language.Yul.QuasiQuote
import Solcore.Backend.Mast
import Solcore.Frontend.Syntax
import Solcore.Primitives.Primitives (string, tupleExpFromList, tupleTyFromList, unit, word)

Expand Down Expand Up @@ -156,7 +157,7 @@ transformConstructor contractName cons
Signature
{ sigVars = mempty,
sigContext = mempty,
sigName = "start",
sigName = deployerName,
sigParams = mempty,
sigReturn = Just unit
}
Expand Down
2 changes: 1 addition & 1 deletion yule/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ addRetCode c = c <> retCode
deployCode :: String -> Bool -> YulCode
deployCode _name withStart = YulCode $ go withStart
where
go True = [[yulStmt| usr$start() |]]
go True = [[yulStmt| usr$_start() |]]
go False = []

createDeployment :: YulObject -> YulObject
Expand Down
Loading