Don't require TypeInfo in a minimal runtime if it's not needed#7799
Don't require TypeInfo in a minimal runtime if it's not needed#7799dlang-bot merged 1 commit intodlang:masterfrom JinShil:optional_typeinfo
Conversation
|
Thanks for your pull request, @JinShil! 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. |
| { | ||
| torig.error(Loc.initial, "`TypeInfo` cannot be used with -betterC"); | ||
| fatal(); | ||
| } |
There was a problem hiding this comment.
This block of code was modified to make it consistent with the following in statementsem.d
Lines 3626 to 3636 in ec4534e
There was a problem hiding this comment.
Can we have a valid line for the error?
There was a problem hiding this comment.
Does this error apply for both explicit and implicit uses of RTTI?
There was a problem hiding this comment.
Does this error apply for both explicit and implicit uses of RTTI?
It applies to anything that ends up calling genTypeInfo, which, under the current implementation could be implicit or explicit uses of TypeInfo. For example, trying to do a string concatenation will eventually call runtime hooks like _d_arraycatnTX which takes TypeInfo as one of its arguments. See https://issues.dlang.org/show_bug.cgi?id=18312
IMO all of those runtime hooks should be changed to templates, that don't require TypeInfo, so we shouldn't need TypeInfo for string concatenation as long as the runtime hooks are implemented. That's something I hope to champion after this PR (maybe 1 or 2 more) are merged.
TL;DR: Yes implicit and explicit uses of TypeInfo will trigger the error, but by replacing runtime hooks with templates (later) we may be able to eliminate such errors.
There was a problem hiding this comment.
Ok, but I'd still feel better if explicit uses got a file/line location to highlight where you're using RTTI.
There was a problem hiding this comment.
By "explicit uses" are you referring to typeid? That's the only case I can think of where TypeInfo is explicitly used, and even then, it's indirect. Please let me know if you have something else in mind.
There was a problem hiding this comment.
I think showing the location of implicit uses is even more desirable, as you cannot grep for these as with explicit uses of typeid. That would mean to pass the location of an expression via semanticTypeInfo and getTypeInfoType.
That will probably also be helpful when generating type info more lazily as in #6561
There was a problem hiding this comment.
OK, I'll explore this. Marking this as WIP while I try.
| // ModuleInfo and exception handling code | ||
| // This test ensures an empty main with a struct, built with a minimal runtime, | ||
| // does not generate ModuleInfo or exception handling code, and does not | ||
| // require TypeInfo |
There was a problem hiding this comment.
Don't you have to modify verify_symbols to check for TypeInfo?
There was a problem hiding this comment.
Yeah, best to be thorough. Done.
|
Ping @WalterBright, @ZombineDev, @ibuclaw... anyone, really. |
| { | ||
| torig.error(Loc.initial, "`TypeInfo` cannot be used with -betterC"); | ||
| fatal(); | ||
| } |
There was a problem hiding this comment.
Can we have a valid line for the error?
| { | ||
| torig.error(Loc.initial, "`TypeInfo` cannot be used with -betterC"); | ||
| fatal(); | ||
| } |
There was a problem hiding this comment.
Does this error apply for both explicit and implicit uses of RTTI?
|
I add a I also added DDoc header comments to the function signatures I modified, and a couple more tests to increase coverage. There is somewhat of a drawback to this, however. For example, the following code will produce an error message about void test()
{
string s = "abc"
s = "(" ~ s ~ ")"; // main.d(8): Error: `object.TypeInfo` was not found
}That is not actually a problem with this PR, but a general problem with D's ubiquitous use of runtime type information (i.e. |
src/dmd/e2ir.d
Outdated
| // This is a hack so we can call postblits on const/immutable objects. | ||
| elem *eti = getTypeInfo(tb.unSharedOf().mutableOf(), irs); | ||
| AggregateDeclaration ad = cast(AggregateDeclaration)tb; | ||
| elem *eti = getTypeInfo(ad.loc, tb.unSharedOf().mutableOf(), irs); |
There was a problem hiding this comment.
This location is the one of the aggregate declaration, not the using expression. For completeness, setArray should probably receive the expression to forward it here.
There was a problem hiding this comment.
Done. Thanks for the help!
src/dmd/typinf.d
Outdated
| if (!Type.dtypeinfo) | ||
| { | ||
| torig.error(Loc.initial, "TypeInfo not found. object.d may be incorrectly installed or corrupt, compile with -v switch"); | ||
| torig.error(loc, "`object.TypeInfo` was not found"); |
There was a problem hiding this comment.
Maybe add "but implicitly used" to the error message.
|
This produced a regression https://issues.dlang.org/show_bug.cgi?id=18905 |
This is a followup to the following PRs
ModuleInfoThrowableis not declared #7786 forThrowableIt is to
TypeInfowhat the above PRs were forModuleInfoandThrowableWith this PR, it is now possible to have the same functionality as -betterC (without the -betterC compiler switch) by simply adding the following minimal runtime for executables...
... or the following minimal runtime for libraries:
For libraries it would be nice to not require an empty object.d file, but I'm leaving that for another potential PR. UPDATE: See #7825
Again, this will be of interest to users wishing to incrementally or partially port D to new platforms, users hoping to target resource constrained platforms, and users wishing to use D as a library from other languages without druntime.