Skip to content

Commit

Permalink
Allow reassigning of BindingsMap (#8190)
Browse files Browse the repository at this point in the history
Fixes #8186 by turning `IllegalStateException` into log message. Re-assigning of `BindingsMap` can happen in the IDE where evaluation of modules is repeated again and again. In addition to that avoid dropping errors in compiler without them being noticed.
  • Loading branch information
JaroslavTulach authored Oct 31, 2023
1 parent c1c4c8a commit f2cfd7f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,19 +99,31 @@ final class EnsureCompiledJob(
ctx: RuntimeContext,
logger: TruffleLogger
): Option[CompilationStatus] = {
compile(module)
applyEdits(new File(module.getPath)).map { changeset =>
compile(module)
.map { _ =>
invalidateCaches(module, changeset)
if (module.isIndexed) {
ctx.jobProcessor.runBackground(AnalyzeModuleJob(module, changeset))
} else {
AnalyzeModuleJob.analyzeModule(module, changeset)
}
runCompilationDiagnostics(module)
val result = compile(module)
result match {
case Left(ex) =>
logger.log(
Level.WARNING,
s"Error while ensureCompiledModule ${module.getName}",
ex
)
Some(CompilationStatus.Failure)
case _ =>
applyEdits(new File(module.getPath)).map { changeset =>
compile(module)
.map { _ =>
invalidateCaches(module, changeset)
if (module.isIndexed) {
ctx.jobProcessor.runBackground(
AnalyzeModuleJob(module, changeset)
)
} else {
AnalyzeModuleJob.analyzeModule(module, changeset)
}
runCompilationDiagnostics(module)
}
.getOrElse(CompilationStatus.Failure)
}
.getOrElse(CompilationStatus.Failure)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.oracle.truffle.api.TruffleFile;
import java.util.Optional;
import java.util.stream.StreamSupport;
import org.enso.interpreter.util.ScalaConversions;
import org.enso.pkg.Package;
import org.enso.pkg.QualifiedName;

Expand All @@ -20,7 +19,8 @@ private PackageRepositoryUtils() {}
*/
public static Optional<QualifiedName> getModuleNameForFile(
PackageRepository packageRepository, TruffleFile file) {
return ScalaConversions.asJava(packageRepository.getLoadedPackages()).stream()
return scala.jdk.javaapi.CollectionConverters.asJava(packageRepository.getLoadedPackages())
.stream()
.filter(pkg -> file.startsWith(pkg.sourceDir()))
.map(pkg -> pkg.moduleNameForFile(file))
.findFirst();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ public abstract static class Module {

public abstract Package<TruffleFile> getPackage();

public abstract boolean isSameAs(org.enso.interpreter.runtime.Module m);

public abstract QualifiedName getName();

public abstract BindingsMap getBindingsMap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.enso.compiler.core.ir.module.scope.Export;
import org.enso.compiler.data.BindingsMap;
import org.enso.compiler.pass.IRPass;
import org.enso.interpreter.util.ScalaConversions;
import scala.collection.immutable.Seq;
import scala.jdk.javaapi.CollectionConverters;

Expand Down Expand Up @@ -49,8 +48,10 @@ public Seq<IRPass> precursorPasses() {
}

@Override
@SuppressWarnings("unchecked")
public Seq<IRPass> invalidatedPasses() {
return ScalaConversions.nil();
Object obj = scala.collection.immutable.Nil$.MODULE$;
return (scala.collection.immutable.List<IRPass>) obj;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
import org.enso.compiler.context.InlineContext;
import org.enso.compiler.context.ModuleContext;
Expand All @@ -14,7 +13,6 @@
import org.enso.compiler.core.ir.module.scope.Import;
import org.enso.compiler.data.BindingsMap;
import org.enso.compiler.pass.IRPass;
import org.enso.interpreter.util.ScalaConversions;
import org.enso.pkg.QualifiedName;
import scala.Option;
import scala.collection.immutable.Seq;
Expand Down Expand Up @@ -55,8 +53,10 @@ public Seq<IRPass> precursorPasses() {
}

@Override
@SuppressWarnings("unchecked")
public Seq<IRPass> invalidatedPasses() {
return ScalaConversions.nil();
Object obj = scala.collection.immutable.Nil$.MODULE$;
return (scala.collection.immutable.List<IRPass>) obj;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ public void invalidateCache() {
public void close() {
if (map != null) {
if (module.bindings != null) {
throw new IllegalStateException("Reassigining bindings to " + module);
loggerCompiler.log(Level.FINE, "Reassigining bindings to {0}", module);
}
module.bindings = map;
}
Expand Down Expand Up @@ -384,11 +384,6 @@ final org.enso.interpreter.runtime.Module unsafeModule() {
return module;
}

@Override
public boolean isSameAs(org.enso.interpreter.runtime.Module m) {
return module == m;
}

@Override
public QualifiedName getName() {
return module.getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ class IrToTruffle(
if (
resolution.isInstanceOf[ResolvedConstructor] || !resolution.module
.unsafeAsModule()
.isSameAs(moduleScope.getModule)
.equals(moduleScope.getModule.asCompilerModule)
) {
resolution match {
case BindingsMap.ResolvedType(module, tp) =>
Expand Down

0 comments on commit f2cfd7f

Please sign in to comment.