compiler: no escape analysis at -opt=0
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 42/100
- Tipo de issue
- Error
- Claridad
- Bastante claro
- Estado de actividad
- Activo
- Stack tecnológico
- go
- Área
- build-system, compilers
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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
- Lenguaje dominante
- Go
- Estrellas
- 17.8k
- Forks
- 1.1k
- Merge medio
- 1 d 4 h
- PR fusionados (30 d)
- 380
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de tinygo-org/tinygo
-
avr: SPI Mode2 runs as mode 1Abiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
tinygo-org/tinygo#6727 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
tinygo-org/tinygo#6711 ·
Los mantenedores suelen responder en 1 día
-
Builds are not reproducible: cgo snippet paths in debug infoPosiblemente ocupada @tridev-tej la tomó hace 1 día. Abiertoenhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
tinygo-org/tinygo#6619 ·
Los mantenedores suelen responder en 1 día
-
Fix the targets that tinygo build -target rejectsPosiblemente ocupada @narguis la tomó hace 2 días. Abiertobug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
tinygo-org/tinygo#6617 · 5 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
tinygo-org/tinygo#6312 ·
Los mantenedores suelen responder en 1 día
Todos los issues de tinygo-org/tinygo
Issues similares
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
sresarehumantoo/cc-artex#456 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
ollama/ollama#20021 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
factory:subtask
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
Los mantenedores suelen responder en 1 día
-
release
Dificultad 1/5 Menos de una hora Aptitud para principiantes 75/100
github/gh-aw-mcpg#17603 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
bboerst/stratum-work#351 ·
Los mantenedores suelen responder en 1 día