Skip to content

Conversation

@samcowger
Copy link
Contributor

This refactors crux-mir's Mir.Overrides.regEval to give access to the MIR Type of a value being concretized, in addition to its TypeRepr.

This is largely meant to be a refactoring and functionality-preserving change to help give access to more type information at concretization time, to support work on #1666. However, it does restrict concretization a bit, as regEval conducts stricter typechecking of values being concretized. I've included an xfail test demonstrates one such bit of restriction on slices.

Note to reviewers: this includes a fair amount of whitespace-only changes, so it's probably easier to review it commit by commit.

@samcowger samcowger marked this pull request as ready for review January 8, 2026 00:59
Copy link
Contributor

@RyanGlScott RyanGlScott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks plausible at a glance, although it will be hard to truly evaluate this until a solution for #1666 is implemented.

, Just Refl <- testEquality tpr (cfgReturnType cfg)
= bindFnHandle (cfgHandle cfg) $ UseOverride $ mkOverride' "concretize" tpr $ concretize symOnline
= let fns = cs ^. collection . M.functions
fn = fns Map.! textId name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Worth leaving a comment here about why this use of Map.! (a partial function) is expected to succeed. It might also be worth making this panic in the event that the lookup fails, as Map.! won't give a very helpful error message if it does fail.

Comment on lines +211 to +214
-- produce that same `tpr`. The type is in `Maybe` because there are cases
-- in which it's unknowable/inapplicable - for instance, in `goMirRef`, we
-- can't recover the `M.Ty` of the reference's `RefRoot`, only its
-- `TypeRepr`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we implement a solution for #1666, what will happen in the cases where the Maybe Ty argument is Nothing? Will we not be able to deduce type widths for array elements in such cases? If so, what are the ramifications of not being able to do so?

Comment on lines +236 to +237
go Nothing MirSliceRepr _ =
throwUnsupported sym "slice-like value of unknown MIR type"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unlike other go Nothing cases, this one actually throws an error outright. Does this mean that concretization of slices can throw this error message in certain cases? Would it be worth adding a test for this?

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.

3 participants