Skip to content

[ConstraintSystem] Add index value (as an impact of the score kind) to output of debug constraints. #78740

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 3 commits into from
Jan 23, 2025

Conversation

kntkymt
Copy link
Contributor

@kntkymt kntkymt commented Jan 19, 2025

Environment

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
Target: arm64-apple-macosx14.0

Motivation

resolve #72842

As I mentioned in #72842,
In current output of debug-constraints, We cannot easily recognize which score is more impactful.

class Animal {}
class Cat: Animal {}
func f(_ a: [Cat?]) { }
func f(_ a: [Any]) { }

let a: [Cat] = [Cat()]
f(a)
// swiftc -Xfrontend -debug-constraints Source.swift

---Solver statistics---
--- Solution #0 ---
Fixed score: [component: collection upcast conversion(s), value: 1] [component: value to optional promotion(s), value: 1]
...

--- Solution #1 ---
Fixed score: [component: collection upcast conversion(s), value: 1] [component: empty-existential conversion(s), value: 1]
...

---Solution---
Fixed score: [component: collection upcast conversion(s), value: 1] [component: empty-existential conversion(s), value: 1]
...

Full Output

We cannot recognize which score is more/less impactful. e.g. between value to optional promotion of Solution#0 and empty-existential conversion of Solution#1.
(We can guess empty-existential conversion(s) is less impactful, since final Solution is Solution#1 but it is ambiguous.)

Proposed Solution

I added number indicating impact of score to output of debug-constraints.
Currently I used index of enum ScoreKind. (i.e. smaller number is more impactful).

// swiftc -Xfrontend -debug-constraints Source.swift

---Solver statistics---
--- Solution #0 ---
Fixed score: [component: #14 collection upcast conversion(s), value: 1] [component: #15 value to optional promotion(s), value: 1]
...

--- Solution #1 ---
Fixed score: [component: #14 collection upcast conversion(s), value: 1] [component: #16 empty-existential conversion(s), value: 1]
...

---Solution---
Fixed score: [component: #14 collection upcast conversion(s), value: 1] [component: #16 empty-existential conversion(s), value: 1]
...

Alternative Format

Suggestion for other formats are welcome.

e. g.

// reversed index (i.e. bigger number is more impactful)
[component: #8 collection upcast conversion(s), value: 1]

// added label as well (I'm not sure whether "rank" is correct wording or not tho)
[rank: 14, component: collection upcast conversion(s), value: 1]

@kntkymt kntkymt marked this pull request as ready for review January 19, 2025 09:55
@kntkymt kntkymt requested review from hborla and xedin as code owners January 19, 2025 09:55
@@ -1197,6 +1197,9 @@ struct Score {
for (unsigned int i = 0; i < NumScoreKinds; ++i) {
if (Data[i] != 0) {
out << " [component: ";
out << "#";
out << std::to_string(i);
out << " ";
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks! I think to clarify this even further we should use weight instead of index (which is opposite) and instead of value: -> impact:. This would better reflect the meaning of these values.

Copy link
Contributor Author

@kntkymt kntkymt Jan 21, 2025

Choose a reason for hiding this comment

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

Thanks for suggestion! I addressed at 88fba29

before this PR

Fixed score: [component: collection upcast conversion(s), value: 1] [component: empty-existential conversion(s), value: 1]

now

Fixed score: [component: #8 collection upcast conversion(s), impact: 1] [component: #6 empty-existential conversion(s), impact: 1]

Copy link
Contributor

Choose a reason for hiding this comment

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

As I mentioned in my previous comment, I think we need to change component: that you added into something which has clearer meaning i.e. weight and print it the inverse of it to indicate the scores placed at a higher index have a higher weight.

Copy link
Contributor Author

@kntkymt kntkymt Jan 22, 2025

Choose a reason for hiding this comment

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

@xedin Thanks again, sorry for my misunderstanding.

print it the inverse of it to indicate the scores placed at a higher index have a higher weight.

is NumScoreKinds - i correct? this means higher value indicate higher weight I think.
e.g.

  • SK_Hole== 22
  • SK_UnappliedFunction == 1

I think we need to change component: that you added into something which has clearer meaning i.e. weight

let me double check, did you mean like this?

[weight: #8 collection upcast conversion(s), impact: 1]

If I still have misunderstanding, I'd be very happy if you suggest with a example output like ↑🙇

Copy link
Contributor Author

Choose a reason for hiding this comment

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

also I thought

[collection upcast conversion(s), weight: 8, impact: 1]

maybe more readable? (either is fine for me 😄 )

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the latter format where both values are together and yes about NumScoreKinds - i, SK_Hole has more weight than SK_UnappliedFunction during solution ranking.

Copy link
Contributor Author

@kntkymt kntkymt Jan 22, 2025

Choose a reason for hiding this comment

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

@xedin Thanks. it's very clear now 🙇

I addressed at 31d7233

  • remove "component:" label
  • use NumScoreKinds - i instead of i
    • e.g.: SK_Fix = 22 SK_UnappliedFunction = 1
  • put "weight" label and its value next to name of score's kind
    • e.g.: [collection upcast conversion(s), weight: 8, impact: 1]

@kntkymt kntkymt requested a review from xedin January 21, 2025 13:02
@kntkymt kntkymt force-pushed the add-score-impact-debug-constraints branch from bc10f6f to 88fba29 Compare January 21, 2025 14:29
@xedin
Copy link
Contributor

xedin commented Jan 22, 2025

@swift-ci please test

@xedin xedin merged commit bdfb609 into swiftlang:main Jan 23, 2025
5 checks passed
@xedin
Copy link
Contributor

xedin commented Jan 23, 2025

Thank you for the contribution!

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.

[ConstraintSystem] Improve score label in the debug output so that we can easily recognize which score is more/less impactful.
2 participants