Skip to content

Commit 425cd57

Browse files
committed
Drop script slot analysis opt-out
1 parent 7fa952a commit 425cd57

6 files changed

Lines changed: 13 additions & 40 deletions

File tree

src/Asynkron.JsEngine/Ast/Legacy/StatementNodeExtensions.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,13 +2180,12 @@ private static JsValue EvaluateProgramJsValueCore(ProgramNode program, JsEnviron
21802180
program.IsStrict ? ScopeMode.Strict : ScopeMode.Sloppy,
21812181
cancellationToken,
21822182
executionKind);
2183-
// For eval, always disable identifier caching/slot analysis because eval runs in the caller's
2183+
// For eval, always disable identifier caching because eval runs in the caller's
21842184
// lexical environment which may contain 'with' statements or allow deletable bindings.
21852185
// The static analysis of the eval code alone doesn't tell us about the outer context.
2186-
var allowScriptSlotAnalysis = context.RealmState.Options.AllowScriptSlotAnalysis &&
2187-
executionKind != ExecutionKind.Eval;
2186+
var allowIdentifierCache = executionKind != ExecutionKind.Eval;
21882187
var allowsIdentifierCaching = AllowsIdentifierCaching(program);
2189-
context.AllowIdentifierCache = allowScriptSlotAnalysis &&
2188+
context.AllowIdentifierCache = allowIdentifierCache &&
21902189
allowsIdentifierCaching;
21912190
context.DrainAwaitMicrotasks = drainAwaitMicrotasks;
21922191
if (inheritedPrivateNameScopes is { IsDefault: false, Length: > 0 } scopes)
@@ -2352,7 +2351,7 @@ trueGlobalEnvironment is not null &&
23522351
var canUseIrPlan = context.AllowIdentifierCache || canUseNoSlotIr;
23532352
ScriptPlanCache? scriptPlanCache = null;
23542353
ExecutionPlan? scriptPlan = null;
2355-
var enableScriptSlots = allowScriptSlotAnalysis && context.AllowIdentifierCache;
2354+
var enableScriptSlots = context.AllowIdentifierCache;
23562355
if (canUseIrPlan)
23572356
{
23582357
scriptPlanCache = ((IAstCacheable<ScriptPlanCache>)program).GetOrCreateCache();
@@ -2441,7 +2440,7 @@ trueGlobalEnvironment is not null &&
24412440

24422441
if (!canUseIrPlan)
24432442
{
2444-
const string failureReason = "script slot analysis disabled for non-dynamic script execution";
2443+
const string failureReason = "identifier caching is unavailable for non-dynamic script execution";
24452444
context.RealmState.Logger?.LogInformation(
24462445
"Rejecting non-dynamic script because IR script plan is unavailable: {FailureReason}",
24472446
failureReason);

src/Asynkron.JsEngine/IJsEngineOptions.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,6 @@ public interface IJsEngineOptions
3131
/// </summary>
3232
bool DebugMode { get; }
3333

34-
/// <summary>
35-
/// Enables script-level slot analysis and identifier caching when it is safe to do so
36-
/// (no direct eval/with). Defaults to false for safety.
37-
/// </summary>
38-
bool AllowScriptSlotAnalysis { get; }
39-
4034
/// <summary>
4135
/// Optional logger used for realm-level diagnostics such as identifier slot hit/miss tracing.
4236
/// </summary>

src/Asynkron.JsEngine/JsEngineOptions.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ public sealed class JsEngineOptions : IJsEngineOptions
1919
public TimeZoneInfo TimeZone { get; init; } = TimeZoneInfo.Utc;
2020
public bool AllowImportMeta { get; init; } = true;
2121
public bool DebugMode { get; init; }
22-
public bool AllowScriptSlotAnalysis { get; init; } = true;
2322

2423
/// <summary>
2524
/// Optional logger to receive realm traces and diagnostics.

tests/Asynkron.JsEngine.Tests.Test262/Test262Test.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,11 @@ internal static JsEngine CreateTest262Engine(ILogger? logger, bool debugMode, bo
200200
? BaseRealmSnapshot.Instance.Value.CreateEngine(new JsEngineOptions
201201
{
202202
Logger = logger,
203-
AllowScriptSlotAnalysis = true,
204203
DebugMode = debugMode,
205204
})
206205
: new JsEngine(new JsEngineOptions
207206
{
208207
Logger = logger,
209-
AllowScriptSlotAnalysis = true,
210208
DebugMode = debugMode,
211209
});
212210

tests/Asynkron.JsEngine.Tests/DynamicFunctionClassTestBomb.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,14 @@ public async Task H1_TopLevelScript_DefaultEngine()
4646
AssertBrandCheckResult(result);
4747
}
4848

49-
/// H2: The exact top-level script should also work when script slot analysis is enabled.
49+
/// H2: The exact top-level script should also work when debug diagnostics are enabled.
5050
[Fact(Timeout = 10000)]
51-
public async Task H2_TopLevelScript_WithScriptSlotAnalysis()
51+
public async Task H2_TopLevelScript_WithDebugDiagnostics()
5252
{
5353
await using var engine = CreateEngine(() => new JsEngineOptions
5454
{
5555
Logger = CurrentLogger,
5656
DebugMode = true,
57-
AllowScriptSlotAnalysis = true,
5857
});
5958

6059
var result = await engine.Evaluate(PrivateMethodClassSource);

tests/Asynkron.JsEngine.Tests/ScriptSlotAnalysisTests.cs

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,19 @@ public ScriptSlotAnalysisTests(ITestOutputHelper output) : base(output)
1111
}
1212

1313
[Fact]
14-
public async Task ScriptSlotAnalysisToggle_ProducesSameResult()
14+
public async Task ScriptSlotAnalysis_SimpleScriptUsesIrByDefault()
1515
{
1616
const string script = """
1717
let a = 1;
1818
let b = 2;
1919
a + b;
2020
""";
2121

22-
await using var engineNoSlots = CreateEngine(() => new JsEngineOptions
23-
{
24-
AllowScriptSlotAnalysis = false
25-
});
26-
await using var engineWithSlots = CreateEngine(() => new JsEngineOptions
27-
{
28-
AllowScriptSlotAnalysis = true
29-
});
22+
await using var engine = CreateEngine();
3023

31-
await Assert.ThrowsAsync<NotSupportedException>(async () => await engineNoSlots.Evaluate(script));
32-
var resultWith = await engineWithSlots.Evaluate(script);
24+
var result = await engine.Evaluate(script);
3325

34-
Assert.Equal(3d, resultWith);
26+
Assert.Equal(3d, result);
3527
}
3628

3729
[Fact]
@@ -46,7 +38,6 @@ public async Task ScriptSlotAnalysis_DirectEvalWithoutCapturedWith_UsesIrPath()
4638

4739
await using var engine = CreateEngine(() => new JsEngineOptions
4840
{
49-
AllowScriptSlotAnalysis = true,
5041
DebugMode = true,
5142
Logger = logger
5243
});
@@ -61,7 +52,7 @@ static record => record.Message.Contains(
6152
}
6253

6354
[Fact]
64-
public async Task ScriptSlotAnalysis_DisabledWhenWithIsPresent()
55+
public async Task ScriptSlotAnalysis_WithStatementUsesNoSlotIrPath()
6556
{
6657
const string script = """
6758
var obj = { value: 7 };
@@ -72,10 +63,7 @@ public async Task ScriptSlotAnalysis_DisabledWhenWithIsPresent()
7263
result;
7364
""";
7465

75-
await using var engine = CreateEngine(() => new JsEngineOptions
76-
{
77-
AllowScriptSlotAnalysis = true
78-
});
66+
await using var engine = CreateEngine();
7967

8068
var result = await engine.Evaluate(script);
8169
Assert.Equal(7d, result);
@@ -96,7 +84,6 @@ public async Task ScriptSlotAnalysis_TopLevelWithWithoutCapturedWith_UsesIrPath(
9684

9785
await using var engine = CreateEngine(() => new JsEngineOptions
9886
{
99-
AllowScriptSlotAnalysis = true,
10087
DebugMode = true,
10188
Logger = logger
10289
});
@@ -122,7 +109,6 @@ public async Task ScriptSlotAnalysis_EvalWithWithoutCapturedWith_UsesIrPath()
122109

123110
await using var engine = CreateEngine(() => new JsEngineOptions
124111
{
125-
AllowScriptSlotAnalysis = true,
126112
DebugMode = true,
127113
Logger = logger
128114
});
@@ -150,7 +136,6 @@ public async Task ScriptSlotAnalysis_DirectEvalInsideWithWithoutCapturedClosure_
150136

151137
await using var engine = CreateEngine(() => new JsEngineOptions
152138
{
153-
AllowScriptSlotAnalysis = true,
154139
DebugMode = true,
155140
Logger = logger
156141
});
@@ -178,7 +163,6 @@ public async Task ScriptSlotAnalysis_DirectEvalVarDeclarationInsideWithWithoutCa
178163

179164
await using var engine = CreateEngine(() => new JsEngineOptions
180165
{
181-
AllowScriptSlotAnalysis = true,
182166
DebugMode = true,
183167
Logger = logger
184168
});

0 commit comments

Comments
 (0)