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

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kntkymt
Copy link

@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.

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