aliased-mut: a primitive part of a lent object is a copy, also on a path from this #164
Loading…
Reference in a new issue
No description provided.
Delete branch "aliased-mut-primitives"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
What was wrong
aliased-mutcounted a primitive member of a lent object as "a part of it":LEQUALis anumberread before the call. The callee gets its value, not a reference, so nothing it changes through the loan can change what it was given. An adopter had 15 such findings with WebGL constants.What I reproduced on main:
this(this.ctx.gl.LEQUAL, deeperthis.ctx.nested.gl.GREATER,this.settings.depth,this.counter.nthrough a getter, an enum member) was reported every time. The declared type was never followed forthis, only for a parameter or a local.gl.GREATER,const { LEQUAL } = gl) was not reported. The type wasn't settled there, and an unsettled type from a binding is no finding.const ctx = this.ctx: names are bound before the walk, sothisgot the module's owner. The name stood for no path of the method. That is why the adopter'sconst { gl } = ctxform reportedthis.ctx.gl.LEQUALwith no way to settle it.What changed
this(an instance of a module-level class) goes to the whole-program pass, as a path from a binding already did. An unsettled type fromthisis still reported, as before. From a binding it still isn't.member_primitivesettles more types:gl.LEQUAL,gl.ARRAY_BUFFER,node.ELEMENT_NODE) is taken to be a constant. TypeScript's lib declares each such property as a number or a string, except the methodDate.UTCand the single letterBiquadFilterNode.Q(anAudioParam). Both are left out. The newtests/platform_constants.rsparses everylib.*.d.tsand fails on any capitalised member that isn't a primitive, which is how it foundQ. A type the program declares or augments (declare global { interface Window { … } }) is decided by its declaration: tested, still reported.ModeorMode.Fill, are primitives. A class of the program is not.number,string,boolean,bigint,symbol, a literal or a union of them, or set to a literal without a type, and a getter with such a return type. Inherited ones are found too.readonlyobject field (readonly settings: Settings = { … }), which wins over the literal.const x = this.yis now bound with the function around it as owner.Still reported (fixture
loans_primitives)settings.tags,settings.inner,counter.items,this.limits.inner.this.ctx.gl.canvas.both(mut(this.settings), mut(this.settings.inner)).const saving = save(mut(this.settings)); adjust(mut(this.settings), this.settings.depth).constname:const ctx = this.ctx; this.redraw(mut(ctx)). It was missed before because of the owner bug.Adopter tree (
apps packages scripts, main binary and this branch run back to back)state.setDepth(mut(gl), …, gl.LEQUAL)(14) orgl.GREATER(1), withglfromconst { gl, state } = ctxandconst ctx = this.ctx. All are false positives.this.drawStaticChunkBatches(mut(ctx), …)withconst ctx = this.ctx. The method getsthis, which holdsthis.ctx. This is the documented receiver form, and main reports it when writtenmut(this.ctx). These are true positives that the owner bug hid.Tests
cargo nextest run --workspace(fast profile): 416/416 pass.npm run test:rewrites(full): passes after count updates inmisses.txt. Every moved count comes from the new fixture's sites, and no other fixture moved:miss aliased-mut hoist-const6 → 14 (fast and full)new missing-mut hoist-const265 → 294new prefer-option optional-guard338 → 351new unneeded-mut type-alias8 → 9text aliased-mut call16 → 24npm run test:soundness: 16 of 110 classes escape, exactly the listed ones.npm run test:docs: passes.Docs:
docs/rules/aliased-mut.md(What it reports, What the rule can't see, one ✅ example line), the README rules row, and CHANGELOG.Open
useCanvas(mut(gl), gl.canvas)withgla parameter is missed, while the same path fromthisis reported. That asymmetry predates this PR and is kept. Changing it is a policy decision.this.ctx.gl.drawingBufferWidth, a number, is still reported fromthis).@types/…) isn't told apart from lib's, so its capitalised members are taken to be constants. This is documented.🤖 Generated with Claude Code
this61ccef94e85e52863eef