Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/gt4py/next/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@
neg,
neighbor_sum,
power,
scan,
sin,
sinh,
sqrt,
Expand Down Expand Up @@ -186,6 +187,7 @@
"neg",
"neighbor_sum",
"power",
"scan",
"sin",
"sinh",
"sqrt",
Expand Down
47 changes: 47 additions & 0 deletions src/gt4py/next/ffront/fbuiltins.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"where",
"broadcast",
"astype",
"scan",
"abs",
"neg",
"sin",
Expand Down Expand Up @@ -293,6 +294,51 @@ def broadcast(
return field # type: ignore[return-value] # see comment above


class ScanBuiltinFunction(BuiltInFunction[_R, _P]):
def __gt_type__(self) -> ts.FunctionType:
return ts.FunctionType(
pos_only_args=[ts.DeferredType(constraint=None)],
pos_or_kw_args={},
kw_only_args={
"axis": ts.DeferredType(constraint=ts.DimensionType),
"forward": ts.DeferredType(constraint=ts.ScalarType),
"init": ts.DeferredType(constraint=(ts.ScalarType, ts.TupleType)),
},
returns=ts.DeferredType(constraint=None),
)


@ScanBuiltinFunction
def scan(
scan_pass: Callable,
/,
*,
axis: common.Dimension | None = None,
forward: bool = True,
init: core_defs.Scalar | Tuple = 0.0,
) -> Callable[..., common.Field | Tuple]:
"""
Create a scan operator from a scan pass, to be called inside a field operator.

Args:
scan_pass: Field operator `(carry, *args) -> carry` on scalars (or tuples thereof).
axis: Vertical dimension to scan along. If omitted, it is the unique vertical
dimension of the arguments the scan operator is called with.
forward: Scan direction.
init: Initial value of the carry, a compile-time constant.

Examples:
>>> scan(my_pass, axis=KDim, forward=True, init=0.0)(a) # doctest: +SKIP
"""
from gt4py.next.embedded import context as embedded_context, operators as embedded_operators

def scan_operator(*args: Any, **kwargs: Any) -> common.Field | Tuple:
scan_axis = axis if axis is not None else embedded_context.get_closure_column_range().dim
return embedded_operators.ScanOperator(scan_pass, forward, init, scan_axis)(*args, **kwargs)

return scan_operator


@WhereBuiltinFunction
def where(
mask: common.Field,
Expand Down Expand Up @@ -453,6 +499,7 @@ def impl(
"broadcast",
"where",
"astype",
"scan",
*MATH_BUILTIN_NAMES,
]

Expand Down
205 changes: 172 additions & 33 deletions src/gt4py/next/ffront/foast_passes/type_deduction.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,64 @@ def _no_implicit_conversion_diagnostic(left: foast.Expr, right: foast.Expr) -> d
}


def _is_scan_builtin(expr: foast.Expr) -> bool:
return isinstance(expr, foast.Name) and expr.id == "scan"


def _is_literal(expr: foast.Expr) -> bool:

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

don't we have a similar check somewhere else on foast level?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are similar checks, but none we can reuse:

  • func_to_foast._verify_builtin_type_constructor: Python-AST level, accepts Constant or ±Constant, for type-constructor arguments.
  • foast_to_gtir._visit_type_constr: the same shape again, raised only at lowering.
  • foast_passes/utils.expr_to_index: ±int constants for tuple indices.

None of them handles tuples or constructor calls, which a tuple init needs.

Recommendation: keep _is_literal here for now and delete it in the runtime-init PR. Then only forward needs the check, and that is a plain isinstance(..., foast.Constant). forward=FWD with a closure variable still works, because ClosureVarFolding turns it into a Constant before type deduction (func_to_foast.py:187-190).

🤖 Written by an agent on behalf of @havogt

match expr:
case foast.Constant():
return True
case foast.TupleExpr():
return all(_is_literal(el) for el in expr.elts)
case foast.UnaryOp():
return _is_literal(expr.operand)
case foast.Call(func=foast.Name(type=ts.ConstructorType())):
return all(_is_literal(arg) for arg in expr.args)
return False
Comment on lines +166 to +180

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to foast_passes/utils.py



def _check_scan_pass(
location: eve.SourceLocation,
name: str,
pass_type: ts.FunctionType,
forward_type: ts.TypeSpec,
init_type: ts.TypeSpec,
) -> None:
if not (isinstance(forward_type, ts.ScalarType) and forward_type.kind == ts.ScalarKind.BOOL):
raise errors.DSLError(
location, f"Argument 'forward' to scan operator '{name}' must be a boolean."
)
if not all(
type_info.is_arithmetic(type_) or type_info.is_logical(type_)
for type_ in type_info.primitive_constituents(init_type)
):
raise errors.DSLError(
location,
f"Argument 'init' to scan operator '{name}' must "
"be an arithmetic type or a logical type or a composite of arithmetic and logical types.",
)
if not pass_type.pos_or_kw_args:
raise errors.DSLError(
location,
f"Scan operator '{name}' must have at least one argument (the carry).",
)
carry_arg_name = next(iter(pass_type.pos_or_kw_args.keys()))
carry_type = pass_type.pos_or_kw_args[carry_arg_name]
if carry_type != pass_type.returns:
raise errors.DSLError(
location,
f"Argument '{carry_arg_name}' to scan operator '{name}' must have same type as its return: "
f"expected '{pass_type.returns}', got '{carry_type}'.",
)
elif init_type != carry_type:
raise errors.DSLError(
location,
f"Argument 'init' to scan operator '{name}' must have same type as '{carry_arg_name}' argument: "
f"expected '{carry_type}', got '{init_type}'.",
)


class FieldOperatorTypeDeduction(traits.VisitorWithSymbolTableTrait, NodeTranslator):
"""
Deduce and check types of FOAST expressions and symbols.
Expand Down Expand Up @@ -250,51 +308,115 @@ def visit_ScanOperator(self, node: foast.ScanOperator, **kwargs: Any) -> foast.S
f"Argument 'axis' to scan operator '{node.id}' must be a vertical dimension.",
)
new_forward = self.visit(node.forward, **kwargs)
if not new_forward.type.kind == ts.ScalarKind.BOOL:
raise errors.DSLError(
node.location, f"Argument 'forward' to scan operator '{node.id}' must be a boolean."
)
new_init = self.visit(node.init, **kwargs)
if not all(
type_info.is_arithmetic(type_) or type_info.is_logical(type_)
for type_ in type_info.primitive_constituents(new_init.type)
):
new_definition = self.visit(node.definition, **kwargs)
_check_scan_pass(
node.location, node.id, new_definition.type, new_forward.type, new_init.type
)

new_type = ts_ffront.ScanOperatorType(
axis=new_axis.type.dim, definition=new_definition.type
)
return foast.ScanOperator(
id=node.id,
axis=new_axis,
forward=new_forward,
init=new_init,
definition=new_definition,
type=new_type,
location=node.location,
)

def _visit_scan_call(
self, node: foast.Call, scan_arg_types: list[ts.TypeSpec], **kwargs: Any
) -> foast.Call:
"""Type `scan(pass, axis=..., forward=..., init=...)`, the callee of a call-site scan."""
new_func = self.visit(node.func, **kwargs)
if len(node.args) != 1:
raise errors.DSLError(
node.location,
f"Argument 'init' to scan operator '{node.id}' must "
"be an arithmetic type or a logical type or a composite of arithmetic and logical types.",
f"'scan' takes exactly one positional argument (the scan pass), got {len(node.args)}.",
)
new_definition = self.visit(node.definition, **kwargs)
new_def_type = new_definition.type
if not new_def_type.pos_or_kw_args:
if unexpected := set(node.kwargs) - {"axis", "forward", "init"}:
raise errors.DSLError(
node.location,
f"Scan operator '{node.id}' must have at least one argument (the carry).",
f"Unexpected keyword argument(s) {', '.join(sorted(unexpected))} to 'scan'.",
)
carry_arg_name = next(iter(new_def_type.pos_or_kw_args.keys()))
carry_type = new_def_type.pos_or_kw_args[carry_arg_name]
if carry_type != new_def_type.returns:
new_pass = self.visit(node.args[0], **kwargs)
if not isinstance(new_pass.type, ts_ffront.FieldOperatorType):
raise errors.DSLError(
node.location,
f"Argument '{carry_arg_name}' to scan operator '{node.id}' must have same type as its return: "
f"expected '{new_def_type.returns}', got '{carry_type}'.",
new_pass.location,
f"The scan pass must be a field operator, got '{new_pass.type}'.",
)
elif new_init.type != carry_type:
pass_type = new_pass.type.definition
pass_name = str(new_pass)

new_kwargs = {
"forward": foast.Constant(value=True, location=node.location),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

defaults should come from lowering

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. Type deduction shouldn't rewrite the node with materialised defaults.

Recommendation: leave absent kwargs absent in FOAST and insert the literals in foast_to_gtir._visit_scan_call. The default values should live in exactly one place, the signature of fbuiltins.scan, and the lowering reads them from there instead of repeating True/0.0. Type deduction then checks against the type of the default without inserting it. If we make init required (see the next thread), only forward is left to default, which makes this simpler still.

🤖 Written by an agent on behalf of @havogt

"init": foast.Constant(value=0.0, location=node.location),

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does init have a default value?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently yes: 0.0, mirroring @scan_operator(init=0.0) and the fbuiltins.scan signature. But that default only type-checks for a float64 carry. Any other carry (float32, int, bool, tuple) fails with "Argument 'init' ... must have same type as ..." until the user passes init explicitly.

Recommendation: make init required for the scan builtin. There is no backwards-compatibility constraint because the builtin is new. A default that is only right for one dtype is a trap. And the stacked scan-init branch makes init a runtime/per-column value anyway, where a scalar default makes even less sense. @scan_operator keeps its default.

🤖 Written by an agent on behalf of @havogt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a separate PR we should remove the default from init.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. #2920 keeps init=0.0 so it behaves like @scan_operator, and the default gets removed in a follow-up.

Recommendation: do it in the same follow-up that makes init runtime (see the thread on L360). Both change what init is, and a runtime init has no sensible default anyway.

🤖 Written by an agent on behalf of @havogt

**node.kwargs,
}
new_kwargs = {name: self.visit(arg, **kwargs) for name, arg in new_kwargs.items()}
for name in ("forward", "init"):

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

init should be runtime

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dropping this check alone doesn't work. GTIR stencils must be closed, and a non-literal init in scan(λ, fwd, init) refers to an outer symbol. Every backend then fails in TraceShifts with ValueError: Undefined symbol init_param (trace_shifts.py:291; verified on roundtrip, gtfn and dace). Allowing open stencils would mean auditing every pass that assumes they are closed: trace_shifts, fuse_as_fieldop, inline_lambdas/CSE, global_tmps, and dace's capture_outer_data=False.

There is an approach that works without any GTIR or backend change, and it is already implemented on the stacked branch scan-init (c590dae, 1658535; +221/-38). The frontend desugars the scan: init becomes an extra stencil argument, and the carry gets a "first level" flag. That handles both a runtime scalar and a per-column field (no scan axis). An init with the scan axis is rejected, because which level it reads would move with domain inference.

Recommendation: keep #2920 compile-time and make runtime init the next PR, together with removing the default. It's a separate, self-contained lowering with its own design decision (rejecting init with the scan axis), and keeping it out keeps #2920 reviewable. If you'd rather have it here, I can merge scan-init's two commits into this branch.

🤖 Written by an agent on behalf of @havogt

if not _is_literal(new_kwargs[name]):
raise errors.DSLError(
new_kwargs[name].location,
f"Argument '{name}' to 'scan' must be a compile-time constant.",
)
_check_scan_pass(
node.location, pass_name, pass_type, new_kwargs["forward"].type, new_kwargs["init"].type
)
if not all(
isinstance(t, ts.ScalarType)
for param in [*pass_type.pos_or_kw_args.values(), pass_type.returns]
for t in type_info.primitive_constituents(param)
):
raise errors.DSLError(
node.location,
f"Argument 'init' to scan operator '{node.id}' must have same type as '{carry_arg_name}' argument: "
f"expected '{carry_type}', got '{new_init.type}'.",
new_pass.location,
f"The scan pass '{pass_name}' must take and return scalars or tuples of scalars.",
)
if pass_type.pos_only_args or pass_type.kw_only_args:
raise errors.DSLError(
new_pass.location,
f"The scan pass '{pass_name}' must not have positional-only or keyword-only arguments.",
)

new_type = ts_ffront.ScanOperatorType(axis=new_axis.type.dim, definition=new_def_type)
return foast.ScanOperator(
id=node.id,
axis=new_axis,
forward=new_forward,
init=new_init,
definition=new_definition,
type=new_type,
if "axis" in new_kwargs:
axis_type = new_kwargs["axis"].type
if not isinstance(axis_type, ts.DimensionType):
raise errors.DSLError(
new_kwargs["axis"].location, "Argument 'axis' to 'scan' must be a dimension."

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have only one check of the kwargs shared between scan_call and ScanOperator.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. forward and init already share _check_scan_pass, but the axis check is duplicated: here, and in visit_ScanOperator (L300-309).

Recommendation: fold the axis check into the shared helper so it covers all three kwargs, e.g. _check_scan_kwargs(location, name, pass_type, axis_type, forward_type, init_type) -> Dimension, and call it from both visitors. The compile-time-constant check on forward/init can go in there too: on the decorator path both are always literals, so it costs nothing. Only the axis inference (no axis= given) stays specific to scan(...).

🤖 Written by an agent on behalf of @havogt

)
axis = axis_type.dim
if axis.kind != DimensionKind.VERTICAL:
raise errors.DSLError(
new_kwargs["axis"].location,
"Argument 'axis' to 'scan' must be a vertical dimension.",
)
else:
vertical_dims = {
dim
for arg_type in scan_arg_types
for el in type_info.primitive_constituents(arg_type)
for dim in type_info.extract_dims(el)
if dim.kind == DimensionKind.VERTICAL
}
if len(vertical_dims) != 1:
found = ", ".join(sorted(f"'{d.value}'" for d in vertical_dims)) or "none"
raise errors.DSLError(
node.location,
"Cannot infer the 'axis' of 'scan' from its arguments, expected exactly one "
f"vertical dimension, found {found}.",
hints=["Pass the axis explicitly, e.g. 'scan(..., axis=KDim)'."],
)
(axis,) = vertical_dims

return foast.Call(
func=new_func,
args=[new_pass],
kwargs=new_kwargs,
location=node.location,
type=ts_ffront.ScanOperatorType(axis=axis, definition=pass_type),
)

def visit_Name(self, node: foast.Name, **kwargs: Any) -> foast.Name:
Expand Down Expand Up @@ -757,9 +879,22 @@ def visit_TupleExpr(self, node: foast.TupleExpr, **kwargs: Any) -> foast.TupleEx
return foast.TupleExpr(elts=new_elts, type=new_type, location=node.location)

def visit_Call(self, node: foast.Call, **kwargs: Any) -> foast.Call:
new_func = self.visit(node.func, **kwargs)
if _is_scan_builtin(node.func):
raise errors.DSLError(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we remove this limitation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not in this PR, in my view. Allowing s = scan(p, ...) with a later s(a), or passing the result around, makes a scan operator a first-class value. That is the first step of general (user-defined) higher-order functions. It needs:

  • a standalone scan(...) to lower to a GTIR lambda λ(*args) → as_fieldop(scan(...))(*args) instead of being fused with its call;
  • calls of function-typed values to go through the generic call path;
  • axis to be explicit whenever the call isn't directly attached, since there are no arguments to infer it from at the definition.

GTIR already supports this, and InlineLambdas specialises it away. The work is in the frontend gates, and that is exactly what the HOF follow-up replaces.

Recommendation: keep the limitation in #2920 and lift it in the HOF PR, together with removing the scan-specific special cases at L890 and L917. Relaxing it here would grow the scan-specific code that the HOF PR then throws away.

🤖 Written by an agent on behalf of @havogt

node.location,
"'scan' creates a scan operator which must be called directly: "
"'scan(scan_pass, ...)(args)'.",
)
new_args = self.visit(node.args, **kwargs)
new_kwargs = self.visit(node.kwargs, **kwargs)
if isinstance(node.func, foast.Call) and _is_scan_builtin(node.func.func):
new_func = self._visit_scan_call(
node.func,
scan_arg_types=[arg.type for arg in [*new_args, *new_kwargs.values()]],
**kwargs,
)
else:
new_func = self.visit(node.func, **kwargs)

func_type = new_func.type
arg_types = [arg.type for arg in new_args]
Expand All @@ -779,6 +914,9 @@ def visit_Call(self, node: foast.Call, **kwargs: Any) -> foast.Call:
if not isinstance(
new_func,
(foast.FunctionDefinition, foast.FieldOperator, foast.ScanOperator, foast.Name),
) and not (

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mention here that scan is the only higher order function (if it applies here).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it applies. scan is the only builtin that returns a function, so a call to a scan(...) result is the only callee here that isn't a name or definition.

Recommendation: add a one-line comment on the clause: "scan(pass, ...) is the only higher-order builtin, so its result is the only callable call result." Both the comment and the clause go away with general HOF support.

🤖 Written by an agent on behalf of @havogt

isinstance(new_func, foast.Call)
and isinstance(new_func.type, ts_ffront.ScanOperatorType)
):
raise errors.DSLError(node.location, "Functions can only be called directly.")
elif isinstance(new_func.type, ts.FieldType):
Expand Down Expand Up @@ -811,6 +949,7 @@ def visit_Call(self, node: foast.Call, **kwargs: Any) -> foast.Call:
f"Expression of type '{new_func.type}' is not callable, must be a 'Function', 'FieldOperator', 'ScanOperator' or 'Field'.",
)

assert isinstance(func_type, ts.CallableType)
# ensure signature is valid
try:
type_info.accepts_args(
Expand Down
26 changes: 25 additions & 1 deletion src/gt4py/next/ffront/foast_to_gtir.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ def _visit_shift(self, node: foast.Call, **kwargs: Any) -> itir.Expr:
return current_expr

def visit_Call(self, node: foast.Call, **kwargs: Any) -> itir.Expr:
if type_info.type_class(node.func.type) is ts.FieldType:
if isinstance(node.func, foast.Call) and isinstance(
node.func.type, ts_ffront.ScanOperatorType
):
return self._visit_scan_call(node, **kwargs)
elif type_info.type_class(node.func.type) is ts.FieldType:
return self._visit_shift(node, **kwargs)
elif isinstance(node.func, foast.Name) and node.func.id in fbuiltins.MATH_BUILTIN_NAMES:
return self._visit_math_built_in(node, **kwargs)
Expand Down Expand Up @@ -393,6 +397,26 @@ def visit_Call(self, node: foast.Call, **kwargs: Any) -> itir.Expr:
f"Call to object of type '{type(node.func.type).__name__}' not understood."
)

def _visit_scan_call(self, node: foast.Call, **kwargs: Any) -> itir.Expr:
# `scan(scan_pass, forward=..., init=...)(*args)`

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there overlap between this and visitScanOperator

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Both end in as_fieldop(scan(λ, forward, init))(*args). They differ only in how the λ is built:

  • visit_ScanOperator inlines the lowered definition and let-binds the derefed params.
  • This version calls the pass by reference: λ(carry, *params): pass(carry, *deref(params)).

After InlineFundefs/InlineLambdas both are the same thing.

Recommendation: extract one helper, e.g. _lower_scan(pass_expr, param_names, forward, init, args), and use it from both. visit_ScanOperator would pass its lowered definition as a lambda. No unit test pins the scan GTIR of either path, so the change is covered by the existing scan integration tests. The decorator path goes away later in the stack (scan-drop-decorator), so the alternative is to accept the duplication until then. I'd still share it now, since it is small and keeps the two paths from drifting.

🤖 Written by an agent on behalf of @havogt

scan_call = node.func
assert isinstance(scan_call, foast.Call)
assert isinstance(scan_call.type, ts_ffront.ScanOperatorType)
scan_pass = self.visit(scan_call.args[0], **kwargs)
forward = self.visit(scan_call.kwargs["forward"], **kwargs)
init = self.visit(scan_call.kwargs["init"], **kwargs)

lowered_args, lowered_kwargs = type_info.canonicalize_arguments(
scan_call.type, self.visit(node.args, **kwargs), self.visit(node.kwargs, **kwargs)
)
stencil_args = [*lowered_args, *lowered_kwargs.values()]
carry = next(self.uid_generator["__scan_carry"])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to generate the name? and not use the name of the first parameter of the scanpass.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no real need. The λ is a fresh scope, and its only free symbol is the reference to the pass itself. A collision would only happen if a pass parameter had the same name as the pass, which isn't worth guarding against.

Recommendation: use the pass's own parameter names, pass_type.pos_or_kw_args (carry first). The GTIR becomes readable, matches what visit_ScanOperator emits, and drops the __scan_carry/__scan_arg uids. This fits naturally into the shared helper from the previous thread.

🤖 Written by an agent on behalf of @havogt

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's keep as is

params = [next(self.uid_generator["__scan_arg"]) for _ in stencil_args]
definition = im.lambda_(carry, *params)(
im.call(scan_pass)(carry, *(im.deref(param) for param in params))
)
return im.as_fieldop(im.scan(definition, forward, init))(*stencil_args)

def _visit_astype(self, node: foast.Call, **kwargs: Any) -> itir.Expr:
# Note: the type to convert to is uniquely identified by its GT4Py type (`ConstructorType`),
# not by e.g. its name.
Expand Down
4 changes: 4 additions & 0 deletions src/gt4py/next/ffront/foast_to_past.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class ItirShim:
definition: ConcreteFOASTOperatorDef
foast_to_itir: workflow.Workflow[ConcreteFOASTOperatorDef, itir.FunctionDefinition]

@property
def foast_stage(self) -> ffront_stages.FOASTOperatorDef:
return self.definition.data

def __gt_closure_vars__(self) -> Optional[dict[str, Any]]:
return self.definition.data.closure_vars

Expand Down
Loading
Loading