Skip to content

Added location to user defined attributes#12524

Closed
AsterMiha wants to merge 1 commit intodlang:masterfrom
AsterMiha:uadItemExp
Closed

Added location to user defined attributes#12524
AsterMiha wants to merge 1 commit intodlang:masterfrom
AsterMiha:uadItemExp

Conversation

@AsterMiha
Copy link
Contributor

Created a new node (UadItem) to preserve the location of all user defined attributes

@dlang-bot
Copy link
Contributor

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 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#12524"

src/dmd/parse.d Outdated
Comment on lines 1466 to 1471
udas.push(exp);
udas.push(new AST.UadItem(udastart, exp, parens));
Copy link
Member

Choose a reason for hiding this comment

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

And why can't exp have its loc set to udastart?

Copy link
Contributor Author

@AsterMiha AsterMiha May 16, 2021

Choose a reason for hiding this comment

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

Because udas can be written in any of these ways: @ e, @(e), @(e1, e2)
In the first 2 cases changing the loc of the exp would work but in the last it would be confusing to set all of them to the loc of '@', especially when the expressions are on different lines.

Copy link
Member

Choose a reason for hiding this comment

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

I also think that introducing a new AST type to represent this is overkill, and will not scale well.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

That's a lot of changes to have the position so I wont give my mind on this aspect.
The changes requested are more about

  1. The coverage that is not really good.
  2. The style a bit inconsistent with the use of isUadItem() and most importantly the name of the new node is not good. the offical name for those attribs are UDA, so UDAItem is better.
  3. ASTBase declaration

TupleExp te = cast(TupleExp)e;
eval(sc, te.exps, lastTag);
}
if (e.op == TOK.at)
Copy link

Choose a reason for hiding this comment

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

if (UadItem te = e.isUadItem()){...}

Copy link

Choose a reason for hiding this comment

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

However now I see that the way you write the cast is consistent with the other cast in the block.

@jacob-carlborg
Copy link
Contributor

jacob-carlborg commented May 20, 2021

I will not do an extended review of this, but the tests are a bit lacking. They need to include:

  • UDAs on multiple lines, i.e:
    @(3)
    @(4)
    int a;
  • Both of the other two UDA syntaxes (if those are indented to be supported by this PR), i.e.:
    @(3) {
        int a;
    }
    @(3):
        int a;
  • A combination of all of the above, i.e.:
    @(4):
    @(3) {
        @(6)
        @(5) int a;
    }

@AsterMiha AsterMiha force-pushed the uadItemExp branch 8 times, most recently from ef903b2 to 872e34c Compare May 23, 2021 17:50
@AsterMiha
Copy link
Contributor Author

AsterMiha commented May 23, 2021

@tungstenheart Renamed the node and added the ASTBase declaration. I forgot to remove some of the code from previous attempts and that caused the coverage issues, but I fixed that now. Also added a couple more tests.

@ghost
Copy link

ghost commented May 24, 2021

thanks, (someone can cancel my request for changes)

{
// None of these can be value parameters
if (e.op == TOK.tuple || e.op == TOK.scope_ ||
if (e.op == TOK.tuple || e.op == TOK.at || e.op == TOK.scope_ ||
Copy link
Contributor

Choose a reason for hiding this comment

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

I am confused by this addition. What do UDAs have to do with value parameters? Do you have a code snippet that is directly affected by this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Semantic2 attempts to interpret all expressions in UserAttributeDeclaration [1]. Now that the actual expressions are inside a UDAItem node we need to reach its contents first. An alternative would be to add UDAItem to the Interpretor visitor to unpack the node there.

[1]

dmd/src/dmd/semantic2.d

Lines 573 to 574 in 2453350

if (definitelyValueParameter(e))
e = e.ctfeInterpret();

Copy link
Contributor

@RazvanN7 RazvanN7 left a comment

Choose a reason for hiding this comment

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

Looks good to me. I'll wait for @jacob-carlborg 's review

@jacob-carlborg
Copy link
Contributor

I'll wait for jacob-carlborg 's review

I've already done the review I'll be doing.

@RazvanN7 RazvanN7 added the Merge:72h no objection -> merge The PR will be merged if there are no objections raised. label May 26, 2021
@ghost
Copy link

ghost commented May 27, 2021

SInce this was not discussed (here at least), what is the value added , what are the use cases ?

@RazvanN7
Copy link
Contributor

RazvanN7 commented May 27, 2021

Currently, UDAs do not contain the location, as a result third-party tools using dmd-as-a-lib that want to properly expose the location of UDAs cannot do that. This PR fixes that. More info: #11788 (comment)

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

see comments. Mostly the assert that will avoid to merge possibly dead code.

}
}

extern (C++) class UDAItem : Expression
Copy link
Member

Choose a reason for hiding this comment

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

No new class should be introduced without a proper documentation. Someone should be able to look at this code and know why this class exists and when it should be used / where one can expect to find it in the tree.

src/dmd/parse.d Outdated
Comment on lines 1466 to 1471
udas.push(exp);
udas.push(new AST.UadItem(udastart, exp, parens));
Copy link
Member

Choose a reason for hiding this comment

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

I also think that introducing a new AST type to represent this is overkill, and will not scale well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants