on master help sign in
Merge pull request #1679 from edwinb/partial-eval

Partial evaluation improvements

commitf8a67462f205e0e014e9c3406756a06bdacd863e authorEdwin Brady <edwin.brady@gmail.com> dateMon 27 Oct 2014, 09:52 (12 years ago) parente380d0c31fef0d
2 files changed+14−8
src/Idris/Elab/Clause.hs+13−7 src/Idris/Transforms.hs+1−1
src/Idris/Elab/Clause.hs+13−7
@@ -409,18 +409,24 @@ elabPE info fc caller r =
409409 -- get the clause of a specialised application
410410 getSpecClause ist (n, args)
411411 = let newnm = sUN ("PE_" ++ show (nsroot n) ++ "_" ++
412− qhash 0 (showSep "_" (map showArg args))) in
412+ qhash 5381 (showSep "_" (map showArg args))) in
413413 -- UN (show n ++ show (map snd args)) in
414414 (n, newnm, mkPE_TermDecl ist newnm n args)
415− where showArg (ExplicitS, n) = show n
416− showArg (ImplicitS, n) = show n
415+ where showArg (ExplicitS, n) = qshow n
416+ showArg (ImplicitS, n) = qshow n
417417 showArg _ = ""
418418
419− -- TMP for readability! This is obviously a really bad hashing
420− -- function.
419+ qshow (Bind _ _ _) = "fn"
420+ qshow (App f a) = qshow f ++ qshow a
421+ qshow (P _ n _) = show n
422+ qshow (Constant c) = show c
423+ qshow _ = ""
424+
425+ -- Simple but effective string hashing...
426+ -- Keep it to 32 bits for readability/debuggability
421427 qhash :: Int -> String -> String
422− qhash acc [] = showHex acc ""
423− qhash acc (x:xs) = qhash (fromEnum x + acc) xs
428+ qhash hash [] = showHex (abs hash `mod` 0xffffffff) ""
429+ qhash hash (x:xs) = qhash (hash * 33 + fromEnum x) xs
424430
425431-- checks if the clause is a possible left hand side. Returns the term if
426432-- possible, otherwise Nothing.
src/Idris/Transforms.hs+1−1
@@ -93,7 +93,7 @@ matchTerm lhs tm = matchVars [] lhs tm
9393 = do fm <- doMatch ns f f'
9494 am <- doMatch ns a a'
9595 return (fm ++ am)
96− doMatch ns x y | x == y = return []
96+ doMatch ns x y | vToP x == vToP y = return []
9797 | otherwise = Nothing
9898
9999