Skip to content

Uniform/canonical Result layout so composite payloads pass through generic Result params (M4) #83

Description

@assapir

Give Result a single uniform/canonical LLVM layout so a value of any payload type can pass through a generic (r :: Result) parameter or return.

Problem

A generic (r :: Result) param currently lowers to {i8, double} (discriminant + f64 payload slot), but a composite-payload Result is {i8, {ptr, i64}} (e.g. Ok(Text), Ok([]Text)). LLVM rejects the call because the aggregate types don't match. Result deliberately has no canonical sum_layouts entry today — its shape follows the concrete payload — so any function taking a bare Result can only accept discriminant-compatible (f64-payload) values.

This blocks core.test's assertOk/assertNotOk (and any user helper) from operating on a Result carrying a composite payload. Surfaced by core.cli (getEnv → Ok(Text), getOpt → Ok([]Text)): the self-asserting example must verify presence via match → Bool + assert(...) instead of assertOk/assertNotOk.

Decision (LOCKED)

Full uniform/canonical Result representation — a single layout that construction, every ?/| match, and all Result params/returns agree on, so any payload passes through a generic Result. Chosen over a narrow discriminant-only call-site coercion (a band-aid that wouldn't let the payload be used through a generic Result).

Scope

Part of M4 (monomorphization + authoritative types in codegen). Cross-cutting: touches Result construction, matching/extraction, and Result-typed params/returns. Not a blocker for core.cli (#66) — that ships with the match → Bool + assert workaround.

Unblocks

  • assertOk/assertNotOk on composite-payload Results everywhere (convert the core.cli example off the match → Bool workaround).
  • General use of composite-payload Result values through generic Result params/returns.

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions