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
chaining of procs with concepts yields Error: too nested for type matching
or exponential compile time
#9422
Comments
Error: too nested for type matching
fixed ! see timotheecour/vitanim@3885dd5 instead of using concepts ( I'll leave this issue open, it looks odd that concepts used this way lead to either |
Error: too nested for type matching
Error: too nested for type matching
The exponential compiletimes for concepts are known and mysterious. :-) But I'm leaving this open since it's a new test case that doesn't depend on |
Error: too nested for type matching
Error: too nested for type matching
Error: too nested for type matching
Error: too nested for type matching
or exponential compile time
EDIT previous title was:
but I found a proper workaround in #9422 (comment) ; turns out this issue was with chaining of concepts.blocker for implementing D ranges in Nim: Error: too nested for type matching
/cc @zah @Araq @LemonBoy
motivation
I'm trying to bring to Nim the concept of D ranges (https://dlang.org/phobos/std_range.html and http://ddili.org/ders/d.en/ranges.html), arguably one of the most powerful and unique features of D. One feature of D ranges is that they have no compiler support (beyond
foreach
syntax sugar) and are purely defined in library code, which makes me think we should be able to do the same in Nim.Why should we care ? because Nim's iterators have serious shortcomings, as has been discussed many times (see also related github issues):
Unlike Nim closure iterators, D ranges are a zero-cost abstraction (as fast as manual code could be), while being first class citizens, meaning you can return ranges, combine them arbitrarily, etc. They're also more flexible than even closure iterators, eg can be extended with arbitrary concepts via duck-typing: D's standard library defines (and uses extensively) variations on Ranges such as:
len
and random access; act similar to aseq
but they don't have to be backed by in-memory buffer, eg:iota
: see https://dlang.org/library/std/range/iota.html)implementation
My implementation below is very straightfoward and works... to a point. I define below
map
,filter
,take
(that operate lazily on ranges, returning ranges), as well as a simplified version of D'siota
range (https://dlang.org/library/std/range/iota.html) which is a lazy range with elements0
throughn-1
.This works well:
the bug
but whenever I have a composition of >=3 range operations (instead of just 2, like above), I get a giant error with 13145 lines of compiler error mentioning "too nested for type matching" in a lot of places; see also WORKAROUND below (with its associated caveat)
full implementation
(EDIT extracted from nimble package
drange
that I'm working on: https://github.com/timotheecour/vitanim/tree/master/drange)See fully self contained example below where I show the bug I'm running into.
related forum discussion with @Araq
links
workaround (with exponential compile time)
EDIT as a workaround, set
if prevMatchedConcept.depth > 10
in sigmatch.nim ; however this results in dramatic (exponential in number of chained ranges) slowdown with deeper expression, as shown in timotheecour/vitanim@e92cdaf :The text was updated successfully, but these errors were encountered: