dmd icon indicating copy to clipboard operation
dmd copied to clipboard

constant fold typeid(T).tsize()

Open WalterBright opened this issue 5 years ago • 11 comments

The idea here is that since the compiler knows what .tsize() is, it can be constant folded. Works with both runtime and compile time computations. If this is successful, will generalize it to more typeid members.

WalterBright avatar Sep 25 '20 09:09 WalterBright

Thanks for your pull request, @WalterBright!

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

Testing this PR locally

If you don't have a local development environment setup, you can use Digger to test this PR:

dub run digger -- build "master + dmd#11792"

dlang-bot avatar Sep 25 '20 09:09 dlang-bot

@WalterBright how many lines is that? For just the size property?

UplinkCoder avatar Sep 25 '20 09:09 UplinkCoder

messy stuff like that is exactly what I want to avoid. How about getting the UDA's on a type. do you also want that in typeid? vtbls? field-offsets?

UplinkCoder avatar Sep 25 '20 09:09 UplinkCoder

For just the size property?

For the moment. I intend to expand it if successful to as many TypeInfo members as I can. This enables CTFE on typeid expressions. I should have thought of doing this optimization 10 years ago.

WalterBright avatar Sep 25 '20 09:09 WalterBright

That is not generalized system though. type functions are.

UplinkCoder avatar Sep 25 '20 09:09 UplinkCoder

@andralex What about looking at the big picture?

UplinkCoder avatar Oct 01 '20 03:10 UplinkCoder

Could tsize be adapted in such a way that allows constant folding, rather than the compiler shortcuting the call?

Genuine concern and possible use-case as there are a number of people/companies using D to target embedded systems.

If I implement the following in a "minimal" run-time library, either to discourage use or as a stub until it's implemented proper.

class TypeInfo
{
    @property final size_t tsize() nothrow pure const @safe @nogc { assert(false, "Unimplemented"); }
}

With this change, there's now a split brain between compiler and library.

ibuclaw avatar Oct 01 '20 08:10 ibuclaw

@WalterBright when you remove the risky label please state why the PR is not risky anymore. The reason I added the risky label was because of Iains comment.

Genuine concern and possible use-case as there are a number of people/companies using D to target embedded systems.

If I implement the following in a "minimal" run-time library, either to discourage use or as a stub until it's implemented proper.

class TypeInfo
{
    @property final size_t tsize() nothrow pure const @safe @nogc { assert(false, "Unimplemented"); }
}

With this change, there's now a split brain between compiler and library.

Has this issue been addressed?

UplinkCoder avatar Oct 23 '20 10:10 UplinkCoder

@WalterBright what is your response to @ibuclaw's comments?

RazvanN7 avatar Jan 08 '21 10:01 RazvanN7

@WalterBright What is the state of this PR and what is your response to @ibuclaw 's concerns?

RazvanN7 avatar May 31 '21 09:05 RazvanN7

@WalterBright This is still failing the testsuite and also Iain's comment remains unaddressed.

RazvanN7 avatar Jul 18 '22 08:07 RazvanN7