changeset 1595:154cfe2eb366

Better error messages about server-side use of client-side functions
author Adam Chlipala <adam@chlipala.net>
date Mon, 14 Nov 2011 09:15:10 -0500
parents d9de8b3f8167
children 02a50a9d50ea e283ca05c829
files src/compiler.sig src/compiler.sml src/settings.sml src/sidecheck.sig src/sidecheck.sml src/sources tests/sidecheck.ur tests/sidecheckGood.ur
diffstat 8 files changed, 117 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/compiler.sig	Mon Nov 14 09:02:00 2011 -0500
+++ b/src/compiler.sig	Mon Nov 14 09:15:10 2011 -0500
@@ -116,6 +116,7 @@
     val jscomp : (Mono.file, Mono.file) phase
     val fuse : (Mono.file, Mono.file) phase
     val pathcheck : (Mono.file, Mono.file) phase
+    val sidecheck : (Mono.file, Mono.file) phase
     val cjrize : (Mono.file, Cjr.file) phase
     val scriptcheck : (Cjr.file, Cjr.file) phase
     val prepare : (Cjr.file, Cjr.file) phase
@@ -176,6 +177,7 @@
     val toUntangle3 : (string, Mono.file) transform
     val toMono_shake3 : (string, Mono.file) transform
     val toPathcheck : (string, Mono.file) transform
+    val toSidecheck : (string, Mono.file) transform
     val toCjrize : (string, Cjr.file) transform
     val toScriptcheck : (string, Cjr.file) transform
     val toPrepare : (string, Cjr.file) transform
--- a/src/compiler.sml	Mon Nov 14 09:02:00 2011 -0500
+++ b/src/compiler.sml	Mon Nov 14 09:15:10 2011 -0500
@@ -1274,12 +1274,19 @@
 
 val toPathcheck = transform pathcheck "pathcheck" o toMono_shake3
 
+val sidecheck = {
+    func = SideCheck.check,
+    print = MonoPrint.p_file MonoEnv.empty
+}
+
+val toSidecheck = transform sidecheck "sidecheck" o toPathcheck
+
 val cjrize = {
     func = Cjrize.cjrize,
     print = CjrPrint.p_file CjrEnv.empty
 }
 
-val toCjrize = transform cjrize "cjrize" o toPathcheck
+val toCjrize = transform cjrize "cjrize" o toSidecheck
 
 val scriptcheck = {
     func = ScriptCheck.classify,
--- a/src/settings.sml	Mon Nov 14 09:02:00 2011 -0500
+++ b/src/settings.sml	Mon Nov 14 09:15:10 2011 -0500
@@ -164,8 +164,7 @@
 fun setBenignEffectful ls = benign := S.addList (benignBase, ls)
 fun isBenignEffectful x = S.member (!benign, x)
 
-val clientBase = basis ["get",
-                        "set",
+val clientBase = basis ["get_client_source",
                         "current",
                         "alert",
                         "confirm",
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/sidecheck.sig	Mon Nov 14 09:15:10 2011 -0500
@@ -0,0 +1,32 @@
+(* Copyright (c) 2011, Adam Chlipala
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ *   this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * - The names of contributors may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *)
+
+signature SIDE_CHECK = sig
+
+    val check : Mono.file -> Mono.file
+
+end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/sidecheck.sml	Mon Nov 14 09:15:10 2011 -0500
@@ -0,0 +1,59 @@
+(* Copyright (c) 2011, Adam Chlipala
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ *   this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * - The names of contributors may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *)
+
+structure SideCheck :> SIDE_CHECK = struct
+
+open Mono
+
+structure E = ErrorMsg
+
+structure FS = BinarySetFn(struct
+                           type ord_key = string * string
+                           fun compare ((x1, y1), (x2, y2)) = Order.join (String.compare (x1, x2),
+                                                                          fn () => String.compare (y1, y2))
+                           end)
+
+fun check ds =
+    let
+        val fs = MonoUtil.File.fold {typ = fn (_, fs) => fs,
+                                     exp = fn (e, fs) =>
+                                              case e of
+                                                  EFfi k => FS.add (fs, k)
+                                                | EFfiApp (k1, k2, _) => FS.add (fs, (k1, k2))
+                                                | _ => fs,
+                                     decl = fn (_, fs) => fs}
+                                    FS.empty ds
+    in
+        FS.app (fn k as (k1, k2) =>
+                   if Settings.isClientOnly k then
+                       E.error ("Server-side code uses client-side-only identifier \"" ^ k1 ^ "." ^ k2 ^ "\"")
+                   else
+                       ()) fs;
+        ds
+    end
+
+end
--- a/src/sources	Mon Nov 14 09:02:00 2011 -0500
+++ b/src/sources	Mon Nov 14 09:15:10 2011 -0500
@@ -189,6 +189,9 @@
 pathcheck.sig
 pathcheck.sml
 
+sidecheck.sig
+sidecheck.sml
+
 cjr.sml
 
 postgres.sig
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sidecheck.ur	Mon Nov 14 09:15:10 2011 -0500
@@ -0,0 +1,6 @@
+fun main () : transaction page =
+    s <- source 0;
+    n <- get s;
+    set s (n + 1);
+    n' <- get s;
+    return <xml>{[n']}</xml>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/sidecheckGood.ur	Mon Nov 14 09:15:10 2011 -0500
@@ -0,0 +1,6 @@
+fun main () : transaction page =
+    s <- source 0;
+    set s 42;
+    return <xml><body>
+      <dyn signal={n <- signal s; return (txt n)}/>
+    </body></xml>