Skip to content

[Loom] Preserve C++ increment values and conditional mutations - #687

Merged
benvanik merged 1 commit into
mainfrom
users/benvanik/cxx-increment-values
Sep 19, 2026
Merged

benvanik merged 1 commit into
mainfrom
users/benvanik/cxx-increment-values

Conversation

@benvanik

Copy link
Copy Markdown
Collaborator

C/C++ prefix and postfix ++/-- can now produce values from integer and pointer bindings. This admits ordinary pointer streams and conditional counters that previously failed import:

void copy(const unsigned* input, unsigned* output, unsigned count) {
  unsigned index = 0;
  while (index++ < count) {
    *output++ = *input++;
  }
}

unsigned visit(unsigned value, unsigned limit) {
  unsigned visits = 0;
  bool accepted = value < limit && visits++ == 0u;
  return visits + (unsigned)accepted;
}

Postfix expressions return the captured previous value; prefix expressions return the updated value. Updates use the existing promoted integer arithmetic and narrowing rules or provenance-preserving pointer displacement. Discarded increments use the same implementation.

&&, ||, and ?: now join modified source bindings alongside their expression results. Each arm starts with the state established by its condition, and skipped operands neither update bindings nor perform loads. The existing control analysis retains expression mutation facts in its single source traversal; translation consumes those facts and snapshots only changed bindings. Skipped logical operands publish their known boolean result directly.

The standalone corpus adds exact byte/64-bit wrap, signed decrement, nested lazy expressions, condition mutations, loop updates, and guarded pointer streams. It checks 532 scalar VM cases and 17 GPU inputs both normally and with device access sanitization, including complete outputs, unchanged inputs, and guard values. The existing attention, RMSNorm, and SwiGLU examples retain byte-identical HSACO.

The admitted destinations remain owned automatic integer and pointer bindings. Memory-element, vector, floating-point, const, and volatile updates retain source diagnostics; this change does not introduce an implicit storage model for them.

Use one source update path for discarded and value-producing integer and
pointer increments. Capture the old value for postfix expressions and
return the narrowed or displaced value for prefix expressions while
retaining pointer allocation identity.

Retain conditional-expression mutation summaries in the existing source
control analysis and join updated bindings with expression results. Each
arm starts from the condition's resulting state, skipped operands
publish their known boolean value, and translation snapshots only the
bindings the expression can change.
@benvanik
benvanik marked this pull request as ready for review September 19, 2026 22:50
@benvanik
benvanik requested a review from a team as a code owner September 19, 2026 22:50
@benvanik
benvanik merged commit 8ba368e into main Sep 19, 2026
44 of 46 checks passed
@benvanik
benvanik deleted the users/benvanik/cxx-increment-values branch September 19, 2026 23:12
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