Skip to content

Commit

Permalink
fixes #35 guida diff elm/json 1.0.0 1.1.2 shows wrong result
Browse files Browse the repository at this point in the history
  • Loading branch information
decioferreira committed Oct 9, 2024
1 parent 072e5af commit 6c18aac
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 85 deletions.
76 changes: 39 additions & 37 deletions elm.json
Original file line number Diff line number Diff line change
@@ -1,41 +1,43 @@
{
"type": "application",
"source-directories": ["src"],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"andre-dietrich/parser-combinators": "4.1.0",
"dasch/levenshtein": "1.0.3",
"elm/browser": "1.0.2",
"elm/bytes": "1.0.8",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/json": "1.1.3",
"elm/parser": "1.1.0",
"elm/time": "1.0.0",
"elm-community/array-extra": "2.6.0",
"elm-community/basics-extra": "4.1.0",
"elm-community/list-extra": "8.7.0",
"elm-community/maybe-extra": "5.3.0",
"guida-lang/glsl": "1.0.0",
"mgold/elm-nonempty-list": "4.2.0",
"pilatch/flip": "1.0.0",
"rtfeldman/elm-hex": "1.0.0",
"the-sett/elm-pretty-printer": "3.1.0",
"zwilias/elm-rosetree": "1.5.0"
"type": "application",
"source-directories": [
"src"
],
"elm-version": "0.19.1",
"dependencies": {
"direct": {
"andre-dietrich/parser-combinators": "4.1.0",
"dasch/levenshtein": "1.0.3",
"elm/browser": "1.0.2",
"elm/bytes": "1.0.8",
"elm/core": "1.0.5",
"elm/html": "1.0.0",
"elm/json": "1.1.3",
"elm/parser": "1.1.0",
"elm/time": "1.0.0",
"elm-community/array-extra": "2.6.0",
"elm-community/basics-extra": "4.1.0",
"elm-community/list-extra": "8.7.0",
"elm-community/maybe-extra": "5.3.0",
"guida-lang/glsl": "1.0.0",
"mgold/elm-nonempty-list": "4.2.0",
"rtfeldman/elm-hex": "1.0.0",
"the-sett/elm-pretty-printer": "3.1.0",
"zwilias/elm-rosetree": "1.5.0"
},
"indirect": {
"elm/random": "1.0.0",
"elm/regex": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.3",
"fredcy/elm-parseint": "2.0.1",
"pilatch/flip": "1.0.0"
}
},
"indirect": {
"elm/random": "1.0.0",
"elm/regex": "1.0.0",
"elm/url": "1.0.0",
"elm/virtual-dom": "1.0.3",
"fredcy/elm-parseint": "2.0.1"
"test-dependencies": {
"direct": {
"elm-explorations/test": "2.2.0"
},
"indirect": {}
}
},
"test-dependencies": {
"direct": {
"elm-explorations/test": "2.2.0"
},
"indirect": {}
}
}
10 changes: 3 additions & 7 deletions src/Builder/Build.elm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module Builder.Build exposing
, writeDocs
)

import Basics.Extra exposing (flip)
import Builder.Elm.Details as Details
import Builder.Elm.Outline as Outline
import Builder.File as File
Expand Down Expand Up @@ -46,7 +47,6 @@ import Data.Graph as Graph
import Data.IO as IO exposing (IO, IORef(..))
import Data.Map as Dict exposing (Dict)
import Data.Set as EverySet
import Flip
import Json.Decode as Decode
import Json.Encode as Encode
import Utils.Crash exposing (crash)
Expand Down Expand Up @@ -360,7 +360,7 @@ crawlModule ((Env _ root projectType srcDirs buildID locals foreigns) as env) mv
fileName =
ModuleName.toFilePath name ++ ".elm"
in
Utils.filterM File.exists (List.map (Flip.flip addRelative fileName) srcDirs)
Utils.filterM File.exists (List.map (flip addRelative fileName) srcDirs)
|> IO.bind
(\paths ->
case paths of
Expand Down Expand Up @@ -1818,11 +1818,7 @@ bResultEncoder bResult =
, ( "local", Details.localEncoder local )
, ( "iface", I.interfaceEncoder iface )
, ( "objects", Opt.localGraphEncoder objects )
, ( "docs"
, docs
|> Maybe.map Docs.jsonModuleEncoder
|> Maybe.withDefault Encode.null
)
, ( "docs", E.maybe Docs.jsonModuleEncoder docs )
]

RCached main lastChange (MVar ref) ->
Expand Down
6 changes: 3 additions & 3 deletions src/Builder/Deps/Diff.elm
Original file line number Diff line number Diff line change
Expand Up @@ -253,11 +253,11 @@ isEquivalentRenaming varPairs =
allUnique list =
List.length list == EverySet.size (EverySet.fromList compare list)
in
case List.filterMap verify renamings of
[] ->
case Utils.maybeMapM verify renamings of
Nothing ->
False

verifiedRenamings ->
Just verifiedRenamings ->
List.all compatibleVars verifiedRenamings
&& allUnique (List.map Tuple.second verifiedRenamings)

Expand Down
4 changes: 2 additions & 2 deletions src/Builder/Deps/Registry.elm
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module Builder.Deps.Registry exposing
, update
)

import Basics.Extra exposing (flip)
import Builder.Deps.Website as Website
import Builder.File as File
import Builder.Http as Http
Expand All @@ -24,7 +25,6 @@ import Compiler.Json.Encode as E
import Compiler.Parse.Primitives as P
import Data.IO as IO exposing (IO(..))
import Data.Map as Dict exposing (Dict)
import Flip
import Json.Decode as Decode
import Json.Encode as Encode

Expand Down Expand Up @@ -104,7 +104,7 @@ allPkgsDecoder =

toKnownVersions : List V.Version -> D.Decoder () KnownVersions
toKnownVersions versions =
case List.sortWith (Flip.flip V.compare) versions of
case List.sortWith (flip V.compare) versions of
v :: vs ->
D.pure (KnownVersions v vs)

Expand Down
18 changes: 9 additions & 9 deletions src/Compiler/Canonicalize/Expression.elm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module Compiler.Canonicalize.Expression exposing
, verifyBindings
)

import Basics.Extra exposing (flip)
import Compiler.AST.Canonical as Can
import Compiler.AST.Source as Src
import Compiler.AST.Utils.Binop as Binop
Expand All @@ -25,7 +26,6 @@ import Compiler.Reporting.Result as R
import Compiler.Reporting.Warning as W
import Data.Graph as Graph
import Data.Map as Dict exposing (Dict)
import Flip
import List.Extra as List
import Prelude
import Utils.Main as Utils
Expand Down Expand Up @@ -359,16 +359,16 @@ addBindingsHelp bindings (A.At region pattern) =
bindings

Src.PTuple a b cs ->
List.foldl (Flip.flip addBindingsHelp) bindings (a :: b :: cs)
List.foldl (flip addBindingsHelp) bindings (a :: b :: cs)

Src.PCtor _ _ patterns ->
List.foldl (Flip.flip addBindingsHelp) bindings patterns
List.foldl (flip addBindingsHelp) bindings patterns

Src.PCtorQual _ _ _ patterns ->
List.foldl (Flip.flip addBindingsHelp) bindings patterns
List.foldl (flip addBindingsHelp) bindings patterns

Src.PList patterns ->
List.foldl (Flip.flip addBindingsHelp) bindings patterns
List.foldl (flip addBindingsHelp) bindings patterns

Src.PCons hd tl ->
addBindingsHelp (addBindingsHelp bindings hd) tl
Expand Down Expand Up @@ -533,16 +533,16 @@ getPatternNames names (A.At region pattern) =
names

Src.PTuple a b cs ->
List.foldl (Flip.flip getPatternNames) (getPatternNames (getPatternNames names a) b) cs
List.foldl (flip getPatternNames) (getPatternNames (getPatternNames names a) b) cs

Src.PCtor _ _ args ->
List.foldl (Flip.flip getPatternNames) names args
List.foldl (flip getPatternNames) names args

Src.PCtorQual _ _ _ args ->
List.foldl (Flip.flip getPatternNames) names args
List.foldl (flip getPatternNames) names args

Src.PList patterns ->
List.foldl (Flip.flip getPatternNames) names patterns
List.foldl (flip getPatternNames) names patterns

Src.PCons hd tl ->
getPatternNames (getPatternNames names hd) tl
Expand Down
87 changes: 79 additions & 8 deletions src/Compiler/Elm/Compiler/Type.elm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module Compiler.Elm.Compiler.Type exposing
, encode
, encodeMetadata
, jsonDecoder
, jsonEncoder
, toDoc
)

Expand All @@ -22,6 +23,7 @@ import Compiler.Reporting.Doc as D
import Compiler.Reporting.Render.Type as RT
import Compiler.Reporting.Render.Type.Localizer as L
import Json.Decode as Decode
import Json.Encode as Encode
import Utils.Crash exposing (crash)


Expand Down Expand Up @@ -199,15 +201,84 @@ toVariantObject ( name, args ) =
-- ENCODERS and DECODERS


jsonEncoder : Type -> Encode.Value
jsonEncoder type_ =
case type_ of
Lambda arg body ->
Encode.object
[ ( "type", Encode.string "Lambda" )
, ( "arg", jsonEncoder arg )
, ( "body", jsonEncoder body )
]

Var name ->
Encode.object
[ ( "type", Encode.string "Var" )
, ( "name", Encode.string name )
]

Type name args ->
Encode.object
[ ( "type", Encode.string "Type" )
, ( "name", Encode.string name )
, ( "args", Encode.list jsonEncoder args )
]

Record fields ext ->
Encode.object
[ ( "type", Encode.string "Record" )
, ( "fields", Encode.list (E.jsonPair Encode.string jsonEncoder) fields )
, ( "ext", E.maybe Encode.string ext )
]

Unit ->
Encode.object
[ ( "type", Encode.string "Unit" )
]

Tuple a b cs ->
Encode.object
[ ( "type", Encode.string "Tuple" )
, ( "a", jsonEncoder a )
, ( "b", jsonEncoder b )
, ( "cs", Encode.list jsonEncoder cs )
]


jsonDecoder : Decode.Decoder Type
jsonDecoder =
Decode.string
Decode.field "type" Decode.string
|> Decode.andThen
(\str ->
case P.fromByteString parser (\_ _ -> ()) str of
Ok type_ ->
Decode.succeed type_

Err _ ->
Decode.fail ("failed to parse package name: " ++ str)
(\type_ ->
case type_ of
"Lambda" ->
Decode.map2 Lambda
(Decode.field "arg" jsonDecoder)
(Decode.field "body" jsonDecoder)

"Var" ->
Decode.map Var
(Decode.field "name" Decode.string)

"Type" ->
Decode.map2 Type
(Decode.field "name" Decode.string)
(Decode.field "args" (Decode.list jsonDecoder))

"Record" ->
Decode.map2 Record
(Decode.field "fields" (Decode.list (D.jsonPair Decode.string jsonDecoder)))
(Decode.field "ext" (Decode.maybe Decode.string))

"Unit" ->
Decode.succeed Unit

"Tuple" ->
Decode.map3 Tuple
(Decode.field "a" jsonDecoder)
(Decode.field "b" jsonDecoder)
(Decode.field "cs" (Decode.list jsonDecoder))

_ ->
Decode.fail ("Failed to decode Type's type: " ++ type_)
)
Loading

0 comments on commit 6c18aac

Please sign in to comment.