Commit graph

423 commits

Author SHA1 Message Date
kyren b8da08187d Move integration tests into top-level tests directory
other minor refactors
2018-09-16 20:15:51 -04:00
kyren 4a587ca1c5 Add compilefail test for Scope::create_nonstatic_userdata 2018-09-16 19:54:58 -04:00
kyren 7eb71fb1df Rename Scope::create_userdata to Scope::create_nonstatic_userdata
avoids clashing with the previous method name to avoid confusion
2018-09-16 19:54:12 -04:00
kyren 58b991b83b
Merge pull request #86 from kyren/unstatic
Allow non-'static UserData created from Scope
2018-09-16 19:42:14 -04:00
kyren 6153ec4b95 basic tests for nonstatic userdata 2018-09-04 19:41:00 -04:00
kyren add547b356 comment terminology... fix? 2018-09-04 19:09:09 -04:00
kyren 703601e348 code re-org have slightly less pub(crate) items 2018-09-04 19:05:21 -04:00
kyren 30a94c4dec Comment updates that I really hope are correct
Tried to explain the rationale for safety around callbacks in Lua and Scope a
bit better, because every time I don't look at this for a while I forget my
reasoning.  I'm not always so great at using the right terminology, so to
whoever reads this, if I got this wrong please tell me.
2018-09-04 17:36:06 -04:00
kyren bd00af2bac Initial design for non-'static scoped userdata
Uses the same UserData trait, and should at least in theory support everything
that 'static UserData does, except that any functions added that rely on
AnyUserData are pretty much useless.

Probably pretty slow and I'm not sure how to make it dramatically faster, which
is a shame because generally when you need non'-static userdata you might be
creating it kind of a lot (if it was long-lived, it would probably be 'static).

Haven't added tests yet, will do that next.
2018-09-04 03:40:13 -04:00
kyren 37165a8201 Don't leak userdata if the metatable creation errors or panics 2018-09-04 03:38:22 -04:00
kyren 89b9968920 small macro style change 2018-09-02 20:34:39 -04:00
kyren 42054a9bfe better cargo test flags for travis 2018-09-02 02:53:30 -04:00
kyren 9c4d451d4c Implement tuple MultiValue tuple conversion up to 16 2018-09-02 02:48:54 -04:00
kyren ac21874d11 (cargo-release) start next development iteration 0.14.3-alpha.0 2018-08-06 19:09:27 -04:00
kyren ca8326475f (cargo-release) version 0.14.2 2018-08-06 19:09:09 -04:00
kyren 9fbcbdac64 Update changelog for 0.14.2 additional soundness fix 2018-08-06 19:08:50 -04:00
kyren 1a9c50f228 Solve (maybe) *another* soundness issue with Lua::scope
Callbacks should not be able to capture their arguments and hold onto them,
because the `&Lua` used in previous calls will not remain valid across calls.
One could imagine an API where the specific `&Lua` is simply stored inside the
`Scope` itself, but this is harder to do, and would (badly) encourage storing
references inside Lua userdata.

Ideally, the only way it should be possible to store Lua handles inside Lua
itself is through usafety or the `rental` crate or other self-borrowing
techniques to make references into 'static types.  If at all possible this
roadblock should stay, because reference types inside userdata are almost always
going to lead to a a memory leak, and if you accept the risks you should just
use `RegistryKey` with its manual removal.
2018-08-05 20:03:47 -04:00
kyren b35ff5fa12 Remove out of date documentation, simpler scope lifetimes
The documentation describing it being a logic bug to access "outer" callback
handles when inside an "inner" callback is inaccurate, that was only true when
using an older design for handle values.

Also, there is no reason to have a separate 'callback lifetime, because 'scope
is already invariant and just using 'scope seems equivalent.
2018-08-05 19:02:19 -04:00
kyren e4de847395 (cargo-release) start next development iteration 0.14.2-alpha.0 2018-08-05 12:35:05 -04:00
kyren e6ca00b65c (cargo-release) version 0.14.1 2018-08-05 12:33:26 -04:00
kyren 294f3e64ca Update changelog in preparation for 0.14.1 release
I'm a bit unclear on whether bumping a dependency's minor version is considered
a semver breaking change, but without doing this everyone probably gets
deprecation warnings?
2018-08-05 12:31:33 -04:00
kyren a2615a8cbb Fix for a soundness bug around scope, don't allow callback parameters to escape
Also includes other fixes for compiletest_rs failures, and a small reorg of tests
2018-08-05 11:54:33 -04:00
kyren 8366960368 Update to failure 0.1.2, rename deprecated methods 2018-08-05 11:48:25 -04:00
kyren 2e1bdb64c0 format with up-to-date rustfmt 2018-08-05 09:51:39 -04:00
kyren e6688e1db2 very small doc fixes 2018-08-05 09:51:32 -04:00
kyren 73306d2286 Upgrade embedded Lua to 5.3.5 2018-07-18 05:29:27 -04:00
kyren 2d4f4b95c8 (cargo-release) start next development iteration 0.14.1-alpha.0 2018-06-29 01:28:28 -04:00
kyren 0cab2e25de (cargo-release) version 0.14.0 2018-06-29 01:25:15 -04:00
kyren 02bc8da203 Prepare for 0.14.0 release 2018-06-29 01:24:28 -04:00
kyren 31fa9173ae Fix #78 2018-05-02 20:05:43 -04:00
kyren 71f3dd50a1 New approach for ref types, use an auxillary thread stack
Vastly simpler and less magical than using a fixed size magical section of the
active stack, and seems to be no slower.  The only real downside is that
it *seems* extremely extremely hacky (and to be fair, it is).
2018-03-28 01:09:51 -04:00
kyren 60bfe1fb07 Nope, require failure 1.0 because otherwise it depends on backtrace automatically 2018-03-20 16:23:23 -04:00
kyren a22c23ae26 rely on failure 0.1.2 from git to get backtrace disabled by default
without relying on an unreleased 1.0 API.  Trying to get rid of the special
chucklefish hack branches in the meantime before 1.0.
2018-03-20 15:17:27 -04:00
kyren 5aa22de68e Use git dependency on failure 1.0 for right now 2018-03-20 14:07:32 -04:00
kyren 8b9ab3d031 Small renames and comments to better communicate the intention of stack checking functions 2018-03-19 17:42:10 -04:00
kyren a05f0d5cd0 Where possible, don't call to_lua / from_lua / to_lua_multi / from_lua_multi callbacks during Lua stack manipulation
This should protect against being able to trigger a stack assert in Lua.  Lua
and associated types shoul be able to assume that LUA_MINSTACK stack slots are
available on any user entry point.  In the future, we could turn check_stack
into something that only checked the Lua stack when debug_assertions is true.
2018-03-19 15:16:40 -04:00
kyren 0d5e45e800 Always ensure LUA_MINSTACK available stack spaces on callback
Otherwise, cleanly error with an appropriate stack error.  Part of an effort to
ensure that it should not be possible to trigger a stack space assert.
2018-03-19 14:36:01 -04:00
kyren 4b6809c766 Clean up some lifetime specification 2018-03-19 14:35:46 -04:00
kyren 985636267c Fix some bad potential unsafety on inner callback calls.
Since we now optionally use stack spaces for handle values, we have to be
mindful of whether our stack handle points to the stack in an outer level of
Lua "stack protection".  We now keep track of the "recursion level" of Lua
instances, and do not allow ref manipulation on "outer" Lua instances until the
inner callback has returned.  Also, update the documentation to reflect the
additional panic behavior.
2018-03-12 22:36:52 -04:00
kyren c1e1ac432c changelog fixes 2018-03-12 21:06:31 -04:00
kyren 1019ab8a3f Use rlua_ asserts instead of unreachable!, changelog updates for 0.14
0.14 will be released alongside `failure` 1.0 with a dependency update.
2018-03-12 20:36:39 -04:00
kyren c252668ba6 Fix README mention of "registry handles" 2018-03-12 18:13:22 -04:00
kyren c6c90f201c Documentation updates for new handle behavior, and some minor cleanup 2018-03-12 17:50:48 -04:00
kyren 4358034bbf Do not crash in release when accessing an AnyUserData
Also, don't bother asserting if the userdata has no metatable, just behave as
though the userdata has no type.  This should be impossible to trigger currently
without the debug library, but it is not really that useful of an assert anyway.
2018-03-12 17:48:05 -04:00
kyren f0775f4a1a Move several asserts to only be active with debug, bump alpha version number 2018-03-12 16:14:52 -04:00
kyren f79d771f1a Documentation improvements, split scope into its own module, improved tests
Also makes `Lua` and associated types !UnwindSafe and !RefUnwindSafe, which they
should be because they are intensely internally mutable.  Lua IS still panic
safe, but that doesn't mean it should be marked as UnwindSafe (as I understand
it).
2018-03-12 16:00:11 -04:00
kyren ee23f199f0 Remove stack_guard function and instead just use StackGuard directly 2018-03-12 13:13:44 -04:00
kyren 7b2f7a2932 Add a simple userdata benchmark 2018-03-12 12:48:20 -04:00
kyren 95633ce915 Merge branch 'bench' 2018-03-12 12:29:27 -04:00
kyren 601e9f4cac A lot of performance changes.
Okay, so this is kind of a mega-commit of a lot of performance related changes
to rlua, some of which are pretty complicated.

There are some small improvements here and there, but most of the benefits of
this change are from a few big changes.  The simplest big change is that there
is now `protect_lua` as well as `protect_lua_call`, which allows skipping a
lightuserdata parameter and some stack manipulation in some cases.  Second
simplest is the change to use Vec instead of VecDeque for MultiValue, and to
have MultiValue be used as a sort of "backwards-only" Vec so that ToLuaMulti /
FromLuaMulti still work correctly.

The most complex change, though, is a change to the way LuaRef works, so that
LuaRef can optionally point into the Lua stack instead of only registry values.
At state creation a set number of stack slots is reserved for the first N LuaRef
types (currently 16), and space for these are also allocated separately
allocated at callback time.  There is a huge breaking change here, which is that
now any LuaRef types MUST only be used with the Lua on which they were created,
and CANNOT be used with any other Lua callback instance.  This mostly will
affect people using LuaRef types from inside a scope callback, but hopefully in
those cases `Function::bind` will be a suitable replacement.  On the plus side,
the rules for LuaRef types are easier to state now.

There is probably more easy-ish perf on the table here, but here's the
preliminary results, based on my very limited benchmarks:

create table            time:   [314.13 ns 315.71 ns 317.44 ns]
                        change: [-36.154% -35.670% -35.205%] (p = 0.00 < 0.05)
create array 10         time:   [2.9731 us 2.9816 us 2.9901 us]
                        change: [-16.996% -16.600% -16.196%] (p = 0.00 < 0.05)
                        Performance has improved.
create string table 10  time:   [5.6904 us 5.7164 us 5.7411 us]
                        change: [-53.536% -53.309% -53.079%] (p = 0.00 < 0.05)
                        Performance has improved.
call add function 3 10  time:   [5.1134 us 5.1222 us 5.1320 us]
                        change: [-4.1095% -3.6910% -3.1781%] (p = 0.00 < 0.05)
                        Performance has improved.
call callback add 2 10  time:   [5.4408 us 5.4480 us 5.4560 us]
                        change: [-6.4203% -5.7780% -5.0013%] (p = 0.00 < 0.05)
                        Performance has improved.
call callback append 10 time:   [9.8243 us 9.8410 us 9.8586 us]
                        change: [-26.937% -26.702% -26.469%] (p = 0.00 < 0.05)
                        Performance has improved.
create registry 10      time:   [3.7005 us 3.7089 us 3.7174 us]
                        change: [-8.4965% -8.1042% -7.6926%] (p = 0.00 < 0.05)
                        Performance has improved.

I think that a lot of these benchmarks are too "easy", and most API usage is
going to be more like the 'create string table 10' benchmark, where there are a
lot of handles and tables and strings, so I think that 25%-50% improvement is a
good guess for most use cases.
2018-03-11 23:20:10 -04:00