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

Already on GitHub? Sign in to your account

Fix type->contract on structures. Now uses struct/c. #139

Closed
wants to merge 5 commits into
from

Conversation

Projects
None yet
3 participants
Contributor

endobson commented Aug 24, 2012

This is still not complete. It fails on one test case, fail/pr11686.rkt.

The issue is that the constraint on what kind of contract we need to produce can come from multiple places.
For a immutable struct contract we need that each field is a chaperone contract. Any type which contains an Univ type on the typed side will produce a impersonator contract due to any-wrap. The issue is when we need to make a recursive contract for a Mu type. We need to make it a impersonator contract if it contains an Univ, and we need to make it a chaperone contract if a struct type uses its recursive id in a chaperone only context.

My current solution is to just assume that structs won't use the contract recursively, which is why it fails the test case. The correct solution is to see if it is used in any place where it needs to be a chaperone and then make it a chaperone, otherwise make it an impersonator.

On a side note, I don't see what any-wrap/c protects against. Why cannot it be any/c?

Owner

samth commented Aug 24, 2012

On Fri, Aug 24, 2012 at 3:10 AM, Eric Dobson notifications@github.com wrote:

On a side note, I don't see what any-wrap/c protects against. Why cannot
it be any/c?

See https://gist.github.com/3449728 for an example.

sam th
samth@ccs.neu.edu

Contributor

endobson commented Aug 24, 2012

Ok, makes sense. Also it seems to me that if one runs into an error because
they have Any in the type that they are exporting, then it is not a failing
of the contract system but a failing on them for not providing a good type.

On Fri, Aug 24, 2012 at 4:52 AM, Sam Tobin-Hochstadt <
notifications@github.com> wrote:

On Fri, Aug 24, 2012 at 3:10 AM, Eric Dobson notifications@github.com
wrote:

On a side note, I don't see what any-wrap/c protects against. Why cannot
it be any/c?

See https://gist.github.com/3449728 for an example.

sam th
samth@ccs.neu.edu


Reply to this email directly or view it on GitHubhttps://github.com/plt/racket/pull/139#issuecomment-7999232.

Owner

samth commented Aug 24, 2012

Right, the problem is due to a weak type in that case. But TR can't just let there be a dynamic error in the typed part of the program, even if a weak type is used.

Contributor

endobson commented Sep 3, 2012

This is still failing some test cases, but I am pretty sure it is because of pr 13090.

I added a parameter which is the current kind of contract, this is for bottom up restrictions (i.e. -> contracts must be chaperones) versus the argument which is a top down restriction (i.e. key contracts must be a chaperone-contract). This seemed cleaner than adding an extra return value.

This is still broken in a couple cases, but they are smaller than before. And it is just that the error is caught when constructing the contract instead of when constructing the syntax of the contract. The issue is that free variables are not checked to make sure they are used in a valid context. Thus if they are used in a context that requires them to be chaperone contracts, but are bound to a value that requires them to be impersonator contracts the error happens at runtime. Should I fix that in this pull request?

;; tmp.rkt
#lang typed/racket/base

(define-type T (Rec r (-> (U (All (a) (a -> Symbol)) (HashTable r Symbol)))))
(: a T)
(: b T)
(define (b) (plambda: (a) ((x : a)) 'y))
(define (a) (make-hash (list (cons b 'sym))))
(: f (T -> Void))
(define (f x) (void))

(provide a f)

;; tmp2.rkt
#lang racket

(require "tmp.rkt")

(f (hash a 'sym))

Owner

samth commented Sep 19, 2012

Ok, I'm back on this, trying to figure out what's going on in PR 13090.

Owner

samth commented Sep 19, 2012

And 13090 is now fixed, so I'll get to merging this.

Owner

samth commented Sep 24, 2012

This currently has two genuine errors:

--------------------
Typed Racket Tests > Integration tests > succeed > pr10939.rkt > #f
Unnamed test 
FAILURE
message:    "Exception raised"
ssage: "a:empty?: undefined;\n cannot reference an identifier before its definition\n  in module: \"/home/samth/sw/plt/collects/tests/typed-racket/succeed/pr10939.rkt\""
exception:  #(struct:exn:fail:contract "a:empty?: undefined;\n cannot reference an identifier before its definition\n  in module: \"/home/samth/sw/plt/collects/tests/typed-racket/succeed/pr10939.rkt\"" #<continuation-mark-set>)
name:       check-not-exn
location:   main.rkt:81:31
expression: (check-not-exn thnk)
params:     #<procedure:...-racket/main.rkt:73:10>

Check failure
--------------------
--------------------
Typed Racket Tests > Integration tests > succeed > pr11504.rkt > #f
Unnamed test 
FAILURE
message:    "Exception raised"
ssage: "cat?: undefined;\n cannot reference an identifier before its definition\n  in module: \"/home/samth/sw/plt/collects/tests/typed-racket/succeed/pr11504.rkt\""
exception:  #(struct:exn:fail:contract "cat?: undefined;\n cannot reference an identifier before its definition\n  in module: \"/home/samth/sw/plt/collects/tests/typed-racket/succeed/pr11504.rkt\"" #<continuation-mark-set>)
name:       check-not-exn
location:   main.rkt:81:31
expression: (check-not-exn thnk)
params:     #<procedure:...-racket/main.rkt:73:10>

Check failure
--------------------

I'm looking into it.

Owner

samth commented Sep 27, 2012

This was merged as part of #143.

@elibarzilay elibarzilay closed this Oct 4, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment