Skip to content

Commit 141a713

Browse files
committed
Tweaks in progress. Waiting for conversion to GHC 10.7.3 and HERMIT 1.0.0.1
1 parent 877d1fa commit 141a713

File tree

4 files changed

+49
-41
lines changed

4 files changed

+49
-41
lines changed

src/LambdaCCC/Monomorphize.hs

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -178,19 +178,29 @@ specializeTyDict' =
178178
-- const $ all isTyOrDict
179179
#endif
180180

181+
unTypeMb :: CoreExpr -> Maybe Type
182+
unTypeMb (Type ty) = Just ty
183+
unTypeMb _ = Nothing
184+
181185
specializeTyDict :: ReExpr
182186
specializeTyDict = watchR "specializeTyDict" $
183187
tryR simplifyAll
184188
. unfoldPredR okay
185189
. rejectR (dictResultTy . exprType')
186190
. rejectR isType
187191
where
188-
okay v [Type ty] = not (isPrimOrRepMeth v ty)
192+
-- Arguments are all types, and function/method is not a prim or repr/abst.
193+
okay v (mapM unTypeMb -> Just tys) = isGlobalId v && -- EXPERIMENTAL. See below.
194+
not (isPrimOrRepMeth v tys)
195+
-- okay v [Type ty] = not (isPrimOrRepMeth v [ty])
189196
-- not (isRepMeth v || (isPrimitiveOp v && isPrimitiveTy ty))
190197
-- what's this one for? If I use it, take care with repr/abst
191198
-- okay v [] = isGlobalId v
192199
okay _ _ = False
193200

201+
-- TODO: revisit the isGlobalId test. I don't think it's really what I'm looking
202+
-- for. Sometimes GHC moves code out of the 'reifyEP' call but still local.
203+
-- Also, what about local polymorphic definitions?
194204

195205
#if 1
196206
dictResultTy :: Type -> Bool
@@ -372,9 +382,13 @@ letFloatArgNoDelayR = unlessM (isDelayLet <$> id) letFloatArgR
372382
caseDefaultR :: ReExpr
373383
caseDefaultR =
374384
do Case scrut wild _ [(_,[],body)] <- id
375-
return $ case idOccInfo wild of
376-
IAmDead -> body
377-
_ -> Let (NonRec wild scrut) body
385+
case idOccInfo wild of
386+
IAmDead -> return body
387+
_ ->
388+
-- do guardMsg (not (isUnLiftedType (exprType scrut)))
389+
-- "caseDefaultR: unlifted type"
390+
return (Let (NonRec wild scrut) body)
391+
378392

379393
retypeProgR :: ReProg
380394
retypeProgR = progRhsAnyR ({-bracketR "retypeExprR"-} retypeExprR)

src/LambdaCCC/ReifySimple.hs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,13 @@ unEval = unCallE1 evalS
134134
reifyEval :: ReExpr
135135
reifyEval = unReify >>> unEval
136136

137+
-- Generate a reify call. Fail on dictionaries.
137138
reifyOf :: CoreExpr -> TransformU CoreExpr
138-
reifyOf e = appsE reifyS [exprType' e] [e]
139+
reifyOf e = do guardMsg (not (isDictTy (exprType' e)))
140+
"reifyOf: Given a type expr."
141+
appsE reifyS [exprType' e] [e]
142+
143+
-- reifyOf e = appsE reifyS [exprType' e] [e]
139144

140145
evalOf :: CoreExpr -> TransformU CoreExpr
141146
evalOf e = appsE evalS [dropEP (exprType' e)] [e]
@@ -467,9 +472,9 @@ isPrimitiveName name =
467472
|| name `M.member` stdMeths
468473
-- || isRepMeth name
469474

470-
isPrimOrRepMeth :: Var -> Type -> Bool
471-
isPrimOrRepMeth (fqVarName -> name) ty =
472-
isRepMeth name || (isPrimitiveName name && isPrimitiveTy ty)
475+
isPrimOrRepMeth :: Var -> [Type] -> Bool
476+
isPrimOrRepMeth (fqVarName -> name) tys =
477+
isRepMeth name || (isPrimitiveName name && all isPrimitiveTy tys)
473478

474479
isPrimitiveOp :: Var -> Bool
475480
isPrimitiveOp (fqVarName -> name) =

test/DoTreeNoReify.hss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ set-pp-coercion Kind
1010

1111
binding-of 'main
1212
-- Marked INLINE in LambdaCCC.Run, but still needs explicit unfolding here:
13-
try (any-td (unfold ['go,'go','goM,'goM','goMSep,'reifyMealy,'goNew,'goNew']))
13+
try (any-td (unfold ['go,'go','goSep,'goM,'goM','goMSep,'reifyMealy,'goNew,'goNew']))
1414
down ; try simplifyAll' ; up
1515

1616
-- Necessary??

test/TreeTest.hs

Lines changed: 21 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -307,48 +307,37 @@ do2 = inTest "hermit TreeTest.hs -v0 -opt=LambdaCCC.Monomorphize DoTree.hss"
307307
-- Only works when compiled with HERMIT
308308
main :: IO ()
309309

310-
#if 0
311-
-------- Dave's FFT stuff ----------------------------------------------
312-
-- Phasor, as a function of tree depth.
313-
phasor :: (IsNat n, RealFloat a, Enum a) => Nat n -> RTree n (Complex a)
314-
phasor n = scanlTEx (*) 1 (pure phaseDelta)
315-
where phaseDelta = cis ((-pi) / 2 ** natToZ n)
316-
317-
-- Radix-2, DIT FFT
318-
fft_r2_dit :: (IsNat n, RealFloat a, Enum a) => RTree n (Complex a) -> RTree n (Complex a)
319-
fft_r2_dit = fft_r2_dit' nat
320-
321-
fft_r2_dit' :: (RealFloat a, Enum a) => Nat n -> RTree n (Complex a) -> RTree n (Complex a)
322-
fft_r2_dit' Zero = id
323-
fft_r2_dit' (Succ n) = RT.toB . P.inP (uncurry (+) &&& uncurry (-)) . P.secondP (liftA2 (*) (phasor n)) . fmap (fft_r2_dit' n) . RT.bottomSplit
324-
325-
-- main = go "fft_r2_dit" (fft_r2_dit :: RTree N1 (Complex Int) -> RTree N1 (Complex Int))
326-
-- main = go "fft_r2_dit" (fft_r2_dit :: RTree N2 (Complex Double) -> RTree N2 (Complex Double))
327-
-- main = go "fft_r2_dit" (fft_r2_dit :: RTree N1 (Complex PrettyDouble) -> RTree N1 (Complex PrettyDouble))
328-
-- main = go "fft_r2_dit" (fft_r2_dit :: RTree N2 (Complex Int) -> RTree N2 (Complex Int))
329-
-- main = goSep "fft_r2_dit" 1 (fft_r2_dit :: RTree N1 (Complex Int) -> RTree N1 (Complex Int))
330-
-------- End Dave's FFT stuff ------------------------------------------
331-
#else
310+
---- FFT
332311

333312
type C = Complex Double
334313

335314
-- main = go "foo" ()
336315

337316
-- main = go "fft-p" (fft :: Unop (Pair C))
338317

339-
-- main = go "fft-lt0" (fft :: LTree N0 C -> RTree N0 C)
340-
341-
-- main = go "fft-lt2" (fft :: LTree N2 C -> RTree N2 C)
318+
-- main = go "fft-lt1" (fft :: LTree N1 C -> RTree N1 C)
342319

343320
-- main = go "fft-rt1" (fft :: RTree N1 C -> LTree N1 C)
344321

345322
-- twiddles :: forall g f a. (AFS g, AFS f, RealFloat a) => g (f (Complex a))
346323

347-
-- main = go "twiddles-rt1p" (twiddles :: RTree N1 (Pair C))
324+
-- main = go "twiddles-lt1p" (twiddles :: LTree N1 (Pair C))
325+
326+
-- main = go "foo" (omega (size (undefined :: (LTree N1 :. Pair) ())))
327+
328+
-- twiddles :: forall g f a. (AFS g, AFS f, RealFloat a) => g (f (Complex a))
329+
-- twiddles = powers <$> powers (omega (tySize(g :. f)))
348330

349-
main = go "foo" (size (undefined :: RTree N1 ()))
331+
main = go "foo" (powers :: Int -> LTree N1 Int)
350332

351-
-- main = go "foo" (size (undefined :: (RTree N1 :. Pair) ()))
333+
-- zoop :: Int
334+
-- zoop = 3
335+
336+
-- main = go "foo" zoop
337+
338+
-- main = go "foo" (size (undefined :: RTree N3 ()))
339+
340+
-- main = go "foo" (size (undefined :: (LTree N3 :. Pair) ()))
352341

353342
-- main = go "foo" (size (undefined :: Pair ()))
354343

@@ -377,13 +366,13 @@ main = go "foo" (size (undefined :: RTree N1 ()))
377366

378367
-- main = go "foo" (exp :: Double -> Double)
379368

380-
#endif
369+
---- End FFT
381370

382371
-- main = go "map-not-v5" (fmap not :: Vec N5 Bool -> Vec N5 Bool)
383372

384373
-- main = go "map-square-v5" (fmap square :: Vec N5 Int -> Vec N5 Int)
385374

386-
-- main = go "map-t3" (fmap not :: Unop (RTree N3 Bool))
375+
-- main = go "map-rt3" (fmap not :: Unop (RTree N3 Bool))
387376

388377
-- main = go "tdott-2" (dot''' :: Pair (RTree N2 Int) -> Int)
389378

@@ -439,10 +428,10 @@ main = go "foo" (size (undefined :: RTree N1 ()))
439428
-- main = go "test" (dot :: RTree N4 (Int,Int) -> Int)
440429

441430
-- -- Ranksep: rt1=0.5, rt2=1, rt3=2, rt4=4,rt5=8
442-
-- main = goSep "transpose-pt4" 4 (transpose :: Pair (RTree N4 Bool) -> RTree N4 (Pair Bool))
431+
-- main = goSep "transpose-prt4" 4 (transpose :: Pair (RTree N4 Bool) -> RTree N4 (Pair Bool))
443432

444433
-- -- Ranksep: rt1=0.5, rt2=1, rt3=2, rt4=4,rt5=8
445-
-- main = goSep "transpose-t4p" 4 (transpose :: RTree N4 (Pair Bool) -> Pair (RTree N4 Bool))
434+
-- main = goSep "transpose-rt2p" 1 (transpose :: RTree N2 (Pair Bool) -> Pair (RTree N2 Bool))
446435

447436
-- -- Ranksep: rt1=1, rt2=2, rt3=4, rt4=8, rt5=16
448437
-- main = goSep "transpose-v3t5" 16 (transpose :: Vec N3 (RTree N5 Bool) -> RTree N5 (Vec N3 Bool))

0 commit comments

Comments
 (0)