msv-lab / modus

A language for building Docker/OCI container images
GNU Affero General Public License v3.0
279 stars 9 forks source link

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

Open maowtm opened 2 years ago

maowtm commented 2 years ago

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

thevirtuoso1973 commented 2 years ago

Can you elaborate on this?

maowtm commented 2 years ago

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 commented 2 years ago

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...