Skip to content

Commit 9409776

Browse files
committed
Updated deps, removed Prim.undefined, no unused arguments.
1 parent e562d22 commit 9409776

File tree

27 files changed

+238
-272
lines changed

27 files changed

+238
-272
lines changed

flake.lock

+9-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

+41-21
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,19 @@
55
flake-utils.url = "github:numtide/flake-utils";
66
easy-purescript-nix.url = "github:justinwoo/easy-purescript-nix";
77
};
8-
outputs = { self, nixpkgs, flake-utils, haskellNix, easy-purescript-nix }:
9-
let supportedSystems = [ "x86_64-linux" ];
10-
in flake-utils.lib.eachSystem supportedSystems (system:
8+
outputs =
9+
{
10+
self,
11+
nixpkgs,
12+
flake-utils,
13+
haskellNix,
14+
easy-purescript-nix,
15+
}:
16+
let
17+
supportedSystems = [ "x86_64-linux" ];
18+
in
19+
flake-utils.lib.eachSystem supportedSystems (
20+
system:
1121
let
1222
easy-ps = easy-purescript-nix.packages.${system};
1323
pkgs = import nixpkgs {
@@ -21,49 +31,59 @@
2131
src = ./.;
2232
compiler-nix-name = "ghc98";
2333
evalSystem = "x86_64-linux";
24-
modules = let prof = false;
25-
in [{
26-
doHaddock = false;
27-
doHoogle = false;
28-
enableProfiling = prof;
29-
enableLibraryProfiling = prof;
30-
}];
34+
modules =
35+
let
36+
prof = false;
37+
in
38+
[
39+
{
40+
doHaddock = false;
41+
doHoogle = false;
42+
enableProfiling = prof;
43+
enableLibraryProfiling = prof;
44+
}
45+
];
3146

3247
name = "purescript-lua";
3348

3449
shell = {
3550
tools = {
36-
cabal = {};
37-
fourmolu = {};
38-
hlint = {};
39-
haskell-language-server = {};
51+
cabal = { };
52+
fourmolu = { };
53+
hlint = { };
54+
haskell-language-server = { };
4055
};
4156
buildInputs = with pkgs; [
4257
cachix
43-
lua51Packages.lua
44-
lua51Packages.luacheck
4558
easy-ps.purs-0_15_15
4659
easy-ps.spago
60+
lua51Packages.lua
61+
lua51Packages.luacheck
62+
nil
4763
treefmt
4864
upx
4965
yamlfmt
5066
];
5167
};
52-
5368
};
5469
})
5570
];
5671
flake = pkgs.psluaProject.flake { };
57-
in flake // {
72+
in
73+
flake
74+
// {
5875
legacyPackages = pkgs;
5976
packages.default = flake.packages."pslua:exe:pslua";
6077
packages.static = flake.ciJobs.x86_64-unknown-linux-musl.packages."pslua:exe:pslua";
61-
});
78+
}
79+
);
6280

6381
# --- Flake Local Nix Configuration ----------------------------
6482
nixConfig = {
65-
extra-substituters =
66-
[ "https://cache.iog.io" "https://purescript-lua.cachix.org" ];
83+
extra-substituters = [
84+
"https://cache.iog.io"
85+
"https://purescript-lua.cachix.org"
86+
];
6787
extra-trusted-public-keys = [
6888
"hydra.iohk.io:f/Ea+s+dFdN+3Y/G+FDgSq+a5NEWhJGzdjvKNGv0/EQ="
6989
"purescript-lua.cachix.org-1:yLs4ei2HtnuPtzLekOrW3xdfm95+Etw15gwgyIGTayA="

lib/Language/PureScript/Backend/IR.hs

+5-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import Language.PureScript.PSString
2828
, decodeStringEscaping
2929
)
3030
import Relude.Extra (toFst)
31-
import Relude.Unsafe qualified as Unsafe
3231
import Text.Megaparsec qualified as Megaparsec
3332
import Text.Pretty.Simple (pShow)
3433
import Text.Show (Show (..))
@@ -135,7 +134,10 @@ useAnnotation name = do
135134
mkImports RepM [ModuleName]
136135
mkImports = do
137136
Cfn.Module {moduleName, moduleImports} gets contextModule
138-
pure $ filter (isIncluded moduleName) (snd <$> moduleImports)
137+
pure $
138+
-- it's ok to always add prim as an explicit import:
139+
-- DCE removes it if it's not used.
140+
ModuleName "Prim" : [i | (_ann, i) moduleImports, isIncluded moduleName i]
139141
where
140142
isIncluded PS.ModuleName ModuleName Bool
141143
isIncluded currentModule modname = modname /= currentModule
@@ -170,7 +172,7 @@ collectDataDeclarations cfnModules = Map.unions do
170172
| bind Cfn.moduleBindings cfnModule
171173
, Cfn.Constructor _ann tyName ctorName fields boundExp bind
172174
]
173-
, let ty = fst (Unsafe.head ctors) -- groupBy never makes an empty group
175+
, let ty = fst (head (NE.fromList ctors)) -- groupBy never makes an empty group
174176
, let algebraicType = if length ctors == 1 then ProductType else SumType
175177
]
176178
where

lib/Language/PureScript/Backend/IR/Linker.hs

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Data.Graph (graphFromEdges', reverseTopSort)
66
import Data.Map qualified as Map
77
import Language.PureScript.Backend.IR.Inliner qualified as Inline
88
import Language.PureScript.Backend.IR.Names
9-
( ModuleName
9+
( ModuleName (..)
1010
, Name (..)
1111
, PropName (PropName)
1212
, QName (QName)

lib/Language/PureScript/Backend/Lua.hs

+23-37
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ module Language.PureScript.Backend.Lua
44
( fromUberModule
55
, fromIR
66
, fromName
7-
-- , qualifyName
87
, qualifyName
98
, Error (..)
109
) where
@@ -23,7 +22,7 @@ import Data.Traversable (for)
2322
import Language.PureScript.Backend.IR qualified as IR
2423
import Language.PureScript.Backend.IR.Linker (UberModule (..))
2524
import Language.PureScript.Backend.IR.Linker qualified as Linker
26-
import Language.PureScript.Backend.IR.Query (usesPrimModule, usesRuntimeLazy)
25+
import Language.PureScript.Backend.IR.Query (usesRuntimeLazy)
2726
import Language.PureScript.Backend.Lua.Fixture qualified as Fixture
2827
import Language.PureScript.Backend.Lua.Key qualified as Key
2928
import Language.PureScript.Backend.Lua.Linker.Foreign qualified as Foreign
@@ -32,7 +31,7 @@ import Language.PureScript.Backend.Lua.Name qualified as Name
3231
import Language.PureScript.Backend.Lua.Types (ParamF (..))
3332
import Language.PureScript.Backend.Lua.Types qualified as Lua
3433
import Language.PureScript.Backend.Types (AppOrModule (..))
35-
import Language.PureScript.Names (ModuleName, runModuleName)
34+
import Language.PureScript.Names (ModuleName (..), runModuleName)
3635
import Language.PureScript.Names qualified as PS
3736
import Path (Abs, Dir, Path)
3837
import Prelude hiding (exp, local)
@@ -82,13 +81,9 @@ fromUberModule foreigns needsRuntimeLazy appOrModule uber = (`evalStateT` 0) do
8281
recBinds forM (toList recGroup) \(IR.QName modname name, irExp)
8382
(modname,name,) . asExpression
8483
<$> fromIR foreigns Set.empty modname irExp
85-
let declarations = DList.fromList do
86-
(modname, name, _exp) recBinds
87-
pure $ mkBinding modname (fromName name) Lua.Nil
88-
assignments = DList.fromList do
89-
(modname, name, exp) recBinds
90-
pure $ mkBinding modname (fromName name) exp
91-
pure $ declarations <> assignments
84+
pure $ DList.fromList do
85+
(modname, name, exp) recBinds
86+
pure $ mkBinding modname (fromName name) exp
9287

9388
returnExp
9489
case appOrModule of
@@ -111,25 +106,19 @@ fromUberModule foreigns needsRuntimeLazy appOrModule uber = (`evalStateT` 0) do
111106
)
112107

113108
pure . mconcat $
114-
[ [Lua.assign moduleVar (Lua.table []) | not (null bindings)]
115-
, [ mkBinding Fixture.primModule Fixture.undefined Lua.Nil
116-
| usesPrimModule uber
117-
]
118-
, [Fixture.runtimeLazy | untag needsRuntimeLazy && usesRuntimeLazy uber]
109+
[ [Fixture.runtimeLazy | untag needsRuntimeLazy && usesRuntimeLazy uber]
119110
, [Fixture.objectUpdate | UsesObjectUpdate [usesObjectUpdate]]
111+
, [Lua.local1 Fixture.moduleName (Lua.table []) | not (null bindings)]
120112
, toList (DList.snoc bindings returnStat)
121113
]
122114

123115
mkBinding ModuleName Lua.Name Lua.Exp Lua.Statement
124116
mkBinding modname name =
125117
Lua.assign $
126118
Lua.VarField
127-
(Lua.ann (Lua.var moduleVar))
119+
(Lua.ann (Lua.varName Fixture.moduleName))
128120
(qualifyName modname name)
129121

130-
moduleVar Lua.Var
131-
moduleVar = Lua.VarName [Lua.name|M|]
132-
133122
asExpression Either Lua.Chunk Lua.Exp Lua.Exp
134123
asExpression = \case
135124
Left chunk Lua.chunkToExpression chunk
@@ -206,26 +195,29 @@ fromIR foreigns topLevelNames modname ir = case ir of
206195
Lua.functionCall (Lua.varName Fixture.objectUpdateName) [obj, vals]
207196
IR.Abs _ann param expr do
208197
e goExp expr
209-
luaParam
210-
Lua.ParamNamed
211-
<$> case param of
212-
IR.ParamUnused _ann uniqueName "unused"
213-
IR.ParamNamed _ann name pure (fromName name)
214-
pure . Right $ Lua.functionDef [luaParam] [Lua.return e]
215-
IR.App _ann expr param do
198+
let luaParams = case param of
199+
IR.ParamUnused _ann []
200+
IR.ParamNamed _ann name [ParamNamed (fromName name)]
201+
pure . Right $ Lua.functionDef luaParams [Lua.return e]
202+
IR.App _ann expr arg do
216203
e goExp expr
217-
a goExp param
218-
pure . Right $ Lua.functionCall e [a]
204+
Right . Lua.functionCall e <$> case arg of
205+
-- PS sometimes inserts syntetic unused argument "Prim.undefined"
206+
IR.Ref _ann (IR.Imported (IR.ModuleName "Prim") (IR.Name "undefined")) _
207+
pure []
208+
_ goExp arg <&> \a [a]
219209
IR.Ref _ann qualifiedName index
220210
pure . Right $ case qualifiedName of
221211
IR.Local name
222212
| topLevelName qualifyName modname (fromName name)
223213
, Set.member topLevelName topLevelNames
224-
Lua.varField (Lua.var moduleVar) topLevelName
214+
Lua.varField (Lua.varName Fixture.moduleName) topLevelName
225215
IR.Local name
226216
Lua.varName (fromNameWithIndex name index)
227217
IR.Imported modname' name
228-
Lua.varField (Lua.var moduleVar) (qualifyName modname' (fromName name))
218+
Lua.varField
219+
(Lua.varName Fixture.moduleName)
220+
(qualifyName modname' (fromName name))
229221
IR.Let _ann bindings bodyExp do
230222
body go bodyExp
231223
recs
@@ -294,11 +286,5 @@ keyCtor = Lua.String "$ctor"
294286
--------------------------------------------------------------------------------
295287
-- Helpers ---------------------------------------------------------------------
296288

297-
uniqueName MonadState Natural m Text m Lua.Name
298-
uniqueName prefix = do
299-
index get
300-
modify' (+ 1)
301-
pure $ Lua.unsafeName (prefix <> show index)
302-
303289
qualifyName ModuleName Lua.Name Lua.Name
304-
qualifyName modname = Fixture.psluaName . Name.join2 (fromModuleName modname)
290+
qualifyName modname = Name.join2 (fromModuleName modname)

0 commit comments

Comments
 (0)