luau/tests
Petri Häkkinen 2173938eb0
Add tagged lightuserdata (#1087)
This change adds support for tagged lightuserdata and optional custom
typenames for lightuserdata.

Background: Lightuserdata is an efficient representation for many kinds
of unmanaged handles and resources in a game engine. However, currently
the VM only supports one kind of lightuserdata, which makes it
problematic in practice. For example, it's not possible to distinguish
between different kinds of lightuserdata in Lua bindings, which can lead
to unsafe practices and even crashes when a wrong kind of lightuserdata
is passed to a binding function. Tagged lightuserdata work similarly to
tagged userdata, i.e. they allow checking the tag quickly using
lua_tolightuserdatatagged (or lua_lightuserdatatag).

The tag is stored in the 'extra' field of TValue so it will add no cost
to the (untagged) lightuserdata type.

Alternatives would be to use full userdata values or use bitpacking to
embed type information into lightuserdata on application level.
Unfortunately these options are not that great in practice: full
userdata have major performance implications and bitpacking fails in
cases where full 64 bits are already used (e.g. pointers or 64-bit
hashes).

Lightuserdata names are not strictly necessary but they are rather
convenient when debugging Lua code. More precise error messages and
tostring returning more specific typename are useful to have in practice
(e.g. "resource" or "entity" instead of the more generic "userdata").

Impl note: I did not add support for renaming tags in
lua_setlightuserdataname as I'm not sure if it's possible to free fixed
strings. If it's simple enough, maybe we should allow renaming (although
I can't think of a specific need for it)?

---------

Co-authored-by: Petri Häkkinen <petrih@rmd.remedy.fi>
2023-12-14 15:05:51 -08:00
..
conformance Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
require Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
AssemblyBuilderA64.test.cpp Sync to upstream/release/600 (#1076) 2023-10-20 18:10:30 -07:00
AssemblyBuilderX64.test.cpp Sync to upstream/release/603 (#1097) 2023-11-10 13:10:07 -08:00
AstJsonEncoder.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
AstQuery.test.cpp Sync to upstream/release/596 (#1050) 2023-09-22 12:12:15 -07:00
AstQueryDsl.cpp Sync to upstream/release/549 (#707) 2022-10-14 12:48:41 -07:00
AstQueryDsl.h Sync to upstream/release/549 (#707) 2022-10-14 12:48:41 -07:00
AstVisitor.test.cpp Sync to upstream/release/501 (#20) 2021-11-01 14:52:34 -07:00
Autocomplete.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
BuiltinDefinitions.test.cpp Sync to upstream/release/567 (#860) 2023-03-10 12:21:07 -08:00
ClassFixture.cpp Sync to upstream/release/600 (#1076) 2023-10-20 18:10:30 -07:00
ClassFixture.h Sync to upstream/release/600 (#1076) 2023-10-20 18:10:30 -07:00
CodeAllocator.test.cpp Sync to upstream/release/597 (#1054) 2023-09-29 18:13:05 -07:00
Compiler.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
Config.test.cpp Sync to upstream/release/501 (#20) 2021-11-01 14:52:34 -07:00
Conformance.test.cpp Add tagged lightuserdata (#1087) 2023-12-14 15:05:51 -08:00
ConstraintGeneratorFixture.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
ConstraintGeneratorFixture.h Sync to upstream/release/602 (#1089) 2023-11-03 16:45:04 -07:00
ConstraintSolver.test.cpp Sync to upstream/release/602 (#1089) 2023-11-03 16:45:04 -07:00
CostModel.test.cpp Sync to upstream/release/591 (#1012) 2023-08-18 11:15:41 -07:00
DataFlowGraph.test.cpp Sync to upstream/release/606 (#1127) 2023-12-08 13:50:16 -08:00
DenseHash.test.cpp Sync to upstream/release/561 (#820) 2023-01-27 14:28:31 -08:00
DiffAsserts.cpp Sync to upstream/release/600 (#1076) 2023-10-20 18:10:30 -07:00
DiffAsserts.h Sync to upstream/release/600 (#1076) 2023-10-20 18:10:30 -07:00
Differ.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
Error.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
Fixture.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
Fixture.h Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
Frontend.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
InsertionOrderedMap.test.cpp Sync to upstream/release/580 (#951) 2023-06-09 10:08:00 -07:00
IostreamOptional.h Sync to upstream/release/603 (#1097) 2023-11-10 13:10:07 -08:00
IrBuilder.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
IrCallWrapperX64.test.cpp Sync to upstream/release/601 (#1084) 2023-10-27 14:18:41 -07:00
IrRegAllocX64.test.cpp Sync to upstream/release/595 (#1044) 2023-09-15 10:26:59 -07:00
JsonEmitter.test.cpp Sync to upstream/release/543 (#657) 2022-09-01 16:14:03 -07:00
Lexer.test.cpp Sync to upstream/release/570 (#885) 2023-03-31 11:42:49 -07:00
Linter.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
LValue.test.cpp Sync to upstream/release/557 (#794) 2023-01-04 12:53:17 -08:00
main.cpp Sync to upstream/release/603 (#1097) 2023-11-10 13:10:07 -08:00
Module.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
NonstrictMode.test.cpp Sync to upstream/release/574 (#910) 2023-04-28 12:55:13 -07:00
NonStrictTypeChecker.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
Normalize.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
NotNull.test.cpp Sync to upstream/release/555 (#768) 2022-12-02 10:09:59 -08:00
Parser.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
RegisterCallbacks.cpp Sync to upstream/release/594 (#1036) 2023-09-07 17:13:49 -07:00
RegisterCallbacks.h Sync to upstream/release/594 (#1036) 2023-09-07 17:13:49 -07:00
Repl.test.cpp Sync to upstream/release/553 (#742) 2022-11-10 14:53:13 -08:00
RequireByString.test.cpp Sync to upstream/release/606 (#1127) 2023-12-08 13:50:16 -08:00
RequireTracer.test.cpp Sync to upstream/release/514 (#372) 2022-02-17 17:18:01 -08:00
RuntimeLimits.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
ScopedFlags.h Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
Set.test.cpp Sync to upstream/release/604 (#1106) 2023-11-17 10:46:18 -08:00
Simplify.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
StringUtils.test.cpp Sync to upstream/release/588 (#992) 2023-07-28 08:13:53 -07:00
Subtyping.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
Symbol.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
ToDot.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TopoSort.test.cpp Sync to upstream/release/523 (#459) 2022-04-14 16:57:43 -07:00
ToString.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
Transpiler.test.cpp Sync to upstream/release/603 (#1097) 2023-11-10 13:10:07 -08:00
TxnLog.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeFamily.test.cpp Sync to upstream/release/598 (#1063) 2023-10-06 12:02:32 -07:00
TypeInfer.aliases.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.annotations.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.anyerror.test.cpp Sync to upstream/release/604 (#1106) 2023-11-17 10:46:18 -08:00
TypeInfer.builtins.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.cfa.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.classes.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.definitions.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.functions.test.cpp Sync to upstream/release/606 (#1127) 2023-12-08 13:50:16 -08:00
TypeInfer.generics.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.intersectionTypes.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.loops.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.modules.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.negations.test.cpp Sync to upstream/release/574 (#910) 2023-04-28 12:55:13 -07:00
TypeInfer.oop.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.operators.test.cpp Sync to upstream/release/603 (#1097) 2023-11-10 13:10:07 -08:00
TypeInfer.primitives.test.cpp Sync to upstream/release/600 (#1076) 2023-10-20 18:10:30 -07:00
TypeInfer.provisional.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.refinements.test.cpp Sync to upstream/release/606 (#1127) 2023-12-08 13:50:16 -08:00
TypeInfer.rwprops.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.singletons.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.tables.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.tryUnify.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.typePacks.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.typestates.test.cpp Sync to upstream/release/606 (#1127) 2023-12-08 13:50:16 -08:00
TypeInfer.unionTypes.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeInfer.unknownnever.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypePack.test.cpp Sync to upstream/release/571 (#895) 2023-04-07 14:01:29 -07:00
TypePath.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
TypeVar.test.cpp Sync to upstream/release/597 (#1054) 2023-09-29 18:13:05 -07:00
Unifier2.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00
Variant.test.cpp Sync to upstream/release/552 (#735) 2022-11-04 10:33:22 -07:00
VisitType.test.cpp Sync to upstream/release/605 (#1118) 2023-12-01 23:46:57 -08:00