Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array size self mutation or string concatenation issue #2308

Closed
codec-abc opened this issue Oct 27, 2017 · 3 comments
Closed

Array size self mutation or string concatenation issue #2308

codec-abc opened this issue Oct 27, 2017 · 3 comments
Assignees
Labels
triggers release Major issue that when fixed, results in an "emergency" release

Comments

@codec-abc
Copy link
Contributor

In the following code we create an array of 56 bytes and never add or delete element. Then, we call a behavior that will print the array size and call itself again. The first calls print the correct size (56) but at some point in time, it starts to print other (wrong) values. After a few iterations I got the following output:

in behavior - array size is 47 in behavior
in behavior - array size is 8241904171254706025

I tested it on Windows with the version 0.19.3-6a0dd3a [release] and compiled it with ponyc -d

use "collections"
use "debug"

struct ArrayWrapper
  var array : Array[U8]
  new create() =>
        array = Array[U8]()
        for i in Range(0, 56) do
            array.push(0)
        end
        Debug.out("constructor - array size is " + array.size().string())
  

actor Main
  var array_wrapper : ArrayWrapper
  
  new create(env: Env) =>
    array_wrapper = ArrayWrapper
    Debug.out("after assignment - array size is " + array_wrapper.array.size().string())
    a_call()
    
  be a_call() =>
    Debug.out("in behavior - array size is " + array_wrapper.array.size().string())
    a_call()

Since I reported it on the IRC channel first, @Praetonus has managed to reproduce it and started to investigate it and thinks it is a bug in the string concatenation.

@codec-abc codec-abc changed the title Array mutate itself or string concatenation issue Array size self mutation or string concatenation issue Oct 27, 2017
@Praetonus Praetonus added bug: 1 - needs investigation triggers release Major issue that when fixed, results in an "emergency" release labels Oct 27, 2017
@codec-abc
Copy link
Contributor Author

codec-abc commented Nov 16, 2017

I ran more tests on it on found that the bug is only triggered because using a struct. If using a class instead the bug is never triggered.

@jemc
Copy link
Member

jemc commented Dec 13, 2017

@Praetonus - if you're not actively working on this, can you dump what you learned in your investigation so far, and then unassign yourself here, so that someone else might be able to pick it up?

@Praetonus
Copy link
Member

This is a GC issue with structs where trace functions aren't getting generated, which in this case causes a premature collection of the inner array. This should be an easy fix.

Praetonus pushed a commit to Praetonus/ponyc that referenced this issue Dec 15, 2017
Previously, tracing functions weren't being generated for structs,
which caused their fields to never be traced, resulting in various bugs
including premature GC collection.

Closes ponylang#2308.
Praetonus pushed a commit that referenced this issue Dec 15, 2017
Previously, tracing functions weren't being generated for structs,
which caused their fields to never be traced, resulting in various bugs
including premature GC collection.

Closes #2308.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triggers release Major issue that when fixed, results in an "emergency" release
Projects
None yet
Development

No branches or pull requests

4 participants