Wado

Effect Rows in the Inference Context

Context

WEP: Effects Through Closures gave a closure literal's type the effects its body performs. The elaborator leaves an effect variable where a row is not known yet, and the effect check solves the variables on the whole program after reify.

So the elaborator decides everything that reads a row before any row is solved, and reads a variable as the empty row:

A bound asked of a type holding a variable could be deferred and asked again once the rows are solved. That repairs a yes-or-no question after the fact. It cannot repair a question whose answer the elaborator has already built on: a selected impl, or a type it resolved.

This is the defect class WEP: One Inference Context names for type variables: a site decides alone what is known. Effect rows are the one kind of variable that WEP leaves outside the context.

Decision

An effect row variable is a variable of the body's inference context, and the context solves it while the body is elaborated.

Rows are sets

A row is a set of effects, so a row variable is solved by inclusion, not by equality. A variable holds a lower bound: the effects shown to flow into it. The solution is the least row that meets every inclusion. Inclusions only add effects, so the solution only grows, and it exists.

Inference is body-local

A function signature declares its effects with with, so nothing a body infers flows into another body's rows. Each body's rows are solved by the end of the body, as its type variables are.

Obligations wait for rows

An obligation that reads a row stays queued until the row settles: a row settles once every inclusion that can still widen it has been recorded. A selection between impls that differ only in their rows, and an associated type read through one, then sees the solved row.

A site that needs the answer before the row settles (resolve_head, or an obligation the row's own inclusions wait on) closes the row at what it holds. A later flow that would widen a closed row is an error at that flow, naming the site that closed it.

Instances are keyed by effect arguments

A function's own effect parameters are part of its instance's key, as its type parameters are, so its body reads each bound row and a dispatch through a bound that names one finds the impl for that row. Every distinct row is a distinct instance, even where the body never reads the row. Merging instances whose bodies come out identical is the optimizer's job, not the key's: the key stays the same shape for type and effect arguments.

What goes

The effect check verifies rows it is given; it no longer solves any. write_back_effect_rows and the effect check's fixed point over the program (solve_rows) are deleted. Every type the elaborator writes back holds solved rows, so reify and the TIR never see an effect variable.

Roadmap

Each step keeps every fixture passing and deletes what it replaces.

Known gaps