Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow reassigning of BindingsMap #8190

Merged
merged 3 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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