Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance type error understanding by displaying incompatible constraints #2402

Merged

Conversation

Gueckmooh
Copy link
Contributor

@Gueckmooh Gueckmooh commented Feb 25, 2023

Sometimes it is complicated to understand errors such as Unable to deduce type for variable a. I tried to add more information on the cause of the error.

For now it is still a work in progress, but I have a few results.

Example

.decl foo(a: number, b: number)
.decl foo(a: symbol, b: number)

foo(1, 2).
bar(a, b) :-
   foo(a, b).

Before

$ souffle test.dl
Error: Unable to deduce type for variable a in file test.dl at line 5
bar(a, b) :-
----^--------
Error: Unable to deduce type for variable a in file test.dl at line 6
    foo(a, b).
--------^------
2 errors generated, evaluation aborted

After

$ souffle test.dl
Error: Unable to deduce type for variable a in file test.dl at line 5
bar(a, b) :-
----^--------
Following constraints are incompatible:
   Type of variable 'a' should be a subtype of 'symbol'
   Type of variable 'a' should be a subtype of 'number' in file test.dl at line 6
    foo(a, b).
----^----------
1 errors generated, evaluation aborted

How

I added an ErrorAnalyzer class that collects the minimal set of incompatible constraints on a problem, similarly to the unsat core of a SAT problem. It is injected into the type analysis to gather those information.

Then when emitting errors, it is used to "explain" why the error occurs.

To do

  • Deduplicate errors (merge line 5 and line 6 errors in the example)
  • Associate source location information to constraints
  • Get user friendly messages to explain failing constraints
  • Activate the "error understanding" mechanism on option
  • Unit tests
  • Remove the option
  • Prettify constant type names

Make deduplication less ugly it's ugly but only when an error occurs

Let me know if the change looks too intrusive.

@codecov
Copy link

codecov bot commented Feb 25, 2023

Codecov Report

Merging #2402 (2914f7b) into master (0334b07) will increase coverage by 0.19%.
The diff coverage is 89.13%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2402      +/-   ##
==========================================
+ Coverage   77.56%   77.75%   +0.19%     
==========================================
  Files         467      474       +7     
  Lines       30785    31164     +379     
==========================================
+ Hits        23877    24232     +355     
- Misses       6908     6932      +24     
Impacted Files Coverage Δ
src/ast/analysis/typesystem/Type.h 50.00% <ø> (-10.00%) ⬇️
src/parser/ParserDriver.h 100.00% <ø> (ø)
src/synthesiser/Synthesiser.h 100.00% <ø> (ø)
.../ast/transform/SimplifyConstantBinaryConstraints.h 50.00% <50.00%> (ø)
src/MainDriver.cpp 70.39% <70.27%> (+0.15%) ⬆️
src/parser/scanner.ll 78.01% <76.92%> (+5.49%) ⬆️
tests/libsouffle_interface/vfs_overlay_test.cpp 85.93% <85.93%> (ø)
src/ast/analysis/ConstraintSystem.h 96.96% <86.36%> (-3.04%) ⬇️
src/parser/SrcLocation.cpp 91.86% <87.50%> (+7.24%) ⬆️
src/parser/ParserDriver.cpp 89.44% <88.33%> (-0.39%) ⬇️
... and 28 more

@Gueckmooh Gueckmooh changed the title Enhancement error understanding Enhance error understanding by displaying incompatible constraints Feb 25, 2023
@Gueckmooh Gueckmooh changed the title Enhance error understanding by displaying incompatible constraints Enhance type error understanding by displaying incompatible constraints Feb 25, 2023
@julienhenry julienhenry self-requested a review March 3, 2023 09:40
@julienhenry julienhenry merged commit 18d77b9 into souffle-lang:master Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants