Conversation
|
Thanks for your pull request and interest in making D better, @thewilsonator! 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#8609" |
|
Would be better if each new function were its own commit, or even better its own PR. But a few global comments before I even attempt to review this: 1) All new functions should have full DDoc headers with |
|
Will do func per commit.
|
Sorry, I didn't look at it in detail. It's hard to see the surround scope in these diffs. It's not a concern if the scope is private. |
|
Yeah, hopefully will be more obvious when I do it 1 commit per function. |
|
Sorry, this is pretty much impossible to review, and no description of what is being done here. Try multiple PRs, each with a smallish chunk (not multiple commits to one PR). Is there a reason to combine all these into one PR? |
src/dmd/semantic3.d
Outdated
|
|
||
| assert(funcdecl.type == f || (funcdecl.type.ty == Tfunction && f.purity == PURE.impure && (cast(TypeFunction)funcdecl.type).purity >= PURE.fwdref)); | ||
| f = cast(TypeFunction)funcdecl.type; | ||
| void semantic() |
There was a problem hiding this comment.
Naming this function semantic is really confusing. In dmd there are 3 semantic stages named bluntly dsymbolSemantic, semantic2 and semantic3. Although the function is defined in the file semantic3, on caller site it is not obvious to the reader which of the semantic passes it is calling. I would recommend renaming it doSemantic3 or semantic3Impl or whatever that makes it obvious that it's the invocation of semantic3
src/dmd/semantic3.d
Outdated
| sym.loc = funcdecl.loc; | ||
| sym.endlinnum = funcdecl.endloc.linnum; | ||
| sc2 = sc2.push(sym); | ||
| private struct FuncDeclSem |
There was a problem hiding this comment.
Is this struct really needed? Why not just free functions?
There was a problem hiding this comment.
Making smaller PRs is the way to go here and I suggest first breaking the visit(FuncDeclaration) method into smaller functions. After all those PR's are merged you should try submitting the PR with the creation of the struct FuncDeclSem because it will be more obvious if the struct is needed or not. Smaller refactoring PRs are easy to review and merge.
2f90a80 to
2f3c76d
Compare
|
The struct is absolutely required, otherwise each function call will take a ridiculous number of arguments. The struct will hold each used local variable of |
2f3c76d to
3741497
Compare
| } | ||
| } | ||
|
|
||
| private struct FuncDeclSem3 |
There was a problem hiding this comment.
Maybe you should instead move this to a new module which encapulates running semantic on FuncDeclaration, you could also move functionSemantic and functionSemantic3 there too.
module dmd.funcsemantic;
extern(C++) bool functionSemantic(FuncDeclaration fd);
extern(C++) bool functionSemantic3(FuncDeclaration fd);
private struct Semantic3Function // Or whatever you insist on naming it.
{
FuncDeclaration funcdecl;
}
The visitor entry in semantic3.d could then just call functionSemantic3.
There was a problem hiding this comment.
Actually, the tangle is even worse than I thought.
We have the following methods that do "semantic" on a function.
- DsymbolSemanticVisitor::visit(FuncDeclaration)
- DsymbolSemanticVisitor::funcDeclarationSemantic(FuncDeclaration)
- FuncDeclaration::functionSemantic
- FuncDeclaration::functionSemantic3
- Semantic3Visitor::visit(FuncDeclaration)
I revise my suggestion, they should probably go into two separate leaf modules - funcsemantic and funcsemantic3 - each with one public entry point named accordingly.
There was a problem hiding this comment.
You're saying fold Semantic3Visitor::visit(FuncDeclaration) out of https://github.com/dlang/dmd/blob/master/src/dmd/func.d#L391 so that it calls the function directly? Sure, but I think it would be better suited to a later PR. I want to get this refactored to a comprehendible state so I can fix 14246 with hopefully a bit more finesse than last time it was tried.
I've half a mind to (eventually) move all the semantic analysis modules to a separate directory, src/dmd is mighty cluttered.
I think this is ready to be merged, not sure why buildkite is failing.
| } | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
I see the point of factoring out checkInContractOverrides() into a separate function, but I don't see the point of creating FuncDeclSem3?
There was a problem hiding this comment.
It will hold local variables of visit(FuncDeclaration) so that there won't be heaps of arguments to the function.
There was a problem hiding this comment.
We already have Scope for that.
|
Can we move forward with this? I'm not sure why build kite is failing though. |
| } | ||
|
|
||
| uint oldErrors = global.errors; | ||
| auto fds = FuncDeclSem3(funcdecl,sc); |
There was a problem hiding this comment.
Can this be made const or are we expecting it to change?
There was a problem hiding this comment.
It will eventually. e: change that is. It will hold the locals vars of the function which all do.
|
Why was this merged without waiting for all reviewers to acknowledge the responses to their questions? |
|
Someone thought two approvals were good enough? |
|
This is apparently the start of a major refactoring. I don't know why it is being done. What is it intended to accomplish? How will the code get better? Until this is all clear and agreed upon, we should not be proceeding with it. For example, I've provided lists before of goals of refactoring. As far as I can see, this addresses none of them. |
|
@ibuclaw This is just the start of the refactorization and it is not divergent with your suggestion. The purpose of this refactorization is to break the semantic3 for FuncDeclarations into smaller-documented functions. Your suggestion can be implemented in a future PR @WalterBright The goal of this refactoring is to make semantic3::visit(FuncDeclaration) more readable as it has >1000 lines of code. I have been working with that code myself and it is really hard to try and isolate the code of interest in that giant chunk. This PR (and subsequent ones) will refactor the logic into separate function that are documented. This will make it easier to read and understand what the code does. |
|
As per https://github.com/dlang/dmd/pull/8609/files#discussion_r213101229 and #8609 (comment), moving from a member function of one type to a member function of another is not improving encapsulation. At least my suggestion of putting all moved code into a free function in a new module should have been followed (unless me and @WalterBright disagree there, of course). |
|
You are right, but the point of this and the next 24ish PRs is not to improve encapsulation but to improve comprehensibility, 1100 lines is too much for me to make functional changes in and I suspect too much for reviewers as well. PRs that follow after that can deal with encapsulation. |
|
However moving the code to another place in the same module does not improve comprehensibility. You're better off hitting two birds with one stone here and just moving them to a new module from the start. |
Oh, but it does. Going from 1100 lines of almost completely undocumented code, to ~300 of documented code at a high level leads to a massive increase in the ability to comprehend what the code is doing. Or you have a different definition of comprehensibility than I do. Splitting out code to a new module can come later. |
I sincerely apologise for the diff size, and would recommend using something other than the regular diff algorithm as it logically consists of a small addition combined with a massive deletion, and a massive addition, not lots of additions and deletions. Does anyone know how to use
--patienceor--histogramwith GitHub?