Skip to main content

Module effects

Module effects 

Source
Expand description

Effects on the world outside the function: files, the network, other services, processes and the environment.

The access analysis (crate::access) sees the function’s own variables and fields. It cannot see that api.delete(name).await and api.create(obj).await touch the same object on a server, or that fs::write("a", ..) and fs::read("a") touch the same file: neither statement writes a variable the other reads. This module gives every statement a list of Effects, each one an operation of some Kind on a target in a Domain, recognized from the call:

  • Files: path-qualified calls into a file-system module (std::fs::write, tokio::fs::read_to_string, fs::remove_file), File::create/File::open, OpenOptions. The target is the path argument.
  • Network: TcpStream::connect, UdpSocket::bind, send_to, … on the net types.
  • Processes: Command::new, process::exit, kill. A child process may touch anything, so a process effect conflicts with every other domain.
  • Environment: env::set_var, env::remove_var, set_current_dir write it; env::var reads it.
  • Services: any other awaited call, classified by the verb its name starts with (delete_object, create, post, put, upload, send write; get, list, head, fetch read). The target domain is the receiver (self.s3, api), and the target is the verb’s first argument. An awaited free function (delete_user(id).await) reaches an unknown service, which may be any receiver.

Two effects conflict when one writes, their domains may be the same resource, and their targets may be the same: two distinct string literals ("a.toml", "b.toml") are known to differ, and in a loop two targets computed from the loop item are assumed to differ between iterations (each item names its own object); anything else may be the same. Conflicting statements keep their order.

A write is also irreversible: psync does not run it ahead of an earlier statement that may leave the function or loop (?, return, break), because sequential code would then not have performed it. #[psync::speculate] on the statement (or loop, or speculate on the whole function) asserts that running it anyway is harmless, for idempotent operations.

An awaited call whose name has no known verb (client.request(req), do_work(x)) is unclassified. By default it is assumed to read (the behavior before effects existed), and reported. Under #[psync::graph(strict)] it is a write to an unknown resource, which conflicts with every effect and never runs speculatively.

StructsΒ§

Config
Function-wide settings from #[psync::graph(..)].
Effect πŸ”’
One operation on the outside world.
Finder πŸ”’
Found πŸ”’
The effects of a statement or expression, and the awaited calls psync could not classify.

EnumsΒ§

Calls
#[psync::graph(calls = ..)]: a function-wide mark for the calls psync cannot classify, and whether the function’s statements commute.
Domain πŸ”’
Where an effect lands.
Kind πŸ”’
Piece πŸ”’
One piece of a Target::Template.
Target πŸ”’
What an effect acts on inside its domain.
Verb
What a function or method name says about the operation, for tools outside the macro (cargo psync check classifies calls into other crates with the same lists).

ConstantsΒ§

FS_READS πŸ”’
File-system functions (last path segment) that only read.
NET_WRITES πŸ”’
Network functions that write (send data); the rest of net only connects or reads.
ORDERED_VERBS πŸ”’
First words of names whose relative order is observable on one domain.
PATH_FS_READS πŸ”’
Methods of std::path::Path without arguments that read the file system at the path.
READ_VERBS πŸ”’
First words of names that read.
REDIS_ORDERED πŸ”’
Commands whose order on one key is visible: list pushes and pops, stream appends.
REDIS_READS πŸ”’
Redis commands, as the redis crate names its methods (con.hget(k, f), con.get_del(k)) and as redis::cmd("HGET") names them. Matched by the whole name or its first word, before the verbs: get_del deletes, though its first word reads.
REDIS_WRITES πŸ”’
SQL_READS πŸ”’
Statements that only read, by their first word. EXPLAIN without ANALYZE only plans.
SQL_WRITES πŸ”’
Statements that change the database or the session, by their first word.
SQL_WRITE_WORDS πŸ”’
Words that make a reading statement write or lock: SELECT .. FOR UPDATE, SELECT .. INTO, nextval(..), a data-modifying WITH, EXPLAIN ANALYZE (which runs the statement).
WRITE_VERBS πŸ”’
First words of names that write.

FunctionsΒ§

conflict πŸ”’
Why two effects conflict, if they do.
conflicts πŸ”’
The first conflict between two effect lists.
contains_await πŸ”’
ended πŸ”’
A template’s pieces, ended as a place ends: a file path with / (a directory overlaps the files in it), any other string with an end marker (it overlaps only itself).
first_word πŸ”’
fs_reads
True for file-system functions that only read (read_to_string, metadata, open, …).
http_kind πŸ”’
RFC 9110: GET, HEAD, OPTIONS and TRACE are safe (they behave as reads); every other method may change the server.
http_of_chain πŸ”’
The HTTP method a chain names, if any, with the URL it goes to: request(Method::PUT, url) (reqwest, http, hyper, any path ending in Method::X), or a builder’s .method(Method::PUT) / .method("PUT") with the URL from .uri(..) or .url(..). The last element is the URL’s expression, when the target was taken from it (a gate may compare it at run time).
of_stmt πŸ”’
Find the effects in node (a statement’s tokens, parsed by the caller).
of_stmt_in πŸ”’
of_stmt, in synchronous code when sync is set (Phase II): there a call blocks instead of being awaited, so every method chain and free function is classified by its verb as an awaited one is. A call without a known verb has no effect, and is not reported: in synchronous code most calls are computations (len, Vec::new).
per_environment πŸ”’
baseline = resync: effects as ReSynchronizer (ECOOP 2021, Β§4.4) models them, one pseudo-variable per environment. Every file effect acts on β€œthe file system” and every network or service effect on β€œthe network”, whatever its target, so a write orders every other access to its environment.
plain_place πŸ”’
A name or a field path (dir, self.root), as tokens.
receiver_path πŸ”’
The dotted path of a receiver (self.client), or None when it is computed.
short πŸ”’
sql_kind πŸ”’
Read or write, if text is an SQL statement: its first word is a statement keyword and more follows. None for any other string.
sql_of_chain πŸ”’
The SQL statement in an awaited chain, if any: a string literal argument of its root call (sqlx::query("..")), its root macro (sqlx::query!("..")) or one of its methods (client.execute("..", &[])). A statement psync cannot read in a call it knows is SQL (sqlx::query(&sql), diesel::sql_query(s)) may be anything, so it writes.
target_of πŸ”’
template πŸ”’
format!("..", args..) as a template, if every placeholder is a plain expression.
templates_alias πŸ”’
Two ended templates may name the same string: they agree until one runs out (one is a prefix of the other), or they first differ where either has a hole (a hole may be any text).
value_target πŸ”’
The target named by the value of a binding’s initializer: target_of, and also base.join(name) with base a name or field and name a string literal or format! whose text starts with a character that cannot make it absolute: the path base/name, as a template whose first hole is base. (Path::join with an absolute name replaces base; /, \ and a drive letter C: are refused.)
verb_of
The verb a name starts with, if psync knows it.