Thread overview | |||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
April 27, 2014 [Issue 3827] Warn against and then deprecate implicit concatenation of adjacent string literals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=3827 --- Comment #32 from bearophile_hugs@eml.cc --- A new bug of mine caused by the implicit concatenation of strings. The point of this little program is to show the Phobos isNumeric function: void main() { import std.stdio, std.string, std.array; foreach (const s; ["12", " 12\t", "hello12", "-12", "02" "0-12", "+12", "1.5", "1,000", "1_000", "0x10", "0b10101111_11110000_11110000_00110011", "-0b10101", "0x10.5"]) writefln(`isNumeric("%s"): %s`, s, s.strip().isNumeric(true)); } As you see the last example "02" of the first row of the array literal lacks a comma. I have found this bug with the DScanner tool. -- |
April 30, 2014 [Issue 3827] Warn against and then deprecate implicit concatenation of adjacent string literals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=3827 --- Comment #33 from bearophile_hugs@eml.cc --- A problem with @nogc: void main() @nogc { string s1 = "AB" "CD"; // OK string s2 = "AB" ~ "CD"; // Error } temp.d(3,17): Error: cannot use operator ~ in @nogc function main Some workarounds: void main() @nogc { static immutable string s3 = "AB" ~ "CD"; // OK string s4 = ctEval!("AB" ~ "CD"); // OK } Where ctEval is used to generate a compile-time value. -- |
April 30, 2014 [Issue 3827] Warn against and then deprecate implicit concatenation of adjacent string literals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=3827 --- Comment #34 from Stewart Gordon <smjg@iname.com> --- (In reply to bearophile_hugs from comment #33) > A problem with @nogc: > > > void main() @nogc { > string s1 = "AB" "CD"; // OK > string s2 = "AB" ~ "CD"; // Error > } > > > temp.d(3,17): Error: cannot use operator ~ in @nogc function main That's a separate bug - please file it if it isn't already there. -- |
April 30, 2014 [Issue 3827] Warn against and then deprecate implicit concatenation of adjacent string literals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=3827 --- Comment #35 from bearophile_hugs@eml.cc --- (In reply to Stewart Gordon from comment #34) > > void main() @nogc { > > string s1 = "AB" "CD"; // OK > > string s2 = "AB" ~ "CD"; // Error > > } > > > > > > temp.d(3,17): Error: cannot use operator ~ in @nogc function main > > That's a separate bug - please file it if it isn't already there. I don't understand what you suggest me to file. A line of code "string s2 = "AB" ~ "CD";" performs a run-time array concatenation, that always performs a memory allocation, so it can't be @nogc. -- |
April 30, 2014 [Issue 3827] Warn against and then deprecate implicit concatenation of adjacent string literals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=3827 --- Comment #36 from yebblies <yebblies@gmail.com> --- (In reply to bearophile_hugs from comment #35) > > I don't understand what you suggest me to file. If the @nogc enforcement was done after constant folding, then that expression wouldn't use the gc. Same with things like `[1, 2, 3][0]`. > A line of code "string s2 = > "AB" ~ "CD";" performs a run-time array concatenation, that always performs > a memory allocation, so it can't be @nogc. Try it, look at the asm. No memory allocation. -- |
April 30, 2014 [Issue 3827] Warn against and then deprecate implicit concatenation of adjacent string literals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=3827 --- Comment #37 from bearophile_hugs@eml.cc --- (In reply to yebblies from comment #36) > Try it, look at the asm. No memory allocation. The asm is not enough. @nogc is a purely front-end thing, to avoid different optimizations in different compilers to lead to @nogc-annotated code to compile or not compile in different compilers. So this problem is not a bug, it's an enhancement request, to add this optimization in the front-end. -- |
April 30, 2014 [Issue 3827] Warn against and then deprecate implicit concatenation of adjacent string literals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=3827 --- Comment #38 from bearophile_hugs@eml.cc --- (In reply to bearophile_hugs from comment #33) > Where ctEval is used to generate a compile-time value. A simple implementation: alias ctEval(alias expr) = expr; -- |
April 30, 2014 [Issue 3827] Warn against and then deprecate implicit concatenation of adjacent string literals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=3827 --- Comment #39 from yebblies <yebblies@gmail.com> --- (In reply to bearophile_hugs from comment #37) > (In reply to yebblies from comment #36) > > > Try it, look at the asm. No memory allocation. > > The asm is not enough. @nogc is a purely front-end thing, to avoid different optimizations in different compilers to lead to @nogc-annotated code to compile or not compile in different compilers. So this problem is not a bug, it's an enhancement request, to add this optimization in the front-end. As nice as that all sounds, the reality is that the dmd frontend currently defines which optimizations are guaranteed by the frontend. There are many places where const-folding already affects semantics (especially implicit conversions). Tying improving the usability of @nogc to a mythical optimization spec will likely only achieve preventing improvement to the usability of @nogc. > to add this optimization in the front-end. That is exactly where const-folding is done. -- |
April 30, 2014 [Issue 3827] Warn against and then deprecate implicit concatenation of adjacent string literals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=3827 --- Comment #40 from bearophile_hugs@eml.cc --- (In reply to yebblies from comment #39) > That is exactly where const-folding is done. You know the compiler much better than me, while I don't understand this situation enough. So I leave to you or Stewart to open the bug/ER. See also Issue 12642 for a probably related problem. -- |
June 04, 2015 [Issue 3827] Warn against and then deprecate implicit concatenation of adjacent string literals | ||||
---|---|---|---|---|
| ||||
https://issues.dlang.org/show_bug.cgi?id=3827 naptime <naptimeentertainment@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |naptimeentertainment@gmail. | |com -- |
Copyright © 1999-2021 by the D Language Foundation