From 9f839c11612d80592a0f94f4e19230605a4aa8c5 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 11 Oct 2018 06:55:04 -0600 Subject: [PATCH] expander: avoid retaining some syntax objects During the expansion of an internal-definition contexts, don't retain full forms, and instead keep just enough to perform syntax tracking, if any. --- racket/src/expander/expand/body.rkt | 24 +-- racket/src/racket/src/startup.inc | 301 +++++++++++++++------------- 2 files changed, 176 insertions(+), 149 deletions(-) diff --git a/racket/src/expander/expand/body.rkt b/racket/src/expander/expand/body.rkt index ae8dea8f99..864548e2b8 100644 --- a/racket/src/expander/expand/body.rkt +++ b/racket/src/expander/expand/body.rkt @@ -155,10 +155,11 @@ (for/list ([done-body (in-list done-bodys)]) (no-binds done-body s phase)) val-rhss)) - (cons exp-body (append - (for/list ([done-body (in-list done-bodys)]) - #f) - track-stxs)) + (cons (keep-as-needed body-ctx exp-body #:for-track? #t) + (append + (for/list ([done-body (in-list done-bodys)]) + #f) + track-stxs)) trans-idss trans-stxs stx-clauses @@ -195,7 +196,7 @@ val-rhss track-stxs (cons ids trans-idss) - (cons exp-body trans-stxs) + (cons (keep-as-needed body-ctx exp-body #:for-track? #t) trans-stxs) (cons (datum->syntax #f (list ids (m 'rhs)) exp-body) stx-clauses) new-dups)] [else @@ -295,13 +296,12 @@ (log-expand* body-ctx ['exit-prim exp-s] ['return exp-s]) (if (expand-context-to-parsed? body-ctx) (list exp-s) - (list (for/fold ([exp-s (attach-disappeared-transformer-bindings - exp-s - disappeared-transformer-bindings)]) - ([disappeared-transformer-form (in-list disappeared-transformer-forms)]) - (syntax-track-origin exp-s - disappeared-transformer-form - (car (syntax-e disappeared-transformer-form))))))])) + (let ([exp-s (attach-disappeared-transformer-bindings + exp-s + disappeared-transformer-bindings)]) + (list (for/fold ([exp-s exp-s]) ([form (in-list disappeared-transformer-forms)] + #:when form) + (syntax-track-origin exp-s form)))))])) ;; Roughly, create a `letrec-values` for for the given ids, right-hand sides, and ;; body. While expanding right-hand sides, though, keep track of whether any diff --git a/racket/src/racket/src/startup.inc b/racket/src/racket/src/startup.inc index 475f5f1a29..e37c9a6601 100644 --- a/racket/src/racket/src/startup.inc +++ b/racket/src/racket/src/startup.inc @@ -51,6 +51,7 @@ static const char *startup_source = "(1/namespace-module-identifier namespace-module-identifier)" "(1/namespace-require namespace-require)" "(1/namespace-syntax-introduce namespace-syntax-introduce)" +"(1/namespace-variable-value namespace-variable-value)" "(1/read read)" "(1/read-accept-compiled read-accept-compiled)" "(1/read-syntax read-syntax)" @@ -62132,7 +62133,18 @@ static const char *startup_source = " lst_0))))" " val-rhss_0))" "(cons" -" exp-body_0" +"(let-values(((body-ctx110_0)" +" body-ctx_1)" +"((exp-body111_0)" +" exp-body_0)" +"((temp112_0)" +" #t))" +"(keep-as-needed119.1" +" temp112_0" +" #f" +" #f" +" body-ctx110_0" +" exp-body111_0))" "(append" "(reverse$1" "(let-values(((lst_0)" @@ -62199,16 +62211,16 @@ static const char *startup_source = "(void)))" "(values))))" "(let-values(((ok?_0" -" define-syntaxes110_0" -" id111_0" -" rhs112_0)" +" define-syntaxes113_0" +" id114_0" +" rhs115_0)" "(let-values(((s_1)" " disarmed-exp-body_0))" "(let-values(((orig-s_0)" " s_1))" -"(let-values(((define-syntaxes110_0" -" id111_0" -" rhs112_0)" +"(let-values(((define-syntaxes113_0" +" id114_0" +" rhs115_0)" "(let-values(((s_2)" "(if(syntax?$1" " s_1)" @@ -62217,13 +62229,13 @@ static const char *startup_source = " s_1)))" "(if(pair?" " s_2)" -"(let-values(((define-syntaxes113_0)" +"(let-values(((define-syntaxes116_0)" "(let-values(((s_3)" "(car" " s_2)))" " s_3))" -"((id114_0" -" rhs115_0)" +"((id117_0" +" rhs118_0)" "(let-values(((s_3)" "(cdr" " s_2)))" @@ -62235,7 +62247,7 @@ static const char *startup_source = " s_3)))" "(if(pair?" " s_4)" -"(let-values(((id116_0)" +"(let-values(((id119_0)" "(let-values(((s_5)" "(car" " s_4)))" @@ -62284,7 +62296,7 @@ static const char *startup_source = " id_0))" "(let-values(((id_2)" "(let-values()" -"(let-values(((id119_0)" +"(let-values(((id122_0)" "(let-values()" "(if(let-values(((or-part_0)" "(if(syntax?$1" @@ -62304,7 +62316,7 @@ static const char *startup_source = " orig-s_0" " s_7)))))" "(cons" -" id119_0" +" id122_0" " id_1)))))" "(values" " id_2)))))" @@ -62320,7 +62332,7 @@ static const char *startup_source = " lst_0)))))" "(reverse$1" " id_0))))))))" -"((rhs117_0)" +"((rhs120_0)" "(let-values(((s_5)" "(cdr" " s_4)))" @@ -62332,7 +62344,7 @@ static const char *startup_source = " s_5)))" "(if(pair?" " s_6)" -"(let-values(((rhs118_0)" +"(let-values(((rhs121_0)" "(let-values(((s_7)" "(car" " s_6)))" @@ -62355,34 +62367,34 @@ static const char *startup_source = " \"bad syntax\"" " orig-s_0))))))" "(values" -" rhs118_0))" +" rhs121_0))" "(raise-syntax-error$1" " #f" " \"bad syntax\"" " orig-s_0))))))" "(values" -" id116_0" -" rhs117_0))" +" id119_0" +" rhs120_0))" "(raise-syntax-error$1" " #f" " \"bad syntax\"" " orig-s_0))))))" "(values" -" define-syntaxes113_0" -" id114_0" -" rhs115_0))" +" define-syntaxes116_0" +" id117_0" +" rhs118_0))" "(raise-syntax-error$1" " #f" " \"bad syntax\"" " orig-s_0)))))" "(values" " #t" -" define-syntaxes110_0" -" id111_0" -" rhs112_0))))))" +" define-syntaxes113_0" +" id114_0" +" rhs115_0))))))" "(let-values(((ids_0)" "(remove-use-site-scopes" -" id111_0" +" id114_0" " body-ctx_1)))" "(let-values((()" "(begin" @@ -62399,24 +62411,24 @@ static const char *startup_source = " #f" "(list" " ids_0" -" rhs112_0)))))" +" rhs115_0)))))" "(void)))" "(values))))" "(let-values(((new-dups_0)" -"(let-values(((ids120_0)" +"(let-values(((ids123_0)" " ids_0)" -"((phase121_0)" +"((phase124_0)" " phase_0)" -"((exp-body122_0)" +"((exp-body125_0)" " exp-body_0)" -"((dups123_0)" +"((dups126_0)" " dups_0))" "(check-no-duplicate-ids7.1" " unsafe-undefined" -" ids120_0" -" phase121_0" -" exp-body122_0" -" dups123_0))))" +" ids123_0" +" phase124_0" +" exp-body125_0" +" dups126_0))))" "(let-values(((counter_0)" "(root-expand-context-counter" " ctx_0)))" @@ -62451,22 +62463,22 @@ static const char *startup_source = "(let-values()" "(cons" "(let-values()" -"(let-values(((id124_0)" +"(let-values(((id127_0)" " id_0)" -"((phase125_0)" +"((phase128_0)" " phase_0)" -"((counter126_0)" +"((counter129_0)" " counter_0)" -"((frame-id127_0)" +"((frame-id130_0)" " frame-id_0)" -"((exp-body128_0)" +"((exp-body131_0)" " exp-body_0))" "(add-local-binding!37.1" -" frame-id127_0" -" exp-body128_0" -" id124_0" -" phase125_0" -" counter126_0)))" +" frame-id130_0" +" exp-body131_0" +" id127_0" +" phase128_0" +" counter129_0)))" " fold-var_1))))" "(values" " fold-var_2)))))" @@ -62514,7 +62526,7 @@ static const char *startup_source = "(let-values(((vals_0)" "(eval-for-syntaxes-binding" " 'define-syntaxes" -" rhs112_0" +" rhs115_0" " ids_0" " body-ctx_1)))" "(let-values(((extended-env_0)" @@ -62626,17 +62638,17 @@ static const char *startup_source = " v_0))" "(if(expand-context/outer?" " the-struct_0)" -"(let-values(((env129_0)" +"(let-values(((env132_0)" " extended-env_0)" -"((binding-layer130_0)" +"((binding-layer133_0)" "(maybe-increment-binding-layer_0" " ids_0" " body-ctx_1))" -"((inner131_0)" +"((inner134_0)" "(root-expand-context/outer-inner" " v_0)))" "(expand-context/outer1.1" -" inner131_0" +" inner134_0" "(root-expand-context/outer-post-expansion" " the-struct_0)" "(root-expand-context/outer-use-site-scopes" @@ -62645,12 +62657,12 @@ static const char *startup_source = " the-struct_0)" "(expand-context/outer-context" " the-struct_0)" -" env129_0" +" env132_0" "(expand-context/outer-scopes" " the-struct_0)" "(expand-context/outer-def-ctx-scopes" " the-struct_0)" -" binding-layer130_0" +" binding-layer133_0" "(expand-context/outer-reference-records" " the-struct_0)" "(expand-context/outer-only-immediate?" @@ -62677,14 +62689,25 @@ static const char *startup_source = " ids_0" " trans-idss_0)" "(cons" -" exp-body_0" +"(let-values(((body-ctx135_0)" +" body-ctx_1)" +"((exp-body136_0)" +" exp-body_0)" +"((temp137_0)" +" #t))" +"(keep-as-needed119.1" +" temp137_0" +" #f" +" #f" +" body-ctx135_0" +" exp-body136_0))" " trans-stxs_0)" "(cons" "(datum->syntax$1" " #f" "(list" " ids_0" -" rhs112_0)" +" rhs115_0)" " exp-body_0)" " stx-clauses_0)" " new-dups_0)))))))))))))))" @@ -62803,31 +62826,31 @@ static const char *startup_source = " def-ctx-scopes_0)))" "(let-values(((the-struct_0) v_0))" "(if(expand-context/outer? the-struct_0)" -"(let-values(((context132_0) 'expression)" -"((use-site-scopes133_0)(box null))" -"((scopes134_0)" +"(let-values(((context138_0) 'expression)" +"((use-site-scopes139_0)(box null))" +"((scopes140_0)" "(append" "(unbox" "(root-expand-context-use-site-scopes" " body-ctx_0))" "(expand-context-scopes body-ctx_0)))" -"((only-immediate?135_0) #f)" -"((def-ctx-scopes136_0) #f)" -"((post-expansion137_0) #f)" -"((inner138_0)" +"((only-immediate?141_0) #f)" +"((def-ctx-scopes142_0) #f)" +"((post-expansion143_0) #f)" +"((inner144_0)" "(root-expand-context/outer-inner v_0)))" "(expand-context/outer1.1" -" inner138_0" -" post-expansion137_0" -" use-site-scopes133_0" +" inner144_0" +" post-expansion143_0" +" use-site-scopes139_0" "(root-expand-context/outer-frame-id the-struct_0)" -" context132_0" +" context138_0" "(expand-context/outer-env the-struct_0)" -" scopes134_0" -" def-ctx-scopes136_0" +" scopes140_0" +" def-ctx-scopes142_0" "(expand-context/outer-binding-layer the-struct_0)" "(expand-context/outer-reference-records the-struct_0)" -" only-immediate?135_0" +" only-immediate?141_0" "(expand-context/outer-need-eventually-defined" " the-struct_0)" "(expand-context/outer-current-introduction-scopes" @@ -62927,9 +62950,9 @@ static const char *startup_source = " obs_0" " 'next)))" "(void)))" -"(let-values(((done-body139_0)" +"(let-values(((done-body145_0)" " done-body_0)" -"((temp140_0)" +"((temp146_0)" "(if(if name_0" "(=" " i_0" @@ -62941,13 +62964,13 @@ static const char *startup_source = " v_0))" "(if(expand-context/outer?" " the-struct_0)" -"(let-values(((name141_0)" +"(let-values(((name147_0)" " name_0)" -"((inner142_0)" +"((inner148_0)" "(root-expand-context/outer-inner" " v_0)))" "(expand-context/outer1.1" -" inner142_0" +" inner148_0" "(root-expand-context/outer-post-expansion" " the-struct_0)" "(root-expand-context/outer-use-site-scopes" @@ -62974,7 +62997,7 @@ static const char *startup_source = " the-struct_0)" "(expand-context/outer-current-use-scopes" " the-struct_0)" -" name141_0))" +" name147_0))" "(raise-argument-error" " 'struct-copy" " \"expand-context/outer?\"" @@ -62984,8 +63007,8 @@ static const char *startup_source = " #f" " #f" " #f" -" done-body139_0" -" temp140_0))))" +" done-body145_0" +" temp146_0))))" " fold-var_1))))" "(values" " fold-var_2)))))" @@ -63049,29 +63072,29 @@ static const char *startup_source = "(void)))" "(values))))" "(let-values(((exp-s_0)" -"(let-values(((val-idss143_0) val-idss_0)" -"((val-keyss144_0) val-keyss_0)" -"((val-rhss145_0) val-rhss_0)" -"((track-stxs146_0) track-stxs_0)" -"((temp147_0)(not stratified?_0))" -"((frame-id148_0) frame-id_0)" -"((finish-ctx149_0) finish-ctx_0)" -"((s150_0) s_0)" -"((temp151_0)(pair? stx-clauses_0))" -"((finish-bodys152_0) finish-bodys_0)" -"((temp153_0) #f))" +"(let-values(((val-idss149_0) val-idss_0)" +"((val-keyss150_0) val-keyss_0)" +"((val-rhss151_0) val-rhss_0)" +"((track-stxs152_0) track-stxs_0)" +"((temp153_0)(not stratified?_0))" +"((frame-id154_0) frame-id_0)" +"((finish-ctx155_0) finish-ctx_0)" +"((s156_0) s_0)" +"((temp157_0)(pair? stx-clauses_0))" +"((finish-bodys158_0) finish-bodys_0)" +"((temp159_0) #f))" "(expand-and-split-bindings-by-reference52.1" -" finish-ctx149_0" -" frame-id148_0" -" finish-bodys152_0" -" temp151_0" -" s150_0" -" temp147_0" +" finish-ctx155_0" +" frame-id154_0" +" finish-bodys158_0" +" temp157_0" +" s156_0" " temp153_0" -" val-idss143_0" -" val-keyss144_0" -" val-rhss145_0" -" track-stxs146_0))))" +" temp159_0" +" val-idss149_0" +" val-keyss150_0" +" val-rhss151_0" +" track-stxs152_0))))" "(begin" "(let-values(((obs_0)(expand-context-observer body-ctx_0)))" "(if obs_0" @@ -63083,6 +63106,10 @@ static const char *startup_source = "(void)))" "(if(expand-context-to-parsed? body-ctx_0)" "(list exp-s_0)" +"(let-values(((exp-s_1)" +"(attach-disappeared-transformer-bindings" +" exp-s_0" +" disappeared-transformer-bindings_0)))" "(list" "(let-values(((lst_0) disappeared-transformer-forms_0))" "(begin" @@ -63091,36 +63118,36 @@ static const char *startup_source = "(void)" "(let-values()(check-list lst_0)))" "((letrec-values(((for-loop_0)" -"(lambda(exp-s_1 lst_1)" +"(lambda(exp-s_2 lst_1)" "(begin" " 'for-loop" "(if(pair? lst_1)" -"(let-values(((disappeared-transformer-form_0)" +"(let-values(((form_0)" "(unsafe-car lst_1))" "((rest_0)" -"(unsafe-cdr lst_1)))" -"(let-values(((exp-s_2)" -"(let-values(((exp-s_2)" -" exp-s_1))" +"(unsafe-cdr" +" lst_1)))" "(let-values(((exp-s_3)" +"(let-values(((exp-s_3)" +" exp-s_2))" +"(if form_0" +"(let-values(((exp-s_4)" +" exp-s_3))" +"(let-values(((exp-s_5)" "(let-values()" "(syntax-track-origin$1" -" exp-s_2" -" disappeared-transformer-form_0" -"(car" -"(syntax-e$1" -" disappeared-transformer-form_0))))))" +" exp-s_4" +" form_0))))" "(values" -" exp-s_3)))))" +" exp-s_5)))" +" exp-s_3))))" "(if(not #f)" -"(for-loop_0 exp-s_2 rest_0)" -" exp-s_2)))" -" exp-s_1)))))" +"(for-loop_0 exp-s_3 rest_0)" +" exp-s_3)))" +" exp-s_2)))))" " for-loop_0)" -"(attach-disappeared-transformer-bindings" -" exp-s_0" -" disappeared-transformer-bindings_0)" -" lst_0))))))))))))))))))))))))))))))))" +" exp-s_1" +" lst_0)))))))))))))))))))))))))))))))))" "(define-values" "(expand-and-split-bindings-by-reference52.1)" "(lambda(ctx36_0" @@ -63186,9 +63213,9 @@ static const char *startup_source = " accum-keyss_0" " accum-rhss_0))" " exp-body_0))" -"(let-values(((track?154_0) track?_1)" -"((s155_0) s_0)" -"((temp156_0)" +"(let-values(((track?160_0) track?_1)" +"((s161_0) s_0)" +"((temp162_0)" "(list*" "(if(null? accum-idss_0)" "(core-id" @@ -63203,9 +63230,9 @@ static const char *startup_source = " accum-track-stxs_0)" " exp-body_0)))" "(rebuild5.1" -" track?154_0" -" s155_0" -" temp156_0)))))" +" track?160_0" +" s161_0" +" temp162_0)))))" "(begin" "(let-values(((obs_0)" "(expand-context-observer ctx_0)))" @@ -63236,8 +63263,8 @@ static const char *startup_source = "(values))))" "(let-values(((ids_0)(car idss_1)))" "(let-values(((expanded-rhs_0)" -"(let-values(((temp157_0)(car rhss_1))" -"((temp158_0)" +"(let-values(((temp163_0)(car rhss_1))" +"((temp164_0)" "(as-named-context" " ctx_0" " ids_0)))" @@ -63245,8 +63272,8 @@ static const char *startup_source = " #f" " #f" " #f" -" temp157_0" -" temp158_0))))" +" temp163_0" +" temp164_0))))" "(let-values(((track-stx_0)(car track-stxs_1)))" "(let-values(((local-or-forward-references?_0)" "(reference-record-forward-references?" @@ -63297,11 +63324,11 @@ static const char *startup_source = "(car keyss_1)" " expanded-rhs_0))" " exp-rest_0)" -"(let-values(((track?159_0)" +"(let-values(((track?165_0)" " track?_1)" -"((s160_0)" +"((s166_0)" " s_0)" -"((temp161_0)" +"((temp167_0)" "(list*" "(core-id" " 'let-values" @@ -63313,9 +63340,9 @@ static const char *startup_source = " track-stx_0))" " exp-rest_0)))" "(rebuild5.1" -" track?159_0" -" s160_0" -" temp161_0)))))" +" track?165_0" +" s166_0" +" temp167_0)))))" "(begin" "(let-values(((obs_0)" "(expand-context-observer" @@ -63377,11 +63404,11 @@ static const char *startup_source = " accum-keyss_0" " accum-rhss_0)))" " exp-rest_0)" -"(let-values(((track?162_0)" +"(let-values(((track?168_0)" " track?_1)" -"((s163_0)" +"((s169_0)" " s_0)" -"((temp164_0)" +"((temp170_0)" "(list*" "(core-id" " 'letrec-values" @@ -63398,9 +63425,9 @@ static const char *startup_source = " accum-track-stxs_0))" " exp-rest_0)))" "(rebuild5.1" -" track?162_0" -" s163_0" -" temp164_0)))))" +" track?168_0" +" s169_0" +" temp170_0)))))" "(begin" "(let-values(((obs_0)" "(expand-context-observer"