Skip to content
12 changes: 6 additions & 6 deletions src/Memory.hs
Original file line number Diff line number Diff line change
Expand Up @@ -628,11 +628,11 @@ refTargetIsAlive xobj =
in case Set.toList deadVars of
[] -> pure (Right xobj)
(deadName : _) ->
let original = Map.lookup deadName (memStateNames m)
let originalName = Map.lookup deadName (memStateNames m)
in pure
( case xobjObj xobj of
(Lst (LetPat _ _ body)) -> Left (UsingDeadReference body deadName original)
_ -> Left (UsingDeadReference xobj deadName original)
(Lst (LetPat _ _ body)) -> Left (UsingDeadReference body deadName originalName)
_ -> Left (UsingDeadReference xobj deadName originalName)
)
Just LifetimeOutsideFunction ->
pure (Right xobj)
Expand Down Expand Up @@ -677,11 +677,11 @@ returnRefTargetIsAlive xobj =
in case Set.toList deadVars of
[] -> pure (Right xobj)
(deadName : _) ->
let original = Map.lookup deadName (memStateNames m)
reportOn = case xobjObj fnBody of
let reportOn = case xobjObj fnBody of
Lst (LetPat _ _ body) -> body
_ -> fnBody
in pure (Left (UsingDeadReference reportOn deadName original))
originalName = Map.lookup deadName (memStateNames m)
in pure (Left (UsingDeadReference reportOn deadName originalName))

-- | Map from lifetime variables (of refs) to a `LifetimeMode`
-- | (usually containing the name of the XObj that the lifetime is tied to).
Expand Down
53 changes: 31 additions & 22 deletions src/TypeError.hs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ instance Show TypeError where
++ prettyInfoFromXObj xobj
++ ".\n\nI need exactly one body form. For multiple forms, try using `do`."
show (UnificationFailed (Constraint a b aObj bObj ctx _) mappings _) =
"I can’t match the types `" ++ showTy a ++ "` and `" ++ showTy b ++ "`."
"Type mismatch: I can’t match the types `" ++ showTy a ++ "` and `" ++ showTy b ++ "`."
++ extra
++ showObj aObj
++ showObj bObj
Expand Down Expand Up @@ -212,16 +212,16 @@ instance Show TypeError where
show (NotAValidType xobj) =
pretty xobj ++ " is not a valid type at " ++ prettyInfoFromXObj xobj
show (FunctionsCantReturnRefTy xobj t) =
"Functions can’t return references. " ++ getName xobj ++ " : " ++ show t
"Functions can’t return references. The function '" ++ getName xobj ++ "' has the type " ++ show t
++ " at "
++ prettyInfoFromXObj xobj
++ "\n\nYou’ll have to copy the return value using `@`."
++ ".\n\nYou’ll have to copy the return value using `@` or return an owned value."
show (LetCantReturnRefTy xobj t) =
"`let` expressions can’t return references. " ++ pretty xobj ++ " : "
"`let` expressions can’t return references. The expression '" ++ pretty xobj ++ "' has the type "
++ show t
++ " at "
++ prettyInfoFromXObj xobj
++ "\n\nYou’ll have to copy the return value using `@`."
++ ".\n\nYou’ll have to copy the return value using `@` or return an owned value."
show (GettingReferenceToUnownedValue xobj) =
"You’re referencing a given-away value `" ++ pretty xobj ++ "` at "
++ prettyInfoFromXObj xobj --"' (expression " ++ freshVar i ++ ") at " ++
Expand All @@ -236,17 +236,22 @@ instance Show TypeError where
"You’re using a value `" ++ pretty xobj
++ "` that was captured by a function at "
++ prettyInfoFromXObj xobj
++ "."
++ ".\n\nCaptured values can't be moved. You'll have to borrow it using `&` or copy it using `@`."
show (ArraysCannotContainRefs xobj) =
"Arrays can’t contain references: `" ++ pretty xobj ++ "` at "
++ prettyInfoFromXObj xobj
++ ".\n\nYou’ll have to make a copy using `@`."
show (MainCanOnlyReturnUnitOrInt _ t) =
"The main function can only return an `Int` or a unit type (`()`), but it got `"
show (MainCanOnlyReturnUnitOrInt xobj t) =
"The main function can only return an `Int` or a unit type `()`, but it got `"
++ show t
++ "`."
show (MainCannotHaveArguments _ c) =
"The main function may not receive arguments, but it got " ++ show c ++ "."
++ "` at "
++ prettyInfoFromXObj xobj
++ "."
show (MainCannotHaveArguments xobj c) =
"The main function may not receive arguments, but it got " ++ show c
++ " at "
++ prettyInfoFromXObj xobj
++ "."
show (CannotConcretize xobj) =
"I’m unable to concretize the expression '" ++ pretty xobj ++ "' at "
++ prettyInfoFromXObj xobj
Expand All @@ -259,7 +264,7 @@ instance Show TypeError where
show (NotAType xobj) =
"I don’t understand the type '" ++ pretty xobj ++ "' at "
++ prettyInfoFromXObj xobj
++ "\n\nIs it defined?"
++ ".\n\nIs it defined? If it's an external type, make sure it's registered using `register-type`."
show (CannotSet xobj) =
"I can’t `set!` the expression `" ++ pretty xobj ++ "` at "
++ prettyInfoFromXObj xobj
Expand Down Expand Up @@ -303,7 +308,7 @@ instance Show TypeError where
show (NotAmongRegisteredTypes t xobj) =
"I can’t find a definition for the type `" ++ show t ++ "` at "
++ prettyInfoFromXObj xobj
++ ".\n\nWas it registered?"
++ ".\n\nIs it defined? If it's an external type, make sure it's registered using `register-type`."
show (UnevenMembers xobjs) =
"The number of members and types is uneven: `"
++ joinWithComma (map pretty xobjs)
Expand All @@ -320,11 +325,15 @@ instance Show TypeError where
++ prettyInfoFromXObj (head xobjs)
++ ". \n\n Binding names must be symbols."
show (DuplicateBinding xobj) =
"I encountered a duplicate binding `" ++ pretty xobj ++ "` inside the `let` at " ++ prettyInfoFromXObj xobj ++ "."
"I encountered a duplicate binding `" ++ pretty xobj ++ "` inside the `let` at "
++ prettyInfoFromXObj xobj
++ ".\n\nEach name in a `let` must be unique."
show (DefinitionsMustBeAtToplevel xobj) =
"I encountered a definition that was not at top level: `" ++ pretty xobj ++ "`"
show (UsingDeadReference xobj dependsOn originalName) =

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use either ' or `, not both.

"The reference '" ++ pretty xobj ++ "' (depending on the variable '" ++ (fromMaybe dependsOn originalName) ++ "') isn't alive at " ++ prettyInfoFromXObj xobj ++ "."
"The reference `" ++ pretty xobj ++ "` is no longer valid because the value it depends on (`" ++ fromMaybe dependsOn originalName ++ "`) has been moved or deleted at "
++ prettyInfoFromXObj xobj
++ "."
show (UninhabitedConstructor ty xobj got wanted) =
"Can't use a struct or sumtype constructor without arguments as a member type at " ++ prettyInfoFromXObj xobj ++ ". The type constructor " ++ show ty ++ " expects " ++ show wanted ++ " arguments but got " ++ show got
show (InconsistentKinds varName xobjs) =
Expand Down Expand Up @@ -402,17 +411,17 @@ machineReadableErrorStrings fppl err =
(NotAValidType xobj) ->
[machineReadableInfoFromXObj fppl xobj ++ " Not a valid type: " ++ pretty xobj ++ "."]
(NotAType xobj) ->
[machineReadableInfoFromXObj fppl xobj ++ " Can't understand the type '" ++ pretty xobj ++ "'."]
[machineReadableInfoFromXObj fppl xobj ++ " I don't understand the type '" ++ pretty xobj ++ "'. Is it defined? If it's an external type, make sure it's registered using 'register-type'."]
(FunctionsCantReturnRefTy xobj t) ->
[machineReadableInfoFromXObj fppl xobj ++ " Functions can't return references. " ++ getName xobj ++ " : " ++ show t ++ "."]
[machineReadableInfoFromXObj fppl xobj ++ " Functions can't return references. The function '" ++ getName xobj ++ "' has the type " ++ show t ++ ". You’ll have to copy the return value using `@` or return an owned value."]
(LetCantReturnRefTy xobj t) ->
[machineReadableInfoFromXObj fppl xobj ++ " Let-expressions can't return references. '" ++ pretty xobj ++ "' : " ++ show t ++ "."]
[machineReadableInfoFromXObj fppl xobj ++ " `let` expressions can't return references. The expression '" ++ pretty xobj ++ "' has the type " ++ show t ++ ". You’ll have to copy the return value using `@` or return an owned value."]
(GettingReferenceToUnownedValue xobj) ->
[machineReadableInfoFromXObj fppl xobj ++ " Referencing a given-away value '" ++ pretty xobj ++ "'."]
(UsingUnownedValue xobj) ->
[machineReadableInfoFromXObj fppl xobj ++ " Using a given-away value '" ++ pretty xobj ++ "'."]
(UsingCapturedValue xobj) ->
[machineReadableInfoFromXObj fppl xobj ++ " Using a captured value '" ++ pretty xobj ++ "'."]
[machineReadableInfoFromXObj fppl xobj ++ " Using a captured value '" ++ pretty xobj ++ "'. Captured values can't be moved. You'll have to borrow it using `&` or copy it using `@`."]
(ArraysCannotContainRefs xobj) ->
[machineReadableInfoFromXObj fppl xobj ++ " Arrays can't contain references: '" ++ pretty xobj ++ "'."]
(MainCanOnlyReturnUnitOrInt xobj t) ->
Expand Down Expand Up @@ -444,17 +453,17 @@ machineReadableErrorStrings fppl err =
++ "`. Use `Ptr` or `Box`."
]
(NotAmongRegisteredTypes t xobj) ->
[machineReadableInfoFromXObj fppl xobj ++ " The type '" ++ show t ++ "' isn't defined."]
[machineReadableInfoFromXObj fppl xobj ++ " The type '" ++ show t ++ "' isn't defined. Is it defined? If it's an external type, make sure it's registered using 'register-type'."]
(UnevenMembers xobjs) ->
[machineReadableInfoFromXObj fppl (head xobjs) ++ " Uneven nr of members / types: " ++ joinWithComma (map pretty xobjs)]
(InvalidLetBinding xobjs (sym, expr)) ->
[machineReadableInfoFromXObj fppl (head xobjs) ++ "Invalid let binding `" ++ pretty sym ++ pretty expr ++ "` at " ++ joinWithComma (map pretty xobjs)]
(DuplicateBinding xobj) ->
[machineReadableInfoFromXObj fppl xobj ++ " Duplicate binding `" ++ pretty xobj ++ "` inside `let`."]
[machineReadableInfoFromXObj fppl xobj ++ " Duplicate binding `" ++ pretty xobj ++ "` inside `let`. Each name in a `let` must be unique."]
(DefinitionsMustBeAtToplevel xobj) ->
[machineReadableInfoFromXObj fppl xobj ++ " Definition not at top level: `" ++ pretty xobj ++ "`"]
(UsingDeadReference xobj _ _) ->
[machineReadableInfoFromXObj fppl xobj ++ " The reference '" ++ pretty xobj ++ "' isn't alive."]
[machineReadableInfoFromXObj fppl xobj ++ " The reference '" ++ pretty xobj ++ "' is no longer valid."]
(UninhabitedConstructor ty xobj got wanted) ->
[machineReadableInfoFromXObj fppl xobj ++ "Can't use a struct or sumtype constructor without arguments as a member type at " ++ prettyInfoFromXObj xobj ++ ". The type constructor " ++ show ty ++ " expects " ++ show wanted ++ " arguments but got " ++ show got]
(InconsistentKinds varName xobjs) ->
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
duplicate_binding.carp:5:9 Duplicate binding `x` inside `let`.
duplicate_binding.carp:5:9 Duplicate binding `x` inside `let`. Each name in a `let` must be unique.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lambda_capturing_ref_that_dies.carp:8:6 The reference 'f' isn't alive.
lambda_capturing_ref_that_dies.carp:8:6 The reference 'f' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lifetime_sig_dangling_ref.carp:5:33 The reference '(ref local)' isn't alive.
lifetime_sig_dangling_ref.carp:5:33 The reference '(ref local)' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return_ref_in_do.carp:4:3 The reference '(do () () () () (ref [1 2 3]))' isn't alive.
return_ref_in_do.carp:4:3 The reference '(do () () () () (ref [1 2 3]))' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return_ref_in_let.carp:5:5 The reference 'xs' isn't alive.
return_ref_in_let.carp:5:5 The reference 'xs' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return_ref_to_array_literal.carp:4:4 The reference '(ref [1 2 3])' isn't alive.
return_ref_to_array_literal.carp:4:4 The reference '(ref [1 2 3])' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
return_ref_to_function_result.carp:7:4 The reference '(ref (make-data))' isn't alive.
return_ref_to_function_result.carp:7:4 The reference '(ref (make-data))' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set_ref_outlives_in_do.carp:10:15 The reference 'x' isn't alive.
set_ref_outlives_in_do.carp:10:15 The reference 'x' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set_ref_outlives_multiple.carp:11:15 The reference 'x' isn't alive.
set_ref_outlives_multiple.carp:11:15 The reference 'x' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set_ref_outlives_nested.carp:9:15 The reference 'x' isn't alive.
set_ref_outlives_nested.carp:9:15 The reference 'x' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set_ref_outlives_source.carp:10:15 The reference 'x' isn't alive.
set_ref_outlives_source.carp:10:15 The reference 'x' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set_ref_outlives_string_copy.carp:8:15 The reference 'x' isn't alive.
set_ref_outlives_string_copy.carp:8:15 The reference 'x' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
set_ref_outlives_via_call.carp:10:15 The reference 'x' isn't alive.
set_ref_outlives_via_call.carp:10:15 The reference 'x' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use_ref_after_free.carp:7:17 The reference 'r' isn't alive.
use_ref_after_free.carp:7:17 The reference 'r' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use_ref_arg_after_free.carp:6:17 The reference 'r' isn't alive.
use_ref_arg_after_free.carp:6:17 The reference 'r' is no longer valid.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use_ref_via_nth_after_free.carp:9:19 The reference 'q' isn't alive.
use_ref_via_nth_after_free.carp:9:19 The reference 'q' is no longer valid.
Loading