This repository has been archived by the owner on Jan 2, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 97
Extend position mapping with fuzzy ranges #785
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pepeiborra
approved these changes
Sep 13, 2020
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, just add the missing bangs and good to merge
4 tasks
I'm a bit concerned about adding bangs to the datatype definition, I must admit. I think it changes the asymptotics of 'n' binds in sequence from linear to exponential. Let me confirm by writing a synthetic benchmark. |
Yes, its as I suspected. Here is the benchmark I'm using f :: Int -> PositionResult Int
f i = PositionRange (i-1) (i+1)
g :: Int -> Int -> PositionResult Int
g 0 x = pure x
g i x = f x >>= g (i-1)
main :: IO ()
main = do
print $ g 100 0 with data PositionResult a = PositionRange { unsafeLowerRange :: !a, unsafeUpperRange :: !a } | PositionExact !a This doesn't terminate any time soon. It terminates pretty much instantly with the following: data PositionResult a = PositionRange { unsafeLowerRange :: a, unsafeUpperRange :: a } | PositionExact !a It also terminates if we add bangs to the Monad instance: instance Monad PositionResult where
(PositionExact a) >>= f = f a
(PositionRange !lower !upper) >>= f = PositionRange lower' upper'
where
lower' = lowerRange $ f lower
upper' = upperRange $ f upper However, adding bangs to |
Wow, good catch! |
pepeiborra
pushed a commit
to pepeiborra/ide
that referenced
this pull request
Dec 29, 2020
* Extend position mapping with fuzzy ranges * fix tests * add bangs * make fields lazy again
pepeiborra
pushed a commit
to pepeiborra/ide
that referenced
this pull request
Dec 29, 2020
* Extend position mapping with fuzzy ranges * fix tests * add bangs * make fields lazy again
pepeiborra
pushed a commit
to pepeiborra/ide
that referenced
this pull request
Dec 29, 2020
* Extend position mapping with fuzzy ranges * fix tests * add bangs * make fields lazy again
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
We sometimes need to know the original range that a position mapped to, when a simple failure is not helpful.
For example, when the user is typing inside a do block, we would like to use position mapping to tell us that the current cursor position is within the span of the do block, where the span is known from the old version of the file for which we have compiler artifacts. This can be helpful for things like generating completions based on local variables.