Skip to content

Spike: More reflection support#5582

Draft
StachuDotNet wants to merge 4 commits intodarklang:mainfrom
StachuDotNet:reflection
Draft

Spike: More reflection support#5582
StachuDotNet wants to merge 4 commits intodarklang:mainfrom
StachuDotNet:reflection

Conversation

@StachuDotNet
Copy link
Member

We had a Builtin.reflect. I had AI think: what similar things might we find useful?

StachuDotNet and others added 4 commits January 23, 2026 02:19
Create comprehensive plan to expand reflection system beyond the current
minimal Builtin.reflect. Plan includes:

- Adding 3 new core builtins (reflectType, typeOf, typeName)
- Creating Darklang.LanguageTools.Reflection package with helpers
- Adding tests and demos for reflection capabilities
- Writing CLI integration report exploring reflection use cases
- Keeping F# code changes minimal and focused

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Added three new builtins to Reflection.fs:
  - Builtin.reflectType: Get ValueType without full Dval structure
  - Builtin.typeOf: Human-readable type names (e.g., 'Int64', 'List<String>')
  - Builtin.typeName: Extract FQTypeName for custom types (records/enums)

- Created comprehensive Darklang.LanguageTools.Reflection package module:
  - Type checking helpers: isPrimitive, isCollection, isCustomType, isFunction
  - Type-specific checks: isList, isDict, isTuple, isRecord, isEnum
  - Data extraction: getFields, getCaseName, getListElementType, getDictValueType

- Added reflection-demo.dark with practical examples:
  - Type-aware pretty printing
  - Type validation and serialization checks
  - Metadata extraction from custom types
  - Schema inference for collections

- Added comprehensive tests:
  - stdlib/reflection.dark: Tests for all new builtins with primitives, collections, and custom types
  - cli/reflection-test.dark: CLI integration test demonstrating reflection usage

- Created reflection-cli-integration.md report analyzing:
  - CLI command ideas (inspect, type, debug, infer-schema, validate)
  - REPL enhancements with type display
  - App/editor integration possibilities (hover types, value inspector, auto-completion)
  - Implementation priorities and technical considerations

Key design decisions:
- Minimal F# code impact (only 3 new builtins in Reflection.fs)
- Most functionality in Darklang package code for flexibility
- Focused on practical, useful reflection operations
- Lightweight alternatives to full reflection for performance

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant