How can I have those "template instance recursive expansion" errors under control?
realhet
real_het at hotmail.com
Sat Nov 30 19:32:45 UTC 2024
On Saturday, 30 November 2024 at 18:11:56 UTC, realhet wrote:
> narrowing it down would take
I was lucky, I narrowed down to only 2 files.
The recursion error occurs when I call this 'abomination' of a
template function:
https://github.com/realhet/hetlib/blob/fe028689791d011cd98bc63042ee76e28fcffad2/het/Math.d#L2271
With a vector color:
```d
image2D(1, 2, RGB(0,0,0))
```
This 'statically' calls itself: image2D(ivec2(1, 2), RGB(0,0,0))
And generates a 1 step deep recursion:
```d
hetmath.image2D!("", int, int, Vector!(ubyte, 3)).image2D(int
__param_0, int __param_1, Vector!(ubyte, 3) __param_2)
hetmath.image2D!("", Vector!(int, 2), Vector!(ubyte,
3)).image2D(Vector!(int, 2) __param_0, Vector!(ubyte, 3)
__param_1)
hetmath.image2D!("", Vector!(int, 2), MapResult!(__lambda3,
MapResult!(__lambda4, Result))).image2D(Vector!(int, 2)
__param_0, MapResult!(__lambda3, MapResult!(__lambda4, Result))
__param_1)
hetmath.d(609): Error: template instance
`std.traits.isNumeric!(Vector!(float, 3))` recursive expansion
```
It doesn't seems too much...
```d
image2D(ivec2(1, 2), 123) and image2D(1, 2, 123)
```
work well, but then I'm restricted to one color channels. :/
For example this could be a recursion violation:
```d
return image2D!fun(ivec2(args[0], args[1]), args[2..$])
```
I 'call' itself but with a single 2d vector parameter instead of
2 integer width/height parameters.
I do a lot of these unifications to keep the amnount of code low.
And I learned long ago that better to use a single declaration
that supports everything,
```d
auto image2D(alias fun="", A...)(A args) {}
```
A big overload set with all the possible parameter
specializations will be not usable. At least this is my feeling
based on my early experiences.
What annoys me the most is that I don't see the mechanics of what
things are going towards the template recursion error. :S It's
just seems like try and error and sometimes I find the voodoo
magic that will solve it for a while :D
But now it's kinda broken for me. (I had a big change since it
worked: LDC 1.28->1.40)
More information about the Digitalmars-d-learn
mailing list