@tracecode/harness 0.6.6 → 0.7.0-beta7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/README.md +134 -15
- package/THIRD_PARTY_NOTICES.md +170 -0
- package/dist/browser.cjs +2361 -1033
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +33 -3
- package/dist/browser.d.ts +33 -3
- package/dist/browser.js +2357 -1033
- package/dist/browser.js.map +1 -1
- package/dist/cli.cjs +160 -23
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +161 -24
- package/dist/cli.js.map +1 -1
- package/dist/core.cjs +748 -867
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +21 -85
- package/dist/core.d.ts +21 -85
- package/dist/core.js +734 -855
- package/dist/core.js.map +1 -1
- package/dist/cpp-worker-client-Bn7kC0_L.d.ts +84 -0
- package/dist/cpp-worker-client-BzdJLuZa.d.cts +84 -0
- package/dist/cpp.cjs +1063 -0
- package/dist/cpp.cjs.map +1 -0
- package/dist/cpp.d.cts +7 -0
- package/dist/cpp.d.ts +7 -0
- package/dist/cpp.js +1035 -0
- package/dist/cpp.js.map +1 -0
- package/dist/csharp-worker-client-DMHIa2YG.d.cts +69 -0
- package/dist/csharp-worker-client-JwqS6LiX.d.ts +69 -0
- package/dist/csharp.cjs +1012 -0
- package/dist/csharp.cjs.map +1 -0
- package/dist/csharp.d.cts +7 -0
- package/dist/csharp.d.ts +7 -0
- package/dist/csharp.js +984 -0
- package/dist/csharp.js.map +1 -0
- package/dist/index.cjs +3142 -1160
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +13 -5
- package/dist/index.d.ts +13 -5
- package/dist/index.js +3117 -1148
- package/dist/index.js.map +1 -1
- package/dist/internal/browser.cjs +1639 -30
- package/dist/internal/browser.cjs.map +1 -1
- package/dist/internal/browser.d.cts +6 -199
- package/dist/internal/browser.d.ts +6 -199
- package/dist/internal/browser.js +1636 -30
- package/dist/internal/browser.js.map +1 -1
- package/dist/java-worker-client-BOwKW-11.d.cts +72 -0
- package/dist/java-worker-client-C97DDnCp.d.ts +72 -0
- package/dist/java.cjs +1225 -0
- package/dist/java.cjs.map +1 -0
- package/dist/java.d.cts +7 -0
- package/dist/java.d.ts +7 -0
- package/dist/java.js +1197 -0
- package/dist/java.js.map +1 -0
- package/dist/javascript-worker-client-CYBGEEvc.d.cts +51 -0
- package/dist/javascript-worker-client-DIX1Mp21.d.ts +51 -0
- package/dist/javascript.cjs +1063 -19
- package/dist/javascript.cjs.map +1 -1
- package/dist/javascript.d.cts +7 -4
- package/dist/javascript.d.ts +7 -4
- package/dist/javascript.js +1061 -19
- package/dist/javascript.js.map +1 -1
- package/dist/pyodide-worker-client-C-2rfHj9.d.ts +111 -0
- package/dist/pyodide-worker-client-Cn0a8Uv3.d.cts +111 -0
- package/dist/python.cjs +1282 -74
- package/dist/python.cjs.map +1 -1
- package/dist/python.d.cts +20 -14
- package/dist/python.d.ts +20 -14
- package/dist/python.js +1279 -74
- package/dist/python.js.map +1 -1
- package/dist/runtime-language-info-BFUSti3-.d.ts +43 -0
- package/dist/runtime-language-info-Bxza1cI2.d.cts +43 -0
- package/dist/runtime-types-2qM0MukN.d.cts +244 -0
- package/dist/runtime-types-2qM0MukN.d.ts +244 -0
- package/package.json +73 -8
- package/workers/cpp/cpp-compiler-frame.html +82 -0
- package/workers/cpp/cpp-compiler-worker.js +131 -0
- package/workers/cpp/cpp-worker.js +5790 -0
- package/workers/cpp/tracecode_runtime.hpp +6147 -0
- package/workers/csharp/csharp-worker.js +301 -0
- package/workers/java/.build/classes/harness/browser/JavaRewriteLibrary.class +0 -0
- package/workers/java/java-source-augmentations.js +880 -0
- package/workers/java/java-worker.js +2149 -178
- package/workers/java/src/harness/browser/JavaRewriteLibrary.java +1645 -32
- package/workers/java/src/javafx/util/Pair.java +42 -0
- package/workers/java/src/tracecode/browser/BrowserCompileAndTraceLibrary.java +714 -0
- package/workers/java/src/tracecode/browser/BrowserCompileAndTraceMain.java +76 -0
- package/workers/java/src/tracecode/browser/RuntimeProbeMain.java +14 -0
- package/workers/java/src/tracecode/user/TraceHooks.java +1406 -0
- package/workers/javascript/javascript-libraries-entry.js +71 -0
- package/workers/javascript/javascript-worker.js +2054 -424
- package/workers/python/generated-python-harness-snippets.js +4 -4
- package/workers/python/pyodide-worker.js +222 -61
- package/workers/python/runtime-core.js +1387 -301
- package/workers/vendor/csharp/.stamp +0 -0
- package/workers/vendor/csharp/TraceCode.CSharpHost.runtimeconfig.json +32 -0
- package/workers/vendor/csharp/_framework/Microsoft.CSharp.wasm +0 -0
- package/workers/vendor/csharp/_framework/Microsoft.CodeAnalysis.CSharp.wasm +0 -0
- package/workers/vendor/csharp/_framework/Microsoft.CodeAnalysis.wasm +0 -0
- package/workers/vendor/csharp/_framework/Microsoft.VisualBasic.Core.wasm +0 -0
- package/workers/vendor/csharp/_framework/Microsoft.VisualBasic.wasm +0 -0
- package/workers/vendor/csharp/_framework/Microsoft.Win32.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/Microsoft.Win32.Registry.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.AppContext.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Buffers.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Collections.Concurrent.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Collections.Immutable.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Collections.NonGeneric.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Collections.Specialized.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Collections.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ComponentModel.Annotations.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ComponentModel.DataAnnotations.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ComponentModel.EventBasedAsync.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ComponentModel.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ComponentModel.TypeConverter.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ComponentModel.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Configuration.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Console.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Core.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Data.Common.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Data.DataSetExtensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Data.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.Contracts.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.Debug.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.DiagnosticSource.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.FileVersionInfo.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.Process.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.StackTrace.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.TextWriterTraceListener.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.Tools.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.TraceSource.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Diagnostics.Tracing.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Drawing.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Drawing.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Dynamic.Runtime.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Formats.Asn1.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Formats.Tar.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Globalization.Calendars.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Globalization.Extensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Globalization.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Compression.Brotli.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Compression.FileSystem.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Compression.ZipFile.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Compression.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.FileSystem.AccessControl.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.FileSystem.DriveInfo.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.FileSystem.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.FileSystem.Watcher.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.FileSystem.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.IsolatedStorage.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.MemoryMappedFiles.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Pipelines.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Pipes.AccessControl.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.Pipes.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.UnmanagedMemoryStream.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.IO.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Linq.AsyncEnumerable.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Linq.Expressions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Linq.Parallel.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Linq.Queryable.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Linq.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Memory.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Http.Json.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Http.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.HttpListener.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Mail.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.NameResolution.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.NetworkInformation.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Ping.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Quic.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Requests.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Security.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.ServerSentEvents.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.ServicePoint.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.Sockets.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.WebClient.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.WebHeaderCollection.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.WebProxy.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.WebSockets.Client.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.WebSockets.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Net.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Numerics.Vectors.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Numerics.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ObjectModel.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Private.CoreLib.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Private.DataContractSerialization.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Private.Uri.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Private.Xml.Linq.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Private.Xml.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.DispatchProxy.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.Emit.ILGeneration.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.Emit.Lightweight.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.Emit.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.Extensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.Metadata.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.TypeExtensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Reflection.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Resources.Reader.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Resources.ResourceManager.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Resources.Writer.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.CompilerServices.Unsafe.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.CompilerServices.VisualC.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Extensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Handles.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.InteropServices.JavaScript.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.InteropServices.RuntimeInformation.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.InteropServices.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Intrinsics.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Loader.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Numerics.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Serialization.Formatters.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Serialization.Json.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Serialization.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Serialization.Xml.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.Serialization.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Runtime.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.AccessControl.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Claims.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.Algorithms.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.Cng.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.Csp.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.Encoding.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.OpenSsl.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.Primitives.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.X509Certificates.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Cryptography.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Principal.Windows.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.Principal.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.SecureString.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Security.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ServiceModel.Web.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ServiceProcess.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Text.Encoding.CodePages.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Text.Encoding.Extensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Text.Encoding.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Text.Encodings.Web.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Text.Json.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Text.RegularExpressions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.AccessControl.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Channels.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Overlapped.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Tasks.Dataflow.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Tasks.Extensions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Tasks.Parallel.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Tasks.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Thread.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.ThreadPool.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.Timer.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Threading.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Transactions.Local.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Transactions.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.ValueTuple.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Web.HttpUtility.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Web.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Windows.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.Linq.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.ReaderWriter.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.Serialization.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.XDocument.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.XPath.XDocument.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.XPath.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.XmlDocument.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.XmlSerializer.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.Xml.wasm +0 -0
- package/workers/vendor/csharp/_framework/System.wasm +0 -0
- package/workers/vendor/csharp/_framework/TraceCode.CSharpHost.wasm +0 -0
- package/workers/vendor/csharp/_framework/WindowsBase.wasm +0 -0
- package/workers/vendor/csharp/_framework/cs/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/cs/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/de/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/de/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/dotnet.boot.js +1958 -0
- package/workers/vendor/csharp/_framework/dotnet.js +4 -0
- package/workers/vendor/csharp/_framework/dotnet.js.map +1 -0
- package/workers/vendor/csharp/_framework/dotnet.native.js +6687 -0
- package/workers/vendor/csharp/_framework/dotnet.native.wasm +0 -0
- package/workers/vendor/csharp/_framework/dotnet.runtime.js +4 -0
- package/workers/vendor/csharp/_framework/dotnet.runtime.js.map +1 -0
- package/workers/vendor/csharp/_framework/es/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/es/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/fr/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/fr/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/it/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/it/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/ja/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/ja/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/ko/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/ko/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/mscorlib.wasm +0 -0
- package/workers/vendor/csharp/_framework/netstandard.wasm +0 -0
- package/workers/vendor/csharp/_framework/pl/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/pl/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/pt-BR/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/pt-BR/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/ru/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/ru/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/0_Microsoft.CodeAnalysis.CSharp.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/100_System.Reflection.Emit.ILGeneration.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/101_System.Reflection.Emit.Lightweight.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/102_System.Reflection.Extensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/103_System.Reflection.Metadata.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/104_System.Reflection.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/105_System.Reflection.TypeExtensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/106_System.Resources.Reader.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/107_System.Resources.ResourceManager.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/108_System.Resources.Writer.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/109_System.Runtime.CompilerServices.Unsafe.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/10_System.Buffers.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/110_System.Runtime.CompilerServices.VisualC.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/111_System.Runtime.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/112_System.Runtime.Extensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/113_System.Runtime.Handles.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/114_System.Runtime.InteropServices.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/115_System.Runtime.InteropServices.JavaScript.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/116_System.Runtime.InteropServices.RuntimeInformation.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/117_System.Runtime.Intrinsics.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/118_System.Runtime.Loader.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/119_System.Runtime.Numerics.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/11_System.Collections.Concurrent.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/120_System.Runtime.Serialization.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/121_System.Runtime.Serialization.Formatters.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/122_System.Runtime.Serialization.Json.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/123_System.Runtime.Serialization.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/124_System.Runtime.Serialization.Xml.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/125_System.Security.AccessControl.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/126_System.Security.Claims.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/127_System.Security.Cryptography.Algorithms.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/128_System.Security.Cryptography.Cng.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/129_System.Security.Cryptography.Csp.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/12_System.Collections.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/130_System.Security.Cryptography.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/131_System.Security.Cryptography.Encoding.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/132_System.Security.Cryptography.OpenSsl.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/133_System.Security.Cryptography.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/134_System.Security.Cryptography.X509Certificates.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/135_System.Security.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/136_System.Security.Principal.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/137_System.Security.Principal.Windows.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/138_System.Security.SecureString.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/139_System.ServiceModel.Web.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/13_System.Collections.Immutable.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/140_System.ServiceProcess.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/141_System.Text.Encoding.CodePages.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/142_System.Text.Encoding.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/143_System.Text.Encoding.Extensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/144_System.Text.Encodings.Web.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/145_System.Text.Json.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/146_System.Text.RegularExpressions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/147_System.Threading.AccessControl.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/148_System.Threading.Channels.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/149_System.Threading.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/14_System.Collections.NonGeneric.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/150_System.Threading.Overlapped.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/151_System.Threading.Tasks.Dataflow.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/152_System.Threading.Tasks.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/153_System.Threading.Tasks.Extensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/154_System.Threading.Tasks.Parallel.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/155_System.Threading.Thread.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/156_System.Threading.ThreadPool.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/157_System.Threading.Timer.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/158_System.Transactions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/159_System.Transactions.Local.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/15_System.Collections.Specialized.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/160_System.ValueTuple.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/161_System.Web.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/162_System.Web.HttpUtility.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/163_System.Windows.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/164_System.Xml.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/165_System.Xml.Linq.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/166_System.Xml.ReaderWriter.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/167_System.Xml.Serialization.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/168_System.Xml.XDocument.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/169_System.Xml.XmlDocument.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/16_System.ComponentModel.Annotations.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/170_System.Xml.XmlSerializer.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/171_System.Xml.XPath.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/172_System.Xml.XPath.XDocument.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/173_TraceCode.CSharpHost.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/174_WindowsBase.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/17_System.ComponentModel.DataAnnotations.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/18_System.ComponentModel.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/19_System.ComponentModel.EventBasedAsync.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/1_Microsoft.CodeAnalysis.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/20_System.ComponentModel.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/21_System.ComponentModel.TypeConverter.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/22_System.Configuration.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/23_System.Console.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/24_System.Core.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/25_System.Data.Common.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/26_System.Data.DataSetExtensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/27_System.Data.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/28_System.Diagnostics.Contracts.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/29_System.Diagnostics.Debug.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/2_Microsoft.CSharp.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/30_System.Diagnostics.DiagnosticSource.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/31_System.Diagnostics.FileVersionInfo.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/32_System.Diagnostics.Process.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/33_System.Diagnostics.StackTrace.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/34_System.Diagnostics.TextWriterTraceListener.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/35_System.Diagnostics.Tools.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/36_System.Diagnostics.TraceSource.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/37_System.Diagnostics.Tracing.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/38_System.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/39_System.Drawing.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/3_Microsoft.VisualBasic.Core.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/40_System.Drawing.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/41_System.Dynamic.Runtime.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/42_System.Formats.Asn1.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/43_System.Formats.Tar.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/44_System.Globalization.Calendars.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/45_System.Globalization.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/46_System.Globalization.Extensions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/47_System.IO.Compression.Brotli.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/48_System.IO.Compression.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/49_System.IO.Compression.FileSystem.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/4_Microsoft.VisualBasic.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/50_System.IO.Compression.ZipFile.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/51_System.IO.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/52_System.IO.FileSystem.AccessControl.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/53_System.IO.FileSystem.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/54_System.IO.FileSystem.DriveInfo.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/55_System.IO.FileSystem.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/56_System.IO.FileSystem.Watcher.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/57_System.IO.IsolatedStorage.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/58_System.IO.MemoryMappedFiles.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/59_System.IO.Pipelines.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/5_Microsoft.Win32.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/60_System.IO.Pipes.AccessControl.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/61_System.IO.Pipes.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/62_System.IO.UnmanagedMemoryStream.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/63_System.Linq.AsyncEnumerable.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/64_System.Linq.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/65_System.Linq.Expressions.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/66_System.Linq.Parallel.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/67_System.Linq.Queryable.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/68_System.Memory.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/69_System.Net.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/6_Microsoft.Win32.Registry.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/70_System.Net.Http.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/71_System.Net.Http.Json.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/72_System.Net.HttpListener.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/73_System.Net.Mail.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/74_System.Net.NameResolution.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/75_System.Net.NetworkInformation.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/76_System.Net.Ping.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/77_System.Net.Primitives.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/78_System.Net.Quic.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/79_System.Net.Requests.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/7_mscorlib.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/80_System.Net.Security.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/81_System.Net.ServerSentEvents.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/82_System.Net.ServicePoint.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/83_System.Net.Sockets.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/84_System.Net.WebClient.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/85_System.Net.WebHeaderCollection.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/86_System.Net.WebProxy.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/87_System.Net.WebSockets.Client.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/88_System.Net.WebSockets.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/89_System.Numerics.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/8_netstandard.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/90_System.Numerics.Vectors.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/91_System.ObjectModel.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/92_System.Private.CoreLib.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/93_System.Private.DataContractSerialization.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/94_System.Private.Uri.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/95_System.Private.Xml.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/96_System.Private.Xml.Linq.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/97_System.Reflection.DispatchProxy.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/98_System.Reflection.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/99_System.Reflection.Emit.dll +0 -0
- package/workers/vendor/csharp/_framework/supportFiles/9_System.AppContext.dll +0 -0
- package/workers/vendor/csharp/_framework/tr/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/tr/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/zh-Hans/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/zh-Hans/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/zh-Hant/Microsoft.CodeAnalysis.CSharp.resources.wasm +0 -0
- package/workers/vendor/csharp/_framework/zh-Hant/Microsoft.CodeAnalysis.resources.wasm +0 -0
- package/workers/vendor/csharp/main.mjs +5 -0
- package/workers/vendor/csharp/package.json +1 -0
- package/workers/vendor/java-browser-helper.jar +0 -0
- package/workers/vendor/java-rewriter.jar +0 -0
- package/workers/vendor/javascript-libraries.js +10106 -0
- package/dist/runtime-types-89nchXlY.d.cts +0 -89
- package/dist/runtime-types-CCQ-ZLc9.d.ts +0 -89
- package/dist/types-zyvpJKCi.d.cts +0 -100
- package/dist/types-zyvpJKCi.d.ts +0 -100
- package/workers/java/java-source-augmentations.cjs +0 -242
- package/workers/java/src/spike/user/TraceHooks.java +0 -619
- package/workers/vendor/java-browser-spike-helper.jar +0 -0
- package/workers/vendor/java-practice-rewriter.jar +0 -0
- package/workers/vendor/java-rewrite-bridge.jar +0 -0
|
@@ -6,6 +6,29 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
(function initPyodideRuntimeCore(globalScope) {
|
|
9
|
+
const PYTHON_DEFAULT_IMPORT_PRELUDE = `
|
|
10
|
+
import array
|
|
11
|
+
from array import array
|
|
12
|
+
import bisect
|
|
13
|
+
from bisect import *
|
|
14
|
+
import collections
|
|
15
|
+
from collections import *
|
|
16
|
+
import functools
|
|
17
|
+
from functools import *
|
|
18
|
+
import heapq
|
|
19
|
+
from heapq import *
|
|
20
|
+
import itertools
|
|
21
|
+
from itertools import *
|
|
22
|
+
import operator
|
|
23
|
+
from operator import *
|
|
24
|
+
import re
|
|
25
|
+
import string
|
|
26
|
+
try:
|
|
27
|
+
from sortedcontainers import SortedDict, SortedList, SortedSet
|
|
28
|
+
except Exception:
|
|
29
|
+
pass
|
|
30
|
+
`;
|
|
31
|
+
|
|
9
32
|
function generateTracingCode(deps, userCode, functionName, inputs, executionStyle = 'function', options = {}) {
|
|
10
33
|
const inputSetup = Object.entries(inputs)
|
|
11
34
|
.map(([key, value]) => `${key} = ${deps.toPythonLiteral(value)}`)
|
|
@@ -38,8 +61,10 @@ ${deps.PYTHON_CLASS_DEFINITIONS_SNIPPET}
|
|
|
38
61
|
_TRACECODE_TYPING_GLOBALS = {name for name in globals().keys() if not name.startswith('_')}
|
|
39
62
|
|
|
40
63
|
_trace_data = []
|
|
64
|
+
_trace_events = []
|
|
41
65
|
_console_output = []
|
|
42
66
|
_original_print = _builtins.print
|
|
67
|
+
_tracecode_builtin_id = _builtins.id
|
|
43
68
|
_target_function = "${targetFunction}"
|
|
44
69
|
_MIRROR_PRINT_TO_WORKER_CONSOLE = ${mirrorPrintToConsole ? 'True' : 'False'}
|
|
45
70
|
_MINIMAL_TRACE = ${minimalTrace ? 'True' : 'False'}
|
|
@@ -54,7 +79,8 @@ def _custom_print(*args, **kwargs):
|
|
|
54
79
|
_console_output.append(output)
|
|
55
80
|
try:
|
|
56
81
|
_frame = sys._getframe(1)
|
|
57
|
-
|
|
82
|
+
TraceHooks.flush_completed_line(_frame)
|
|
83
|
+
__tracecode_append_trace_step(_frame, {
|
|
58
84
|
'line': _frame.f_lineno,
|
|
59
85
|
'event': 'stdout',
|
|
60
86
|
'variables': {'output': output},
|
|
@@ -73,29 +99,31 @@ ${deps.PYTHON_TRACE_SERIALIZE_FUNCTION_SNIPPET}
|
|
|
73
99
|
_call_stack = []
|
|
74
100
|
_pending_accesses = {}
|
|
75
101
|
_last_trace_index_by_frame = {}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
_internal_funcs = {'_serialize', '_tracer', '_custom_print', '_dict_to_tree', '_dict_to_list', '_is_structural_constructor_frame', '_snapshot_call_stack', '_snapshot_locals', '_stable_token', '_looks_like_adjacency_list', '_looks_like_indexed_adjacency_list', '_extract_hashmap_snapshot', '_classify_runtime_object_kind', '_infer_hashmap_delta', '_clear_frame_hashmap_snapshots', '_build_runtime_visualization', '_resolve_inplace_result', '__tracecode_record_access', '__tracecode_flush_accesses', '__tracecode_append_trace_step', '__tracecode_attach_accesses_to_previous_step', '__tracecode_normalize_indices', '__tracecode_make_access_event', '__tracecode_read_value', '__tracecode_write_value', '__tracecode_apply_augmented_value', '_tracecode_read_index', '_tracecode_write_index', '_tracecode_augassign_index', '_tracecode_mutating_call', '_tracecode_mutating_index_call', '_tracecode_is_pure_literal_scaffold', '_tracecode_collect_collapsed_literal_lines', '__tracecode_attach_parents', '_tracecode_extract_named_subscript', '__TracecodeAccessTransformer', '__tracecode_compile_user_code', '<listcomp>', '<dictcomp>', '<setcomp>', '<genexpr>'}
|
|
102
|
+
_TRACE_MUTATING_METHODS = {'append', 'appendleft', 'pop', 'popleft', 'extend', 'insert', 'add', 'remove', 'discard', 'clear', 'sort', 'reverse'}
|
|
103
|
+
_internal_funcs = {'_serialize', '_tracecode_ref_id', '_tracer', '_custom_print', '_dict_to_tree', '_dict_to_list', '_tracecode_materialize_input', '_is_structural_constructor_frame', '_snapshot_call_stack', '_snapshot_locals', '_stable_token', '_looks_like_adjacency_list', '_looks_like_indexed_adjacency_list', '_resolve_inplace_result', 'TraceHooks', 'flush_completed_line', '_resolve_previous_step', '_append_step_runtime_events', '__tracecode_record_access', '__tracecode_flush_accesses', '__tracecode_append_trace_step', '__tracecode_append_trace_events_for_step', '__tracecode_append_runtime_event', '__tracecode_frame_id_for_step', '__tracecode_access_target', '__tracecode_access_binding', '__tracecode_access_kind', '__tracecode_value_at_path', '__tracecode_access_value', '__tracecode_attach_accesses_to_previous_step', '__tracecode_normalize_indices', '__tracecode_make_access_event', '__tracecode_is_indexable_sequence', '__tracecode_read_value', '__tracecode_write_value', '__tracecode_delete_value', '__tracecode_apply_augmented_value', '_tracecode_read_index', '_tracecode_write_index', '_tracecode_write_scalar', '_tracecode_delete_index', '_tracecode_augassign_index', '_tracecode_mutating_call', '_tracecode_mutating_index_call', '_tracecode_heapq_mutation', '_tracecode_dict_get', '_tracecode_dict_get_indexed', '_tracecode_len', '_tracecode_enumerate', '_tracecode_iter_bind', '_tracecode_iter_bind_indexed', '_tracecode_iter_bind_slice', '_tracecode_range_bind', '_tracecode_for_target_binding_name', '_tracecode_is_pure_literal_scaffold', '_tracecode_collect_collapsed_literal_lines', '__tracecode_attach_parents', '_tracecode_extract_named_subscript', '_tracecode_extract_mutable_container_target', '__TracecodeAccessTransformer', '__tracecode_compile_user_code', '<listcomp>', '<dictcomp>', '<setcomp>', '<genexpr>'}
|
|
79
104
|
_internal_locals = {
|
|
80
|
-
'_trace_data', '_console_output', '_original_print', '_target_function',
|
|
105
|
+
'_trace_data', '_trace_events', '_console_output', '_original_print', '_target_function',
|
|
81
106
|
'_MIRROR_PRINT_TO_WORKER_CONSOLE', '_MINIMAL_TRACE', '_SKIP_SENTINEL',
|
|
82
107
|
'_SCRIPT_MODE', '_TRACE_INPUT_NAMES', '_SCRIPT_PRE_USER_GLOBALS',
|
|
108
|
+
'_tracecode_builtin_id',
|
|
83
109
|
'_TRACECODE_TYPING_GLOBALS',
|
|
84
|
-
'_call_stack', '_pending_accesses', '_last_trace_index_by_frame', '
|
|
85
|
-
'_trace_limit_exceeded', '_timeout_reason', '_total_line_events', '_max_line_events',
|
|
110
|
+
'_call_stack', '_pending_accesses', '_last_trace_index_by_frame', '_TRACE_MUTATING_METHODS', '_internal_funcs', '_internal_locals', '_max_trace_steps',
|
|
111
|
+
'_trace_limit_exceeded', '_timeout_reason', '_total_line_events', '_max_line_events', '_max_stored_events',
|
|
86
112
|
'_line_hit_count', '_max_single_line_hits', '_infinite_loop_line',
|
|
87
113
|
'_MAX_SERIALIZE_DEPTH', '_trace_failed', '_inplace',
|
|
88
|
-
'_custom_print', '_tracer', '_serialize', '_dict_to_tree', '_dict_to_list',
|
|
114
|
+
'_custom_print', '_tracer', '_serialize', '_tracecode_ref_id', '_dict_to_tree', '_dict_to_list', '_tracecode_materialize_input',
|
|
89
115
|
'_is_structural_constructor_frame', '_snapshot_call_stack', '_snapshot_locals', '_stable_token',
|
|
90
|
-
'_looks_like_adjacency_list', '_looks_like_indexed_adjacency_list', '
|
|
91
|
-
'_clear_frame_hashmap_snapshots', '_build_runtime_visualization', '_resolve_inplace_result',
|
|
116
|
+
'_looks_like_adjacency_list', '_looks_like_indexed_adjacency_list', '_resolve_inplace_result',
|
|
92
117
|
'__tracecode_record_access', '__tracecode_flush_accesses', '__tracecode_append_trace_step',
|
|
118
|
+
'__tracecode_append_trace_events_for_step', '__tracecode_frame_id_for_step',
|
|
119
|
+
'__tracecode_access_target', '__tracecode_access_binding', '__tracecode_access_kind', '__tracecode_value_at_path',
|
|
120
|
+
'__tracecode_access_value',
|
|
93
121
|
'__tracecode_attach_accesses_to_previous_step', '__tracecode_normalize_indices',
|
|
94
|
-
'__tracecode_make_access_event', '__tracecode_read_value', '__tracecode_write_value',
|
|
95
|
-
'__tracecode_apply_augmented_value', '_tracecode_read_index', '_tracecode_write_index',
|
|
96
|
-
'_tracecode_augassign_index', '_tracecode_mutating_call', '_tracecode_mutating_index_call', '_tracecode_collapsed_literal_lines',
|
|
122
|
+
'__tracecode_make_access_event', '__tracecode_is_indexable_sequence', '__tracecode_read_value', '__tracecode_write_value',
|
|
123
|
+
'__tracecode_delete_value', '__tracecode_apply_augmented_value', '_tracecode_read_index', '_tracecode_write_index', '_tracecode_write_scalar',
|
|
124
|
+
'_tracecode_delete_index', '_tracecode_augassign_index', '_tracecode_mutating_call', '_tracecode_mutating_index_call', '_tracecode_heapq_mutation', '_tracecode_read_attr', '_tracecode_write_attr', '_tracecode_contains_key', '_tracecode_dict_get', '_tracecode_dict_get_indexed', '_tracecode_enumerate', '_tracecode_iter_bind', '_tracecode_iter_bind_indexed', '_tracecode_iter_bind_slice', '_tracecode_range_bind', '_tracecode_for_target_binding_name', '_tracecode_exception_value', '_tracecode_collapsed_literal_lines',
|
|
97
125
|
'_tracecode_is_pure_literal_scaffold', '_tracecode_collect_collapsed_literal_lines', '__tracecode_attach_parents',
|
|
98
|
-
'_tracecode_extract_named_subscript', '__TracecodeAccessTransformer', '__tracecode_compile_user_code',
|
|
126
|
+
'_tracecode_extract_named_subscript', '_tracecode_extract_mutable_container_target', '__TracecodeAccessTransformer', '__tracecode_compile_user_code',
|
|
99
127
|
'_InfiniteLoopDetected', '_tb', '_result', '_exc_type', '_exc_msg', '_exc_tb',
|
|
100
128
|
'_error_line', '_solver', '_ops', '_args', '_cls', '_instance', '_out',
|
|
101
129
|
'_i', '_op', '_call_args', '_method', '_user_code_str', '_textwrap',
|
|
@@ -103,6 +131,7 @@ _internal_locals = {
|
|
|
103
131
|
'__tracecode_tree', '__tracecode_compiled'
|
|
104
132
|
}
|
|
105
133
|
_max_trace_steps = ${effectiveMaxTraceSteps}
|
|
134
|
+
_max_stored_events = ${maxStoredEvents}
|
|
106
135
|
_trace_limit_exceeded = False
|
|
107
136
|
_timeout_reason = None
|
|
108
137
|
_total_line_events = 0
|
|
@@ -147,10 +176,10 @@ def _snapshot_call_stack():
|
|
|
147
176
|
return [f.copy() for f in _call_stack]
|
|
148
177
|
|
|
149
178
|
def _is_serialized_ref(value):
|
|
150
|
-
return isinstance(value, dict) and len(value) == 1 and isinstance(value.get('__ref__'), str)
|
|
179
|
+
return isinstance(value, _builtins.dict) and len(value) == 1 and isinstance(value.get('__ref__'), _builtins.str)
|
|
151
180
|
|
|
152
181
|
def _is_serialized_list_node(value):
|
|
153
|
-
return isinstance(value, dict) and value.get('__type__') == 'ListNode' and isinstance(value.get('__id__'), str)
|
|
182
|
+
return isinstance(value, _builtins.dict) and value.get('__type__') == 'ListNode' and isinstance(value.get('__id__'), _builtins.str)
|
|
154
183
|
|
|
155
184
|
def _serialized_list_root_id(value):
|
|
156
185
|
if _is_serialized_list_node(value):
|
|
@@ -174,13 +203,13 @@ def _collect_serialized_list_component(value, node_ids=None, ref_ids=None, seen=
|
|
|
174
203
|
if not _is_serialized_list_node(value):
|
|
175
204
|
return (node_ids, ref_ids)
|
|
176
205
|
|
|
177
|
-
marker =
|
|
206
|
+
marker = _tracecode_builtin_id(value)
|
|
178
207
|
if marker in seen:
|
|
179
208
|
return (node_ids, ref_ids)
|
|
180
209
|
seen.add(marker)
|
|
181
210
|
|
|
182
211
|
node_id = value.get('__id__')
|
|
183
|
-
if isinstance(node_id, str):
|
|
212
|
+
if isinstance(node_id, _builtins.str):
|
|
184
213
|
node_ids.add(node_id)
|
|
185
214
|
|
|
186
215
|
for field_name in ('next', 'prev'):
|
|
@@ -190,19 +219,69 @@ def _collect_serialized_list_component(value, node_ids=None, ref_ids=None, seen=
|
|
|
190
219
|
return (node_ids, ref_ids)
|
|
191
220
|
|
|
192
221
|
def _clone_serialized_value(value):
|
|
193
|
-
if isinstance(value, dict):
|
|
222
|
+
if isinstance(value, _builtins.dict):
|
|
194
223
|
return {key: _clone_serialized_value(nested) for key, nested in value.items()}
|
|
195
|
-
if isinstance(value, list):
|
|
224
|
+
if isinstance(value, _builtins.list):
|
|
196
225
|
return [_clone_serialized_value(item) for item in value]
|
|
197
226
|
return value
|
|
198
227
|
|
|
228
|
+
def _is_serialized_custom_object(value):
|
|
229
|
+
return (
|
|
230
|
+
isinstance(value, _builtins.dict) and
|
|
231
|
+
isinstance(value.get('__id__'), _builtins.str) and
|
|
232
|
+
isinstance(value.get('__class__'), _builtins.str) and
|
|
233
|
+
value.get('__type__') not in ('TreeNode', 'ListNode')
|
|
234
|
+
)
|
|
235
|
+
|
|
236
|
+
def _collect_serialized_custom_object_payloads(value, payloads=None, seen=None):
|
|
237
|
+
if payloads is None:
|
|
238
|
+
payloads = {}
|
|
239
|
+
if seen is None:
|
|
240
|
+
seen = set()
|
|
241
|
+
if isinstance(value, _builtins.list):
|
|
242
|
+
marker = _tracecode_builtin_id(value)
|
|
243
|
+
if marker in seen:
|
|
244
|
+
return payloads
|
|
245
|
+
seen.add(marker)
|
|
246
|
+
for item in value:
|
|
247
|
+
_collect_serialized_custom_object_payloads(item, payloads, seen)
|
|
248
|
+
return payloads
|
|
249
|
+
if not isinstance(value, _builtins.dict):
|
|
250
|
+
return payloads
|
|
251
|
+
marker = _tracecode_builtin_id(value)
|
|
252
|
+
if marker in seen:
|
|
253
|
+
return payloads
|
|
254
|
+
seen.add(marker)
|
|
255
|
+
if _is_serialized_custom_object(value):
|
|
256
|
+
payloads[value.get('__id__')] = value
|
|
257
|
+
for nested in value.values():
|
|
258
|
+
_collect_serialized_custom_object_payloads(nested, payloads, seen)
|
|
259
|
+
return payloads
|
|
260
|
+
|
|
261
|
+
def _materialize_top_level_custom_object_aliases(local_vars):
|
|
262
|
+
if not isinstance(local_vars, _builtins.dict) or len(local_vars) < 2:
|
|
263
|
+
return local_vars
|
|
264
|
+
payloads = {}
|
|
265
|
+
for value in local_vars.values():
|
|
266
|
+
_collect_serialized_custom_object_payloads(value, payloads)
|
|
267
|
+
if not payloads:
|
|
268
|
+
return local_vars
|
|
269
|
+
for name, value in list(local_vars.items()):
|
|
270
|
+
if not _is_serialized_ref(value):
|
|
271
|
+
continue
|
|
272
|
+
ref_id = value.get('__ref__')
|
|
273
|
+
target = payloads.get(ref_id)
|
|
274
|
+
if target is not None:
|
|
275
|
+
local_vars[name] = _clone_serialized_value(target)
|
|
276
|
+
return local_vars
|
|
277
|
+
|
|
199
278
|
def _inline_component_list_refs(value, root_payloads, seen_root_ids=None):
|
|
200
279
|
if seen_root_ids is None:
|
|
201
280
|
seen_root_ids = set()
|
|
202
281
|
|
|
203
282
|
if _is_serialized_ref(value):
|
|
204
283
|
ref_id = value.get('__ref__')
|
|
205
|
-
if not isinstance(ref_id, str):
|
|
284
|
+
if not isinstance(ref_id, _builtins.str):
|
|
206
285
|
return value
|
|
207
286
|
target = root_payloads.get(ref_id)
|
|
208
287
|
if target is None or ref_id in seen_root_ids:
|
|
@@ -211,16 +290,16 @@ def _inline_component_list_refs(value, root_payloads, seen_root_ids=None):
|
|
|
211
290
|
next_seen.add(ref_id)
|
|
212
291
|
return _inline_component_list_refs(_clone_serialized_value(target), root_payloads, next_seen)
|
|
213
292
|
|
|
214
|
-
if isinstance(value, list):
|
|
293
|
+
if isinstance(value, _builtins.list):
|
|
215
294
|
return [_inline_component_list_refs(item, root_payloads, seen_root_ids) for item in value]
|
|
216
295
|
|
|
217
|
-
if not isinstance(value, dict):
|
|
296
|
+
if not isinstance(value, _builtins.dict):
|
|
218
297
|
return value
|
|
219
298
|
|
|
220
299
|
out = {}
|
|
221
300
|
next_seen = set(seen_root_ids)
|
|
222
301
|
value_id = value.get('__id__')
|
|
223
|
-
if isinstance(value_id, str):
|
|
302
|
+
if isinstance(value_id, _builtins.str):
|
|
224
303
|
next_seen.add(value_id)
|
|
225
304
|
|
|
226
305
|
for key, nested in value.items():
|
|
@@ -228,7 +307,7 @@ def _inline_component_list_refs(value, root_payloads, seen_root_ids=None):
|
|
|
228
307
|
return out
|
|
229
308
|
|
|
230
309
|
def _normalize_top_level_linked_list_locals(local_vars):
|
|
231
|
-
if not isinstance(local_vars, dict) or len(local_vars) < 2:
|
|
310
|
+
if not isinstance(local_vars, _builtins.dict) or len(local_vars) < 2:
|
|
232
311
|
return local_vars
|
|
233
312
|
|
|
234
313
|
ordered_names = list(local_vars.keys())
|
|
@@ -237,7 +316,7 @@ def _normalize_top_level_linked_list_locals(local_vars):
|
|
|
237
316
|
for index, name in enumerate(ordered_names):
|
|
238
317
|
value = local_vars.get(name)
|
|
239
318
|
root_id = _serialized_list_root_id(value)
|
|
240
|
-
if not isinstance(root_id, str):
|
|
319
|
+
if not isinstance(root_id, _builtins.str):
|
|
241
320
|
continue
|
|
242
321
|
node_ids, ref_ids = _collect_serialized_list_component(value)
|
|
243
322
|
all_ids = set(node_ids) | set(ref_ids)
|
|
@@ -302,7 +381,7 @@ def _normalize_top_level_linked_list_locals(local_vars):
|
|
|
302
381
|
for candidate in group:
|
|
303
382
|
root_id = candidate.get('root_id')
|
|
304
383
|
value = candidate.get('value')
|
|
305
|
-
if isinstance(root_id, str) and _is_serialized_list_node(value):
|
|
384
|
+
if isinstance(root_id, _builtins.str) and _is_serialized_list_node(value):
|
|
306
385
|
root_payloads[root_id] = _clone_serialized_value(value)
|
|
307
386
|
|
|
308
387
|
canonical = max(
|
|
@@ -319,14 +398,14 @@ def _normalize_top_level_linked_list_locals(local_vars):
|
|
|
319
398
|
local_vars[canonical['name']] = _inline_component_list_refs(
|
|
320
399
|
_clone_serialized_value(canonical['value']),
|
|
321
400
|
root_payloads,
|
|
322
|
-
set([canonical.get('root_id')]) if isinstance(canonical.get('root_id'), str) else set(),
|
|
401
|
+
set([canonical.get('root_id')]) if isinstance(canonical.get('root_id'), _builtins.str) else set(),
|
|
323
402
|
)
|
|
324
403
|
|
|
325
404
|
for candidate in group:
|
|
326
405
|
if candidate is canonical:
|
|
327
406
|
continue
|
|
328
407
|
root_id = candidate.get('root_id')
|
|
329
|
-
if isinstance(root_id, str):
|
|
408
|
+
if isinstance(root_id, _builtins.str):
|
|
330
409
|
local_vars[candidate['name']] = {'__ref__': root_id}
|
|
331
410
|
|
|
332
411
|
return local_vars
|
|
@@ -371,54 +450,271 @@ def _snapshot_locals(frame, with_sources=False):
|
|
|
371
450
|
if v != _SKIP_SENTINEL
|
|
372
451
|
}
|
|
373
452
|
local_vars = _normalize_top_level_linked_list_locals(local_vars)
|
|
453
|
+
local_vars = _materialize_top_level_custom_object_aliases(local_vars)
|
|
374
454
|
local_sources = {name: _sources.get(name, 'user') for name in local_vars.keys()}
|
|
375
455
|
return (local_vars, local_sources) if with_sources else local_vars
|
|
376
456
|
except Exception:
|
|
377
457
|
return ({}, {}) if with_sources else {}
|
|
378
458
|
|
|
379
459
|
def __tracecode_record_access(frame, event):
|
|
380
|
-
if
|
|
460
|
+
if _trace_limit_exceeded:
|
|
461
|
+
return
|
|
462
|
+
if frame is None or not isinstance(event, _builtins.dict):
|
|
381
463
|
return
|
|
382
|
-
frame_key =
|
|
464
|
+
frame_key = _tracecode_builtin_id(frame)
|
|
383
465
|
_pending_accesses.setdefault(frame_key, []).append(event)
|
|
384
466
|
|
|
385
467
|
def __tracecode_flush_accesses(frame):
|
|
468
|
+
if _trace_limit_exceeded:
|
|
469
|
+
return []
|
|
386
470
|
if frame is None:
|
|
387
471
|
return []
|
|
388
|
-
return _pending_accesses.pop(
|
|
472
|
+
return _pending_accesses.pop(_tracecode_builtin_id(frame), [])
|
|
473
|
+
|
|
474
|
+
def __tracecode_frame_id_for_step(step):
|
|
475
|
+
stack = step.get('callStack') if isinstance(step, _builtins.dict) else []
|
|
476
|
+
if isinstance(stack, _builtins.list) and len(stack) > 0:
|
|
477
|
+
frame = stack[-1]
|
|
478
|
+
if isinstance(frame, _builtins.dict):
|
|
479
|
+
return str(frame.get('function')) + ':' + str(frame.get('line'))
|
|
480
|
+
return str(step.get('function')) + ':' + str(step.get('line'))
|
|
481
|
+
|
|
482
|
+
def __tracecode_access_target(access):
|
|
483
|
+
indices = access.get('indices') if isinstance(access, _builtins.dict) else None
|
|
484
|
+
if isinstance(indices, _builtins.list) and len(indices) > 0:
|
|
485
|
+
target = {'variable': access.get('variable'), 'path': indices}
|
|
486
|
+
index_sources = access.get('indexSources')
|
|
487
|
+
if isinstance(index_sources, _builtins.list) and len(index_sources) > 0:
|
|
488
|
+
target['indexSources'] = index_sources
|
|
489
|
+
return target
|
|
490
|
+
return {'variable': access.get('variable')}
|
|
491
|
+
|
|
492
|
+
def __tracecode_access_binding(access):
|
|
493
|
+
binding = access.get('binding') if isinstance(access, _builtins.dict) else None
|
|
494
|
+
if not isinstance(binding, _builtins.dict):
|
|
495
|
+
return None
|
|
496
|
+
variable = binding.get('variable')
|
|
497
|
+
if not isinstance(variable, _builtins.str) or len(variable) == 0:
|
|
498
|
+
return None
|
|
499
|
+
event = {'variable': variable}
|
|
500
|
+
if binding.get('kind') == 'iteration':
|
|
501
|
+
event['kind'] = 'iteration'
|
|
502
|
+
return event
|
|
503
|
+
|
|
504
|
+
def __tracecode_access_kind(access):
|
|
505
|
+
kind = access.get('kind') if isinstance(access, _builtins.dict) else None
|
|
506
|
+
if kind in ('indexed-read', 'cell-read'):
|
|
507
|
+
return 'read'
|
|
508
|
+
if kind in ('indexed-write', 'cell-write'):
|
|
509
|
+
return 'write'
|
|
510
|
+
return 'mutate'
|
|
511
|
+
|
|
512
|
+
def __tracecode_value_at_path(value, path):
|
|
513
|
+
if not isinstance(path, _builtins.list) or len(path) == 0:
|
|
514
|
+
return value
|
|
515
|
+
current = value
|
|
516
|
+
for part in path:
|
|
517
|
+
try:
|
|
518
|
+
current = current[part]
|
|
519
|
+
except Exception:
|
|
520
|
+
return None
|
|
521
|
+
return current
|
|
522
|
+
|
|
523
|
+
def __tracecode_access_value(step, access):
|
|
524
|
+
if isinstance(access, _builtins.dict) and 'value' in access:
|
|
525
|
+
return access.get('value')
|
|
526
|
+
variables = step.get('variables') if isinstance(step, _builtins.dict) else {}
|
|
527
|
+
root = variables.get(access.get('variable')) if isinstance(variables, _builtins.dict) else None
|
|
528
|
+
return __tracecode_value_at_path(root, access.get('indices'))
|
|
529
|
+
|
|
530
|
+
def __tracecode_append_runtime_event(event):
|
|
531
|
+
global _trace_limit_exceeded, _timeout_reason
|
|
532
|
+
if len(_trace_events) >= _max_stored_events:
|
|
533
|
+
if not _trace_limit_exceeded:
|
|
534
|
+
_trace_limit_exceeded = True
|
|
535
|
+
_timeout_reason = 'trace-limit'
|
|
536
|
+
_pending_accesses.clear()
|
|
537
|
+
return False
|
|
538
|
+
_trace_events.append(event)
|
|
539
|
+
return True
|
|
540
|
+
|
|
541
|
+
def __tracecode_append_trace_events_for_step(step):
|
|
542
|
+
if not isinstance(step, _builtins.dict):
|
|
543
|
+
return
|
|
544
|
+
if _trace_limit_exceeded and step.get('event') != 'timeout':
|
|
545
|
+
return
|
|
546
|
+
line = step.get('line')
|
|
547
|
+
event_kind = step.get('event')
|
|
548
|
+
function_name = step.get('function')
|
|
549
|
+
base = {
|
|
550
|
+
'runId': 'python:run',
|
|
551
|
+
'line': line,
|
|
552
|
+
'frameId': __tracecode_frame_id_for_step(step)
|
|
553
|
+
}
|
|
554
|
+
if event_kind == 'line':
|
|
555
|
+
__tracecode_append_runtime_event({**base, 'kind': 'line', 'function': function_name})
|
|
556
|
+
elif event_kind == 'call':
|
|
557
|
+
stack = step.get('callStack') if isinstance(step.get('callStack'), _builtins.list) else []
|
|
558
|
+
frame = stack[-1] if len(stack) > 0 and isinstance(stack[-1], _builtins.dict) else {}
|
|
559
|
+
__tracecode_append_runtime_event({**base, 'kind': 'call', 'function': function_name, 'args': frame.get('args')})
|
|
560
|
+
elif event_kind == 'return':
|
|
561
|
+
event = {**base, 'kind': 'return', 'function': function_name}
|
|
562
|
+
if 'returnValue' in step:
|
|
563
|
+
event['value'] = step.get('returnValue')
|
|
564
|
+
__tracecode_append_runtime_event(event)
|
|
565
|
+
elif event_kind == 'exception':
|
|
566
|
+
variables = step.get('variables') if isinstance(step.get('variables'), _builtins.dict) else {}
|
|
567
|
+
__tracecode_append_runtime_event({**base, 'kind': 'exception', 'message': str(step.get('returnValue') or variables.get('error') or 'Runtime exception')})
|
|
568
|
+
elif event_kind == 'timeout':
|
|
569
|
+
__tracecode_append_runtime_event({**base, 'kind': 'timeout', 'message': 'Runtime timeout'})
|
|
570
|
+
elif event_kind == 'stdout':
|
|
571
|
+
variables = step.get('variables') if isinstance(step.get('variables'), _builtins.dict) else {}
|
|
572
|
+
__tracecode_append_runtime_event({'kind': 'stdout', 'runId': 'python:run', 'line': line, 'text': str(step.get('returnValue') or variables.get('output') or '')})
|
|
573
|
+
|
|
574
|
+
variables = step.get('variables')
|
|
575
|
+
if event_kind != '__access_only__' and isinstance(variables, _builtins.dict):
|
|
576
|
+
for variable, value in variables.items():
|
|
577
|
+
if not __tracecode_append_runtime_event({**base, 'kind': 'snapshot', 'target': {'variable': variable}, 'value': value}):
|
|
578
|
+
return
|
|
579
|
+
|
|
580
|
+
accesses = step.get('accesses')
|
|
581
|
+
if isinstance(accesses, _builtins.list):
|
|
582
|
+
for access in accesses:
|
|
583
|
+
if not isinstance(access, _builtins.dict):
|
|
584
|
+
continue
|
|
585
|
+
kind = __tracecode_access_kind(access)
|
|
586
|
+
target = __tracecode_access_target(access)
|
|
587
|
+
if kind == 'mutate':
|
|
588
|
+
method = access.get('method')
|
|
589
|
+
event = {**base, 'kind': kind, 'target': target}
|
|
590
|
+
if method:
|
|
591
|
+
event['method'] = method
|
|
592
|
+
if isinstance(access.get('args'), _builtins.list):
|
|
593
|
+
event['args'] = access.get('args')
|
|
594
|
+
if not __tracecode_append_runtime_event(event):
|
|
595
|
+
return
|
|
596
|
+
else:
|
|
597
|
+
event = {**base, 'kind': kind, 'target': target, 'value': __tracecode_access_value(step, access)}
|
|
598
|
+
binding = __tracecode_access_binding(access)
|
|
599
|
+
if binding is not None:
|
|
600
|
+
event['binding'] = binding
|
|
601
|
+
if not __tracecode_append_runtime_event(event):
|
|
602
|
+
return
|
|
603
|
+
|
|
604
|
+
class TraceHooks:
|
|
605
|
+
"""
|
|
606
|
+
RuntimeTrace is post-line: public line frames describe a source line after it
|
|
607
|
+
completed. Python sys.settrace reports line events before execution, so the
|
|
608
|
+
Python runtime keeps the legacy step pending and flushes it when execution
|
|
609
|
+
advances to the next line or returns.
|
|
610
|
+
"""
|
|
611
|
+
|
|
612
|
+
@staticmethod
|
|
613
|
+
def _resolve_previous_step(frame):
|
|
614
|
+
if frame is None:
|
|
615
|
+
return None
|
|
616
|
+
previous_index = _last_trace_index_by_frame.get(_tracecode_builtin_id(frame))
|
|
617
|
+
if previous_index is None or previous_index < 0 or previous_index >= len(_trace_data):
|
|
618
|
+
return None
|
|
619
|
+
previous_step = _trace_data[previous_index]
|
|
620
|
+
return previous_step if isinstance(previous_step, _builtins.dict) else None
|
|
621
|
+
|
|
622
|
+
@staticmethod
|
|
623
|
+
def _append_step_runtime_events(step):
|
|
624
|
+
if step.get('__runtime_flushed'):
|
|
625
|
+
return
|
|
626
|
+
step['__runtime_flushed'] = True
|
|
627
|
+
globals()['__tracecode_append_trace_events_for_step'](step)
|
|
628
|
+
|
|
629
|
+
@staticmethod
|
|
630
|
+
def flush_completed_line(frame):
|
|
631
|
+
previous_step = TraceHooks._resolve_previous_step(frame)
|
|
632
|
+
if previous_step is None:
|
|
633
|
+
return
|
|
634
|
+
if previous_step.get('event') != 'line':
|
|
635
|
+
globals()['__tracecode_attach_accesses_to_previous_step'](frame)
|
|
636
|
+
return
|
|
637
|
+
if previous_step.get('__runtime_flushed'):
|
|
638
|
+
return
|
|
639
|
+
local_vars, local_sources = _snapshot_locals(frame, with_sources=True)
|
|
640
|
+
accesses = globals()['__tracecode_flush_accesses'](frame)
|
|
641
|
+
previous_step['variables'] = local_vars
|
|
642
|
+
previous_step['variableSources'] = local_sources
|
|
643
|
+
previous_step['accesses'] = accesses
|
|
644
|
+
previous_step['callStack'] = _snapshot_call_stack()
|
|
645
|
+
previous_step['stdoutLineCount'] = len(_console_output)
|
|
646
|
+
TraceHooks._append_step_runtime_events(previous_step)
|
|
389
647
|
|
|
390
648
|
def __tracecode_append_trace_step(frame, step):
|
|
649
|
+
global _trace_limit_exceeded, _timeout_reason
|
|
650
|
+
if _trace_limit_exceeded and (not isinstance(step, _builtins.dict) or step.get('event') != 'timeout'):
|
|
651
|
+
return
|
|
652
|
+
if len(_trace_data) >= _max_trace_steps and (not isinstance(step, _builtins.dict) or step.get('event') != 'timeout'):
|
|
653
|
+
if not _trace_limit_exceeded:
|
|
654
|
+
_trace_limit_exceeded = True
|
|
655
|
+
_timeout_reason = 'trace-limit'
|
|
656
|
+
_pending_accesses.clear()
|
|
657
|
+
return
|
|
391
658
|
_trace_data.append(step)
|
|
659
|
+
if not (isinstance(step, _builtins.dict) and step.get('event') == 'line'):
|
|
660
|
+
if isinstance(step, _builtins.dict):
|
|
661
|
+
step['__runtime_flushed'] = True
|
|
662
|
+
__tracecode_append_trace_events_for_step(step)
|
|
392
663
|
if frame is not None:
|
|
393
|
-
_last_trace_index_by_frame[
|
|
664
|
+
_last_trace_index_by_frame[_tracecode_builtin_id(frame)] = len(_trace_data) - 1
|
|
394
665
|
|
|
395
666
|
def __tracecode_attach_accesses_to_previous_step(frame):
|
|
396
667
|
accesses = __tracecode_flush_accesses(frame)
|
|
397
668
|
if not accesses:
|
|
398
669
|
return []
|
|
399
|
-
frame_key =
|
|
670
|
+
frame_key = _tracecode_builtin_id(frame)
|
|
400
671
|
previous_index = _last_trace_index_by_frame.get(frame_key)
|
|
401
672
|
if previous_index is not None and 0 <= previous_index < len(_trace_data):
|
|
402
673
|
previous_step = _trace_data[previous_index]
|
|
403
674
|
existing_accesses = previous_step.get('accesses')
|
|
404
|
-
if isinstance(existing_accesses, list):
|
|
675
|
+
if isinstance(existing_accesses, _builtins.list):
|
|
405
676
|
existing_accesses.extend(accesses)
|
|
406
677
|
else:
|
|
407
678
|
previous_step['accesses'] = accesses
|
|
679
|
+
for access in accesses:
|
|
680
|
+
__tracecode_append_trace_events_for_step({
|
|
681
|
+
'line': previous_step.get('line'),
|
|
682
|
+
'event': '__access_only__',
|
|
683
|
+
'variables': previous_step.get('variables', {}),
|
|
684
|
+
'function': previous_step.get('function'),
|
|
685
|
+
'callStack': previous_step.get('callStack', []),
|
|
686
|
+
'accesses': [access],
|
|
687
|
+
})
|
|
408
688
|
return []
|
|
409
689
|
return accesses
|
|
410
690
|
|
|
411
691
|
def __tracecode_normalize_indices(indices, max_depth=2):
|
|
412
|
-
if not isinstance(indices, (list, tuple)) or len(indices) == 0 or len(indices) > max_depth:
|
|
692
|
+
if not isinstance(indices, (list, _builtins.tuple)) or len(indices) == 0 or len(indices) > max_depth:
|
|
413
693
|
return None
|
|
414
694
|
normalized = []
|
|
415
695
|
for index in indices:
|
|
416
|
-
if
|
|
696
|
+
if isinstance(index, slice):
|
|
697
|
+
start = '' if index.start is None else str(index.start)
|
|
698
|
+
stop = '' if index.stop is None else str(index.stop)
|
|
699
|
+
step = '' if index.step is None else str(index.step)
|
|
700
|
+
normalized.append(f'{start}:{stop}' if step == '' else f'{start}:{stop}:{step}')
|
|
701
|
+
continue
|
|
702
|
+
if not isinstance(index, (int, _builtins.str)):
|
|
417
703
|
return None
|
|
418
|
-
normalized.append(int(index))
|
|
704
|
+
normalized.append(int(index) if isinstance(index, int) else index)
|
|
419
705
|
return normalized
|
|
420
706
|
|
|
421
|
-
def
|
|
707
|
+
def __tracecode_normalize_index_sources(index_sources, path_length):
|
|
708
|
+
if not isinstance(index_sources, (list, _builtins.tuple)) or not isinstance(path_length, int) or path_length <= 0:
|
|
709
|
+
return None
|
|
710
|
+
normalized = []
|
|
711
|
+
for source in list(index_sources)[:path_length]:
|
|
712
|
+
normalized.append(source if isinstance(source, _builtins.str) and len(source) > 0 else None)
|
|
713
|
+
while len(normalized) < path_length:
|
|
714
|
+
normalized.append(None)
|
|
715
|
+
return normalized if any(source is not None for source in normalized) else None
|
|
716
|
+
|
|
717
|
+
def __tracecode_make_access_event(var_name, kind, indices=None, method_name=None, binding=None, value=None, index_sources=None, args=None):
|
|
422
718
|
event = {
|
|
423
719
|
'variable': var_name,
|
|
424
720
|
'kind': kind,
|
|
@@ -426,26 +722,71 @@ def __tracecode_make_access_event(var_name, kind, indices=None, method_name=None
|
|
|
426
722
|
if indices is not None:
|
|
427
723
|
event['indices'] = list(indices)
|
|
428
724
|
event['pathDepth'] = len(indices)
|
|
725
|
+
normalized_sources = __tracecode_normalize_index_sources(index_sources, len(indices))
|
|
726
|
+
if normalized_sources is not None:
|
|
727
|
+
event['indexSources'] = normalized_sources
|
|
429
728
|
if method_name is not None:
|
|
430
729
|
event['method'] = method_name
|
|
730
|
+
if binding is not None:
|
|
731
|
+
event['binding'] = binding
|
|
732
|
+
if value is not None:
|
|
733
|
+
event['value'] = value
|
|
734
|
+
if args is not None:
|
|
735
|
+
event['args'] = args
|
|
431
736
|
return event
|
|
432
737
|
|
|
738
|
+
def __tracecode_is_indexable_sequence(value):
|
|
739
|
+
return isinstance(value, (list, tuple, _builtins.str)) or (
|
|
740
|
+
getattr(getattr(value, '__class__', None), '__name__', '') == 'deque'
|
|
741
|
+
)
|
|
742
|
+
|
|
433
743
|
def __tracecode_read_value(container, indices):
|
|
434
744
|
current = container
|
|
435
745
|
for index in indices:
|
|
436
|
-
current
|
|
746
|
+
if isinstance(current, _builtins.dict) or __tracecode_is_indexable_sequence(current):
|
|
747
|
+
current = current[index]
|
|
748
|
+
else:
|
|
749
|
+
current = getattr(current, index)
|
|
437
750
|
return current
|
|
438
751
|
|
|
439
752
|
def __tracecode_write_value(container, indices, value):
|
|
440
753
|
if len(indices) == 1:
|
|
441
|
-
container
|
|
754
|
+
if isinstance(container, _builtins.dict) or isinstance(container, _builtins.list):
|
|
755
|
+
container[indices[0]] = value
|
|
756
|
+
else:
|
|
757
|
+
setattr(container, indices[0], value)
|
|
442
758
|
return value
|
|
443
759
|
parent = container
|
|
444
760
|
for index in indices[:-1]:
|
|
445
|
-
parent
|
|
446
|
-
|
|
761
|
+
if isinstance(parent, _builtins.dict) or __tracecode_is_indexable_sequence(parent):
|
|
762
|
+
parent = parent[index]
|
|
763
|
+
else:
|
|
764
|
+
parent = getattr(parent, index)
|
|
765
|
+
if isinstance(parent, _builtins.dict) or isinstance(parent, _builtins.list):
|
|
766
|
+
parent[indices[-1]] = value
|
|
767
|
+
else:
|
|
768
|
+
setattr(parent, indices[-1], value)
|
|
447
769
|
return value
|
|
448
770
|
|
|
771
|
+
def __tracecode_delete_value(container, indices):
|
|
772
|
+
if len(indices) == 1:
|
|
773
|
+
if isinstance(container, _builtins.dict) or isinstance(container, _builtins.list):
|
|
774
|
+
del container[indices[0]]
|
|
775
|
+
else:
|
|
776
|
+
delattr(container, indices[0])
|
|
777
|
+
return None
|
|
778
|
+
parent = container
|
|
779
|
+
for index in indices[:-1]:
|
|
780
|
+
if isinstance(parent, _builtins.dict) or __tracecode_is_indexable_sequence(parent):
|
|
781
|
+
parent = parent[index]
|
|
782
|
+
else:
|
|
783
|
+
parent = getattr(parent, index)
|
|
784
|
+
if isinstance(parent, _builtins.dict) or isinstance(parent, _builtins.list):
|
|
785
|
+
del parent[indices[-1]]
|
|
786
|
+
else:
|
|
787
|
+
delattr(parent, indices[-1])
|
|
788
|
+
return None
|
|
789
|
+
|
|
449
790
|
def __tracecode_apply_augmented_value(current, op_name, rhs):
|
|
450
791
|
if op_name == 'add':
|
|
451
792
|
return current + rhs
|
|
@@ -473,7 +814,8 @@ def __tracecode_apply_augmented_value(current, op_name, rhs):
|
|
|
473
814
|
return current ^ rhs
|
|
474
815
|
return rhs
|
|
475
816
|
|
|
476
|
-
def _tracecode_read_index(var_name, container, indices):
|
|
817
|
+
def _tracecode_read_index(var_name, container, indices, index_sources=None):
|
|
818
|
+
result = __tracecode_read_value(container, list(indices))
|
|
477
819
|
normalized = __tracecode_normalize_indices(indices)
|
|
478
820
|
if normalized is not None:
|
|
479
821
|
__tracecode_record_access(
|
|
@@ -482,49 +824,99 @@ def _tracecode_read_index(var_name, container, indices):
|
|
|
482
824
|
var_name,
|
|
483
825
|
'cell-read' if len(normalized) == 2 else 'indexed-read',
|
|
484
826
|
normalized,
|
|
827
|
+
index_sources=index_sources,
|
|
828
|
+
value=_serialize(result),
|
|
485
829
|
),
|
|
486
830
|
)
|
|
487
|
-
return
|
|
831
|
+
return result
|
|
488
832
|
|
|
489
|
-
def _tracecode_write_index(var_name, container, indices, value):
|
|
833
|
+
def _tracecode_write_index(var_name, container, indices, index_sources, value):
|
|
490
834
|
effective_indices = list(indices)
|
|
491
835
|
result = __tracecode_write_value(container, effective_indices, value)
|
|
492
836
|
normalized = __tracecode_normalize_indices(effective_indices)
|
|
493
837
|
if normalized is not None:
|
|
838
|
+
if isinstance(container, _builtins.dict):
|
|
839
|
+
__tracecode_record_access(
|
|
840
|
+
sys._getframe(1),
|
|
841
|
+
__tracecode_make_access_event(var_name, 'indexed-write', normalized, index_sources=index_sources, value=_serialize(result)),
|
|
842
|
+
)
|
|
843
|
+
return result
|
|
494
844
|
__tracecode_record_access(
|
|
495
845
|
sys._getframe(1),
|
|
496
846
|
__tracecode_make_access_event(
|
|
497
847
|
var_name,
|
|
498
848
|
'cell-write' if len(normalized) == 2 else 'indexed-write',
|
|
499
849
|
normalized,
|
|
850
|
+
index_sources=index_sources,
|
|
851
|
+
value=_serialize(result),
|
|
500
852
|
),
|
|
501
853
|
)
|
|
502
854
|
return result
|
|
503
855
|
|
|
504
|
-
def
|
|
856
|
+
def _tracecode_write_scalar(var_name, value):
|
|
857
|
+
__tracecode_record_access(
|
|
858
|
+
sys._getframe(1),
|
|
859
|
+
__tracecode_make_access_event(var_name, 'indexed-write', value=_serialize(value)),
|
|
860
|
+
)
|
|
861
|
+
return value
|
|
862
|
+
|
|
863
|
+
def _tracecode_delete_index(var_name, container, indices, index_sources=None):
|
|
864
|
+
effective_indices = list(indices)
|
|
865
|
+
__tracecode_delete_value(container, effective_indices)
|
|
866
|
+
normalized = __tracecode_normalize_indices(effective_indices)
|
|
867
|
+
if normalized is not None:
|
|
868
|
+
if isinstance(container, _builtins.dict):
|
|
869
|
+
__tracecode_record_access(
|
|
870
|
+
sys._getframe(1),
|
|
871
|
+
__tracecode_make_access_event(var_name, 'mutating-call', method_name='remove'),
|
|
872
|
+
)
|
|
873
|
+
else:
|
|
874
|
+
__tracecode_record_access(
|
|
875
|
+
sys._getframe(1),
|
|
876
|
+
__tracecode_make_access_event(var_name, 'mutating-call', normalized, method_name='remove', index_sources=index_sources),
|
|
877
|
+
)
|
|
878
|
+
return None
|
|
879
|
+
|
|
880
|
+
def _tracecode_augassign_index(var_name, container, indices, index_sources, op_name, rhs):
|
|
505
881
|
effective_indices = list(indices)
|
|
506
882
|
current = __tracecode_read_value(container, effective_indices)
|
|
507
883
|
normalized = __tracecode_normalize_indices(effective_indices)
|
|
508
884
|
if normalized is not None:
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
var_name,
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
885
|
+
if isinstance(container, _builtins.dict):
|
|
886
|
+
__tracecode_record_access(
|
|
887
|
+
sys._getframe(1),
|
|
888
|
+
__tracecode_make_access_event(var_name, 'indexed-read', normalized, index_sources=index_sources, value=_serialize(current)),
|
|
889
|
+
)
|
|
890
|
+
else:
|
|
891
|
+
__tracecode_record_access(
|
|
892
|
+
sys._getframe(1),
|
|
893
|
+
__tracecode_make_access_event(
|
|
894
|
+
var_name,
|
|
895
|
+
'cell-read' if len(normalized) == 2 else 'indexed-read',
|
|
896
|
+
normalized,
|
|
897
|
+
index_sources=index_sources,
|
|
898
|
+
value=_serialize(current),
|
|
899
|
+
),
|
|
900
|
+
)
|
|
517
901
|
next_value = __tracecode_apply_augmented_value(current, op_name, rhs)
|
|
518
902
|
__tracecode_write_value(container, effective_indices, next_value)
|
|
519
903
|
if normalized is not None:
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
var_name,
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
904
|
+
if isinstance(container, _builtins.dict):
|
|
905
|
+
__tracecode_record_access(
|
|
906
|
+
sys._getframe(1),
|
|
907
|
+
__tracecode_make_access_event(var_name, 'indexed-write', normalized, index_sources=index_sources, value=_serialize(next_value)),
|
|
908
|
+
)
|
|
909
|
+
else:
|
|
910
|
+
__tracecode_record_access(
|
|
911
|
+
sys._getframe(1),
|
|
912
|
+
__tracecode_make_access_event(
|
|
913
|
+
var_name,
|
|
914
|
+
'cell-write' if len(normalized) == 2 else 'indexed-write',
|
|
915
|
+
normalized,
|
|
916
|
+
index_sources=index_sources,
|
|
917
|
+
value=_serialize(next_value),
|
|
918
|
+
),
|
|
919
|
+
)
|
|
528
920
|
return next_value
|
|
529
921
|
|
|
530
922
|
def _tracecode_mutating_call(var_name, container, method_name, *args, **kwargs):
|
|
@@ -532,11 +924,11 @@ def _tracecode_mutating_call(var_name, container, method_name, *args, **kwargs):
|
|
|
532
924
|
if method_name in _TRACE_MUTATING_METHODS:
|
|
533
925
|
__tracecode_record_access(
|
|
534
926
|
sys._getframe(1),
|
|
535
|
-
__tracecode_make_access_event(var_name, 'mutating-call', method_name=method_name),
|
|
927
|
+
__tracecode_make_access_event(var_name, 'mutating-call', method_name=method_name, args=[_serialize(arg) for arg in args]),
|
|
536
928
|
)
|
|
537
929
|
return result
|
|
538
930
|
|
|
539
|
-
def _tracecode_mutating_index_call(var_name, container, indices, method_name, *args, **kwargs):
|
|
931
|
+
def _tracecode_mutating_index_call(var_name, container, indices, index_sources, method_name, *args, **kwargs):
|
|
540
932
|
effective_indices = list(indices)
|
|
541
933
|
target = __tracecode_read_value(container, effective_indices)
|
|
542
934
|
result = getattr(target, method_name)(*args, **kwargs)
|
|
@@ -544,10 +936,217 @@ def _tracecode_mutating_index_call(var_name, container, indices, method_name, *a
|
|
|
544
936
|
if method_name in _TRACE_MUTATING_METHODS:
|
|
545
937
|
__tracecode_record_access(
|
|
546
938
|
sys._getframe(1),
|
|
547
|
-
__tracecode_make_access_event(var_name, '
|
|
939
|
+
__tracecode_make_access_event(var_name, 'indexed-read', normalized, index_sources=index_sources),
|
|
548
940
|
)
|
|
941
|
+
__tracecode_record_access(
|
|
942
|
+
sys._getframe(1),
|
|
943
|
+
__tracecode_make_access_event(var_name, 'mutating-call', normalized, method_name, index_sources=index_sources, args=[_serialize(arg) for arg in args]),
|
|
944
|
+
)
|
|
945
|
+
return result
|
|
946
|
+
|
|
947
|
+
def _tracecode_heapq_mutation(var_name, container, indices, method_name, *args, **kwargs):
|
|
948
|
+
import heapq as __tracecode_heapq
|
|
949
|
+
effective_indices = list(indices or [])
|
|
950
|
+
target = __tracecode_read_value(container, effective_indices) if effective_indices else container
|
|
951
|
+
normalized = __tracecode_normalize_indices(effective_indices)
|
|
952
|
+
__tracecode_record_access(
|
|
953
|
+
sys._getframe(1),
|
|
954
|
+
__tracecode_make_access_event(
|
|
955
|
+
var_name,
|
|
956
|
+
'indexed-read',
|
|
957
|
+
normalized,
|
|
958
|
+
value=_serialize(target),
|
|
959
|
+
),
|
|
960
|
+
)
|
|
961
|
+
if method_name == 'heappush':
|
|
962
|
+
result = __tracecode_heapq.heappush(target, *args, **kwargs)
|
|
963
|
+
elif method_name == 'heappop':
|
|
964
|
+
result = __tracecode_heapq.heappop(target, *args, **kwargs)
|
|
965
|
+
else:
|
|
966
|
+
return getattr(__tracecode_heapq, method_name)(target, *args, **kwargs)
|
|
967
|
+
if normalized:
|
|
968
|
+
__tracecode_record_access(
|
|
969
|
+
sys._getframe(1),
|
|
970
|
+
__tracecode_make_access_event(var_name, 'mutating-call', normalized, method_name, args=[_serialize(arg) for arg in args]),
|
|
971
|
+
)
|
|
972
|
+
else:
|
|
973
|
+
__tracecode_record_access(
|
|
974
|
+
sys._getframe(1),
|
|
975
|
+
__tracecode_make_access_event(var_name, 'mutating-call', method_name=method_name, args=[_serialize(arg) for arg in args]),
|
|
976
|
+
)
|
|
977
|
+
return result
|
|
978
|
+
|
|
979
|
+
def _tracecode_read_attr(var_name, obj, attr_name):
|
|
980
|
+
value = getattr(obj, attr_name)
|
|
981
|
+
__tracecode_record_access(
|
|
982
|
+
sys._getframe(1),
|
|
983
|
+
__tracecode_make_access_event(var_name, 'indexed-read', [attr_name], value=_serialize(value)),
|
|
984
|
+
)
|
|
985
|
+
return value
|
|
986
|
+
|
|
987
|
+
def _tracecode_len(var_name, obj):
|
|
988
|
+
value = len(obj)
|
|
989
|
+
__tracecode_record_access(
|
|
990
|
+
sys._getframe(1),
|
|
991
|
+
__tracecode_make_access_event(var_name, 'indexed-read', ['len'], value=value),
|
|
992
|
+
)
|
|
993
|
+
return value
|
|
994
|
+
|
|
995
|
+
def _tracecode_write_attr(var_name, obj, attr_name, value):
|
|
996
|
+
setattr(obj, attr_name, value)
|
|
997
|
+
__tracecode_record_access(
|
|
998
|
+
sys._getframe(1),
|
|
999
|
+
__tracecode_make_access_event(var_name, 'indexed-write', [attr_name], value=_serialize(value)),
|
|
1000
|
+
)
|
|
1001
|
+
return value
|
|
1002
|
+
|
|
1003
|
+
def _tracecode_contains_key(var_name, container, key, key_source=None):
|
|
1004
|
+
result = key in container
|
|
1005
|
+
__tracecode_record_access(
|
|
1006
|
+
sys._getframe(1),
|
|
1007
|
+
__tracecode_make_access_event(
|
|
1008
|
+
var_name,
|
|
1009
|
+
'indexed-read',
|
|
1010
|
+
[key] if isinstance(key, (int, _builtins.str)) else None,
|
|
1011
|
+
index_sources=[key_source] if isinstance(key_source, _builtins.str) and key_source else None,
|
|
1012
|
+
value=result,
|
|
1013
|
+
),
|
|
1014
|
+
)
|
|
549
1015
|
return result
|
|
550
1016
|
|
|
1017
|
+
def _tracecode_dict_get(var_name, container, key, default=None):
|
|
1018
|
+
result = container.get(key, default)
|
|
1019
|
+
__tracecode_record_access(
|
|
1020
|
+
sys._getframe(1),
|
|
1021
|
+
__tracecode_make_access_event(var_name, 'indexed-read', [key] if isinstance(key, (int, _builtins.str)) else None),
|
|
1022
|
+
)
|
|
1023
|
+
return result
|
|
1024
|
+
|
|
1025
|
+
def _tracecode_dict_get_indexed(var_name, container, indices, key, default=None):
|
|
1026
|
+
target = __tracecode_read_value(container, list(indices))
|
|
1027
|
+
result = target.get(key, default)
|
|
1028
|
+
access_indices = list(indices) + [key]
|
|
1029
|
+
__tracecode_record_access(
|
|
1030
|
+
sys._getframe(1),
|
|
1031
|
+
__tracecode_make_access_event(
|
|
1032
|
+
var_name,
|
|
1033
|
+
'indexed-read',
|
|
1034
|
+
access_indices if __tracecode_normalize_indices(access_indices) is not None else None,
|
|
1035
|
+
),
|
|
1036
|
+
)
|
|
1037
|
+
return result
|
|
1038
|
+
|
|
1039
|
+
def _tracecode_enumerate(var_name, container, binding_name=None, index_binding_name=None, *args, **kwargs):
|
|
1040
|
+
for offset, (index, value) in enumerate(enumerate(container, *args, **kwargs)):
|
|
1041
|
+
if isinstance(index_binding_name, _builtins.str) and index_binding_name:
|
|
1042
|
+
__tracecode_record_access(
|
|
1043
|
+
sys._getframe(1),
|
|
1044
|
+
__tracecode_make_access_event(index_binding_name, 'indexed-write', value=_serialize(index)),
|
|
1045
|
+
)
|
|
1046
|
+
__tracecode_record_access(
|
|
1047
|
+
sys._getframe(1),
|
|
1048
|
+
__tracecode_make_access_event(
|
|
1049
|
+
var_name,
|
|
1050
|
+
'indexed-read',
|
|
1051
|
+
[offset],
|
|
1052
|
+
binding={'kind': 'iteration', 'variable': binding_name} if isinstance(binding_name, _builtins.str) and binding_name else None,
|
|
1053
|
+
value=value,
|
|
1054
|
+
index_sources=[index_binding_name] if isinstance(index_binding_name, _builtins.str) and index_binding_name else None,
|
|
1055
|
+
),
|
|
1056
|
+
)
|
|
1057
|
+
yield index, value
|
|
1058
|
+
|
|
1059
|
+
def _tracecode_iter_bind(var_name, container, binding_name):
|
|
1060
|
+
for index, value in enumerate(container):
|
|
1061
|
+
__tracecode_record_access(
|
|
1062
|
+
sys._getframe(1),
|
|
1063
|
+
__tracecode_make_access_event(
|
|
1064
|
+
var_name,
|
|
1065
|
+
'indexed-read',
|
|
1066
|
+
[index],
|
|
1067
|
+
binding={'kind': 'iteration', 'variable': binding_name},
|
|
1068
|
+
value=value,
|
|
1069
|
+
),
|
|
1070
|
+
)
|
|
1071
|
+
yield value
|
|
1072
|
+
|
|
1073
|
+
def _tracecode_iter_bind_indexed(var_name, container, base_indices, index_sources, binding_name):
|
|
1074
|
+
effective_base_indices = list(base_indices)
|
|
1075
|
+
normalized_base = __tracecode_normalize_indices(effective_base_indices)
|
|
1076
|
+
normalized_sources = list(index_sources) if isinstance(index_sources, _builtins.list) else []
|
|
1077
|
+
for index, value in enumerate(container):
|
|
1078
|
+
if normalized_base is not None:
|
|
1079
|
+
__tracecode_record_access(
|
|
1080
|
+
sys._getframe(1),
|
|
1081
|
+
__tracecode_make_access_event(
|
|
1082
|
+
var_name,
|
|
1083
|
+
'cell-read' if len(normalized_base) + 1 == 2 else 'indexed-read',
|
|
1084
|
+
[*normalized_base, index],
|
|
1085
|
+
binding={'kind': 'iteration', 'variable': binding_name},
|
|
1086
|
+
value=value,
|
|
1087
|
+
index_sources=[*normalized_sources, None],
|
|
1088
|
+
),
|
|
1089
|
+
)
|
|
1090
|
+
yield value
|
|
1091
|
+
|
|
1092
|
+
def _tracecode_iter_bind_slice(var_name, container, start, binding_name):
|
|
1093
|
+
offset = start if isinstance(start, int) and start >= 0 else 0
|
|
1094
|
+
for index, value in enumerate(container[offset:]):
|
|
1095
|
+
__tracecode_record_access(
|
|
1096
|
+
sys._getframe(1),
|
|
1097
|
+
__tracecode_make_access_event(
|
|
1098
|
+
var_name,
|
|
1099
|
+
'indexed-read',
|
|
1100
|
+
[offset + index],
|
|
1101
|
+
binding={'kind': 'iteration', 'variable': binding_name},
|
|
1102
|
+
value=value,
|
|
1103
|
+
),
|
|
1104
|
+
)
|
|
1105
|
+
yield value
|
|
1106
|
+
|
|
1107
|
+
def _tracecode_range_bind(binding_name, iterable):
|
|
1108
|
+
for value in iterable:
|
|
1109
|
+
__tracecode_record_access(
|
|
1110
|
+
sys._getframe(1),
|
|
1111
|
+
__tracecode_make_access_event(binding_name, 'indexed-write', value=_serialize(value)),
|
|
1112
|
+
)
|
|
1113
|
+
yield value
|
|
1114
|
+
|
|
1115
|
+
def _tracecode_for_target_binding_name(target):
|
|
1116
|
+
if isinstance(target, ast.Name):
|
|
1117
|
+
return target.id
|
|
1118
|
+
if isinstance(target, (ast.Tuple, ast.List)):
|
|
1119
|
+
names = []
|
|
1120
|
+
for element in target.elts:
|
|
1121
|
+
if not isinstance(element, ast.Name):
|
|
1122
|
+
return None
|
|
1123
|
+
names.append(element.id)
|
|
1124
|
+
return ','.join(names) if names else None
|
|
1125
|
+
return None
|
|
1126
|
+
|
|
1127
|
+
def _tracecode_scalar_target_names(target):
|
|
1128
|
+
if isinstance(target, ast.Name):
|
|
1129
|
+
return [target.id]
|
|
1130
|
+
if isinstance(target, (ast.Tuple, ast.List)):
|
|
1131
|
+
names = []
|
|
1132
|
+
for element in target.elts:
|
|
1133
|
+
names.extend(_tracecode_scalar_target_names(element))
|
|
1134
|
+
return names
|
|
1135
|
+
return []
|
|
1136
|
+
|
|
1137
|
+
def _tracecode_exception_value(line_number, error):
|
|
1138
|
+
frame = sys._getframe(1)
|
|
1139
|
+
TraceHooks.flush_completed_line(frame)
|
|
1140
|
+
__tracecode_append_trace_step(frame, {
|
|
1141
|
+
'line': line_number,
|
|
1142
|
+
'event': 'exception',
|
|
1143
|
+
'variables': {},
|
|
1144
|
+
'function': frame.f_code.co_name,
|
|
1145
|
+
'callStack': _snapshot_call_stack(),
|
|
1146
|
+
'returnValue': str(error),
|
|
1147
|
+
})
|
|
1148
|
+
return error
|
|
1149
|
+
|
|
551
1150
|
def __tracecode_attach_parents(node, parent=None):
|
|
552
1151
|
for child in ast.iter_child_nodes(node):
|
|
553
1152
|
setattr(child, '__trace_parent__', node)
|
|
@@ -559,12 +1158,260 @@ def _tracecode_extract_named_subscript(node):
|
|
|
559
1158
|
while isinstance(current, ast.Subscript) and len(indices) < 3:
|
|
560
1159
|
indices.insert(0, current.slice)
|
|
561
1160
|
current = current.value
|
|
1161
|
+
while isinstance(current, ast.Attribute) and len(indices) < 3:
|
|
1162
|
+
indices.insert(0, ast.Constant(value=current.attr))
|
|
1163
|
+
current = current.value
|
|
562
1164
|
if not isinstance(current, ast.Name) or len(indices) == 0 or len(indices) > 2:
|
|
563
1165
|
return None
|
|
564
1166
|
return current.id, indices
|
|
565
1167
|
|
|
1168
|
+
def _tracecode_index_source_node(index):
|
|
1169
|
+
if isinstance(index, ast.Name):
|
|
1170
|
+
return ast.Constant(value=index.id)
|
|
1171
|
+
has_name = False
|
|
1172
|
+
for child in ast.walk(index):
|
|
1173
|
+
if isinstance(child, ast.Name):
|
|
1174
|
+
has_name = True
|
|
1175
|
+
break
|
|
1176
|
+
if has_name:
|
|
1177
|
+
try:
|
|
1178
|
+
return ast.Constant(value=ast.unparse(index).strip())
|
|
1179
|
+
except Exception:
|
|
1180
|
+
return ast.Constant(value=None)
|
|
1181
|
+
return ast.Constant(value=None)
|
|
1182
|
+
|
|
1183
|
+
def _tracecode_extract_named_attribute(node):
|
|
1184
|
+
if isinstance(node, ast.Attribute) and isinstance(node.value, ast.Name):
|
|
1185
|
+
return node.value.id, node.attr
|
|
1186
|
+
return None
|
|
1187
|
+
|
|
1188
|
+
def _tracecode_extract_mutable_container_target(node):
|
|
1189
|
+
if isinstance(node, ast.Name):
|
|
1190
|
+
return node.id, ast.Name(id=node.id, ctx=ast.Load()), []
|
|
1191
|
+
extracted = _tracecode_extract_named_subscript(node)
|
|
1192
|
+
if extracted is not None:
|
|
1193
|
+
var_name, indices = extracted
|
|
1194
|
+
return var_name, ast.Name(id=var_name, ctx=ast.Load()), indices
|
|
1195
|
+
attr_extracted = _tracecode_extract_named_attribute(node)
|
|
1196
|
+
if attr_extracted is not None:
|
|
1197
|
+
var_name, attr_name = attr_extracted
|
|
1198
|
+
return var_name, ast.Name(id=var_name, ctx=ast.Load()), [ast.Constant(value=attr_name)]
|
|
1199
|
+
return None
|
|
1200
|
+
|
|
1201
|
+
def _tracecode_is_annotation_node(node):
|
|
1202
|
+
current = node
|
|
1203
|
+
parent = getattr(current, '__trace_parent__', None)
|
|
1204
|
+
while parent is not None:
|
|
1205
|
+
if (
|
|
1206
|
+
(isinstance(parent, ast.arg) and getattr(parent, 'annotation', None) is current) or
|
|
1207
|
+
(isinstance(parent, ast.AnnAssign) and getattr(parent, 'annotation', None) is current) or
|
|
1208
|
+
(isinstance(parent, (ast.FunctionDef, ast.AsyncFunctionDef)) and getattr(parent, 'returns', None) is current)
|
|
1209
|
+
):
|
|
1210
|
+
return True
|
|
1211
|
+
current = parent
|
|
1212
|
+
parent = getattr(current, '__trace_parent__', None)
|
|
1213
|
+
return False
|
|
1214
|
+
|
|
566
1215
|
class __TracecodeAccessTransformer(ast.NodeTransformer):
|
|
1216
|
+
def _tracecode_wrap_comprehension_generators(self, generators):
|
|
1217
|
+
for generator in generators:
|
|
1218
|
+
binding_name = _tracecode_for_target_binding_name(generator.target)
|
|
1219
|
+
if binding_name is None:
|
|
1220
|
+
continue
|
|
1221
|
+
if (
|
|
1222
|
+
isinstance(generator.iter, ast.Name)
|
|
1223
|
+
):
|
|
1224
|
+
var_name = generator.iter.id
|
|
1225
|
+
generator.iter = ast.copy_location(
|
|
1226
|
+
ast.Call(
|
|
1227
|
+
func=ast.Name(id='_tracecode_iter_bind', ctx=ast.Load()),
|
|
1228
|
+
args=[
|
|
1229
|
+
ast.Constant(value=var_name),
|
|
1230
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1231
|
+
ast.Constant(value=binding_name),
|
|
1232
|
+
],
|
|
1233
|
+
keywords=[],
|
|
1234
|
+
),
|
|
1235
|
+
generator.iter,
|
|
1236
|
+
)
|
|
1237
|
+
continue
|
|
1238
|
+
if (
|
|
1239
|
+
isinstance(generator.iter, ast.Call) and
|
|
1240
|
+
isinstance(generator.iter.func, ast.Name) and
|
|
1241
|
+
generator.iter.func.id == 'enumerate' and
|
|
1242
|
+
len(generator.iter.args) >= 1 and
|
|
1243
|
+
isinstance(generator.iter.args[0], ast.Name)
|
|
1244
|
+
):
|
|
1245
|
+
var_name = generator.iter.args[0].id
|
|
1246
|
+
index_binding_name = None
|
|
1247
|
+
value_binding_name = binding_name
|
|
1248
|
+
if (
|
|
1249
|
+
isinstance(generator.target, ast.Tuple) and
|
|
1250
|
+
len(generator.target.elts) >= 2 and
|
|
1251
|
+
isinstance(generator.target.elts[0], ast.Name) and
|
|
1252
|
+
isinstance(generator.target.elts[1], ast.Name)
|
|
1253
|
+
):
|
|
1254
|
+
index_binding_name = generator.target.elts[0].id
|
|
1255
|
+
value_binding_name = generator.target.elts[1].id
|
|
1256
|
+
generator.iter = ast.copy_location(
|
|
1257
|
+
ast.Call(
|
|
1258
|
+
func=ast.Name(id='_tracecode_enumerate', ctx=ast.Load()),
|
|
1259
|
+
args=[
|
|
1260
|
+
ast.Constant(value=var_name),
|
|
1261
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1262
|
+
ast.Constant(value=value_binding_name),
|
|
1263
|
+
ast.Constant(value=index_binding_name),
|
|
1264
|
+
*generator.iter.args[1:],
|
|
1265
|
+
],
|
|
1266
|
+
keywords=generator.iter.keywords,
|
|
1267
|
+
),
|
|
1268
|
+
generator.iter,
|
|
1269
|
+
)
|
|
1270
|
+
|
|
1271
|
+
def visit_ListComp(self, node):
|
|
1272
|
+
node = self.generic_visit(node)
|
|
1273
|
+
self._tracecode_wrap_comprehension_generators(node.generators)
|
|
1274
|
+
return node
|
|
1275
|
+
|
|
1276
|
+
def visit_DictComp(self, node):
|
|
1277
|
+
node = self.generic_visit(node)
|
|
1278
|
+
self._tracecode_wrap_comprehension_generators(node.generators)
|
|
1279
|
+
return node
|
|
1280
|
+
|
|
1281
|
+
def visit_SetComp(self, node):
|
|
1282
|
+
node = self.generic_visit(node)
|
|
1283
|
+
self._tracecode_wrap_comprehension_generators(node.generators)
|
|
1284
|
+
return node
|
|
1285
|
+
|
|
1286
|
+
def visit_For(self, node):
|
|
1287
|
+
original_iter = node.iter
|
|
1288
|
+
node = self.generic_visit(node)
|
|
1289
|
+
binding_name = _tracecode_for_target_binding_name(node.target)
|
|
1290
|
+
if (
|
|
1291
|
+
isinstance(node.iter, ast.Name) and
|
|
1292
|
+
binding_name is not None
|
|
1293
|
+
):
|
|
1294
|
+
var_name = node.iter.id
|
|
1295
|
+
node.iter = ast.copy_location(
|
|
1296
|
+
ast.Call(
|
|
1297
|
+
func=ast.Name(id='_tracecode_iter_bind', ctx=ast.Load()),
|
|
1298
|
+
args=[
|
|
1299
|
+
ast.Constant(value=var_name),
|
|
1300
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1301
|
+
ast.Constant(value=binding_name),
|
|
1302
|
+
],
|
|
1303
|
+
keywords=[],
|
|
1304
|
+
),
|
|
1305
|
+
node.iter,
|
|
1306
|
+
)
|
|
1307
|
+
return node
|
|
1308
|
+
if (
|
|
1309
|
+
isinstance(original_iter, ast.Subscript) and
|
|
1310
|
+
isinstance(original_iter.value, ast.Name) and
|
|
1311
|
+
not isinstance(original_iter.slice, ast.Slice) and
|
|
1312
|
+
binding_name is not None
|
|
1313
|
+
):
|
|
1314
|
+
var_name = original_iter.value.id
|
|
1315
|
+
extracted = _tracecode_extract_named_subscript(original_iter)
|
|
1316
|
+
if extracted is not None:
|
|
1317
|
+
_, indices = extracted
|
|
1318
|
+
node.iter = ast.copy_location(
|
|
1319
|
+
ast.Call(
|
|
1320
|
+
func=ast.Name(id='_tracecode_iter_bind_indexed', ctx=ast.Load()),
|
|
1321
|
+
args=[
|
|
1322
|
+
ast.Constant(value=var_name),
|
|
1323
|
+
node.iter,
|
|
1324
|
+
ast.List(elts=[self.visit(index) for index in indices], ctx=ast.Load()),
|
|
1325
|
+
ast.List(elts=[_tracecode_index_source_node(index) for index in indices], ctx=ast.Load()),
|
|
1326
|
+
ast.Constant(value=binding_name),
|
|
1327
|
+
],
|
|
1328
|
+
keywords=[],
|
|
1329
|
+
),
|
|
1330
|
+
node.iter,
|
|
1331
|
+
)
|
|
1332
|
+
return node
|
|
1333
|
+
if (
|
|
1334
|
+
isinstance(original_iter, ast.Subscript) and
|
|
1335
|
+
isinstance(original_iter.value, ast.Name) and
|
|
1336
|
+
isinstance(original_iter.slice, ast.Slice) and
|
|
1337
|
+
isinstance(original_iter.slice.lower, ast.Constant) and
|
|
1338
|
+
isinstance(original_iter.slice.lower.value, int) and
|
|
1339
|
+
original_iter.slice.upper is None and
|
|
1340
|
+
original_iter.slice.step is None and
|
|
1341
|
+
binding_name is not None
|
|
1342
|
+
):
|
|
1343
|
+
var_name = original_iter.value.id
|
|
1344
|
+
node.iter = ast.copy_location(
|
|
1345
|
+
ast.Call(
|
|
1346
|
+
func=ast.Name(id='_tracecode_iter_bind_slice', ctx=ast.Load()),
|
|
1347
|
+
args=[
|
|
1348
|
+
ast.Constant(value=var_name),
|
|
1349
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1350
|
+
ast.Constant(value=original_iter.slice.lower.value),
|
|
1351
|
+
ast.Constant(value=binding_name),
|
|
1352
|
+
],
|
|
1353
|
+
keywords=[],
|
|
1354
|
+
),
|
|
1355
|
+
node.iter,
|
|
1356
|
+
)
|
|
1357
|
+
return node
|
|
1358
|
+
if (
|
|
1359
|
+
isinstance(node.iter, ast.Call) and
|
|
1360
|
+
isinstance(node.iter.func, ast.Name) and
|
|
1361
|
+
node.iter.func.id == 'range' and
|
|
1362
|
+
isinstance(node.target, ast.Name)
|
|
1363
|
+
):
|
|
1364
|
+
binding_name = node.target.id
|
|
1365
|
+
node.iter = ast.copy_location(
|
|
1366
|
+
ast.Call(
|
|
1367
|
+
func=ast.Name(id='_tracecode_range_bind', ctx=ast.Load()),
|
|
1368
|
+
args=[
|
|
1369
|
+
ast.Constant(value=binding_name),
|
|
1370
|
+
node.iter,
|
|
1371
|
+
],
|
|
1372
|
+
keywords=[],
|
|
1373
|
+
),
|
|
1374
|
+
node.iter,
|
|
1375
|
+
)
|
|
1376
|
+
return node
|
|
1377
|
+
if (
|
|
1378
|
+
isinstance(node.iter, ast.Call) and
|
|
1379
|
+
isinstance(node.iter.func, ast.Name) and
|
|
1380
|
+
node.iter.func.id == 'enumerate' and
|
|
1381
|
+
len(node.iter.args) >= 1 and
|
|
1382
|
+
isinstance(node.iter.args[0], ast.Name)
|
|
1383
|
+
):
|
|
1384
|
+
var_name = node.iter.args[0].id
|
|
1385
|
+
binding_name = None
|
|
1386
|
+
if (
|
|
1387
|
+
isinstance(node.target, ast.Tuple) and
|
|
1388
|
+
len(node.target.elts) >= 2 and
|
|
1389
|
+
isinstance(node.target.elts[0], ast.Name) and
|
|
1390
|
+
isinstance(node.target.elts[1], ast.Name)
|
|
1391
|
+
):
|
|
1392
|
+
index_binding_name = node.target.elts[0].id
|
|
1393
|
+
binding_name = node.target.elts[1].id
|
|
1394
|
+
else:
|
|
1395
|
+
index_binding_name = None
|
|
1396
|
+
node.iter = ast.copy_location(
|
|
1397
|
+
ast.Call(
|
|
1398
|
+
func=ast.Name(id='_tracecode_enumerate', ctx=ast.Load()),
|
|
1399
|
+
args=[
|
|
1400
|
+
ast.Constant(value=var_name),
|
|
1401
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1402
|
+
ast.Constant(value=binding_name),
|
|
1403
|
+
ast.Constant(value=index_binding_name),
|
|
1404
|
+
*node.iter.args[1:],
|
|
1405
|
+
],
|
|
1406
|
+
keywords=node.iter.keywords,
|
|
1407
|
+
),
|
|
1408
|
+
node.iter,
|
|
1409
|
+
)
|
|
1410
|
+
return node
|
|
1411
|
+
|
|
567
1412
|
def visit_Subscript(self, node):
|
|
1413
|
+
if _tracecode_is_annotation_node(node):
|
|
1414
|
+
return self.generic_visit(node)
|
|
568
1415
|
parent = getattr(node, '__trace_parent__', None)
|
|
569
1416
|
if isinstance(parent, ast.Subscript) and getattr(parent, 'value', None) is node:
|
|
570
1417
|
return self.generic_visit(node)
|
|
@@ -573,18 +1420,19 @@ class __TracecodeAccessTransformer(ast.NodeTransformer):
|
|
|
573
1420
|
if isinstance(parent, ast.AugAssign) and getattr(parent, 'target', None) is node:
|
|
574
1421
|
return self.generic_visit(node)
|
|
575
1422
|
|
|
576
|
-
node = self.generic_visit(node)
|
|
577
1423
|
extracted = _tracecode_extract_named_subscript(node)
|
|
578
1424
|
if extracted is None or not isinstance(node.ctx, ast.Load):
|
|
579
|
-
return node
|
|
1425
|
+
return self.generic_visit(node)
|
|
580
1426
|
|
|
581
1427
|
var_name, indices = extracted
|
|
1428
|
+
index_sources = [_tracecode_index_source_node(index) for index in indices]
|
|
582
1429
|
call = ast.Call(
|
|
583
1430
|
func=ast.Name(id='_tracecode_read_index', ctx=ast.Load()),
|
|
584
1431
|
args=[
|
|
585
1432
|
ast.Constant(value=var_name),
|
|
586
1433
|
ast.Name(id=var_name, ctx=ast.Load()),
|
|
587
|
-
ast.List(elts=indices, ctx=ast.Load()),
|
|
1434
|
+
ast.List(elts=[self.visit(index) for index in indices], ctx=ast.Load()),
|
|
1435
|
+
ast.List(elts=index_sources, ctx=ast.Load()),
|
|
588
1436
|
],
|
|
589
1437
|
keywords=[],
|
|
590
1438
|
)
|
|
@@ -595,6 +1443,7 @@ class __TracecodeAccessTransformer(ast.NodeTransformer):
|
|
|
595
1443
|
extracted = _tracecode_extract_named_subscript(node.targets[0])
|
|
596
1444
|
if extracted is not None:
|
|
597
1445
|
var_name, indices = extracted
|
|
1446
|
+
index_sources = [_tracecode_index_source_node(index) for index in indices]
|
|
598
1447
|
value = self.visit(node.value)
|
|
599
1448
|
call = ast.Call(
|
|
600
1449
|
func=ast.Name(id='_tracecode_write_index', ctx=ast.Load()),
|
|
@@ -602,16 +1451,86 @@ class __TracecodeAccessTransformer(ast.NodeTransformer):
|
|
|
602
1451
|
ast.Constant(value=var_name),
|
|
603
1452
|
ast.Name(id=var_name, ctx=ast.Load()),
|
|
604
1453
|
ast.List(elts=[self.visit(index) for index in indices], ctx=ast.Load()),
|
|
1454
|
+
ast.List(elts=index_sources, ctx=ast.Load()),
|
|
1455
|
+
value,
|
|
1456
|
+
],
|
|
1457
|
+
keywords=[],
|
|
1458
|
+
)
|
|
1459
|
+
return ast.copy_location(ast.Expr(value=call), node)
|
|
1460
|
+
attr_extracted = _tracecode_extract_named_attribute(node.targets[0])
|
|
1461
|
+
if attr_extracted is not None:
|
|
1462
|
+
var_name, attr_name = attr_extracted
|
|
1463
|
+
value = self.visit(node.value)
|
|
1464
|
+
call = ast.Call(
|
|
1465
|
+
func=ast.Name(id='_tracecode_write_attr', ctx=ast.Load()),
|
|
1466
|
+
args=[
|
|
1467
|
+
ast.Constant(value=var_name),
|
|
1468
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1469
|
+
ast.Constant(value=attr_name),
|
|
605
1470
|
value,
|
|
606
1471
|
],
|
|
607
1472
|
keywords=[],
|
|
608
1473
|
)
|
|
609
1474
|
return ast.copy_location(ast.Expr(value=call), node)
|
|
1475
|
+
if isinstance(node.targets[0], ast.Name):
|
|
1476
|
+
visited = self.generic_visit(node)
|
|
1477
|
+
var_name = node.targets[0].id
|
|
1478
|
+
call = ast.Expr(value=ast.Call(
|
|
1479
|
+
func=ast.Name(id='_tracecode_write_scalar', ctx=ast.Load()),
|
|
1480
|
+
args=[
|
|
1481
|
+
ast.Constant(value=var_name),
|
|
1482
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1483
|
+
],
|
|
1484
|
+
keywords=[],
|
|
1485
|
+
))
|
|
1486
|
+
return [visited, ast.copy_location(call, node)]
|
|
1487
|
+
scalar_names = _tracecode_scalar_target_names(node.targets[0])
|
|
1488
|
+
if scalar_names:
|
|
1489
|
+
visited = self.generic_visit(node)
|
|
1490
|
+
writes = []
|
|
1491
|
+
for scalar_name in scalar_names:
|
|
1492
|
+
write_call = ast.Expr(value=ast.Call(
|
|
1493
|
+
func=ast.Name(id='_tracecode_write_scalar', ctx=ast.Load()),
|
|
1494
|
+
args=[
|
|
1495
|
+
ast.Constant(value=scalar_name),
|
|
1496
|
+
ast.Name(id=scalar_name, ctx=ast.Load()),
|
|
1497
|
+
],
|
|
1498
|
+
keywords=[],
|
|
1499
|
+
))
|
|
1500
|
+
writes.append(ast.copy_location(write_call, node))
|
|
1501
|
+
return [visited, *writes]
|
|
1502
|
+
return self.generic_visit(node)
|
|
1503
|
+
|
|
1504
|
+
def visit_AnnAssign(self, node):
|
|
1505
|
+
if isinstance(node.target, ast.Name) and node.value is not None:
|
|
1506
|
+
visited = self.generic_visit(node)
|
|
1507
|
+
var_name = node.target.id
|
|
1508
|
+
call = ast.Expr(value=ast.Call(
|
|
1509
|
+
func=ast.Name(id='_tracecode_write_scalar', ctx=ast.Load()),
|
|
1510
|
+
args=[
|
|
1511
|
+
ast.Constant(value=var_name),
|
|
1512
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1513
|
+
],
|
|
1514
|
+
keywords=[],
|
|
1515
|
+
))
|
|
1516
|
+
return [visited, ast.copy_location(call, node)]
|
|
610
1517
|
return self.generic_visit(node)
|
|
611
1518
|
|
|
612
1519
|
def visit_AugAssign(self, node):
|
|
613
1520
|
extracted = _tracecode_extract_named_subscript(node.target)
|
|
614
1521
|
if extracted is None:
|
|
1522
|
+
if isinstance(node.target, ast.Name):
|
|
1523
|
+
visited = self.generic_visit(node)
|
|
1524
|
+
var_name = node.target.id
|
|
1525
|
+
call = ast.Expr(value=ast.Call(
|
|
1526
|
+
func=ast.Name(id='_tracecode_write_scalar', ctx=ast.Load()),
|
|
1527
|
+
args=[
|
|
1528
|
+
ast.Constant(value=var_name),
|
|
1529
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1530
|
+
],
|
|
1531
|
+
keywords=[],
|
|
1532
|
+
))
|
|
1533
|
+
return [visited, ast.copy_location(call, node)]
|
|
615
1534
|
return self.generic_visit(node)
|
|
616
1535
|
|
|
617
1536
|
op_names = {
|
|
@@ -633,6 +1552,7 @@ class __TracecodeAccessTransformer(ast.NodeTransformer):
|
|
|
633
1552
|
return self.generic_visit(node)
|
|
634
1553
|
|
|
635
1554
|
var_name, indices = extracted
|
|
1555
|
+
index_sources = [_tracecode_index_source_node(index) for index in indices]
|
|
636
1556
|
rhs = self.visit(node.value)
|
|
637
1557
|
call = ast.Call(
|
|
638
1558
|
func=ast.Name(id='_tracecode_augassign_index', ctx=ast.Load()),
|
|
@@ -640,6 +1560,7 @@ class __TracecodeAccessTransformer(ast.NodeTransformer):
|
|
|
640
1560
|
ast.Constant(value=var_name),
|
|
641
1561
|
ast.Name(id=var_name, ctx=ast.Load()),
|
|
642
1562
|
ast.List(elts=[self.visit(index) for index in indices], ctx=ast.Load()),
|
|
1563
|
+
ast.List(elts=index_sources, ctx=ast.Load()),
|
|
643
1564
|
ast.Constant(value=op_name),
|
|
644
1565
|
rhs,
|
|
645
1566
|
],
|
|
@@ -647,22 +1568,103 @@ class __TracecodeAccessTransformer(ast.NodeTransformer):
|
|
|
647
1568
|
)
|
|
648
1569
|
return ast.copy_location(ast.Expr(value=call), node)
|
|
649
1570
|
|
|
1571
|
+
def visit_Delete(self, node):
|
|
1572
|
+
if len(node.targets) != 1:
|
|
1573
|
+
return self.generic_visit(node)
|
|
1574
|
+
extracted = _tracecode_extract_named_subscript(node.targets[0])
|
|
1575
|
+
if extracted is None:
|
|
1576
|
+
return self.generic_visit(node)
|
|
1577
|
+
var_name, indices = extracted
|
|
1578
|
+
index_sources = [_tracecode_index_source_node(index) for index in indices]
|
|
1579
|
+
call = ast.Call(
|
|
1580
|
+
func=ast.Name(id='_tracecode_delete_index', ctx=ast.Load()),
|
|
1581
|
+
args=[
|
|
1582
|
+
ast.Constant(value=var_name),
|
|
1583
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1584
|
+
ast.List(elts=[self.visit(index) for index in indices], ctx=ast.Load()),
|
|
1585
|
+
ast.List(elts=index_sources, ctx=ast.Load()),
|
|
1586
|
+
],
|
|
1587
|
+
keywords=[],
|
|
1588
|
+
)
|
|
1589
|
+
return ast.copy_location(ast.Expr(value=call), node)
|
|
1590
|
+
|
|
650
1591
|
def visit_Call(self, node):
|
|
1592
|
+
if (
|
|
1593
|
+
isinstance(node.func, ast.Name) and
|
|
1594
|
+
node.func.id == 'len' and
|
|
1595
|
+
len(node.args) == 1 and
|
|
1596
|
+
isinstance(node.args[0], ast.Name)
|
|
1597
|
+
):
|
|
1598
|
+
var_name = node.args[0].id
|
|
1599
|
+
call = ast.Call(
|
|
1600
|
+
func=ast.Name(id='_tracecode_len', ctx=ast.Load()),
|
|
1601
|
+
args=[
|
|
1602
|
+
ast.Constant(value=var_name),
|
|
1603
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1604
|
+
],
|
|
1605
|
+
keywords=[],
|
|
1606
|
+
)
|
|
1607
|
+
return ast.copy_location(call, node)
|
|
1608
|
+
|
|
1609
|
+
if (
|
|
1610
|
+
isinstance(node.func, ast.Attribute) and
|
|
1611
|
+
node.func.attr == 'get'
|
|
1612
|
+
):
|
|
1613
|
+
extracted = _tracecode_extract_mutable_container_target(node.func.value)
|
|
1614
|
+
if extracted is not None and len(extracted[2]) > 0:
|
|
1615
|
+
var_name, container, indices = extracted
|
|
1616
|
+
call = ast.Call(
|
|
1617
|
+
func=ast.Name(id='_tracecode_dict_get_indexed', ctx=ast.Load()),
|
|
1618
|
+
args=[
|
|
1619
|
+
ast.Constant(value=var_name),
|
|
1620
|
+
container,
|
|
1621
|
+
ast.List(elts=[self.visit(index) for index in indices], ctx=ast.Load()),
|
|
1622
|
+
*[self.visit(arg) for arg in node.args],
|
|
1623
|
+
],
|
|
1624
|
+
keywords=[self.visit(keyword) for keyword in node.keywords],
|
|
1625
|
+
)
|
|
1626
|
+
return ast.copy_location(call, node)
|
|
1627
|
+
|
|
1628
|
+
if (
|
|
1629
|
+
isinstance(node.func, ast.Attribute) and
|
|
1630
|
+
isinstance(node.func.value, ast.Name) and
|
|
1631
|
+
node.func.value.id == 'heapq' and
|
|
1632
|
+
node.func.attr in {'heappush', 'heappop'} and
|
|
1633
|
+
len(node.args) >= 1
|
|
1634
|
+
):
|
|
1635
|
+
extracted_heap = _tracecode_extract_mutable_container_target(node.args[0])
|
|
1636
|
+
if extracted_heap is not None:
|
|
1637
|
+
var_name, container, indices = extracted_heap
|
|
1638
|
+
call = ast.Call(
|
|
1639
|
+
func=ast.Name(id='_tracecode_heapq_mutation', ctx=ast.Load()),
|
|
1640
|
+
args=[
|
|
1641
|
+
ast.Constant(value=var_name),
|
|
1642
|
+
container,
|
|
1643
|
+
ast.List(elts=[self.visit(index) for index in indices], ctx=ast.Load()),
|
|
1644
|
+
ast.Constant(value=node.func.attr),
|
|
1645
|
+
*[self.visit(arg) for arg in node.args[1:]],
|
|
1646
|
+
],
|
|
1647
|
+
keywords=[self.visit(keyword) for keyword in node.keywords],
|
|
1648
|
+
)
|
|
1649
|
+
return ast.copy_location(call, node)
|
|
1650
|
+
|
|
651
1651
|
if isinstance(node.func, ast.Attribute):
|
|
652
1652
|
method_name = node.func.attr
|
|
653
1653
|
if method_name in _TRACE_MUTATING_METHODS:
|
|
654
1654
|
extracted = _tracecode_extract_named_subscript(node.func.value)
|
|
655
1655
|
if extracted is not None:
|
|
656
1656
|
var_name, indices = extracted
|
|
1657
|
+
index_sources = [_tracecode_index_source_node(index) for index in indices]
|
|
657
1658
|
call = ast.Call(
|
|
658
1659
|
func=ast.Name(id='_tracecode_mutating_index_call', ctx=ast.Load()),
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
],
|
|
1660
|
+
args=[
|
|
1661
|
+
ast.Constant(value=var_name),
|
|
1662
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1663
|
+
ast.List(elts=[self.visit(index) for index in indices], ctx=ast.Load()),
|
|
1664
|
+
ast.List(elts=index_sources, ctx=ast.Load()),
|
|
1665
|
+
ast.Constant(value=method_name),
|
|
1666
|
+
*[self.visit(arg) for arg in node.args],
|
|
1667
|
+
],
|
|
666
1668
|
keywords=[self.visit(keyword) for keyword in node.keywords],
|
|
667
1669
|
)
|
|
668
1670
|
return ast.copy_location(call, node)
|
|
@@ -670,6 +1672,17 @@ class __TracecodeAccessTransformer(ast.NodeTransformer):
|
|
|
670
1672
|
node = self.generic_visit(node)
|
|
671
1673
|
if isinstance(node.func, ast.Attribute) and isinstance(node.func.value, ast.Name):
|
|
672
1674
|
method_name = node.func.attr
|
|
1675
|
+
if method_name == 'get':
|
|
1676
|
+
call = ast.Call(
|
|
1677
|
+
func=ast.Name(id='_tracecode_dict_get', ctx=ast.Load()),
|
|
1678
|
+
args=[
|
|
1679
|
+
ast.Constant(value=node.func.value.id),
|
|
1680
|
+
ast.Name(id=node.func.value.id, ctx=ast.Load()),
|
|
1681
|
+
*node.args,
|
|
1682
|
+
],
|
|
1683
|
+
keywords=node.keywords,
|
|
1684
|
+
)
|
|
1685
|
+
return ast.copy_location(call, node)
|
|
673
1686
|
if method_name in _TRACE_MUTATING_METHODS:
|
|
674
1687
|
call = ast.Call(
|
|
675
1688
|
func=ast.Name(id='_tracecode_mutating_call', ctx=ast.Load()),
|
|
@@ -684,12 +1697,72 @@ class __TracecodeAccessTransformer(ast.NodeTransformer):
|
|
|
684
1697
|
return ast.copy_location(call, node)
|
|
685
1698
|
return node
|
|
686
1699
|
|
|
1700
|
+
def visit_Compare(self, node):
|
|
1701
|
+
if (
|
|
1702
|
+
len(node.ops) == 1 and
|
|
1703
|
+
len(node.comparators) == 1 and
|
|
1704
|
+
isinstance(node.ops[0], (ast.In, ast.NotIn)) and
|
|
1705
|
+
isinstance(node.comparators[0], ast.Name)
|
|
1706
|
+
):
|
|
1707
|
+
container_name = node.comparators[0].id
|
|
1708
|
+
call = ast.Call(
|
|
1709
|
+
func=ast.Name(id='_tracecode_contains_key', ctx=ast.Load()),
|
|
1710
|
+
args=[
|
|
1711
|
+
ast.Constant(value=container_name),
|
|
1712
|
+
ast.Name(id=container_name, ctx=ast.Load()),
|
|
1713
|
+
self.visit(node.left),
|
|
1714
|
+
_tracecode_index_source_node(node.left),
|
|
1715
|
+
],
|
|
1716
|
+
keywords=[],
|
|
1717
|
+
)
|
|
1718
|
+
value = ast.UnaryOp(op=ast.Not(), operand=call) if isinstance(node.ops[0], ast.NotIn) else call
|
|
1719
|
+
return ast.copy_location(value, node)
|
|
1720
|
+
return self.generic_visit(node)
|
|
1721
|
+
|
|
1722
|
+
def visit_Raise(self, node):
|
|
1723
|
+
if node.exc is None:
|
|
1724
|
+
return self.generic_visit(node)
|
|
1725
|
+
line_number = getattr(node, 'lineno', 1)
|
|
1726
|
+
call = ast.Call(
|
|
1727
|
+
func=ast.Name(id='_tracecode_exception_value', ctx=ast.Load()),
|
|
1728
|
+
args=[
|
|
1729
|
+
ast.Constant(value=line_number),
|
|
1730
|
+
self.visit(node.exc),
|
|
1731
|
+
],
|
|
1732
|
+
keywords=[],
|
|
1733
|
+
)
|
|
1734
|
+
return ast.copy_location(ast.Raise(exc=call, cause=self.visit(node.cause) if node.cause else None), node)
|
|
1735
|
+
|
|
1736
|
+
def visit_Attribute(self, node):
|
|
1737
|
+
parent = getattr(node, '__trace_parent__', None)
|
|
1738
|
+
if isinstance(parent, ast.Assign) and node in getattr(parent, 'targets', []):
|
|
1739
|
+
return self.generic_visit(node)
|
|
1740
|
+
if isinstance(parent, ast.Call) and getattr(parent, 'func', None) is node:
|
|
1741
|
+
return self.generic_visit(node)
|
|
1742
|
+
|
|
1743
|
+
node = self.generic_visit(node)
|
|
1744
|
+
extracted = _tracecode_extract_named_attribute(node)
|
|
1745
|
+
if extracted is None or not isinstance(node.ctx, ast.Load):
|
|
1746
|
+
return node
|
|
1747
|
+
|
|
1748
|
+
var_name, attr_name = extracted
|
|
1749
|
+
call = ast.Call(
|
|
1750
|
+
func=ast.Name(id='_tracecode_read_attr', ctx=ast.Load()),
|
|
1751
|
+
args=[
|
|
1752
|
+
ast.Constant(value=var_name),
|
|
1753
|
+
ast.Name(id=var_name, ctx=ast.Load()),
|
|
1754
|
+
ast.Constant(value=attr_name),
|
|
1755
|
+
],
|
|
1756
|
+
keywords=[],
|
|
1757
|
+
)
|
|
1758
|
+
return ast.copy_location(call, node)
|
|
1759
|
+
|
|
687
1760
|
def __tracecode_compile_user_code(source):
|
|
688
|
-
tree = ast.parse(source, filename='
|
|
1761
|
+
tree = ast.parse(source, filename='solution.py', mode='exec')
|
|
689
1762
|
__tracecode_attach_parents(tree)
|
|
690
1763
|
tree = __TracecodeAccessTransformer().visit(tree)
|
|
691
1764
|
ast.fix_missing_locations(tree)
|
|
692
|
-
return compile(tree, '
|
|
1765
|
+
return compile(tree, 'solution.py', 'exec')
|
|
693
1766
|
|
|
694
1767
|
def _tracecode_is_pure_literal_scaffold(node):
|
|
695
1768
|
if isinstance(node, (ast.Constant, ast.Name)):
|
|
@@ -709,7 +1782,7 @@ def _tracecode_is_pure_literal_scaffold(node):
|
|
|
709
1782
|
|
|
710
1783
|
def _tracecode_collect_collapsed_literal_lines(source):
|
|
711
1784
|
try:
|
|
712
|
-
tree = ast.parse(source, filename='
|
|
1785
|
+
tree = ast.parse(source, filename='solution.py', mode='exec')
|
|
713
1786
|
except Exception:
|
|
714
1787
|
return set()
|
|
715
1788
|
|
|
@@ -741,9 +1814,9 @@ def _stable_token(value):
|
|
|
741
1814
|
return repr(value)
|
|
742
1815
|
|
|
743
1816
|
def _looks_like_adjacency_list(value):
|
|
744
|
-
if not isinstance(value, dict) or len(value) == 0:
|
|
1817
|
+
if not isinstance(value, _builtins.dict) or len(value) == 0:
|
|
745
1818
|
return False
|
|
746
|
-
if not all(isinstance(v, list) for v in value.values()):
|
|
1819
|
+
if not all(isinstance(v, _builtins.list) for v in value.values()):
|
|
747
1820
|
return False
|
|
748
1821
|
key_set = {str(k) for k in value.keys()}
|
|
749
1822
|
has_valid_neighbor = False
|
|
@@ -757,9 +1830,9 @@ def _looks_like_adjacency_list(value):
|
|
|
757
1830
|
return has_valid_neighbor
|
|
758
1831
|
|
|
759
1832
|
def _looks_like_indexed_adjacency_list(value):
|
|
760
|
-
if not isinstance(value, list) or len(value) == 0:
|
|
1833
|
+
if not isinstance(value, _builtins.list) or len(value) == 0:
|
|
761
1834
|
return False
|
|
762
|
-
if not all(isinstance(row, list) for row in value):
|
|
1835
|
+
if not all(isinstance(row, _builtins.list) for row in value):
|
|
763
1836
|
return False
|
|
764
1837
|
|
|
765
1838
|
node_count = len(value)
|
|
@@ -784,186 +1857,6 @@ def _looks_like_indexed_adjacency_list(value):
|
|
|
784
1857
|
|
|
785
1858
|
return True
|
|
786
1859
|
|
|
787
|
-
def _extract_hashmap_snapshot(value):
|
|
788
|
-
if not isinstance(value, dict):
|
|
789
|
-
return None
|
|
790
|
-
|
|
791
|
-
value_type = value.get('__type__')
|
|
792
|
-
|
|
793
|
-
if value_type == 'set' and isinstance(value.get('values'), list):
|
|
794
|
-
_values = value.get('values') or []
|
|
795
|
-
return {
|
|
796
|
-
'kind': 'set',
|
|
797
|
-
'entries': [{'key': item, 'value': True} for item in _values],
|
|
798
|
-
'setValues': {_stable_token(item): item for item in _values},
|
|
799
|
-
}
|
|
800
|
-
|
|
801
|
-
if value_type in ('TreeNode', 'ListNode'):
|
|
802
|
-
return None
|
|
803
|
-
|
|
804
|
-
if value_type == 'map' and isinstance(value.get('entries'), list):
|
|
805
|
-
_entries = []
|
|
806
|
-
_map_values = {}
|
|
807
|
-
for entry in value.get('entries') or []:
|
|
808
|
-
if isinstance(entry, (list, tuple)) and len(entry) >= 2:
|
|
809
|
-
_key = entry[0]
|
|
810
|
-
_value = entry[1]
|
|
811
|
-
_entries.append({'key': _key, 'value': _value})
|
|
812
|
-
_map_values[str(_key)] = _value
|
|
813
|
-
return {
|
|
814
|
-
'kind': 'map',
|
|
815
|
-
'entries': _entries,
|
|
816
|
-
'mapValues': _map_values,
|
|
817
|
-
}
|
|
818
|
-
|
|
819
|
-
if value_type in ('map',):
|
|
820
|
-
return None
|
|
821
|
-
|
|
822
|
-
if '__ref__' in value and len(value) == 1:
|
|
823
|
-
return None
|
|
824
|
-
|
|
825
|
-
if _looks_like_adjacency_list(value):
|
|
826
|
-
return None
|
|
827
|
-
|
|
828
|
-
return {
|
|
829
|
-
'kind': 'hashmap',
|
|
830
|
-
'entries': [{'key': key, 'value': val} for key, val in value.items()],
|
|
831
|
-
'mapValues': {str(key): val for key, val in value.items()},
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
def _classify_runtime_object_kind(value):
|
|
835
|
-
if isinstance(value, list):
|
|
836
|
-
if _looks_like_indexed_adjacency_list(value):
|
|
837
|
-
return 'graph-adjacency'
|
|
838
|
-
return None
|
|
839
|
-
|
|
840
|
-
if not isinstance(value, dict):
|
|
841
|
-
return None
|
|
842
|
-
|
|
843
|
-
value_type = value.get('__type__')
|
|
844
|
-
if value_type == 'set' and isinstance(value.get('values'), list):
|
|
845
|
-
return 'set'
|
|
846
|
-
if value_type == 'map' and isinstance(value.get('entries'), list):
|
|
847
|
-
return 'map'
|
|
848
|
-
if value_type == 'TreeNode':
|
|
849
|
-
return 'tree'
|
|
850
|
-
if value_type == 'ListNode':
|
|
851
|
-
return 'linked-list'
|
|
852
|
-
if '__ref__' in value and len(value) == 1:
|
|
853
|
-
return None
|
|
854
|
-
if _looks_like_adjacency_list(value):
|
|
855
|
-
return 'graph-adjacency'
|
|
856
|
-
return 'hashmap'
|
|
857
|
-
|
|
858
|
-
def _infer_hashmap_delta(previous_snapshot, current_snapshot):
|
|
859
|
-
if not previous_snapshot or not current_snapshot:
|
|
860
|
-
return (None, None)
|
|
861
|
-
|
|
862
|
-
if previous_snapshot.get('kind') != current_snapshot.get('kind'):
|
|
863
|
-
return (None, None)
|
|
864
|
-
|
|
865
|
-
highlighted_key = None
|
|
866
|
-
deleted_key = None
|
|
867
|
-
|
|
868
|
-
if current_snapshot.get('kind') in ('hashmap', 'map'):
|
|
869
|
-
previous_map = previous_snapshot.get('mapValues') or {}
|
|
870
|
-
current_map = current_snapshot.get('mapValues') or {}
|
|
871
|
-
|
|
872
|
-
previous_keys = set(previous_map.keys())
|
|
873
|
-
current_keys = set(current_map.keys())
|
|
874
|
-
|
|
875
|
-
new_keys = [key for key in current_keys if key not in previous_keys]
|
|
876
|
-
removed_keys = [key for key in previous_keys if key not in current_keys]
|
|
877
|
-
changed_keys = [
|
|
878
|
-
key for key in current_keys
|
|
879
|
-
if key in previous_map and previous_map.get(key) != current_map.get(key)
|
|
880
|
-
]
|
|
881
|
-
|
|
882
|
-
if len(new_keys) == 1:
|
|
883
|
-
highlighted_key = new_keys[0]
|
|
884
|
-
elif len(changed_keys) == 1:
|
|
885
|
-
highlighted_key = changed_keys[0]
|
|
886
|
-
|
|
887
|
-
if len(removed_keys) == 1:
|
|
888
|
-
deleted_key = removed_keys[0]
|
|
889
|
-
|
|
890
|
-
return (highlighted_key, deleted_key)
|
|
891
|
-
|
|
892
|
-
if current_snapshot.get('kind') == 'set':
|
|
893
|
-
previous_values = previous_snapshot.get('setValues') or {}
|
|
894
|
-
current_values = current_snapshot.get('setValues') or {}
|
|
895
|
-
|
|
896
|
-
added_tokens = [token for token in current_values.keys() if token not in previous_values]
|
|
897
|
-
removed_tokens = [token for token in previous_values.keys() if token not in current_values]
|
|
898
|
-
|
|
899
|
-
if len(added_tokens) == 1:
|
|
900
|
-
highlighted_key = current_values.get(added_tokens[0])
|
|
901
|
-
if len(removed_tokens) == 1:
|
|
902
|
-
deleted_key = previous_values.get(removed_tokens[0])
|
|
903
|
-
|
|
904
|
-
return (highlighted_key, deleted_key)
|
|
905
|
-
|
|
906
|
-
def _clear_frame_hashmap_snapshots(frame):
|
|
907
|
-
frame_prefix = f"{id(frame)}::"
|
|
908
|
-
stale_keys = [
|
|
909
|
-
key for key in list(_prev_hashmap_snapshots.keys())
|
|
910
|
-
if key.startswith(frame_prefix)
|
|
911
|
-
]
|
|
912
|
-
for key in stale_keys:
|
|
913
|
-
_prev_hashmap_snapshots.pop(key, None)
|
|
914
|
-
|
|
915
|
-
def _build_runtime_visualization(local_vars, frame):
|
|
916
|
-
try:
|
|
917
|
-
hash_maps = []
|
|
918
|
-
object_kinds = {}
|
|
919
|
-
active_snapshot_keys = set()
|
|
920
|
-
frame_prefix = f"{id(frame)}::"
|
|
921
|
-
|
|
922
|
-
for name, value in local_vars.items():
|
|
923
|
-
kind = _classify_runtime_object_kind(value)
|
|
924
|
-
if kind is not None:
|
|
925
|
-
object_kinds[name] = kind
|
|
926
|
-
|
|
927
|
-
snapshot = _extract_hashmap_snapshot(value)
|
|
928
|
-
if snapshot is None:
|
|
929
|
-
continue
|
|
930
|
-
|
|
931
|
-
snapshot_key = f"{frame_prefix}{name}"
|
|
932
|
-
active_snapshot_keys.add(snapshot_key)
|
|
933
|
-
previous_snapshot = _prev_hashmap_snapshots.get(snapshot_key)
|
|
934
|
-
highlighted_key, deleted_key = _infer_hashmap_delta(previous_snapshot, snapshot)
|
|
935
|
-
|
|
936
|
-
payload = {
|
|
937
|
-
'name': name,
|
|
938
|
-
'kind': snapshot.get('kind', 'hashmap'),
|
|
939
|
-
'entries': snapshot.get('entries', []),
|
|
940
|
-
}
|
|
941
|
-
if highlighted_key is not None:
|
|
942
|
-
payload['highlightedKey'] = highlighted_key
|
|
943
|
-
if deleted_key is not None:
|
|
944
|
-
payload['deletedKey'] = deleted_key
|
|
945
|
-
|
|
946
|
-
hash_maps.append(payload)
|
|
947
|
-
_prev_hashmap_snapshots[snapshot_key] = snapshot
|
|
948
|
-
|
|
949
|
-
stale_keys = [
|
|
950
|
-
key for key in list(_prev_hashmap_snapshots.keys())
|
|
951
|
-
if key.startswith(frame_prefix) and key not in active_snapshot_keys
|
|
952
|
-
]
|
|
953
|
-
for key in stale_keys:
|
|
954
|
-
_prev_hashmap_snapshots.pop(key, None)
|
|
955
|
-
|
|
956
|
-
if len(hash_maps) > 0 or len(object_kinds) > 0:
|
|
957
|
-
payload = {}
|
|
958
|
-
if len(hash_maps) > 0:
|
|
959
|
-
payload['hashMaps'] = hash_maps
|
|
960
|
-
if len(object_kinds) > 0:
|
|
961
|
-
payload['objectKinds'] = object_kinds
|
|
962
|
-
return payload
|
|
963
|
-
return {}
|
|
964
|
-
except Exception:
|
|
965
|
-
return {}
|
|
966
|
-
|
|
967
1860
|
def _tracer(frame, event, arg):
|
|
968
1861
|
global _trace_limit_exceeded, _timeout_reason, _total_line_events, _line_hit_count, _infinite_loop_line
|
|
969
1862
|
func_name = frame.f_code.co_name
|
|
@@ -977,9 +1870,18 @@ def _tracer(frame, event, arg):
|
|
|
977
1870
|
|
|
978
1871
|
# Fast counter for any loops
|
|
979
1872
|
if event == 'line':
|
|
980
|
-
|
|
981
|
-
if frame.f_code.co_filename == '<user_code>' and frame.f_lineno in _tracecode_collapsed_literal_lines:
|
|
1873
|
+
if frame.f_code.co_filename == 'solution.py' and frame.f_lineno in _tracecode_collapsed_literal_lines:
|
|
982
1874
|
return _tracer
|
|
1875
|
+
previous_step = TraceHooks._resolve_previous_step(frame)
|
|
1876
|
+
if (
|
|
1877
|
+
isinstance(previous_step, _builtins.dict)
|
|
1878
|
+
and previous_step.get('event') == 'line'
|
|
1879
|
+
and previous_step.get('line') == frame.f_lineno
|
|
1880
|
+
and not previous_step.get('__runtime_flushed')
|
|
1881
|
+
and not _pending_accesses.get(_tracecode_builtin_id(frame))
|
|
1882
|
+
):
|
|
1883
|
+
return _tracer
|
|
1884
|
+
TraceHooks.flush_completed_line(frame)
|
|
983
1885
|
_total_line_events += 1
|
|
984
1886
|
|
|
985
1887
|
# Check total line events
|
|
@@ -1018,8 +1920,7 @@ def _tracer(frame, event, arg):
|
|
|
1018
1920
|
'function': func_name,
|
|
1019
1921
|
'callStack': _snapshot_call_stack(),
|
|
1020
1922
|
'stdoutLineCount': len(_console_output),
|
|
1021
|
-
'accesses': []
|
|
1022
|
-
'visualization': _build_runtime_visualization(local_vars, frame)
|
|
1923
|
+
'accesses': []
|
|
1023
1924
|
})
|
|
1024
1925
|
sys.settrace(None)
|
|
1025
1926
|
raise _InfiniteLoopDetected(f"Line {frame.f_lineno} executed {_max_single_line_hits} times")
|
|
@@ -1040,8 +1941,14 @@ def _tracer(frame, event, arg):
|
|
|
1040
1941
|
'stdoutLineCount': len(_console_output),
|
|
1041
1942
|
'accesses': [],
|
|
1042
1943
|
})
|
|
1944
|
+
_pending_accesses.clear()
|
|
1043
1945
|
sys.settrace(None)
|
|
1044
|
-
|
|
1946
|
+
return None
|
|
1947
|
+
|
|
1948
|
+
if _trace_limit_exceeded and _timeout_reason == 'trace-limit':
|
|
1949
|
+
_pending_accesses.clear()
|
|
1950
|
+
sys.settrace(None)
|
|
1951
|
+
return None
|
|
1045
1952
|
|
|
1046
1953
|
if event == 'call':
|
|
1047
1954
|
local_vars, local_sources = _snapshot_locals(frame, with_sources=True)
|
|
@@ -1061,8 +1968,7 @@ def _tracer(frame, event, arg):
|
|
|
1061
1968
|
'function': func_name,
|
|
1062
1969
|
'callStack': _snapshot_call_stack(),
|
|
1063
1970
|
'stdoutLineCount': len(_console_output),
|
|
1064
|
-
'accesses': __tracecode_flush_accesses(frame)
|
|
1065
|
-
'visualization': _build_runtime_visualization(local_vars, frame)
|
|
1971
|
+
'accesses': __tracecode_flush_accesses(frame)
|
|
1066
1972
|
})
|
|
1067
1973
|
elif event == 'line':
|
|
1068
1974
|
if _MINIMAL_TRACE:
|
|
@@ -1076,11 +1982,10 @@ def _tracer(frame, event, arg):
|
|
|
1076
1982
|
'function': func_name,
|
|
1077
1983
|
'callStack': _snapshot_call_stack(),
|
|
1078
1984
|
'stdoutLineCount': len(_console_output),
|
|
1079
|
-
'accesses': []
|
|
1080
|
-
'visualization': _build_runtime_visualization(local_vars, frame)
|
|
1985
|
+
'accesses': []
|
|
1081
1986
|
})
|
|
1082
1987
|
elif event == 'return':
|
|
1083
|
-
|
|
1988
|
+
TraceHooks.flush_completed_line(frame)
|
|
1084
1989
|
if not _MINIMAL_TRACE:
|
|
1085
1990
|
local_vars, local_sources = _snapshot_locals(frame, with_sources=True)
|
|
1086
1991
|
__tracecode_append_trace_step(frame, {
|
|
@@ -1092,12 +1997,10 @@ def _tracer(frame, event, arg):
|
|
|
1092
1997
|
'returnValue': _serialize(arg),
|
|
1093
1998
|
'callStack': _snapshot_call_stack(),
|
|
1094
1999
|
'stdoutLineCount': len(_console_output),
|
|
1095
|
-
'accesses': []
|
|
1096
|
-
'visualization': _build_runtime_visualization(local_vars, frame)
|
|
2000
|
+
'accesses': []
|
|
1097
2001
|
})
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
_last_trace_index_by_frame.pop(id(frame), None)
|
|
2002
|
+
_pending_accesses.pop(_tracecode_builtin_id(frame), None)
|
|
2003
|
+
_last_trace_index_by_frame.pop(_tracecode_builtin_id(frame), None)
|
|
1101
2004
|
if _call_stack and _call_stack[-1]['function'] == func_name:
|
|
1102
2005
|
_call_stack.pop()
|
|
1103
2006
|
|
|
@@ -1105,10 +2008,10 @@ def _tracer(frame, event, arg):
|
|
|
1105
2008
|
|
|
1106
2009
|
# Clear user-defined globals from previous runs
|
|
1107
2010
|
# Use __builtins__ to access real globals() and list() in case they were shadowed
|
|
1108
|
-
_real_globals = __builtins__['globals'] if isinstance(__builtins__, dict) else getattr(__builtins__, 'globals')
|
|
1109
|
-
_real_list = __builtins__['list'] if isinstance(__builtins__, dict) else getattr(__builtins__, 'list')
|
|
2011
|
+
_real_globals = __builtins__['globals'] if isinstance(__builtins__, _builtins.dict) else getattr(__builtins__, 'globals')
|
|
2012
|
+
_real_list = __builtins__['list'] if isinstance(__builtins__, _builtins.dict) else getattr(__builtins__, 'list')
|
|
1110
2013
|
_globals_dict = _real_globals()
|
|
1111
|
-
_preserve = {"TreeNode", "ListNode", 'sys', 'json', 'math', 'ast', 'print', '__builtins__', '__name__', '__doc__', '__package__', '__loader__', '__spec__'} | _TRACECODE_TYPING_GLOBALS
|
|
2014
|
+
_preserve = {"TreeNode", "ListNode", "TraceHooks", 'sys', 'json', 'math', 'ast', 'print', '__builtins__', '__name__', '__doc__', '__package__', '__loader__', '__spec__'} | _TRACECODE_TYPING_GLOBALS
|
|
1112
2015
|
for _k in _real_list(_globals_dict.keys()):
|
|
1113
2016
|
if not _k.startswith('_') and _k not in _preserve:
|
|
1114
2017
|
_globals_dict.pop(_k, None)
|
|
@@ -1117,6 +2020,8 @@ del _preserve, _real_globals, _real_list
|
|
|
1117
2020
|
# Ensure print remains routed through the tracer harness after global cleanup
|
|
1118
2021
|
print = _custom_print
|
|
1119
2022
|
|
|
2023
|
+
${PYTHON_DEFAULT_IMPORT_PRELUDE}
|
|
2024
|
+
pow = _builtins.pow
|
|
1120
2025
|
`;
|
|
1121
2026
|
|
|
1122
2027
|
const userCodeStartLine = 1;
|
|
@@ -1127,17 +2032,15 @@ print = _custom_print
|
|
|
1127
2032
|
|
|
1128
2033
|
Object.entries(inputs).forEach(([key, value]) => {
|
|
1129
2034
|
if (value && typeof value === 'object' && !Array.isArray(value) && ('val' in value || 'value' in value)) {
|
|
2035
|
+
const explicitType = typeof value.__type__ === 'string' ? value.__type__ : null;
|
|
1130
2036
|
const hasLeft = 'left' in value;
|
|
1131
2037
|
const hasRight = 'right' in value;
|
|
1132
2038
|
const hasNext = 'next' in value;
|
|
1133
2039
|
|
|
1134
|
-
if (hasLeft || hasRight) {
|
|
2040
|
+
if (explicitType === 'TreeNode' || hasLeft || hasRight) {
|
|
1135
2041
|
treeInputKeys.push(key);
|
|
1136
|
-
} else if (hasNext) {
|
|
2042
|
+
} else if (explicitType === 'ListNode' || hasNext) {
|
|
1137
2043
|
listInputKeys.push(key);
|
|
1138
|
-
} else {
|
|
1139
|
-
// Default to tree for backwards compatibility
|
|
1140
|
-
treeInputKeys.push(key);
|
|
1141
2044
|
}
|
|
1142
2045
|
}
|
|
1143
2046
|
});
|
|
@@ -1153,9 +2056,10 @@ print = _custom_print
|
|
|
1153
2056
|
const argList = Object.keys(inputs)
|
|
1154
2057
|
.map((key) => `${key}=${key}`)
|
|
1155
2058
|
.join(', ');
|
|
1156
|
-
const inplaceCandidates = ['nums1', 'nums', 'arr', 'array', 'matrix', 'board', 'grid'
|
|
2059
|
+
const inplaceCandidates = ['nums1', 'nums', 'arr', 'array', 'matrix', 'board', 'grid']
|
|
1157
2060
|
.filter((key) => Object.prototype.hasOwnProperty.call(inputs, key));
|
|
1158
2061
|
const inplaceCandidatesLiteral = JSON.stringify(inplaceCandidates);
|
|
2062
|
+
const traceInputNamesLiteral = JSON.stringify(Object.keys(inputs));
|
|
1159
2063
|
const executionCode = functionName
|
|
1160
2064
|
? executionStyle === 'solution-method'
|
|
1161
2065
|
? [
|
|
@@ -1182,8 +2086,9 @@ print = _custom_print
|
|
|
1182
2086
|
` _call_args = _args[_i] if _i < len(_args) else []`,
|
|
1183
2087
|
` if _call_args is None:`,
|
|
1184
2088
|
` _call_args = []`,
|
|
1185
|
-
` if not isinstance(_call_args, (list, tuple)):`,
|
|
2089
|
+
` if not isinstance(_call_args, (_builtins.list, _builtins.tuple)):`,
|
|
1186
2090
|
` _call_args = [_call_args]`,
|
|
2091
|
+
` _call_args = _tracecode_materialize_input(_call_args)`,
|
|
1187
2092
|
` if _i == 0:`,
|
|
1188
2093
|
` _instance = _cls(*_call_args)`,
|
|
1189
2094
|
` _out.append(None)`,
|
|
@@ -1214,6 +2119,50 @@ print = _custom_print
|
|
|
1214
2119
|
${userCodeTraceSetup}
|
|
1215
2120
|
${deps.PYTHON_CONVERSION_HELPERS_SNIPPET}
|
|
1216
2121
|
|
|
2122
|
+
|
|
2123
|
+
def _tracecode_materialize_custom_input(obj):
|
|
2124
|
+
if isinstance(obj, _builtins.list):
|
|
2125
|
+
return [_tracecode_materialize_custom_input(item) for item in obj]
|
|
2126
|
+
if isinstance(obj, _builtins.tuple):
|
|
2127
|
+
return tuple(_tracecode_materialize_custom_input(item) for item in obj)
|
|
2128
|
+
if isinstance(obj, _builtins.dict):
|
|
2129
|
+
if obj.get('__type__') == 'TreeNode' or 'left' in obj or 'right' in obj:
|
|
2130
|
+
return _dict_to_tree(obj)
|
|
2131
|
+
if obj.get('__type__') == 'ListNode' or 'next' in obj:
|
|
2132
|
+
return _dict_to_list(obj)
|
|
2133
|
+
_type_name = obj.get('__type__') if isinstance(obj.get('__type__'), _builtins.str) else obj.get('__class__')
|
|
2134
|
+
_fields = {key: _tracecode_materialize_custom_input(value) for key, value in obj.items() if key not in ('__type__', '__class__', '__id__')}
|
|
2135
|
+
if isinstance(_type_name, _builtins.str):
|
|
2136
|
+
_fields = {'__type__': _type_name, **_fields}
|
|
2137
|
+
_constructor_fields = {key: value for key, value in _fields.items() if key not in ('__type__', '__class__')}
|
|
2138
|
+
_cls = globals().get(_type_name) if isinstance(_type_name, _builtins.str) else None
|
|
2139
|
+
if isinstance(_cls, _builtins.type):
|
|
2140
|
+
try:
|
|
2141
|
+
return _cls(**_constructor_fields)
|
|
2142
|
+
except Exception:
|
|
2143
|
+
pass
|
|
2144
|
+
try:
|
|
2145
|
+
return _cls(*_builtins.list(_constructor_fields.values()))
|
|
2146
|
+
except Exception:
|
|
2147
|
+
pass
|
|
2148
|
+
try:
|
|
2149
|
+
_instance = _cls.__new__(_cls)
|
|
2150
|
+
for _key, _value in _constructor_fields.items():
|
|
2151
|
+
setattr(_instance, _key, _value)
|
|
2152
|
+
return _instance
|
|
2153
|
+
except Exception:
|
|
2154
|
+
pass
|
|
2155
|
+
return _fields
|
|
2156
|
+
return obj
|
|
2157
|
+
|
|
2158
|
+
def _tracecode_materialize_named_inputs(_names):
|
|
2159
|
+
for _name in _names:
|
|
2160
|
+
if _name in globals():
|
|
2161
|
+
globals()[_name] = _tracecode_materialize_custom_input(globals()[_name])
|
|
2162
|
+
|
|
2163
|
+
def _tracecode_materialize_input(obj):
|
|
2164
|
+
return _tracecode_materialize_custom_input(obj)
|
|
2165
|
+
|
|
1217
2166
|
def _resolve_inplace_result():
|
|
1218
2167
|
for _name in ${inplaceCandidatesLiteral}:
|
|
1219
2168
|
if _name in globals():
|
|
@@ -1227,6 +2176,7 @@ ${treeConversions}
|
|
|
1227
2176
|
${listConversions}
|
|
1228
2177
|
|
|
1229
2178
|
${preloadUserDefinitions}
|
|
2179
|
+
_tracecode_materialize_named_inputs(${traceInputNamesLiteral})
|
|
1230
2180
|
|
|
1231
2181
|
if _SCRIPT_MODE:
|
|
1232
2182
|
_SCRIPT_PRE_USER_GLOBALS = set(globals().keys()) - _TRACE_INPUT_NAMES
|
|
@@ -1253,7 +2203,7 @@ except Exception as e:
|
|
|
1253
2203
|
if _exc_tb.tb_lineno is not None:
|
|
1254
2204
|
_error_line = _exc_tb.tb_lineno
|
|
1255
2205
|
_exc_tb = _exc_tb.tb_next
|
|
1256
|
-
|
|
2206
|
+
__tracecode_append_trace_step(None, {
|
|
1257
2207
|
'line': _error_line,
|
|
1258
2208
|
'event': 'exception',
|
|
1259
2209
|
'variables': {
|
|
@@ -1279,7 +2229,15 @@ print = _original_print
|
|
|
1279
2229
|
|
|
1280
2230
|
json.dumps({
|
|
1281
2231
|
'trace': _trace_data,
|
|
1282
|
-
'
|
|
2232
|
+
'runtimeTrace': {
|
|
2233
|
+
'schemaVersion': 'runtime-trace-2026-04-28',
|
|
2234
|
+
'language': 'python',
|
|
2235
|
+
'runId': 'python:run',
|
|
2236
|
+
'events': _trace_events,
|
|
2237
|
+
'lineEventCount': len([event for event in _trace_events if event.get('kind') == 'line']),
|
|
2238
|
+
'traceStepCount': len(_trace_events)
|
|
2239
|
+
},
|
|
2240
|
+
'result': _serialize_output(_result),
|
|
1283
2241
|
'console': _console_output,
|
|
1284
2242
|
'userCodeStartLine': ${userCodeStartLine},
|
|
1285
2243
|
'traceLimitExceeded': _trace_limit_exceeded,
|
|
@@ -1324,7 +2282,7 @@ function parsePythonError(rawError, userCodeStartLine, userCodeLineCount) {
|
|
|
1324
2282
|
|
|
1325
2283
|
// Prefer frame lines from user-compiled code, then fall back to generic "line N" matches.
|
|
1326
2284
|
const frameLineMatches = [
|
|
1327
|
-
...rawError.matchAll(/File "(?:<exec>|<string>|<user_code
|
|
2285
|
+
...rawError.matchAll(/File "(?:<exec>|<string>|<user_code>|solution\.py)", line (\d+)/g),
|
|
1328
2286
|
];
|
|
1329
2287
|
const frameRawLines = frameLineMatches.map((match) => parseInt(match[1], 10));
|
|
1330
2288
|
const genericLineMatches = [...rawError.matchAll(/line (\d+)/g)];
|
|
@@ -1396,6 +2354,36 @@ function parsePythonError(rawError, userCodeStartLine, userCodeLineCount) {
|
|
|
1396
2354
|
};
|
|
1397
2355
|
}
|
|
1398
2356
|
|
|
2357
|
+
const RUNTIME_TRACE_SCHEMA_VERSION = 'runtime-trace-2026-04-28';
|
|
2358
|
+
|
|
2359
|
+
function remapPythonRuntimeTrace(runtimeTrace, userCodeStartLine, userCodeLineCount, runId = 'python:run', file) {
|
|
2360
|
+
const normalizedEvents = [];
|
|
2361
|
+
const events = runtimeTrace && Array.isArray(runtimeTrace.events) ? runtimeTrace.events : [];
|
|
2362
|
+
for (const event of events) {
|
|
2363
|
+
if (!event || typeof event !== 'object') continue;
|
|
2364
|
+
const normalized = {
|
|
2365
|
+
...event,
|
|
2366
|
+
runId,
|
|
2367
|
+
...(file ? { file } : {}),
|
|
2368
|
+
};
|
|
2369
|
+
if (typeof normalized.line === 'number') {
|
|
2370
|
+
normalized.line = normalized.line > 0 ? normalized.line - userCodeStartLine + 1 : normalized.line;
|
|
2371
|
+
if (normalized.line < 1 || normalized.line > userCodeLineCount) {
|
|
2372
|
+
continue;
|
|
2373
|
+
}
|
|
2374
|
+
}
|
|
2375
|
+
normalizedEvents.push(normalized);
|
|
2376
|
+
}
|
|
2377
|
+
return {
|
|
2378
|
+
schemaVersion: runtimeTrace?.schemaVersion ?? RUNTIME_TRACE_SCHEMA_VERSION,
|
|
2379
|
+
language: 'python',
|
|
2380
|
+
runId,
|
|
2381
|
+
events: normalizedEvents,
|
|
2382
|
+
lineEventCount: normalizedEvents.filter((event) => event.kind === 'line').length,
|
|
2383
|
+
traceStepCount: normalizedEvents.length,
|
|
2384
|
+
};
|
|
2385
|
+
}
|
|
2386
|
+
|
|
1399
2387
|
/**
|
|
1400
2388
|
* Execute Python code with tracing
|
|
1401
2389
|
* @param {string} code - The user's Python code
|
|
@@ -1451,6 +2439,8 @@ async function executeWithTracing(deps, code, functionName, inputs, executionSty
|
|
|
1451
2439
|
timeoutReason === 'single-line-limit' ||
|
|
1452
2440
|
(result.traceLimitExceeded && timeoutReason !== 'client-timeout');
|
|
1453
2441
|
|
|
2442
|
+
const traceOnlyBudgetExceeded = timeoutReason === 'trace-limit';
|
|
2443
|
+
|
|
1454
2444
|
// Handle tracing guard stops and execution timeouts
|
|
1455
2445
|
if (result.traceLimitExceeded || timeoutStep) {
|
|
1456
2446
|
const lastStep = adjustedTrace[adjustedTrace.length - 1];
|
|
@@ -1460,7 +2450,7 @@ async function executeWithTracing(deps, code, functionName, inputs, executionSty
|
|
|
1460
2450
|
if (timeoutReason === 'client-timeout') {
|
|
1461
2451
|
errorMessage = `Execution timed out${lineSuffix}. This may indicate an infinite loop or very expensive execution.`;
|
|
1462
2452
|
} else if (isTraceBudgetExceeded) {
|
|
1463
|
-
errorMessage = `Trace budget exceeded${lineSuffix}.
|
|
2453
|
+
errorMessage = `Trace budget exceeded${lineSuffix}. Trace playback hit its safety limits before execution finished.`;
|
|
1464
2454
|
} else {
|
|
1465
2455
|
errorMessage = `Execution stopped${lineSuffix}.`;
|
|
1466
2456
|
}
|
|
@@ -1488,11 +2478,20 @@ async function executeWithTracing(deps, code, functionName, inputs, executionSty
|
|
|
1488
2478
|
}
|
|
1489
2479
|
|
|
1490
2480
|
return {
|
|
1491
|
-
success:
|
|
2481
|
+
success:
|
|
2482
|
+
!errorStep &&
|
|
2483
|
+
(!result.traceLimitExceeded || traceOnlyBudgetExceeded) &&
|
|
2484
|
+
(!timeoutStep || traceOnlyBudgetExceeded),
|
|
1492
2485
|
output: result.result,
|
|
1493
2486
|
error: errorMessage,
|
|
1494
2487
|
errorLine,
|
|
1495
|
-
trace:
|
|
2488
|
+
trace: remapPythonRuntimeTrace(
|
|
2489
|
+
result.runtimeTrace,
|
|
2490
|
+
userCodeStartLine,
|
|
2491
|
+
userCodeLineCount,
|
|
2492
|
+
'python:run',
|
|
2493
|
+
'solution.py'
|
|
2494
|
+
),
|
|
1496
2495
|
executionTimeMs,
|
|
1497
2496
|
consoleOutput: result.console,
|
|
1498
2497
|
traceLimitExceeded: result.traceLimitExceeded,
|
|
@@ -1513,7 +2512,7 @@ async function executeWithTracing(deps, code, functionName, inputs, executionSty
|
|
|
1513
2512
|
? 'Execution timed out. This may indicate an infinite loop or very expensive execution.'
|
|
1514
2513
|
: message,
|
|
1515
2514
|
errorLine: line,
|
|
1516
|
-
trace: [],
|
|
2515
|
+
trace: remapPythonRuntimeTrace({ events: [] }, userCodeStartLine, userCodeLineCount, 'python:run', 'solution.py'),
|
|
1517
2516
|
executionTimeMs,
|
|
1518
2517
|
consoleOutput: [],
|
|
1519
2518
|
timeoutReason: isClientTimeout ? 'client-timeout' : undefined,
|
|
@@ -1552,16 +2551,15 @@ async function executeCode(deps, code, functionName, inputs, executionStyle = 'f
|
|
|
1552
2551
|
|
|
1553
2552
|
Object.entries(inputs).forEach(([key, value]) => {
|
|
1554
2553
|
if (value && typeof value === 'object' && !Array.isArray(value) && ('val' in value || 'value' in value)) {
|
|
2554
|
+
const explicitType = typeof value.__type__ === 'string' ? value.__type__ : null;
|
|
1555
2555
|
const hasLeft = 'left' in value;
|
|
1556
2556
|
const hasRight = 'right' in value;
|
|
1557
2557
|
const hasNext = 'next' in value;
|
|
1558
2558
|
|
|
1559
|
-
if (hasLeft || hasRight) {
|
|
2559
|
+
if (explicitType === 'TreeNode' || hasLeft || hasRight) {
|
|
1560
2560
|
treeInputKeys.push(key);
|
|
1561
|
-
} else if (hasNext) {
|
|
2561
|
+
} else if (explicitType === 'ListNode' || hasNext) {
|
|
1562
2562
|
listInputKeys.push(key);
|
|
1563
|
-
} else {
|
|
1564
|
-
treeInputKeys.push(key);
|
|
1565
2563
|
}
|
|
1566
2564
|
}
|
|
1567
2565
|
});
|
|
@@ -1577,9 +2575,10 @@ async function executeCode(deps, code, functionName, inputs, executionStyle = 'f
|
|
|
1577
2575
|
const inputArgs = Object.keys(inputs)
|
|
1578
2576
|
.map((key) => `${key}=${key}`)
|
|
1579
2577
|
.join(', ');
|
|
1580
|
-
const inplaceCandidates = ['nums1', 'nums', 'arr', 'array', 'matrix', 'board', 'grid'
|
|
2578
|
+
const inplaceCandidates = ['nums1', 'nums', 'arr', 'array', 'matrix', 'board', 'grid']
|
|
1581
2579
|
.filter((key) => Object.prototype.hasOwnProperty.call(inputs, key));
|
|
1582
2580
|
const inplaceCandidatesLiteral = JSON.stringify(inplaceCandidates);
|
|
2581
|
+
const traceInputNamesLiteral = JSON.stringify(Object.keys(inputs));
|
|
1583
2582
|
const executionCall = executionStyle === 'solution-method'
|
|
1584
2583
|
? `if 'Solution' in globals() and hasattr(Solution, '${functionName}'):
|
|
1585
2584
|
_solver = Solution()
|
|
@@ -1602,7 +2601,7 @@ for _i, _op in enumerate(_ops):
|
|
|
1602
2601
|
_call_args = _args[_i] if _i < len(_args) else []
|
|
1603
2602
|
if _call_args is None:
|
|
1604
2603
|
_call_args = []
|
|
1605
|
-
if not isinstance(_call_args, (list, tuple)):
|
|
2604
|
+
if not isinstance(_call_args, (_builtins.list, _builtins.tuple)):
|
|
1606
2605
|
_call_args = [_call_args]
|
|
1607
2606
|
if _i == 0:
|
|
1608
2607
|
_instance = _cls(*_call_args)
|
|
@@ -1632,9 +2631,12 @@ import math
|
|
|
1632
2631
|
import sys
|
|
1633
2632
|
import builtins as _builtins
|
|
1634
2633
|
${deps.PYTHON_CLASS_DEFINITIONS_SNIPPET}
|
|
2634
|
+
${PYTHON_DEFAULT_IMPORT_PRELUDE}
|
|
2635
|
+
pow = _builtins.pow
|
|
1635
2636
|
|
|
1636
2637
|
_console_output = []
|
|
1637
2638
|
_original_print = _builtins.print
|
|
2639
|
+
_tracecode_builtin_id = _builtins.id
|
|
1638
2640
|
_MIRROR_PRINT_TO_WORKER_CONSOLE = ${mirrorPrintToConsole ? 'True' : 'False'}
|
|
1639
2641
|
|
|
1640
2642
|
def _custom_print(*args, **kwargs):
|
|
@@ -1746,6 +2748,46 @@ def _interview_guard_stop():
|
|
|
1746
2748
|
? `
|
|
1747
2749
|
${deps.PYTHON_CONVERSION_HELPERS_SNIPPET}
|
|
1748
2750
|
|
|
2751
|
+
def _tracecode_materialize_custom_input(obj):
|
|
2752
|
+
if isinstance(obj, _builtins.list):
|
|
2753
|
+
return [_tracecode_materialize_custom_input(item) for item in obj]
|
|
2754
|
+
if isinstance(obj, _builtins.tuple):
|
|
2755
|
+
return tuple(_tracecode_materialize_custom_input(item) for item in obj)
|
|
2756
|
+
if isinstance(obj, _builtins.dict):
|
|
2757
|
+
if obj.get('__type__') == 'TreeNode' or 'left' in obj or 'right' in obj:
|
|
2758
|
+
return _dict_to_tree(obj)
|
|
2759
|
+
if obj.get('__type__') == 'ListNode' or 'next' in obj:
|
|
2760
|
+
return _dict_to_list(obj)
|
|
2761
|
+
_type_name = obj.get('__type__') if isinstance(obj.get('__type__'), _builtins.str) else obj.get('__class__')
|
|
2762
|
+
_fields = {key: _tracecode_materialize_custom_input(value) for key, value in obj.items() if key not in ('__type__', '__class__', '__id__')}
|
|
2763
|
+
if isinstance(_type_name, _builtins.str):
|
|
2764
|
+
_fields = {'__type__': _type_name, **_fields}
|
|
2765
|
+
_constructor_fields = {key: value for key, value in _fields.items() if key not in ('__type__', '__class__')}
|
|
2766
|
+
_cls = globals().get(_type_name) if isinstance(_type_name, _builtins.str) else None
|
|
2767
|
+
if isinstance(_cls, _builtins.type):
|
|
2768
|
+
try:
|
|
2769
|
+
return _cls(**_constructor_fields)
|
|
2770
|
+
except Exception:
|
|
2771
|
+
pass
|
|
2772
|
+
try:
|
|
2773
|
+
return _cls(*_builtins.list(_constructor_fields.values()))
|
|
2774
|
+
except Exception:
|
|
2775
|
+
pass
|
|
2776
|
+
try:
|
|
2777
|
+
_instance = _cls.__new__(_cls)
|
|
2778
|
+
for _key, _value in _constructor_fields.items():
|
|
2779
|
+
setattr(_instance, _key, _value)
|
|
2780
|
+
return _instance
|
|
2781
|
+
except Exception:
|
|
2782
|
+
pass
|
|
2783
|
+
return _fields
|
|
2784
|
+
return obj
|
|
2785
|
+
|
|
2786
|
+
def _tracecode_materialize_named_inputs(_names):
|
|
2787
|
+
for _name in _names:
|
|
2788
|
+
if _name in globals():
|
|
2789
|
+
globals()[_name] = _tracecode_materialize_custom_input(globals()[_name])
|
|
2790
|
+
|
|
1749
2791
|
def _resolve_inplace_result():
|
|
1750
2792
|
for _name in ${inplaceCandidatesLiteral}:
|
|
1751
2793
|
if _name in globals():
|
|
@@ -1758,6 +2800,8 @@ ${treeConversions}
|
|
|
1758
2800
|
|
|
1759
2801
|
${listConversions}
|
|
1760
2802
|
|
|
2803
|
+
_tracecode_materialize_named_inputs(${traceInputNamesLiteral})
|
|
2804
|
+
|
|
1761
2805
|
_result = None
|
|
1762
2806
|
_interview_guard_triggered = False
|
|
1763
2807
|
_interview_guard_reason = None
|
|
@@ -1797,6 +2841,46 @@ _json_out
|
|
|
1797
2841
|
: `
|
|
1798
2842
|
${deps.PYTHON_CONVERSION_HELPERS_SNIPPET}
|
|
1799
2843
|
|
|
2844
|
+
def _tracecode_materialize_custom_input(obj):
|
|
2845
|
+
if isinstance(obj, _builtins.list):
|
|
2846
|
+
return [_tracecode_materialize_custom_input(item) for item in obj]
|
|
2847
|
+
if isinstance(obj, _builtins.tuple):
|
|
2848
|
+
return tuple(_tracecode_materialize_custom_input(item) for item in obj)
|
|
2849
|
+
if isinstance(obj, _builtins.dict):
|
|
2850
|
+
if obj.get('__type__') == 'TreeNode' or 'left' in obj or 'right' in obj:
|
|
2851
|
+
return _dict_to_tree(obj)
|
|
2852
|
+
if obj.get('__type__') == 'ListNode' or 'next' in obj:
|
|
2853
|
+
return _dict_to_list(obj)
|
|
2854
|
+
_type_name = obj.get('__type__') if isinstance(obj.get('__type__'), _builtins.str) else obj.get('__class__')
|
|
2855
|
+
_fields = {key: _tracecode_materialize_custom_input(value) for key, value in obj.items() if key not in ('__type__', '__class__', '__id__')}
|
|
2856
|
+
if isinstance(_type_name, _builtins.str):
|
|
2857
|
+
_fields = {'__type__': _type_name, **_fields}
|
|
2858
|
+
_constructor_fields = {key: value for key, value in _fields.items() if key not in ('__type__', '__class__')}
|
|
2859
|
+
_cls = globals().get(_type_name) if isinstance(_type_name, _builtins.str) else None
|
|
2860
|
+
if isinstance(_cls, _builtins.type):
|
|
2861
|
+
try:
|
|
2862
|
+
return _cls(**_constructor_fields)
|
|
2863
|
+
except Exception:
|
|
2864
|
+
pass
|
|
2865
|
+
try:
|
|
2866
|
+
return _cls(*_builtins.list(_constructor_fields.values()))
|
|
2867
|
+
except Exception:
|
|
2868
|
+
pass
|
|
2869
|
+
try:
|
|
2870
|
+
_instance = _cls.__new__(_cls)
|
|
2871
|
+
for _key, _value in _constructor_fields.items():
|
|
2872
|
+
setattr(_instance, _key, _value)
|
|
2873
|
+
return _instance
|
|
2874
|
+
except Exception:
|
|
2875
|
+
pass
|
|
2876
|
+
return _fields
|
|
2877
|
+
return obj
|
|
2878
|
+
|
|
2879
|
+
def _tracecode_materialize_named_inputs(_names):
|
|
2880
|
+
for _name in _names:
|
|
2881
|
+
if _name in globals():
|
|
2882
|
+
globals()[_name] = _tracecode_materialize_custom_input(globals()[_name])
|
|
2883
|
+
|
|
1800
2884
|
def _resolve_inplace_result():
|
|
1801
2885
|
for _name in ${inplaceCandidatesLiteral}:
|
|
1802
2886
|
if _name in globals():
|
|
@@ -1809,6 +2893,8 @@ ${treeConversions}
|
|
|
1809
2893
|
|
|
1810
2894
|
${listConversions}
|
|
1811
2895
|
|
|
2896
|
+
_tracecode_materialize_named_inputs(${traceInputNamesLiteral})
|
|
2897
|
+
|
|
1812
2898
|
try:
|
|
1813
2899
|
${executionCallInTry}
|
|
1814
2900
|
finally:
|