Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warning for when an "arbitrary" rule is chosen? #160

Open
maowtm opened this issue Mar 5, 2022 · 3 comments
Open

Warning for when an "arbitrary" rule is chosen? #160

maowtm opened this issue Mar 5, 2022 · 3 comments

Comments

@maowtm
Copy link
Collaborator

maowtm commented Mar 5, 2022

Just spent 3 hour on a simple mistake caused by an accidentally unbounded variable.

@thevirtuoso1973
Copy link
Collaborator

Can you elaborate on this?

@maowtm
Copy link
Collaborator Author

maowtm commented Mar 5, 2022

Basically I had a config predicate that defined some config corresponding to variants, like:

config("default", "make all").
config("32bit", "make 32bit").

etc...

And I use it like this:

redis(version, variant) :-
  ...
  config(variant, make_cmd),
  ...
  run(make_cmd).

However, there was a special case for when variant = "alpine", so I copy-pasted the definition for redis and added this:

redis(version, "alpine") :-
  ...
  config(variant, make_cmd),
  ...
  run(make_cmd).

I thought it would be alright to just replace the "variant" variable with "alpine", and I thought I have replaced all the "variant" variable, but it turns out I forgot to replace the "variant" in the config line, so the result is that it arbitrarily chose a make_cmd, and because it is quite deep inside a merge I did not notice that, so was wondering why things won't compile...

@maowtm
Copy link
Collaborator Author

maowtm commented Mar 5, 2022

I was thinking about a warning when there are multiple valid choices for a predicate. This would also prevent mistake like

foo(bar) :- (bar = "1"; bar = "2"), do_things_specific_for_1_and_2.
foo(bar) :- bar != "1", do_things_for_anything_else. # did not cover the case where bar = "2".

When we add some kind of cost-based selection later maybe we could limit this warning to just logic predicates...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants