Resolution: a requirement nothing in the mesh answers holds its consumers too; optional ones stay absent (A-452)
The mesh-wide refusal ("nothing in this mesh provides") holds its consumers as the
node-wide one does; a module that wants the name only optionally is left absent
(ADR 0330 §3), never held. A held why still names the nodes that offer nothing
here. The two tests of the first commit are folded as rows into one table test
that replaces two existing ones.
Builds: design 47 G A-452
This commit is contained in:
@@ -151,9 +151,6 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
// once, and saying the same thing twice makes a person hunt for the difference between two
|
||||
// identical lines before realising there is none.
|
||||
reported := map[string]bool{}
|
||||
// A requirement nothing answers costs the modules that want it, not the machine (A-452, ADR 0636 §3): said once per name,
|
||||
// each consumer is held after the walk, when the set is known.
|
||||
var unanswered []string
|
||||
|
||||
// **An optional requirement is settled last** (novox/hq ADR 0330). Whether a name is optional is
|
||||
// a question about every module that wants it, and a module pulled in later may want it hard; so
|
||||
@@ -184,6 +181,22 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
absent[want] = true
|
||||
reported[want] = true
|
||||
}
|
||||
// A requirement nothing answers costs the modules that want it, not the machine (A-452, ADR 0636 §3): said once per name,
|
||||
// each consumer is held after the walk, when the set is known.
|
||||
// The value is the remedy the mesh-wide refusal adds, empty for a requirement nothing on the node answers.
|
||||
unanswered := map[string]string{}
|
||||
var unansweredOrder []string
|
||||
holdWhenUnanswered := func(want, remedy string) {
|
||||
if !wantedHard(want) && wantedOptionally(want) {
|
||||
// Only optional consumers: left absent, never held (ADR 0330 §3).
|
||||
leaveAbsent(want)
|
||||
return
|
||||
}
|
||||
if _, ok := unanswered[want]; !ok {
|
||||
unansweredOrder = append(unansweredOrder, want)
|
||||
}
|
||||
unanswered[want] = remedy
|
||||
}
|
||||
|
||||
for {
|
||||
if len(queue) == 0 {
|
||||
@@ -376,9 +389,8 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
} else if len(answers) > 1 {
|
||||
remedy = "— assign one of these to a node: " + strings.Join(answers, ", ")
|
||||
}
|
||||
problems = append(problems, fmt.Sprintf(
|
||||
"nothing in this mesh provides %q, wanted by %s %s",
|
||||
want, because[want], remedy))
|
||||
// Not answered on the node nor in the rest of the mesh: costs its consumers only (A-452).
|
||||
holdWhenUnanswered(want, remedy)
|
||||
case len(where) == 1:
|
||||
if c, pinned := world.Pinned[want]; pinned && !chosenMatches(c, where[0]) {
|
||||
// One provider, and it is not the one this machine was told to use. Silently
|
||||
@@ -486,7 +498,7 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
continue
|
||||
}
|
||||
reported[want] = true
|
||||
unanswered = append(unanswered, want)
|
||||
holdWhenUnanswered(want, "")
|
||||
continue
|
||||
case 1:
|
||||
// No choice to make, so none is made. This is the case that lets `install i3` bring
|
||||
@@ -601,7 +613,7 @@ func resolve(catalogue map[string]mcat.Manifest, assigned []string, node mcat.No
|
||||
|
||||
problems = append(problems, checkCapabilities(resolution.Modules, node)...)
|
||||
claims, held := holdClaims(resolution.Modules, node, elsewhere, world.Holdings)
|
||||
held, unheld := holdUnanswered(resolution.Modules, unanswered, because, held)
|
||||
held, unheld := holdUnanswered(resolution.Modules, unansweredOrder, unanswered, because, held)
|
||||
problems = append(problems, unheld...)
|
||||
problems = append(problems, checkResources(resolution.Modules)...)
|
||||
resolution.Claims = claims
|
||||
@@ -684,11 +696,19 @@ func checkCapabilities(modules []mcat.Manifest, node mcat.Node) []string {
|
||||
return problems
|
||||
}
|
||||
|
||||
// unansweredWords is why a consumer is held for a requirement nothing answers, naming the provision.
|
||||
func unansweredWords(want, consumer, remedy string) string {
|
||||
if remedy == "" {
|
||||
return fmt.Sprintf("nothing provides %q, wanted by %s", want, consumer)
|
||||
}
|
||||
return fmt.Sprintf("nothing in this mesh provides %q, wanted by %s %s", want, consumer, remedy)
|
||||
}
|
||||
|
||||
// holdUnanswered holds each module of the set that wants a requirement nothing answers, with the words "nothing provides" naming the
|
||||
// provision (A-452): it stays in the set, so what it provides still counts for the others. A requirement none of the set's modules
|
||||
// wants (an assigned name the catalogue does not know) has no consumer to hold and comes back as a problem of the node; so does a
|
||||
// set whose every module is held, since then nothing could be composed.
|
||||
func holdUnanswered(modules []mcat.Manifest, unanswered []string, because map[string]string, held map[string]string) (map[string]string, []string) {
|
||||
func holdUnanswered(modules []mcat.Manifest, unanswered []string, remedies map[string]string, because map[string]string, held map[string]string) (map[string]string, []string) {
|
||||
var problems []string
|
||||
for _, want := range unanswered {
|
||||
found := false
|
||||
@@ -704,17 +724,21 @@ func holdUnanswered(modules []mcat.Manifest, unanswered []string, because map[st
|
||||
continue
|
||||
}
|
||||
found = true
|
||||
if m.IsOptional(want) {
|
||||
// Optional for this module: not held (ADR 0330 §3).
|
||||
continue
|
||||
}
|
||||
if held == nil {
|
||||
held = map[string]string{}
|
||||
}
|
||||
why := fmt.Sprintf("nothing provides %q, wanted by %s", want, m.Module)
|
||||
why := unansweredWords(want, m.Module, remedies[want])
|
||||
if prior, ok := held[m.Module]; ok {
|
||||
why = prior + "; " + why
|
||||
}
|
||||
held[m.Module] = why
|
||||
}
|
||||
if !found {
|
||||
problems = append(problems, fmt.Sprintf("nothing provides %q, wanted by %s", want, because[want]))
|
||||
problems = append(problems, unansweredWords(want, because[want], remedies[want]))
|
||||
}
|
||||
}
|
||||
if len(unanswered) > 0 && len(held) >= len(modules) {
|
||||
|
||||
Reference in New Issue
Block a user