diff options
author | Adam Chlipala <adam@chlipala.net> | 2011-11-14 09:15:10 -0500 |
---|---|---|
committer | Adam Chlipala <adam@chlipala.net> | 2011-11-14 09:15:10 -0500 |
commit | 82e0f83b9af579778f1a81daeedc8affaa81ac46 (patch) | |
tree | bfa2b4548397ac6717436e5b2870679cabb52945 | |
parent | 81b9a30041b3a657a8e81d6c4adf022f640a936d (diff) |
Better error messages about server-side use of client-side functions
-rw-r--r-- | src/compiler.sig | 2 | ||||
-rw-r--r-- | src/compiler.sml | 9 | ||||
-rw-r--r-- | src/settings.sml | 3 | ||||
-rw-r--r-- | src/sidecheck.sig | 32 | ||||
-rw-r--r-- | src/sidecheck.sml | 59 | ||||
-rw-r--r-- | src/sources | 3 | ||||
-rw-r--r-- | tests/sidecheck.ur | 6 | ||||
-rw-r--r-- | tests/sidecheckGood.ur | 6 |
8 files changed, 117 insertions, 3 deletions
diff --git a/src/compiler.sig b/src/compiler.sig index 62b57856..8bf493f1 100644 --- a/src/compiler.sig +++ b/src/compiler.sig @@ -116,6 +116,7 @@ signature COMPILER = sig 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 @@ signature COMPILER = sig 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 diff --git a/src/compiler.sml b/src/compiler.sml index 3fbc6008..9b43efa0 100644 --- a/src/compiler.sml +++ b/src/compiler.sml @@ -1274,12 +1274,19 @@ val pathcheck = { 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, diff --git a/src/settings.sml b/src/settings.sml index f7bb4027..f6d653f1 100644 --- a/src/settings.sml +++ b/src/settings.sml @@ -164,8 +164,7 @@ val benign = ref benignBase 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", diff --git a/src/sidecheck.sig b/src/sidecheck.sig new file mode 100644 index 00000000..30abced6 --- /dev/null +++ b/src/sidecheck.sig @@ -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 diff --git a/src/sidecheck.sml b/src/sidecheck.sml new file mode 100644 index 00000000..737c5c2b --- /dev/null +++ b/src/sidecheck.sml @@ -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 diff --git a/src/sources b/src/sources index 862845d5..5d1f099d 100644 --- a/src/sources +++ b/src/sources @@ -189,6 +189,9 @@ jscomp.sml pathcheck.sig pathcheck.sml +sidecheck.sig +sidecheck.sml + cjr.sml postgres.sig diff --git a/tests/sidecheck.ur b/tests/sidecheck.ur new file mode 100644 index 00000000..e21a0041 --- /dev/null +++ b/tests/sidecheck.ur @@ -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> diff --git a/tests/sidecheckGood.ur b/tests/sidecheckGood.ur new file mode 100644 index 00000000..01a8c3d1 --- /dev/null +++ b/tests/sidecheckGood.ur @@ -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> |