Skip to content

analyze audit:all fails on every ?? / unwrap_or: a downcast place typed as the enum vs codegen projecting the variant struct #1381

Closed

Description

@ehartford

Found during #1363. with analyze repro.w audit:all fails on the smallest carrier eliminator:

fn main:
    let o: Option[i32] = Some(3)
    print(o ?? 0)
violation: place 6 in main: projection lowers to LLVM type kind 10 but its MIR type 339 (Option[i32]) is kind 10; base _3: Option[i32] (ty 339) proj[0]=kind3:0 got-int-width=-1 want-int-width=-1
compiler-analysis-audit: facts=12175 violations=1 FAILED

Two defects:

  1. The MIR/codegen disagreement. lower_double_question, lower_unwrap_or_method, lower_unwrap_or_else_method and most Option/Result combinators in src/MirLower.w build new_downcast_place(value_place, idx, value_ty), typing the downcast place as the whole enum, while codegen (mir_place_projected_type) lowers PK_DOWNCAST to the variant struct. Match lowering passes sema type 0 (lines ~8646, ~8927), which the audit skips. One rule is needed: what type a downcast place has (the variant payload struct, or none), used by every producer.
  2. The message: "lowers to LLVM type kind 10 but ... is kind 10" compares type identity while printing only kinds, so it reads as a contradiction. Print both LLVM type names.

Because of (1), audit:all cannot be used as a gate on any program using ??/unwrap_or (the #1363 repro fails it for this reason alone, not for its real defect).

Activity

  1. ehartford commented on Sep 23, 2026

    @ehartford
    ContributorAuthor

    The same violation shows on every ? over a Result, not only ??/unwrap_or. With the seed at 8c859a7, analyze audit:all on

    error DbError =
        | Failed(status: i32)
    
    fn open(mode: i32) -> Result[i32, DbError]:
        if mode == 1: return Err(DbError.Failed(1))
        Ok(2)
    
    fn a(mode: i32) -> Result[i32, DbError]:
        let h = open(mode)?
        Ok(h)
    
    fn main:
        print(f"{a(0).is_ok()}")
    

    reports place 6 in a: projection lowers to LLVM type kind 10 but its MIR type 958 (Result[i32, DbError]) is kind 10 … proj[0]=kind3:1 (and kind3:0). Found on the stage 5 facade fixtures (#1426).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions