Bug 23638 – [betterC] Better Error Message For Runtime Usage

Status
NEW
Severity
enhancement
Priority
P4
Component
dmd
Product
D
Version
D2
Platform
All
OS
All
Creation time
2023-01-16T21:18:09Z
Last change time
2024-12-13T19:26:44Z
Keywords
betterC, diagnostic
Assigned to
No Owner
Creator
Jack Stouffer
Moved to GitHub: dmd#20214 →

Comments

Comment #0 by jack — 2023-01-16T21:18:09Z
Consider extern (C) int main () { auto s = "a".idup; return 0; } This gives the following src/druntime/import/object.d(3822): Error: `TypeInfo` cannot be used with -betterC This is a trivial example, but when the library is 30 kloc it's a bit harder to track down the offending code from this message. Especially since it doesn't even tell you which runtime function is the problem. I think the easiest thing to do would be to just add a stack trace like the ones in the error messages for bad template instantiations. Something like src/druntime/import/object.d(3822): Error: `TypeInfo` cannot be used with -betterC Instantiated from here: main.d(3) It would be nice to have but not necessary to say the name of the runtime function that's attempted to be used. src/druntime/import/object.d(3822): Error: `TypeInfo` cannot be used with -betterC In function dup defined on object.d(3820) Instantiated from here: main.d(3)
Comment #1 by razvan.nitu1305 — 2023-01-18T13:54:10Z
Unfortunately, the problem comes from the fact that the hook uses typeid internally. `dup` is just a normal template so the compiler does not give it any special treatment. The source of this is that dup uses internally typeid to pass a Typeinfo to the newarray hook (which currently is not templatized). Once newarray is templatized and Typeinfo is not needed anymore, the problem will disappear. So, I guess, the real solution in this case is to templatize the _d_new_array hook.
Comment #2 by jack — 2023-01-18T17:23:48Z
(In reply to RazvanN from comment #1) > Unfortunately, the problem comes from the fact that the hook uses typeid > internally. `dup` is just a normal template so the compiler does not give it > any special treatment. The source of this is that dup uses internally typeid > to pass a Typeinfo to the newarray hook (which currently is not > templatized). Once newarray is templatized and Typeinfo is not needed > anymore, the problem will disappear. > > So, I guess, the real solution in this case is to templatize the > _d_new_array hook. Sounds like the actual root cause is that use of typeid in betterC mode doesn't result in a trace. People have been trying to template-ize druntime for like seven years so fixing the typeid problem is more likely to bear fruit.
Comment #3 by razvan.nitu1305 — 2023-01-20T10:25:35Z
(In reply to Jack Stouffer from comment #2) > (In reply to RazvanN from comment #1) > > Unfortunately, the problem comes from the fact that the hook uses typeid > > internally. `dup` is just a normal template so the compiler does not give it > > any special treatment. The source of this is that dup uses internally typeid > > to pass a Typeinfo to the newarray hook (which currently is not > > templatized). Once newarray is templatized and Typeinfo is not needed > > anymore, the problem will disappear. > > > > So, I guess, the real solution in this case is to templatize the > > _d_new_array hook. > > Sounds like the actual root cause is that use of typeid in betterC mode > doesn't result in a trace. People have been trying to template-ize druntime > for like seven years so fixing the typeid problem is more likely to bear > fruit. Actually, a lot of progress has been recently and a lot of hooks have already been templated: https://www.youtube.com/watch?v=dsa8GWL6TUo&ab_channel=TheDLanguageFoundation . I have highs hopes that 2023 will be the year when we finally achieve this.
Comment #4 by razvan.nitu1305 — 2023-01-20T10:50:14Z
(In reply to Jack Stouffer from comment #2) > (In reply to RazvanN from comment #1) > > Unfortunately, the problem comes from the fact that the hook uses typeid > > internally. `dup` is just a normal template so the compiler does not give it > > any special treatment. The source of this is that dup uses internally typeid > > to pass a Typeinfo to the newarray hook (which currently is not > > templatized). Once newarray is templatized and Typeinfo is not needed > > anymore, the problem will disappear. > > > > So, I guess, the real solution in this case is to templatize the > > _d_new_array hook. > > Sounds like the actual root cause is that use of typeid in betterC mode > doesn't result in a trace. People have been trying to template-ize druntime > for like seven years so fixing the typeid problem is more likely to bear > fruit. Also, the typeid problem is just at the surface, the underlying issue is that a function that receives a Typeinfo object is called (and typeid is used to get the underling Typeinfo). We can get around this only by templating that function (which is a compiler hook).
Comment #5 by robert.schadek — 2024-12-13T19:26:44Z
THIS ISSUE HAS BEEN MOVED TO GITHUB https://github.com/dlang/dmd/issues/20214 DO NOT COMMENT HERE ANYMORE, NOBODY WILL SEE IT, THIS ISSUE HAS BEEN MOVED TO GITHUB