Skip to content
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

require/untyped-contract leads to errors in no-check, Shallow, and Optional #1286

Open
bennn opened this issue Sep 27, 2022 · 3 comments
Open

Comments

@bennn
Copy link
Contributor

bennn commented Sep 27, 2022

What version of Racket are you using?

Welcome to Racket v8.6.0.9 [cs].

What program did you run?

This program is ok with normal TR and not okay for shallow, optional, and no-check

server.rkt

#lang typed/racket/shallow ;optional ;no-check

(provide mynum check-array-shape)

(define mynum 42)

(define-type (MVec T) (Mutable-Vectorof T))

(define-type Indexes (MVec Index))
(define-type In-Indexes (U (MVec Integer) Indexes))

(: check-array-shape (In-Indexes (-> Nothing) -> Indexes))
(define (check-array-shape ds fail)
  (define dims (vector-length ds))
  (define: new-ds : Indexes (make-vector dims 0))
  (let loop ([#{i : Nonnegative-Fixnum} 0])
    (cond [(i . < . dims)
           (define di (vector-ref ds i))
           (cond [(index? di)  (vector-set! new-ds i di)
                               (loop (+ i 1))]
                 [else  (fail)])]
          [else  new-ds])))

main.rkt

#lang racket/base

(require typed/untyped-utils
         typed/racket/no-check
         (except-in "server.rkt"
                    check-array-shape))

(require/untyped-contract
 "server.rkt"
 [check-array-shape  ((Vectorof Integer) (-> Nothing) -> (Vectorof Index))])

(check-array-shape (vector 1 2 3) (lambda () (error 'die)))

What should have happened?

No error

If you got an error message, please include it here.

Shallow

/home/ben/code/racket/fork/extra-pkgs/typed-racket/typed-racket-lib/typed/untyped-utils.rkt:64:13:
Type Checker: type mismatch
  expected: (-> (Vectorof Integer) (-> Nothing) (Vectorof Index))
  given: (-> In-Indexes (-> Nothing) Indexes)
  in: (define check-array-shape check-array-shape2)

no-check

/home/ben/code/racket/fork/extra-pkgs/typed-racket/typed-racket-lib/typed/untyped-utils.rkt:64:13:
Type Checker: missing type for identifier;
 consider using `require/typed' to import it
  identifier: check-array-shape2
  from module: test-ruc-server.rkt
  in: (define check-array-shape check-array-shape2)

PS thanks to @Rscho314 for the report in racket/math#75

@bennn bennn changed the title require/untypedcontract require/untyped-contract leads to errors in no-check, Shallow, and Optional Sep 27, 2022
@bennn
Copy link
Contributor Author

bennn commented Sep 27, 2022

Ideas:

  • let require/untyped-contract know what language the server is using
  • use unsafe-require/typed somehow inside require/untyped-contract --- which probably means we need to fix unsafe-require/typed to work for optional/shallow => deep

@Rscho314
Copy link
Sponsor

Hi @bennn ,

I have posted some seemingly working code to add a language specification to require/untyped-contract. Two questions:

  • I guess I should make the language spec argument optional, to avoid breaking existing code?
  • Another idea would be fetching the language spec automatically from the imported module. Do you think that's worth pursuing?

Best,
Raoul

@racket-discourse-github-bot

This issue has been mentioned on Racket Discussions. There might be relevant details there:

https://racket.discourse.group/t/replacing-lexical-context-in-a-macro/2004/1

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

No branches or pull requests

3 participants