Skip to content

Commit e75d9a8

Browse files
authored
add flag to disable static contract optimization (#1156)
1 parent 8faea14 commit e75d9a8

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

typed-racket-doc/typed-racket/scribblings/reference/optimization.scrbl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,13 @@ is insufficiently powerful to access @racketmodname[racket/unsafe/ops],
2727
for example when executing in a sandbox (see @secref["Sandboxed_Evaluation"
2828
#:doc '(lib "scribblings/reference/reference.scrbl")]). This prevents untrusted
2929
code from accessing these operations by exploiting errors in the type system.
30+
31+
32+
@section{Contract Optimization}
33+
34+
Typed Racket generates contracts for its exports to protect them against
35+
untyped code.
36+
By default, these contracts do not check that typed code obeys the types.
37+
If you want to generate contracts that check both sides equally (for analysis,
38+
for teaching, etc.) then set the environment variable
39+
@envvar{PLT_TR_NO_CONTRACT_OPTIMIZE} to any value and recompile.

typed-racket-lib/typed-racket/static-contracts/instantiate.rkt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
compute-recursive-kinds
4141
instantiate/inner))
4242

43+
(define no-optimize-sc? (and (getenv "PLT_TR_NO_CONTRACT_OPTIMIZE") #t))
44+
4345
(define (instantiate/optimize sc fail [kind 'impersonator] #:cache [cache #f] #:trusted-positive [trusted-positive #f] #:trusted-negative [trusted-negative #f])
4446
(define recursive-kinds
4547
(with-handlers [(exn:fail:constraint-failure?
@@ -53,7 +55,7 @@
5355
#f))]
5456
(compute-recursive-kinds
5557
(contract-restrict-recursive-values (compute-constraints sc kind)))))
56-
(define sc/opt (optimize sc #:trusted-positive trusted-positive #:trusted-negative trusted-negative #:recursive-kinds recursive-kinds))
58+
(define sc/opt (if no-optimize-sc? sc (optimize sc #:trusted-positive trusted-positive #:trusted-negative trusted-negative #:recursive-kinds recursive-kinds)))
5759
(instantiate sc/opt fail kind #:cache cache #:recursive-kinds recursive-kinds))
5860

5961
;; kind is the greatest kind of contract that is supported, if a greater kind would be produced the

0 commit comments

Comments
 (0)