Open damon-kwok opened 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.
yes, dont't need change poo.c
for linux
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.
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)
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
@damon-kwok if you can create a smaller minimal example, that would be very helpful.
I am able to reproduce on manjaro 19.0.2
@SeanTAllen minimal example: https://playground.ponylang.io/?gist=088deb24c703163e5befaa0d876926dc Now if you delete any line, the crash cannot be reproduced
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
@EpicEric no, your code is works. not crash.
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.
@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
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;$cmakePath = $(Get-Item $( Invoke-Expression '& "$vswhere" -prerelease -latest -requires Microsoft.VisualStudio.Component.VC.CMake.Project -find Common7/IDE/**/cmake.exe ' )).Directory.FullName
build ponyc
build info:
test case
https://playground.ponylang.io/?gist=8db97641fa8d34cc693941bef9555576
zulip:
https://ponylang.zulipchat.com/#narrow/stream/189985-beginner-help/topic/ponyc.20stack.20dump/near/195329702