Skip to content

feat: make dot notation be affected by export/open#6189

Merged
kmill merged 2 commits intoleanprover:masterfrom
kmill:dot_aliases
Nov 25, 2024
Merged

feat: make dot notation be affected by export/open#6189
kmill merged 2 commits intoleanprover:masterfrom
kmill:dot_aliases

Conversation

@kmill
Copy link
Copy Markdown
Collaborator

@kmill kmill commented Nov 23, 2024

This PR changes how generalized field notation ("dot notation") resolves the function. The new resolution rule is that if x : S, then x.f resolves the name S.f relative to the root namespace (hence it now affected by export and open). Breaking change: aliases now resolve differently. Before, if x : S, and if S.f is an alias for S'.f, then x.f would use S'.f and look for an argument of type S'. Now, it looks for an argument of type S, which is more generally useful behavior. Code making use of the old behavior should consider defining S or S' in terms of the other, since dot notation can unfold definitions during resolution.

This also fixes a bug in explicit-mode generalized field notation (@x.f) where x could be passed as the wrong argument. This was not a bug for explicit-mode structure projections.

Closes #3031. Addresses the Function namespace issue in #1629.

This PR changes how generalized field notation ("dot notation") resolves the name of the function, adds a feature where terms such as `x.toString` can resolve as `toString x` as a last resort, and modifies the `Function` dot notation to always use the first explicit argument rather than the first function argument. The new rule is that if `x : S`, then `x.f` resolves the name `S.f` relative to the root namespace (hence it now responds to `export` and `open). Breaking change: aliases now resolve differently. Before, if `x : S`, and `S.f` is an alias for `S'.f`, then `x.f` would use `S'.f` and look for an argument of type `S'`. Now, it looks for an argument of type `S`, which is more generally useful behavior. Code making use of the old behavior should consider defining `S` or `S'` in terms of the other, since dot notation can unfold definitions during resolution.

This also fixes a bug in explicit field notation (`@x.f`) where `x` could be passed as the wrong argument.

Closes leanprover#3031
@kmill kmill added the changelog-language Language features and metaprograms label Nov 23, 2024
@kmill
Copy link
Copy Markdown
Collaborator Author

kmill commented Nov 23, 2024

This almost addresses #5482. If there were the additional features from #1629 (see comments), then declarations could be exported into a different namespace and then be used with different types.

@github-actions github-actions bot added the toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN label Nov 23, 2024
ghost pushed a commit to leanprover-community/batteries that referenced this pull request Nov 23, 2024
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Nov 23, 2024
@ghost
Copy link
Copy Markdown

ghost commented Nov 24, 2024

Mathlib CI status (docs):

@ghost ghost added breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan builds-mathlib CI has verified that Mathlib builds against this PR and removed breaks-mathlib This is not necessarily a blocker for merging: but there needs to be a plan labels Nov 24, 2024
@kmill kmill changed the title feat: dot notation improvements feat: make dot notation be affected by export/open Nov 25, 2024
ghost pushed a commit to leanprover-community/batteries that referenced this pull request Nov 25, 2024
ghost pushed a commit to leanprover-community/mathlib4 that referenced this pull request Nov 25, 2024
@kmill kmill added this pull request to the merge queue Nov 25, 2024
Merged via the queue into leanprover:master with commit 606aedd Nov 25, 2024
kmill added a commit to kmill/lean4 that referenced this pull request Nov 30, 2024
This PR introduces the `dotParam` marker to indicate which parameter should be used for generalized field notation ("dot notation"). Example:
```
class A (α : Type _) where
  a : α → Nat

def A.get {α : Type _} [A α] (self : dotParam α) : Nat := a self

structure B where
  b : Nat

instance : A B := ⟨B.b⟩

namespace B
export A (get)
end B

#check fun (b : B) => b.get
-- b.get : Nat
```
The pretty printing code is modified to support the `export`-resolved dot notation introduced in leanprover#6189.

Closes leanprover#1629, closes leanprover#5482
github-merge-queue bot pushed a commit that referenced this pull request Dec 10, 2024
…n-API `export`s" (#5689)

This PR adjusts the way the pretty printer unresolves names. It used to
make use of all `export`s when pretty printing, but now it only uses
`export`s that put names into parent namespaces (heuristic: these are
"API exports" that are intended by the library author), rather than
"horizontal exports" that put the names into an unrelated namespace,
which the dot notation feature in #6189 now incentivizes.

Closes the already closed #2524
luisacicolini pushed a commit to opencompl/lean4 that referenced this pull request Jan 21, 2025
…n-API `export`s" (leanprover#5689)

This PR adjusts the way the pretty printer unresolves names. It used to
make use of all `export`s when pretty printing, but now it only uses
`export`s that put names into parent namespaces (heuristic: these are
"API exports" that are intended by the library author), rather than
"horizontal exports" that put the names into an unrelated namespace,
which the dot notation feature in leanprover#6189 now incentivizes.

Closes the already closed leanprover#2524
JovanGerb pushed a commit to JovanGerb/lean4 that referenced this pull request Jan 21, 2025
This PR changes how generalized field notation ("dot notation") resolves
the function. The new resolution rule is that if `x : S`, then `x.f`
resolves the name `S.f` relative to the root namespace (hence it now
affected by `export` and `open`). Breaking change: aliases now resolve
differently. Before, if `x : S`, and if `S.f` is an alias for `S'.f`,
then `x.f` would use `S'.f` and look for an argument of type `S'`. Now,
it looks for an argument of type `S`, which is more generally useful
behavior. Code making use of the old behavior should consider defining
`S` or `S'` in terms of the other, since dot notation can unfold
definitions during resolution.

This also fixes a bug in explicit-mode generalized field notation
(`@x.f`) where `x` could be passed as the wrong argument. This was not a
bug for explicit-mode structure projections.

Closes leanprover#3031. Addresses the `Function` namespace issue in leanprover#1629.
JovanGerb pushed a commit to JovanGerb/lean4 that referenced this pull request Jan 21, 2025
…n-API `export`s" (leanprover#5689)

This PR adjusts the way the pretty printer unresolves names. It used to
make use of all `export`s when pretty printing, but now it only uses
`export`s that put names into parent namespaces (heuristic: these are
"API exports" that are intended by the library author), rather than
"horizontal exports" that put the names into an unrelated namespace,
which the dot notation feature in leanprover#6189 now incentivizes.

Closes the already closed leanprover#2524
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

builds-mathlib CI has verified that Mathlib builds against this PR changelog-language Language features and metaprograms toolchain-available A toolchain is available for this PR, at leanprover/lean4-pr-releases:pr-release-NNNN

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Using open or export does not make names accessible for extended field notation (dot notation)

1 participant