Comments/C++headers/Changelog entry for lambda comparison#7809
Comments/C++headers/Changelog entry for lambda comparison#7809wilzbach merged 1 commit intodlang:masterfrom
Conversation
|
Thanks for your pull request, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Some tips to help speed things up:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. 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. |
src/dmd/lambdacomp.d
Outdated
| { | ||
| v.getConstInitializer.accept(this); | ||
| } | ||
| // Otherwise, the function is uncomparable |
There was a problem hiding this comment.
This flow is a little confusing.
please let the buf.reset be a fall-through case.
There was a problem hiding this comment.
it is a fall-through case, I just need it to be reset inside the first if-block if the var declaration isn't a manifest constant. I don't know now to do it differently without adding a label, which in my opinion would be worse.
There was a problem hiding this comment.
Easy, use return. Then you only need to call buf.reset at the end.
There was a problem hiding this comment.
it could also be {auto v = s.isVarDeclaration if (v && (v.storage_class & STC.manifest))}
In general if (a) {if (b) {c}} maps exactly to if (a && b) {c}
src/dmd/lambdacomp.d
Outdated
| else | ||
| buf.reset(); | ||
| } | ||
| // Or it may be an enum |
changelog/lambdacomp.dd
Outdated
|
|
||
| -> the lambda function arguments must not have a template instantiation as an explicit argument type. Any other argument types (basic, user-defined, template) are supported. | ||
|
|
||
| -> the lambda function body must contain a single expression (no return statement) which contains only numeric values, manifest constants, enum values and arguments. If the expression contains local variables, function calls or return statements, the function is considered uncomparable. |
There was a problem hiding this comment.
more rational wanted.
why are the limitations the way they are ?
There was a problem hiding this comment.
That's the point I got to. Later on, the limitations will be lifted (where possible).
stefan-koch-sociomantic
left a comment
There was a problem hiding this comment.
it's better but could be improved.
meta concern,
why would you serialize to a string and then compare that ?
it's expensive.
To do parameter renaming and hopefully, later on, do some other computation (e.g. to be able to distinguish between |
src/dmd/lambdacomp.d
Outdated
| * found when visiting the AST nodes to higher levels of the | ||
| * AST. | ||
| */ | ||
| enum ExpType |
There was a problem hiding this comment.
Seems like this can be private.
| * The serialization of this. | ||
| * != null only if tok == TOKreserved. | ||
| */ | ||
| const(char)* serialization; |
There was a problem hiding this comment.
Could have a better description of what it's used for.
changelog/lambdacomp.dd
Outdated
| If the expression contains local variables, function calls or return statements, | ||
| the function is considered uncomparable. | ||
|
|
||
| These limitation will be lifted in the next release version. |
There was a problem hiding this comment.
These limitation will be lifted in the next release version.
I would recommend avoiding being this specific. There are not guarantees that those changes will make it into the next release. I would say something like: "These limitations might be lifted in the future".
|
changelog/lambdacomp.dd
Outdated
| correctly compare two lambdas, the following conditions must be | ||
| satisfied: | ||
|
|
||
| -> the lambda function arguments must not have a template instantiation |
There was a problem hiding this comment.
Until we have MarkDown support, the following is recommended:
$(UL
$(LI ..)
)
src/dmd/func.d
Outdated
|
|
||
| /** | ||
| * The serialization of this. | ||
| * != null only if tok == TOKreserved. |
| /*** | ||
| * Compiler implementation of the | ||
| * $(LINK2 http://www.dlang.org, D programming language). | ||
| * |
There was a problem hiding this comment.
Describe the module here.
| @@ -1,3 +1,15 @@ | |||
| /*** | |||
| * Compiler implementation of the | |||
| * $(LINK2 http://www.dlang.org, D programming language). | |||
There was a problem hiding this comment.
I know that this is the default header, but I don't like it very much. It's not helping anyone. The module description should be used to ... guess what ... describe the module.
src/dmd/lambdacomp.d
Outdated
| } | ||
|
|
||
| /** | ||
| * The serialize visitor visits a FuncLiteralDeclaration |
There was a problem hiding this comment.
$(REF dmd, func, FuncLiteralDeclaration) - in general there's also $(REF_ALTEXT myText, FuncLiteralDeclaration, dmd, func) if you prefer a custom text.
| } | ||
|
|
||
| /** | ||
| * Entrypoint of the SerializeVisitor. |
src/dmd/lambdacomp.d
Outdated
| override void visit(FuncLiteralDeclaration fld) | ||
| { | ||
| if (fld.type.ty == Terror) | ||
| return; |
| value.writestring("arg"); | ||
| value.print(i); | ||
| arg_hash.insert(key, strlen(key), value.extractString); | ||
| arg_hash.insert(&key[0], key.length, value.extractString); |
src/dmd/lambdacomp.d
Outdated
| } | ||
| // Otherwise, the function is uncomparable | ||
| else | ||
| buf.reset(); |
There was a problem hiding this comment.
FWIW DStyle would require the else to use brackets here too.
src/dmd/lambdacomp.d
Outdated
| { | ||
| v.getConstInitializer.accept(this); | ||
| } | ||
| // Otherwise, the function is uncomparable |
There was a problem hiding this comment.
Easy, use return. Then you only need to call buf.reset at the end.
src/dmd/lambdacomp.d
Outdated
| import dmd.visitor; | ||
|
|
||
| /** | ||
| * This enum is used to report the type of the expression |
There was a problem hiding this comment.
This enum is used to report can be excised with no change in meaning to the sentence.
src/dmd/lambdacomp.d
Outdated
| /** | ||
| * This enum is used to report the type of the expression | ||
| * found when visiting the AST nodes to higher levels of the | ||
| * AST. |
There was a problem hiding this comment.
I don't know what visiting the AST nodes to the higher levels of the AST means.
src/dmd/lambdacomp.d
Outdated
|
|
||
| /** | ||
| * The serialize visitor visits a FuncLiteralDeclaration | ||
| * AST node, serializing the implementation of the lambda |
There was a problem hiding this comment.
What does serialization of the implementation mean? Is a string produced? A hash?
9e5c10c to
9811ad2
Compare
9811ad2 to
0c2ad9c
Compare
I don't see any reason why it should. It's more or less a "private function of the DMD frontend implemented as a visitor" for the other backends. They only care about the IR.
I'm going to merge this now, s.t. it appears on the 2.079 changelog. |
Part 2 of #7484
cc @ibuclaw @wilzbach @UplinkCoder