@@ -4,7 +4,7 @@ use std::sync::Arc;
44use fxhash:: FxHashMap ;
55use scoped_arena:: Scope ;
66
7- use crate :: core:: semantics:: { ArcValue , Elim , ElimEnv , Value } ;
7+ use crate :: core:: semantics:: { ArcValue , Elim , ElimEnv , Head , Value } ;
88use crate :: core:: { self , Const , Plicity , Prim , UIntStyle } ;
99use crate :: env:: { self , SharedEnv , UniqueEnv } ;
1010use crate :: source:: { Span , Spanned , StringId , StringInterner } ;
@@ -58,17 +58,6 @@ impl<'arena> Env<'arena> {
5858 let mut env = EnvBuilder :: new ( interner, scope) ;
5959
6060 env. define_prim ( VoidType , & UNIVERSE ) ;
61- // fun (A : Type) -> Void -> A
62- env. define_prim (
63- Absurd ,
64- & core:: Term :: FunType (
65- Span :: Empty ,
66- Plicity :: Explicit ,
67- env. name ( "A" ) ,
68- & UNIVERSE ,
69- & core:: Term :: FunType ( Span :: Empty , Plicity :: Explicit , None , & VOID_TYPE , & VAR1 ) ,
70- ) ,
71- ) ;
7261 env. define_prim ( BoolType , & UNIVERSE ) ;
7362 env. define_prim ( U8Type , & UNIVERSE ) ;
7463 env. define_prim ( U16Type , & UNIVERSE ) ;
@@ -122,8 +111,8 @@ impl<'arena> Env<'arena> {
122111 FormatDeref ,
123112 & core:: Term :: FunType (
124113 Span :: Empty ,
125- Plicity :: Explicit ,
126- env. name ( "A " ) ,
114+ Plicity :: Implicit ,
115+ env. name ( "f " ) ,
127116 & FORMAT_TYPE ,
128117 & Term :: FunType (
129118 Span :: Empty ,
@@ -144,7 +133,7 @@ impl<'arena> Env<'arena> {
144133 FormatSucceed ,
145134 & core:: Term :: FunType (
146135 Span :: Empty ,
147- Plicity :: Explicit ,
136+ Plicity :: Implicit ,
148137 env. name ( "A" ) ,
149138 & UNIVERSE ,
150139 & Term :: FunType ( Span :: Empty , Plicity :: Explicit , None , & VAR0 , & FORMAT_TYPE ) ,
@@ -153,11 +142,11 @@ impl<'arena> Env<'arena> {
153142 env. define_prim ( FormatFail , & FORMAT_TYPE ) ;
154143 env. define_prim (
155144 FormatUnwrap ,
156- // fun (A : Type) -> Option A -> Format
157- // fun (A : Type) -> Option A@0 -> Format
145+ // fun (@ A : Type) -> Option A -> Format
146+ // fun (@ A : Type) -> Option A@0 -> Format
158147 & core:: Term :: FunType (
159148 Span :: Empty ,
160- Plicity :: Explicit ,
149+ Plicity :: Implicit ,
161150 env. name ( "A" ) ,
162151 & UNIVERSE ,
163152 & Term :: FunType (
@@ -176,6 +165,18 @@ impl<'arena> Env<'arena> {
176165 ) ;
177166 env. define_prim_fun ( FormatRepr , [ & FORMAT_TYPE ] , & UNIVERSE ) ;
178167
168+ // fun (@A : Type) -> Void -> A
169+ env. define_prim (
170+ Absurd ,
171+ & core:: Term :: FunType (
172+ Span :: Empty ,
173+ Plicity :: Implicit ,
174+ env. name ( "A" ) ,
175+ & UNIVERSE ,
176+ & core:: Term :: FunType ( Span :: Empty , Plicity :: Explicit , None , & VOID_TYPE , & VAR1 ) ,
177+ ) ,
178+ ) ;
179+
179180 env. define_prim_fun ( BoolEq , [ & BOOL_TYPE , & BOOL_TYPE ] , & BOOL_TYPE ) ;
180181 env. define_prim_fun ( BoolNeq , [ & BOOL_TYPE , & BOOL_TYPE ] , & BOOL_TYPE ) ;
181182 env. define_prim_fun ( BoolNot , [ & BOOL_TYPE ] , & BOOL_TYPE ) ;
@@ -309,11 +310,11 @@ impl<'arena> Env<'arena> {
309310
310311 env. define_prim (
311312 OptionSome ,
312- // fun (A : Type) -> A -> Option A
313- // fun (A : Type) -> A@0 -> Option A@1
313+ // fun (@ A : Type) -> A -> Option A
314+ // fun (@ A : Type) -> A@0 -> Option A@1
314315 & core:: Term :: FunType (
315316 Span :: Empty ,
316- Plicity :: Explicit ,
317+ Plicity :: Implicit ,
317318 env. name ( "A" ) ,
318319 & UNIVERSE ,
319320 & Term :: FunType (
@@ -332,11 +333,11 @@ impl<'arena> Env<'arena> {
332333 ) ;
333334 env. define_prim (
334335 OptionNone ,
335- // fun (A : Type) -> Option A
336- // fun (A : Type) -> Option A@0
336+ // fun (@ A : Type) -> Option A
337+ // fun (@ A : Type) -> Option A@0
337338 & core:: Term :: FunType (
338339 Span :: Empty ,
339- Plicity :: Explicit ,
340+ Plicity :: Implicit ,
340341 env. name ( "A" ) ,
341342 & UNIVERSE ,
342343 & Term :: FunApp (
@@ -349,16 +350,16 @@ impl<'arena> Env<'arena> {
349350 ) ;
350351 env. define_prim (
351352 OptionFold ,
352- // fun (A : Type) (B : Type) -> B -> (A -> B ) -> Option A -> B
353- // fun (A : Type) (B : Type) -> B@0 -> (A@2 -> B@2) -> Option A@3 -> B@3
353+ // fun (@ A : Type) (@ B : Type) -> B -> (A -> B ) -> Option A -> B
354+ // fun (@ A : Type) (@ B : Type) -> B@0 -> (A@2 -> B@2) -> Option A@3 -> B@3
354355 scope. to_scope ( core:: Term :: FunType (
355356 Span :: Empty ,
356- Plicity :: Explicit ,
357+ Plicity :: Implicit ,
357358 env. name ( "A" ) ,
358359 & UNIVERSE ,
359360 scope. to_scope ( core:: Term :: FunType (
360361 Span :: Empty ,
361- Plicity :: Explicit ,
362+ Plicity :: Implicit ,
362363 env. name ( "B" ) ,
363364 & UNIVERSE ,
364365 scope. to_scope ( core:: Term :: FunType (
@@ -391,17 +392,18 @@ impl<'arena> Env<'arena> {
391392 ) ) ,
392393 ) ;
393394
394- // fun (len : UN) (A : Type) -> (A -> Bool) -> ArrayN len A -> Option A
395- // fun (len : UN) (A : Type) -> (A@0 -> Bool) -> ArrayN len@2 A@1 -> Option A@2
395+ // fun (@len : UN) (@A : Type) -> (A -> Bool) -> ArrayN len A -> Option A
396+ // fun (@len : UN) (@A : Type) -> (A@0 -> Bool) -> ArrayN len@2 A@1 -> Option
397+ // A@2
396398 let find_type = |index_type, array_type| {
397399 scope. to_scope ( core:: Term :: FunType (
398400 Span :: Empty ,
399- Plicity :: Explicit ,
401+ Plicity :: Implicit ,
400402 env. name ( "len" ) ,
401403 index_type,
402404 scope. to_scope ( core:: Term :: FunType (
403405 Span :: Empty ,
404- Plicity :: Explicit ,
406+ Plicity :: Implicit ,
405407 env. name ( "A" ) ,
406408 & UNIVERSE ,
407409 scope. to_scope ( core:: Term :: FunType (
@@ -447,17 +449,17 @@ impl<'arena> Env<'arena> {
447449 env. define_prim ( Array32Find , array32_find_type) ;
448450 env. define_prim ( Array64Find , array64_find_type) ;
449451
450- // fun (len : UN) -> ( A : Type) -> (index : UN) -> ArrayN len A -> A
451- // fun (len : UN) -> ( A : Type) -> (index : UN) -> ArrayN len@2 A@1 -> A@2
452+ // fun (@ len : UN) (@ A : Type) (index : UN) -> ArrayN len A -> A
453+ // fun (@ len : UN) (@ A : Type) (index : UN) -> ArrayN len@2 A@1 -> A@2
452454 let array_index_type = |index_type, array_type| {
453455 scope. to_scope ( core:: Term :: FunType (
454456 Span :: Empty ,
455- Plicity :: Explicit ,
457+ Plicity :: Implicit ,
456458 env. name ( "len" ) ,
457459 index_type,
458460 scope. to_scope ( core:: Term :: FunType (
459461 Span :: Empty ,
460- Plicity :: Explicit ,
462+ Plicity :: Implicit ,
461463 env. name ( "A" ) ,
462464 & UNIVERSE ,
463465 scope. to_scope ( core:: Term :: FunType (
@@ -574,7 +576,7 @@ pub type Step = for<'arena> fn(&ElimEnv<'arena, '_>, &[Elim<'arena>]) -> Option<
574576macro_rules! step {
575577 ( $env: pat, [ $( $param: pat) ,* ] => $body: expr) => {
576578 |$env, spine| match spine {
577- [ $( Elim :: FunApp ( Plicity :: Explicit , $param) ) ,* ] => Some ( $body) ,
579+ [ $( Elim :: FunApp ( _ , $param) ) ,* ] => Some ( $body) ,
578580 _ => return None ,
579581 }
580582 } ;
@@ -782,30 +784,38 @@ pub fn step(prim: Prim) -> Step {
782784
783785 Prim :: OptionFold => step ! ( env, [ _, _, on_none, on_some, option] => {
784786 match option. match_prim_spine( ) ? {
785- ( Prim :: OptionSome , [ Elim :: FunApp ( Plicity :: Explicit , value) ] ) => env . fun_app (
786- Plicity :: Explicit ,
787- on_some . clone ( ) , value . clone ( ) ) ,
788- ( Prim :: OptionNone , [ ] ) => on_none. clone( ) ,
787+ ( Prim :: OptionSome , [ _ , Elim :: FunApp ( Plicity :: Explicit , value) ] ) => {
788+ env . fun_app ( Plicity :: Explicit , on_some . clone ( ) , value . clone ( ) )
789+ } ,
790+ ( Prim :: OptionNone , [ _ ] ) => on_none. clone( ) ,
789791 _ => return None ,
790792 }
791793 } ) ,
792794
793795 Prim :: Array8Find | Prim :: Array16Find | Prim :: Array32Find | Prim :: Array64Find => {
794- step ! ( env, [ _, _ , pred, array] => match array. as_ref( ) {
796+ step ! ( env, [ _, elem_type , pred, array] => match array. as_ref( ) {
795797 Value :: ArrayLit ( elems) => {
796798 for elem in elems {
797799 match env. fun_app(
798- Plicity :: Explicit ,
799- pred. clone( ) , elem. clone( ) ) . as_ref( ) {
800+ Plicity :: Explicit ,
801+ pred. clone( ) , elem. clone( ) ) . as_ref( ) {
800802 Value :: ConstLit ( Const :: Bool ( true ) ) => {
801- // TODO: Is elem.span right here?
802- return Some ( Spanned :: new( elem. span( ) , Arc :: new( Value :: prim( Prim :: OptionSome , [ elem. clone( ) ] ) ) ) )
803+ return Some ( Spanned :: empty( Arc :: new( Value :: Stuck (
804+ Head :: Prim ( Prim :: OptionSome ) ,
805+ vec![
806+ Elim :: FunApp ( Plicity :: Implicit , elem_type. clone( ) ) ,
807+ Elim :: FunApp ( Plicity :: Explicit , elem. clone( ) ) ,
808+ ] ,
809+ ) ) ) ) ;
803810 } ,
804811 Value :: ConstLit ( Const :: Bool ( false ) ) => { }
805812 _ => return None ,
806813 }
807814 }
808- Spanned :: empty( Arc :: new( Value :: prim( Prim :: OptionNone , [ ] ) ) )
815+ Spanned :: empty( Arc :: new( Value :: Stuck (
816+ Head :: Prim ( Prim :: OptionNone ) ,
817+ vec![ Elim :: FunApp ( Plicity :: Implicit , elem_type. clone( ) ) ] ,
818+ ) ) )
809819 }
810820 _ => return None ,
811821 } )
0 commit comments