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

cmd/compile: remove badgerbadgerbadger optimization? #29242

Open
josharian opened this Issue Dec 14, 2018 · 4 comments

Comments

Projects
None yet
5 participants
@josharian
Copy link
Contributor

josharian commented Dec 14, 2018

From walk.go:

func walkcompareString(n *Node, init *Nodes) *Node {
	// s + "badgerbadgerbadger" == "badgerbadgerbadger"
	if (n.Op == OEQ || n.Op == ONE) && Isconst(n.Right, CTSTR) && n.Left.Op == OADDSTR && n.Left.List.Len() == 2 && Isconst(n.Left.List.Second(), CTSTR) && strlit(n.Right) == strlit(n.Left.List.Second()) {
		r := nod(n.Op, nod(OLEN, n.Left.List.First(), nil), nodintconst(0))
		return finishcompare(n, r, init)
	}

	// cont...

I've always been skeptical that anyone writes code that matches this pattern; I'd like to remove it.

Thoughts/objections?

cc @mdempsky @randall77

@josharian josharian added this to the Go1.13 milestone Dec 14, 2018

@randall77

This comment has been minimized.

Copy link
Contributor

randall77 commented Dec 14, 2018

Fine by me. Might want to double-check that the stdlib doesn't have any (except a possible test for this optimization).

@mdempsky

This comment has been minimized.

Copy link
Member

mdempsky commented Dec 14, 2018

SGTM

@seebs

This comment has been minimized.

Copy link
Contributor

seebs commented Dec 14, 2018

That is a very common pattern... in bourne shell. Where the idiom is test "x$foo" != "x" as a workaround to handle cases where $foo might contain something that would be interpreted as a flag by the test command's option parser. I've also seen it in Makefiles, I think. I agree that it seems vanishingly unlikely to show up in go.

Also why is the function not called walkCompareString with a capital C?

@bradfitz bradfitz added the NeedsFix label Dec 14, 2018

@mdempsky

This comment has been minimized.

Copy link
Member

mdempsky commented Dec 14, 2018

Also why is the function not called walkCompareString with a capital C?

It's a subroutine of the vestigially-named walkcompare function. We try to toe a balance between adopting current Go conventions and staying consistent with the current archaic code base.

See also #27167.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment