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 thenettypes. - 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_dirwrite it;env::varreads it. - Services: any other awaited call, classified by the verb its name starts with
(
delete_object,create,post,put,upload,sendwrite;get,list,head,fetchread). 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 checkclassifies 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
netonly connects or reads. - ORDERED_
VERBS π - First words of names whose relative order is observable on one domain.
- PATH_
FS_ πREADS - Methods of
std::path::Pathwithout 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
rediscrate names its methods (con.hget(k, f),con.get_del(k)) and asredis::cmd("HGET")names them. Matched by the whole name or its first word, before the verbs:get_deldeletes, though its first word reads. - REDIS_
WRITES π - SQL_
READS π - Statements that only read, by their first word.
EXPLAINwithoutANALYZEonly 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-modifyingWITH,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 inMethod::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 whensyncis 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), orNonewhen it is computed. - short π
- sql_
kind π - Read or write, if
textis an SQL statement: its first word is a statement keyword and more follows.Nonefor 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 alsobase.join(name)withbasea name or field andnamea string literal orformat!whose text starts with a character that cannot make it absolute: the pathbase/name, as a template whose first hole isbase. (Path::joinwith an absolutenamereplacesbase;/,\and a drive letterC:are refused.) - verb_of
- The verb a name starts with, if psync knows it.