Bug? `raise` may not fully implement the intended R6RS semantics

Open
#884 2 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
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Domain
backend

Research direction

Start by reading the R6RS exception and dynamic environment semantics cited in the issue, then trace how raise and with-exception-handler manage the handler stack and thread parameters. Reproduce the expression in Chez Scheme and inspect the relevant implementation and tests. Done means the outer handler observes p as outer when the non-continuable exception is raised.

Written by the indexing model from the issue text.

Description

The expression

(call/cc
    (lambda (k)
      (define p (make-thread-parameter 'outer))
      (define v #f)
      (with-exception-handler
          (lambda (obj)
            (if (non-continuable-violation? obj)
                (k (list v (p)))
                (raise-continuable obj)))
        (lambda ()
          (with-exception-handler
              (lambda (obj)
                (if (eqv? obj 42)
                    (set! v (p))
                    (raise-continuable obj)))
            (lambda ()
              (parameterize ((p 'inner))
                (raise 42))))))))

is evaluated to (inner inner) by Chez Scheme. The first "inner" comes from evaluating (p) in the inner exception handler that is invoked by (raise 42). This is correct by R6RS because the handler is called with the same dynamic environment (except for changes in the handler stack) as the call to raise. As the exception handler returns, raise now raises an exception with condition type &non-continuable. This is intercepted by the outer exception handler, which evaluates (p) again, this time producing the second "inner" in the case of Chez's implementation. However, by R6RS, the "non-continuable" exception should be raised in the dynamic environment of the (inner) handler where the value of the parameter p is outer.

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 Backend & API Design issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.