Borrow function arguments and use one byte type

Abierto
#1,987 1 comentario 0 reacciones 0 asignados Ver en GitHub

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
38/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust
Área
api

Línea de trabajo

Start from Sandbox::call on the host side and the guest call_host path, then trace how String, Vec<u8> and Vec<Bytes> arguments are converted and placed into virtqueue buffers. The issue names the target types and copy counts but not files or tests, so locate the serialization and guest parameter-reading code before changing signatures. Done means &str and &[u8] are accepted alongside owned values, and all byte arguments use one wire format whose guest-side read depends on whether the parameter is Vec<u8> or Vec<Bytes>.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

A-api S-needs-triage

Function calls copy byte and string arguments more often than they need to.

Problem

  • call and call_host take arguments by value. A caller that holds a &str or &[u8] must clone it first, even though the call only reads it.
  • A function can receive bytes as Vec<u8> or Vec<Bytes>. In the guest, Vec<u8> joins the transport buffers into a new vector and Vec<Bytes> does not. The cost is hidden in the receiver's signature.

Proposal

Callers pass borrowed values. Functions take and return bytes only as Vec<Bytes>.

Arguments Parameters and return types
Scalars i32, u32, i64, u64, f32, f64, bool same, plus () as a return type
Strings &str String
Bytes &[u8], &[u8; N], &[Bytes] Vec<Bytes>

Arguments are what callers pass to call, call_host and #[host_function] stubs. Parameters and return types are what #[guest_function] and host functions declare.

Breaking changes

  • Owned String, Vec<u8>, Bytes and Vec<Bytes> are no longer accepted as arguments. Pass s.as_str(), &v or &chunks.
  • Vec<u8> is no longer a parameter or return type. Use Vec<Bytes>. concat() joins the chunks when a function needs one contiguous buffer.

These are hard breaks, but each fix is a one-line change at a call site or a function signature, and the compile error names it.

Effect

Copies per byte argument, host to guest:

Caller holds Guest parameter (today) Today After
Vec<u8> Vec<u8> 2 1
&[u8] Vec<u8> 3 1
&[u8] Vec<Bytes> 2 1
Vec<Bytes> Vec<Bytes> 1 1

After the change, every byte argument takes one copy: the host writes it into the guest's transport buffers, and the guest reads it from them in place. Guest-to-host calls save the caller's clone. The host still copies guest data once before reading it, for safety.

Lenguaje dominante
Rust
Estrellas
4.8k
Forks
222
Merge medio
1 d 16 h
PR fusionados (30 d)
60

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de hyperlight-dev/hyperlight

Todos los issues de hyperlight-dev/hyperlight

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.