Skip to content

Conversation

@rikkimax
Copy link
Contributor

Throwing the experimental fast DFA engine at CI to see what happens, this PR is not going to be merged can be ignored.

@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#21494"

@rikkimax rikkimax force-pushed the idea-dfa branch 7 times, most recently from c1f7ebf to f85972d Compare June 29, 2025 16:03
@rikkimax
Copy link
Contributor Author

rikkimax commented Jun 29, 2025

Ugh isBinExp doesn't work for EXP.loweredAssignExp flags are not set for it even though the hierarchy matches.

@rikkimax rikkimax force-pushed the idea-dfa branch 21 times, most recently from a4354e5 to b741ece Compare July 1, 2025 03:48
@benjones
Copy link
Contributor


__stdin.d(14): Error: Assert can be proven to be false
assert(a is b);

shouldn't a and b both be null at that point?

@rikkimax
Copy link
Contributor Author

__stdin.d(14): Error: Assert can be proven to be false
assert(a is b);

shouldn't a and b both be null at that point?

Yes, it's a false positive and needs fixing on my end.

@rikkimax rikkimax force-pushed the idea-dfa branch 9 times, most recently from dccf42e to 4bf8120 Compare October 2, 2025 22:01
@rikkimax
Copy link
Contributor Author

rikkimax commented Oct 2, 2025

True positives:

runnable\template9.d(3410): Error: Argument is expected to be non-null but was null
    mat.map_front12186!((in r) => 0);              // OK
       ^
runnable\template9.d(3400):        For parameter `r` in argument 0
    auto map_front12186(Range)(Range r)
compilable\test21299d.d(25): Error: Argument is expected to be non-null but was null
        moveToEnd([], hook);
                 ^
compilable\test21299d.d(16):        For parameter `array` in argument 0
    void moveToEnd(T, Pred = DefaultPredicates.IsEqual!T)(T[] array, T element, Pred pred = Pred.init)
compilable\test22916.d(29): Error: Argument is expected to be non-null but was null
    g = front_p(_errors);   // should pass
               ^
compilable\test22916.d(21):        For parameter `p` in argument 0
   ref char* front_p(ref return scope char** p) { return *p; }

#21941

Overall the interprocedural nullability analysis looks to be working. Although unit-threaded will need to be analysed (can't be bothered to do it atm).

@rikkimax rikkimax force-pushed the idea-dfa branch 5 times, most recently from 5c26677 to 699ec5e Compare October 9, 2025 04:26
@rikkimax rikkimax force-pushed the idea-dfa branch 7 times, most recently from d2ff64e to fbc977e Compare October 13, 2025 03:18
@rikkimax
Copy link
Contributor Author

rikkimax commented Oct 13, 2025

Waiting on this PR to go green and the following PR's to be merged.

Will follow with final PR after this.

Comment on lines +78 to +83
Is any symbol this scope is applied known to have a compile time only accessible context.
This is not the same as `skipCodegen` nor can it be used to contribute to this.
It is meant for analysis engines to be conservative in what functions they analyse,
to prevent perceived false positives for meta-programming heavy code.
*/
bool knownACompileTimeOnlyContext;
Copy link
Contributor

Choose a reason for hiding this comment

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

Grammar?
Is any symbol this scope is applied [to?] known to have a compile time only accessible context.

bool knownACompileTimeOnlyContext; feels like it should be
knownCompileTimeOnlyContext or knownAtCompileTimeOnlyContext

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Singular is correct, it may not be exclusive to CT.

So something like knownToHaveANonExclusiveCompileTimeOnlyContext.

However this isn't the right way to solve it long term. The right solution is to have something like @__ctfe and tell people to annotate their code appropriately rather than letting the compiler ignore problems. I sent Walter and Atila an email requesting that they think about where they want to go here, but that doesn't appear to have gone anywhere.

The adding of to will happen on follow up PR.

/// Information for data flow analysis per parameter
extern(D) struct ParameterDFAInfo
{
/// Parameter id: -1 this, -2 return, otherwise it is FuncDeclaration.parameters
Copy link
Contributor

Choose a reason for hiding this comment

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

FuncDeclaration.parameters index?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, updated for next PR.

"Sema1: Function ",
"Sema2: ",
"Sema3: ",
"DFA: ",
Copy link
Contributor

Choose a reason for hiding this comment

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

Data Flow Analysis. also feel free to add more events (if there are logical places to put them) if it makes producing statistics for how much time this consumes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is enough for the fast DFA.

Having only like 8 instances show up on 100k LOC codebase is pretty telling and they are 1-2ms each.

I'm sure it'll need adjusting for the error pass, and slow DFA, but we aren't there right now.

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