# stage2: use indexes for Decl objects · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/f7596ae9423e9de8276629803147e1a243f2177b)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: f7596ae9423e9de8276629803147e1a243f2177b

Requested commit: f7596ae9423e9de8276629803147e1a243f2177b

Commit: f7596ae9423e9de8276629803147e1a243f2177b

Tree: b97f2a8e8fdb84a118f587bcbfd76918710587dd

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
stage2: use indexes for Decl objects

Rather than allocating Decl objects with an Allocator, we instead allocate
them with a SegmentedList. This provides four advantages:
 * Stable memory so that one thread can access a Decl object while another
   thread allocates additional Decl objects from this list.
 * It allows us to use u32 indexes to reference Decl objects rather than
   pointers, saving memory in Type, Value, and dependency sets.
 * Using integers to reference Decl objects rather than pointers makes
   serialization trivial.
 * It provides a unique integer to be used for anonymous symbol names,
   avoiding multi-threaded contention on an atomic counter.

```

## Parents

- [4f527e5d36f66a83ff6a263a03f16e2c4d049f1e](https://git.cafe/gitcafe/zig/commit/4f527e5d36f66a83ff6a263a03f16e2c4d049f1e?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/f7596ae9423e9de8276629803147e1a243f2177b?format=markdown)
