Skip to content

[ConstraintSystem] Print constraint simplification in type inference debug output #60828

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 5 commits into from
Sep 17, 2022

Conversation

amritpan
Copy link
Member

@amritpan amritpan commented Aug 29, 2022

The constraint currently being evaluated for the overload, any new constraints added as a result of this evaluation (or removed), and the result of the simplification will be printed out to show the constraint simplification process of the constraint solver.

The following is a constraint simplification attempt for an overload choice of $T0 := (String, String) -> String). The initial constraint is simplified and two new smaller constraints are generated to evaluate the expression for this overload. The initial constraint is then removed and the simplification is shown as simplified:

(considering -> (_const $T1, _const $T2) -> $T3 applicable fn $T0 [[locator@0x13704a3f0 [Binary@/... -> apply function]]];
  (simplification result: 
    (added Constraint: $T1 operator arg conv String [[locator@0x13704a4c0 [Binary@/... -> apply argument -> comparing call argument #0 to parameter #0]]];)
    (added Constraint: $T2 operator arg conv String [[locator@0x13704a560 [Binary@/... -> apply argument -> comparing call argument #1 to parameter #1]]];)
    (removed Constraint: (_const $T1, _const $T2) -> $T3 applicable fn $T0 [[locator@0x13704a3f0 [Binary@/... -> apply function]]];)
  )
  (outcome: simplified)
)

If the constraint simplification attempt fails, it will print the constraints followed by an error result:

(considering -> (_const $T2, _const $T3) -> $T4 applicable fn $T1 [[locator@0x13f09b190 [Binary@/... -> apply function]]];
  (simplification result:
    (added constraint: $T2 operator arg conv String [[locator@0x13f09b680 [Binary@/...-> apply argument -> comparing call argument #0 to parameter #0]]];)
    (added constraint: $T3 operator arg conv String [[locator@0x13f09b720 [Binary@/... -> apply argument -> comparing call argument #1 to parameter #1]]];)
    (removed constraint: (_const $T2, _const $T3) -> $T4 applicable fn $T1 [[locator@0x13f09b190 [Binary@/... -> apply function]]];)
    (failed constraint (_const $T2, _const $T3) -> $T4 applicable fn $T1 [[locator@0x13f09b190 [Binary@/... -> apply function]]];)
  )
  (outcome: error)
)

If an added constraint is a disjunction kind, its choices will be nested:

(considering -> @lvalue Int? operator arg conv $T5 [[locator@0x13e00d360 [Binary@/Users/amritpankaur/test.swift:72:18 -> apply argument -> comparing call argument #1 to parameter #1 -> @autoclosure result]]];
  (simplification result:
    (added constraint: disjunction [[locator@0x13e00d360 [Binary@/Users/amritpankaur/test.swift:72:18 -> apply argument -> comparing call argument #1 to parameter #1 -> @autoclosure result]]]:
    >  [favored]  Int? bind Int?? [deep equality] [[locator@0x13e00d360 [Binary@/Users/amritpankaur/test.swift:72:18 -> apply argument -> comparing call argument #1 to parameter #1 -> @autoclosure result]]];
    >             Int? operator arg conv Int?? [optional-to-optional] [[locator@0x13e00d360 [Binary@/Users/amritpankaur/test.swift:72:18 -> apply argument -> comparing call argument #1 to parameter #1 -> @autoclosure result]]];
    >             Int? operator arg conv Int?? [value-to-optional] [[locator@0x13e00d360 [Binary@/Users/amritpankaur/test.swift:72:18 -> apply argument -> comparing call argument #1 to parameter #1 -> @autoclosure result]]];)
  (removed constraint: @lvalue Int? operator arg conv $T5 [[locator@0x13e00d360 [Binary@/Users/amritpankaur/test.swift:72:18 -> apply argument -> comparing call argument #1 to parameter #1 -> @autoclosure result]]];)
  )
  (outcome: simplified)
)

This adds to the solver step Changes printed in #59971.

@amritpan amritpan force-pushed the print-simplification branch 4 times, most recently from 400f87b to 5f074e9 Compare September 4, 2022 21:32
@xedin xedin self-requested a review September 4, 2022 22:04
@amritpan amritpan force-pushed the print-simplification branch from 5f074e9 to f2c6735 Compare September 5, 2022 16:38
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.

Looks great, I left a couple of minor comments inline.

@amritpan amritpan force-pushed the print-simplification branch from f2c6735 to 789d3a3 Compare September 13, 2022 15:46
@amritpan amritpan requested a review from xedin September 13, 2022 16:06
Amritpan Kaur added 5 commits September 16, 2022 09:17
@amritpan amritpan force-pushed the print-simplification branch from 789d3a3 to 1151960 Compare September 16, 2022 17:13
@xedin
Copy link
Contributor

xedin commented Sep 16, 2022

@swift-ci please test

@xedin
Copy link
Contributor

xedin commented Sep 16, 2022

@swift-ci please test macOS platform

@xedin xedin merged commit 127ff11 into swiftlang:main Sep 17, 2022
@amritpan amritpan deleted the print-simplification branch September 19, 2022 05:07
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