Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suboptimal placement of comment #388

Open
msprotz opened this issue Sep 30, 2024 · 3 comments · May be fixed by #389
Open

Suboptimal placement of comment #388

msprotz opened this issue Sep 30, 2024 · 3 comments · May be fixed by #389
Assignees
Labels
C-bug A bug in charon

Comments

@msprotz
Copy link
Contributor

msprotz commented Sep 30, 2024

Consider the following function (from mlkem):

pub(crate) fn barrett_reduce_element(value: FieldElement) -> FieldElement {
    // hax_debug_assert!(
    //     i32::from(value) > -BARRETT_R && i32::from(value) < BARRETT_R,
    //     "value is {value}"
    // );

    let t = (i32::from(value) * BARRETT_MULTIPLIER) + (BARRETT_R >> 1);
    ...

If I dump what I receive from Charon, the comment is attached to the intermediary (unnamed) value that MIR introduces for i32::from(value) (which internally is just value), or more specifically:

// pseudo-MIR
fn barrett_...(...) {
... lots of variable declarations
i32 t; // this is the user-provided name
... lots of variable declarations
i32 tmp; // internal MIR name
... lots more variable declarations
<<comment attached to the assignment below>>
tmp := value;

I would expect the comment to be attached either to
i) the declaration i32 t; or ii) the assignment into t that comes further down (not modeled in the snippet above).

Right now, Eurydice tracks the location of the comment all the way down to C, re-inlines the temporary computations, and produces something unsightly:

  int32_t
  t =
    (int32_t)/*
    hax_debug_assert!(
    i32::from(value) > -BARRETT_R && i32::from(value) < BARRETT_R,
    "value is {value}"
    );
    */
      value

notice how the comment is attached to the inner value, per the original LLBC received from Charon. Thank you!

@msprotz msprotz added the C-bug A bug in charon label Sep 30, 2024
@msprotz
Copy link
Contributor Author

msprotz commented Sep 30, 2024

initially spotted by @franziskuskiefer

@Nadrieril
Copy link
Member

Right now I assign each comment to the first MIR statement that has a matching span. Maybe I should choose the last one instead? I expect that being more precise than that will be hard because I can't inspect the original syntax.

@Nadrieril
Copy link
Member

Nevermind I can do better

@Nadrieril Nadrieril linked a pull request Oct 1, 2024 that will close this issue
@Nadrieril Nadrieril self-assigned this Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug A bug in charon
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants