Skip to content

chore(scripts): handle simple to_additive deprecations#38635

Draft
Fieldnote-Echo wants to merge 1 commit intoleanprover-community:masterfrom
Fieldnote-Echo:NSpe/add-deprecations-to-additive
Draft

chore(scripts): handle simple to_additive deprecations#38635
Fieldnote-Echo wants to merge 1 commit intoleanprover-community:masterfrom
Fieldnote-Echo:NSpe/add-deprecations-to-additive

Conversation

@Fieldnote-Echo
Copy link
Copy Markdown
Contributor

@Fieldnote-Echo Fieldnote-Echo commented Apr 28, 2026

Closes #38550.

This updates scripts/add_deprecations.sh so that, when a renamed declaration is near an existing @[to_additive] attribute, the script also emits the additive deprecation alias in the common default-name case.

For example, foo_mul -> bar_mul now produces:

@[deprecated (since := "...")]
alias foo_add := bar_add

@[to_additive existing, deprecated (since := "...")]
alias foo_mul := bar_mul

This is intentionally conservative and text-based, matching the existing script. It handles common name translations such as mul/add, prod/sum, one/zero, inv/neg, and div/sub, and skips cases that look like they need less common to_additive name generation.

Tested with a local six-case fixture and a scratch Lean file confirming that the generated alias form compiles and produces deprecation warnings for both names.

I opened this as draft because I still count as a new contributor under the LLM-assisted PR policy. I have one merged mathlib PR (#36443), and this is a one-file script patch that I reviewed/tested manually. I'll leave it as draft unless a maintainer gives it the green light to flip ready.

I used Claude assistance while drafting and testing the patch. I reviewed the final diff manually and tested the generated Lean form locally.

…renames

When a renamed declaration carries `@[to_additive]`, emit the additive
deprecation alias first, followed by the multiplicative alias tagged
`@[to_additive existing, deprecated ...]` so the additive deprecation is
rederived through the to_additive machinery.

Detection uses an --unified=3 diff so awk can read the attribute from
context lines. The additive name is computed by a small substitution
table (mul/add, prod/sum, one/zero, inv/neg, div/sub) over declaration-
name tokens; typeclass prefixes are not renamed.

When the substituted name still contains `Monoid`/`Group`/`Semigroup`
without an `Add` prefix, the additive alias is skipped — those renames
are left for manual deprecation rather than emitting a name that does
not exist.

Adding or removing `@[to_additive]` in the rename does not trigger an
additive alias (regex anchored to context lines).
`@[to_additive_relevant_arg]` is rejected by an identifier boundary.

The first-comma-only split in addDeprecations preserves commas inside
the deprecation text.

Closes leanprover-community#38550.
@github-actions github-actions Bot added the new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community! label Apr 28, 2026
@github-actions
Copy link
Copy Markdown

Welcome new contributor!

Thank you for contributing to Mathlib! If you haven't done so already, please review our contribution guidelines, as well as the style guide and naming conventions. In particular, we kindly remind contributors that we have guidelines regarding the use of AI when making pull requests.

We use a review queue to manage reviews. If your PR does not appear there, it is probably because it is not successfully building (i.e., it doesn't have a green checkmark), has the awaiting-author tag, or another reason described in the Lifecycle of a PR. The review dashboard has a dedicated webpage which shows whether your PR is on the review queue, and (if not), why.

If you haven't already done so, please come to https://leanprover.zulipchat.com/, introduce yourself, and mention your new PR.

Thank you again for joining our community.

@github-actions
Copy link
Copy Markdown

PR summary 35aa1b8156

Import changes for modified files

No significant changes to the import graph

Import changes for all files
Files Import difference

Declarations diff

+ foo_add
+ foo_mul

You can run this locally as follows
## from your `mathlib4` directory:
git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci

## summary with just the declaration names:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh <optional_commit>

## more verbose report:
../mathlib-ci/scripts/pr_summary/declarations_diff.sh long <optional_commit>

The doc-module for scripts/pr_summary/declarations_diff.sh in the mathlib-ci repository contains some details about this script.


No changes to technical debt.

This script lives in the mathlib-ci repository. To run it locally, from your mathlib4 directory:

git clone https://github.com/leanprover-community/mathlib-ci.git ../mathlib-ci
../mathlib-ci/scripts/reporting/technical-debt-metrics.sh pr_summary
  • The relative value is the weighted sum of the differences with weight given by the inverse of the current value of the statistic.
  • The absolute value is the relative value divided by the total sum of the inverses of the current values (i.e. the weighted average of the differences).

@github-actions github-actions Bot added the CI Modifies the continuous integration setup or other automation label Apr 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI Modifies the continuous integration setup or other automation new-contributor This PR was made by a contributor with at most 5 merged PRs. Welcome to the community!

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make scripts/add_deprecations.sh support additivised declarations

1 participant