Skip to content

Conversation

@PhoenixWhitefire
Copy link

@PhoenixWhitefire PhoenixWhitefire commented Nov 6, 2025

Implements:

  • The modifications to the math library type definition
  • The new members of the math table
  • The new fastcalls
  • Additional tests
  • Constant folding
  • 3 new flags: LuauMathIsNanInfFinite, LuauCompileMathIsNanInfFinite, LuauTypeCheckerMathIsNanInfFinite

, as per RFC https://rfcs.luau.org/math-isnan-isfinite-isinf.html

This PR does not implement NCG

Implements:
- The modifications to the `math` library type definition
- The new members of the `math` table
- The new fastcalls
- Conformance tests
Copy link
Collaborator

@vegorov-rbx vegorov-rbx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builtin info is missing.
Compiler type info is missing as well.

@vegorov-rbx
Copy link
Collaborator

Why is constant-folding skipped?

@PhoenixWhitefire
Copy link
Author

I didn't implement constant folding because I didn't think it would actually do anything in any real codebase, but I'm implementing it now (as well as fixing all these errors caused by me not running the conformance tests correctly yet again :,) )

@vegorov-rbx
Copy link
Collaborator

We get requests for constant-folding more items even if it's hard to come up with realistic scenario (In this case, I can imagine some configuration constant having a special path for infinity(?)).
In any case, it should be relatively simple, so we aim to cover the whole 'math' at least.

@PhoenixWhitefire
Copy link
Author

I think there are some missing compiler options that are causing mine to not emit the necessary warnings 😓 I checked the other fastcalls, hopefully I haven't missed any switches this time

@PhoenixWhitefire
Copy link
Author

PhoenixWhitefire commented Nov 6, 2025

Everything seems to be in order now, thank you vegorov!

@vegorov-rbx
Copy link
Collaborator

Looking nice.

Will be good to cover a bit more code.
You can extend the TEST_CASE("BuiltinFolding") test with 3 new folds.

Adds constant folding tests

Fixes `Types.cpp` `TypeMapVisitor` resolved type being wrong for the new functions
@PhoenixWhitefire
Copy link
Author

PhoenixWhitefire commented Nov 6, 2025

I have added folding tests!

hgoldstein and others added 2 commits November 9, 2025 09:55
Hello all! Another week, another release!

* Fixed `table.clone` in the old solver to ensure intersections of
tables were being entirely cloned: prior only the _first_ table in the
intersection would be copied:
```luau
type FIRST = { some: string }
type SECOND = FIRST & { thing: string }
local b: SECOND
-- c's type used to be FIRST, but should be the full type of SECOND
local c = table.clone(b)
```
* Fixed `table.clone` in the old solver to be more permissive and treat
a variadic return as having _at least_ one element. This works around
some unfortunate behavior in the old solver version of nonstrict mode,
see:
```luau
-- A.luau
--!nonstrict
return function()
    return {}
end
-- B.luau
local A = require("A")
-- This line would previously error as `A` has type `() -> (...any)`, so
-- we might not be providing enough parameters to `table.clone`.
local _ = table.clone(A())
```
* Fixed a bug in the new solver where error suppression was not kicking
in for indexing, as in:
```luau
local function f(value: any)
    if value ~= nil then
        for k = 1, #value do
            -- Previously this would error, claiming you cannot index into a `*error-type* | ~nil`
            local _ = value[k]
        end
    end
end
```
* Fix the `getmetatable` type function in the new solver to accept
`*error-type*` and `table` as valid type inputs.
* Changed how error reporting for invalid `for ... in` loops works: for
now this may result in slightly worse error messages (see the example
below), but should mean error suppression is more consistent going
forward:
```luau
function my_iter(state: string, index: number)
    return state, index
end
local my_state = {}
local first_index = "first"
-- Prior we would claim `my_state` and `first_index` are of the incorrect types,
-- now we claim that `my_iter` is of the incorrect type, which can be considered
-- true, but is less helpful.
for a, b in my_iter, my_state, first_index do
end
```

* Introduced `lua_rawgetptagged` and `lua_rawsetptagged`, as well as Lua
5.2+ compatibility macros `lua_rawgetp` and `lua_rawsetp`, to be able to
perform lookups into tables using tagged or untagged `lightuserdata`
without additional calls and stack manipulation. This enables a more
efficient lookup way for `lightuserdata` keys similar to how
`lua_rawgetfield` and `lua_rawgeti` avoid extra operations for their
corresponding types.

---

Co-authored-by: Andy Friesen <[email protected]>
Co-authored-by: Annie Tang <[email protected]>
Co-authored-by: Ariel Weiss <[email protected]>
Co-authored-by: Hunter Goldstein <[email protected]>
Co-authored-by: Varun Saini <[email protected]>
Co-authored-by: Vyacheslav Egorov <[email protected]>

---------

Co-authored-by: Varun Saini <[email protected]>
Co-authored-by: Alexander Youngblood <[email protected]>
Co-authored-by: Menarul Alam <[email protected]>
Co-authored-by: Aviral Goel <[email protected]>
Co-authored-by: Vighnesh <[email protected]>
Co-authored-by: Vyacheslav Egorov <[email protected]>
Co-authored-by: Ariel Weiss <[email protected]>
Co-authored-by: Andy Friesen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants