| RFC-0038: Separating layout from constraints ||
|---|---|
| Status | Rejected |
| Areas | - FIDL |
| Description | We propose a syntax change to convey differences between layout from constraints. |
| Authors | - [pascallouis@google.com](https://fuchsia-review.googlesource.com/q/owner:pascallouis@google.com) |
| Date submitted (year-month-day) | 2019-03-07 |

[Edit this RFC](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/contribute/governance/rfcs/0038_separating_layout_from_constraints.md)
[Edit RFC metadata](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/contribute/governance/rfcs/_rfcs.yaml&searchAndJump=-+name:+'RFC-0038')

> [!NOTE]
> **Note:** Formerly known as [FTP](https://fuchsia.dev/fuchsia-src/contribute/governance/deprecated-ftp-process.md)-038.

## Rejection rationale

When this proposal was drafted, and socialized, there was a strong consensus to
consider syntax changes all at once, rather than one at a time (see also
[RFC-0039](https://fuchsia.dev/docs/contribute/governance/rfcs/0039_types_come_second)). We also
wanted one person to be the syntax arbiter, rather than risk designing by
committee.

Eventually, this proposal was obsoleted by
[RFC-0050](https://fuchsia.dev/docs/contribute/governance/rfcs/0050_syntax_revamp) which met
both conditions sought.

## Summary

We propose a syntax change to convey differences between layout from
constraints.

## Motivation

#### Layout vs constraint

Quickly:

- If two types have a different layout, it is not possible to soft transition from one to the other, and vice versa (not easily at least).
- The layout describes how the bytes are laid out, vs how they are interpreted.
- The constraint of a type is the validation step done during encoding/decoding.
- Constraints can evolve, and as long as writers are more constrained than readers, things are compatible.

#### Same syntax for different things

Types which have different layout, and types which have the same layout (but
different constraints) look alike.

Same layout:

- `vector<T>:6`, or `vector<T>:10`
- `T?` where `T` is a `union`, `vector`, or `string`
- `handle`, `handle<vmo>`, or `handle<channel>`

Different layout:

- `array<T>:6` vs `array<T>:10`
- `S?` where `S` is a `struct`

## Design

Align on the syntax

    layout:constraint

For types, i.e. anything that controls layout is before the colon, anything that
controls constraint is after the colon.

Suggested changes:

        array<T>:N    becomes            array<T, N>

        S?            becomes            box<S>:nullable       (S is a struct)

        T?            becomes            T:nullable            (T is a vector, or union)

        string        is an alias for    vector<uint8>:utf8

        handle<K>     becomes            handle:K

Notes:

- Not all constraints are meaningful for all types, for instance it is not possible to mark a `struct` nullable.
- Not everything can be boxed, initially only structs can (the goal is to change the syntax, not introduce more ways to have optionality).

## Ergonomics

This proposal improves ergonomics by conveying ABI implications to developers
through syntax.

## Documentation and Examples

At least:

- [Language Specification](https://fuchsia.dev/docs/reference/fidl/language/language)
- [Grammar](https://fuchsia.dev/docs/reference/fidl/language/grammar)
- Examples using structs

## Backwards Compatibility

This is not source level backwards compatible.

*** ** * ** ***

> [!NOTE]
> **Note:** This RFC was rejected early during its socialization phase, which explains the multiple missing sections (e.g. "Implementation strategy", or "Drawbacks, alternatives, and unknowns").

[](https://issues.fuchsia.dev/issues/new?component=1439230&template=1881640&description=Issue+on:+https://fuchsia.dev/docs/contribute/governance/rfcs/0038_separating_layout_from_constraints.md "Report a bug or suggest improvements on this page") [](https://cs.opensource.google/fuchsia/fuchsia/+/main:docs/contribute/governance/rfcs/0038_separating_layout_from_constraints.md "View the source code of this page") [](https://ci.android.com/edit?repo=fuchsia/fuchsia/main&file=docs/contribute/governance/rfcs/0038_separating_layout_from_constraints.md&cloneRepo=fuchsia/fuchsia:refs/heads/main&fullPath=fuchsia/docs/contribute/governance/rfcs/0038_separating_layout_from_constraints.md "Edit the source code of this page")