Zulip Chat Archive

Stream: mathlib4

Topic: Scoping instances


Matthew Ballard (Aug 09 2024 at 13:14):

Is it really the case that none of our 222 Fintype instances are scoped?

import Mathlib

open Lean Meta Elab Command

run_cmd do -- 222, 0
  let dt  liftCoreM getGlobalInstancesIndex
  let globalNames : Array Name := dt.fold (init := #[]) fun arr keys inst =>
    if let .const `Fintype _ := keys[0]! then
      if inst.attrKind == .global then
        arr.push inst.globalName?.get!
      else arr
    else arr
  let scopedNames := dt.fold (init := #[]) fun arr keys inst =>
    if let .const `Fintype _ := keys[0]! then
      if inst.attrKind == .scoped then
        arr.push inst.globalName?.get!
      else arr
    else arr
  logInfo m!"{globalNames.size}, {scopedNames.size}"

Matthew Ballard (Aug 09 2024 at 13:17):

Here are their names

Eric Wieser (Aug 09 2024 at 13:18):

My understanding was that scoped instance was only for instances that carry surprising or controversial data; and the fact that Subsingleton (Fintype _) is true means that Fintype instances should never be surprising.

Matthew Ballard (Aug 09 2024 at 13:22):

How much work does Lean need to do to not be surprised?

Matthew Ballard (Aug 09 2024 at 13:24):

CommSemiring is 69, 0 so this behavior is the case across all classes

Matthew Ballard (Aug 09 2024 at 13:26):

I would imagine any instance declared in CategoryTheory should be scoped to CategoryTheory for example

Matthew Ballard (Aug 09 2024 at 13:28):

No one is accidentally using Quiver.Hom notation.

Jireh Loreaux (Aug 09 2024 at 13:29):

Shouldn't that mean that those instances aren't ever checked in the first place when people aren't using them? So there's no need to scope them?

Jireh Loreaux (Aug 09 2024 at 13:30):

(the category theory ones, not CommSemiring)

Matthew Ballard (Aug 09 2024 at 13:30):

It depends on the keys.

Matthew Ballard (Aug 09 2024 at 13:30):

If those are robust enough, then yes. But in some cases they are not, eg lean#4932

Matthew Ballard (Aug 09 2024 at 13:35):

For example, CategoryTheory.FinCategory.fintypeObj will be tried for any search for Fintype on a Subtype

Eric Wieser (Aug 09 2024 at 13:40):

I think rather than disabling instances, it might be better to try and come up with a better keying algorithm

Eric Wieser (Aug 09 2024 at 13:41):

Perhaps along the lines of allowing a custom key generator for certain types like Subtype

Matthew Ballard (Aug 09 2024 at 13:43):

lean#4932 should fix the Subtype issue itself but philosophically why should one want to have anything to do with CategoryTheory instances if they are not working explicitly on CategoryTheory when all the basic notation is scoped to that namespace already

Matthew Ballard (Aug 09 2024 at 13:45):

One thing that the keying algorithm doesn't do is look in the context. One could imagine some light weight filtering based on this information.


Last updated: May 02 2025 at 03:31 UTC