Skip to content

Commit 99068cb

Browse files
committed
drop Nim 1.6 support
1 parent 88bb76b commit 99068cb

File tree

5 files changed

+50
-77
lines changed

5 files changed

+50
-77
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
build:
1111
uses: status-im/nimbus-common-workflow/.github/workflows/common.yml@main
1212
with:
13-
nimble-version: 1b4deb9be9fca7b8a21576a6c0de85f1ae7c30de
13+
nim-versions: '["version-2-0", "version-2-2", "devel"]'
1414
test-command: |
1515
env NIMLANG=c nimble test
1616
env NIMLANG=cpp nimble test

json_serialization.nimble

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ description = "Flexible JSON serialization not relying on run-time type inform
1616
license = "Apache License 2.0"
1717
skipDirs = @["tests", "fuzzer"]
1818

19-
requires "nim >= 1.6.0",
19+
requires "nim >= 2.0.0",
2020
"faststreams >= 0.5.0",
2121
"serialization",
2222
"stew >= 0.2.0",

json_serialization/format.nim

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,9 @@ template flavorEnumRep*(T: type Json, rep: static[EnumRepresentation]) =
8383
static:
8484
DefaultFlavorEnumRep = rep
8585

86-
when declared(macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey
87-
# Keep backward compatibility behavior, DefaultFlavor always enable all built in serialization.
88-
generateJsonAutoSerializationAddon(DefaultFlavor)
89-
DefaultFlavor.automaticBuiltinSerialization(true)
86+
# Keep backward compatibility behavior, DefaultFlavor always enable all built in serialization.
87+
generateJsonAutoSerializationAddon(DefaultFlavor)
88+
DefaultFlavor.automaticBuiltinSerialization(true)
9089

9190
# We create overloads of these traits to force the mixin treatment of the symbols
9291
type DummyFlavor* = object
@@ -96,9 +95,8 @@ template flavorRequiresAllFields*(T: type DummyFlavor): bool = false
9695
template flavorAllowsUnknownFields*(T: type DummyFlavor): bool = false
9796
template flavorSkipNullFields*(T: type DummyFlavor): bool = false
9897

99-
when declared(macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey
100-
generateJsonAutoSerializationAddon(DummyFlavor)
101-
DummyFlavor.automaticBuiltinSerialization(false)
98+
generateJsonAutoSerializationAddon(DummyFlavor)
99+
DummyFlavor.automaticBuiltinSerialization(false)
102100

103101
template decode*(
104102
Format: type Json,
@@ -148,10 +146,9 @@ template createJsonFlavor*(FlavorName: untyped,
148146
static:
149147
`FlavorName EnumRep` = rep
150148

151-
when declared(macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey
152-
generateJsonAutoSerializationAddon(FlavorName)
149+
generateJsonAutoSerializationAddon(FlavorName)
153150

154-
# Set default to true for backward compatibility
155-
# but user can call it again later with different value.
156-
# Or fine tuning use `Flavor.automaticSerialization(type, true/false)`
157-
FlavorName.automaticBuiltinSerialization(automaticPrimitivesSerialization)
151+
# Set default to true for backward compatibility
152+
# but user can call it again later with different value.
153+
# Or fine tuning use `Flavor.automaticSerialization(type, true/false)`
154+
FlavorName.automaticBuiltinSerialization(automaticPrimitivesSerialization)

json_serialization/reader_impl.nim

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -226,33 +226,27 @@ proc readRecordValue*[T](r: var JsonReader, value: var T)
226226
r.raiseUnexpectedField(key, cstring typeName)
227227

228228
template autoSerializeCheck(F: distinct type, T: distinct type, body) =
229-
when declared(macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey
230-
mixin typeAutoSerialize
231-
when not F.typeAutoSerialize(T):
232-
const
233-
typeName = typetraits.name(T)
234-
flavorName = typetraits.name(F)
235-
{.error: flavorName &
236-
": automatic serialization is not enabled or readValue not implemented for `" &
237-
typeName & "`".}
238-
else:
239-
body
229+
mixin typeAutoSerialize
230+
when not F.typeAutoSerialize(T):
231+
const
232+
typeName = typetraits.name(T)
233+
flavorName = typetraits.name(F)
234+
{.error: flavorName &
235+
": automatic serialization is not enabled or readValue not implemented for `" &
236+
typeName & "`".}
240237
else:
241238
body
242239

243240
template autoSerializeCheck(F: distinct type, TC: distinct type, M: distinct type, body) =
244-
when declared(macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey
245-
mixin typeClassOrMemberAutoSerialize
246-
when not F.typeClassOrMemberAutoSerialize(TC, M):
247-
const
248-
typeName = typetraits.name(M)
249-
typeClassName = typetraits.name(TC)
250-
flavorName = typetraits.name(F)
251-
{.error: flavorName &
252-
": automatic serialization is not enabled or readValue not implemented for `" &
253-
typeName & "` of typeclass `" & typeClassName & "`".}
254-
else:
255-
body
241+
mixin typeClassOrMemberAutoSerialize
242+
when not F.typeClassOrMemberAutoSerialize(TC, M):
243+
const
244+
typeName = typetraits.name(M)
245+
typeClassName = typetraits.name(TC)
246+
flavorName = typetraits.name(F)
247+
{.error: flavorName &
248+
": automatic serialization is not enabled or readValue not implemented for `" &
249+
typeName & "` of typeclass `" & typeClassName & "`".}
256250
else:
257251
body
258252

@@ -391,17 +385,11 @@ proc readValue*[T](r: var JsonReader, value: var T)
391385
r.raiseUnexpectedValue("Too many items for " & $(typeof(value)))
392386

393387
elif value is object:
394-
when declared(macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey and cannot accept `object` param
395-
autoSerializeCheck(Flavor, object, typeof(value)):
396-
readValueObjectOrTuple(Flavor, r, value)
397-
else:
388+
autoSerializeCheck(Flavor, object, typeof(value)):
398389
readValueObjectOrTuple(Flavor, r, value)
399390

400391
elif value is tuple:
401-
when declared(macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey and cannot accept `tuple` param
402-
autoSerializeCheck(Flavor, tuple, typeof(value)):
403-
readValueObjectOrTuple(Flavor, r, value)
404-
else:
392+
autoSerializeCheck(Flavor, tuple, typeof(value)):
405393
readValueObjectOrTuple(Flavor, r, value)
406394

407395
else:

json_serialization/writer.nim

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -390,33 +390,27 @@ template isStringLikeArray[N](v: array[N, char]): bool = true
390390
template isStringLikeArray(v: auto): bool = false
391391

392392
template autoSerializeCheck(F: distinct type, T: distinct type, body) =
393-
when declared(macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey
394-
mixin typeAutoSerialize
395-
when not F.typeAutoSerialize(T):
396-
const
397-
typeName = typetraits.name(T)
398-
flavorName = typetraits.name(F)
399-
{.error: flavorName &
400-
": automatic serialization is not enabled or writeValue not implemented for `" &
401-
typeName & "`".}
402-
else:
403-
body
393+
mixin typeAutoSerialize
394+
when not F.typeAutoSerialize(T):
395+
const
396+
typeName = typetraits.name(T)
397+
flavorName = typetraits.name(F)
398+
{.error: flavorName &
399+
": automatic serialization is not enabled or writeValue not implemented for `" &
400+
typeName & "`".}
404401
else:
405402
body
406403

407404
template autoSerializeCheck(F: distinct type, TC: distinct type, M: distinct type, body) =
408-
when declared(macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey
409-
mixin typeClassOrMemberAutoSerialize
410-
when not F.typeClassOrMemberAutoSerialize(TC, M):
411-
const
412-
typeName = typetraits.name(M)
413-
typeClassName = typetraits.name(TC)
414-
flavorName = typetraits.name(F)
415-
{.error: flavorName &
416-
": automatic serialization is not enabled or writeValue not implemented for `" &
417-
typeName & "` of typeclass `" & typeClassName & "`".}
418-
else:
419-
body
405+
mixin typeClassOrMemberAutoSerialize
406+
when not F.typeClassOrMemberAutoSerialize(TC, M):
407+
const
408+
typeName = typetraits.name(M)
409+
typeClassName = typetraits.name(TC)
410+
flavorName = typetraits.name(F)
411+
{.error: flavorName &
412+
": automatic serialization is not enabled or writeValue not implemented for `" &
413+
typeName & "` of typeclass `" & typeClassName & "`".}
420414
else:
421415
body
422416

@@ -553,17 +547,11 @@ proc writeValue*[V: not void](w: var JsonWriter, value: V) {.raises: [IOError].}
553547
w.writeArray(value)
554548

555549
elif value is object:
556-
when declared(macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey and cannot accept `object` param
557-
autoSerializeCheck(Flavor, object, typeof(value)):
558-
writeValueObjectOrTuple(Flavor, w, value)
559-
else:
550+
autoSerializeCheck(Flavor, object, typeof(value)):
560551
writeValueObjectOrTuple(Flavor, w, value)
561552

562553
elif value is tuple:
563-
when declared(macrocache.hasKey): # Nim 1.6 have no macrocache.hasKey and cannot accept `tuple` param
564-
autoSerializeCheck(Flavor, tuple, typeof(value)):
565-
writeValueObjectOrTuple(Flavor, w, value)
566-
else:
554+
autoSerializeCheck(Flavor, tuple, typeof(value)):
567555
writeValueObjectOrTuple(Flavor, w, value)
568556

569557
elif value is distinct:

0 commit comments

Comments
 (0)