Closed mahrud closed 3 years ago
Correction: it doesn't crash, just gets stuck in an infinite loop here: https://github.com/Macaulay2/M2/blob/65332ed07101a51255182fb5a16e4e6e20809292/M2/Macaulay2/d/stdio.d#L414-L425
And this one works (??):
i5 : capture "aaaaaaaaaaaaaaaaaaaaaaaaaaaa"
o5 = (false, , {i1 : aaaaaaaaaaaaaaaaaaaaaaaaaaaa, i2 : })
i1 : aaaaaaaaaaaaaaaaaaaaaaaaaaaa
o1 = aaaaaaaaaaaaaaaaaaaaaaaaaaaa
o1 = aaaaaaaaaaaaaaaaaaaaaaaaaaaa
o1 : Symbol
o1 : Symbol
i2 :
o5 : Sequence
I can't figure out what makes it go wrong. That string was the shortest thing that worked, but for a more realistic thing take any documentation node and try:
capture toString examples (sum, List)
@DanGrayson here's the patch for the error above:
diff --git a/M2/Macaulay2/d/stdio.d b/M2/Macaulay2/d/stdio.d
index dc67ff295..003cdac40 100644
--- a/M2/Macaulay2/d/stdio.d
+++ b/M2/Macaulay2/d/stdio.d
@@ -415,6 +415,7 @@ simpleout(o:file,x:string):int := (
if j == n then (
if simpleflush(o) == ERROR then (releaseFileFOSS(o); return ERROR);
j = foss.outindex;
+ n = length(foss.outbuffer);
);
b := m-i; -- number of bytes to transfer this time
if b > n-j then b = n-j;
@@ -554,7 +555,6 @@ export (o:file) << (c:char) : file := (
foss := getFileFOSS(o);
if o.output then (
if foss.hadNet then (
- foss.hadNet = true;
foss.nets = NetList(foss.nets,toNet(c));
)
else (
However, another error remains in printing nets:
i3 : (capture "1\n2\n3")#1
o3 = 123
i1 : 1
o1 =
i2 : 2
o2 =
i3 : 3
o3 =
i4 :
Commit 1fe22f49059b474de733ec2579ca4fbd411cf41e almost fixed capture, but:
print last capture "4*4"
*** out of memory trying to allocate -10 bytes, exiting ***
Thanks, that looks similar to the crash that happens when printing in threads, so maybe we'll fix it now! I'll make a debug build and track it down.
Fixed in commit 0e76993ac56d94ca81131971b10f947d3bef125d on the development branch now.
Thanks, but i
is missing:
./M2 -q --silent --no-preload -e 'print last capture "4*4"; exit 0'
1 : 4*4
1 = 16
2 :
Could you make a branch and open a PR for fixing this instead of commit by commit? That way I could also help.
Thanks, but
i
is missing:./M2 -q --silent --no-preload -e 'print last capture "4*4"; exit 0' 1 : 4*4 1 = 16 2 :
Fixed, by setting the interpreterDepth to 1 when capturing and making the variable thread local.
Could you make a branch and open a PR for fixing this instead of commit by commit? That way I could also help.
Sure, done. See https://github.com/Macaulay2/M2/pull/1481 -- I'll do other things for a while.
i1 : a = 12
o1 = 12
i2 : capture "a"
o2 = (false, )
i1 : a
o1 = 12
i2 :
How would one make capture work in an empty frame? (is that the right term?)
I'm guessing the dictionaryPath needs to be truncated, but I'm not sure what should remain in it.
Ah, good point. I wouldn't call it a "frame" -- what we want, for the sake of running examples, is to have no previously set global variables around, and to have a place for putting new ones that none of the other threads are using.
All dictionary lookups happen by following the dictionary path:
Macaulay2, version 1.16.0.2
with packages: ConwayPolynomials, Elimination, IntegralClosure, InverseSystems, LLLBases, MinimalPrimes, PrimaryDecomposition, ReesAlgebra, TangentCone, Truncations
i1 : dictionaryPath
o1 = {Truncations.Dictionary, SimpleDoc.Dictionary, InverseSystems.Dictionary, ConwayPolynomials.Dictionary, ReesAlgebra.Dictionary, TangentCone.Dictionary, Classic.Dictionary,
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
PrimaryDecomposition.Dictionary, IntegralClosure.Dictionary, MinimalPrimes.Dictionary, LLLBases.Dictionary, Elimination.Dictionary, User#"private dictionary", User.Dictionary,
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Core.Dictionary, OutputDictionary, PackageDictionary}
o1 : List
i2 : select(dictionaryPath,mutable)
o2 = {User#"private dictionary", User.Dictionary, OutputDictionary, PackageDictionary}
o2 : List
We want to set dictionaryPath
to a new value that includes the dictionaries of just the needed packages, at least one mutable dictionary where new symbols can go, the OutputDictionary, where o1, o2, ... go, and the PackageDictionary, which has to be there for referring to loaded packages. Get rid of the two User dictionaries. A new mutable dictionary can be made with new Dictionary
. Make two, put one on the list and assign one to OutputDictionary. To run examples in threads, we have to make the symbol OutputDictionary thread local. Some variables are already thread local: debugLevel engineDebugLevel debuggingMode allowableThreads loadDepth stopIfError. Use those as a model. The code for them all is in the d directory.
I tried variations of this suggestion, but ran into mysterious issues, for instance with QQ[a..c]
or things of this sort. I'll try again later today.
Oh, yes. The problem is that "getSymbol" refers to "User":
i23 : code getSymbol
o23 = ../../../../../../Macaulay2/m2/setup.m2:61:15-63:49: --source code:
getSymbol = s -> (
if instance(User,Symbol) then error "getSymbol used before package User created";
getGlobalSymbol(User#"private dictionary", s))
So we have to make User thread local and give it a suitable value.
Sure, I figured I have to empty the User dictionaries, but errors persisted:
i1 : R = QQ[a..d,MonomialOrder=>GLex]
o1 = R
o1 : PolynomialRing
i2 : a^3*b+a^4+b^100
../../../../Macaulay2/m2/robust.m2:98:26:(1):[14]: error: no method for binary operator ^ applied to objects:
-- a (of class Symbol)
-- ^ 3 (of class ZZ)
currentString:2:2:(3):[13]: --back trace--
And this:
i1 : R = ZZ/101[a .. o];
i2 : f = genericMatrix(R, a, 3, 5)
../../../../Macaulay2/m2/methods.m2:37:35:(1):[15]: error: no method found for applying genericMatrix to:
argument 1 : R (of class PolynomialRing)
argument 2 : a (of class Symbol)
argument 3 : 3 (of class ZZ)
argument 4 : 5 (of class ZZ)
../../../../Macaulay2/m2/methods.m2:133:19:(1):[14]: --back trace--
currentString:2:5:(3):[13]: --back trace--
Now it's a mystery. What if you insert use R
?
Since capture doesn't crash anymore, I'll close this and open another one with a list of remaining issues.
This tool is potentially very powerful, but it crashes arbitrarily:
This happened in v1.15 too: