Skip to content

Unify CanonicalVar and DebruijnIndex #49887

Closed

Description

@nikomatsakis

From #49810:

The plan is to generalize the existing CanonicalVar so that it represents a "bound" thing -- probably it just gets unified with DebruijnIndex.

General instructions:

The canonical var is a "new type index" declared here:

newtype_index!(CanonicalVar);

We would basically just want to remove it completely and replace uses of it with DebruijnIndex. There are a few complications to be overcome. One is that debruijn indices are currently 1-based (that is #49813), so indexing with them will require some tweaks. Another related problem is that DebruijnIndex does not implement the Idx trait, so we can't presently have a IndexVec<DebruijnIndex>, as we do in the CanonicalVarValues struct:

pub struct CanonicalVarValues<'tcx> {
pub var_values: IndexVec<CanonicalVar, Kind<'tcx>>,
}

This is not that big a deal -- we can just use a plain vector -- although if we make debruijn indices 0-based we could then generate it with the newtype_index! macro, which would be nice.

Activity

  1. sgrif commented on Apr 11, 2018

    @sgrif
    Contributor

    Can we pick some better names while we're at it?

  2. nikomatsakis commented on Apr 11, 2018

    @nikomatsakis
    ContributorAuthor

    Which names are you thinking we should change?

  3. sgrif commented on Apr 11, 2018

    @sgrif
    Contributor

    DebruijnIndex in particular is one I find extremely opaque. I get that it's a math term and there's a wikipedia article, but I don't think we should require that sort of reading to understand a term in a codebase (I argue for Mappable over Functor for the same reason). CanonicalVar is better in context, but I also think it's the sort of name that unless you see it specifically in the context of canonicalization there's no reason you'd know what it means.

  4. nikomatsakis commented on Apr 11, 2018

    @nikomatsakis
    ContributorAuthor

    Hmm. I suppose we could call it BinderIndex or something maybe? That said, I sort of like DebruijnIndex because it has a very unique, instant meaning, and I'm not sure that there exists a non-mathemetical term for this thing. Still, ordinarily I agree we should strive for "accessible and memorable" terminology.

  5. varkor commented on Apr 11, 2018

    @varkor
    Contributor

    If there is a very precise technical term for something, it's least ambiguous if you give that something the name. Giving something a more friendly, and less descriptive name, means that people who know the term won't be immediately familiar with it, whereas people who aren't familiar with the concept still need to look it up anyway. Plus, technical terms are more memorable. I'd prefer to stick with DeBruijnIndex here.

  6. sgrif commented on Apr 11, 2018

    @sgrif
    Contributor

    Even though DeMorgan Machine is generally a more precise technical term for computers today, we use the term computer, since it had a more generally understandable meaning for those involved, even if that term was nonsense when applied to a machine at the time. I don't think "math calls it X" is a great argument in a code base meant to be read by programmers, who may or may not have a degree in mathematics.

  7. varkor commented on Apr 11, 2018

    @varkor
    Contributor

    This might be a reasonable argument about technical terms (e.g. Functor) in user-facing libraries, but I'd argue the internals of a compiler are technical enough that one should expect some compiler / programming language theory terminology (e.g. DeBruijnIndex ).

    (Although now that I've just noticed, I would be in favour of changing the capitalisation on the name ;) )

  8. eddyb commented on Apr 11, 2018

    @eddyb
    Contributor

    BinderDepth or BinderDistance might work out as alternatives?
    Although I'm not sure I like Binder either, but there I have no suggestions.
    (Using Binder and BinderSomething would make it easier to connect the two though)

    Also, aren't many canonical vars bound at the same binder? How would that work?

  9. Ixrec commented on Apr 12, 2018

    @Ixrec
    Contributor

    This does seem like a case where a vague, non-"scary" term might be more obfuscating in practice than the technically correct, unambiguous term.

    imo, if DeBruijnIndex usually appears in close proximity to a Binder, then renaming it to BinderIndex is probably a net win. But if DeBruijnIndex is mostly operated on/passed around independently of whatever type it is an index for, then it's probably better to keep it the way it is.

  10. eddyb commented on Apr 12, 2018

    @eddyb
    Contributor

    @Ixrec AIUI, it's specifically "how many Binders do I have to pass through to get to the Binder that introduces this parameter?" - "index" can be confusing because there is a separate notion of "which parameter" within a Binder - and the anonymous ones are distinguished by... an index.

  11. nikomatsakis commented on Apr 30, 2018

    @nikomatsakis
    ContributorAuthor

    @fabric-and-ink yeah this is sort of a "meta issue"

  12. nikomatsakis commented on Apr 30, 2018

    @nikomatsakis
    ContributorAuthor

    but I'll try to comment here or ping you once we get #49813 resolved

  13. nikomatsakis commented on May 29, 2018

    @nikomatsakis
    ContributorAuthor

    cc @fabric-and-ink — still interested in giving this a shot? #49813 is finally closed.

  14. nikomatsakis commented on May 29, 2018

    @nikomatsakis
    ContributorAuthor

    I guess a good first step would be to convert DebruijnIndex to support the Idx trait. The idea would be to declare it via the newtype_index! macro.

  15. added a commit that references this issue on Jun 18, 2018
  16. nikomatsakis commented on Jul 2, 2018

    @nikomatsakis
    ContributorAuthor

    @fabric-and-ink argh sorry for missing your update! probably yes! Let me give a look

  17. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    on Jul 7, 2018
  18. added a commit that references this issue on Oct 21, 2018
    0e2f912
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-trait-systemArea: Trait systemC-enhancementCategory: An issue proposing an enhancement or a PR with one.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions