Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Play nice with ghcide #369

Merged
merged 25 commits into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
298c37f
Avoid binding an unused type variable.
robrix Oct 30, 2019
7262484
Add language extensions to everything.
robrix Oct 30, 2019
a8a3bca
Fix some missed language extensions.
robrix Oct 30, 2019
17f860a
Only enable StrictData by default.
robrix Oct 30, 2019
f68fa5e
Enable hard-mode warnings project-wide.
robrix Oct 30, 2019
8d6eecc
Fix partial record selector warnings for LoopControl.
robrix Oct 30, 2019
9770cbd
:fire: partial field selectors for Token.
robrix Oct 30, 2019
29db8b3
:fire: partial field selectors for Python.QualifiedName.
robrix Oct 30, 2019
b2ad11a
Don’t bind unused type variables.
robrix Oct 30, 2019
fa865e8
Disable extensions in the hlint config.
robrix Oct 30, 2019
29085fd
Extract the partial moduleName & span fields into a new type.
robrix Oct 30, 2019
a2ec2ae
:fire: partial record selectors from ControlFlowVertex.
robrix Oct 30, 2019
6230181
Fix up the graph style.
robrix Oct 30, 2019
22f1e72
:fire: redundant imports.
robrix Oct 30, 2019
b07382d
:fire: partial record selectors in the integration spec.
robrix Oct 30, 2019
3a18af8
We don’t actually use NamedFieldPuns here.
robrix Oct 30, 2019
eeec38a
:fire: the highly suspect release flag use from the tests.
robrix Oct 30, 2019
60886eb
:fire: the silencing of no export list warnigns.
robrix Oct 30, 2019
4941cb8
:fire: redundant constraints.
robrix Oct 30, 2019
890d05d
:fire: branchNode/leafNode/toTerm.
robrix Oct 30, 2019
0c89785
:fire: redundant constraints.
robrix Oct 30, 2019
17fe2b0
:fire: redundant language extensions.
robrix Oct 30, 2019
50fb138
Correct how we silence a lint.
robrix Oct 30, 2019
c6c729d
:fire: redundant Generic & Hashable instances.
robrix Oct 30, 2019
cab72da
:fire
robrix Oct 30, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .hlint.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# HLint configuration file
# https://github.com/ndmitchell/hlint

- arguments: [--color=auto, -XDataKinds, -XDeriveFoldable, -XDeriveFunctor, -XDeriveGeneric, -XDeriveTraversable, -XFlexibleContexts, -XFlexibleInstances, -XMultiParamTypeClasses, -XOverloadedStrings, -XRecordWildCards, -XStandaloneDeriving, -XStrictData, -XTypeApplications, -XDerivingVia]
- arguments: [--color=auto, -XStrictData]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

yay!


# Blacklist some functions by default.
- functions:
Expand All @@ -23,7 +23,7 @@
- warn: {group: {name: default}}

# Ignore the highly noisy module export list hint
- ignore: {name: Use module export list}
- ignore: {name: Use explicit module export list}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one apparently changed.


# Ignore some builtin hints
- ignore: {name: Use mappend}
Expand Down
23 changes: 8 additions & 15 deletions bench/Evaluation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,22 @@

module Evaluation (benchmarks) where

import Algebra.Graph
import Control.Monad
Comment on lines -5 to -6
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Did you know we didn’t have warnings enabled in the benchmarks?

Copy link
Contributor

Choose a reason for hiding this comment

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

😮

import Control.Carrier.Parse.Simple
import qualified Data.Duration as Duration
import Data.Abstract.Evaluatable
import Data.Abstract.FreeVariables
import Data.Blob
import Data.Blob.IO (readBlobFromFile')
import Data.Bifunctor
import Data.Functor.Classes
import Data.Functor.Foldable (Base, Recursive)
import "semantic" Data.Graph (Graph (..), topologicalSort)
import Data.Graph.ControlFlowVertex
import "semantic" Data.Graph (topologicalSort)
import qualified Data.Language as Language
import Data.Project
import Data.Proxy
import Data.Term
import Gauge.Main
import Parsing.Parser
import Semantic.Config (defaultOptions)
import Semantic.Graph
import Semantic.Task (SomeException, TaskSession (..), runTask, withOptions)
import Semantic.Task (TaskSession (..), runTask, withOptions)
import Semantic.Util
import Source.Loc
import Source.Span (HasSpan)
import qualified System.Path as Path
import System.Path ((</>))

Expand All @@ -40,20 +31,22 @@ callGraphProject' :: ( Language.SLanguage lang
-> Path.RelFile
-> IO (Either String ())
callGraphProject' session proxy path
| let lang = Language.reflect proxy
, Just (SomeParser parser) <- parserForLanguage analysisParsers lang = fmap (bimap show (const ())) . runTask session $ do
| Just (SomeParser parser) <- parserForLanguage analysisParsers lang = fmap (bimap show (const ())) . runTask session $ do
blob <- readBlobFromFile' (fileForTypedPath path)
package <- fmap snd <$> runParse (Duration.fromSeconds 10) (parsePackage parser (Project (Path.toString (Path.takeDirectory path)) [blob] lang []))
modules <- topologicalSort <$> runImportGraphToModules proxy package
runCallGraph proxy False modules package
| otherwise = error $ "Analysis not supported for: " <> show lang
where lang = Language.reflect proxy

callGraphProject proxy paths = withOptions defaultOptions $ \ config logger statter ->
callGraphProject' (TaskSession config "" False logger statter) proxy paths

evaluateProject proxy path
| let lang = Language.reflect proxy
, Just (SomeParser parser) <- parserForLanguage analysisParsers lang = withOptions defaultOptions $ \ config logger statter ->
| Just (SomeParser parser) <- parserForLanguage analysisParsers lang = withOptions defaultOptions $ \ config logger statter ->
fmap (const ()) . justEvaluating =<< evaluateProject' (TaskSession config "" False logger statter) proxy parser [Path.toString path]
| otherwise = error $ "Analysis not supported for: " <> show lang
where lang = Language.reflect proxy

pyEval :: Path.RelFile -> Benchmarkable
pyEval p = nfIO $ evaluateProject (Proxy @'Language.Python) (Path.relDir "bench/bench-fixtures/python" </> p)
Expand Down
2 changes: 1 addition & 1 deletion bench/Main.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module Main where
module Main (main) where

import Gauge
import qualified Evaluation
Expand Down
39 changes: 18 additions & 21 deletions semantic.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,22 @@ flag release
-- GHC extensions shared between targets
common haskell
default-language: Haskell2010
default-extensions: DataKinds
, DeriveFoldable
, DeriveFunctor
, DeriveGeneric
, DeriveTraversable
, FlexibleContexts
, FlexibleInstances
, MonadFailDesugaring
, MultiParamTypeClasses
, OverloadedStrings
, RecordWildCards
, StandaloneDeriving
, StrictData
, TypeApplications
Comment on lines -28 to -41
Copy link
Contributor Author

Choose a reason for hiding this comment

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

All of these have been moved to the .hs files, except StrictData, which does not affect parsing/typechecking, and MonadFailDesugaring, which is obsolete in 8.6+.

default-extensions: StrictData
ghc-options:
-Weverything
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hard mode.

-Wno-missing-local-signatures
-Wno-missing-import-lists
-Wno-implicit-prelude
-Wno-safe
-Wno-unsafe
-Wno-name-shadowing
-Wno-monomorphism-restriction
-Wno-missed-specialisations
-Wno-all-missed-specialisations
-Wno-star-is-type
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Slightly less hard mode.

if (impl(ghc >= 8.8))
ghc-options: -Wno-missing-deriving-strategies


-- Except in case of vendored dependencies, these deps should be expressed
-- as caret-operator bounds relative to a version in Stackage.
Expand Down Expand Up @@ -74,11 +76,8 @@ common dependencies
common executable-flags
ghc-options: -threaded -rtsopts "-with-rtsopts=-N -A4m -n2m"

common ghc-warnings
ghc-options: -Wall -Wmissing-export-lists -Wcompat -Wincomplete-record-updates -Wincomplete-uni-patterns -Wredundant-constraints -Wno-name-shadowing

library
import: haskell, dependencies, ghc-warnings
import: haskell, dependencies
hs-source-dirs: src
exposed-modules:
-- Analyses & term annotations
Expand Down Expand Up @@ -317,7 +316,7 @@ executable semantic
, semantic

test-suite test
import: haskell, dependencies, executable-flags, ghc-warnings
import: haskell, dependencies, executable-flags
type: exitcode-stdio-1.0
hs-source-dirs: test
main-is: Spec.hs
Expand Down Expand Up @@ -371,8 +370,6 @@ test-suite test
, HUnit ^>= 1.6.0.0
, leancheck >= 0.8 && <1
, temporary ^>= 1.3
if flag(release)
ghc-options: -dynamic
Comment on lines -374 to -375
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was dodgy as hell.


test-suite parse-examples
import: haskell, dependencies, executable-flags
Expand Down
2 changes: 1 addition & 1 deletion src/Analysis/Abstract/Caching/FlowInsensitive.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE GeneralizedNewtypeDeriving, TypeOperators #-}
{-# LANGUAGE DeriveFunctor, FlexibleContexts, GeneralizedNewtypeDeriving, TypeApplications, TypeOperators #-}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

A lot of these FlexibleContexts additions are going to go away with fused-effects 1.0.

module Analysis.Abstract.Caching.FlowInsensitive
( cachingTerms
, convergingModules
Expand Down
2 changes: 1 addition & 1 deletion src/Analysis/Abstract/Caching/FlowSensitive.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE ConstraintKinds, GADTs, GeneralizedNewtypeDeriving, TypeOperators #-}
{-# LANGUAGE ConstraintKinds, FlexibleContexts, GADTs, GeneralizedNewtypeDeriving, TypeApplications, TypeOperators #-}
module Analysis.Abstract.Caching.FlowSensitive
( Cache
, cachingTerms
Expand Down
2 changes: 1 addition & 1 deletion src/Analysis/Abstract/Dead.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE GeneralizedNewtypeDeriving, TypeOperators #-}
{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, StandaloneDeriving #-}
module Analysis.Abstract.Dead
( Dead(..)
, revivingTerms
Expand Down
16 changes: 8 additions & 8 deletions src/Analysis/Abstract/Graph.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE DerivingVia, LambdaCase, RankNTypes, ScopedTypeVariables, TypeFamilies, TypeOperators, UndecidableInstances #-}
{-# LANGUAGE DerivingVia, FlexibleContexts, FlexibleInstances, LambdaCase, MultiParamTypeClasses, OverloadedStrings, RankNTypes, ScopedTypeVariables, TypeFamilies, UndecidableInstances #-}
module Analysis.Abstract.Graph
( Graph(..)
, ControlFlowVertex(..)
Expand Down Expand Up @@ -35,12 +35,12 @@ style = (defaultStyle (T.encodeUtf8Builder . vertexIdentifier))
{ vertexAttributes = vertexAttributes
, edgeAttributes = edgeAttributes
}
where vertexAttributes Package{} = [ "style" := "dashed", "shape" := "box" ]
vertexAttributes Module{} = [ "style" := "dotted, rounded", "shape" := "box" ]
vertexAttributes UnknownModule{} = [ "style" := "dotted, rounded", "shape" := "box", "color" := "red", "fontcolor" := "red" ]
vertexAttributes Variable{..} = [ "label" := T.encodeUtf8Builder (vertexName <> " (Variable)"), "tooltip" := T.encodeUtf8Builder (showSpan vertexSpan), "style" := "rounded", "shape" := "box" ]
vertexAttributes Method{..} = [ "label" := T.encodeUtf8Builder (vertexName <> " (Method)"), "tooltip" := T.encodeUtf8Builder (showSpan vertexSpan) , "style" := "rounded", "shape" := "box" ]
vertexAttributes Function{..} = [ "label" := T.encodeUtf8Builder (vertexName <> " (Function)"), "tooltip" := T.encodeUtf8Builder (showSpan vertexSpan), "style" := "rounded", "shape" := "box" ]
where vertexAttributes Package{} = [ "style" := "dashed", "shape" := "box" ]
vertexAttributes Module{} = [ "style" := "dotted, rounded", "shape" := "box" ]
vertexAttributes UnknownModule{} = [ "style" := "dotted, rounded", "shape" := "box", "color" := "red", "fontcolor" := "red" ]
vertexAttributes (Variable n _ s) = [ "label" := T.encodeUtf8Builder (n <> " (Variable)"), "tooltip" := T.encodeUtf8Builder (showSpan s), "style" := "rounded", "shape" := "box" ]
vertexAttributes (Method n _ s) = [ "label" := T.encodeUtf8Builder (n <> " (Method)"), "tooltip" := T.encodeUtf8Builder (showSpan s) , "style" := "rounded", "shape" := "box" ]
vertexAttributes (Function n _ s) = [ "label" := T.encodeUtf8Builder (n <> " (Function)"), "tooltip" := T.encodeUtf8Builder (showSpan s), "style" := "rounded", "shape" := "box" ]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fallout from the changes to ControlFlowVertex.

edgeAttributes Module{} Module{} = [ "len" := "5.0", "label" := "imports" ]
edgeAttributes Module{} UnknownModule{} = [ "len" := "5.0", "label" := "imports" ]
edgeAttributes Package{} Module{} = [ "len" := "5.0", "style" := "dashed" ]
Expand Down Expand Up @@ -78,7 +78,7 @@ graphingTerms recur term = do
case toVertex definedInModule term of
Just (v@Function{}, name) -> recurWithContext v name
Just (v@Method{}, name) -> recurWithContext v name
Just (v@Variable{..}, name) -> do
Just (v@Variable{}, name) -> do
variableDefinition v
slot <- lookupSlot (Declaration name)
defined <- gets (Map.lookup slot)
Expand Down
2 changes: 1 addition & 1 deletion src/Analysis/Abstract/Tracing.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleContexts #-}
module Analysis.Abstract.Tracing
( tracingTerms
, tracing
Expand Down
4 changes: 2 additions & 2 deletions src/Analysis/ConstructorName.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE ScopedTypeVariables, TypeFamilies, TypeOperators, UndecidableInstances #-}
{-# LANGUAGE DataKinds, FlexibleInstances, MultiParamTypeClasses, ScopedTypeVariables, TypeApplications, TypeFamilies, TypeOperators, UndecidableInstances #-}
module Analysis.ConstructorName
( ConstructorName(..)
) where
Expand Down Expand Up @@ -32,7 +32,7 @@ type family ConstructorNameStrategy syntax where
ConstructorNameStrategy (Sum _) = 'Custom
ConstructorNameStrategy [] = 'Custom
ConstructorNameStrategy (TermF _ _) = 'Custom
ConstructorNameStrategy syntax = 'Default
ConstructorNameStrategy _ = 'Default

class ConstructorNameWithStrategy (strategy :: Strategy) syntax where
constructorNameWithStrategy :: proxy strategy -> syntax a -> String
Expand Down
6 changes: 3 additions & 3 deletions src/Analysis/CyclomaticComplexity.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE DataKinds, DefaultSignatures, GeneralizedNewtypeDeriving, MultiParamTypeClasses, ScopedTypeVariables, TypeFamilies, UndecidableInstances #-}
{-# LANGUAGE DataKinds, DefaultSignatures, FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, ScopedTypeVariables, TypeApplications, TypeFamilies, UndecidableInstances #-}
module Analysis.CyclomaticComplexity
( CyclomaticComplexity(..)
, HasCyclomaticComplexity
Expand Down Expand Up @@ -103,8 +103,8 @@ type family CyclomaticComplexityStrategy syntax where
CyclomaticComplexityStrategy Statement.If = 'Custom
CyclomaticComplexityStrategy Statement.Pattern = 'Custom
CyclomaticComplexityStrategy Statement.While = 'Custom
CyclomaticComplexityStrategy (Sum fs) = 'Custom
CyclomaticComplexityStrategy a = 'Default
CyclomaticComplexityStrategy (Sum _) = 'Custom
CyclomaticComplexityStrategy _ = 'Default


-- | The 'Default' strategy takes the sum without incrementing.
Expand Down
2 changes: 1 addition & 1 deletion src/Analysis/Decorator.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE FlexibleContexts, TypeFamilies #-}
module Analysis.Decorator
( decoratorWithAlgebra
) where
Expand Down
6 changes: 3 additions & 3 deletions src/Analysis/HasTextElement.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE ScopedTypeVariables, TypeFamilies, TypeOperators, UndecidableInstances #-}
{-# LANGUAGE DataKinds, FlexibleInstances, MultiParamTypeClasses, ScopedTypeVariables, TypeApplications, TypeFamilies, TypeOperators, UndecidableInstances #-}
module Analysis.HasTextElement
( HasTextElement(..)
) where
Expand Down Expand Up @@ -29,8 +29,8 @@ class HasTextElementWithStrategy (strategy :: Strategy) syntax where

type family TextElementStrategy syntax where
TextElementStrategy Literal.TextElement = 'Custom
TextElementStrategy (Sum fs) = 'Custom
TextElementStrategy a = 'Default
TextElementStrategy (Sum _) = 'Custom
TextElementStrategy _ = 'Default

instance HasTextElementWithStrategy 'Default syntax where
isTextElementWithStrategy _ _ = False
Expand Down
8 changes: 4 additions & 4 deletions src/Analysis/PackageDef.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE ScopedTypeVariables, TypeFamilies, UndecidableInstances #-}
{-# LANGUAGE DataKinds, FlexibleInstances, MultiParamTypeClasses, RecordWildCards, ScopedTypeVariables, TypeApplications, TypeFamilies, UndecidableInstances #-}
module Analysis.PackageDef
( PackageDef(..)
, HasPackageDef
Expand All @@ -15,7 +15,7 @@ import Prologue
import Source.Loc

newtype PackageDef = PackageDef { moduleDefIdentifier :: T.Text }
deriving (Eq, Generic, Show)
deriving (Eq, Show)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also took the opportunity to 🔥 a few Generic instances we weren’t using.


-- | An r-algebra producing 'Just' a 'PackageDef' for syntax nodes corresponding to high-level declarations, or 'Nothing' otherwise.
--
Expand Down Expand Up @@ -80,8 +80,8 @@ class HasPackageDefWithStrategy (strategy :: Strategy) syntax where
-- If you’re seeing errors about missing a 'CustomHasPackageDef' instance for a given type, you’ve probably listed it in here but not defined a 'CustomHasPackageDef' instance for it, or else you’ve listed the wrong type in here. Conversely, if your 'customHasPackageDef' method is never being called, you may have forgotten to list the type in here.
type family PackageDefStrategy syntax where
PackageDefStrategy Language.Go.Syntax.Package = 'Custom
PackageDefStrategy (Sum fs) = 'Custom
PackageDefStrategy a = 'Default
PackageDefStrategy (Sum _) = 'Custom
PackageDefStrategy _ = 'Default


-- | The 'Default' strategy produces 'Nothing'.
Expand Down
6 changes: 3 additions & 3 deletions src/Analysis/TOCSummary.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{-# LANGUAGE AllowAmbiguousTypes, LambdaCase, RankNTypes, ScopedTypeVariables, TypeFamilies, TypeOperators, UndecidableInstances, ViewPatterns #-}
{-# LANGUAGE AllowAmbiguousTypes, DataKinds, FlexibleContexts, FlexibleInstances, LambdaCase, MultiParamTypeClasses, OverloadedStrings, RankNTypes, RecordWildCards, ScopedTypeVariables, TypeApplications, TypeFamilies, TypeOperators, UndecidableInstances, ViewPatterns #-}
module Analysis.TOCSummary
( Declaration(..)
, formatIdentifier
Expand Down Expand Up @@ -151,5 +151,5 @@ type family DeclarationStrategy syntax where
DeclarationStrategy Declaration.Method = 'Custom
DeclarationStrategy Markdown.Heading = 'Custom
DeclarationStrategy Syntax.Error = 'Custom
DeclarationStrategy (Sum fs) = 'Custom
DeclarationStrategy a = 'Default
DeclarationStrategy (Sum _) = 'Custom
DeclarationStrategy _ = 'Default
Loading