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

Change representation of class signatures #8516

Merged
merged 22 commits into from
Jul 15, 2021

Commits on Jul 13, 2021

  1. Add more classes tests

    lpw25 committed Jul 13, 2021
    Configuration menu
    Copy the full SHA
    a734bc6 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    73c8add View commit details
    Browse the repository at this point in the history
  3. Relax object duplication restrictions

    Currently object duplications (i.e. `{< ... >}`) can only refer to
    instance variables that are specified before the method in which
    they occur. This restriction made sense before OCaml 3.10 when
    instance variables could shadow one another. However, instance
    variables now override one another instead and so the restriction
    is not needed.
    lpw25 committed Jul 13, 2021
    Configuration menu
    Copy the full SHA
    0ca24f9 View commit details
    Browse the repository at this point in the history
  4. Build met_env on second pass

    Move the extension of the method environment to the second pass of
    `class_field` in "typeclass.ml".
    lpw25 committed Jul 13, 2021
    Configuration menu
    Copy the full SHA
    b28ce4a View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    caf5108 View commit details
    Browse the repository at this point in the history
  6. Change representation of class types

    Previously, class types represented their methods via the csig_self
    field. This was a type_expr that was restricted to be syntactically
    a Tobject node. With this patch the methods are represented directly
    with a methods table. csig_self is no longer restricted to be
    a Tobject node and is no longer required to contain the private methods.
    We also add a csig_self_row field to hold the row variable of the class
    type -- which means we can avoid going through csig_self to find it.
    lpw25 committed Jul 13, 2021
    Configuration menu
    Copy the full SHA
    6e5b863 View commit details
    Browse the repository at this point in the history
  7. Bootstrap

    lpw25 committed Jul 13, 2021
    Configuration menu
    Copy the full SHA
    37c5cb1 View commit details
    Browse the repository at this point in the history
  8. Add dummy methods in all cases

    Fix some regressions introduced 4.07 by ensuring that class types and
    class expressions for classes under construction always include a dummy
    method.
    lpw25 committed Jul 13, 2021
    Configuration menu
    Copy the full SHA
    013717d View commit details
    Browse the repository at this point in the history
  9. Give more precise errors for virtual methods

    Previously, the check that a non-virtual class did not
    have virtual methods was delayed until the last stage of
    type-checking the class. Now we do those checks more eagerly
    allowing for clearer errors, especially in common cases.
    lpw25 committed Jul 13, 2021
    Configuration menu
    Copy the full SHA
    1aa65fa View commit details
    Browse the repository at this point in the history
  10. Represent ancestor variables more directly

    Previously, some of the translation of method calls on ancestor
    variables (bindings from `inherit` statements) was done in typecore.ml
    by creating fake typedtree expressions. This has been moved into
    translcore.ml which is simpler. We also pass the types of inherited
    methods directly as part of the ancestor variable's kind, which
    eleminates the need for the dummy `selfpat-n` variables.
    lpw25 committed Jul 13, 2021
    Configuration menu
    Copy the full SHA
    b43ecd1 View commit details
    Browse the repository at this point in the history
  11. Track dummy methods via their scope

    Prevent self types from escaping using the scope of the dummy
    method field rather than its level. This is a more accurate
    representation of the restriction and allows the level of the
    self type to vary, which fixes a bug in principal mode.
    lpw25 committed Jul 13, 2021
    Configuration menu
    Copy the full SHA
    e6aa05b View commit details
    Browse the repository at this point in the history
  12. Remove private_self and public_self

    Now that private methods are stored in the method table there is
    no need to distinguish `private_self`, `public_self` and `self_type`
    in `Typeclass.class_structure`. This required extending
    `Ctype.filter_method` to handle the case of filtering a private method
    from a closed object type -- which brings the function into line with
    the equivalent call to `Ctype.unify`.
    lpw25 committed Jul 13, 2021
    Configuration menu
    Copy the full SHA
    8f9b766 View commit details
    Browse the repository at this point in the history

Commits on Jul 14, 2021

  1. Treat class_signature more like type_expr

    Treat class_signature more like type_expr by making all its
    components mutable and using three unification-like operations
    for manipulating them: add_method, add_instance_variable and
    inherit_class_signature. These operations behave similarly to
    filter_self_method, which they replace.
    
    We move much of the logic for handling class_signature into Btype
    and Ctype and use it for the typing of class signatures
    and class structures.
    
    Instead of using method and variable tables with both identifiers and
    type components as accumulators during class structure typing, we use
    tables with just identifiers along with a single class_signature. This
    makes the logic clearer and makes it easier to share things with the
    typing of class signatures.
    trefis authored and lpw25 committed Jul 14, 2021
    Configuration menu
    Copy the full SHA
    845ac93 View commit details
    Browse the repository at this point in the history
  2. Fix warning attributes in class signatures

    [@@@warning ...] was not previously preserved in class signatures
    lpw25 committed Jul 14, 2021
    Configuration menu
    Copy the full SHA
    19203f8 View commit details
    Browse the repository at this point in the history
  3. Set object name of self type

    Sets the object name of the self type to the #-abbreviation, which
    improves error messages and allows us to remove the `unify_parents`
    functions from Typeclass.
    lpw25 committed Jul 14, 2021
    Configuration menu
    Copy the full SHA
    b7ef616 View commit details
    Browse the repository at this point in the history

Commits on Jul 15, 2021

  1. Keep class signature row up-to-date

    Keep the csig_self_row field up-to-date as we add new methods. This
    seems more correct and should be slightly more efficient in the
    common case.
    lpw25 committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    f7e6b79 View commit details
    Browse the repository at this point in the history
  2. Rename Concr

    The Types.Concr module is just a string set, and it is used in
    a number of places. It was originally used for the set of
    concrete methods in a class signature, but it's not used for
    that anymore and almost none of the places it is still used
    are related to that. This commit replaces is with MethSet and
    VarSet modules for sets of method or instance variable labels,
    and with Misc.Stdlib.String.Set for other uses.
    lpw25 committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    dc351b3 View commit details
    Browse the repository at this point in the history
  3. Change warning 13 message

    Remove the mention of OCaml 3.10 in the message of warning 13 (instance
    variable override). It's been over a decade since that release -- I
    think we can stop telling people that it changed the behaviour of
    instance variables.
    lpw25 committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    dbd5002 View commit details
    Browse the repository at this point in the history
  4. Move method spine generalisation logic into Ctype

    Move the method spine generalisation code into ctype.ml. Since that
    is the only code that needs to use generalize_spine we also hide
    generalize_spine from the interface of Ctype and rewrite the other
    use to use generalize_structure. (I would prefer to get rid of
    generalize_spine and use generalize_structure for methods as well,
    since generalize_spine seems a bit suspect in terms of principality,
    but that change would be very invovlved).
    lpw25 committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    964a13c View commit details
    Browse the repository at this point in the history
  5. Remove unused csig_inher field

    lpw25 committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    990ea08 View commit details
    Browse the repository at this point in the history
  6. Add helpers for warning_scope in typeclass.ml

    Add a couple of small helper functions to reduce code duplication
    around calls to warning_scope.
    lpw25 committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    e8dd017 View commit details
    Browse the repository at this point in the history
  7. Add Changes entry

    lpw25 committed Jul 15, 2021
    Configuration menu
    Copy the full SHA
    73b648e View commit details
    Browse the repository at this point in the history