on master help sign in
Suppress the full-read warning per run/run1 with a trailing comment

A trailing comment on the run/run1 line (-- allow full read) opts that specific call out of the full-read warning — the same source can be read partially elsewhere without suppressing those. The suppression is tied to the run line only (not the line above), so a comment on one run does not suppress the next. Suite 291/0.

commit0ddc1154a46b0ce5fb2c6711b53f541a13ad5d84 authoriko <mail@iko.soy> dateSun 30 Aug 2026, 14:10 (1 month ago) parent0351d25
1 file changed+18−2
crates/knot-compiler/src/codegen.rs+18−2
crates/knot-compiler/src/codegen.rs+18−2
@@ -7191,8 +7191,13 @@ impl<M: cranelift_module::Module> Codegen<M> {
71917191 && let Some(schema) = self.source_schemas.get(&source_name).cloned()
71927192 {
71937193 let fn_name = Self::query_form_name(func_expr).unwrap();
7194− self.in_memory_source_reads
7195− .insert(source_name.clone(), (expr.span, fn_name.to_string()));
7194+ // A `-- allow full read` comment on this line (or the line above)
7195+ // opts this specific run/run1 out of the full-read warning — the
7196+ // same source may be read partially elsewhere.
7197+ if !self.suppresses_full_read_warning(expr.span) {
7198+ self.in_memory_source_reads
7199+ .insert(source_name.clone(), (expr.span, fn_name.to_string()));
7200+ }
71967201 self.emit_stm_track_read(builder, &source_name);
71977202 let (name_ptr, name_len) = self.string_ptr(builder, &source_name);
71987203 let (schema_ptr, schema_len) = self.string_ptr(builder, &schema);
@@ -16386,6 +16391,17 @@ impl<M: cranelift_module::Module> Codegen<M> {
1638616391 /// every codegen path that emits one of them must call this for every
1638716392 /// table the query touches — otherwise an STM `retry` watching the
1638816393 /// table is never woken by writes to it.
16394+ /// Whether the full-read warning is suppressed for the `run`/`run1` call at
16395+ /// `span` — a `-- allow full read` comment on that line (a trailing comment).
16396+ fn suppresses_full_read_warning(&self, span: ast::Span) -> bool {
16397+ let (line, _) = knot::diagnostic::line_col(&self.source_text, span.start);
16398+ // Only the run's own line — a trailing `-- allow full read` on it.
16399+ self.source_text
16400+ .lines()
16401+ .nth(line.saturating_sub(1))
16402+ .is_some_and(|l| l.contains("-- allow full read"))
16403+ }
16404+
1638916405 fn emit_stm_track_read(&mut self, builder: &mut FunctionBuilder, source_name: &str) {
1639016406 let (tn_ptr, tn_len) = self.string_ptr(builder, source_name);
1639116407 self.call_rt_void(builder, "knot_stm_track_read", &[tn_ptr, tn_len]);