@@ -21,43 +21,36 @@ import Lamdera.Project (lamderaCore)
2121
2222
2323constrain pkg modu name annotation@ (Can. Forall freevars t) region expected =
24- if pkg == lamderaCore && modu == " Lamdera" && name == " sendToBackend" then
25- do
26- sourcePkg <- determineTypesLocation " ToBackend"
27- let
28- fn (Can. TVar " toBackend" ) = Can. TType (ModuleName. Canonical Pkg. dummyName sourcePkg) " ToBackend" []
29- fn x = x
30- pure $ CForeign region name (Can. Forall freevars (mapTvars fn t)) expected
31-
32- else if pkg == lamderaCore && modu == " Lamdera" && name == " sendToFrontend" then
33- do
34- sourcePkg <- determineTypesLocation " ToFrontend"
35- let
36- fn (Can. TVar " toFrontend" ) = Can. TType (ModuleName. Canonical Pkg. dummyName sourcePkg) " ToFrontend" []
37- fn x = x
38- pure $ CForeign region name (Can. Forall freevars (mapTvars fn t)) expected
39-
40- else if pkg == lamderaCore && modu == " Lamdera" && name == " broadcast" then
41- do
42- sourcePkg <- determineTypesLocation " ToFrontend"
43- let
44- fn (Can. TVar " toFrontend" ) = Can. TType (ModuleName. Canonical Pkg. dummyName sourcePkg) " ToFrontend" []
45- fn x = x
46- pure $ CForeign region name (Can. Forall freevars (mapTvars fn t)) expected
24+ if pkg == lamderaCore && modu == " Lamdera" then
25+
26+ case name of
27+ " sendToBackend" -> do
28+ sourcePkg <- determineTypesLocation " ToBackend"
29+ let
30+ fn (Can. TVar " toBackend" ) = Can. TType (ModuleName. Canonical Pkg. dummyName sourcePkg) " ToBackend" []
31+ fn x = x
32+ pure $ CForeign region name (Can. Forall freevars (mapTvars fn t)) expected
33+
34+ " sendToFrontend" -> do
35+ sourcePkg <- determineTypesLocation " ToFrontend"
36+ let
37+ fn (Can. TVar " toFrontend" ) = Can. TType (ModuleName. Canonical Pkg. dummyName sourcePkg) " ToFrontend" []
38+ fn x = x
39+ pure $ CForeign region name (Can. Forall freevars (mapTvars fn t)) expected
40+
41+ " broadcast" -> do
42+ sourcePkg <- determineTypesLocation " ToFrontend"
43+ let
44+ fn (Can. TVar " toFrontend" ) = Can. TType (ModuleName. Canonical Pkg. dummyName sourcePkg) " ToFrontend" []
45+ fn x = x
46+ pure $ CForeign region name (Can. Forall freevars (mapTvars fn t)) expected
47+
48+ _ ->
49+ pure $ CForeign region name annotation expected
4750
4851 else
4952 pure $ CForeign region name annotation expected
5053
51- -- @LEGACY, left here in case we run into issues, but likely no longer needed.
52- -- Since we don't have type annotations on codecs, we have exposed top-level
53- -- things without type annotations, which means that we see bugs in the type
54- -- inference engine that shouldn't be there. This is a hotfix for such a bug,
55- -- where the forall. part of the type doesn't hold all the tvars used in the
56- -- type, so we inject any missning tvars and hope it works out.
57- -- @LAMDERA todo legacy from Haskell transpilation, re-evalutate and remove
58- -- else
59- -- pure $ CForeign region name (Can.Forall (freevars <> getFreevars t) t) expected -- NOTE: prefer freevars over getFreevars if there's a conflict
60-
6154
6255determineTypesLocation :: Text -> IO N. Name
6356determineTypesLocation tipe = do
@@ -94,6 +87,8 @@ determineTypesLocation tipe = do
9487typeLocations :: IORef (Map. Map Text N. Name )
9588typeLocations = unsafePerformIO $ newIORef Map. empty
9689
90+ resetTypeLocations :: IO ()
91+ resetTypeLocations = atomicModifyIORef typeLocations (\ m -> (Map. empty, () ))
9792
9893rememberTypeLocation :: Text -> N. Name -> IO ()
9994rememberTypeLocation str d = atomicModifyIORef typeLocations (\ m -> (Map. insert str d m, () ))
0 commit comments