compiler: zero-capacity slice pointers differ from Go

Aperta
#6,171 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

  • #6172 di @davecheney — chiusa senza merge

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
go
Ambito
compilers

Direzione di ricerca

Start by reading the slice expression handling in TinyGo’s compiler and compare left-slice behavior with Go’s behavior described in the issue. The examples cover slice, three-index, nested-slice, and array cases; use them to identify the affected cases and define compatibility as matching Go’s printed pointer comparisons. Pull request #6172 is already open for this issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

When slicing produces a zero-capacity result, TinyGo advances the data pointer by the start index. Go’s compiler currently keeps the input pointer. This difference is visible through unsafe.SliceData and reflect.Value.Pointer.

package main

import (
	"fmt"
	"unsafe"
)

func main() {
	s := []byte{1, 2, 3, 4, 5}
	fmt.Println("slice end:", unsafe.SliceData(s[5:]) == unsafe.SliceData(s))
	fmt.Println("three-index:", unsafe.SliceData(s[2:2:2]) == unsafe.SliceData(s))

	tail := s[1:]
	fmt.Println("nested end:", unsafe.SliceData(tail[4:]) == unsafe.SliceData(tail))

	a := [5]byte{}
	fmt.Println("array end:", unsafe.SliceData(a[5:]) == &a[0])
}

Go 1.27.3 prints:

slice end: true
three-index: true
nested end: true
array end: true

TinyGo dev (45c6e674) prints:

slice end: false
three-index: false
nested end: false
array end: false

The Go spec does not specify the address used for a zero-capacity result. For a non-nil slice with zero capacity, unsafe.SliceData specifies a non-nil pointer to an unspecified address. Both results are permitted, so matching Go would be a compatibility improvement rather than a specification fix.

The GC retention concern in #1078 has already been addressed. This issue concerns the remaining observable pointer difference. In #4214, @niaow suggested clamping left-slice operations like Go does.

Lingua principale
Go
Stelle
17.8k
Fork
1.1k
Merge medio
1g 4h
PR unite (30g)
380

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tinygo-org/tinygo

Tutte le issue di tinygo-org/tinygo

Issue simili

Altre issue su Go

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.