Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: bump Nim from 1.4.8 to 1.6.0 #419

Merged
merged 3 commits into from Oct 21, 2021
Merged

Conversation

ee7
Copy link
Member

@ee7 ee7 commented Sep 7, 2021

This PR will fail until Nim 1.6.0 is actually released.

But RC1 is released - see https://forum.nim-lang.org/t/8404

@ErikSchierboom
Copy link
Member

Is 1.6 the release where we get the "share fields between different discriminators in types?

@ee7
Copy link
Member Author

ee7 commented Sep 7, 2021

Is 1.6 the release where we get the "share fields between different discriminators in types?

Short answer:
No.

Long answer:
No, because although a Nim feature release is very close to the latest devel, it hasn't been merged to devel yet. It looks like the RFC was accepted and then un-accepted.

Nim's development model works like this:

  • Merge PRs to the devel branch.
  • When it's time for a feature release, create a version-1-x branch that's even with the devel branch (where x is the even number that's greater than the minor version number of the previous feature release). Then create some RCs, make any necessary fixes, and release.
  • For a patch release, backport commits from devel to the desired version-1-x branch.

Right now, the version-1-6 branch is one commit behind devel (see here). So, basically, anything that was merged to devel will be in 1.6.

@ee7 ee7 marked this pull request as ready for review October 19, 2021 17:33
@ErikSchierboom
Copy link
Member

ErikSchierboom commented Oct 19, 2021

Sweet! (I had already approved before)

@ErikSchierboom
Copy link
Member

support for Apple silicon/M1

We might want to add this to the releases too.

This commit pulls in the latest changes to the json module from the Nim
standard library.

The `json.nim` file in the configlet repo is the result of applying the
below patch to the upstream 1.6.0 `json.nim` file.

diff --git a/Nim/lib/pure/json.nim b/configlet/src/patched_stdlib/json.nim
index 85c3393..55daa6d 100644
--- a/Nim/lib/pure/json.nim
+++ b/configlet/src/patched_stdlib/json.nim
@@ -1,11 +1,28 @@
-#
-#
-#            Nim's Runtime Library
-#        (c) Copyright 2015 Andreas Rumpf, Dominik Picheta
-#
-#    See the file "copying.txt", included in this
-#    distribution, for details about the copyright.
-#
+# This file is minimally adapted from this version in the Nim standard library:
+# https://github.com/nim-lang/Nim/blob/58080525a1dc/lib/pure/json.nim
+# The standard library version is lenient: it silently allows a trailing comma.
+# The below version is stricter: it raises a `JsonParsingError` for a trailing
+# comma.
+
+# Copyright (c) 2015 Andreas Rumpf, Dominik Picheta
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.

 ## This module implements a simple high performance `JSON`:idx:
 ## parser. JSON (JavaScript Object Notation) is a lightweight
@@ -893,6 +910,9 @@ proc parseJson(p: var JsonParser; rawIntegers, rawFloats: bool): JsonNode =
       result[key] = val
       if p.tok != tkComma: break
       discard getTok(p)
+      # Raise `JsonParsingError` for a trailing comma, unlike `std/json`
+      if p.tok == tkCurlyRi:
+        raiseParseErr(p, "found trailing comma. } or key/value pair")
     eat(p, tkCurlyRi)
   of tkBracketLe:
     result = newJArray()
@@ -901,6 +921,9 @@ proc parseJson(p: var JsonParser; rawIntegers, rawFloats: bool): JsonNode =
       result.add(parseJson(p, rawIntegers, rawFloats))
       if p.tok != tkComma: break
       discard getTok(p)
+      # Raise `JsonParsingError` for a trailing comma, unlike `std/json`
+      if p.tok == tkBracketRi:
+        raiseParseErr(p, "found trailing comma. ] or array item")
     eat(p, tkBracketRi)
   of tkError, tkCurlyRi, tkBracketRi, tkColon, tkComma, tkEof:
     raiseParseErr(p, "{")
This commit pulls in the latest changes to the parsejson module from the
Nim standard library.

The `parsejson.nim` file in the configlet repo is the result of applying
the below patch to the upstream 1.6.0 `parsejson.nim` file.

diff --git a/Nim/lib/pure/parsejson.nim b/configlet/src/patched_stdlib/parsejson.nim
index 196d8c3..48e1e05 100644
--- a/Nim/lib/pure/parsejson.nim
+++ b/configlet/src/patched_stdlib/parsejson.nim
@@ -1,11 +1,29 @@
-#
-#
-#            Nim's Runtime Library
-#        (c) Copyright 2018 Nim contributors
-#
-#    See the file "copying.txt", included in this
-#    distribution, for details about the copyright.
-#
+# This file is minimally adapted from this version in the Nim standard library:
+# https://github.com/nim-lang/Nim/blob/285539c87aa2/lib/pure/parsejson.nim
+# The standard library version is lenient: it silently allows line comments
+# with `//`, and long comments with `/* */`.
+# The below version is stricter: it raises a `JsonParsingError` for such
+# comments.
+
+# Copyright (c) 2018 Nim contributors
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.

 ## This module implements a json parser. It is used
 ## and exported by the `json` standard library
@@ -54,7 +72,6 @@ type
     errBracketRiExpected, ## `]` expected
     errCurlyRiExpected,   ## `}` expected
     errQuoteExpected,     ## `"` or `'` expected
-    errEOC_Expected,      ## `*/` expected
     errEofExpected,       ## EOF expected
     errExprExpected       ## expr expected

@@ -85,7 +102,6 @@ const
     "']' expected",
     "'}' expected",
     "'\"' or \"'\" expected",
-    "'*/' expected",
     "EOF expected",
     "expression expected"
   ]
@@ -263,43 +279,8 @@ proc skip(my: var JsonParser) =
   var pos = my.bufpos
   while true:
     case my.buf[pos]
-    of '/':
-      if my.buf[pos+1] == '/':
-        # skip line comment:
-        inc(pos, 2)
-        while true:
-          case my.buf[pos]
-          of '\0':
-            break
-          of '\c':
-            pos = lexbase.handleCR(my, pos)
-            break
-          of '\L':
-            pos = lexbase.handleLF(my, pos)
-            break
-          else:
-            inc(pos)
-      elif my.buf[pos+1] == '*':
-        # skip long comment:
-        inc(pos, 2)
-        while true:
-          case my.buf[pos]
-          of '\0':
-            my.err = errEOC_Expected
-            break
-          of '\c':
-            pos = lexbase.handleCR(my, pos)
-          of '\L':
-            pos = lexbase.handleLF(my, pos)
-          of '*':
-            inc(pos)
-            if my.buf[pos] == '/':
-              inc(pos)
-              break
-          else:
-            inc(pos)
-      else:
-        break
+    # Raise `JsonParsingError` for comments with `//` or `/* */`,
+    # unlike `std/parsejson`
     of ' ', '\t':
       inc(pos)
     of '\c':
@@ -350,7 +331,7 @@ proc parseName(my: var JsonParser) =

 proc getTok*(my: var JsonParser): TokKind =
   setLen(my.a, 0)
-  skip(my) # skip whitespace, comments
+  skip(my) # skip whitespace
   case my.buf[my.bufpos]
   of '-', '.', '0'..'9':
     parseNumber(my)
@ee7
Copy link
Member Author

ee7 commented Oct 21, 2021

I've pushed commits to this PR to update our forked json modules at the same time - otherwise, we'd have an incomplete update to Nim 1.6.0, with JSON modules patched from an older Nim version. It could eventually cause problems if we forgot to update the patched versions for a long time.

See below for the resulting diff to each upstream Nim 1.6.0 module. The behavior-affecting part of each diff is unchanged.

diff --git a/Nim/lib/pure/json.nim b/configlet/src/patched_stdlib/json.nim
index 85c3393..55daa6d 100644
--- a/Nim/lib/pure/json.nim
+++ b/configlet/src/patched_stdlib/json.nim
@@ -1,11 +1,28 @@
-#
-#
-#            Nim's Runtime Library
-#        (c) Copyright 2015 Andreas Rumpf, Dominik Picheta
-#
-#    See the file "copying.txt", included in this
-#    distribution, for details about the copyright.
-#
+# This file is minimally adapted from this version in the Nim standard library:
+# https://github.com/nim-lang/Nim/blob/58080525a1dc/lib/pure/json.nim
+# The standard library version is lenient: it silently allows a trailing comma.
+# The below version is stricter: it raises a `JsonParsingError` for a trailing
+# comma.
+
+# Copyright (c) 2015 Andreas Rumpf, Dominik Picheta
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.

 ## This module implements a simple high performance `JSON`:idx:
 ## parser. JSON (JavaScript Object Notation) is a lightweight
@@ -893,6 +910,9 @@ proc parseJson(p: var JsonParser; rawIntegers, rawFloats: bool): JsonNode =
       result[key] = val
       if p.tok != tkComma: break
       discard getTok(p)
+      # Raise `JsonParsingError` for a trailing comma, unlike `std/json`
+      if p.tok == tkCurlyRi:
+        raiseParseErr(p, "found trailing comma. } or key/value pair")
     eat(p, tkCurlyRi)
   of tkBracketLe:
     result = newJArray()
@@ -901,6 +921,9 @@ proc parseJson(p: var JsonParser; rawIntegers, rawFloats: bool): JsonNode =
       result.add(parseJson(p, rawIntegers, rawFloats))
       if p.tok != tkComma: break
       discard getTok(p)
+      # Raise `JsonParsingError` for a trailing comma, unlike `std/json`
+      if p.tok == tkBracketRi:
+        raiseParseErr(p, "found trailing comma. ] or array item")
     eat(p, tkBracketRi)
   of tkError, tkCurlyRi, tkBracketRi, tkColon, tkComma, tkEof:
     raiseParseErr(p, "{")
diff --git a/Nim/lib/pure/parsejson.nim b/configlet/src/patched_stdlib/parsejson.nim
index 196d8c3..48e1e05 100644
--- a/Nim/lib/pure/parsejson.nim
+++ b/configlet/src/patched_stdlib/parsejson.nim
@@ -1,11 +1,29 @@
-#
-#
-#            Nim's Runtime Library
-#        (c) Copyright 2018 Nim contributors
-#
-#    See the file "copying.txt", included in this
-#    distribution, for details about the copyright.
-#
+# This file is minimally adapted from this version in the Nim standard library:
+# https://github.com/nim-lang/Nim/blob/285539c87aa2/lib/pure/parsejson.nim
+# The standard library version is lenient: it silently allows line comments
+# with `//`, and long comments with `/* */`.
+# The below version is stricter: it raises a `JsonParsingError` for such
+# comments.
+
+# Copyright (c) 2018 Nim contributors
+
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.

 ## This module implements a json parser. It is used
 ## and exported by the `json` standard library
@@ -54,7 +72,6 @@ type
     errBracketRiExpected, ## `]` expected
     errCurlyRiExpected,   ## `}` expected
     errQuoteExpected,     ## `"` or `'` expected
-    errEOC_Expected,      ## `*/` expected
     errEofExpected,       ## EOF expected
     errExprExpected       ## expr expected

@@ -85,7 +102,6 @@ const
     "']' expected",
     "'}' expected",
     "'\"' or \"'\" expected",
-    "'*/' expected",
     "EOF expected",
     "expression expected"
   ]
@@ -263,43 +279,8 @@ proc skip(my: var JsonParser) =
   var pos = my.bufpos
   while true:
     case my.buf[pos]
-    of '/':
-      if my.buf[pos+1] == '/':
-        # skip line comment:
-        inc(pos, 2)
-        while true:
-          case my.buf[pos]
-          of '\0':
-            break
-          of '\c':
-            pos = lexbase.handleCR(my, pos)
-            break
-          of '\L':
-            pos = lexbase.handleLF(my, pos)
-            break
-          else:
-            inc(pos)
-      elif my.buf[pos+1] == '*':
-        # skip long comment:
-        inc(pos, 2)
-        while true:
-          case my.buf[pos]
-          of '\0':
-            my.err = errEOC_Expected
-            break
-          of '\c':
-            pos = lexbase.handleCR(my, pos)
-          of '\L':
-            pos = lexbase.handleLF(my, pos)
-          of '*':
-            inc(pos)
-            if my.buf[pos] == '/':
-              inc(pos)
-              break
-          else:
-            inc(pos)
-      else:
-        break
+    # Raise `JsonParsingError` for comments with `//` or `/* */`,
+    # unlike `std/parsejson`
     of ' ', '\t':
       inc(pos)
     of '\c':
@@ -350,7 +331,7 @@ proc parseName(my: var JsonParser) =

 proc getTok*(my: var JsonParser): TokKind =
   setLen(my.a, 0)
-  skip(my) # skip whitespace, comments
+  skip(my) # skip whitespace
   case my.buf[my.bufpos]
   of '-', '.', '0'..'9':
     parseNumber(my)

Copy link
Member

@ErikSchierboom ErikSchierboom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was it much work to update this?

@ee7 ee7 merged commit 761936b into exercism:main Oct 21, 2021
@ee7 ee7 deleted the build-bump-nim-1.6.0 branch October 21, 2021 06:53
@ee7
Copy link
Member Author

ee7 commented Oct 21, 2021

Was it much work to update this?

No - I've got a local branch in my Nim repo that I just pulled the upstream changes into, and then resolved a few simple merge conflicts (e.g. double backticks changed to single backticks).

It's also straightforward for somebody else to do:

  • clone nim-lang/Nim
  • create a branch at the release commit, e.g. nim-lang/Nim@727c637
  • replace the upstream json.nim and parsejson.nim contents with that of the copies in this repo
  • commit
  • when there's a new Nim release, pull in the new changes
  • if there's a merge conflict, make each overall diff look like the diff I've posted above.

For clarity, in each file I've also written the commit hash of the previous upstream change to that file.

In the long-term, we might not need to maintain our own copies if the stdlib json modules gain the ability to do stricter parsing, or if we migrate entirely to something like treeform/jsony.

@ErikSchierboom
Copy link
Member

In the long-term, we might not need to maintain our own copies if the stdlib json modules gain the ability to do stricter parsing, or if we migrate entirely to something like treeform/jsony.

We're already using jsony for the second phase linting, right? If so, I think that would be the best approach for us.

@ee7
Copy link
Member Author

ee7 commented Oct 22, 2021

We're already using jsony for the second phase linting, right? If so, I think that would be the best approach for us.

Indeed. We'd have to workaround some things with jsony too, though. It's designed to be lenient - by default it would allow wrongly capitalized key names, and permit trailing commas (but not comments), and each missing field is given its default value (so we have to be careful to distinguish that case).

support for Apple silicon/M1

We might want to add this to the releases too.

Sure - let's track it in #24 and #122

It will also require resolving #363, and updating the fetch-configlet script in every repo accordingly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants