Moved getAttributes from attrib.d to expressionsem.d#11788
Moved getAttributes from attrib.d to expressionsem.d#11788AsterMiha wants to merge 2 commits intodlang:masterfrom
Conversation
|
Thanks for your pull request and interest in making D better, @AsterMiha! 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 run digger -- build "master + dmd#11788" |
|
This still needs to be accessible from C++ for LDC (and I presume also GDC). |
a65891a to
d8e92a8
Compare
| return true; | ||
| } | ||
|
|
||
| extern (C++) Expressions* getAttributes(UserAttributeDeclaration uad) |
There was a problem hiding this comment.
it also needs to be in the headers somewhere too.
d8e92a8 to
509f61a
Compare
509f61a to
213a609
Compare
src/dmd/attrib.h
Outdated
There was a problem hiding this comment.
It seems that the style is to have the * (star) right before the name of the function.
There was a problem hiding this comment.
Yes, and the param is a pointer too.
There was a problem hiding this comment.
Please add a test to cxx-unittest so that it is covered.
There was a problem hiding this comment.
@ibuclaw do you mean src/tests/cxxfrontend.c or should I add it to test/unit?
There was a problem hiding this comment.
@ibuclaw do you mean src/tests/cxxfrontend.c or should I add it to test/unit?
cxxfrontend.c - just need to call the function from c++ to verify that mangling matches.
| Dsymbol* syntaxCopy(Dsymbol* s); | ||
| Scope* newScope(Scope* sc); | ||
| void setScope(Scope* sc); | ||
| Array<Expression*>* getAttributes(); |
There was a problem hiding this comment.
You probably need to add it too here.
src/dmd/objc.d
Outdated
There was a problem hiding this comment.
Because of UFCS[1] you leave this line unmodified.
[1] https://tour.dlang.org/tour/en/gems/uniform-function-call-syntax-ufcs
src/dmd/traits.d
Outdated
There was a problem hiding this comment.
Again, this line can be left unmodified.
|
Before diving into all these little details, how about questioning the point of this little refactoring? Moving |
|
Splitting semantic analysis from the ast nodes will ultimately lead to getting rid of the duplications in ASTBase. The fact that |
|
So the end goal is to move every little function invoking sema to dedicated sema files? A quick grep shows still loads of occurrences in something like 40 files... |
|
Out of the AST nodes, yes. |
213a609 to
68980f4
Compare
|
How will that make DMD usable as a library ? |
|
@Geod24 The initial phase is a clean-up one so that Mihaela can accommodate with the codebase and then we will tackle the interface. I think that having the separation helps making the code base cleaner anyway. |
"Clean code" can be a very subjective criteria. I see the the milestones come from dlang/project-ideas#68 . I highly suggest you rethink it around use cases. One metric should be: "If we stop the project at step X, how usable will the result be?". We already have good experience with There's plenty of use cases available out there. One such is VisualD. There are a few points which are very clearly needed in all projects, require a lot of work, and will bring net benefits, such as adding start and end locations, or making the AST non-destructive. The former is an easy problem, the latter is a hard one, but progress in any of those means progress that won't be lost if the project is not completed and someone else has to pick it up next year. |
Having designed many libraries myself, I can say "almost always" is actually "certainly". |
|
@Geod24 Thanks for the insightful comment. I think that starting with adding start and end locations for AST nodes could be a good start. |
|
@RazvanN7 Here's a list of problems I've encountered when trying to use DMD as a library (these are actual problems I ran into trying to use the library to write a useful tool) :
I think it would be even simpler to start with the tokens. Here's a list of related tasks (in order of difficulty, with the easiest one first) that will improve the possibility for source code refactorings (this is needed for some LSP features and other tools). I think this list is a good start, because most work will confined to the lexer and parser:
I think the rest of the above mentioned problems are more difficult to tackle. When it comes to testing of these tasks, I think best way is to write unit test style tests, like those available here [1]. There's no point in running the full compiler, including semantic analysis and code generation to only test the lexer or parser. There are already directories for the lexer and parser. [1] https://github.com/dlang/dmd/tree/master/test/unit |
|
@Geod24 Regarding dlang/project-ideas#68. I think the last two tasks:
Are useful and have use cases. I have a use case for the first one in the above list. But I don't think they are realistic to achieve in the available time. I don't know if the other tasks are prerequisite for the above two tasks. |
This question still makes me wince. If gdc and ldc haven't been using dmd as a library for all these years now, how are we using it? |
|
@jacob-carlborg Thank you for the detailed suggestions! I will start following this plan from now on.
But first: could you please clarify if this position refers to the character count in the file or to how many tokens have been found? I would assume it's the second case since the first one sounds more like the start position. |
@AsterMiha In DMD there's a type called This is required to be able to extract the exact code range from the source file a given AST node or token occupies. This is needed to be able to do the source code refactoring. Here's an example of a source file: foo "bar"The above source file consists of two tokens. First an identifier, then a string literal. The byte offset of the second token, the string literal, will be 4 (first byte starts at offset 0).
Yes, it is the start position. DMD already has the start position, but in other units (line number and column number). We need it in number of bytes. I added an explicit item for end locations in my previous post: #11788 (comment). |
I suspect you'll get push back about adding this to Loc since it's used so frequently that increasing its size could have noticeable memory impact. I'm not saying don't do it, but be aware. |
That's a valid concern which can be resolved by hiding the end location behind an appropriate |
|
I will close this since the focus has changed to a different strategy. |
Taking semantic elements out of attrib.d