Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/make/unit-tests make(1): document how short-circuit ...



details:   https://anonhg.NetBSD.org/src/rev/1cb1cea081f4
branches:  trunk
changeset: 957499:1cb1cea081f4
user:      rillig <rillig%NetBSD.org@localhost>
date:      Mon Nov 30 18:20:20 2020 +0000

description:
make(1): document how short-circuit evaluation behaved on 2020-07-03

diffstat:

 usr.bin/make/unit-tests/cond-short.mk |  45 ++++++++++++++++++++++++++++-------
 1 files changed, 36 insertions(+), 9 deletions(-)

diffs (80 lines):

diff -r 9b8fdf3ee85e -r 1cb1cea081f4 usr.bin/make/unit-tests/cond-short.mk
--- a/usr.bin/make/unit-tests/cond-short.mk     Mon Nov 30 17:06:02 2020 +0000
+++ b/usr.bin/make/unit-tests/cond-short.mk     Mon Nov 30 18:20:20 2020 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: cond-short.mk,v 1.12 2020/11/15 14:58:14 rillig Exp $
+# $NetBSD: cond-short.mk,v 1.13 2020/11/30 18:20:20 rillig Exp $
 #
 # Demonstrates that in conditions, the right-hand side of an && or ||
 # is only evaluated if it can actually influence the result.
@@ -6,9 +6,13 @@
 # mode in most programming languages.  A notable exception is Ada, which
 # distinguishes between the operators 'And', 'And Then', 'Or', 'Or Else'.
 #
-# Between 2015-10-11 and 2020-06-28, the right-hand side of an && or ||
-# operator was always evaluated, which was wrong.
-# TODO: Had the evaluation been correct at some time before 2015-11-12?
+# Before 2020-06-28, the right-hand side of an && or || operator was always
+# evaluated, which was wrong.  In cond.c 1.69 and var.c 1.197 on 2015-10-11,
+# Var_Parse got a new parameter named 'wantit'.  Since then it would have been
+# possible to skip evaluation of irrelevant variable expressions and only
+# parse them.  They were still evaluated though, the only difference to
+# relevant variable expressions was that in the irrelevant variable
+# expressions, undefined variables were allowed.
 
 # The && operator.
 
@@ -130,18 +134,29 @@
 .endif
 x!=    echo 'defined(V42) && ${V42} > 0: $x' >&2; echo
 
-# this one throws both String comparison operator and
-# Malformed conditional with cond.c 1.78
-# indirect iV2 would expand to "" and treated as 0
+# With cond.c 1.76 from 2020-07-03, the following condition triggered a
+# warning: "String comparison operator should be either == or !=".
+# This was because the variable expression ${iV2} was defined, but the
+# contained variable V66 was undefined.  The left-hand side of the comparison
+# therefore evaluated to the string "${V66}", which is obviously not a number.
+#
+# This was fixed in cond.c 1.79 from 2020-07-09 by not evaluating irrelevant
+# comparisons.  Instead, they are only parsed and then discarded.
+#
+# At that time, there was not enough debug logging to see the details in the
+# -dA log.  To actually see it, add debug logging at the beginning and end of
+# Var_Parse.
 .if defined(V66) && ( ${iV2} < ${V42} )
 x=     Fail
 .else
 x=     Ok
 .endif
+# XXX: This condition doesn't match the one above. The quotes are missing
+# above.  This is a crucial detail since without quotes, the variable
+# expression ${iV2} evaluates to "${V66}", and with quotes, it evaluates to ""
+# since undefined variables are allowed and expand to an empty string.
 x!=    echo 'defined(V66) && ( "${iV2}" < ${V42} ): $x' >&2; echo
 
-# next two thow String comparison operator with cond.c 1.78
-# indirect iV1 would expand to 42
 .if 1 || ${iV1} < ${V42}
 x=     Ok
 .else
@@ -149,6 +164,18 @@
 .endif
 x!=    echo '1 || ${iV1} < ${V42}: $x' >&2; echo
 
+# With cond.c 1.76 from 2020-07-03, the following condition triggered a
+# warning: "String comparison operator should be either == or !=".
+# This was because the variable expression ${iV2} was defined, but the
+# contained variable V66 was undefined.  The left-hand side of the comparison
+# therefore evaluated to the string "${V66}", which is obviously not a number.
+#
+# This was fixed in cond.c 1.79 from 2020-07-09 by not evaluating irrelevant
+# comparisons.  Instead, they are only parsed and then discarded.
+#
+# At that time, there was not enough debug logging to see the details in the
+# -dA log.  To actually see it, add debug logging at the beginning and end of
+# Var_Parse.
 .if 1 || ${iV2:U2} < ${V42}
 x=     Ok
 .else



Home | Main Index | Thread Index | Old Index