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

cmd/compile: discard blank functions/methods after typechecking #47446

Closed
mdempsky opened this issue Jul 28, 2021 · 4 comments
Closed

cmd/compile: discard blank functions/methods after typechecking #47446

mdempsky opened this issue Jul 28, 2021 · 4 comments
Assignees
Labels
Milestone

Comments

@mdempsky
Copy link
Member

@mdempsky mdempsky commented Jul 28, 2021

Blank functions and methods need to pass typechecking, but they don't affect the final program at all. We should just discard them after typechecking and not bother compiling them. This will simplify unified IR somewhat, because then it doesn't need to worry about representing blank functions in export data: they can just be skipped over completely.

I think the only thing preventing this today is that some test cases in $GOROOT/test use blank functions/methods to exercise backend code. Those should be changed to use named functions so they continue actually testing the backend.

@mdempsky mdempsky added this to the Go1.18 milestone Jul 28, 2021
@mdempsky mdempsky self-assigned this Jul 28, 2021
@gopherbot
Copy link

@gopherbot gopherbot commented Jul 28, 2021

Change https://golang.org/cl/338094 mentions this issue: [dev.typeparams] test: rename blank functions

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 28, 2021

Change https://golang.org/cl/338095 mentions this issue: [dev.typeparams] cmd/compile: don't compile blank functions

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Jul 28, 2021

Change https://golang.org/cl/338096 mentions this issue: [dev.typeparams] cmd/compile: don't export blank functions in unified IR

Loading

gopherbot pushed a commit that referenced this issue Jul 28, 2021
This CL renames blank functions in the test/ directory so that they
don't rely on the compiler doing anything more than typechecking them.

In particular, I ran this search to find files that used blank
functions and methods:

$ git grep -l '^func.*\b_(' | xargs grep -n '^' | grep '\.go:1:' | grep -v '// errorcheck$'

I then skipped updating a few files:

* blank.go
* fixedbugs/issue11699.go
* fixedbugs/issue29870.go

  These tests specifically check that blank functions/methods work.

* interface/fail.go

  Not sure the motivation for the blank method here, but it's empty
  anyway.

* typeparam/tparam1.go

  Type-checking test, but uses "-G" (to use types2 instead of typecheck).

Updates #47446.

Change-Id: I9ec1714f499808768bd0dcd7ae6016fb2b078e5e
Reviewed-on: https://go-review.googlesource.com/c/go/+/338094
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
gopherbot pushed a commit that referenced this issue Jul 28, 2021
After typechecking a blank function, we can clear out its body and
skip applying middle-end optimizations (inlining, escape analysis). We
already skip sending them through SSA, and the previous CL updated
inlining and escape analysis regress tests to not depend on compiling
blank functions.

Updates #47446.

Change-Id: Ie678763b0e6ff13dd606ce14906b1ccf1bbccaae
Reviewed-on: https://go-review.googlesource.com/c/go/+/338095
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
gopherbot pushed a commit that referenced this issue Jul 28, 2021
After the previous two CLs, there's no need for unified IR to
write/read blank functions anymore: types2 has already checked that
they're valid, and the compiler backend is going to ignore them.

Allows dropping code for worrying about blank methods and will
probably simplify some of the object handling code eventually too.

Fixes #47446.

Change-Id: I03cb722793d676a246b1ab768b5cf0d3d2578b12
Reviewed-on: https://go-review.googlesource.com/c/go/+/338096
Trust: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
@mdempsky
Copy link
Member Author

@mdempsky mdempsky commented Jul 28, 2021

This is fixed on dev.typeparams.

Loading

@mdempsky mdempsky closed this Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants