runtimeverification / runtimeverification/mir-semantics

Support struct-like variants in `parser.py`

Open
#696 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
52
Forks
5
PR merge metrics
No merged PRs in 30d

Description

Consider

pub enum VariantsShape {
    Single { index: VariantIdx },
    Multiple {
        tag: Scalar,
        tag_encoding: TagEncoding,
        tag_field: usize,
        variants: Vec<LayoutShape>,
    },
}

This can be modeled with proper parser support in K as follows:

syntax VariantsShape ::= variantsShapeSingle(VariantsShapeSingle)     [group(mir-enum), symbol(VariantsShape::Single)]
                       | variantsShapeMultiple(VariantsShapeMultiple) [group(mir-enum), symbol(VariantsShape::Multiple)]

syntax VariantsShapeSingle ::= mk(index: VariantIdx) [group(mir---index)]

syntax VariantsShapeMultiple ::= mk ( tag: Scalar
                                    , tagEncoding: TagEncoding
                                    , tagField: MIRInt
                                    , variants: LayoutShapes
                                    ) [group(mir---tag--tag-encoding--tag-field--variants)]

The ideal solution would be to eliminate the mk constructors, and model the struct-like variants directly, e.g.:

syntax VariantsShape ::= variantsShapeSingle(index: VariantIdx) [group(mir-enum---index), symbol(VariantsShape::Single)]
                       | variantsShapeMultiple ( tag: Scalar
                                               , tagEncoding: TagEncoding
                                               , tagField: MIRInt
                                               , variants: LayoutShapes
                                               ) [group(mir-enum---tag--tag-encoding--tag-field--variants), symbol(VariantsShape::Multiple)]

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in parser.py and compare the existing handling of enum variants with the VariantsShape examples in the issue. Determine how the Single and Multiple fields map into the parser's K syntax, then verify that both struct-like forms are accepted and represented correctly. The ideal completion removes the intermediate mk constructors where possible.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.