Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #639 from purescript/no-runtime-type-checks
Remove --runtime-type-checks
  • Loading branch information
paf31 committed Oct 15, 2014
2 parents 54c1d90 + d2a3d4e commit 5a20c09
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 56 deletions.
1 change: 0 additions & 1 deletion docs/source/start.rst
Expand Up @@ -35,7 +35,6 @@ The following options are supported:
--stdin Read input from standard input instead of from files.
--output Write the generated Javascript to the specified file.
--externs Write a list of foreign imports declarations to the specified file in addition to generating Javascript output.
--runtime-type-checks Generate simple runtime type checks for function arguments with simple types.
--no-tco Turn off tail-call elimination.
--no-prelude Do not include the Prelude in the generated Javascript.
--no-magic-do Turn off optimizations which inline calls to ``>>=`` for the ``Eff`` monad.
Expand Down
6 changes: 1 addition & 5 deletions psc-make/Main.hs
Expand Up @@ -104,10 +104,6 @@ noTco :: Term Bool
noTco = value $ flag $ (optInfo [ "no-tco" ])
{ optDoc = "Disable tail call optimizations" }

performRuntimeTypeChecks :: Term Bool
performRuntimeTypeChecks = value $ flag $ (optInfo [ "runtime-type-checks" ])
{ optDoc = "Generate runtime type checks" }

noPrelude :: Term Bool
noPrelude = value $ flag $ (optInfo [ "no-prelude" ])
{ optDoc = "Omit the Prelude" }
Expand All @@ -125,7 +121,7 @@ verboseErrors = value $ flag $ (optInfo [ "v", "verbose-errors" ])
{ optDoc = "Display verbose error messages" }

options :: Term (P.Options P.Make)
options = P.Options <$> noPrelude <*> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> pure Nothing <*> noOpts <*> verboseErrors <*> pure P.MakeOptions
options = P.Options <$> noPrelude <*> noTco <*> noMagicDo <*> pure Nothing <*> noOpts <*> verboseErrors <*> pure P.MakeOptions

noPrefix :: Term Bool
noPrefix = value $ flag $ (optInfo ["p", "no-prefix" ])
Expand Down
6 changes: 1 addition & 5 deletions psc/Main.hs
Expand Up @@ -96,10 +96,6 @@ noTco :: Term Bool
noTco = value $ flag $ (optInfo [ "no-tco" ])
{ optDoc = "Disable tail call optimizations" }

performRuntimeTypeChecks :: Term Bool
performRuntimeTypeChecks = value $ flag $ (optInfo [ "runtime-type-checks" ])
{ optDoc = "Generate runtime type checks" }

noPrelude :: Term Bool
noPrelude = value $ flag $ (optInfo [ "no-prelude" ])
{ optDoc = "Omit the Prelude" }
Expand Down Expand Up @@ -137,7 +133,7 @@ noPrefix = value $ flag $ (optInfo ["no-prefix" ])
{ optDoc = "Do not include comment header"}

options :: Term (P.Options P.Compile)
options = P.Options <$> noPrelude <*> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> runMain <*> noOpts <*> verboseErrors <*> additionalOptions
options = P.Options <$> noPrelude <*> noTco <*> noMagicDo <*> runMain <*> noOpts <*> verboseErrors <*> additionalOptions
where
additionalOptions = P.CompileOptions <$> browserNamespace <*> dceModules <*> codeGenModules

Expand Down
4 changes: 2 additions & 2 deletions psci/Main.hs
Expand Up @@ -114,7 +114,7 @@ findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
--
getHistoryFilename :: IO FilePath
getHistoryFilename = do
home <- getHomeDirectory
home <- getHomeDirectory
let filename = home </> ".purescript" </> "psci_history"
mkdirp filename
return filename
Expand Down Expand Up @@ -202,7 +202,7 @@ completion = completeWord Nothing " \t\n\r" findCompletions
-- | Compilation options.
--
options :: P.Options P.Make
options = P.Options False False False False Nothing False False P.MakeOptions
options = P.Options False False False Nothing False False P.MakeOptions

-- |
-- PSCI monad
Expand Down
37 changes: 0 additions & 37 deletions src/Language/PureScript/CodeGen/JS.hs
Expand Up @@ -33,7 +33,6 @@ import Language.PureScript.Names
import Language.PureScript.Declarations
import Language.PureScript.Options
import Language.PureScript.CodeGen.JS.AST as AST
import Language.PureScript.Types
import Language.PureScript.Optimizer
import Language.PureScript.CodeGen.Common
import Language.PureScript.Environment
Expand Down Expand Up @@ -228,10 +227,6 @@ valueToJs opts m e (Let ds val) = do
valueToJs opts m e (Abs (Left arg) val) = do
ret <- valueToJs opts m e val
return $ JSFunction Nothing [identToJs arg] (JSBlock [JSReturn ret])
valueToJs opts m e (TypedValue _ (Abs (Left arg) val) ty) | optionsPerformRuntimeTypeChecks opts = do
let arg' = identToJs arg
ret <- valueToJs opts m e val
return $ JSFunction Nothing [arg'] (JSBlock $ runtimeTypeChecks arg' ty ++ [JSReturn ret])
valueToJs _ m _ (Var ident) = return $ varToJs m ident
valueToJs opts m e (TypedValue _ val _) = valueToJs opts m e val
valueToJs opts m e (PositionedValue _ val) = valueToJs opts m e val
Expand All @@ -257,38 +252,6 @@ extendObj obj sts = do
extend = map stToAssign sts
return $ JSApp (JSFunction Nothing [] block) []

-- |
-- Generate code in the simplified Javascript intermediate representation for runtime type checks.
--
runtimeTypeChecks :: String -> Type -> [JS]
runtimeTypeChecks arg ty =
let
argTy = getFunctionArgumentType ty
in
maybe [] (argumentCheck (JSVar arg)) argTy
where
getFunctionArgumentType :: Type -> Maybe Type
getFunctionArgumentType (TypeApp (TypeApp t funArg) _) | t == tyFunction = Just funArg
getFunctionArgumentType (ForAll _ ty' _) = getFunctionArgumentType ty'
getFunctionArgumentType _ = Nothing
argumentCheck :: JS -> Type -> [JS]
argumentCheck val t | t == tyNumber = [typeCheck val "number"]
argumentCheck val t | t == tyString = [typeCheck val "string"]
argumentCheck val t | t == tyBoolean = [typeCheck val "boolean"]
argumentCheck val (TypeApp t _) | t == tyArray = [arrayCheck val]
argumentCheck val (TypeApp t row) | t == tyObject =
let
(pairs, _) = rowToList row
in
typeCheck val "object" : concatMap (\(prop, ty') -> argumentCheck (accessorString prop val) ty') pairs
argumentCheck val (TypeApp (TypeApp t _) _) | t == tyFunction = [typeCheck val "function"]
argumentCheck val (ForAll _ ty' _) = argumentCheck val ty'
argumentCheck _ _ = []
typeCheck :: JS -> String -> JS
typeCheck js ty' = JSIfElse (JSBinary NotEqualTo (JSTypeOf js) (JSStringLiteral ty')) (JSBlock [JSThrow (JSStringLiteral $ ty' ++ " expected")]) Nothing
arrayCheck :: JS -> JS
arrayCheck js = JSIfElse (JSUnary Not (JSApp (JSAccessor "isArray" (JSVar "Array")) [js])) (JSBlock [JSThrow (JSStringLiteral "Array expected")]) Nothing

-- |
-- Generate code in the simplified Javascript intermediate representation for a reference to a
-- variable.
Expand Down
8 changes: 2 additions & 6 deletions src/Language/PureScript/Options.hs
Expand Up @@ -52,10 +52,6 @@ data Options mode = Options {
-- Disable tail-call elimination
--
, optionsNoTco :: Bool
-- |
-- Perform type checks at runtime
--
, optionsPerformRuntimeTypeChecks :: Bool
-- |
-- Disable inlining of calls to return and bind for the Eff monad
--
Expand Down Expand Up @@ -84,10 +80,10 @@ data Options mode = Options {
-- Default compiler options
--
defaultCompileOptions :: Options Compile
defaultCompileOptions = Options False False False False Nothing False False (CompileOptions "PS" [] [])
defaultCompileOptions = Options False False False Nothing False False (CompileOptions "PS" [] [])

-- |
-- Default make options
--
defaultMakeOptions :: Options Make
defaultMakeOptions = Options False False False False Nothing False False MakeOptions
defaultMakeOptions = Options False False False Nothing False False MakeOptions

0 comments on commit 5a20c09

Please sign in to comment.