Skip to content

Refactor IntrinsicFunction handling to align with stable-mir-json and existing development patterns #661

@Stevengre

Description

@Stevengre

The current implementation of IntrinsicFunction in mono.md deviates from our established patterns for modeling JSON contents in K sorts. This issue tracks the technical debt introduced in PR #659 to enable intrinsic function support, which we're accepting temporarily to unblock development.

Current Issues

  1. Inconsistent Symbol Naming Convention
    - The IntrinsicFunction constructor lacks the MonoItemKind:: prefix that other constructors use
    - Current: IntrinsicFunction(Symbol)
    - Expected: MonoItemKind::IntrinsicFunction(Symbol) or similar
  2. Deviation from JSON Modeling Pattern
    - Previously, all sorts used by kmir-ast.md were directly present in the JSON
    - IntrinsicFunction introduces a K-specific constructor that doesn't directly correspond to the JSON structure
    - This breaks the 1:1 mapping between stable-mir-json output and K sorts

Proposed Solution

Consider refactoring to use a different sort structure that better separates concerns:

  • Create distinct constructors like Function(Symbol, Body) and Intrinsic(Symbol) in the runtime function table. This would maintain the JSON modeling integrity while still supporting intrinsic functions
  • Don't tightly couple stable-mir-json and kmir, but rather let stable-mir-json focus on extracting all useful MIR information, while kmir focuses on formal semantics. The connection between stable-mir-json and kmir can also be accomplished through a tool.

Context

Notes

This refactoring should be done after:

  1. The relationship between kmir and stable-mir-json is better defined
  2. Any broader kmir refactoring efforts are completed
  3. The stable-mir-json intrinsics PR is merged and stabilized

Metadata

Metadata

Assignees

Labels

refactorTool Improvement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions