StringRepeat
: Add support for generating longer strings & fix instantiations with unions
#1046
+34
−12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Similar to #1042,
StringRepeat
currently can generate strings only upto length 90.Why 90?
Looks like the compiler applies minor optimisations if we extract the recursive call using
infer
and then use the extracted type instead of the recursive call directly.Let's consider an example: the following non-tail recursive implementation of
GetChars
fails at 50 characters.Playground
However, if we extract
GetChars<Rest>
into a separate type and then use the extracted type, the implementation starts working for upto 147 characters.Playground
A similar thing happens in our existing implementation of
StringRepeat
. However, the test case I've added doesn’t consider this minor improvement, so it tests for 50 characters and not 91 characters.This PR refactors
StringRepeat
to leverage tail recursion, allowing it to generate strings upto 1000 characters.Other notes:
The existing implementation also doesn't work with unions, this PR fixes that as well.
Removed the use of
Subtract
because it was severely impacting the performance when used in a tail-recursive implementation.demo-compressed.mov