-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(frontends/lean/elaborator): backport Lean 4 field notation (#757)
This backports a number of features from the Lean 4 field notation ("dot notation") and fixes a couple of bugs. * Field notation not in a function application position (i.e., `x.f` instead of `x.f a b c`) now uses the general resolution procedure rather than a stripped-down one that is unaware of extended field notation. It also now correctly records its source position and correctly allows local recursive calls to have the recursive argument be after the first. * If `f` is a function, then `f.foo` resolves to `function.foo f` (or more precisely `f` is inserted at the first function argument of `function.foo`). * If `s` is a structure, then `s.foo` is resolved in the following way: * If `foo` is a field of `s`, then it resolves into a projection. (Unchanged.) * If the structure's namespace or one of its ancestor's namespaces contains `foo`, then resolves to that. (Change: now considers ancestors too.) * If the structure's namespace contains `foo` as an alias, then resolves to that. (New, though note it is not fully functional since Lean 3 alias resolution is not as capable as Lean 4's.) * We leave the "insufficient number of arguments" error (deferring Lean 4's lambda synthesis to a potential future PR), but we improve error recovery, making it more likely that users can go-to definition on the field. One breaking change (and a consequence of the first item) is illustrated by the following example: ```lean structure bar := (f : ∀ {m : ℕ}, m = 0) variables (s : bar) #check (s.f : 37 = 0) -- formerly #check (s.f : ∀ {m : ℕ}, m = 0) ``` To get the old behavior, one can generally add lambdas, for example `(λ _, s.f : ∀ {m : ℕ}, m = 0)`. To preserve reverse compatibility, we (temporarily?) add a feature that if the elaborator fails to find an explicit argument corresponding to the structure, it will insert the structure as the first explicit argument. This matches the previous behavior for non-application dot notation (`x.f`). The reason for including this feature is that mathlib has been misusing this type of dot notation for terms with `has_coe_to_fun` instances. It is not currently compatible with Lean 4. (Note that, when paired with the new aliases feature, this feature allows for extension methods.)
- Loading branch information
Showing
12 changed files
with
453 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.