Open redvers opened 2 years ago
I accidentally'd the stack.
From my backtrace, it seems like the compiler is getting into an infinite recursive loop:
frame #55455: 0x00000001000a44f8 ponyc`is_x_sub_x + 1824
frame #55456: 0x00000001000a6cc8 ponyc`is_typeparam_sub_x + 184
frame #55457: 0x00000001000a7390 ponyc`is_eq_typeargs + 232
frame #55458: 0x00000001000a7278 ponyc`exact_nominal + 196
frame #55459: 0x00000001000a44f8 ponyc`is_x_sub_x + 1824
frame #55460: 0x00000001000a7390 ponyc`is_eq_typeargs + 232
frame #55461: 0x00000001000a7278 ponyc`exact_nominal + 196
frame #55462: 0x00000001000a44f8 ponyc`is_x_sub_x + 1824
frame #55463: 0x00000001000a6cc8 ponyc`is_typeparam_sub_x + 184
frame #55464: 0x00000001000a7390 ponyc`is_eq_typeargs + 232
frame #55465: 0x00000001000a7278 ponyc`exact_nominal + 196
frame #55466: 0x00000001000a44f8 ponyc`is_x_sub_x + 1824
frame #55467: 0x00000001000a7390 ponyc`is_eq_typeargs + 232
frame #55468: 0x00000001000a4c34 ponyc`is_x_sub_x + 3676
frame #55469: 0x000000010006a70c ponyc`check_receiver_cap + 712
frame #55470: 0x000000010006a3bc ponyc`method_application + 1504
Well, since this is tagged 'help wanted' and the issue isn't obvious - let's see if I can help:
Minimal Crash:
fun flatten[A: Array[Array[A]] #read](arrayin: Array[Array[A]]) =>
let rv: Array[A] = Array[A]
for f in arrayin.values() do
None
end
Doesn't crash:
fun flatten[A: Array[Array[A]] #read](arrayin: Array[Array[A]]) => //: Array[A] =>
let rv: Array[A] = Array[A]
Crashes:
fun flatten[A: Array[Array[A]] #read](arrayin: Array[Array[A]]) => //: Array[A] =>
let rv: Array[A] = Array[A]
try
let q = arrayin(0)?
end
Doesn't crash:
fun flatten[A: Array[MapIs[A, Any]] #read](arrayin: Array[MapIs[A, Any]]) => //: Array[A] =>
let rv: Array[A] = Array[A]
try
let q = arrayin(0)?
end
Does crash:
fun flatten[A: MapIs[MapIs[A, Any], Any] #read](arrayin: MapIs[MapIs[A, Any], Any]) => //: Array[A] =>
let rv: Array[A] = Array[A]
try
let q = arrayin(0)?
end
So, I'm concluding that the compiler is having issues with generic types which contain themselves. I'm guessing (I'm not deep enough in the compiler to fully understand what is going on) that when it tries to navigate the AST the reference to Array[A] and Array[Array[A]] is the same?
fun flatten[A: Array[A] #read, B: Array[A]](arrayin: Array[Array[A]]) =>
Also crashes
fun flatten[A: Array[B] #read, B: Array[Any] #read](arrayin: Array[Array[A]]) =>
Does work when you don't do anything with it, but when you try and use it:
/home/red/projects/pony/pony-enum/enum/Enum.pony:71:43: Any tag is not a subtype of Array[Any tag] #read
fun flatten[A: Array[B] #read, B: Array[Any] #read](arrayin: Array[Array[A]]) => //: Array[A] =>
^
/home/red/projects/pony/pony-enum/enum/Enum.pony:71:18: Array[B #read] #read has different type arguments than Array[Any tag] #read^
fun flatten[A: Array[B] #read, B: Array[Any] #read](arrayin: Array[Array[A]]) => //: Array[A] =>
^
/home/red/projects/pony/pony-enum/enum/Enum.pony:71:18: Array[B #read] #read is not a subtype of Array[Any tag] #read^: #read is not a subcap of #read^
fun flatten[A: Array[B] #read, B: Array[Any] #read](arrayin: Array[Array[A]]) => //: Array[A] =>
^
The more I think about this, the more that I'm thinking I'm asking the impossible. This may be something that shouldn't be able to be expressed. I'm going to think on it some more.
... because I'm saying that A is always an Array of something. So it's Arrays all the way down.
I should probably close this.
(Basically - I'm doing a version of this:
fun flatten[A: Array[B] #read, B: Array[A] #read](arrayin: Array[Array[A]]) =>
I don't think this should be closed, it should at least be fixed by making the compiler print an error message.
I'm trying to see if I can formulate another way to create my function. I'm not sure there is.
fun flatten[A: Array[Array[B]] #read, B: Any #read](arrayin: Array[Array[B]])
!
Yeah, there are two issues here:
I would love to be able to have recursive types. There's a really old issue opened by me for it.
That said as @jasoncarr0 said, we should fix the "BOOM!" that happens here. I know at some point there was no boom for recursive types, that might still be the case and this is missed by the recursive type prevention in the compiler.
Minimal case:
lldb gives: