Skip to content

variant: allow for conditional booleans#32492

Closed
skosukhin wants to merge 1 commit intospack:developfrom
skosukhin:conditional_bool
Closed

variant: allow for conditional booleans#32492
skosukhin wants to merge 1 commit intospack:developfrom
skosukhin:conditional_bool

Conversation

@skosukhin
Copy link
Copy Markdown
Member

Currently, we have the following in the llvm package:

variant(
"z3", default=False, when="+clang @8:", description="Use Z3 for the clang static analyzer"
)

What it means is that we can't have llvm~clang+z3:

$ spack spec llvm~clang+z3
==> Error: Cannot set variant 'z3' for package 'llvm' because the variant condition cannot be satisfied for the given spec

Good. Now, what about llvm~clang~z3? As a user, I would expect it to be possible but it is not:

$ spack spec llvm~clang~z3
==> Error: Cannot set variant 'z3' for package 'llvm' because the variant condition cannot be satisfied for the given spec

With the modifications from this PR, it is possible to declare the z3 variant differently:

variant(
    "z3",
    values=(conditional(True, when="+clang @8:"), False),
    default=False,
    description="Use Z3 for the clang static analyzer",
)

And it looks like we can have the expected behaviour. We still get an error for llvm~clang+z3 (with a different message though):

$ spack spec llvm~clang+z3
==> Error: 'llvm' required multiple values for single-valued variant 'clang'
    Requested '~clang' and '+clang'

And we can also explicitly disable z3:

$ spack spec llvm~clang~z3
Input spec
--------------------------------
llvm~clang~z3

Concretized
--------------------------------
[email protected]%[email protected]~clang~cuda+gold~ipo~link_llvm_dylib+lld+llvm_dylib~mlir~omp_debug~omp_tsan+polly~python~split_dwarf~z3 build_type=Release patches=6379168,d85ef51,f920173 shlib_symbol_version=none targets=none version_suffix=none arch=linux-debian11-skylake
...

NOTE: The order of the values is important:

variant(..., values=(True, False), default=False,...)

seems to be the same as

variant(..., values=None, default=False,...)

but if we swap the order of values, i.e.

variant(..., values=(False, True), default=False,...)

we get:

$ spack spec llvm+z3
==> Error: invalid values for variant "z3" in package "llvm": ['True']
$ spack spec llvm~z3
==> Error: invalid values for variant "z3" in package "llvm": ['False']

The same problem is when values has a conditional as above, i.e.:

variant(..., values=(False, conditional(True, when="+clang @8:")), default=False,...)

It might be worth fixing too.

@alalazo

@spackbot-app spackbot-app bot added the core PR affects Spack core functionality label Sep 2, 2022
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.

The documentation on conditional variants says:

The variant directive accepts a when clause. The variant will only be present on specs that otherwise satisfy the spec listed as the when clause

so if spec.satisfies("~clang") the z3 variant doesn't exist. That explains the:

Now, what about llvm~clang ~z3? As a user, I would expect it to be possible [ ... ]

If a boolean variant can take a single value under certain conditions, I think it is more appropriate to either remove the variant like done in llvm (to not clutter the spec) or use conflicts.

@skosukhin
Copy link
Copy Markdown
Member Author

@alalazo thanks. I'm closing this then. I just noticed the trend to avoid conflicts whenever possible. However, the suggested modification hardly implies less work for the concretizer than just a simple conflict.

@skosukhin skosukhin closed this Sep 2, 2022
@skosukhin
Copy link
Copy Markdown
Member Author

@alalazo there is still something wrong, which annoyed me in the first place but I failed to describe it properly. I would expect the following two commands to produce similar error messages but that is not the case:

$ spack spec llvm~clang~z3
==> Error: Cannot set variant 'z3' for package 'llvm' because the variant condition cannot be satisfied for the given spec
$ spack spec llvm~clang~z3~lldb
==> Error: 'llvm' required multiple values for single-valued variant 'clang'
    Requested '~clang' and '+clang'

The second one is rather misleading. But that's another story, I guess.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core PR affects Spack core functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants