@@ -472,18 +472,7 @@ fun _checking(e :: Expr, expect-type :: Type, top-level :: Boolean, context :: C
472
472
end )
473
473
else :
474
474
shadow context = misc-collect-example( e, context)
475
-
476
- synthesis( l, false , context). bind( lam ( _, left-type, shadow context) :
477
- cases ( Option <Expr >) r:
478
- | some( shadow r) =>
479
- synthesis( r, false , context). bind( lam ( _, right-type, shadow-context) :
480
- shadow context = context. add-constraint( left-type, right-type)
481
- typing-result( e, expect-type, context)
482
- end )
483
- | none =>
484
- typing-result( e, expect-type, context)
485
- end
486
- end )
475
+ synthesis-s-check-test( e, loc, op, refinement, l, r, context)
487
476
end
488
477
| s-check-expr( l, expr, ann) =>
489
478
synthesis( expr, false , context) # XXX: this should probably use the annotation instead
@@ -748,21 +737,7 @@ fun _synthesis(e :: Expr, top-level :: Boolean, context :: Context) -> TypingRes
748
737
end )
749
738
else :
750
739
shadow context = misc-collect-example( e, context)
751
- synthesis( l, false , context). bind( lam ( _, left-type, shadow context) :
752
- cases ( Option <Expr >) r:
753
- | some( shadow r) =>
754
- synthesis( r, false , context). bind( lam ( _, right-type, shadow-context) :
755
- shadow context = context. add-constraint( left-type, right-type)
756
- result-type = new-existential( loc, false )
757
- shadow context = context. add-variable( result-type)
758
- typing-result( e, result-type, context)
759
- end )
760
- | none =>
761
- result-type = new-existential( loc, false )
762
- shadow context = context. add-variable( result-type)
763
- typing-result( e, result-type, context)
764
- end
765
- end )
740
+ synthesis-s-check-test( e, loc, op, refinement, l, r, context)
766
741
end
767
742
| s-check-expr( l, expr, ann) =>
768
743
synthesis( expr, false , context) # XXX: this should probably use the annotation instead
@@ -2366,6 +2341,109 @@ fun ignore-checker(l :: Loc, binds :: List<A.LetBind>, body :: Expr, blocky, con
2366
2341
handler( l, binds, body, context)
2367
2342
end
2368
2343
end
2344
+ fun synthesis-s-check-test( e :: Expr , loc :: Loc , op :: A . CheckOp , refinement :: Option <Expr >, left :: Expr , right :: Option <Expr >, context :: Context ) -> TypingResult :
2345
+ fun create-result( shadow context :: Context ) -> TypingResult :
2346
+ result-type = new-existential( loc, false )
2347
+ shadow context = context. add-variable( result-type)
2348
+ typing-result( e, result-type, context)
2349
+ end
2350
+
2351
+ fun synthesis-equivalent( l :: Loc ) -> TypingResult :
2352
+ cases ( Option <Expr >) right:
2353
+ | some( shadow right) =>
2354
+ synthesis( left, false , context). bind( lam ( _, left-type, shadow context) :
2355
+ synthesis( right, false , context). bind( lam ( _, right-type, shadow context) :
2356
+ shadow context = context. add-constraint( left-type, right-type)
2357
+ create-result( context)
2358
+ end )
2359
+ end )
2360
+ | none =>
2361
+ raise( "Expected test to have a right hand side" )
2362
+ end
2363
+ end
2364
+
2365
+ fun synthesis-refinement( l :: Loc ) -> TypingResult :
2366
+ cases ( Option <Expr >) refinement:
2367
+ | some( shadow refinement) =>
2368
+ cases ( Option <Expr >) right:
2369
+ | some( shadow right) =>
2370
+ synthesis( left, false , context). bind( lam ( _, left-type, shadow context) :
2371
+ synthesis( right, false , context). bind( lam ( _, right-type, shadow context) :
2372
+ synthesis( refinement, false , context). bind( lam ( _, refinement-type, shadow context) :
2373
+ shadow context = context. add-constraint( refinement-type, t-arrow( [ list: left-type, right-type] , t-boolean( loc) , l, false ))
2374
+ create-result( context)
2375
+ end )
2376
+ end )
2377
+ end )
2378
+ | none =>
2379
+ raise( "Expected test to have a right hand side" )
2380
+ end
2381
+ | none =>
2382
+ synthesis-equivalent( l)
2383
+ end
2384
+ end
2385
+
2386
+ fun synthesis-predicate( l :: Loc ) -> TypingResult :
2387
+ cases ( Option <Expr >) right:
2388
+ | some( shadow right) =>
2389
+ synthesis( left, false , context). bind( lam ( _, left-type, shadow context) :
2390
+ synthesis( right, false , context). bind( lam ( _, pred-type, shadow context) :
2391
+ shadow context = context. add-constraint( pred-type, t-arrow( [ list: left-type] , t-boolean( loc) , l, false ))
2392
+ create-result( context)
2393
+ end )
2394
+ end )
2395
+ | none =>
2396
+ raise( "Expected test to have a right hand side" )
2397
+ end
2398
+ end
2399
+
2400
+ fun synthesis-string( l :: Loc ) -> TypingResult :
2401
+ cases ( Option <Expr >) right:
2402
+ | some( shadow right) =>
2403
+ synthesis( left, false , context). bind( lam ( _, left-type, shadow context) :
2404
+ checking( right, t-string( loc) , false , context). bind( lam ( _, _, shadow context) :
2405
+ create-result( context)
2406
+ end )
2407
+ end )
2408
+ | none =>
2409
+ raise( "Expected test to have a right hand side" )
2410
+ end
2411
+ end
2412
+
2413
+ fun synthesis-exception( l :: Loc ) -> TypingResult :
2414
+ cases ( Option <Expr >) right:
2415
+ | some( shadow right) =>
2416
+ synthesis( left, false , context). bind( lam ( _, left-type, shadow context) :
2417
+ synthesis( right, false , context). bind( lam ( _, pred-type, shadow context) :
2418
+ shadow context = context. add-constraint( pred-type, t-arrow( [ list: t-top( l, false ) ] , t-boolean( loc) , l, false ))
2419
+ create-result( context)
2420
+ end )
2421
+ end )
2422
+ | none =>
2423
+ raise( "Expected test to have a right hand side" )
2424
+ end
2425
+ end
2426
+
2427
+ cases ( A . CheckOp ) op:
2428
+ | s-op-is( l) => synthesis-refinement( l)
2429
+ | s-op-is-roughly( l) => synthesis-equivalent( l)
2430
+ | s-op-is-op( l, _) => synthesis-equivalent( l)
2431
+ | s-op-is-not( l) => synthesis-refinement( l)
2432
+ | s-op-is-not-op( l, _) => synthesis-equivalent( l)
2433
+ | s-op-satisfies( l) => synthesis-predicate( l)
2434
+ | s-op-satisfies-not( l) => synthesis-predicate( l)
2435
+ | s-op-raises( l) => synthesis-string( l)
2436
+ | s-op-raises-other( l) => synthesis-string( l)
2437
+ | s-op-raises-not( l) =>
2438
+ synthesis( left, false , context). bind( lam ( _, left-type, shadow context) :
2439
+ create-result( context)
2440
+ end )
2441
+ | s-op-raises-satisfies( l) =>
2442
+ synthesis-exception( l)
2443
+ | s-op-raises-violates( l) =>
2444
+ synthesis-exception( l)
2445
+ end
2446
+ end
2369
2447
2370
2448
################### Test Inference ####################
2371
2449
0 commit comments