Re: [racket-dev] expand, local-expand, and syntax-procedure-converted-arguments-property

2013-07-11 Thread Matthew Flatt
At Wed, 10 Jul 2013 23:45:07 -0400, Carl Eastlund wrote:
 That came up on IRC.  I believe Asumu said the key is an uninterned
 identifier, meaning it's a stateful value.  Right now, cross-phase
 persistent modules can't store anything stateful other than generative
 struct types.

Oh, I thought that `(gensym)' was already allowed. I'll add it.

Allowing stateful things in the sense of object identity is the point
of a cross-phase persistent module. I don't see how they're useful
otherwise.

_
  Racket Developers list:
  http://lists.racket-lang.org/dev


[racket-dev] expand, local-expand, and syntax-procedure-converted-arguments-property

2013-07-10 Thread Asumu Takikawa
Hi all,

I'm currently trying to fix the Typed Racket unit tests. I think I've
narrowed down the issue to a certain syntax property for keyword
functions.

The issue is illustrated by the following example:

  #lang racket

  (require racket/file
   (for-syntax racket/file
   racket/keyword-transform))

  ;; the property is #f
  (begin-for-syntax
   (displayln
 (syntax-case (expand-syntax #'(copy-directory/files 1 2)) ()
   [(let-values (((temp1) _)
 ((temp2) _))
  (if _
  (#%plain-app1 copy-directory/files15 e1 ...)
  (#%plain-app2 copy-directory/files17 e2 ...)))
(syntax-procedure-converted-arguments-property 
#'copy-directory/files15)])))

  ;; property is syntax
  (begin-for-syntax
   (displayln
 (syntax-case (local-expand #'(copy-directory/files 1 2) 'expression null) 
()
   [(let-values (((temp1) _)
 ((temp2) _))
  (if _
  (#%plain-app1 copy-directory/files15 e1 ...)
  (#%plain-app2 copy-directory/files17 e2 ...)))
(syntax-procedure-converted-arguments-property 
#'copy-directory/files15)])))

There are two syntax-time computations here. Both are expanding an
application of a keyword function (one with local-expand, one with
expand) and looking at the resulting syntax.

The key point here is that I want to find the property looked up by
`syntax-procedure-converted-arguments-property` on an output identifier
because Typed Racket needs it to type-check the expansion.

Unfortunately, as the comments indicate, only the second piece of code
can find the property. The reason appears to be that the property key is
actually a private `gensym`ed symbol and the two pieces of code appear
to get separate instantiations of the kw.rkt module (perhaps at different
phases).

To check that, if I modify kw.rkt to use a plain symbol, both of the
snippets above return the same property value.

Anyone have any idea how I can keep using `expand` but still be able to
look up the property?

Cheers,
Asumu
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] expand, local-expand, and syntax-procedure-converted-arguments-property

2013-07-10 Thread Eric Dobson
I'm not sure about the exact problem. But I have some work for the TR
unit tests that make it use a saner way of running the tests, and it
allows for the TR syntax properties to be gensyms. It will likely be a
week or two until they are in HEAD (tons of commits that need to be
cleaned up and reviewed) but I can push to github tonight and let you
see if they fix your issue.

On Wed, Jul 10, 2013 at 6:04 PM, Asumu Takikawa as...@ccs.neu.edu wrote:
 Hi all,

 I'm currently trying to fix the Typed Racket unit tests. I think I've
 narrowed down the issue to a certain syntax property for keyword
 functions.

 The issue is illustrated by the following example:

   #lang racket

   (require racket/file
(for-syntax racket/file
racket/keyword-transform))

   ;; the property is #f
   (begin-for-syntax
(displayln
  (syntax-case (expand-syntax #'(copy-directory/files 1 2)) ()
[(let-values (((temp1) _)
  ((temp2) _))
   (if _
   (#%plain-app1 copy-directory/files15 e1 ...)
   (#%plain-app2 copy-directory/files17 e2 ...)))
 (syntax-procedure-converted-arguments-property 
 #'copy-directory/files15)])))

   ;; property is syntax
   (begin-for-syntax
(displayln
  (syntax-case (local-expand #'(copy-directory/files 1 2) 'expression 
 null) ()
[(let-values (((temp1) _)
  ((temp2) _))
   (if _
   (#%plain-app1 copy-directory/files15 e1 ...)
   (#%plain-app2 copy-directory/files17 e2 ...)))
 (syntax-procedure-converted-arguments-property 
 #'copy-directory/files15)])))

 There are two syntax-time computations here. Both are expanding an
 application of a keyword function (one with local-expand, one with
 expand) and looking at the resulting syntax.

 The key point here is that I want to find the property looked up by
 `syntax-procedure-converted-arguments-property` on an output identifier
 because Typed Racket needs it to type-check the expansion.

 Unfortunately, as the comments indicate, only the second piece of code
 can find the property. The reason appears to be that the property key is
 actually a private `gensym`ed symbol and the two pieces of code appear
 to get separate instantiations of the kw.rkt module (perhaps at different
 phases).

 To check that, if I modify kw.rkt to use a plain symbol, both of the
 snippets above return the same property value.

 Anyone have any idea how I can keep using `expand` but still be able to
 look up the property?

 Cheers,
 Asumu
 _
   Racket Developers list:
   http://lists.racket-lang.org/dev
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] expand, local-expand, and syntax-procedure-converted-arguments-property

2013-07-10 Thread Ryan Culpepper

On 07/10/2013 09:04 PM, Asumu Takikawa wrote:

Hi all,

I'm currently trying to fix the Typed Racket unit tests. I think I've
narrowed down the issue to a certain syntax property for keyword
functions.

The issue is illustrated by the following example:

   #lang racket

   (require racket/file
(for-syntax racket/file
racket/keyword-transform))

   ;; the property is #f
   (begin-for-syntax
(displayln
  (syntax-case (expand-syntax #'(copy-directory/files 1 2)) ()
[(let-values (((temp1) _)
  ((temp2) _))
   (if _
   (#%plain-app1 copy-directory/files15 e1 ...)
   (#%plain-app2 copy-directory/files17 e2 ...)))
 (syntax-procedure-converted-arguments-property 
#'copy-directory/files15)])))

   ;; property is syntax
   (begin-for-syntax
(displayln
  (syntax-case (local-expand #'(copy-directory/files 1 2) 'expression null) 
()
[(let-values (((temp1) _)
  ((temp2) _))
   (if _
   (#%plain-app1 copy-directory/files15 e1 ...)
   (#%plain-app2 copy-directory/files17 e2 ...)))
 (syntax-procedure-converted-arguments-property 
#'copy-directory/files15)])))

There are two syntax-time computations here. Both are expanding an
application of a keyword function (one with local-expand, one with
expand) and looking at the resulting syntax.

The key point here is that I want to find the property looked up by
`syntax-procedure-converted-arguments-property` on an output identifier
because Typed Racket needs it to type-check the expansion.

Unfortunately, as the comments indicate, only the second piece of code
can find the property. The reason appears to be that the property key is
actually a private `gensym`ed symbol and the two pieces of code appear
to get separate instantiations of the kw.rkt module (perhaps at different
phases).

To check that, if I modify kw.rkt to use a plain symbol, both of the
snippets above return the same property value.

Anyone have any idea how I can keep using `expand` but still be able to
look up the property?


To get information about a phase-0 '#%app' expansion, you need to call 
the phase-1 version of 'syntax-procedure-converted-arguments-property'. 
That's going to require a bit of phase-crossing trickery, because the 
identifier you want to query is a phase-0 (dynamic) value, and you want 
the result as a phase-0 value, but the phase-1 function naturally 
consumes and produces phase-1 values.


One solution is to use 'quote-syntax', 'eval', and 'phase1-eval' all 
together. Use 'eval' with 'quote-syntax' to convert the phase-0 
identifier to a phase-1 identifier. Use 'phase1-eval' to run the 
computation at phase 1 and capture the phase-1 result as a phase-0 value 
(also using 'quote-syntax').


Here's the code:

(require unstable/macro-testing)

(define (get-converted-args-property proc-id)
  (eval
   #`(phase1-eval
  (syntax-procedure-converted-arguments-property
   (quote-syntax #,proc-id))
  #:quote quote-syntax)))

(printf property is ~s\n
(syntax-case (expand-syntax #'(copy-directory/files 1 2)) ()
  [(let-values (((temp1) _)
((temp2) _))
 (if _
 (#%plain-app1 copy-directory/files15 e1 ...)
 (#%plain-app2 copy-directory/files17 e2 ...)))
   (get-converted-args-property #'copy-directory/files15)]))

Note that by asking 'phase1-eval' to convert the phase-1 result to a 
phase-0 value using 'quote-syntax', we've converted the pair of 
identifiers to a syntax object containing the pair. You'll have to break 
it apart again yourself.


Ryan

_
 Racket Developers list:
 http://lists.racket-lang.org/dev


Re: [racket-dev] expand, local-expand, and syntax-procedure-converted-arguments-property

2013-07-10 Thread Matthew Flatt
At Wed, 10 Jul 2013 23:15:46 -0400, Ryan Culpepper wrote:
 On 07/10/2013 09:04 PM, Asumu Takikawa wrote:
  Hi all,
 
  I'm currently trying to fix the Typed Racket unit tests. I think I've
  narrowed down the issue to a certain syntax property for keyword
  functions.
 
  The issue is illustrated by the following example:
 
 #lang racket
 
 (require racket/file
  (for-syntax racket/file
  racket/keyword-transform))
 
 ;; the property is #f
 (begin-for-syntax
  (displayln
(syntax-case (expand-syntax #'(copy-directory/files 1 2)) ()
  [(let-values (((temp1) _)
((temp2) _))
 (if _
 (#%plain-app1 copy-directory/files15 e1 ...)
 (#%plain-app2 copy-directory/files17 e2 ...)))
   (syntax-procedure-converted-arguments-property 
 #'copy-directory/files15)])))
 
 ;; property is syntax
 (begin-for-syntax
  (displayln
(syntax-case (local-expand #'(copy-directory/files 1 2) 'expression 
 null) ()
  [(let-values (((temp1) _)
((temp2) _))
 (if _
 (#%plain-app1 copy-directory/files15 e1 ...)
 (#%plain-app2 copy-directory/files17 e2 ...)))
   (syntax-procedure-converted-arguments-property 
 #'copy-directory/files15)])))
 
  There are two syntax-time computations here. Both are expanding an
  application of a keyword function (one with local-expand, one with
  expand) and looking at the resulting syntax.
 
  The key point here is that I want to find the property looked up by
  `syntax-procedure-converted-arguments-property` on an output identifier
  because Typed Racket needs it to type-check the expansion.
 
  Unfortunately, as the comments indicate, only the second piece of code
  can find the property. The reason appears to be that the property key is
  actually a private `gensym`ed symbol and the two pieces of code appear
  to get separate instantiations of the kw.rkt module (perhaps at different
  phases).
 
  To check that, if I modify kw.rkt to use a plain symbol, both of the
  snippets above return the same property value.
 
  Anyone have any idea how I can keep using `expand` but still be able to
  look up the property?
 
 To get information about a phase-0 '#%app' expansion, you need to call 
 the phase-1 version of 'syntax-procedure-converted-arguments-property'. 
 That's going to require a bit of phase-crossing trickery, because the 
 identifier you want to query is a phase-0 (dynamic) value, and you want 
 the result as a phase-0 value, but the phase-1 function naturally 
 consumes and produces phase-1 values.
 
 One solution is to use 'quote-syntax', 'eval', and 'phase1-eval' all 
 together. Use 'eval' with 'quote-syntax' to convert the phase-0 
 identifier to a phase-1 identifier. Use 'phase1-eval' to run the 
 computation at phase 1 and capture the phase-1 result as a phase-0 value 
 (also using 'quote-syntax').

I haven't thought about this much, but would it make more sense to move
the property key to a cross-phase persistent module (with a `protected'
provide) in this case?

_
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] expand, local-expand, and syntax-procedure-converted-arguments-property

2013-07-10 Thread Carl Eastlund
Carl Eastlund


On Wed, Jul 10, 2013 at 11:28 PM, Matthew Flatt mfl...@cs.utah.edu wrote:

 At Wed, 10 Jul 2013 23:15:46 -0400, Ryan Culpepper wrote:
  On 07/10/2013 09:04 PM, Asumu Takikawa wrote:
   Hi all,
  
   I'm currently trying to fix the Typed Racket unit tests. I think I've
   narrowed down the issue to a certain syntax property for keyword
   functions.
  
   The issue is illustrated by the following example:
  
  #lang racket
  
  (require racket/file
   (for-syntax racket/file
   racket/keyword-transform))
  
  ;; the property is #f
  (begin-for-syntax
   (displayln
 (syntax-case (expand-syntax #'(copy-directory/files 1 2)) ()
   [(let-values (((temp1) _)
 ((temp2) _))
  (if _
  (#%plain-app1 copy-directory/files15 e1 ...)
  (#%plain-app2 copy-directory/files17 e2 ...)))
(syntax-procedure-converted-arguments-property
  #'copy-directory/files15)])))
  
  ;; property is syntax
  (begin-for-syntax
   (displayln
 (syntax-case (local-expand #'(copy-directory/files 1 2)
 'expression
  null) ()
   [(let-values (((temp1) _)
 ((temp2) _))
  (if _
  (#%plain-app1 copy-directory/files15 e1 ...)
  (#%plain-app2 copy-directory/files17 e2 ...)))
(syntax-procedure-converted-arguments-property
  #'copy-directory/files15)])))
  
   There are two syntax-time computations here. Both are expanding an
   application of a keyword function (one with local-expand, one with
   expand) and looking at the resulting syntax.
  
   The key point here is that I want to find the property looked up by
   `syntax-procedure-converted-arguments-property` on an output identifier
   because Typed Racket needs it to type-check the expansion.
  
   Unfortunately, as the comments indicate, only the second piece of code
   can find the property. The reason appears to be that the property key
 is
   actually a private `gensym`ed symbol and the two pieces of code appear
   to get separate instantiations of the kw.rkt module (perhaps at
 different
   phases).
  
   To check that, if I modify kw.rkt to use a plain symbol, both of the
   snippets above return the same property value.
  
   Anyone have any idea how I can keep using `expand` but still be able to
   look up the property?
 
  To get information about a phase-0 '#%app' expansion, you need to call
  the phase-1 version of 'syntax-procedure-converted-arguments-property'.
  That's going to require a bit of phase-crossing trickery, because the
  identifier you want to query is a phase-0 (dynamic) value, and you want
  the result as a phase-0 value, but the phase-1 function naturally
  consumes and produces phase-1 values.
 
  One solution is to use 'quote-syntax', 'eval', and 'phase1-eval' all
  together. Use 'eval' with 'quote-syntax' to convert the phase-0
  identifier to a phase-1 identifier. Use 'phase1-eval' to run the
  computation at phase 1 and capture the phase-1 result as a phase-0 value
  (also using 'quote-syntax').

 I haven't thought about this much, but would it make more sense to move
 the property key to a cross-phase persistent module (with a `protected'
 provide) in this case?


That came up on IRC.  I believe Asumu said the key is an uninterned
identifier, meaning it's a stateful value.  Right now, cross-phase
persistent modules can't store anything stateful other than generative
struct types.

--Carl
_
  Racket Developers list:
  http://lists.racket-lang.org/dev