git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge pull request #639 from purescript/no-runtime-type-checks

Remove --runtime-type-checks

commit5a20c0992061e09d79e7fe2ea083942f020b4145 authorPhil Freeman <paf31@cantab.net> dateWed 15 Oct 2014, 18:08 (12 years ago) parent54c1d90d2a3d4e
6 files changed+6−56
docs/source/start.rst−1 psc-make/Main.hs+1−5 psc/Main.hs+1−5 psci/Main.hs+2−2 src/Language/PureScript/CodeGen/JS.hs−37 src/Language/PureScript/Options.hs+2−6
docs/source/start.rst−1
@@ -35,7 +35,6 @@ The following options are supported:
3535--stdin Read input from standard input instead of from files.
3636--output Write the generated Javascript to the specified file.
3737--externs Write a list of foreign imports declarations to the specified file in addition to generating Javascript output.
38−--runtime-type-checks Generate simple runtime type checks for function arguments with simple types.
3938--no-tco Turn off tail-call elimination.
4039--no-prelude Do not include the Prelude in the generated Javascript.
4140--no-magic-do Turn off optimizations which inline calls to ``>>=`` for the ``Eff`` monad.
psc-make/Main.hs+1−5
@@ -104,10 +104,6 @@ noTco :: Term Bool
104104noTco = value $ flag $ (optInfo [ "no-tco" ])
105105 { optDoc = "Disable tail call optimizations" }
106106
107−performRuntimeTypeChecks :: Term Bool
108−performRuntimeTypeChecks = value $ flag $ (optInfo [ "runtime-type-checks" ])
109− { optDoc = "Generate runtime type checks" }
110−
111107noPrelude :: Term Bool
112108noPrelude = value $ flag $ (optInfo [ "no-prelude" ])
113109 { optDoc = "Omit the Prelude" }
@@ -125,7 +121,7 @@ verboseErrors = value $ flag $ (optInfo [ "v", "verbose-errors" ])
125121 { optDoc = "Display verbose error messages" }
126122
127123options :: Term (P.Options P.Make)
128−options = P.Options <$> noPrelude <*> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> pure Nothing <*> noOpts <*> verboseErrors <*> pure P.MakeOptions
124+options = P.Options <$> noPrelude <*> noTco <*> noMagicDo <*> pure Nothing <*> noOpts <*> verboseErrors <*> pure P.MakeOptions
129125
130126noPrefix :: Term Bool
131127noPrefix = value $ flag $ (optInfo ["p", "no-prefix" ])
psc/Main.hs+1−5
@@ -96,10 +96,6 @@ noTco :: Term Bool
9696noTco = value $ flag $ (optInfo [ "no-tco" ])
9797 { optDoc = "Disable tail call optimizations" }
9898
99−performRuntimeTypeChecks :: Term Bool
100−performRuntimeTypeChecks = value $ flag $ (optInfo [ "runtime-type-checks" ])
101− { optDoc = "Generate runtime type checks" }
102−
10399noPrelude :: Term Bool
104100noPrelude = value $ flag $ (optInfo [ "no-prelude" ])
105101 { optDoc = "Omit the Prelude" }
@@ -137,7 +133,7 @@ noPrefix = value $ flag $ (optInfo ["no-prefix" ])
137133 { optDoc = "Do not include comment header"}
138134
139135options :: Term (P.Options P.Compile)
140−options = P.Options <$> noPrelude <*> noTco <*> performRuntimeTypeChecks <*> noMagicDo <*> runMain <*> noOpts <*> verboseErrors <*> additionalOptions
136+options = P.Options <$> noPrelude <*> noTco <*> noMagicDo <*> runMain <*> noOpts <*> verboseErrors <*> additionalOptions
141137 where
142138 additionalOptions = P.CompileOptions <$> browserNamespace <*> dceModules <*> codeGenModules
143139
psci/Main.hs+2−2
@@ -114,7 +114,7 @@ findNodeProcess = runMaybeT . msum $ map (MaybeT . findExecutable) names
114114--
115115getHistoryFilename :: IO FilePath
116116getHistoryFilename = do
117− home <- getHomeDirectory
117+ home <- getHomeDirectory
118118 let filename = home </> ".purescript" </> "psci_history"
119119 mkdirp filename
120120 return filename
@@ -202,7 +202,7 @@ completion = completeWord Nothing " \t\n\r" findCompletions
202202-- | Compilation options.
203203--
204204options :: P.Options P.Make
205−options = P.Options False False False False Nothing False False P.MakeOptions
205+options = P.Options False False False Nothing False False P.MakeOptions
206206
207207-- |
208208-- PSCI monad
src/Language/PureScript/CodeGen/JS.hs−37
@@ -33,7 +33,6 @@ import Language.PureScript.Names
3333import Language.PureScript.Declarations
3434import Language.PureScript.Options
3535import Language.PureScript.CodeGen.JS.AST as AST
36−import Language.PureScript.Types
3736import Language.PureScript.Optimizer
3837import Language.PureScript.CodeGen.Common
3938import Language.PureScript.Environment
@@ -228,10 +227,6 @@ valueToJs opts m e (Let ds val) = do
228227valueToJs opts m e (Abs (Left arg) val) = do
229228 ret <- valueToJs opts m e val
230229 return $ JSFunction Nothing [identToJs arg] (JSBlock [JSReturn ret])
231−valueToJs opts m e (TypedValue _ (Abs (Left arg) val) ty) | optionsPerformRuntimeTypeChecks opts = do
232− let arg' = identToJs arg
233− ret <- valueToJs opts m e val
234− return $ JSFunction Nothing [arg'] (JSBlock $ runtimeTypeChecks arg' ty ++ [JSReturn ret])
235230valueToJs _ m _ (Var ident) = return $ varToJs m ident
236231valueToJs opts m e (TypedValue _ val _) = valueToJs opts m e val
237232valueToJs opts m e (PositionedValue _ val) = valueToJs opts m e val
@@ -257,38 +252,6 @@ extendObj obj sts = do
257252 extend = map stToAssign sts
258253 return $ JSApp (JSFunction Nothing [] block) []
259254
260−-- |
261−-- Generate code in the simplified Javascript intermediate representation for runtime type checks.
262−--
263−runtimeTypeChecks :: String -> Type -> [JS]
264−runtimeTypeChecks arg ty =
265− let
266− argTy = getFunctionArgumentType ty
267− in
268− maybe [] (argumentCheck (JSVar arg)) argTy
269− where
270− getFunctionArgumentType :: Type -> Maybe Type
271− getFunctionArgumentType (TypeApp (TypeApp t funArg) _) | t == tyFunction = Just funArg
272− getFunctionArgumentType (ForAll _ ty' _) = getFunctionArgumentType ty'
273− getFunctionArgumentType _ = Nothing
274− argumentCheck :: JS -> Type -> [JS]
275− argumentCheck val t | t == tyNumber = [typeCheck val "number"]
276− argumentCheck val t | t == tyString = [typeCheck val "string"]
277− argumentCheck val t | t == tyBoolean = [typeCheck val "boolean"]
278− argumentCheck val (TypeApp t _) | t == tyArray = [arrayCheck val]
279− argumentCheck val (TypeApp t row) | t == tyObject =
280− let
281− (pairs, _) = rowToList row
282− in
283− typeCheck val "object" : concatMap (\(prop, ty') -> argumentCheck (accessorString prop val) ty') pairs
284− argumentCheck val (TypeApp (TypeApp t _) _) | t == tyFunction = [typeCheck val "function"]
285− argumentCheck val (ForAll _ ty' _) = argumentCheck val ty'
286− argumentCheck _ _ = []
287− typeCheck :: JS -> String -> JS
288− typeCheck js ty' = JSIfElse (JSBinary NotEqualTo (JSTypeOf js) (JSStringLiteral ty')) (JSBlock [JSThrow (JSStringLiteral $ ty' ++ " expected")]) Nothing
289− arrayCheck :: JS -> JS
290− arrayCheck js = JSIfElse (JSUnary Not (JSApp (JSAccessor "isArray" (JSVar "Array")) [js])) (JSBlock [JSThrow (JSStringLiteral "Array expected")]) Nothing
291−
292255-- |
293256-- Generate code in the simplified Javascript intermediate representation for a reference to a
294257-- variable.
src/Language/PureScript/Options.hs+2−6
@@ -52,10 +52,6 @@ data Options mode = Options {
5252 -- Disable tail-call elimination
5353 --
5454 , optionsNoTco :: Bool
55− -- |
56− -- Perform type checks at runtime
57− --
58− , optionsPerformRuntimeTypeChecks :: Bool
5955 -- |
6056 -- Disable inlining of calls to return and bind for the Eff monad
6157 --
@@ -84,10 +80,10 @@ data Options mode = Options {
8480-- Default compiler options
8581--
8682defaultCompileOptions :: Options Compile
87−defaultCompileOptions = Options False False False False Nothing False False (CompileOptions "PS" [] [])
83+defaultCompileOptions = Options False False False Nothing False False (CompileOptions "PS" [] [])
8884
8985-- |
9086-- Default make options
9187--
9288defaultMakeOptions :: Options Make
93−defaultMakeOptions = Options False False False False Nothing False False MakeOptions
89+defaultMakeOptions = Options False False False Nothing False False MakeOptions