data-structure

Guide compiler data structure design with typed indices and Span ranges.

64|21|Updated Nov 19, 2025
One-click install
npx skills add https://github.com/plankevm/plank-monorepo --skill data-structure
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: data-structure
Source: https://github.com/plankevm/plank-monorepo/tree/main/plankc/.claude/skills/data-structure
Command: npx skills add https://github.com/plankevm/plank-monorepo --skill data-structure

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Provides concrete design guidance for compiler data structures to avoid lifetime complexity, invalid indices, and fragile references when managing arenas and interlinked collections.

Core Features & Use Cases

  • Prefer storing typed indices instead of direct references to avoid Rust lifetime issues and enable mutation without borrow conflicts.
  • Use Span for contiguous child ranges that point into a shared arena to keep parent structs compact and often Copy.
  • Never manually construct indices; obtain them from collection operations such as push, enumerate_idx, or iter_idx to guarantee validity.
  • Anti-patterns to avoid: using plain Vec when elements are referenced by index, mixing raw usize across collections, storing &T references for long-term linking, and constructing indices by hand.
  • Libraries and patterns: use newtype_index to declare compact typed indices, plank_core IndexVec for index-typed collections, Span for range semantics, and DenseIndexSet for bitset membership operations.

Quick Start

When adding a new AST node, define a typed index with newtype_index, store instances in plank_core IndexVec, and reference child ranges using Span instead of per-parent Vecs.

Frequently Asked Questions about data-structure

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I avoid Rust lifetime issues when designing compiler data structures?

To avoid Rust lifetime issues in compiler data structures, store typed indices instead of direct references. This approach enables mutation without borrow conflicts and guarantees validity by obtaining indices from collection operations like push or enumerate_idx.

What is the best way to manage contiguous child ranges in a Rust AST arena?

The best way to manage contiguous child ranges in a Rust AST arena is using Span. Span provides range semantics that point into a shared arena, keeping parent structs compact and often Copy instead of allocating per-parent Vecs.

How do I implement safe index-based collections for a Rust compiler?

Implement safe index-based collections by declaring compact typed indices with newtype_index and using IndexVec. Never manually construct indices; obtain them from collection operations to guarantee type safety and prevent invalid index usage.

Why should I avoid storing direct references in compiler data structures?

You should avoid storing direct references because they cause Rust lifetime complexity and fragile linking. Storing typed indices instead enables safe mutation without borrow conflicts and ensures long-term structural integrity across interlinked collections.

What are common anti-patterns when using indices with Vec in Rust compilers?

Common anti-patterns include using plain Vec when elements are referenced by index, mixing raw usize across collections, storing long-term references, and constructing indices by hand. These practices lead to invalid indices and fragile code.

Can I use DenseIndexSet for membership operations in a Rust compiler?

Yes, you can use DenseIndexSet for bitset membership operations in a Rust compiler. It provides type-safe membership tracking when combined with typed indices and plank_core utilities, preventing invalid index construction.