Repository navigation
-mm=own: @lends, and a string parameter the body assigns owns what it holds - #623
Merged
Merged
Conversation
… holds
- `@lends("p")` says a function's result is a borrow of argument p: the
caller owns nothing of it and it may not outlive p. It crosses modules
through __decls, is checked against the body and family overrides, and
names one parameter; it cannot be combined with @borrows.
- Under own a string parameter the body assigns, including `p.length = n`,
starts a local of its own made from a copy, as rc already did. Left as the
parameter's slot, the assigned string leaked and `return this` returned a
copy read up to its first NUL: the default library's
`"".clone().resize(n)` returned one byte that its caller filled with n,
which corrupted the own DefaultLib's regexp results.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes the two follow-ups left by #622.
Corrupted regexp strings in an own DefaultLib. This turned out not to be a borrowed temporary.
resizeassigns itsthisparameter (this.length = n). Under own, a string parameter's slot did not own what was assigned to it, which caused two problems:return thisreturned ats.StringCopyof it. The copy is read up to the first NUL, so it came back one byte long, and the caller ("".clone().resize(len)inMatchResults.get,padStart,repeat, ...) then wrotelenbytes into it.Now, under own, a string parameter that the body assigns (including
p.length = n) starts a local of its own, made from a copy (mlirGenFunctionOwnAssignedParams), as rc already did. Assigned class parameters are still rejected, as before. Test:own_string_param_assigned.ts, run under own, rc and gc. It fails without the fix.@lends("p"). A new marker says that a function's result is a borrow of the argumentp(__own_result_borrows). The caller owns nothing of it, and it may not outlivep. Until now an exported function like that was rejected, because callers in other modules couldn't know.@keepsbut not with@borrows.__declsand copied onto dynamic-import globals.@keepsalone is told to add@lends; a body that keeps an argument under@lendsalone is told to add@keeps.@lendsor@keepswould put the fact in its signature.Tests:
own_lends.tsruns under own, rc and gc.own_err_lends_*cases cover the errors.import_own_markers(under gc, rc and own, compiled and JIT) andimport_own_markers_lent_outlives.Full suite: 4827/4827 passed (Release, Windows), with DefaultLib rebuilt for gc, rc, none and own.
matchAll,padStartandrepeatthrough the own DefaultLib now give correct results.🤖 Generated with Claude Code