lang::cfg

lang/src/cfg.mo

#[cfg ...] predicates over mote features. Mirrors rust/core/src/cfg.rs.

#[cfg P1 P2 ...] is an implicit all; each P is a flag (test), a key/value block ({feature := "sys"}) or a combinator group ([not P], [all P...], [any P...]). Unknown flags and keys are false.

test is decided by the test-mode filters, so CfgEnv.keep drops a declaration only when its predicate is false with and without test.

typeCfgPred#
pub type CfgPred {
    flag (name : String),
    key_value (key : String) (value : String),
    negate (p : CfgPred),
    all_of (ps : List CfgPred),
    any_of (ps : List CfgPred),
}
structCfgEnv#
pub struct CfgEnv {
    features : List String,
}

The features enabled for the mote that owns the file being parsed.

defCfgEnv.empty#
pub def CfgEnv.empty : CfgEnv
defCfgPred.parse#
pub def CfgPred.parse (args : List AttrArg) : Option CfgPred

The predicate of one #[cfg ...] attribute's args; none if malformed.

defCfgPred.eval#
pub def CfgPred.eval (p : CfgPred) (env : CfgEnv) (test : Bool) : Bool
defCfgEnv.keep#
pub def CfgEnv.keep (env : CfgEnv) (attrs : List Attribute) : Bool

Keep a declaration unless one of its #[cfg]s is false both with and without test. A malformed predicate keeps the declaration.

defCfgEnv.for_mote#
pub def CfgEnv.for_mote (mote : String) (table : List (Pair String (List String))) (spec : Option String) : CfgEnv

The features enabled for mote: the mote/feature items of spec (MONAD_FEATURES, comma- or whitespace-separated) plus default when table ([features]) declares it, closed over the plain features each enabled one lists. dep:x and x/f items name dependencies and are not followed. Mirrors CfgSet::with_manifest_features.

A not token before an item SUBTRACTS it, so a manifest's default can be turned off from the outside:

MONAD_FEATURES="not cli/default"        // the whole default set off
MONAD_FEATURES="not cli/lsp, cli/doc"   // lsp off, doc on

not is Monad's own negation vocabulary -- the same word #[cfg [not {feature := "on"}]] uses and CfgPred.negate implements -- rather than a punctuation prefix, and it is a separate whitespace-delimited TOKEN so both splitters already carry it through untouched. It is lowercase-only, matching cfg_group_head's own comparison.

The subtraction is applied to mote only: an item naming another mote is neither requested nor suppressed here, exactly as it is not requested. That is what makes not std/foo inert while checking cli rather than a claim about a mote this call knows nothing about.

default is the one item whose subtraction changes what is ENABLED without appearing in requested: it is added by this function, so removing it here is the only way to reach it.

THE SUPPRESSION IS APPLIED TWICE, and both halves are load-bearing -- dropping from start alone is a bug test_cfg_not_ordinary_feature_wins_over_default caught:

  • BEFORE expansion, so not cli/default stops default from being expanded at all. Filtering only the output would delete the name default while leaving y and x -- everything it pulled in -- in place, which is the opposite of turning it off.
  • AFTER expansion, so not cli/x still wins when x is reachable transitively (default -> y -> x). Dropping it from start cannot help there: x is not IN start, it is derived from it, and cfg_expand would put it straight back.

So the rule a caller can rely on is simply "a subtracted name is not in the answer", whichever route it would have taken in.