-
Notifications
You must be signed in to change notification settings - Fork 326
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Store whole IR.Module in .bindings cache
- Loading branch information
1 parent
41c7b5a
commit 6803429
Showing
9 changed files
with
128 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
engine/runtime/src/main/java/org/enso/interpreter/caches/CacheUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package org.enso.interpreter.caches; | ||
|
||
import java.io.IOException; | ||
import java.util.UUID; | ||
import java.util.function.Function; | ||
|
||
import org.enso.compiler.context.CompilerContext; | ||
import org.enso.compiler.core.ir.ProcessingPass; | ||
|
||
final class CacheUtils { | ||
private CacheUtils() { | ||
} | ||
|
||
static Function<Object, Object> writeReplace(CompilerContext context) { | ||
return (obj) -> switch (obj) { | ||
case ProcessingPass.Metadata metadata -> metadata.prepareForSerialization(context); | ||
case UUID _ -> null; | ||
case null -> null; | ||
default -> obj; | ||
}; | ||
} | ||
|
||
static Function<Object, Object> readResolve(CompilerContext context) { | ||
return (obj) -> switch (obj) { | ||
case ProcessingPass.Metadata metadata -> { | ||
var option = metadata.restoreFromSerialization(context); | ||
if (option.nonEmpty()) { | ||
yield option.get(); | ||
} else { | ||
throw raise( | ||
RuntimeException.class, new IOException("Cannot convert " + metadata)); | ||
} | ||
} | ||
case null -> null; | ||
default -> obj; | ||
}; | ||
|
||
} | ||
|
||
@SuppressWarnings("unchecked") | ||
static <T extends Exception> T raise(Class<T> cls, Exception e) throws T { | ||
throw (T) e; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.