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

saw-core typechecking debugging #1496

Merged
merged 5 commits into from
Nov 12, 2021
Merged

Conversation

jpaykin
Copy link
Contributor

@jpaykin jpaykin commented Nov 4, 2021

This branch adds debugging information to saw-core typechecking errors. It adds a new constructor to the TCError data structure, called ErrorTerm, which keeps track of the term in which an error resides. The error message displays this term to provide context to the error. This means that instead of messages like

Inferred type
  sort 1
Not a subtype of expected type
  sort 0
For term
  sort 0

We will now produce error messages of the form

In term
  Prelude.LRT_Fun
  sort 0
  (\(arg4 : sort 0) ->
     let { x@1 = Prelude.BVVec 64 arg0
                   (Prelude.BVVec 64 arg1 (Prelude.Vec 64 Prelude.Bool))
         }
      in Prelude.LRT_Fun
           x@1
           (\(p0' : x@1) ->
              Prelude.LRT_Fun
                #(-empty-)
                (\(p1 : #(-empty-)) ->
                   Prelude.LRT_Fun
                     #(-empty-)
                     (\(p2 : #(-empty-)) ->
                        Prelude.LRT_Fun
                          #(-empty-)
                          (\(p3 : #(-empty-)) ->
                             Prelude.LRT_Fun
                               #(-empty-)
                               (\(p4 : #(-empty-)) ->
                                  Prelude.LRT_Fun
                                    #(-empty-)
                                    (\(p5 : #(-empty-)) ->
                                       Prelude.LRT_Fun
                                         arg4
                                         (\(p6 : arg4) ->
                                            let { x@2 = Prelude.Vec 64
                                                          Prelude.Bool
                                                }
                                             in Prelude.LRT_Ret
                                                  (Prelude.BVVec 64 arg0
                                                     (Prelude.BVVec 64 arg1
                                                        x@2) * x@2)))))))))
Inferred type
  sort 1
Not a subtype of expected type
  sort 0
For term
  sort 0

There are several avenues for potentially improving this feature if needbe:

  1. Make ErrorTerm controllable by a debugging flag
  2. Before printing an ErrorTerm, check the size of the term; if it is so big that printing the term would not be useful, consider eliding the term, possibly printing its type
  3. Raise the ErrorTerm for a different set of terms. Currently it will be raised for any expression called via typeInferComplete, which skips many recursive cases that call typeInfer.

@jpaykin jpaykin added error-messages saw-core Related to the saw-core package labels Nov 4, 2021
@eddywestbrook
Copy link
Contributor

@brianhuffman what do you think of this change? We are waiting for your thumbs up or thumbs down on it.

Copy link
Contributor

@brianhuffman brianhuffman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks reasonable to me.

@eddywestbrook eddywestbrook added the ready-to-merge If at least one person approves this PR, automatically merge it when CI finishes successfully. label Nov 12, 2021
@mergify mergify bot merged commit 462f06c into master Nov 12, 2021
@mergify mergify bot deleted the saw-core/typechecking-debugging branch November 12, 2021 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
error-messages ready-to-merge If at least one person approves this PR, automatically merge it when CI finishes successfully. saw-core Related to the saw-core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants