From 06a0a9760a4e5bcab261c05d64cdf0dda9b40925 Mon Sep 17 00:00:00 2001 From: Gabe Johnson Date: Mon, 26 Feb 2018 15:31:38 -0600 Subject: [PATCH 1/2] Prevent codegen when `--dump-corefn` is supplied --- CONTRIBUTORS.md | 1 + src/Language/PureScript/Make.hs | 41 ++++++++++++++++++--------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index b87b25adf3..238e997a18 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -120,6 +120,7 @@ If you would prefer to use different terms, please use the section below instead | [@bjornmelgaaard](https://github.com/BjornMelgaard) | Sergey Homa | [MIT license](http://opensource.org/licenses/MIT) | | [@thimoteus](https://github.com/Thimoteus) | thimoteus | [MIT license](http://opensource.org/licenses/MIT) | | [@sloosch](https://github.com/sloosch) | Simon Looschen | [MIT license](http://opensource.org/licenses/MIT) | +| [@gabejohnson](https://github.com/gabejohnson) | Gabe Johnson | [MIT license](http://opensource.org/licenses/MIT) | ### Contributors using Modified Terms diff --git a/src/Language/PureScript/Make.hs b/src/Language/PureScript/Make.hs index 3031dc315c..21f947e593 100644 --- a/src/Language/PureScript/Make.hs +++ b/src/Language/PureScript/Make.hs @@ -357,28 +357,31 @@ buildMakeActions outputDir filePathMap foreigns usePrefix = return $ Just $ Imp.App Nothing (Imp.Var Nothing "require") [Imp.StringLiteral Nothing "./foreign"] Nothing | requiresForeign m -> throwError . errorMessage $ MissingFFIModule mn | otherwise -> return Nothing - rawJs <- J.moduleToJs m foreignInclude - dir <- lift $ makeIO (const (ErrorMessage [] $ CannotGetFileInfo ".")) getCurrentDirectory - sourceMaps <- lift $ asks optionsSourceMaps - let (pjs, mappings) = if sourceMaps then prettyPrintJSWithSourceMaps rawJs else (prettyPrintJS rawJs, []) + let filePath = T.unpack (runModuleName mn) - jsFile = outputDir filePath "index.js" - mapFile = outputDir filePath "index.js.map" externsFile = outputDir filePath "externs.json" - foreignFile = outputDir filePath "foreign.js" - prefix = ["Generated by purs version " <> T.pack (showVersion Paths.version) | usePrefix] - js = T.unlines $ map ("// " <>) prefix ++ [pjs] - mapRef = if sourceMaps then "//# sourceMappingURL=index.js.map\n" else "" - lift $ do - writeTextFile jsFile (B.fromStrict $ TE.encodeUtf8 $ js <> mapRef) - for_ (mn `M.lookup` foreigns) (readTextFile >=> writeTextFile foreignFile) - writeTextFile externsFile exts - lift $ when sourceMaps $ genSourceMap dir mapFile (length prefix) mappings + lift $ writeTextFile externsFile exts dumpCoreFn <- lift $ asks optionsDumpCoreFn - when dumpCoreFn $ do - let coreFnFile = outputDir filePath "corefn.json" - let json = CFJ.moduleToJSON Paths.version m - lift $ writeTextFile coreFnFile (encode json) + if dumpCoreFn + then do + let coreFnFile = outputDir filePath "corefn.json" + json = CFJ.moduleToJSON Paths.version m + lift $ writeTextFile coreFnFile (encode json) + else do + rawJs <- J.moduleToJs m foreignInclude + dir <- lift $ makeIO (const (ErrorMessage [] $ CannotGetFileInfo ".")) getCurrentDirectory + sourceMaps <- lift $ asks optionsSourceMaps + let (pjs, mappings) = if sourceMaps then prettyPrintJSWithSourceMaps rawJs else (prettyPrintJS rawJs, []) + jsFile = outputDir filePath "index.js" + mapFile = outputDir filePath "index.js.map" + foreignFile = outputDir filePath "foreign.js" + prefix = ["Generated by purs version " <> T.pack (showVersion Paths.version) | usePrefix] + js = T.unlines $ map ("// " <>) prefix ++ [pjs] + mapRef = if sourceMaps then "//# sourceMappingURL=index.js.map\n" else "" + lift $ do + writeTextFile jsFile (B.fromStrict $ TE.encodeUtf8 $ js <> mapRef) + for_ (mn `M.lookup` foreigns) (readTextFile >=> writeTextFile foreignFile) + lift $ when sourceMaps $ genSourceMap dir mapFile (length prefix) mappings genSourceMap :: String -> String -> Int -> [SMap] -> Make () genSourceMap dir mapFile extraLines mappings = do From 87b7106814ef23d6ed49fd358829e4a5c98f6208 Mon Sep 17 00:00:00 2001 From: Gabe Johnson Date: Thu, 5 Apr 2018 11:47:01 -0500 Subject: [PATCH 2/2] Prevent FFI checks when --dump-corefn is used --- src/Language/PureScript/Make.hs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Language/PureScript/Make.hs b/src/Language/PureScript/Make.hs index 21f947e593..45a68e0c87 100644 --- a/src/Language/PureScript/Make.hs +++ b/src/Language/PureScript/Make.hs @@ -347,17 +347,6 @@ buildMakeActions outputDir filePathMap foreigns usePrefix = codegen :: CF.Module CF.Ann -> Environment -> Externs -> SupplyT Make () codegen m _ exts = do let mn = CF.moduleName m - foreignInclude <- case mn `M.lookup` foreigns of - Just path - | not $ requiresForeign m -> do - tell $ errorMessage $ UnnecessaryFFIModule mn path - return Nothing - | otherwise -> do - checkForeignDecls m path - return $ Just $ Imp.App Nothing (Imp.Var Nothing "require") [Imp.StringLiteral Nothing "./foreign"] - Nothing | requiresForeign m -> throwError . errorMessage $ MissingFFIModule mn - | otherwise -> return Nothing - let filePath = T.unpack (runModuleName mn) externsFile = outputDir filePath "externs.json" lift $ writeTextFile externsFile exts @@ -368,6 +357,17 @@ buildMakeActions outputDir filePathMap foreigns usePrefix = json = CFJ.moduleToJSON Paths.version m lift $ writeTextFile coreFnFile (encode json) else do + foreignInclude <- case mn `M.lookup` foreigns of + Just path + | not $ requiresForeign m -> do + tell $ errorMessage $ UnnecessaryFFIModule mn path + return Nothing + | otherwise -> do + checkForeignDecls m path + return $ Just $ Imp.App Nothing (Imp.Var Nothing "require") [Imp.StringLiteral Nothing "./foreign"] + Nothing | requiresForeign m -> throwError . errorMessage $ MissingFFIModule mn + | otherwise -> return Nothing + rawJs <- J.moduleToJs m foreignInclude dir <- lift $ makeIO (const (ErrorMessage [] $ CannotGetFileInfo ".")) getCurrentDirectory sourceMaps <- lift $ asks optionsSourceMaps