Avoiding cycles in everything but closures

This commit is contained in:
Blake Johnson 2010-10-07 13:24:25 -06:00 committed by Jay McCarthy
parent d84b78daab
commit 7bffbc31a2
4 changed files with 42 additions and 19 deletions

View File

@ -76,6 +76,7 @@ Here's the idea:
(define merged-source-path (path-add-suffix file-to-batch #".merged.rkt")) (define merged-source-path (path-add-suffix file-to-batch #".merged.rkt"))
(define merged-struct-path (path-add-suffix file-to-batch #".mergeds.rkt"))
(define-values (merged-source-base merged-source-name _1) (split-path merged-source-path)) (define-values (merged-source-base merged-source-name _1) (split-path merged-source-path))
(define merged-zo-path (build-compiled-path merged-source-base (path-add-suffix merged-source-name #".zo"))) (define merged-zo-path (build-compiled-path merged-source-base (path-add-suffix merged-source-name #".zo")))
@ -113,6 +114,13 @@ Here's the idea:
(pretty-print (decompile batch-final))) (pretty-print (decompile batch-final)))
#:exists 'replace) #:exists 'replace)
(log-debug "Writing merged struct~n")
(with-output-to-file
merged-struct-path
(lambda ()
(pretty-write batch-final))
#:exists 'replace)
(log-debug "Writing merged zo~n") (log-debug "Writing merged zo~n")
(void (void
(with-output-to-file (with-output-to-file

View File

@ -75,6 +75,8 @@
(if (encountered? v) (if (encountered? v)
pos pos
(encounter! v)))] (encounter! v)))]
[(member v (rest (continuation-mark-set->list (current-continuation-marks) 'cycle)))
#f]
[error? ; If we would error if this were not present, then we must share it [error? ; If we would error if this were not present, then we must share it
(encounter! v) (encounter! v)
(share! v)] (share! v)]
@ -481,11 +483,18 @@
(define-syntax with-type-trace (define-syntax with-type-trace
(syntax-rules () (syntax-rules ()
[(_ v body ...) [(_ v body ...)
#;(begin body ...) (begin body ...)
(with-continuation-mark 'zo (typeof v) #;(with-continuation-mark 'zo (typeof v)
(begin0 (begin body ...) (void)))]))
(define-syntax with-cycle-check
(syntax-rules ()
[(_ v body ...)
(with-continuation-mark 'cycle v
(begin0 (begin body ...) (void)))])) (begin0 (begin body ...) (void)))]))
(define (out-anything v out) (define (out-anything v out)
(with-cycle-check v
(with-type-trace v (with-type-trace v
(out-shared (out-shared
v out v out
@ -861,7 +870,7 @@
(define bstr (get-output-bytes s)) (define bstr (get-output-bytes s))
(out-number (bytes-length bstr) out) (out-number (bytes-length bstr) out)
(out-bytes bstr out)] (out-bytes bstr out)]
[else (error 'out-anything "~s" (current-type-trace))]))))) [else (error 'out-anything "~s" (current-type-trace))]))))))
(define-struct module-decl (content)) (define-struct module-decl (content))

View File

@ -1046,6 +1046,8 @@
(for ([i (in-range 1 symtabsize)]) (for ([i (in-range 1 symtabsize)])
(read-sym cp i)) (read-sym cp i))
#;(for ([(i v) (in-dict (cport-symtab cp))])
(printf "~a = ~a\n" i (placeholder-get v)) )
(set-cport-pos! cp shared-size) (set-cport-pos! cp shared-size)
(make-reader-graph (make-reader-graph
(read-marshalled 'compilation-top-type cp)))) (read-marshalled 'compilation-top-type cp))))

View File

@ -4738,9 +4738,13 @@ static Scheme_Object *read_compact(CPort *port, int use_stack)
l = read_compact_number(port); l = read_compact_number(port);
RANGE_CHECK(l, < port->symtab_size); RANGE_CHECK(l, < port->symtab_size);
v = port->symtab[l]; v = port->symtab[l];
if (v == -1) {
// there is a cycle
scheme_ill_formed_code(port);
};
if (!v) { if (!v) {
long save_pos = port->pos; long save_pos = port->pos;
port->symtab[l] = scheme_false; /* avoid cycles if marshaled form is broken: */ port->symtab[l] = -1; /* avoid cycles if marshaled form is broken: */
port->pos = port->shared_offsets[l - 1]; port->pos = port->shared_offsets[l - 1];
v = read_compact(port, 0); v = read_compact(port, 0);
port->pos = save_pos; port->pos = save_pos;