Skip to content

Commit 3b57adc

Browse files
committed
CAP: Avoid duplicate methods for primitive replacements
When a primitive CAP operation is replaced by another primitive implementation, update the category operation record without installing another method with identical filters. Installed dispatch methods now consult the current operation record, so the latest implementation is used while preserving added_functions history. This avoids Julia method-overwrite errors during module precompilation. Add CapOperationInstallationInfo and emit a level-1 message when an accepted primitive installation replaces another primitive implementation. Include the operation, category, and old and new weights. Bump CAP to v2026.07-04
1 parent 3f8578a commit 3b57adc

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

CAP/PackageInfo.g

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ SetPackageInfo( rec(
1010

1111
PackageName := "CAP",
1212
Subtitle := "Categories, Algorithms, Programming",
13-
Version := "2026.07-03",
13+
Version := "2026.07-04",
1414
Date := (function ( ) if IsBound( GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE ) then return GAPInfo.SystemEnvironment.GAP_PKG_RELEASE_DATE; else return Concatenation( ~.Version{[ 1 .. 4 ]}, "-", ~.Version{[ 6, 7 ]}, "-01" ); fi; end)( ),
1515
License := "GPL-2.0-or-later",
1616

CAP/gap/InstallAdds.gd

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
#! @Section InstallAdd Function
1010

11+
DeclareInfoClass( "CapOperationInstallationInfo" );
12+
1113
DeclareOperation( "AddCapOperation", [ IsString, IsCapCategory, IsFunction, IsInt ] );
1214

1315
DeclareGlobalFunction( "CAP_INTERNAL_INSTALL_ADDS_FROM_RECORD" );

CAP/gap/InstallAdds.gi

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ InstallMethod( AddCapOperation,
2323
[ "IsPrecompiledDerivation", false ],
2424
],
2525
function( CAP_NAMED_ARGUMENTS, function_name, category, func_to_install, weight )
26-
local record, category_name, is_derivation, is_final_derivation, is_precompiled_derivation, type, replaced_filter_list,
26+
local record, category_name, is_derivation, is_final_derivation, is_precompiled_derivation, type, replaces_primitive_installation, replaced_filter_list,
2727
input_human_readable_identifier_getter, input_sanity_check_functions, data_type, output_human_readable_identifier_getter,
2828
output_data_type, output_sanity_check_function, filter_string;
2929

@@ -68,6 +68,8 @@ InstallMethod( AddCapOperation,
6868
type := "primitive_installation";
6969

7070
fi;
71+
72+
replaces_primitive_installation := false;
7173

7274
# Display a warning in various cases when overwriting existing functions
7375
if IsBound( category!.operations.(function_name) ) then
@@ -88,6 +90,20 @@ InstallMethod( AddCapOperation,
8890
return;
8991

9092
fi;
93+
94+
replaces_primitive_installation :=
95+
category!.operations.( function_name ).type = "primitive_installation" and
96+
type = "primitive_installation";
97+
98+
if replaces_primitive_installation then
99+
100+
Info( CapOperationInstallationInfo, 1,
101+
"Duplicate primitive installation for ", function_name,
102+
" in category \"", category_name,
103+
"\": replacing weight ", category!.operations.( function_name ).weight,
104+
" with weight ", weight, "." );
105+
106+
fi;
91107

92108
if category!.operations.( function_name ).type = "primitive_installation" then
93109

@@ -221,6 +237,12 @@ InstallMethod( AddCapOperation,
221237
fi;
222238

223239
fi;
240+
241+
if replaces_primitive_installation then
242+
243+
return;
244+
245+
fi;
224246

225247
if not category!.overhead then
226248

@@ -229,7 +251,7 @@ InstallMethod( AddCapOperation,
229251

230252
function( arg )
231253

232-
return CallFuncList( func_to_install, arg );
254+
return CallFuncList( category!.operations.( function_name ).func, arg );
233255

234256
end );
235257

@@ -280,7 +302,7 @@ InstallMethod( AddCapOperation,
280302

281303
fi;
282304

283-
result := CallFuncList( func_to_install, arg );
305+
result := CallFuncList( category!.operations.( function_name ).func, arg );
284306

285307
if collect_timing_statistics then
286308

0 commit comments

Comments
 (0)