Skip to content

Better handling for environments #209

@iamrecursion

Description

@iamrecursion

In Noir's compiler, function types carry around an 'environment' that describes the things that are captured by the function type. This is particularly relevant for lambdas.

At the moment, we do nothing with this, carrying the information through the analysis phase for as long as possible before dropping it during syntax print. We could potentially make some use out of this, as—in combination with the types of the function arguments—we could use it to determine whether an arbitrary callable is pure. If it captures only non-references and takes no mutable references, then it is pure.

To add support for this, we would need to:

  • Add support in the type syntax for it (e.g. λ[e,*](arg,*) -> Ret).
  • Add support in the Lambda syntax for it (e.g. fn[e,*](arg,*): Ret := expr).
  • Output this new syntax in the extractor.
  • Add support for it in the Tp.fn constructor (e.g. Tp.fn (env : List Tp) (args : List Tp) (outTp : Tp)).
  • Add support for it in the Expr.lam constructor in a similar vein.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions