mirror of
https://github.com/enso-org/enso.git
synced 2024-12-24 19:03:27 +03:00
Fix re-exports of type constructors (#7724)
close #7674 Changelog: - fix: setting reexport field when serializing the library
This commit is contained in:
parent
ddbccd8764
commit
a1f2560491
@ -38,14 +38,9 @@ public final class ExportsMap {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public QualifiedName get(ExportedSymbol symbol) {
|
public Option<QualifiedName> get(Suggestion suggestion) {
|
||||||
return exportsMap.get(symbol);
|
|
||||||
}
|
|
||||||
|
|
||||||
public QualifiedName get(Suggestion suggestion) {
|
|
||||||
return ExportedSymbol.fromSuggestion(suggestion)
|
return ExportedSymbol.fromSuggestion(suggestion)
|
||||||
.flatMap(symbol -> Option.apply(exportsMap.get(symbol)))
|
.flatMap(symbol -> Option.apply(exportsMap.get(symbol)));
|
||||||
.getOrElse(() -> exportsMap.get(ExportedSymbol.suggestionModule(suggestion)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static QualifiedName getShortest(QualifiedName name1, QualifiedName name2) {
|
private static QualifiedName getShortest(QualifiedName name1, QualifiedName name2) {
|
||||||
|
@ -26,9 +26,7 @@ import java.util.logging.Level
|
|||||||
import scala.collection.mutable
|
import scala.collection.mutable
|
||||||
import scala.jdk.OptionConverters.RichOptional
|
import scala.jdk.OptionConverters.RichOptional
|
||||||
|
|
||||||
final class SerializationManager(
|
final class SerializationManager(compiler: Compiler) {
|
||||||
compiler: Compiler
|
|
||||||
) {
|
|
||||||
|
|
||||||
import SerializationManager._
|
import SerializationManager._
|
||||||
|
|
||||||
@ -260,7 +258,7 @@ final class SerializationManager(
|
|||||||
suggestions
|
suggestions
|
||||||
}
|
}
|
||||||
.map { suggestion =>
|
.map { suggestion =>
|
||||||
val reexport = Option(exportsMap.get(suggestion)).map(_.toString)
|
val reexport = exportsMap.get(suggestion).map(_.toString)
|
||||||
suggestion.withReexport(reexport)
|
suggestion.withReexport(reexport)
|
||||||
}
|
}
|
||||||
.foreach(suggestions.add)
|
.foreach(suggestions.add)
|
||||||
|
@ -0,0 +1,127 @@
|
|||||||
|
package org.enso.compiler;
|
||||||
|
|
||||||
|
import com.oracle.truffle.api.TruffleFile;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.concurrent.ExecutionException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
import java.util.concurrent.TimeoutException;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.enso.editions.LibraryName;
|
||||||
|
import org.enso.interpreter.runtime.EnsoContext;
|
||||||
|
import org.enso.interpreter.runtime.util.TruffleFileSystem;
|
||||||
|
import org.enso.interpreter.test.InterpreterContext;
|
||||||
|
import org.enso.pkg.Package;
|
||||||
|
import org.enso.pkg.PackageManager;
|
||||||
|
import org.enso.polyglot.LanguageInfo;
|
||||||
|
import org.enso.polyglot.MethodNames;
|
||||||
|
import org.enso.polyglot.Suggestion;
|
||||||
|
import org.junit.*;
|
||||||
|
|
||||||
|
public class SerializationManagerTest {
|
||||||
|
|
||||||
|
private static final long COMPILE_TIMEOUT_SECONDS = 20;
|
||||||
|
|
||||||
|
private final PackageManager<TruffleFile> packageManager;
|
||||||
|
private final InterpreterContext interpreterContext;
|
||||||
|
private final EnsoContext ensoContext;
|
||||||
|
|
||||||
|
public SerializationManagerTest() {
|
||||||
|
packageManager = new PackageManager<>(new TruffleFileSystem());
|
||||||
|
interpreterContext = new InterpreterContext(x -> x);
|
||||||
|
ensoContext =
|
||||||
|
interpreterContext
|
||||||
|
.ctx()
|
||||||
|
.getBindings(LanguageInfo.ID)
|
||||||
|
.invokeMember(MethodNames.TopScope.LEAK_CONTEXT)
|
||||||
|
.asHostObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
interpreterContext.ctx().initialize(LanguageInfo.ID);
|
||||||
|
interpreterContext.ctx().enter();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void teardown() {
|
||||||
|
interpreterContext.ctx().close();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path getLibraryPath(LibraryName libraryName) {
|
||||||
|
return Paths.get(
|
||||||
|
interpreterContext.languageHome(),
|
||||||
|
"..",
|
||||||
|
"lib",
|
||||||
|
libraryName.namespace(),
|
||||||
|
libraryName.name(),
|
||||||
|
interpreterContext.edition())
|
||||||
|
.toAbsolutePath()
|
||||||
|
.normalize();
|
||||||
|
}
|
||||||
|
|
||||||
|
private Package<TruffleFile> getLibraryPackage(LibraryName libraryName) {
|
||||||
|
Path libraryPath = getLibraryPath(libraryName);
|
||||||
|
TruffleFile libraryFile =
|
||||||
|
ensoContext.getEnvironment().getInternalTruffleFile(libraryPath.toString());
|
||||||
|
return packageManager.loadPackage(libraryFile).get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void clearLibraryCache(LibraryName libraryName) {
|
||||||
|
Path libraryCachePath = Paths.get(getLibraryPath(libraryName).toString(), ".enso");
|
||||||
|
FileUtils.deleteQuietly(libraryCachePath.toFile());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void serializeLibrarySuggestions()
|
||||||
|
throws ExecutionException, InterruptedException, TimeoutException {
|
||||||
|
SerializationManager serializationManager = new SerializationManager(ensoContext.getCompiler());
|
||||||
|
LibraryName standardBaseLibrary = new LibraryName("Standard", "Base");
|
||||||
|
Package<TruffleFile> standardBasePackage = getLibraryPackage(standardBaseLibrary);
|
||||||
|
ensoContext
|
||||||
|
.getPackageRepository()
|
||||||
|
.registerMainProjectPackage(standardBaseLibrary, standardBasePackage);
|
||||||
|
|
||||||
|
Object result =
|
||||||
|
ensoContext
|
||||||
|
.getCompiler()
|
||||||
|
.compile(false, false)
|
||||||
|
.get(COMPILE_TIMEOUT_SECONDS, TimeUnit.SECONDS);
|
||||||
|
Assert.assertEquals(Boolean.TRUE, result);
|
||||||
|
|
||||||
|
SuggestionsCache.CachedSuggestions cachedSuggestions =
|
||||||
|
serializationManager.deserializeSuggestions(standardBaseLibrary).get();
|
||||||
|
Assert.assertEquals(standardBaseLibrary, cachedSuggestions.getLibraryName());
|
||||||
|
|
||||||
|
Supplier<Stream<Suggestion.Constructor>> cachedConstructorSuggestions =
|
||||||
|
() ->
|
||||||
|
cachedSuggestions.getSuggestions().stream()
|
||||||
|
.flatMap(
|
||||||
|
suggestion -> {
|
||||||
|
if (suggestion instanceof Suggestion.Constructor constructor) {
|
||||||
|
return Stream.of(constructor);
|
||||||
|
}
|
||||||
|
return Stream.empty();
|
||||||
|
});
|
||||||
|
|
||||||
|
Suggestion.Constructor booleanTrueSuggestion =
|
||||||
|
cachedConstructorSuggestions
|
||||||
|
.get()
|
||||||
|
.filter(constructor -> constructor.name().equals("True"))
|
||||||
|
.findFirst()
|
||||||
|
.get();
|
||||||
|
Assert.assertEquals(scala.Some.apply("Standard.Base.Main"), booleanTrueSuggestion.reexport());
|
||||||
|
|
||||||
|
Suggestion.Constructor runtimeContextInputSuggestion =
|
||||||
|
cachedConstructorSuggestions
|
||||||
|
.get()
|
||||||
|
.filter(constructor -> constructor.name().equals("Input"))
|
||||||
|
.findFirst()
|
||||||
|
.get();
|
||||||
|
Assert.assertEquals(scala.None$.MODULE$, runtimeContextInputSuggestion.reexport());
|
||||||
|
|
||||||
|
clearLibraryCache(standardBaseLibrary);
|
||||||
|
}
|
||||||
|
}
|
@ -205,7 +205,7 @@ trait CompilerRunner {
|
|||||||
passConfiguration: Option[PassConfiguration] = None,
|
passConfiguration: Option[PassConfiguration] = None,
|
||||||
compilerConfig: CompilerConfig = defaultConfig,
|
compilerConfig: CompilerConfig = defaultConfig,
|
||||||
isGeneratingDocs: Boolean = false
|
isGeneratingDocs: Boolean = false
|
||||||
) = buildModuleContextModule(
|
): ModuleContext = buildModuleContextModule(
|
||||||
moduleName,
|
moduleName,
|
||||||
freshNameSupply,
|
freshNameSupply,
|
||||||
passConfiguration,
|
passConfiguration,
|
||||||
|
@ -108,6 +108,12 @@ class InterpreterContext(
|
|||||||
val in = new PipedInputStream(inOut)
|
val in = new PipedInputStream(inOut)
|
||||||
val sessionManager = new ReplaceableSessionManager
|
val sessionManager = new ReplaceableSessionManager
|
||||||
|
|
||||||
|
val languageHome = Paths
|
||||||
|
.get("../../test/micro-distribution/component")
|
||||||
|
.toFile
|
||||||
|
.getAbsolutePath
|
||||||
|
val edition = "0.0.0-dev"
|
||||||
|
|
||||||
val ctx = contextModifiers(
|
val ctx = contextModifiers(
|
||||||
Context
|
Context
|
||||||
.newBuilder(LanguageInfo.ID)
|
.newBuilder(LanguageInfo.ID)
|
||||||
@ -121,14 +127,8 @@ class InterpreterContext(
|
|||||||
.environment("NO_COLOR", "true")
|
.environment("NO_COLOR", "true")
|
||||||
.logHandler(System.err)
|
.logHandler(System.err)
|
||||||
.in(in)
|
.in(in)
|
||||||
.option(
|
.option(RuntimeOptions.LANGUAGE_HOME_OVERRIDE, languageHome)
|
||||||
RuntimeOptions.LANGUAGE_HOME_OVERRIDE,
|
.option(RuntimeOptions.EDITION_OVERRIDE, edition)
|
||||||
Paths
|
|
||||||
.get("../../test/micro-distribution/component")
|
|
||||||
.toFile
|
|
||||||
.getAbsolutePath
|
|
||||||
)
|
|
||||||
.option(RuntimeOptions.EDITION_OVERRIDE, "0.0.0-dev")
|
|
||||||
.serverTransport { (uri, peer) =>
|
.serverTransport { (uri, peer) =>
|
||||||
if (uri.toString == DebugServerInfo.URI) {
|
if (uri.toString == DebugServerInfo.URI) {
|
||||||
new DebuggerSessionManagerEndpoint(sessionManager, peer)
|
new DebuggerSessionManagerEndpoint(sessionManager, peer)
|
||||||
|
Loading…
Reference in New Issue
Block a user