-
Notifications
You must be signed in to change notification settings - Fork 0
fix(P-004): capture-aware static-lambda tier — non-capturing lambda is not a region escape #211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| using System; | ||
|
|
||
| namespace Own.Samples; | ||
|
|
||
| // Issue #199 — the SILENT lambda-handler tiers (the static/injected tiers live in | ||
| // AppDomainShutdownSample.cs / LambdaHandlerViewModel.cs). Source lifetime decides the | ||
| // verdict for a lambda exactly as for a method group; a lambda merely can never be | ||
| // `-=`'d (no handle), which matters only when the source actually outlives `this`. | ||
|
|
||
| // BOUNDED / LOCAL source + lambda: the publisher is constructed HERE (a local), so it is | ||
| // method-bounded — it dies with the scope and cannot outlive `this`, so the subscription | ||
| // is no heap leak -> SILENT (the extractor drops source=="local"). The lambda has no `-=` | ||
| // handle, but with a bounded source there is nothing to leak: this IS the | ||
| // "`-=`-impossible-but-bounded" shape that must stay silent. | ||
| public sealed class LocalBoundedLambda | ||
| { | ||
| public void Work() | ||
| { | ||
| var pub = new Publisher(); | ||
| pub.Changed += (s, e) => Console.WriteLine("bounded"); // local source -> SILENT | ||
| pub.Raise(); | ||
| } | ||
| } | ||
|
|
||
| // SELF-OWNED field source + lambda: the class constructs the source (a field it `new`s), | ||
| // so the source<->this cycle is collectable together -> SILENT (self-owned exemption), | ||
| // whether the handler is a lambda (captures `this`) or a method group. | ||
| public sealed class SelfOwnedFieldLambda | ||
| { | ||
| private int _n; | ||
| private readonly Publisher _pub = new Publisher(); | ||
|
|
||
| public SelfOwnedFieldLambda() | ||
| { | ||
| _pub.Changed += (s, e) => _n++; // self-owned source -> SILENT | ||
| } | ||
| } | ||
|
|
||
| // INJECTED source + lambda: the publisher is handed in (a ctor param), so its lifetime is | ||
| // unknown — it may outlive `this`, and the inline lambda has no `-=` handle to ever detach -> | ||
| // OWN001 WARNING (the injected tier — the honest hedge; a WPF/region profile is what escalates | ||
| // it to OWN014). This is also the file's POSITIVE anchor: it is the only class here the extractor | ||
| // emits a component for, so the silent negatives above cannot pass vacuously if this file ever | ||
| // stops being extracted. | ||
| public sealed class InjectedSourceLambda | ||
| { | ||
| private int _n; | ||
|
|
||
| public InjectedSourceLambda(Publisher pub) | ||
| { | ||
| pub.Changed += (s, e) => _n++; // injected source -> OWN001 warning | ||
Check warningCode scanning / Own.NET owned resource not released on all paths (possible leak) Warning
event 'pub.Changed' is subscribed (handler '(s, e) => _n++') but never unsubscribed; its source is an injected dependency whose lifetime is unknown, so it may outlive and keep 'InjectedSourceLambda' alive (possible leak — and being an inline lambda it has no '-=' handle, so it could never be detached) [resource: subscription token]
|
||
|
|
||
| } | ||
| } | ||
|
|
||
| public sealed class Publisher | ||
| { | ||
| public event EventHandler? Changed; | ||
|
|
||
| public void Raise() => Changed?.Invoke(this, EventArgs.Empty); | ||
| } | ||
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.