no-mistakes-postgres-engine 0.109.131

PostgreSQL embedded SQL extraction, schema catalog, and replay-safety analysis for no-mistakes
Documentation
use super::*;
impl<'a> ScopeVisitor<'a> {
    pub(in crate::embedded::walk) fn revoke_lock_helper_arguments(
        &mut self,
        call: &CallExpression<'_>,
        helpers: std::ops::Range<usize>,
    ) {
        let deferred = self.imported_lock_helpers[helpers]
            .iter()
            .filter(|invocation| invocation.deferred_receiver_escape())
            .map(|invocation| invocation.executor)
            .collect::<Vec<_>>();
        self.revoke_namespace_arguments(&call.callee, &call.arguments, &deferred);
    }

    pub(super) fn record_unknown_lock_helper(&mut self, call: &CallExpression<'_>, name: &str) {
        for (executor, argument) in call.arguments.iter().enumerate() {
            let Some(expression) = argument.as_expression() else {
                continue;
            };
            if self.lock_helper_access(expression).is_none() {
                continue;
            }
            let receiver = match unwrap_ts_wrappers(expression) {
                Expression::StaticMemberExpression(member) => &member.object,
                expression => expression,
            };
            let mut fact = EmbeddedSqlCall::default();
            super::super::transaction::annotate_receiver(
                self,
                receiver,
                call.span.start,
                &mut fact,
            );
            super::super::transaction::annotate_pending_receiver(self, receiver, &mut fact);
            if !fact.executor_transaction_known || fact.transaction_id.is_none() {
                continue;
            }
            fact.lock_scope_analysis = true;
            fact.track_share_lock_writes = self.executor_options.track_share_lock_writes;
            super::super::transaction::annotate_execution_location(
                self,
                call,
                &mut fact,
                super::super::transaction::execution_scope(self),
            );
            fact.execution_loop = self.execution_loop;
            fact.line = byte_offset_to_line(self.source, call.span.start as usize);
            fact.callee = name.to_owned();
            fact.kind = EmbeddedSqlKind::Dynamic;
            fact.execution_unconditional = self.helper_execution_unconditional();
            let relative_owners = self
                .provisional
                .iter()
                .find(|span| Some(span.start) == fact.transaction_id)
                .map_or_else(Vec::new, |span| span.owners.clone());
            self.imported_lock_helpers.push(Invocation {
                relative_owners,
                accesses: call
                    .arguments
                    .iter()
                    .map(|argument| {
                        argument
                            .as_expression()
                            .and_then(|value| self.lock_helper_access(value))
                    })
                    .collect(),
                resolve_helper: self.awaited_lock_helper_calls.contains(&call.span.start)
                    && !call.optional
                    && self.imported_names.contains(name)
                    && self.lookup(name).is_none()
                    && call
                        .arguments
                        .iter()
                        .all(|argument| argument.as_expression().is_some()),
                name: name.to_owned(),
                executor,
                arguments: Vec::new(),
                call: fact,
                span: (call.span.start, call.span.end),
            });
        }
    }
}

impl ScopeVisitor<'_> {
    pub(super) fn helper_execution_unconditional(&self) -> bool {
        use super::super::transaction::{execution_scope, execution_unconditional};
        execution_unconditional(self, execution_scope(self))
    }
}