lang::features

lang/src/features.mo

Optional-dependency and feature resolution.

Pure: the caller supplies one FeaturePackage per reachable mote (its [features] table and its dependency policies), plus the root's selection. No filesystem read happens here, which is what makes the resolver unit-testable and identical in both compilers.

Rules (Cargo's model):

  • features are additive and unioned; a dependency is enabled if any dependent enables it;
  • a non-optional dependency is always enabled with the parent's default-features choice;
  • an optional dependency is enabled only by dep:name, name/f or a plain item naming an optional dep;
  • name?/f is weak: it enables f only if name is already enabled;
  • default is a feature like any other; the root's is on unless no_default, a dependency's follows its policy.

This module is the feature half of implementations/ attributes-deprecated-and-cfg.md's CfgSet; it does not do the #[cfg] filtering itself.

structDepPolicy#
pub struct DepPolicy {
    optional : Bool,
    features : List String,
    default_features : Bool
}
defDepPolicy.default#
pub def DepPolicy.default : DepPolicy
structFeaturePackage#
pub struct FeaturePackage {
    name : String,
    features : List (Pair String (List String)),
    deps : List (Pair String DepPolicy)
}

One package's feature declarations and dependency policies.

structFeatureSelection#
pub struct FeatureSelection {
    features : List (Pair String (List String)),
    enabled_deps : List (Pair String (List String))
}

The resolved answer: each package's enabled feature set, and each package's enabled dependency names (non-optional plus activated optional ones).

defFeatures.resolve#
pub def Features.resolve (pkgs : List FeaturePackage) (root : String)
(requested : List String) (no_default : Bool) : Result String FeatureSelection

Resolve a root's features. requested are the CLI/target features; no_default drops only the root's default.