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

Do not inhibit the dead code elimination. #341

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions cmp/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ func (ps pathStep) String() string {
if ps.typ == nil {
return "<nil>"
}
s := value.TypeString(ps.typ, false)
// NOTE: do not use value.TypeString(qualified = false) to avoid
// calls to reflect.Type.Method() which disables the DCE.
s := ps.typ.String()
if s == "" || strings.ContainsAny(s, "{}\n") {
return "root" // Type too simple or complex to print
}
Expand Down Expand Up @@ -293,7 +295,11 @@ type typeAssertion struct {

func (ta TypeAssertion) Type() reflect.Type { return ta.typ }
func (ta TypeAssertion) Values() (vx, vy reflect.Value) { return ta.vx, ta.vy }
func (ta TypeAssertion) String() string { return fmt.Sprintf(".(%v)", value.TypeString(ta.typ, false)) }
func (ta TypeAssertion) String() string {
// NOTE: do not use value.TypeString(qualified = false) to avoid
// calls to reflect.Type.Method() which disables the DCE.
return fmt.Sprintf(".(%v)", ta.typ.String())
}

// Transform is a [PathStep] that represents a transformation
// from the parent type to the current type.
Expand Down