diff --git a/src/definedness.ml b/src/definedness.ml index ae4616de360..32a5c18c19b 100644 --- a/src/definedness.ml +++ b/src/definedness.ml @@ -198,4 +198,8 @@ and decs msgs decs : f = M.disjoint_union (map_of_set Eager e) (map_of_set Delayed d) |> M.filter (fun v _ -> M.mem v defWhen = false) -let check_prog msgs prog = ignore (decs msgs prog.it) +let check_prog prog = + Diag.with_message_store (fun msgs -> + ignore (decs msgs prog.it); + Some () + ) diff --git a/src/definedness.mli b/src/definedness.mli index 845edb6c6c8..a2f983e4002 100644 --- a/src/definedness.mli +++ b/src/definedness.mli @@ -1 +1 @@ -val check_prog : Diag.msg_store -> Syntax.prog -> unit +val check_prog : Syntax.prog -> unit Diag.result diff --git a/src/pipeline.ml b/src/pipeline.ml index bda5cdb204d..ffdd713f0a7 100644 --- a/src/pipeline.ml +++ b/src/pipeline.ml @@ -137,6 +137,14 @@ let typecheck_library senv filename prog : Typing.scope Diag.result = phase "Checking" prog.Source.note; Typing.check_library senv (filename, prog) +(* Definedness checking *) + +let defindeness_prog prog : unit Diag.result = + phase "Definedness" prog.Source.note; + Definedness.check_prog prog + +let defindeness_progs progs : unit Diag.result = + Diag.traverse_ defindeness_prog progs (* Imported file loading *) @@ -189,11 +197,12 @@ let chase_imports senv0 imports : (Syntax.libraries * Typing.scope) Diag.result Diag.bind (Resolve_import.resolve prog base) (fun more_imports -> Diag.bind (go_set more_imports) (fun () -> Diag.bind (typecheck_library !senv f prog) (fun sscope -> + Diag.bind (defindeness_prog prog) (fun () -> libraries := (f, prog) :: !libraries; (* NB: Conceptually an append *) senv := Typing.adjoin_scope !senv sscope; pending := remove f !pending; Diag.return () - ))))) + )))))) end and go_set todo = Diag.traverse_ go (elements todo) in @@ -208,8 +217,9 @@ let load_progs parse senv : load_result = (List.map snd rs) in Diag.bind (chase_imports senv libraries) (fun (libraries, senv') -> Diag.bind (typecheck_progs senv' progs') (fun senv'' -> + Diag.bind (defindeness_progs progs') (fun _ -> Diag.return (libraries, progs', senv'') - )))) + ))))) let load_decl parse_one senv : load_decl_result = Diag.bind parse_one (fun parsed -> diff --git a/src/typing.ml b/src/typing.ml index 61e09bdfbc0..030f33bf4b6 100644 --- a/src/typing.ml +++ b/src/typing.ml @@ -1492,7 +1492,6 @@ let infer_prog scope prog : (T.typ * scope) Diag.result = (fun prog -> let env = env_of_scope msgs scope in let res = infer_block env prog.it prog.at in - Definedness.check_prog msgs prog; res ) prog @@ -1513,7 +1512,6 @@ let check_library scope (filename, prog) : scope Diag.result = (fun prog -> let env = env_of_scope msgs scope in let typ = infer_library env prog.it prog.at in - Definedness.check_prog msgs prog; library_scope filename typ ) prog diff --git a/test/fail/ok/ast81-clash.run-ir.ok b/test/fail/ok/ast81-clash.run-ir.ok deleted file mode 100644 index a44cd01d45f..00000000000 --- a/test/fail/ok/ast81-clash.run-ir.ok +++ /dev/null @@ -1,63 +0,0 @@ -prelude:189.1-214.2: internal error, Env.Make(X).Clash("x") - -Last environment: -@new_async = func -@text_of_Bool = func -@text_of_Int = func -@text_of_Nat = func -@text_of_Text = func -@text_of_array = func -@text_of_array_mut = func -@text_of_option = func -@text_of_variant = func -Array_init = func -Array_tabulate = func -abs = func -btstWord16 = func -btstWord32 = func -btstWord64 = func -btstWord8 = func -charToText = func -charToWord32 = func -clzWord16 = func -clzWord32 = func -clzWord64 = func -clzWord8 = func -ctzWord16 = func -ctzWord32 = func -ctzWord64 = func -ctzWord8 = func -decodeUTF8 = func -hashInt = func -ignore = func -intToWord16 = func -intToWord32 = func -intToWord64 = func -intToWord8 = func -natToWord16 = func -natToWord32 = func -natToWord64 = func -natToWord8 = func -popcntWord16 = func -popcntWord32 = func -popcntWord64 = func -popcntWord8 = func -print = func -printChar = func -printInt = func -range = func -revrange = func -shrsWord16 = func -shrsWord32 = func -shrsWord64 = func -shrsWord8 = func -word16ToInt = func -word16ToNat = func -word32ToChar = func -word32ToInt = func -word32ToNat = func -word64ToInt = func -word64ToNat = func -word8ToInt = func -word8ToNat = func - diff --git a/test/fail/ok/ast81-clash.run-low.ok b/test/fail/ok/ast81-clash.run-low.ok deleted file mode 100644 index a44cd01d45f..00000000000 --- a/test/fail/ok/ast81-clash.run-low.ok +++ /dev/null @@ -1,63 +0,0 @@ -prelude:189.1-214.2: internal error, Env.Make(X).Clash("x") - -Last environment: -@new_async = func -@text_of_Bool = func -@text_of_Int = func -@text_of_Nat = func -@text_of_Text = func -@text_of_array = func -@text_of_array_mut = func -@text_of_option = func -@text_of_variant = func -Array_init = func -Array_tabulate = func -abs = func -btstWord16 = func -btstWord32 = func -btstWord64 = func -btstWord8 = func -charToText = func -charToWord32 = func -clzWord16 = func -clzWord32 = func -clzWord64 = func -clzWord8 = func -ctzWord16 = func -ctzWord32 = func -ctzWord64 = func -ctzWord8 = func -decodeUTF8 = func -hashInt = func -ignore = func -intToWord16 = func -intToWord32 = func -intToWord64 = func -intToWord8 = func -natToWord16 = func -natToWord32 = func -natToWord64 = func -natToWord8 = func -popcntWord16 = func -popcntWord32 = func -popcntWord64 = func -popcntWord8 = func -print = func -printChar = func -printInt = func -range = func -revrange = func -shrsWord16 = func -shrsWord32 = func -shrsWord64 = func -shrsWord8 = func -word16ToInt = func -word16ToNat = func -word32ToChar = func -word32ToInt = func -word32ToNat = func -word64ToInt = func -word64ToNat = func -word8ToInt = func -word8ToNat = func - diff --git a/test/fail/ok/ast81-clash.run.ok b/test/fail/ok/ast81-clash.run.ok deleted file mode 100644 index a44cd01d45f..00000000000 --- a/test/fail/ok/ast81-clash.run.ok +++ /dev/null @@ -1,63 +0,0 @@ -prelude:189.1-214.2: internal error, Env.Make(X).Clash("x") - -Last environment: -@new_async = func -@text_of_Bool = func -@text_of_Int = func -@text_of_Nat = func -@text_of_Text = func -@text_of_array = func -@text_of_array_mut = func -@text_of_option = func -@text_of_variant = func -Array_init = func -Array_tabulate = func -abs = func -btstWord16 = func -btstWord32 = func -btstWord64 = func -btstWord8 = func -charToText = func -charToWord32 = func -clzWord16 = func -clzWord32 = func -clzWord64 = func -clzWord8 = func -ctzWord16 = func -ctzWord32 = func -ctzWord64 = func -ctzWord8 = func -decodeUTF8 = func -hashInt = func -ignore = func -intToWord16 = func -intToWord32 = func -intToWord64 = func -intToWord8 = func -natToWord16 = func -natToWord32 = func -natToWord64 = func -natToWord8 = func -popcntWord16 = func -popcntWord32 = func -popcntWord64 = func -popcntWord8 = func -print = func -printChar = func -printInt = func -range = func -revrange = func -shrsWord16 = func -shrsWord32 = func -shrsWord64 = func -shrsWord8 = func -word16ToInt = func -word16ToNat = func -word32ToChar = func -word32ToInt = func -word32ToNat = func -word64ToInt = func -word64ToNat = func -word8ToInt = func -word8ToNat = func - diff --git a/test/fail/ok/ast81-clash.tc.ok b/test/fail/ok/ast81-clash.tc.ok index d24e7265597..5523bebdb52 100644 --- a/test/fail/ok/ast81-clash.tc.ok +++ b/test/fail/ok/ast81-clash.tc.ok @@ -1 +1 @@ -Fatal error: exception Env.Make(X).Clash("x") +ast81-clash.as:8.11-8.12: type error, duplicate definition for x in block diff --git a/test/fail/ok/ast81-clash.wasm.stderr.ok b/test/fail/ok/ast81-clash.wasm.stderr.ok deleted file mode 100644 index a44cd01d45f..00000000000 --- a/test/fail/ok/ast81-clash.wasm.stderr.ok +++ /dev/null @@ -1,63 +0,0 @@ -prelude:189.1-214.2: internal error, Env.Make(X).Clash("x") - -Last environment: -@new_async = func -@text_of_Bool = func -@text_of_Int = func -@text_of_Nat = func -@text_of_Text = func -@text_of_array = func -@text_of_array_mut = func -@text_of_option = func -@text_of_variant = func -Array_init = func -Array_tabulate = func -abs = func -btstWord16 = func -btstWord32 = func -btstWord64 = func -btstWord8 = func -charToText = func -charToWord32 = func -clzWord16 = func -clzWord32 = func -clzWord64 = func -clzWord8 = func -ctzWord16 = func -ctzWord32 = func -ctzWord64 = func -ctzWord8 = func -decodeUTF8 = func -hashInt = func -ignore = func -intToWord16 = func -intToWord32 = func -intToWord64 = func -intToWord8 = func -natToWord16 = func -natToWord32 = func -natToWord64 = func -natToWord8 = func -popcntWord16 = func -popcntWord32 = func -popcntWord64 = func -popcntWord8 = func -print = func -printChar = func -printInt = func -range = func -revrange = func -shrsWord16 = func -shrsWord32 = func -shrsWord64 = func -shrsWord8 = func -word16ToInt = func -word16ToNat = func -word32ToChar = func -word32ToInt = func -word32ToNat = func -word64ToInt = func -word64ToNat = func -word8ToInt = func -word8ToNat = func - diff --git a/test/fail/ok/decl-clash.run-ir.ok b/test/fail/ok/decl-clash.run-ir.ok deleted file mode 100644 index 7b59d9004e4..00000000000 --- a/test/fail/ok/decl-clash.run-ir.ok +++ /dev/null @@ -1,25 +0,0 @@ -prelude:66.1-91.2: internal error, Env.Make(X).Clash("test") - -Last environment: -@new_async = func -Array_init = func -Array_tabulate = func -abs = func -ignore = func -intToWord16 = func -intToWord32 = func -intToWord8 = func -natToWord16 = func -natToWord32 = func -natToWord8 = func -print = func -printInt = func -range = func -revrange = func -word16ToInt = func -word16ToNat = func -word32ToInt = func -word32ToNat = func -word8ToInt = func -word8ToNat = func - diff --git a/test/fail/ok/decl-clash.run-low.ok b/test/fail/ok/decl-clash.run-low.ok deleted file mode 100644 index 7b59d9004e4..00000000000 --- a/test/fail/ok/decl-clash.run-low.ok +++ /dev/null @@ -1,25 +0,0 @@ -prelude:66.1-91.2: internal error, Env.Make(X).Clash("test") - -Last environment: -@new_async = func -Array_init = func -Array_tabulate = func -abs = func -ignore = func -intToWord16 = func -intToWord32 = func -intToWord8 = func -natToWord16 = func -natToWord32 = func -natToWord8 = func -print = func -printInt = func -range = func -revrange = func -word16ToInt = func -word16ToNat = func -word32ToInt = func -word32ToNat = func -word8ToInt = func -word8ToNat = func - diff --git a/test/fail/ok/decl-clash.run.ok b/test/fail/ok/decl-clash.run.ok deleted file mode 100644 index 7b59d9004e4..00000000000 --- a/test/fail/ok/decl-clash.run.ok +++ /dev/null @@ -1,25 +0,0 @@ -prelude:66.1-91.2: internal error, Env.Make(X).Clash("test") - -Last environment: -@new_async = func -Array_init = func -Array_tabulate = func -abs = func -ignore = func -intToWord16 = func -intToWord32 = func -intToWord8 = func -natToWord16 = func -natToWord32 = func -natToWord8 = func -print = func -printInt = func -range = func -revrange = func -word16ToInt = func -word16ToNat = func -word32ToInt = func -word32ToNat = func -word8ToInt = func -word8ToNat = func - diff --git a/test/fail/ok/decl-clash.wasm.stderr.ok b/test/fail/ok/decl-clash.wasm.stderr.ok deleted file mode 100644 index 7b59d9004e4..00000000000 --- a/test/fail/ok/decl-clash.wasm.stderr.ok +++ /dev/null @@ -1,25 +0,0 @@ -prelude:66.1-91.2: internal error, Env.Make(X).Clash("test") - -Last environment: -@new_async = func -Array_init = func -Array_tabulate = func -abs = func -ignore = func -intToWord16 = func -intToWord32 = func -intToWord8 = func -natToWord16 = func -natToWord32 = func -natToWord8 = func -print = func -printInt = func -range = func -revrange = func -word16ToInt = func -word16ToNat = func -word32ToInt = func -word32ToNat = func -word8ToInt = func -word8ToNat = func - diff --git a/test/repl/ok/double-import.stdout.ok b/test/repl/ok/double-import.stdout.ok index 729462bd50a..fcb5a4f25f6 100644 --- a/test/repl/ok/double-import.stdout.ok +++ b/test/repl/ok/double-import.stdout.ok @@ -2,6 +2,7 @@ ActorScript 0.1 interpreter -- Parsing stdin: > -- Parsing empty.as: -- Checking empty.as: +-- Definedness empty.as: -- Checking stdin: -- Interpreting empty.as: -- Interpreting stdin: diff --git a/test/repl/ok/file-and-repl.stdout.ok b/test/repl/ok/file-and-repl.stdout.ok index 3874c6064a4..c50a24d93a4 100644 --- a/test/repl/ok/file-and-repl.stdout.ok +++ b/test/repl/ok/file-and-repl.stdout.ok @@ -1,6 +1,7 @@ ActorScript 0.1 interpreter -- Parsing 63: -- Checking 63: +-- Definedness 63: -- Interpreting 63: -- Parsing stdin: > -- Checking stdin: diff --git a/test/repl/ok/triangle-import.stdout.ok b/test/repl/ok/triangle-import.stdout.ok index 8bc3cadcebb..daa4d66a983 100644 --- a/test/repl/ok/triangle-import.stdout.ok +++ b/test/repl/ok/triangle-import.stdout.ok @@ -3,7 +3,9 @@ ActorScript 0.1 interpreter > -- Parsing b.as: -- Parsing c.as: -- Checking c.as: +-- Definedness c.as: -- Checking b.as: +-- Definedness b.as: -- Checking stdin: -- Interpreting c.as: -- Interpreting b.as: @@ -14,6 +16,7 @@ ActorScript 0.1 interpreter -- Parsing stdin: > -- Parsing a.as: -- Checking a.as: +-- Definedness a.as: -- Checking stdin: -- Interpreting a.as: -- Interpreting stdin: @@ -29,6 +32,7 @@ ActorScript 0.1 interpreter -- Parsing stdin: > -- Parsing triangle.as: -- Checking triangle.as: +-- Definedness triangle.as: -- Checking stdin: -- Interpreting triangle.as: -- Interpreting stdin: