Skip to content

Implement DIP1009 correctly (#303)#304

Merged
dlang-bot merged 8 commits intodlang-community:masterfrom
LaurentTreguier:issue-303
Nov 5, 2018
Merged

Implement DIP1009 correctly (#303)#304
dlang-bot merged 8 commits intodlang-community:masterfrom
LaurentTreguier:issue-303

Conversation

@LaurentTreguier
Copy link
Contributor

This PR adds the following changes from the API perspective:

  • new InContractExpression and OutContractExpression classes to represent expression-based contracts
  • new inContractExpressions and outContractExpressions properties for FunctionBody to store them
  • new assertion and message properties for Invariant in the case of an expression-based invariant

These are obviously breaking changes since they change the way FunctionBody and Invariant store expression-based contracts.

@codecov
Copy link

codecov bot commented Nov 3, 2018

Codecov Report

Merging #304 into master will decrease coverage by 0.11%.
The diff coverage is 86.66%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #304      +/-   ##
=========================================
- Coverage   83.62%   83.5%   -0.12%     
=========================================
  Files           7       7              
  Lines        4817    4784      -33     
=========================================
- Hits         4028    3995      -33     
  Misses        789     789
Impacted Files Coverage Δ
src/dparse/ast.d 14.54% <0%> (-0.32%) ⬇️
src/dparse/parser.d 90.29% <95.12%> (+0.1%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 03a293a...6d828b4. Read the comment docs.

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.

Sorry but the official grammar is much more complex. Reference document is here : https://github.com/dlang/DIPs/blob/master/DIPs/accepted/DIP1009.md#grammar. Your implementation goes in the right direction but more new nodes are required.

@LaurentTreguier
Copy link
Contributor Author

I had based this on the way AssertExpression is handled, and didn't realize that the DIP changed its grammar as well.
I'll have a better look at the grammar and stick to it

@LaurentTreguier
Copy link
Contributor Author

I've tried to follow the changes of DIP1009 more closely.
I used the name AssertArguments instead of ContractArguments since it's the name used in the grammar on dlang.org.

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.

Nice work. Maybe just the in/ouTokenLocation to remove

{
mixin (visitIfNotNull!(assertArguments));
}
/** */ size_t inTokenLocation;
Copy link

Choose a reason for hiding this comment

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

I don't think this is required. IIRC you wanted this for DFMT but with the official grammar FunctionContract gives the information if it's a expression style contract (its InOutStatement is null) or a statement style contract (its InOutContractExpression) is null.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

inTokenLocation and outTokenLocation were already used for detecting classic contract statements; the problem with them was simply that they weren't filled for expression-based contracts, so DFMT didn't consider them as contracts.
But inTokenLocation and outTokenLocation are used to distinguish contracts from other usages of in and out, and not to distinguish expression-based ones from statement ones, so I think it's probably better to leave them there

Copy link

@ghost ghost Nov 4, 2018

Choose a reason for hiding this comment

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

ok then. since my comment i just remembered too that DFMT is based on the tokens and only very partially on the AST.

{
mixin (visitIfNotNull!(parameter, assertArguments));
}
/** */ size_t outTokenLocation;
Copy link

Choose a reason for hiding this comment

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

same as comment related to InContractExpression

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.

Two things i didn't see the first time

}
ownArray(node.functionContracts, contracts);

if (current.type == tok!"do"
Copy link

Choose a reason for hiding this comment

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

prefer currentIs(tok!"do")

ownArray(node.functionContracts, contracts);

if (current.type == tok!"do"
|| (current.type == tok!"identifier" && current.text == "body"))
Copy link

@ghost ghost Nov 4, 2018

Choose a reason for hiding this comment

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

if (moreTokens && ... to prevent any RangeError.

trace("Found register");
mixin (nullCheck!`(node.register = parseRegister())`);
if (current.type == tok!":")
if (currentIs(tok!":"))
Copy link

Choose a reason for hiding this comment

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

Please only address to the locations indicated. This usage is unrealted to DIP1009 and is fixed in #302

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh ok.

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.

Thanks, I see no problem anymore. But will keep it opened for a few days before merging if someone else wants to review.

@ghost ghost added the auto-merge-squash label Nov 5, 2018
@dlang-bot dlang-bot merged commit daa93a5 into dlang-community:master Nov 5, 2018
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.

2 participants