compiler: no escape analysis at -opt=0
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- go
- Lĩnh vực
- build-system, compilers
Hướng nghiên cứu
Start in transform.Optimize and trace how the function-attrs and OptimizeAllocs passes are scheduled at -opt=0; compare with the escape-analysis behavior cited from cmd/compile. Reproduce the supplied //go:noheap, interrupt-handler, and startup randomness cases at -opt=0. Done means these cases build or run without unintended heap allocation while existing optimization behavior remains correct.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
At -opt=0, transform.Optimize does not run OptimizeAllocs. Each local whose address is passed to a call is allocated on the heap. I think this is a correctness problem, because code that is correct at -opt=1 fails at -opt=0.
With -gc=none, the build fails. #6613 reports this for the rp2 clock code, with object allocated on the heap with -gc=none.
In a //go:noheap function, the build also fails. The runtime.alloc_noheap comment says the call "must either be optimized away or throw a linker error". This program builds at -opt=1. At -opt=0 it fails with object allocated on the heap in //go:noheap function.
package main
//go:noheap
func main() {
var a int
add(&a)
}
//go:noinline
func add(p *int) { *p++ }
In an interrupt handler, the program aborts. At -opt=0 this handler calls runtime.alloc for c, and alloc in gc_blocks.go calls runtimeFatal("heap alloc in interrupt"). At -opt=1, c is a stack slot.
func handler(interrupt.Interrupt) {
c := counter{&total, 1}
c.add() // func (c *counter) add()
}
#5823 is an earlier case. At -opt=0, hardwareRand allocated n with runtime.alloc before initHeap, and linux programs crashed before main. At -opt=0, Go code cannot pass the address of a stack variable to a call. So 94173b29 replaced getrandom with the AT_RANDOM bytes from getauxval.
The generic startupRand still calls hardwareRand. On windows/amd64 at -opt=0, runtime.run calls initRand before initHeap, and hardwareRand calls runtime.alloc for n. I have not run this on Windows.
OptimizeAllocs has run only above -opt=0 since 42196525 added it as an optimisation. f41b6a3b and 85d223c5 later added the interrupt check and //go:noheap, and both depend on this pass.
The gc compiler runs escape analysis when -N disables optimisations. cmd/compile calls escape.Funcs with no check of -N, and its comment says escape analysis is required. See https://github.com/golang/go/blob/go1.27.4/src/cmd/compile/internal/gc/main.go#L285-L294. With -gcflags='-N -l -m', gc reports c does not escape for the receiver above, and main.main does not call runtime.newobject.
I propose that transform.Optimize also runs function-attrs and OptimizeAllocs at -opt=0. I tried this on the three cases above. All three build, and the handler uses a stack slot.
cc @rdon-key @dgryski
- Ngôn ngữ chính
- Go
- Star
- 17.8k
- Fork
- 1.1k
- Merge trung bình
- 1 ngày 4 giờ
- Pull request đã merge (30 ngày)
- 380
Chuẩn bị môi trường
Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của tinygo-org/tinygo
-
avr: SPI Mode2 runs as mode 1Đang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
tinygo-org/tinygo#6727 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 86/100
tinygo-org/tinygo#6711 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Builds are not reproducible: cgo snippet paths in debug infoCó thể đã có người làm @tridev-tej đã nhận 1 ngày trước. Đang mởenhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
tinygo-org/tinygo#6619 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Fix the targets that tinygo build -target rejectsCó thể đã có người làm @narguis đã nhận 2 ngày trước. Đang mởbug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
tinygo-org/tinygo#6617 · 5 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 62/100
tinygo-org/tinygo#6312 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của tinygo-org/tinygo
Issue tương tự
-
enhancement
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
sresarehumantoo/cc-artex#456 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
ollama/ollama#20021 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
factory:subtask
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
release
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 75/100
github/gh-aw-mcpg#17603 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
bboerst/stratum-work#351 ·
Maintainer thường phản hồi trong vòng 1 ngày