improve spawn error messages

This commit is contained in:
Sam Caldwell 2020-02-25 16:14:30 -05:00
parent f8c385e31d
commit 480feb961c
2 changed files with 58 additions and 3 deletions

View File

@ -326,9 +326,9 @@
"Spawned actors not valid in dataspace"
#:fail-unless (project-safe? ( (strip-? #'τ-o) #'τ-c.norm)
#'τ-i)
"Not prepared to handle all inputs"
#:fail-unless (project-safe? #'τ-o/i #'τ-i/i)
"Not prepared to handle internal events"
(string-append "Not prepared to handle inputs:\n" (make-actor-error-message #'τ-i #'τ-o #'τ-c.norm))
#:fail-unless (project-safe? ( (strip-? #'τ-o/i) #'τ-o/i) #'τ-i/i)
(string-append "Not prepared to handle internal events:\n" (make-actor-error-message #'τ-i/i #'τ-o/i #'τ-o/i))
--------------------------------------------------------------------------------------------
[ (syndicate:spawn (syndicate:on-start s-)) ( : ★/t)
( ν-s (τ-final))]]
@ -338,6 +338,26 @@
----------------------------------------
[ (spawn #,τc s)]])
;; Type Type Type -> String
(define-for-syntax (make-actor-error-message τ-i τ-o τ-c)
(define mismatches (find-surprising-inputs τ-i τ-o τ-c))
(string-join (map type->str mismatches) ",\n"))
;; Type Type Type -> (Listof Type)
(define-for-syntax (find-surprising-inputs τ-i τ-o τ-c)
(define incoming ( (strip-? τ-o) τ-c))
;; Type -> (Listof Type)
(let loop ([ty incoming])
(syntax-parse ty
[(~U* τ ...)
(apply append (map loop (syntax->list #'(τ ...))))]
[_
(cond
[(project-safe? ty τ-i)
'()]
[else
(list ty)])])))
(define-typed-syntax (dataspace τ-c:type s ...)
#:fail-unless (flat-type? #'τ-c.norm) "Communication type must be first-order"
#:mode (communication-type-mode #'τ-c.norm)

View File

@ -0,0 +1,35 @@
#lang typed/syndicate/roles
(require rackunit/turnstile)
(check-type
(spawn (U (Tuple Int) (Observe (Tuple ★/t)))
(start-facet _
(on (asserted (tuple $x))
(add1 x))))
;; wanted: ν-s ((Actor (Tuple Int)))
: ★/t)
(typecheck-fail
(spawn (U (Tuple String) (Observe (Tuple ★/t)))
(start-facet _
(on (asserted (tuple $x:Int))
(add1 x))))
#:with-msg "spawn: Not prepared to handle inputs:\n\\(Tuple- String\\)")
(check-type
(spawn (U)
(start-facet _
(know (tuple 5))
(on (know (tuple $x:Int))
(add1 x))))
;; wanted: ν-s ((Actor (U)))
: ★/t)
(typecheck-fail
(spawn (U)
(start-facet _
(know (tuple "hi"))
(on (know (tuple $x:Int))
(add1 x))))
#:with-msg "spawn: Not prepared to handle internal events:\n\\(Tuple- String\\)")