-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Make IntSet a generic ordinal set PackedSet[A] + new module packedsets #15564
Conversation
a4b7c85
to
3b95df0
Compare
3b95df0
to
d9b5c9b
Compare
6d619a7
to
a012d35
Compare
I liked it better before it touched the compiler, but whatever. I think we have to wait until |
/cc @landerl
what do you mean? this passes: type int2 = distinct int
doAssert int2 is Ordinal |
See my comment above, making all the type params A: Ordinal didn't work for me, but just making OrdSet[A: Ordinal] and the api procs [A] seems to work and has now better compilation errors, so yes, concepts are not necessary for this. |
78e65ee
to
2987344
Compare
I mean that |
At the moment is magic but there could be a concept modeling Ordinal with That Ordinal concept could be further generalised to Isomorphic. so concept |
2987344
to
857e1dd
Compare
857e1dd
to
63687ac
Compare
63687ac
to
5dde786
Compare
ad98aa4
to
4b81ab3
Compare
LGTM; good to merge? |
I've already did a full review and gave my LGTM ... @Araq or other nim member can i merge this? |
Sorry, I thought it already was merged. |
I do realise now that sed doesn't go through the commit messages, so the commit log still talks about OrdSet and not the renamed PackedSet. Nevermind. |
Thanks for all your work on this, @landerlo -- I know it was a slog but this is a nice contribution. ❤️ |
I hate to say it, but this is causing the https://github.com/disruptek/gram/runs/1419861309?check_suite_focus=true /home/adavidoff/nims/lib/std/packedsets.nim(370, 14) Error: type mismatch: got <PackedSet[system.int]>
but expected one of:
iterator items(a: cstring): char
first type mismatch at position: 1
required type for a: cstring
but expression 's' is of type: PackedSet[system.int]
iterator items(a: string): char
first type mismatch at position: 1
required type for a: string
but expression 's' is of type: PackedSet[system.int]
iterator items(n: NimNode): NimNode
first type mismatch at position: 1
required type for n: NimNode
but expression 's' is of type: PackedSet[system.int]
iterator items[IX, T](a: array[IX, T]): T
first type mismatch at position: 1
required type for a: array[IX, T]
but expression 's' is of type: PackedSet[system.int]
iterator items[N, E; F: static[GraphFlags]](graph: Graph[N, E, F]): N
first type mismatch at position: 1
required type for graph: Graph[items.N, items.E, items.F]
but expression 's' is of type: PackedSet[system.int]
iterator items[T: char](a: openArray[T]): T
first type mismatch at position: 1
required type for a: openArray[T: char]
but expression 's' is of type: PackedSet[system.int]
iterator items[T: enum](E: typedesc[T]): T
first type mismatch at position: 1
required type for E: type T: enum
but expression 's' is of type: PackedSet[system.int]
iterator items[T: not char](a: openArray[T]): lent2 T
first type mismatch at position: 1
required type for a: openArray[T: not char]
but expression 's' is of type: PackedSet[system.int]
iterator items[T](a: seq[T]): lent2 T
first type mismatch at position: 1
required type for a: seq[T]
but expression 's' is of type: PackedSet[system.int]
iterator items[T](a: set[T]): T
first type mismatch at position: 1
required type for a: set[T]
but expression 's' is of type: PackedSet[system.int]
iterator items[T](s: HSlice[T, T]): T
first type mismatch at position: 1
required type for s: HSlice[items.T, items.T]
but expression 's' is of type: PackedSet[system.int]
expression: items(s) |
@disruptek can you provide a minimized reproducible example? |
Is gram too complex for you? |
that's basically what everyone has to go through when submitting bug reports, providing minimized reproducing examples. More work for the reporter, less work for everyone else looking at it. |
Yeah, but only if they didn't manage to get their package into |
|
Let's agree that you'll be the |
As a compromise, both modules could expand a common template implementation -- then there cannot be regressions like this. |
@disruptek Sorry for the regression. Tests test int iterators but there must be some issue why the iterator is not properly inferred. |
Can't we just fix it instead? |
=> #16060, much cleaner |
Nice work! Another good reason to be explicit with iterators, at least until this is fixed. |
* Make IntSet an ordinal set OrdSet[A: Ordinal] Backward compatibility with IntSet is maintained. IntSet is an alias for OrdSet[int] * move ordsets to new file, intsets exports it * ordset, move to lib/std folder * Fix `$` for ordsets and test cleanup * Fix ordsets compilation in doc example * Rename ordsets to packedsets
* Make IntSet an ordinal set OrdSet[A: Ordinal] Backward compatibility with IntSet is maintained. IntSet is an alias for OrdSet[int] * move ordsets to new file, intsets exports it * ordset, move to lib/std folder * Fix `$` for ordsets and test cleanup * Fix ordsets compilation in doc example * Rename ordsets to packedsets
* packedsets fix regression introduced in nim-lang#15564 * add tests
* Make IntSet an ordinal set OrdSet[A: Ordinal] Backward compatibility with IntSet is maintained. IntSet is an alias for OrdSet[int] * move ordsets to new file, intsets exports it * ordset, move to lib/std folder * Fix `$` for ordsets and test cleanup * Fix ordsets compilation in doc example * Rename ordsets to packedsets
* Make IntSet an ordinal set OrdSet[A: Ordinal] Backward compatibility with IntSet is maintained. IntSet is an alias for OrdSet[int] * move ordsets to new file, intsets exports it * ordset, move to lib/std folder * Fix `$` for ordsets and test cleanup * Fix ordsets compilation in doc example * Rename ordsets to packedsets
* packedsets fix regression introduced in nim-lang#15564 * add tests
This makes intsets generic for ordinal types like enums or distinct of ints. For cases when multiple intsets with complex logic making them generic boosts their usability and type safety.
E.g. iqqn my use case I need to distinguish different ids making them distinct and get compilation errors if
I do any set operations with incompatible ids.
The PR achieves this maintaining full backwards compatibility and same performance.
As a drop in replacement, the current api is unchanged and IntSet is aliased to OrdSet[int].
OrdSet is for ordinal set. I realise there might be a confusion with ordered sets, so naming suggestions welcome.
Better error messages on compilation errors will be achieved when the concepts are ready, but I didn't want to tie it to a future roadmap, and the current solution achieves the stated goals satisfactorily IMHO.