Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid unnecessary Target canonicalisation in Session setup #2359

Merged
merged 13 commits into from Nov 29, 2021

Conversation

fendor
Copy link
Collaborator

@fendor fendor commented Nov 16, 2021

Closes #2358

In particular, this test checks whether modules that are actually
symbolic lins can be found by ghcide.
This is known to be broken, as Session.hs canonicalises Targets, e.g.
saves the location of the symbolic link. When we later try to load that
module, we can't find it, as it won't be part of the known targets since
it is not canonicalized.
Canonicalising Targets makes it harder later to actually find the
targets during import analysis, as ghcide only looks for modules in the
import paths and checks for existence in the known target Map.

However, import analysis doesn't canonicalise target candidates, thus
the lookup in the known target Map will always fail.

We no longer canonicalise Targets, so import analysis will succeed
loading modules that are actually symbolic links.
return [TargetDetails (TargetModule mod) env dep locs]
-- For a 'TargetFile' we consider all the possible module names
fromTargetId _ _ (GHC.TargetFile f _) env deps = do
nf <- toNormalizedFilePath' <$> canonicalizePath f
let nf = toNormalizedFilePath' f
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let nf = toNormalizedFilePath' f
nf <- toNormalizedFilePath' <$> makeAbsolute f

This might be better to make sure the paths are absolute but let's see what CI says

@pepeiborra
Copy link
Collaborator

Did you check the git history to make sure we are not missing anything? This seems like a risky change

@fendor
Copy link
Collaborator Author

fendor commented Nov 16, 2021

The canonicalisation seems to be from the first implementation done by mpickering. One of the earliest commits I can find in this repository is f1b36ba#diff-d7140bbfca1b7aaafd8c82d1d6aa21a3f941eb27ba8f08e4d9fb13766b21b418R316

I think this was mainly done to avoid possible issues with relative and absolute paths. In hie-bios we had similar issues with symbolic links due to the use of canonicalizePath. We gradually replaced every occurrence of that with makeAbsolute.

Alternatively, if you feel uncomfortable with this solution, we can canonicalize the candidates of the imports at https://github.com/haskell/haskell-language-server/blob/master/ghcide/src/Development/IDE/Import/FindImports.hs#L71
This way this issue is also resolved.
However, I feel like patching it in FindImports is the worse solution, as NormalizedFilePath does currently not guarantee that file paths are canonicalised, so canonicalising in seemingly arbitrary places feels like a plaster.

@fendor
Copy link
Collaborator Author

fendor commented Nov 16, 2021

After looking some more around, I found:

-- Canonicalize import paths since we also canonicalize targets
which we need to patch as well for the same reasons.

Any other occurrence of canonicalizePath is either in tests, not in a relevant code-path (e.g. Main.hs debug loading) or in a plugin. Notably, in the module-name plugin, which we almost definitely have to patch as well to use makeAbsolute.

I think we should use makeAbsolute everywhere in most places in ghcide instead of canonicalizePath.

@fendor
Copy link
Collaborator Author

fendor commented Nov 17, 2021

I am weirded out that this commit fixed anything

@fendor
Copy link
Collaborator Author

fendor commented Nov 17, 2021

@jneira are windows tests flaky?

@jneira
Copy link
Member

jneira commented Nov 17, 2021

@jneira are windows tests flaky?

always 😆

a little bit more flaky than ubuntu/macos ones

@jneira
Copy link
Member

jneira commented Nov 17, 2021

@jneira are windows tests flaky?

always laughing

a little bit more flaky than ubuntu/macos ones

Lately ghcide tests are more flaky in ubuntu 🤔

@fendor
Copy link
Collaborator Author

fendor commented Nov 17, 2021

This is weird. CI is apparently slightly flaky. I am not fully on-board with changes from b790142 as I did not check thoroughly what they influence. Should we just ignore it, or should I revert this commit since I didnt check it?

@jneira
Copy link
Member

jneira commented Nov 17, 2021

This is weird. CI is apparently slightly flaky. I am not fully on-board with changes from b790142 as I did not check thoroughly what they influence. Should we just ignore it, or should I revert this commit since I didnt check it?

makeAbsolute does a normalisation? or it keeps . and .. f.e.? (one of the call sites talk about remove ..)

@fendor fendor mentioned this pull request Nov 17, 2021
Copy link
Member

@jneira jneira left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, it includes the appropiate regression test and ci is green. Great work as usual.

I would wait to next release to dogfooding it if you dont mind

Would like to know @pepeiborra thoughts though

@jneira jneira added the merge me Label to trigger pull request merge label Nov 18, 2021
@jneira jneira removed the merge me Label to trigger pull request merge label Nov 22, 2021
@jneira
Copy link
Member

jneira commented Nov 22, 2021

we will need a new release with the fixes for the early bugs found in 1.5.0, will merge afterwards

@jneira jneira added merge me Label to trigger pull request merge and removed merge me Label to trigger pull request merge labels Nov 28, 2021
@jneira jneira added the merge me Label to trigger pull request merge label Nov 29, 2021
@mergify mergify bot merged commit 00d08b8 into haskell:master Nov 29, 2021
drsooch pushed a commit to drsooch/haskell-language-server that referenced this pull request Dec 3, 2021
)

* Add test-case for projects that use symbolic links

In particular, this test checks whether modules that are actually
symbolic lins can be found by ghcide.
This is known to be broken, as Session.hs canonicalises Targets, e.g.
saves the location of the symbolic link. When we later try to load that
module, we can't find it, as it won't be part of the known targets since
it is not canonicalized.

* Dont canonicalise Targets during session setup

Canonicalising Targets makes it harder later to actually find the
targets during import analysis, as ghcide only looks for modules in the
import paths and checks for existence in the known target Map.

However, import analysis doesn't canonicalise target candidates, thus
the lookup in the known target Map will always fail.

We no longer canonicalise Targets, so import analysis will succeed
loading modules that are actually symbolic links.

* Prefer makeAbsolute over canonicalizePath

* Use makeAbsolute to read HIE files from disk

* Restore repeated builds

the ghcide build fails for win and ghc-8.8 with segfaults

Co-authored-by: Javier Neira <atreyu.bbb@gmail.com>
Co-authored-by: Pepe Iborra <pepeiborra@gmail.com>
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
@fendor fendor mentioned this pull request Aug 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Label to trigger pull request merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HLS can't find symlinked Modules
3 participants