---
# System prepended metadata

title: Max_Size aspect summary

---

# Max_Size aspect summary

The original idea is to be able to annotate a tagged type declaration with a `Max_Size` aspect like so:

```ada
type Foo is tagged abstract null record 
with Max_Size => 16; --  I imagine the size would be in bytes
```

Then, any time a descendent would be declared, the compiler would verify that it satisfies the size constraints

```ada
type Bar is new Foo with record
   S : String (1 .. 128);
end record; --  ERROR: Record doesn't fit in 16 bytes
```

The usefulness of this is that the classwide type for `Foo` would be of a definite and known size, which would allow the users to do stuff like:

```ada
Inst : Foo'Class;
type Foo_Array is array (Positive range <>) of Foo'Class;
```

The nice part about this is that it is very simple. The tedious part is that you would have to plan in advance for the size, and that computing a size manually is kind of tedious.

Another idea would be to leverage another nice and useful new feature, which would be the ability to "seal" a tagged record or tagged record hierarchy (see https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/sealed for reference):

```ada
type Foo is tagged abstract null record
with Sealed => Package, Max_Size => Auto;
--  This type can only be derived inside the package it has been declared in.


type Bar is new Foo with record
    A, B : Integer;
end record;

type Baz is new Foo with record
    S : String (1 .. 128)
end record;

-- Size of Foo'Class automatically infered to be Max (Bar'Size, Baz'Size, ...)
```

The advantage of this is that you don't have to compute the `Max_Size` by hand anymore. The drawback being you need to declare your whole hierarchy in a single package, which might not always be desirable. So it seems that having both possibilities is the best.

TODO: Write a high level RFC for sealed tagged hierarchies.