From 87a8031c6898952550b14f3af66c5ba050fbfe94 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 8 Oct 2026 14:49:17 +0200 Subject: [PATCH] kernel: pass mutability on explicitly to new lists Some functions create their result with the tnum of an argument, and thereby give it the mutability of that argument: ZeroSameMutability for plain lists of FFEs, sums and differences of a cyclotomic vector and a scalar, and REDUCE_LETREP_WORDS_REW_SYS. Say so explicitly, so that this keeps working once mutability is no longer part of the tnum (see #6025). Assisted-by: Claude Code (Opus 5.5) --- src/tietze.c | 3 ++- src/vecffe.c | 2 +- src/vector.c | 9 ++++++--- tst/testinstall/kbsemi.tst | 11 +++++++++++ tst/testinstall/kernel/vecffe.tst | 10 ++++++++++ tst/testinstall/kernel/vector.tst | 30 ++++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 5 deletions(-) create mode 100644 tst/testinstall/kernel/vector.tst diff --git a/src/tietze.c b/src/tietze.c index 87997a7cd9..75d1192b76 100644 --- a/src/tietze.c +++ b/src/tietze.c @@ -1482,7 +1482,8 @@ static Obj FuncREDUCE_LETREP_WORDS_REW_SYS(Obj self, Obj tzrules, Obj a_w) } else { // make space for the new word - nw = NEW_PLIST(TNUM_OBJ(w),newlen); + nw = NEW_PLIST_WITH_MUTABILITY(IS_MUTABLE_OBJ(w), TNUM_OBJ(w), + newlen); // addresses wa=ADDR_OBJ(w); diff --git a/src/vecffe.c b/src/vecffe.c index 6b68078c77..616b4fce1b 100644 --- a/src/vecffe.c +++ b/src/vecffe.c @@ -859,7 +859,7 @@ static Obj ZeroVecFFE(Obj vec) TNUM_OBJ(vec) <= T_PLIST_FFE + IMMUTABLE); len = LEN_PLIST(vec); assert(len); - res = NEW_PLIST(TNUM_OBJ(vec), len); + res = NEW_PLIST_WITH_MUTABILITY(IS_MUTABLE_OBJ(vec), T_PLIST_FFE, len); SET_LEN_PLIST(res, len); z = ZERO_SAMEMUT(ELM_PLIST(vec, 1)); for (i = 1; i <= len; i++) diff --git a/src/vector.c b/src/vector.c index 8c72b59b19..96e9a6c166 100644 --- a/src/vector.c +++ b/src/vector.c @@ -47,7 +47,8 @@ static Obj SumIntVector(Obj elmL, Obj vecR) // make the result list len = LEN_PLIST(vecR); - vecS = NEW_PLIST(TNUM_OBJ(vecR), len); + vecS = NEW_PLIST_WITH_MUTABILITY(IS_MUTABLE_OBJ(vecR), TNUM_OBJ(vecR), + len); SET_LEN_PLIST(vecS, len); // loop over the elements and add @@ -93,7 +94,8 @@ static Obj SumVectorInt(Obj vecL, Obj elmR) // make the result list len = LEN_PLIST(vecL); - vecS = NEW_PLIST(TNUM_OBJ(vecL), len); + vecS = NEW_PLIST_WITH_MUTABILITY(IS_MUTABLE_OBJ(vecL), TNUM_OBJ(vecL), + len); SET_LEN_PLIST(vecS, len); // loop over the elements and add @@ -253,7 +255,8 @@ static Obj DiffVectorInt(Obj vecL, Obj elmR) // make the result list len = LEN_PLIST(vecL); - vecD = NEW_PLIST(TNUM_OBJ(vecL), len); + vecD = NEW_PLIST_WITH_MUTABILITY(IS_MUTABLE_OBJ(vecL), TNUM_OBJ(vecL), + len); SET_LEN_PLIST(vecD, len); // loop over the elements and subtract diff --git a/tst/testinstall/kbsemi.tst b/tst/testinstall/kbsemi.tst index e4e6958fdf..5baccd2bb3 100644 --- a/tst/testinstall/kbsemi.tst +++ b/tst/testinstall/kbsemi.tst @@ -77,5 +77,16 @@ gap> KnuthBendixRewritingSystem(N, \<); Knuth Bendix Rewriting System for Monoid( [ m1, m2 ] ) with rules [ [ m2, m1 ] ] +# the reduced word has the mutability of the given word +gap> w := ReduceLetterRepWordsRewSys([ [ [ 1, 2 ], [ 3 ] ] ], [ 1, 2, 4 ]);; +gap> w; IsMutable(w); +[ 3, 4 ] +true +gap> w := MakeImmutable([ 1, 2, 4 ]);; +gap> w := ReduceLetterRepWordsRewSys([ [ [ 1, 2 ], [ 3 ] ] ], w);; +gap> w; IsMutable(w); +[ 3, 4 ] +false + # gap> STOP_TEST("kbsemi.tst"); diff --git a/tst/testinstall/kernel/vecffe.tst b/tst/testinstall/kernel/vecffe.tst index 27791b9125..6c6b0e469e 100644 --- a/tst/testinstall/kernel/vecffe.tst +++ b/tst/testinstall/kernel/vecffe.tst @@ -124,5 +124,15 @@ gap> SMALLEST_FIELD_VECFFE([Z(2), Z(4)]); gap> SMALLEST_FIELD_VECFFE([Z(8), Z(4)]); 64 +# +# ZeroSameMutability +# +gap> v := [ Z(5), 0*Z(5) ];; IS_VECFFE(v); +true +gap> IsMutable(ZeroSameMutability(v)); +true +gap> IsMutable(ZeroSameMutability(MakeImmutable(v))); +false + # gap> STOP_TEST("kernel/vecffe.tst"); diff --git a/tst/testinstall/kernel/vector.tst b/tst/testinstall/kernel/vector.tst new file mode 100644 index 0000000000..814d31682c --- /dev/null +++ b/tst/testinstall/kernel/vector.tst @@ -0,0 +1,30 @@ +# +# Tests for functions defined in src/vector.c +# +#@local v, w +gap> START_TEST("kernel/vector.tst"); + +# sum and difference of a vector and a scalar have the mutability of the vector +gap> v := [ 1, 2, 3 ];; +gap> w := 1 + v;; w; IsMutable(w); +[ 2, 3, 4 ] +true +gap> w := v + 1;; w; IsMutable(w); +[ 2, 3, 4 ] +true +gap> w := v - 1;; w; IsMutable(w); +[ 0, 1, 2 ] +true +gap> MakeImmutable(v);; +gap> w := 1 + v;; w; IsMutable(w); +[ 2, 3, 4 ] +false +gap> w := v + 1;; w; IsMutable(w); +[ 2, 3, 4 ] +false +gap> w := v - 1;; w; IsMutable(w); +[ 0, 1, 2 ] +false + +# +gap> STOP_TEST("kernel/vector.tst");