elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.51k stars 656 forks source link

error with bump/diff when docs.json line is longer than 65535 (in 0.19.1 but not 0.19.0) #2055

Open rlefevre opened 4 years ago

rlefevre commented 4 years ago

Quick Summary:

When running elm bump on justgook/alt-linear-algebra with elm 0.19.1, we get the following error:

$ elm bump
-- PROBLEM LOADING DOCS --------------------------------------------------------

I need the docs for 1.0.0 to compute the next version number, so I fetched:

    https://package.elm-lang.org/packages/justgook/alt-linear-algebra/1.0.0/docs.json

I got the data back, but it was not what I was expecting. The response body
contains 82839 bytes. Here is the beginning:

    [{"name":"AltMath.Alternative.ADT.Matrix4","comment":" This library uses ...

Does this error keep showing up? Maybe there is something weird with your
internet connection. We have gotten reports that schools, businesses, airports,
etc. sometimes intercept requests and add things to the body or change its
contents entirely. Could that be the problem?

When running the same command with elm 0.19.0, it works as expected.

SSCCE

git clone https://github.com/justgook/alt-linear-algebra.git
cd alt-linear-algebra
git checkout 1.0.0
elm bump

Additional Details

As it works with elm 0.19.0, it seems to be a regression.

The compiler fails to parse the alt-linear-algebra package documentation.

When adding a putStrLn in the compiler, we get the following error:

(Index 12 (Field "aliases" (Index 1 (Field "type" (Failure (Region (Position 1 65376) (Position 1 164)) BadType)))))

By getting the same index with jq, we get:

$ jq '.[12]["aliases"][1]["type"]' docs.json
"{ m11 : Basics.Float, m21 : Basics.Float, m31 : Basics.Float, m41 : Basics.Float, m12 : Basics.Float, m22 : Basics.Float, m32 : Basics.Float, m42 : Basics.Float, m13 : Basics.Float, m23 : Basics.Float, m33 : Basics.Float, m43 : Basics.Float, m14 : Basics.Float, m24 : Basics.Float, m34 : Basics.Float, m44 : Basics.Float }"

The full type is Matrix4Record:

{"name":"Matrix4Record","comment":" Just type alias for matrix record\n","args":[],"type":"{ m11 : Basics.Float, m21 : Basics.Float, m31 : Basics.Float, m41 : Basics.Float, m12 : Basics.Float, m22 : Basics.Float, m32 : Basics.Float, m42 : Basics.Float, m13 : Basics.Float, m23 : Basics.Float, m33 : Basics.Float, m43 : Basics.Float, m14 : Basics.Float, m24 : Basics.Float, m34 : Basics.Float, m44 : Basics.Float }"}

The fact that this type goes above the 65535 offset (error is at 65376) might also be significant if this is another 16bits integer optimization issue.

rlefevre commented 4 years ago

Another example with elm diff:

$ elm diff elm-community/typed-svg 5.2.0 6.0.0
-- PROBLEM LOADING DOCS --------------------------------------------------------

I need the docs for 5.2.0 to compute this diff, so I fetched:

    https://package.elm-lang.org/packages/elm-community/typed-svg/5.2.0/docs.json

I got the data back, but it was not what I was expecting. The response body
contains 133164 bytes. Here is the beginning:

    [{"name":"TypedSvg","comment":"\n\n\n# HTML Embedding\n\n@docs svg\n\n\n#...

Does this error keep showing up? Maybe there is something weird with your
internet connection. We have gotten reports that schools, businesses, airports,
etc. sometimes intercept requests and add things to the body or change its
contents entirely. Could that be the problem?
elm diff elm-community/typed-svg 5.2.0 6.0.0

The parser error is:

(Index 1 (Field "values" (Index 164 (Field "type" (Failure (Region (Position 1 65494) (Position 1 4)) BadType)))))

Again at a string going above the 65535 offset, which confirms with a very high probability the 16 bits optimization issue.

rupertlssmith commented 4 years ago

Workaround, try doing elm diff or elm bump or elm publish with version 0.19.0.

Show stopper - if your package depends on "elm-version": "0.19.1 <= v < 0.20.0". Probably a good idea not to make packages require 0.19.1 anyway.

michaelglass commented 3 years ago

thanks @rupertlssmith!

@juanedi just had this probelm with elm-ui (elm 0.19.1 choked on this file).

used $ npx elm@0.19.0-no-deps bump to get this work