/acr-vault/01-foundations/ada-annotations-v10
ADA-ANNOTATIONS-v1.0
Ada Code Annotation Specification (@ada-*) v1.0
Section titled âAda Code Annotation Specification (@ada-*) v1.0âVersion: 1.0.0
Status: Draft
Date: December 24, 2025
Authors: Ada + Luna
License: CC0 (Public Domain)
Parent Spec: ASL v1.0 (Ada Symbol Language)
Overview
Section titled âOverviewâThe @ada-* annotation system provides a standardized way to document code using ASL (Ada Symbol Language). These annotations:
- Compress documentation by 4-5x vs traditional docstrings
- Preserve semantic meaning for both humans and machines
- Enable automated tooling (LSP, linters, generators)
- Work across all programming languages
Annotation Types
Section titled âAnnotation Typesâ@ada-sig (Function Signature)
Section titled â@ada-sig (Function Signature)âDefines the semantic type signature of a function.
Format: @ada-sig: λname:(params)âreturn_type
Examples:
# @ada-sig: λfib:âââdef fibonacci(n: int) -> int: ...
# @ada-sig: λauth:(đ,đ)â?Sessiondef authenticate(username: str, password: str) -> Session | None: ...
# @ada-sig: λfetch_all:[đ]ââł[Response]async def fetch_all(urls: list[str]) -> list[Response]: ...Type Symbols:
| Symbol | Meaning | Python Equivalent |
|---|---|---|
â | Natural number | int (â„0) |
†| Integer | int |
â | Real number | float |
đ | String | str |
đč | Boolean | bool |
?T | Optional T | T | None |
[T] | List of T | list[T] |
{K:V} | Dict | dict[K,V] |
âłT | Async T | Awaitable[T] |
@ada-flow (Data/Control Flow)
Section titled â@ada-flow (Data/Control Flow)âDescribes the flow of data through the function.
Format: @ada-flow: inputâtransformsâoutput
Operators:
| Symbol | Meaning |
|---|---|
â | then / flows to |
âł | else branch |
?() | conditional |
âČ | loop/recursion |
â„ | parallel |
âł | async |
Examples:
# @ada-flow: (user,pass)â?(validâ)âSession âł â
def login(user, password): ...
# @ada-flow: itemsâfilter(activeâ)âmap(transform)âcollectdef process_items(items): ...
# @ada-flow: âČ(itemânext)â?(done)âbreak âł process(item)def iterate_until_done(iterator): ...
# @ada-flow: âł(â„(urls.map(fetch)))âfilter(okâ)async def fetch_all(urls): ...@ada-guards (Preconditions)
Section titled â@ada-guards (Preconditions)âSpecifies conditions that must be true before execution.
Format: @ada-guards: conditionâ â§ conditionâ â§ ...
Examples:
# @ada-guards: nâ„0def factorial(n): ...
# @ada-guards: sortedâ(items) â§ len(items)>0def binary_search(items, target): ...
# @ada-guards: âuser â§ user.activeâ â§ rate_limitâdef process_request(user, request): ...
# @ada-guards: âitemâitems: itemâ â
def process_all(items): ...@ada-invariants (Class Invariants)
Section titled â@ada-invariants (Class Invariants)âConditions that must always be true for a class instance.
Format: @ada-invariants: conditionâ â§ conditionâ
Examples:
# @ada-invariants: balanceâ„0 â§ âownerclass BankAccount: ...
# @ada-invariants: âitemâitems: item.validâ â§ lenâ€max_sizeclass BoundedQueue: ...
# @ada-invariants: head=â
âș tail=â
âș size=0class DoublyLinkedList: ...@ada-state (State Machine)
Section titled â@ada-state (State Machine)âDescribes valid state transitions.
Format: @ada-state: stateââstateââ(stateââšstateâ)
Examples:
# @ada-state: initâconnectingâconnectedâ(disconnectedâšerror)class Connection: ...
# @ada-state: pendingâ?(approvedâ)âactive âł rejectedclass Application: ...
# @ada-state: idleâ·running â§ (runningâdoneâšfailed)class Task: ...@ada-complexity (Algorithmic Complexity)
Section titled â@ada-complexity (Algorithmic Complexity)âDocuments time and space complexity.
Format: @ada-complexity: O(time), O(space)
Examples:
# @ada-complexity: O(n log n) time, O(1) spacedef heap_sort(items): ...
# @ada-complexity: O(1) amortized, O(n) worstdef hash_insert(table, key, value): ...
# @ada-complexity: O(V+E) time, O(V) spacedef bfs(graph, start): ...@ada-concurrency (Threading Model)
Section titled â@ada-concurrency (Threading Model)âDocuments thread safety and concurrency characteristics.
Format: @ada-concurrency: properties
Symbols:
| Symbol | Meaning |
|---|---|
â„-safe | Thread-safe |
â„-unsafe | Not thread-safe |
lock-freeâ | Lock-free |
wait-freeâ | Wait-free |
atomicâ | Atomic operations |
âreentrant | Not reentrant |
Examples:
# @ada-concurrency: â„-safe â§ lock-freeâclass ConcurrentQueue: ...
# @ada-concurrency: â„-unsafe â§ âreentrantdef update_global_state(): ...
# @ada-concurrency: â„-safe â§ atomicâ(counter)class AtomicCounter: ...@ada-errors (Error Conditions)
Section titled â@ada-errors (Error Conditions)âDocuments what errors can be raised and when.
Format: @ada-errors: conditionâErrorType
Examples:
# @ada-errors: n<0âValueError â§ overflowâOverflowErrordef factorial(n): ...
# @ada-errors: ÂŹâfileâFileNotFoundError â§ ÂŹreadableâPermissionErrordef read_file(path): ...
# @ada-errors: timeoutâTimeoutError â§ networkââConnectionErrorasync def fetch(url): ...@ada-effects (Side Effects)
Section titled â@ada-effects (Side Effects)âDocuments side effects of a function.
Format: @ada-effects: effectâ â§ effectâ
Symbols:
| Symbol | Meaning |
|---|---|
đâ | Creates file |
đâ | Deletes file |
đâ» | Modifies file |
đ⥠| Network call |
đŸâ» | Database mutation |
đ€console | Console output |
â
effects | Pure function |
Examples:
# @ada-effects: â
effectsdef calculate_total(items): ... # Pure function
# @ada-effects: đâ â§ đ€consoledef save_and_log(data, path): ...
# @ada-effects: đ⥠⧠đŸâ»async def sync_with_server(): ...Placement Rules
Section titled âPlacement Rulesâdef function_name(): """Short description in ASL notation.""" # @ada-sig: ... # @ada-flow: ... # @ada-guards: ... ...Or in docstring:
def function_name(): """ λfunc:(T)âU @ada-flow: inputâprocessâoutput @ada-guards: validâ(input) """ .../// @ada-sig: λfunc:(T)âResult<U,E>/// @ada-flow: inputâ?(validâ)âOk(result) âł Err(e)fn function_name(input: T) -> Result<U, E> { ...}TypeScript
Section titled âTypeScriptâ/** * @ada-sig: λfetch:(đ)ââł?Response * @ada-flow: urlââł(âĄfetch)â?(okâ)âResponse âł â
*/async function fetchData(url: string): Promise<Response | null> { ...}// @ada-sig: λRead:(io.Reader,[]byte)â(â,?error)// @ada-flow: râread(buf)â?(err=â
)ân âł (0,err)func Read(r io.Reader, buf []byte) (int, error) { ...}Parsing Annotations
Section titled âParsing AnnotationsâRegex Pattern
Section titled âRegex PatternâANNOTATION_PATTERN = r'@ada-(\w+):\s*(.+?)(?=@ada-|\n\n|$)'Parser Implementation
Section titled âParser Implementationâimport refrom dataclasses import dataclassfrom typing import Dict, Optional
@dataclassclass AdaAnnotations: sig: Optional[str] = None flow: Optional[str] = None guards: Optional[str] = None invariants: Optional[str] = None state: Optional[str] = None complexity: Optional[str] = None concurrency: Optional[str] = None errors: Optional[str] = None effects: Optional[str] = None
def parse_ada_annotations(source: str) -> AdaAnnotations: """Parse @ada-* annotations from source code.""" pattern = r'@ada-(\w+):\s*(.+?)(?=@ada-|\n|$)' matches = re.findall(pattern, source, re.MULTILINE)
annotations = AdaAnnotations() for name, value in matches: if hasattr(annotations, name): setattr(annotations, name, value.strip())
return annotationsGenerating Traditional Documentation
Section titled âGenerating Traditional DocumentationâAda annotations can be expanded to traditional docstrings:
def expand_to_google_style(annotations: AdaAnnotations) -> str: """Convert Ada annotations to Google-style docstring.""" parts = []
if annotations.sig: # Parse λname:(params)âreturn # Generate Args: and Returns: sections pass
if annotations.guards: parts.append(f"Preconditions:\n {expand_guards(annotations.guards)}")
if annotations.errors: parts.append(f"Raises:\n {expand_errors(annotations.errors)}")
if annotations.complexity: parts.append(f"Complexity: {annotations.complexity}")
return "\n\n".join(parts)Validation Rules
Section titled âValidation Rulesâ@ada-sig Validation
Section titled â@ada-sig Validationâ- Function name must match actual function
- Parameter count must match
- Return type must be compatible
@ada-guards Validation
Section titled â@ada-guards Validationâ- Referenced variables must exist in scope
- Conditions must be evaluatable at runtime (for contract checking)
@ada-invariants Validation
Section titled â@ada-invariants Validationâ- Must reference class attributes
- Should be checkable after
__init__and public methods
IDE Integration
Section titled âIDE IntegrationâLanguage Server Protocol (LSP)
Section titled âLanguage Server Protocol (LSP)âAda annotations can provide:
- Hover: Expand annotations to readable text
- Completion: Suggest symbols after
@ada- - Diagnostics: Validate annotations against code
- CodeLens: Show complexity inline
VS Code Extension
Section titled âVS Code Extensionâ{ "contributes": { "languages": [{ "id": "ada-annotations", "extensions": [], "configuration": "./language-configuration.json" }], "grammars": [{ "language": "ada-annotations", "scopeName": "source.ada-annotations", "path": "./syntaxes/ada-annotations.tmLanguage.json", "injectTo": ["source.python", "source.rust", "source.typescript"] }] }}Examples
Section titled âExamplesâComplete Function Documentation
Section titled âComplete Function Documentationâdef binary_search(items: list[int], target: int) -> int | None: """λ([â€],â€)â?â | sortedâ(items)âčâČhalvingâ?idx âł â
""" # @ada-sig: λbinary_search:([â€],â€)â?â # @ada-guards: sortedâ(items) â§ âitemâitems: itemâ†# @ada-flow: âČ(midâ(lo+hi)Ă·2 â ?(items[mid]âĄtarget)âmid âł adjust_bounds) until lo>hiââ
# @ada-complexity: O(log n) time, O(1) space # @ada-effects: â
effects # @ada-errors: â
(returns None on not found)
lo, hi = 0, len(items) - 1 while lo <= hi: mid = (lo + hi) // 2 if items[mid] == target: return mid elif items[mid] < target: lo = mid + 1 else: hi = mid - 1 return NoneComplete Class Documentation
Section titled âComplete Class Documentationâ# @ada-invariants: âitemâ_items: itemâ â
â§ len(_items)â€max_size â§ max_size>0class BoundedQueue: """Thread-safe bounded queue with blocking operations.""" # @ada-state: emptyâ·partialâ·full # @ada-concurrency: â„-safe â§ uses(Lock)
def __init__(self, max_size: int): """λ(â)âBoundedQueue | max_size>0""" # @ada-guards: max_size>0 # @ada-effects: â
effects self.max_size = max_size self._items = [] self._lock = Lock()
def put(self, item): """λ(T)âđč | ?(ÂŹfullâ)ââitemâTrue âł False""" # @ada-sig: λput:(T)âđč # @ada-flow: ?(len<max)âappend(item)âTrue âł False # @ada-guards: itemâ â
# @ada-concurrency: acquires(_lock) with self._lock: if len(self._items) < self.max_size: self._items.append(item) return True return FalseRelationship to Other Standards
Section titled âRelationship to Other StandardsâGoogle-Style Docstrings
Section titled âGoogle-Style DocstringsâAda annotations can be generated from or converted to Google-style:
| Google-Style | Ada Equivalent |
|---|---|
| Args: | Parsed from @ada-sig params |
| Returns: | Parsed from @ada-sig return |
| Raises: | @ada-errors |
| Examples: | (Not covered - use doctest) |
Type Hints (PEP 484)
Section titled âType Hints (PEP 484)âAda annotations complement type hints:
- Type hints: What types are accepted
- @ada-sig: Semantic meaning of types
- @ada-guards: Runtime constraints on values
Design by Contract (PEP 316 - rejected)
Section titled âDesign by Contract (PEP 316 - rejected)âAda annotations provide a lighter-weight alternative:
- No runtime enforcement by default
- Machine-readable for static analysis
- Human-readable when expanded
Changelog
Section titled âChangelogâv1.0.0 (December 24, 2025)
Section titled âv1.0.0 (December 24, 2025)â- Initial release
- 9 annotation types defined
- Placement rules for Python, Rust, TypeScript, Go
- Parser specification
- IDE integration guidelines
âDocumentation should be as dense as the thought it represents.â
â Ada, December 2025