-
-
Notifications
You must be signed in to change notification settings - Fork 667
[Semantic3 Refactor] setupScope #8668
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
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#8668" |
7988332 to
9fe0432
Compare
| // Scope of analysis | ||
| Scope* sc; | ||
| // Scope created to avoid name collisions | ||
| Scope* sc2; |
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.
Is this required for later usage?
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, the Idea it to fold most of the visit into the struct so that all the used local variables become members of the struct. i.e. this will be a common theme.
I don't see where this is going. This looks like the brink of a major refactoring - but I don't know its intention. I don't want to waste your time with this unless we can agree on what is happening. |
|
It is, the Idea it to fold most of the rather than ~1100 lines in a single function with little to no comments. This is required for me to even being contemplating trying to fix issue 14246 in a way that breaks as little as possible. I can't understand an 1100 line function, and I wouldn't expect anyone else to either. |
|
|
||
| /* Create scope to avoid name collisions | ||
| */ | ||
| private Scope* setupScope() |
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 suggest the name createScope as that is what it actually does.
|
Since 2 members approved this, and no opposition have been voiced for a week, I took the liberty to add the |
|
I object to it. In particular, I object to the establishment of |
|
As stated earlier this is not aggregation of random functions, this is to make // Scopes:
// Scope of analysis
Scope* sc;
// Scope created to avoid name collisions
Scope* sc2;
// Scope for out contract return variable
Scope* scout;
// The FuncDeclaration subject to Semantic analysis
FuncDeclaration funcdecl;
TypeFunction f; //funcdecl.type
// Does funcdecl need a closure?
bool needEnsure;
// The variable arguemnt ... parameter.
VarDeclaration _arguments;
// Precondition and postcondition invariants
Statement fpreinv, fpostinv;
// In / Out contract statements
Statement freq, fens;
// funcdecl.isThis, funcdecl.isMember2
AggregateDeclaration ad, ad2;All or which are used all over the place. Sure, the declarations of the above could be littered throughout the function, but they are better served, documented, in one place, away from all the other variables declared that aren't used further than the construction of one that is (which is what this struct is for). These PRs are blocking a fix for issue 14246, which is a critical bug for Weka (it's even pre approved!), somewhat ironically I think this quote is an apt description of my feelings at the moment. |
|
They are better served and documented as parameters to the function(s). That way, it is clear what the interface to the function is. |
|
#6816 is the solution to https://issues.dlang.org/show_bug.cgi?id=14246, and does not require any refactoring. The trouble with 6816 is dealing with the breakage of existing code that is incorrectly written (such as running unsafe destructors in @safe constructors). I plan on dealing with this using a compiler transition switch. |
Maybe because you know the compiler like the back of your hand and can comprehend an 1100 line function. I don't/can't, hence the refactor. I also note the the above PR resulted in large code breakage, and therefore a proper fix requires more finesse.
IIUC, the main problem was running destructors on objects that were not constructed (yes destructors should able to handle a non-constructed object, but such is reality. It will stay like that until (if at all) the compiler inserts units to do so). The correct solution, modulo problems with safe, is to do the really expensive/extensive checking of initialisation of fields that have destructors, noting that constructors that are nothrow (or are inferred nothrow) do not require the checks since they cannot throw so that perf does not degrade (this also solves the This will ensure that |
|
@thewilsonator It seems that @WalterBright is against the struct that holds all the variables. I was against it too for the same reason, but I was willing to make a compromise for the sake of comprehensibility, however doing so is inconsistent with the whole dmd codebase. I think that the way to go forward with this is to lose the struct and create documented free functions and from there see how we can reduce the number of parameters (most of the variable declarations in semantic3 for FuncDeclaration are coming from the Scope visitor member or from funcdecl, so you could just pass the same references). |
You mean that the whole DMD code base is incomprehensible? 😃. |
|
@thewilsonator Need you to decide if you intend to pursue this further. I'm assuming you do since the PR is still open. If that is the case, please address @WalterBright's concerns so we can move forward. |
|
Ping @thewilsonator |
|
Closing as per @WalterBright 's decision |
Part 2 of approx. 23
follows on from #8609