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

Rebase of #1040, do not merge to main #1070

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c0f66a4
refactor: Abstract over labelling in available actions property test
georgefst May 15, 2023
93a3276
refactor: Match actual function names in hedgehog output
georgefst May 15, 2023
f1a59da
test: Extend available actions property test to cover typedefs
georgefst May 16, 2023
ead8c89
`AddConField` - update TC
georgefst May 16, 2023
901f662
allow "renaming" a type to its old name
georgefst May 17, 2023
eec1659
make `AddInput` work in con fields
georgefst May 17, 2023
1ad0eec
less strict duplicate name checking
georgefst May 23, 2023
3af356f
refactor - updateType'
georgefst May 23, 2023
59a75dd
update names in metadata when renaming type
georgefst May 23, 2023
dd5b275
detect capture when renaming type param
georgefst May 23, 2023
19fd241
WIP - more fixes needed (see TODOs, then re-run test to check for more)
georgefst May 24, 2023
88fad9f
fix: better metadata on rhs of new branch when addcon; that action no…
brprice May 30, 2023
a779b5c
fix: use cached type of scrut in transformCaseBranches...
brprice Jun 2, 2023
d869692
chore: clarify variable naming in checkEverything
brprice Jun 2, 2023
b3590e6
fix: checkEverything does smartholes inside typedefs
brprice Jun 2, 2023
d3a0d6e
fix: stable kind cache when AddConField
brprice Jun 2, 2023
ba123ab
post-rebase fixup - format and fix warnings
georgefst Jun 9, 2023
6c9d519
fix test
georgefst Jun 9, 2023
1f6d8c4
fix available actions test
georgefst Jun 9, 2023
78e2d01
fix forgetProgTypecache to fix benchmark tests
georgefst Jun 9, 2023
791df62
ignore capture-like failures for typedef names
georgefst Jun 10, 2023
1bcfd22
don't offer to delete in-use type params
georgefst Jun 10, 2023
8487cfa
rebase on `main` post-fixup
dhess Jun 11, 2023
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
2 changes: 1 addition & 1 deletion primer/src/Primer/API.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1183,7 +1183,7 @@ availableActions = curry3 $ logAPI (noError AvailableActions) $ \(sid, level, se
(editable, def) <- findASTTypeDef allTypeDefs sel.def
let getActions = case sel.node of
Nothing -> Available.forTypeDef
Just (TypeDefParamNodeSelection _) -> Available.forTypeDefParamNode
Just (TypeDefParamNodeSelection p) -> Available.forTypeDefParamNode p
Just (TypeDefConsNodeSelection s) -> case s.field of
Nothing -> Available.forTypeDefConsNode
Just field -> Available.forTypeDefConsFieldNode s.con field.index field.meta
Expand Down
35 changes: 23 additions & 12 deletions primer/src/Primer/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Control.Monad.Fresh (MonadFresh)
import Data.Aeson (Value)
import Data.Bifunctor.Swap qualified as Swap
import Data.Bitraversable (bisequence)
import Data.Data (Data)
import Data.Functor.Compose (Compose (..))
import Data.Generics.Product (typed)
import Data.List (delete, findIndex, insertBy)
Expand Down Expand Up @@ -1051,6 +1052,7 @@ renameForall b zt = case target zt of

-- | Convert a high-level 'Available.NoInputAction' to a concrete sequence of 'ProgAction's.
toProgActionNoInput ::
(HasID a, Data a) =>
DefMap ->
Either (ASTTypeDef a) ASTDef ->
Selection' ID ->
Expand Down Expand Up @@ -1084,18 +1086,27 @@ toProgActionNoInput defs def0 sel0 = \case
-- on the domain (left) side of the arrow.
toProgAction [ConstructArrowL, Move Child1]
Available.AddInput -> do
-- This action traverses the function type and adds a function arrow to the end of it,
-- resulting in a new argument type. The result type is unchanged.
-- The cursor location is also unchanged.
-- e.g. A -> B -> C ==> A -> B -> ? -> C
id <- nodeID
def <- termDef
type_ <- case findType id $ astDefType def of
Just t -> pure t
Nothing -> case map fst $ findNodeWithParent id $ astDefExpr def of
Just (TypeNode t) -> pure t
Just sm -> Left $ NeedType sm
Nothing -> Left $ IDNotFound id
type_ <- case def0 of
Left def -> do
(tName, vcName, field) <- conFieldSel
let id = field.meta
vc <- maybeToEither (ValConNotFound tName vcName) $ find ((== vcName) . valConName) $ astTypeDefConstructors def
t <- maybeToEither (FieldIndexOutOfBounds vcName field.index) $ flip atMay field.index $ valConArgs vc
case findType id t of
Just t' -> pure $ forgetTypeMetadata t'
Nothing -> Left $ IDNotFound id
Right def -> do
-- This action traverses the function type and adds a function arrow to the end of it,
-- resulting in a new argument type. The result type is unchanged.
-- The cursor location is also unchanged.
-- e.g. A -> B -> C ==> A -> B -> ? -> C
id <- nodeID
forgetTypeMetadata <$> case findType id $ astDefType def of
Just t -> pure t
Nothing -> case map fst $ findNodeWithParent id $ astDefExpr def of
Just (TypeNode t) -> pure t
Just sm -> Left $ NeedType sm
Nothing -> Left $ IDNotFound id
l <- case type_ of
TFun _ a b -> pure $ NE.length $ fst $ unfoldFun a b
t -> Left $ NeedTFun t
Expand Down
15 changes: 11 additions & 4 deletions primer/src/Primer/Action/Available.hs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ import Primer.Core (
Pattern (PatCon, PatPrim),
PrimCon (PrimChar, PrimInt),
TyConName,
TyVarName,
Type,
Type' (..),
TypeMeta,
Expand All @@ -84,7 +85,7 @@ import Primer.Core (
_typeMetaLens,
)
import Primer.Core.Transform (decomposeTAppCon)
import Primer.Core.Utils (forgetTypeMetadata, freeVars)
import Primer.Core.Utils (forgetTypeMetadata, freeVars, freeVarsTy)
import Primer.Def (
ASTDef (..),
DefMap,
Expand Down Expand Up @@ -367,20 +368,26 @@ forTypeDef l Editable tydefs defs tdName td =
)

forTypeDefParamNode ::
TyVarName ->
Level ->
Editable ->
TypeDefMap ->
DefMap ->
TyConName ->
ASTTypeDef TypeMeta ->
[Action]
forTypeDefParamNode _ NonEditable _ _ _ _ = mempty
forTypeDefParamNode l Editable tydefs defs tdName td =
forTypeDefParamNode _ _ NonEditable _ _ _ _ = mempty
forTypeDefParamNode paramName l Editable tydefs defs tdName td =
sortByPriority l $
[ Input RenameTypeParam
]
<> mwhen
(l == Expert && not (typeInUse tdName td tydefs defs))
( l == Expert
&& not
( typeInUse tdName td tydefs defs
|| any (elem paramName . freeVarsTy) (concatMap valConArgs $ astTypeDefConstructors td)
)
)
[NoInput DeleteTypeParam]

forTypeDefConsNode ::
Expand Down
5 changes: 3 additions & 2 deletions primer/src/Primer/Action/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import Data.Aeson (FromJSON (..), ToJSON (..))
import Primer.Action.Actions (Action)
import Primer.Action.Available qualified as Available
import Primer.Action.Movement (Movement)
import Primer.Core (Expr, GVarName, ID, LVarName, ModuleName, Pattern, TyConName, Type, Type', ValConName)
import Primer.Core (Expr, GVarName, ID, LVarName, ModuleName, Pattern, TyConName, Type', ValConName)
import Primer.JSON (CustomJSON (..), PrimerJSON)
import Primer.Typecheck.TypeError (TypeError)
import Primer.Zipper (SomeNode)
Expand Down Expand Up @@ -62,7 +62,7 @@ data ActionError
-- The extra unit is to avoid having two constructors with a single
-- TypeError field, breaking our MonadNestedError machinery...
ImportFailed () TypeError
| NeedTFun Type
| NeedTFun (Type' ())
| NeedType SomeNode
| NeedGlobal Available.Option
| NeedLocal Available.Option
Expand All @@ -78,5 +78,6 @@ data ActionError
| NeedTypeDefParamSelection
| NoNodeSelection
| ValConNotFound TyConName ValConName
| FieldIndexOutOfBounds ValConName Int
deriving stock (Eq, Show, Read, Generic)
deriving (FromJSON, ToJSON) via PrimerJSON ActionError
Loading