Skip to content

Conversation

@rikkimax
Copy link
Contributor

Apart from one CI that was timed out, it was green in previous PR: #21494

@rikkimax rikkimax requested a review from ibuclaw as a code owner October 13, 2025 04:45
@dlang-bot
Copy link
Contributor

Thanks for your pull request and interest in making D better, @rikkimax! 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.

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 "master + dmd#21965"

@rikkimax
Copy link
Contributor Author

Will retrigger after: #21966

@thewilsonator
Copy link
Contributor

dependant PR merged

@thewilsonator
Copy link
Contributor

Calling it fast DFA implies there is or will be a slow one. Is there going to be a slow one or can we move all of the .d files in dfa/fast into dfa and remove the fast folder?

@rikkimax
Copy link
Contributor Author

Calling it fast DFA implies there is or will be a slow one. Is there going to be a slow one or can we move all of the .d files in dfa/fast into dfa and remove the fast folder?

If it succeeds, then yes, I intend to also implement a slow DFA.

The slow DFA is meant to be more false positive heavy, but also more accurate. Requiring the use of attributes and changing of code to satisfy the DFA. This would be opt-in.

The fast DFA is meant to be free of false positives, but not necessarily able to model all code. No attributes or changing of code is meant to happen unless it is in some way bad. This would be on by default.

Different target audiences. So they are quite opposite of each other.

@rikkimax
Copy link
Contributor Author

Why hasn't this been merged?

@thewilsonator
Copy link
Contributor

Well it still has PoC in the title of the PR for one, I take it that it is good to go now?

@rikkimax
Copy link
Contributor Author

Yes.

It is PoC since no attributes, and missing features rather than PR being incomplete for its scope.

@thewilsonator thewilsonator merged commit 856f4c7 into dlang:master Oct 19, 2025
44 checks passed
@rikkimax
Copy link
Contributor Author

Okay something changed since the testsuite ran.

src\dmd\dfa\fast\expression.d(1612): Error: no property `toBool` for `ie` of type `dmd.expression.IntegerExp`

                    auto b = ie.toBool;

@thewilsonator
Copy link
Contributor

Oh, you want toBool(ie) there

@rikkimax
Copy link
Contributor Author

It was moved out of being a method, and put as a free-function in expressionsem, fixing.

@thewilsonator
Copy link
Contributor

Of you way need to import dmd.expressionsem;

@nordlow
Copy link
Contributor

nordlow commented Oct 21, 2025

This is awesome! How come this was approved so quickly? Are we suddenly more liberal in adding new -preview features in dmd or has this always been possible?

@rikkimax
Copy link
Contributor Author

This is awesome! How come this was approved so quickly? Are we suddenly more liberal in adding new -preview features in dmd or has this always been possible?

Sort of.

I proposed adding it under a preview switch a few months ago, but I placed some rules upon myself to minimize risk:

  1. No AST modifications, however I do intend to set flags like this will be non-null so can elide on null dereference throw an Error (upcoming work).
  2. No attributes, there will be attributes in the future if this works out, and I intend to have a @__borrows defined in core.attribute just to test that the borrow checker works, however thats a fair bit out from where I am today.

This approach has been applied to Walter's work with the ARM backend. I also got permission for Stefan, to do the same for newCTFE but he hasn't done a PR yet. Better to merge something that is low risk under a preview switch than to see 6+ months worth of work wasted, times X.

And thanks :)

@nordlow
Copy link
Contributor

nordlow commented Oct 21, 2025

This is awesome! How come this was approved so quickly? Are we suddenly more liberal in adding new -preview features in dmd or has this always been possible?

Sort of.

I proposed adding it under a preview switch a few months ago, but I placed some rules upon myself to minimize risk:

1. No AST modifications, however I do intend to set flags like this will be non-null so can elide on null dereference throw an Error (upcoming work).

2. No attributes, there will be attributes in the future if this works out, and I intend to have a `@__borrows` defined in core.attribute just to test that the borrow checker works, however thats a fair bit out from where I am today.

This approach has been applied to Walter's work with the ARM backend. I also got permission for Stefan, to do the same for newCTFE but he hasn't done a PR yet. Better to merge something that is low risk under a preview switch than to see 6+ months worth of work wasted, times X.

And thanks :)

This is fantastic news. Thanks for doing this. I too did experiment with dmd detection of unused variables years ago. What about Stefans' work on type functions?

@nordlow
Copy link
Contributor

nordlow commented Oct 21, 2025

What about extending this DFA to also cover referencing of non-intialized variable values or pointes in cases such as

int *x = void;
auto y = *x; // should error

?

@rikkimax
Copy link
Contributor Author

This is fantastic news. Thanks for doing this. I too did experiment with dmd detection of unused variables years ago. What about Stefans' work on type functions?

If I remember right he gave up on it, and it is full of risk to try to do something like this with that.

What about extending this DFA to also cover referencing of non-intialized variable values or pointes in cases such as

int *x = void;
auto y = *x; // should error

?

Originally I wanted to model type state as a whole, with nullability being a later value after uninitialized.

I may yet decide to implement it.

For now though it's very incremental in development, and I need to see it succeeding before using more of my time on it.

@nordlow
Copy link
Contributor

nordlow commented Oct 22, 2025

Do you have a list of upcoming diagnostics that make use of the infrastructure added here? Just curious which of these that overlap with my pre-existing work and feature requests.

@rikkimax
Copy link
Contributor Author

I do not no, I have goals but the exact order isn't known to me currently.

But the end goal is to try to get a borrow checker akin to what people expect. Anything else is a nice (but intended) bonus.

@ibuclaw
Copy link
Member

ibuclaw commented Dec 31, 2025

This PR introduced a regression

Segmentation fault
...
0x11ed471 Semantic3Visitor::visit(FuncDeclaration*)
	dmd/semantic3.d:1165
0x11e9dcf _D3dmd9semantic3QkFCQs7dsymbol7DsymbolPSQBm6dscope5ScopeZv
	dmd/semantic3.d:90
0x11ea1f6 Semantic3Visitor::visit(Module*)
	dmd/semantic3.d:210
0x11ea1f6 Semantic3Visitor::visit(Module*)
	dmd/semantic3.d:192
0x11e9dcf _D3dmd9semantic3QkFCQs7dsymbol7DsymbolPSQBm6dscope5ScopeZv
	dmd/semantic3.d:90
...

auto ls = new LabelStatement(Loc.initial, Id.returnLabel, fens);
funcdecl.returnLabel.statement = ls;
a.push(funcdecl.returnLabel.statement);

FeatureState dtorFields; // destruct fields of partially constructed objects
// https://issues.dlang.org/show_bug.cgi?id=14246
FeatureState systemVariables; // limit access to variables marked @system from @safe code
bool useFastDFA; // Use fast data flow analysis engine
Copy link
Member

Choose a reason for hiding this comment

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

... it would seem this is the regressing line.

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.

5 participants