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

ponyc crash #3528

Open damon-kwok opened 4 years ago

damon-kwok commented 4 years ago

In order to successfully compile in VS2019 preview 4.0

typedef struct pool_block_t { pool_block_t(){} // Added: pool_block_t(){} struct pool_block_t prev; union { struct pool_block_t next; PONY_ATOMIC(struct pool_block_t*) global; //Note, PONY_ATOMIC(T) is a std::atomic<T> it need a Constructor }; size_t size; PONY_ATOMIC(bool) acquired; } pool_block_t;

- modified: make.ps1  add:"-prerelease" for vswhere

$cmakePath = $(Get-Item $( Invoke-Expression '& "$vswhere" -prerelease -latest -requires Microsoft.VisualStudio.Component.VC.CMake.Project -find Common7/IDE/**/cmake.exe ' )).Directory.FullName


````bash
$ ponyc --version
0.33.2-19bf994 [release]
Compiled with: LLVM 9.0.1 -- MSVC-19.26.28803.1-x64 1926
$ git log
commit 955a9ae4745e573307169f4f7e39a0eff3514eea (HEAD -> master, origin/master, origin/HEAD)
Author: Ponylang Main Bot <ponylang.main@gmail.com>
Date:   Fri Apr 24 23:50:39 2020 +0000

    Update CHANGELOG for PR #3525 [skip ci]

commit 19bf9945788b77bb7e58eb3d580ced35fa4c4e62
Author: Sean T. Allen <sean@seantallen.com>
Date:   Fri Apr 24 15:00:21 2020 -0400

    Add prebuilt FreeBSD 12.1 builds for releases
$ ./vswhere -prerelease
Copyright (C) Microsoft Corporation. All rights reserved.

instanceId: b5b4e456
installDate: 2020/3/12 11:16:22
installationName: VisualStudioPreview/16.6.0-pre.4.0+30021.99
installationPath: C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview
installationVersion: 16.6.30021.99
productId: Microsoft.VisualStudio.Product.Community
productPath: C:\Program Files (x86)\Microsoft Visual Studio\2019\Preview\Common7\IDE\devenv.exe
state: 4294967295
isComplete: 1
isLaunchable: 1
isPrerelease: 1
isRebootRequired: 0
displayName: Visual Studio Community 2019
description: 功能强大的 IDE,供学生、开放源代码参与者和个人免费使用
channelId: VisualStudio.16.Preview
channelUri: https://aka.ms/vs/16/pre/channel
enginePath: C:\program files (x86)\microsoft visual studio\installer\resources\app\ServiceHub\Services\Microsof
installChannelUri: C:\D\vs2019-prevew-offline\ChannelManifest.json
layoutPath: C:\D\vs2019-prevew-offline
releaseNotes: https://go.microsoft.com/fwlink/?LinkId=660894#16.6.0-pre.4.0
thirdPartyNotices: https://go.microsoft.com/fwlink/?LinkId=660909
updateDate: 2020-04-24T05:36:58.7871126Z
catalog_buildBranch: d16.6
catalog_buildVersion: 16.6.30021.99
catalog_id: VisualStudioPreview/16.6.0-pre.4.0+30021.99
catalog_localBuild: build-lab
catalog_manifestName: VisualStudioPreview
catalog_manifestType: installer
catalog_productDisplayVersion: 16.6.0 Preview 4.0
catalog_productLine: Dev16
catalog_productLineVersion: 2019
catalog_productMilestone: Preview
catalog_productMilestoneIsPreRelease: True
catalog_productName: Visual Studio
catalog_productPatchVersion: 0
catalog_productPreReleaseMilestoneSuffix: 4.0
catalog_productSemanticVersion: 16.6.0-pre.4.0+30021.99
catalog_requiredEngineVersion: 2.6.2108.39667
properties_campaignId:
properties_channelManifestId: VisualStudio.16.Preview/16.6.0-pre.4.0+30021.99
properties_nickname:
properties_setupEngineFilePath: C:\Program Files (x86)\Microsoft Visual Studio\Installer\vs_installershell.exe

build ponyc

.\make.ps1 libs
.\make.ps1 configure
.\make.ps1 build
.\make.ps1 test
.\make.ps1 install

build info:

-*- mode: compilation; default-directory: "~/workspace/projects/pony/pony-shoe/" -*-
Compilation started at Sun Apr 26 19:07:32

ponyc
Building builtin -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\builtin
Building . -> d:\msys64\home\damon\workspace\projects\pony\pony-shoe
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 collections -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\collections
Building random -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\random
Building debug -> D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\packages\debug
Generating
 Reachability
 Selector painting
 Data prototypes
 Data types
 Function prototypes
 Functions
 Descriptors
Optimising
Writing .\pony-shoe.obj
Stack dump:
0.  Running pass 'Function Pass Manager' on module 'pony-shoe'.
1.  Running pass 'Machine InstCombiner' on function '@151'
 #0 0x00007ff62878cceb pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x3dcceb)
 #1 0x00007ff62878ecd1 pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x3decd1)
 #2 0x00007ff62878b693 pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x3db693)
 #3 0x00007ff62878d83e pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x3dd83e)
 #4 0x00007ff6286a410f pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x2f410f)
 #5 0x00007ff6286a565f pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x2f565f)
 #6 0x00007ff62877dd53 pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x3cdd53)
 #7 0x00007ff6285591d6 pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x1a91d6)
 #8 0x00007ff628559453 pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x1a9453)
 #9 0x00007ff6285596a7 pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x1a96a7)
#10 0x00007ff628558a60 pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x1a8a60)
#11 0x00007ff628e136af pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0xa636af)
#12 0x00007ff628e13de9 pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0xa63de9)
#13 0x00007ff6284959b3 (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0xe59b3)
#14 0x00007ff628478a1a (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0xc8a1a)
#15 0x00007ff628438c1a (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x88c1a)
#16 0x00007ff6283ec545 (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x3c545)
#17 0x00007ff6283ec6d2 (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0x3c6d2)
#18 0x00007ff62905deb4 pony_asio_event_set_writeable (D:\msys64\home\damon\.ome_local\repo\ponyc-git\build\install\bin\ponyc.exe+0xcadeb4)
#19 0x00007ffe9e167bd4 (C:\Windows\System32\KERNEL32.DLL+0x17bd4)
#20 0x00007ffe9e68ce51 (C:\Windows\SYSTEM32\ntdll.dll+0x6ce51)

Compilation exited abnormally with code 5 at Sun Apr 26 19:07:34

test case

https://playground.ponylang.io/?gist=8db97641fa8d34cc693941bef9555576

zulip:

https://ponylang.zulipchat.com/#narrow/stream/189985-beginner-help/topic/ponyc.20stack.20dump/near/195329702

SeanTAllen commented 4 years ago

I'm going to try to reproduce on Ubuntu without the change to pool.c.

It would be helpful if someone can try reproducing in a Windows environment that doesn't require the change to pool.c. The pool.c changes should be unrelated, but fewer variables is always better.

damon-kwok commented 4 years ago

yes, dont't need change poo.c for linux

SeanTAllen commented 4 years ago

Test case inline (in case the playground disappears) is:

use "random"
use "collections"

actor Main
  let _env: Env

  new create(env: Env) =>
    _env = env
    test_join(env)

  fun test_join(env: Env) =>
    var arr: Array[String] = ["111"; "222"; "333"]
    let str = Seqs[Array[String], String].join(arr, "")
    env.out.print(str)
    Seqs[Array[String], String].trace(arr, env)

primitive Seqs[A: Seq[B] ref = Array[USize],
  B: Comparable[B] #read = USize] is Sequence[A, B]

trait Sequence[A: Seq[B] ref, B: Comparable[B] #read ]

  fun join(a: A, joiner: String = "", f_str: ({(B): String} | None) = None): String =>
    """
    Joins the given sequence into a binary using joiner as a separator.

    ````pony
    Seqs.join([1; 2; 3])
    "123"

    Seqs.join([1; 2; 3], " = ")
    "1 = 2 = 3"
See also: `map_join`
````pony
Seqs.map_join([1; 2; 3], "", {(x: U32): U32 => x * 2})
"246"

Seqs.map_join([1; 2; 3], " = ", {(x: U32): U32 => x * 2})
"2 = 4 = 6"
````
"""
var s: String = ""
var i: USize = 0
for e in a.values() do
  if f_str is None then
    s = s + try (e as Stringable).string() else "*" end
  else
    s = s + try (f_str as {(B): String val})(e) else "*" end
  end
  if i < (a.size() - 1) then s = s.add(joiner) end
  i = i + 1
end
s

fun typeof(a: A): SeqType => """ Return sequence type enum value. """ iftype A <: List[B] then return ListType end iftype A <: Array[B] then return ArrayType end iftype A <: String then return StringType end UnknowType

fun trace(a: A, env: Env, f: ({(B): String} | None) = None) => """ Print sequence debug info. """ env.out.print("11111") let t = typeof(a) env.out.print("22222") var out = "[Trace] " var joiner = "," match t | ListType => joiner = "," out = out + "List => size:"+a.size().string() + " {" | ArrayType => joiner = ";" out = out + "Array => size:"+a.size().string() + " [" | StringType => joiner = "" out = out + "String => size:"+a.size().string() + " \"" | UnknowType => out = out + "<Unknow type!> $ size:"+a.size().string() end out = out + join(a, joiner, f) env.out.print("22222") match t | ListType => out = out + "}" | ArrayType => out = out + "]" | StringType => out = out +"\"" end env.out.print("3333") //Debug.out(out) env.out.print(out)

interface Cloneable[A: Seq[B] ref, B: Comparable[B] #read] fun clone(): A^

primitive ArrayType primitive ListType primitive StringType primitive UnknowType type SeqType is (ArrayType | ListType | StringType | UnknowType)



if someone can reduce this quite a bit to a more minimal example, that would be great.
SeanTAllen commented 4 years ago

I am able to reproduce on Ubuntu 18.04.

3528>  ~/code/ponylang/ponyc/build/release/ponyc
Building builtin -> /home/sean/code/ponylang/ponyc/packages/builtin
Building . -> /home/sean/pony-scratch/3528
Building random -> /home/sean/code/ponylang/ponyc/packages/random
Building ponytest -> /home/sean/code/ponylang/ponyc/packages/ponytest
Building time -> /home/sean/code/ponylang/ponyc/packages/time
Building collections -> /home/sean/code/ponylang/ponyc/packages/collections
Generating
 Reachability
 Selector painting
 Data prototypes
 Data types
 Function prototypes
 Functions
 Descriptors
Optimising
Writing ./3528.o
Stack dump:
0.      Running pass 'Function Pass Manager' on module '3528'.
1.      Running pass 'Machine InstCombiner' on function '@147'
fish: '~/code/ponylang/ponyc/build/rel…' terminated by signal SIGSEGV (Address boundary error)
SeanTAllen commented 4 years ago

It does build with optimizations off (as expected)

3528>  ~/code/ponylang/ponyc/build/release/ponyc --debug
Building builtin -> /home/sean/code/ponylang/ponyc/packages/builtin
Building . -> /home/sean/pony-scratch/3528
Building random -> /home/sean/code/ponylang/ponyc/packages/random
Building ponytest -> /home/sean/code/ponylang/ponyc/packages/ponytest
Building time -> /home/sean/code/ponylang/ponyc/packages/time
Building collections -> /home/sean/code/ponylang/ponyc/packages/collections
Generating
 Reachability
 Selector painting
 Data prototypes
 Data types
 Function prototypes
 Functions
 Descriptors
Writing ./3528.o
Linking ./3528
SeanTAllen commented 4 years ago

@damon-kwok if you can create a smaller minimal example, that would be very helpful.

damon-kwok commented 4 years ago

I am able to reproduce on manjaro 19.0.2

damon-kwok commented 4 years ago

@SeanTAllen minimal example: https://playground.ponylang.io/?gist=088deb24c703163e5befaa0d876926dc Now if you delete any line, the crash cannot be reproduced

EpicEric commented 4 years ago

Minimal reproduction:

actor Main
  new create(env: Env) =>
    Foo[Array[String], String](["111"])

primitive Foo[A: Seq[B] ref, B: Comparable[B] #read]
  fun apply(a: A) =>
    iftype A <: Array[B] then
      return None
    end
    None
damon-kwok commented 4 years ago

@EpicEric no, your code is works. not crash.

mfelsche commented 4 years ago

I was able to make the example from compile here https://github.com/ponylang/ponyc/issues/3528#issuecomment-619566893 by using elseif with iftype https://playground.ponylang.io/?gist=da18b57d948144a4ab4dedfe25db9e9a

This is not solving this bug, but might present workaround for the time being. I do remember some limitations on iftype, i.e. that it is not safe to use it as basically the whole method body, but @jemc is the most knowledgable person to talk to here.

damon-kwok commented 4 years ago

@mfelsche It may be that multiple iftypes in a row cause some problems in the generated code. This problem seems to have some randomness, if you comment some insignificant code, it can also be successfully compiled.iftype is an enemy worth watching