这是indexloc提供的服务,不要输入任何密码
Skip to content

cast: add value-name #1332

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 16, 2023
Merged

cast: add value-name #1332

merged 2 commits into from
Jun 16, 2023

Conversation

bennn
Copy link
Contributor

@bennn bennn commented Jun 15, 2023

Replace #f with a name in TR's cast.

I'm not sure what name to use, but anything seems better than #f! The current name is inspired by require/typed's (interface for _) names.

cc @mfelleisen who discovered that running the contract profiler on code like this gave confusing output:

#lang typed/racket

(define-type Fighter Integer)
(define-type Pill Integer)
(struct interactive [{whose-turn : Symbol} {state : State}] #:prefab #:type-name Interactive)
(struct state [{fighters : [Listof Fighter]} {pills : {Listof Pill}}] #:prefab #:type-name State)

(define mk-state
  (let ((ff 0) (pp 0))
    (lambda ()
      (state
        (begin0 (list ff) (set! ff (+ 1 ff)))
        (begin0 (list pp) (set! pp (+ 1 pp)))))))

(define mk-interactive
  (let ((ww 'who))
    (lambda ()
      (interactive
        ww
        (mk-state)))))

(define NN (expt 10 4))

(define ii*
  (for/list : (Listof Interactive) ((_kk : Natural (in-range NN)))
    (cast (cast (mk-interactive) Any) Interactive)))

Contract profile output talks about Any and #f, so it's not at all clear where the costs came from:

Running time is 40.67% contracts
146/359 ms

Any                                                              98 ms
ben.rkt:28:4                                                    
    #f                                                           98 ms

(prefab/c (quote interactive) symbol? (prefab/c (quote state ... 27.5 ms
ben.rkt:28:4                                                    
    #f                                                           27.5 ms

(-> any/c boolean?)                                              20.5 ms
(lib syntax/id-set.rkt)                                         
    #f                                                           20.5 ms

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 1 file in this pull request and found no issues.

@bennn
Copy link
Contributor Author

bennn commented Jun 16, 2023

Example output afterward:

Running time is 29.89% contracts
107/358 ms

Any                                                              107 ms
ben.rkt:28:4                                                    
    (cast for interactive)                                       107 ms

@bennn bennn merged commit 3a6d176 into racket:master Jun 16, 2023
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resyntax analyzed 1 file in this pull request and found no issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants