Skip to content

Commit

Permalink
Report errors when generating indexes (#6123)
Browse files Browse the repository at this point in the history
`--compile` command would run the compilation pipeline but silently omit any encountered errors, thus skipping the serialization. This maybe was a good idea in the past but it was problematic now that we generate indexes on build time.
This resulted in rather obscure errors (#6092) for modules that were missing their caches.

The change should significantly improve developers' experience when working on stdlib.

# Important Notes
Making compilation more resilient to sudden cache misses is a separate item to be worked on.
  • Loading branch information
hubertp authored Mar 30, 2023
1 parent ef45b6e commit 90612cf
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 20 deletions.
27 changes: 26 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2120,7 +2120,32 @@ buildEngineDistribution := {
editionName = currentEdition,
sourceStdlibVersion = stdLibVersion,
targetStdlibVersion = targetStdlibVersion,
targetDir = (`syntax-rust-definition` / rustParserTargetDirectory).value
targetDir = (`syntax-rust-definition` / rustParserTargetDirectory).value,
generateIndex = true
)
log.info(s"Engine package created at $root")
}

lazy val buildEngineDistributionNoIndex =
taskKey[Unit]("Builds the engine distribution without generating indexes")
buildEngineDistributionNoIndex := {
val _ = (`engine-runner` / assembly).value
updateLibraryManifests.value
val root = engineDistributionRoot.value
val log = streams.value.log
val cacheFactory = streams.value.cacheStoreFactory
DistributionPackage.createEnginePackage(
distributionRoot = root,
cacheFactory = cacheFactory,
log = log,
graalVersion = graalVersion,
javaVersion = javaVersion,
ensoVersion = ensoVersion,
editionName = currentEdition,
sourceStdlibVersion = stdLibVersion,
targetStdlibVersion = targetStdlibVersion,
targetDir = (`syntax-rust-definition` / rustParserTargetDirectory).value,
generateIndex = false
)
log.info(s"Engine package created at $root")
}
Expand Down
14 changes: 10 additions & 4 deletions engine/runner/src/main/scala/org/enso/runner/Main.scala
Original file line number Diff line number Diff line change
Expand Up @@ -502,13 +502,19 @@ object Main {
logLevel,
logMasking,
enableIrCaches = true,
strictErrors = true,
useGlobalIrCacheLocation = shouldUseGlobalCache
)
val topScope = context.getTopScope
topScope.compile(shouldCompileDependencies)

context.context.close()
exitSuccess()
try {
topScope.compile(shouldCompileDependencies)
exitSuccess()
} catch {
case _: Throwable =>
exitFail()
} finally {
context.context.close()
}
}

/** Handles the `--run` CLI option.
Expand Down
5 changes: 2 additions & 3 deletions engine/runtime/src/main/java/org/enso/compiler/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ private Optional<T> loadCacheFrom(
if (cachedObject != null) {
return Optional.of(cachedObject);
} else {
logger.log(logLevel, "`" + logName + "` was corrupt on disk.");
logger.log(logLevel, "`{0}` was corrupt on disk.", logName);
invalidateCache(cacheRoot, logger);
return Optional.empty();
}
Expand All @@ -276,8 +276,7 @@ private Optional<T> loadCacheFrom(
return Optional.empty();
}
} else {
logger.log(
logLevel, "One or more digests did not match for the cache for [" + logName + "].");
logger.log(logLevel, "One or more digests did not match for the cache for [{0}].", logName);
invalidateCache(cacheRoot, logger);
return Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import java.io.File;
import java.util.Collection;
import java.util.Optional;
import java.util.concurrent.ExecutionException;

import org.enso.compiler.PackageRepository;
import org.enso.interpreter.EnsoLanguage;
import org.enso.interpreter.runtime.EnsoContext;
Expand Down Expand Up @@ -173,9 +175,13 @@ private static Object compile(Object[] arguments, EnsoContext context)
.getOptions()
.get(RuntimeOptions.USE_GLOBAL_IR_CACHE_LOCATION_KEY);
boolean shouldCompileDependencies = Types.extractArguments(arguments, Boolean.class);
context.getCompiler().compile(shouldCompileDependencies, useGlobalCache);

return true;
try {
return context.getCompiler().compile(shouldCompileDependencies, useGlobalCache).get();
} catch (InterruptedException e) {
throw new RuntimeException(e);
} catch (ExecutionException e) {
throw new RuntimeException(e);
}
}

@Specialization
Expand Down
21 changes: 12 additions & 9 deletions project/DistributionPackage.scala
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ object DistributionPackage {
editionName: String,
sourceStdlibVersion: String,
targetStdlibVersion: String,
targetDir: File
targetDir: File,
generateIndex: Boolean
): Unit = {
copyDirectoryIncremental(
file("distribution/engine/THIRD-PARTY"),
Expand Down Expand Up @@ -171,14 +172,16 @@ object DistributionPackage {
javaVersion = javaVersion
)

indexStdLibs(
stdLibVersion = targetStdlibVersion,
ensoVersion = ensoVersion,
stdLibRoot = distributionRoot / "lib",
ensoExecutable = distributionRoot / "bin" / "enso",
cacheFactory = cacheFactory.sub("stdlib"),
log = log
)
if (generateIndex) {
indexStdLibs(
stdLibVersion = targetStdlibVersion,
ensoVersion = ensoVersion,
stdLibRoot = distributionRoot / "lib",
ensoExecutable = distributionRoot / "bin" / "enso",
cacheFactory = cacheFactory.sub("stdlib"),
log = log
)
}
}

def indexStdLibs(
Expand Down

0 comments on commit 90612cf

Please sign in to comment.