@@ -52,6 +52,7 @@ LUAU_FASTFLAG(LuauPushTypeConstraint2)
5252LUAU_FASTFLAGVARIABLE(LuauScopedSeenSetInLookupTableProp)
5353LUAU_FASTFLAGVARIABLE(LuauIterableBindNotUnify)
5454LUAU_FASTFLAGVARIABLE(LuauAvoidOverloadSelectionForFunctionType)
55+ LUAU_FASTFLAG(LuauSimplifyIntersectionNoTreeSet)
5556
5657namespace Luau
5758{
@@ -2412,46 +2413,95 @@ bool ConstraintSolver::tryDispatch(const AssignIndexConstraint& c, NotNull<const
24122413
24132414 if (auto lhsIntersection = getMutable<IntersectionType>(lhsType))
24142415 {
2415- std::set<TypeId> parts;
24162416
2417- for (TypeId t : lhsIntersection )
2417+ if (FFlag::LuauSimplifyIntersectionNoTreeSet )
24182418 {
2419- if (auto tbl = getMutable<TableType>(follow (t)))
2419+
2420+ TypeIds parts;
2421+
2422+ for (TypeId t : lhsIntersection)
24202423 {
2421- if (tbl-> indexer )
2424+ if (auto tbl = getMutable<TableType>( follow (t)) )
24222425 {
2423- unify (constraint, indexType, tbl->indexer ->indexType );
2424- parts.insert (tbl->indexer ->indexResultType );
2425- }
2426+ if (tbl->indexer )
2427+ {
2428+ unify (constraint, indexType, tbl->indexer ->indexType );
2429+ parts.insert (tbl->indexer ->indexResultType );
2430+ }
24262431
2427- if (tbl->state == TableState::Unsealed || tbl->state == TableState::Free)
2432+ if (tbl->state == TableState::Unsealed || tbl->state == TableState::Free)
2433+ {
2434+ tbl->indexer = TableIndexer{indexType, rhsType};
2435+ parts.insert (rhsType);
2436+ }
2437+ }
2438+ else if (auto cls = get<ExternType>(follow (t)))
24282439 {
2429- tbl->indexer = TableIndexer{indexType, rhsType};
2430- parts.insert (rhsType);
2440+ while (true )
2441+ {
2442+ if (cls->indexer )
2443+ {
2444+ unify (constraint, indexType, cls->indexer ->indexType );
2445+ parts.insert (cls->indexer ->indexResultType );
2446+ break ;
2447+ }
2448+
2449+ if (cls->parent )
2450+ cls = get<ExternType>(cls->parent );
2451+ else
2452+ break ;
2453+ }
24312454 }
24322455 }
2433- else if (auto cls = get<ExternType>(follow (t)))
2456+
2457+ TypeId res = simplifyIntersection (constraint->scope , constraint->location , std::move (parts));
2458+
2459+ unify (constraint, rhsType, res);
2460+ }
2461+ else
2462+ {
2463+
2464+ std::set<TypeId> parts;
2465+
2466+ for (TypeId t : lhsIntersection)
24342467 {
2435- while ( true )
2468+ if ( auto tbl = getMutable<TableType>( follow (t)) )
24362469 {
2437- if (cls ->indexer )
2470+ if (tbl ->indexer )
24382471 {
2439- unify (constraint, indexType, cls->indexer ->indexType );
2440- parts.insert (cls->indexer ->indexResultType );
2441- break ;
2472+ unify (constraint, indexType, tbl->indexer ->indexType );
2473+ parts.insert (tbl->indexer ->indexResultType );
24422474 }
24432475
2444- if (cls->parent )
2445- cls = get<ExternType>(cls->parent );
2446- else
2447- break ;
2476+ if (tbl->state == TableState::Unsealed || tbl->state == TableState::Free)
2477+ {
2478+ tbl->indexer = TableIndexer{indexType, rhsType};
2479+ parts.insert (rhsType);
2480+ }
2481+ }
2482+ else if (auto cls = get<ExternType>(follow (t)))
2483+ {
2484+ while (true )
2485+ {
2486+ if (cls->indexer )
2487+ {
2488+ unify (constraint, indexType, cls->indexer ->indexType );
2489+ parts.insert (cls->indexer ->indexResultType );
2490+ break ;
2491+ }
2492+
2493+ if (cls->parent )
2494+ cls = get<ExternType>(cls->parent );
2495+ else
2496+ break ;
2497+ }
24482498 }
24492499 }
2450- }
24512500
2452- TypeId res = simplifyIntersection (constraint->scope , constraint->location , std::move (parts));
2501+ TypeId res = simplifyIntersection_DEPRECATED (constraint->scope , constraint->location , std::move (parts));
24532502
2454- unify (constraint, rhsType, res);
2503+ unify (constraint, rhsType, res);
2504+ }
24552505 }
24562506
24572507 // Other types do not support index assignment.
@@ -3805,11 +3855,11 @@ TypeId ConstraintSolver::simplifyIntersection(NotNull<Scope> scope, Location loc
38053855 return ::Luau::simplifyIntersection (builtinTypes, arena, left, right).result ;
38063856}
38073857
3808- TypeId ConstraintSolver::simplifyIntersection (NotNull<Scope> scope, Location location, std::set<TypeId> parts)
3858+ TypeId ConstraintSolver::simplifyIntersection (NotNull<Scope> scope, Location location, TypeIds parts)
38093859{
38103860 if (FFlag::DebugLuauEqSatSimplification)
38113861 {
3812- TypeId ty = arena->addType (IntersectionType{std::vector ( parts.begin (), parts. end () )});
3862+ TypeId ty = arena->addType (IntersectionType{parts.take ( )});
38133863
38143864 std::optional<EqSatSimplificationResult> res = eqSatSimplify (simplifier, ty);
38153865 if (!res)
@@ -3824,6 +3874,25 @@ TypeId ConstraintSolver::simplifyIntersection(NotNull<Scope> scope, Location loc
38243874 return ::Luau::simplifyIntersection (builtinTypes, arena, std::move (parts)).result ;
38253875}
38263876
3877+ TypeId ConstraintSolver::simplifyIntersection_DEPRECATED (NotNull<Scope> scope, Location location, std::set<TypeId> parts)
3878+ {
3879+ if (FFlag::DebugLuauEqSatSimplification)
3880+ {
3881+ TypeId ty = arena->addType (IntersectionType{std::vector (parts.begin (), parts.end ())});
3882+
3883+ std::optional<EqSatSimplificationResult> res = eqSatSimplify (simplifier, ty);
3884+ if (!res)
3885+ return ty;
3886+
3887+ for (TypeId ty : res->newTypeFunctions )
3888+ pushConstraint (scope, location, ReduceConstraint{ty});
3889+
3890+ return res->result ;
3891+ }
3892+ else
3893+ return ::Luau::simplifyIntersection_DEPRECATED (builtinTypes, arena, std::move (parts)).result ;
3894+ }
3895+
38273896TypeId ConstraintSolver::simplifyUnion (NotNull<Scope> scope, Location location, TypeId left, TypeId right)
38283897{
38293898 if (FFlag::DebugLuauEqSatSimplification)
0 commit comments