Skip to content

Enhancement: Compiler diagnostics improvements #7

@Chesterguan

Description

@Chesterguan

Summary

Potential improvements to the compiler diagnostics identified during RFC-0006 implementation review.

Proposed Enhancements

1. Transitive Unused Entity Detection

Current behavior: A signal used only by an unused trend is not flagged as unused.

Example:

signals:
  BUN:
    ref: blood_urea_nitrogen  # Not flagged as unused

trends:
  bun_unused:
    expr: sma(BUN, 24h)  # Flagged as unused

logic:
  alert:
    when: some_other_trend > 0  # Does not use bun_unused

Proposed: Add "transitively unused" warnings for signals that are only used by unused trends.

2. Expanded Diagnostic Codes

Current codes (in DiagnosticCode):

  • S100: Signal not found
  • T101: Trend unknown signal
  • L101: Logic unknown term
  • D100: DAG circular dependency
  • W100: Unused signal
  • W101: Unused trend

Proposed additions:

  • T102: Trend uses deprecated operator
  • T103: Trend window exceeds recommended maximum
  • L102: Logic expression complexity warning
  • W102: Transitively unused signal
  • I100: Info - optimization suggestion

3. Optional Strict Schema Validation Mode

Current behavior: Parser is more permissive than JSON Schema for developer convenience.

Proposed: Add --strict flag to parser that validates against full JSON Schema (requires psdl_version, audit, outputs).

# Current (permissive)
scenario = parse_scenario(yaml)

# Proposed (strict mode)
scenario = parse_scenario(yaml, strict=True)  # Validates against spec/schema.json

Implementation Notes

  • These are non-breaking enhancements
  • Transitive detection requires updating _detect_unused_entities() in compile.py
  • Strict mode can leverage existing _generated/validate.py

Related

  • RFC-0006: Spec-Driven Compilation Architecture
  • src/psdl/core/compile.py: CompilationDiagnostics
  • src/psdl/_generated/validate.py: Schema validation utilities

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions