The ownership panel

View source

The Actus Ownership panel in VS Code, read on one real program. For each verb it shows every participant with its role and state, the views and loans, what happened to each one, and the cleanup in order.

An Actus program says, at every call, who takes part and how: erg is the owner that acts, abs only looks, ins is lent for the call and comes back, dat is handed over for good. The compiler follows each participant through the verb and knows, at every line, in which state it is: active, moved, frozen by a view, suspended by a loan, or dropped. The panel shows that record.

The Actus Ownership panel is a panel of VS Code, next to Terminal and Problems. For each verb of the open file it lists:

  • every participant, with its role and its type,
  • every view and every loan,
  • what happened to each participant, in the order the compiler recorded it: moved, dropped, frozen, released, loaned, returned, restored, joined,
  • the cleanup at the end of each scope, in the order it runs.

The panel shows facts of the compiler and nothing else. It never works out ownership from the text of the file. If the compiler cannot say, the panel says so, as described in When the file does not check.

The Actus Ownership panel under the editor. The verb wire_parser_finish of the standard library has ten events: the ins loans of parser and payload_output, the erg binding decoded and its move into the case.

The picture shows the panel on wire_parser_finish of the standard library. The cursor is on line 189, so the rows of decoded have a green background and the other rows are dim. The bracket on the left joins payload_output with its loan to wire_frame_decode and its return. Each row ends with the state and the line.

Open the panel

Use one of these:

  • Run Actus: Show Ownership Chain Graph from the Command Palette.
  • Choose Show Ownership Chain Graph in the Quick Actions of the status bar.
  • Click the tab Actus Ownership in the panel area.

The panel has one view, called Ownership Chain Graph. It follows the Actus file that is active in the editor. If the active editor is not an Actus file, it follows another Actus file that is visible. With no Actus file at all it says Open an Actus file that checks with the language server running.

The panel asks the language server again when you switch files, 250 ms after you stop typing, when you save, when the server has started, and when you press Refresh. It sees the text in the editor, so unsaved changes count.

One program

The program below has two Buffer owners, an abs view, two ins loans, a hand-off with dat, numbers, and an if that hands the buffer over in one branch. All the examples on this page are checked with Actus 0.3.0, and the rows in the tables are what the language server of that compiler sends to the panel.

actus
verb record(ins log: Buffer, abs reading: u8) {
    append(log, reading as Int);
}

verb archive(dat log: Buffer) -> Int {
    return buffer_length(buffer: abs log);
}

verb main() {
    erg limit = 3;
    erg log: Buffer = Buffer[0];
    erg note: Buffer = Buffer[0];
    record(log: ins log, reading: abs 65u8);
    record(log: ins note, reading: abs 66u8);
    if limit > 5 {
        erg total = archive(log: dat log);
        println(int: total);
        return;
    } else {
        abs view = ref log;
        println(buffer: abs view);
    }
}
bash
actus run
text
A
process exited with status 0

limit is 3, so the else branch runs: view is a view of log, and the program prints the byte that record appended, the letter A.

With this file open, the panel shows this. The top of the panel is a toolbar with a badge main.act · 8 bindings, a search field, the filters All erg abs ins dat drop, and the buttons Collapse All, Focus Cursor and Refresh. Under it comes one section for each verb. The header of a section reads verb record, the number of rows, the state Scope and the place of the verb, Ln 1:1.

verb record, 2 events, Ln 1:1

RoleRowDetailStateLine
inslog: BufferDeclared as insActive1:13
absreading: u8Scalar value (abs)Value1:30

verb archive, 2 events, Ln 5:1

RoleRowDetailStateLine
datlog: BufferDeclared as datActive5:14
dropdrop logCompiler cleanup plan (LIFO)Dropped7:2

verb main, 15 events, Ln 9:1

RoleRowDetailStateLine
erglimit: IntScalar value (erg)Value10:5
erglog: BufferDeclared as ergActive11:5
ergnote: BufferDeclared as ergActive12:5
insins log -> record(log:)Exclusive ins loan to record(log:) (Active -> Suspended)Suspended13:21
insreturned logExclusive ins loan returned (Suspended -> Active)Active13:44
insins note -> record(log:)Exclusive ins loan to record(log:) (Active -> Suspended)Suspended14:21
insreturned noteExclusive ins loan returned (Suspended -> Active)Active14:45
ergtotal: IntScalar value (erg)Value16:9
datdat log -> archive(log:)dat argument to archive(log:) (Active -> Moved)Moved16:38
ergrestored logBranch start (if) (Moved -> Active)Active19:12
absview: BufferDeclared as absActive20:9
absfrozen logabs view started (Active -> Frozen)Frozen20:9
absreleased logabs view ended (Frozen -> Active)Active22:6
dropdrop noteCompiler cleanup plan (LIFO)Dropped23:2
dropdrop logCompiler cleanup plan (LIFO)Dropped23:2

The panel draws these as rows of one list, with a role badge on the left, the row text, the detail in a lighter colour, a state label and the position on the right. The tables show the same columns. Here is main, row by row.

  1. limit: Int. A number is a value, not a participant. It has no role in the sense of the model and no state: the label says Value, and it has no cleanup and no connector. The same is true of reading: u8 in record and of total: Int.
  2. log: Buffer. The owner log, declared as erg on line 11. Its type is written after the name. This row is the start of log.
  3. note: Buffer. A second owner.
  4. ins log -> record(log:). Line 13, column 21 is the log after ins in the call. The call lends log to record for its parameter log. While the call runs, log is Suspended: nobody else may read it or change it.
  5. returned log. The call has ended. The place is the end of the call, column 44, at the ;. log is Active again, with the byte that record appended.
  6. and 7. The same loan and return for note. The call names the parameter log of record, so the text is record(log:) for both.
  7. total: Int. A number declared in the first branch of the if.
  8. dat log -> archive(log:). The dat argument on line 16. The owner hands log over to archive for good. The state after it is Moved. This is the end of log on this path: the branch returns on the next lines.
  9. restored log. Line 19, at the { of the else. The else branch does not follow the first branch. It starts from the state before the if, so log goes from Moved back to Active. The detail says why: Branch start (if).
  10. view: Buffer. The binding view, declared as abs. It holds a view of log and owns nothing.
  11. frozen log. Same place, the ref log of the view. While the view exists, the owner is Frozen: it cannot change and cannot be handed over. The row is an abs row, because the view is what freezes it.
  12. released log. Line 22, right after the } that ends the else block. The view ends with its scope, and log is Active again.
  13. and 15. drop note, drop log. The cleanup of the verb, at line 23, just after its closing brace, in this order: the owner that was declared last is released first (LIFO). limit, total and view have no cleanup row: the first two are values and the third is a view, which ended at row 13.

The rows are sorted by position in the file. Rows at the same position keep the order in which the compiler gave them, which is why view: Buffer comes before frozen log.

Now record and archive. In record, log is an ins parameter: the verb may change it, and the owner is the caller, so the verb has no cleanup row for it. In archive, log is a dat parameter: the verb owns it, and it must be released at the end, so the panel has the row drop log at line 7, column 2, just after the closing brace.

Where the rows come from

The panel sends two requests for the open file: actus/memoryGraph and actus/semanticModel. The memory graph has the nodes, the edges and the transitions. The semantic model is used for one thing only: the type that is written after a name in a declaration row. If that request fails, the rows have no types.

A binding of the program is a node. This is the node of limit. The compiler says scalar: true, so the panel writes Value and not the state:

json
{
  "id": "binding:3",
  "kind": "binding",
  "name": "limit",
  "role": "erg",
  "scalar": true,
  "state": "Active"
}

Each event of the history is one entry of transitions, in the order in which the compiler recorded it. This is row 9, the dat hand-off of log. The line and the column are counted from 0 in the answer and from 1 in the panel, so line: 15, character: 37 becomes Ln 16:38:

json
{
  "node": "binding:4",
  "kind": "moved",
  "from": { "ownership": "Active", "access": "Mutable" },
  "to": { "ownership": "Moved", "access": "Mutable" },
  "range": {
    "start": { "line": 15, "character": 37 },
    "end": { "line": 15, "character": 40 }
  },
  "cause": { "kind": "datArgument", "callee": "archive", "parameter": "log" },
  "source": "ownership-history"
}

kind becomes the text of the row, cause becomes the detail, and from and to become the arrow (Active -> Moved). The cleanup of the verb is a node with the actions in the order in which they run. The panel makes one row of each action. This is the cleanup of main; the indices are those of note (5) and log (4):

json
{
  "id": "cleanup:4",
  "kind": "cleanup",
  "state": "Planned",
  "actions": [
    { "kind": "dropBinding", "bindingIndex": 5 },
    { "kind": "dropBinding", "bindingIndex": 4 }
  ]
}

The answers are shortened here: each node also has a range. The format is the one of the language server, described in Editor support.

Reading a row

Each row has five parts.

PartWhat it says
RoleA coloured badge. It is the role of the construct that the row is about. See Roles and colours.
RowThe name and the type of a participant (log: Buffer), or what happened (dat log -> archive(log:)).
DetailIn a lighter colour. For an event it names the cause and the change of state, for example dat argument to archive(log:) (Active -> Moved).
StateThe state of the participant after the row. See States.
Lineline:column in the file, both counted from 1. The row opens that place when you click it.

A declaration row has the state that the compiler records for the binding at the end of its scope, not at the place where it is declared. A binding that is moved on every path therefore shows Moved in its first row. The rows after it show how it got there.

The place of a row is where its cause is: the argument of a call for a dat hand-off, the call for a loan, the ref expression for a view. A row that ends something (a returned loan, a release, a join, a cleanup) has the place where the call, the scope or the construct ends.

The header of a verb has the state Scope, or Inactive when the verb is excluded by the target of the project. The number in it counts the rows of the verb, declarations included.

Roles and colours

The badge colours are the same as the role colours of the editor.

BadgeColourUsed for
verb#21F1A8the header of a verb
erg#4ADE80an owner: its declaration, its reinitialization, restore and join
abs#60A5FAa view: the declaration of a view, and a view that starts or ends
ins#FACC15a loan: it starts, and it is returned
dat#F472B6a hand-off
drop#94A3B8a release: explicit drop and the cleanup of a scope

drop is not a role of the language. It is the badge for a release, so that you can filter for it. A declaration row has the badge of the declared role, also for a parameter (ins for log in record). A restored or joined row has the role of the binding.

States

The state label of a row is one of these.

StateWhat it means for the participant
ActiveThe owner holds the value. It can be read, changed, lent, viewed and handed on.
MovedThe value was handed over, for example by a dat argument. The name cannot be used until it holds a value again.
FrozenA live abs view of the owner exists. Nobody can change it or move it until the view ends.
SuspendedThe owner is lent to a call by ins. Only that call can use it until it returns.
DroppedThe value was released, by an explicit drop or by the cleanup at the end of a scope.
PartiallyMovedA field of the value was moved out. The rest is still owned.
ValueThe row is about a number or a Bool. A scalar is a value and has no state, because it is copied and never moves.
Scope, InactiveThe header of a verb.

Frozen and Suspended are states of access to an owner whose ownership is still Active. When an owner has one of them, the panel shows it instead of Active, because it is what matters at that place.

What each event is

The compiler records nine kinds of events. Each is caused by one construct of your program.

EventCaused byRole badgeRow text
moveda dat argument, or another place where the value goes to a new ownerdatdat log -> archive(log:)
droppedan explicit dropdropdropped log
reinitializeda new value for an owner or a field that had moved outergreinitialized log
frozenan abs view of the owner starts, as in abs view = ref logabsfrozen log
releasedthat view ends with its scopeabsreleased log
loanedan ins argument: the owner is lent to the callinsins log -> record(log:)
returnedthe call ends and the owner is backinsreturned log
restoredthe start of a branch of an if or of an arm of a case: back to the state before itrole of the bindingrestored log
joinedthe end of an if, a case or a loop: the paths come togetherrole of the bindingjoined log

A moved event that has no call as its cause, such as a move into another owner, is written moved log, and the detail names its cause. A kind of event or of cause that the panel does not know is shown under its own name.

A loaned or moved row names the callee and the parameter. The parameter name is the one of the declaration, so two loans of different variables to the same parameter both read record(log:).

The joined event is recorded only when the path that continues has another state than the one the analysis has at that point. Here the else branch moves log and returns, and the code after the if continues from the first branch:

actus
verb archive(dat log: Buffer) -> Int {
    return buffer_length(buffer: abs log);
}

verb main() {
    erg limit = 3;
    erg log: Buffer = Buffer[0];
    if limit > 5 {
        println(int: limit);
    } else {
        erg total = archive(log: dat log);
        println(int: total);
        return;
    }
    println(int: buffer_length(buffer: abs log));
}

The rows of main:

RoleRowDetailStateLine
erglimit: IntScalar value (erg)Value6:5
erglog: BufferDeclared as ergActive7:5
ergtotal: IntScalar value (erg)Value11:9
datdat log -> archive(log:)dat argument to archive(log:) (Active -> Moved)Moved11:38
ergjoined logPath join (if) (Moved -> Active)Active14:6
dropdrop logCompiler cleanup plan (LIFO)Dropped16:2

The joined row is at the end of the if, line 14 column 6. The path that moved log leaves the verb, so after the if the owner has the state of the other path, Active, and the last line may use it.

An explicit drop is its own event, and then the cleanup at the end has nothing left to do for that owner:

actus
verb main() {
    erg log: Buffer = Buffer[0];
    append(log, 65);
    drop(log);
}
RoleRowDetailStateLine
erglog: BufferDeclared as ergDropped2:5
dropdropped logExplicit drop (Active -> Dropped)Dropped4:5

The declaration row says Dropped, because that is the state of log at the end of its scope.

The cleanup rows

At the end of every scope the compiler has a plan of what to release. The panel shows each action as a row with the badge drop, at the place where the scope ends, in the order of the plan:

  • drop log releases an owner. Owners are released in reverse order of their declaration, last first. In main above, drop note comes before drop log.
  • drop remaining fields of log is used when some fields of a struct moved out. The detail lists them.
  • reset arena name is the end of an arena.
  • drop log (Enum.Variant.field) releases the payload of an enum value.
  • end view on log appears when a view ends at the end of a scope and no released row shows it. In the program above the released row does.

A parameter that the verb does not own, abs or ins, has no cleanup row. A scalar has none either.

The connectors

At the left of the role badges there is a narrow column. For every participant that has two or more rows, it draws a thin rounded bracket from each of its rows to the next one. In main, log is connected from its declaration through the loan, the return, the hand-off, the restore, the freeze and the release, down to its cleanup. note has its own connector, and the two run side by side. A scalar has none, and neither has a participant with only one row, such as view.

The connectors are pale. When you hold the pointer over a row, or when the cursor of the editor is on a participant, its connectors get brighter and thicker and take the colour of the role of the row where each part starts. The connectors of other participants fade. So you can follow one participant down a long verb.

Pointer, cursor and click

  • Hover. The pointer over a row lights up the connectors of its participant.
  • Cursor focus. When you move the cursor in the editor, the panel finds the row whose range holds the cursor. If there is none, it takes the first row on the same line. The rows of that participant get a green background, and all other rows become dim. A declaration row covers the whole declaration, so the cursor anywhere in erg log: Buffer = Buffer[0]; selects log.
  • Click on a row. The editor opens the place of the row, selects it, scrolls it into view and marks it for a moment. The participant becomes the focused one.
  • Click on a verb header. The section opens or closes, and the editor moves to the verb. The arrow at the left of the header only opens and closes.

Filters, search and buttons

ControlWhat it does
Search fieldKeeps the rows whose text contains what you type: name, type, row, detail, state or role. The case does not matter.
All erg abs ins dat dropKeeps the rows with that badge. It combines with the search field.
Collapse AllCloses every verb section. The button then reads Expand All.
Focus CursorKeeps only the rows of the participant under the cursor, while it is switched on.
RefreshAsks the language server again.

When a filter, a search or Focus Cursor is on, the verb headers are hidden and only the verbs that have a matching row are shown. If nothing matches, the panel says No ownership transitions match the current filter.

For example, the filter dat on the program above leaves the declaration of log in archive and the hand-off in main. The filter drop leaves the three cleanup rows. The search Frozen leaves frozen log and released log, because the detail of the second one says Frozen -> Active.

When the file does not check

The panel only describes a package that the compiler accepts. If it does not, the compiler gives no graph and says why, and the panel shows that reason followed by a note. Here the buffer is used after it was handed over:

actus
verb archive(dat log: Buffer) -> Int {
    return buffer_length(buffer: abs log);
}

verb main() {
    erg log: Buffer = Buffer[0];
    archive(log: dat log);
    println(int: buffer_length(buffer: abs log));
}

The reason comes from the compiler. Open in the editor, this file gives the panel only this text, and no rows:

text
the package does not check: E1005 use of moved binding `log` — the Actus Ownership panel requires a file that checks.

Fix the error and the panel fills in again. The Problems panel has the error in the usual place, with the quick fix Explain Actus E1005.

The other messages are:

MessageWhen
Actus language server is not running followed by the notethe server did not start, or was stopped
Could not query actus/memoryGraph (...) followed by the notethe request failed
Unsupported actus/memoryGraph schemaVersion N (expected 1). Please update the Actus VS Code extension.the compiler speaks a newer schema
No bindings or ownership events reported by the compiler for this file.the file has nothing to show

What the panel does not do

  • It shows one file at a time: the active Actus file. The compiler checks the whole package to answer.
  • It does not change the file. It has no buttons for fixes.
  • It shows the analysis of the compiler, and that is all. If you want to know why the compiler rejects a program, the error has the explanation and actus explain has the long text. See Fixing and explaining errors.

What you learned

  • The panel lists, for each verb, every participant with its role, type and state, and every event the compiler recorded for it, in order.
  • The states are Active, Moved, Frozen, Suspended and Dropped. A number or a Bool is a value and has no state.
  • A dat argument gives Moved, an abs view gives frozen and released, an ins loan gives loaned and returned, an explicit drop gives dropped, and an if gives restored and joined.
  • The cleanup rows come last in each scope, in reverse order of declaration.
  • The rows are the answer of actus/memoryGraph. When a file does not check, the panel shows the reason of the compiler.

Next: Tests in VS Code.