cp0 may introduce uninitialized references when lifting letrec RHS bindings

Open
#1,111 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
30/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Domain
compilers

Research direction

Start by building Chez and running the #!chezscheme reproducer in the issue, comparing the two schedules (full run-cp0 versus opt (#%$cp0 tree)) to confirm the vector/void divergence. Then read the cp0-rec-let handling together with split-value to see where an eager let binding is lifted out of a letrec right-hand side and merged into the enclosing nonsequential letrec; the fix must preserve the original initialization order. Done means the reproducer yields the same result for both schedules and the cp0 mat tests still pass.

Written by the indexing model from the issue text.

Description

cp0 may incorrectly lift an eager binding from a letrec RHS and merge it into the enclosing nonsequential letrec.

For example, a transformation resembling:

(letrec ([x (let ([a E]) (f a))]) body)

into:

(letrec ([a E] [x (f a)]) body)

introduces an initialization dependency that was not present in the original program. The reference to a in the RHS of x is now potentially uninitialized.

The issue appears to involve split-value and the merging of lifted bindings in cp0-rec-let.

eg.

#!chezscheme
(import (chezscheme))

(define src
  '(lambda (u v)
     (letrec ([x (let ([a (vector (lambda () x))])
                   (if (eq? a u) (eq? a v) a))])
        x)))
(define (check schedule)
  (parameterize ([optimize-level 2] [run-cp0 schedule])
    (let ([result ((compile src (environment '(chezscheme))) #f #f)])
      (cond [(vector? result) 'vector] [(eq? result (void)) 'void] [else result]))))
(write (list (check (run-cp0)) (check (lambda (opt tree) (opt (#%$cp0 tree))))))
Dominant language
Scheme
Stars
7.4k
Forks
1k
Avg merge
1d 20h
Merged PRs (30d)
19

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

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 cisco/ChezScheme

All issues in cisco/ChezScheme

Similar issues

More Compilers issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.