From cf69cb2aff1348044166799b1043d00cb289d196 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Fri, 11 Mar 2011 15:29:45 -0700 Subject: [PATCH] special treatment of void as 'inferred-name property allows keyword-based application to hide temporary names that happen to be bound to procedure arguments --- collects/racket/private/kw.rkt | 6 ++- collects/racket/private/name.rkt | 42 ++++++++++--------- .../scribblings/reference/syntax-model.scrbl | 5 ++- collects/syntax/scribblings/name.scrbl | 7 ++-- doc/release-notes/racket/HISTORY.txt | 1 + src/racket/src/fun.c | 4 ++ 6 files changed, 41 insertions(+), 24 deletions(-) diff --git a/collects/racket/private/kw.rkt b/collects/racket/private/kw.rkt index 125446365b..37e40e31ed 100644 --- a/collects/racket/private/kw.rkt +++ b/collects/racket/private/kw.rkt @@ -821,7 +821,11 @@ [(keyword? (syntax-e (car l))) (loop (cddr l) (cdr ids) - (cons (list (car ids) (cadr l)) bind-accum) + (cons (list (car ids) (syntax-property (cadr l) + 'inferred-name + ;; void hides binding name + (void))) + bind-accum) arg-accum (cons (cons (car l) (car ids)) kw-pairs))] diff --git a/collects/racket/private/name.rkt b/collects/racket/private/name.rkt index 6400d7676c..b66d7f0578 100644 --- a/collects/racket/private/name.rkt +++ b/collects/racket/private/name.rkt @@ -4,22 +4,26 @@ (#%provide syntax-local-infer-name) (define (syntax-local-infer-name stx) - (or (syntax-property stx 'inferred-name) - (let ([n (syntax-local-name)]) - (or n - (let ([s (syntax-source stx)]) - (and s - (let ([s (let ([s (format - "~a" - (cond - [(path? s) (path->string s)] - [else s]))]) - (if ((string-length s) . > . 20) - (string-append "..." (substring s (- (string-length s) 20))) - s))] - [l (syntax-line stx)] - [c (syntax-column stx)]) - (if l - (string->symbol (format "~a:~a:~a" s l c)) - (let ([p (syntax-position stx)]) - (string->symbol (format "~a::~a" s p)))))))))))) + (let-values ([(prop) (syntax-property stx 'inferred-name)]) + (or (and prop + (not (void? prop)) + prop) + (let ([n (and (not (void? prop)) + (syntax-local-name))]) + (or n + (let ([s (syntax-source stx)]) + (and s + (let ([s (let ([s (format + "~a" + (cond + [(path? s) (path->string s)] + [else s]))]) + (if ((string-length s) . > . 20) + (string-append "..." (substring s (- (string-length s) 20))) + s))] + [l (syntax-line stx)] + [c (syntax-column stx)]) + (if l + (string->symbol (format "~a:~a:~a" s l c)) + (let ([p (syntax-position stx)]) + (string->symbol (format "~a::~a" s p))))))))))))) diff --git a/collects/scribblings/reference/syntax-model.scrbl b/collects/scribblings/reference/syntax-model.scrbl index 25c697c294..6ea71a3c63 100644 --- a/collects/scribblings/reference/syntax-model.scrbl +++ b/collects/scribblings/reference/syntax-model.scrbl @@ -968,7 +968,10 @@ When an @indexed-racket['inferred-name] property is attached to a syntax object for an expression (see @secref["stxprops"]), the property value is used for naming the expression, and it overrides any name that was inferred from the expression's context. Normally, the -property value should be a symbol or an identifier. +property value should be a symbol. A @racket['inferred-name] +property value of @|void-const| hides a name that would otherwise be +inferred from context (perhaps because a binding identifier's was +automatically generated and should not be exposed). When an inferred name is not available, but a source location is available, a name is constructed using the source location diff --git a/collects/syntax/scribblings/name.scrbl b/collects/syntax/scribblings/name.scrbl index dab4229af6..a24957bd58 100644 --- a/collects/syntax/scribblings/name.scrbl +++ b/collects/syntax/scribblings/name.scrbl @@ -11,6 +11,7 @@ Similar to @scheme[syntax-local-name] except that @scheme[stx] is checked for an @scheme['inferred-name] property (which overrides any inferred name). If neither @scheme[syntax-local-name] nor -@scheme['inferred-name] produce a name, then a name is constructed -from the source-location information in @scheme[stx], if any. If no -name can be constructed, the result is @scheme[#f].} +@scheme['inferred-name] produce a name, or if the +@scheme['inferred-name] property value is @|void-const|, then a name +is constructed from the source-location information in @scheme[stx], +if any. If no name can be constructed, the result is @scheme[#f].} diff --git a/doc/release-notes/racket/HISTORY.txt b/doc/release-notes/racket/HISTORY.txt index bd4df035c7..aea334c118 100644 --- a/doc/release-notes/racket/HISTORY.txt +++ b/doc/release-notes/racket/HISTORY.txt @@ -2,6 +2,7 @@ Version 5.1.0.4 Change file-or-directory-permission to add 'bits mode and permission-setting mode racket/file: add user-read-bit, etc. +Added special treatment of void as an 'inferred-name property Version 5.1.0.2 Enabled single-precision floats by default diff --git a/src/racket/src/fun.c b/src/racket/src/fun.c index 193019ee68..eebc7ba024 100644 --- a/src/racket/src/fun.c +++ b/src/racket/src/fun.c @@ -1944,6 +1944,10 @@ Scheme_Object *scheme_build_closure_name(Scheme_Object *code, Scheme_Compile_Inf name = scheme_stx_property(code, scheme_inferred_name_symbol, NULL); if (name && SCHEME_SYMBOLP(name)) { name = combine_name_with_srcloc(name, code, 0); + } else if (name && SCHEME_VOIDP(name)) { + name = scheme_source_to_name(code); + if (name) + name = combine_name_with_srcloc(name, code, 1); } else { name = rec[drec].value_name; if (!name || SCHEME_FALSEP(name)) {