Skip to content

Commit c68208d

Browse files
committed
Clean up pre-loading of 'one' values in LSL compiler
1 parent df84e40 commit c68208d

File tree

2 files changed

+6
-18
lines changed

2 files changed

+6
-18
lines changed

Compiler/include/Luau/LSLCompiler.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ struct LuauSymbolData {
1717
// Constants that need small indices (tracked during resource visitor pass)
1818
// Each import is stored as module,method pair (e.g., "bit32","bnot" or "lsl","cast")
1919
std::unordered_set<std::string> needed_import_strings; // Individual strings used in imports
20-
bool needs_int_one = false; // For integer ++/--
21-
bool needs_float_one = false; // For float ++/--
22-
bool needs_vector_one = false; // For vector ++/-- (unlikely but possible)
20+
std::unordered_set<LSLType*> needed_one_types; // Types which we need the default `one` value for.
2321
};
2422

2523
typedef std::unordered_map<LSLSymbol *, LuauSymbolData> LuauSymbolMap;

Compiler/src/LSLCompiler.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,8 @@ bool LuauResourceVisitor::visit(LSLUnaryExpression *un_expr)
113113
if (op == OP_PRE_INCR || op == OP_POST_INCR || op == OP_PRE_DECR || op == OP_POST_DECR)
114114
{
115115
auto *lvalue = (LSLLValueExpression *)child_expr;
116-
auto itype = lvalue->getIType();
117-
if (itype == LST_INTEGER)
118-
_mCurrentFunc->needs_int_one = true;
119-
else if (itype == LST_FLOATINGPOINT)
120-
_mCurrentFunc->needs_float_one = true;
121-
else if (itype == LST_VECTOR)
122-
_mCurrentFunc->needs_vector_one = true;
116+
// We will need the type's `one` value as a low-indexed constant to do these ops
117+
_mCurrentFunc->needed_one_types.insert(lvalue->getType());
123118
}
124119
else if (op == OP_BIT_NOT)
125120
{
@@ -495,14 +490,9 @@ void LuauVisitor::buildFunction(LSLASTNode *func_like)
495490

496491
// Pre-allocate constants that need small indices (detected by LuauResourceVisitor)
497492
// Do this first to ensure they get low constant indices
498-
if (sym_data.needs_int_one)
499-
addConstantInteger(1, UINT8_MAX);
500-
if (sym_data.needs_float_one)
501-
addConstantFloat(1.0f, UINT8_MAX);
502-
if (sym_data.needs_vector_one)
503-
{
504-
// Vector <1, 1, 1> for vector increment/decrement
505-
addConstantUnder(TYPE(LST_VECTOR)->getOneValue(), UINT8_MAX);
493+
for (auto one_type : sym_data.needed_one_types)
494+
{
495+
addConstantUnder(one_type->getOneValue(), UINT8_MAX);
506496
}
507497

508498
// Pre-allocate import strings to ensure they're under index 1024

0 commit comments

Comments
 (0)