Skip to content

Fold ObjectProp field reads over known constructor applications #213

Description

@Unisay

Problem

Constructor field access reaches the IR as an ObjectProp record projection (ObjectProp (Ref v) (PropName "value0")), not as DataArgumentByIndex. This is what the generated workers actually contain: in the Golden.MaybeChain and Golden.LongMaybeBind IR the bind/maybe/map workers read their scrutinee's payload with ObjectProp … "value0".

Nothing folds that shape. reduceObjectProp folds record literals and updates only (#153), and the case-of-known-constructor folds of #177 cover the DataArgumentByIndex field-read form only. So ObjectProp (K a₀ … aₙ) (PropName "valueᵢ") over a syntactically known, saturated constructor is left standing: (Just 7).value0 does not reduce to 7, even with the constructor in place.

Approach

Extend case-of-known-constructor to the record-projection field read. ObjectProp scrutinee (PropName "valueᵢ"), where scrutinee is a saturated Ctor application, reduces to aᵢ. The label maps to its positional index through the constructor's declared [FieldName] (value0, value1, … are the keys the Lua backend emits for a Ctor). The effect discipline matches the existing DataArgumentByIndex fold: discarded arguments are dropped rather than evaluated or duplicated, and the folded value takes the read node's own annotation, not the argument's (the leak care of #169 and reduceObjectProp).

Prerequisites / Relations

Nothing needs to land first. This is the ObjectProp twin of the DataArgumentByIndex fold in #177 and the algebraic-type companion of the record-literal fold in #153. It is a prerequisite for #180: the dictionary methods inlined there read constructor payloads through exactly this shape.

Verification / Measurement

Standalone impact is near zero, since the shape barely occurs before method inlining lands, so the value shows up through the #180 cascade and is measured end to end by #172. Because the rule touches discard semantics, stress the randomized optimizer specs across seeds.

Metadata

Metadata

Assignees

No one assigned

    Labels

    OptimisationA Compiler Optimisationarea: irIR / optimizer / DCE / inliner

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions