RustQ.Meta.Lower.Stdlib.Lowering behaviour (rustq v1.0.0-rc.19)

Copy Markdown View Source

The behaviour of a module lowering one Elixir standard-library module, and the helpers such a module lowers and types its arguments with.

RustQ.Meta.Lower.Stdlib dispatches a call to Enum to RustQ.Meta.Lower.Enum, a call to Map to RustQ.Meta.Lower.Map, and so on: the module named after the Elixir module, when it implements this behaviour. use this module to implement it and import the helpers:

defmodule RustQ.Meta.Lower.List do
  use RustQ.Meta.Lower.Stdlib.Lowering

  @impl true
  def lower(%Call{function: :first, args: [list]}, %Context{} = context),
    do: {:ok, list |> lowered(context) |> A.method(:into_iter) |> A.method(:next)}
end

A lowering returns :unsupported for a call it does not lower, and RustQ.Meta.Lower.Stdlib reports it.

Summary

Callbacks

Lowers call, or returns :unsupported for a call this module does not lower.

Types call, or returns :unsupported for a call this module does not type.

Functions

A captured named function, as the Rust path of that function.

A closure taking args and returning body, lowered.

A closure taking args and returning body as a value of returns, lowered.

A closure argument, as a Rust closure argument.

A closure's body, lowered to return a value of returns.

argument evaluated for its effects, then the constant value.

Whether collection is still in use after this use of it; see RustQ.Meta.Ownership.

A Rust count as Elixir's integer, an i64, unless the call is expected to produce a usize.

expression, lowered.

expression, lowered to produce a value of expected.

Whether module lowers an Elixir standard-library module.

count as a usize, when it is a literal or unsigned count that cannot be negative.

expression, lowered as an operand: a fallible one propagates its error with ?.

The type a call shapes its value as: a fallible call's success type, and others' own.

The type of expression, or nil when it is not known.

The type of expression where vars are bound to the given types.

Callbacks

lower(t, t)

Lowers call, or returns :unsupported for a call this module does not lower.

synth(t, t)

Types call, or returns :unsupported for a call this module does not type.

Functions

capture(function, context)

A captured named function, as the Rust path of that function.

closure(args, body, context)

A closure taking args and returning body, lowered.

closure(args, body, returns, context)

A closure taking args and returning body as a value of returns, lowered.

closure_arg(arg)

@spec closure_arg(Macro.t()) :: atom() | RustQ.Rust.AST.pat()

A closure argument, as a Rust closure argument.

closure_body(body, returns, context)

A closure's body, lowered to return a value of returns.

evaluated_constant(argument, value, context)

@spec evaluated_constant(
  Macro.t(),
  term(),
  RustQ.Meta.Lower.Stdlib.Lowering.Context.t()
) ::
  {:ok, RustQ.Rust.AST.expr()}

argument evaluated for its effects, then the constant value.

in_use?(collection, context)

Whether collection is still in use after this use of it; see RustQ.Meta.Ownership.

integer_count(count, context)

A Rust count as Elixir's integer, an i64, unless the call is expected to produce a usize.

lowered(expression, context)

expression, lowered.

lowered(expression, expected, context)

expression, lowered to produce a value of expected.

lowering?(module)

@spec lowering?(module()) :: boolean()

Whether module lowers an Elixir standard-library module.

nonnegative_count(count, context)

@spec nonnegative_count(Macro.t(), RustQ.Meta.Lower.Stdlib.Lowering.Context.t()) ::
  {:ok, RustQ.Rust.AST.expr()} | :unsupported

count as a usize, when it is a literal or unsigned count that cannot be negative.

operand(expression, context)

expression, lowered as an operand: a fallible one propagates its error with ?.

shape_type(type)

@spec shape_type(RustQ.Meta.Type.t() | nil) :: RustQ.Meta.Type.t() | nil

The type a call shapes its value as: a fallible call's success type, and others' own.

type_of(expression, arg2)

The type of expression, or nil when it is not known.

type_with_vars(expression, vars, type_context)

@spec type_with_vars(
  Macro.t(),
  %{optional(atom()) => RustQ.Meta.Type.t()},
  RustQ.Meta.Lower.Stdlib.Lowering.TypeContext.t()
) :: RustQ.Meta.Type.t() | nil

The type of expression where vars are bound to the given types.