M2 icon indicating copy to clipboard operation
M2 copied to clipboard

doubly nested cache table

Open DanGrayson opened this issue 5 years ago • 5 comments
trafficstars

This extra cache table should not be there:

Macaulay2, version 1.16.0.2
with packages: Colon, ConwayPolynomials, Elimination, IntegralClosure, InverseSystems, LLLBases, MinimalPrimes, PrimaryDecomposition, ReesAlgebra, TangentCone, Truncations

i1 : M = ZZ^2;

i2 : peek M.cache

o2 = CacheTable{cache => MutableHashTable{}}

i3 : 

Process M2 finished

+ /Applications/Macaulay2-1.16/bin/M2 --no-readline --print-width 92
Macaulay2, version 1.16
with packages: ConwayPolynomials, Elimination, IntegralClosure, InverseSystems, LLLBases,
               MinimalPrimes, PrimaryDecomposition, ReesAlgebra, TangentCone, Truncations

i1 : M = ZZ^2;

i2 : peek M.cache

o2 = CacheTable{cache => MutableHashTable{}}

DanGrayson avatar Nov 21 '20 14:11 DanGrayson

I didn't expect this to return much, but here are a few places it seems to be used:

[mahrud@noether M2]$ grep -R "cache.cache\b" Macaulay2/
Macaulay2/m2/modules2.m2:     Y := youngest(M.cache.cache,N.cache.cache);
Macaulay2/m2/modules2.m2:     Y := youngest(M.cache.cache,N.cache.cache);
Macaulay2/packages/Complexes.m2:    Y := youngest(M.cache.cache,N.cache.cache);
Macaulay2/packages/Complexes.m2:  peek N.cache.cache -- why does N.cache have its own cache table?
Macaulay2/tests/normal/hom.m2:assert ( hash (Hom(M,N)).cache.cache === hash (Hom(M,N)).cache.cache )
Macaulay2/tests/normal/hom.m2:assert ( hash (M**N).cache.cache === hash (M**N).cache.cache )

Note the second occurrence in Complexes.m2 😂

mahrud avatar Nov 22 '20 16:11 mahrud

Oh, did this issue come up in relation to #1570?

mahrud avatar Nov 22 '20 16:11 mahrud

Oh, maybe this comment explains it:

new Module from Sequence := (Module,x) -> (
     (R,rM) -> (
	  assert instance(R,Ring);
	  assert instance(rM,RawFreeModule);
	  new Module of Vector from hashTable {
     	       symbol cache => new CacheTable from { 
		    cache => new MutableHashTable	    -- this hash table is mutable, hence has a hash number that can serve as its age
		    },
     	       symbol RawFreeModule => rM,
     	       symbol ring => R,
     	       symbol numgens => rawRank rM
     	       })) x

Cache tables are also mutable, but their hash codes are always 0. Modules are immutable, so there's no way to figure out their age.

Maybe there's a cleaner way to arrange it. Oh, well, not urgent.

DanGrayson avatar Nov 22 '20 18:11 DanGrayson

Oh, did this issue come up in relation to #1570?

No.

Oops, I keep forgetting to work on that for them.

DanGrayson avatar Nov 22 '20 18:11 DanGrayson

Cache tables are also mutable, but their hash codes are always 0. Modules are immutable, so there's no way to figure out their age.

Perhaps in order to avoid confusion M.cache.cache shouldn't be called cache, because it's just a MutableHashTable and not a CacheTable. Or perhaps M.cache should be a MutableHashTable instead. Would that break ===?

mahrud avatar Jul 01 '23 19:07 mahrud