Skip to content

fix #21409 - Closure not created for default arguments of a static function if called from a nested one#21453

Closed
ghost wants to merge 1 commit intostablefrom
unknown repository
Closed

fix #21409 - Closure not created for default arguments of a static function if called from a nested one#21453
ghost wants to merge 1 commit intostablefrom
unknown repository

Conversation

@ghost
Copy link
Copy Markdown

@ghost ghost commented Jun 16, 2025

Default args sema appears to be already run but sometimes it needs to be recontextualized

@dlang-bot
Copy link
Copy Markdown
Contributor

dlang-bot commented Jun 16, 2025

Thanks for your pull request and interest in making D better, @baz-bg! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the coverage diff by visiting the details link of the codecov check)
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

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 references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

⚠️⚠️⚠️ Warnings ⚠️⚠️⚠️

  • In preparation for migrating from Bugzilla to GitHub Issues, the issue reference syntax has changed. Please add the word "Bugzilla" to issue references. For example, Fix Bugzilla Issue 12345 or Fix Bugzilla 12345.(Reminder: the edit needs to be done in the Git commit message, not the GitHub pull request.)

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "stable + dmd#21453"

Comment thread compiler/src/dmd/expressionsem.d Outdated
Comment thread compiler/test/runnable/issue21409.d
Copy link
Copy Markdown
Member

@ibuclaw ibuclaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See review.

  1. The current proposed fix will run semantic on the variable declaration from a scope different from where it is declared, which isn't sound from a semantic POV.
  2. There already exists a function for checking each variable reference in arg, that is lambdaCheckForNestedRef(arg, sc). I suggest to call this function after inlineCopy and resolveLoc. Propagate the return value if an error occurs (return true).
  3. Split up tests into one per function, add a couple more different variations of the expression, such as uint c0 = p0 + 1 or uint c0 = fun(p0). I would also suggest an = this example, but it would appear dmd is unable to inline a field if its object has a member function (https://compiler-explorer.com/z/PrxjnzcE3)
  4. Please target stable branch.

@ghost ghost changed the base branch from master to stable June 19, 2025 18:34
@ghost
Copy link
Copy Markdown
Author

ghost commented Jun 19, 2025

@ibuclaw ok, expected for the this test. If I change the inline cost of the ThisExp, your test compiles but that might cause unwanted compiler slowdowns.

Comment thread compiler/src/dmd/expressionsem.d
@ibuclaw
Copy link
Copy Markdown
Member

ibuclaw commented Jun 19, 2025

@ibuclaw ok, expected for the this test. If I change the inline cost of the ThisExp, your test compiles but that might cause unwanted compiler slowdowns.

GDC doesn't use the front-end inliner, so it "just works" for that compiler. The use of inlineCopy here for default arguments is an odd choice, because "inline" doesn't appear anywhere in user code (I forgot I once tried to make DMD exactly same as GDC a few years ago #14309).

If inlineCopy really is unavoidable for DMD, then it should ignore cost when it comes to copying default arguments.

A separate issue can be used to track this though, not here.

@ibuclaw
Copy link
Copy Markdown
Member

ibuclaw commented Jun 19, 2025

@baz-bg thanks for tackling this by the way.

Default arguments is a bit of a "left behind" feature that has not been kept up to date with other development in the language - no safety, purity, nogc checks, etc.

@ghost ghost requested a review from ibuclaw June 21, 2025 15:17
@ghost ghost closed this by deleting the head repository Jul 9, 2025
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants