Skip to content

SY-3680: Fix Issues with Arc Channel Analysis#1940

Merged
emilbon99 merged 4 commits into
sy-3673-synnax-505from
sy-3680-cannot-use-an-arc-function-twice
Feb 5, 2026
Merged

SY-3680: Fix Issues with Arc Channel Analysis#1940
emilbon99 merged 4 commits into
sy-3673-synnax-505from
sy-3680-cannot-use-an-arc-function-twice

Conversation

@emilbon99

@emilbon99 emilbon99 commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Issue Pull Request

Linear Issue

Fixes:

SY-3680
SY-3679

Description

Basic Readiness

  • I have performed a self-review of my code.
  • I have added relevant, automated tests to cover the changes.
  • I have updated documentation to reflect the changes.

Greptile Overview

Greptile Summary

Fixed two critical Arc language bugs and one C++ error handling bug:

Core Fixes:

  • SY-3679: Fixed stateful variables initialized from channels to store values instead of channel references by unwrapping channel types in analyzeStatefulVariable
  • SY-3680: Fixed function reusability with channel configs by deep copying Channels when creating nodes, preventing shared state between multiple function invocations
  • Out-of-bounds read: Fixed xerrors::Error::matches() to provide end iterator for both ranges, preventing undefined behavior when pattern is longer than error type
  • Index out-of-bounds: Fixed ReadChannelValue() to check for empty MultiSeries before accessing last element

Test Coverage:
All fixes include comprehensive test coverage with regression tests, integration tests, and edge case validation.

UI Improvements:
Enhanced Arc editor UX by enabling scrollBeyondLastLine, repositioning controls to full width with gradient overlay, and removing problematic platform-specific font override.

Confidence Score: 5/5

  • This PR is safe to merge with no identified issues
  • All changes address specific bugs with proper fixes, include comprehensive test coverage, and follow established patterns in the codebase
  • No files require special attention

Important Files Changed

Filename Overview
arc/go/analyzer/statement/statement.go Added type unwrapping for stateful variables initialized from channels to store values instead of channel references
arc/go/runtime/state/state.go Fixed index out-of-bounds bug by checking for empty MultiSeries and using len() instead of Len() method
arc/go/text/analyze.go Fixed channel aliasing bug by deep copying Channels when creating function nodes to prevent shared state
x/cpp/xerrors/errors.h Fixed out-of-bounds read in matches() by providing end iterator to std::mismatch for both ranges

Sequence Diagram

sequenceDiagram
    participant User as Arc Program
    participant Analyzer as Statement Analyzer
    participant TextAnalyzer as Text Analyzer
    participant State as Runtime State
    participant WASM as WASM Runtime
    
    Note over User,WASM: Issue 1: Channel values in stateful vars
    User->>Analyzer: counter $= counter_ch
    Analyzer->>Analyzer: Check if varType is Chan
    Analyzer->>Analyzer: Unwrap() to get value type
    Analyzer->>User: Store value type (f32), not channel
    
    Note over User,WASM: Issue 2: Reusing functions with channel config
    User->>TextAnalyzer: increment{counter=counter_1}
    TextAnalyzer->>TextAnalyzer: sym.Channels.Copy()
    TextAnalyzer->>TextAnalyzer: slices.Clone(config)
    TextAnalyzer->>User: Create node with independent channels
    User->>TextAnalyzer: increment{counter=counter_2}
    TextAnalyzer->>TextAnalyzer: sym.Channels.Copy()
    TextAnalyzer->>User: Create separate node with own channels
    
    Note over User,WASM: Runtime: Reading channel values
    WASM->>State: ReadChannelValue(key)
    State->>State: Check if key exists
    State->>State: Check if len(ms.Series) > 0
    State->>State: Return ms.Series[len(ms.Series)-1]
    State->>WASM: Return last series safely
    
    Note over User,WASM: C++ Error Matching Fix
    User->>State: error.matches("long.pattern")
    State->>State: std::mismatch with both end iterators
    State->>User: Return false (no out-of-bounds)
Loading

@emilbon99 emilbon99 changed the base branch from main to sy-3673-synnax-505 February 5, 2026 01:38
@emilbon99 emilbon99 requested a review from sy-nico February 5, 2026 01:39

@greptile-apps greptile-apps Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

4 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@sy-nico

sy-nico commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

Can now use a function multiple times.
image

However, when attempting to initialize a variable with a channel value, there is no output on the counters
image

@sy-nico sy-nico left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Chatted offline and left screenshots

@emilbon99 emilbon99 merged commit 29e7531 into sy-3673-synnax-505 Feb 5, 2026
15 of 16 checks passed
@emilbon99 emilbon99 deleted the sy-3680-cannot-use-an-arc-function-twice branch February 5, 2026 04:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants