Skip to content

Commit 2d29e04

Browse files
committed
fixup! feat(core.utils): _option_is_set mirrors compiler gates precisely
1 parent 65ae457 commit 2d29e04

File tree

2 files changed

+29
-7
lines changed

2 files changed

+29
-7
lines changed

cuda_core/cuda/core/utils/_program_cache.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,31 @@ def _cuda_core_version() -> str:
303303
_SIDE_EFFECT_OPTIONS = ("create_pch", "time", "fdevice_time_trace")
304304

305305

306+
# ProgramOptions fields gated by plain truthiness in ``_program.pyx`` (the
307+
# compiler writes the flag only when the value is truthy). For every other
308+
# field listed in the cache-guard sets, the compiler uses ``is not None``,
309+
# so even ``False`` / ``""`` must count as set.
310+
_BOOLEAN_OPTION_FIELDS = frozenset({"pch"})
311+
312+
306313
def _option_is_set(options: ProgramOptions, name: str) -> bool:
307314
"""Match how ``_program.pyx`` gates option emission.
308315
309-
The compiler checks ``is not None`` for path-like fields (so an empty
310-
string ``""`` is still emitted as a real ``--use-pch=`` flag) but an
311-
empty list/tuple in ``include_path``/``pre_include`` means "no extra
312-
includes". Mirror that here so the cache-key guard neither misses a
313-
real option (``create_pch=""``) nor fires on a harmless one
314-
(``include_path=[]``).
316+
- For boolean flags (``pch``): value must be truthy.
317+
- For sequence-shaped fields (``include_path``, ``pre_include``): ``None``
318+
or an empty ``list``/``tuple`` counts as absent; any other value
319+
(including the empty string, which NVRTC still emits as ``--flag=``)
320+
is set.
321+
- For path/string-shaped fields (``create_pch``, ``time``,
322+
``fdevice_time_trace``, ``use_pch``, ``pch_dir``): ``is not None`` --
323+
the compiler emits ``--flag=<value>`` for any non-None value, so
324+
``False``/``""``/``0`` must still count as set.
315325
"""
316326
value = getattr(options, name, None)
317-
if value is None or value is False:
327+
if value is None:
318328
return False
329+
if name in _BOOLEAN_OPTION_FIELDS:
330+
return bool(value)
319331
return not (isinstance(value, (list, tuple)) and len(value) == 0)
320332

321333

cuda_core/tests/test_program_cache.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,11 @@ def _flaky_replace(src, dst):
437437
pytest.param({"use_pch": ""}, id="use_pch_empty_string"),
438438
pytest.param({"pch_dir": ""}, id="pch_dir_empty_string"),
439439
pytest.param({"pre_include": ""}, id="pre_include_empty_string"),
440+
# Same for ``False`` -- NVRTC's gate on these path-shaped fields is
441+
# ``is not None``, so even False emits a real flag.
442+
pytest.param({"use_pch": False}, id="use_pch_false"),
443+
pytest.param({"pch_dir": False}, id="pch_dir_false"),
444+
pytest.param({"pre_include": False}, id="pre_include_false"),
440445
],
441446
)
442447
def test_make_program_cache_key_rejects_external_content_without_extra_digest(option_kw):
@@ -516,8 +521,13 @@ def test_make_program_cache_key_accepts_external_content_with_extra_digest():
516521
# compilation, so the side effect (writing the PCH) would not run.
517522
pytest.param({"create_pch": "out.pch"}, b"x" * 32, id="create_pch_with_extra_digest"),
518523
pytest.param({"create_pch": ""}, None, id="create_pch_empty_string"),
524+
# NVRTC emits ``--create-pch=False`` for any non-None value, so False
525+
# still triggers the side effect and must be rejected.
526+
pytest.param({"create_pch": False}, None, id="create_pch_false"),
519527
pytest.param({"time": "timing.csv"}, None, id="time"),
528+
pytest.param({"time": False}, None, id="time_false"),
520529
pytest.param({"fdevice_time_trace": "trace.json"}, None, id="fdevice_time_trace"),
530+
pytest.param({"fdevice_time_trace": False}, None, id="fdevice_time_trace_false"),
521531
],
522532
)
523533
def test_make_program_cache_key_rejects_side_effect_options_nvrtc(option_kw, extra_digest):

0 commit comments

Comments
 (0)