Skip to content

fix: fixed augmented assignment 🦾 - #192

Merged
timfennis merged 5 commits into
masterfrom
fix/augmented-assignment
Aug 23, 2026
Merged

fix: fixed augmented assignment 🦾#192
timfennis merged 5 commits into
masterfrom
fix/augmented-assignment

Conversation

@timfennis

@timfennis timfennis commented Aug 19, 2026

Copy link
Copy Markdown
Owner

The current augmented assignment implementation is messy and incomplete. While implementing augmented assignment for struct fields multiple problems were discovered. This PR attempts to fix these issues by having the analyzer plan the augmented assignment during analysis and generalizing the compilation of augmented assignment to also be applicable to situations like the one below:

let ll = [[1]];
ll[0] ++= [2,3];

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f7000d86d6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ndc_vm/src/compiler.rs Outdated
@timfennis timfennis changed the title Fix/augmented assignment 🦾 fixed augmented assignment Aug 19, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 376f4a1baf

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ndc_vm/src/compiler.rs Outdated
Comment thread ndc_analyser/src/analyser.rs Outdated

Copy link
Copy Markdown
Owner Author

Follow-up: move temporary-slot allocation metadata into the analyser

The current source_local_count solution correctly keeps compiler-generated temporaries above analyser-assigned source locals, but it requires the compiler to recursively rediscover the highest local slot by walking every AST variant.

Longer term, the analyser should record the source-local count for the top-level frame and for each function. The compiler can then initialize num_locals from that value and allocate all hidden temporaries after it. This would:

  • remove source_local_count and the max_source_local_* traversal;
  • avoid updating compiler bookkeeping whenever a new expression variant is added;
  • keep slot ownership in the component that actually assigns source slots;
  • give indexed augmented assignment, comprehensions, and future compiler temporaries one safe allocation path.

The REPL/resume path will need the top-level high-water mark to remain monotonic across analysis batches, while nested functions need their own independent count.

This is not blocking for this PR. The current scan is functionally correct, but this would be a worthwhile follow-up refactor.

@timfennis
timfennis force-pushed the fix/augmented-assignment branch from 376f4a1 to 6e296ed Compare August 19, 2026 20:32

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 6e296ed10d

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ndc_analyser/src/analyser.rs Outdated
Comment thread tests/compiler/tests/compiler.rs
@timfennis timfennis changed the title 🦾 fixed augmented assignment fix: fixed augmented assignment 🦾 Aug 20, 2026

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 57789c58a0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ndc_analyser/src/analyser.rs

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1c2d6efba9

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread ndc_analyser/src/analyser.rs
Comment on lines +53 to +56
pub enum AugmentedAssignmentPlan {
Unresolved,
Resolved(Binding),
}

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Isn't this just Option<Binding> with extra steps? There is precedent for using Option<Binding>? correct?

@timfennis
timfennis force-pushed the fix/augmented-assignment branch from 1c2d6ef to 3da4d2e Compare August 23, 2026 16:07

@chatgpt-codex-connector chatgpt-codex-connector 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3da4d2ea27

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

}

let compiled = match Compiler::compile(expressions.into_iter()) {
let compiled = match Compiler::compile(expressions.into_iter(), Default::default()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Pass analysed local counts into the panic pipeline

For any generated valid program containing a function declaration, this empty metadata makes compile_function_decl return missing source-local count; the immediately following Err(_) => return then silently skips both nested-function compilation and VM execution. Take the analyser result and pass its source_local_counts here so the property test continues exercising function-containing programs.

Useful? React with 👍 / 👎.

@timfennis
timfennis merged commit 1a091ee into master Aug 23, 2026
1 check passed
@timfennis
timfennis deleted the fix/augmented-assignment branch August 23, 2026 16:15
timfennis added a commit that referenced this pull request Aug 23, 2026
Follow-ups from the review of #192, stacked on #193. The review's bigger
findings (fuzzer metadata wiring) were made obsolete by the temp-layout
refactor in #193; these are the pieces that survived.

## Changes

- **analyser**: named the `Binding::None` arms in the
augmented-assignment plan match (fixes the
`match_wildcard_for_single_variants` clippy warning introduced by #192)
and extracted the twice-duplicated "index type is an int-range slice"
check into `index_type_is_slice`.
- **compiler**: `compile_batch` now takes the expression iterator
directly instead of forcing every caller to `.collect()` into a `Vec`
first.
- **manual**: the augmented-assignment page only documented variable
targets; added sections for indexed/slice/string targets, the once-each
evaluation-order guarantee, and the type-checking rules (in-place
operators preserve the target type, fallback operators may widen). All
new examples are verified to run.

Remaining clippy warnings (`chunk.rs` `use_self`,
`only_used_in_recursion`, doc backticks) pre-date this stack on master
and are left for a separate cleanup.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant