Auto strict mode based on optimization level

This commit is contained in:
Aaron Smith 2023-09-20 12:23:51 +01:00
parent 8b4210e66a
commit cc4b390d3d
5 changed files with 31 additions and 28 deletions

View file

@ -1 +1,7 @@
return { strict = false } local function inline_test(): string
return debug.info(1, "n")
end
local is_O2 = inline_test() ~= "inline_test"
return { strict = not is_O2 }

View file

@ -91,9 +91,6 @@ local vide = {
end end
} }
do
local set = false
setmetatable(vide :: any, { setmetatable(vide :: any, {
__index = function(_, index: unknown): () __index = function(_, index: unknown): ()
if index == "strict" then if index == "strict" then
@ -105,14 +102,11 @@ do
__newindex = function(_, index: unknown, value: unknown) __newindex = function(_, index: unknown, value: unknown)
if index == "strict" then if index == "strict" then
if set then throw "strict mode has already been set" end
set = true
flags.strict = value :: boolean flags.strict = value :: boolean
else else
throw(`{tostring(index)} is not a valid member of vide`) throw(`{tostring(index)} is not a valid member of vide`)
end end
end end
}) })
end
return vide return vide

View file

@ -9,6 +9,8 @@ local values = vide.values
local cleanup = vide.cleanup local cleanup = vide.cleanup
local create = vide.create local create = vide.create
assert(not vide.strict)
local function TITLE(name: string) local function TITLE(name: string)
print() print()
print(testkit.color.white(name)) print(testkit.color.white(name))

View file

@ -31,6 +31,8 @@ end
local NIL = nil :: any local NIL = nil :: any
vide.strict = false
TEST("graph", function() TEST("graph", function()
local create_node = graph.create_node local create_node = graph.create_node
local track = graph.track local track = graph.track
@ -1644,6 +1646,8 @@ TEST("changed()", wrap_root(function()
end end
end)) end))
vide.strict = true
TEST("strict", wrap_root(function() TEST("strict", wrap_root(function()
vide.strict = true vide.strict = true

View file

@ -1,16 +1,13 @@
# todo # todo
- auto-enable of strict mode depending on compiler optimizaton level
- property binding optimization - property binding optimization
- would no longer allow `cleanup()` usage in binding scopes - would no longer allow `cleanup()` usage in binding scopes
- solution to nested reactivity, see: SolidJS stores - solution to nested reactivity, see: SolidJS stores
- investigate performance of wide graphs - optimize wide graph updating
- optimize child removal
- implement from solid: - implement from solid:
- Portal - Portal
- batch - batch
- optimize `indexes()` double-diffing - optimize `indexes()` double-diffing
- define behavior of deriving a source within a derived source - define behavior of deriving a source within a derived source
- review destruction of node under a root that has a child in another root - define behavior of node destruction under a root that has a child in another root
- check in strict mode for forgetting to call constructor `create(class)`
- improve crash course, some sections feel like information dumps - improve crash course, some sections feel like information dumps