Pattern matching is-expressions

Paul Backus snarwin at
Wed Aug 19 17:06:23 UTC 2020

On Wednesday, 19 August 2020 at 15:18:03 UTC, Stefan Koch wrote:
> Type functions work by doing partial evaluation,
> In the first, static pass they can use the regular semantic 
> transform and checking pass that the rest of dmd uses.
> However everything which touches the type variables, cannot be 
> semantically analyzed or transformed because the types aren't 
> known yet.
> Furthermore if during the interpretation the types are in a 
> known state, you cannot change/enrich the type information 
> within the AST based on that.
> Since that would change the AST which would either violate the 
> rule that ctfe has to be pure, and cause all sorts of issues, 
> or you would have duplicate the whole subtree (this is what 
> templates, do.).
> Both of these things are not an option for me.

I see. I had assumed that type functions would work by 
duplicating the subtree, using the copy as a temporary "stack 
frame" in which local mutation was permitted, and then throwing 
it away at the end of interpretation.

This is still more efficient than using recursive templates, 
since it reduces the number of syntax-tree copies from O(n) to 
O(1), but I guess that's not enough of a performance win for what 
you're trying to accomplish.

More information about the Digitalmars-d mailing list