objectionary / objectionary/lints
`unoptimizable-recursion` falsely indicates autonamed identifiers as defects
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 14
- Forks
- 39
- Avg merge
- 22h 54m
- Merged PRs (30d)
- 90
Description
unoptimizable-recursion names the offending formation with whatever is in @name, including the auto-generated cactus names the parser invents, so the defect points at an identifier the author never wrote and cannot search for.
Run over the parsed XMIR of eo-runtime/src/main/eo/directory.eo (objectionary/eo at b747717325):
directory.xmir:115 warning experimental
The recursion in "a🌵100-6" cannot be turned into a loop, no self-call sits in a tail position
The name comes from the XMIR:
<o base="ξ.ρ.a🌵100-6"
line="115"
loc="Φ.directory.walk.a🌵99-4.a🌵100-6.earlier"
name="earlier"
pos="9">
a🌵100-6 is what the parser generates for an object written with the >> auto-name suffix (§9.2) — in the source, line 115 of directory.eo is
^.stepped rest.tail > earlier
inside a [^ accum prefix dir] >> walked / [^ rest] >> stepped pair, neither of which has a name a reader could match against a🌵100-6.
src/main/resources/org/eolang/lints/design/unoptimizable-recursion.xsl:63 selects every named formation:
<xsl:for-each select="//o[eo:abstract(.) and @name and parent::o and o[@name='φ']]">
and line 82 prints the name as it stands:
<xsl:text>The recursion in </xsl:text>
<xsl:value-of select="eo:escape(@name)"/>
The rest of the codebase treats a cactus name as something not to talk about — funcs/special-name.xsl:10 exists for exactly this:
<xsl:sequence select="$name = 'φ' or $name = $eo:lambda or $name = $eo:xi or contains($name, $eo:cactoos)"/>
and anemic-getter, compound-name, invalid-name-notation, non-kebab-name and unsorted-named-attributes all call eo:special() before reporting.
Suggested fix
Either skip the auto-named formations, if the advice cannot be acted on without a name:
<xsl:for-each select="//o[eo:abstract(.) and @name and not(eo:special(@name)) and parent::o and o[@name='φ']]">
or keep reporting them and say where they are instead of what they are called — the @loc of the same node (Φ.directory.walk.a🌵99-4.a🌵100-6) is not much better, but the enclosing named ancestor is:
<xsl:value-of select="eo:escape((ancestor::o[@name and not(eo:special(@name))])[last()]/@name)"/>
which would say "the recursion inside walk", a name the author can find.
The choice matters beyond this rule: >> is the idiomatic way to write a helper in the runtime, so any rule that reports on formations will meet cactus names.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/main/resources/org/eolang/lints/design/unoptimizable-recursion.xsl at lines 63 and 82, then read funcs/special-name.xsl to understand how cactus names are identified. Run the rule on the parsed directory.eo XMIR and make the warning either skip auto-named formations or identify their enclosing named ancestor, so it no longer points authors to an unsearchable cactus name.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- xml
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100