Skip to content

Commit

Permalink
Merge branch 'topic/refactor_diagnostics' into 'master'
Browse files Browse the repository at this point in the history
Refactor how diagnostics are handled in lkql_jit

See merge request eng/libadalang/langkit-query-language!224
  • Loading branch information
raph-amiard committed May 17, 2024
2 parents d714bb1 + 1ee35dc commit 643c97e
Show file tree
Hide file tree
Showing 166 changed files with 950 additions and 1,284 deletions.
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ endif
ADDITIONAL_MANAGE_ARGS=

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

lkql: build/bin/liblkqllang_parse

doc: lkql_native_jit
doc: build_lkql_native_jit
cd user_manual && make clean html

gnatcheck: lkql
Expand All @@ -52,11 +52,11 @@ clean_lkql:
clean_lkql_jit:
cd lkql_jit && $(MAVEN) clean

lkql_jit: lkql
build_lkql_jit: lkql
$(MAVEN) -f lkql/build/java/ install
$(MAVEN) -f lkql_jit/ clean install

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

Expand Down
10 changes: 5 additions & 5 deletions lkql_checker/share/lkql/kp/KP-S621-051.lkql
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ fun kp_s621_051(node) =
node is ParamAssoc(
parent: AssocList(parent: c@CallExpr(
p_is_call(): true
) when c.f_name.p_referenced_decl() is decl@BasicDecl(
) when c.f_name.p_referenced_decl() is decl@BasicDecl(
p_has_aspect("Import"): false
) when stdlib.enclosing_body(decl) == stdlib.enclosing_body(node)
) when stdlib.enclosing_body(decl) == stdlib.enclosing_body(node)
),

f_r_expr: Name(
p_referenced_decl(): ParamSpec,
p_expression_type(): AnonymousTypeDecl(p_is_access_type(): true)
p_referenced_decl(): ParamSpec,
p_expression_type(): AnonymousTypeDecl(p_is_access_type(): true)
)
)
2 changes: 1 addition & 1 deletion lkql_checker/share/lkql/kp/KP-T420-033.lkql
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ import stdlib
@check(message="possible occurrence of KP T420-033", impact="18.*,19.*,20.1")
fun kp_t420_033(node) =
node is ComponentDecl
when node.p_semantic_parent().p_is_tagged_type()
when node.p_semantic_parent() is BaseTypeDecl(p_is_tagged_type(): true)
and node.f_component_def.f_type_expr is s@SubtypeIndication
when stdlib.has_non_default_sso(s.f_name.p_referenced_decl())
5 changes: 3 additions & 2 deletions lkql_checker/share/lkql/kp/KP-U928-018.lkql
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

@check(message="possible occurrence of KP U928-018", impact="22.*,23.1")
fun kp_u928_018(node) =
node is ForLoopStmt(f_spec: spec@ForLoopSpec(
f_loop_type: IterTypeOf)
node is ForLoopStmt(
f_spec: spec@ForLoopSpec(f_loop_type: IterTypeOf)
# Find a CallExpr whose f_name's type has a Constant_Indexing aspect
when (from spec select first c@CallExpr
when c.f_name.p_expression_type() is ConcreteTypeDecl(
p_has_aspect("Constant_Indexing"): true))
)
2 changes: 2 additions & 0 deletions lkql_checker/share/lkql/kp/KP-V616-018.lkql
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,5 @@ fun kp_v616_018(node) =
f_name: n@Name
when access_to_unconstrained_array(n.p_referenced_decl())) |
a@AnonymousType when access_to_unconstrained_array(a.f_type_decl)
)
)
15 changes: 10 additions & 5 deletions lkql_checker/src/gnatcheck-compiler.adb
Original file line number Diff line number Diff line change
Expand Up @@ -336,18 +336,23 @@ package body Gnatcheck.Compiler is
Msg (File_Idx .. Idx - 1) &
Msg (Idx + 7 .. Last - 2) &
Annotate_Rule (All_Rules.Table (Id).all),
Diagnosis_Kind =>
(if Last - Idx > 21
and then Msg (Idx + 7 .. Idx + 20) = "internal error"
then Internal_Error else Rule_Violation),
Diagnosis_Kind => Rule_Violation,
SF => SF,
Rule => Id);
return;
end;
elsif Msg (Idx .. Idx + 6) = "error: " then
Message_Kind := Error;

if Msg'Last - Idx > 21
and then Msg (Idx + 7 .. Idx + 20) = "internal error"
then
Kind := Internal_Error;
else
Kind := Compiler_Error;
end if;

Errors := True;
Kind := Compiler_Error;

elsif Msg (Idx .. Idx + 8) = "warning: " then
if Index (Msg (Idx .. Msg'Last), ": violation of restriction") /= 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,9 @@ protected int executeScript(Context.Builder contextBuilder) {
System.err.println("File not found : " + this.args.script);
return 2;
} catch (Exception e) {
System.err.println(e.getMessage());
if (this.args.verbose) {
e.printStackTrace();
} else {
System.err.println(e.getMessage());
}
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.adacore.lkql_jit.utils.Constants;
import com.adacore.lkql_jit.utils.functions.ArrayUtils;
import com.adacore.lkql_jit.utils.functions.StringUtils;
import com.adacore.lkql_jit.utils.source_location.LalLocationWrapper;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.TruffleLanguage;
import com.oracle.truffle.api.source.Source;
Expand Down Expand Up @@ -44,6 +45,8 @@ public final class LKQLContext {
/** The global values of the LKQL execution. */
private final GlobalScope global;

public final CheckerUtils.SourceLinesCache linesCache = new CheckerUtils.SourceLinesCache();

// ----- Ada project attributes -----

/** The analysis context for the ada files. */
Expand All @@ -55,10 +58,14 @@ public final class LKQLContext {
/** Event handler for the project manager. */
private final Libadalang.EventHandler eventHandler =
Libadalang.EventHandler.create(
(ctx, name, from, found, not_found_is_error) -> {
if (!found && not_found_is_error) {
(ctx, name, from, found, notFoundIsError) -> {
if (!found && notFoundIsError) {
boolean isFatal = !this.keepGoingOnMissingFile();
this.getDiagnosticEmitter().emitMissingFile(from, name, isFatal, this);
this.getDiagnosticEmitter()
.emitFileNotFound(
new LalLocationWrapper(from.getRoot(), this.linesCache),
name,
notFoundIsError);
if (isFatal) {
this.env.getContext().closeExited(null, 1);
}
Expand Down Expand Up @@ -508,7 +515,7 @@ public void initSources() {
this.specifiedSourceFiles.add(sourceFile.getAbsolutePath());
} else {
this.getDiagnosticEmitter()
.emitMissingFile(null, file, !this.keepGoingOnMissingFile(), this);
.emitFileNotFound(null, file, this.keepGoingOnMissingFile());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import com.adacore.liblkqllang.Liblkqllang;
import com.adacore.lkql_jit.built_ins.values.LKQLNamespace;
import com.adacore.lkql_jit.checker.utils.CheckerUtils;
import com.adacore.lkql_jit.exception.LKQLRuntimeException;
import com.adacore.lkql_jit.langkit_translator.passes.FramingPass;
import com.adacore.lkql_jit.langkit_translator.passes.TranslationPass;
Expand All @@ -17,6 +18,7 @@
import com.adacore.lkql_jit.runtime.GlobalScope;
import com.adacore.lkql_jit.utils.Constants;
import com.adacore.lkql_jit.utils.enums.DiagnosticOutputMode;
import com.adacore.lkql_jit.utils.source_location.SourceSectionWrapper;
import com.oracle.truffle.api.CallTarget;
import com.oracle.truffle.api.Option;
import com.oracle.truffle.api.TruffleLanguage;
Expand Down Expand Up @@ -323,9 +325,6 @@ protected OptionDescriptors getOptionDescriptors() {
return new LKQLLanguageOptionDescriptors();
}

/**
* @see com.oracle.truffle.api.TruffleLanguage#parse(ParsingRequest)
*/
@Override
protected CallTarget parse(ParsingRequest request) {
final Liblkqllang.AnalysisUnit unit;
Expand All @@ -341,9 +340,22 @@ protected CallTarget parse(ParsingRequest request) {
}

// Verify the parsing result
final Liblkqllang.Diagnostic[] diagnostics = unit.getDiagnostics();
final var diagnostics = unit.getDiagnostics();
if (diagnostics.length > 0) {
throw LKQLRuntimeException.parsingException(diagnostics, request.getSource());
var ctx = LKQLLanguage.getContext(null);

// Iterate over diagnostics
for (Liblkqllang.Diagnostic diagnostic : diagnostics) {
ctx.getDiagnosticEmitter()
.emitDiagnostic(
CheckerUtils.MessageKind.ERROR,
diagnostic.message.toString(),
null,
SourceSectionWrapper.create(
diagnostic.sourceLocationRange, request.getSource()));
}
throw LKQLRuntimeException.fromMessage(
"Syntax errors in " + unit.getFileName(false) + ": stopping interpreter");
}

// Get the LKQL langkit AST
Expand All @@ -357,7 +369,10 @@ protected CallTarget parse(ParsingRequest request) {
// Print the Truffle AST if the JIT is in debug mode
if (getContext(result).isVerbose()) {
System.out.println(
"=== Truffle AST <" + result.getLocation().getFileName() + "> :\n" + result);
"=== Truffle AST <"
+ result.getSourceSection().getSource().getPath()
+ "> :\n"
+ result);
}

// Return the call target
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,10 @@ public String lkqlProfile() {
for (int i = 0; i < parameterNames.length; i++) {
var defVal = parameterDefaultValues[i];
if (defVal != null) {
expandedParams.add(parameterNames[i] + "=" + defVal.getLocation().getText());
expandedParams.add(
parameterNames[i]
+ "="
+ defVal.getSourceSection().getCharacters().toString());
} else {
expandedParams.add(parameterNames[i]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@
import com.adacore.lkql_jit.utils.LKQLTypesHelper;
import com.adacore.lkql_jit.utils.functions.ObjectUtils;
import com.adacore.lkql_jit.utils.functions.ReflectionUtils;
import com.adacore.lkql_jit.utils.source_location.Locatable;
import com.oracle.truffle.api.CompilerDirectives;
import com.oracle.truffle.api.dsl.Fallback;
import com.oracle.truffle.api.dsl.Specialization;
import com.oracle.truffle.api.interop.*;
import com.oracle.truffle.api.library.ExportLibrary;
import com.oracle.truffle.api.library.ExportMessage;
import com.oracle.truffle.api.nodes.Node;
import com.oracle.truffle.api.utilities.TriState;

/** This class represents a Libadalang property access in LKQL. */
Expand Down Expand Up @@ -73,7 +73,7 @@ public boolean isField() {
* @param caller The locatable which called the execution.
* @param arguments The argument for the property call.
*/
public Object executeAsProperty(Locatable caller, ArgList argList, Object... arguments) {
public Object executeAsProperty(Node caller, ArgList argList, Object... arguments) {
try {
return ReflectionUtils.callProperty(
this.node, this.description, caller, argList, arguments);
Expand All @@ -88,7 +88,7 @@ public Object executeAsProperty(Locatable caller, ArgList argList, Object... arg
*
* @param caller The locatable which called the execution.
*/
public Object executeAsField(Locatable caller) {
public Object executeAsField(Node caller) {
try {
return ReflectionUtils.callProperty(this.node, this.description, caller, null);
} catch (com.adacore.lkql_jit.exception.utils.UnsupportedTypeException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ public LKQLSelectorList getList(Object value) {
/**
* Execute the selector value on an ada node with additional arguments.
*
* @param node The node to execute the selector on.
* @param maxDepth The maximum depth of the selector list.
* @param minDepth The minimal depth of the selector list.
* @param depth The precise depth to get.
Expand Down
Loading

0 comments on commit 643c97e

Please sign in to comment.