Opened 5 years ago

Last modified 5 years ago

#1635 new defect

Include multiple times in a row 'interrupts' definitions

Reported by: Diego Owned by:
Priority: minor Milestone: someday
Component: expander Version: 5.1.0
Keywords: Cc:
Estimated difficulty: hard

Description (last modified by sjamaan)

Given file include.scm:

(define (foo)
  (print that))

and a file "include2.scm" with arbitrary contents (including an empty file), the following code works (interpreted and compiled):

#!/usr/bin/csi -s
(define (main #!optional args)
  (include "include.scm")
  (define that "hey")
  (foo))

(main)

whereas this does not (interpreted or compiled):

#!/usr/bin/csi -s
(define (main #!optional args)
  (include "include.scm")
  (include "include2.scm")
  (define that "hey")
  (foo))

(main)

The latter throws an error about that being unbound.

Change History (3)

comment:1 Changed 5 years ago by Diego

there's a typo here - both of the last code snippets should be using csi -s on top

comment:2 Changed 5 years ago by sjamaan

Component: unknownexpander
Estimated difficulty: hard

This won't be easy. The issue is that when ##sys#canonicalize-body encounters a ##core#include, it will hand back to the compiler and passes the remaining body along with it. The compiler then calls canonicalize-body/ln (which is basically ##sys#canonicalize-body) with the forms from the file and the remaining ones appended. This extra call is unaware of what came before and starts a new letrec.

See 0be9d247a57da082bb2126b2e91958ea191c5513, which made this work at all (before, the include would be processed at toplevel, which is strictly much worse than what we have now).

Changing this probably requires restructuring how the canonicalization works (again). Maybe we'd have to introduce a new compiler form that allows canonicalize-body to be run in two steps, or something like it.

comment:3 Changed 5 years ago by sjamaan

Description: modified (diff)
Note: See TracTickets for help on using tickets.