Skip to content

Commit

Permalink
s/forall/forAll/ as it will become a restricted keyword
Browse files Browse the repository at this point in the history
-Wforall-identifier
  • Loading branch information
neduard committed Jun 25, 2024
1 parent d745d24 commit 56874a6
Show file tree
Hide file tree
Showing 12 changed files with 38 additions and 38 deletions.
6 changes: 3 additions & 3 deletions codebase2/util-term/U/Util/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ flattenEffects es = [es]
generalize :: (Ord v) => [v] -> TypeR r v -> TypeR r v
generalize vs t = foldr f t vs
where
f v t = if Set.member v (ABT.freeVars t) then forall v t else t
f v t = if Set.member v (ABT.freeVars t) then forAll v t else t

-- * Patterns

Expand All @@ -80,8 +80,8 @@ pattern Effect1' e t <- ABT.Tm' (Effect e t)
pattern Ref' :: r -> TypeR r v
pattern Ref' r <- ABT.Tm' (Ref r)

forall :: (Ord v) => v -> TypeR r v -> TypeR r v
forall v body = ABT.tm () (Forall (ABT.abs () v body))
forAll :: (Ord v) => v -> TypeR r v -> TypeR r v
forAll v body = ABT.tm () (Forall (ABT.abs () v body))

unforall' :: TypeR r v -> ([v], TypeR r v)
unforall' (ForallsNamed' vs t) = (vs, t)
Expand Down
2 changes: 1 addition & 1 deletion parser-typechecker/src/Unison/Builtin.hs
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,7 @@ refPromiseBuiltins =
forall1 :: Text -> (Type -> Type) -> Type
forall1 name body =
let a = Var.named name
in Type.forall () a (body $ Type.var () a)
in Type.forAll () a (body $ Type.var () a)

forall2 ::
Text -> Text -> (Type -> Type -> Type) -> Type
Expand Down
2 changes: 1 addition & 1 deletion parser-typechecker/src/Unison/Builtin/Decls.hs
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,7 @@ builtinEffectDecls =
Structural
()
[]
[ ((), v "Exception.raise", Type.forall () (v "x") (failureType () `arr` self (var "x")))
[ ((), v "Exception.raise", Type.forAll () (v "x") (failureType () `arr` self (var "x")))
]

pattern UnitRef :: Reference
Expand Down
2 changes: 1 addition & 1 deletion parser-typechecker/src/Unison/Codebase/MainTerm.hs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ getMainTerm loadTypeOfTerm parseNames mainName mainType = do
builtinMain :: (Var v) => a -> Type.Type v a
builtinMain a =
let result = Var.named "result"
in Type.forall a result (builtinMainWithResultType a (Type.var a result))
in Type.forAll a result (builtinMainWithResultType a (Type.var a result))

-- '{io2.IO, Exception} res
builtinMainWithResultType :: (Var v) => a -> Type.Type v a -> Type.Type v a
Expand Down
6 changes: 3 additions & 3 deletions parser-typechecker/src/Unison/Syntax/TypeParser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ type TypeP v m = P v m (Type v Ann)
-- the right of a function arrow:
-- valueType ::= Int | Text | App valueType valueType | Arrow valueType computationType
valueType :: (Monad m, Var v) => TypeP v m
valueType = forall type1 <|> type1
valueType = forAll type1 <|> type1

-- Computation
-- computationType ::= [{effect*}] valueType
Expand Down Expand Up @@ -119,8 +119,8 @@ arrow rec =
in chainr1 (effect <|> rec) (reserved "->" *> eff)

-- "forall a b . List a -> List b -> Maybe Text"
forall :: (Var v) => TypeP v m -> TypeP v m
forall rec = do
forAll :: (Var v) => TypeP v m -> TypeP v m
forAll rec = do
kw <- reserved "forall" <|> reserved ""
vars <- fmap (fmap L.payload) . some $ prefixDefinitionName
_ <- reserved "."
Expand Down
8 changes: 4 additions & 4 deletions parser-typechecker/src/Unison/Typechecker/Context.hs
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,7 @@ apply' solvedExistentials t = go t
Type.Ann' v k -> Type.ann a (go v) k
Type.Effect1' e t -> Type.effect1 a (go e) (go t)
Type.Effects' es -> Type.effects a (map go es)
Type.ForallNamed' v t' -> Type.forall a v (go t')
Type.ForallNamed' v t' -> Type.forAll a v (go t')
Type.IntroOuterNamed' v t' -> Type.introOuter a v (go t')
_ -> error $ "Match error in Context.apply': " ++ show t
where
Expand Down Expand Up @@ -1059,7 +1059,7 @@ vectorConstructorOfArity loc arity = do
let elementVar = Var.named "elem"
args = replicate arity (loc, Type.var loc elementVar)
resultType = Type.app loc (Type.list loc) (Type.var loc elementVar)
vt = Type.forall loc elementVar (Type.arrows args resultType)
vt = Type.forAll loc elementVar (Type.arrows args resultType)
pure vt

generalizeAndUnTypeVar :: (Var v) => Type v a -> Type.Type v a
Expand Down Expand Up @@ -1984,7 +1984,7 @@ tweakEffects v0 t0
rewrite p ty
| Type.ForallNamed' v t <- ty,
v0 /= v =
second (Type.forall a v) <$> rewrite p t
second (Type.forAll a v) <$> rewrite p t
| Type.Arrow' i o <- ty = do
(vis, i) <- rewrite (not <$> p) i
(vos, o) <- rewrite p o
Expand Down Expand Up @@ -2097,7 +2097,7 @@ generalizeP p ctx0 ty = foldr gen (applyCtx ctx0 ty) ctx
-- location of the forall is just the location of the input type
-- and the location of each quantified variable is just inherited
-- from its source location
Type.forall
Type.forAll
(loc t)
(TypeVar.Universal v)
(ABT.substInheritAnnotation tv (universal' () v) t)
Expand Down
8 changes: 4 additions & 4 deletions parser-typechecker/tests/Unison/Test/DataDeclaration.hs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ unhashComponentTest =
inventedVarsFreshnessTest =
let var = Type.var ()
app = Type.app ()
forall = Type.forall ()
forAll = Type.forAll ()
(-->) = Type.arrow ()
h = Hash.fromByteString (encodeUtf8 "abcd")
ref = R.Id h 0
Expand All @@ -104,8 +104,8 @@ unhashComponentTest =
annotation = (),
bound = [],
constructors' =
[ ((), nil, forall a (listType `app` var a)),
((), cons, forall b (var b --> listType `app` var b --> listType `app` var b))
[ ((), nil, forAll a (listType `app` var a)),
((), cons, forAll b (var b --> listType `app` var b --> listType `app` var b))
]
}
component :: Map R.Id (Decl Symbol ())
Expand All @@ -120,7 +120,7 @@ unhashComponentTest =
in tests
[ -- check that `nil` constructor's type did not collapse to `forall a. a a`,
-- which would happen if the var invented for `listRef` was simply `Var.refNamed listRef`
expectEqual (forall z (listType' `app` var z)) nilType',
expectEqual (forAll z (listType' `app` var z)) nilType',
-- check that the variable assigned to `listRef` is different from `cons`,
-- which would happen if the var invented for `listRef` was simply `Var.refNamed listRef`
expectNotEqual cons listVar
Expand Down
4 changes: 2 additions & 2 deletions parser-typechecker/tests/Unison/Test/Term.hs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test =
Type.arrow () (tv "a") (tv "x")
)
)
(Type.forall () (v "a") (tv "a"))
(Type.forAll () (v "a") (tv "a"))
tm' = Term.substTypeVar (v "x") (tv "a") tm
expected =
Term.ann
Expand All @@ -45,7 +45,7 @@ test =
Type.arrow () (Type.var () $ v1 "a") (tv "a")
)
)
(Type.forall () (v1 "a") (Type.var () $ v1 "a"))
(Type.forAll () (v1 "a") (Type.var () $ v1 "a"))
note $ show tm'
note $ show expected
expect $ tm == tm
Expand Down
4 changes: 2 additions & 2 deletions parser-typechecker/tests/Unison/Test/Typechecker.hs
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ test =
isSubtypeTest :: Test ()
isSubtypeTest =
let symbol i n = Symbol i (Var.User n)
forall v t = Type.forall () v t
forAll v t = Type.forAll () v t
var v = Type.var () v

a = symbol 0 "a"
a_ i = symbol i "a"
lhs = forall a (var a) -- ∀a. a
lhs = forAll a (var a) -- ∀a. a
rhs_ i = var (a_ i) -- a_i
in -- check that `∀a. a <: a_i` (used to fail for i = 2, 3)
tests [expectSubtype lhs (rhs_ i) | i <- [0 .. 5]]
Expand Down
2 changes: 1 addition & 1 deletion unison-core/src/Unison/Term.hs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ substTypeVar vt ty = go Set.empty
t2 = ABT.bindInheritAnnotation body (Type.var () v2)
in uncapture ((ABT.annotation t, v2) : vs) (renameTypeVar v v2 e) t2
uncapture vs e t0 =
let t = foldl (\body (loc, v) -> Type.forall loc v body) t0 vs
let t = foldl (\body (loc, v) -> Type.forAll loc v body) t0 vs
bound' = case Type.unForalls (Type.stripIntroOuters t) of
Nothing -> bound
Just (vs, _) -> bound <> Set.fromList vs
Expand Down
26 changes: 13 additions & 13 deletions unison-core/src/Unison/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -451,28 +451,28 @@ arrow' i o = arrow (ABT.annotation i <> ABT.annotation o) i o
ann :: (Ord v) => a -> Type v a -> K.Kind -> Type v a
ann a e t = ABT.tm' a (Ann e t)

forall :: (Ord v) => a -> v -> Type v a -> Type v a
forall a v body = ABT.tm' a (Forall (ABT.abs' a v body))
forAll :: (Ord v) => a -> v -> Type v a -> Type v a
forAll a v body = ABT.tm' a (Forall (ABT.abs' a v body))

introOuter :: (Ord v) => a -> v -> Type v a -> Type v a
introOuter a v body = ABT.tm' a (IntroOuter (ABT.abs' a v body))

iff :: (Var v) => Type v ()
iff = forall () aa $ arrows (f <$> [boolean (), a, a]) a
iff = forAll () aa $ arrows (f <$> [boolean (), a, a]) a
where
aa = Var.named "a"
a = var () aa
f x = ((), x)

iff' :: (Var v) => a -> Type v a
iff' loc = forall loc aa $ arrows (f <$> [boolean loc, a, a]) a
iff' loc = forAll loc aa $ arrows (f <$> [boolean loc, a, a]) a
where
aa = Var.named "a"
a = var loc aa
f x = (loc, x)

iff2 :: (Var v) => a -> Type v a
iff2 loc = forall loc aa $ arrows (f <$> [a, a]) a
iff2 loc = forAll loc aa $ arrows (f <$> [a, a]) a
where
aa = Var.named "a"
a = var loc aa
Expand All @@ -498,11 +498,11 @@ v' s = ABT.var (Var.named s)
av' :: (Var v) => a -> Text -> Type v a
av' a s = ABT.annotatedVar a (Var.named s)

forall' :: (Var v) => a -> [Text] -> Type v a -> Type v a
forall' a vs body = foldr (forall a) body (Var.named <$> vs)
forAll' :: (Var v) => a -> [Text] -> Type v a -> Type v a
forAll' a vs body = foldr (forAll a) body (Var.named <$> vs)

foralls :: (Ord v) => a -> [v] -> Type v a -> Type v a
foralls a vs body = foldr (forall a) body vs
foralls a vs body = foldr (forAll a) body vs

-- Note: `a -> b -> c` parses as `a -> (b -> c)`
-- the annotation associated with `b` will be the annotation for the `b -> c`
Expand Down Expand Up @@ -545,7 +545,7 @@ stripEffect t = ([], t)
-- The type of the flipped function application operator:
-- `(a -> (a -> b) -> b)`
flipApply :: (Var v) => Type v () -> Type v ()
flipApply t = forall () b $ arrow () (arrow () t (var () b)) (var () b)
flipApply t = forAll () b $ arrow () (arrow () t (var () b)) (var () b)
where
b = ABT.fresh t (Var.named "b")

Expand All @@ -554,12 +554,12 @@ generalize' k t = generalize vsk t
where
vsk = [v | v <- Set.toList (freeVars t), Var.typeOf v == k]

-- | Bind the given variables with an outer `forall`, if they are used in `t`.
-- | Bind the given variables with an outer `forAll`, if they are used in `t`.
generalize :: (Ord v) => [v] -> Type v a -> Type v a
generalize vs t = foldr f t vs
where
f v t =
if Set.member v (ABT.freeVars t) then forall (ABT.annotation t) v t else t
if Set.member v (ABT.freeVars t) then forAll (ABT.annotation t) v t else t

unforall :: Type v a -> Type v a
unforall (ForallsNamed' _ t) = t
Expand Down Expand Up @@ -755,7 +755,7 @@ functionResult = go False
-- `.foo -> .foo` becomes `.foo -> .foo` (not changed)
-- `.foo.bar -> blarrg.woot` becomes `.foo.bar -> blarrg.woot` (unchanged)
generalizeLowercase :: (Var v) => Set v -> Type v a -> Type v a
generalizeLowercase except t = foldr (forall (ABT.annotation t)) t vars
generalizeLowercase except t = foldr (forAll (ABT.annotation t)) t vars
where
vars =
[v | v <- Set.toList (ABT.freeVars t `Set.difference` except), Var.universallyQuantifyIfFree v]
Expand All @@ -774,7 +774,7 @@ normalizeForallOrder tm0 =
where
step :: (a, v) -> Type v a -> Type v a
step (a, v) body
| Set.member v (ABT.freeVars body) = forall a v body
| Set.member v (ABT.freeVars body) = forAll a v body
| otherwise = body
(body, vs0) = extract tm0
vs = sortOn (\(_, v) -> Map.lookup v ind) vs0
Expand Down
6 changes: 3 additions & 3 deletions unison-hashing-v2/src/Unison/Hashing/V2/Type.hs
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ charRef = ReferenceBuiltin "Char"
listRef = ReferenceBuiltin "Sequence"
effectRef = ReferenceBuiltin "Effect"

forall :: (Ord v) => a -> v -> Type v a -> Type v a
forall a v body = ABT.tm' a (TypeForall (ABT.abs' a v body))
forAll :: (Ord v) => a -> v -> Type v a -> Type v a
forAll a v body = ABT.tm' a (TypeForall (ABT.abs' a v body))

-- | Bind the given variables with an outer `forall`, if they are used in `t`.
generalize :: (Ord v) => [v] -> Type v a -> Type v a
generalize vs t = foldr f t vs
where
f v t =
if Set.member v (ABT.freeVars t) then forall (ABT.annotation t) v t else t
if Set.member v (ABT.freeVars t) then forAll (ABT.annotation t) v t else t

unforall' :: Type v a -> ([v], Type v a)
unforall' (ForallsNamed' vs t) = (vs, t)
Expand Down

0 comments on commit 56874a6

Please sign in to comment.