concretizer: simplify and suppress warnings for variant handling

We are relying on default logic in the variant handling in that we set a
default value if we never see `variant_set(P, V, X)`.

- Move the logic for this into `concretize.lp` instead of generating it
  for every package.

- For programs that don't have explicit variant settings, clingo warns
  that variant_set(P, V, X) doesn't appear in any rule head, because a
  setting is never generated.

  - Specifically suppress this warning.
This commit is contained in:
Todd Gamblin 2019-08-10 18:04:26 -07:00
parent b171ac5050
commit d94d957536
2 changed files with 19 additions and 8 deletions

View File

@ -196,14 +196,17 @@ def pkg_rules(self, pkg):
single = fn.variant_single_value(pkg.name, name)
if single_value:
self.rule(single, fn.node(pkg.name))
self.rule(fn.variant_value(pkg.name, name, variant.default),
self._not(fn.variant_set(pkg.name, name)))
self.rule(
fn.variant_default_value(pkg.name, name, variant.default),
fn.node(pkg.name))
else:
self.rule(self._not(single), fn.node(pkg.name))
defaults = variant.default.split(',')
for val in defaults:
self.rule(fn.variant_value(pkg.name, name, val),
self._not(fn.variant_set(pkg.name, name)))
self.rule(
fn.variant_default_value(pkg.name, name, val),
fn.node(pkg.name))
self.out.write('\n')
# dependencies
for name, conditions in pkg.dependencies.items():
@ -231,7 +234,7 @@ def spec_rules(self, spec):
# variants
for vname, variant in spec.variants.items():
self.fact(fn.variant_value(spec.name, vname, variant.value))
self.fact(fn.variant_set(spec.name, vname, variant.value))
# TODO
# dependencies
@ -265,9 +268,10 @@ def generate_asp_program(self, specs):
self.title('Spec Constraints')
for spec in specs:
self.section('Spec: %s' % pkg)
self.spec_rules(spec)
self.out.write('\n')
for dep in spec.traverse():
self.section('Spec: %s' % str(dep))
self.spec_rules(dep)
self.out.write('\n')
self.out.write(pkgutil.get_data('spack.solver', 'display.lp'))
self.out.write('\n')

View File

@ -25,6 +25,13 @@ arch_target(D, A) :- node(D), depends_on(P, D), arch_target(P, A).
% if a variant is set to anything, it is considered 'set'.
variant_set(P, V) :- variant_set(P, V, _).
% suppress wranings about this atom being unset. It's only set if some
% spec or some package sets it, and without this, clingo will give
% warnings like 'info: atom does not occur in any rule head'.
#defined variant_set/3.
% variant_set is an explicitly set variant value. If it's not 'set',
% we revert to the default value. If it is set, we force the set value
variant_value(P, V, X) :- node(P), variant(P, V), variant_set(P, V, X).
variant_value(P, V, X) :- node(P), variant(P, V), not variant_set(P, V),
variant_default_value(P, V, X).