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

[Merged by Bors] - fix(frontends/lean/definition_cmds): put auto-bound universes before explicit #788

Closed
wants to merge 1 commit into from

Conversation

digama0
Copy link
Member

@digama0 digama0 commented Dec 1, 2022

@gebner
Copy link
Member

gebner commented Dec 1, 2022

I'm not sure I can reproduce this. The following file produces the same order of universe parameters in both Lean 3 and Lean 4:

universe a universe z
def foo (α : Type a) (β : Type _) (γ : Type z) := α × β × γ
set_option pp.universes true
#print foo
$ lean +leanprover-community/lean:3.49.1 788.lean
def {a z u_1} foo : Type a → Type u_1 → Type z → Type (max a u_1 z) :=
λ (α : Type a) (β : Type u_1) (γ : Type z), α × β × γ
$ lean +leanprover/lean4:nightly-2022-11-30 788.lean
def foo.{a, z, u_1} : Type a → Type u_1 → Type z → Type (max a z u_1) :=
fun α β γ => Prod.{a, max z u_1} α (Prod.{u_1, z} β γ)

Also do we really want this order (and not change Lean 4)? Also please add a test.

@digama0
Copy link
Member Author

digama0 commented Dec 1, 2022

You are right, this isn't the issue. The mystery _aux_param_0 is actually in the definition of List.traverse._main:

namespace list
universes u v

protected def traverse {F : Type u → Type v} [applicative F] {α β : Type*} (f : α → F β) :
  list α → F (list β)
| [] := pure []
| (x :: xs) := list.cons <$> f x <*> traverse xs

set_option pp.universes true
#print list.traverse._main

end list
def {_aux_param_0 u v} list.traverse._main : Π {F : Type u → Type v} [_inst_1 : applicative.{u v} F] {α : Type _aux_param_0} {β : Type u},
  (α → F β) → list.{_aux_param_0} α → F (list.{u} β) := ...

I think cause is actually this line:

std::sort(m_level_params.begin(), m_level_params.end());

which sorts the newly generated universe parameters alphabetically, after introducing fresh variables using the _aux_param_i naming convention which of course will put them first. I think we should just remove the sort and let them be ordered by appearance in the term.

@gebner
Copy link
Member

gebner commented Dec 14, 2022

Let's just try this out.

bors merge

@bors
Copy link

bors bot commented Dec 15, 2022

@bors bors bot changed the title fix(frontends/lean/definition_cmds): put auto-bound universes before explicit [Merged by Bors] - fix(frontends/lean/definition_cmds): put auto-bound universes before explicit Dec 15, 2022
@bors bors bot closed this Dec 15, 2022
@bors bors bot deleted the auto_bound_univ branch December 15, 2022 00:03
@gebner
Copy link
Member

gebner commented Dec 15, 2022

Apparently this also broke Lean 4 compatibility in the example I posted:

universe a universe z
def foo (α : Type a) (β : Type _) (γ : Type z) := α × β × γ
set_option pp.universes true
#print foo

Now prints u_1 a z instead of a z u_1. I think we should just revert this PR.

gebner added a commit that referenced this pull request Dec 15, 2022
bors bot pushed a commit that referenced this pull request Dec 15, 2022
bors bot pushed a commit that referenced this pull request Dec 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants