History

Add transformation rules for top level methods

This can be quite effective at removing runtime overhead when just using an overloaded method directly. It is, however, still quite limited (only works on top level interfaces, so no inlining of parents, e.g. like X a => X (List a), and sometimes generating the transform rules fails for reasons I haven't worked out yet). This is experimental, I might change the way this works at any point, but it's a nice improvement for now.

Edwin Brady committed 6 years ago

Commit b617cae1 parent 11cbc303 files · +30 −6Browse files

Unified · Split

3 files
  1. libs/prelude/Prelude.idr +0 −1
  2. src/Core/Transform.idr +1 −2
  3. src/Idris/Elab/Implementation.idr +29 −3
libs/prelude/Prelude.idr+0−1
@@ -1416,7 +1416,6 @@ Applicative IO where · 1415 unmodified lines
14161416 io_bind a (\a' =>
14171417 io_pure (f' a')))
14181418
1419−%inline
14201419 public export
14211420 Monad IO where
14221421 b >>= k = io_bind b k
src/Core/Transform.idr+1−2
@@ -108,8 +108,7 @@ trans env stk (Ref fc Func fn) · 107 unmodified lines
108108 = do defs <- get Ctxt
109109 case lookup fn (transforms defs) of
110110 Nothing => pure (unload stk (Ref fc Func fn))
111− Just ts => do fullapp <- normaliseHoles defs env
112− (unload stk (Ref fc Func fn))
111+ Just ts => do let fullapp = unload stk (Ref fc Func fn)
113112 let (u, tm') = apply ts fullapp
114113 upd <- get Upd
115114 put Upd (upd || u)
src/Idris/Elab/Implementation.idr+29−3
@@ -217,10 +217,14 @@ elabImplementation {vars} fc vis opts_in pass env nest is cons iname ps impln nu · 216 unmodified lines
217217 -- case of dependencies)
218218
219219 -- 5. Elaborate the method bodies
220−
221− body' <- traverse (updateBody (map methNameUpdate fns)) body
220+ let upds = map methNameUpdate fns
221+ body' <- traverse (updateBody upds) body
222222 log 10 $ "Implementation body: " ++ show body'
223223 traverse (processDecl [] nest env) body'
224+
225+ -- 6. Add transnformation rules for top level methods
226+ traverse (addTransform impName upds) (methods cdata)
227+
224228 -- Reset the open hints (remove the named implementation)
225229 setOpenHints hs
226230 pure ()) mbody
@@ -283,7 +287,8 @@ elabImplementation {vars} fc vis opts_in pass env nest is cons iname ps impln nu · 56 unmodified lines
283287 methName : Name -> Name
284288 methName (NS _ n) = methName n
285289 methName n
286− = DN (show n) (UN (show n ++ "_" ++ show iname ++ "_" ++
290+ = DN (show n)
291+ (UN (show n ++ "_" ++ show iname ++ "_" ++
287292 maybe "" show impln ++ "_" ++
288293 showSep "_" (map show ps)))
289294
@@ -404,3 +409,24 @@ elabImplementation {vars} fc vis opts_in pass env nest is cons iname ps impln nu · 114 unmodified lines
404409 updateBody ns _
405410 = throw (GenericMsg fc
406411 "Implementation body can only contain definitions")
412+
413+ addTransform : Name -> List (Name, Name) ->
414+ (Name, RigCount, Bool, RawImp) ->
415+ Core ()
416+ addTransform iname ns (top, _, _, ty)
417+ = do log 3 $ "Adding transform for " ++ show top ++ " : " ++ show ty ++
418+ "\n\tfor " ++ show iname ++ " in " ++ show ns
419+ let lhs = IImplicitApp fc (IVar fc top)
420+ (Just (UN "__con"))
421+ (IVar fc iname)
422+ let Just mname = lookup (dropNS top) ns
423+ | Nothing => pure ()
424+ let rhs = IVar fc mname
425+ log 5 $ show lhs ++ " ==> " ++ show rhs
426+ handleUnify
427+ (processDecl [] nest env
428+ (ITransform fc (UN (show top ++ " " ++ show iname)) lhs rhs))
429+ (\err =>
430+ log 5 $ "Can't add transform " ++
431+ show lhs ++ " ==> " ++ show rhs ++
432+ "\n\t" ++ show err)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t