Fixes redundant hash in ghcide cache path (getCacheDirsDefault)#4854
Fixes redundant hash in ghcide cache path (getCacheDirsDefault)#4854fendor merged 5 commits intohaskell:masterfrom
Conversation
|
Hi, thank you for your PR. You give no reasoning or justification for your fix. I encourage you to think about it in more detail or to reach out with questions if you do not understand why the code is how it is right now. |
db2a6b5 to
fa2a354
Compare
|
Hi,thanks for the feedback. I'm pretty new to open source and this codebase, so I really appreciate the guidance. |
|
If you validate your PR against the cache dirs on your local system, do you think your patch would work? Fixing upstream is a far better solution than monkey patching in HLS, imo :) |
|
Ah , thanks I just realised that now , if the hashes are different it will be appended no matter what . |
|
Out of curiosity, how did you figure out this hash is appended by cabal or is a cabal hash? |
The screenshot you are sending never had any double hashes, the double hashes are only added when the unit id is Your reasoning seems very circular, are you saying, you assume it is a cabal hash, although it doesn't look like cabal generated uses this hash, but you have no better explanation than it being a cabal hash? The idea of stripping the last part of the hash is wrong. Both hashes are present for a reason. I updated the original issue description, which hopefully explains the solution in more detail, instead of simply stripping the last hash away. |
|
oh , i'm sorry , i meant to share this
You are totally right that my explanation was confusing , to clarify my thought process: I initially assumed it was Cabal adding the hash, but when I checked the dist-newstyle cache and verbose build logs, i realized Cabal wasn't generating it. I deduced the hash was being appended somewhere in between the build and ghcide, but since I did not go through the whole thing as i was fixated on shortening the path by stripping the last hash, I didn't know exactly where that was happening. Thank you for pointing me directly to those lines of code.
Understood, I will drop this idea of stripping the last part .
Thanks for the update. I see now the goal is to thread that original ByteString hash to getCacheDirsDefault and combine them into a single hash. |
7e001d5 to
5901a7b
Compare
|
Thank you, this looks much better now. I kind of still dislike the tuple, what do you say to replacing the tuple you modified into a proper datatype? What do you think about this? Referring to this tuple in particular: A potential name could be something again Also, please make sure you use the whitespace consistently, like adding a space after a comma in tuples, e.g. Afterwards, I think this is ready to merge :) Note, you will also have to rebase this PR, as we have merged a quite a number of changes to |
|
Hi, thanks for the heads-up, I see all the hashing logic was moved to Ghc.hs , I agree to use a datatype named |
fe503b8 to
cb74d59
Compare
|
Hey @fendor, |
fendor
left a comment
There was a problem hiding this comment.
LGTM, thank you!
Only small documentation issues and nitpicks!
Also, one more rebase, please!
| , sessionLoadingOptions = newSessionLoadingOptions | ||
| } | ||
|
|
||
|
|
| toFlagsMap TargetDetails{..} = | ||
| [ (l, (targetEnv, targetDepends)) | l <- targetLocations] | ||
|
|
||
|
|
|
|
||
| -- | Mapping from @hie.yaml@ to all components that have been loaded | ||
| -- from this @hie.yaml@ location. | ||
|
|
| return (Map.insert k res mp, res) | ||
| Just res -> return (mp, res) | ||
|
|
||
|
|
| getCacheDirsDefault :: String -> Maybe B.ByteString -> [String] -> IO CacheDirs | ||
| getCacheDirsDefault prefix mFirstHash opts = do |
There was a problem hiding this comment.
As this function got more complicated, let's give it some proper haddock docs!
| -- | Maps cradle dependencies, such as `stack.yaml`, or `.cabal` file | ||
| -- to last modification time. See Note [Multi Cradle Dependency Info]. | ||
| , rawComponentDependencyInfo :: DependencyInfo | ||
| -- | The raw ByteString for the hash generated in setoptions for the uid "main" |
There was a problem hiding this comment.
| -- | The raw ByteString for the hash generated in setoptions for the uid "main" | |
| -- | An optional hash seed generated in 'setOptions' for the unit id "main". |
If you quote function names and definitions like this, then they are linked in HLS, and you can even gotoDefinition for setOptions in the docs.
| import qualified Data.Map.Strict as Map | ||
| import Data.Maybe | ||
| import Data.Proxy | ||
|
|
…ted hashBytes inside the monadic tuple (earlier, it was only returning the flags and the target). * To thread this down, I added a new rawComponentHash field as a Maybe B.ByteString to the RawComponentInfo data type. This passes the hash from setOptions straight into getCacheDirsDefault. * Inside getCacheDirsDefault, I added a check: * If we have Just mFirstHash, I set the prefix to 'main'. Then, I initiate a new hash and update it with mFirstHash using H.updates, storing this mutated context as baseCtx. * If it's Nothing, baseCtx just gets a standard H.init. * Finally, for opts_hash, it takes that baseCtx and updates it with the opts string (converted via B.pack). This gives out the final 40-character hex string for the SHA1 hash. (Also updated getCacheDirs in the session loading to accept the ByteString). This keeps the path short and stops Windows from crashing
…o Ghc.hs after rebase ,also updated the getDirsDefault to handel the Maybe B.ByteString in Session.hs
…o Ghc.hs after rebase ,also updated the getDirsDefault to handel the Maybe B.ByteString in Session.hs
cb74d59 to
31d55e2
Compare
31d55e2 to
c61dc27
Compare
Co-authored-by: fendor <fendor@users.noreply.github.com>
|
One of the checks is failing , can you please re run that |




Fixes #4843