-
-
Notifications
You must be signed in to change notification settings - Fork 659
Remove closures from splitPath and appendSplitPath callbacks #21516
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
Conversation
Thanks for your pull request and interest in making D better, @gorsing! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please see CONTRIBUTING.md for more information. If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment. Bugzilla referencesYour PR doesn't reference any Bugzilla issue. If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog. Testing this PR locallyIf you don't have a local development environment setup, you can use Digger to test this PR: dub run digger -- build "master + dmd#21516" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This prepares the codebase for future improvements, better static analysis, and eliminates risks associated with closure captures in system code.
Why is this required for that? In isolation, this change does not look to be desirable.
Great question, and I appreciate the opportunity to clarify the motivation behind this change.
You're absolutely right — moving from delegates to function pointers with an explicit context may seem like a step back in terms of ergonomics and readability. However, this change is less about immediate benefits and more about reinforcing long-term safety and clarity, especially in system-critical parts of the codebase like Here's why this approach was chosen, and how it aligns with broader goals:1. Prevents Unsafe or Inconsistent Closure CapturesAs outlined in [Issue #21497], closures that capture variables with destructors can lead to subtle and dangerous bugs — including double destruction and use-after-free. These issues often occur silently, when closures unintentionally capture more than intended. 2. Enables Better Static Analysis and Code AuditingClosures hide what is captured, which complicates both compiler reasoning and human review. Explicit context passing makes ownership and data flow more transparent, supporting safer refactoring, improved diagnostics, and better tooling support. 3. Aligns with C-Compatible System-Level DesignModules in 4. Proactively Aligns with Potential Language EvolutionPR #21514 proposes stricter rules regarding closure captures involving destructors. While this direction is still under discussion within the community, adopting a more explicit and controlled approach at this stage helps ensure forward compatibility with possible future language semantics. This change avoids potentially fragile patterns and decouples the current refactoring from future adjustments, making any transition smoother and more predictable. That said, this is merely a suggestion based on my personal perspective, and I fully understand that the community may ultimately decide on a different path. 5. Improves Debugging and Maintenance ExperienceDelegate-based closures introduce implicit memory management and runtime complexity that can obscure stack traces or complicate debugging. Function pointers with explicit context are simpler, more transparent, and easier to reason about in low-level scenarios. So, while the change might appear more verbose at the call site, it's a deliberate tradeoff: clarity, safety, and maintainability over brevity. In areas of the codebase where long-term stability is paramount, this approach helps mitigate risk and reduce technical debt. Of course, I’m open to alternative suggestions if there’s a cleaner or more ergonomic solution that achieves the same safety guarantees — feedback is always welcome. |
@thewilsonator What are your arguments? |
After review by myself and Nic, we have concluded that this is not an appropriate solution. It is a very C centric solution, by using the However, this is not required, if you apply You are more than welcome to join us on Discord if you haven't already. |
Thank you for the detailed feedback. I understand your concern regarding type-safety and the C-style approach. |
As a next step, I’d like to explore a cleaner and more idiomatic approach using I’m going to prototype an alternative version based on your suggestions. Once I have something solid, would it make sense to open a new PR — or would you prefer continued discussion here first? Thanks again for the guidance — I’m looking forward to improving the fix the right way. |
I have replied to your other PR, explaining that the issues you are seeing stem from lifetimes not being respected. You are welcome to give it a go in another PR, such exploratory work is always good for learning new things. But please don't use LLM's to generate text in response to us. |
I really appreciate your patience and guidance. |
This change refactors splitPath and appendSplitPath to use static function pointer callbacks with an explicit context pointer (void*), instead of D closures (delegates).
This prepares the codebase for future improvements, better static analysis, and eliminates risks associated with closure captures in system code.