Repository navigation
Use object code for Template Haskell - #836
Conversation
|
OK, I figured out the issue ( |
|
ghc-lib :( I have no idea how to locally build this configuration, and worse still, no tests run so I have no way to know if my changes work. |
|
It would be cool to see the performance improvements of this change, but for that we need a benchmark example that uses TH (and doesn't have too many dependencies). EDIT: see #838, now you only need to find a suitable example (the hard part) |
pepeiborra
left a comment
There was a problem hiding this comment.
CI benchmarks look rather useless. Can you run cabal bench locally and share the results?
|
|
||
| generateObjectCode :: HscEnv -> TcModuleResult -> IO (IdeResult Linkable) | ||
| generateObjectCode hscEnv tmr = do | ||
| (compile_diags, Just (_, guts, _)) <- compileModule (RunSimplifier True) hscEnv tmr |
There was a problem hiding this comment.
Can we avoid compiling the module here? I think the answer is not, because GenerateCore is not used anymore
| catchSrcErrors "compile" $ do | ||
| setupEnv (deps ++ [(tmrModSummary tmr, tmrModInfo tmr)]) | ||
|
|
||
| setupEnv [(tmrModSummary tmr, tmrModInfo tmr)] |
There was a problem hiding this comment.
surprised that we don't need to setup the env with the dependencies
There was a problem hiding this comment.
I've looked for every usage of this and made sure it is only called with GhcSessionDeps. In that case I don't think we need to call setupEnv
| setPriority priorityGenerateCore | ||
| packageState <- hscEnv <$> use_ GhcSession file | ||
| liftIO $ compileModule runSimplifier packageState [(tmrModSummary x, tmrModInfo x) | x <- tms] tm | ||
| liftIO $ compileModule runSimplifier packageState tm |
There was a problem hiding this comment.
surprised that this can work with GhcSession and doesn't need GhcSessionDeps
Possibly dumb question, but: we need object code for a module's dependencies if the module uses TH. This PR achieves that by checking a module's dependants to see if they'll eventually use TH. But couldn't we just set up rules for computing the object code and only request it if we need it? i.e.
Isn't this the joy of building our IDE on a build system? I haven't understood the code in detail, but it looks like you're sort of doing that already. So what stops this becoming entirely demand-driven? |
Good question. This is indeed what we were doing before, with the To compile a module, we need the actual typechecked AST that ghc computes after typechecking. However, to avoid excessive memory usage, we only keep typechecked ASTs for files that the user has open in their editor. For all other modules, we compute a This is no good for when we need to compile object/byte code for a module. Previously, we were calling the Now, we figure out if we are going to need the object code before we throw away the typechecked AST, restoring the invariant that we only keep typechecked ASTs in memory for files the user has opened. Furthermore, we avoid duplicating work caused by needing to typecheck the same file twice. |
|
There are a bunch of options here we can expose to the user -
For 1) and 2), I imagine we want to set a default based on some benchmarks. |
|
Interesting, this is potentially a usecase for Core Interface Sections, something we've been working on at IOHK. The idea being that you dump the post-desugaring Core into the interface file, and ideally you should then be able to resume compilation from that step. So you'd be able to do the Typecheck->ObjectCode step later without redoing work. (Speculative, obviously) |
My views:
|
|
I thought bytecode was serialised for the external interpreter? |
1b7ea9f to
4d57c12
Compare
|
I think I have found the root cause of the bug that #741 fixed. We call If we want to generate code, we need to use For now, I've changed Also, @mpickering says we always need to run the simplifier, as discussed in #410. We do set |
|
The way to run it at a lower priority is to do: That says start with desugaring, but once you have type checked, put yourself to the back of the queue behind all other type checks. |
|
@ndmitchell what happens if a rule with high priority |
|
The rule with high priority will wait for the low priority one to finish - you get priority inversion - so its generally not a good thing to do (although its not that harmful, unless you have a lot of normal priority stuff waiting around) |
|
I'm a bit confused about the meaning of priorities. We have the following in newtype Priority = Priority Double
setPriority :: Priority -> Action ()
setPriority (Priority p) = reschedule p
priorityTypeCheck :: Priority
priorityTypeCheck = Priority 0
priorityGenerateCore :: Priority
priorityGenerateCore = Priority (-1)
priorityFilesOfInterest :: Priority
priorityFilesOfInterest = Priority (-2)Which one of these will be given preference by the scheduler? Reading the reschedule x = do
(wait, _) <- actionAlwaysRequeuePriority (PoolDeprioritize $ negate x) $ pure ()Too many negations for me to follow 😕 |
|
Getting some strange failures when I add desugaring to kick ¯\_(ツ)_/¯ First one is particularly spooky. Otherwise, I think this is ready after a re-review. |
|
This looks fantastic, great job @wz1000, hopefully fixing all the TH bugs in the process. I will find the time to re-review tomorrow evening. In the meantime:
|
|
The changes to the shake graph are as follows:
Benchmarks and fixing the remaining tests are next on my agenda. I'm still conflicted about whether we need to keep the result of |
|
I'm using the following configuration for benchmarking: example:
name: haskell-lsp-types
version: 0.22.0.0
# # path: path/to/example
module: src/Language/Haskell/LSP/Types/Lens.hsHere are the results: version name success samples startup setup userTime delayedTime totalTime maxResidency allocatedBytes
upstream hover True 100 10.614806232000001 0.0 0.10257583399999999 3.340193600000001e-2 0.14050068000000002 319777184 6115153688
HEAD hover True 100 7.7185963520000005 0.0 0.45777121499999973 3.5779573e-2 0.497748911 164670560 2716464040
upstream edit True 100 9.299547219 0.0 27.364207991 0.20843280399999992 27.578036549 339209832 47839423136
HEAD edit True 100 8.063393366 0.0 38.008773957999985 0.6213196139999998 38.635416729 166595120 68167264816
upstream getDefinition True 100 9.299885888 0.0 6.3038403e-2 2.0231722999999993e-2 8.6907673e-2 320671832 6090475128
HEAD getDefinition True 100 8.01779254 0.0 7.801578100000002e-2 0.39756615800000006 0.479599582 164391728 2692337384
upstream hover after edit True 100 9.569584439 0.0 0.649604651 27.137278584000008 27.792731983000003 333945152 55002822280
HEAD hover after edit True 100 7.8474618430000005 0.0 1.2949229160000006 76.95365204099998 78.255706743 175195272 135863207032
upstream completions after edit True 100 9.292151514 0.0 6.870972618000005 21.154938894000004 28.032305479 339928928 69540079968
HEAD completions after edit True 100 8.354598959 0.0 7.296952549000002 22.032134922999994 29.337312232000002 177797184 65961116000
upstream code actions True 100 9.418781461 0.7522214460000001 0.6891327480000001 4.1814197000000004e-2 0.737375199 365674056 8408618680
HEAD code actions True 100 8.478195708000001 0.8031139460000001 0.9741454130000003 0.28154403900000013 1.262175481 222930536 5155011264
upstream code actions after edit True 100 9.205042200000001 0.0 65.97669554199999 3.9817547000000016e-2 66.02095223 388161080 126965911240
HEAD code actions after edit True 100 8.362657242000001 0.0 73.54964010300002 0.4446636240000001 74.000585133 245196664 116454301472
upstream documentSymbols after edit True 100 9.106493854 0.0 0.4217413190000001 0.5491246350000001 0.977217133 328066504 8863760416
HEAD documentSymbols after edit True 100 10.102078910000001 0.0 0.4835813629999999 1.193969614000001 1.6880487540000002 165829184 6147453776User time and total time increase, max residency is halved. |
|
Here are the results if we don't desugar and just typecheck diff --git a/src/Development/IDE/Core/OfInterest.hs b/src/Development/IDE/Core/OfInterest.hs
index 1caacfc3..dda25030 100644
--- a/src/Development/IDE/Core/OfInterest.hs
+++ b/src/Development/IDE/Core/OfInterest.hs
@@ -94,10 +94,10 @@ kick = mkDelayedAction "kick" Debug $ do
liftIO $ progressUpdate KickStarted
-- Update the exports map for the project
- results <- uses GenerateCore $ HashMap.keys files
+ results <- uses TypeCheck $ HashMap.keys files
ShakeExtras{exportsMap} <- getShakeExtras
let mguts = catMaybes results
- !exportsMap' = createExportsMapMg mguts
+ !exportsMap' = createExportsMapTc $ map tmrTypechecked mguts
liftIO $ modifyVar_ exportsMap $ evaluate . (exportsMap' <>) |
|
If we use bytecode instead of object code, and don't desugar in kick, here is what we get: Something is clearly going wrong somewhere, or we would expect similar performance to upstream |
|
Thank you so much! This is great! |
…l/ghcide#836) * Use object code for TH * Set target location for TargetFiles * Fix tests * hlint * fix build on 8.10 * fix ghc-lib * address review comments * hlint * better error handling if module headers don't parse * Always desugar, don't call interactive API functions * deprioritize desugar when not TH, fix iface handling * write hie file on save * more tweaks * fix tests * disable desugarer warnings * use ModGuts for exports map * don't desugar * use bytecode * make HiFileStable early-cutoff * restore object code * re-enable desugar * review comments * Don't use ModIface for DocMap * fix docs for the current module * mark test as broken on windows
…l/ghcide#836) * Use object code for TH * Set target location for TargetFiles * Fix tests * hlint * fix build on 8.10 * fix ghc-lib * address review comments * hlint * better error handling if module headers don't parse * Always desugar, don't call interactive API functions * deprioritize desugar when not TH, fix iface handling * write hie file on save * more tweaks * fix tests * disable desugarer warnings * use ModGuts for exports map * don't desugar * use bytecode * make HiFileStable early-cutoff * restore object code * re-enable desugar * review comments * Don't use ModIface for DocMap * fix docs for the current module * mark test as broken on windows
…l/ghcide#836) * Use object code for TH * Set target location for TargetFiles * Fix tests * hlint * fix build on 8.10 * fix ghc-lib * address review comments * hlint * better error handling if module headers don't parse * Always desugar, don't call interactive API functions * deprioritize desugar when not TH, fix iface handling * write hie file on save * more tweaks * fix tests * disable desugarer warnings * use ModGuts for exports map * don't desugar * use bytecode * make HiFileStable early-cutoff * restore object code * re-enable desugar * review comments * Don't use ModIface for DocMap * fix docs for the current module * mark test as broken on windows
Rework of mpickering#43
Should improve performance and also functions as a workaround for #614
We now generate object code along with the interface file. Object code is only generated for a module if
For this to work, we require the complete module graph. Earlier, tests were failing because
TargetFile's were not included in the set of known files. I fixed this, but now tests are failing because the modules don't define amainfunction. Any idea why this is happening @pepeiborra? See my last commit.FIxes #614
Fixes #107