Skip to content

Commit f34cf92

Browse files
committed
Remove runtime type checks purescript#93
1 parent 5699960 commit f34cf92

4 files changed

Lines changed: 3 additions & 45 deletions

File tree

psc/Main.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,6 @@ tco :: Term Bool
8383
tco = value $ flag $ (optInfo [ "tco" ])
8484
{ optDoc = "Perform tail call optimizations" }
8585

86-
performRuntimeTypeChecks :: Term Bool
87-
performRuntimeTypeChecks = value $ flag $ (optInfo [ "runtime-type-checks" ])
88-
{ optDoc = "Generate runtime type checks" }
89-
9086
noPrelude :: Term Bool
9187
noPrelude = value $ flag $ (optInfo [ "no-prelude" ])
9288
{ optDoc = "Omit the Prelude" }
@@ -112,7 +108,7 @@ dceModules = value $ optAll [] $ (optInfo [ "m", "module" ])
112108
{ optDoc = "Enables dead code elimination, all code which is not a transitive dependency of a specified module will be removed. This argument can be used multiple times." }
113109

114110
options :: Term P.Options
115-
options = P.Options <$> tco <*> performRuntimeTypeChecks <*> magicDo <*> runMain <*> noOpts <*> browserNamespace <*> dceModules
111+
options = P.Options <$> tco <*> magicDo <*> runMain <*> noOpts <*> browserNamespace <*> dceModules
116112

117113
stdInOrInputFiles :: FilePath -> Term (Maybe [FilePath])
118114
stdInOrInputFiles prelude = combine <$> useStdIn <*> (not <$> noPrelude) <*> inputFiles

psci/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ completion = completeWord Nothing " \t\n\r" findCompletions
195195
-- | Compilation options.
196196
--
197197
options :: P.Options
198-
options = P.Options True False True (Just "Main") True "PS" []
198+
options = P.Options True True (Just "Main") True "PS" []
199199

200200
-- |
201201
-- Makes a volatile module to execute the current expression.

src/Language/PureScript/CodeGen/JS.hs

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,6 @@ valueToJs opts m e (IfThenElse cond th el) = JSConditional (valueToJs opts m e c
135135
valueToJs opts m e (Accessor prop val) = JSAccessor prop (valueToJs opts m e val)
136136
valueToJs opts m e (App val arg) = JSApp (valueToJs opts m e val) [valueToJs opts m e arg]
137137
valueToJs opts m e (Abs (Left arg) val) = JSFunction Nothing [identToJs arg] (JSBlock [JSReturn (valueToJs opts m (bindName m arg e) val)])
138-
valueToJs opts m e (TypedValue _ (Abs (Left arg) val) ty) | optionsPerformRuntimeTypeChecks opts = let arg' = identToJs arg in JSFunction Nothing [arg'] (JSBlock $ runtimeTypeChecks arg' ty ++ [JSReturn (valueToJs opts m e val)])
139138
valueToJs _ m _ (Var ident) = varToJs m ident
140139
valueToJs opts m e (TypedValue _ val _) = valueToJs opts m e val
141140
valueToJs _ _ _ (TypeClassDictionary _ _) = error "Type class dictionary was not replaced"
@@ -173,39 +172,6 @@ bindNames m idents env = env { names = M.fromList [ ((m, ident), (noType, LocalV
173172
where
174173
noType = error "Temporary lambda variable type was read"
175174

176-
177-
-- |
178-
-- Generate code in the simplified Javascript intermediate representation for runtime type checks.
179-
--
180-
runtimeTypeChecks :: String -> Type -> [JS]
181-
runtimeTypeChecks arg ty =
182-
let
183-
argTy = getFunctionArgumentType ty
184-
in
185-
maybe [] (argumentCheck (JSVar arg)) argTy
186-
where
187-
getFunctionArgumentType :: Type -> Maybe Type
188-
getFunctionArgumentType (TypeApp (TypeApp t funArg) _) | t == tyFunction = Just funArg
189-
getFunctionArgumentType (ForAll _ ty' _) = getFunctionArgumentType ty'
190-
getFunctionArgumentType _ = Nothing
191-
argumentCheck :: JS -> Type -> [JS]
192-
argumentCheck val t | t == tyNumber = [typeCheck val "number"]
193-
argumentCheck val t | t == tyString = [typeCheck val "string"]
194-
argumentCheck val t | t == tyBoolean = [typeCheck val "boolean"]
195-
argumentCheck val (TypeApp t _) | t == tyArray = [arrayCheck val]
196-
argumentCheck val (Object row) =
197-
let
198-
(pairs, _) = rowToList row
199-
in
200-
typeCheck val "object" : concatMap (\(prop, ty') -> argumentCheck (JSAccessor prop val) ty') pairs
201-
argumentCheck val (TypeApp (TypeApp t _) _) | t == tyFunction = [typeCheck val "function"]
202-
argumentCheck val (ForAll _ ty' _) = argumentCheck val ty'
203-
argumentCheck _ _ = []
204-
typeCheck :: JS -> String -> JS
205-
typeCheck js ty' = JSIfElse (JSBinary NotEqualTo (JSTypeOf js) (JSStringLiteral ty')) (JSBlock [JSThrow (JSStringLiteral $ ty' ++ " expected")]) Nothing
206-
arrayCheck :: JS -> JS
207-
arrayCheck js = JSIfElse (JSUnary Not (JSApp (JSAccessor "isArray" (JSVar "Array")) [js])) (JSBlock [JSThrow (JSStringLiteral "Array expected")]) Nothing
208-
209175
-- |
210176
-- Generate code in the simplified Javascript intermediate representation for a reference to a
211177
-- variable.

src/Language/PureScript/Options.hs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ data Options = Options {
2323
-- Perform tail-call elimination
2424
--
2525
optionsTco :: Bool
26-
-- |
27-
-- Perform type checks at runtime
28-
--
29-
, optionsPerformRuntimeTypeChecks :: Bool
3026
-- |
3127
-- Inline calls to ret and bind for the Eff monad
3228
--
@@ -55,4 +51,4 @@ data Options = Options {
5551
-- Default compiler options
5652
--
5753
defaultOptions :: Options
58-
defaultOptions = Options False False False Nothing False "PS" []
54+
defaultOptions = Options False False Nothing False "PS" []

0 commit comments

Comments
 (0)