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

Fix unused binding annotations #5218

Merged
merged 5 commits into from
Jul 13, 2024
Merged

Fix unused binding annotations #5218

merged 5 commits into from
Jul 13, 2024

Conversation

ChrisPenner
Copy link
Contributor

@ChrisPenner ChrisPenner commented Jul 12, 2024

Overview

Previously I thought we wouldn't be able to get the correct locations of bindings for printing errors, but found we were actually stripping them during component minimization. This propagates the annotations so we can improve the location of unused bindings errors (and any other diagnostics which reference bindings in the future).

Old:
image

New:

image

Implementation notes

  • Changes the annotations we have on Abs nodes to be the annotation of the actual variable
  • Use the ann from the Abs node instead of the top-level-term
  • Split to have a separate diagnostic for each var
  • Set the diagnostics as "unnecessary" so they render as greyed-out in editors (just like HLS does it)

Interesting/controversial decisions

This does remove the invariant I had previously held where every node's annotations contains everything inside, but I think it's worth it to gain this functionality. I just special-cased the other commands to know to ignore the Abs annotation when looking things up.

Ideally I'd just have a spot to put a distinct annotation for variable bindings, but I can't do that without changing either the Term or the ABT which is a ton of work and would maybe affect hashing. Maybe we can address this when we do the next re-hash migration.

Test coverage

Added some clever tests where you can mark the expected diagnostic location for a given error.

Loose ends

The let-binding error still spans the entire binding rather than just the name. I think I can fix this by threading another annotation through the Unison File, but that's a bigger change for a pretty small value-add, so I'll leave that for later.

@ChrisPenner ChrisPenner force-pushed the lsp/fix-unused-binding-locs branch from 598fc16 to ab5534c Compare July 12, 2024 21:08
@@ -169,7 +169,7 @@ expandSimple keep (v, bnd) = (v, apps' (var a v) evs)
evs = map (var a) . Set.toList $ Set.difference fvs keep

abstract :: (Var v) => Set v -> Term v a -> Term v a
abstract keep bnd = lam' a evs bnd
Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the runtime we don't typically care about annotations, it's fine if we use the top-level annotation for arguments in lamdas (like we already do)

@ChrisPenner ChrisPenner force-pushed the lsp/fix-unused-binding-locs branch from ab5534c to 149cd9c Compare July 12, 2024 21:26
@ChrisPenner ChrisPenner force-pushed the lsp/fix-unused-binding-locs branch from 149cd9c to 11208f5 Compare July 12, 2024 21:48
@ChrisPenner ChrisPenner marked this pull request as ready for review July 13, 2024 00:05
@ChrisPenner ChrisPenner requested a review from aryairani July 13, 2024 00:05
@aryairani aryairani merged commit 264a31a into trunk Jul 13, 2024
35 checks passed
@aryairani aryairani deleted the lsp/fix-unused-binding-locs branch July 13, 2024 03:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants