Closed apblack closed 5 years ago
I have also seen this happening in an interesting situation. I created a directory of files using a zip file exported from the web IDE. Because of a timezone issue, all of the source files were timestamped tomorrow. This meant that even after a file was compiled, the object file was not newer than the source file. Thus, it was compiled again — several times (once for each import) — for a single top-level compilation.
Unless one turns on --verbose
, it seems like the compiler is just running very slowly.
Here is a concrete scenario where this issue arrises.
Two modules being compiled import ast. Source file ast.grace is in directory .., while object file ast.js is in /usr/local/lib/grace/modules. Source is newer than object, so source is recompiled. There is no --dir flag, so new object file also goes in directory ..
The snag: GRACE_MODULE_PATH=/usr/local/lib/grace/modules/:../js:..:../js/tests
Hence, next time the sources are compiled, the out-of-date object file is again found, since it is on GRACE_MODULE_PATH
ahead of the up-to-date one.
I think that the way this ought to work is that we look for the first .grace file on the GRACE_MODULE_PATH
. That is the file we should be using, because we have said that Grace programs are represented as source, and several other implementations are interpreters. If we can't find a compiled version of that file that corresponds to that source, we have to compiler it again. We look for the compiled version on the same path, but we should not look for the first compiled version on the path — we should look for a version that has the same SHA as the source.
This means computing the SHA and putting it in the name of the compiled file, or at least inside the file.
An alternative solution is to change the way that the object-file is sought. Instead of looking for the first file on the path, and checking that it is newer than the source, we could instead look for the first file on the path that is newer than the source, simply ignoring all older files (which can't possibly help us). This might give us the wrong file, but it won't cause multiple compilations (assuming that we add any --dir argument to the path).
This is resolved by commit 0cf0402, which used a SHA-256 checksum to find an appropriate compiled code file, ignoring file times.
See also issue #293, which I hope is resolved by the same commit.
This is the inverse of #230. If there is an out-of date .js file on GRACE_MODULE_PATH, here is what can happen.
Notice that collectionsPrelude.grace is re-compiled twice. An out-of-date version is found in /pkgs/minigrace/lib/grace/modules/./collectionsPrelude.js, which is therefore recompiled, creating a new binary in /pkgs/minigrace/source/, the same directory in which the source code was found.
However, the next time that collectionsPrelude is checked, the same thing happens again; the freshly compiled version is not found. This is because the current
GRACE_MODULE_PATH
does not contain the current directory.
Why, then, is the source code found in the current directory? There must be some inconsistency as to if, and where, the current directory is added to the search path.