Skip to main content

desugared_list_method

Function desugared_list_method 

Source
pub fn desugared_list_method<'a>(
    call_node: &'a AIRNode,
    callee: &'a AIRNode,
    args: &'a [AirArg],
) -> Option<(&'a AIRNode, &'a str, &'a [AirArg])>
Expand description

Recognise a desugared List built-in method call.

Building on the same desugared shape desugared_self_call detects (Call { callee: FieldAccess(recv, method), args: [recv, ...rest] }), this helper additionally requires that method is one of the read-only List built-ins (READ_ONLY_LIST_METHODS). It is the shared recogniser each backend wires into its Call arm before the generic desugared_self_call / fall-through, so nums.len(), nums.get(i), nums.contains(x), etc. are lowered to the target’s idiomatic form (e.g. (nums).length, a tagged-Optional bounds check, …) rather than emitted verbatim as nums.len(nums) — which would fail at the target’s runtime/compile step.

call_node is the full Call AIR node (it holds the recv_kind annotation); callee/args are its fields, passed separately so a backend can call this from inside its NodeKind::Call { callee, args, .. } arm.

Unlike the Optional/Result/Map/Set recognisers — which fire only on their exact recv_kind stamp — this one accepts both a recv_kind = "List" stamp and an absent stamp (the checker leaves the receiver untagged when its type is an unresolved inference variable, and several existing list fixtures rely on that fall-through). It does, however, reject a call carrying any other stamp: that rules out a same-named method on a user record (recv_kind = "User:Counter"), a primitive, or another container, so a user-defined len()/is_empty()/contains(...) falls through to the user-method path instead of being shadowed by the built-in List lowering.

Returns the receiver, the (validated) method name, and the remaining (non-self) arguments. The element type of the list is intentionally not inspected here: the checker has already type-checked the call, and each backend’s lowering is element-type-agnostic for these methods.