Skip to content

Commit

Permalink
Merge branch 'backend'
Browse files Browse the repository at this point in the history
  • Loading branch information
programLyrique committed Dec 10, 2024
2 parents dfc3f68 + 71c7c81 commit 31046ce
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 93 deletions.
4 changes: 0 additions & 4 deletions .settings/org.eclipse.jdt.apt.core.prefs

This file was deleted.

4 changes: 4 additions & 0 deletions client/rsh/R/rsh.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ rsh_compile <- function(f, options) {
options$tier <- "optimized"
}

if(is.null(options$cache)) {
options$cache <- TRUE
}

invisible(.Call(C_compile, f, options))
}

Expand Down
1 change: 1 addition & 0 deletions client/rsh/src/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Client::remote_compile(std::vector<uint8_t> const &rds_closure,
request.set_bc_opt(options.bc_opt);
request.mutable_function()->set_name(options.name);
request.set_cc_opt(options.cc_opt);
request.set_no_cache(!options.cache);
request.mutable_function()->set_body(rds_closure.data(), rds_closure.size());

// We replace the body of a function with its compiled version so it would not
Expand Down
3 changes: 3 additions & 0 deletions client/rsh/src/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ CompilerOptions CompilerOptions::from_list(SEXP listsxp) {
} else if (!strcmp(name, "inplace")) {
opts.inplace =
vec_element_as_bool(listsxp, i, "inplace option must be a logical");
} else if (!strcmp(name, "cache")) {
opts.cache =
vec_element_as_bool(listsxp, i, "cache option must be a logical");
} else if (!strcmp(name, "tier")) {
SEXP tier_sxp = VECTOR_ELT(listsxp, i);
if (TYPEOF(tier_sxp) != STRSXP) {
Expand Down
1 change: 1 addition & 0 deletions client/rsh/src/compiler.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ struct CompilerOptions {
int bc_opt = 3;
int cc_opt = 3;
bool inplace;
bool cache = true;
protocol::Tier tier = protocol::Tier::OPTIMIZED;

static CompilerOptions from_list(SEXP listsxp);
Expand Down
203 changes: 116 additions & 87 deletions client/rsh/src/messages.pb.cc

Large diffs are not rendered by default.

31 changes: 31 additions & 0 deletions client/rsh/src/messages.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions proto/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ message CompileRequest {
optional int32 bc_opt = 6;// for the bytecode. Native does bytecode first so this is also need when compiling to native
optional Context context = 7;
optional Environment environment = 8;//The values of all the bindings that statically appear in the function
bool no_cache = 9;//If true, the server will not cache the result
}

message CompileResponse {
Expand Down
12 changes: 10 additions & 2 deletions server/src/main/java/org/prlprg/server/CompileService.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,18 @@ public void compile(
+ " Serialized size = "
+ request.getSerializedSize());

if (request.getNoCache()) {
logger.info("This closure will not be cached (but it might vae already been).");
}

// Compile the code and build response
Messages.CompileResponse.Builder response = Messages.CompileResponse.newBuilder();
response.setTier(tier);
response.setHash(function.getHash());

// Cache requests
NativeClosure ccCached = null;

var nativeKey = Triple.of(function.getHash(), bcOpt, ccOpt);
if (tier.equals(Messages.Tier.OPTIMIZED)) {
ccCached = nativeCache.get(nativeKey);
Expand Down Expand Up @@ -146,7 +151,7 @@ public void compile(
+ function.getName()
+ ". Not caching and returning the original body.");
// We will keep the code field empty
} else {
} else if (!request.getNoCache()) { // We do not cache if the client does not want to
serializedBc = RDSWriter.writeByteString(SEXPs.bcode(bc.get()));
response.setCode(serializedBc);
bcCached =
Expand Down Expand Up @@ -202,7 +207,10 @@ public void compile(
ccCached =
new NativeClosure(
ByteString.copyFrom(res), module.topLevelFunName(), serializedConstantPool);
nativeCache.put(nativeKey, ccCached);

if (!request.getNoCache()) {
nativeCache.put(nativeKey, ccCached);
}
response.setCode(ccCached.code());
response.setConstants(ccCached.constantPool());
} catch (Exception e) {
Expand Down
1 change: 1 addition & 0 deletions server/src/main/proto/messages.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ message CompileRequest {
optional int32 bc_opt = 6;// for the bytecode. Native does bytecode first so this is also need when compiling to native
optional Context context = 7;
optional Environment environment = 8;//The values of all the bindings that statically appear in the function
bool no_cache = 9;//If true, the server will not cache the result
}

message CompileResponse {
Expand Down

0 comments on commit 31046ce

Please sign in to comment.