# HG changeset patch # User Adam Chlipala # Date 1392929433 18000 # Node ID 7db8356caef57b0572d34bdd16629ef7a53ee848 # Parent 7bd2ecf96bb0e5b5a80dc9fbde78d0227e3134f1 Tweaked parameter renaming for functors, so now demos and the original bug-triggering application work diff -r 7bd2ecf96bb0 -r 7db8356caef5 src/elaborate.sml --- a/src/elaborate.sml Thu Feb 20 10:48:17 2014 -0500 +++ b/src/elaborate.sml Thu Feb 20 15:50:33 2014 -0500 @@ -4455,16 +4455,6 @@ subSgn env' loc actual ran'; (ran', gs) end - - (* Later compiler phases are simplified by alpha-varying - * the functor formal argument here, if the same name - * will be defined independently in the functor body. *) - fun ensureUnused m = - case E.projectStr env' {sgn = actual, str = (L'.StrVar 0, loc), field = m} of - NONE => m - | SOME _ => ensureUnused ("?" ^ m) - - val m = ensureUnused m in ((L'.StrFun (m, n, dom', formal, str'), loc), (L'.SgnFun (m, n, dom', formal), loc), diff -r 7bd2ecf96bb0 -r 7db8356caef5 src/expl_rename.sml --- a/src/expl_rename.sml Thu Feb 20 10:48:17 2014 -0500 +++ b/src/expl_rename.sml Thu Feb 20 15:50:33 2014 -0500 @@ -422,6 +422,20 @@ val (st, n) = St.bind (st, FormalId) val (ds, st) = ListUtil.foldlMapConcat dupDecl st ds + + (* Revenge of the functor parameter renamer! + * See comment in elaborate.sml for the start of the saga. + * We need to alpha-rename the argument to allow sufficient shadowing in the body. *) + + fun mungeName m = + if List.exists (fn (DStr (x, _, _, _), _) => x = m + | _ => false) ds then + mungeName ("?" ^ m) + else + m + + val FormalName = mungeName FormalName + val ds = (DStr (FormalName, n, (SgnConst [], loc), (StrVar FormalId, loc)), loc) :: ds in (St.next st, (StrConst ds, loc))