From 3b47880cad5a4f83200436a823b6f697f8f97f8d Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 15:34:47 +0200 Subject: [PATCH 01/19] Simplify code --- src/Elm.elm | 56 ++++++++++++++++++++++-------------------- src/Elm/Case.elm | 46 +++++++++++++++++----------------- tests/Pattern.elm | 4 +-- tests/TypeChecking.elm | 36 +++++++++++---------------- 4 files changed, 69 insertions(+), 73 deletions(-) diff --git a/src/Elm.elm b/src/Elm.elm index 270b47e5..368bae8a 100644 --- a/src/Elm.elm +++ b/src/Elm.elm @@ -1165,11 +1165,8 @@ presentAndMatching fieldName fieldInference existingFields = if gathered then gathered - else if fieldName == existingFieldName then - True - else - False + fieldName == existingFieldName ) False existingFields @@ -2584,36 +2581,43 @@ determineExposure dec exposedDec = Expose.Explicit nodes -> case dec of Declaration.FunctionDeclaration myFn -> - case Compiler.denode myFn.declaration of - implementation -> - case Compiler.denode implementation.name of - name -> - if List.any (valueIsExposed name) nodes then - Compiler.Exposed { group = Nothing, exposeConstructor = False } + let + implementation = + Compiler.denode myFn.declaration - else - Compiler.NotExposed + name = + Compiler.denode implementation.name + in + if List.any (valueIsExposed name) nodes then + Compiler.Exposed { group = Nothing, exposeConstructor = False } + + else + Compiler.NotExposed Declaration.AliasDeclaration typeAlias -> - case Compiler.denode typeAlias.name of - name -> - if List.any (typeIsExposed name) nodes then - Compiler.Exposed { group = Nothing, exposeConstructor = False } + let + name = + Compiler.denode typeAlias.name + in + if List.any (typeIsExposed name) nodes then + Compiler.Exposed { group = Nothing, exposeConstructor = False } - else - Compiler.NotExposed + else + Compiler.NotExposed Declaration.CustomTypeDeclaration type_ -> - case Compiler.denode type_.name of - name -> - if List.any (typeIsExposed name) nodes then - Compiler.Exposed { group = Nothing, exposeConstructor = False } + let + name = + Compiler.denode type_.name + in + if List.any (typeIsExposed name) nodes then + Compiler.Exposed { group = Nothing, exposeConstructor = False } - else if List.any (typeConstructorIsExposed name) nodes then - Compiler.Exposed { group = Nothing, exposeConstructor = True } + else if List.any (typeConstructorIsExposed name) nodes then + Compiler.Exposed { group = Nothing, exposeConstructor = True } - else - Compiler.NotExposed + else + Compiler.NotExposed Declaration.PortDeclaration sig -> Compiler.NotExposed diff --git a/src/Elm/Case.elm b/src/Elm/Case.elm index fa8ca42c..19e0f8ab 100644 --- a/src/Elm/Case.elm +++ b/src/Elm/Case.elm @@ -444,31 +444,33 @@ result mainExpression branches = (Index.dive index) [ Branch (\branchIndex -> - case branches.ok of - ( okNameStr, toOk ) -> - let - ok = - Compiler.toVarMaybeType branchIndex okNameStr Nothing - in - ( ok.index - , Pattern.NamedPattern { moduleName = [], name = "Ok" } - [ Compiler.nodify (Pattern.VarPattern ok.name) ] - , toOk ok.val - ) + let + ( okNameStr, toOk ) = + branches.ok + + ok = + Compiler.toVarMaybeType branchIndex okNameStr Nothing + in + ( ok.index + , Pattern.NamedPattern { moduleName = [], name = "Ok" } + [ Compiler.nodify (Pattern.VarPattern ok.name) ] + , toOk ok.val + ) ) , Branch (\branchIndex -> - case branches.err of - ( errNameStr, toErr ) -> - let - err = - Compiler.toVarMaybeType branchIndex errNameStr Nothing - in - ( err.index - , Pattern.NamedPattern { moduleName = [], name = "Err" } - [ Compiler.nodify (Pattern.VarPattern err.name) ] - , toErr err.val - ) + let + ( errNameStr, toErr ) = + branches.err + + err = + Compiler.toVarMaybeType branchIndex errNameStr Nothing + in + ( err.index + , Pattern.NamedPattern { moduleName = [], name = "Err" } + [ Compiler.nodify (Pattern.VarPattern err.name) ] + , toErr err.val + ) ) ] in diff --git a/tests/Pattern.elm b/tests/Pattern.elm index 2ae8c93b..f79cdc3c 100644 --- a/tests/Pattern.elm +++ b/tests/Pattern.elm @@ -1,15 +1,13 @@ module Pattern exposing (suite) import Elm exposing (Expression) -import Elm.Annotation as Type exposing (Annotation) +import Elm.Annotation as Type import Elm.Case import Elm.Case.Branch as Pattern import Elm.Expect -import Elm.Let import Elm.Op import Elm.ToString import Expect -import Gen.Maybe import Gen.String import Internal.Compiler as Compiler import Internal.Index as Index diff --git a/tests/TypeChecking.elm b/tests/TypeChecking.elm index a22c9d25..55281f57 100644 --- a/tests/TypeChecking.elm +++ b/tests/TypeChecking.elm @@ -240,12 +240,8 @@ myMap = "Present" ( "present", Type.var "a" ) (\a -> - let - result = - present [] - (Elm.apply fn [ a ]) - in - result + present [] + (Elm.apply fn [ a ]) ) , Elm.Case.branch0 "Null" (null []) , Elm.Case.branch0 "Absent" (absent []) @@ -255,22 +251,18 @@ myMap = present : List String -> Elm.Expression -> Elm.Expression present optionalModuleName a = - let - val = - Elm.apply - (Elm.value - { importFrom = optionalModuleName - , name = "Present" - , annotation = - Just - (Type.function [ Type.var "a2" ] (Type.namedWith optionalModuleName "Optional" [ Type.var "a2" ])) - - -- Nothing - } - ) - [ a ] - in - val + Elm.apply + (Elm.value + { importFrom = optionalModuleName + , name = "Present" + , annotation = + Just + (Type.function [ Type.var "a2" ] (Type.namedWith optionalModuleName "Optional" [ Type.var "a2" ])) + + -- Nothing + } + ) + [ a ] null : List String -> Elm.Expression From b64fd5d4f4bc463a568c857d5bf0fd8ace6b6323 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 15:36:34 +0200 Subject: [PATCH 02/19] Explicit export list --- src/Internal/Compiler.elm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Internal/Compiler.elm b/src/Internal/Compiler.elm index fccb4aa0..fae38026 100644 --- a/src/Internal/Compiler.elm +++ b/src/Internal/Compiler.elm @@ -1,4 +1,4 @@ -module Internal.Compiler exposing (..) +module Internal.Compiler exposing (AliasCache, Annotation(..), AnnotationDetails, Declaration(..), DeclarationDetails, Expose(..), Expression(..), ExpressionDetails, Inference, InferenceError(..), Module, RenderedDeclaration(..), Restrictions(..), VariableCache, Visited, Warning, addAlias, addInference, applyType, denode, denodeAll, denodeMaybe, documentation, emptyAliases, expose, exposeWith, expression, facts, findAlias, fullModName, getAliases, getAnnotation, getAnnotationImports, getGenerics, getImports, getInnerAnnotation, getInnerInference, getTypeModule, importInferences, inference, inferenceErrorToString, makeImport, mergeAliases, mergeInferences, noImports, nodify, nodifyAll, nodifyMaybe, parens, resolve, resolveField, thread, toExpressionDetails, toVar, toVarExactName, toVarMaybeType, toVarWithType, unify, unifyOn) import Dict exposing (Dict) import Elm.Syntax.Declaration as Declaration From 1623654f98253d6d289a12c3dc1ed3e5f2c7d067 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 15:43:34 +0200 Subject: [PATCH 03/19] Second elm-review pass --- src/Elm.elm | 6 +----- src/Elm/Case.elm | 32 ++++++++++++++++---------------- src/Elm/Case/Branch.elm | 2 +- src/Internal/Comments.elm | 4 ++-- src/Internal/Compiler.elm | 30 ++++++++++++++++++------------ src/Internal/Debug.elm | 8 +++----- src/Internal/Index.elm | 4 ++-- src/Internal/Write.elm | 8 +------- tests/Elm/Expect.elm | 2 +- 9 files changed, 45 insertions(+), 51 deletions(-) diff --git a/src/Elm.elm b/src/Elm.elm index 368bae8a..46e15997 100644 --- a/src/Elm.elm +++ b/src/Elm.elm @@ -100,19 +100,15 @@ import Dict import Elm.Annotation import Elm.Parser import Elm.Processing -import Elm.Syntax.Declaration as Declaration exposing (Declaration(..)) +import Elm.Syntax.Declaration as Declaration import Elm.Syntax.Exposing as Expose import Elm.Syntax.Expression as Exp -import Elm.Syntax.Infix as Infix import Elm.Syntax.Module import Elm.Syntax.Node as Node import Elm.Syntax.Pattern as Pattern -import Elm.Syntax.Range as Range import Elm.Syntax.TypeAnnotation as Annotation import Internal.Clean as Clean -import Internal.Comments import Internal.Compiler as Compiler -import Internal.Debug import Internal.Dependencies import Internal.Format as Format import Internal.Index as Index diff --git a/src/Elm/Case.elm b/src/Elm/Case.elm index 19e0f8ab..2f9b9377 100644 --- a/src/Elm/Case.elm +++ b/src/Elm/Case.elm @@ -64,7 +64,7 @@ Generates -} -import Dict exposing (Dict) +import Dict import Elm exposing (Expression) import Elm.Annotation as Type import Elm.Syntax.Expression as Exp @@ -73,7 +73,6 @@ import Elm.Syntax.Pattern as Pattern import Elm.Syntax.TypeAnnotation as Annotation import Internal.Branch as Branch exposing (Branch, Pattern(..)) import Internal.Compiler as Compiler -import Internal.Debug as Debug import Internal.Format as Format import Internal.Index as Index @@ -234,20 +233,21 @@ maybe mainExpression branches = ) , Branch (\branchIndex -> - case branches.just of - ( justVarName, toReturn ) -> - let - just = - Compiler.toVarMaybeType branchIndex justVarName Nothing - in - ( just.index - , Pattern.NamedPattern - { moduleName = [] - , name = "Just" - } - [ Compiler.nodify (Pattern.VarPattern just.name) ] - , toReturn just.val - ) + let + ( justVarName, toReturn ) = + branches.just + + just = + Compiler.toVarMaybeType branchIndex justVarName Nothing + in + ( just.index + , Pattern.NamedPattern + { moduleName = [] + , name = "Just" + } + [ Compiler.nodify (Pattern.VarPattern just.name) ] + , toReturn just.val + ) ) ] in diff --git a/src/Elm/Case/Branch.elm b/src/Elm/Case/Branch.elm index bbe2178c..1df5168a 100644 --- a/src/Elm/Case/Branch.elm +++ b/src/Elm/Case/Branch.elm @@ -134,7 +134,7 @@ These helpers let you define a Custom Type pattern with a builder. import Elm exposing (Expression) import Elm.Annotation as Type -import Elm.Syntax.Node as Node exposing (Node(..)) +import Elm.Syntax.Node exposing (Node) import Elm.Syntax.Pattern as Pattern import Internal.Branch as Branch exposing (Pattern(..)) import Internal.Compiler as Compiler diff --git a/src/Internal/Comments.elm b/src/Internal/Comments.elm index bc232cce..0521bb97 100644 --- a/src/Internal/Comments.elm +++ b/src/Internal/Comments.elm @@ -1,7 +1,7 @@ module Internal.Comments exposing ( Comment, CommentPart(..), DocComment, FileComment , emptyComment, addPart - , prettyDocComment, prettyFileComment + , prettyFileComment ) {-| A component DSL that helps with building comments. @@ -22,7 +22,7 @@ can be extracted to order the exposing clause by. # Pretty printing of comments -@docs prettyDocComment, prettyFileComment +@docs prettyFileComment -} diff --git a/src/Internal/Compiler.elm b/src/Internal/Compiler.elm index fae38026..646166c4 100644 --- a/src/Internal/Compiler.elm +++ b/src/Internal/Compiler.elm @@ -635,9 +635,11 @@ getGenericsHelper ann = Annotation.Record recordDefinition -> List.concatMap (\nodedField -> - case denode nodedField of - ( name, field ) -> - getGenericsHelper (denode field) + let + ( name, field ) = + denode nodedField + in + getGenericsHelper (denode field) ) recordDefinition @@ -645,9 +647,11 @@ getGenericsHelper ann = denode recordName :: List.concatMap (\nodedField -> - case denode nodedField of - ( name, field ) -> - getGenericsHelper (denode field) + let + ( name, field ) = + denode nodedField + in + getGenericsHelper (denode field) ) (denode recordDefinition) @@ -2558,13 +2562,15 @@ getFieldFromList selector fields = Nothing nodifiedTop :: remain -> - case denode nodifiedTop of - ( fieldname, contents ) -> - if denode fieldname == selector then - Just (denode contents) + let + ( fieldname, contents ) = + denode nodifiedTop + in + if denode fieldname == selector then + Just (denode contents) - else - getFieldFromList selector remain + else + getFieldFromList selector remain addInference : diff --git a/src/Internal/Debug.elm b/src/Internal/Debug.elm index c88e7de5..c84b947d 100644 --- a/src/Internal/Debug.elm +++ b/src/Internal/Debug.elm @@ -1,4 +1,4 @@ -module Internal.Debug exposing (annotationFormatted, everything, everythingFormatted, facts) +module Internal.Debug exposing (facts) import Dict import Internal.Compiler as Compiler @@ -59,8 +59,7 @@ everythingFormatted log exp = [ err ] Ok e -> - List.concatMap - identity + List.concat [ [ "Signature" , " " ++ e.signature ] @@ -94,8 +93,7 @@ annotationFormatted log ann = [ err ] Ok e -> - List.concatMap - identity + List.concat [ [ "Signature" , " " ++ e.signature ] diff --git a/src/Internal/Index.elm b/src/Internal/Index.elm index 93703e62..b4009493 100644 --- a/src/Internal/Index.elm +++ b/src/Internal/Index.elm @@ -1,6 +1,6 @@ module Internal.Index exposing ( Index, startIndex, startChecked - , next, nextN, dive + , next, dive , getName, indexToString, protectTypeName , typecheck ) @@ -9,7 +9,7 @@ module Internal.Index exposing @docs Index, startIndex, startChecked -@docs next, nextN, dive +@docs next, dive @docs getName, indexToString, protectTypeName diff --git a/src/Internal/Write.elm b/src/Internal/Write.elm index 4fe83377..b4e65180 100644 --- a/src/Internal/Write.elm +++ b/src/Internal/Write.elm @@ -2,13 +2,11 @@ module Internal.Write exposing ( write , writeAnnotation , writeAnnotationWith - , writeDeclaration , writeDeclarationWith , writeExpression , writeExpressionWith , writeImports , writeInference - , writeSignature , writeSignatureWith ) @@ -813,11 +811,7 @@ adjustExpressionParentheses context expression = True ( False, _, Application _ ) -> - if context.precedence < 11 then - True - - else - False + context.precedence < 11 ( False, _, FunctionOrValue _ _ ) -> True diff --git a/tests/Elm/Expect.elm b/tests/Elm/Expect.elm index 89bb8709..4e155cb0 100644 --- a/tests/Elm/Expect.elm +++ b/tests/Elm/Expect.elm @@ -1,4 +1,4 @@ -module Elm.Expect exposing (declarationAs, equal, fileContentAs, importAs, infersType, renderedAs) +module Elm.Expect exposing (declarationAs, equal, fileContentAs, importAs, renderedAs) import Elm import Elm.ToString From abe39d58c480fbf5d34cfccedab52bae742627bd Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 15:53:51 +0200 Subject: [PATCH 04/19] One more pass --- src/Elm.elm | 53 +++++++++++++---------------- src/Elm/Annotation.elm | 3 +- src/Elm/Case/Branch.elm | 5 ++- src/Elm/Let.elm | 10 +++--- src/Elm/Op.elm | 19 ----------- src/Elm/ToString.elm | 1 - src/Internal/Compiler.elm | 17 ++++----- src/Internal/ImportsAndExposing.elm | 2 +- src/Internal/Render.elm | 2 +- src/Internal/Types.elm | 3 +- src/Internal/Write.elm | 2 +- tests/Pattern.elm | 2 +- 12 files changed, 43 insertions(+), 76 deletions(-) diff --git a/src/Elm.elm b/src/Elm.elm index 46e15997..8b1029cf 100644 --- a/src/Elm.elm +++ b/src/Elm.elm @@ -994,14 +994,14 @@ record fields = |> Annotation.Record , inferences = List.foldl - (\( name, ann ) gathered -> + (\( _, ann ) gathered -> Compiler.mergeInferences ann.inferences gathered ) Dict.empty unified.fieldAnnotations , aliases = List.foldl - (\( name, ann ) gathered -> + (\( _, ann ) gathered -> Compiler.mergeAliases ann.aliases gathered ) Compiler.emptyAliases @@ -1157,7 +1157,7 @@ verifyFieldsHelper existingFields updatedFields = presentAndMatching fieldName fieldInference existingFields = List.foldl - (\(Node.Node _ ( Node.Node _ existingFieldName, Node.Node _ existingFieldType )) gathered -> + (\(Node.Node _ ( Node.Node _ existingFieldName, Node.Node _ _ )) gathered -> if gathered then gathered @@ -1196,7 +1196,7 @@ customType name variants = variants , docs = Nothing , toBody = - \index -> + \_ -> { warning = Nothing , additionalImports = [] , declaration = @@ -1299,7 +1299,7 @@ alias name innerAnnotation = Compiler.getAnnotationImports innerAnnotation , docs = Nothing , toBody = - \index -> + \_ -> { warning = Nothing , additionalImports = [] , declaration = @@ -2084,26 +2084,21 @@ declaration nameStr (Compiler.Expression toBody) = -- (renderDebugDocumentation resolvedType body.annotation) , signature = - case body.annotation of - Ok sig -> - case resolvedType of - Ok (Annotation.GenericType generic) -> - -- Top level values can't be lonely generic types. - Nothing - - Ok finalType -> - Just - (Compiler.nodify - { name = Compiler.nodify name - , typeAnnotation = - Compiler.nodify (Clean.clean finalType) - } - ) + case ( body.annotation, resolvedType ) of + ( Ok _, Ok (Annotation.GenericType _) ) -> + -- Top level values can't be lonely generic types. + Nothing - Err errMsg -> - Nothing + ( Ok _, Ok finalType ) -> + Just + (Compiler.nodify + { name = Compiler.nodify name + , typeAnnotation = + Compiler.nodify (Clean.clean finalType) + } + ) - Err _ -> + _ -> Nothing , declaration = case body.expression of @@ -2153,7 +2148,7 @@ functionAdvanced args fullExpression = Exp.LambdaExpression { args = List.map - (\( name, ann ) -> Compiler.nodify (Pattern.VarPattern name)) + (\( name, _ ) -> Compiler.nodify (Pattern.VarPattern name)) args , expression = Compiler.nodify expr.expression } @@ -2166,7 +2161,7 @@ functionAdvanced args fullExpression = Ok { type_ = List.foldr - (\( name, Compiler.Annotation ann ) fnbody -> + (\( _, Compiler.Annotation ann ) fnbody -> Annotation.FunctionTypeAnnotation (Compiler.nodify ann.annotation) (Compiler.nodify fnbody) @@ -2367,7 +2362,7 @@ portIncoming nameStr args = List.concatMap Compiler.getAnnotationImports args , docs = Nothing , toBody = - \index -> + \_ -> { warning = Nothing , additionalImports = [] , declaration = @@ -2437,7 +2432,7 @@ portOutgoing nameStr arg = Compiler.getAnnotationImports arg , docs = Nothing , toBody = - \index -> + \_ -> { warning = Nothing , additionalImports = [] , declaration = @@ -2504,7 +2499,7 @@ parse source = [] , docs = Nothing , toBody = - \index -> + \_ -> { warning = Nothing , additionalImports = [] , declaration = @@ -2663,7 +2658,7 @@ typeConstructorIsExposed name node = Expose.InfixExpose _ -> False - Expose.FunctionExpose fnName -> + Expose.FunctionExpose _ -> False Expose.TypeOrAliasExpose typeName -> diff --git a/src/Elm/Annotation.elm b/src/Elm/Annotation.elm index 121f9c5c..0d300ff6 100644 --- a/src/Elm/Annotation.elm +++ b/src/Elm/Annotation.elm @@ -223,8 +223,7 @@ alias mod name vars target = List.concatMap Compiler.getAnnotationImports vars _ -> - [ mod ] - ++ List.concatMap Compiler.getAnnotationImports vars + mod :: List.concatMap Compiler.getAnnotationImports vars , aliases = List.foldl (\ann aliases -> diff --git a/src/Elm/Case/Branch.elm b/src/Elm/Case/Branch.elm index 1df5168a..faa23055 100644 --- a/src/Elm/Case/Branch.elm +++ b/src/Elm/Case/Branch.elm @@ -133,7 +133,6 @@ These helpers let you define a Custom Type pattern with a builder. -} import Elm exposing (Expression) -import Elm.Annotation as Type import Elm.Syntax.Node exposing (Node) import Elm.Syntax.Pattern as Pattern import Internal.Branch as Branch exposing (Pattern(..)) @@ -786,7 +785,7 @@ list { patterns, gather, startWith, finally } = let ( finalIndex, itemPatterns, finalGathered ) = List.foldl - (\((Branch toBranch) as branch) ( index, patternList, gathered ) -> + (\(Branch toBranch) ( index, patternList, gathered ) -> let ( newIndex, pattern, value ) = toBranch index @@ -863,7 +862,7 @@ listWithRemaining { patterns, gather, startWith, remaining, finally } = ( finalIndex, itemPatterns, finalGathered ) = List.foldl - (\((Branch toBranch) as branch) ( index, patternList, gathered ) -> + (\(Branch toBranch) ( index, patternList, gathered ) -> let ( newIndex, pattern, value ) = toBranch index diff --git a/src/Elm/Let.elm b/src/Elm/Let.elm index 5f736fe4..53b3c417 100644 --- a/src/Elm/Let.elm +++ b/src/Elm/Let.elm @@ -219,7 +219,7 @@ value desiredName valueExpr sourceLet = , index = finalIndex , return = Compiler.Expression - (\i -> + (\_ -> { details | expression = Exp.FunctionOrValue [] @@ -285,7 +285,7 @@ fn desiredName ( desiredArg, argAnnotation ) toInnerFn sourceLet = \callerArg -> Elm.apply (Compiler.Expression - (\i -> + (\_ -> { innerFnDetails | expression = Exp.FunctionOrValue [] @@ -366,7 +366,7 @@ fn2 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) toInnerFn \oneIncoming twoIncoming -> Elm.apply (Compiler.Expression - (\i -> + (\_ -> { innerFnDetails | expression = Exp.FunctionOrValue [] @@ -461,7 +461,7 @@ fn3 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) ( threeDes \oneIncoming twoIncoming threeIncoming -> Elm.apply (Compiler.Expression - (\i -> + (\_ -> { innerFnDetails | expression = Exp.FunctionOrValue [] @@ -584,7 +584,7 @@ record fields recordExp sourceLet = ( finalIndex, unpackedfields ) = List.foldl - (\fieldName ( i, gathered ) -> + (\fieldName ( _, gathered ) -> let ( gotIndex, got ) = Elm.get fieldName recordExp diff --git a/src/Elm/Op.elm b/src/Elm/Op.elm index 72f61e81..eeea33b3 100644 --- a/src/Elm/Op.elm +++ b/src/Elm/Op.elm @@ -57,25 +57,12 @@ Would generate import Dict import Elm exposing (Expression) -import Elm.Annotation -import Elm.Parser -import Elm.Processing -import Elm.Syntax.Declaration as Declaration exposing (Declaration(..)) -import Elm.Syntax.Exposing as Expose import Elm.Syntax.Expression as Exp import Elm.Syntax.Infix as Infix -import Elm.Syntax.Module -import Elm.Syntax.Node as Node -import Elm.Syntax.Pattern as Pattern -import Elm.Syntax.Range as Range import Elm.Syntax.TypeAnnotation as Annotation -import Internal.Comments import Internal.Compiler as Compiler -import Internal.Debug import Internal.Index as Index import Internal.Types -import Internal.Write -import Set @@ -494,9 +481,6 @@ applyPipe (BinOp symbol dir _) infixAnnotation l r = ( rightIndex, right ) = Compiler.toExpressionDetails leftIndex r - - annotationIndex = - Index.next rightIndex in { expression = Exp.OperatorApplication symbol @@ -548,9 +532,6 @@ applyInfix extraImports (BinOp symbol dir _) infixAnnotation l r = ( rightIndex, right ) = Compiler.toExpressionDetails leftIndex r - - annotationIndex = - Index.next rightIndex in { expression = Exp.OperatorApplication symbol diff --git a/src/Elm/ToString.elm b/src/Elm/ToString.elm index 011a7be9..d3127210 100644 --- a/src/Elm/ToString.elm +++ b/src/Elm/ToString.elm @@ -22,7 +22,6 @@ import Elm exposing (Declaration, Expression) import Elm.Annotation exposing (Annotation) import Elm.Syntax.Declaration as Declaration import Elm.Syntax.Node as Node exposing (Node(..)) -import Elm.Writer import Internal.Clean as Clean import Internal.Compiler as Compiler import Internal.Index as Index diff --git a/src/Internal/Compiler.elm b/src/Internal/Compiler.elm index 646166c4..cafd81e5 100644 --- a/src/Internal/Compiler.elm +++ b/src/Internal/Compiler.elm @@ -1,4 +1,4 @@ -module Internal.Compiler exposing (AliasCache, Annotation(..), AnnotationDetails, Declaration(..), DeclarationDetails, Expose(..), Expression(..), ExpressionDetails, Inference, InferenceError(..), Module, RenderedDeclaration(..), Restrictions(..), VariableCache, Visited, Warning, addAlias, addInference, applyType, denode, denodeAll, denodeMaybe, documentation, emptyAliases, expose, exposeWith, expression, facts, findAlias, fullModName, getAliases, getAnnotation, getAnnotationImports, getGenerics, getImports, getInnerAnnotation, getInnerInference, getTypeModule, importInferences, inference, inferenceErrorToString, makeImport, mergeAliases, mergeInferences, noImports, nodify, nodifyAll, nodifyMaybe, parens, resolve, resolveField, thread, toExpressionDetails, toVar, toVarExactName, toVarMaybeType, toVarWithType, unify, unifyOn) +module Internal.Compiler exposing (AliasCache, Annotation(..), AnnotationDetails, Declaration(..), DeclarationDetails, Expose(..), Expression(..), ExpressionDetails, Inference, InferenceError(..), Module, RenderedDeclaration(..), Restrictions(..), VariableCache, Visited, Warning, addAlias, addInference, applyType, denode, denodeAll, denodeMaybe, documentation, emptyAliases, expose, exposeWith, expression, facts, findAlias, fullModName, getAliases, getAnnotation, getAnnotationImports, getGenerics, getImports, getInnerAnnotation, getInnerInference, getTypeModule, importInferences, inference, inferenceErrorToString, makeImport, mergeAliases, mergeInferences, noImports, nodify, nodifyAll, parens, resolve, resolveField, thread, toExpressionDetails, toVar, toVarExactName, toVarMaybeType, toVarWithType, unify, unifyOn) import Dict exposing (Dict) import Elm.Syntax.Declaration as Declaration @@ -6,10 +6,9 @@ import Elm.Syntax.Exposing as Expose import Elm.Syntax.Expression as Exp import Elm.Syntax.ModuleName as ModuleName import Elm.Syntax.Node as Node exposing (Node(..)) -import Elm.Syntax.Range as Range exposing (emptyRange) +import Elm.Syntax.Range as Range import Elm.Syntax.TypeAnnotation as Annotation import Elm.Writer -import Error.Format import Internal.Format as Format import Internal.Index as Index exposing (Index) import Set exposing (Set) @@ -303,7 +302,7 @@ toVar index desiredName = , index = newIndex , val = Expression <| - \ignoredIndex_ -> + \_ -> { expression = Exp.FunctionOrValue [] name @@ -339,7 +338,7 @@ toVarExactName index name = , index = Index.next index , val = Expression <| - \ignoredIndex_ -> + \_ -> { expression = Exp.FunctionOrValue [] name @@ -387,7 +386,7 @@ toVarMaybeType index desiredName maybeAnnotation = , index = newIndex , val = Expression <| - \ignoredIndex_ -> + \_ -> { expression = Exp.FunctionOrValue [] name @@ -422,7 +421,7 @@ toVarWithType index desiredName (Annotation ann) = , index = newIndex , exp = Expression <| - \ignoredIndex_ -> + \_ -> { expression = Exp.FunctionOrValue [] name @@ -1237,10 +1236,6 @@ resolveVariables visited cache annotation = Err err Ok resolvedField -> - let - restrictions = - getRestrictions annotation cache - in Ok (Node fieldRange ( name, Node fieldTypeRange resolvedField ) diff --git a/src/Internal/ImportsAndExposing.elm b/src/Internal/ImportsAndExposing.elm index 8910b17e..a1e87b76 100644 --- a/src/Internal/ImportsAndExposing.elm +++ b/src/Internal/ImportsAndExposing.elm @@ -1,6 +1,6 @@ module Internal.ImportsAndExposing exposing (sortAndDedupExposings, sortAndDedupImports) -import Elm.Syntax.Exposing exposing (ExposedType, Exposing(..), TopLevelExpose(..)) +import Elm.Syntax.Exposing exposing (Exposing(..), TopLevelExpose(..)) import Elm.Syntax.Import exposing (Import) import Elm.Syntax.Node as Node exposing (Node(..)) import Elm.Syntax.Range exposing (emptyRange) diff --git a/src/Internal/Render.elm b/src/Internal/Render.elm index e085a23b..aa31b44d 100644 --- a/src/Internal/Render.elm +++ b/src/Internal/Render.elm @@ -10,7 +10,7 @@ import Internal.Comments import Internal.Compiler as Compiler import Internal.Index as Index import Internal.Write -import Set exposing (Set) +import Set {-| -} diff --git a/src/Internal/Types.elm b/src/Internal/Types.elm index 22d7d860..b2c7b9e8 100644 --- a/src/Internal/Types.elm +++ b/src/Internal/Types.elm @@ -1,9 +1,8 @@ module Internal.Types exposing (appendable, bool, char, comparable, custom, float, function, int, list, string, var) -import Elm.Syntax.Node as Node exposing (Node(..)) +import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.Range as Range import Elm.Syntax.TypeAnnotation as Annotation -import Internal.Compiler exposing (Annotation) import Internal.Format as Format diff --git a/src/Internal/Write.elm b/src/Internal/Write.elm index b4e65180..7d141f5a 100644 --- a/src/Internal/Write.elm +++ b/src/Internal/Write.elm @@ -35,7 +35,7 @@ import Elm.Syntax.TypeAlias exposing (TypeAlias) import Elm.Syntax.TypeAnnotation exposing (RecordDefinition, RecordField, TypeAnnotation(..)) import Hex import Internal.Comments as Comments -import Internal.Compiler as Util exposing (denode, denodeAll, denodeMaybe, nodify, nodifyAll, nodifyMaybe) +import Internal.Compiler as Util exposing (denode, denodeAll, denodeMaybe, nodify) import Internal.ImportsAndExposing as ImportsAndExposing import Pretty exposing (Doc) diff --git a/tests/Pattern.elm b/tests/Pattern.elm index f79cdc3c..072ec52b 100644 --- a/tests/Pattern.elm +++ b/tests/Pattern.elm @@ -89,7 +89,7 @@ suite = Type.unit [ Pattern.triple (Pattern.unit ()) (Pattern.var "name") (Pattern.int 123 (Elm.int 123)) |> Pattern.map - (\( (), name, literalInt ) -> + (\( (), _, _ ) -> Elm.unit ) ] From 02968a4ab1fa435c16ff71b44716a2bfd154d21a Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 16:03:15 +0200 Subject: [PATCH 05/19] Unused imports, bindings --- src/Elm.elm | 64 ++++++++++++++--------------- src/Elm/Case.elm | 2 +- src/Elm/Case/Branch.elm | 2 +- src/Elm/Let.elm | 6 +-- src/Elm/Op.elm | 4 +- src/Internal/Clean.elm | 6 +-- src/Internal/Compiler.elm | 62 ++++++++++++++-------------- src/Internal/ImportsAndExposing.elm | 4 +- src/Internal/Render.elm | 4 +- src/Internal/Write.elm | 31 ++++++-------- tests/Declare.elm | 13 +----- tests/File.elm | 13 ------ tests/Let.elm | 9 ---- tests/PackageHelpers.elm | 5 +-- tests/TypeChecking.elm | 4 +- 15 files changed, 93 insertions(+), 136 deletions(-) diff --git a/src/Elm.elm b/src/Elm.elm index 8b1029cf..6912b8a6 100644 --- a/src/Elm.elm +++ b/src/Elm.elm @@ -363,7 +363,7 @@ withType ((Compiler.Annotation annDetails) as ann) (Compiler.Expression toExp) = , aliases = expressionAnnotation.aliases } - Err err -> + Err _ -> Ok { type_ = annDetails.annotation , inferences = Dict.empty @@ -581,7 +581,7 @@ tuple oneExp twoExp = ( oneIndex, one ) = Compiler.toExpressionDetails index oneExp - ( twoIndex, two ) = + ( _, two ) = Compiler.toExpressionDetails oneIndex twoExp in { expression = @@ -623,7 +623,7 @@ triple oneExp twoExp threeExp = ( twoIndex, two ) = Compiler.toExpressionDetails oneIndex twoExp - ( threeIndex, three ) = + ( _, three ) = Compiler.toExpressionDetails twoIndex threeExp in { expression = @@ -889,7 +889,7 @@ updateRecord fields recordExpression = ) } - otherwise -> + _ -> recordExp.annotation otherwise -> @@ -949,11 +949,11 @@ record fields = Err errs -> errs ++ found.errors - Ok ann -> + Ok _ -> found.errors , fieldAnnotations = case exp.annotation of - Err err -> + Err _ -> found.fieldAnnotations Ok ann -> @@ -1061,7 +1061,7 @@ ifThen condition thenBranch elseBranch = ( thenIndex, thenB ) = Compiler.toExpressionDetails condIndex thenBranch - ( finalIndex, elseB ) = + ( _, elseB ) = Compiler.toExpressionDetails thenIndex elseBranch in { expression = @@ -1157,7 +1157,7 @@ verifyFieldsHelper existingFields updatedFields = presentAndMatching fieldName fieldInference existingFields = List.foldl - (\(Node.Node _ ( Node.Node _ existingFieldName, Node.Node _ _ )) gathered -> + (\(Node.Node _ ( Node.Node _ existingFieldName, _ )) gathered -> if gathered then gathered @@ -1406,7 +1406,7 @@ fn ( oneBaseName, maybeAnnotation ) toExpression = } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1469,7 +1469,7 @@ functionReduced argBaseName toExpression = } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1599,7 +1599,7 @@ fn2 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) toExpression = two = Compiler.toVarMaybeType one.index twoBaseName maybeTwoType - ( newIndex_, return ) = + ( _, return ) = Compiler.toExpressionDetails two.index (toExpression one.val two.val) in { expression = @@ -1612,7 +1612,7 @@ fn2 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) toExpression = } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1655,7 +1655,7 @@ fn3 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, three = Compiler.toVarMaybeType two.index threeBaseName maybeThreeType - ( newIndex, return ) = + ( _, return ) = Compiler.toExpressionDetails three.index (toExpression one.val two.val three.val) in { expression = @@ -1669,7 +1669,7 @@ fn3 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1721,7 +1721,7 @@ fn4 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, four = Compiler.toVarMaybeType three.index fourBaseName maybeFourType - ( newIndex, return ) = + ( _, return ) = Compiler.toExpressionDetails four.index (toExpression one.val two.val three.val four.val) in { expression = @@ -1736,7 +1736,7 @@ fn4 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1797,7 +1797,7 @@ fn5 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, five = Compiler.toVarMaybeType four.index fiveBaseName maybeFiveType - ( newIndex, return ) = + ( _, return ) = Compiler.toExpressionDetails five.index (toExpression one.val two.val three.val four.val five.val) in { expression = @@ -1813,7 +1813,7 @@ fn5 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1883,7 +1883,7 @@ fn6 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, six = Compiler.toVarMaybeType five.index sixBaseName maybeSixType - ( newIndex, return ) = + ( _, return ) = Compiler.toExpressionDetails five.index (toExpression one.val two.val three.val four.val five.val six.val) in { expression = @@ -1900,7 +1900,7 @@ fn6 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, } , annotation = case return.annotation of - Err err -> + Err _ -> return.annotation Ok returnAnnotation -> @@ -1970,9 +1970,9 @@ renderDocumentation : -> Maybe String renderDocumentation resolvedType bodyAnnotation = case resolvedType of - Ok sig -> + Ok _ -> case bodyAnnotation of - Ok inference -> + Ok _ -> Nothing Err err -> @@ -1991,7 +1991,7 @@ sep = renderDebugDocumentation resolvedType bodyAnnotation = case resolvedType of - Ok sig -> + Ok _ -> case bodyAnnotation of Ok inference -> Just (Internal.Write.writeInference inference) @@ -2052,9 +2052,9 @@ declaration nameStr (Compiler.Expression toBody) = maybeWarning = case resolvedType of - Ok sig -> + Ok _ -> case body.annotation of - Ok inference -> + Ok _ -> Nothing Err [] -> @@ -2376,7 +2376,7 @@ portIncoming nameStr args = (Compiler.nodify (Annotation.GenericType "msg")) (Compiler.nodify sub) - start :: remain -> + _ :: _ -> Annotation.FunctionTypeAnnotation (groupAnn (Compiler.nodify @@ -2470,7 +2470,7 @@ unsafe source = parse : String -> Result String { declarations : List Declaration } parse source = case Elm.Parser.parse source of - Err deadends -> + Err _ -> Err "Uh oh" Ok raw -> @@ -2548,7 +2548,7 @@ decName decBody = Compiler.denode myPort.name |> Just - Declaration.InfixDeclaration inf -> + Declaration.InfixDeclaration _ -> Nothing Declaration.Destructuring _ _ -> @@ -2610,13 +2610,13 @@ determineExposure dec exposedDec = else Compiler.NotExposed - Declaration.PortDeclaration sig -> + Declaration.PortDeclaration _ -> Compiler.NotExposed - Declaration.InfixDeclaration infixDec -> + Declaration.InfixDeclaration _ -> Compiler.NotExposed - Declaration.Destructuring pattern exp -> + Declaration.Destructuring _ _ -> Compiler.NotExposed @@ -2642,7 +2642,7 @@ typeIsExposed name node = Expose.InfixExpose _ -> False - Expose.FunctionExpose fnName -> + Expose.FunctionExpose _ -> False Expose.TypeOrAliasExpose typeName -> diff --git a/src/Elm/Case.elm b/src/Elm/Case.elm index 2f9b9377..0db5c019 100644 --- a/src/Elm/Case.elm +++ b/src/Elm/Case.elm @@ -162,7 +162,7 @@ captureCaseHelper mainCaseExpressionModule (Branch toBranch) accum = _ -> originalPattern - ( newIndex, exp ) = + ( _, exp ) = Compiler.toExpressionDetails branchIndex caseExpression in { index = accum.index diff --git a/src/Elm/Case/Branch.elm b/src/Elm/Case/Branch.elm index faa23055..4285d7bd 100644 --- a/src/Elm/Case/Branch.elm +++ b/src/Elm/Case/Branch.elm @@ -857,7 +857,7 @@ listWithRemaining { patterns, gather, startWith, remaining, finally } = (Branch toRemaining) = remaining - ( restIndex, restPattern, remainingValue ) = + ( _, restPattern, remainingValue ) = toRemaining startIndex ( finalIndex, itemPatterns, finalGathered ) = diff --git a/src/Elm/Let.elm b/src/Elm/Let.elm index 53b3c417..a58d1748 100644 --- a/src/Elm/Let.elm +++ b/src/Elm/Let.elm @@ -523,7 +523,7 @@ tuple desiredNameOne desiredNameTwo valueExpr sourceLet = Ok inference -> case inference.type_ of - Annotation.Tupled [ Node.Node _ oneType, Node.Node _ twoType ] -> + Annotation.Tupled [ Node.Node _ oneType, _ ] -> Ok { type_ = oneType , inferences = Dict.empty @@ -547,7 +547,7 @@ tuple desiredNameOne desiredNameTwo valueExpr sourceLet = Ok inference -> case inference.type_ of - Annotation.Tupled [ Node.Node _ oneType, Node.Node _ twoType ] -> + Annotation.Tupled [ _, Node.Node _ twoType ] -> Ok { type_ = twoType , inferences = Dict.empty @@ -636,7 +636,7 @@ toExpression (Let toScope) = scope = toScope index - ( returnIndex, return ) = + ( _, return ) = Compiler.toExpressionDetails scope.index scope.return in { expression = diff --git a/src/Elm/Op.elm b/src/Elm/Op.elm index eeea33b3..f5c0c31c 100644 --- a/src/Elm/Op.elm +++ b/src/Elm/Op.elm @@ -479,7 +479,7 @@ applyPipe (BinOp symbol dir _) infixAnnotation l r = ( leftIndex, left ) = Compiler.toExpressionDetails index l - ( rightIndex, right ) = + ( _, right ) = Compiler.toExpressionDetails leftIndex r in { expression = @@ -530,7 +530,7 @@ applyInfix extraImports (BinOp symbol dir _) infixAnnotation l r = ( leftIndex, left ) = Compiler.toExpressionDetails index l - ( rightIndex, right ) = + ( _, right ) = Compiler.toExpressionDetails leftIndex r in { expression = diff --git a/src/Internal/Clean.elm b/src/Internal/Clean.elm index 0d678654..18a9a895 100644 --- a/src/Internal/Clean.elm +++ b/src/Internal/Clean.elm @@ -65,7 +65,7 @@ sanitized str = [] -> str - top :: remain -> + top :: _ -> top @@ -75,7 +75,7 @@ prepareRename ann dict = Type.GenericType generic -> dict |> Set.insert generic - Type.Typed name nodedVars -> + Type.Typed _ nodedVars -> List.foldl (\(Node.Node _ tipe) d -> prepareRename tipe d) dict nodedVars Type.Unit -> @@ -87,7 +87,7 @@ prepareRename ann dict = Type.Record record -> List.foldl (\(Node.Node _ ( _, Node.Node _ field )) d -> prepareRename field d) dict record - Type.GenericRecord name (Node.Node range record) -> + Type.GenericRecord _ (Node.Node _ record) -> List.foldl (\(Node.Node _ ( _, Node.Node _ field )) d -> prepareRename field d) dict record Type.FunctionTypeAnnotation (Node.Node _ one) (Node.Node _ two) -> diff --git a/src/Internal/Compiler.elm b/src/Internal/Compiler.elm index cafd81e5..2b87faa8 100644 --- a/src/Internal/Compiler.elm +++ b/src/Internal/Compiler.elm @@ -29,7 +29,7 @@ type alias AnnotationDetails = getTypeModule : Annotation -> List String getTypeModule (Annotation annotation) = case annotation.annotation of - Annotation.Typed (Node _ ( mod, typeName )) _ -> + Annotation.Typed (Node _ ( mod, _ )) _ -> mod _ -> @@ -182,7 +182,7 @@ parens expr = Exp.UnitExpr -> expr - Exp.Integer i -> + Exp.Integer _ -> expr Exp.Literal _ -> @@ -448,7 +448,7 @@ mergeInferences one two = case oneVal of Annotation.GenericRecord recordName (Node.Node oneRange recordDefinition) -> case twoVal of - Annotation.GenericRecord twoRecordName (Node.Node twoRange twoRecordDefinition) -> + Annotation.GenericRecord _ (Node.Node _ twoRecordDefinition) -> Dict.insert key (Annotation.GenericRecord recordName (Node.Node oneRange (recordDefinition ++ twoRecordDefinition)) @@ -530,7 +530,7 @@ inferenceErrorToString inf = |> Elm.Writer.write ) - RecordUpdateIncorrectFields details -> + RecordUpdateIncorrectFields _ -> "Mismatched record update" EmptyCaseStatement -> @@ -622,7 +622,7 @@ getGenericsHelper ann = Annotation.GenericType str -> [ str ] - Annotation.Typed modName anns -> + Annotation.Typed _ anns -> List.concatMap (getGenericsHelper << denode) anns Annotation.Unit -> @@ -635,7 +635,7 @@ getGenericsHelper ann = List.concatMap (\nodedField -> let - ( name, field ) = + ( _, field ) = denode nodedField in getGenericsHelper (denode field) @@ -647,7 +647,7 @@ getGenericsHelper ann = :: List.concatMap (\nodedField -> let - ( name, field ) = + ( _, field ) = denode nodedField in getGenericsHelper (denode field) @@ -723,7 +723,7 @@ documentation rawDoc decl = Comment _ -> decl - Block source -> + Block _ -> decl Declaration details -> @@ -1403,7 +1403,7 @@ getRestrictionsHelper : -> Restrictions getRestrictionsHelper existingRestrictions notation cache = case notation of - Annotation.FunctionTypeAnnotation (Node.Node oneCoords one) (Node.Node twoCoords two) -> + Annotation.FunctionTypeAnnotation _ _ -> existingRestrictions Annotation.GenericType name -> @@ -1414,19 +1414,19 @@ getRestrictionsHelper existingRestrictions notation cache = ) cache - Annotation.Typed nodedModuleName vars -> + Annotation.Typed _ _ -> existingRestrictions Annotation.Unit -> existingRestrictions - Annotation.Tupled nodes -> + Annotation.Tupled _ -> existingRestrictions - Annotation.Record fields -> + Annotation.Record _ -> existingRestrictions - Annotation.GenericRecord baseName (Node recordNode fields) -> + Annotation.GenericRecord _ _ -> existingRestrictions @@ -1481,13 +1481,13 @@ rewriteTypeVariablesHelper existing renames type_ = Annotation.Unit -> ( renames, type_ ) - Annotation.Tupled valsA -> + Annotation.Tupled _ -> ( renames, type_ ) - Annotation.Record fieldsA -> + Annotation.Record _ -> ( renames, type_ ) - Annotation.GenericRecord (Node.Node _ reVarName) (Node.Node fieldsARange fieldsA) -> + Annotation.GenericRecord _ _ -> ( renames, type_ ) Annotation.FunctionTypeAnnotation one two -> @@ -1706,7 +1706,7 @@ applyTypeHelper aliases cache fn args = (denode two) rest - ( varCache, Err err ) -> + ( _, Err err ) -> Err [ err ] @@ -1832,7 +1832,7 @@ unifyHelper exps existing = case top.annotation of Ok ann -> case unifiable ann.aliases ann.inferences ann.type_ existing.type_ of - ( _, Err err ) -> + ( _, Err _ ) -> Err [ MismatchedList ann.type_ existing.type_ ] @@ -1920,12 +1920,12 @@ unifyWithAlias aliases vars typename typeVars typeToUnifyWith = typeToUnifyWith in case unifiedResult of - Ok finalInference -> + Ok _ -> -- We want to maintain the declared alias in the type signature -- So, we are using `unifiable` to check that Just ( returnedVars, Ok fullAliasedType ) - Err err -> + Err _ -> Nothing @@ -2070,7 +2070,7 @@ unifiable aliases vars one two = ( newVars, Err err ) -> ( newVars, Err err ) - Just knownType -> + Just _ -> -- NOTE: we should probably check knownType in some way? case unifiableFields aliases vars fieldsA fieldsB [] of ( newVars, Ok unifiedFields ) -> @@ -2102,7 +2102,7 @@ unifiable aliases vars one two = _ -> ( vars, Err (UnableToUnify one two) ) - Annotation.GenericRecord (Node.Node _ reVarName) (Node.Node fieldsARange fieldsA) -> + Annotation.GenericRecord _ (Node.Node _ fieldsA) -> case two of Annotation.GenericType b -> case Dict.get b vars of @@ -2129,7 +2129,7 @@ unifiable aliases vars one two = ( newVars, Err err ) -> ( newVars, Err err ) - Just knownType -> + Just _ -> -- NOTE: we should probably check knownType in some way? case unifiableFields aliases vars fieldsA fieldsB [] of ( newVars, Ok unifiedFields ) -> @@ -2300,7 +2300,7 @@ unifiableLists aliases vars one two unified = ( newVars, Ok un ) -> unifiableLists aliases newVars oneRemain twoRemain (un :: unified) - ( newVars, Err err ) -> + ( _, Err err ) -> ( vars, Err err ) _ -> @@ -2324,7 +2324,7 @@ unifyNumber vars numberName two = , Ok two ) - Annotation.GenericType twoVarName -> + Annotation.GenericType _ -> -- We don't know how this will resolve -- So, for now we say this is fine -- and in the resolveVariables step, we need to check that everything works @@ -2360,7 +2360,7 @@ unifyAppendable vars numberName two = , Ok two ) - Annotation.GenericType twoVarName -> + Annotation.GenericType _ -> -- We don't know how this will resolve -- So, for now we say this is fine -- and in the resolveVariables step, we need to check that everything works @@ -2398,7 +2398,7 @@ isAppendable annotation = Annotation.Typed (Node.Node _ ( [], "String" )) _ -> True - Annotation.Typed (Node.Node _ ( [], "List" )) [ Node.Node _ inner ] -> + Annotation.Typed (Node.Node _ ( [], "List" )) [ _ ] -> True _ -> @@ -2444,7 +2444,7 @@ unifyComparable vars comparableName two = else case two of - Annotation.GenericType twoVarName -> + Annotation.GenericType _ -> -- We don't know how this will resolve -- So, for now we say this is fine -- and in the resolveVariables step, we need to check that everything works @@ -2480,7 +2480,7 @@ resolveField index type_ aliases inferences fieldName = } ] - Annotation.GenericRecord name fields -> + Annotation.GenericRecord _ fields -> case getFieldFromList fieldName (denode fields) of Just ann -> Ok @@ -2506,7 +2506,7 @@ resolveField index type_ aliases inferences fieldName = , fieldName = fieldName } - Annotation.Typed nodedModAndName vars -> + Annotation.Typed nodedModAndName _ -> case getAlias nodedModAndName aliases of Nothing -> Err @@ -2582,7 +2582,7 @@ addInference key value infs = Just (Annotation.GenericRecord (Node.Node range recordName) (Node.Node fieldRange fields)) -> case value of - Annotation.GenericRecord (Node.Node existingRange existingRecordName) (Node.Node existingFieldRange existingFields) -> + Annotation.GenericRecord _ (Node.Node _ existingFields) -> Just (Annotation.GenericRecord (Node.Node range recordName) diff --git a/src/Internal/ImportsAndExposing.elm b/src/Internal/ImportsAndExposing.elm index a1e87b76..32939681 100644 --- a/src/Internal/ImportsAndExposing.elm +++ b/src/Internal/ImportsAndExposing.elm @@ -29,7 +29,7 @@ topLevelExposeOrder tlel tler = ( _, InfixExpose _ ) -> GT - ( _, _ ) -> + _ -> compare (topLevelExposeName tlel) (topLevelExposeName tler) @@ -102,7 +102,7 @@ combineTopLevelExposes exposes = _ -> exp - ( _, _ ) -> + _ -> result ) hd diff --git a/src/Internal/Render.elm b/src/Internal/Render.elm index aa31b44d..086dad7b 100644 --- a/src/Internal/Render.elm +++ b/src/Internal/Render.elm @@ -223,7 +223,7 @@ addDocs maybeDoc decl = (Compiler.nodify doc) } - Elm.Syntax.Declaration.PortDeclaration sig -> + Elm.Syntax.Declaration.PortDeclaration _ -> decl Elm.Syntax.Declaration.InfixDeclaration _ -> @@ -280,7 +280,7 @@ addExposed exposed declaration otherExposes = Expose.FunctionExpose typeName :: otherExposes - Elm.Syntax.Declaration.InfixDeclaration inf -> + Elm.Syntax.Declaration.InfixDeclaration _ -> otherExposes Elm.Syntax.Declaration.Destructuring _ _ -> diff --git a/src/Internal/Write.elm b/src/Internal/Write.elm index 7d141f5a..acdc8652 100644 --- a/src/Internal/Write.elm +++ b/src/Internal/Write.elm @@ -19,20 +19,18 @@ Thank you Rupert! import Dict import Elm.Syntax.Declaration import Elm.Syntax.Documentation exposing (Documentation) -import Elm.Syntax.Exposing exposing (ExposedType, Exposing(..), TopLevelExpose(..)) -import Elm.Syntax.Expression exposing (Case, CaseBlock, Expression(..), Function, FunctionImplementation, Lambda, LetBlock, LetDeclaration(..), RecordSetter) -import Elm.Syntax.File +import Elm.Syntax.Exposing exposing (Exposing(..), TopLevelExpose(..)) +import Elm.Syntax.Expression exposing (CaseBlock, Expression(..), Function, FunctionImplementation, Lambda, LetBlock, LetDeclaration(..), RecordSetter) import Elm.Syntax.Import exposing (Import) import Elm.Syntax.Infix exposing (Infix, InfixDirection(..)) import Elm.Syntax.Module exposing (DefaultModuleData, EffectModuleData, Module(..)) import Elm.Syntax.ModuleName exposing (ModuleName) -import Elm.Syntax.Node as Node exposing (Node(..)) -import Elm.Syntax.Pattern exposing (Pattern(..), QualifiedNameRef) -import Elm.Syntax.Range exposing (Location, Range, emptyRange) +import Elm.Syntax.Node exposing (Node) +import Elm.Syntax.Pattern exposing (Pattern(..)) import Elm.Syntax.Signature exposing (Signature) import Elm.Syntax.Type exposing (Type, ValueConstructor) import Elm.Syntax.TypeAlias exposing (TypeAlias) -import Elm.Syntax.TypeAnnotation exposing (RecordDefinition, RecordField, TypeAnnotation(..)) +import Elm.Syntax.TypeAnnotation exposing (RecordField, TypeAnnotation(..)) import Hex import Internal.Comments as Comments import Internal.Compiler as Util exposing (denode, denodeAll, denodeMaybe, nodify) @@ -72,7 +70,7 @@ prepareLayout width file = Just fileComment -> let - ( fileCommentStr, innerTags ) = + ( fileCommentStr, _ ) = Comments.prettyFileComment width fileComment in doc @@ -633,7 +631,7 @@ adjustPatternParentheses isTop pattern = ( False, AsPattern _ _ ) -> nodify pat |> ParenthesizedPattern - ( _, _ ) -> + _ -> pat removeParens pat = @@ -657,7 +655,7 @@ adjustPatternParentheses isTop pattern = ( _, AsPattern _ _ ) -> False - ( _, _ ) -> + _ -> isTop in removeParens pattern @@ -786,7 +784,7 @@ adjustExpressionParentheses context expression = ( False, False, IfBlock _ _ _ ) -> nodify expr |> ParenthesizedExpression - ( _, _, _ ) -> + _ -> expr removeParens expr = @@ -852,7 +850,7 @@ adjustExpressionParentheses context expression = ( False, _, RecordUpdateExpression _ _ ) -> True - ( _, _, _ ) -> + _ -> False in removeParens expression @@ -968,7 +966,7 @@ prettyExpressionInner aliases context indent expression = RecordUpdateExpression var setters -> prettyRecordUpdateExpression aliases indent var setters - GLSLExpression val -> + GLSLExpression _ -> ( Pretty.string "glsl" , True ) @@ -1107,12 +1105,9 @@ prettyIfBlock aliases indent exprBool exprTrue exprFalse = innerIfBlock : Node Expression -> Node Expression -> Node Expression -> List (Doc t) innerIfBlock innerExprBool innerExprTrue innerExprFalse = let - context = - topContext - ifPart = let - ( prettyBoolExpr, alwaysBreak ) = + ( _, alwaysBreak ) = prettyExpressionInner aliases topContext 4 (denode innerExprBool) in [ [ Pretty.string "if" @@ -1664,7 +1659,7 @@ isNakedCompound typeAnn = Typed _ [] -> False - Typed _ args -> + Typed _ _ -> True FunctionTypeAnnotation _ _ -> diff --git a/tests/Declare.elm b/tests/Declare.elm index 70e1ceb8..724e4d32 100644 --- a/tests/Declare.elm +++ b/tests/Declare.elm @@ -2,21 +2,10 @@ module Declare exposing (suite) {-| -} -import Dict import Elm -import Elm.Annotation as Type import Elm.Declare import Elm.Expect -import Elm.Let import Elm.Op -import Elm.ToString -import Expect exposing (Expectation) -import Fuzz exposing (Fuzzer, int, list, string) -import Gen.Element -import Gen.Maybe -import Internal.Compiler as Compiler -import Internal.Debug -import Internal.Write import Test exposing (..) @@ -55,4 +44,4 @@ mySweetNumber = myFn 82 """ - ] + ] diff --git a/tests/File.elm b/tests/File.elm index 0b1d584f..7b4b33e8 100644 --- a/tests/File.elm +++ b/tests/File.elm @@ -2,21 +2,8 @@ module File exposing (suite) {-| -} -import Dict import Elm -import Elm.Annotation as Type -import Elm.Declare import Elm.Expect -import Elm.Let -import Elm.Op -import Elm.ToString -import Expect exposing (Expectation) -import Fuzz exposing (Fuzzer, int, list, string) -import Gen.Element -import Gen.Maybe -import Internal.Compiler as Compiler -import Internal.Debug -import Internal.Write import Test exposing (..) diff --git a/tests/Let.elm b/tests/Let.elm index 0558e7f0..08f354a3 100644 --- a/tests/Let.elm +++ b/tests/Let.elm @@ -1,19 +1,10 @@ module Let exposing (suite) -import Dict import Elm import Elm.Annotation as Type import Elm.Expect import Elm.Let import Elm.Op -import Elm.ToString -import Expect exposing (Expectation) -import Fuzz exposing (Fuzzer, int, list, string) -import Gen.Element -import Gen.Maybe -import Internal.Compiler as Compiler -import Internal.Debug -import Internal.Write import Test exposing (..) diff --git a/tests/PackageHelpers.elm b/tests/PackageHelpers.elm index 6777c0a4..a3686f61 100644 --- a/tests/PackageHelpers.elm +++ b/tests/PackageHelpers.elm @@ -2,16 +2,13 @@ module PackageHelpers exposing (suite) import Dict import Elm -import Elm.Annotation as Type import Elm.Expect import Elm.Op import Elm.ToString -import Expect exposing (Expectation) -import Fuzz exposing (Fuzzer, int, list, string) +import Expect import Gen.Element import Gen.Maybe import Internal.Compiler as Compiler -import Internal.Debug import Internal.Write import Test exposing (..) diff --git a/tests/TypeChecking.elm b/tests/TypeChecking.elm index 55281f57..fa371a4a 100644 --- a/tests/TypeChecking.elm +++ b/tests/TypeChecking.elm @@ -5,10 +5,8 @@ import Elm.Annotation as Type import Elm.Case import Elm.Op import Elm.ToString -import Expect exposing (Expectation) -import Fuzz exposing (Fuzzer, int, list, string) +import Expect import Internal.Compiler as Compiler -import Internal.Debug as Debug import Internal.Index as Index import Test exposing (..) From 3c1c86ae541ef793139c833cd8eea4061b1522b7 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 16:09:32 +0200 Subject: [PATCH 06/19] Avoid premature computation --- src/Elm.elm | 5 +- src/Internal/Compiler.elm | 13 ++--- src/Internal/Write.elm | 115 +++++++++++++++++++------------------- 3 files changed, 63 insertions(+), 70 deletions(-) diff --git a/src/Elm.elm b/src/Elm.elm index 6912b8a6..9eac760c 100644 --- a/src/Elm.elm +++ b/src/Elm.elm @@ -1520,11 +1520,8 @@ betaReduce e = case popLastAndDenodeLast args of Just ( initLambdaArgs, Pattern.VarPattern lastLambdaArg ) -> case Compiler.denode expression of - Exp.RecordAccess argNode fieldNode -> + Exp.RecordAccess argNode (Node.Node _ fieldName) -> let - fieldName = - Compiler.denode fieldNode - arg = Compiler.denode argNode in diff --git a/src/Internal/Compiler.elm b/src/Internal/Compiler.elm index 2b87faa8..1b96f47e 100644 --- a/src/Internal/Compiler.elm +++ b/src/Internal/Compiler.elm @@ -1131,12 +1131,12 @@ threadHelper index exps rendered = resolve : Index -> VariableCache -> Annotation.TypeAnnotation -> Result String Annotation.TypeAnnotation resolve index cache annotation = if Index.typecheck index then - let - restrictions = - getRestrictions annotation cache - in case resolveVariables Set.empty cache annotation of Ok newAnnotation -> + let + restrictions = + getRestrictions annotation cache + in newAnnotation |> rewriteTypeVariables |> checkRestrictions restrictions @@ -2263,14 +2263,11 @@ getField name val fields captured = top :: remain -> let - ( topFieldName, topFieldVal ) = + ( topFieldName, Node _ topVal ) = denode top topName = denode topFieldName - - topVal = - denode topFieldVal in if topName == name then Ok diff --git a/src/Internal/Write.elm b/src/Internal/Write.elm index acdc8652..b5ab7f0f 100644 --- a/src/Internal/Write.elm +++ b/src/Internal/Write.elm @@ -1068,18 +1068,19 @@ prettyOperatorApplicationRight aliases indent symbol _ exprl exprr = innerIndent = decrementIndent 4 (String.length symbol + 1) - leftIndent = - if isTop then - indent - - else - innerIndent - rightSide = denode right |> expandExpr innerIndent context in case rightSide of ( hdExpr, hdBreak ) :: tl -> + let + leftIndent = + if isTop then + indent + + else + innerIndent + in List.append (denode left |> expandExpr leftIndent context) (( Pretty.string sym |> Pretty.a Pretty.space |> Pretty.a hdExpr, hdBreak ) :: tl) @@ -1183,19 +1184,18 @@ prettyLiteral val = prettyTupledExpression : Aliases -> Int -> List (Node Expression) -> ( Doc t, Bool ) prettyTupledExpression aliases indent exprs = - let - open = - Pretty.a Pretty.space (Pretty.string "(") - - close = - Pretty.a (Pretty.string ")") Pretty.line - in case exprs of [] -> ( Pretty.string "()", False ) _ -> let + open = + Pretty.a Pretty.space (Pretty.string "(") + + close = + Pretty.a (Pretty.string ")") Pretty.line + ( prettyExpressions, alwaysBreak ) = List.map (prettyExpressionInner aliases topContext (decrementIndent indent 2)) (denodeAll exprs) |> List.unzip @@ -1323,20 +1323,19 @@ prettyLambdaExpression aliases indent lambda = prettyRecordExpr : Aliases -> List (Node RecordSetter) -> ( Doc t, Bool ) prettyRecordExpr aliases setters = - let - open = - Pretty.a Pretty.space (Pretty.string "{") - - close = - Pretty.a (Pretty.string "}") - Pretty.line - in case setters of [] -> ( Pretty.string "{}", False ) _ -> let + open = + Pretty.a Pretty.space (Pretty.string "{") + + close = + Pretty.a (Pretty.string "}") + Pretty.line + ( prettyExpressions, alwaysBreak ) = List.map (prettySetter aliases) (denodeAll setters) |> List.unzip @@ -1372,19 +1371,18 @@ prettySetter aliases ( fld, val ) = prettyList : Aliases -> Int -> List (Node Expression) -> ( Doc t, Bool ) prettyList aliases indent exprs = - let - open = - Pretty.a Pretty.space (Pretty.string "[") - - close = - Pretty.a (Pretty.string "]") Pretty.line - in case exprs of [] -> ( Pretty.string "[]", False ) _ -> let + open = + Pretty.a Pretty.space (Pretty.string "[") + + close = + Pretty.a (Pretty.string "]") Pretty.line + ( prettyExpressions, alwaysBreak ) = List.map (prettyExpressionInner aliases topContext (decrementIndent indent 2)) (denodeAll exprs) |> List.unzip @@ -1415,17 +1413,6 @@ prettyRecordAccess aliases expr field = prettyRecordUpdateExpression : Aliases -> Int -> Node String -> List (Node RecordSetter) -> ( Doc t, Bool ) prettyRecordUpdateExpression aliases indent var setters = let - open = - [ Pretty.string "{" - , Pretty.string (denode var) - ] - |> Pretty.words - |> Pretty.a Pretty.line - - close = - Pretty.a (Pretty.string "}") - Pretty.line - addBarToFirst exprs = case exprs of [] -> @@ -1440,6 +1427,17 @@ prettyRecordUpdateExpression aliases indent var setters = _ -> let + open = + [ Pretty.string "{" + , Pretty.string (denode var) + ] + |> Pretty.words + |> Pretty.a Pretty.line + + close = + Pretty.a (Pretty.string "}") + Pretty.line + ( prettyExpressions, alwaysBreak ) = List.map (prettySetter aliases) (denodeAll setters) |> List.unzip @@ -1532,18 +1530,18 @@ prettyTypeAnnotationParens aliases typeAnn = prettyRecord : Aliases -> List RecordField -> Doc t prettyRecord aliases fields = - let - open = - Pretty.a Pretty.space (Pretty.string "{") - - close = - Pretty.a (Pretty.string "}") Pretty.line - in case fields of [] -> Pretty.string "{}" _ -> + let + open = + Pretty.a Pretty.space (Pretty.string "{") + + close = + Pretty.a (Pretty.string "}") Pretty.line + in fields |> List.map (Tuple.mapBoth denode denode) |> List.map (prettyFieldTypeAnn aliases) @@ -1555,17 +1553,6 @@ prettyRecord aliases fields = prettyGenericRecord : Aliases -> String -> List RecordField -> Doc t prettyGenericRecord aliases paramName fields = let - open = - [ Pretty.string "{" - , Pretty.string paramName - ] - |> Pretty.words - |> Pretty.a Pretty.line - - close = - Pretty.a (Pretty.string "}") - Pretty.line - addBarToFirst exprs = case exprs of [] -> @@ -1579,6 +1566,18 @@ prettyGenericRecord aliases paramName fields = Pretty.string "{}" _ -> + let + open = + [ Pretty.string "{" + , Pretty.string paramName + ] + |> Pretty.words + |> Pretty.a Pretty.line + + close = + Pretty.a (Pretty.string "}") + Pretty.line + in open |> Pretty.a (fields From 3b5b6bbe2073fbc041894f24d5008d223a1cf85c Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 16:27:20 +0200 Subject: [PATCH 07/19] de-denode --- src/Elm.elm | 49 +++++++---------- src/Elm/Op.elm | 5 +- src/Internal/Compiler.elm | 103 +++++++++++++---------------------- src/Internal/Write.elm | 111 ++++++++++++++++++-------------------- 4 files changed, 113 insertions(+), 155 deletions(-) diff --git a/src/Elm.elm b/src/Elm.elm index 9eac760c..0c91e06b 100644 --- a/src/Elm.elm +++ b/src/Elm.elm @@ -104,7 +104,7 @@ import Elm.Syntax.Declaration as Declaration import Elm.Syntax.Exposing as Expose import Elm.Syntax.Expression as Exp import Elm.Syntax.Module -import Elm.Syntax.Node as Node +import Elm.Syntax.Node as Node exposing (Node(..)) import Elm.Syntax.Pattern as Pattern import Elm.Syntax.TypeAnnotation as Annotation import Internal.Clean as Clean @@ -1497,8 +1497,8 @@ popLastAndDenodeLast lst = [] -> Nothing - last :: initReverse -> - Just ( List.reverse initReverse, Compiler.denode last ) + (Node _ last) :: initReverse -> + Just ( List.reverse initReverse, last ) betaReduce : Exp.Expression -> Exp.Expression @@ -1509,8 +1509,8 @@ betaReduce e = Exp.FunctionOrValue [] n -> Just n - Exp.ParenthesizedExpression p -> - extractLastArg <| Compiler.denode p + Exp.ParenthesizedExpression (Node _ p) -> + extractLastArg p _ -> Nothing @@ -1520,11 +1520,7 @@ betaReduce e = case popLastAndDenodeLast args of Just ( initLambdaArgs, Pattern.VarPattern lastLambdaArg ) -> case Compiler.denode expression of - Exp.RecordAccess argNode (Node.Node _ fieldName) -> - let - arg = - Compiler.denode argNode - in + Exp.RecordAccess (Node _ arg) (Node.Node _ fieldName) -> case arg of Exp.FunctionOrValue [] argName -> if argName == lastLambdaArg then @@ -1549,8 +1545,8 @@ betaReduce e = if extractLastArg lastApplicationArg == Just lastLambdaArg then if List.isEmpty initLambdaArgs then case initApplicationArgs of - [ s ] -> - betaReduce <| Compiler.denode s + [ Node _ s ] -> + betaReduce s _ -> Exp.Application initApplicationArgs @@ -2482,13 +2478,8 @@ parse source = declarations = List.map - (\dec -> - let - declar = - Compiler.denode dec - in - ( Node.range dec - |> (.start >> .row) + (\(Node range declar) -> + ( range.start.row , Compiler.Declaration { name = Maybe.withDefault "parsed" (decName declar) , exposed = determineExposure declar exposedList @@ -2509,11 +2500,9 @@ parse source = comments = List.map - (\nodedComment -> - ( Node.range nodedComment - |> (.start >> .row) - , Compiler.Comment - (Compiler.denode nodedComment) + (\(Node range nodedComment) -> + ( range.start.row + , Compiler.Comment nodedComment ) ) parsedFile.comments @@ -2618,8 +2607,8 @@ determineExposure dec exposedDec = valueIsExposed : String -> Node.Node Expose.TopLevelExpose -> Bool -valueIsExposed name node = - case Compiler.denode node of +valueIsExposed name (Node _ node) = + case node of Expose.InfixExpose _ -> False @@ -2634,8 +2623,8 @@ valueIsExposed name node = typeIsExposed : String -> Node.Node Expose.TopLevelExpose -> Bool -typeIsExposed name node = - case Compiler.denode node of +typeIsExposed name (Node _ node) = + case node of Expose.InfixExpose _ -> False @@ -2650,8 +2639,8 @@ typeIsExposed name node = typeConstructorIsExposed : String -> Node.Node Expose.TopLevelExpose -> Bool -typeConstructorIsExposed name node = - case Compiler.denode node of +typeConstructorIsExposed name (Node _ node) = + case node of Expose.InfixExpose _ -> False diff --git a/src/Elm/Op.elm b/src/Elm/Op.elm index f5c0c31c..8ceabed0 100644 --- a/src/Elm/Op.elm +++ b/src/Elm/Op.elm @@ -59,6 +59,7 @@ import Dict import Elm exposing (Expression) import Elm.Syntax.Expression as Exp import Elm.Syntax.Infix as Infix +import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.TypeAnnotation as Annotation import Internal.Compiler as Compiler import Internal.Index as Index @@ -666,8 +667,8 @@ autopipe committed topFn expressions = [] -> Exp.Application [] - innerFn :: remain -> - autopipe True (Compiler.denode innerFn) (List.map Compiler.denode remain) + (Node _ innerFn) :: remain -> + autopipe True innerFn (Compiler.denodeAll remain) ) ) (Compiler.nodify diff --git a/src/Internal/Compiler.elm b/src/Internal/Compiler.elm index 1b96f47e..35d094d7 100644 --- a/src/Internal/Compiler.elm +++ b/src/Internal/Compiler.elm @@ -633,31 +633,23 @@ getGenericsHelper ann = Annotation.Record recordDefinition -> List.concatMap - (\nodedField -> - let - ( _, field ) = - denode nodedField - in - getGenericsHelper (denode field) + (\(Node _ ( _, Node _ field )) -> + getGenericsHelper field ) recordDefinition - Annotation.GenericRecord recordName recordDefinition -> - denode recordName + Annotation.GenericRecord (Node _ recordName) (Node _ recordDefinition) -> + recordName :: List.concatMap - (\nodedField -> - let - ( _, field ) = - denode nodedField - in - getGenericsHelper (denode field) + (\(Node _ ( _, Node _ field )) -> + getGenericsHelper field ) - (denode recordDefinition) + recordDefinition - Annotation.FunctionTypeAnnotation one two -> + Annotation.FunctionTypeAnnotation (Node _ one) (Node _ two) -> List.concatMap getGenericsHelper - [ denode one - , denode two + [ one + , two ] @@ -1465,10 +1457,10 @@ rewriteTypeVariablesHelper existing renames type_ = ( newUsed, newVars ) = vars |> List.foldl - (\typevar ( varUsed, varList ) -> + (\(Node _ typevar) ( varUsed, varList ) -> let ( oneUsed, oneType ) = - rewriteTypeVariablesHelper existing varUsed (denode typevar) + rewriteTypeVariablesHelper existing varUsed typevar in ( oneUsed, nodify oneType :: varList ) ) @@ -1490,13 +1482,13 @@ rewriteTypeVariablesHelper existing renames type_ = Annotation.GenericRecord _ _ -> ( renames, type_ ) - Annotation.FunctionTypeAnnotation one two -> + Annotation.FunctionTypeAnnotation (Node _ one) (Node _ two) -> let ( oneUsed, oneType ) = - rewriteTypeVariablesHelper existing renames (denode one) + rewriteTypeVariablesHelper existing renames one ( twoUsed, twoType ) = - rewriteTypeVariablesHelper existing oneUsed (denode two) + rewriteTypeVariablesHelper existing oneUsed two in ( twoUsed , Annotation.FunctionTypeAnnotation @@ -1688,7 +1680,7 @@ applyTypeHelper : -> Result (List InferenceError) Inference applyTypeHelper aliases cache fn args = case fn of - Annotation.FunctionTypeAnnotation one two -> + Annotation.FunctionTypeAnnotation (Node _ one) (Node _ two) -> case args of [] -> Ok @@ -1698,18 +1690,16 @@ applyTypeHelper aliases cache fn args = } top :: rest -> - case unifiable aliases cache (denode one) top of + case unifiable aliases cache one top of ( variableCache, Ok _ ) -> applyTypeHelper aliases variableCache - (denode two) + two rest ( _, Err err ) -> - Err - [ err - ] + Err [ err ] Annotation.GenericType varName -> case args of @@ -2161,7 +2151,7 @@ unifiable aliases vars one two = _ -> ( vars, Err (UnableToUnify one two) ) - Annotation.FunctionTypeAnnotation oneA oneB -> + Annotation.FunctionTypeAnnotation (Node _ oneA) (Node _ oneB) -> case two of Annotation.GenericType b -> case Dict.get b vars of @@ -2173,10 +2163,10 @@ unifiable aliases vars one two = Just foundTwo -> unifiable aliases vars one foundTwo - Annotation.FunctionTypeAnnotation twoA twoB -> - case unifiable aliases vars (denode oneA) (denode twoA) of + Annotation.FunctionTypeAnnotation (Node _ twoA) (Node _ twoB) -> + case unifiable aliases vars oneA twoA of ( aVars, Ok unifiedA ) -> - case unifiable aliases aVars (denode oneB) (denode twoB) of + case unifiable aliases aVars oneB twoB of ( bVars, Ok unifiedB ) -> ( bVars , Ok @@ -2213,22 +2203,12 @@ unifiableFields aliases vars one two unified = ( [], [] ) -> ( vars, Ok (nodifyAll (List.reverse unified)) ) - ( oneX :: oneRemain, twoFields ) -> - let - ( oneFieldName, oneFieldVal ) = - denode oneX - - oneName = - denode oneFieldName - - oneVal = - denode oneFieldVal - in - case getField oneName oneVal twoFields [] of + ( (Node _ ( Node _ oneFieldName, Node _ oneFieldVal )) :: oneRemain, twoFields ) -> + case getField oneFieldName oneFieldVal twoFields [] of Ok ( matchingFieldVal, remainingTwo ) -> let ( newVars, unifiedFieldResult ) = - unifiable aliases vars oneVal matchingFieldVal + unifiable aliases vars oneFieldVal matchingFieldVal in case unifiedFieldResult of Ok unifiedField -> @@ -2236,7 +2216,7 @@ unifiableFields aliases vars one two unified = newVars oneRemain remainingTwo - (( nodify oneName, nodify unifiedField ) :: unified) + (( nodify oneFieldName, nodify unifiedField ) :: unified) Err err -> ( newVars, Err err ) @@ -2263,11 +2243,8 @@ getField name val fields captured = top :: remain -> let - ( topFieldName, Node _ topVal ) = + ( Node _ topName, Node _ topVal ) = denode top - - topName = - denode topFieldName in if topName == name then Ok @@ -2284,16 +2261,16 @@ unifiableLists aliases vars one two unified = ( [], [] ) -> ( vars, Ok (nodifyAll (List.reverse unified)) ) - ( [ oneX ], [ twoX ] ) -> - case unifiable aliases vars (denode oneX) (denode twoX) of + ( [ Node _ oneX ], [ Node _ twoX ] ) -> + case unifiable aliases vars oneX twoX of ( newVars, Ok un ) -> ( newVars, Ok (nodifyAll (List.reverse (un :: unified))) ) ( newVars, Err err ) -> ( newVars, Err err ) - ( oneX :: oneRemain, twoX :: twoRemain ) -> - case unifiable aliases vars (denode oneX) (denode twoX) of + ( (Node _ oneX) :: oneRemain, (Node _ twoX) :: twoRemain ) -> + case unifiable aliases vars oneX twoX of ( newVars, Ok un ) -> unifiableLists aliases newVars oneRemain twoRemain (un :: unified) @@ -2477,8 +2454,8 @@ resolveField index type_ aliases inferences fieldName = } ] - Annotation.GenericRecord _ fields -> - case getFieldFromList fieldName (denode fields) of + Annotation.GenericRecord _ (Node _ fields) -> + case getFieldFromList fieldName fields of Just ann -> Ok { type_ = ann @@ -2493,7 +2470,7 @@ resolveField index type_ aliases inferences fieldName = , existingFields = List.map (denode >> Tuple.first >> denode) - (denode fields) + fields } ] @@ -2553,13 +2530,9 @@ getFieldFromList selector fields = [] -> Nothing - nodifiedTop :: remain -> - let - ( fieldname, contents ) = - denode nodifiedTop - in - if denode fieldname == selector then - Just (denode contents) + (Node _ ( Node _ fieldname, Node _ contents )) :: remain -> + if fieldname == selector then + Just contents else getFieldFromList selector remain diff --git a/src/Internal/Write.elm b/src/Internal/Write.elm index b5ab7f0f..e14f6583 100644 --- a/src/Internal/Write.elm +++ b/src/Internal/Write.elm @@ -25,7 +25,7 @@ import Elm.Syntax.Import exposing (Import) import Elm.Syntax.Infix exposing (Infix, InfixDirection(..)) import Elm.Syntax.Module exposing (DefaultModuleData, EffectModuleData, Module(..)) import Elm.Syntax.ModuleName exposing (ModuleName) -import Elm.Syntax.Node exposing (Node) +import Elm.Syntax.Node exposing (Node(..)) import Elm.Syntax.Pattern exposing (Pattern(..)) import Elm.Syntax.Signature exposing (Signature) import Elm.Syntax.Type exposing (Type, ValueConstructor) @@ -419,8 +419,8 @@ prettyElmSyntaxDeclaration aliases decl = Elm.Syntax.Declaration.InfixDeclaration infix_ -> prettyInfix infix_ - Elm.Syntax.Declaration.Destructuring pattern expr -> - prettyDestructuring aliases (denode pattern) (denode expr) + Elm.Syntax.Declaration.Destructuring (Node _ pattern) (Node _ expr) -> + prettyDestructuring aliases pattern expr prettyDeclarations : Aliases -> List Util.RenderedDeclaration -> Doc t @@ -636,10 +636,9 @@ adjustPatternParentheses isTop pattern = removeParens pat = case pat of - ParenthesizedPattern innerPat -> - if shouldRemove (denode innerPat) then - denode innerPat - |> removeParens + ParenthesizedPattern (Node _ innerPat) -> + if shouldRemove innerPat then + removeParens innerPat else pat @@ -703,10 +702,10 @@ prettyPatternInner aliases isTop pattern = |> Pretty.surround Pretty.space Pretty.space |> Pretty.braces - UnConsPattern hdPat tlPat -> - [ prettyPatternInner aliases False (denode hdPat) + UnConsPattern (Node _ hdPat) (Node _ tlPat) -> + [ prettyPatternInner aliases False hdPat , Pretty.string "::" - , prettyPatternInner aliases False (denode tlPat) + , prettyPatternInner aliases False tlPat ] |> Pretty.words @@ -737,15 +736,15 @@ prettyPatternInner aliases isTop pattern = :: List.map (prettyPatternInner aliases False) (denodeAll listPats) |> Pretty.words - AsPattern pat name -> - [ prettyPatternInner aliases False (denode pat) + AsPattern (Node _ pat) (Node _ name) -> + [ prettyPatternInner aliases False pat , Pretty.string "as" - , Pretty.string (denode name) + , Pretty.string name ] |> Pretty.words - ParenthesizedPattern pat -> - prettyPatternInner aliases True (denode pat) + ParenthesizedPattern (Node _ pat) -> + prettyPatternInner aliases True pat |> Pretty.parens @@ -789,10 +788,9 @@ adjustExpressionParentheses context expression = removeParens expr = case expr of - ParenthesizedExpression innerExpr -> - if shouldRemove (denode innerExpr) then - denode innerExpr - |> removeParens + ParenthesizedExpression (Node _ innerExpr) -> + if shouldRemove innerExpr then + removeParens innerExpr else expr @@ -913,10 +911,10 @@ prettyExpressionInner aliases context indent expression = , False ) - Negation expr -> + Negation (Node _ expr) -> let ( prettyExpr, alwaysBreak ) = - prettyExpressionInner aliases topContext 4 (denode expr) + prettyExpressionInner aliases topContext 4 expr in ( Pretty.string "-" |> Pretty.a prettyExpr @@ -1017,7 +1015,7 @@ prettyOperatorApplication aliases indent symbol dir exprl exprr = prettyOperatorApplicationLeft : Aliases -> Int -> String -> InfixDirection -> Node Expression -> Node Expression -> ( Doc t, Bool ) -prettyOperatorApplicationLeft aliases indent symbol _ exprl exprr = +prettyOperatorApplicationLeft aliases indent symbol _ (Node _ exprl) (Node _ exprr) = let context = { precedence = precedence symbol @@ -1026,10 +1024,10 @@ prettyOperatorApplicationLeft aliases indent symbol _ exprl exprr = } ( prettyExpressionLeft, alwaysBreakLeft ) = - prettyExpressionInner aliases context 4 (denode exprl) + prettyExpressionInner aliases context 4 exprl ( prettyExpressionRight, alwaysBreakRight ) = - prettyExpressionInner aliases context 4 (denode exprr) + prettyExpressionInner aliases context 4 exprr alwaysBreak = alwaysBreakLeft || alwaysBreakRight @@ -1057,7 +1055,7 @@ prettyOperatorApplicationRight aliases indent symbol _ exprl exprr = [ prettyExpressionInner aliases context innerIndent expr ] innerOpApply : Bool -> String -> Node Expression -> Node Expression -> List ( Doc t, Bool ) - innerOpApply isTop sym left right = + innerOpApply isTop sym (Node _ left) (Node _ right) = let context = { precedence = precedence sym @@ -1069,7 +1067,7 @@ prettyOperatorApplicationRight aliases indent symbol _ exprl exprr = decrementIndent 4 (String.length symbol + 1) rightSide = - denode right |> expandExpr innerIndent context + right |> expandExpr innerIndent context in case rightSide of ( hdExpr, hdBreak ) :: tl -> @@ -1081,7 +1079,7 @@ prettyOperatorApplicationRight aliases indent symbol _ exprl exprr = else innerIndent in - List.append (denode left |> expandExpr leftIndent context) + List.append (left |> expandExpr leftIndent context) (( Pretty.string sym |> Pretty.a Pretty.space |> Pretty.a hdExpr, hdBreak ) :: tl) [] -> @@ -1104,15 +1102,15 @@ prettyIfBlock : Aliases -> Int -> Node Expression -> Node Expression -> Node Exp prettyIfBlock aliases indent exprBool exprTrue exprFalse = let innerIfBlock : Node Expression -> Node Expression -> Node Expression -> List (Doc t) - innerIfBlock innerExprBool innerExprTrue innerExprFalse = + innerIfBlock (Node _ innerExprBool) (Node _ innerExprTrue) (Node _ innerExprFalse) = let ifPart = let ( _, alwaysBreak ) = - prettyExpressionInner aliases topContext 4 (denode innerExprBool) + prettyExpressionInner aliases topContext 4 innerExprBool in [ [ Pretty.string "if" - , prettyExpressionInner aliases topContext 4 (denode innerExprBool) |> Tuple.first + , prettyExpressionInner aliases topContext 4 innerExprBool |> Tuple.first ] |> Pretty.lines |> optionalGroup alwaysBreak @@ -1123,7 +1121,7 @@ prettyIfBlock aliases indent exprBool exprTrue exprFalse = |> optionalGroup alwaysBreak truePart = - prettyExpressionInner aliases topContext 4 (denode innerExprTrue) + prettyExpressionInner aliases topContext 4 innerExprTrue |> Tuple.first |> Pretty.indent indent @@ -1132,12 +1130,12 @@ prettyIfBlock aliases indent exprBool exprTrue exprFalse = |> Pretty.a (Pretty.string "else") falsePart = - case denode innerExprFalse of + case innerExprFalse of IfBlock nestedExprBool nestedExprTrue nestedExprFalse -> innerIfBlock nestedExprBool nestedExprTrue nestedExprFalse _ -> - [ prettyExpressionInner aliases topContext 4 (denode innerExprFalse) + [ prettyExpressionInner aliases topContext 4 innerExprFalse |> Tuple.first |> Pretty.indent indent ] @@ -1211,7 +1209,7 @@ prettyTupledExpression aliases indent exprs = prettyParenthesizedExpression : Aliases -> Int -> Node Expression -> ( Doc t, Bool ) -prettyParenthesizedExpression aliases indent expr = +prettyParenthesizedExpression aliases indent (Node _ expr) = let open = Pretty.string "(" @@ -1220,7 +1218,7 @@ prettyParenthesizedExpression aliases indent expr = Pretty.a (Pretty.string ")") Pretty.tightline ( prettyExpr, alwaysBreak ) = - prettyExpressionInner aliases topContext (decrementIndent indent 1) (denode expr) + prettyExpressionInner aliases topContext (decrementIndent indent 1) expr in ( prettyExpr |> Pretty.nest 1 @@ -1252,14 +1250,14 @@ prettyLetDeclaration aliases indent letDecl = LetFunction fn -> prettyFun aliases fn - LetDestructuring pattern expr -> - [ prettyPatternInner aliases False (denode pattern) + LetDestructuring (Node _ pattern) (Node _ expr) -> + [ prettyPatternInner aliases False pattern , Pretty.string "=" ] |> Pretty.words |> Pretty.a Pretty.line |> Pretty.a - (prettyExpressionInner aliases topContext 4 (denode expr) + (prettyExpressionInner aliases topContext 4 expr |> Tuple.first |> Pretty.indent indent ) @@ -1284,11 +1282,11 @@ prettyCaseBlock aliases indent caseBlock = |> Pretty.lines |> optionalGroup alwaysBreak - prettyCase ( pattern, expr ) = - prettyPattern aliases (denode pattern) + prettyCase ( Node _ pattern, Node _ expr ) = + prettyPattern aliases pattern |> Pretty.a (Pretty.string " ->") |> Pretty.a Pretty.line - |> Pretty.a (prettyExpressionInner aliases topContext 4 (denode expr) |> Tuple.first |> Pretty.indent 4) + |> Pretty.a (prettyExpressionInner aliases topContext 4 expr |> Tuple.first |> Pretty.indent 4) |> Pretty.indent indent patternsPart = @@ -1351,12 +1349,12 @@ prettyRecordExpr aliases setters = prettySetter : Aliases -> ( Node String, Node Expression ) -> ( Doc t, Bool ) -prettySetter aliases ( fld, val ) = +prettySetter aliases ( Node _ fld, Node _ val ) = let ( prettyExpr, alwaysBreak ) = - prettyExpressionInner aliases topContext 4 (denode val) + prettyExpressionInner aliases topContext 4 val in - ( [ [ Pretty.string (denode fld) + ( [ [ Pretty.string fld , Pretty.string "=" ] |> Pretty.words @@ -1398,20 +1396,20 @@ prettyList aliases indent exprs = prettyRecordAccess : Aliases -> Node Expression -> Node String -> ( Doc t, Bool ) -prettyRecordAccess aliases expr field = +prettyRecordAccess aliases (Node _ expr) (Node _ field) = let ( prettyExpr, alwaysBreak ) = - prettyExpressionInner aliases topContext 4 (denode expr) + prettyExpressionInner aliases topContext 4 expr in ( prettyExpr |> Pretty.a dot - |> Pretty.a (Pretty.string (denode field)) + |> Pretty.a (Pretty.string field) , alwaysBreak ) prettyRecordUpdateExpression : Aliases -> Int -> Node String -> List (Node RecordSetter) -> ( Doc t, Bool ) -prettyRecordUpdateExpression aliases indent var setters = +prettyRecordUpdateExpression aliases indent (Node _ var) setters = let addBarToFirst exprs = case exprs of @@ -1429,7 +1427,7 @@ prettyRecordUpdateExpression aliases indent var setters = let open = [ Pretty.string "{" - , Pretty.string (denode var) + , Pretty.string var ] |> Pretty.words |> Pretty.a Pretty.line @@ -1481,19 +1479,16 @@ prettyTypeAnnotation aliases typeAnn = Record recordDef -> prettyRecord aliases (denodeAll recordDef) - GenericRecord paramName recordDef -> - prettyGenericRecord aliases (denode paramName) (denodeAll (denode recordDef)) + GenericRecord (Node _ paramName) (Node _ recordDef) -> + prettyGenericRecord aliases paramName (denodeAll recordDef) FunctionTypeAnnotation fromAnn toAnn -> prettyFunctionTypeAnnotation aliases fromAnn toAnn prettyTyped : Aliases -> Node ( ModuleName, String ) -> List (Node TypeAnnotation) -> Doc t -prettyTyped aliases fqName anns = +prettyTyped aliases (Node _ ( moduleName, typeName )) anns = let - ( moduleName, typeName ) = - denode fqName - typeDoc = prettyModuleNameDot aliases moduleName |> Pretty.a (Pretty.string typeName) @@ -1626,14 +1621,14 @@ prettyFunctionTypeAnnotation aliases left right = [ prettyTypeAnnotation aliases ann ] innerFnTypeAnn : Node TypeAnnotation -> Node TypeAnnotation -> List (Doc t) - innerFnTypeAnn innerLeft innerRight = + innerFnTypeAnn (Node _ innerLeft) (Node _ innerRight) = let rightSide = - denode innerRight |> expandRight + innerRight |> expandRight in case rightSide of hd :: tl -> - (denode innerLeft |> expandLeft) + (innerLeft |> expandLeft) :: ([ Pretty.string "->", hd ] |> Pretty.words) :: tl From bc86780c69f387340c2d8f1dbd05f973a511084a Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 16:29:36 +0200 Subject: [PATCH 08/19] Enable more elm-review rules --- review/src/ReviewConfig.elm | 47 +++++++++---------- .../NoMissingTypeAnnotationInLetIn.json | 27 +++++++++++ .../NoUnused.CustomTypeConstructorArgs.json | 9 ++++ review/suppressed/NoUnused.Exports.json | 9 ++++ review/suppressed/NoUnused.Variables.json | 17 +++++++ review/suppressed/Simplify.json | 8 ++++ 6 files changed, 93 insertions(+), 24 deletions(-) create mode 100644 review/suppressed/NoMissingTypeAnnotationInLetIn.json create mode 100644 review/suppressed/NoUnused.CustomTypeConstructorArgs.json create mode 100644 review/suppressed/NoUnused.Exports.json create mode 100644 review/suppressed/NoUnused.Variables.json create mode 100644 review/suppressed/Simplify.json diff --git a/review/src/ReviewConfig.elm b/review/src/ReviewConfig.elm index ac3570e8..c49f01fe 100644 --- a/review/src/ReviewConfig.elm +++ b/review/src/ReviewConfig.elm @@ -39,30 +39,29 @@ config : List Rule config = [ NoMissingTypeExpose.rule , NoUnused.Dependencies.rule - - -- , Docs.NoMissing.rule - -- { document = onlyExposed - -- , from = exposedModules - -- } - --, Docs.ReviewLinksAndSections.rule - --, Docs.ReviewAtDocs.rule - --, Docs.UpToDateReadmeLinks.rule - --, NoDebug.Log.rule - --, NoDebug.TodoOrToString.rule - -- |> Rule.ignoreErrorsForDirectories [ "tests/" ] - --, NoExposingEverything.rule - --, NoImportingEverything.rule [] - --, NoMissingTypeAnnotation.rule - --, NoMissingTypeAnnotationInLetIn.rule - --, NoSimpleLetBody.rule - --, NoPrematureLetComputation.rule - --, NoUnused.CustomTypeConstructors.rule [] - --, NoUnused.CustomTypeConstructorArgs.rule - --, NoUnused.Exports.rule - --, NoUnused.Parameters.rule - --, NoUnused.Patterns.rule - --, NoUnused.Variables.rule - --, Simplify.rule Simplify.defaults + , Docs.NoMissing.rule + { document = onlyExposed + , from = exposedModules + } + , Docs.ReviewLinksAndSections.rule + , Docs.ReviewAtDocs.rule + -- , Docs.UpToDateReadmeLinks.rule + , NoDebug.Log.rule + , NoDebug.TodoOrToString.rule + |> Rule.ignoreErrorsForDirectories [ "tests/" ] + , NoExposingEverything.rule + , NoImportingEverything.rule [] + , NoMissingTypeAnnotation.rule + , NoMissingTypeAnnotationInLetIn.rule + , NoSimpleLetBody.rule + , NoPrematureLetComputation.rule + -- , NoUnused.CustomTypeConstructors.rule [] + , NoUnused.CustomTypeConstructorArgs.rule + , NoUnused.Exports.rule + , NoUnused.Parameters.rule + , NoUnused.Patterns.rule + , NoUnused.Variables.rule + , Simplify.rule Simplify.defaults ] |> List.map (Rule.ignoreErrorsForDirectories diff --git a/review/suppressed/NoMissingTypeAnnotationInLetIn.json b/review/suppressed/NoMissingTypeAnnotationInLetIn.json new file mode 100644 index 00000000..6671c010 --- /dev/null +++ b/review/suppressed/NoMissingTypeAnnotationInLetIn.json @@ -0,0 +1,27 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 59, "filePath": "src/Elm.elm" }, + { "count": 49, "filePath": "src/Internal/Write.elm" }, + { "count": 38, "filePath": "src/Elm/Case.elm" }, + { "count": 28, "filePath": "src/Elm/Declare.elm" }, + { "count": 15, "filePath": "src/Internal/Compiler.elm" }, + { "count": 9, "filePath": "src/Elm/Let.elm" }, + { "count": 8, "filePath": "src/Internal/Render.elm" }, + { "count": 7, "filePath": "tests/PackageHelpers.elm" }, + { "count": 5, "filePath": "src/Elm/Case/Branch.elm" }, + { "count": 5, "filePath": "src/Internal/Debug.elm" }, + { "count": 4, "filePath": "src/Internal/ImportsAndExposing.elm" }, + { "count": 3, "filePath": "src/Elm/Op.elm" }, + { "count": 3, "filePath": "src/Internal/Clean.elm" }, + { "count": 3, "filePath": "src/Internal/Index.elm" }, + { "count": 2, "filePath": "src/Elm/ToString.elm" }, + { "count": 1, "filePath": "src/Error/Format.elm" }, + { "count": 1, "filePath": "src/Internal/Comments.elm" }, + { "count": 1, "filePath": "src/Internal/Format.elm" }, + { "count": 1, "filePath": "src/Internal/Types.elm" }, + { "count": 1, "filePath": "tests/TypeChecking.elm" } + ] +} diff --git a/review/suppressed/NoUnused.CustomTypeConstructorArgs.json b/review/suppressed/NoUnused.CustomTypeConstructorArgs.json new file mode 100644 index 00000000..c9391d9c --- /dev/null +++ b/review/suppressed/NoUnused.CustomTypeConstructorArgs.json @@ -0,0 +1,9 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 1, "filePath": "src/Elm/Op.elm" }, + { "count": 1, "filePath": "src/Internal/Compiler.elm" } + ] +} diff --git a/review/suppressed/NoUnused.Exports.json b/review/suppressed/NoUnused.Exports.json new file mode 100644 index 00000000..3f2338e0 --- /dev/null +++ b/review/suppressed/NoUnused.Exports.json @@ -0,0 +1,9 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 1, "filePath": "src/Error/Format.elm" }, + { "count": 1, "filePath": "src/Internal/Debug.elm" } + ] +} diff --git a/review/suppressed/NoUnused.Variables.json b/review/suppressed/NoUnused.Variables.json new file mode 100644 index 00000000..2afae835 --- /dev/null +++ b/review/suppressed/NoUnused.Variables.json @@ -0,0 +1,17 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 9, "filePath": "src/Internal/Compiler.elm" }, + { "count": 5, "filePath": "src/Elm.elm" }, + { "count": 5, "filePath": "src/Internal/Write.elm" }, + { "count": 4, "filePath": "src/Internal/Debug.elm" }, + { "count": 2, "filePath": "src/Elm/Op.elm" }, + { "count": 2, "filePath": "src/Internal/Comments.elm" }, + { "count": 2, "filePath": "tests/Pattern.elm" }, + { "count": 1, "filePath": "src/Internal/Index.elm" }, + { "count": 1, "filePath": "tests/Elm/Expect.elm" }, + { "count": 1, "filePath": "tests/PackageHelpers.elm" } + ] +} diff --git a/review/suppressed/Simplify.json b/review/suppressed/Simplify.json new file mode 100644 index 00000000..5b0bfc56 --- /dev/null +++ b/review/suppressed/Simplify.json @@ -0,0 +1,8 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 2, "filePath": "src/Internal/Compiler.elm" } + ] +} From cf624f83bb4e1dd3bf18240df5e7b0a7498a76c1 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 16:35:23 +0200 Subject: [PATCH 09/19] Add missing type annotations --- tests/Declare.elm | 4 +++- tests/File.elm | 4 +++- tests/Let.elm | 2 +- tests/PackageHelpers.elm | 9 +++++++-- tests/Pattern.elm | 30 +++++++++++++++--------------- tests/TypeChecking.elm | 7 ++++++- 6 files changed, 35 insertions(+), 21 deletions(-) diff --git a/tests/Declare.elm b/tests/Declare.elm index 724e4d32..38d960c6 100644 --- a/tests/Declare.elm +++ b/tests/Declare.elm @@ -6,7 +6,7 @@ import Elm import Elm.Declare import Elm.Expect import Elm.Op -import Test exposing (..) +import Test exposing (Test, describe, test) suite : Test @@ -16,12 +16,14 @@ suite = ] +myFn : { declaration : Elm.Declaration, call : Elm.Expression -> Elm.Expression, callFrom : List String -> Elm.Expression -> Elm.Expression, value : List String -> Elm.Expression } myFn = Elm.Declare.fn "myFn" ( "myInt", Nothing ) (Elm.Op.plus (Elm.int 5)) +declarations : Test declarations = describe "declarations" [ test "Basic function dec" <| diff --git a/tests/File.elm b/tests/File.elm index 7b4b33e8..fc9dae9e 100644 --- a/tests/File.elm +++ b/tests/File.elm @@ -4,9 +4,10 @@ module File exposing (suite) import Elm import Elm.Expect -import Test exposing (..) +import Test exposing (Test, describe, test) +testFn1 : Elm.Declaration testFn1 = Elm.declaration "testFn1" <| Elm.fn ( "arg", Nothing ) <| @@ -14,6 +15,7 @@ testFn1 = arg +testFn2 : Elm.Declaration testFn2 = Elm.declaration "testFn2" <| Elm.fn ( "arg", Nothing ) <| diff --git a/tests/Let.elm b/tests/Let.elm index 08f354a3..20f904a5 100644 --- a/tests/Let.elm +++ b/tests/Let.elm @@ -5,7 +5,7 @@ import Elm.Annotation as Type import Elm.Expect import Elm.Let import Elm.Op -import Test exposing (..) +import Test exposing (Test, describe, test) suite : Test diff --git a/tests/PackageHelpers.elm b/tests/PackageHelpers.elm index a3686f61..220963d4 100644 --- a/tests/PackageHelpers.elm +++ b/tests/PackageHelpers.elm @@ -1,18 +1,20 @@ module PackageHelpers exposing (suite) -import Dict +import Dict exposing (Dict) import Elm import Elm.Expect import Elm.Op +import Elm.Syntax.TypeAnnotation exposing (TypeAnnotation) import Elm.ToString import Expect import Gen.Element import Gen.Maybe import Internal.Compiler as Compiler import Internal.Write -import Test exposing (..) +import Test exposing (Test, describe, test) +detectCycles : List ( String, TypeAnnotation ) -> List Bool detectCycles list = let dict = @@ -27,6 +29,7 @@ detectCycles list = ) +countCycles : List ( String, TypeAnnotation ) -> List number countCycles list = let dict = @@ -41,6 +44,7 @@ countCycles list = ) +hasCycles : Dict String TypeAnnotation -> String -> List String -> Bool hasCycles dict key found = case Dict.get key dict of Nothing -> @@ -58,6 +62,7 @@ hasCycles dict key found = hasCycles dict val (val :: found) +findDepth : Dict String TypeAnnotation -> String -> List String -> number -> number findDepth dict key found depth = case Dict.get key dict of Nothing -> diff --git a/tests/Pattern.elm b/tests/Pattern.elm index 072ec52b..4173bc5a 100644 --- a/tests/Pattern.elm +++ b/tests/Pattern.elm @@ -247,21 +247,21 @@ expectImports expectedImports expression = |> Expect.equal (Set.fromList expectedImports) -fromString = - \fromStringArg -> - Elm.apply - (Elm.value - { importFrom = [ "QueryParams" ] - , name = "fromString" - , annotation = - Just - (Type.function - [ Type.string ] - (Type.namedWith [] "QueryParams" []) - ) - } - ) - [ fromStringArg ] +fromString : Expression -> Expression +fromString fromStringArg = + Elm.apply + (Elm.value + { importFrom = [ "QueryParams" ] + , name = "fromString" + , annotation = + Just + (Type.function + [ Type.string ] + (Type.namedWith [] "QueryParams" []) + ) + } + ) + [ fromStringArg ] renderedAs : String -> Expression -> Expect.Expectation diff --git a/tests/TypeChecking.elm b/tests/TypeChecking.elm index fa371a4a..2fac12d1 100644 --- a/tests/TypeChecking.elm +++ b/tests/TypeChecking.elm @@ -8,9 +8,10 @@ import Elm.ToString import Expect import Internal.Compiler as Compiler import Internal.Index as Index -import Test exposing (..) +import Test exposing (Test, describe, test) +successfullyInferredType : Compiler.Expression -> Expect.Expectation successfullyInferredType expression = let ( _, details ) = @@ -28,6 +29,7 @@ successfullyInferredType expression = ) +renderedAs : Elm.Expression -> String -> Expect.Expectation renderedAs expression str = Expect.equal (Elm.ToString.expression expression @@ -36,6 +38,7 @@ renderedAs expression str = str +declarationAs : Elm.Declaration -> String -> Expect.Expectation declarationAs decl str = Expect.equal (Elm.ToString.declaration decl @@ -218,6 +221,7 @@ map fn optional = ] +myMap2 : Elm.Expression myMap2 = Elm.fn2 ( "fn", Nothing ) @@ -227,6 +231,7 @@ myMap2 = ) +myMap : Elm.Expression myMap = Elm.fn2 ( "fn", Nothing ) From e9d903f2179b856e01bd42c573e1d4f5481fbf48 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 16:46:00 +0200 Subject: [PATCH 10/19] Add missing type annotations --- src/Internal/Comments.elm | 5 ++++- src/Internal/Compiler.elm | 40 +++++++++++++++++++++++++++++++++++++++ src/Internal/Index.elm | 6 +++--- src/Internal/Render.elm | 3 +++ src/Internal/Write.elm | 5 +++-- 5 files changed, 53 insertions(+), 6 deletions(-) diff --git a/src/Internal/Comments.elm b/src/Internal/Comments.elm index 0521bb97..ac7b79f8 100644 --- a/src/Internal/Comments.elm +++ b/src/Internal/Comments.elm @@ -198,15 +198,18 @@ prettyCommentPart part = prettyTags tags +prettyMarkdown : String -> Doc t prettyMarkdown val = Pretty.string val +prettyCode : String -> Doc t prettyCode val = Pretty.string val |> Pretty.indent 4 +prettyTags : List String -> Doc t prettyTags tags = [ Pretty.string "@docs" , List.map Pretty.string tags @@ -216,7 +219,7 @@ prettyTags tags = partToStringAndTags : Int -> CommentPart -> ( String, List String ) -partToStringAndTags width part = +partToStringAndTags _ part = case part of Markdown val -> ( val, [] ) diff --git a/src/Internal/Compiler.elm b/src/Internal/Compiler.elm index 35d094d7..848add92 100644 --- a/src/Internal/Compiler.elm +++ b/src/Internal/Compiler.elm @@ -1872,6 +1872,13 @@ unifyOn (Annotation annDetails) res = [ err ] +unifyWithAlias : + AliasCache + -> VariableCache + -> Node ( ModuleName.ModuleName, String ) + -> List (Node Annotation.TypeAnnotation) + -> Annotation.TypeAnnotation + -> Maybe ( VariableCache, Result error Annotation.TypeAnnotation ) unifyWithAlias aliases vars typename typeVars typeToUnifyWith = case getAlias typename aliases of Nothing -> @@ -2228,6 +2235,17 @@ unifiableFields aliases vars one two unified = ( vars, Err MismatchedTypeVariables ) +getField : + String + -> Annotation.TypeAnnotation + -> List (Node ( Node String, Node Annotation.TypeAnnotation )) + -> List (Node ( Node String, Node Annotation.TypeAnnotation )) + -> + Result + InferenceError + ( Annotation.TypeAnnotation + , List (Node ( Node String, Node Annotation.TypeAnnotation )) + ) getField name val fields captured = case fields of [] -> @@ -2256,6 +2274,13 @@ getField name val fields captured = getField name val remain (top :: captured) +unifiableLists : + AliasCache + -> VariableCache + -> List (Node Annotation.TypeAnnotation) + -> List (Node Annotation.TypeAnnotation) + -> List Annotation.TypeAnnotation + -> ( VariableCache, Result InferenceError (List (Node Annotation.TypeAnnotation)) ) unifiableLists aliases vars one two unified = case ( one, two ) of ( [], [] ) -> @@ -2433,6 +2458,19 @@ unifyComparable vars comparableName two = ) +resolveField : + Index + -> Annotation.TypeAnnotation + -> AliasCache + -> VariableCache + -> String + -> + Result + (List InferenceError) + { type_ : Annotation.TypeAnnotation + , inferences : VariableCache + , aliases : AliasCache + } resolveField index type_ aliases inferences fieldName = if Index.typecheck index then case type_ of @@ -2639,6 +2677,7 @@ protectInference index infResult = Err err +protectAnnotation : Index -> Annotation.TypeAnnotation -> Annotation.TypeAnnotation protectAnnotation index ann = case ann of Annotation.GenericType str -> @@ -2674,6 +2713,7 @@ protectAnnotation index ann = (mapNode (protectAnnotation index) two) +protectField : Index -> Node ( a, Node Annotation.TypeAnnotation ) -> Node ( a, Node Annotation.TypeAnnotation ) protectField index (Node.Node nodeRange ( nodedName, nodedType )) = Node.Node nodeRange ( nodedName diff --git a/src/Internal/Index.elm b/src/Internal/Index.elm index b4009493..d0aa2956 100644 --- a/src/Internal/Index.elm +++ b/src/Internal/Index.elm @@ -43,7 +43,7 @@ type Index typecheck : Index -> Bool -typecheck (Index top tail scope check) = +typecheck (Index _ _ _ check) = check @@ -108,7 +108,7 @@ getName desiredName ((Index top tail scope check) as index) = protectTypeName : String -> Index -> String -protectTypeName base ((Index top tail scope check) as index) = +protectTypeName base ((Index _ tail _ _) as index) = case tail of [] -> Format.formatValue base @@ -119,7 +119,7 @@ protectTypeName base ((Index top tail scope check) as index) = indexToString : Index -> String -indexToString (Index top tail scope check) = +indexToString (Index top tail _ _) = (if top == 0 then "" diff --git a/src/Internal/Render.elm b/src/Internal/Render.elm index 086dad7b..4555de3c 100644 --- a/src/Internal/Render.elm +++ b/src/Internal/Render.elm @@ -3,6 +3,7 @@ module Internal.Render exposing (render) {-| -} import Elm.Syntax.Declaration +import Elm.Syntax.Documentation import Elm.Syntax.Exposing as Expose import Elm.Syntax.Module import Elm.Syntax.Range as Range @@ -194,6 +195,7 @@ dedupImports mods = |> List.sortBy Compiler.fullModName +addDocs : Maybe Elm.Syntax.Documentation.Documentation -> Elm.Syntax.Declaration.Declaration -> Elm.Syntax.Declaration.Declaration addDocs maybeDoc decl = case maybeDoc of Nothing -> @@ -233,6 +235,7 @@ addDocs maybeDoc decl = decl +addExposed : Compiler.Expose -> Elm.Syntax.Declaration.Declaration -> List Expose.TopLevelExpose -> List Expose.TopLevelExpose addExposed exposed declaration otherExposes = case exposed of Compiler.NotExposed -> diff --git a/src/Internal/Write.elm b/src/Internal/Write.elm index e14f6583..10d1cdb7 100644 --- a/src/Internal/Write.elm +++ b/src/Internal/Write.elm @@ -382,7 +382,7 @@ prettyTopLevelExpose tlExpose = {-| Pretty prints a single top-level declaration. -} prettyDeclaration : Int -> Util.RenderedDeclaration -> Doc t -prettyDeclaration width decl = +prettyDeclaration _ decl = case decl of Util.RenderedDecl innerDecl -> prettyElmSyntaxDeclaration noAliases innerDecl @@ -759,6 +759,7 @@ type alias Context = } +topContext : { precedence : number, isTop : Bool, isLeftPipe : Bool } topContext = { precedence = 11 , isTop = True @@ -1015,7 +1016,7 @@ prettyOperatorApplication aliases indent symbol dir exprl exprr = prettyOperatorApplicationLeft : Aliases -> Int -> String -> InfixDirection -> Node Expression -> Node Expression -> ( Doc t, Bool ) -prettyOperatorApplicationLeft aliases indent symbol _ (Node _ exprl) (Node _ exprr) = +prettyOperatorApplicationLeft aliases _ symbol _ (Node _ exprl) (Node _ exprr) = let context = { precedence = precedence symbol From 81a37d8c4978428c209f847b917fdd23c4a0643a Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 16:46:48 +0200 Subject: [PATCH 11/19] Ignore missing docs for now --- review/suppressed/Docs.NoMissing.json | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 review/suppressed/Docs.NoMissing.json diff --git a/review/suppressed/Docs.NoMissing.json b/review/suppressed/Docs.NoMissing.json new file mode 100644 index 00000000..4fe7a449 --- /dev/null +++ b/review/suppressed/Docs.NoMissing.json @@ -0,0 +1,14 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 32, "filePath": "src/Elm/Case/Branch.elm" }, + { "count": 29, "filePath": "src/Elm.elm" }, + { "count": 22, "filePath": "src/Elm/Annotation.elm" }, + { "count": 13, "filePath": "src/Elm/Case.elm" }, + { "count": 9, "filePath": "src/Elm/Let.elm" }, + { "count": 8, "filePath": "src/Elm/Declare.elm" }, + { "count": 6, "filePath": "src/Elm/ToString.elm" } + ] +} From d25c03c7a35176637b9c6893b63b4b0d50278e94 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 16:57:06 +0200 Subject: [PATCH 12/19] Add missing rules --- review/src/ReviewConfig.elm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/review/src/ReviewConfig.elm b/review/src/ReviewConfig.elm index c49f01fe..dcd8b4a0 100644 --- a/review/src/ReviewConfig.elm +++ b/review/src/ReviewConfig.elm @@ -45,7 +45,7 @@ config = } , Docs.ReviewLinksAndSections.rule , Docs.ReviewAtDocs.rule - -- , Docs.UpToDateReadmeLinks.rule + , Docs.UpToDateReadmeLinks.rule , NoDebug.Log.rule , NoDebug.TodoOrToString.rule |> Rule.ignoreErrorsForDirectories [ "tests/" ] @@ -55,7 +55,7 @@ config = , NoMissingTypeAnnotationInLetIn.rule , NoSimpleLetBody.rule , NoPrematureLetComputation.rule - -- , NoUnused.CustomTypeConstructors.rule [] + , NoUnused.CustomTypeConstructors.rule [] , NoUnused.CustomTypeConstructorArgs.rule , NoUnused.Exports.rule , NoUnused.Parameters.rule From 39707fd17a24a3fe2b535c3686bdabc35c2c3513 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 16:57:15 +0200 Subject: [PATCH 13/19] Add missing annotations --- src/Elm.elm | 54 ++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 17 deletions(-) diff --git a/src/Elm.elm b/src/Elm.elm index 0c91e06b..5fd4c1c1 100644 --- a/src/Elm.elm +++ b/src/Elm.elm @@ -103,6 +103,7 @@ import Elm.Processing import Elm.Syntax.Declaration as Declaration import Elm.Syntax.Exposing as Expose import Elm.Syntax.Expression as Exp +import Elm.Syntax.File import Elm.Syntax.Module import Elm.Syntax.Node as Node exposing (Node(..)) import Elm.Syntax.Pattern as Pattern @@ -131,6 +132,7 @@ type alias Expression = toString : Expression -> String toString (Compiler.Expression toExp) = let + expresh : Compiler.ExpressionDetails expresh = toExp Index.startIndex in @@ -297,13 +299,12 @@ value details = case details.annotation of Nothing -> let + typename : String typename = Index.protectTypeName details.name index in Ok - { type_ = - Annotation.GenericType - typename + { type_ = Annotation.GenericType typename , inferences = Dict.empty , aliases = Compiler.emptyAliases } @@ -345,6 +346,7 @@ withType ((Compiler.Annotation annDetails) as ann) (Compiler.Expression toExp) = Compiler.Expression <| \index -> let + exp : Compiler.ExpressionDetails exp = toExp index in @@ -387,9 +389,11 @@ unwrapper modName typename = Compiler.Expression <| \index -> let + arg : { name : String, typename : String, val : Compiler.Expression, index : Index.Index } arg = Compiler.toVar index "val" + return : { name : String, typename : String, val : Compiler.Expression, index : Index.Index } return = Compiler.toVar arg.index "unwrapped" in @@ -727,6 +731,7 @@ list exprs = Compiler.expression <| \index -> let + exprDetails : List Compiler.ExpressionDetails exprDetails = Compiler.thread index exprs in @@ -773,12 +778,14 @@ updateRecord fields recordExpression = |> List.foldl (\( fieldNameUnformatted, fieldExp ) ( currentIndex, fieldAnnotationResult, items ) -> let + fieldName : String fieldName = Format.formatValue fieldNameUnformatted ( newIndex, exp ) = Compiler.toExpressionDetails currentIndex fieldExp + currentFieldAnnotations : Result (List Compiler.InferenceError) (List ( String, Compiler.Inference )) currentFieldAnnotations = case fieldAnnotationResult of Ok fieldAnns -> @@ -820,6 +827,7 @@ updateRecord fields recordExpression = _ -> let + name : String name = "record" ++ Index.indexToString fieldIndex in @@ -920,6 +928,7 @@ record fields = Compiler.expression <| \index -> let + unified : { index : Index.Index, fields : List ( Node String, Node Exp.Expression ), passed : Set.Set String, errors : List Compiler.InferenceError, fieldAnnotations : List ( String, Compiler.Inference ), imports : List Compiler.Module } unified = fields |> List.foldl @@ -928,6 +937,7 @@ record fields = ( newIndex, exp ) = Compiler.toExpressionDetails found.index fieldExpression + fieldName : String fieldName = Format.formatValue unformattedFieldName in @@ -1090,6 +1100,7 @@ get unformattedFieldName recordExpression = Compiler.Expression <| \index -> let + fieldName : String fieldName = Format.formatValue unformattedFieldName @@ -1148,23 +1159,16 @@ verifyFieldsHelper existingFields updatedFields = True ( fieldName, fieldInference ) :: remain -> - if presentAndMatching fieldName fieldInference existingFields then - verifyFieldsHelper existingFields remain - - else - False + presentAndMatching fieldName fieldInference existingFields + && verifyFieldsHelper existingFields remain -presentAndMatching fieldName fieldInference existingFields = - List.foldl - (\(Node.Node _ ( Node.Node _ existingFieldName, _ )) gathered -> - if gathered then - gathered - - else - fieldName == existingFieldName +presentAndMatching : String -> Compiler.Inference -> List (Node Annotation.RecordField) -> Bool +presentAndMatching fieldName _ existingFields = + List.any + (\(Node.Node _ ( Node.Node _ existingFieldName, _ )) -> + fieldName == existingFieldName ) - False existingFields @@ -1324,6 +1328,7 @@ apply fnExp argExpressions = ( annotationIndex, fnDetails ) = Compiler.toExpressionDetails index fnExp + args : List Compiler.ExpressionDetails args = Compiler.thread annotationIndex argExpressions in @@ -1390,12 +1395,14 @@ fn ( oneBaseName, maybeAnnotation ) toExpression = Compiler.expression <| \index -> let + one : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } one = Compiler.toVarMaybeType index oneBaseName maybeAnnotation (Compiler.Expression toExpr) = toExpression one.val + return : Compiler.ExpressionDetails return = toExpr one.index in @@ -1445,9 +1452,11 @@ functionReduced argBaseName toExpression = ( arg1Name, newIndex ) = Index.getName argBaseName index + argType : Elm.Annotation.Annotation argType = Elm.Annotation.var arg1Name + arg1 : Expression arg1 = value { importFrom = [] @@ -1458,6 +1467,7 @@ functionReduced argBaseName toExpression = (Compiler.Expression toExpr) = toExpression arg1 + return : Compiler.ExpressionDetails return = toExpr newIndex in @@ -1504,6 +1514,7 @@ popLastAndDenodeLast lst = betaReduce : Exp.Expression -> Exp.Expression betaReduce e = let + extractLastArg : Exp.Expression -> Maybe String extractLastArg arg = case arg of Exp.FunctionOrValue [] n -> @@ -1982,6 +1993,7 @@ sep = "\n----\n" +renderDebugDocumentation : Result String value -> Result (List Compiler.InferenceError) Compiler.Inference -> Maybe String renderDebugDocumentation resolvedType bodyAnnotation = case resolvedType of Ok _ -> @@ -2388,6 +2400,7 @@ portIncoming nameStr args = } +groupAnn : Node Annotation.TypeAnnotation -> Node Annotation.TypeAnnotation groupAnn ann = Annotation.Tupled [ ann ] @@ -2468,10 +2481,12 @@ parse source = Ok raw -> let + parsedFile : Elm.Syntax.File.File parsedFile = Elm.Processing.process elmProcessContext raw + exposedList : Expose.Exposing exposedList = Compiler.denode parsedFile.moduleDefinition |> Elm.Syntax.Module.exposingList @@ -2516,6 +2531,7 @@ parse source = } +decName : Declaration.Declaration -> Maybe String decName decBody = case decBody of Declaration.FunctionDeclaration func -> @@ -2559,9 +2575,11 @@ determineExposure dec exposedDec = case dec of Declaration.FunctionDeclaration myFn -> let + implementation : Exp.FunctionImplementation implementation = Compiler.denode myFn.declaration + name : String name = Compiler.denode implementation.name in @@ -2573,6 +2591,7 @@ determineExposure dec exposedDec = Declaration.AliasDeclaration typeAlias -> let + name : String name = Compiler.denode typeAlias.name in @@ -2584,6 +2603,7 @@ determineExposure dec exposedDec = Declaration.CustomTypeDeclaration type_ -> let + name : String name = Compiler.denode type_.name in From 7ee58b08c9c73b1a6704f4eb9895be3be920abac Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 17:14:37 +0200 Subject: [PATCH 14/19] Simplify folds, add type annotations --- src/Elm/ToString.elm | 15 ++++----------- src/Internal/Compiler.elm | 37 +++++++------------------------------ src/Internal/Debug.elm | 28 ++++++---------------------- tests/PackageHelpers.elm | 20 +++++++++++--------- tests/TypeChecking.elm | 1 + 5 files changed, 29 insertions(+), 72 deletions(-) diff --git a/src/Elm/ToString.elm b/src/Elm/ToString.elm index d3127210..0af18243 100644 --- a/src/Elm/ToString.elm +++ b/src/Elm/ToString.elm @@ -76,17 +76,10 @@ expressionWith options (Compiler.Expression toExp) = errMsg Err inferenceError -> - List.foldl - (\err str -> - case str of - "" -> - Compiler.inferenceErrorToString err - - _ -> - str ++ "\n\n" ++ Compiler.inferenceErrorToString err - ) - "Err: " - inferenceError + "Err: " + ++ String.join + "\n\n" + (List.map Compiler.inferenceErrorToString inferenceError) } diff --git a/src/Internal/Compiler.elm b/src/Internal/Compiler.elm index 848add92..de298063 100644 --- a/src/Internal/Compiler.elm +++ b/src/Internal/Compiler.elm @@ -239,17 +239,9 @@ facts (Expression exp) = |> Ok Err inferenceError -> - List.foldl - (\err str -> - case str of - "" -> - inferenceErrorToString err - - _ -> - str ++ "\n\n" ++ inferenceErrorToString err - ) - "" - inferenceError + inferenceError + |> List.map inferenceErrorToString + |> String.join "\n\n" |> Err @@ -1500,25 +1492,10 @@ rewriteTypeVariablesHelper existing renames type_ = {-| -} simplify : String -> String simplify fullStr = - String.split "_" fullStr - |> List.foldl - (\piece str -> - let - isDigit = - String.all Char.isDigit piece - in - if isDigit then - str - - else - case str of - "" -> - piece - - _ -> - str ++ "_" ++ piece - ) - "" + fullStr + |> String.split "_" + |> List.filter (\piece -> not <| String.all Char.isDigit piece) + |> String.join "_" checkRestrictions : Restrictions -> Annotation.TypeAnnotation -> Result String Annotation.TypeAnnotation diff --git a/src/Internal/Debug.elm b/src/Internal/Debug.elm index c84b947d..1b9fb499 100644 --- a/src/Internal/Debug.elm +++ b/src/Internal/Debug.elm @@ -28,17 +28,9 @@ facts (Compiler.Expression exp) = |> Ok Err inferenceError -> - List.foldl - (\err str -> - case str of - "" -> - Compiler.inferenceErrorToString err - - _ -> - str ++ "\n\n" ++ Compiler.inferenceErrorToString err - ) - "" - inferenceError + inferenceError + |> List.map Compiler.inferenceErrorToString + |> String.join "\n\n" |> Err @@ -162,15 +154,7 @@ annotation ann = } Err inferenceError -> - List.foldl - (\err str -> - case str of - "" -> - Compiler.inferenceErrorToString err - - _ -> - str ++ "\n\n" ++ Compiler.inferenceErrorToString err - ) - "" - inferenceError + inferenceError + |> List.map Compiler.inferenceErrorToString + |> String.join "\n\n" |> Err diff --git a/tests/PackageHelpers.elm b/tests/PackageHelpers.elm index 220963d4..88ace4fe 100644 --- a/tests/PackageHelpers.elm +++ b/tests/PackageHelpers.elm @@ -17,9 +17,9 @@ import Test exposing (Test, describe, test) detectCycles : List ( String, TypeAnnotation ) -> List Bool detectCycles list = let + dict : Dict String TypeAnnotation dict = - list - |> Dict.fromList + Dict.fromList list in dict |> Dict.keys @@ -32,9 +32,9 @@ detectCycles list = countCycles : List ( String, TypeAnnotation ) -> List number countCycles list = let + dict : Dict String TypeAnnotation dict = - list - |> Dict.fromList + Dict.fromList list in dict |> Dict.keys @@ -52,14 +52,12 @@ hasCycles dict key found = Just type_ -> let + val : String val = Internal.Write.writeAnnotation type_ in - if List.member val found then - True - - else - hasCycles dict val (val :: found) + List.member val found + || hasCycles dict val (val :: found) findDepth : Dict String TypeAnnotation -> String -> List String -> number -> number @@ -70,6 +68,7 @@ findDepth dict key found depth = Just type_ -> let + val : String val = Internal.Write.writeAnnotation type_ in @@ -99,10 +98,12 @@ packageHelpers = , test "typechecking an Element.row doesn't hang forever" <| \_ -> let + myRow : Elm.Expression myRow = Gen.Element.row [ Gen.Element.spacing 5 ] [ Gen.Element.none ] + layout : Elm.Expression layout = Gen.Element.layout [] (Gen.Element.column [ Gen.Element.spacing 24 ] @@ -112,6 +113,7 @@ packageHelpers = ] ) + cycles : Bool cycles = layout |> Compiler.facts diff --git a/tests/TypeChecking.elm b/tests/TypeChecking.elm index 2fac12d1..6f401382 100644 --- a/tests/TypeChecking.elm +++ b/tests/TypeChecking.elm @@ -170,6 +170,7 @@ generatedCode = , test "Function, arg order isn't reversed" <| \_ -> let + exp : Elm.Expression exp = Elm.function [ ( "str", Just Type.string ) From 4d93e62aed47cbc2fda39c0acf291411d664dca6 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 17:55:51 +0200 Subject: [PATCH 15/19] Add missing type annotations, create `Result.Extra` for cleaner iteration --- .../NoMissingTypeAnnotationInLetIn.json | 27 ---- src/Internal/Compiler.elm | 120 +++++++----------- src/Internal/Debug.elm | 5 + src/Internal/Format.elm | 1 + src/Internal/ImportsAndExposing.elm | 5 + src/Internal/Index.elm | 3 + src/Internal/Render.elm | 25 ++-- src/Internal/Types.elm | 1 + src/Internal/Write.elm | 56 +++++++- src/Result/Extra.elm | 21 +++ 10 files changed, 139 insertions(+), 125 deletions(-) delete mode 100644 review/suppressed/NoMissingTypeAnnotationInLetIn.json create mode 100644 src/Result/Extra.elm diff --git a/review/suppressed/NoMissingTypeAnnotationInLetIn.json b/review/suppressed/NoMissingTypeAnnotationInLetIn.json deleted file mode 100644 index 6671c010..00000000 --- a/review/suppressed/NoMissingTypeAnnotationInLetIn.json +++ /dev/null @@ -1,27 +0,0 @@ -{ - "version": 1, - "automatically created by": "elm-review suppress", - "learn more": "elm-review suppress --help", - "suppressions": [ - { "count": 59, "filePath": "src/Elm.elm" }, - { "count": 49, "filePath": "src/Internal/Write.elm" }, - { "count": 38, "filePath": "src/Elm/Case.elm" }, - { "count": 28, "filePath": "src/Elm/Declare.elm" }, - { "count": 15, "filePath": "src/Internal/Compiler.elm" }, - { "count": 9, "filePath": "src/Elm/Let.elm" }, - { "count": 8, "filePath": "src/Internal/Render.elm" }, - { "count": 7, "filePath": "tests/PackageHelpers.elm" }, - { "count": 5, "filePath": "src/Elm/Case/Branch.elm" }, - { "count": 5, "filePath": "src/Internal/Debug.elm" }, - { "count": 4, "filePath": "src/Internal/ImportsAndExposing.elm" }, - { "count": 3, "filePath": "src/Elm/Op.elm" }, - { "count": 3, "filePath": "src/Internal/Clean.elm" }, - { "count": 3, "filePath": "src/Internal/Index.elm" }, - { "count": 2, "filePath": "src/Elm/ToString.elm" }, - { "count": 1, "filePath": "src/Error/Format.elm" }, - { "count": 1, "filePath": "src/Internal/Comments.elm" }, - { "count": 1, "filePath": "src/Internal/Format.elm" }, - { "count": 1, "filePath": "src/Internal/Types.elm" }, - { "count": 1, "filePath": "tests/TypeChecking.elm" } - ] -} diff --git a/src/Internal/Compiler.elm b/src/Internal/Compiler.elm index de298063..60ce9460 100644 --- a/src/Internal/Compiler.elm +++ b/src/Internal/Compiler.elm @@ -11,6 +11,7 @@ import Elm.Syntax.TypeAnnotation as Annotation import Elm.Writer import Internal.Format as Format import Internal.Index as Index exposing (Index) +import Result.Extra import Set exposing (Set) @@ -696,6 +697,7 @@ getAnnotation exp = documentation : String -> Declaration -> Declaration documentation rawDoc decl = let + doc : String doc = String.trim rawDoc in @@ -980,22 +982,7 @@ getExposedGroups decls = matchName : Maybe a -> Maybe a -> Bool matchName one two = - case one of - Nothing -> - case two of - Nothing -> - True - - _ -> - False - - Just oneName -> - case two of - Nothing -> - False - - Just twoName -> - oneName == twoName + one == two groupExposing : List ( Maybe String, String ) -> List { group : Maybe String, members : List String } @@ -1118,6 +1105,7 @@ resolve index cache annotation = case resolveVariables Set.empty cache annotation of Ok newAnnotation -> let + restrictions : Restrictions restrictions = getRestrictions annotation cache in @@ -1172,71 +1160,45 @@ resolveVariables visited cache annotation = Result.map Annotation.Tupled (resolveVariableList visited cache nodes []) Annotation.Record fields -> - Result.map (Annotation.Record << List.reverse) - (List.foldl - (\(Node fieldRange ( name, Node fieldTypeRange fieldType )) found -> - case found of - Err err -> - Err err - - Ok processedFields -> - case resolveVariables visited cache fieldType of - Err err -> - Err err - - Ok resolvedField -> - let - restrictions = - getRestrictions annotation cache - in - case checkRestrictions restrictions resolvedField of - Ok _ -> - Ok - (Node fieldRange - ( name, Node fieldTypeRange resolvedField ) - :: processedFields - ) - - Err err -> - -- Note, this error probably need - Err err - ) - (Ok []) - fields + Result.Extra.combineMap + (\(Node fieldRange ( name, Node fieldTypeRange fieldType )) -> + resolveVariables visited cache fieldType + |> Result.andThen + (\resolvedField -> + let + restrictions : Restrictions + restrictions = + getRestrictions annotation cache + in + Result.map + (\_ -> + Node fieldRange + ( name, Node fieldTypeRange resolvedField ) + ) + (checkRestrictions restrictions resolvedField) + ) ) + fields + |> Result.map Annotation.Record Annotation.GenericRecord baseName (Node recordNode fields) -> - let - newFieldResult = - List.foldl - (\(Node fieldRange ( name, Node fieldTypeRange fieldType )) found -> - case found of - Err err -> - Err err - - Ok processedFields -> - case resolveVariables visited cache fieldType of - Err err -> - Err err - - Ok resolvedField -> - Ok - (Node fieldRange - ( name, Node fieldTypeRange resolvedField ) - :: processedFields - ) - ) - (Ok []) - fields - in - Result.map - (\newFields -> - Annotation.GenericRecord baseName - (Node recordNode - (List.reverse newFields) + Result.Extra.combineMap + (\(Node fieldRange ( name, Node fieldTypeRange fieldType )) -> + Result.map + (\resolvedField -> + Node fieldRange + ( name, Node fieldTypeRange resolvedField ) ) + (resolveVariables visited cache fieldType) ) - newFieldResult + fields + |> Result.map + (\newFields -> + Annotation.GenericRecord baseName + (Node recordNode + newFields + ) + ) resolveVariableList : @@ -1417,6 +1379,7 @@ getRestrictionsHelper existingRestrictions notation cache = rewriteTypeVariables : Annotation.TypeAnnotation -> Annotation.TypeAnnotation rewriteTypeVariables type_ = let + existing : Set String existing = getGenericsHelper type_ |> Set.fromList @@ -1431,6 +1394,7 @@ rewriteTypeVariablesHelper existing renames type_ = case Dict.get varName renames of Nothing -> let + simplified : String simplified = simplify varName in @@ -1689,6 +1653,7 @@ applyTypeHelper aliases cache fn args = _ -> let + resultType : Annotation.TypeAnnotation resultType = Annotation.GenericType (varName ++ "_result") in @@ -1863,6 +1828,7 @@ unifyWithAlias aliases vars typename typeVars typeToUnifyWith = Just foundAlias -> let + fullAliasedType : Annotation.TypeAnnotation fullAliasedType = case foundAlias.variables of [] -> @@ -1870,6 +1836,7 @@ unifyWithAlias aliases vars typename typeVars typeToUnifyWith = _ -> let + makeAliasVarCache : a -> Node b -> ( a, b ) makeAliasVarCache varName (Node.Node _ varType) = ( varName, varType ) in @@ -2613,6 +2580,7 @@ containsFieldByName ( Node.Node _ oneName, _ ) ( Node.Node _ twoName, _ ) = inferRecordField : Index -> { nameOfRecord : String, fieldName : String } -> Result (List InferenceError) Inference inferRecordField index { nameOfRecord, fieldName } = let + fieldType : Annotation.TypeAnnotation fieldType = Annotation.GenericType (Format.formatValue diff --git a/src/Internal/Debug.elm b/src/Internal/Debug.elm index 1b9fb499..fb340957 100644 --- a/src/Internal/Debug.elm +++ b/src/Internal/Debug.elm @@ -14,6 +14,7 @@ import Internal.Write facts : Compiler.Expression -> Result String (List ( String, String )) facts (Compiler.Expression exp) = let + expresh : Compiler.ExpressionDetails expresh = exp Index.startIndex in @@ -40,6 +41,7 @@ everythingFormatted : -> List String everythingFormatted log exp = let + every : Result String { facts : List ( String, String ), signature : String, aliases : List ( String, String ) } every = everything exp @@ -74,6 +76,7 @@ annotationFormatted : -> List String annotationFormatted log ann = let + every : Result String { facts : List ( String, String ), signature : String, aliases : List ( String, String ) } every = annotation ann @@ -111,6 +114,7 @@ everything : } everything (Compiler.Expression exp) = let + expresh : Compiler.ExpressionDetails expresh = exp Index.startIndex in @@ -133,6 +137,7 @@ annotation ann = case ann of Ok sig -> let + allFacts : List ( String, String ) allFacts = sig.inferences |> Dict.toList diff --git a/src/Internal/Format.elm b/src/Internal/Format.elm index 751428e0..ce1b2917 100644 --- a/src/Internal/Format.elm +++ b/src/Internal/Format.elm @@ -10,6 +10,7 @@ module Internal.Format exposing (formatDeclarationName, formatType, formatValue, formatValue : String -> String formatValue str = let + formatted : String formatted = String.toLower (String.left 1 str) ++ String.dropLeft 1 str in diff --git a/src/Internal/ImportsAndExposing.elm b/src/Internal/ImportsAndExposing.elm index 32939681..9135eb41 100644 --- a/src/Internal/ImportsAndExposing.elm +++ b/src/Internal/ImportsAndExposing.elm @@ -2,6 +2,7 @@ module Internal.ImportsAndExposing exposing (sortAndDedupExposings, sortAndDedup import Elm.Syntax.Exposing exposing (Exposing(..), TopLevelExpose(..)) import Elm.Syntax.Import exposing (Import) +import Elm.Syntax.ModuleName import Elm.Syntax.Node as Node exposing (Node(..)) import Elm.Syntax.Range exposing (emptyRange) @@ -61,6 +62,7 @@ groupByExposingName innerImports = List.foldl (\exp ( currName, currAccum, accum ) -> let + nextName : String nextName = topLevelExposeName exp in @@ -161,6 +163,7 @@ sortAndDedupExposing exp = sortAndDedupImports : List Import -> List Import sortAndDedupImports imports = let + impName : Import -> Elm.Syntax.ModuleName.ModuleName impName imp = denode imp.moduleName in @@ -181,6 +184,7 @@ groupByModuleName innerImports = List.foldl (\imp ( currName, currAccum, accum ) -> let + nextName : Elm.Syntax.ModuleName.ModuleName nextName = denode imp.moduleName in @@ -207,6 +211,7 @@ combineImports innerImports = hd :: tl -> let + combinedImports : Import combinedImports = List.foldl (\imp result -> diff --git a/src/Internal/Index.elm b/src/Internal/Index.elm index d0aa2956..6fd62c6a 100644 --- a/src/Internal/Index.elm +++ b/src/Internal/Index.elm @@ -81,6 +81,7 @@ dive (Index top tail scope check) = getName : String -> Index -> ( String, Index ) getName desiredName ((Index top tail scope check) as index) = let + formattedName : String formattedName = Format.formatValue desiredName in @@ -89,6 +90,7 @@ getName desiredName ((Index top tail scope check) as index) = else let + protectedName : String protectedName = formattedName ++ String.fromInt top in @@ -99,6 +101,7 @@ getName desiredName ((Index top tail scope check) as index) = else let + protectedNameLevel2 : String protectedNameLevel2 = formattedName ++ indexToString index in diff --git a/src/Internal/Render.elm b/src/Internal/Render.elm index 4555de3c..a58f792f 100644 --- a/src/Internal/Render.elm +++ b/src/Internal/Render.elm @@ -50,6 +50,7 @@ render : -> File render toDocComment fileDetails = let + rendered : { declarations : List Compiler.RenderedDeclaration, imports : List Compiler.Module, exposed : List Expose.TopLevelExpose, exposedGroups : List ( Maybe String, String ), hasPorts : Bool, warnings : List Compiler.Warning } rendered = List.foldl (\decl gathered -> @@ -62,6 +63,7 @@ render toDocComment fileDetails = Compiler.Declaration decDetails -> let + result : { declaration : Elm.Syntax.Declaration.Declaration, additionalImports : List Compiler.Module, warning : Maybe Compiler.Warning } result = decDetails.toBody fileDetails.index in @@ -107,6 +109,7 @@ render toDocComment fileDetails = } fileDetails.declarations + body : String body = Internal.Write.write { moduleDefinition = @@ -178,6 +181,7 @@ dedupImports mods = List.foldl (\mod ( set, gathered ) -> let + stringName : String stringName = Compiler.fullModName mod in @@ -245,6 +249,7 @@ addExposed exposed declaration otherExposes = case declaration of Elm.Syntax.Declaration.FunctionDeclaration fn -> let + fnName : String fnName = Compiler.denode (.name (Compiler.denode fn.declaration)) in @@ -253,6 +258,7 @@ addExposed exposed declaration otherExposes = Elm.Syntax.Declaration.AliasDeclaration synonym -> let + aliasName : String aliasName = Compiler.denode synonym.name in @@ -261,6 +267,7 @@ addExposed exposed declaration otherExposes = Elm.Syntax.Declaration.CustomTypeDeclaration myType -> let + typeName : String typeName = Compiler.denode myType.name in @@ -277,6 +284,7 @@ addExposed exposed declaration otherExposes = Elm.Syntax.Declaration.PortDeclaration myPort -> let + typeName : String typeName = Compiler.denode myPort.name in @@ -315,19 +323,4 @@ groupExposing items = matchName : Maybe a -> Maybe a -> Bool matchName one two = - case one of - Nothing -> - case two of - Nothing -> - True - - _ -> - False - - Just oneName -> - case two of - Nothing -> - False - - Just twoName -> - oneName == twoName + one == two diff --git a/src/Internal/Types.elm b/src/Internal/Types.elm index b2c7b9e8..13ebd45a 100644 --- a/src/Internal/Types.elm +++ b/src/Internal/Types.elm @@ -19,6 +19,7 @@ nodify exp = formatValue : String -> String formatValue str = let + formatted : String formatted = if String.toUpper str == str then String.toLower str diff --git a/src/Internal/Write.elm b/src/Internal/Write.elm index 10d1cdb7..e972f800 100644 --- a/src/Internal/Write.elm +++ b/src/Internal/Write.elm @@ -254,6 +254,7 @@ prettyPortModuleData moduleData = prettyEffectModuleData : EffectModuleData -> Doc t prettyEffectModuleData moduleData = let + prettyCmdAndSub : Maybe String -> Maybe String -> Maybe (Doc t) prettyCmdAndSub maybeCmd maybeSub = case ( maybeCmd, maybeSub ) of ( Nothing, Nothing ) -> @@ -335,6 +336,7 @@ The exposed values will be de-duplicated and sorted. prettyExposing : Exposing -> Doc t prettyExposing exposing_ = let + exposings : Doc t exposings = case exposing_ of All _ -> @@ -464,6 +466,7 @@ prettyFun aliases fn = prettyTypeAlias : Aliases -> TypeAlias -> Doc t prettyTypeAlias aliases tAlias = let + typeAliasPretty : Doc t typeAliasPretty = [ Pretty.string "type alias" , Pretty.string (denode tAlias.name) @@ -486,6 +489,7 @@ prettyTypeAlias aliases tAlias = prettyCustomType : Aliases -> Type -> Doc t prettyCustomType aliases type_ = let + customTypePretty : Doc t customTypePretty = [ Pretty.string "type" , Pretty.string (denode type_.name) @@ -532,6 +536,7 @@ prettyPortDeclaration aliases sig = prettyInfix : Infix -> Doc t prettyInfix infix_ = let + dirToString : InfixDirection -> String dirToString direction = case direction of Left -> @@ -623,6 +628,7 @@ prettyPattern aliases pattern = adjustPatternParentheses : Bool -> Pattern -> Pattern adjustPatternParentheses isTop pattern = let + addParens : Pattern -> Pattern addParens pat = case ( isTop, pat ) of ( False, NamedPattern _ (_ :: _) ) -> @@ -634,6 +640,7 @@ adjustPatternParentheses isTop pattern = _ -> pat + removeParens : Pattern -> Pattern removeParens pat = case pat of ParenthesizedPattern (Node _ innerPat) -> @@ -646,6 +653,7 @@ adjustPatternParentheses isTop pattern = _ -> pat + shouldRemove : Pattern -> Bool shouldRemove pat = case ( isTop, pat ) of ( False, NamedPattern _ _ ) -> @@ -716,9 +724,11 @@ prettyPatternInner aliases isTop pattern = _ -> let + open : Doc t open = Pretty.a Pretty.space (Pretty.string "[") + close : Doc t close = Pretty.a (Pretty.string "]") Pretty.space in @@ -770,6 +780,7 @@ topContext = adjustExpressionParentheses : Context -> Expression -> Expression adjustExpressionParentheses context expression = let + addParens : Expression -> Expression addParens expr = case ( context.isTop, context.isLeftPipe, expr ) of ( False, False, LetExpression _ ) -> @@ -787,6 +798,7 @@ adjustExpressionParentheses context expression = _ -> expr + removeParens : Expression -> Expression removeParens expr = case expr of ParenthesizedExpression (Node _ innerExpr) -> @@ -799,6 +811,7 @@ adjustExpressionParentheses context expression = _ -> expr + shouldRemove : Expression -> Bool shouldRemove expr = case ( context.isTop, context.isLeftPipe, expr ) of ( True, _, _ ) -> @@ -998,12 +1011,7 @@ prettyApplication aliases indent exprs = isEndLineOperator : String -> Bool isEndLineOperator op = - case op of - "<|" -> - True - - _ -> - False + op == "<|" prettyOperatorApplication : Aliases -> Int -> String -> InfixDirection -> Node Expression -> Node Expression -> ( Doc t, Bool ) @@ -1018,6 +1026,7 @@ prettyOperatorApplication aliases indent symbol dir exprl exprr = prettyOperatorApplicationLeft : Aliases -> Int -> String -> InfixDirection -> Node Expression -> Node Expression -> ( Doc t, Bool ) prettyOperatorApplicationLeft aliases _ symbol _ (Node _ exprl) (Node _ exprr) = let + context : Context context = { precedence = precedence symbol , isTop = False @@ -1030,6 +1039,7 @@ prettyOperatorApplicationLeft aliases _ symbol _ (Node _ exprl) (Node _ exprr) = ( prettyExpressionRight, alwaysBreakRight ) = prettyExpressionInner aliases context 4 exprr + alwaysBreak : Bool alwaysBreak = alwaysBreakLeft || alwaysBreakRight in @@ -1058,21 +1068,25 @@ prettyOperatorApplicationRight aliases indent symbol _ exprl exprr = innerOpApply : Bool -> String -> Node Expression -> Node Expression -> List ( Doc t, Bool ) innerOpApply isTop sym (Node _ left) (Node _ right) = let + context : Context context = { precedence = precedence sym , isTop = False , isLeftPipe = "<|" == sym } + innerIndent : Int innerIndent = decrementIndent 4 (String.length symbol + 1) + rightSide : List ( Doc t, Bool ) rightSide = right |> expandExpr innerIndent context in case rightSide of ( hdExpr, hdBreak ) :: tl -> let + leftIndent : Int leftIndent = if isTop then indent @@ -1105,6 +1119,7 @@ prettyIfBlock aliases indent exprBool exprTrue exprFalse = innerIfBlock : Node Expression -> Node Expression -> Node Expression -> List (Doc t) innerIfBlock (Node _ innerExprBool) (Node _ innerExprTrue) (Node _ innerExprFalse) = let + ifPart : Doc t ifPart = let ( _, alwaysBreak ) = @@ -1121,15 +1136,18 @@ prettyIfBlock aliases indent exprBool exprTrue exprFalse = |> Pretty.lines |> optionalGroup alwaysBreak + truePart : Doc t truePart = prettyExpressionInner aliases topContext 4 innerExprTrue |> Tuple.first |> Pretty.indent indent + elsePart : Doc t elsePart = Pretty.line |> Pretty.a (Pretty.string "else") + falsePart : List (Doc t) falsePart = case innerExprFalse of IfBlock nestedExprBool nestedExprTrue nestedExprFalse -> @@ -1160,6 +1178,7 @@ prettyIfBlock aliases indent exprBool exprTrue exprFalse = ] tl + prettyExpressions : List (Doc t) prettyExpressions = innerIfBlock exprBool exprTrue exprFalse in @@ -1189,9 +1208,11 @@ prettyTupledExpression aliases indent exprs = _ -> let + open : Doc t open = Pretty.a Pretty.space (Pretty.string "(") + close : Doc t close = Pretty.a (Pretty.string ")") Pretty.line @@ -1212,9 +1233,11 @@ prettyTupledExpression aliases indent exprs = prettyParenthesizedExpression : Aliases -> Int -> Node Expression -> ( Doc t, Bool ) prettyParenthesizedExpression aliases indent (Node _ expr) = let + open : Doc t open = Pretty.string "(" + close : Doc t close = Pretty.a (Pretty.string ")") Pretty.tightline @@ -1267,6 +1290,7 @@ prettyLetDeclaration aliases indent letDecl = prettyCaseBlock : Aliases -> Int -> CaseBlock -> ( Doc t, Bool ) prettyCaseBlock aliases indent caseBlock = let + casePart : Doc t casePart = let ( caseExpression, alwaysBreak ) = @@ -1283,6 +1307,7 @@ prettyCaseBlock aliases indent caseBlock = |> Pretty.lines |> optionalGroup alwaysBreak + prettyCase : Elm.Syntax.Expression.Case -> Doc t prettyCase ( Node _ pattern, Node _ expr ) = prettyPattern aliases pattern |> Pretty.a (Pretty.string " ->") @@ -1290,6 +1315,7 @@ prettyCaseBlock aliases indent caseBlock = |> Pretty.a (prettyExpressionInner aliases topContext 4 expr |> Tuple.first |> Pretty.indent 4) |> Pretty.indent indent + patternsPart : Doc t patternsPart = List.map prettyCase caseBlock.cases |> doubleLines @@ -1328,9 +1354,11 @@ prettyRecordExpr aliases setters = _ -> let + open : Doc t open = Pretty.a Pretty.space (Pretty.string "{") + close : Doc t close = Pretty.a (Pretty.string "}") Pretty.line @@ -1376,9 +1404,11 @@ prettyList aliases indent exprs = _ -> let + open : Doc t open = Pretty.a Pretty.space (Pretty.string "[") + close : Doc t close = Pretty.a (Pretty.string "]") Pretty.line @@ -1412,6 +1442,7 @@ prettyRecordAccess aliases (Node _ expr) (Node _ field) = prettyRecordUpdateExpression : Aliases -> Int -> Node String -> List (Node RecordSetter) -> ( Doc t, Bool ) prettyRecordUpdateExpression aliases indent (Node _ var) setters = let + addBarToFirst : List (Doc t) -> List (Doc t) addBarToFirst exprs = case exprs of [] -> @@ -1426,6 +1457,7 @@ prettyRecordUpdateExpression aliases indent (Node _ var) setters = _ -> let + open : Doc t open = [ Pretty.string "{" , Pretty.string var @@ -1433,6 +1465,7 @@ prettyRecordUpdateExpression aliases indent (Node _ var) setters = |> Pretty.words |> Pretty.a Pretty.line + close : Doc t close = Pretty.a (Pretty.string "}") Pretty.line @@ -1490,10 +1523,12 @@ prettyTypeAnnotation aliases typeAnn = prettyTyped : Aliases -> Node ( ModuleName, String ) -> List (Node TypeAnnotation) -> Doc t prettyTyped aliases (Node _ ( moduleName, typeName )) anns = let + typeDoc : Doc t typeDoc = prettyModuleNameDot aliases moduleName |> Pretty.a (Pretty.string typeName) + argsDoc : Doc t argsDoc = List.map (prettyTypeAnnotationParens aliases) (denodeAll anns) |> Pretty.words @@ -1532,9 +1567,11 @@ prettyRecord aliases fields = _ -> let + open : Doc t open = Pretty.a Pretty.space (Pretty.string "{") + close : Doc t close = Pretty.a (Pretty.string "}") Pretty.line in @@ -1549,6 +1586,7 @@ prettyRecord aliases fields = prettyGenericRecord : Aliases -> String -> List RecordField -> Doc t prettyGenericRecord aliases paramName fields = let + addBarToFirst : List (Doc t) -> List (Doc t) addBarToFirst exprs = case exprs of [] -> @@ -1563,6 +1601,7 @@ prettyGenericRecord aliases paramName fields = _ -> let + open : Doc t open = [ Pretty.string "{" , Pretty.string paramName @@ -1570,6 +1609,7 @@ prettyGenericRecord aliases paramName fields = |> Pretty.words |> Pretty.a Pretty.line + close : Doc t close = Pretty.a (Pretty.string "}") Pretty.line @@ -1624,6 +1664,7 @@ prettyFunctionTypeAnnotation aliases left right = innerFnTypeAnn : Node TypeAnnotation -> Node TypeAnnotation -> List (Doc t) innerFnTypeAnn (Node _ innerLeft) (Node _ innerRight) = let + rightSide : List (Doc t) rightSide = innerRight |> expandRight in @@ -1677,6 +1718,7 @@ prettyMaybe prettyFn maybeVal = decrementIndent : Int -> Int -> Int decrementIndent currentIndent spaces = let + modded : Int modded = modBy 4 (currentIndent - spaces) in @@ -1766,8 +1808,10 @@ optionalParens flag doc = toHexString : Int -> String toHexString val = let + padWithZeros : String -> String padWithZeros str = let + length : Int length = String.length str in diff --git a/src/Result/Extra.elm b/src/Result/Extra.elm new file mode 100644 index 00000000..11638aaf --- /dev/null +++ b/src/Result/Extra.elm @@ -0,0 +1,21 @@ +module Result.Extra exposing (combineMap) + + +combineMap : (a -> Result e b) -> List a -> Result e (List b) +combineMap f list = + combineMapHelper f [] list + + +combineMapHelper : (a -> Result e b) -> List b -> List a -> Result e (List b) +combineMapHelper f acc list = + case list of + [] -> + Ok (List.reverse acc) + + h :: t -> + case f h of + Err e -> + Err e + + Ok fh -> + combineMapHelper f (fh :: acc) t From 77853a73c14b04ab6b602d44cab2d73626951c57 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 18:21:30 +0200 Subject: [PATCH 16/19] Add suppressions --- review/suppressed/Docs.ReviewAtDocs.json | 8 ++++++++ review/suppressed/Docs.ReviewLinksAndSections.json | 8 ++++++++ review/suppressed/Docs.UpToDateReadmeLinks.json | 8 ++++++++ review/suppressed/NoUnused.CustomTypeConstructors.json | 9 +++++++++ review/suppressed/NoUnused.Parameters.json | 8 ++++++++ 5 files changed, 41 insertions(+) create mode 100644 review/suppressed/Docs.ReviewAtDocs.json create mode 100644 review/suppressed/Docs.ReviewLinksAndSections.json create mode 100644 review/suppressed/Docs.UpToDateReadmeLinks.json create mode 100644 review/suppressed/NoUnused.CustomTypeConstructors.json create mode 100644 review/suppressed/NoUnused.Parameters.json diff --git a/review/suppressed/Docs.ReviewAtDocs.json b/review/suppressed/Docs.ReviewAtDocs.json new file mode 100644 index 00000000..caa4ab64 --- /dev/null +++ b/review/suppressed/Docs.ReviewAtDocs.json @@ -0,0 +1,8 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 2, "filePath": "src/Elm.elm" } + ] +} diff --git a/review/suppressed/Docs.ReviewLinksAndSections.json b/review/suppressed/Docs.ReviewLinksAndSections.json new file mode 100644 index 00000000..ffeedf42 --- /dev/null +++ b/review/suppressed/Docs.ReviewLinksAndSections.json @@ -0,0 +1,8 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 1, "filePath": "src/Elm.elm" } + ] +} diff --git a/review/suppressed/Docs.UpToDateReadmeLinks.json b/review/suppressed/Docs.UpToDateReadmeLinks.json new file mode 100644 index 00000000..f77b0272 --- /dev/null +++ b/review/suppressed/Docs.UpToDateReadmeLinks.json @@ -0,0 +1,8 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 2, "filePath": "README.md" } + ] +} diff --git a/review/suppressed/NoUnused.CustomTypeConstructors.json b/review/suppressed/NoUnused.CustomTypeConstructors.json new file mode 100644 index 00000000..c2a8979a --- /dev/null +++ b/review/suppressed/NoUnused.CustomTypeConstructors.json @@ -0,0 +1,9 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 4, "filePath": "src/Internal/Compiler.elm" }, + { "count": 1, "filePath": "src/Internal/Comments.elm" } + ] +} diff --git a/review/suppressed/NoUnused.Parameters.json b/review/suppressed/NoUnused.Parameters.json new file mode 100644 index 00000000..4b9639bc --- /dev/null +++ b/review/suppressed/NoUnused.Parameters.json @@ -0,0 +1,8 @@ +{ + "version": 1, + "automatically created by": "elm-review suppress", + "learn more": "elm-review suppress --help", + "suppressions": [ + { "count": 1, "filePath": "src/Internal/Compiler.elm" } + ] +} From acb91c36b15c9a104917ba424506a51b9e188822 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 18:21:39 +0200 Subject: [PATCH 17/19] Deduplicate --- src/Elm/Declare.elm | 322 ++++++++++---------------------------------- 1 file changed, 73 insertions(+), 249 deletions(-) diff --git a/src/Elm/Declare.elm b/src/Elm/Declare.elm index 22355a92..5d523ac5 100644 --- a/src/Elm/Declare.elm +++ b/src/Elm/Declare.elm @@ -67,6 +67,7 @@ In that case you can do something like this using `callFrom`: import Elm exposing (Declaration, Expression) import Elm.Annotation import Elm.Syntax.Expression as Exp +import Elm.Syntax.ModuleName as ModuleName import Internal.Compiler as Compiler import Internal.Format as Format @@ -84,45 +85,13 @@ fn : } fn name one toExp = let + funcExp : Expression funcExp = Elm.fn one toExp - - valueFrom importFrom = - Compiler.Expression <| - \index -> - case funcExp of - Compiler.Expression toFnExp -> - let - fnExp = - toFnExp index - in - { expression = - -- This *must* be an un-protected name, where we only use - -- literally what the dev gives us, because we are trying - -- to refer to something that already exists. - Exp.FunctionOrValue importFrom - (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports - } - - call importFrom argOne = - Elm.apply - (valueFrom importFrom) - [ argOne ] in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom - } + innerFunction name funcExp <| + \call argOne -> + call [ argOne ] {-| -} @@ -139,45 +108,13 @@ fn2 : } fn2 name one two toExp = let + funcExp : Expression funcExp = Elm.fn2 one two toExp - - valueFrom importFrom = - Compiler.Expression <| - \index -> - case funcExp of - Compiler.Expression toFnExp -> - let - fnExp = - toFnExp index - in - { expression = - -- This *must* be an un-protected name, where we only use - -- literally what the dev gives us, because we are trying - -- to refer to something that already exists. - Exp.FunctionOrValue importFrom - (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports - } - - call importFrom argOne argTwo = - Elm.apply - (valueFrom importFrom) - [ argOne, argTwo ] in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom - } + innerFunction name funcExp <| + \call argOne argTwo -> + call [ argOne, argTwo ] {-| -} @@ -195,45 +132,13 @@ fn3 : } fn3 name one two three toExp = let + funcExp : Expression funcExp = Elm.fn3 one two three toExp - - valueFrom importFrom = - Compiler.Expression <| - \index -> - case funcExp of - Compiler.Expression toFnExp -> - let - fnExp = - toFnExp index - in - { expression = - -- This *must* be an un-protected name, where we only use - -- literally what the dev gives us, because we are trying - -- to refer to something that already exists. - Exp.FunctionOrValue importFrom - (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports - } - - call importFrom argOne argTwo argThree = - Elm.apply - (valueFrom importFrom) - [ argOne, argTwo, argThree ] in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom - } + innerFunction name funcExp <| + \call argOne argTwo argThree -> + call [ argOne, argTwo, argThree ] {-| -} @@ -252,45 +157,13 @@ fn4 : } fn4 name one two three four toExp = let + funcExp : Expression funcExp = Elm.fn4 one two three four toExp - - valueFrom importFrom = - Compiler.Expression <| - \index -> - case funcExp of - Compiler.Expression toFnExp -> - let - fnExp = - toFnExp index - in - { expression = - -- This *must* be an un-protected name, where we only use - -- literally what the dev gives us, because we are trying - -- to refer to something that already exists. - Exp.FunctionOrValue importFrom - (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports - } - - call importFrom argOne argTwo argThree argFour = - Elm.apply - (valueFrom importFrom) - [ argOne, argTwo, argThree, argFour ] in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom - } + innerFunction name funcExp <| + \call argOne argTwo argThree argFour -> + call [ argOne, argTwo, argThree, argFour ] {-| -} @@ -310,45 +183,13 @@ fn5 : } fn5 name one two three four five toExp = let + funcExp : Expression funcExp = Elm.fn5 one two three four five toExp - - valueFrom importFrom = - Compiler.Expression <| - \index -> - case funcExp of - Compiler.Expression toFnExp -> - let - fnExp = - toFnExp index - in - { expression = - -- This *must* be an un-protected name, where we only use - -- literally what the dev gives us, because we are trying - -- to refer to something that already exists. - Exp.FunctionOrValue importFrom - (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports - } - - call importFrom argOne argTwo argThree argFour argFive = - Elm.apply - (valueFrom importFrom) - [ argOne, argTwo, argThree, argFour, argFive ] in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom - } + innerFunction name funcExp <| + \call argOne argTwo argThree argFour argFive -> + call [ argOne, argTwo, argThree, argFour, argFive ] {-| -} @@ -369,15 +210,55 @@ fn6 : } fn6 name one two three four five six toExp = let + funcExp : Expression funcExp = Elm.fn6 one two three four five six toExp + in + innerFunction name funcExp <| + \call argOne argTwo argThree argFour argFive argSix -> + call [ argOne, argTwo, argThree, argFour, argFive, argSix ] + +{-| -} +function : + String + -> List ( String, Maybe Elm.Annotation.Annotation ) + -> (List Expression -> Expression) + -> + { declaration : Declaration + , call : List Expression -> Expression + , callFrom : List String -> List Expression -> Expression + , value : List String -> Expression + } +function name params toExp = + let + funcExp : Expression + funcExp = + Elm.function params toExp + in + innerFunction name funcExp identity + + +innerFunction : + String + -> Expression + -> ((List Expression -> Expression) -> a) + -> + { declaration : Declaration + , call : a + , callFrom : ModuleName.ModuleName -> a + , value : ModuleName.ModuleName -> Expression + } +innerFunction name funcExp collectArgs = + let + valueFrom : ModuleName.ModuleName -> Expression valueFrom importFrom = Compiler.Expression <| \index -> case funcExp of Compiler.Expression toFnExp -> let + fnExp : Compiler.ExpressionDetails fnExp = toFnExp index in @@ -387,26 +268,21 @@ fn6 name one two three four five six toExp = -- to refer to something that already exists. Exp.FunctionOrValue importFrom (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports + , annotation = fnExp.annotation + , imports = fnExp.imports } - call importFrom argOne argTwo argThree argFour argFive argSix = - Elm.apply - (valueFrom importFrom) - [ argOne, argTwo, argThree, argFour, argFive, argSix ] + call : ModuleName.ModuleName -> a + call importFrom = + collectArgs + (Elm.apply + (valueFrom importFrom) + ) in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom + { declaration = Elm.declaration name funcExp + , call = call [] + , callFrom = call + , value = valueFrom } @@ -434,55 +310,3 @@ value name expression = , value = declaration_.call [] , valueFrom = \from -> declaration_.callFrom from [] } - - -{-| -} -function : - String - -> List ( String, Maybe Elm.Annotation.Annotation ) - -> (List Expression -> Expression) - -> - { declaration : Declaration - , call : List Expression -> Expression - , callFrom : List String -> List Expression -> Expression - , value : List String -> Expression - } -function name params toExp = - let - funcExp = - Elm.function params toExp - - valueFrom importFrom = - Compiler.Expression <| - \index -> - case funcExp of - Compiler.Expression toFnExp -> - let - fnExp = - toFnExp index - in - { expression = - -- This *must* be an un-protected name, where we only use - -- literally what the dev gives us, because we are trying - -- to refer to something that already exists. - Exp.FunctionOrValue importFrom - (Format.sanitize name) - , annotation = - fnExp.annotation - , imports = - fnExp.imports - } - - call importFrom args = - Elm.apply (valueFrom importFrom) args - in - { declaration = - Elm.declaration name - funcExp - , call = - call [] - , callFrom = - call - , value = - valueFrom - } From 9a8417bd2c123d87e836e75b958fa215d9f6a256 Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 18:21:46 +0200 Subject: [PATCH 18/19] Add missing type annotations --- src/Elm/Let.elm | 9 +++++++++ src/Elm/Op.elm | 3 +++ src/Elm/ToString.elm | 6 ++++++ src/Error/Format.elm | 1 + src/Internal/Clean.elm | 3 +++ src/Internal/Comments.elm | 1 + src/Internal/Compiler.elm | 19 +++++++++---------- 7 files changed, 32 insertions(+), 10 deletions(-) diff --git a/src/Elm/Let.elm b/src/Elm/Let.elm index a58d1748..817d8b26 100644 --- a/src/Elm/Let.elm +++ b/src/Elm/Let.elm @@ -164,9 +164,11 @@ with (Let toScopeA) (Let toScopeAB) = Let (\index -> let + resultA : { letDecls : List (Node.Node Exp.LetDeclaration), index : Index.Index, return : a, imports : List Module } resultA = toScopeA index + resultB : { letDecls : List (Node.Node Exp.LetDeclaration), index : Index.Index, return : a -> b, imports : List Module } resultB = toScopeAB resultA.index in @@ -251,6 +253,7 @@ fn desiredName ( desiredArg, argAnnotation ) toInnerFn sourceLet = ( argName, thirdIndex ) = Index.getName desiredArg secondIndex + arg : Expression arg = Elm.value { importFrom = [] @@ -323,6 +326,7 @@ fn2 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) toInnerFn ( twoName, fourIndex ) = Index.getName twoDesiredArg thirdIndex + one : Expression one = Elm.value { importFrom = [] @@ -330,6 +334,7 @@ fn2 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) toInnerFn , name = oneName } + two : Expression two = Elm.value { importFrom = [] @@ -409,6 +414,7 @@ fn3 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) ( threeDes ( threeName, fifthIndex ) = Index.getName threeDesiredArg fourIndex + one : Expression one = Elm.value { importFrom = [] @@ -416,6 +422,7 @@ fn3 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) ( threeDes , name = oneName } + two : Expression two = Elm.value { importFrom = [] @@ -423,6 +430,7 @@ fn3 desiredName ( oneDesiredArg, oneType ) ( twoDesiredArg, twoType ) ( threeDes , name = twoName } + three : Expression three = Elm.value { importFrom = [] @@ -633,6 +641,7 @@ toExpression (Let toScope) = Compiler.Expression <| \index -> let + scope : { letDecls : List (Node.Node Exp.LetDeclaration), index : Index.Index, return : Expression, imports : List Module } scope = toScope index diff --git a/src/Elm/Op.elm b/src/Elm/Op.elm index 8ceabed0..f16347b4 100644 --- a/src/Elm/Op.elm +++ b/src/Elm/Op.elm @@ -513,6 +513,7 @@ parens (Compiler.Expression toExp) = Compiler.Expression (\index -> let + exp : Compiler.ExpressionDetails exp = toExp index in @@ -565,9 +566,11 @@ applyNumber symbol dir l r = ( rightIndex, right ) = Compiler.toExpressionDetails leftIndex r + annotationIndex : Index.Index annotationIndex = Index.next rightIndex + numberTypeName : String numberTypeName = Index.protectTypeName "number" diff --git a/src/Elm/ToString.elm b/src/Elm/ToString.elm index 0af18243..565de3bf 100644 --- a/src/Elm/ToString.elm +++ b/src/Elm/ToString.elm @@ -56,6 +56,7 @@ expressionWith : } expressionWith options (Compiler.Expression toExp) = let + expresh : Compiler.ExpressionDetails expresh = toExp Index.startIndex in @@ -110,6 +111,11 @@ declarationWith options decl = case decl of Compiler.Declaration { imports, docs, toBody } -> let + rendered : + { declaration : Declaration.Declaration + , additionalImports : List Compiler.Module + , warning : Maybe Compiler.Warning + } rendered = toBody Index.startIndex in diff --git a/src/Error/Format.elm b/src/Error/Format.elm index 7bd80ce9..50019f8d 100644 --- a/src/Error/Format.elm +++ b/src/Error/Format.elm @@ -60,6 +60,7 @@ grey str = color : Int -> Int -> String -> String color openCode closeCode content = let + delim : Int -> String delim code = --"\\u001B[" ++ String.fromInt code ++ "m" "\u{001B}[" ++ String.fromInt code ++ "m" diff --git a/src/Internal/Clean.elm b/src/Internal/Clean.elm index 18a9a895..6077cdc2 100644 --- a/src/Internal/Clean.elm +++ b/src/Internal/Clean.elm @@ -20,6 +20,7 @@ import Set exposing (Set) clean : Type.TypeAnnotation -> Type.TypeAnnotation clean ann = let + renames : Dict String String renames = prepareRename ann Set.empty |> verify @@ -33,6 +34,7 @@ verify set = Set.foldl (\name gathered -> let + newName : String newName = findClean 0 (sanitized name) set in @@ -45,6 +47,7 @@ verify set = findClean : Int -> String -> Set String -> String findClean i name set = let + newName : String newName = if i == 0 then name diff --git a/src/Internal/Comments.elm b/src/Internal/Comments.elm index ac7b79f8..d62b793d 100644 --- a/src/Internal/Comments.elm +++ b/src/Internal/Comments.elm @@ -106,6 +106,7 @@ layoutTags width parts = case part of DocTags tags -> let + splits : List (List String) splits = fitAndSplit width tags in diff --git a/src/Internal/Compiler.elm b/src/Internal/Compiler.elm index 60ce9460..c3449645 100644 --- a/src/Internal/Compiler.elm +++ b/src/Internal/Compiler.elm @@ -230,6 +230,7 @@ parens expr = facts : Expression -> Result String (List ( String, Annotation.TypeAnnotation )) facts (Expression exp) = let + expresh : ExpressionDetails expresh = exp Index.startIndex in @@ -252,25 +253,21 @@ unique [ 0, 1, 1, 0, 1 ] -} unique : List a -> List a unique list = - uniqueHelp identity [] list [] + uniqueHelp list [] -uniqueHelp : (a -> b) -> List b -> List a -> List a -> List a -uniqueHelp f existing remaining accumulator = +uniqueHelp : List a -> List a -> List a +uniqueHelp remaining accumulator = case remaining of [] -> List.reverse accumulator first :: rest -> - let - computedFirst = - f first - in - if List.member computedFirst existing then - uniqueHelp f existing rest accumulator + if List.member first accumulator then + uniqueHelp rest accumulator else - uniqueHelp f (computedFirst :: existing) rest (first :: accumulator) + uniqueHelp rest (first :: accumulator) toVar : @@ -287,6 +284,7 @@ toVar index desiredName = ( name, newIndex ) = Index.getName desiredName index + typename : String typename = Index.protectTypeName desiredName index in @@ -323,6 +321,7 @@ toVarExactName : } toVarExactName index name = let + typename : String typename = Index.protectTypeName name index in From 940a3317bd4fd0deca57d6fa5e20f7e89133c32a Mon Sep 17 00:00:00 2001 From: Leonardo Taglialegne Date: Sat, 26 Aug 2023 18:30:23 +0200 Subject: [PATCH 19/19] Add missing type annotations --- src/Elm.elm | 89 ++++++++++++++++++------- src/Elm/Case.elm | 142 +++++++++++++++++++++++++++------------- src/Elm/Case/Branch.elm | 6 ++ 3 files changed, 165 insertions(+), 72 deletions(-) diff --git a/src/Elm.elm b/src/Elm.elm index 5fd4c1c1..a68fd4a9 100644 --- a/src/Elm.elm +++ b/src/Elm.elm @@ -1597,9 +1597,11 @@ fn2 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) toExpression = Compiler.expression <| \index -> let + one : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } one = Compiler.toVarMaybeType index oneBaseName maybeOneType + two : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } two = Compiler.toVarMaybeType one.index twoBaseName maybeTwoType @@ -1609,9 +1611,10 @@ fn2 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) toExpression = { expression = Exp.LambdaExpression { args = - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - ] + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + ] , expression = Compiler.nodify return.expression } , annotation = @@ -1650,12 +1653,15 @@ fn3 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, Compiler.expression <| \index -> let + one : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } one = Compiler.toVarMaybeType index oneBaseName maybeOneType + two : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } two = Compiler.toVarMaybeType one.index twoBaseName maybeTwoType + three : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } three = Compiler.toVarMaybeType two.index threeBaseName maybeThreeType @@ -1665,10 +1671,11 @@ fn3 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, { expression = Exp.LambdaExpression { args = - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - ] + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + ] , expression = Compiler.nodify return.expression } , annotation = @@ -1713,15 +1720,19 @@ fn4 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, Compiler.expression <| \index -> let + one : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } one = Compiler.toVarMaybeType index oneBaseName maybeOneType + two : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } two = Compiler.toVarMaybeType one.index twoBaseName maybeTwoType + three : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } three = Compiler.toVarMaybeType two.index threeBaseName maybeThreeType + four : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } four = Compiler.toVarMaybeType three.index fourBaseName maybeFourType @@ -1731,11 +1742,12 @@ fn4 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, { expression = Exp.LambdaExpression { args = - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - , Compiler.nodify (Pattern.VarPattern four.name) - ] + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + , Pattern.VarPattern four.name + ] , expression = Compiler.nodify return.expression } , annotation = @@ -1786,18 +1798,23 @@ fn5 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, Compiler.expression <| \index -> let + one : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } one = Compiler.toVarMaybeType index oneBaseName maybeOneType + two : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } two = Compiler.toVarMaybeType one.index twoBaseName maybeTwoType + three : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } three = Compiler.toVarMaybeType two.index threeBaseName maybeThreeType + four : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } four = Compiler.toVarMaybeType three.index fourBaseName maybeFourType + five : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } five = Compiler.toVarMaybeType four.index fiveBaseName maybeFiveType @@ -1807,12 +1824,13 @@ fn5 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, { expression = Exp.LambdaExpression { args = - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - , Compiler.nodify (Pattern.VarPattern four.name) - , Compiler.nodify (Pattern.VarPattern five.name) - ] + Compiler.nodifyAll <| + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + , Pattern.VarPattern four.name + , Pattern.VarPattern five.name + ] , expression = Compiler.nodify return.expression } , annotation = @@ -1869,21 +1887,27 @@ fn6 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, Compiler.expression <| \index -> let + one : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } one = Compiler.toVarMaybeType index oneBaseName maybeOneType + two : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } two = Compiler.toVarMaybeType one.index twoBaseName maybeTwoType + three : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } three = Compiler.toVarMaybeType two.index threeBaseName maybeThreeType + four : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } four = Compiler.toVarMaybeType three.index fourBaseName maybeFourType + five : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } five = Compiler.toVarMaybeType four.index fiveBaseName maybeFiveType + six : { name : String, type_ : Annotation.TypeAnnotation, val : Compiler.Expression, index : Index.Index } six = Compiler.toVarMaybeType five.index sixBaseName maybeSixType @@ -1893,13 +1917,14 @@ fn6 ( oneBaseName, maybeOneType ) ( twoBaseName, maybeTwoType ) ( threeBaseName, { expression = Exp.LambdaExpression { args = - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - , Compiler.nodify (Pattern.VarPattern four.name) - , Compiler.nodify (Pattern.VarPattern five.name) - , Compiler.nodify (Pattern.VarPattern six.name) - ] + Compiler.nodifyAll <| + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + , Pattern.VarPattern four.name + , Pattern.VarPattern five.name + , Pattern.VarPattern six.name + ] , expression = Compiler.nodify return.expression } , annotation = @@ -2034,6 +2059,7 @@ renderError err = declaration : String -> Expression -> Declaration declaration nameStr (Compiler.Expression toBody) = let + name : String name = Format.formatDeclarationName nameStr in @@ -2046,15 +2072,18 @@ declaration nameStr (Compiler.Expression toBody) = , toBody = \index -> let + body : Compiler.ExpressionDetails body = toBody index + resolvedType : Result String Annotation.TypeAnnotation resolvedType = body.annotation |> Result.mapError renderError |> Result.andThen (\sig -> Compiler.resolve index sig.inferences sig.type_) + maybeWarning : Maybe { declaration : String, warning : String } maybeWarning = case resolvedType of Ok _ -> @@ -2144,6 +2173,7 @@ functionAdvanced args fullExpression = Compiler.expression <| \index -> let + expr : Compiler.ExpressionDetails expr = case fullExpression of Compiler.Expression toExpr -> @@ -2206,6 +2236,7 @@ function initialArgList toFullExpression = Compiler.expression <| \index -> let + args : { index : Index.Index, args : List Expression, names : List String, types : List Annotation.TypeAnnotation } args = List.foldl (\( nameBase, maybeType ) found -> @@ -2213,6 +2244,7 @@ function initialArgList toFullExpression = ( name, newIndex ) = Index.getName nameBase found.index + argType : Compiler.Annotation argType = Maybe.withDefault (Compiler.Annotation @@ -2228,6 +2260,7 @@ function initialArgList toFullExpression = ) maybeType + arg : Expression arg = value { importFrom = [] @@ -2248,9 +2281,11 @@ function initialArgList toFullExpression = } initialArgList + fullExpression : Expression fullExpression = toFullExpression (List.reverse args.args) + expr : Compiler.ExpressionDetails expr = case fullExpression of Compiler.Expression toExpr -> @@ -2357,6 +2392,7 @@ This will give you more flexibility in the future and save you having to wire up portIncoming : String -> List Elm.Annotation.Annotation -> Declaration portIncoming nameStr args = let + name : String name = Format.formatDeclarationName nameStr in @@ -2428,6 +2464,7 @@ will generate portOutgoing : String -> Elm.Annotation.Annotation -> Declaration portOutgoing nameStr arg = let + name : String name = Format.formatDeclarationName nameStr in @@ -2491,6 +2528,7 @@ parse source = Compiler.denode parsedFile.moduleDefinition |> Elm.Syntax.Module.exposingList + declarations : List ( Int, Compiler.Declaration ) declarations = List.map (\(Node range declar) -> @@ -2513,6 +2551,7 @@ parse source = ) parsedFile.declarations + comments : List ( Int, Compiler.Declaration ) comments = List.map (\(Node range nodedComment) -> diff --git a/src/Elm/Case.elm b/src/Elm/Case.elm index 0db5c019..43ef2ca4 100644 --- a/src/Elm/Case.elm +++ b/src/Elm/Case.elm @@ -97,6 +97,12 @@ captureCase mainExpression mainExpressionTypeModule index branches = ( branchIndex, mainExpressionDetails ) = Compiler.toExpressionDetails index mainExpression + caseExp : + { index : Index.Index + , cases : List ( Node.Node Pattern.Pattern, Node.Node Exp.Expression ) + , imports : List Compiler.Module + , annotation : Maybe (Result (List Compiler.InferenceError) Compiler.Inference) + } caseExp = List.foldl (captureCaseHelper mainExpressionTypeModule) @@ -145,6 +151,7 @@ captureCaseHelper mainCaseExpressionModule (Branch toBranch) accum = ( branchIndex, originalPattern, caseExpression ) = toBranch (Index.dive accum.index) + pattern : Pattern.Pattern pattern = case mainCaseExpressionModule of [] -> @@ -237,6 +244,7 @@ maybe mainExpression branches = ( justVarName, toReturn ) = branches.just + just : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } just = Compiler.toVarMaybeType branchIndex justVarName Nothing in @@ -301,17 +309,20 @@ tuple mainExpression oneName twoName branches = [ Branch (\branchIndex -> let + first : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } first = Compiler.toVarMaybeType branchIndex oneName Nothing + second : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } second = Compiler.toVarMaybeType first.index twoName Nothing in ( second.index - , Pattern.TuplePattern - [ Compiler.nodify (Pattern.VarPattern first.name) - , Compiler.nodify (Pattern.VarPattern second.name) - ] + , Pattern.TuplePattern <| + Compiler.nodifyAll + [ Pattern.VarPattern first.name + , Pattern.VarPattern second.name + ] , branches first.val second.val ) ) @@ -368,21 +379,25 @@ triple mainExpression one two three branches = [ Branch (\branchIndex -> let + first : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } first = Compiler.toVarMaybeType branchIndex one Nothing + second : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } second = Compiler.toVarMaybeType first.index two Nothing + third : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } third = Compiler.toVarMaybeType second.index three Nothing in ( third.index - , Pattern.TuplePattern - [ Compiler.nodify (Pattern.VarPattern first.name) - , Compiler.nodify (Pattern.VarPattern second.name) - , Compiler.nodify (Pattern.VarPattern third.name) - ] + , Pattern.TuplePattern <| + Compiler.nodifyAll + [ Pattern.VarPattern first.name + , Pattern.VarPattern second.name + , Pattern.VarPattern third.name + ] , branches first.val second.val third.val ) ) @@ -448,6 +463,7 @@ result mainExpression branches = ( okNameStr, toOk ) = branches.ok + ok : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } ok = Compiler.toVarMaybeType branchIndex okNameStr Nothing in @@ -463,6 +479,7 @@ result mainExpression branches = ( errNameStr, toErr ) = branches.err + err : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } err = Compiler.toVarMaybeType branchIndex errNameStr Nothing in @@ -502,6 +519,7 @@ string mainExpression branches = Compiler.Expression <| \index -> let + allBranches : List (Pattern Expression) allBranches = List.map (\( caseString, caseExpression ) -> @@ -588,9 +606,11 @@ list mainExpression branches = , Branch (\branchIndex -> let + top : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } top = Compiler.toVarMaybeType branchIndex "top" Nothing + remaining : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } remaining = Compiler.toVarMaybeType branchIndex "remaining" Nothing in @@ -631,6 +651,7 @@ custom mainExpression annotation branches = Compiler.Expression <| \index -> let + myMain : Expression myMain = mainExpression |> Elm.withType annotation @@ -680,6 +701,7 @@ otherwise toExp = Branch (\index -> let + other : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } other = Compiler.toVarMaybeType index "otherwise" Nothing in @@ -696,16 +718,15 @@ branch1 name ( argName, argType ) toExp = Branch (\index -> let - var = + one : { name : String, exp : Expression, index : Index.Index } + one = Compiler.toVarWithType index argName argType in - ( var.index - , Pattern.NamedPattern - { moduleName = [] - , name = Format.formatType name - } - [ Compiler.nodify (Pattern.VarPattern var.name) ] - , toExp var.exp + ( one.index + , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } <| + Compiler.nodifyAll + [ Pattern.VarPattern one.name ] + , toExp one.exp ) ) @@ -716,17 +737,20 @@ branch2 name ( oneName, oneType ) ( twoName, twoType ) toExp = Branch (\index -> let + one : { name : String, exp : Expression, index : Index.Index } one = Compiler.toVarWithType index oneName oneType + two : { name : String, exp : Expression, index : Index.Index } two = Compiler.toVarWithType one.index twoName twoType in ( two.index - , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - ] + , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } <| + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + ] , toExp one.exp two.exp ) ) @@ -744,21 +768,25 @@ branch3 name ( oneName, oneType ) ( twoName, twoType ) ( threeName, threeType ) Branch (\index -> let + one : { name : String, exp : Expression, index : Index.Index } one = Compiler.toVarWithType index oneName oneType + two : { name : String, exp : Expression, index : Index.Index } two = Compiler.toVarWithType one.index twoName twoType + three : { name : String, exp : Expression, index : Index.Index } three = Compiler.toVarWithType two.index threeName threeType in ( three.index - , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - ] + , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } <| + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + ] , toExp one.exp two.exp three.exp ) ) @@ -777,25 +805,30 @@ branch4 name ( oneName, oneType ) ( twoName, twoType ) ( threeName, threeType ) Branch (\index -> let + one : { name : String, exp : Expression, index : Index.Index } one = Compiler.toVarWithType index oneName oneType + two : { name : String, exp : Expression, index : Index.Index } two = Compiler.toVarWithType one.index twoName twoType + three : { name : String, exp : Expression, index : Index.Index } three = Compiler.toVarWithType two.index threeName threeType + four : { name : String, exp : Expression, index : Index.Index } four = Compiler.toVarWithType three.index fourName fourType in ( four.index - , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - , Compiler.nodify (Pattern.VarPattern four.name) - ] + , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } <| + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + , Pattern.VarPattern four.name + ] , toExp one.exp two.exp three.exp four.exp ) ) @@ -822,29 +855,35 @@ branch5 name ( oneName, oneType ) ( twoName, twoType ) ( threeName, threeType ) Branch (\index -> let + one : { name : String, exp : Expression, index : Index.Index } one = Compiler.toVarWithType index oneName oneType + two : { name : String, exp : Expression, index : Index.Index } two = Compiler.toVarWithType one.index twoName twoType + three : { name : String, exp : Expression, index : Index.Index } three = Compiler.toVarWithType two.index threeName threeType + four : { name : String, exp : Expression, index : Index.Index } four = Compiler.toVarWithType three.index fourName fourType + five : { name : String, exp : Expression, index : Index.Index } five = Compiler.toVarWithType four.index fiveName fiveType in ( five.index - , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - , Compiler.nodify (Pattern.VarPattern four.name) - , Compiler.nodify (Pattern.VarPattern five.name) - ] + , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } <| + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + , Pattern.VarPattern four.name + , Pattern.VarPattern five.name + ] , toExp one.exp two.exp three.exp four.exp five.exp ) ) @@ -873,33 +912,40 @@ branch6 name ( oneName, oneType ) ( twoName, twoType ) ( threeName, threeType ) Branch (\index -> let + one : { name : String, exp : Expression, index : Index.Index } one = Compiler.toVarWithType index oneName oneType + two : { name : String, exp : Expression, index : Index.Index } two = Compiler.toVarWithType one.index twoName twoType + three : { name : String, exp : Expression, index : Index.Index } three = Compiler.toVarWithType two.index threeName threeType + four : { name : String, exp : Expression, index : Index.Index } four = Compiler.toVarWithType three.index fourName fourType + five : { name : String, exp : Expression, index : Index.Index } five = Compiler.toVarWithType four.index fiveName fiveType + six : { name : String, exp : Expression, index : Index.Index } six = Compiler.toVarWithType four.index sixName sixType in ( six.index - , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } - [ Compiler.nodify (Pattern.VarPattern one.name) - , Compiler.nodify (Pattern.VarPattern two.name) - , Compiler.nodify (Pattern.VarPattern three.name) - , Compiler.nodify (Pattern.VarPattern four.name) - , Compiler.nodify (Pattern.VarPattern five.name) - , Compiler.nodify (Pattern.VarPattern six.name) - ] + , Pattern.NamedPattern { moduleName = [], name = Format.formatType name } <| + Compiler.nodifyAll + [ Pattern.VarPattern one.name + , Pattern.VarPattern two.name + , Pattern.VarPattern three.name + , Pattern.VarPattern four.name + , Pattern.VarPattern five.name + , Pattern.VarPattern six.name + ] , toExp one.exp two.exp three.exp four.exp five.exp six.exp ) ) @@ -916,6 +962,7 @@ branchWith name arity toExp = |> List.map (\i -> let + var : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } var = Compiler.toVarMaybeType index ("arg" ++ String.fromInt i) Nothing in @@ -942,6 +989,7 @@ branchList arity toExp = List.foldl (\i ( listPattern, currentArgs ) -> let + var : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } var = Compiler.toVarMaybeType index ("arg" ++ String.fromInt i) Nothing in diff --git a/src/Elm/Case/Branch.elm b/src/Elm/Case/Branch.elm index 4285d7bd..9e4c3d08 100644 --- a/src/Elm/Case/Branch.elm +++ b/src/Elm/Case/Branch.elm @@ -135,6 +135,7 @@ These helpers let you define a Custom Type pattern with a builder. import Elm exposing (Expression) import Elm.Syntax.Node exposing (Node) import Elm.Syntax.Pattern as Pattern +import Elm.Syntax.TypeAnnotation as Annotation import Internal.Branch as Branch exposing (Pattern(..)) import Internal.Compiler as Compiler import Internal.Format as Format @@ -397,6 +398,7 @@ withField newField (Record toRecord) = ( newIndex, existingFields, recordBuilder ) = toRecord index + new : { name : String, typename : String, val : Expression, index : Index.Index } new = Compiler.toVarExactName newIndex newField in @@ -462,6 +464,7 @@ withParam (Branch toBranch) (CustomType toCustomType) = ( newIndex, pattern, val ) = toBranch index + custom : { index : Index.Index, base : String, patterns : List Pattern.Pattern, value : a -> b } custom = toCustomType newIndex in @@ -479,6 +482,7 @@ toPattern (CustomType toCustomType) = Branch.Branch (\index -> let + custom : { index : Index.Index, base : String, patterns : List Pattern.Pattern, value : a } custom = toCustomType index in @@ -687,6 +691,7 @@ aliasAs name combine (Branch.Branch branch) = ( newIndex, pattern, destructured ) = branch index + aliased : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } aliased = Compiler.toVarMaybeType newIndex name Nothing in @@ -738,6 +743,7 @@ var name = Branch.Branch (\index -> let + variable : { name : String, type_ : Annotation.TypeAnnotation, val : Expression, index : Index.Index } variable = Compiler.toVarMaybeType index name Nothing in