on master help sign in
More sensible hash function for specialised names
16f7dd7Edwin Brady
src/Idris/Elab/Clause.hs+13−7
@@ -409,18 +409,24 @@ elabPE info fc caller r =
409 -- get the clause of a specialised application
409 -- get the clause of a specialised application
410 getSpecClause ist (n, args)
410 getSpecClause ist (n, args)
411 = let newnm = sUN ("PE_" ++ show (nsroot n) ++ "_" ++
411 = let newnm = sUN ("PE_" ++ show (nsroot n) ++ "_" ++
412− qhash 0 (showSep "_" (map showArg args))) in
412+ qhash 5381 (showSep "_" (map showArg args))) in
413 -- UN (show n ++ show (map snd args)) in
413 -- UN (show n ++ show (map snd args)) in
414 (n, newnm, mkPE_TermDecl ist newnm n args)
414 (n, newnm, mkPE_TermDecl ist newnm n args)
415− where showArg (ExplicitS, n) = show n
415+ where showArg (ExplicitS, n) = qshow n
416− showArg (ImplicitS, n) = show n
416+ showArg (ImplicitS, n) = qshow n
417 showArg _ = ""
417 showArg _ = ""
418
418
419− -- TMP for readability! This is obviously a really bad hashing
419+ qshow (Bind _ _ _) = "fn"
420− -- function.
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
421 qhash :: Int -> String -> String
427 qhash :: Int -> String -> String
422− qhash acc [] = showHex acc ""
428+ qhash hash [] = showHex (abs hash `mod` 0xffffffff) ""
423− qhash acc (x:xs) = qhash (fromEnum x + acc) xs
429+ qhash hash (x:xs) = qhash (hash * 33 + fromEnum x) xs
424
430
425-- checks if the clause is a possible left hand side. Returns the term if
431-- checks if the clause is a possible left hand side. Returns the term if
426-- possible, otherwise Nothing.
432-- possible, otherwise Nothing.