racket / racket/redex

define-extended-judgment-form should replace rules with same name

Open
#192 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Racket
Stars
112
Forks
42
PR merge metrics
No merged PRs in 30d

Description

I was surprised to discover that define-extended-judgment-form does not do something similar to extend-reduction-relation when an extension names a rule the same as the underlying relation, i.e. replace that rule with the new one.

Here is a concrete example:

#lang racket
(require redex/reduction-semantics)

(define-language A
  (v ::= integer))

(define-extended-language B A
  (v ::= .... boolean))

(define-judgment-form A
  #:mode (valA I)
  #:contract (valA v)
  [---- id
   (valA v)])

(define-extended-judgment-form B valA
  #:mode (valB I)
  #:contract (valB v)
  [---- id
   (valB boolean)])

(judgment-holds (valB 4))  ;; should produce #f, id rule replaced
(judgment-holds (valB #t)) ;; should produce #t

Being able to do this is critical when you want to extend "helper" judgments by replacing the original rule with a similar rule that use the helper for the extended language.

For example:

#lang racket
(require redex/reduction-semantics)

(define-language A
  (v ::= integer))

(define-extended-language B A
  (v ::= .... boolean))

(define-judgment-form A
  #:mode (valA I)
  #:contract (valA v)
  [(helpA v)
   ---- id
   (valA v)])

(define-judgment-form A
  #:mode (helpA I)
  #:contract (helpA v)
  [-----
   (helpA v)])

(define-extended-judgment-form B valA
  #:mode (valB I)
  #:contract (valB v)  
  [(helpB boolean)
    ---- id
   (valB boolean)])

;; reinterpret helpA over B
(define-extended-judgment-form B helpA
  #:mode (helpB I)
  #:contract (helpB v))

(judgment-holds (helpB #t)) ;; #t, as expected

;; should produce #t, results in a contract violation
;; because helpA is still being used
(judgment-holds (valB #t)) 

It's also conceptually confusing since using define-extended-judgment-form lets you create two distinct rules with the same name, which is not allowed when you to write out the same judgment form without using extension.

Contributor guide

No contributing guide indexed for this repository

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.

Research direction

Start by locating the implementation and tests for define-extended-judgment-form, then compare its rule-handling behavior with extend-reduction-relation and the judgment-holds examples in this issue. Done means an extended judgment rule with the same name replaces the inherited rule, including when the inherited judgment is reinterpreted for the extended language.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.