Skip to content

fix: fixed augmented assignment 🦾 - #192

Open
timfennis wants to merge 5 commits into
masterfrom
fix/augmented-assignment
Open

fix: fixed augmented assignment 🦾#192
timfennis wants to merge 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".

.scope_tree
.resolve_call(operation, &arg_types, CallKind::Operator);
let has_op_binding = !matches!(op_binding, Binding::None);
let assign_is_eligible = Self::augmented_rhs_is_compatible(&left_type, &right_type);

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 Allow type-preserving map removal assignments

Do not use a blanket rhs <: lhs test for every specialized assignment operator. Map -= only removes keys from the left map, so a valid expression such as let values = %{1: 10}; values -= %{1: "marker"}; cannot change the left map's Map<Int, Int> type, yet Map<Int, String> fails this compatibility check and the branch below emits a mismatched-types error. Map &= has the same issue because it only retains existing left-side entries; eligibility needs to account for the selected operator's actual mutation contract rather than requiring the entire RHS map type to be a subtype.

Useful? React with 👍 / 👎.

@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 on lines +760 to +763
if let Expression::Identifier {
resolved: Binding::Resolved(Candidate::Scalar(target)),
..
} = &value.expression

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 Widen inferred containers through nested index targets

When an indexed write targets another index expression, this direct-identifier check prevents widening the stable root binding. For example, let values = [[1]]; values[0][0] = "two"; now emits a mismatched-types error even though values is inferred and the assignment can validly widen it to List<List<Any>>; the same regression affects nested augmented assignments whose result changes type. Trace nested index targets back to their resolved root identifier and widen each affected container layer instead of treating every non-identifier container as non-widenable.

Useful? React with 👍 / 👎.

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