Skip to content

Conversation

@KKiiim
Copy link
Member

@KKiiim KKiiim commented Oct 2, 2025

AssemblyScript/assemblyscript#2948

Summary by CodeRabbit

  • Bug Fixes

    • Ensures non-parameter fields in constructors are consistently initialized, including zero values, improving reliability for unmanaged classes.
    • Restricts zero-initialization optimization to a specific runtime to prevent unintended omission of field initialization.
  • Tests

    • Updated tests to verify that unmanaged objects correctly initialize fields via setters, including zero values.

@KKiiim
Copy link
Member Author

KKiiim commented Oct 4, 2025

@HerrCai0907 Can't request reviewers

Copy link
Contributor

@HerrCai0907 HerrCai0907 left a comment

Choose a reason for hiding this comment

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

LGTM. please add test case for this cases,

@HerrCai0907
Copy link
Contributor

@coderabbitai summary

@coderabbitai
Copy link

coderabbitai bot commented Oct 9, 2025

✅ Actions performed

Summary regeneration triggered.

@coderabbitai
Copy link

coderabbitai bot commented Oct 9, 2025

Walkthrough

Adjusted compiler’s constructor field initialization logic: zero-initialization optimization now applies only under Runtime.Incremental. Unified handling of non-parameter field initializers using a computed valueExpr and a single setter call path, with special handling for unmanaged classes. Updated WAT test to reflect explicit setter calls for unmanaged objects.

Changes

Cohort / File(s) Summary
Compiler constructor init and zero-init optimization
assemblyscript/src/compiler.ts
Restricted canOptimizeZeroInitialization to Runtime.Incremental. Refactored constructor non-parameter field initialization to compute valueExpr (initializer or zero), initialize when class is unmanaged or zero-opt not applicable, and always call setter with valueExpr, appending resulting expression to statements.
Test updates for unmanaged constructor behavior
tests/frontend/compiler/object-literal.wat
Updated expected WAT: Unmanaged constructor now calls Unmanaged#set:bar(0) and Unmanaged#set:baz(0) following allocation before return.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor Caller
  participant Ctor as Unmanaged#constructor
  participant Heap as Runtime/Allocator
  participant SetBar as Unmanaged#set:bar
  participant SetBaz as Unmanaged#set:baz

  Caller->>Ctor: new Unmanaged(...)
  Ctor->>Heap: allocate instance (if needed)
  Note over Ctor: Unified init: valueExpr = initializer or zero

  alt Class is unmanaged
    Ctor->>SetBar: set(0)
    SetBar-->>Ctor: ok
    Ctor->>SetBaz: set(0)
    SetBaz-->>Ctor: ok
  else Class is managed
    alt Runtime.Incremental AND init is const zero
      Note over Ctor: Skip zero-initialization (optimized)
    else
      Ctor->>SetBar: set(valueExpr as needed)
      Ctor->>SetBaz: set(valueExpr as needed)
    end
  end

  Ctor-->>Caller: instance
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes


📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 120d530 and 2808e5f.

📒 Files selected for processing (2)
  • assemblyscript/src/compiler.ts (3 hunks)
  • tests/frontend/compiler/object-literal.wat (1 hunks)

Comment @coderabbitai help to get the list of available commands and usage tips.

@HerrCai0907 HerrCai0907 merged commit fd0f3aa into wasm-ecosystem:main Oct 11, 2025
5 checks passed
@HerrCai0907 HerrCai0907 linked an issue Oct 11, 2025 that may be closed by this pull request
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.

the member zero init is missed for unmanaged class

2 participants