-
-
Notifications
You must be signed in to change notification settings - Fork 611
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
Add deinitializeDMD
function to deinitialize the front end
#8528
Conversation
Thanks for your pull request and interest in making D better, @jacob-carlborg! 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 fetch digger
dub run digger -- build "master + dmd#8528" |
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.
I think we should add the unittests directly in the source code. That way they are also automatically run on all platforms that the auto-tester supports and are easier to find and we could even shown some of them in the documentation.
test/unit/source/deinitialization.d
Outdated
immutable init = global.init; | ||
assertStructsEqual(global, init); | ||
|
||
global._init(); |
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.
Partially OT: What do you think about renaming this to initialize
, s.t. the pattern matches with the other modules?
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.
And also for the same reason we renamed TypeInfo.init
to TypeInfo.initializer
.
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.
Yes, I would like to rename all _init
to initialize
. That's why I named it deinitialize
and not deinit
. This will get rid of the ugly underscore prefix and spell out the full name instead of an abbreviation. A double win, in my opinion 😃.
I think there will be too much code in the existing modules. If we would covert all the existing tests to unit tests directly in the existing modules it would add another 200k lines. I think it still will be difficult to test individual functions. I'm thinking we need to start with tests that uses the front end to lex and parse and perhaps run semantic analysis. The tests would then do some assertions on the AST. If there's not a single function that is being it will be more difficult to find a good place to put the test. There will not always be an obvious module to place it in. |
e939e4b
to
886d5dc
Compare
@wilzbach Dub is not installed on the auto-tester machines. Can we installed that or do I need to find a different approach? |
That's a question for @braddr. |
@jacob-carlborg would it be possible to have the tests be a GitHub project and test it with build kite, substituting dmd master with the merge of the PR being tested? |
Would be a pain to upgrade them whenever this still unstable frontend API changes. |
I guess the only way for now is to only run these tests on CircleCi. |
I was planning to replace Dub with a D script. That should work everywhere? |
Yes, but what do you mean by replace? Isn't this partially already done by build.d? |
Currently |
Ah good. I thought you were talking about this, but I wasn't sure. |
886d5dc
to
f55d206
Compare
efc0f48
to
1341200
Compare
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.
Looks great! Just a few minor nits
- a lot of (probably necessary) normalization happens here
- consistency
unittest
vs.unit_test
vs.unit_tests
(this PR uses all three)
test/run.d
Outdated
}; | ||
|
||
return target; | ||
} |
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 won't play nice with rebuilds.
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.
Any suggestions?
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.
It's not that important as we currently don't have many tests, but in the future we probably have to do:
- write a file after every invocation
- lastEdit = MAX(timestamp of src/*.d)
- compare lastEdit with the timestamp of the written file
(that's how the current testsuite does it, except that it checks the timestamp of the DMD binary which wouldn't be helpful here.)
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.
That could work, but it would complicate the unit test runner even more. It would also need to check unit/*.d
.
A few? 😃 |
I don't use Here's the deal. In English it's called "unit test", it's also what the D spec calls it in the title [1]. Therefore I use "unit test" or "unit tests" (when it's plural) everywhere it's possible. It's not possible to use "unit test" for an identifier in D source code, therefore the convention is to use camel casing, i.e. |
41a7a30
to
10f87db
Compare
10f87db
to
a3fe274
Compare
Fixed (not sure why I can't reply inline to #8528 (comment)). |
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.
LGTM! (just a few final questions out of interest).
test/tools/unit_test_runner.d
Outdated
runConfig(); | ||
buildStrtold(); | ||
execute(dmdPath, "@" ~ cmdfilePath); | ||
execute(outputPath); |
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.
So I presume that you save the commands to a file because you want to be able to invoke DMD outside of this tool, but why not add -run
to the command flags above?
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.
So I presume that you save the commands to a file because you want to be able to invoke DMD outside of this tool
The assumption is that there might be a lot of files added and I think Windows has a limitation on how many arguments can be passed to an application.
but why not add
-run
to the command flags above?
It didn't work. Seems to be some kind of bug. I didn't mange to create a small test case.
test/tools/unit_test_runner.d
Outdated
cmd ~= "/etc"; | ||
|
||
execute(cmd); | ||
} |
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.
Why do we need this? This file will be generated as part of either building DMD or building DMD as a library with Dub.
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 is not using Dub anymore. I failed to get it to install. But it might not be required since the assumption is that DMD is built anyway. I'll see if I can remove it.
test/run.d
Outdated
}; | ||
|
||
return target; | ||
} |
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.
It's not that important as we currently don't have many tests, but in the future we probably have to do:
- write a file after every invocation
- lastEdit = MAX(timestamp of src/*.d)
- compare lastEdit with the timestamp of the written file
(that's how the current testsuite does it, except that it checks the timestamp of the DMD binary which wouldn't be helpful here.)
BTW as this does have an impact on the testsuite and tooling based on it it would be amazing if @CyberShadow or @MartinNowak could have a quick look over this too. |
My first impression: that's a lot of kinds of changes in a single commit. I would suggest splitting the changes into separate commits (or PRs, as often argued by Walter), with one kind of change in one commit. |
There are two kinds of changes: a unit test runner is added and a new function to deinitialize the frontend. What complicates things are that we have five CI systems and two different ways to invoke the tests.
I bet if I do that there will be complains that code is added that doesn't do anything. |
I haven't really been following this side of things. As for the components I'm responsible for, Digger just runs
Can this be done in a separate commit or PR? |
Yes, anything is possible. |
Created a new PR with only the unit test runner: #9333. |
a3fe274
to
16ec85c
Compare
This PR now contains two commits, one which adds the unit test runner and one which adds the deinitialization function. When #9333 is merged I'll rebase this PR and the unit test runner commit will be gone from this PR. |
16ec85c
to
acc1249
Compare
This is a start of being able to restore the global state initialized by `initDMD` to its original state. It only deinitializes state initialized by `initDMD`, state store directly inside functions are not restored. This is useful to invoke the compiler multiple times within the same application. This allows to write more fine grained tests for the compiler, more of a unit test style compared to the current end to end tests.
acc1249
to
46c27f1
Compare
Is blocking: #9350. |
This is a start of being able to restore the global state initialized by
initDMD
to its original state. It only deinitializes state initialized byinitDMD
, state store directly inside functions are not restored.This is useful to invoke the compiler multiple times within the same application. This allows to write more fine grained tests for the compiler, more of a unit test style compared to the current end to end tests.