understanding-stability-inference

Explains why the Compose compiler classifies types as stable, runtime, unknown, or unstable.

Updated May 31, 2026
One-click install
npx skills add https://github.com/decoutkhanqindev/Lich-Viet-Loc-Phat --skill understanding-stability-inference-decoutkhanqindev
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: understanding-stability-inference
Source: https://github.com/decoutkhanqindev/Lich-Viet-Loc-Phat/tree/main/.claude/skills/understanding-stability-inference
Command: npx skills add https://github.com/decoutkhanqindev/Lich-Viet-Loc-Phat --skill understanding-stability-inference-decoutkhanqindev

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve? Compose compiler stability reports often show surprising verdicts like runtime stable, unknown, or unstable for classes that look fine, and developers cannot tell why. This Skill teaches the 12-phase inference algorithm the compiler uses so you can explain and predict any classification before running a report. ## Core Features & Use Cases - 12-Phase Algorithm Walkthrough: Trace any type through the exact phases the Compose compiler runs, from the primitive fast path through cycle detection, annotation checks, the Known Stable Constructs registry, and field-by-field analysis. - Generic Bitmask Decoding: Interpret Pair=0b11, ImmutableList=0b1, and @StabilityInferred(parameters = ...) bitmasks, plus the runtime $stable: Int field on JVM and the mangled property on Native/JS. - Use Case: A report says runtime stable class Box<T> for a generic class from another module. Use this Skill to explain that separate compilation emitted @StabilityInferred and a $stable field, that the verdict is correct and not a bug, and that the runtime resolves it with one Int load and a bitwise AND. ## Quick Start Ask the assistant to explain why the Compose compiler classified a specific class or composable parameter as runtime stable, unknown, or unstable.

Frequently Asked Questions about understanding-stability-inference

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

FAQPage Schema
Why does the Compose compiler report my class as runtime stable?▼

Runtime stable means the class was compiled in a separate module, so the compiler emitted @StabilityInferred with a parameter bitmask and a $stable: Int field. The runtime ANDs that bitmask against the actual type arguments. It is a correct verdict, not a bug or an unstable classification.

How does Compose stability inference work for generic classes?▼

Generic classes are classified as Stability.Parameter with a bitmask where bit i set means type argument Ti affects stability. For example Pair uses 0b11 and ImmutableList uses 0b1. At the call site, the bitmask is ANDed against the substituted argument stabilities to produce the final verdict.

Why is my recursive data class unstable in Compose?▼

The compiler's cycle detection phase conservatively returns unstable for recursive types like Node(children: List<Node>) to guarantee termination. The fix is annotating the recursive class with @Immutable and using ImmutableList, which hits the Known Stable Constructs registry before cycle detection matters.

What is the difference between unknown and unstable in Compose stability?▼

Unknown means the compiler cannot decide, typically for interfaces and abstract classes, and the runtime falls back to identity (===) equality. Unstable means the compiler proved instability, such as a var property or an unstable field type, which disables skipping outright.

Does @Immutable enable more optimizations than @Stable in Compose?▼

Yes. Both classify as Stability.Certain, but @Immutable promises the value never changes, letting the compiler promote property reads to static expressions and elide equality checks. @Stable only promises change notification, so equality probes are still emitted.

When should I not use this stability inference skill?▼

Skip it when no compiler report exists yet, when the fix is mechanical like changing var to val or List to ImmutableList, or when you want CI enforcement of stability. Those cases belong to the diagnosing, stabilizing, and CI-enforcement skills respectively.