Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,24 @@ jobs:
- name: Test hygiene
run: cargo run --locked -q -p xtask -- test-hygiene

# Direct uses of a layer's rows outside rustgis-data may not rise above xtask/row-uses.txt
# (`cargo xtask rows`, #2431). The compiler counts them as deprecation warnings, so this job
# leaves warnings as warnings; the lint job denies them in the normal build.
rows:
name: Direct row uses
runs-on: ubuntu-latest
env:
RUSTFLAGS: ""
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7
- uses: dtolnay/rust-toolchain@b725eda525362e7cf34af9a7243cac1e3f01a7ec # stable
- uses: Swatinem/rust-cache@d1527c8f67ef9af357290475d4af4b0fab8f12e0 # v2
with:
# Only main saves the cache (see test-rust.yml).
save-if: ${{ github.ref == 'refs/heads/main' }}
- name: Count direct row uses
run: cargo run --locked -q -p xtask -- rows

# The packages whose tests this run needs, for `test` (.github/scripts/test-selection.sh). Only
# tests are narrowed: lint, the wasm build, licences and the schema check run whole every time.
select:
Expand Down Expand Up @@ -298,7 +316,7 @@ jobs:
# unless their conditions below hold (the same as on the jobs), and every other job always runs.
tests_pass:
name: Tests pass
needs: [lint, wasm, ios, android, licenses, schema, plan, select, test]
needs: [lint, wasm, ios, android, licenses, schema, rows, plan, select, test]
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
Expand Down
6 changes: 6 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ the pull request which of these it reaches and why the rest don't apply:
`#[ignore = "reason"]` on ignored tests; prefer completion or progress signals.
`cargo xtask memory` (in CI on Linux) fails when a command line workflow's peak memory grows past
its limit in `xtask/memory-limits.txt`; a change that lowers one commits the lower limit with it.
`cargo xtask rows` (also in CI) fails when code outside `rustgis-data` uses a layer's rows directly
(`Feature` fields, the row vector) more often than `xtask/row-uses.txt` allows: use the accessors on
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
`Features` (`row`, `rows`, `value`, `set_value`, …), and `--update` when you lower the count (#2431).
It counts only the libraries and programs built for the host, not tests, examples, benches or code
built only for other targets, nor a row indexed without reading a field (`features[i]` alone); use
the accessors there too.
While you work, `cargo xtask changed` runs the same checks on only the packages your branch changes
and those that depend on them (and `test-hygiene` on the whole workspace), or everything when a
changed file such as `Cargo.lock` is outside every package and nothing includes it.
Expand Down
3 changes: 3 additions & 0 deletions crates/data/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ rustix = { version = "1.1", features = ["process", "fs"] }
pdf = ["dep:hayro"]
# The JSON Schema of the saved types (`cargo xtask schema`).
schema = ["dep:schemars", "rustgis-geom/schema"]
# Marks direct uses of the row vector and of `Feature`'s fields as deprecated, so that
# `cargo xtask rows` can count them outside this crate (#2431). Nothing else turns it on.
count-row-uses = []

[dev-dependencies]
# Writing sample GeoParquet files.
Expand Down
18 changes: 11 additions & 7 deletions crates/data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub mod provenance;
pub mod publish;
pub mod query;
pub mod raster;
mod row_access;
pub mod rows;
pub mod s3_address;
pub mod secrets;
Expand All @@ -62,6 +63,7 @@ pub mod zip;

pub use date::{Date, DateTime};
pub use geometry::{Geometry, GeometryType, Measure, VertexId, ambiguous_area_message, pole_loop_count, pole_loop_message};
pub use row_access::RowRef;
pub use rustgis_geom::{Coord, Extent};
pub use value::{Field, FieldType, Value};

Expand Down Expand Up @@ -202,8 +204,11 @@ mod secret_redaction_tests {
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
pub struct Feature {
#[cfg_attr(feature = "count-row-uses", deprecated(note = "read rows through `Features::row`/`rows` (`RowRef`); see cargo xtask rows"))]
pub id: u64,
#[cfg_attr(feature = "count-row-uses", deprecated(note = "read rows through `Features::row`/`rows` (`RowRef`); see cargo xtask rows"))]
pub geometry: Option<Geometry>,
#[cfg_attr(feature = "count-row-uses", deprecated(note = "read rows through `Features::row`/`rows` (`RowRef`); see cargo xtask rows"))]
pub attrs: Vec<Value>,
}

Expand Down Expand Up @@ -276,6 +281,7 @@ impl Features {
}

/// The rows, taking them out of the share (copying them only when another copy holds them).
#[cfg_attr(feature = "count-row-uses", deprecated(note = "use `Features::to_rows` or the row accessors; see cargo xtask rows"))]
pub fn into_vec(self) -> Vec<Feature> {
self.before_copy();
std::sync::Arc::unwrap_or_clone(self.rows)
Expand Down Expand Up @@ -504,7 +510,7 @@ impl Dataset {
if self.windowed {
return 0;
}
self.features.iter().flat_map(|f| &f.attrs).filter(|v| v.is_non_finite()).count()
self.features.rows().flat_map(RowRef::values).filter(|v| v.is_non_finite()).count()
}

/// How many of its features have a coordinate that isn't a number (NaN, infinity), which a
Expand All @@ -514,7 +520,7 @@ impl Dataset {
if self.windowed {
return 0;
}
self.features.iter().filter(|f| f.geometry.as_ref().is_some_and(|g| !g.is_finite())).count()
self.features.rows().filter(|r| r.geometry().is_some_and(|g| !g.is_finite())).count()
}
}

Expand Down Expand Up @@ -836,14 +842,14 @@ impl Dataset {

/// Value of `field` for feature `row` (Null when out of range).
pub fn value(&self, row: usize, field: usize) -> &Value {
self.features.get(row).and_then(|f| f.attrs.get(field)).unwrap_or(&Value::Null)
self.features.value(row, field)
}

/// The box around its features' geometry, in its own coordinates ([`Dataset::coord_crs`]), as
/// a file in that system would hold it. [`Dataset::lonlat_extent`] gives it in
/// longitude/latitude, for zooming and for what the map and the notices take.
pub fn extent(&self) -> Extent {
self.features.iter().filter_map(|f| f.geometry.as_ref()).fold(Extent::EMPTY, |e, g| e.union(&g.extent()))
self.features.rows().filter_map(RowRef::geometry).fold(Extent::EMPTY, |e, g| e.union(&g.extent()))
}

/// The box around its features' geometry in longitude/latitude: [`Dataset::extent`] through
Expand Down Expand Up @@ -981,9 +987,7 @@ impl Dataset {
return i;
}
self.fields.push(Field::new(name, ty));
for f in &mut self.features {
f.attrs.push(Value::Null);
}
self.features.add_column(Value::Null);
self.fields.len() - 1
}

Expand Down
Loading
Loading