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

Fixes to Persistance #10101

Merged
merged 27 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d08f80a
add test for storing NULL reference
radeusgd May 23, 2024
caf213a
fix storing NULL references
radeusgd May 23, 2024
4a7e358
add test for serializing a deserialized loop (it used to be failing)
radeusgd May 24, 2024
b867051
try fixing by making the writer aware of the inner type of the Reference
radeusgd May 24, 2024
86a08a4
simplify supertype search
radeusgd May 24, 2024
db4ec13
Revert "try fixing by making the writer aware of the inner type of th…
radeusgd May 24, 2024
6600f60
store Persistance Ids next to references
radeusgd May 24, 2024
d073c3d
add debug info
radeusgd May 24, 2024
63f4e8a
enable asserts in persistance tests
radeusgd May 27, 2024
4c7e444
fix sizes after protocol update
radeusgd May 27, 2024
fb3f6ce
rename for clarity
radeusgd May 27, 2024
8376869
introduce InlineReference
radeusgd May 27, 2024
3d9bd75
better error message
radeusgd May 27, 2024
57d98bf
move java List persistance to IrPersistance
radeusgd May 27, 2024
ca1fd9d
count InlineReferences instead of Sequences
radeusgd May 27, 2024
6d68b8a
update test
radeusgd May 27, 2024
12e7cf3
ensure persistance of List and Seq is aligned
radeusgd May 27, 2024
65adea6
cleanup after cherry pick
radeusgd May 27, 2024
f50063b
update count at the right moment
radeusgd May 27, 2024
e74d7ea
cleanup
radeusgd May 27, 2024
1de43b1
null
radeusgd May 27, 2024
1a2b251
Avoid storing unnecessary integer for NULL references, make the code …
radeusgd May 27, 2024
f0e9ffa
Merge branch 'refs/heads/develop' into wip/radeusgd/cycles-in-persist…
radeusgd May 28, 2024
3f8e144
Exposing just a single Persistance.Reference abstraction (#10117)
JaroslavTulach Jun 1, 2024
86adcfb
Merge branch 'refs/heads/develop' into wip/radeusgd/cycles-in-persist…
radeusgd Jun 8, 2024
f239249
add missing persistance module to language-server tests
radeusgd Jun 8, 2024
38b21c4
Merge branch 'refs/heads/develop' into wip/radeusgd/cycles-in-persist…
radeusgd Jun 10, 2024
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
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -1258,6 +1258,7 @@ lazy val `persistance` = (project in file("lib/java/persistance"))
commands += WithDebugCommand.withDebug,
frgaalJavaCompilerSetting,
Compile / javacOptions := ((Compile / javacOptions).value),
inConfig(Compile)(truffleRunOptionsSettings),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you.

libraryDependencies ++= Seq(
"org.slf4j" % "slf4j-api" % slf4jVersion,
"org.netbeans.api" % "org-openide-util-lookup" % netbeansApiVersion,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package org.enso.compiler.core.ir;

import java.io.IOException;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;
Expand Down Expand Up @@ -192,33 +194,89 @@ protected Double readObject(Input in) throws IOException, ClassNotFoundException
}
}

/**
* The persistance for Scala List is needed, because some places expect the more general List type
* instead of Seq.
*
* <p>Because List is a subtype of Seq and can be deserialized using any of the two persistance
* implementations, we want to ensure that the format of both is compatible. Seq is generally
* preferred as it can be lazy.
*/
@ServiceProvider(service = Persistance.class)
public static final class PersistScalaList extends Persistance<List> {
public PersistScalaList() {
super(List.class, true, 4432);
}

private final PersistScalaSeq underlying = new PersistScalaSeq();

@Override
protected void writeObject(List list, Output out) throws IOException {
underlying.writeObject(list, out);
}

@Override
@SuppressWarnings("unchecked")
protected List readObject(Input in) throws IOException, ClassNotFoundException {
// Algorithm that is aligned with `underlying`, but is not lazy.
var builder = List.newBuilder();
var size = in.readInt();
for (var i = 0; i < size; i++) {
var elem = in.readObject();
builder.addOne(elem);
}
return builder.result();
}
}

/**
* Persistance for Java List.
*
* <p>When reading back, the deserialization is done lazily.
*/
@ServiceProvider(service = Persistance.class)
public static final class PersistJavaListLazy extends Persistance<java.util.List> {
public PersistJavaListLazy() {
super(java.util.List.class, true, 34011);
}

@Override
protected void writeObject(java.util.List list, Output out) throws IOException {
var size = list.size();
out.writeInt(size);
var l = list.reverse();
for (var i = 0; i < size; i++) {
out.writeObject(l.head());
l = (List) l.tail();
out.writeObject(list.get(i));
}
}

@Override
@SuppressWarnings("unchecked")
protected List readObject(Input in) throws IOException, ClassNotFoundException {
protected java.util.List readObject(Input in) throws IOException, ClassNotFoundException {
var size = in.readInt();
List list = scala.collection.immutable.Nil$.MODULE$;
var references = new ArrayList<Reference<Object>>(size);
for (var i = 0; i < size; i++) {
var elem = in.readObject();
list = scala.collection.immutable.$colon$colon$.MODULE$.apply(elem, list);
var elem = in.readReference(Object.class);
references.add(elem);
}

return new ListOfReferences(references);
}

private static class ListOfReferences extends AbstractList<Object> {
private final java.util.List<Reference<Object>> references;

public ListOfReferences(java.util.List<Reference<Object>> references) {
this.references = references;
}

@Override
public Object get(int index) {
return references.get(index).get(Object.class);
}

@Override
public int size() {
return references.size();
}
return list;
}
}

Expand Down Expand Up @@ -351,11 +409,12 @@ public PersistScalaSeq() {
}

@Override
protected void writeObject(Seq list, Output out) throws IOException {
var size = list.size();
protected void writeObject(Seq seq, Output out) throws IOException {
var size = seq.size();
out.writeInt(size);
for (var i = 0; i < size; i++) {
out.writeObject(list.apply(i));
var it = seq.iterator();
while (it.hasNext()) {
out.writeObject(it.next());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package org.enso.compiler.core.ir

import org.enso.compiler.core.Implicits.{ShowPassData, ToStringHelper}
import org.enso.compiler.core.{IR, Identifier}
import org.enso.persist.Persistance

import java.util.UUID

Expand Down Expand Up @@ -36,22 +37,24 @@ object Function {
* better optimisation.
*
* @param arguments the arguments to the lambda
* @param body the body of the lambda
* @param bodyReference the body of the lambda, stored as a reference to ensure
* laziness of storage
* @param location the source location that the node corresponds to
* @param canBeTCO whether or not the function can be tail-call optimised
* @param passData the pass metadata associated with this node
* @param diagnostics compiler diagnostics for this node
*/
sealed case class Lambda(
override val arguments: List[DefinitionArgument],
bodySeq: Seq[Expression],
bodyReference: Persistance.Reference[Expression],
location: Option[IdentifiedLocation],
override val canBeTCO: Boolean,
passData: MetadataStorage,
diagnostics: DiagnosticStorage
) extends Function
with IRKind.Primitive
with LazyId {

def this(
arguments: List[DefinitionArgument],
body: Expression,
Expand All @@ -60,9 +63,17 @@ object Function {
passData: MetadataStorage = new MetadataStorage(),
diagnostics: DiagnosticStorage = new DiagnosticStorage()
) = {
this(arguments, Seq(body), location, canBeTCO, passData, diagnostics)
this(
arguments,
Persistance.Reference.of(body, true),
location,
canBeTCO,
passData,
diagnostics
)
}
override lazy val body = bodySeq.head

override lazy val body: Expression = bodyReference.get(classOf[Expression])

/** Creates a copy of `this`.
*
Expand All @@ -85,7 +96,14 @@ object Function {
id: UUID @Identifier = id
): Lambda = {
val res =
Lambda(arguments, Seq(body), location, canBeTCO, passData, diagnostics)
Lambda(
arguments,
Persistance.Reference.of(body, false),
location,
canBeTCO,
passData,
diagnostics
)
res.id = id
res
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package definition

import org.enso.compiler.core.Implicits.{ShowPassData, ToStringHelper}
import org.enso.compiler.core.{IR, Identifier}
import org.enso.persist.Persistance

import java.util.UUID

Expand Down Expand Up @@ -41,14 +42,14 @@ object Method {
/** The definition of a method for a given constructor.
*
* @param methodReference a reference to the method being defined
* @param body the body of the method
* @param bodyReference the body of the method
* @param location the source location that the node corresponds to
* @param passData the pass metadata associated with this node
* @param diagnostics compiler diagnostics for this node
*/
sealed case class Explicit(
override val methodReference: Name.MethodReference,
val bodySeq: Seq[Expression],
val bodyReference: Persistance.Reference[Expression],
val isStatic: Boolean,
val isStaticWrapperForInstanceMethod: Boolean,
override val location: Option[IdentifiedLocation],
Expand All @@ -66,7 +67,7 @@ object Method {
) = {
this(
methodReference,
Seq(body),
Persistance.Reference.of(body, false),
Explicit.computeIsStatic(body),
Explicit.computeIsStaticWrapperForInstanceMethod(body),
location,
Expand All @@ -75,7 +76,7 @@ object Method {
);
}

lazy val body = bodySeq.head
lazy val body: Expression = bodyReference.get(classOf[Expression])

/** Creates a copy of `this`.
*
Expand All @@ -100,7 +101,7 @@ object Method {
): Explicit = {
val res = Explicit(
methodReference,
List(body),
Persistance.Reference.of(body, false),
isStatic,
isStaticWrapperForInstanceMethod,
location,
Expand Down
Loading
Loading