HUGE fix for Type Functions, which also fixes an issue reported in the devforums and should make solving faster #1418
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.
@alexmccord :) I did it!
I fixed the
tabletype
thing even though when I found this fix that I am submitting here I wasn't pursuing to fix that, but I had the feeling that this would resolve a bunch of stuff.Infact this fixes and should also this Devforum Post (if you check the message it replies to) which I added the Unit Test for this fix as well.
It doesn't break any Unit Tests.
So why is this change HUGE?
This comment says:
But did you actually know that it pushes the new constraints AT THE END?
It causes the following issue:
Explanation with Pseudocode example
And yes, you can move
keyof
at the bottom to prevent that from happening.But this doesn't make sense.
Type Functions can produce a ReduceConstraint
But the Solver pushes them at the end, and if your type function is closer to the end, it will solve it immediately. This doesn't make sense.
Considering that this however is true, it is a fact. And this fact makes it very reasonable for this fix to be correct and the actual intended way on how Type Functions should be resolved.
What did I change?
I changed a concept.
I can change the implementation on request. I can also FFlag it.
But the point is that I am pushing the new created constraints right after the Type Function Constraint. This also prevents things from getting blocked, hence why solving should be faster.
Here are changes that you can use in https://luau-lang.github.io/dcr-timetraveler/:
WITHOUT THE FIX: https://paste.ivr.fi/raw/oqukuqobyt
WITH THE FIX: https://paste.ivr.fi/raw/itopunanyz
Differences
Before
After
@alexmccord Initially the thought was that
keyof
doesn't wait fortypetable
and figuring out the fix for it would be very a bit difficult for me.But by making myself more debug logging I learned A LOT about the ConstraintSolver. Learning that it creates Constraints at the wrong position.
We can think of Type Functions not being standalone Constraints. They're like more than one, however because of the current issue it's being delayed which is bad and causes issues, a lot of issues.
If one plans to implement User Defined Type Functions, I am pretty sure that this fix can help reduce headaches and other problems.
The Solver works Up to Down and with this fix, it supports that more.
My change makes these Constraints happen at the time they were actually meant to happen.