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

Implement "split" tactic #521

Closed
wants to merge 2 commits into from
Closed

Conversation

WorldSEnder
Copy link

Originated as isovector#30 this implements a split tactic for introducing specific constructors in holes on the user's request. For more details also see the linked PR.

@WorldSEnder WorldSEnder changed the title implement "split" tactic Implement "split" tactic Oct 20, 2020
Copy link
Collaborator

@isovector isovector 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 to me. The test failures have me concerned though! I think I might know what's going wrong, so I'll try to fix that today.

stack.yaml Outdated
@@ -4,6 +4,7 @@ packages:
- .
- ./ghcide/
- ./hls-plugin-api
- ./plugins/tactics
Copy link
Collaborator

Choose a reason for hiding this comment

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

Good catch! Not sure how I missed this.

@isovector
Copy link
Collaborator

I suspect the following diff will fix the tests:

diff --git a/plugins/tactics/src/Ide/Plugin/Tactic/Debug.hs b/plugins/tactics/src/Ide/Plugin/Tactic/Debug.hs
index ba91a7c..6c528da 100644
--- a/plugins/tactics/src/Ide/Plugin/Tactic/Debug.hs
+++ b/plugins/tactics/src/Ide/Plugin/Tactic/Debug.hs
@@ -1,3 +1,7 @@
+{-# LANGUAGE BangPatterns     #-}
+{-# LANGUAGE CPP              #-}
+{-# LANGUAGE TypeApplications #-}
+
 module Ide.Plugin.Tactic.Debug
   ( unsafeRender
   , unsafeRender'
@@ -9,17 +13,36 @@ module Ide.Plugin.Tactic.Debug
   , traceMX
   ) where
 
+import Control.DeepSeq
+import Control.Exception
 import Debug.Trace
 import DynFlags (unsafeGlobalDynFlags)
 import Outputable hiding ((<>))
+import System.IO.Unsafe (unsafePerformIO)
+
+#if __GLASGOW_HASKELL__ >= 808
+import PlainPanic (PlainGhcException)
+type GHC_EXCEPTION = PlainGhcException
+#else
+import Panic (GhcException)
+type GHC_EXCEPTION = GhcException
+#endif
+
 
 ------------------------------------------------------------------------------
 -- | Print something
 unsafeRender :: Outputable a => a -> String
 unsafeRender = unsafeRender' . ppr
 
+
 unsafeRender' :: SDoc -> String
-unsafeRender' = showSDoc unsafeGlobalDynFlags
+unsafeRender' sdoc = unsafePerformIO $ do
+  let z = showSDoc unsafeGlobalDynFlags sdoc
+  -- We might not have unsafeGlobalDynFlags (like during testing), in which
+  -- case GHC panics. Instead of crashing, let's just fail to print.
+  !res <- try @GHC_EXCEPTION $ evaluate $ deepseq z z
+  pure $ either (const "<unsafeRender'>") id res
+{-# NOINLINE unsafeRender' #-}
 
 traceMX :: (Monad m, Show a) => String -> a -> m ()
 traceMX str a = traceM $ mappend ("!!!" <> str <> ": ") $ show a

diff --git a/plugins/tactics/hls-tactics-plugin.cabal b/plugins/tactics/hls-tactics-plugin.cabal
index 9abb2b5..7fecc86 100644
--- a/plugins/tactics/hls-tactics-plugin.cabal
+++ b/plugins/tactics/hls-tactics-plugin.cabal
@@ -75,6 +75,28 @@ library
     , syb
     , text
     , transformers
+    , deepseq

@WorldSEnder
Copy link
Author

WorldSEnder commented Oct 20, 2020

I wonder what exactly is the difference now between the circle ci and the github tests, seeing that the latter worked fine, and only the former failed before?

@isovector
Copy link
Collaborator

Yeah, I have no idea. We're in #haskell-ide-engine on freenode trying to suss out wtf.

@jneira
Copy link
Member

jneira commented Oct 21, 2020

We were not able to come to a conclusion in irc, summarizin some facts:

  • tests are failing in circleci but no in github wf
    • the former uses stack and the latter cabal
  • both ci jobs uses -j1 for the test suite itself (but no for the build tool cabal/stack)
  • tests are not failing locally (with cabal or stack)
  • tests fail more frequently for ghc-8.8 but the fail occasionally for ghc-8.10. No fail ever for ghc-8.6
  • the main diff between this pr and hlint one from the original pr that introduced tests is the bump of lsp-test from 0.11.0.4 to 0.11.0.5/0.11.0.6

@jneira
Copy link
Member

jneira commented Oct 21, 2020

Ok, i've tried to add waitForDiagnostics for tactic func tests and it seems they are working at first:

@WorldSEnder
Copy link
Author

Progress! Thank you @jneira that seems to have at least fixed stack-ghc-8.10. Locally stack-8.8.x is also no problem. The github action fail for windows-ghc-8.10.1 looks suspicious, although probably not connected to the PR.

@isovector
Copy link
Collaborator

@jneira uh oh. Now eval > Evaluation of expressions is failing with Exception: fd:3: hPutBuf: resource vanished (Broken pipe). Something is seriously wonky in the testing infrastructure.

@jneira
Copy link
Member

jneira commented Oct 21, 2020

i've hit it another one in hlint pr too, after rebasing waitForDiagnostics, but at least they are much less frequent now

@isovector
Copy link
Collaborator

@WorldSEnder everything should be cleared up if you merge master.

One code action per datatype constructor is produced.
test cases for splitting

don't suggest constructors with hash by default

suggesting I# for Int probably is not what you want
99% of the time

also reuse tyDataCons, tacname
use 'algebraicTyCon' as filter for now
@jneira
Copy link
Member

jneira commented Nov 25, 2020

Rerunning circleci failed jobs

@isovector
Copy link
Collaborator

I'd like to get this merged. Mind if I take over, @WorldSEnder ?

@WorldSEnder
Copy link
Author

Go ahead, the branch is set to accept commits from maintainers.

@Ailrun
Copy link
Member

Ailrun commented Feb 17, 2021

I guess this PR is not relevant anymore, as succeeded by #1379. If not, feel free to reopen this.

@Ailrun Ailrun closed this Feb 17, 2021
@isovector isovector reopened this Feb 17, 2021
@isovector
Copy link
Collaborator

Different meaning of "split", I'm afraid!

@isovector
Copy link
Collaborator

Implemented in #1461

@isovector isovector closed this Feb 28, 2021
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.

4 participants