ref: 21ed5016647dc84c7310637cfc9da644fea5649b
parent: fef81c25bf7ac217797c6c209d5e5ad38b52712c
author: Lennart Augustsson <lennart.augustsson@epicgames.com>
date: Wed Sep 20 12:46:20 EDT 2023
More location info.
--- a/comb/mhs.comb
+++ b/comb/mhs.comb
@@ -1,3 +1,3 @@
v3.4
-850
-(($A :0 ((_645 _594) (($B ((($S' ($C ((($C' ($S' _645)) (($B ($C _2)) _577)) (($B ($B (_645 _674))) ((($C' ($C' $C)) ((($C' ($S' ($C' $C))) ((($C' ($C' ($C' $C))) ((($C' ($C' ($C' ($C' $S')))) (($B ($B ($B ($B $C)))) ((($C' ($C' ($C' $B))) (($B ($B ($B ($C' $S)))) ((($C' ($C' ($C' ($C' $C)))) ((($C' ($C' ($C' ($C' ($C' $S'))))) (($B ($B ($B ($B ($B $C))))) ((($C' ($C' ($C' ($C' ($C' $C))))) ((($C' ($C' ($C' $B))) (($B ($B ($B ($C' ($C' $S'))))) ((($C' ($C' ($C' ($C' ($C' $C'))))) ((($C' ($C' ($C' ($S' ($C' $C'))))) (($B ($B ($B ($B $B')))) ((($S' $B) ($B' ($B' (($B ($S' $B)) (($B ($B _646)) ((($C' $B) (($B _743) (($B _664) ((($C' _779) _9) 0)))) (($B (_743 _667)) (($B (_680 "top level defns: ")) _625)))))))) ((($S' $B) ($B' (($B ($C' $B)) (($B $B') (($B ($B _646)) ((($C' $B) (($B _743) (($B _664) ((($C' _779) _9) 1)))) (_663 ($T (($B ($B (_743 _667))) ((($C' $B) (($B _680) ((($C' _680) _583) " = "))) (($C _403) $K))))))))))) ((($C' $B) ((($S' $C') (($B $C') (($B $C') _10))) ((($S' $B) (($B ($C' ($C' _646))) ((($C' $B) ($B' (($B _743) (($B _669) _12)))) (($B _680) ((($C' _680) (($B (_680 _1)) _625)) (($O 10) $K)))))) (($B ($B (_645 _674))) ((($C' $B) ($B' (($B _743) (($B _664) ((($C' _779) _9) 0))))) (($B ($B (_743 _667))) ((($C' ($C' _680)) (($B ($B (_680 "final pass "))) (($B ($B (_639 6))) (($B ($B _625)) _773)))) "ms"))))))) _3))))) ((($C' ($C' $C)) (($B (($C' $C) (($B ($C _685)) _403))) (($C _698) (_714 0)))) $K))) (($B ($C $B)) (($B ($B ($C $B))) (($B ($B $BK)) (($B ($B (($C' $B) (($B _744) (($B _680) ((($C' _680) (($B (_680 "(($A :")) _625)) (($O 32) $K))))))) ((($C' $B) (($B ($C' _744)) ($B _403))) (($B (_744 (_680 ") "))) (($C _744) (_680 (($O 41) $K)))))))))))) $T)) (($B $Y) ((($C' ($C' $S)) ((($C' ($C' $S)) ((($C' $B) $P) ((($S' ($C' $B)) ($B _378)) $I))) ($BK $K))) $K))))) (($B (($S' _743) (($B _740) (($B (_743 _788)) (($B (_680 "main: findIdent: ")) _583))))) (($C' _613) _580)))) _620))) (($B ($B _617)) ((($C' $B) (($B _682) (($B $T) (($B ($C $B)) (($B ($B $BK)) ((($C' ($C' ($C' $O))) ($B (($C' $P) _580))) $K)))))) (($C _698) (_714 0))))))) ($T $A))) ($T $K))) $I)) (($B (_743 _377)) (($B (_743 _577)) (($B (_680 (($O 95) $K))) _625)))))))) (($S (($S ((($S' _8) (($B _697) (_684 (_637 "-v")))) ((_713 _637) "-r"))) (($B (_678 (($O 46) $K))) (($B _742) (_683 ((_702 _764) "-i")))))) (($B (_743 _709)) ((($C' _680) (($B _742) (_683 ((_702 _764) "-o")))) (($O "out.comb") $K))))) (($B (($S (($C ((($C' _775) _697) 1)) (_788 "Usage: mhs [-v] [-r] [-iPATH] [-oFILE] ModuleName"))) _709)) (_684 ((_744 _784) ((_744 (_637 (($O 45) $K))) (_695 1))))))) (_705 ((_744 _784) (_637 "--")))))) (($A :1 "v3.4\10&") (($A :2 ((($S' ($S' _645)) _17) (($B ($B ($B (_645 _674)))) ((($C' ($C' $B)) (($B ($B ($C' (($S' _645) (($B _647) (_736 _223)))))) (($B ($B ($B ($B $T)))) (($B ($B ($B ($B (_645 _674))))) ((($C' $B) (($B ($C' $B)) (($B ($B ($C' _646))) ((($C' $B) ($B' (($B _743) (($B _664) ((($C' _779) _9) 0))))) (($B ($B (_743 _667))) ((($C' ($C' _680)) (($B ($B (_680 "combinator conversion "))) (($B ($B (_639 6))) (($B ($B _625)) _773)))) "ms")))))) (($B ($B _647)) (($B $P) (($C _586) (_577 "main"))))))))) (_682 ($T ((($C' ($C' $O)) ((($C' $B) $P) _406)) $K))))))) (($A :3 (($B (_645 _594)) (($B (($C' _595) ((($C' _768) (($B _697) (_705 ((_744 _784) (_637 "--"))))) 1))) (($B (_743 _7)) _4)))) (($A :4 ($T (($C ((($C' $C') (($B $S) ($C $C))) (($B ($B $Y)) (($B ($B ($B _567))) (($C' ($C' _682)) (($B ($B $T)) ((($C' ($C' ($C' ($C' $O)))) (($B ($B (($C' $B) $P))) ($B _5))) $K))))))) (($B (($S' _743) (($B _740) (($B (_743 _788)) (($B (_680 "not found ")) _583))))) ($C _568))))) (($A :5 ((($C' $C) ((($S' $C) ((($C' ($C' $S')) (($S $P) ((($S' ($C' $B)) (($B ($B _7)) _5)) _5))) ($BK $K))) ((($C' ($S' $C)) ((($C' ($C' $C)) (($B (($C' $C) (($B ($P _7)) $K))) ((($C' $B) _5) _405))) ((($S' _743) (($B _740) (($B (_743 _788)) (_680 "primlookup: ")))) (($C (_719 _637)) _6)))) $K))) (_788 "trans: impossible"))) (($A :6 (($O (($P (($O 66) $K)) $B)) (($O (($P (($O 79) $K)) $O)) (($O (($P (($O 75) $K)) $K)) (($O (($P "C'") $C')) (($O (($P (($O 67)
\ No newline at end of file
+852
+(($A :0 ((_647 _596) (($B ((($S' ($C ((($C' ($S' _647)) (($B ($C _2)) _579)) (($B ($B (_647 _676))) ((($C' ($C' $C)) ((($C' ($S' ($C' $C))) ((($C' ($C' ($C' $C))) ((($C' ($C' ($C' ($C' $S')))) (($B ($B ($B ($B $C)))) ((($C' ($C' ($C' $B))) (($B ($B ($B ($C' $S)))) ((($C' ($C' ($C' ($C' $C)))) ((($C' ($C' ($C' ($C' ($C' $S'))))) (($B ($B ($B ($B ($B $C))))) ((($C' ($C' ($C' ($C' ($C' $C))))) ((($C' ($C' ($C' $B))) (($B ($B ($B ($C' ($C' $S'))))) ((($C' ($C' ($C' ($C' ($C' $C'))))) ((($C' ($C' ($C' ($S' ($C' $C'))))) (($B ($B ($B ($B $B')))) ((($S' $B) ($B' ($B' (($B ($S' $B)) (($B ($B _648)) ((($C' $B) (($B _745) (($B _666) ((($C' _781) _9) 0)))) (($B (_745 _669)) (($B (_682 "top level defns: ")) _627)))))))) ((($S' $B) ($B' (($B ($C' $B)) (($B $B') (($B ($B _648)) ((($C' $B) (($B _745) (($B _666) ((($C' _781) _9) 1)))) (_665 ($T (($B ($B (_745 _669))) ((($C' $B) (($B _682) ((($C' _682) _585) " = "))) (($C _405) $K))))))))))) ((($C' $B) ((($S' $C') (($B $C') (($B $C') _10))) ((($S' $B) (($B ($C' ($C' _648))) ((($C' $B) ($B' (($B _745) (($B _671) _12)))) (($B _682) ((($C' _682) (($B (_682 _1)) _627)) (($O 10) $K)))))) (($B ($B (_647 _676))) ((($C' $B) ($B' (($B _745) (($B _666) ((($C' _781) _9) 0))))) (($B ($B (_745 _669))) ((($C' ($C' _682)) (($B ($B (_682 "final pass "))) (($B ($B (_641 6))) (($B ($B _627)) _775)))) "ms"))))))) _3))))) ((($C' ($C' $C)) (($B (($C' $C) (($B ($C _687)) _405))) (($C _700) (_716 0)))) $K))) (($B ($C $B)) (($B ($B ($C $B))) (($B ($B $BK)) (($B ($B (($C' $B) (($B _746) (($B _682) ((($C' _682) (($B (_682 "(($A :")) _627)) (($O 32) $K))))))) ((($C' $B) (($B ($C' _746)) ($B _405))) (($B (_746 (_682 ") "))) (($C _746) (_682 (($O 41) $K)))))))))))) $T)) (($B $Y) ((($C' ($C' $S)) ((($C' ($C' $S)) ((($C' $B) $P) ((($S' ($C' $B)) ($B _380)) $I))) ($BK $K))) $K))))) (($B (($S' _745) (($B _742) (($B (_745 _790)) (($B (_682 "main: findIdent: ")) _585))))) (($C' _615) _582)))) _622))) (($B ($B _619)) ((($C' $B) (($B _684) (($B $T) (($B ($C $B)) (($B ($B $BK)) ((($C' ($C' ($C' $O))) ($B (($C' $P) _582))) $K)))))) (($C _700) (_716 0))))))) ($T $A))) ($T $K))) $I)) (($B (_745 _379)) (($B (_745 _579)) (($B (_682 (($O 95) $K))) _627)))))))) (($S (($S ((($S' _8) (($B _699) (_686 (_639 "-v")))) ((_715 _639) "-r"))) (($B (_680 (($O 46) $K))) (($B _744) (_685 ((_704 _766) "-i")))))) (($B (_745 _711)) ((($C' _682) (($B _744) (_685 ((_704 _766) "-o")))) (($O "out.comb") $K))))) (($B (($S (($C ((($C' _777) _699) 1)) (_790 "Usage: mhs [-v] [-r] [-iPATH] [-oFILE] ModuleName"))) _711)) (_686 ((_746 _786) ((_746 (_639 (($O 45) $K))) (_697 1))))))) (_707 ((_746 _786) (_639 "--")))))) (($A :1 "v3.4\10&") (($A :2 ((($S' ($S' _647)) _17) (($B ($B ($B (_647 _676)))) ((($C' ($C' $B)) (($B ($B ($C' (($S' _647) (($B _649) (_738 _223)))))) (($B ($B ($B ($B $T)))) (($B ($B ($B ($B (_647 _676))))) ((($C' $B) (($B ($C' $B)) (($B ($B ($C' _648))) ((($C' $B) ($B' (($B _745) (($B _666) ((($C' _781) _9) 0))))) (($B ($B (_745 _669))) ((($C' ($C' _682)) (($B ($B (_682 "combinator conversion "))) (($B ($B (_641 6))) (($B ($B _627)) _775)))) "ms")))))) (($B ($B _649)) (($B $P) (($C _588) (_579 "main"))))))))) (_684 ($T ((($C' ($C' $O)) ((($C' $B) $P) _408)) $K))))))) (($A :3 (($B (_647 _596)) (($B (($C' _597) ((($C' _770) (($B _699) (_707 ((_746 _786) (_639 "--"))))) 1))) (($B (_745 _7)) _4)))) (($A :4 ($T (($C ((($C' $C') (($B $S) ($C $C))) (($B ($B $Y)) (($B ($B ($B _569))) (($C' ($C' _684)) (($B ($B $T)) ((($C' ($C' ($C' ($C' $O)))) (($B ($B (($C' $B) $P))) ($B _5))) $K))))))) (($B (($S' _745) (($B _742) (($B (_745 _790)) (($B (_682 "not found ")) _585))))) ($C _570))))) (($A :5 ((($C' $C) ((($S' $C) ((($C' ($C' $S')) (($S $P) ((($S' ($C' $B)) (($B ($B _7)) _5)) _5))) ($BK $K))) ((($C' ($S' $C)) ((($C' ($C' $C)) (($B (($C' $C) (($B ($P _7)) $K))) ((($C' $B) _5) _407))) ((($S' _745) (($B _742) (($B (_745 _790)) (_682 "primlookup: ")))) (($C (_721 _639)) _6)))) $K))) (_790 "trans: impossible"))) (($A :6 (($O (($P (($O 66) $K)) $B)) (($O (($P (($O 79) $K)) $O)) (($O (($P (($O 75) $K)) $K)) (($O (($P "C'") $C')) (($O (($P (($O 67)
\ No newline at end of file
--- a/src/MicroHs/Desugar.hs
+++ b/src/MicroHs/Desugar.hs
@@ -216,7 +216,7 @@
ECon _ -> ap
EApp f a -> EApp (dsPat f) (dsPat a)
EListish (LList ps) -> dsPat $ foldr (\ x xs -> EApp (EApp consCon x) xs) nilCon ps
- ETuple ps -> dsPat $ foldl EApp (tupleCon (length ps)) ps
+ ETuple ps -> dsPat $ foldl EApp (tupleCon (getSLocExpr ap) (length ps)) ps
EAt i p -> EAt i (dsPat p)
ELit _ _ -> ap
_ -> impossible
@@ -235,10 +235,10 @@
c = mkIdent "Data.List.:"
in ECon $ ConData [(n, 0), (c, 2)] n
-tupleCon :: Int -> EPat
-tupleCon n =
+tupleCon :: SLoc -> Int -> EPat
+tupleCon loc n =
let
- c = tupleConstr n
+ c = tupleConstr loc n
in ECon $ ConData [(c, n)] c
dummyIdent :: Ident
--- a/src/MicroHs/Expr.hs
+++ b/src/MicroHs/Expr.hs
@@ -205,8 +205,8 @@
kType :: EKind
kType = EVar (Ident noSLoc "Primitives.Type")
-tupleConstr :: Int -> Ident
-tupleConstr n = mkIdent (replicate (n - 1) ',')
+tupleConstr :: SLoc -> Int -> Ident
+tupleConstr loc n = mkIdentSLoc loc (replicate (n - 1) ',')
untupleConstr :: Ident -> Int
untupleConstr i = length (unIdent i) + 1
--- a/src/MicroHs/TypeCheck.hs
+++ b/src/MicroHs/TypeCheck.hs
@@ -134,8 +134,8 @@
getAppCon (EApp f _) = getAppCon f
getAppCon _ = undefined
-eVarI :: String -> Expr
-eVarI = EVar . mkIdent
+eVarI :: SLoc -> String -> Expr
+eVarI loc = EVar . mkIdentSLoc loc
--tcExpErr :: forall a . Ident -> T a
--tcExpErr i = tcError (getSLocIdent i) $ ": export undefined " ++ showIdent i
@@ -286,32 +286,38 @@
kTypeTypeTypeS :: ETypeScheme
kTypeTypeTypeS = kArrow kType $ kArrow kType kType
+builtinLoc :: SLoc
+builtinLoc = SLoc "builtin" 0 0
+
+mkIdentB :: String -> Ident
+mkIdentB = mkIdentSLoc builtinLoc
+
primKindTable :: KindTable
primKindTable =
let
- entry i = Entry (EVar (mkIdent i))
+ entry i = Entry (EVar (mkIdentB i))
in M.fromList [
-- The kinds are wired in (for now)
- (mkIdent "Primitives.Type", [entry "Primitives.Type" kTypeS]),
- (mkIdent "Type", [entry "Primitives.Type" kTypeS]),
- (mkIdent "Primitives.->", [entry "Primitives.->" kTypeTypeTypeS]),
- (mkIdent "->", [entry "Primitives.->" kTypeTypeTypeS])
+ (mkIdentB "Primitives.Type", [entry "Primitives.Type" kTypeS]),
+ (mkIdentB "Type", [entry "Primitives.Type" kTypeS]),
+ (mkIdentB "Primitives.->", [entry "Primitives.->" kTypeTypeTypeS]),
+ (mkIdentB "->", [entry "Primitives.->" kTypeTypeTypeS])
]
primTypes :: [(Ident, [Entry])]
primTypes =
let
- entry i = Entry (EVar (mkIdent i))
+ entry i = Entry (EVar (mkIdentB i))
tuple n =
let
- i = tupleConstr n
+ i = tupleConstr builtinLoc n
in (i, [entry (unIdent i) $ foldr kArrow kType (replicate n kType)])
in
[
-- The function arrow is bothersome to define in Primtives, so keep it here.
- (mkIdent "->", [entry "Primitives.->" kTypeTypeTypeS]),
+ (mkIdentB "->", [entry "Primitives.->" kTypeTypeTypeS]),
-- Primitives.hs uses the type [], and it's annoying to fix that.
- (mkIdent "Data.List.[]", [entry "Data.List.[]" kTypeTypeS])
+ (mkIdentB "Data.List.[]", [entry "Data.List.[]" kTypeTypeS])
] ++
map tuple (enumFromTo 2 10)
@@ -320,7 +326,7 @@
let
tuple n =
let
- c = tupleConstr n
+ c = tupleConstr builtinLoc n
vks = [IdKind (mkIdent ("a" ++ showInt i)) kType | i <- enumFromTo 1 n]ts = map tVarK vks
r = tApps c ts
@@ -733,6 +739,7 @@
tcExprR :: --XHasCallStack =>
Maybe EType -> Expr -> T (Typed Expr)
tcExprR mt ae =
+ let { loc = getSLocExpr ae } incase ae of
EVar i ->
if isUnderscore i then
@@ -742,13 +749,12 @@
(e, t) <- tLookupInst "variable" i
case mt of
Just tu@(EForall _ tt) -> T.do
- unify (getSLocExpr ae) tt t
+ unify loc tt t -- XXX is this really sufficient?
T.return (e, tu)
_ -> T.do
- munify (getSLocIdent i) mt t
+ munify loc mt t
T.return (e, t)
EApp f a -> T.do
- let loc = getSLocExpr ae
(ef, tf) <- tcExpr Nothing f
(ta, tr) <- unArrow loc tf
(ea, _) <- tcExpr (Just ta) a
@@ -762,7 +768,7 @@
-}
EOper e ies -> tcOper mt e ies
ELam is e -> tcExprLam mt is e
- ELit loc l -> tcLit mt loc l
+ ELit loc' l -> tcLit mt loc' l
ECase a arms -> T.do
(ea, ta) <- tcExpr Nothing a
tt <- unMType mt
@@ -774,8 +780,8 @@
n = length es
(ees, tes) <- T.fmap unzip (T.mapM (tcExpr Nothing) es)
let
- ttup = tApps (tupleConstr n) tes
- munify (getSLocExpr ae) mt ttup
+ ttup = tApps (tupleConstr loc n) tes
+ munify loc mt ttup
T.return (ETuple ees, ttup)
EDo mmn ass -> T.do
case ass of
@@ -783,16 +789,14 @@
[as] ->
case as of
SThen a -> tcExpr mt a
- _ -> tcError (getSLocExpr ae) $ "bad do "
+ _ -> tcError loc $ "bad do "
as : ss -> T.do
- let
- loc = getSLocExpr ae
case as of
SBind p a -> T.do
let
sbind = maybe (mkIdentSLoc loc ">>=") (\ mn -> qualIdent mn (mkIdentSLoc loc ">>=")) mmn
tcExpr mt (EApp (EApp (EVar sbind) a)
- (ELam [eVarI "$x"] (ECase (eVarI "$x") [(p, EAlts [([], EDo mmn ss)] [])])))
+ (ELam [eVarI loc "$x"] (ECase (eVarI loc "$x") [(p, EAlts [([], EDo mmn ss)] [])])))
SThen a -> T.do
let
sthen = maybe (mkIdentSLoc loc ">>") (\ mn -> qualIdent mn (mkIdentSLoc loc ">>") ) mmn
@@ -803,12 +807,12 @@
ESectL e i -> tcExpr mt (EApp (EVar i) e)
ESectR i e ->
- tcExpr mt (ELam [eVarI "$x"] (EApp (EApp (EVar i) (eVarI "$x")) e))
+ tcExpr mt (ELam [eVarI loc "$x"] (EApp (EApp (EVar i) (eVarI loc"$x")) e))
EIf e1 e2 e3 -> T.do
(ee1, _) <- tcExpr (Just tBool) e1
(ee2, te2) <- tcExpr mt e2
(ee3, te3) <- tcExpr mt e3
- unify (getSLocExpr ae) te2 te3
+ unify loc te2 te3
T.return (EIf ee1 ee2 ee3, te2)
EListish (LList es) -> T.do
(ees, ts) <- T.fmap unzip (T.mapM (tcExpr Nothing) es)
@@ -816,8 +820,8 @@
[] -> newUVar
t : _ -> T.return t
let
- tlist = tApps (mkIdent "Data.List.[]") [te]
- munify (getSLocExpr ae) mt tlist
+ tlist = tApps (mkIdentSLoc loc "Data.List.[]") [te]
+ munify loc mt tlist
T.return (EListish (LList ees), tlist)
EListish (LCompr eret ass) -> T.do
let
@@ -843,21 +847,21 @@
(rss, (ea, ta)) <- doStmts [] ass
let
tr = tApp tList ta
- munify (getSLocExpr ae) mt tr
+ munify loc mt tr
T.return (EListish (LCompr ea rss), tr)
- EListish (LFrom e) -> tcExpr mt (enum "From" [e])
- EListish (LFromTo e1 e2) -> tcExpr mt (enum "FromTo" [e1, e2])
- EListish (LFromThen e1 e2) -> tcExpr mt (enum "FromThen" [e1,e2])
- EListish (LFromThenTo e1 e2 e3) -> tcExpr mt (enum "FromThenTo" [e1,e2,e3])
+ EListish (LFrom e) -> tcExpr mt (enum loc "From" [e])
+ EListish (LFromTo e1 e2) -> tcExpr mt (enum loc "FromTo" [e1, e2])
+ EListish (LFromThen e1 e2) -> tcExpr mt (enum loc "FromThen" [e1,e2])
+ EListish (LFromThenTo e1 e2 e3) -> tcExpr mt (enum loc "FromThenTo" [e1,e2,e3])
ESign e t -> T.do
(tt, _) <- tcType (Just kType) t
(ee, _) <- tcExpr (Just tt) e
- munify (getSLocExpr ae) mt tt
+ munify loc mt tt
T.return (ee, tt)
EAt i e -> T.do
(ee, t) <- tcExpr mt e
(_, ti) <- tLookupInst "impossible!" i
- unify (getSLocExpr ae) t ti
+ unify loc t ti
T.return (EAt i ee, t)
EForall vks t ->
withVks vks kType $ \ vvks _ -> T.do
@@ -865,8 +869,8 @@
T.return (EForall vvks tt, k)
_ -> impossible
-enum :: String -> [Expr] -> Expr
-enum f = foldl EApp (EVar (mkIdent ("enum" ++ f)))+enum :: SLoc -> String -> [Expr] -> Expr
+enum loc f = foldl EApp (EVar (mkIdentSLoc loc ("enum" ++ f)))tcLit :: Maybe EType -> SLoc -> Lit -> T (Typed Expr)
tcLit mt loc l =
@@ -1057,7 +1061,7 @@
EApp f a -> EApp (dsType f) (dsType a)
EOper t ies -> EOper (dsType t) [(i, dsType e) | (i, e) <- ies]
EListish (LList [t]) -> tApp tList (dsType t)
- ETuple ts -> tApps (tupleConstr (length ts)) (map dsType ts)
+ ETuple ts -> tApps (tupleConstr (getSLocExpr at) (length ts)) (map dsType ts)
ESign t k -> ESign (dsType t) k
EForall iks t -> EForall iks (dsType t)
_ -> impossible
--
⑨