5679 Commits

Author SHA1 Message Date
Roberto Ierusalimschy
8a3a49250c Detail
Small improvement in line-tracing for internal debugging.
2025-01-06 14:44:06 -03:00
Roberto Ierusalimschy
1ec251e091 Detail (debugging aid)
When compiling with option HARDMEMTESTS, every creation of a new key
in a table forces an emergency GC.
2025-01-06 12:41:39 -03:00
Roberto Ierusalimschy
5894ca7b95 Scanner doesn't need to anchor reserved words 2024-12-30 16:53:51 -03:00
Roberto Ierusalimschy
abf8b1cd4a Small optimization in 'luaH_psetshortstr'
Do not optimize only for table updates (key already present).
Creation of new short keys in new tables can be quite common in
programs that create lots of small tables, for instance with
constructors like {x=e1,y=e2}.
2024-12-28 15:05:01 -03:00
Roberto Ierusalimschy
2a307f898b When parser reuses constants, only floats can collide
Ensure that float constants never use integer keys, so that only
floats can collide in 'k2proto'.
2024-12-28 15:03:48 -03:00
Roberto Ierusalimschy
f81d0bbd4f Detail in 'luaD_inctop'
Protect stack top before possible stack reallocation. (In the current
implementation, a stack reallocation cannot call an emergency
collection, so there is no bug, but it is safer not to depend on that.)
2024-12-17 13:36:12 -03:00
Roberto Ierusalimschy
1c40ff9faa Scanner and parser use different tables for constants
Moreover, each function being parsed has its own table.

The code is cleaner when each table is used for one specific purpose:
The scanner uses its table to anchor and unify strings, mapping strings
to themselves; the parser uses it to reuse constants in the code,
mapping constants to their indices in the constant table. A different
table for each task avoids false collisions.
2024-12-17 11:23:22 -03:00
Roberto Ierusalimschy
7538f3886d 'addk' broken in two functions 2024-12-16 14:13:49 -03:00
Roberto Ierusalimschy
412e9a4d95 'luaH_fastseti' uses 'checknoTM'
The extra check in checknoTM (versus only checking whether there is a
metatable) is cheap, and it is not that uncommon for a table to have a
metatable without a __newindex metafield.
2024-12-11 15:32:43 -03:00
Roberto Ierusalimschy
25a491fe34 OP_SELF restricted to constant short strings
Optimize this opcode for the common case. For long names or method
calls after too many constants, operation can be coded as a move
followed by 'gettable'.
2024-12-11 13:56:03 -03:00
Roberto Ierusalimschy
b4b616bdf2 Rehash reinserts elements with "lighter" functions
When reinserting elements into a table during a rehash, the code does
not need to invoke all the complexity of a full 'luaH_set':

- The table has space for all keys.
- The key cannot exist in the new hash.
- The keys are valid (not NaN nor nil).
- The keys are normalized (1.0 -> 1).
- The values cannot be nil.
- No barrier needed (the table already pointed to the key and value).
2024-12-05 17:34:08 -03:00
Roberto Ierusalimschy
bb93f04d87 Refactoring of 'luaH_newkey'
Function broke in two and some checks moved to the caller. (We may
want to call it without the checks.)
2024-12-05 14:27:58 -03:00
Roberto Ierusalimschy
975d4e0592 Fix in the definition of 'sizeLclosure'
The array at the end of a Lua closure has pointers to upvalues, not
to tagged values. This bug cannot cause any issue: The ISO C standard
requires that all pointers to structures have the same representation,
so sizeof(TValue*) must be equal to sizeof(UpVal*).
2024-12-03 10:53:46 -03:00
Roberto Ierusalimschy
04e495403b New function 'lua_printvalue' for internal debugging 2024-12-02 11:19:03 -03:00
Roberto Ierusalimschy
62afbc6bfc Details
Added two warnings to the makefile.
2024-11-29 17:39:20 -03:00
Roberto Ierusalimschy
002beeebe7 New way to keep hints for table length
Instead of using 'alimit' for keeping the size of the array and at
the same time being a hint for '#t', a table now keeps these two
values separate. The Table structure has a field 'asize' with the
size of the array, while the length hint is kept in the array itself.
That way, tables with no array part waste no space with that field.
Moreover, the space for the hint may have zero cost for small arrays,
if the array of tags plus the hint still fits in a single word.
2024-11-29 17:26:20 -03:00
Roberto Ierusalimschy
9329eeac3b Avoid an extra call to 'concretesize' in 'resizearray' 2024-11-27 18:37:29 -03:00
Roberto Ierusalimschy
682efe2678 Change to macro 'LUAI_TRY'
The call to 'f' is done by the macro, to give it more flexibility.
2024-11-25 15:47:08 -03:00
Roberto Ierusalimschy
50c7c915ee Debug information about extra arguments from __call
'debug.getinfo' can return number of extra arguments added to a call by
a chain of __call metavalues. That information is being used to improve
error messages about errors in these extra arguments.
2024-11-19 14:09:18 -03:00
Roberto Ierusalimschy
b117bdb344 Counter for length of chains of __call metamethods
This counter will allow (in a later commit) error messages to correct
argument numbers in functions called through __call metamethods.
2024-11-16 12:00:28 -03:00
Roberto Ierusalimschy
f12ce4029d More integration of 'nresults' into 'callstatus' 2024-11-15 15:25:11 -03:00
Roberto Ierusalimschy
a4762b6ffe 'objsize' returns 'l_mem'
Sums of size_t may not fit in a size_t.
2024-11-15 12:04:53 -03:00
Roberto Ierusalimschy
d4247befa1 New macro 'assert_code'
It allows code that is only used by assertions but that are not
assertions (e.g., declaration of a variable used in a later assertion).
2024-11-15 11:57:18 -03:00
Roberto Ierusalimschy
ee6a4cd1ec Ease slightly making Lua with C89 2024-11-15 11:43:32 -03:00
Roberto Ierusalimschy
8a4419b119 Dummy node has a non-nil key
That allows 'getfreepos' to treat it like a regular hash part that has
a deleted entry.
2024-11-15 10:48:52 -03:00
Roberto Ierusalimschy
9a91fe1640 Add extra size when resizing tables with deleted keys
Without this extra space, sequences of insertions/deletions (and
some other uses) can have unpexpected low performances.  See the
added tests for an example, and *Mathematical Models to Analyze Lua
Hybrid Tables and Why They Need a Fix* (Martínez, Nicaud, Rotondo;
arXiv:2208.13602v2) for detais.
2024-11-14 11:48:25 -03:00
Roberto Ierusalimschy
2491b87c10 New rule for size of array part
Array part needs 1/3 of its elements filled, instead of 1/2.
Array entries use ~1/3 the memory of hash entries, so this new rule
still ensures that array parts do not use more memory than keeping
the values in the hash, while allowing more uses of the array part,
which is more efficient than the hash.
2024-11-13 13:37:24 -03:00
Roberto Ierusalimschy
0de8191152 New structure to count keys in a table for rehashing 2024-10-28 14:15:21 -03:00
Roberto Ierusalimschy
853311e5b1 Table rehash can resize only the hash part
If there are no integer keys outside the array part, there is no
reason to resize it, saving the time to count its elements.  Moreover,
assignments to non-integer keys will not collapse a table created with
'table.create'.
2024-10-28 10:54:36 -03:00
Roberto Ierusalimschy
25a2dac2bc Always use unsigned int for indexing table-arrays 2024-10-24 15:33:25 -03:00
Roberto Ierusalimschy
e3ce88c9e8 New function 'lua_numbertostrbuff'
It converts a Lua number to a string in a buffer, without creating
a new Lua string.
2024-10-23 17:16:17 -03:00
Roberto Ierusalimschy
5ffcd458f0 Some changes in default GC parameters 2024-10-23 17:15:06 -03:00
Roberto Ierusalimschy
9b01da97e3 Small bug in 'luaE_luaE_statesize'
Plus, function was renamed to 'luaE_threadsize'.
2024-10-21 15:30:35 -03:00
Roberto Ierusalimschy
258355734d Better support in 'ltests' for tracing the GC 2024-10-21 15:18:20 -03:00
Roberto Ierusalimschy
d0815046d0 Some adjustments in transition minor->major
Plus extra comments and other details.
2024-10-18 17:10:20 -03:00
Roberto Ierusalimschy
3d54b42d59 'objsize' broke in smaller pieces 2024-09-30 14:01:42 -03:00
Roberto Ierusalimschy
e4f418f07c Local declaration in the REPL generates a warning 2024-09-27 10:00:35 -03:00
Roberto Ierusalimschy
20d42ccaae No errors in 'luaO_pushvfstring'
Any call to 'va_start' must have a corresponding call to 'va_end';
so, functions called between them (luaO_pushvfstring in particular)
cannot raise errors.
2024-09-20 15:56:39 -03:00
Roberto Ierusalimschy
70d6975018 Towards no errors in 'luaO_pushvfstring'
Any call to 'va_start' must have a corresponding call to 'va_end';
so, functions called between them (luaO_pushvfstring in particular)
cannot raise errors.
2024-09-20 12:21:11 -03:00
Roberto Ierusalimschy
00e34375ec In 'luaO_pushvfstring', all options use 'addstr2buff' 2024-09-20 10:06:06 -03:00
Roberto Ierusalimschy
45a8f1b593 Removed 'if' left from commit ddfa1fbccfe 2024-09-20 09:43:46 -03:00
Roberto Ierusalimschy
8fac494509 Avoid Microsoft warning
> warning C4334: '<<': result of 32-bit shift implicitly converted to
> 64 bits (was 64-bit shift intended?)
2024-09-19 19:09:35 -03:00
Roberto Ierusalimschy
9b72355f99 USHRT_MAX changed to SHRT_MAX
USHRT_MAX does not fit in an 'int' in 16-bit systems.
2024-09-19 19:06:16 -03:00
Roberto Ierusalimschy
ddfa1fbccf GC back to controling pace counting bytes
Memory is the resource we want to save. Still to be reviewed again.
2024-09-19 19:02:14 -03:00
Roberto Ierusalimschy
b443145ff3 Details
Fixed comments in sort partition.
2024-09-12 11:08:11 -03:00
Roberto Ierusalimschy
4901853c11 Parameter for lua_gc/LUA_GCSTEP changed to 'size_t'
'size_t' is the common type for measuring memory. 'int' can be too
small for steps.
2024-09-10 17:05:39 -03:00
Roberto Ierusalimschy
a04e0ffdb9 Rename of fields in global state that control GC
All fields in the global state that control the pace of the garbage
collector prefixed with 'GC'.
2024-09-06 14:38:39 -03:00
Roberto Ierusalimschy
007b8c7a01 Details
Identation + comments
2024-09-06 14:35:04 -03:00
Roberto Ierusalimschy
fd0e1f530d Added option for direct correction of stack pointers
The use of a pointer (not access, only for computations) after its
deallocation is forbiden in ISO C, but seems to work fine in all
platforms we are aware of. So, using that to correct stack pointers
after a stack reallocation seems safe and is much simpler than the
current implementation (first change all pointers to offsets and
then changing the offsets back to pointers). Anyway, for now that
option is disabled.
2024-08-22 11:11:00 -03:00
Roberto Ierusalimschy
75620b45ae 'lcode.c' can use 'checklimit', too 2024-08-20 15:15:23 -03:00