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 runtime erroneously copies flags from existing block #17482

Open
dlangBugzillaToGithub opened this issue Jun 18, 2024 · 1 comment
Open
Labels

Comments

@dlangBugzillaToGithub
Copy link

Steven Schveighoffer (@schveiguy) reported this on 2024-06-18T11:56:09Z

Transferred from https://issues.dlang.org/show_bug.cgi?id=24617

Description

If an array slice starts from a GC allocated block that is *not* marked appendable, the appendable flag never gets set until appending occurs.

example:

```d
struct S
{
    int[1] val;
}
void main()
{
    auto s = new S;
    int[] arr = s.val[];
    assert(arr.capacity == 0); // starts out without appendability
    arr.length = 2;
    assert(arr.capacity > 0); // this fails
    arr.reserve(100);
    assert(arr.capacity > 0); // this fails
    arr ~= 10;
    assert(arr.capacity > 0); // finally, this succeeds
}
```

The issue is that the `__arrayAlloc` function copies the original bits instead of using the typeinfo to decide the new array bits if a BlkInfo has already been looked up. I guess the thought is that using the TypeInfo to build the bits is more expensive, and we "already have something".

Options are to just always use the typeinfo, or to check for the appendable bit before using the old bits (but copying the other bits might be questionable as well).
@dlangBugzillaToGithub
Copy link
Author

dlang-bot commented on 2024-06-19T17:03:11Z

@ntrel created dlang/dmd pull request #16599 "Fix Bugzilla 24617 - array runtime erroneously copies flags from exis…" fixing this issue:

- Fix Bugzilla 24617 - array runtime erroneously copies flags from existing block

https://github.com/dlang/dmd/pull/16599

@thewilsonator thewilsonator added the Druntime Specific to druntime label Dec 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants