ScalarToSymbolPromotion: replace the `0`-assignment fallback with guard-aware read/write analysis

Open
#2,745 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 2 days

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
42/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Active
Tech stack
python
Domain
compilers

Research direction

Read the #2712 branch analysis in dace/sdfg/state.py (lines 4333–4373) and the 0 fallback in dace/transformation/passes/scalar_to_symbol.py (lines 879–890). Use the repro and expected behavior in tests/passes/scalar_to_symbol_test.py (lines 902–944) to understand the case. Done when guarded reads are recognized so defined transients stay out of free_symbols, the fallback is removed, and genuinely unassigned reads still warn or remain free.

Written by the indexing model from the issue text.

Description

ScalarToSymbolPromotion: replace the 0-assignment fallback with guard-aware read/write analysis

Is your feature request related to a problem? Please describe.
A transient written and read under the same condition (e.g. if c: s = ... then if c and s > 1: ...) promotes to a free symbol since #2712. #2744 works around this by silently initializing such symbols to 0 in a new start block (scalar_to_symbol.py L879–L890), turning what used to be a loud "Missing program argument" into silent 0-based behavior.

Describe the solution you'd like
Make the #2712 branch analysis (state.py L4333–L4373) guard-aware: if every read of the promoted transient is guarded by a condition that implies the write's guard, treat it as defined and keep it out of free_symbols — then drop the 0 initialization. Genuinely unassigned reads should warn or stay free instead.

Describe alternatives you've considered
Keeping the 0 fallback but emitting a warning when it triggers; requiring the caller to pass the symbol (pre-#2744 behavior that broke working programs).

Additional context
Repro and expected behavior in the #2744 test (tests/passes/scalar_to_symbol_test.py L902–L944). Follow-up agreed in the #2744 review.

Dominant language
Python
Stars
602
Forks
171
Avg merge
1d 16h
Merged PRs (30d)
43

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from spcl/dace

All issues in spcl/dace

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.