Skip to content

[ConstraintSystem] Improve connected components printing in the type inference algorithm debug output #59971

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

Merged
merged 8 commits into from
Aug 23, 2022

Conversation

amritpan
Copy link
Member

@amritpan amritpan commented Jul 8, 2022

The connected components will explicitly state the type variables currently in scope, their initial possible bindings, and the next type variable eligible for evaluation. Additionally, any new type variables, constraints or equivalence classes found, added, and removed as a result of the solver step attempt will be listed under a new section called Changes

For each component under evaluation, an Current Bindings section will present the initial type variable bindings and disjunctions/conjunctions.

For example:

---Connected components---
  0: $T1 $T2 $T3 $T4
  1: $T5
    (solving component #1
      ($T5 bindings={(subtypes of) Int})
      Initial bindings: $T5 := Int
      (attempting type variable $T5 := Int
       ...

will now print as:

---Connected components---
  0: $T1 $T2 $T3 $T4
  1: $T5
    (solving component #1
      Type variables in scope = [$T5]
      (Current Binding: 
        ($T5 [with possible bindings: (subtypes of) Int])
      )
      (attempting type variable $T5 := Int
       ...

When a new type variable, equivalence class or constraint is removed or added during a solving attempt, a Changes section will present these updated type variables and constraints. For example:

 (attempting disjunction choice $T1 bound to decl Swift.(file).AdditiveArithmetic.+ : <Self where Self : AdditiveArithmetic> (Self.Type) -> (Self, Self) -> Self [[locator@0x13e0a0b98 [OverloadedDeclRef@/...]]];
          ...
          ($T2 [with possible bindings: (subtypes of) Int])
          ($T3 [attributes: [literal: string]] [with possible bindings: (subtypes of) Int])
          Initial bindings: $T2 := Int
          (attempting type variable $T2 := Int
         ... 

will now print the following Changes:

  (attempting disjunction choice $T1 bound to decl Swift.(file).AdditiveArithmetic.+ : <Self where Self : AdditiveArithmetic> (Self.Type) -> (Self, Self) -> Self [[locator@0x13b903798 [OverloadedDeclRef@/...]]];
          ...
          (Changes:
            (New Bound Type: 
              > $T1 := ($T7, $T7) -> $T7
              > $T7 := Int
            )
            (New Type Variable: 
              > $T7
            )
            (Added Constraint: 
              > $T2 transitive conformance to AdditiveArithmetic [[locator@0x13b933158 [OverloadedDeclRef@/... -> opened generic -> type parameter requirement #0 (conformance)]]];
              > $T2 operator arg conv $T7 [[locator@0x13b905e80 [Binary@/... -> apply argument -> comparing call argument #0 to parameter #0]]];
              > $T3 transitive conformance to AdditiveArithmetic [[locator@0x13b933158 [OverloadedDeclRef@/... -> opened generic -> type parameter requirement #0 (conformance)]]];
              > $T3 operator arg conv $T7 [[locator@0x13b905f20 [Binary@/... -> apply argument -> comparing call argument #1 to parameter #1]]];
            )
            (Removed Constraint: 
              > (_const $T2, _const $T3) -> $T4 applicable fn $T1 [[locator@0x13b905990 [Binary@/... -> apply function]]];
            )
          )
          (Current Bindings: 
            ($T2 [with possible bindings: (subtypes of) Int])
            ($T3 [attributes: [literal: string]] [with possible bindings: (subtypes of) Int])
          )
          (attempting type variable $T2 := Int
          ... 

@amritpan amritpan force-pushed the improve-connected-components-printing branch 2 times, most recently from f06a2c0 to ad86ec2 Compare July 12, 2022 22:35
@amritpan amritpan marked this pull request as draft July 12, 2022 22:55
@amritpan amritpan changed the title [WIP][ConstraintSystem] Improve connected components printing in the type inference algorithm debug output [ConstraintSystem] Improve connected components printing in the type inference algorithm debug output Jul 12, 2022
@amritpan amritpan force-pushed the improve-connected-components-printing branch 9 times, most recently from 716e93f to 020da92 Compare July 19, 2022 22:58
@amritpan amritpan marked this pull request as ready for review July 20, 2022 16:20
@amritpan amritpan force-pushed the improve-connected-components-printing branch from 020da92 to 7aa60d4 Compare August 16, 2022 20:19
@xedin xedin self-requested a review August 17, 2022 00:01
@amritpan amritpan force-pushed the improve-connected-components-printing branch from 7aa60d4 to d079755 Compare August 18, 2022 03:05
@amritpan amritpan requested a review from xedin August 18, 2022 03:06
@amritpan amritpan force-pushed the improve-connected-components-printing branch 3 times, most recently from 57f5c19 to 8c9a341 Compare August 19, 2022 02:34
@amritpan amritpan requested a review from xedin August 19, 2022 02:46
Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

LGTM! I left a few small comments inline.

@amritpan amritpan force-pushed the improve-connected-components-printing branch from 8c9a341 to 6f6e089 Compare August 21, 2022 16:34
@amritpan amritpan requested a review from xedin August 21, 2022 16:38
@amritpan amritpan force-pushed the improve-connected-components-printing branch from 6f6e089 to 6d55c52 Compare August 22, 2022 23:29
@amritpan amritpan requested a review from xedin August 22, 2022 23:31
}
log.indent(CS.solverState->getCurrentIndent());

if (disjunction) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This and conjunction section prints a selected disjunction/conjunction instead of all of them but let’s address that in a follow up PR instead of holding this one.

@xedin
Copy link
Contributor

xedin commented Aug 23, 2022

@swift-ci please test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants