Skip to content

Commit 0f877d4

Browse files
authored
perf: make more SizeOf instances noncomputable
This PR makes more `SizeOf` instances noncomputable, for consistency with the derived instances. See https://leanprover.zulipchat.com/#narrow/channel/113489-new-members/topic/Compiler.20error.20with.20sizeOf/with/561525387 for the kind of confusion this PR tries to avoid.
1 parent e548fa4 commit 0f877d4

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/Init/SizeOf.lean

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ and in many cases this will suffice to do the proof that a recursive function
2525
is only called on smaller values.
2626
If the default proof strategy fails, it is recommended to supply a custom
2727
size measure using the `termination_by` argument on the function definition.
28+
29+
The derived `SizeOf` instances are intended only for termination checking and
30+
are not compiled. It is not recommended to use `sizeOf` for programming purposes.
2831
-/
2932
class SizeOf (α : Sort u) where
3033
/-- The "size" of an element, a natural number which decreases on fields of
@@ -49,17 +52,17 @@ for every element of `α`.
4952
Every type `α` has a low priority default `SizeOf` instance that just returns `0`
5053
for every element of `α`.
5154
-/
52-
instance (priority := low) instSizeOfDefault (α : Sort u) : SizeOf α where
55+
noncomputable instance (priority := low) instSizeOfDefault (α : Sort u) : SizeOf α where
5356
sizeOf := default.sizeOf α
5457

5558
@[simp] theorem sizeOf_default (n : α) : sizeOf n = 0 := rfl
5659

57-
instance : SizeOf Nat where
60+
noncomputable instance : SizeOf Nat where
5861
sizeOf n := n
5962

6063
@[simp] theorem sizeOf_nat (n : Nat) : sizeOf n = n := rfl
6164

62-
instance [SizeOf α] : SizeOf (Unit → α) where
65+
noncomputable instance [SizeOf α] : SizeOf (Unit → α) where
6366
sizeOf f := sizeOf (f ())
6467

6568
@[simp] theorem sizeOf_thunk [SizeOf α] (f : Unit → α) : sizeOf f = sizeOf (f ()) :=

0 commit comments

Comments
 (0)