Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
40e1ebb
kernel: use MUTABLE_TNUM to avoid some uses of IMMUTABLE
fingolfin Jun 27, 2025
2a93d60
kernel: let KTNumPlist & KTNumHomPlist return mutable tnum
fingolfin Jun 27, 2025
2b4bfd8
kernel: replace IS_PLIST_MUTABLE by IS_MUTABLE_OBJ
fingolfin Jun 27, 2025
183f9f6
Remove IMMUTABLE: src/plist.h
fingolfin Jun 26, 2025
218887a
kernel: make implicit mutability check explicit
fingolfin Jun 26, 2025
b926d29
kernel: add OBJ_FLAG_IMMUTABLE
fingolfin Jan 15, 2020
c9d5bca
kernel: remove MakeBagTypePublic calls for IMMUTABLE tnums
fingolfin Jan 6, 2019
7f3153c
kernel: remove IMMUTABLE from FiltListTNums handling
fingolfin Jan 6, 2019
e2c4eb4
Remove IMMUTABLE: src/blister.c
fingolfin Jun 26, 2025
08e3b2d
Remove IMMUTABLE: src/listoper.c
fingolfin Jun 26, 2025
4291391
Remove IMMUTABLE: src/lists.c
fingolfin Jun 23, 2025
4fddcd9
Remove IMMUTABLE: src/objset.c
fingolfin Jun 26, 2025
3bb8490
Remove IMMUTABLE: src/plist.c
fingolfin Jun 26, 2025
6c12dee
Remove IMMUTABLE: src/precord.c
fingolfin Jun 26, 2025
5367d8e
Remove IMMUTABLE: src/range.c
fingolfin Jun 23, 2025
add4fd9
Remove IMMUTABLE: src/stringobj.c
fingolfin Jun 26, 2025
1f0cfa4
Remove IMMUTABLE: src/vecffe.c
fingolfin Jun 26, 2025
c94a525
Remove IMMUTABLE: src/vector.c
fingolfin Jun 26, 2025
87056f1
Remove IMMUTABLE: src/hpc/serialize.c
fingolfin Jun 26, 2025
56dc6e8
kernel: adjust IS_* helpers to ignore IMMUTABLE
fingolfin Jan 6, 2019
88b7520
Remove (IM)MUTABLE_TNUM
fingolfin Jun 26, 2025
45621bc
kernel: remove IMMUTABLE
fingolfin Jun 26, 2025
05f1fbb
Fix lib/mat8bit.gi to deal with IMMUTABLE removal
fingolfin Jun 27, 2025
2fcd2f6
WIP: fixup TypePlistHomHelper
fingolfin Jun 27, 2025
b2af850
Adjust some tests
fingolfin Jun 30, 2025
57826aa
Some IMMUTABLE fixes
fingolfin Jun 30, 2025
0161bd5
TODOs for the HPC-GAP serializer code
fingolfin Jun 30, 2025
86e3522
HPC-GAP fix
fingolfin Jul 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions lib/mat8bit.gi
Original file line number Diff line number Diff line change
Expand Up @@ -821,10 +821,10 @@ InstallGlobalFunction( RepresentationsOfMatrix,
Print(" compressed over GF(",Q_VEC8BIT(m),") ");
elif IsPlistRep(m) then
Print(" plain list, tnum: ",TNUM_OBJ(m)," ");
if TNUM_OBJ(m) in [T_PLIST_FFE,T_PLIST_FFE+1] then
if TNUM_OBJ(m) in T_PLIST_FFE then
Print("known to be vecffe over GF(",CHAR_FFE_DEFAULT(m[1]),"^",
DEGREE_FFE_DEFAULT(m[1]),") ");
elif TNUM_OBJ(m) in [T_PLIST_CYC..T_PLIST_CYC_SSORT+1] then
elif TNUM_OBJ(m) in [T_PLIST_CYC..T_PLIST_CYC_SSORT] then
Print("known to be vector of cyclotomics ");
fi;
else
Expand Down
26 changes: 0 additions & 26 deletions src/bags.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ void PrecheckRetypeBag(Bag bag, UInt new_type)
if (TNUM_BAG(bag) == T_POSOBJ)
return;
#endif
Int oldImm = !IS_MUTABLE_OBJ(bag);
Int newImm = new_type & IMMUTABLE;
if (oldImm && !newImm) {
ErrorMayQuit(
"RetypeBag: cannot change immutable object to mutable", 0, 0);
}
}
}
#endif
Expand All @@ -74,32 +68,12 @@ void PrecheckRetypeBag(Bag bag, UInt new_type)
// TODO: perhaps this should become RetypeObj ?
void RetypeBagSM(Bag bag, UInt new_type)
{
if (FIRST_IMM_MUT_TNUM <= new_type && new_type <= LAST_IMM_MUT_TNUM) {
Int oldImm = !IS_MUTABLE_OBJ(bag);
Int newImm = new_type & IMMUTABLE;
if (newImm)
ErrorMayQuit(
"RetypeBagSM: target tnum should not indicate immutability",
0, 0);
if (oldImm)
new_type |= IMMUTABLE;
}
RetypeBag(bag, new_type);
}

#ifdef HPCGAP
void RetypeBagSMIfWritable(Bag bag, UInt new_type)
{
if (FIRST_IMM_MUT_TNUM <= new_type && new_type <= LAST_IMM_MUT_TNUM) {
Int oldImm = !IS_MUTABLE_OBJ(bag);
Int newImm = new_type & IMMUTABLE;
if (newImm)
ErrorMayQuit(
"RetypeBagSM: target tnum should not indicate immutability",
0, 0);
if (oldImm)
new_type |= IMMUTABLE;
}
RetypeBagIfWritable(bag, new_type);
}
#endif
50 changes: 7 additions & 43 deletions src/blister.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static Obj DoCopyBlist(Obj list, Int mut)
Obj copy;

// make a copy
copy = NewBag(MUTABLE_TNUM(TNUM_OBJ(list)), SIZE_OBJ(list));
copy = NewBag(TNUM_OBJ(list), SIZE_OBJ(list));
if (!mut)
MakeImmutableNoRecurse(copy);

Expand Down Expand Up @@ -1701,11 +1701,8 @@ static void MakeImmutableBlist(Obj blist)
*/
static StructBagNames BagNames[] = {
{ T_BLIST, "list (boolean)" },
{ T_BLIST +IMMUTABLE, "list (boolean,imm)" },
{ T_BLIST_NSORT, "list (boolean,nsort)" },
{ T_BLIST_NSORT +IMMUTABLE, "list (boolean,nsort,imm)" },
{ T_BLIST_SSORT, "list (boolean,ssort)" },
{ T_BLIST_SSORT +IMMUTABLE, "list (boolean,ssort,imm)" },
{ -1, "" }
};

Expand Down Expand Up @@ -1890,25 +1887,14 @@ static Int InitKernel (
// GASMAN marking functions and GASMAN names
InitBagNamesFromTable( BagNames );

for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT; t1 += 2 ) {
for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT; t1++ ) {
InitMarkFuncBags( t1 , MarkNoSubBags );
InitMarkFuncBags( t1 +IMMUTABLE , MarkNoSubBags );
}

// Make immutable blists public
#ifdef HPCGAP
for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT; t1 += 2 ) {
MakeBagTypePublic( t1 + IMMUTABLE );
}
#endif

// install the type methods
TypeObjFuncs[ T_BLIST ] = TypeBlist;
TypeObjFuncs[ T_BLIST +IMMUTABLE ] = TypeBlist;
TypeObjFuncs[ T_BLIST_NSORT ] = TypeBlistNSort;
TypeObjFuncs[ T_BLIST_NSORT +IMMUTABLE ] = TypeBlistNSort;
TypeObjFuncs[ T_BLIST_SSORT ] = TypeBlistSSort;
TypeObjFuncs[ T_BLIST_SSORT +IMMUTABLE ] = TypeBlistSSort;

// initialise list tables
InitClearFiltsTNumsFromTable ( ClearFiltsTab );
Expand All @@ -1918,74 +1904,52 @@ static Int InitKernel (

#ifdef GAP_ENABLE_SAVELOAD
// Install the saving functions -- cannot save while copying
for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT; t1 += 2 ) {
for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT; t1++ ) {
SaveObjFuncs[ t1 ] = SaveBlist;
SaveObjFuncs[ t1 +IMMUTABLE ] = SaveBlist;
LoadObjFuncs[ t1 ] = LoadBlist;
LoadObjFuncs[ t1 +IMMUTABLE ] = LoadBlist;
}
#endif

// install the copy functions
for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT; t1 += 2 ) {
for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT; t1++ ) {
#if !defined(USE_THREADSAFE_COPYING)
CopyObjFuncs [ t1 ] = CopyBlist;
CopyObjFuncs [ t1 +IMMUTABLE ] = CopyBlist;
CleanObjFuncs[ t1 ] = 0;
CleanObjFuncs[ t1 +IMMUTABLE ] = 0;
#endif
ShallowCopyObjFuncs[ t1 ] = ShallowCopyBlist;
ShallowCopyObjFuncs[ t1 +IMMUTABLE ] = ShallowCopyBlist;
}

// install the comparison methods
for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT+IMMUTABLE; t1++ ) {
for ( t2 = T_BLIST; t2 <= T_BLIST_SSORT+IMMUTABLE; t2++ ) {
for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT; t1++ ) {
for ( t2 = T_BLIST; t2 <= T_BLIST_SSORT; t2++ ) {
EqFuncs[ t1 ][ t2 ] = EqBlist;
}
}

// install the list functions in the tables
for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT; t1 += 2 ) {
for ( t1 = T_BLIST; t1 <= T_BLIST_SSORT; t1 ++ ) {
LenListFuncs [ t1 ] = LenBlist;
LenListFuncs [ t1 +IMMUTABLE ] = LenBlist;
IsbListFuncs [ t1 ] = IsbBlist;
IsbListFuncs [ t1 +IMMUTABLE ] = IsbBlist;
Elm0ListFuncs [ t1 ] = Elm0Blist;
Elm0ListFuncs [ t1 +IMMUTABLE ] = Elm0Blist;
Elm0vListFuncs [ t1 ] = Elm0vBlist;
Elm0vListFuncs [ t1 +IMMUTABLE ] = Elm0vBlist;
ElmListFuncs [ t1 ] = ElmBlist;
ElmListFuncs [ t1 +IMMUTABLE ] = ElmBlist;
ElmvListFuncs [ t1 ] = ElmvBlist;
ElmvListFuncs [ t1 +IMMUTABLE ] = ElmvBlist;
ElmwListFuncs [ t1 ] = ElmvBlist;
ElmwListFuncs [ t1 +IMMUTABLE ] = ElmvBlist;
ElmsListFuncs [ t1 ] = ElmsBlist;
ElmsListFuncs [ t1 +IMMUTABLE ] = ElmsBlist;
UnbListFuncs [ t1 ] = UnbBlist;
AssListFuncs [ t1 ] = AssBlist;
AsssListFuncs [ t1 ] = AsssListDefault;
IsDenseListFuncs[ t1 ] = AlwaysYes;
IsDenseListFuncs[ t1 +IMMUTABLE ] = AlwaysYes;
IsHomogListFuncs[ t1 ] = IsHomogBlist;
IsHomogListFuncs[ t1 +IMMUTABLE ] = IsHomogBlist;
IsTableListFuncs[ t1 ] = AlwaysNo;
IsTableListFuncs[ t1 +IMMUTABLE ] = AlwaysNo;
IsPossListFuncs [ t1 ] = IsPossBlist;
IsPossListFuncs [ t1 +IMMUTABLE ] = IsPossBlist;
PosListFuncs [ t1 ] = PosBlist;
PosListFuncs [ t1 +IMMUTABLE ] = PosBlist;
PlainListFuncs [ t1 ] = PlainBlist;
PlainListFuncs [ t1 +IMMUTABLE ] = PlainBlist;
MakeImmutableObjFuncs [ t1 ] = MakeImmutableBlist;
}
IsSSortListFuncs[ T_BLIST ] = IsSSortBlist;
IsSSortListFuncs[ T_BLIST +IMMUTABLE ] = IsSSortBlist;
IsSSortListFuncs[ T_BLIST_NSORT ] = AlwaysNo;
IsSSortListFuncs[ T_BLIST_NSORT +IMMUTABLE ] = AlwaysNo;
IsSSortListFuncs[ T_BLIST_SSORT ] = AlwaysYes;
IsSSortListFuncs[ T_BLIST_SSORT +IMMUTABLE ] = AlwaysYes;

// Import the types of blists:
ImportGVarFromLibrary( "TYPE_BLIST_MUT", &TYPE_BLIST_MUT );
Expand Down
2 changes: 1 addition & 1 deletion src/blister.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
EXPORT_INLINE BOOL IS_BLIST_REP(Obj list)
{
return T_BLIST <= TNUM_OBJ(list) &&
TNUM_OBJ(list) <= T_BLIST_SSORT + IMMUTABLE;
TNUM_OBJ(list) <= T_BLIST_SSORT;
}


Expand Down
14 changes: 6 additions & 8 deletions src/hpc/serialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@

#include <stdio.h>

// TODO/FIXME: serialize mutability information again somehow?

typedef struct SerializerState {
Obj stack;
Obj obj;
Expand Down Expand Up @@ -585,8 +587,6 @@ static Obj DeserializeRecord(DeserializerState * state, UInt tnum)
SET_ELM_PREC(result, i, el);
}
SortPRecRNam(result);
if (tnum == T_PREC + IMMUTABLE)
RetypeBag(result, tnum);
return result;
}

Expand Down Expand Up @@ -713,7 +713,6 @@ static Obj LookupIntTag(Obj tag)
retry:
switch (map ? TNUM_OBJ(map) : -1) {
case T_OBJMAP:
case T_OBJMAP + IMMUTABLE:
result = LookupObjMap(map, tag);
if (result || func)
return result;
Expand Down Expand Up @@ -741,7 +740,6 @@ static Obj DeserializeTypedObj(DeserializerState * state, UInt tnum)
switch (tagtnum) {
case T_INT:
case T_STRING:
case T_STRING + IMMUTABLE:
if (tagtnum == T_INT) {
tag = DeserializeInt(state, T_INT);
type = LookupIntTag(tag);
Expand All @@ -765,6 +763,7 @@ static Obj DeserializeTypedObj(DeserializerState * state, UInt tnum)
ErrorQuit("DeserializeTypedObj: expected plist, got %s", (Int)TNAM_OBJ(result), 0);
break;
case T_PREC:
// TODO/FIXME: reject immutable ones?
result = DeserializeObj(state);
if (TNUM_OBJ(result) != T_COMOBJ)
ErrorQuit("DeserializeTypedObj: expected component object, got %s", (Int)TNAM_OBJ(result), 0);
Expand Down Expand Up @@ -858,7 +857,6 @@ static void SerializeTypedObj(SerializerState * state, Obj obj)
switch (TNUM_OBJ(rep)) {
case T_INT:
case T_STRING:
case T_STRING + IMMUTABLE:
SerializeObj(state, rep);
UInt sp = LEN_PLIST(state->stack);
switch (TNUM_OBJ(obj)) {
Expand Down Expand Up @@ -1058,13 +1056,13 @@ static Int InitKernel(StructInitInfo * module)
for (i = FIRST_PLIST_TNUM; i <= LAST_PLIST_TNUM; i++) {
RegisterSerializerFunctions(i, SerializeList, DeserializeList);
}
for (i = T_RANGE_NSORT; i <= T_RANGE_SSORT + IMMUTABLE; i++) {
for (i = T_RANGE_NSORT; i <= T_RANGE_SSORT; i++) {
RegisterSerializerFunctions(i, SerializeRange, DeserializeRange);
}
for (i = T_BLIST; i <= T_BLIST_SSORT + IMMUTABLE; i++) {
for (i = T_BLIST; i <= T_BLIST_SSORT; i++) {
RegisterSerializerFunctions(i, SerializeBlist, DeserializeBlist);
}
for (i = T_STRING; i <= T_STRING_SSORT + IMMUTABLE; i++) {
for (i = T_STRING; i <= T_STRING_SSORT; i++) {
RegisterSerializerFunctions(i, SerializeString, DeserializeString);
}

Expand Down
2 changes: 1 addition & 1 deletion src/hpc/threadapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2023,7 +2023,7 @@ MigrateObjects(int count, Obj * objects, Region * target, int retype)
// they need to be sorted, as sorting upon access may prove impossible.
for (i = 0; i < count; i++) {
Obj obj = objects[i];
if (TNUM_OBJ(obj) == T_PREC) {
if (TNUM_OBJ(obj) == T_PREC && IS_MUTABLE_OBJ(obj)) {
SortPRecRNam(obj);
}
SET_REGION(obj, target);
Expand Down
4 changes: 2 additions & 2 deletions src/listfunc.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void AddPlist3(Obj list, Obj obj, Int pos)
{
UInt len;

if (!IS_PLIST_MUTABLE(list)) {
if (!IS_MUTABLE_OBJ(list)) {
ErrorMayQuit("List Assignment: <list> must be a mutable list", 0, 0);
}
// in order to be optimistic when building list call assignment
Expand Down Expand Up @@ -162,7 +162,7 @@ static Obj RemPlist(Obj list)
Int pos;
Obj removed;

if ( ! IS_PLIST_MUTABLE(list) ) {
if ( ! IS_MUTABLE_OBJ(list) ) {
ErrorMayQuit("Remove: <list> must be a mutable list", 0, 0);
}
pos = LEN_PLIST( list );
Expand Down
28 changes: 12 additions & 16 deletions src/listoper.c
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,7 @@ static Obj ZeroListDefault(Obj list)

if (IS_PLIST( list ))
{
if (TNUM_OBJ(list) == T_PLIST_FFE ||
TNUM_OBJ(list) == T_PLIST_FFE+IMMUTABLE)
if (TNUM_OBJ(list) == T_PLIST_FFE)
RetypeBag(res, TNUM_OBJ(list));
else if (TNUM_OBJ(list) >= T_PLIST_CYC &&
TNUM_OBJ(list) < T_PLIST_FFE)
Expand Down Expand Up @@ -398,8 +397,7 @@ static Obj ZeroListMutDefault(Obj list)

if (IS_PLIST( list ))
{
if (TNUM_OBJ(list) == T_PLIST_FFE ||
TNUM_OBJ(list) == T_PLIST_FFE+IMMUTABLE)
if (TNUM_OBJ(list) == T_PLIST_FFE)
RetypeBag(res, T_PLIST_FFE);
else if (TNUM_OBJ(list) >= T_PLIST_CYC &&
TNUM_OBJ(list) < T_PLIST_FFE)
Expand Down Expand Up @@ -494,8 +492,7 @@ static Obj AInvMutListDefault(Obj list)
// Now adjust the result TNUM info

if (IS_PLIST(list)) {
if (TNUM_OBJ(list) == T_PLIST_FFE ||
TNUM_OBJ(list) == T_PLIST_FFE+IMMUTABLE)
if (TNUM_OBJ(list) == T_PLIST_FFE)
RetypeBag(res, T_PLIST_FFE);
else if (TNUM_OBJ(list) >= T_PLIST_CYC &&
TNUM_OBJ(list) < T_PLIST_FFE)
Expand Down Expand Up @@ -549,8 +546,7 @@ static Obj AInvListDefault(Obj list)
// Now adjust the result TNUM info

if (IS_PLIST(list)) {
if (TNUM_OBJ(list) == T_PLIST_FFE ||
TNUM_OBJ(list) == T_PLIST_FFE+IMMUTABLE)
if (TNUM_OBJ(list) == T_PLIST_FFE)
RetypeBag(res, TNUM_OBJ(list));
else if (TNUM_OBJ(list) >= T_PLIST_CYC &&
TNUM_OBJ(list) < T_PLIST_FFE)
Expand Down Expand Up @@ -2162,11 +2158,11 @@ static Int InitKernel (
}

}
for (t1 = T_PLIST_CYC; t1 <= T_PLIST_FFE+IMMUTABLE; t1++) {
for (t2 = T_PLIST_CYC; t2 <= T_PLIST_FFE+IMMUTABLE; t2++) {
for (t1 = T_PLIST_CYC; t1 <= T_PLIST_FFE; t1++) {
for (t2 = T_PLIST_CYC; t2 <= T_PLIST_FFE; t2++) {
SumFuncs[t1][t2] = SumListList;
}
for (t2 = T_PLIST_TAB; t2 <= T_PLIST_TAB_RECT_SSORT+IMMUTABLE; t2++) {
for (t2 = T_PLIST_TAB; t2 <= T_PLIST_TAB_RECT_SSORT; t2++) {
SumFuncs[t1][t2] = SumSclList;
SumFuncs[t2][t1] = SumListScl;
}
Expand All @@ -2180,11 +2176,11 @@ static Int InitKernel (
DiffFuncs[t2][t1] = DiffSclList;
}
}
for (t1 = T_PLIST_CYC; t1 <= T_PLIST_FFE+IMMUTABLE; t1++) {
for (t2 = T_PLIST_CYC; t2 <= T_PLIST_FFE+IMMUTABLE; t2++) {
for (t1 = T_PLIST_CYC; t1 <= T_PLIST_FFE; t1++) {
for (t2 = T_PLIST_CYC; t2 <= T_PLIST_FFE; t2++) {
DiffFuncs[t1][t2] = DiffListList;
}
for (t2 = T_PLIST_TAB; t2 <= T_PLIST_TAB_RECT_SSORT+IMMUTABLE; t2++) {
for (t2 = T_PLIST_TAB; t2 <= T_PLIST_TAB_RECT_SSORT; t2++) {
DiffFuncs[t1][t2] = DiffSclList;
DiffFuncs[t2][t1] = DiffListScl;
}
Expand All @@ -2205,8 +2201,8 @@ static Int InitKernel (
ProdFuncs[t2][t1] = ProdSclList;
}
}
for (t1 = T_PLIST_CYC; t1 <= T_PLIST_FFE+IMMUTABLE; t1++) {
for (t2 = T_PLIST_CYC; t2 <= T_PLIST_FFE+IMMUTABLE; t2++) {
for (t1 = T_PLIST_CYC; t1 <= T_PLIST_FFE; t1++) {
for (t2 = T_PLIST_CYC; t2 <= T_PLIST_FFE; t2++) {
ProdFuncs[t1][t2] = ProdListList;
}
}
Expand Down
Loading
Loading