# HG changeset patch # User Adam Chlipala # Date 1227798802 18000 # Node ID 5fc269f744ee3db188e6e929edbcc94f90192ffd # Parent 40b19310ea9ae10577a324f7192a86e8b9c6c2ef Remove unnecessary [kindof] calls diff -r 40b19310ea9a -r 5fc269f744ee src/elaborate.sml --- a/src/elaborate.sml Wed Nov 26 15:42:00 2008 -0500 +++ b/src/elaborate.sml Thu Nov 27 10:13:22 2008 -0500 @@ -540,6 +540,53 @@ exception SummaryFailure + fun isUnitCon env (c, loc) = + case c of + L'.TFun _ => false + | L'.TCFun _ => false + | L'.TRecord _ => false + + | L'.CRel xn => #1 (#2 (E.lookupCRel env xn)) = L'.KUnit + | L'.CNamed xn => #1 (#2 (E.lookupCNamed env xn)) = L'.KUnit + | L'.CModProj (n, ms, x) => + let + val (_, sgn) = E.lookupStrNamed env n + val (str, sgn) = foldl (fn (m, (str, sgn)) => + case E.projectStr env {sgn = sgn, str = str, field = m} of + NONE => raise Fail "kindof: Unknown substructure" + | SOME sgn => ((L'.StrProj (str, m), loc), sgn)) + ((L'.StrVar n, loc), sgn) ms + in + case E.projectCon env {sgn = sgn, str = str, field = x} of + NONE => raise Fail "kindof: Unknown con in structure" + | SOME ((k, _), _) => k = L'.KUnit + end + + | L'.CApp (c, _) => + (case hnormKind (kindof env c) of + (L'.KArrow (_, k), _) => #1 k = L'.KUnit + | (L'.KError, _) => false + | k => raise CUnify' (CKindof (k, c, "arrow"))) + | L'.CAbs _ => false + | L'.CDisjoint (_, _, _, c) => isUnitCon env c + + | L'.CName _ => false + + | L'.CRecord _ => false + | L'.CConcat _ => false + | L'.CFold _ => false + + | L'.CUnit => true + + | L'.CTuple _ => false + | L'.CProj (c, n) => + (case hnormKind (kindof env c) of + (L'.KTuple ks, _) => #1 (List.nth (ks, n - 1)) = L'.KUnit + | k => raise CUnify' (CKindof (k, c, "tuple"))) + + | L'.CError => false + | L'.CUnif (_, k, _, _) => #1 k = L'.KUnit + fun unifyRecordCons (env, denv) (c1, c2) = let fun rkindof c = @@ -824,9 +871,9 @@ gs1 @ gs2 @ gs3 @ gs4 end | _ => - case (kindof env c1, kindof env c2) of - ((L'.KUnit, _), (L'.KUnit, _)) => [] - | _ => + if isUnitCon env c1 andalso isUnitCon env c2 then + [] + else let val (c1, gs1) = hnormCon (env, denv) c1 val (c2, gs2) = hnormCon (env, denv) c2 @@ -1722,7 +1769,8 @@ ((L'.ELet (eds, e), loc), t, gs1 @ gs2) end in - (*prefaces "/elabExp" [("e", SourcePrint.p_exp eAll)];*) + (*prefaces "elabExp" [("e", SourcePrint.p_exp eAll), + ("t", PD.string (LargeInt.toString (Time.toMilliseconds (Time.- (Time.now (), befor)))))];*) r end @@ -3245,7 +3293,8 @@ (*val tcs = List.filter (fn TypeClass _ => true | _ => false) (#3 (#2 r))*) in (*prefaces "elabDecl" [("e", SourcePrint.p_decl dAll), - ("|tcs|", PD.string (Int.toString (length tcs)))];*) + ("t", PD.string (LargeInt.toString (Time.toMilliseconds + (Time.- (Time.now (), befor)))))];*) r end