Skip to content

Commit

Permalink
Refactor variance operations. WHAT A MESS!
Browse files Browse the repository at this point in the history
There's so much to clean up here. This change completely reworks
variance operations. Notably, the union operator is gone, a product
operator has been introduced, and natural invariants like depth now
produce detailed bounds!

This kicked up a lot of dust and a lot of questions... there's some
serious refactoring and reorganization to do here. However, this
codifies a more complete variance algebra and puts things in a better
place for determining exhaustiveness. Bounds and exhaustiveness are
important for matching, as they prevent unnecessary reads. Depth bounds
can prevent reads beyond the maximum depth of an expression and
exhaustiveness can prevent reads of directory trees that can be safely
ignored when a pattern is used as a negation. The more generally
variance can be reliably queried, the less necessary it is to use
bespoke code that must query token trees **before** applying
combinators.

There's much to solve regarding the exhaustiveness of alternations.
Let's get false positives fixed and get this cleaned up.
  • Loading branch information
olson-sean-k committed Feb 7, 2024
1 parent b032530 commit dca4bb0
Show file tree
Hide file tree
Showing 8 changed files with 957 additions and 496 deletions.
4 changes: 2 additions & 2 deletions src/rule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use thiserror::Error;
use crate::diagnostics::{CompositeSpan, CorrelatedSpan, SpanExt as _, Spanned};
use crate::token::walk::{self, TokenEntry};
use crate::token::{
self, BranchKind, ExpressionMetadata, NaturalVariance, Repetition, Size, Token, TokenTree,
self, BranchKind, ExpressionMetadata, NaturalRange, Repetition, Size, Token, TokenTree,
Tokenized,
};
use crate::{Any, BuildError, Glob, Pattern};
Expand Down Expand Up @@ -665,7 +665,7 @@ where
fn check_group_repetition<'i, 't, A>(
terminals: Terminals<&'i Token<'t, A>>,
outer: Outer<'i, 't, A>,
variance: NaturalVariance,
variance: NaturalRange,
) -> Result<(), CorrelatedError>
where
A: Spanned,
Expand Down
288 changes: 224 additions & 64 deletions src/token/mod.rs

Large diffs are not rendered by default.

Loading

0 comments on commit dca4bb0

Please sign in to comment.