Skip to content

Commit ffa559b

Browse files
committed
"truth" -> "truthiness"
1 parent c8214c9 commit ffa559b

File tree

6 files changed

+47
-47
lines changed

6 files changed

+47
-47
lines changed

Include/internal/pycore_optimizer.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ typedef enum _JitSymType {
172172
JIT_SYM_KNOWN_CLASS_TAG = 6,
173173
JIT_SYM_KNOWN_VALUE_TAG = 7,
174174
JIT_SYM_TUPLE_TAG = 8,
175-
JIT_SYM_TRUTH_TAG = 9,
175+
JIT_SYM_TRUTHINESS_TAG = 9,
176176
} JitSymType;
177177

178178
typedef struct _jit_opt_known_class {
@@ -203,15 +203,15 @@ typedef struct {
203203
uint8_t tag;
204204
bool not;
205205
uint16_t value;
206-
} JitOptTruth;
206+
} JitOptTruthiness;
207207

208208
typedef union _jit_opt_symbol {
209209
uint8_t tag;
210210
JitOptKnownClass cls;
211211
JitOptKnownValue value;
212212
JitOptKnownVersion version;
213213
JitOptTuple tuple;
214-
JitOptTruth truth;
214+
JitOptTruthiness truthiness;
215215
} JitOptSymbol;
216216

217217

@@ -276,7 +276,7 @@ extern bool _Py_uop_sym_is_immortal(JitOptSymbol *sym);
276276
extern JitOptSymbol *_Py_uop_sym_new_tuple(JitOptContext *ctx, int size, JitOptSymbol **args);
277277
extern JitOptSymbol *_Py_uop_sym_tuple_getitem(JitOptContext *ctx, JitOptSymbol *sym, int item);
278278
extern int _Py_uop_sym_tuple_length(JitOptSymbol *sym);
279-
extern JitOptSymbol *_Py_uop_sym_new_truth(JitOptContext *ctx, JitOptSymbol *value, bool not);
279+
extern JitOptSymbol *_Py_uop_sym_new_truthiness(JitOptContext *ctx, JitOptSymbol *value, bool not);
280280

281281
extern void _Py_uop_abstractcontext_init(JitOptContext *ctx);
282282
extern void _Py_uop_abstractcontext_fini(JitOptContext *ctx);
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
Improve the experimental JIT's ability to narrow boolean values based on the
2-
results of truth tests.
2+
results of truthiness tests.

Python/optimizer_analysis.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ remove_globals(_PyInterpreterFrame *frame, _PyUOpInstruction *buffer,
376376
#define sym_tuple_getitem _Py_uop_sym_tuple_getitem
377377
#define sym_tuple_length _Py_uop_sym_tuple_length
378378
#define sym_is_immortal _Py_uop_sym_is_immortal
379-
#define sym_new_truth _Py_uop_sym_new_truth
379+
#define sym_new_truthiness _Py_uop_sym_new_truthiness
380380

381381
static int
382382
optimize_to_bool(

Python/optimizer_bytecodes.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ typedef struct _Py_UOpsAbstractFrame _Py_UOpsAbstractFrame;
3434
#define sym_tuple_getitem _Py_uop_sym_tuple_getitem
3535
#define sym_tuple_length _Py_uop_sym_tuple_length
3636
#define sym_is_immortal _Py_uop_sym_is_immortal
37-
#define sym_new_truth _Py_uop_sym_new_truth
37+
#define sym_new_truthiness _Py_uop_sym_new_truthiness
3838

3939
extern int
4040
optimize_to_bool(
@@ -392,14 +392,14 @@ dummy_func(void) {
392392

393393
op(_TO_BOOL, (value -- res)) {
394394
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
395-
res = sym_new_truth(ctx, value, false);
395+
res = sym_new_truthiness(ctx, value, false);
396396
}
397397
}
398398

399399
op(_TO_BOOL_BOOL, (value -- res)) {
400400
if (!optimize_to_bool(this_instr, ctx, value, &res)) {
401401
sym_set_type(value, &PyBool_Type);
402-
res = sym_new_truth(ctx, value, false);
402+
res = sym_new_truthiness(ctx, value, false);
403403
}
404404
}
405405

@@ -433,7 +433,7 @@ dummy_func(void) {
433433

434434
op(_UNARY_NOT, (value -- res)) {
435435
sym_set_type(value, &PyBool_Type);
436-
res = sym_new_truth(ctx, value, true);
436+
res = sym_new_truthiness(ctx, value, true);
437437
}
438438

439439
op(_COMPARE_OP, (left, right -- res)) {

Python/optimizer_cases.c.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Python/optimizer_symbols.c

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,13 @@ _Py_uop_sym_is_const(JitOptContext *ctx, JitOptSymbol *sym)
107107
if (sym->tag == JIT_SYM_KNOWN_VALUE_TAG) {
108108
return true;
109109
}
110-
if (sym->tag == JIT_SYM_TRUTH_TAG) {
111-
JitOptSymbol *value = allocation_base(ctx) + sym->truth.value;
112-
int truth = _Py_uop_sym_truthiness(ctx, value);
113-
if (truth < 0) {
110+
if (sym->tag == JIT_SYM_TRUTHINESS_TAG) {
111+
JitOptSymbol *value = allocation_base(ctx) + sym->truthiness.value;
112+
int truthiness = _Py_uop_sym_truthiness(ctx, value);
113+
if (truthiness < 0) {
114114
return false;
115115
}
116-
make_const(sym, (truth ^ sym->truth.not) ? Py_True : Py_False);
116+
make_const(sym, (truthiness ^ sym->truthiness.not) ? Py_True : Py_False);
117117
return true;
118118
}
119119
return false;
@@ -132,13 +132,13 @@ _Py_uop_sym_get_const(JitOptContext *ctx, JitOptSymbol *sym)
132132
if (sym->tag == JIT_SYM_KNOWN_VALUE_TAG) {
133133
return sym->value.value;
134134
}
135-
if (sym->tag == JIT_SYM_TRUTH_TAG) {
136-
JitOptSymbol *value = allocation_base(ctx) + sym->truth.value;
137-
int truth = _Py_uop_sym_truthiness(ctx, value);
138-
if (truth < 0) {
135+
if (sym->tag == JIT_SYM_TRUTHINESS_TAG) {
136+
JitOptSymbol *value = allocation_base(ctx) + sym->truthiness.value;
137+
int truthiness = _Py_uop_sym_truthiness(ctx, value);
138+
if (truthiness < 0) {
139139
return NULL;
140140
}
141-
PyObject *res = (truth ^ sym->truth.not) ? Py_True : Py_False;
141+
PyObject *res = (truthiness ^ sym->truthiness.not) ? Py_True : Py_False;
142142
make_const(sym, res);
143143
return res;
144144
}
@@ -187,7 +187,7 @@ _Py_uop_sym_set_type(JitOptContext *ctx, JitOptSymbol *sym, PyTypeObject *typ)
187187
sym->cls.version = 0;
188188
sym->cls.type = typ;
189189
return;
190-
case JIT_SYM_TRUTH_TAG:
190+
case JIT_SYM_TRUTHINESS_TAG:
191191
if (typ != &PyBool_Type) {
192192
sym_set_bottom(ctx, sym);
193193
}
@@ -232,7 +232,7 @@ _Py_uop_sym_set_type_version(JitOptContext *ctx, JitOptSymbol *sym, unsigned int
232232
sym->tag = JIT_SYM_TYPE_VERSION_TAG;
233233
sym->version.version = version;
234234
return true;
235-
case JIT_SYM_TRUTH_TAG:
235+
case JIT_SYM_TRUTHINESS_TAG:
236236
if (version != PyBool_Type.tp_version_tag) {
237237
sym_set_bottom(ctx, sym);
238238
return false;
@@ -279,17 +279,17 @@ _Py_uop_sym_set_const(JitOptContext *ctx, JitOptSymbol *sym, PyObject *const_val
279279
case JIT_SYM_UNKNOWN_TAG:
280280
make_const(sym, const_val);
281281
return;
282-
case JIT_SYM_TRUTH_TAG:
282+
case JIT_SYM_TRUTHINESS_TAG:
283283
if (!PyBool_Check(const_val) ||
284284
(_Py_uop_sym_is_const(ctx, sym) &&
285285
_Py_uop_sym_get_const(ctx, sym) != const_val))
286286
{
287287
sym_set_bottom(ctx, sym);
288288
return;
289289
}
290-
JitOptSymbol *value = allocation_base(ctx) + sym->truth.value;
290+
JitOptSymbol *value = allocation_base(ctx) + sym->truthiness.value;
291291
PyTypeObject *type = _Py_uop_sym_get_type(value);
292-
if (const_val == (sym->truth.not ? Py_False : Py_True)) {
292+
if (const_val == (sym->truthiness.not ? Py_False : Py_True)) {
293293
// value is truthy. This is only useful for bool:
294294
if (type == &PyBool_Type) {
295295
_Py_uop_sym_set_const(ctx, value, Py_True);
@@ -401,7 +401,7 @@ _Py_uop_sym_get_type(JitOptSymbol *sym)
401401
return Py_TYPE(sym->value.value);
402402
case JIT_SYM_TUPLE_TAG:
403403
return &PyTuple_Type;
404-
case JIT_SYM_TRUTH_TAG:
404+
case JIT_SYM_TRUTHINESS_TAG:
405405
return &PyBool_Type;
406406
}
407407
Py_UNREACHABLE();
@@ -425,7 +425,7 @@ _Py_uop_sym_get_type_version(JitOptSymbol *sym)
425425
return Py_TYPE(sym->value.value)->tp_version_tag;
426426
case JIT_SYM_TUPLE_TAG:
427427
return PyTuple_Type.tp_version_tag;
428-
case JIT_SYM_TRUTH_TAG:
428+
case JIT_SYM_TRUTHINESS_TAG:
429429
return PyBool_Type.tp_version_tag;
430430
}
431431
Py_UNREACHABLE();
@@ -445,7 +445,7 @@ _Py_uop_sym_has_type(JitOptSymbol *sym)
445445
case JIT_SYM_KNOWN_CLASS_TAG:
446446
case JIT_SYM_KNOWN_VALUE_TAG:
447447
case JIT_SYM_TUPLE_TAG:
448-
case JIT_SYM_TRUTH_TAG:
448+
case JIT_SYM_TRUTHINESS_TAG:
449449
return true;
450450
}
451451
Py_UNREACHABLE();
@@ -483,16 +483,16 @@ _Py_uop_sym_truthiness(JitOptContext *ctx, JitOptSymbol *sym)
483483
break;
484484
case JIT_SYM_TUPLE_TAG:
485485
return sym->tuple.length != 0;
486-
case JIT_SYM_TRUTH_TAG:
486+
case JIT_SYM_TRUTHINESS_TAG:
487487
;
488-
JitOptSymbol *value = allocation_base(ctx) + sym->truth.value;
489-
int truth = _Py_uop_sym_truthiness(ctx, value);
490-
if (truth < 0) {
491-
return truth;
488+
JitOptSymbol *value = allocation_base(ctx) + sym->truthiness.value;
489+
int truthiness = _Py_uop_sym_truthiness(ctx, value);
490+
if (truthiness < 0) {
491+
return truthiness;
492492
}
493-
truth ^= sym->truth.not;
494-
make_const(sym, truth ? Py_True : Py_False);
495-
return truth;
493+
truthiness ^= sym->truthiness.not;
494+
make_const(sym, truthiness ? Py_True : Py_False);
495+
return truthiness;
496496
}
497497
PyObject *value = sym->value.value;
498498
/* Only handle a few known safe types */
@@ -578,23 +578,23 @@ _Py_uop_sym_is_immortal(JitOptSymbol *sym)
578578
}
579579

580580
JitOptSymbol *
581-
_Py_uop_sym_new_truth(JitOptContext *ctx, JitOptSymbol *value, bool not)
581+
_Py_uop_sym_new_truthiness(JitOptContext *ctx, JitOptSymbol *value, bool not)
582582
{
583-
if (value->tag == JIT_SYM_TRUTH_TAG && value->truth.not == not) {
583+
if (value->tag == JIT_SYM_TRUTHINESS_TAG && value->truthiness.not == not) {
584584
return value;
585585
}
586586
JitOptSymbol *res = sym_new(ctx);
587587
if (res == NULL) {
588588
return out_of_space(ctx);
589589
}
590-
int truth = _Py_uop_sym_truthiness(ctx, value);
591-
if (truth < 0) {
592-
res->tag = JIT_SYM_TRUTH_TAG;
593-
res->truth.not = not;
594-
res->truth.value = (uint16_t)(value - allocation_base(ctx));
590+
int truthiness = _Py_uop_sym_truthiness(ctx, value);
591+
if (truthiness < 0) {
592+
res->tag = JIT_SYM_TRUTHINESS_TAG;
593+
res->truthiness.not = not;
594+
res->truthiness.value = (uint16_t)(value - allocation_base(ctx));
595595
}
596596
else {
597-
make_const(res, (truth ^ not) ? Py_True : Py_False);
597+
make_const(res, (truthiness ^ not) ? Py_True : Py_False);
598598
}
599599
return res;
600600
}

0 commit comments

Comments
 (0)