Skip to content

Commit 643c97e

Browse files
committed
Merge branch 'topic/refactor_diagnostics' into 'master'
Refactor how diagnostics are handled in lkql_jit See merge request eng/libadalang/langkit-query-language!224
2 parents d714bb1 + 1ee35dc commit 643c97e

File tree

166 files changed

+950
-1284
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

166 files changed

+950
-1284
lines changed

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ endif
2828
ADDITIONAL_MANAGE_ARGS=
2929

3030
# WARNING: Note that for some reason parallelizing the build still doesn't work
31-
all: lkql gnatcheck lkql_native_jit doc
31+
all: lkql gnatcheck build_lkql_native_jit doc
3232

3333
lkql: build/bin/liblkqllang_parse
3434

35-
doc: lkql_native_jit
35+
doc: build_lkql_native_jit
3636
cd user_manual && make clean html
3737

3838
gnatcheck: lkql
@@ -52,11 +52,11 @@ clean_lkql:
5252
clean_lkql_jit:
5353
cd lkql_jit && $(MAVEN) clean
5454

55-
lkql_jit: lkql
55+
build_lkql_jit: lkql
5656
$(MAVEN) -f lkql/build/java/ install
5757
$(MAVEN) -f lkql_jit/ clean install
5858

59-
lkql_native_jit: lkql
59+
build_lkql_native_jit: lkql
6060
$(MAVEN) -f lkql/build/java/ install
6161
$(MAVEN) -f lkql_jit/ clean install -P native,$(BUILD_MODE)
6262

lkql_checker/share/lkql/kp/KP-S621-051.lkql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ fun kp_s621_051(node) =
88
node is ParamAssoc(
99
parent: AssocList(parent: c@CallExpr(
1010
p_is_call(): true
11-
) when c.f_name.p_referenced_decl() is decl@BasicDecl(
11+
) when c.f_name.p_referenced_decl() is decl@BasicDecl(
1212
p_has_aspect("Import"): false
13-
) when stdlib.enclosing_body(decl) == stdlib.enclosing_body(node)
13+
) when stdlib.enclosing_body(decl) == stdlib.enclosing_body(node)
1414
),
15-
15+
1616
f_r_expr: Name(
17-
p_referenced_decl(): ParamSpec,
18-
p_expression_type(): AnonymousTypeDecl(p_is_access_type(): true)
17+
p_referenced_decl(): ParamSpec,
18+
p_expression_type(): AnonymousTypeDecl(p_is_access_type(): true)
1919
)
2020
)

lkql_checker/share/lkql/kp/KP-T420-033.lkql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ import stdlib
55
@check(message="possible occurrence of KP T420-033", impact="18.*,19.*,20.1")
66
fun kp_t420_033(node) =
77
node is ComponentDecl
8-
when node.p_semantic_parent().p_is_tagged_type()
8+
when node.p_semantic_parent() is BaseTypeDecl(p_is_tagged_type(): true)
99
and node.f_component_def.f_type_expr is s@SubtypeIndication
1010
when stdlib.has_non_default_sso(s.f_name.p_referenced_decl())

lkql_checker/share/lkql/kp/KP-U928-018.lkql

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
@check(message="possible occurrence of KP U928-018", impact="22.*,23.1")
55
fun kp_u928_018(node) =
6-
node is ForLoopStmt(f_spec: spec@ForLoopSpec(
7-
f_loop_type: IterTypeOf)
6+
node is ForLoopStmt(
7+
f_spec: spec@ForLoopSpec(f_loop_type: IterTypeOf)
88
# Find a CallExpr whose f_name's type has a Constant_Indexing aspect
99
when (from spec select first c@CallExpr
1010
when c.f_name.p_expression_type() is ConcreteTypeDecl(
1111
p_has_aspect("Constant_Indexing"): true))
12+
)

lkql_checker/share/lkql/kp/KP-V616-018.lkql

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,5 @@ fun kp_v616_018(node) =
1616
f_name: n@Name
1717
when access_to_unconstrained_array(n.p_referenced_decl())) |
1818
a@AnonymousType when access_to_unconstrained_array(a.f_type_decl)
19+
)
20+
)

lkql_checker/src/gnatcheck-compiler.adb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,18 +336,23 @@ package body Gnatcheck.Compiler is
336336
Msg (File_Idx .. Idx - 1) &
337337
Msg (Idx + 7 .. Last - 2) &
338338
Annotate_Rule (All_Rules.Table (Id).all),
339-
Diagnosis_Kind =>
340-
(if Last - Idx > 21
341-
and then Msg (Idx + 7 .. Idx + 20) = "internal error"
342-
then Internal_Error else Rule_Violation),
339+
Diagnosis_Kind => Rule_Violation,
343340
SF => SF,
344341
Rule => Id);
345342
return;
346343
end;
347344
elsif Msg (Idx .. Idx + 6) = "error: " then
348345
Message_Kind := Error;
346+
347+
if Msg'Last - Idx > 21
348+
and then Msg (Idx + 7 .. Idx + 20) = "internal error"
349+
then
350+
Kind := Internal_Error;
351+
else
352+
Kind := Compiler_Error;
353+
end if;
354+
349355
Errors := True;
350-
Kind := Compiler_Error;
351356

352357
elsif Msg (Idx .. Idx + 8) = "warning: " then
353358
if Index (Msg (Idx .. Msg'Last), ": violation of restriction") /= 0

lkql_jit/cli/src/main/java/com/adacore/lkql_jit/drivers/LKQLLauncher.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,9 @@ protected int executeScript(Context.Builder contextBuilder) {
226226
System.err.println("File not found : " + this.args.script);
227227
return 2;
228228
} catch (Exception e) {
229+
System.err.println(e.getMessage());
229230
if (this.args.verbose) {
230231
e.printStackTrace();
231-
} else {
232-
System.err.println(e.getMessage());
233232
}
234233
return 0;
235234
}

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import com.adacore.lkql_jit.utils.Constants;
1818
import com.adacore.lkql_jit.utils.functions.ArrayUtils;
1919
import com.adacore.lkql_jit.utils.functions.StringUtils;
20+
import com.adacore.lkql_jit.utils.source_location.LalLocationWrapper;
2021
import com.oracle.truffle.api.CompilerDirectives;
2122
import com.oracle.truffle.api.TruffleLanguage;
2223
import com.oracle.truffle.api.source.Source;
@@ -44,6 +45,8 @@ public final class LKQLContext {
4445
/** The global values of the LKQL execution. */
4546
private final GlobalScope global;
4647

48+
public final CheckerUtils.SourceLinesCache linesCache = new CheckerUtils.SourceLinesCache();
49+
4750
// ----- Ada project attributes -----
4851

4952
/** The analysis context for the ada files. */
@@ -55,10 +58,14 @@ public final class LKQLContext {
5558
/** Event handler for the project manager. */
5659
private final Libadalang.EventHandler eventHandler =
5760
Libadalang.EventHandler.create(
58-
(ctx, name, from, found, not_found_is_error) -> {
59-
if (!found && not_found_is_error) {
61+
(ctx, name, from, found, notFoundIsError) -> {
62+
if (!found && notFoundIsError) {
6063
boolean isFatal = !this.keepGoingOnMissingFile();
61-
this.getDiagnosticEmitter().emitMissingFile(from, name, isFatal, this);
64+
this.getDiagnosticEmitter()
65+
.emitFileNotFound(
66+
new LalLocationWrapper(from.getRoot(), this.linesCache),
67+
name,
68+
notFoundIsError);
6269
if (isFatal) {
6370
this.env.getContext().closeExited(null, 1);
6471
}
@@ -508,7 +515,7 @@ public void initSources() {
508515
this.specifiedSourceFiles.add(sourceFile.getAbsolutePath());
509516
} else {
510517
this.getDiagnosticEmitter()
511-
.emitMissingFile(null, file, !this.keepGoingOnMissingFile(), this);
518+
.emitFileNotFound(null, file, this.keepGoingOnMissingFile());
512519
}
513520
}
514521
}

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

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import com.adacore.liblkqllang.Liblkqllang;
99
import com.adacore.lkql_jit.built_ins.values.LKQLNamespace;
10+
import com.adacore.lkql_jit.checker.utils.CheckerUtils;
1011
import com.adacore.lkql_jit.exception.LKQLRuntimeException;
1112
import com.adacore.lkql_jit.langkit_translator.passes.FramingPass;
1213
import com.adacore.lkql_jit.langkit_translator.passes.TranslationPass;
@@ -17,6 +18,7 @@
1718
import com.adacore.lkql_jit.runtime.GlobalScope;
1819
import com.adacore.lkql_jit.utils.Constants;
1920
import com.adacore.lkql_jit.utils.enums.DiagnosticOutputMode;
21+
import com.adacore.lkql_jit.utils.source_location.SourceSectionWrapper;
2022
import com.oracle.truffle.api.CallTarget;
2123
import com.oracle.truffle.api.Option;
2224
import com.oracle.truffle.api.TruffleLanguage;
@@ -323,9 +325,6 @@ protected OptionDescriptors getOptionDescriptors() {
323325
return new LKQLLanguageOptionDescriptors();
324326
}
325327

326-
/**
327-
* @see com.oracle.truffle.api.TruffleLanguage#parse(ParsingRequest)
328-
*/
329328
@Override
330329
protected CallTarget parse(ParsingRequest request) {
331330
final Liblkqllang.AnalysisUnit unit;
@@ -341,9 +340,22 @@ protected CallTarget parse(ParsingRequest request) {
341340
}
342341

343342
// Verify the parsing result
344-
final Liblkqllang.Diagnostic[] diagnostics = unit.getDiagnostics();
343+
final var diagnostics = unit.getDiagnostics();
345344
if (diagnostics.length > 0) {
346-
throw LKQLRuntimeException.parsingException(diagnostics, request.getSource());
345+
var ctx = LKQLLanguage.getContext(null);
346+
347+
// Iterate over diagnostics
348+
for (Liblkqllang.Diagnostic diagnostic : diagnostics) {
349+
ctx.getDiagnosticEmitter()
350+
.emitDiagnostic(
351+
CheckerUtils.MessageKind.ERROR,
352+
diagnostic.message.toString(),
353+
null,
354+
SourceSectionWrapper.create(
355+
diagnostic.sourceLocationRange, request.getSource()));
356+
}
357+
throw LKQLRuntimeException.fromMessage(
358+
"Syntax errors in " + unit.getFileName(false) + ": stopping interpreter");
347359
}
348360

349361
// Get the LKQL langkit AST
@@ -357,7 +369,10 @@ protected CallTarget parse(ParsingRequest request) {
357369
// Print the Truffle AST if the JIT is in debug mode
358370
if (getContext(result).isVerbose()) {
359371
System.out.println(
360-
"=== Truffle AST <" + result.getLocation().getFileName() + "> :\n" + result);
372+
"=== Truffle AST <"
373+
+ result.getSourceSection().getSource().getPath()
374+
+ "> :\n"
375+
+ result);
361376
}
362377

363378
// Return the call target

lkql_jit/language/src/main/java/com/adacore/lkql_jit/built_ins/values/LKQLFunction.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ public String lkqlProfile() {
191191
for (int i = 0; i < parameterNames.length; i++) {
192192
var defVal = parameterDefaultValues[i];
193193
if (defVal != null) {
194-
expandedParams.add(parameterNames[i] + "=" + defVal.getLocation().getText());
194+
expandedParams.add(
195+
parameterNames[i]
196+
+ "="
197+
+ defVal.getSourceSection().getCharacters().toString());
195198
} else {
196199
expandedParams.add(parameterNames[i]);
197200
}

0 commit comments

Comments
 (0)