Skip to content

Commit ab1aec7

Browse files
authored
rollback NFP interning (#344)
1 parent 08899eb commit ab1aec7

File tree

1 file changed

+2
-21
lines changed
  • lsp-types/src/Language/LSP/Types

1 file changed

+2
-21
lines changed

lsp-types/src/Language/LSP/Types/Uri.hs

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,16 @@ import Control.DeepSeq
2525
import qualified Data.Aeson as A
2626
import Data.Binary (Binary, Get, put, get)
2727
import Data.Hashable
28-
import qualified Data.HashMap.Strict as HM
29-
import Data.IORef (atomicModifyIORef', newIORef)
3028
import Data.List (stripPrefix)
3129
import Data.String (IsString, fromString)
3230
import Data.Text (Text)
3331
import qualified Data.Text as T
34-
import Data.Tuple (swap)
3532
import GHC.Generics
3633
import Network.URI hiding (authority)
3734
import qualified System.FilePath as FP
3835
import qualified System.FilePath.Posix as FPP
3936
import qualified System.FilePath.Windows as FPW
4037
import qualified System.Info
41-
import System.IO.Unsafe (unsafePerformIO)
4238

4339
newtype Uri = Uri { getUri :: Text }
4440
deriving (Eq,Ord,Read,Show,Generic,A.FromJSON,A.ToJSON,Hashable,A.ToJSONKey,A.FromJSONKey)
@@ -175,7 +171,7 @@ instance Binary NormalizedFilePath where
175171

176172
-- | A smart constructor that performs UTF-8 encoding and hash consing
177173
normalizedFilePath :: NormalizedUri -> FilePath -> NormalizedFilePath
178-
normalizedFilePath nuri nfp = intern $ NormalizedFilePath nuri nfp
174+
normalizedFilePath nuri nfp = NormalizedFilePath nuri nfp
179175

180176
-- | Internal helper that takes a file path that is assumed to
181177
-- already be normalized to a URI. It is up to the caller
@@ -211,19 +207,4 @@ normalizedFilePathToUri (NormalizedFilePath uri _) = uri
211207

212208
uriToNormalizedFilePath :: NormalizedUri -> Maybe NormalizedFilePath
213209
uriToNormalizedFilePath nuri = fmap (normalizedFilePath nuri) mbFilePath
214-
where mbFilePath = platformAwareUriToFilePath System.Info.os (fromNormalizedUri nuri)
215-
216-
---------------------------------------------------------------------------
217-
-- Unsafe hashcons of NFP
218-
internIO :: (Eq a, Hashable a) => IO (a -> IO a)
219-
internIO = do
220-
tableRef <- newIORef mempty
221-
let f x = atomicModifyIORef' tableRef $ swap . flip HM.alterF x (\case
222-
Just res -> (res, Just res)
223-
Nothing -> (x, Just x)
224-
)
225-
return f
226-
227-
{-# NOINLINE intern #-}
228-
intern :: NormalizedFilePath -> NormalizedFilePath
229-
intern = let f = unsafePerformIO internIO in \x -> unsafePerformIO (f x)
210+
where mbFilePath = platformAwareUriToFilePath System.Info.os (fromNormalizedUri nuri)

0 commit comments

Comments
 (0)