Compiler eating memory infinitely
Closed this issue · 3 comments
I've tried to minimize this and I just can't seem to get the same behavior when I do.
The project is at https://gitdab.com/s/ootAI. I suspect that the equipment
record in oot/equipment.ml
is the problem.
If equipment: u16
is replaced with equipment: equipment
here (permalink), the compiler gets stuck and eats up all my memory.
As of commit 4852cffa0a, the compiler freezes, but applying this diff makes the compiler work properly.
diff --git a/oot/item.ml b/oot/item.ml
index d077ea2..b39ee47 100644
--- a/oot/item.ml
+++ b/oot/item.ml
@@ -7,7 +7,6 @@ open import "../mem/int.ml"
type item =
| DekuSticks
| NoItem
-| UnknownItem of int
instance decode item begin
let decode addr =
@@ -15,12 +14,10 @@ instance decode item begin
match code with
| 0 -> DekuSticks
| 255 -> NoItem
- | x -> UnknownItem x
end
instance show item begin
let show = function
| DekuSticks -> "Deku Sticks"
| NoItem -> "No Item"
- | UnknownItem x -> "Unknown Item " ^ (show x)
end
What is going on?
I've been told to note that the following diff:
diff --git a/oot/item_equips.ml b/oot/item_equips.ml
index a4374e3..cceb4e2 100644
--- a/oot/item_equips.ml
+++ b/oot/item_equips.ml
@@ -3,8 +3,9 @@ open import "../pretty.ml"
open import "../mem/decode.ml"
open import "../mem/int.ml"
open import "./item.ml"
+open import "./equipment.ml"
-type item_equips = ItemEquips of {
+type item_equips_ 'a = ItemEquips of {
button_item_b: item,
button_item_c_left: item,
button_item_c_down: item,
@@ -12,10 +13,11 @@ type item_equips = ItemEquips of {
button_slot_c_left: u8,
button_slot_c_down: u8,
button_slot_c_right: u8,
- equipment: u16
+ equipment: 'a
}
+type item_equips <- item_equips_ equipment
-instance decode item_equips begin
+instance decode 'a => decode (item_equips_ 'a) begin
let decode addr = ItemEquips {
button_item_b = decode (addr + 0x00),
button_item_c_left = decode (addr + 0x01),
@@ -28,7 +30,7 @@ instance decode item_equips begin
}
end
-instance prettyrecord item_equips begin
+instance pretty 'a => prettyrecord (item_equips_ 'a) begin
let name _ = "ItemEquips"
let fields (ItemEquips x) =
[
@@ -39,10 +41,10 @@ instance prettyrecord item_equips begin
("button_slot_c_left", S x.button_slot_c_left),
("button_slot_c_down", S x.button_slot_c_down),
("button_slot_c_right", S x.button_slot_c_right),
- ("equipment", S x.equipment)
+ ("equipment", P x.equipment)
]
end
-instance pretty item_equips begin
+instance pretty 'a => pretty (item_equips_ 'a) begin
let pretty = pretty_from_record
end
still makes the compiler freeze, even when patching in the above diff.
It's the pattern matcher, because of course it is.
When Lower your guards came out (says August 2020, but this was much earlier) @plt-hokusai and I discussed switching to it. Then lockdown happened and I graduated, and um ... it never materialised.
Guess now is as good a time as any!