Skip to content

Commit

Permalink
Merge branch 'topic/fix_benchmark' into 'master'
Browse files Browse the repository at this point in the history
Fix the LKQL benchmark module

Closes #400

See merge request eng/libadalang/langkit-query-language!370
  • Loading branch information
HugoGGuerrier committed Jan 6, 2025
2 parents 73fd852 + 50c0741 commit 4865ec4
Show file tree
Hide file tree
Showing 14 changed files with 29 additions and 96 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ public class ListComprehensionBenchmark extends TruffleBenchmark {
/** The source for the LKQL list comprehension value. */
private static final String lkqlSource =
"""
val generator = %s
val generator = [%s]
val result = [x * 2 for x in generator].to_list
""";

/** The fibonacci function in JS */
private static final String jsSource =
"""
var generator = %s;
var generator = [%s];
var result = generator.map(x => x * 2);
""";

Expand All @@ -55,7 +55,9 @@ public void setup() {
for (int i = 0; i < size; i++) {
this.generator[i] = i;
}
final String generatorLiteral = Arrays.toString(this.generator);
final String generatorLiteral =
String.join(
",\n", Arrays.stream(this.generator).mapToObj(Integer::toString).toList());
this.lkqlListComp = lkqlSource.formatted(generatorLiteral);
this.jsListComp = jsSource.formatted(generatorLiteral);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,14 @@ public void patchContext(TruffleLanguage.Env newEnv) {
public LKQLOptions getOptions() {
if (this.options == null) {
final var optionsSource = this.env.getOptions().get(LKQLLanguage.options);
final var jsonObject = new JSONObject(new JSONTokener(optionsSource));
this.options = LKQLOptions.fromJson(jsonObject);

// If the "lkql.options" value is empty, get default options.
if (!optionsSource.isBlank()) {
final var jsonObject = new JSONObject(new JSONTokener(optionsSource));
this.options = LKQLOptions.fromJson(jsonObject);
} else {
this.options = LKQLOptions.getDefault();
}
}
return this.options;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public final class LKQLLanguage extends TruffleLanguage<LKQLContext> {
help = "Options for the LKQL engine as a JSON object",
category = OptionCategory.INTERNAL,
stability = OptionStability.STABLE)
static final OptionKey<String> options = new OptionKey<>("{}");
static final OptionKey<String> options = new OptionKey<>("");

Liblkqllang.AnalysisContext lkqlAnalysisContext;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public static LKQLOptions fromJson(JSONObject jsonLKQLOptions) {
AutoFixMode.valueOf(jsonLKQLOptions.getString("autoFixMode")));
}

/** Get a default options instance. */
public static LKQLOptions getDefault() {
return new Builder().build();
}

// ----- Instance methods -----

/** Serialize the LKQL options to a JSON object. */
Expand Down
10 changes: 1 addition & 9 deletions testsuite/tests/interop/function/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ private static void print(String messageName, Object value) {
}

public static void main(String[] args) {
Context context = Context
.newBuilder("lkql")
.option(
"lkql.options", new LKQLOptions.Builder()
.projectFile("default_project/default.gpr")
.build()
.toJson()
.toString()
).build();
Context context = Context.newBuilder("lkql").build();
Value executable = context.parse("lkql", LKQL_SOURCE);

Value namespace = executable.execute(false);
Expand Down
10 changes: 1 addition & 9 deletions testsuite/tests/interop/iterator/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,7 @@ private static void print(String messageName, Object value) {
}

public static void main(String[] args) {
Context context = Context
.newBuilder("lkql")
.option(
"lkql.options", new LKQLOptions.Builder()
.projectFile("default_project/default.gpr")
.build()
.toJson()
.toString()
).build();
Context context = Context.newBuilder("lkql").build();
Value executable = context.parse("lkql", "val list = [1, \"Hello\", [1, 2]]");

Value namespace = executable.execute(false);
Expand Down
10 changes: 1 addition & 9 deletions testsuite/tests/interop/list/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@ private static void print(String messageName, Object value) {
}

public static void main(String[] args) {
Context context = Context
.newBuilder("lkql")
.option(
"lkql.options", new LKQLOptions.Builder()
.projectFile("default_project/default.gpr")
.build()
.toJson()
.toString()
).build();
Context context = Context.newBuilder("lkql").build();
Value executable = context.parse("lkql", LKQL_SOURCE);

Value namespace = executable.execute(false);
Expand Down
10 changes: 1 addition & 9 deletions testsuite/tests/interop/list_comp/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@ private static void print(String messageName, Object value) {
}

public static void main(String[] args) {
Context context = Context
.newBuilder("lkql")
.option(
"lkql.options", new LKQLOptions.Builder()
.projectFile("default_project/default.gpr")
.build()
.toJson()
.toString()
).build();
Context context = Context.newBuilder("lkql").build();
Value executable = context.parse("lkql", LKQL_SOURCE);

Value namespace = executable.execute(false);
Expand Down
10 changes: 1 addition & 9 deletions testsuite/tests/interop/namespace/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ private static void print(String messageName, Object value) {
}

public static void main(String[] args) {
Context context = Context
.newBuilder("lkql")
.option(
"lkql.options", new LKQLOptions.Builder()
.projectFile("default_project/default.gpr")
.build()
.toJson()
.toString()
).build();
Context context = Context.newBuilder("lkql").build();
Value executable = context.parse("lkql", LKQL_SOURCE);

Value namespace = executable.execute(false);
Expand Down
10 changes: 1 addition & 9 deletions testsuite/tests/interop/null/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ private static void print(String messageName, Object value) {
}

public static void main(String[] args) {
Context context = Context
.newBuilder("lkql")
.option(
"lkql.options", new LKQLOptions.Builder()
.projectFile("default_project/default.gpr")
.build()
.toJson()
.toString()
).build();
Context context = Context.newBuilder("lkql").build();
Value executable = context.parse("lkql", LKQL_SOURCE);

Value namespace = executable.execute(false);
Expand Down
10 changes: 1 addition & 9 deletions testsuite/tests/interop/object/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ private static void print(String messageName, Object value) {
}

public static void main(String[] args) {
Context context = Context
.newBuilder("lkql")
.option(
"lkql.options", new LKQLOptions.Builder()
.projectFile("default_project/default.gpr")
.build()
.toJson()
.toString()
).build();
Context context = Context.newBuilder("lkql").build();
Value executable = context.parse("lkql", LKQL_SOURCE);

Value namespace = executable.execute(false);
Expand Down
10 changes: 1 addition & 9 deletions testsuite/tests/interop/pattern/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ private static void print(String messageName, Object value) {
}

public static void main(String[] args) {
Context context = Context
.newBuilder("lkql")
.option(
"lkql.options", new LKQLOptions.Builder()
.projectFile("default_project/default.gpr")
.build()
.toJson()
.toString()
).build();
Context context = Context.newBuilder("lkql").build();
Value executable = context.parse("lkql", LKQL_SOURCE);

Value namespace = executable.execute(false);
Expand Down
10 changes: 1 addition & 9 deletions testsuite/tests/interop/tuple/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ private static void print(String messageName, Object value) {
}

public static void main(String[] args) {
Context context = Context
.newBuilder("lkql")
.option(
"lkql.options", new LKQLOptions.Builder()
.projectFile("default_project/default.gpr")
.build()
.toJson()
.toString()
).build();
Context context = Context.newBuilder("lkql").build();
Value executable = context.parse("lkql", LKQL_SOURCE);

Value namespace = executable.execute(false);
Expand Down
10 changes: 1 addition & 9 deletions testsuite/tests/interop/unit/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,7 @@ private static void print(String messageName, Object value) {
}

public static void main(String[] args) {
Context context = Context
.newBuilder("lkql")
.option(
"lkql.options", new LKQLOptions.Builder()
.projectFile("default_project/default.gpr")
.build()
.toJson()
.toString()
).build();
Context context = Context.newBuilder("lkql").build();
Value executable = context.parse("lkql", LKQL_SOURCE);

Value namespace = executable.execute(false);
Expand Down

0 comments on commit 4865ec4

Please sign in to comment.