DAP: Add intrin DAPSpecs

We now specify intrins as separate DAPS lines. This syntax is much
nicer and well-grouped than the previous negtrin-*/postrin-* param
names.

Alas, we're about to replace it in the next few commits already though.
This commit is contained in:
2026-04-12 04:06:47 -04:00
parent c696316a1e
commit fc1fcae0b0
14 changed files with 595 additions and 284 deletions
+95
View File
@@ -49,6 +49,19 @@ inline constexpr std::array<std::string_view, 3> kNegIntThrParamNames = {
"negtrin-interest-thr",
};
// Short interest-* names: only valid on dedicated postrin/negtrin qualeIfaceApi
// lines (docs/design/intrin-thresholds.md); never on sensory qualeIfaceApi specs.
inline constexpr std::array<std::string_view, 2> kIntrinInterestPcUnprefixed = {
"interest-percentage",
"interest-pc",
};
inline constexpr std::array<std::string_view, 3> kIntrinInterestThrUnprefixed = {
"interest-threshold",
"interest-thresh",
"interest-thr",
};
inline constexpr std::array<std::string_view, 2> kPosDistPcParamNames = {
"postrin-distraction-percentage",
"postrin-distraction-pc",
@@ -150,6 +163,88 @@ bool namesContain(
return false;
}
inline bool isDedicatedIntrinsQualeIfaceApi(std::string_view qualeIfaceApi)
{
return qualeIfaceApi == "negtrin" || qualeIfaceApi == "postrin";
}
inline bool isKnownIntrinsPipelineParamName(std::string_view name)
{
return namesContain(kPosIntPcParamNames, name)
|| namesContain(kPosIntThrParamNames, name)
|| namesContain(kNegIntPcParamNames, name)
|| namesContain(kNegIntThrParamNames, name)
|| namesContain(kIntrinInterestPcUnprefixed, name)
|| namesContain(kIntrinInterestThrUnprefixed, name)
|| namesContain(kPosDistPcParamNames, name)
|| namesContain(kPosDistThrParamNames, name)
|| namesContain(kNegDistPcParamNames, name)
|| namesContain(kNegDistThrParamNames, name)
|| namesContain(kStupefactionPcParamNames, name)
|| namesContain(kStupefactionThrParamNames, name)
|| namesContain(kIntolerablePcParamNames, name)
|| namesContain(kIntolerableThrParamNames, name)
|| name == "passband-count-gt-val"
|| name == "passband-count-lt-val";
}
inline bool hasNonEmptyFromStimbuffParam(
const std::vector<std::pair<std::string, std::string>>& params)
{
for (const auto& [key, value] : params)
{
if (key == "from-stimbuff" && !value.empty())
{ return true; }
}
return false;
}
/**
* Enforces dedicated-only intrin specs: intrinsic thresholds and passband
* comparators appear only on negtrin/postrin qualeIfaceApi specs with
* from-stimbuff. Embedding intrins in other qualeIfaceApi parameter lists is
* rejected (docs/design/intrin-thresholds.md).
*/
inline void validateIntrinsQualeApiPolicy(
const std::string& qualeIfaceApi,
const std::vector<std::pair<std::string, std::string>>& params)
{
if (isDedicatedIntrinsQualeIfaceApi(qualeIfaceApi))
{
if (!hasNonEmptyFromStimbuffParam(params))
{
throw std::runtime_error(
"qualeIfaceApi '" + qualeIfaceApi + "' requires a non-empty "
"'from-stimbuff=<stimbuffQualeIfaceApi>' parameter naming the "
"sensory stimbuff that feeds this intrinsic pipeline.");
}
return;
}
for (const auto& [name, value] : params)
{
(void)value;
if (isKnownIntrinsPipelineParamName(name))
{
throw std::runtime_error(
"Intrinsic threshold and passband comparator params must not "
"appear on qualeIfaceApi '" + qualeIfaceApi + "'. Use dedicated "
"negtrin(...) or postrin(...) lines with from-stimbuff=... "
"(offending param: '" + name + "').");
}
if (name == "from-stimbuff")
{
throw std::runtime_error(
"'from-stimbuff' is only valid on negtrin(...) or postrin(...) "
"qualeIfaceApi specs.");
}
}
}
inline void validateNoForbiddenUnitlessIntrinParams(
const std::vector<std::pair<std::string, std::string>>& params)
{