Description
This is a continuation of #1469.
Currently many examples in the documentation of "Macaulay2Doc" are being generated using capture, however, there are still a number of remaining issues when using capture for generating examples, each one is being avoided by one of the lines below:
M2/M2/Macaulay2/m2/examples.m2
Lines 159 to 171 in 2d48ff6
I think it's fairly safe to use capture for other packages as well, but I think it would require a closer review before doing that for every package.
- The string
-* no-capture-flag *-
is used to single out specific examples that aren't excluded by any other keyword. Currently, only the following examples have this tag:
- (Grassmannian, ZZ, ZZ) and "finite fields", because they use the option
Variable => T
in the following lines:
GF (ZZ/2[T]/(T^9+T+1), Variable => T) -* no-capture-flag *-",
J = Grassmannian(2,5, CoefficientRing => ZZ/31, Variable => T) -* no-capture-flag *-
. As it turns out, the variable "T" (and only this one!) is particularly annoying. See #1627 (comment)
- "new", because it includes this line which has a permanent effect by adding a new method:
new Type of BasicList from Function := (A,B,f) -> hashTable { net => f }; -* no-capture-flag *-
-
capture still doesn't capture direct printing to either stderr or stdout, hence why any keyword that affects those is currently excluded, like
gbTrace, stderr, stdio, print, <<
. -
examples that use
notify
may be changed if a file is already loaded, so those are excluded, examples that usestopIfError
anddebuggingMode
are also likely not going to work yet, unless there's some sort of time limit to interrupt capture. -
Certain actions have a permanent effect:
GlobalAssignHook, GlobalReleaseHook, installMethod
-
export, newPackage, read, run
aren't well tested yet, the same withschedule, thread, *Task
. -
load
in effect prevents any of the checks above from working, so it has to be excluded -
temporaryFileName
is buggy when the same process uses it repeatedly, so it is excluded, but can probably be fixed. -
ThreadedGB and RunExternalM2 packages probably shouldn't use capture anyway.
TODO:
A few things listed above can be fixed, but to reiterate, I think the following are the important ones:
- fix capturing toplevel stderr (see e37f272 and 8ad88cd)
- fix capturing printing of nets (see 8f9aff6)
- fix capturing output directly from engine (printf, cerr, cout, etc.)
- let capture work in a re-initialized thread, with re-initialized thread local variables, etc.
- when that is done, run multiple examples in parallel
- use
capture
forcheck
(see Speeding up running the tests #1708) - let capture enforce time limits, memory limits, etc.
- use capture for memory leak detection and memory benchmarking! (see Too many heap sections capturing check(8, "DiffAlg") on armhf #1728)
- make sure capture can be interrupted without exiting M2 (should
debuggingMode
andstopIfError
be thread local?)
I already have made changes in capture
to save and restore the values of all exported mutable symbols from all packages, but I'm not confident that this entirely eliminates the risk of capturing one example from affecting the result of future examples.