Skip to content

Commit 3e32f73

Browse files
Peter Neissclaude
andcommitted
Phase 122.4: Rename lua_State count fields for clarity
Replaced abbreviated field names with verbose camelCase: - nci → numberOfCallInfos (6 sites) - nCcalls → numberOfCCalls (9 sites) Updated accessor methods for consistency: - getNCI() → getNumberOfCallInfos() - setNCI() → setNumberOfCallInfos() - getNCIRef() → getNumberOfCallInfosRef() - getNCcalls() → getNumberOfCCalls() - setNCcalls() → setNumberOfCCalls() - getNCcallsRef() → getNumberOfCCallsRef() Changes across: - lstate.h (field declarations, accessor methods, helper functions) - lstate.cpp (5 sites: extendCI, freeCI, shrinkCI, luaE_incCstack, luaE_threadsize) - ldo.cpp (5 sites: rawRunProtected, cCall, resume) - parseutils.cpp (1 site: leavelevel) - parser.cpp (1 site: leavelevel) - ltests.cpp (2 sites: stacklevel) Performance: ~2.11s avg (5 runs) - excellent, no regression Tests: All passing ✓ 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 07da1e5 commit 3e32f73

File tree

7 files changed

+7086
-32
lines changed

7 files changed

+7086
-32
lines changed

src/compiler/parser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ inline void enterlevel(LexState* ls) {
5858
}
5959

6060
inline void leavelevel(LexState* ls) noexcept {
61-
ls->getLuaState()->getNCcallsRef()--;
61+
ls->getLuaState()->getNumberOfCCallsRef()--;
6262
}
6363

6464

src/compiler/parseutils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ inline void enterlevel(LexState* ls) {
9393
}
9494

9595
inline void leavelevel(LexState* ls) noexcept {
96-
ls->getLuaState()->getNCcallsRef()--;
96+
ls->getLuaState()->getNumberOfCCallsRef()--;
9797
}
9898

9999

src/core/ldo.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,10 +208,10 @@ l_noret lua_State::throwBaseLevel(TStatus errcode) {
208208
** ENCAPSULATION NOTE:
209209
** This is now a lua_State method rather than a free function, following
210210
** the C++ modernization (Phase 31). All state manipulation uses accessor
211-
** methods (getNCcalls, setErrorJmp, etc.) rather than direct field access.
211+
** methods (getNumberOfCCalls, setErrorJmp, etc.) rather than direct field access.
212212
*/
213213
TStatus lua_State::rawRunProtected(Pfunc f, void *ud) {
214-
l_uint32 oldnCcalls = getNCcalls();
214+
l_uint32 oldnCcalls = getNumberOfCCalls();
215215
lua_longjmp lj;
216216
lj.status = LUA_OK;
217217
lj.previous = getErrorJmp(); /* chain new error handler */
@@ -230,7 +230,7 @@ TStatus lua_State::rawRunProtected(Pfunc f, void *ud) {
230230
}
231231

232232
setErrorJmp(lj.previous); /* restore old error handler */
233-
setNCcalls(oldnCcalls);
233+
setNumberOfCCalls(oldnCcalls);
234234
return lj.status;
235235
}
236236

@@ -670,7 +670,7 @@ CallInfo* lua_State::preCall(StkId func, int nresults) {
670670
// Convert to private lua_State method
671671
void lua_State::cCall(StkId func, int nResults, l_uint32 inc) {
672672
CallInfo *ci_result;
673-
getNCcallsRef() += inc;
673+
getNumberOfCCallsRef() += inc;
674674
if (l_unlikely(getCcalls(this) >= LUAI_MAXCCALLS)) {
675675
checkstackp(this, 0, func); /* free any use of EXTRA_STACK */
676676
luaE_checkcstack(this);
@@ -679,7 +679,7 @@ void lua_State::cCall(StkId func, int nResults, l_uint32 inc) {
679679
ci_result->callStatusRef() |= CIST_FRESH; /* mark that it is a "fresh" execute */
680680
luaV_execute(this, ci_result); /* call it */
681681
}
682-
getNCcallsRef() -= inc;
682+
getNumberOfCCallsRef() -= inc;
683683
}
684684

685685

@@ -902,10 +902,10 @@ LUA_API int lua_resume (lua_State *L, lua_State *from, int nargs,
902902
}
903903
else if (L->getStatus() != LUA_YIELD) /* ended with errors? */
904904
return resume_error(L, "cannot resume dead coroutine", nargs);
905-
L->setNCcalls((from) ? getCcalls(from) : 0);
905+
L->setNumberOfCCalls((from) ? getCcalls(from) : 0);
906906
if (getCcalls(L) >= LUAI_MAXCCALLS)
907907
return resume_error(L, "C stack overflow", nargs);
908-
L->getNCcallsRef()++;
908+
L->getNumberOfCCallsRef()++;
909909
luai_userstateresume(L, nargs);
910910
api_checkpop(L, (L->getStatus() == LUA_OK) ? nargs + 1 : nargs);
911911
status = L->rawRunProtected( resume, &nargs);

src/core/lstate.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ CallInfo *luaE_extendCI (lua_State *L) {
8989
ci->setNext(nullptr);
9090
// trap already initialized to 0 in constructor, but keep this for clarity
9191
ci->getTrap() = 0;
92-
L->getNCIRef()++;
92+
L->getNumberOfCallInfosRef()++;
9393
return ci;
9494
}
9595

@@ -104,7 +104,7 @@ static void freeCI (lua_State *L) {
104104
while ((ci = next) != nullptr) {
105105
next = ci->getNext();
106106
luaM_free(L, ci);
107-
L->getNCIRef()--;
107+
L->getNumberOfCallInfosRef()--;
108108
}
109109
}
110110

@@ -121,7 +121,7 @@ void luaE_shrinkCI (lua_State *L) {
121121
while ((next = ci->getNext()) != nullptr) { /* two extra elements? */
122122
CallInfo *next2 = next->getNext(); /* next's next */
123123
ci->setNext(next2); /* remove next from the list */
124-
L->getNCIRef()--;
124+
L->getNumberOfCallInfosRef()--;
125125
luaM_free(L, next); /* free next */
126126
if (next2 == nullptr)
127127
break; /* no more elements */
@@ -149,7 +149,7 @@ void luaE_checkcstack (lua_State *L) {
149149

150150

151151
LUAI_FUNC void luaE_incCstack (lua_State *L) {
152-
L->getNCcallsRef()++;
152+
L->getNumberOfCCallsRef()++;
153153
if (l_unlikely(getCcalls(L) >= LUAI_MAXCCALLS))
154154
luaE_checkcstack(L);
155155
}
@@ -179,7 +179,7 @@ static void stack_init (lua_State *L1, lua_State *L) {
179179
static void freestack (lua_State *L) {
180180
L->setCI(L->getBaseCI()); /* free the entire 'ci' list */
181181
freeCI(L);
182-
lua_assert(L->getNCI() == 0);
182+
lua_assert(L->getNumberOfCallInfos() == 0);
183183
/* free stack via LuaStack subsystem */
184184
L->getStackSubsystem().free(L);
185185
}
@@ -240,7 +240,7 @@ static void preinit_thread (lua_State *L, global_State *g) {
240240

241241
lu_mem luaE_threadsize (lua_State *L) {
242242
lu_mem sz = static_cast<lu_mem>(sizeof(LX))
243-
+ cast_uint(L->getNCI()) * sizeof(CallInfo);
243+
+ cast_uint(L->getNumberOfCallInfos()) * sizeof(CallInfo);
244244
if (L->getStack().p != nullptr)
245245
sz += cast_uint(L->getStackSize() + EXTRA_STACK) * sizeof(StackValue);
246246
return sz;
@@ -319,7 +319,7 @@ TStatus luaE_resetthread (lua_State *L, TStatus status) {
319319
LUA_API int lua_closethread (lua_State *L, lua_State *from) {
320320
TStatus status;
321321
lua_lock(L);
322-
L->setNCcalls((from) ? getCcalls(from) : 0);
322+
L->setNumberOfCCalls((from) ? getCcalls(from) : 0);
323323
status = luaE_resetthread(L, L->getStatus());
324324
if (L == from) /* closing itself? */
325325
L->throwBaseLevel( status);

src/core/lstate.h

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,8 @@ struct lua_State : public GCBase<lua_State> {
422422
} transferinfo;
423423

424424
// Step 6: Call counter fields (encapsulated)
425-
l_uint32 nCcalls; /* number of nested non-yieldable or C calls */
426-
int nci; /* number of items in 'ci' list */
425+
l_uint32 numberOfCCalls; /* number of nested non-yieldable or C calls */
426+
int numberOfCallInfos; /* number of items in 'ci' list */
427427

428428
public:
429429
// Initialize lua_State fields (GC base fields must already be set by caller)
@@ -442,7 +442,7 @@ struct lua_State : public GCBase<lua_State> {
442442

443443
// CallInfo fields
444444
ci = nullptr;
445-
nci = 0;
445+
numberOfCallInfos = 0;
446446
// base_ci initialized via placement new to call its constructor
447447
new (&base_ci) CallInfo();
448448

@@ -469,7 +469,7 @@ struct lua_State : public GCBase<lua_State> {
469469
transferinfo.ntransfer = 0;
470470

471471
// Call depth
472-
nCcalls = 0;
472+
numberOfCCalls = 0;
473473
}
474474

475475
// Stack subsystem accessor
@@ -563,17 +563,17 @@ struct lua_State : public GCBase<lua_State> {
563563
const auto& getTransferInfo() const noexcept { return transferinfo; }
564564

565565
// Step 6: Call counter field accessors
566-
l_uint32 getNCcalls() const noexcept { return nCcalls; }
567-
void setNCcalls(l_uint32 nc) noexcept { nCcalls = nc; }
568-
l_uint32& getNCcallsRef() noexcept { return nCcalls; } // For increment/decrement
566+
l_uint32 getNumberOfCCalls() const noexcept { return numberOfCCalls; }
567+
void setNumberOfCCalls(l_uint32 nc) noexcept { numberOfCCalls = nc; }
568+
l_uint32& getNumberOfCCallsRef() noexcept { return numberOfCCalls; } // For increment/decrement
569569

570-
int getNCI() const noexcept { return nci; }
571-
void setNCI(int n) noexcept { nci = n; }
572-
int& getNCIRef() noexcept { return nci; } // For increment/decrement
570+
int getNumberOfCallInfos() const noexcept { return numberOfCallInfos; }
571+
void setNumberOfCallInfos(int n) noexcept { numberOfCallInfos = n; }
572+
int& getNumberOfCallInfosRef() noexcept { return numberOfCallInfos; } // For increment/decrement
573573

574574
// Non-yieldable call management
575-
void incrementNonYieldable() noexcept { nCcalls += 0x10000; }
576-
void decrementNonYieldable() noexcept { nCcalls -= 0x10000; }
575+
void incrementNonYieldable() noexcept { numberOfCCalls += 0x10000; }
576+
void decrementNonYieldable() noexcept { numberOfCCalls -= 0x10000; }
577577

578578
// Phase 44.4: Additional lua_State helper methods
579579

@@ -700,12 +700,12 @@ struct lua_State : public GCBase<lua_State> {
700700

701701
/* true if this thread does not have non-yieldable calls in the stack */
702702
inline constexpr bool yieldable(const lua_State* L) noexcept {
703-
return ((L->getNCcalls() & 0xffff0000) == 0);
703+
return ((L->getNumberOfCCalls() & 0xffff0000) == 0);
704704
}
705705

706706
/* real number of C calls */
707707
inline constexpr l_uint32 getCcalls(const lua_State* L) noexcept {
708-
return (L->getNCcalls() & 0xffff);
708+
return (L->getNumberOfCCalls() & 0xffff);
709709
}
710710

711711
/* Increment the number of non-yieldable calls */

src/testing/ltests.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,8 +1108,8 @@ static int stacklevel (lua_State *L) {
11081108
int a = 0;
11091109
lua_pushinteger(L, cast_Integer(L->getTop().p - L->getStack().p));
11101110
lua_pushinteger(L, L->getStackSize());
1111-
lua_pushinteger(L, cast_Integer(L->getNCcalls()));
1112-
lua_pushinteger(L, L->getNCI());
1111+
lua_pushinteger(L, cast_Integer(L->getNumberOfCCalls()));
1112+
lua_pushinteger(L, L->getNumberOfCallInfos());
11131113
lua_pushinteger(L, (lua_Integer)(size_t)&a);
11141114
return 5;
11151115
}

0 commit comments

Comments
 (0)