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.71k stars 415 forks source link

Another way to crash ponyc #3529

Open damon-kwok opened 4 years ago

damon-kwok commented 4 years ago

any_set.pony:

use "collections"
class FooSet[A: Any #read]
  embed _map: FooMap[A!, A]
  let _f_hash: ({(box->A!): USize} val | HashFunction[box->A!] val)

  new create(f: ({(box->A!): USize} val | HashFunction[box->A!] val)
    = {(key: box->A!): USize =>
    match key
      | let key': HashFunction[box->A!] val => key'.hash(key)
      | let key': Hashable val => key'.hash()
    end; 0}) =>
    _f_hash = f
    _map = _map.create(f)
-*- mode: compilation; default-directory: "~/projects/pp6/" -*-
Compilation started at Tue Apr 28 15:17:07

ponyc
Building builtin -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\builtin
Building . -> d:\msys64\home\damon\projects\pp6
Building collections -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\collections
Building ponytest -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\ponytest
Building time -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\time
Building random -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\random
D:\msys64\home\damon\.ome_local\repo\ponyc-git\src\libponyc\ast\ast.c:901: ast_has_annotation: Assertion `ast != NULL` failed.

Backtrace:
  () [00007FF6B88D0384]
  () [00007FF6B8820505]
  () [00007FF6B8882D5A]
  () [00007FF6B888BFFA]
  () [00007FF6B8840A18]
  () [00007FF6B8824925]
  () [00007FF6B88248C7]
  () [00007FF6B88248C7]
  () [00007FF6B88248C7]
  () [00007FF6B88248C7]
  () [00007FF6B88248C7]
  () [00007FF6B88248C7]
  () [00007FF6B88248C7]
  () [00007FF6B88248C7]
  () [00007FF6B88248C7]
  () [00007FF6B88248C7]
  () [00007FF6B88248C7]
  () [00007FF6B882425E]
  () [00007FF6B8824669]
  () [00007FF6B8827E71]
  () [00007FF6B881C4E4]
  () [00007FF6B881C6D2]
  (pony_asio_event_set_writeable) [00007FF6B948DEB4]
  (BaseThreadInitThunk) [00007FFE9E167BD4]
  (RtlUserThreadStart) [00007FFE9E68CE51]
This is an optimised version of ponyc: the backtrace may be imprecise or incorrect.
Use a debug version to get more meaningful information.

Compilation exited abnormally with code 9 at Tue Apr 28 15:17:10
SeanTAllen commented 4 years ago

I'm unable to verify on Ubuntu 18.04 with 0.33.1. I get the correct syntax error message.

SeanTAllen commented 4 years ago

Can't replicate on Ubuntu 18.04 with latest master. I get the correct syntax error message.

SeanTAllen commented 4 years ago

@damon-kwok you'll need to provide more detailed replication instructions.

damon-kwok commented 4 years ago

@SeanTAllen OS: Windows10 Ponyc: 0.33.2 0.34.1

ponyc --version
0.34.1-87b473d [release]
Compiled with: LLVM 9.0.1 -- MSVC-19.26.28803.1-x64 1926
ponyc
Building builtin -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\builtin
Building . -> d:\msys64\home\damon\workspace\projects\pony\crash_ast
Building collections -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\collections
Building ponytest -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\ponytest
Building time -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\time
Building random -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\random
D:\msys64\home\damon\.ome_local\repo\ponyc-git\src\libponyc\ast\ast.c:901: ast_has_annotation: Assertion `ast != NULL` failed.

Backtrace:
  () [00007FF616C70394]
  () [00007FF616BC0515]
  () [00007FF616C22D6A]
  () [00007FF616C2C00A]
  () [00007FF616BE0A28]
  () [00007FF616BC4935]
  () [00007FF616BC48D7]
  () [00007FF616BC48D7]
  () [00007FF616BC48D7]
  () [00007FF616BC48D7]
  () [00007FF616BC48D7]
  () [00007FF616BC48D7]
  () [00007FF616BC48D7]
  () [00007FF616BC48D7]
  () [00007FF616BC48D7]
  () [00007FF616BC48D7]
  () [00007FF616BC48D7]
  () [00007FF616BC426E]
  () [00007FF616BC4679]
  () [00007FF616BC7E81]
  () [00007FF616BBC4E4]
  () [00007FF616BBC6E1]
  (pony_asio_event_set_writeable) [00007FF61782DEC4]
  (BaseThreadInitThunk) [00007FFE9E167BD4]
  (RtlUserThreadStart) [00007FFE9E68CE51]
This is an optimised version of ponyc: the backtrace may be imprecise or incorrect.
Use a debug version to get more meaningful information.

Compilation exited abnormally with code 9 at Fri May  8 10:58:18
SeanTAllen commented 4 years ago

@kulibali can you see if you get an error with a windows build?

chalcolith commented 4 years ago

Yeah, I can repro this on Windows.

SeanTAllen commented 4 years ago

@kulibali what's a better title for this issue?

jemc commented 4 years ago

Given that this is in ast_has_annotation. This is probably in the codegen pass, which might help explain why it only occurs on windows - that's one of the only places in the compiler that is platform-specific.

Sylvan also noted in today's sync call that the reference to asio in the backtrace is probably a red herring because it isn't involved in ponyc - probably the backtrace addresses being totally bogus and just happening to match a function or two by coincidence.

chalcolith commented 4 years ago

Here's a debug backtrace:

Building builtin -> C:\Users\Gordon\Dev\Pony\ponyc_llvm901\packages\builtin
Building . -> C:\Users\Gordon\Dev\Pony\ponyc_llvm901\build\test_3529
Building collections -> C:\Users\Gordon\Dev\Pony\ponyc_llvm901\packages\collections
Building ponytest -> C:\Users\Gordon\Dev\Pony\ponyc_llvm901\packages\ponytest
Building time -> C:\Users\Gordon\Dev\Pony\ponyc_llvm901\packages\time
Building random -> C:\Users\Gordon\Dev\Pony\ponyc_llvm901\packages\random
C:\Users\Gordon\Dev\Pony\ponyc_llvm901\src\libponyc\ast\ast.c:901: ast_has_annotation: Assertion `ast != NULL` failed.

Backtrace:
  (ponyint_assert_fail) [00007FF6A689C46F]
  (ast_has_annotation) [00007FF6A674123D]
  (is_bare) [00007FF6A67DBE85]
  (is_bare) [00007FF6A67DBE9E]
  (check_constraints) [00007FF6A67E6E9D]
  (expr_nominal) [00007FF6A67F89E5]
  (pass_expr) [00007FF6A6784A13]
  (ast_visit) [00007FF6A67490FA]
  (ast_visit) [00007FF6A6749036]
  (ast_visit) [00007FF6A6749036]
  (ast_visit) [00007FF6A6749036]
  (ast_visit) [00007FF6A6749036]
  (ast_visit) [00007FF6A6749036]
  (ast_visit) [00007FF6A6749036]
  (ast_visit) [00007FF6A6749036]
  (ast_visit) [00007FF6A6749036]
  (ast_visit) [00007FF6A6749036]
  (ast_visit) [00007FF6A6749036]
  (ast_visit) [00007FF6A6749036]
  (visit_pass) [00007FF6A6749484]
  (ast_passes) [00007FF6A67498F0]
  (ast_passes_program) [00007FF6A6748B68]
  (program_load) [00007FF6A674ADCF]
  (compile_package) [00007FF6A673BFEC]
  (main) [00007FF6A673C295]
  (__scrt_common_main_seh) [00007FF6A7AA5B5C]
  (BaseThreadInitThunk) [00007FF80E8E7BD4]
  (RtlUserThreadStart) [00007FF80F36CE51]
jemc commented 4 years ago

Thanks, Gordon. So I was wrong about it being in codegen - it's in the expr pass.

jemc commented 4 years ago

You may (or may not) be able to fix this crash by modifying this line: https://github.com/ponylang/ponyc/blob/e55db85d928ce34386edd39b3c135977aba5eb65/src/libponyc/type/reify.c#L380

To look like:

 if(typearg && is_bare(typearg))