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

fix: extend available actions property test to cover typedefs, and fix revealed bugs #1040

Merged
merged 21 commits into from
Jun 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
7644730
refactor: Abstract over labelling in available actions property test
georgefst May 15, 2023
2b72a61
refactor: Match actual function names in hedgehog output
georgefst May 15, 2023
b0aa0d8
fix: `AddConField` action sets correct `TypeCache`s
georgefst May 16, 2023
d579642
feat: allow "renaming" a type to its old name
georgefst May 17, 2023
38955eb
feat: make `AddInput` work in typedef con fields
georgefst May 17, 2023
679f23a
refactor: rename updateType{,Def} in applyProgAction
brprice Jun 20, 2023
eccb0cb
refactor: extract updateType helper in RenameType action
georgefst May 23, 2023
6bbb4c1
fix: update names in metadata when renaming type
georgefst May 23, 2023
750fd9b
fix: detect capture when renaming type param
georgefst May 23, 2023
12670ed
fix: use cached type of scrut in transformCaseBranches
brprice Jun 2, 2023
dbdf8a3
fix: better metadata in new branch from AddCon
brprice May 30, 2023
79f7a07
chore: clarify variable naming in checkEverything
brprice Jun 2, 2023
80bc02c
fix: forgetProgTypecache also acts on typedefs
georgefst Jun 9, 2023
61f97b7
fix: checkEverything does smartholes inside typedefs
brprice Jun 2, 2023
2571fd5
refactor: explicit TC error for duplicate parameters
brprice Jun 21, 2023
b8ebb26
fix: add correct kind cache in AddConField
brprice Jun 2, 2023
e80b8a1
fix: don't offer to delete in-use type params
georgefst Jun 10, 2023
e940ab6
fix: tcWholeProg not change selection inside ctor field
brprice Jun 20, 2023
e1b9fee
test: Extend available actions property test to cover typedefs
georgefst May 16, 2023
a565a5e
fix: ignore typedef name clashes for available-actions-accepted
georgefst Jun 10, 2023
88728cf
fix!: typedef actions detects all name clashes
brprice Jun 21, 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
27 changes: 18 additions & 9 deletions primer/src/Primer/Action.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ renameForall b zt = case target zt of
-- | Convert a high-level 'Available.NoInputAction' to a concrete sequence of 'ProgAction's.
toProgActionNoInput ::
DefMap ->
Either (ASTTypeDef a) ASTDef ->
Either (ASTTypeDef TypeMeta) ASTDef ->
Selection' ID ->
Available.NoInputAction ->
Either ActionError [ProgAction]
Expand Down Expand Up @@ -1088,14 +1088,23 @@ toProgActionNoInput defs def0 sel0 = \case
-- 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
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
10 changes: 8 additions & 2 deletions primer/src/Primer/Action/ProgError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@ data ProgError
| TypeDefNotFound TyConName
| TypeDefAlreadyExists TyConName
| TypeDefInUse TyConName
| -- | Cannot use a name twice in a type definition.
-- This includes
-- - clash between the type itself and a constructor
-- - clash between the type itself and a parameter
-- - clash between two constructors
-- - clash between two parameters
-- - clash between parameter and constructor
TypeDefModifyNameClash Name
| TypeParamInUse TyConName TyVarName
| ConNotFound ValConName
| ConAlreadyExists ValConName
| -- | We expected to see more arguments to a constructor than actually existed
-- (this should never happen in a well-typed program)
ConNotSaturated ValConName
| ParamNotFound TyVarName
| ParamAlreadyExists TyVarName
| NodeIDNotFound ID
| TyConParamClash Name
| ValConParamClash Name
| ActionError ActionError
| EvalError EvalError
Expand Down
Loading