Repository navigation
Fix 15 SharpTS runtime and checker regressions #3625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
d656511
7962f7e
979ed2f
250f40e
5bd74a1
0b003dd
474a3b8
65dea17
efc9e76
3654d70
0153d6f
8c19e99
cc7b0ae
cba760f
f0a2f9b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,14 +22,11 @@ protected bool TryEmitEnumVariable(string name) | |
| return true; | ||
| } | ||
|
|
||
| private FieldBuilder? _enumInitializerField; | ||
| private Action? _loadEnumInitializerObject; | ||
| private HashSet<string>? _enumInitializerMembers; | ||
|
|
||
| protected void EmitEnumDeclaration(Stmt.Enum declaration) | ||
| protected void EmitStaticEnumDeclaration(Stmt.Enum declaration) | ||
| { | ||
| if (declaration is { IsAmbient: true, IsConst: false }) | ||
| return; | ||
|
|
||
| if (Ctx.EnumValueFields == null || !Ctx.EnumValueFields.TryGetValue(Ctx.ResolveEnumName(declaration.Name.Lexeme), out var field)) | ||
| return; | ||
|
|
||
|
|
@@ -42,9 +39,21 @@ protected void EmitEnumDeclaration(Stmt.Enum declaration) | |
| IL.Emit(OpCodes.Stsfld, field); | ||
| IL.MarkLabel(initialized); | ||
|
|
||
| var previousField = _enumInitializerField; | ||
| EmitEnumMembers(declaration, () => IL.Emit(OpCodes.Ldsfld, field)); | ||
| if (Ctx.CurrentModulePath is { } modulePath && | ||
| Ctx.ModuleExportFields?.TryGetValue(modulePath, out var exports) == true && | ||
| exports.TryGetValue(declaration.Name.Lexeme, out var exportField)) | ||
| { | ||
| IL.Emit(OpCodes.Ldsfld, field); | ||
| IL.Emit(OpCodes.Stsfld, exportField); | ||
|
Comment on lines
+43
to
+48
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| } | ||
| } | ||
|
|
||
| protected void EmitEnumMembers(Stmt.Enum declaration, Action loadObject) | ||
| { | ||
| var previousLoadObject = _loadEnumInitializerObject; | ||
| var previousMembers = _enumInitializerMembers; | ||
| _enumInitializerField = field; | ||
| _loadEnumInitializerObject = loadObject; | ||
| _enumInitializerMembers = []; | ||
| var value = IL.DeclareLocal(Types.Object); | ||
| bool firstMember = true; | ||
|
|
@@ -69,7 +78,7 @@ protected void EmitEnumDeclaration(Stmt.Enum declaration) | |
| IL.Emit(OpCodes.Box, Types.Double); | ||
| } | ||
| IL.Emit(OpCodes.Stloc, value); | ||
| IL.Emit(OpCodes.Ldsfld, field); | ||
| loadObject(); | ||
| IL.Emit(OpCodes.Ldstr, member.Name.Lexeme); | ||
| IL.Emit(OpCodes.Ldloc, value); | ||
| IL.Emit(OpCodes.Call, Ctx.Runtime!.ObjectWrite.Property); | ||
|
|
@@ -78,7 +87,7 @@ protected void EmitEnumDeclaration(Stmt.Enum declaration) | |
| // also install the reverse entry, overwriting earlier duplicate values. | ||
| if (member.Value is not Expr.Literal { Value: string }) | ||
| { | ||
| IL.Emit(OpCodes.Ldsfld, field); | ||
| loadObject(); | ||
| IL.Emit(OpCodes.Ldloc, value); | ||
| IL.Emit(OpCodes.Call, Ctx.Runtime.StringCoercion.ToJsString); | ||
| IL.Emit(OpCodes.Ldstr, member.Name.Lexeme); | ||
|
|
@@ -87,23 +96,16 @@ protected void EmitEnumDeclaration(Stmt.Enum declaration) | |
| _enumInitializerMembers.Add(member.Name.Lexeme); | ||
| firstMember = false; | ||
| } | ||
| _enumInitializerField = previousField; | ||
| _loadEnumInitializerObject = previousLoadObject; | ||
| _enumInitializerMembers = previousMembers; | ||
| if (Ctx.CurrentModulePath is { } modulePath && | ||
| Ctx.ModuleExportFields?.TryGetValue(modulePath, out var exports) == true && | ||
| exports.TryGetValue(declaration.Name.Lexeme, out var exportField)) | ||
| { | ||
| IL.Emit(OpCodes.Ldsfld, field); | ||
| IL.Emit(OpCodes.Stsfld, exportField); | ||
| } | ||
| SetStackUnknown(); | ||
| } | ||
|
|
||
| protected bool TryEmitEnumInitializerMember(string name) | ||
| { | ||
| if (_enumInitializerField == null || _enumInitializerMembers?.Contains(name) != true) | ||
| if (_loadEnumInitializerObject == null || _enumInitializerMembers?.Contains(name) != true) | ||
| return false; | ||
| IL.Emit(OpCodes.Ldsfld, _enumInitializerField); | ||
| _loadEnumInitializerObject(); | ||
| IL.Emit(OpCodes.Ldstr, name); | ||
| IL.Emit(OpCodes.Call, Ctx.Runtime!.ObjectRead.Property); | ||
| SetStackUnknown(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Script executed:
Repository: nickna/SharpTS
Length of output: 11146
Script executed:
Repository: nickna/SharpTS
Length of output: 19430
Script executed:
Repository: nickna/SharpTS
Length of output: 42081
Script executed:
Repository: nickna/SharpTS
Length of output: 42633
Script executed:
Repository: nickna/SharpTS
Length of output: 28320
Script executed:
Repository: nickna/SharpTS
Length of output: 25924
Script executed:
Repository: nickna/SharpTS
Length of output: 20714
Script executed:
Repository: nickna/SharpTS
Length of output: 24895
Script executed:
Repository: nickna/SharpTS
Length of output: 19594
Preserve local enums across async-arrow suspension.
When an async arrow declares an enum before an
await, the arrow analysis omits the binding. The compiled enum remains an IL local, so a resumedE.Aread can fail instead of returning the member value. Add enum bindings to the async-arrow persistence analysis.