Skip to content

PARFOR pointer writeback updates parent environment. #151

@python-processing-unit

Description

@python-processing-unit

According to the specification section 3.5:

PARFOR(counter, target){ ... } MUST evaluate target once, require an INT, then execute the iterations 1..target concurrently. The interpreter MUST wait for all iterations to finish before continuing. The loop counter is iteration-local and does not persist afterward, while other symbols declared in iteration bodies are merged back into the enclosing environment. Concurrent writes to shared identifiers are therefore race-prone, and the resulting value is implementation-defined.

In the implementation, however, pointer writeback performed by builtins (e.g. ADD(@runs, 0d1)) calls env_assign on the per-iteration environment. Because the per-iteration env inherits the parent binding for runs, env_assign resolves to and updates the parent binding immediately. As a result, PARFOR iterations directly mutate outer bindings instead of keeping iteration-local writes or merging declared-in-body symbols as intended. This causes the test parfor-zero-and-restore-counter.pre to fail (outer runs becomes non-zero).

Metadata

Metadata

Labels

bugSomething isn't workingpatchRequires a patch version change.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions