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

Reimplement constraint merging for correctness #13292

Merged
merged 4 commits into from
Aug 18, 2021

Commits on Aug 13, 2021

  1. -Ydetailed-stats: clear stats after printing them

    Otherwise they will keep accumulating across multiple compiler instances
    since Stats is global.
    smarter committed Aug 13, 2021
    Configuration menu
    Copy the full SHA
    d71e8ef View commit details
    Browse the repository at this point in the history
  2. Fix printing of OrderingConstraint

    When printing a constraint, we print types which might
    refer to type variables defined in the constraint, but the type printer
    will rely on ctx.typerState.constraint to determine if these type
    variables are instantiated, and this might be a different constraint
    than the one we're trying to print, leading to an incorrect output.
    
    This commit fixes this by temporarily setting ctx.typerState.constraint
    to the current constraint when printing it, this required moving the
    printing logic from OrderingConstraint to PlainPrinter.
    
    At the same time, we drop the distinction between `toText` and
    `contentsToString` (the former wrapped the printed output in
    "Constraint(...)" and the latter didn't, now we never do) because
    preserving it would have been complicated and it didn't seem worth it.
    
    Also fix Ordering#toString to correctly print the bounds (the logic was
    there but it was dead code).
    smarter committed Aug 13, 2021
    Configuration menu
    Copy the full SHA
    581f7e9 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    3a082cb View commit details
    Browse the repository at this point in the history
  4. Reimplement constraint merging for correctness

    The previous implementation simply combined the content of both
    constraints into one, but this is not enough since it meant that bounds
    were not propagated and so transitivity was violated. For example, when
    merging a constraint containing `?S <: ?T` and one containing `?T <:
    ?R`, the result did not verify `?S <:< ?R` (see the unit tests added in
    ConstraintsTest).
    
    The new implementation simply starts with one set of constraints and
    then adds the constraints from the other set one by one using `<:<`
    which takes care of propagating bounds. This is likely to be more
    expensive than the previous implementation but it turns out that
    `TyperState#mergeConstraintWith` is a rare operation (after the previous
    commit it is only called 43 times when compiling scala3-compiler), so
    the difference shouldn't be significant.
    
    This also incidentally fixes scala#12730 because the previous logic for
    checking if merging succeeded was flawed.
    smarter committed Aug 13, 2021
    Configuration menu
    Copy the full SHA
    b9d8ca9 View commit details
    Browse the repository at this point in the history