Skip to content

fix: erase constructor params in toMono - #9222

Closed
zwarich wants to merge 1 commit into
leanprover:masterfrom
zwarich:ctor-params-erased
Closed

zwarich wants to merge 1 commit into
leanprover:masterfrom
zwarich:ctor-params-erased

Conversation

@zwarich

@zwarich zwarich commented Jul 6, 2025

Copy link
Copy Markdown
Contributor

This PR makes the toMono erase all parameters of constructors, not just non-.type parameters. Types are not used in the mono phase, and this makes constructor applications match other applications.

@zwarich
zwarich requested a review from leodemoura as a code owner July 6, 2025 15:14
@zwarich zwarich added the changelog-compiler Compiler, runtime, and FFI label Jul 6, 2025
@zwarich

zwarich commented Jul 6, 2025

Copy link
Copy Markdown
Contributor Author

!bench

@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 Jul 6, 2025
@ghost

ghost commented Jul 6, 2025 •

Copy link
Copy Markdown

Mathlib CI status (docs):

  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 4322a0c7d33fd6722caf84b2c780d72cf824993e --onto 5f818826d14a58b64d42fa8576003cd199adb50a. You can force Mathlib CI using the force-mathlib-ci label. (2025-07-06 15:35:27)
  • ❗ Batteries/Mathlib CI will not be attempted unless your PR branches off the nightly-with-mathlib branch. Try git rebase 53d4139cf169f5e015e278f128dea648799d5971 --onto 5f818826d14a58b64d42fa8576003cd199adb50a. You can force Mathlib CI using the force-mathlib-ci label. (2025-07-06 20:43:32)

@leanprover-bot

leanprover-bot commented Jul 6, 2025 •

Copy link
Copy Markdown
Collaborator

Reference manual CI status:

  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 4322a0c7d33fd6722caf84b2c780d72cf824993e --onto d3dda9f6d4428a906c096067ecb75e432afc4615. You can force reference manual CI using the force-manual-ci label. (2025-07-06 15:35:28)
  • ❗ Reference manual CI will not be attempted unless your PR branches off the nightly-with-manual branch. Try git rebase 53d4139cf169f5e015e278f128dea648799d5971 --onto d3dda9f6d4428a906c096067ecb75e432afc4615. You can force reference manual CI using the force-manual-ci label. (2025-07-06 20:43:34)

@leanprover-bot

Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit f55abc9.
There were significant changes against commit 4322a0c:

  Benchmark      Metric                    Change
  =========================================================
+ channel.lean   unbounded_seq              -2.4%
- liasolver      instructions                2.4% (340.0 σ)
+ stdlib         process pre-definitions    -2.1% (-58.2 σ)

@zwarich
zwarich force-pushed the ctor-params-erased branch from f55abc9 to dc2affa Compare July 6, 2025 20:21
@zwarich

zwarich commented Jul 6, 2025

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-bot

Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit dc2affa.
There were significant changes against commit 53d4139:

  Benchmark   Metric          Change
  ============================================
- liasolver   instructions      1.8% (335.4 σ)
- stdlib      type checking     1.0%  (24.5 σ)

@zwarich
zwarich marked this pull request as draft July 6, 2025 20:53
@zwarich

zwarich commented Jul 6, 2025

Copy link
Copy Markdown
Contributor Author

The codegen differences on that test are quite small and mostly have to do with things like different choices of case/ctor optimizations for Option.none, which I would assume wouldn't amount to a 1.8% instructions difference.

github-merge-queue Bot pushed a commit that referenced this pull request Jul 6, 2025
This PR changes the `toMono` pass to consider the type of an application
and erase all arguments corresponding to erased params. This enables a
lightweight form of relevance analysis by changing the mono type of a
decl. I would have liked to unify this with the behavior for
constructors, but my attempt to give constructors the same behavior in
#9222 (which was in preparation for this PR) had a minor performance
regression that is really incidental to the change. Still, I decided to
hold off on it for the time being. In the future, we can hopefully
extend this to constructors, extern decls, etc.
@zwarich
zwarich force-pushed the ctor-params-erased branch from dc2affa to 5991195 Compare July 10, 2025 03:59
@zwarich

zwarich commented Jul 10, 2025

Copy link
Copy Markdown
Contributor Author

!bench

@leanprover-bot

Copy link
Copy Markdown
Collaborator

Here are the benchmark results for commit 5991195.
The entire run failed.
Found no significant differences.

@zwarich

zwarich commented Jul 20, 2025

Copy link
Copy Markdown
Contributor Author

Going to revisit this later with related optimizations.

@zwarich zwarich closed this Jul 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog-compiler Compiler, runtime, and FFI 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.

2 participants