Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Give a proper type to literal Strings #1730

Merged
merged 1 commit into from
Jan 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Juvix/Compiler/Core/Translation/FromInternal.hs
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ goApplication a = do

goLiteral :: Symbol -> LiteralLoc -> Node
goLiteral intToNat l = case l ^. withLocParam of
Internal.LitString s -> mkLambda' (mkLitConst (ConstString s))
Internal.LitString s -> mkLitConst (ConstString s)
Internal.LitInteger i -> mkApp' (mkIdent' intToNat) (mkLitConst (ConstInteger i))
where
mkLitConst :: ConstantValue -> Node
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ guessArity ::
guessArity = \case
ExpressionHole {} -> return ArityUnknown
ExpressionFunction {} -> return ArityUnit
ExpressionLiteral l -> return (arityLiteral l)
ExpressionLiteral {} -> return arityLiteral
ExpressionApplication a -> appHelper a
ExpressionIden i -> idenHelper i
ExpressionUniverse {} -> return arityUniverse
Expand Down Expand Up @@ -141,16 +141,8 @@ guessArity = \case
arif :: Sem r Arity
arif = guessArity f

arityLiteral :: LiteralLoc -> Arity
arityLiteral (WithLoc _ l) = case l of
LitInteger {} -> ArityUnit
-- The arity of all strings is assumed to be: {} -> 1
LitString {} ->
ArityFunction
FunctionArity
{ _functionArityLeft = ParamImplicit,
_functionArityRight = ArityUnit
}
arityLiteral :: Arity
arityLiteral = ArityUnit

arityUniverse :: Arity
arityUniverse = ArityUnit
Expand Down Expand Up @@ -411,7 +403,7 @@ checkExpression hintArity expr = case expr of
args' :: [(IsImplicit, Expression)] <- case fun of
ExpressionHole {} -> mapM (secondM (checkExpression ArityUnknown)) args
ExpressionIden i -> idenArity i >>= helper (getLoc i)
ExpressionLiteral l -> helper (getLoc l) (arityLiteral l)
ExpressionLiteral l -> helper (getLoc l) arityLiteral
ExpressionUniverse l -> helper (getLoc l) arityUniverse
ExpressionSimpleLambda {} -> simplelambda
ExpressionFunction f ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -479,39 +479,13 @@ literalType lit@(WithLoc i l) = case l of
{ _typedExpression = ExpressionLiteral lit,
_typedType = ExpressionIden (IdenInductive nat)
}
LitString {} -> literalMagicType lit

-- | Returns {A : Expression} → A
literalMagicType :: Members '[NameIdGen] r => LiteralLoc -> Sem r TypedExpression
literalMagicType l = do
uid <- freshNameId
let strA :: Text
strA = "A"
typeVar =
Name
{ _nameText = strA,
_nameId = uid,
_namePretty = strA,
_nameKind = KNameLocal,
_nameLoc = getLoc l
}
param =
FunctionParameter
{ _paramName = Just typeVar,
_paramImplicit = Implicit,
_paramType = smallUniverseE (getLoc l)
}
type_ =
ExpressionFunction
Function
{ _functionLeft = param,
_functionRight = ExpressionIden (IdenVar typeVar)
}
return
TypedExpression
{ _typedType = type_,
_typedExpression = ExpressionLiteral l
}
LitString {} -> do
str <- getBuiltinName i BuiltinString
return
TypedExpression
{ _typedExpression = ExpressionLiteral lit,
_typedType = ExpressionIden (IdenAxiom str)
}

inferExpression' ::
forall r.
Expand Down
2 changes: 1 addition & 1 deletion tests/positive/FullExamples/MonoSimpleFungibleToken.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ compile + {
-- Strings
--------------------------------------------------------------------------------

axiom String : Type;
builtin string axiom String : Type;
compile String {
ghc ↦ "[Char]";
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ compile + {
-- Strings
--------------------------------------------------------------------------------

axiom String : Type;
builtin string axiom String : Type;
compile String {
ghc ↦ "[Char]";
};
Expand Down
4 changes: 3 additions & 1 deletion tests/positive/Internal/LiteralString.juvix
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module LiteralString;
builtin string axiom String : Type;

type A :=
a : A;

type B :=
b : B;

f : A;
f : String;
f := "a";
end;
2 changes: 1 addition & 1 deletion tests/positive/MiniC/HelloWorld/Input.juvix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Input;

axiom String : Type;
builtin string axiom String : Type;

compile String {
c ↦ "char*";
Expand Down
2 changes: 1 addition & 1 deletion tests/positive/MiniC/HigherOrder/Input.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Input;
-- Strings
--------------------------------------------------------------------------------

axiom String : Type;
builtin string axiom String : Type;

compile String {
c ↦ "char*";
Expand Down
2 changes: 1 addition & 1 deletion tests/positive/MiniC/Lib/Data/String.juvix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Data.String;

axiom String : Type;
builtin string axiom String : Type;

compile String {
ghc ↦ "[Char]";
Expand Down
2 changes: 1 addition & 1 deletion tests/positive/MiniC/MultiModules/Data/String.juvix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Data.String;

axiom String : Type;
builtin string axiom String : Type;

compile String {
ghc ↦ "[Char]";
Expand Down
2 changes: 1 addition & 1 deletion tests/positive/MiniC/MutuallyRecursive/Data/String.juvix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Data.String;

axiom String : Type;
builtin string axiom String : Type;

compile String {
ghc ↦ "[Char]";
Expand Down
2 changes: 1 addition & 1 deletion tests/positive/MiniC/Nat/Input.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Bool :=
-- Strings
--------------------------------------------------------------------------------

axiom String : Type;
builtin string axiom String : Type;

compile String {
ghc ↦ "[Char]";
Expand Down
2 changes: 1 addition & 1 deletion tests/positive/MiniC/Polymorphism/Input.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Bool :=
-- Strings
--------------------------------------------------------------------------------

axiom String : Type;
builtin string axiom String : Type;

compile String {
ghc ↦ "[Char]";
Expand Down
2 changes: 1 addition & 1 deletion tests/positive/MiniC/PolymorphismHoles/Input.juvix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Bool :=
-- Strings
--------------------------------------------------------------------------------

axiom String : Type;
builtin string axiom String : Type;

compile String {
ghc ↦ "[Char]";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ compile + {
-- Strings
--------------------------------------------------------------------------------

axiom String : Type;
builtin string axiom String : Type;
compile String {
c ↦ "char*";
};
Expand Down