concretizer: simplify and move architecture semantics into concretize.lp

- Model architecture default settings and propagation off of variants

- Leverage ASP default logic to set architecture to default if it's not
  set otherwise.

- Move logic out of Python and into concretize.lp as first-order rules.
This commit is contained in:
Todd Gamblin 2019-08-10 20:45:09 -07:00
parent 34ea3d20cf
commit f7dce19754
2 changed files with 41 additions and 15 deletions

View file

@ -226,18 +226,14 @@ def spec_rules(self, spec):
# seed architecture at the root (we'll propagate later) # seed architecture at the root (we'll propagate later)
# TODO: use better semantics. # TODO: use better semantics.
arch = spack.spec.ArchSpec(spack.architecture.sys_type()) arch = spec.architecture
spec_arch = spec.architecture if arch:
if spec_arch: if arch.platform:
if spec_arch.platform: self.fact(fn.arch_platform_set(spec.name, arch.platform))
arch.platform = spec_arch.platform if arch.os:
if spec_arch.os: self.fact(fn.arch_os_set(spec.name, arch.os))
arch.os = spec_arch.os if arch.target:
if spec_arch.target: self.fact(fn.arch_target_set(spec.name, arch.target))
arch.target = spec_arch.target
self.fact(fn.arch_platform(spec.name, arch.platform))
self.fact(fn.arch_os(spec.name, arch.os))
self.fact(fn.arch_target(spec.name, arch.target))
# variants # variants
for vname, variant in spec.variants.items(): for vname, variant in spec.variants.items():
@ -268,6 +264,14 @@ def generate_asp_program(self, specs):
concretize_lp = pkgutil.get_data('spack.solver', 'concretize.lp') concretize_lp = pkgutil.get_data('spack.solver', 'concretize.lp')
self.out.write(concretize_lp.decode("utf-8")) self.out.write(concretize_lp.decode("utf-8"))
self.h1('General Constraints')
self.h2('Default architecture')
default_arch = spack.spec.ArchSpec(spack.architecture.sys_type())
self.fact(fn.arch_platform_default(default_arch.platform))
self.fact(fn.arch_os_default(default_arch.os))
self.fact(fn.arch_target_default(default_arch.target))
self.h1('Package Constraints') self.h1('Package Constraints')
for pkg in pkgs: for pkg in pkgs:
self.h2('Package: %s' % pkg) self.h2('Package: %s' % pkg)

View file

@ -39,7 +39,29 @@ variant_value(P, V, X) :- node(P), variant(P, V), not variant_set(P, V),
% Architecture semantics % Architecture semantics
%----------------------------------------------------------------------------- %-----------------------------------------------------------------------------
% arch fields for pkg P are set if set to anything
arch_platform_set(P) :- arch_platform_set(P, _).
arch_os_set(P) :- arch_os_set(P, _).
arch_target_set(P) :- arch_target_set(P, _).
% avoid info warnings (see variants)
#defined arch_platform_set/2.
#defined arch_os_set/2.
#defined arch_target_set/2.
% if architecture value is set, it's the value
arch_platform(P, A) :- node(P), arch_platform_set(P, A).
arch_os(P, A) :- node(P), arch_os_set(P, A).
arch_target(P, A) :- node(P), arch_target_set(P, A).
% if no architecture is set, fall back to the default architecture value.
arch_platform(P, A) :- node(P), not arch_platform_set(P),
arch_platform_default(A).
arch_os(P, A) :- node(P), not arch_os_set(P), arch_os_default(A).
arch_target(P, A) :- node(P), not arch_target_set(P), arch_target_default(A).
% propagate platform, os, target downwards % propagate platform, os, target downwards
arch_platform(D, A) :- node(D), depends_on(P, D), arch_platform(P, A). % TODO: handle multiple dependents and arch compatibility
arch_os(D, A) :- node(D), depends_on(P, D), arch_os(P, A). arch_platform_set(D, A) :- node(D), depends_on(P, D), arch_platform_set(P, A).
arch_target(D, A) :- node(D), depends_on(P, D), arch_target(P, A). arch_os_set(D, A) :- node(D), depends_on(P, D), arch_os_set(P, A).
arch_target_set(D, A) :- node(D), depends_on(P, D), arch_target_set(P, A).