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

Generate full error traces during module inclusion #10407

Merged
merged 10 commits into from
Jun 22, 2021

Commits on Jun 21, 2021

  1. Bug fix: equal_private was being used in too many places

    `equal_private` should only be used when checking inclusion for
    private *type abbreviations*, but was being used incorrectly for
    private data types and private row types as well.
    antalsz committed Jun 21, 2021
    Configuration menu
    Copy the full SHA
    7849115 View commit details
    Browse the repository at this point in the history
  2. Add new test cases for module inclusion errors

    These test cases will have improved error messages in the next
    non-test commit.
    antalsz committed Jun 21, 2021
    Configuration menu
    Copy the full SHA
    79a60b4 View commit details
    Browse the repository at this point in the history
  3. Add more new test cases for module inclusion errors

    These test cases will also have improved error messages in the next
    non-test commit.  They come from the work done to address reviewer
    comments for ocaml#10407.
    antalsz committed Jun 21, 2021
    Configuration menu
    Copy the full SHA
    7fad56e View commit details
    Browse the repository at this point in the history
  4. Add new test cases for failures of type-specific unification methods

    These test cases will also have improved error messages in the next
    non-test commit.  They come from the work done to address reviewer
    comments for ocaml#10407.
    antalsz committed Jun 21, 2021
    Configuration menu
    Copy the full SHA
    abd5490 View commit details
    Browse the repository at this point in the history
  5. Use the new structured errors (ocaml#10170) for better error messages

    We now produce more detailed error messages during various kinds of
    module inclusion, taking advantage of the new structured error trace
    generation from ocaml#10170.  Previously, these errors were "shallow",
    ending as soon as there was an incompatibility; this patch makes them
    "deep", reporting the *reasons* for those problems.  For example,
    consider the following module:
    
        module M : sig
          val x : bool * int
        end = struct
          let x = false , "not an int"
        end
    
    This now produces the following error:
    
        Error: Signature mismatch:
               Modules do not match:
                 sig val x : bool * string end
               is not included in
                 sig val x : bool * int end
               Values do not match:
                 val x : bool * string
               is not included in
                 val x : bool * int
               The type bool * string is not compatible with the type bool * int
               Type string is not compatible with type int
    
    The last two lines are new in this patch.  Previously, the error
    message stopped two lines earlier, omitting the key detail that the
    reason there is an error is specifically that `string` is not equal to
    `int`.
    antalsz committed Jun 21, 2021
    Configuration menu
    Copy the full SHA
    2abe3e4 View commit details
    Browse the repository at this point in the history
  6. Respond to review for the new structured error messages (ocaml#10407)

    In addition to the smaller fixes, there were two major changes:
    
    1. `Errortrace` has its type completely refactored, removing `desc`
       and exposing both `'variant trace` and `'variant error`.  The
       former is for traces that are being built up, and contains
       `type_expr`s; the lattern is for complete traces, and contains
       `expanded_type`s (a record containing two `type_expr`s).  This
       dramatically affected a number of call sites, but is much cleaner.
    
    2. We now detect weakly polymorphic types much better during
       printing.  This involved fixing a bug in moregeneral, which was not
       restoring enough information in the error case; it also involved
       exposing the flag that differentiated between printing a type (no
       weakly polymorphic type detection) and a scheme (yes weakly
       polymorphic type detection) in more places, and giving it its own
       custom variant type, `Printtyp.type_or_scheme`.
    
    Among the minor changes, the updates to `Includecore` to more
    carefully detect privacy violation errors and differentiate between
    the various kinds thereof (recorded in the `privacy_mismatch` type) is
    the most visible in the code.
    antalsz committed Jun 21, 2021
    Configuration menu
    Copy the full SHA
    1820e78 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    80855e2 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    4aacb71 View commit details
    Browse the repository at this point in the history
  9. Make Errortrace.*_error only contain nonempty traces

    This was done by making their constructors private, and introduce
    smart constructors that raise a fatal error if passed an empty trace.
    This change was made for `Errortrace.unification_error`,
    `Errortrace.equality_error`, `Errortrace.moregen_error`, and the new
    type `Errortrace.Subtype.error` (which now contains a (possibly-empty)
    unification trace as well).
    
    As a side effect, in order to ensure that all raised unification
    errors were indeed nonempty, I had to modify `Ctype.filter_arrow`,
    `Ctype.filter_method`, and `Ctype.filter_self_method` to raise bespoke
    errors rather than empty unification traces.  This also allowed me to
    change the error messages printed in those cases to be more precise.
    antalsz committed Jun 21, 2021
    Configuration menu
    Copy the full SHA
    2d62e82 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    0c99332 View commit details
    Browse the repository at this point in the history