fix exception handling for booting actors

This commit is contained in:
Sam Caldwell 2017-03-13 15:28:14 -04:00
parent 6ee97839fa
commit fb3918404c
1 changed files with 34 additions and 15 deletions

View File

@ -501,20 +501,23 @@
;; boot-actor : actor Γ -> Action ;; boot-actor : actor Γ -> Action
(define (boot-actor a Γ) (define (boot-actor a Γ)
(match a (with-handlers ([exn:fail? (lambda (e)
[`(actor ,facet) (eprintf "booting actor died with: ~v\n" e)
(define-values (_ as ft) (boot-facet facet Γ mt-σ)) #f)])
(define assertions (ft-assertions ft mt-Γ mt-σ)) (match a
(spawn-upside-down [`(actor ,facet)
(actor actor-behavior (define-values (_ as ft) (boot-facet facet Γ mt-σ))
(actor-state trie-empty ft) (define assertions (ft-assertions ft mt-Γ mt-σ))
(cons (scn assertions) as)))] (spawn-upside-down
[`(dataspace ,as ...) (actor actor-behavior
(define boot-actions (for/list ([a (in-list as)]) (boot-actor a Γ))) (actor-state trie-empty ft)
;; note the recursive upside-down wrapping of dataspaces-- (cons (scn assertions) as)))]
;; the upside-down-relay is needed for things to line up properly [`(dataspace ,as ...)
(spawn-upside-down (define boot-actions (for/list ([a (in-list as)]) (boot-actor a Γ)))
(dataspace-actor (cons upside-down-relay boot-actions)))])) ;; note the recursive upside-down wrapping of dataspaces--
;; the upside-down-relay is needed for things to line up properly
(spawn-upside-down
(dataspace-actor (cons upside-down-relay boot-actions)))])))
;; dollar-id? : any -> bool ;; dollar-id? : any -> bool
;; test if the input is a symbol whose first character is $ ;; test if the input is a symbol whose first character is $
@ -932,8 +935,24 @@
(actor (react (assert "hello")))))) (actor (react (assert "hello"))))))
(module+ test (module+ test
;; this should bring down the actor *but not* the entire program
(define escaping-field (define escaping-field
'((actor (react (field x #f) '((actor (react (field x #f)
(on-start (react (field y 10) (on-start (react (field y 10)
(on-start (set! x (lambda (v) (set! y v))))) (on-start (set! x (lambda (v) (set! y v)))))
((read x) 5))))))) ((read x) 5)
(send! "success!"))))))
(check-false (run-with-trace (trace (message "success!"))
escaping-field))
(check-not-exn (lambda () (run escaping-field))))
(module+ test
;; starting exceptions
(define nested-spawn-exceptions
'(
(actor (react (on (message "go")
(actor (react (on-start (/ 1 0))))
(send! "lovely happiness"))))
(actor (react (on-start (send! "go"))))))
(test-trace (trace (message "lovely happiness"))
nested-spawn-exceptions))