diff --git a/dev/design/issue-queue.md b/dev/design/issue-queue.md index 73d8eb886d..e39b24523e 100644 --- a/dev/design/issue-queue.md +++ b/dev/design/issue-queue.md @@ -1,6 +1,6 @@ # Reviewed issue queues -Snapshot: 2026-11-06, from live open issues, PRs and the #1649 phase contract. +Snapshot: 2026-11-09, from live open issues, PRs and the #1649 phase contract. This is a bounded selection aid, not the complete backlog or fresh runtime validation. Follow the [triage and claim protocol](../../docs/guides/issue-triage.md) and recheck live issue comments/PRs before starting. Unlisted work is unreviewed @@ -26,6 +26,7 @@ resolved before implementation. No new pass or failure is asserted here. | Code/test boundary | Issue | Priority / state | Evidence, next action and blocker | |---|---|---|---| +| Pure-Perl List::Util fallback | [#2000](https://github.com/fglock/PerlOnJava/issues/2000) `List::Util::MaybeXS` 1.500015 | Normal / Active | CPAN run `20261109-091152-39587` passes on system Perl and fails on both PerlOnJava backends. Current candidate addresses right-operand mutation in `sum`/`product`; scalar `pairgrep` context remains open. Callback returns, B scalar flags, and refcount/destruction checks overlap active #1649 PR #1938 and need coordination. | | Hash dereference assignment | [#1958](https://github.com/fglock/PerlOnJava/issues/1958) Undefined-reference autovivification | Normal / Active | Shared-runtime fix and focused regression pass on both backends; full `make` passes in [PR #1960](https://github.com/fglock/PerlOnJava/pull/1960). [Current claim](https://github.com/fglock/PerlOnJava/issues/1958#issuecomment-6626463414). Object-Hybrid 0.07's follow-on generated `can` dispatch failure is also addressed in that PR under #1959. | | Dynamic class method lookup | [#1959](https://github.com/fglock/PerlOnJava/issues/1959) Object::Hybrid `tieable` promotion | Normal / Active | Generated `HASH_STATIC` declares a bodyless `can`; route it through that class's `AUTOLOAD` when present. Focused reproducer and full `make` pass on both backends. The full upstream suite advances beyond this failure but later exits at `IO::File::FILENO` (separate behavior). Candidate fix is in [PR #1960](https://github.com/fglock/PerlOnJava/pull/1960). | | Scalar introspection | [#1954](https://github.com/fglock/PerlOnJava/issues/1954) `Scalar::Util::isdual` booleans | Normal / Active | Mars 0.05 passes on system Perl and failed assertions 10–11 on both PerlOnJava backends (run `20261103-123832-91742`). [Draft PR #1956](https://github.com/fglock/PerlOnJava/pull/1956) recognizes BOOLEAN values; focused boolean, explicit-dualvar and plain-string coverage plus all 13 Mars assertions pass on both backends, and full `make` passes. | diff --git a/docs/about/changelog.md b/docs/about/changelog.md index fbe606f3d2..7128042e44 100644 --- a/docs/about/changelog.md +++ b/docs/about/changelog.md @@ -8,6 +8,8 @@ priorities and future plans. - Normalize out-of-range calendar fields in `Time::Piece->strptime`, matching Perl date overflow behavior (#2001). +- Preserve right-hand object values during overloaded `+=` and `*=` by dispatching assignment overloads only on the writable left operand. + - Share empty warning-bit and parser-keyword-plugin sentinels across `ScopedSymbolTable` scopes instead of allocating fresh `BitSet` and `LinkedHashMap` instances for every scope entry: `enterScope()`, the constructor, and `snapShot()` now push a static `EMPTY_BITSET`/`EMPTY_PLUGINS` reference when the scope inherits all-default warning state, with copy-on-write in all mutation paths (`enableWarningCategory`, `disableWarningCategory`, `enableFatalWarningCategory`, `enableExperimentalFeatureWarning`, `registerParserKeywordPlugin`). Eliminates ~30 M `BitSet` and ~10 M `LinkedHashMap` allocations per 5 M eval-string iterations, removing both allocation types from the JFR execution-sample profile and halving `ScopedSymbolTable.` sample count. - Eliminate unbounded `WarningBitsRegistry` growth for interpreter-compiled evals: warning bits are now embedded directly in the `caller()` frame token rather than registered in a global `ConcurrentHashMap`, removing a memory leak and a ~22% `ConcurrentHashMap.transfer` hot spot on repeated `eval STRING`. diff --git a/src/main/java/org/perlonjava/runtime/operators/StringOperators.java b/src/main/java/org/perlonjava/runtime/operators/StringOperators.java index 88414faafa..c5c2986170 100644 --- a/src/main/java/org/perlonjava/runtime/operators/StringOperators.java +++ b/src/main/java/org/perlonjava/runtime/operators/StringOperators.java @@ -606,10 +606,9 @@ public static RuntimeScalar stringConcatAssign(RuntimeScalar runtimeScalar, Runt throw new PerlCompilerException("Can't coerce GLOB to string in string context"); } int blessId = RuntimeScalarType.blessedId(runtimeScalar); - int blessId2 = RuntimeScalarType.blessedId(b); - if (blessId < 0 || blessId2 < 0) { + if (blessId < 0) { RuntimeScalar result = OverloadContext.tryTwoArgumentAssignmentOverloadDirect( - runtimeScalar, b, blessId, blessId2, "(.="); + runtimeScalar, b, blessId, "(.="); if (result != null) { // Assignment overloads return the value Perl assigns back to // the lvalue. Preserve that reference instead of stringifying it. diff --git a/src/main/java/org/perlonjava/runtime/runtimetypes/OverloadContext.java b/src/main/java/org/perlonjava/runtime/runtimetypes/OverloadContext.java index aa4361a36e..b2e6511dd7 100644 --- a/src/main/java/org/perlonjava/runtime/runtimetypes/OverloadContext.java +++ b/src/main/java/org/perlonjava/runtime/runtimetypes/OverloadContext.java @@ -374,19 +374,20 @@ public static RuntimeScalar tryTwoArgumentOverloadDirect(RuntimeScalar arg1, Run } /** - * Tries only an explicitly defined assignment overload. Unlike the - * generic binary-overload driver, a missing method does not invoke - * {@code nomethod} or enforce the package fallback policy; callers may - * continue with the corresponding non-assignment operator or its native - * behavior. When the left operand supplies the mutator, preserve Perl's - * copy-constructor semantics before invoking it. + * Tries only an explicitly defined assignment overload on the writable + * left operand. Unlike the generic binary-overload driver, a missing + * method does not invoke {@code nomethod} or enforce the package fallback + * policy; callers may continue with the corresponding non-assignment + * operator or its native behavior. Preserve Perl's copy-constructor + * semantics before invoking a left-operand mutator. The right operand's + * assignment overload is not eligible: Perl falls back to its ordinary + * binary overload instead of mutating the right operand. * * @return The explicit assignment-overload result, or {@code null} when - * neither operand defines it. + * the left operand has no explicit assignment overload. */ public static RuntimeScalar tryTwoArgumentAssignmentOverloadDirect( - RuntimeScalar arg1, RuntimeScalar arg2, int blessId, int blessId2, - String overloadName) { + RuntimeScalar arg1, RuntimeScalar arg2, int blessId, String overloadName) { if (blessId < 0) { OverloadContext ctx1 = prepare(blessId); if (ctx1 != null && ctx1.hasOverload(overloadName)) { @@ -395,13 +396,6 @@ public static RuntimeScalar tryTwoArgumentAssignmentOverloadDirect( overloadName, new RuntimeArray(arg1, arg2, scalarFalse)); } } - if (blessId2 < 0) { - OverloadContext ctx2 = prepare(blessId2); - if (ctx2 != null && ctx2.hasOverload(overloadName)) { - return ctx2.tryOverload( - overloadName, new RuntimeArray(arg2, arg1, scalarTrue)); - } - } return null; } @@ -456,9 +450,12 @@ public static RuntimeScalar tryTwoArgumentOverload(RuntimeScalar arg1, RuntimeSc } } if (blessId2 < 0) { - // Try swapped overload + // A compound assignment applies to its writable left operand. A + // right-hand object's `+=`/`*=` method must not run on that + // object; after assignment overload lookup, try its ordinary + // binary overload through autogeneration instead. ctx2 = prepare(blessId2); - if (ctx2 != null) { + if (ctx2 != null && !isCompoundAssignment(overloadName)) { RuntimeScalar result = ctx2.tryOverload(overloadName, new RuntimeArray(arg2, arg1, scalarTrue)); if (result != null) return result; } @@ -512,6 +509,14 @@ public static RuntimeScalar tryTwoArgumentOverload(RuntimeScalar arg1, RuntimeSc return null; } + private static boolean isCompoundAssignment(String overloadName) { + return switch (overloadName) { + case "(+=", "(-=", "(*=", "(/=", "(%=", "(.=", "(&=", "(|=", "(^=", + "(<<=", "(>>=" -> true; + default -> false; + }; + } + public RuntimeScalar tryOverloadNomethod(RuntimeScalar runtimeScalar, String methodName) { return tryOverload("(nomethod", new RuntimeArray(runtimeScalar, scalarUndef, new RuntimeScalar(""), new RuntimeScalar(methodName))); } diff --git a/src/test/resources/unit/fixtures/List/Util/PP.pm b/src/test/resources/unit/fixtures/List/Util/PP.pm new file mode 100644 index 0000000000..51f1cc02f7 --- /dev/null +++ b/src/test/resources/unit/fixtures/List/Util/PP.pm @@ -0,0 +1,22 @@ +package List::Util::PP; + +use strict; +use warnings; +use Exporter 'import'; + +our @EXPORT_OK = qw(sum product); + +sub sum (@) { + return undef unless @_; + my $sum = 0; + $sum += $_ foreach @_; + return $sum; +} + +sub product (@) { + my $product = 1; + $product *= $_ foreach @_; + return $product; +} + +1; diff --git a/src/test/resources/unit/list_util_pp_bigint_mutation.t b/src/test/resources/unit/list_util_pp_bigint_mutation.t new file mode 100644 index 0000000000..d0202eb480 --- /dev/null +++ b/src/test/resources/unit/list_util_pp_bigint_mutation.t @@ -0,0 +1,23 @@ +use strict; +use warnings; +use FindBin; +use lib "$FindBin::Bin/fixtures"; +use Test::More; +use Math::BigInt; +use List::Util::PP qw(sum product); + +my $sum_input = Math::BigInt->new('36893488147419103232'); +my $sum_result = sum(42, $sum_input); +is($sum_result->bstr, '36893488147419103274', + 'sum preserves BigInt precision with a built-in integer'); +is($sum_input->bstr, '36893488147419103232', + 'sum does not mutate its BigInt input'); + +my $product_input = Math::BigInt->new('36893488147419103232'); +my $product_result = product(42, $product_input); +is($product_result->bstr, '1549526502191602335744', + 'product preserves BigInt precision with a built-in integer'); +is($product_input->bstr, '36893488147419103232', + 'product does not mutate its BigInt input'); + +done_testing();