Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename from Lowered to Canonical #9447

Merged
merged 1 commit into from
Nov 26, 2024
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
4 changes: 2 additions & 2 deletions crates/uv-pep508/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ use url::Url;

use cursor::Cursor;
pub use marker::{
ContainsMarkerTree, ExtraMarkerTree, ExtraOperator, InMarkerTree, LoweredMarkerValueExtra,
LoweredMarkerValueString, LoweredMarkerValueVersion, MarkerEnvironment,
CanonicalMarkerValueExtra, CanonicalMarkerValueString, CanonicalMarkerValueVersion,
ContainsMarkerTree, ExtraMarkerTree, ExtraOperator, InMarkerTree, MarkerEnvironment,
MarkerEnvironmentBuilder, MarkerExpression, MarkerOperator, MarkerTree, MarkerTreeContents,
MarkerTreeKind, MarkerValue, MarkerValueExtra, MarkerValueString, MarkerValueVersion,
MarkerWarningKind, StringMarkerTree, StringVersion, VersionMarkerTree,
Expand Down
34 changes: 17 additions & 17 deletions crates/uv-pep508/src/marker/algebra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ use uv_pep440::{release_specifier_to_range, Operator, Version, VersionSpecifier}
use version_ranges::Ranges;

use crate::marker::lowering::{
LoweredMarkerValueExtra, LoweredMarkerValueString, LoweredMarkerValueVersion,
CanonicalMarkerValueExtra, CanonicalMarkerValueString, CanonicalMarkerValueVersion,
};
use crate::marker::MarkerValueExtra;
use crate::ExtraOperator;
Expand Down Expand Up @@ -162,18 +162,18 @@ impl InternerGuard<'_> {
// to disjoint version ranges.
MarkerExpression::Version { key, specifier } => match key {
MarkerValueVersion::ImplementationVersion => (
Variable::Version(LoweredMarkerValueVersion::ImplementationVersion),
Variable::Version(CanonicalMarkerValueVersion::ImplementationVersion),
Edges::from_specifier(specifier),
),
MarkerValueVersion::PythonFullVersion => (
Variable::Version(LoweredMarkerValueVersion::PythonFullVersion),
Variable::Version(CanonicalMarkerValueVersion::PythonFullVersion),
Edges::from_specifier(specifier),
),
// Normalize `python_version` markers to `python_full_version` nodes.
MarkerValueVersion::PythonVersion => {
match python_version_to_full_version(normalize_specifier(specifier)) {
Ok(specifier) => (
Variable::Version(LoweredMarkerValueVersion::PythonFullVersion),
Variable::Version(CanonicalMarkerValueVersion::PythonFullVersion),
Edges::from_specifier(specifier),
),
Err(node) => return node,
Expand All @@ -188,18 +188,18 @@ impl InternerGuard<'_> {
negated,
} => match key {
MarkerValueVersion::ImplementationVersion => (
Variable::Version(LoweredMarkerValueVersion::ImplementationVersion),
Variable::Version(CanonicalMarkerValueVersion::ImplementationVersion),
Edges::from_versions(&versions, negated),
),
MarkerValueVersion::PythonFullVersion => (
Variable::Version(LoweredMarkerValueVersion::PythonFullVersion),
Variable::Version(CanonicalMarkerValueVersion::PythonFullVersion),
Edges::from_versions(&versions, negated),
),
// Normalize `python_version` markers to `python_full_version` nodes.
MarkerValueVersion::PythonVersion => {
match Edges::from_python_versions(versions, negated) {
Ok(edges) => (
Variable::Version(LoweredMarkerValueVersion::PythonFullVersion),
Variable::Version(CanonicalMarkerValueVersion::PythonFullVersion),
edges,
),
Err(node) => return node,
Expand Down Expand Up @@ -275,14 +275,14 @@ impl InternerGuard<'_> {
name: MarkerValueExtra::Extra(extra),
operator: ExtraOperator::Equal,
} => (
Variable::Extra(LoweredMarkerValueExtra::Extra(extra)),
Variable::Extra(CanonicalMarkerValueExtra::Extra(extra)),
Edges::from_bool(true),
),
MarkerExpression::Extra {
name: MarkerValueExtra::Extra(extra),
operator: ExtraOperator::NotEqual,
} => (
Variable::Extra(LoweredMarkerValueExtra::Extra(extra)),
Variable::Extra(CanonicalMarkerValueExtra::Extra(extra)),
Edges::from_bool(false),
),
// Invalid extras are always `false`.
Expand Down Expand Up @@ -443,7 +443,7 @@ impl InternerGuard<'_> {
// Look for a `python_full_version` expression, otherwise
// we recursively simplify.
let Node {
var: Variable::Version(LoweredMarkerValueVersion::PythonFullVersion),
var: Variable::Version(CanonicalMarkerValueVersion::PythonFullVersion),
children: Edges::Version { ref edges },
} = node
else {
Expand Down Expand Up @@ -516,7 +516,7 @@ impl InternerGuard<'_> {
return NodeId::FALSE;
}
if matches!(i, NodeId::TRUE) {
let var = Variable::Version(LoweredMarkerValueVersion::PythonFullVersion);
let var = Variable::Version(CanonicalMarkerValueVersion::PythonFullVersion);
let edges = Edges::Version {
edges: Edges::from_range(&py_range),
};
Expand All @@ -525,7 +525,7 @@ impl InternerGuard<'_> {

let node = self.shared.node(i);
let Node {
var: Variable::Version(LoweredMarkerValueVersion::PythonFullVersion),
var: Variable::Version(CanonicalMarkerValueVersion::PythonFullVersion),
children: Edges::Version { ref edges },
} = node
else {
Expand Down Expand Up @@ -621,26 +621,26 @@ pub(crate) enum Variable {
///
/// This is the highest order variable as it typically contains the most complex
/// ranges, allowing us to merge ranges at the top-level.
Version(LoweredMarkerValueVersion),
Version(CanonicalMarkerValueVersion),
/// A string marker, such as `os_name`.
String(LoweredMarkerValueString),
String(CanonicalMarkerValueString),
/// A variable representing a `<key> in <value>` expression for a particular
/// string marker and value.
In {
key: LoweredMarkerValueString,
key: CanonicalMarkerValueString,
value: String,
},
/// A variable representing a `<value> in <key>` expression for a particular
/// string marker and value.
Contains {
key: LoweredMarkerValueString,
key: CanonicalMarkerValueString,
value: String,
},
/// A variable representing the existence or absence of a given extra.
///
/// We keep extras at the leaves of the tree, so when simplifying extras we can
/// trivially remove the leaves without having to reconstruct the entire tree.
Extra(LoweredMarkerValueExtra),
Extra(CanonicalMarkerValueExtra),
}

/// A decision node in an Algebraic Decision Diagram.
Expand Down
26 changes: 13 additions & 13 deletions crates/uv-pep508/src/marker/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use uv_pep440::{Version, VersionParseError};

use crate::{LoweredMarkerValueString, LoweredMarkerValueVersion, StringVersion};
use crate::{CanonicalMarkerValueString, CanonicalMarkerValueVersion, StringVersion};

/// The marker values for a python interpreter, normally the current one
///
Expand Down Expand Up @@ -33,28 +33,28 @@ struct MarkerEnvironmentInner {

impl MarkerEnvironment {
/// Returns of the PEP 440 version typed value of the key in the current environment
pub fn get_version(&self, key: LoweredMarkerValueVersion) -> &Version {
pub fn get_version(&self, key: CanonicalMarkerValueVersion) -> &Version {
match key {
LoweredMarkerValueVersion::ImplementationVersion => {
CanonicalMarkerValueVersion::ImplementationVersion => {
&self.implementation_version().version
}
LoweredMarkerValueVersion::PythonFullVersion => &self.python_full_version().version,
CanonicalMarkerValueVersion::PythonFullVersion => &self.python_full_version().version,
}
}

/// Returns of the stringly typed value of the key in the current environment
pub fn get_string(&self, key: LoweredMarkerValueString) -> &str {
pub fn get_string(&self, key: CanonicalMarkerValueString) -> &str {
match key {
LoweredMarkerValueString::ImplementationName => self.implementation_name(),
LoweredMarkerValueString::OsName => self.os_name(),
LoweredMarkerValueString::PlatformMachine => self.platform_machine(),
LoweredMarkerValueString::PlatformPythonImplementation => {
CanonicalMarkerValueString::ImplementationName => self.implementation_name(),
CanonicalMarkerValueString::OsName => self.os_name(),
CanonicalMarkerValueString::PlatformMachine => self.platform_machine(),
CanonicalMarkerValueString::PlatformPythonImplementation => {
self.platform_python_implementation()
}
LoweredMarkerValueString::PlatformRelease => self.platform_release(),
LoweredMarkerValueString::PlatformSystem => self.platform_system(),
LoweredMarkerValueString::PlatformVersion => self.platform_version(),
LoweredMarkerValueString::SysPlatform => self.sys_platform(),
CanonicalMarkerValueString::PlatformRelease => self.platform_release(),
CanonicalMarkerValueString::PlatformSystem => self.platform_system(),
CanonicalMarkerValueString::PlatformVersion => self.platform_version(),
CanonicalMarkerValueString::SysPlatform => self.sys_platform(),
}
}
}
Expand Down
50 changes: 25 additions & 25 deletions crates/uv-pep508/src/marker/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ use crate::{MarkerValueExtra, MarkerValueString, MarkerValueVersion};
/// Those environment markers with a PEP 440 version as value such as `python_version`
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
#[allow(clippy::enum_variant_names)]
pub enum LoweredMarkerValueVersion {
pub enum CanonicalMarkerValueVersion {
/// `implementation_version`
ImplementationVersion,
/// `python_full_version`
PythonFullVersion,
}

impl Display for LoweredMarkerValueVersion {
impl Display for CanonicalMarkerValueVersion {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::ImplementationVersion => f.write_str("implementation_version"),
Expand All @@ -23,18 +23,18 @@ impl Display for LoweredMarkerValueVersion {
}
}

impl From<LoweredMarkerValueVersion> for MarkerValueVersion {
fn from(value: LoweredMarkerValueVersion) -> Self {
impl From<CanonicalMarkerValueVersion> for MarkerValueVersion {
fn from(value: CanonicalMarkerValueVersion) -> Self {
match value {
LoweredMarkerValueVersion::ImplementationVersion => Self::ImplementationVersion,
LoweredMarkerValueVersion::PythonFullVersion => Self::PythonFullVersion,
CanonicalMarkerValueVersion::ImplementationVersion => Self::ImplementationVersion,
CanonicalMarkerValueVersion::PythonFullVersion => Self::PythonFullVersion,
}
}
}

/// Those environment markers with an arbitrary string as value such as `sys_platform`
#[derive(Copy, Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub enum LoweredMarkerValueString {
pub enum CanonicalMarkerValueString {
/// `implementation_name`
ImplementationName,
/// `os_name`
Expand All @@ -54,7 +54,7 @@ pub enum LoweredMarkerValueString {
SysPlatform,
}

impl From<MarkerValueString> for LoweredMarkerValueString {
impl From<MarkerValueString> for CanonicalMarkerValueString {
fn from(value: MarkerValueString) -> Self {
match value {
MarkerValueString::ImplementationName => Self::ImplementationName,
Expand All @@ -77,24 +77,24 @@ impl From<MarkerValueString> for LoweredMarkerValueString {
}
}

impl From<LoweredMarkerValueString> for MarkerValueString {
fn from(value: LoweredMarkerValueString) -> Self {
impl From<CanonicalMarkerValueString> for MarkerValueString {
fn from(value: CanonicalMarkerValueString) -> Self {
match value {
LoweredMarkerValueString::ImplementationName => Self::ImplementationName,
LoweredMarkerValueString::OsName => Self::OsName,
LoweredMarkerValueString::PlatformMachine => Self::PlatformMachine,
LoweredMarkerValueString::PlatformPythonImplementation => {
CanonicalMarkerValueString::ImplementationName => Self::ImplementationName,
CanonicalMarkerValueString::OsName => Self::OsName,
CanonicalMarkerValueString::PlatformMachine => Self::PlatformMachine,
CanonicalMarkerValueString::PlatformPythonImplementation => {
Self::PlatformPythonImplementation
}
LoweredMarkerValueString::PlatformRelease => Self::PlatformRelease,
LoweredMarkerValueString::PlatformSystem => Self::PlatformSystem,
LoweredMarkerValueString::PlatformVersion => Self::PlatformVersion,
LoweredMarkerValueString::SysPlatform => Self::SysPlatform,
CanonicalMarkerValueString::PlatformRelease => Self::PlatformRelease,
CanonicalMarkerValueString::PlatformSystem => Self::PlatformSystem,
CanonicalMarkerValueString::PlatformVersion => Self::PlatformVersion,
CanonicalMarkerValueString::SysPlatform => Self::SysPlatform,
}
}
}

impl Display for LoweredMarkerValueString {
impl Display for CanonicalMarkerValueString {
/// Normalizes deprecated names to the proper ones
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Expand All @@ -112,12 +112,12 @@ impl Display for LoweredMarkerValueString {

/// The [`ExtraName`] value used in `extra` markers.
#[derive(Clone, Debug, Eq, Hash, PartialEq, PartialOrd, Ord)]
pub enum LoweredMarkerValueExtra {
pub enum CanonicalMarkerValueExtra {
/// A valid [`ExtraName`].
Extra(ExtraName),
}

impl LoweredMarkerValueExtra {
impl CanonicalMarkerValueExtra {
/// Returns the [`ExtraName`] value.
pub fn extra(&self) -> &ExtraName {
match self {
Expand All @@ -126,15 +126,15 @@ impl LoweredMarkerValueExtra {
}
}

impl From<LoweredMarkerValueExtra> for MarkerValueExtra {
fn from(value: LoweredMarkerValueExtra) -> Self {
impl From<CanonicalMarkerValueExtra> for MarkerValueExtra {
fn from(value: CanonicalMarkerValueExtra) -> Self {
match value {
LoweredMarkerValueExtra::Extra(extra) => Self::Extra(extra),
CanonicalMarkerValueExtra::Extra(extra) => Self::Extra(extra),
}
}
}

impl Display for LoweredMarkerValueExtra {
impl Display for CanonicalMarkerValueExtra {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
match self {
Self::Extra(extra) => extra.fmt(f),
Expand Down
4 changes: 3 additions & 1 deletion crates/uv-pep508/src/marker/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ mod simplify;
mod tree;

pub use environment::{MarkerEnvironment, MarkerEnvironmentBuilder};
pub use lowering::{LoweredMarkerValueExtra, LoweredMarkerValueString, LoweredMarkerValueVersion};
pub use lowering::{
CanonicalMarkerValueExtra, CanonicalMarkerValueString, CanonicalMarkerValueVersion,
};
pub use tree::{
ContainsMarkerTree, ExtraMarkerTree, ExtraOperator, InMarkerTree, MarkerExpression,
MarkerOperator, MarkerTree, MarkerTreeContents, MarkerTreeDebugGraph, MarkerTreeKind,
Expand Down
Loading
Loading