Skip to content

refactor(ir): centralize storage-dtype composition, de-panic array indices - #17

Open
Boreas618 wants to merge 2 commits into
mainfrom
refactor/ir-dtype-helpers
Open

refactor(ir): centralize storage-dtype composition, de-panic array indices#17
Boreas618 wants to merge 2 commits into
mainfrom
refactor/ir-dtype-helpers

Conversation

@Boreas618

Copy link
Copy Markdown
Contributor

IR-layer unification from the cross-layer audit:

  • compose_var_decl_dtype/compose_var_def_dtype (documented as the single home for storage-type computation) are now actually used by handle_struct_def and type_infer, eliminating the inline duplicated matches; the one legitimately divergent site in type_infer is left in place with a comment explaining why.
  • The input-adjacent panic in array_index_operand (i32::try_from(index).expect(...) on a source-derived index) is now a proper Error::ArrayIndexTooLarge variant.
  • //! module docs added to ir/error.rs, ir/types.rs, ir/gen/static_eval.rs.

Verified: cargo test 30/30 green.

…dices

compose_var_decl_dtype/compose_var_def_dtype are the documented canonical
helpers for combining a base Dtype with an AST declaration shape, but
handle_struct_def and type_infer each kept their own inline copies of the
same scalar/array composition.  Delegate to the helpers wherever the input
shapes and semantics are genuinely identical:

- module_gen::handle_struct_def now calls compose_var_decl_dtype for
  struct member storage types;
- type_infer::process_var_def delegates its array arm to
  compose_var_def_dtype;
- type_infer::process_var_decl delegates every resolved case to
  compose_var_decl_dtype.  The untyped-scalar arm stays inline (with a
  comment recording the divergence) because it must remain Pending rather
  than defaulting to i32.

array_index_operand lowered source-derived usize indices with
i32::try_from(..).expect(..), panicking on user input.  Add
Error::ArrayIndexTooLarge { index } and propagate it from the three call
sites instead.

Also add the missing //! module docs to ir/error.rs, ir/types.rs and
ir/gen/static_eval.rs, matching the documented siblings.
- removed 16 divider banner groups (4 function_gen, 12 type_infer)
- removed 11 obvious narrations/restatements (emit-store, lower-body,
  eval-condition, jump-past-else, emit-loop-test, 2 short-circuit
  duplicates, finalise-block, alloca-hoist restatement, insert-hoisted)
- removed 1 duplicated impl-block doc (static_eval restated module doc)
- rewrote 4 stale/contradictory comments: generate() #Errors claimed an
  impossible UnsupportedReturnType, 'two-phase' impl doc vs 3-pass body,
  local_base_dtype unreachable fallback example, post-hoist invariant
  (referenced empty blocks panic, edges are never dropped)
- rewrote 4 first-person formulations to declarative facts
- trimmed 1 unsupported claim ('no program will ever approach it')
- de-linked 5 unresolved intra-doc links to private/out-of-scope items
  (doc warnings 27 -> 23)
- no TODO/FIXME/HACK tags and no commented-out code found in scope
@Boreas618
Boreas618 force-pushed the refactor/ir-dtype-helpers branch from b086b95 to 4826153 Compare August 1, 2026 10:59
@Boreas618
Boreas618 changed the base branch from assign3 to main August 1, 2026 11:12
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.

1 participant