Skip to content

Commit

Permalink
Merge pull request #1959 from informalsystems/shon/tmp-dir-for-sany
Browse files Browse the repository at this point in the history
Set a unique java.io.tmpdir for each call to SANY
  • Loading branch information
Shon Feder committed Jul 12, 2022
2 parents 2a60f81 + 35e7ad2 commit 6cd7f6a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .unreleased/bug-fixes/1959-sany-tmpdir.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add workaround for Sany parsing failures when running parallel instances of
Apalache (see #1959)
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,13 @@ class SanyImporter(sourceStore: SourceStore, annotationStore: AnnotationStore) e
// Resolver for filenames, patched for wired modules.
val filenameResolver = SanyNameToStream(libraryPaths)

// Set a unique tmpdir to avoid race-condition in SANY
// TODO: RM once https://github.com/tlaplus/tlaplus/issues/688 is fixed
System.setProperty("java.io.tmpdir", sanyTempDir().toString())

// call SANY
val specObj = new SpecObj(file.getAbsolutePath, filenameResolver)

SANY.frontEndMain(
specObj,
file.getAbsolutePath,
Expand Down Expand Up @@ -99,8 +104,7 @@ class SanyImporter(sourceStore: SourceStore, annotationStore: AnnotationStore) e
* the pair (the root module name, a map of modules)
*/
def loadFromSource(source: Source, aux: Seq[Source] = Seq()): (String, Map[String, TlaModule]) = {
val tempDir = Files.createTempDirectory("sanyimp").toFile

val tempDir = sanyTempDir()
val nameAndModule = for {
(rootName, rootFile) <- saveTlaFile(tempDir, source)
// Save the aux modules to files, and get just the module names, if errors are hit, the first one will turn into a `Try`
Expand All @@ -113,6 +117,9 @@ class SanyImporter(sourceStore: SourceStore, annotationStore: AnnotationStore) e
nameAndModule.get
}

// Create a unique temp directory for use by the SANY importer
private def sanyTempDir() = Files.createTempDirectory("sanyimp").toFile

private def ensureModuleNamesAreUnique(moduleNames: Seq[String]): Try[Unit] = {
val duplicateNames = moduleNames.groupBy(identity).filter(_._2.size > 1)
if (duplicateNames.isEmpty) {
Expand Down

0 comments on commit 6cd7f6a

Please sign in to comment.