Skip to content

concretizer: refactor handling of special variants dev_build: and patches#20259

Merged
tgamblin merged 2 commits intodevelopfrom
refactor/new-concretizer-special-specs
Dec 8, 2020
Merged

concretizer: refactor handling of special variants dev_build: and patches#20259
tgamblin merged 2 commits intodevelopfrom
refactor/new-concretizer-special-specs

Conversation

@tgamblin
Copy link
Copy Markdown
Member

@tgamblin tgamblin commented Dec 6, 2020

Refactoring a few things in anticipation of adding reuse of installed dependencies.

Other parts of the concretizer code build up lists of things we can't know without traversing all specs and packages, and they output these list at the very end.

The code for this for variant values from spec literals was intertwined with the code for traversing the input specs. This only covers the input specs and misses variant values that might come from directives in packages.

  • move ad-hoc value handling code into spec_clauses so we do it in one place for CLI and packages
  • move handling of variant_possible_value, etc. into concretize.lp, where we can automatically infer variant existence
    more concisely.
  • simplify/clarify some of the code for variants in spec_clauses()

@tgamblin tgamblin requested a review from alalazo December 6, 2020 18:55
@tgamblin tgamblin changed the title concretizer: refactor handling of special variants dev_build and patches concretizer: refactor handling of special variants dev_build: and patches Dec 6, 2020
@tgamblin
Copy link
Copy Markdown
Member Author

tgamblin commented Dec 6, 2020

@alalazo not sure I understand why the tests are failing here -- if I run

SPACK_TEST_SOLVER=clingo spack unit-test

this passes locally. Is there something I am missing?

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Dec 7, 2020

@tgamblin I'll have a look at this first thing today

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Dec 7, 2020

Confirmed. It passes locally also for me. It's very weird, as tests start failing in architecture.py. I'll try to reproduce locally in the same container image we use to run test, if it goes I'll restart the tests.

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Dec 7, 2020

I can reproduce it consistently in the container, using the merge commit from this branch. If I use either the head of this branch or the head of develop then there are no failures.

EDIT: I have been able to reproduce it locally. The issue is with the merge commit:

$ git fetch origin refs/pull/20259/merge:test-branch

Keep digging...

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Dec 7, 2020

I'm trying to understand what is going on, but in the merge commit all the failing tests reach out to the builtin repo instead of the builtin.mock.

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Dec 7, 2020

It seems this PR and #20247 interact in a way that exposes a bug in our test setup. Facts:

  1. concretizer: each external version is allowed by definition #20247 introduced in our mock packages.yaml a new external, which is the only one containing a variant.
  2. This PR adds a code path that implicitly look up packages mentioned in packages.yaml earlier than was done before
  3. Some tests use mock_config but not the mock_repo, and they fail on the check at 2

@aweits
Copy link
Copy Markdown
Contributor

aweits commented Dec 7, 2020

seems more elegant than #20102, but there's another place where a new variant value can come into existence - something like this, perhaps:

diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
index a4dc98a3abbd..57476173bc26 100644
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -1092,6 +1092,7 @@ def preferred_variants(self, pkg_name):
         if not preferred_variants:
             return
 
+        spec = spack.spec.Spec(pkg_name)
         for variant_name in sorted(preferred_variants):
             variant = preferred_variants[variant_name]
             values = variant.value
@@ -1100,6 +1101,13 @@ def preferred_variants(self, pkg_name):
                 values = (values,)
 
             for value in values:
+                pkg_variant = spec.package_class.variants[variant_name]
+                variant = pkg_variant.make_variant(value)
+                spec.variants[variant_name] = variant
+                self.validate_variant_value(spec, variant.name, value)
+                self.variant_values_from_specs.add(
+                    (pkg_name, variant.name, value)
+                )
                 self.gen.fact(fn.variant_default_value_from_packages_yaml(
                     pkg_name, variant.name, value
                 ))

[edit: possibly a few more places as well, still looking]

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Dec 7, 2020

@tgamblin A minimal fix for this failure is:

diff --git a/lib/spack/spack/solver/asp.py b/lib/spack/spack/solver/asp.py
index 4533021209..189ce0726c 100644
--- a/lib/spack/spack/solver/asp.py
+++ b/lib/spack/spack/solver/asp.py
@@ -1028,6 +1028,10 @@ def external_packages(self):
             if pkg_name == 'all':
                 continue
 
+            # This package does not appear in any repository
+            if pkg_name not in spack.repo.path:
+                continue
+
             if 'externals' not in data:
                 self.gen.fact(fn.external(pkg_name).symbol(positive=False))
 
diff --git a/lib/spack/spack/util/mock_package.py b/lib/spack/spack/util/mock_package.py
index 4751f5af7e..66c6feb068 100644
--- a/lib/spack/spack/util/mock_package.py
+++ b/lib/spack/spack/util/mock_package.py
@@ -168,3 +168,6 @@ class MockPackage(MockPackageBase):
         self.spec_to_pkg["mockrepo." + name] = mock_package
 
         return mock_package
+
+    def __contains__(self, item):
+        return item in self.spec_to_pkg

Notes:

  1. Maybe it's worth emitting a debug print if we have a package in packages.yaml that does not appear in any repository
  2. We may follow this PR witn another one that factors the tests better, so that packages.yaml is hooked in only for unit tests that actually use the mock repository

@alalazo
Copy link
Copy Markdown
Member

alalazo commented Dec 7, 2020

@aweits @tgamblin Would it be fine with you to:

  1. Merge this refactor first
  2. Then rebase and merge concretizer: try hard to obtain all needed variant_possible_value()'s #20102 quickly after 1

?

@aweits
Copy link
Copy Markdown
Contributor

aweits commented Dec 7, 2020

@aweits @tgamblin Would it be fine with you to:

1. Merge this refactor first

2. Then rebase and merge #20102 quickly after 1

I'm fine with that, #20102 will probably need changes beyond a rebase as this obviates most of that functionality.

alalazo
alalazo previously requested changes Dec 7, 2020
Copy link
Copy Markdown
Member

@alalazo alalazo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. The only modification necessary is a couple of lines posted in the diff above to skip validating external packages that are not found in any repository

@tgamblin tgamblin force-pushed the refactor/new-concretizer-special-specs branch from 5d05642 to 2d61848 Compare December 7, 2020 22:47
tgamblin and others added 2 commits December 7, 2020 15:31
Other parts of the concretizer code build up lists of things we can't
know without traversing all specs and packages, and they output these
list at the very end.

The code for this for variant values from spec literals was intertwined
with the code for traversing the input specs. This only covers the input
specs and misses variant values that might come from directives in
packages.

- [x] move ad-hoc value handling code into spec_clauses so we do it in
  one place for CLI and packages

- [x] move handling of `variant_possible_value`, etc. into
  `concretize.lp`, where we can automatically infer variant existence
  more concisely.

- [x] simplify/clarify some of the code for variants in `spec_clauses()`
@tgamblin tgamblin force-pushed the refactor/new-concretizer-special-specs branch from 2d61848 to 1bebfb5 Compare December 7, 2020 23:31
@tgamblin tgamblin merged commit 98c2627 into develop Dec 8, 2020
@tgamblin tgamblin deleted the refactor/new-concretizer-special-specs branch December 8, 2020 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants