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

Refactor CompilerTools into QueryCompiler #2808

Merged
merged 5 commits into from
Sep 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -3,8 +3,8 @@
import io.deephaven.UncheckedDeephavenException;

/**
* This exception is thrown when the thread-local QueryScope, QueryLibrary, or CompilerTools.Context are accessed from
* user-code without an explicit ExecutionContext.
* This exception is thrown when the thread-local QueryScope, QueryLibrary, or QueryCompiler are accessed from user-code
* without an explicit ExecutionContext.
*/
public final class NoExecutionContextRegisteredException extends UncheckedDeephavenException {
public NoExecutionContextRegisteredException() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ default Proxy proxy() {
*
* @apiNote {@code transformer} must be stateless, safe for concurrent use, and able to return a valid result for an
* empty input table. It is required to install an ExecutionContext to access any
* QueryLibrary/QueryScope/CompilerContext functionality from the {@code transformer}.
* QueryLibrary/QueryScope/QueryCompiler functionality from the {@code transformer}.
*
* @param transformer The {@link UnaryOperator} to apply to all constituent {@link Table tables}
* @return The new PartitionedTable containing the resulting constituents
Expand Down Expand Up @@ -245,7 +245,7 @@ default PartitionedTable transform(@NotNull UnaryOperator<Table> transformer) {
*
* @apiNote {@code transformer} must be stateless, safe for concurrent use, and able to return a valid result for
* empty input tables. It is required to install an ExecutionContext to access any
* QueryLibrary/QueryScope/CompilerContext functionality from the {@code transformer}.
* QueryLibrary/QueryScope/QueryCompiler functionality from the {@code transformer}.
*
* @param other The other PartitionedTable to find constituents in
* @param transformer The {@link BinaryOperator} to apply to all pairs of constituent {@link Table tables}
Expand Down Expand Up @@ -275,7 +275,7 @@ default PartitionedTable partitionedTransform(
* </ol>
* <p>
* {@code transformer} must be stateless, safe for concurrent use, and able to return a valid result for empty input
* tables. It is required to install an ExecutionContext to access any QueryLibrary/QueryScope/CompilerContext
* tables. It is required to install an ExecutionContext to access any QueryLibrary/QueryScope/QueryCompiler
* functionality from the {@code transformer}.
*
* @param other The other PartitionedTable to find constituents in
Expand Down
2 changes: 1 addition & 1 deletion engine/context/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ plugins {
id 'io.deephaven.project.register'
}

description 'Engine Context: QueryScope, QueryLibrary and CompilerTools via ExecutionContext'
description 'Engine Context: QueryScope, QueryLibrary and QueryCompiler via ExecutionContext'

configurations {
testCompile.extendsFrom junit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static ExecutionContext makeSystemicExecutionContext() {
return ExecutionContext.newBuilder()
.captureQueryScope()
.captureQueryLibrary()
.captureCompilerContext()
.captureQueryCompiler()
.markSystemic()
.build();
}
Expand All @@ -37,7 +37,7 @@ public static ExecutionContext createForUnitTests() {
.markSystemic()
.newQueryScope()
.newQueryLibrary()
.setCompilerContext(CompilerTools.createContextForUnitTests())
.setQueryCompiler(QueryCompiler.createForUnitTests())
.build();
}

Expand Down Expand Up @@ -96,17 +96,17 @@ static void setContext(final ExecutionContext context) {

private final QueryLibrary queryLibrary;
private final QueryScope queryScope;
private final CompilerTools.Context compilerContext;
private final QueryCompiler queryCompiler;

private ExecutionContext(
final boolean isSystemic,
final QueryLibrary queryLibrary,
final QueryScope queryScope,
final CompilerTools.Context compilerContext) {
final QueryCompiler queryCompiler) {
this.isSystemic = isSystemic;
this.queryLibrary = queryLibrary;
this.queryScope = queryScope;
this.compilerContext = compilerContext;
this.queryCompiler = queryCompiler;
}

/**
Expand Down Expand Up @@ -154,8 +154,8 @@ public QueryScope getQueryScope() {
return queryScope;
}

public CompilerTools.Context getCompilerContext() {
return compilerContext;
public QueryCompiler getQueryCompiler() {
return queryCompiler;
}

@SuppressWarnings("unused")
Expand All @@ -164,7 +164,7 @@ public static class Builder {

private QueryLibrary queryLibrary = PoisonedQueryLibrary.INSTANCE;
private QueryScope queryScope = PoisonedQueryScope.INSTANCE;
private CompilerTools.Context compilerContext = PoisonedCompilerToolsContext.INSTANCE;
private QueryCompiler queryCompiler = PoisonedQueryCompiler.INSTANCE;

/**
* A systemic execution context is one that is supplied by the system and not the user. A systemic context will
Expand Down Expand Up @@ -213,20 +213,20 @@ public Builder captureQueryLibrary() {
}

/**
* Use the provided CompilerTools.Context.
* Use the provided QueryCompiler
*/
@ScriptApi
public Builder setCompilerContext(final CompilerTools.Context compilerContext) {
this.compilerContext = compilerContext;
public Builder setQueryCompiler(final QueryCompiler queryCompiler) {
this.queryCompiler = queryCompiler;
return this;
}

/**
* Use the current ExecutionContext's CompilerTools.Context instance.
* Use the current ExecutionContext's QueryCompiler instance.
*/
@ScriptApi
public Builder captureCompilerContext() {
compilerContext = currentContext.get().getCompilerContext();
public Builder captureQueryCompiler() {
queryCompiler = currentContext.get().getQueryCompiler();
return this;
}

Expand Down Expand Up @@ -297,7 +297,7 @@ public Builder captureQueryScopeVars(String... vars) {
*/
@ScriptApi
public ExecutionContext build() {
return new ExecutionContext(isSystemic, queryLibrary, queryScope, compilerContext);
return new ExecutionContext(isSystemic, queryLibrary, queryScope, queryCompiler);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,49 +6,36 @@
import io.deephaven.internal.log.LoggerFactory;
import io.deephaven.io.logger.Logger;
import io.deephaven.util.NoExecutionContextRegisteredException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.File;
import java.util.Map;
import java.util.concurrent.CompletableFuture;

public class PoisonedCompilerToolsContext implements CompilerTools.Context {
private static final Logger logger = LoggerFactory.getLogger(PoisonedCompilerToolsContext.class);
public static final PoisonedCompilerToolsContext INSTANCE = new PoisonedCompilerToolsContext();
public class PoisonedQueryCompiler extends QueryCompiler {
private static final Logger logger = LoggerFactory.getLogger(PoisonedQueryCompiler.class);
public static final PoisonedQueryCompiler INSTANCE = new PoisonedQueryCompiler();

private PoisonedCompilerToolsContext() {}
private PoisonedQueryCompiler() {}

private <T> T fail() {
logger.error().append("No ExecutionContext provided; cannot use CompilerTools").endl();
logger.error().append("No ExecutionContext provided; cannot use QueryCompiler").endl();
throw new NoExecutionContextRegisteredException();
}

@Override
public Map<String, CompletableFuture<Class<?>>> getKnownClasses() {
return fail();
}

@Override
public ClassLoader getClassLoaderForFormula(Map<String, Class<?>> parameterClasses) {
return fail();
}

@Override
public File getClassDestination() {
public File getFakeClassDestination() {
return fail();
}

@Override
public String getClassPath() {
return fail();
public void setParentClassLoader(ClassLoader parentClassLoader) {
fail();
}

@Override
public File getFakeClassDestination() {
public Class<?> compile(@NotNull String className, @NotNull String classBody, @NotNull String packageNameRoot,
@Nullable StringBuilder codeLog, @NotNull Map<String, Class<?>> parameterClasses) {
return fail();
}

@Override
public void setParentClassLoader(ClassLoader parentClassLoader) {
fail();
}
}
Loading