Serialize UUID for non-library modules (#9057)

Missing ID's in IR meant that instrumentation wouldn't be applied for loaded modules. This is the reason why after a restart engine wouldn't send **any** expression updates.

Closes #8689.

# Important Notes
After the change
[Kazam_screencast_00038.webm](https://github.com/enso-org/enso/assets/292128/4249287b-6c41-4c9d-b138-e7af59512566)

The video somehow doesn't show that all nodes are loaded after the restart, but once I moved the screen they are there. This appears to be a bug in the recording somehow.
This commit is contained in:
Hubert Plociniczak 2024-02-15 17:50:27 +01:00 committed by GitHub
parent 6746bdc148
commit d29c2cd66a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 29 additions and 33 deletions

View File

@ -23,7 +23,7 @@ import scala.annotation.unused
*/
@SerialVersionUID(
8160L // Use BindingsMap
9057L // Use BindingsMap
)
case class BindingsMap(
definedEntities: List[DefinedEntity],

View File

@ -30,7 +30,7 @@ import scala.collection.immutable.List;
*/
public interface IR extends Serializable {
long serialVersionUID = 8145L; // Scala to Java
long serialVersionUID = 9057L; // Scala to Java
/**
* Storage for metadata that the node has been tagged with as the result of various compiler

View File

@ -20,7 +20,7 @@ import java.util.UUID
* @param diagnostics compiler diagnostics for this node
*/
@SerialVersionUID(
8160L // Use BindingsMap
9057L // Use BindingsMap
) // prevents reading broken caches, see PR-3692 for details
final case class Module(
imports: List[Import],

View File

@ -1,5 +1,6 @@
package org.enso.interpreter.caches;
import com.oracle.truffle.api.TruffleFile;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.security.MessageDigest;
@ -8,29 +9,27 @@ import java.util.Comparator;
import java.util.List;
import java.util.UUID;
import java.util.function.Function;
import org.enso.compiler.context.CompilerContext;
import org.enso.compiler.core.ir.ProcessingPass;
import org.enso.pkg.SourceFile;
import org.enso.text.Hex;
import com.oracle.truffle.api.TruffleFile;
final class CacheUtils {
private CacheUtils() {
}
private CacheUtils() {}
static Function<Object, Object> writeReplace(CompilerContext context) {
return (obj) -> switch (obj) {
static Function<Object, Object> writeReplace(CompilerContext context, boolean keepUUIDs) {
return (obj) ->
switch (obj) {
case ProcessingPass.Metadata metadata -> metadata.prepareForSerialization(context);
case UUID _ -> null;
case UUID id -> keepUUIDs ? id : null;
case null -> null;
default -> obj;
};
}
static Function<Object, Object> readResolve(CompilerContext context) {
return (obj) -> switch (obj) {
return (obj) ->
switch (obj) {
case ProcessingPass.Metadata metadata -> {
var option = metadata.restoreFromSerialization(context);
if (option.nonEmpty()) {
@ -75,9 +74,7 @@ final class CacheUtils {
* @param pkgSources the list of package sources
* @return string representation of bytes' hash
*/
static final String computeDigestOfLibrarySources(
List<SourceFile<TruffleFile>> pkgSources
) {
static final String computeDigestOfLibrarySources(List<SourceFile<TruffleFile>> pkgSources) {
pkgSources.sort(Comparator.comparing(o -> o.qualifiedName().toString()));
try {
@ -95,5 +92,4 @@ final class CacheUtils {
static <T extends Exception> T raise(Class<T> cls, Exception e) throws T {
throw (T) e;
}
}

View File

@ -65,7 +65,7 @@ public final class ImportExportCache
public byte[] serialize(EnsoContext context, CachedBindings entry) throws IOException {
var arr =
Persistance.write(
entry.bindings(), CacheUtils.writeReplace(context.getCompiler().context()));
entry.bindings(), CacheUtils.writeReplace(context.getCompiler().context(), false));
return arr;
}

View File

@ -60,7 +60,7 @@ public final class ModuleCache
public byte[] serialize(EnsoContext context, CachedModule entry) throws IOException {
var arr =
Persistance.write(
entry.moduleIR(), CacheUtils.writeReplace(context.getCompiler().context()));
entry.moduleIR(), CacheUtils.writeReplace(context.getCompiler().context(), true));
return arr;
}