Skip to content

Conversation

@omarsy
Copy link
Member

@omarsy omarsy commented Feb 8, 2026

  • Make append overlap-safe for list-backed slices by using directional copy (backward when dst starts after src).
  • Make copy overlap-safe for slice-to-slice by using directional copy when src/dst share the same backing array.

@github-actions github-actions bot added the 📦 🤖 gnovm Issues or PRs gnovm related label Feb 8, 2026
@Gno2D2 Gno2D2 added the review/triage-pending PRs opened by external contributors that are waiting for the 1st review label Feb 8, 2026
@Gno2D2
Copy link
Collaborator

Gno2D2 commented Feb 8, 2026

🛠 PR Checks Summary

🔴 Pending initial approval by a review team member, or review from tech-staff

Manual Checks (for Reviewers):
  • IGNORE the bot requirements for this PR (force green CI check)
Read More

🤖 This bot helps streamline PR reviews by verifying automated checks and providing guidance for contributors and reviewers.

✅ Automated Checks (for Contributors):

🟢 Maintainers must be able to edit this pull request (more info)
🔴 Pending initial approval by a review team member, or review from tech-staff

☑️ Contributor Actions:
  1. Fix any issues flagged by automated checks.
  2. Follow the Contributor Checklist to ensure your PR is ready for review.
    • Add new tests, or document why they are unnecessary.
    • Provide clear examples/screenshots, if necessary.
    • Update documentation, if required.
    • Ensure no breaking changes, or include BREAKING CHANGE notes.
    • Link related issues/PRs, where applicable.
☑️ Reviewer Actions:
  1. Complete manual checks for the PR, including the guidelines and additional checks if applicable.
📚 Resources:
Debug
Automated Checks
Maintainers must be able to edit this pull request (more info)

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 The pull request was created from a fork (head branch repo: omarsy/gno)

Then

🟢 Requirement satisfied
└── 🟢 Maintainer can modify this pull request

Pending initial approval by a review team member, or review from tech-staff

If

🟢 Condition met
└── 🟢 And
    ├── 🟢 The base branch matches this pattern: ^master$
    └── 🟢 Not (🔴 Pull request author is a member of the team: tech-staff)

Then

🔴 Requirement not satisfied
└── 🔴 If
    ├── 🔴 Condition
    │   └── 🔴 Or
    │       ├── 🔴 At least one of these user(s) reviewed the pull request: [jefft0 notJoon omarsy MikaelVallenet] (with state "APPROVED")
    │       ├── 🔴 At least 1 user(s) of the team tech-staff reviewed pull request
    │       └── 🔴 This pull request is a draft
    └── 🔴 Else
        └── 🔴 And
            ├── 🟢 This label is applied to pull request: review/triage-pending
            └── 🔴 On no pull request

Manual Checks
**IGNORE** the bot requirements for this PR (force green CI check)

If

🟢 Condition met
└── 🟢 On every pull request

Can be checked by

  • Any user with comment edit permission

@codecov
Copy link

codecov bot commented Feb 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Copy link
Member

@Davphla Davphla left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix works great, all comments are refacto / nitpick

for i := arg1Length - 1; i >= 0; i-- {
oldElem := list[dstStart+i]
// unrefCopy will resolve references and copy their values
// to copy by value rather than by reference.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment can be simplified

srcEnd := arg1Offset + arg1Length
overlap := arg0Base == arg1Base && dstStart < srcEnd && srcStart < dstEnd
// Overlap-safe copy: copy backward when dst starts after src to avoid clobbering.
if overlap && dstStart > srcStart {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This double duplicate loop can be simplified either by doing a sub helper function, or something like that:

step := 1
start := 0
if overlap && dstStart > srcStart {
    step = -1
    start = arg1Length - 1
}
for i := start; i >= 0 && i < arg1Length; i += step {
    oldElem := list[dstStart+i]
    newElem := arg1Base.List[arg1Offset+i].unrefCopy(m.Alloc, m.Store)
    list[dstStart+i] = newElem
    m.Realm.DidUpdate(
        arg0Base,
        oldElem.GetFirstObject(m.Store),
        newElem.GetFirstObject(m.Store),
    )
}

I think it would be much easier to read

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice suggestion ^^

srcEnd := srcStart + minl
overlap := dstBase == srcBase && dstStart < srcEnd && srcStart < dstEnd
// Overlap-safe copy: copy backward when dst starts after src to avoid clobbering.
if overlap && dstStart > srcStart {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for this one

s4 := []byte{0, 1, 2, 3, 4}
r4 := append(s4[:1], s4[2:4]...)
fmt.Println("append overlap bytes:", r4) // [0 2 3]
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's missing the case where it append to itself (fixed by that PR)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYM, Can you give me an example ?

Copy link
Member

@Davphla Davphla Feb 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example:

r4 := append(s4[:1], s4...)

It's not essential to add tbh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📦 🤖 gnovm Issues or PRs gnovm related review/triage-pending PRs opened by external contributors that are waiting for the 1st review

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

3 participants