[pull] master from GaijinEntertainment:master#1003
Merged
Conversation
Splice-mode planner now folds ten more terminator operators into fused
single-loop invokes via two new lanes:
Ring 1 (accumulator): sum, min, max, average, long_count
Ring 2 (early-exit): first, first_or_default, any, all, contains
LinqLane dispatch in plan_loop_or_count routes by terminator; per-lane
helpers (emit_counter_lane / emit_array_lane / emit_accumulator_lane /
emit_early_exit_lane) factor the emission. min/max use workhorse-branch
direct < / > on workhorse types and _::less on non-workhorse. any with
no predicate emits !empty(src) shortcut. long_count piggybacks on the
existing length() shortcut. All accumulator/early-exit paths preserve
linq.das empty-source semantics (sum→0, min/max→default<T>, average→NaN,
first→panic, first_or_default→d, any→false, all→true, contains→false).
Functional + AST shape coverage:
tests/linq/test_linq_fold.das — Ring 1 ~25 cases, all cross-
checked _fold == _old_fold
tests/linq/test_linq_fold_ast.das — 8 Ring 1 + 8 Ring 2 shape tests,
asserts workhorse-branch ops,
length/empty shortcuts, fall-
through on out-of-scope chains
tests/linq/test_linq_fold_ring2.das — Ring 2 functional tests; lives
in own file as workaround for
ICE 50609 ("multiple instances
of linq.all / linq.contains")
— see follow-up commit
Three new 4-way benchmarks at 100K rows
(long_count_aggregate, first_or_default_match, contains_match);
existing Ring 1/2 benchmark m3f columns move from m3-parity (~25-30 ns)
to single-digit ns/op with zero allocations.
LINQ.md updated with Phase 2B delta tables.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Phase 2B Ring 2 (commit 0851ea0) had to keep its tests in a separate file because both `linq.all` and `linq.contains` ICE with `error[50609]: multiple instances of <gen>` when a single module hits the same op from both a mut-element source (`each(arr)` → `iterator<T -&>`) and a const-element source (iterator comprehensions → `iterator<T const -&>`). Root cause: the generic-name mangler ignores inner element-constness, so two genuinely distinct instantiations hash to one symbol. Pointer-like variance fact (verified empirically; see tests/type_traits/test_iterator_variance.das): `iterator<T -&>` flows into `iterator<T const -&>`, not the reverse. So declaring the iterator overload as `iterator<auto(TT) const>` lets both source flavors converge on a single instantiation per op — the collision becomes impossible. Scope deliberately narrow: only `all` and `contains` are constified (the two known ICE triggers). A blanket sweep of all ~78 iterator overloads caused real cascading breakage — select_impl moves `it` via emplace (can't from const), select_many iterates `it` (needs mutable handle), multiple downstream AOT codegen issues with const struct default-init, and user-defined non-const operators (ComplexType.==). The full fix belongs in the C++ mangler (separate PR); this commit is the narrowest library-side defuse for the two demonstrably broken ops. Side effects: - tests/linq/_common.das: ComplexType `==` and `!=` made `def const` (was `def`); the const-element form of contains() iterates const values and needs a const-callable equality op. This is a legitimate operator-design improvement, not a workaround. - tests/linq/test_linq_fold_ring2.das (134 lines, Ring 2 functional tests) merged into tests/linq/test_linq_fold.das; the workaround file is no longer needed. All 133 fold tests pass. - tests/type_traits/test_iterator_variance.das: new 3-case language regression test pinning the variance rule (positive case, comprehension case, cross-flavor case — the same scenario that ICEs without the fix). - CLAUDE.md: two bullets under `### Iterators and `each`` documenting the variance fact and the mangler pitfall + library workaround. Verification: 695 INTERP + 695 AOT + 695 JIT tests in tests/linq pass. ICE no longer reproducible in the working tree. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Every emit lane in linq_fold.das had a pair of qmacro templates that
differed only in `typedecl($e(topExpr)) - const` vs plain
`typedecl($e(topExpr))` on the invoke block's `$src` parameter. The
strip-when-iter logic was identical across lanes; the duplication had
no real branching purpose beyond "I couldn't conditionally append the
modifier inside a single qmacro template."
New `invoke_src_param_type(top)` helper computes the param TypeDecl
once — clone top._type, strip outer `constant` flag when isIterator —
and the emit lanes splice it with `$t(srcParamType)` instead of
`typedecl($e(topExpr)) - const` / `typedecl($e(topExpr))`.
Collapsed:
- emit_counter_lane: 2 arms → 1
- emit_array_lane: 3 arms → 3 (still need 3 — the axes split on
`expr._type.isIterator` for the return path AND `sourceHasLength`
for the reserve hint; param type itself is now uniform)
- emit_accumulator_lane: 10 arms (5 ops × 2) → 5 (one per op)
- emit_early_exit_lane: 10 arms (5 ops × 2) → 5 (one per op)
Net -89 lines. Behavior unchanged: 133 fold tests, 66 AST shape tests,
695 INTERP, 695 AOT, 695 JIT all pass.
Boris flagged the duplication during the iterator-variance discussion
("why do we still have two versions?"); deferred while we landed the
ICE 50609 defuse, picked back up now.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Cognitive load pass on linq_fold.das. Net -66 lines (504 changed).
Patterns collapsed:
1. push/push_clone workhorse splits (2 sites in plan_loop_or_count array
lane) — use push_clone everywhere. For workhorse types clone == copy
(no allocation, same byte cost as push); for non-workhorse it deep-
clones, which is what we want anyway.
2. emit_length_shortcut: 2 op-arms (count vs long_count) collapse to one
via `$c(castName)(length(src))` where castName is "int" (identity for
int) or "int64". `$c` splices the function name at call position.
3. emit_accumulator_lane: 4 op-arms (long_count / sum / average / min-max)
collapse to one invoke template. Per-op variation is built into 3 lists
(preludeStmts, perMatchStmts, returnExpr); all flattened into a single
bodyStmts list spliced via $b. This shares scope under one wrapping
block — splitting decls / for / return into separate splice points
would put each in its own sub-block, hiding the accumulator (caught by
AST dump under `options log_infer_passes`).
4. emit_early_exit_lane: 5 op-arms (first / first_or_default / any / all
/ contains) collapse the same way — preludeStmts + perMatchStmts +
tailStmts → single bodyStmts → single $b.
5. Multi-stmt-per-op cases use `qmacro_block_to_array() { stmt1; stmt2 }`
to express the prelude/per-match as one literal block instead of N
separate `qmacro_expr() { stmt }` pushes. Roughly halves the line
count for ops with 2+ stmts (average, min/max).
New private helpers (all `[macro_function]`):
- prepend_binds(stmts, intermediateBinds) — shared chain-bind prefix.
- stmts_to_expr(stmts) — collapse N stmts to a single expression
(pass through when N==1, wrap in qmacro_block when N>1). Used by
every lane that builds a per-element block whose length is data-
dependent.
- wrap_with_condition(body, cond) — `if (cond) { body }` when cond
is non-null; pass-through otherwise. Replaces the if/else dance
every lane had for fusing the upstream `where_` predicate.
- min_max_compare(workhorse, opName, valName, accName) — emits the
perf-critical compare. Workhorse types use direct `<` / `>`
(single instruction); non-workhorse uses `_::less` with operand
flip for max. Replaces a 4-arm if/elif inline ladder.
Tests: 133 fold + 66 AST + 695 INTERP + 695 AOT + 695 JIT all pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Same pattern as the accumulator + early-exit lanes from prior commit. Three arms (isIter / sourceHasLength / else) become one invoke template with a per-axis stmt list: - var $i(accName) : array<T> (always) - reserve(length(src)) (only when sourceHasLength && !isIter) - for-loop (always) - return <- acc.to_sequence_move() (when isIter) - return <- acc (else) All stmts share scope under the single $b(bodyStmts) splice. Same shape applies across all four emit lanes in the file now. Tests: 133 fold + 66 AST + 695 INTERP + 695 AOT all pass. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…hase-2b-rings-1-2 linq_fold Phase 2B: aggregates + early-exit terminators (+ ICE 50609 defuse)
Recognizes `[where_*][select*][skip?][take?] |> terminator` chains and
emits bounded-loop counters spliced into the per-element work across
counter, accumulator, early-exit, and array lanes. Trailing take/skip
(no explicit aggregator) routes to ARRAY lane with implicit to_array.
New helpers (linq_fold.das):
- append_skip_take_prelude — emits `var skipRem = K` / `var taken = 0`
alongside the lane accumulator.
- wrap_with_skip_take — prepends take-limit break + skip-counter continue
+ take-counter increment to the per-match block. Take-increment placed
BEFORE the per-match body so early-exit terminators (return-from-block)
don't make it unreachable (LINT001).
- is_buffer_required_op — recognizes order_by/distinct/reverse/group_by/
zip/join/left_join/group_join by name; planner returns null with
per-op `// TODO Phase 2X: <FutureMode>` markers, leaving room for
future BufferTopN / BufferDistinct / MultiSourceZip / BufferedJoin /
BufferGroupBy / BufferReverse emit modes.
Planner extensions:
- ChainStage recognition state machine on (seenSelect, seenSkip, seenTake)
rejects reverse-order shapes (e.g. where-after-skip). At most one skip
and one take per chain in Phase 2C.
- Range-form `take(start..end)` / `skip(start..end)` (slice operator)
falls through — different semantics from int-form.
- Count-shaped length shortcut + any-empty shortcut both gate on
`noLimits` (skip/take truncate the length).
- classify_terminator: take/skip terminal → ARRAY lane (implicit to_array
after `to_array` strip via linqCalls `skip = true`).
- Array-lane reserve tightens to inline `min(N, length(src))` when take
is present (no math::min dep at the call site).
Tests:
- test_linq_fold.das: 28 new functional cases (4 lanes × {where, skip,
take, where.skip.take, edge cases like take(0), skip(huge)}). Covers
correctness against expected values; for accumulator long_count uses
`let r` (drops typename assertion since `let` adds const).
- test_linq_fold_ast.das: 5 new AST tests with count_break_continue
helper — assert splice form (one fused for-loop + break for take +
continue for skip) for counter/accumulator/array lanes, and
fall-through (no invoke wrapper) for order_by.take and distinct.
Benchmarks:
- New take_sum_aggregate.das (accumulator-lane take coverage) and
take_count_filtered.das (counter-lane take + where).
- skip_take, take_sum_aggregate, take_count_filtered all drop to 0
ns/op at 100K rows (bounded loop O(K+N) vs source O(100K)). take_count
unchanged (m3f_old already iterator-fused).
Lint cleanup (Boris's "lint clean even in generated code"):
- daslib/ast_match.das: rename `next_var`-emitted gensyms from `_qm_N`
to `qm_N` — used-downstream, the underscore prefix mis-signaled
unused and triggered LINT004 in every qmatch_function consumer.
- daslib/ast_match.das: switch 4 specific qmacro_expr emissions from
`var $i(...)` to `let $i(...)` (the gensyms aren't reassigned in
generated code; LINT003 was firing across consumers).
- daslib/linq.das: zip_impl (predicate variant) and chunk_impl gain
pre-loop reserve hints — both were emitting PERF006 from push_clone-
in-loop-without-reserve when instantiated from test code.
LINQ.md gains a Phase 2C Ring 3 section with deltas + emission-shape
sketch, the buffer-required marker arms inventory, and a "Planned:
fail-loudly contract" subsection documenting the future PR that will
upgrade silent fallback to `macro_error("_fold: cannot splice — ...")`
per Boris's sqlite_linq-style "splice or error" design directive.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Backtick is the established compiler-generated-name marker in daslib (linq_fold gensyms, etc.) and lint.das:152 already skips backtick-bearing names. Eliminates collision risk with any user identifier — `qm_5` is a valid user identifier; `qm\`5` is not. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…horse guard)
The planner rejected any chained `_select|_select|...` whose previous
projection had a non-workhorse type — the `prevWorkhorse=false → return null`
guard at the `select` arm in plan_loop_or_count. Stated reason: `<-` (move)
corrupts source for lvalue projections like `_._field`. The guard was a
Phase 2B placeholder.
Correctness observation: `:=` is safe on every type — byte copy on workhorse,
deep-clone on non-workhorse — so a single emission shape (`var $i(bind) := ...`)
covers both cases. The workhorse/non-workhorse branch in chained-bind emission
is removed; chained selects of any type now splice through one path.
Audit result — two workhorse-type branches remain in linq_fold.das, both
intentional:
1. fold_select_where (line ~392, `static_if (typeinfo is_workhorse(...))`)
— used exclusively by `_old_fold`'s frozen baseline path via g_foldSeq.
Changing it would alter the frozen baseline output and invalidate the
m3f_old benchmark column.
2. min_max_compare (line ~746) + caller (line ~933)
— perf-critical. Workhorse types use `<` / `>` directly
(single-instruction compare); non-workhorse falls back to `_::less`
so user/tuple comparator overloads still apply. Boris's design
directive 2026-05-16 mandates keeping this branch.
No further workhorse branches in the splice path.
New test: tests/linq/test_linq_fold.das::test_chained_non_workhorse_select
covers three chain shapes that previously fell through:
- int → ComplexType → int → sum
- where + int → ComplexType → int → sum (where-before-selects, canonical)
- workhorse → ComplexType → workhorse → max
LINQ.md gets a new Phase 2C Ring 4 section documenting the change + the
two-branch audit. Phase status table updated.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
When DAS_TOOLS_DISABLED=ON, the `daslang` target is never created
(SETUP_COMPILER_BINARY only runs in the gated `if (NOT ${DAS_TOOLS_DISABLED})`
block). Several unconditional references to it caused configure to fail with
`No target "daslang"`:
- `ADD_EXAMPLE_RUN` macro fed into `run_examples` which uses
`$<TARGET_FILE:daslang>` / `DEPENDS daslang`. Gate the macro itself so all
call sites (incl. dasPEG, dasStbImage, dasLLVM) are automatically safe and
`DAS_EXAMPLES_TO_RUN` stays empty.
- `examples/pathTracer/CMakeLists.txt` depends on `libDaScriptAot`, which is
only created when AOT examples are enabled. Move the include under
`if(NOT DAS_AOT_EXAMPLES_DISABLED)` (same guard already used for tests/aot).
- Documentation build (`das2rst.das` step) references `daslang`. Add
`AND NOT DAS_TOOLS_DISABLED` to the `if(DAS_BUILD_DOCUMENTATION)` guard so
tools-disabled + docs-on no longer fails configure.
Verified locally — both configures succeed:
cmake -B build_off -DDAS_TOOLS_DISABLED=ON -DDAS_AOT_EXAMPLES_DISABLED=ON
cmake -B build_on -DDAS_TOOLS_DISABLED=OFF
Closes #2686
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copilot review on PR #2697 (#2697 (comment)) caught a silent semantic divergence in the take-limit guard. Pre-fix: `if (takenCount == N) break` — for negative N, `takenCount` (which starts at 0 and only ever increments) never satisfies equality, so the spliced loop takes ALL elements. Reference iterator semantics in daslib/linq.das treat non-positive N as "take nothing": take_impl (line 858): `if (total <= 0) break` take_to_array (line 879): `if (total <= 0) break` Post-fix: `if (takenCount >= N) break`. Identical to `==` for positive N (since `takenCount` increments by 1 from 0), short-circuits on the first iteration for N <= 0. Skip is unaffected — the existing emission `if (skipRem > 0) { skipRem--; continue }` is structurally identical to `skip_impl` (linq.das:770-773) and naturally inert for non-positive K (condition false → all elements pass through → skip nothing). Added 4 pinning tests covering take(-1), take(0), skip(-1), skip(0) so the non-positive semantics are documented and the regression can't slip back in. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Previous fix silently skipped the docs block when tools were disabled. DAS_BUILD_DOCUMENTATION is an explicit opt-in, so failing early matches the existing DAS_AOT_EXAMPLES check at line 1081 and surfaces the incompatible flag combination instead of mystifying the user. Addresses Copilot review on #2698.
…hase-2c-take-skip linq_fold Phase 2C: take/skip splice + chained-select := clone
`glClearColor(0.85, 0.85, 0.90)` (lavender) clashed with the daslang theme that the harness now applies — the ImGui windows on top sit on `#0d0c0a` while the GL surface behind them was light. Switch the clear color to the theme bg (`(0.051, 0.047, 0.039)` = `#0d0c0a`) so the viewport blends seamlessly with the windows. Circle outlines were `(0,0,0)` black — invisible on the new dark bg. Recolor to `(0.357, 0.333, 0.278)` (theme `fgFaint`, `#5b5547`) so the epicycle circles are legible without competing with the red arrows or yellow trace. Arrows (red) and trace (yellow) read fine on dark — left as-is. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Three linq_fold cards from Phase 2C (PR #2697) that didn't make it into the merged PR: - chained-select splice: bind via clone-assign universal (drops the prevWorkhorse-only guard) - macro planner: named-marker arms leave room for future modes - splice macro: bounded loop guard for take/skip non-positive N Two dasImgui cards from this session (HDPI PR borisbat/dasImgui#42): - HDPI plumbing pattern (glfwGetWindowContentScale + ScaleAllSizes + GLFW_SCALE_TO_MONITOR hint; float* binding gotcha) - Local daspkg install dance (out-of-tree dasImgui build + --global --force re-install to propagate edits; -project_root won't substitute) Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…-disabled-fix cmake: gate daslang-target references when DAS_TOOLS_DISABLED=ON
Every other compile-family MCP tool (compile_check, lint, aot, run_test, ast_dump, find_symbol, etc.) accepts an optional project : string pointing at a .das_project file for custom module resolution. run_script and eval_expression were the last two outliers — both shell out to daslang.exe (which supports -project) but never piped it through, so any script or expression that needed project-bound module resolution silently failed. - run_script.das / eval_expression.das: trailing project arg, validated via validate_project_arg, injected as -project <file> in argv before the script path. eval_expression also threads it through the daslib- rewrite retry. - protocol.das: PROJECT_PROP registered on both tool schemas; dispatch_tool passes the already-extracted project string. - test_tools.das: two new [test] functions mirroring the existing test_compile_check_invalid_project — exercise both validate_project_arg error branches (nonexistent path, wrong extension). - README.md / doc/source/reference/utils/mcp.rst: document the new arg on run_script + eval_expression, document the previously-shipped-but- undocumented project arg on live_launch, and add the missing live_commands row to the Live-Reload Control tables. Out of scope: removing daslang-live's single-instance lock + adding a -port CLI flag to unblock concurrent live instances (MCP-side port arg already exists on every live_* tool). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…-batch mouse: 5 cards — linq_fold Phase 2C + dasImgui HDPI/build
…ample-dark-bg examples/graphics: dark bg matching daslang theme
…c9afb mcp: thread project arg through run_script and eval_expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
See Commits and Changes for more details.
Created by
pull[bot] (v2.0.0-alpha.4)
Can you help keep this open source service alive? 💖 Please sponsor : )