ponylang / ponyc

Pony is an open-source, actor-model, capabilities-secure, high performance programming language
http://www.ponylang.io
BSD 2-Clause "Simplified" License
5.7k stars 415 forks source link

StdStream.writev with "deep" array literal inference causes compiler crash #2701

Open ergl opened 6 years ago

ergl commented 6 years ago

Compiling this piece of code causes a compilation crash

actor Main
  new create(env: Env) =>
    env.out.writev([])
> ponyc .
Building builtin -> /usr/local/Cellar/ponyc/0.21.3/packages/builtin
Building . -> ~/Downloads/test
Generating
 Reachability
src/libponyc/codegen/genname.c:63: type_append: Assertion `0` failed.

Backtrace:
  0   ponyc                               0x00000001027ef1dd ponyint_assert_fail + 176
  1   ponyc                               0x0000000102793570 types_append + 67
  2   ponyc                               0x0000000102793570 types_append + 67
  3   ponyc                               0x000000010279327e type_append + 288
  4   ponyc                               0x0000000102793143 genname_type + 36
  5   ponyc                               0x00000001027d5f49 reach_type + 23
  6   ponyc                               0x00000001027d6415 add_type + 245
  7   ponyc                               0x00000001027d5bc5 reachable_method + 66
  8   ponyc                               0x00000001027d87b4 reachable_fun + 214
  9   ponyc                               0x00000001027d8332 reachable_expr + 1286
  10  ponyc                               0x00000001027d8516 reachable_expr + 1770
  11  ponyc                               0x00000001027d8516 reachable_expr + 1770
  12  ponyc                               0x00000001027d8516 reachable_expr + 1770
  13  ponyc                               0x00000001027d8516 reachable_expr + 1770
  14  ponyc                               0x00000001027d8516 reachable_expr + 1770
  15  ponyc                               0x00000001027d8516 reachable_expr + 1770
  16  ponyc                               0x00000001027d5b6f reach + 106
  17  ponyc                               0x000000010278c19d genexe + 245
  18  ponyc                               0x0000000102782555 codegen + 216
  19  ponyc                               0x00000001027bfece generate_passes + 16
  20  ponyc                               0x000000010275404d compile_package + 109
  21  ponyc                               0x0000000102753f80 main + 368
  22  libdyld.dylib                       0x00007fff8bba85ad start + 1
This is an optimised version of ponyc: the backtrace may be imprecise or incorrect.
Use a debug version to get more meaningful information.
Abort trap: 6

Pony version:

> ponyc -v
0.21.3 [release]
compiled with: llvm 3.9.1 -- Apple LLVM version 8.0.0 (clang-800.0.42.1)
jemc commented 6 years ago

Specifically, this seems to be related to array literal inference interacting with ByteSeqIter.

SeanTAllen commented 6 years ago

@jemc do you have information you could put here that would allow this to be marked as ready for work?

jemc commented 6 years ago

It's not enough to mark it as ready for work, but I can provide some pointers:

The code for array literal inference is here: https://github.com/ponylang/ponyc/blob/3f5cf694ba10fba81df4999e167cad6274b990ee/src/libponyc/expr/array.c#L52-L355

The strategy for inference is to try to find a viable antecedent type (left hand side) and use it to infer the array literal on the right hand side.

It has separate inference strategies based on the antecedent type, tried in this order.

For ByteSeqIter, which is an interface with a values method, it would be using the third strategy, for which the code is here: https://github.com/ponylang/ponyc/blob/3f5cf694ba10fba81df4999e167cad6274b990ee/src/libponyc/expr/array.c#L84-L119

slfritchie commented 6 years ago

See also #2790 for a bit more context & example code snippets.