Skip to content

Commit 4865ec4

Browse files
committed
Merge branch 'topic/fix_benchmark' into 'master'
Fix the LKQL benchmark module Closes #400 See merge request eng/libadalang/langkit-query-language!370
2 parents 73fd852 + 50c0741 commit 4865ec4

File tree

14 files changed

+29
-96
lines changed

14 files changed

+29
-96
lines changed

lkql_jit/benchmarks/src/test/java/com/adacore/lkql_jit/benchmarks/ListComprehensionBenchmark.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ public class ListComprehensionBenchmark extends TruffleBenchmark {
3131
/** The source for the LKQL list comprehension value. */
3232
private static final String lkqlSource =
3333
"""
34-
val generator = %s
34+
val generator = [%s]
3535
val result = [x * 2 for x in generator].to_list
3636
""";
3737

3838
/** The fibonacci function in JS */
3939
private static final String jsSource =
4040
"""
41-
var generator = %s;
41+
var generator = [%s];
4242
var result = generator.map(x => x * 2);
4343
""";
4444

@@ -55,7 +55,9 @@ public void setup() {
5555
for (int i = 0; i < size; i++) {
5656
this.generator[i] = i;
5757
}
58-
final String generatorLiteral = Arrays.toString(this.generator);
58+
final String generatorLiteral =
59+
String.join(
60+
",\n", Arrays.stream(this.generator).mapToObj(Integer::toString).toList());
5961
this.lkqlListComp = lkqlSource.formatted(generatorLiteral);
6062
this.jsListComp = jsSource.formatted(generatorLiteral);
6163
}

lkql_jit/language/src/main/java/com/adacore/lkql_jit/LKQLContext.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,14 @@ public void patchContext(TruffleLanguage.Env newEnv) {
246246
public LKQLOptions getOptions() {
247247
if (this.options == null) {
248248
final var optionsSource = this.env.getOptions().get(LKQLLanguage.options);
249-
final var jsonObject = new JSONObject(new JSONTokener(optionsSource));
250-
this.options = LKQLOptions.fromJson(jsonObject);
249+
250+
// If the "lkql.options" value is empty, get default options.
251+
if (!optionsSource.isBlank()) {
252+
final var jsonObject = new JSONObject(new JSONTokener(optionsSource));
253+
this.options = LKQLOptions.fromJson(jsonObject);
254+
} else {
255+
this.options = LKQLOptions.getDefault();
256+
}
251257
}
252258
return this.options;
253259
}

lkql_jit/language/src/main/java/com/adacore/lkql_jit/LKQLLanguage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public final class LKQLLanguage extends TruffleLanguage<LKQLContext> {
9191
help = "Options for the LKQL engine as a JSON object",
9292
category = OptionCategory.INTERNAL,
9393
stability = OptionStability.STABLE)
94-
static final OptionKey<String> options = new OptionKey<>("{}");
94+
static final OptionKey<String> options = new OptionKey<>("");
9595

9696
Liblkqllang.AnalysisContext lkqlAnalysisContext;
9797

lkql_jit/options/src/main/java/com/adacore/lkql_jit/options/LKQLOptions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,11 @@ public static LKQLOptions fromJson(JSONObject jsonLKQLOptions) {
122122
AutoFixMode.valueOf(jsonLKQLOptions.getString("autoFixMode")));
123123
}
124124

125+
/** Get a default options instance. */
126+
public static LKQLOptions getDefault() {
127+
return new Builder().build();
128+
}
129+
125130
// ----- Instance methods -----
126131

127132
/** Serialize the LKQL options to a JSON object. */

testsuite/tests/interop/function/Main.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,7 @@ private static void print(String messageName, Object value) {
1313
}
1414

1515
public static void main(String[] args) {
16-
Context context = Context
17-
.newBuilder("lkql")
18-
.option(
19-
"lkql.options", new LKQLOptions.Builder()
20-
.projectFile("default_project/default.gpr")
21-
.build()
22-
.toJson()
23-
.toString()
24-
).build();
16+
Context context = Context.newBuilder("lkql").build();
2517
Value executable = context.parse("lkql", LKQL_SOURCE);
2618

2719
Value namespace = executable.execute(false);

testsuite/tests/interop/iterator/Main.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,7 @@ private static void print(String messageName, Object value) {
88
}
99

1010
public static void main(String[] args) {
11-
Context context = Context
12-
.newBuilder("lkql")
13-
.option(
14-
"lkql.options", new LKQLOptions.Builder()
15-
.projectFile("default_project/default.gpr")
16-
.build()
17-
.toJson()
18-
.toString()
19-
).build();
11+
Context context = Context.newBuilder("lkql").build();
2012
Value executable = context.parse("lkql", "val list = [1, \"Hello\", [1, 2]]");
2113

2214
Value namespace = executable.execute(false);

testsuite/tests/interop/list/Main.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@ private static void print(String messageName, Object value) {
1414
}
1515

1616
public static void main(String[] args) {
17-
Context context = Context
18-
.newBuilder("lkql")
19-
.option(
20-
"lkql.options", new LKQLOptions.Builder()
21-
.projectFile("default_project/default.gpr")
22-
.build()
23-
.toJson()
24-
.toString()
25-
).build();
17+
Context context = Context.newBuilder("lkql").build();
2618
Value executable = context.parse("lkql", LKQL_SOURCE);
2719

2820
Value namespace = executable.execute(false);

testsuite/tests/interop/list_comp/Main.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,7 @@ private static void print(String messageName, Object value) {
1414
}
1515

1616
public static void main(String[] args) {
17-
Context context = Context
18-
.newBuilder("lkql")
19-
.option(
20-
"lkql.options", new LKQLOptions.Builder()
21-
.projectFile("default_project/default.gpr")
22-
.build()
23-
.toJson()
24-
.toString()
25-
).build();
17+
Context context = Context.newBuilder("lkql").build();
2618
Value executable = context.parse("lkql", LKQL_SOURCE);
2719

2820
Value namespace = executable.execute(false);

testsuite/tests/interop/namespace/Main.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,7 @@ private static void print(String messageName, Object value) {
1313
}
1414

1515
public static void main(String[] args) {
16-
Context context = Context
17-
.newBuilder("lkql")
18-
.option(
19-
"lkql.options", new LKQLOptions.Builder()
20-
.projectFile("default_project/default.gpr")
21-
.build()
22-
.toJson()
23-
.toString()
24-
).build();
16+
Context context = Context.newBuilder("lkql").build();
2517
Value executable = context.parse("lkql", LKQL_SOURCE);
2618

2719
Value namespace = executable.execute(false);

testsuite/tests/interop/null/Main.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,7 @@ private static void print(String messageName, Object value) {
1313
}
1414

1515
public static void main(String[] args) {
16-
Context context = Context
17-
.newBuilder("lkql")
18-
.option(
19-
"lkql.options", new LKQLOptions.Builder()
20-
.projectFile("default_project/default.gpr")
21-
.build()
22-
.toJson()
23-
.toString()
24-
).build();
16+
Context context = Context.newBuilder("lkql").build();
2517
Value executable = context.parse("lkql", LKQL_SOURCE);
2618

2719
Value namespace = executable.execute(false);

0 commit comments

Comments
 (0)