mirror of
https://github.com/littensy/charm.git
synced 2026-10-22 12:41:37 +00:00
refactor: satisfy new solver
This commit is contained in:
parent
1740a440d2
commit
ee6237c4a2
4 changed files with 25 additions and 24 deletions
|
|
@ -16,7 +16,7 @@ local analyze = process.run({
|
||||||
"--ignore=**/node_modules/**",
|
"--ignore=**/node_modules/**",
|
||||||
"--base-luaurc=.luaurc",
|
"--base-luaurc=.luaurc",
|
||||||
"--definitions=roblox.d.luau",
|
"--definitions=roblox.d.luau",
|
||||||
-- "--flag:LuauSolverV2=true",
|
"--flag:LuauSolverV2=true",
|
||||||
"packages",
|
"packages",
|
||||||
"tests",
|
"tests",
|
||||||
"benches",
|
"benches",
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@
|
||||||
"publish:npm": "pnpm publish -r --access public",
|
"publish:npm": "pnpm publish -r --access public",
|
||||||
"publish:wally": "pnpm -r --workspace-concurrency 1 publish:wally"
|
"publish:wally": "pnpm -r --workspace-concurrency 1 publish:wally"
|
||||||
},
|
},
|
||||||
"packageManager": "pnpm@10.30.2",
|
"packageManager": "pnpm@10.33.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@eslint/js": "^9.39.4",
|
"@eslint/js": "^9.39.4",
|
||||||
"@rbxts/compiler-types": "3.0.0-types.0",
|
"@rbxts/compiler-types": "3.0.0-types.0",
|
||||||
|
|
|
||||||
|
|
@ -92,6 +92,8 @@ local flags = {
|
||||||
trackInnerEffects = true,
|
trackInnerEffects = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local traceback = debug.traceback :: (string?) -> string
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
Wraps a function to prevent yielding when in strict mode. If the function
|
Wraps a function to prevent yielding when in strict mode. If the function
|
||||||
attempts to yield, an error is thrown.
|
attempts to yield, an error is thrown.
|
||||||
|
|
@ -104,14 +106,13 @@ local function noYield<Args..., Results...>(callback: (Args...) -> Results...):
|
||||||
return callback
|
return callback
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local iterator = function(...): { any }
|
||||||
|
return { callback(...) }
|
||||||
|
end
|
||||||
|
|
||||||
return function(...: Args...): Results...
|
return function(...: Args...): Results...
|
||||||
if coroutine.isyieldable() then
|
if coroutine.isyieldable() then
|
||||||
for results in
|
for results in iterator, ... do
|
||||||
function(...)
|
|
||||||
return { callback(...) }
|
|
||||||
end,
|
|
||||||
...
|
|
||||||
do
|
|
||||||
return unpack(results)
|
return unpack(results)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
@ -186,12 +187,12 @@ local function runCleanups(cleanups: { Cleanup })
|
||||||
cleanups[index] = nil
|
cleanups[index] = nil
|
||||||
|
|
||||||
local prevSub = setActiveSub(nil)
|
local prevSub = setActiveSub(nil)
|
||||||
local success, result = xpcall(cleanup :: () -> nil, debug.traceback)
|
local success, err = xpcall(cleanup :: () -> nil, traceback)
|
||||||
activeSub = prevSub
|
activeSub = prevSub
|
||||||
|
|
||||||
if not success then
|
if not success then
|
||||||
hasErrors = true
|
hasErrors = true
|
||||||
table.insert(errors, tostring(result))
|
table.insert(errors, tostring(err))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -224,7 +225,7 @@ local function run(effect: EffectNode)
|
||||||
effect.flags = WATCHING
|
effect.flags = WATCHING
|
||||||
|
|
||||||
local prevSub = setActiveSub(effect)
|
local prevSub = setActiveSub(effect)
|
||||||
local success, result = xpcall(effect.fn, debug.traceback)
|
local success, result = xpcall(effect.fn, traceback)
|
||||||
activeSub = prevSub
|
activeSub = prevSub
|
||||||
|
|
||||||
purgeDeps(effect)
|
purgeDeps(effect)
|
||||||
|
|
@ -254,7 +255,7 @@ local function flush()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local success, result = pcall(function()
|
local success, err = pcall(function()
|
||||||
while notifyIndex < queuedLength do
|
while notifyIndex < queuedLength do
|
||||||
local effect = queued[notifyIndex] :: EffectNode
|
local effect = queued[notifyIndex] :: EffectNode
|
||||||
queued[notifyIndex] = nil
|
queued[notifyIndex] = nil
|
||||||
|
|
@ -275,7 +276,7 @@ local function flush()
|
||||||
queuedLength = 0
|
queuedLength = 0
|
||||||
|
|
||||||
if not success then
|
if not success then
|
||||||
error(result, 0)
|
error(err, 0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -310,7 +311,7 @@ local function updateComputed(computed: ComputedNode): boolean
|
||||||
|
|
||||||
local prevSub = setActiveSub(computed)
|
local prevSub = setActiveSub(computed)
|
||||||
local oldValue = computed.value
|
local oldValue = computed.value
|
||||||
local success, newValue = xpcall(computed.getter, debug.traceback, oldValue)
|
local success, newValue = xpcall(computed.getter, traceback, oldValue)
|
||||||
activeSub = prevSub
|
activeSub = prevSub
|
||||||
|
|
||||||
computed.flags = bit32.band(computed.flags, bit32.bnot(RECURSED_CHECK))
|
computed.flags = bit32.band(computed.flags, bit32.bnot(RECURSED_CHECK))
|
||||||
|
|
@ -472,7 +473,7 @@ local function signal<T>(initialValue: T, equals: Equals<T>?): (Getter<T>, Sette
|
||||||
-- a direct value
|
-- a direct value
|
||||||
if type(newValue) == "function" then
|
if type(newValue) == "function" then
|
||||||
local prevSub = setActiveSub(nil)
|
local prevSub = setActiveSub(nil)
|
||||||
local success, result = xpcall(noYield(newValue), debug.traceback, node.pendingValue)
|
local success, result = xpcall(noYield(newValue), traceback, node.pendingValue)
|
||||||
activeSub = prevSub
|
activeSub = prevSub
|
||||||
|
|
||||||
if success then
|
if success then
|
||||||
|
|
@ -588,7 +589,7 @@ local function computed<T>(getter: (previousValue: T?) -> T): Getter<T>
|
||||||
node.flags = bit32.bor(MUTABLE, RECURSED_CHECK)
|
node.flags = bit32.bor(MUTABLE, RECURSED_CHECK)
|
||||||
|
|
||||||
local prevSub = setActiveSub(node)
|
local prevSub = setActiveSub(node)
|
||||||
local success, result = xpcall(node.getter, debug.traceback)
|
local success, result = xpcall(node.getter, traceback)
|
||||||
activeSub = prevSub
|
activeSub = prevSub
|
||||||
|
|
||||||
node.flags = bit32.band(node.flags, bit32.bnot(RECURSED_CHECK))
|
node.flags = bit32.band(node.flags, bit32.bnot(RECURSED_CHECK))
|
||||||
|
|
@ -641,7 +642,7 @@ local function effect(fn: () -> ...Cleanup?): Cleanup
|
||||||
startBatch()
|
startBatch()
|
||||||
|
|
||||||
local prevSub = setActiveSub(node)
|
local prevSub = setActiveSub(node)
|
||||||
local success, result = xpcall(node.fn, debug.traceback)
|
local success, result = xpcall(node.fn, traceback)
|
||||||
activeSub = prevSub
|
activeSub = prevSub
|
||||||
|
|
||||||
if not success then
|
if not success then
|
||||||
|
|
@ -678,7 +679,7 @@ local function effectScope(fn: () -> ...Cleanup?, detached: boolean?): Cleanup
|
||||||
end
|
end
|
||||||
|
|
||||||
local prevSub = setActiveSub(node)
|
local prevSub = setActiveSub(node)
|
||||||
local success, result = xpcall(noYield(fn), debug.traceback)
|
local success, result = xpcall(noYield(fn), traceback)
|
||||||
activeSub = prevSub
|
activeSub = prevSub
|
||||||
|
|
||||||
if not success then
|
if not success then
|
||||||
|
|
@ -705,11 +706,11 @@ local function trigger(fn: () -> ...any)
|
||||||
}
|
}
|
||||||
|
|
||||||
local prevSub = setActiveSub(sub)
|
local prevSub = setActiveSub(sub)
|
||||||
local success, result = xpcall(noYield(fn), debug.traceback)
|
local success, err = xpcall(noYield(fn), traceback)
|
||||||
activeSub = prevSub
|
activeSub = prevSub
|
||||||
|
|
||||||
if not success then
|
if not success then
|
||||||
error(result, 2)
|
error(err, 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
local currentLink = sub.deps
|
local currentLink = sub.deps
|
||||||
|
|
@ -760,7 +761,7 @@ end
|
||||||
local function untracked<Args..., Results...>(fn: (Args...) -> Results..., ...: Args...): Results...
|
local function untracked<Args..., Results...>(fn: (Args...) -> Results..., ...: Args...): Results...
|
||||||
if activeSub then
|
if activeSub then
|
||||||
local prevSub = setActiveSub(nil)
|
local prevSub = setActiveSub(nil)
|
||||||
local results: { any } = { xpcall(noYield(fn), debug.traceback, ...) }
|
local results: { any } = { xpcall(noYield(fn), traceback, ...) }
|
||||||
activeSub = prevSub
|
activeSub = prevSub
|
||||||
|
|
||||||
if not results[1] then
|
if not results[1] then
|
||||||
|
|
@ -784,7 +785,7 @@ end
|
||||||
]]
|
]]
|
||||||
local function batch<Args..., Results...>(fn: (Args...) -> Results..., ...: Args...): Results...
|
local function batch<Args..., Results...>(fn: (Args...) -> Results..., ...: Args...): Results...
|
||||||
startBatch()
|
startBatch()
|
||||||
local results: { any } = { xpcall(noYield(fn), debug.traceback, ...) }
|
local results: { any } = { xpcall(noYield(fn), traceback, ...) }
|
||||||
endBatch()
|
endBatch()
|
||||||
|
|
||||||
if not results[1] then
|
if not results[1] then
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
[tools]
|
[tools]
|
||||||
wally = "UpliftGames/wally@0.3.2"
|
wally = "UpliftGames/wally@0.3.2"
|
||||||
rojo = "rojo-rbx/rojo@7.6.1"
|
rojo = "rojo-rbx/rojo@7.6.1"
|
||||||
stylua = "johnnymorganz/stylua@2.4.0"
|
stylua = "johnnymorganz/stylua@2.4.1"
|
||||||
selene = "Kampfkarren/selene@0.30.1"
|
selene = "Kampfkarren/selene@0.30.1"
|
||||||
luau-lsp = "johnnymorganz/luau-lsp@1.64.0"
|
luau-lsp = "johnnymorganz/luau-lsp@1.66.0"
|
||||||
lute = "luau-lang/lute@0.1.0-nightly.20260331"
|
lute = "luau-lang/lute@0.1.0-nightly.20260331"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue