From 484a920b4e637965109144b72bcd4a3756efa357 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Georges=20Dup=C3=A9ron?= Date: Mon, 7 Dec 2015 17:50:54 +0100 Subject: [PATCH] Found source of bug with promises type: locally-defined recursive types can't be used (inferred) in other modules, see TR issue #262 https://github.com/racket/typed-racket/issues/262 . --- graph/graph/__DEBUG_graph_1__.rkt | 46 ++++++++++++++++++++++++++++ graph/graph/__DEBUG_graph_2__.rkt | 21 +++++++++++++ graph/graph/__DEBUG_graph__.rkt | 14 ++++++--- graph/graph/__DEBUG_graph_lift__.rkt | 9 ++++++ graph/graph/graph3.lp2.rkt | 9 +++--- 5 files changed, 90 insertions(+), 9 deletions(-) create mode 100644 graph/graph/__DEBUG_graph_1__.rkt create mode 100644 graph/graph/__DEBUG_graph_2__.rkt create mode 100644 graph/graph/__DEBUG_graph_lift__.rkt diff --git a/graph/graph/__DEBUG_graph_1__.rkt b/graph/graph/__DEBUG_graph_1__.rkt new file mode 100644 index 0000000..bbb5d96 --- /dev/null +++ b/graph/graph/__DEBUG_graph_1__.rkt @@ -0,0 +1,46 @@ +#lang typed/racket + +#| +(module m typed/racket + (define foo + (let () + (define-type Foo (Pairof (Promise Foo) Number)) + + (define (f [n : Number]) : Foo + (cons (delay (f (add1 n))) + n)) + (f 1))) + + (provide foo)) + +(require 'm) +(force (car foo)) +|# + +(define-type (P A) (Pairof (U A Null) (U A Null))) + +(define bar + (let () + (define-type Bar (Pairof (P Bar) Number)) + + (define (f [n : Number]) : Bar + (cons (ann (cons '() '()) (P Bar)) + n)) + + (f 1))) + +(provide P bar) + +#| +(define foo + (let () + ;(define-type Foo (Rec F (Pairof (Promise F) Number))) + (define-type Foo (Pairof (Promise Foo) Number)) + + (define (f [n : Number]) : Foo + (cons (delay (f (add1 n))) + n)) + (f 1))) + +(provide foo) +|# \ No newline at end of file diff --git a/graph/graph/__DEBUG_graph_2__.rkt b/graph/graph/__DEBUG_graph_2__.rkt new file mode 100644 index 0000000..1223c93 --- /dev/null +++ b/graph/graph/__DEBUG_graph_2__.rkt @@ -0,0 +1,21 @@ +#lang typed/racket + +(module m typed/racket + (define-type (TFoo A B) (List 'foo (U (TFoo A B) (TBar A B) A))) + (define-type (TBar A B) (List 'bar (U (TFoo A B) (TBar A B) B))) + + (define foo + (let () + (define-type Foo (TFoo One Zero)) + (define-type Bar (TBar One Zero)) + + (ann (list 'foo 1) Foo))) + + (provide foo)) + +(require 'm) + +(: f (∀ (A) (→ (List Symbol A) Any))) +(define (f x) 2) + +(f foo) \ No newline at end of file diff --git a/graph/graph/__DEBUG_graph__.rkt b/graph/graph/__DEBUG_graph__.rkt index 2082888..bbf98f0 100644 --- a/graph/graph/__DEBUG_graph__.rkt +++ b/graph/graph/__DEBUG_graph__.rkt @@ -1,9 +1,15 @@ -#lang typed/racket +#lang debug typed/racket (require (submod "graph3.lp2.rkt" test)) (require racket/list) -(force (car (second g))) -;(map force (second g)) +;#R(force (second g)) -;(map force (third g)) +(ann g 1) + +#| +#R(force (caadr (force (car (second g))))) +#R(map force (second g)) + +#R(map force (third g)) +|# \ No newline at end of file diff --git a/graph/graph/__DEBUG_graph_lift__.rkt b/graph/graph/__DEBUG_graph_lift__.rkt new file mode 100644 index 0000000..92d5ca2 --- /dev/null +++ b/graph/graph/__DEBUG_graph_lift__.rkt @@ -0,0 +1,9 @@ +#lang typed/racket + +(define-syntax (l stx) + #`(let () + #,(syntax-local-lift-expression #'(begin (define-type Foo (List 'foo Foo Bar One)) (void))) + #,(syntax-local-lift-expression #'(begin (define-type Bar (List 'foo Foo Bar One)) (void))) + 1)) + +(l) \ No newline at end of file diff --git a/graph/graph/graph3.lp2.rkt b/graph/graph/graph3.lp2.rkt index 8e8bf69..2c25e1f 100644 --- a/graph/graph/graph3.lp2.rkt +++ b/graph/graph/graph3.lp2.rkt @@ -330,11 +330,10 @@ Then we define the @tc[node/make-placeholder] function: @subsection{Making with-indices nodes} -We derive the @tc[with-indices] type from each @emph{ideal} node type using -the @tc[tmpl-replace-in-type] template metafunction from the rewrite-type -library. We replace all occurrences of a @tc[node] name with an @tc[Index], -which indicates at which index in the queue's results the successor can be -found. +We derive the @tc[with-indices] type from each @emph{ideal} node type using the +@tc[tmpl-replace-in-type] template metafunction from the rewrite-type library. +We replace all occurrences of a @tc[node] name with an @tc[Index], which +indicates at which index in the queue's results the successor can be found. @; TODO: use a type-expander here, instead of a template metafunction.