MIR lowering for object field access and expanded parameters¶
Summary¶
object-typed values are lowered as flattened per-field locals (__li_o_<root>_<field>…) for field access, assignment, var, expanded call arguments, same-type var dst: T = srcIdent slot copies, whole-object assigns, element-wise copy of fixed array[N, int|float] fields, and LLVM struct returns that pack scalars and fixed arrays as [N x T] members (ReturnObject, callee unpack, var w: T = foo()).
Agent continuation¶
- Read
compiler/mir/include/li/mir.hpp(ReturnObject,MirFn::returns_object/return_object_layout,MirInsn::object_layout),compiler/mir/lower.cpp,compiler/codegen/emit.cpp. - Run
cmake --build buildthen./li-tests/run_all.sh encapsulationand./li-tests/run_all.sh math_linalgwithLICpointing at the builtlic. - Next:
arrayfields withi64/ other scalar elems in struct returns;extern procreturning object;typedictparity. - Blocked:
arrayfields with element types other thanint/float(e.g.i64) on object return/param paths; nestedexternobject ABI.
Changed¶
compiler/mir/include/li/mir.hpp—MirParam::fixed_array_elems; comments forReturnObject/object_layout.compiler/mir/lower.cpp—collect_object_return_layout_r/append_mir_params_for_object_typeinclude fixedarray[N, int|float]; implicitReturnObjectzero uses per-indexArrayStore*for those fields;seed_*_paramsskip fixed-array param roots; prior object work unchanged (ReturnObject,CallProctemps,var/Assigncopies,emit_copy_array_slots_r,g_arr_ctx,Index/AssignFieldAccessbases, deferredg_arr_ctxclear).compiler/codegen/emit.cpp—llvm_type_for_mir_param, LLVM struct fields[N x T],ReturnObjectaggregate load,CallProcaggregate store toArrayAllocslots,mir_arg_valueloads for array idents, prologue stores for expanded array params.li-tests/objects/object_array_return_call.li— callee returns object whose only field isarray[2, int].li-tests/objects/object_mixed_scalar_array_return.li— struct return withint,array[2, int],intfields (ordering vs layout).li-tests/objects/object_mixed_param_pass.li— expandedMixedobject parameter (scalar +array[2,int]) passed to callee.li-tests/manifest.toml— registerobject_mixed_param_pass.li.
Not changed¶
- General scalar/control-flow codegen paths in
emit.cppbeyond struct-return / aggregate-array plumbing. typedictruntime layout (still not flattened in MIR).- Parser, borrow checker, and verifier contracts for objects.
- Dominance:
object_localsis a flat map from the whole procedure AST; assigning to a name that is not object-typed or not declared on all paths may still be accepted by the typechecker separately from MIR slot layout. extern procreturning a Liobjecttype (no struct lowering contract).return_object_layout/ LLVM struct fields forarrayelements other thanint/float(e.g.i64) remain unsupported.
Breaking¶
N/A — fixes incorrect codegen for programs that already type-checked.
Security¶
N/A.
Performance¶
N/A — same stack locals as before for scalar object fields; more MIR parameters for object-by-value calls (ABI expansion).
Downstream¶
Callers of procs that take object parameters must pass the same Li source (compiler expands arguments); no C ABI change for non-object programs.