semantifold 0.3.0 → 0.4.0

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.
Files changed (297) hide show
  1. package/README.md +58 -15
  2. package/build/index.d.ts +48 -2
  3. package/build/index.d.ts.map +1 -1
  4. package/build/index.js +57 -8
  5. package/build/src/artifact-path.d.ts +23 -1
  6. package/build/src/artifact-path.d.ts.map +1 -1
  7. package/build/src/artifact-path.js +45 -3
  8. package/build/src/artifacts.d.ts.map +1 -1
  9. package/build/src/artifacts.js +66 -1
  10. package/build/src/backends/c-validation.d.ts.map +1 -1
  11. package/build/src/backends/c-validation.js +7 -3
  12. package/build/src/backends/cpp-validation.d.ts.map +1 -1
  13. package/build/src/backends/cpp-validation.js +7 -3
  14. package/build/src/backends/csharp.js +7 -1
  15. package/build/src/backends/dart-runtime.d.ts +2 -0
  16. package/build/src/backends/dart-runtime.d.ts.map +1 -0
  17. package/build/src/backends/dart-runtime.js +41 -0
  18. package/build/src/backends/dart.d.ts +20 -0
  19. package/build/src/backends/dart.d.ts.map +1 -0
  20. package/build/src/backends/dart.js +321 -0
  21. package/build/src/backends/effects.d.ts +60 -0
  22. package/build/src/backends/effects.d.ts.map +1 -0
  23. package/build/src/backends/effects.js +746 -0
  24. package/build/src/backends/go.js +18 -4
  25. package/build/src/backends/identifiers.d.ts +36 -4
  26. package/build/src/backends/identifiers.d.ts.map +1 -1
  27. package/build/src/backends/identifiers.js +154 -10
  28. package/build/src/backends/index.d.ts.map +1 -1
  29. package/build/src/backends/index.js +27 -4
  30. package/build/src/backends/ios.d.ts +68 -0
  31. package/build/src/backends/ios.d.ts.map +1 -0
  32. package/build/src/backends/ios.js +1503 -0
  33. package/build/src/backends/java.d.ts.map +1 -1
  34. package/build/src/backends/java.js +429 -36
  35. package/build/src/backends/javascript.d.ts +6 -0
  36. package/build/src/backends/javascript.d.ts.map +1 -1
  37. package/build/src/backends/javascript.js +380 -24
  38. package/build/src/backends/kotlin-runtime.d.ts +3 -0
  39. package/build/src/backends/kotlin-runtime.d.ts.map +1 -0
  40. package/build/src/backends/kotlin-runtime.js +29 -0
  41. package/build/src/backends/kotlin.d.ts +23 -0
  42. package/build/src/backends/kotlin.d.ts.map +1 -0
  43. package/build/src/backends/kotlin.js +136 -0
  44. package/build/src/backends/native-validation.d.ts +2 -2
  45. package/build/src/backends/native-validation.d.ts.map +1 -1
  46. package/build/src/backends/native-validation.js +2 -2
  47. package/build/src/backends/ordered-expressions.d.ts.map +1 -1
  48. package/build/src/backends/ordered-expressions.js +39 -7
  49. package/build/src/backends/php-stdlib-support.d.ts +19 -0
  50. package/build/src/backends/php-stdlib-support.d.ts.map +1 -0
  51. package/build/src/backends/php-stdlib-support.js +227 -0
  52. package/build/src/backends/php.d.ts.map +1 -1
  53. package/build/src/backends/php.js +448 -33
  54. package/build/src/backends/program.d.ts +81 -0
  55. package/build/src/backends/program.d.ts.map +1 -0
  56. package/build/src/backends/program.js +1308 -0
  57. package/build/src/backends/python.js +7 -1
  58. package/build/src/backends/ruby.d.ts.map +1 -1
  59. package/build/src/backends/ruby.js +310 -24
  60. package/build/src/backends/rust-runtime.d.ts +7 -0
  61. package/build/src/backends/rust-runtime.d.ts.map +1 -0
  62. package/build/src/backends/rust-runtime.js +32 -0
  63. package/build/src/backends/rust-validation.d.ts +9 -0
  64. package/build/src/backends/rust-validation.d.ts.map +1 -0
  65. package/build/src/backends/rust-validation.js +78 -0
  66. package/build/src/backends/rust.d.ts +24 -0
  67. package/build/src/backends/rust.d.ts.map +1 -0
  68. package/build/src/backends/rust.js +344 -0
  69. package/build/src/backends/scalars.d.ts +14 -6
  70. package/build/src/backends/scalars.d.ts.map +1 -1
  71. package/build/src/backends/scalars.js +167 -17
  72. package/build/src/backends/shared.d.ts +23 -4
  73. package/build/src/backends/shared.d.ts.map +1 -1
  74. package/build/src/backends/shared.js +2158 -62
  75. package/build/src/backends/stdlib-support.d.ts +14 -0
  76. package/build/src/backends/stdlib-support.d.ts.map +1 -0
  77. package/build/src/backends/stdlib-support.js +237 -0
  78. package/build/src/backends/swift-runtime.d.ts +3 -0
  79. package/build/src/backends/swift-runtime.d.ts.map +1 -0
  80. package/build/src/backends/swift-runtime.js +14 -0
  81. package/build/src/backends/swift.d.ts +8 -0
  82. package/build/src/backends/swift.d.ts.map +1 -0
  83. package/build/src/backends/swift.js +127 -0
  84. package/build/src/backends/typescript.d.ts.map +1 -1
  85. package/build/src/backends/typescript.js +344 -24
  86. package/build/src/backends/wasm.d.ts +43 -0
  87. package/build/src/backends/wasm.d.ts.map +1 -0
  88. package/build/src/backends/wasm.js +2164 -0
  89. package/build/src/backends/writer.d.ts +235 -4
  90. package/build/src/backends/writer.d.ts.map +1 -1
  91. package/build/src/backends/writer.js +468 -3
  92. package/build/src/diagnostic.d.ts +4 -3
  93. package/build/src/diagnostic.d.ts.map +1 -1
  94. package/build/src/diagnostic.js +5 -3
  95. package/build/src/frontends/c.d.ts.map +1 -1
  96. package/build/src/frontends/c.js +5 -3
  97. package/build/src/frontends/cpp.d.ts.map +1 -1
  98. package/build/src/frontends/cpp.js +5 -3
  99. package/build/src/frontends/csharp.d.ts.map +1 -1
  100. package/build/src/frontends/csharp.js +7 -3
  101. package/build/src/frontends/dart.d.ts +10 -0
  102. package/build/src/frontends/dart.d.ts.map +1 -0
  103. package/build/src/frontends/dart.js +913 -0
  104. package/build/src/frontends/index.d.ts +3 -1
  105. package/build/src/frontends/index.d.ts.map +1 -1
  106. package/build/src/frontends/index.js +15 -5
  107. package/build/src/frontends/java.d.ts +110 -1
  108. package/build/src/frontends/java.d.ts.map +1 -1
  109. package/build/src/frontends/java.js +1725 -70
  110. package/build/src/frontends/javascript-typescript.d.ts +69 -1
  111. package/build/src/frontends/javascript-typescript.d.ts.map +1 -1
  112. package/build/src/frontends/javascript-typescript.js +1825 -93
  113. package/build/src/frontends/kotlin.d.ts +10 -0
  114. package/build/src/frontends/kotlin.d.ts.map +1 -0
  115. package/build/src/frontends/kotlin.js +685 -0
  116. package/build/src/frontends/php.d.ts +118 -1
  117. package/build/src/frontends/php.d.ts.map +1 -1
  118. package/build/src/frontends/php.js +1583 -76
  119. package/build/src/frontends/program.d.ts +74 -0
  120. package/build/src/frontends/program.d.ts.map +1 -0
  121. package/build/src/frontends/program.js +989 -0
  122. package/build/src/frontends/ruby.d.ts +68 -1
  123. package/build/src/frontends/ruby.d.ts.map +1 -1
  124. package/build/src/frontends/ruby.js +1446 -101
  125. package/build/src/frontends/rust-parser.d.ts +11 -0
  126. package/build/src/frontends/rust-parser.d.ts.map +1 -0
  127. package/build/src/frontends/rust-parser.js +15 -0
  128. package/build/src/frontends/rust.d.ts +14 -0
  129. package/build/src/frontends/rust.d.ts.map +1 -0
  130. package/build/src/frontends/rust.js +715 -0
  131. package/build/src/frontends/scalars.d.ts +10 -0
  132. package/build/src/frontends/scalars.d.ts.map +1 -1
  133. package/build/src/frontends/scalars.js +28 -2
  134. package/build/src/frontends/swift.d.ts +10 -0
  135. package/build/src/frontends/swift.d.ts.map +1 -0
  136. package/build/src/frontends/swift.js +860 -0
  137. package/build/src/frontends/types.d.ts +186 -0
  138. package/build/src/frontends/types.d.ts.map +1 -0
  139. package/build/src/frontends/types.js +634 -0
  140. package/build/src/language-registry.d.ts +46 -4
  141. package/build/src/language-registry.d.ts.map +1 -1
  142. package/build/src/language-registry.js +167 -13
  143. package/build/src/mapping.d.ts +2 -2
  144. package/build/src/mapping.d.ts.map +1 -1
  145. package/build/src/mapping.js +31 -10
  146. package/build/src/semantic/capabilities.d.ts +66 -0
  147. package/build/src/semantic/capabilities.d.ts.map +1 -0
  148. package/build/src/semantic/capabilities.js +649 -0
  149. package/build/src/semantic/effects.d.ts +26 -0
  150. package/build/src/semantic/effects.d.ts.map +1 -0
  151. package/build/src/semantic/effects.js +764 -0
  152. package/build/src/semantic/generics.d.ts +23 -0
  153. package/build/src/semantic/generics.d.ts.map +1 -0
  154. package/build/src/semantic/generics.js +61 -0
  155. package/build/src/semantic/lifetime.d.ts +37 -0
  156. package/build/src/semantic/lifetime.d.ts.map +1 -0
  157. package/build/src/semantic/lifetime.js +527 -0
  158. package/build/src/semantic/provenance.d.ts +9 -2
  159. package/build/src/semantic/provenance.d.ts.map +1 -1
  160. package/build/src/semantic/provenance.js +462 -20
  161. package/build/src/semantic/scalars.d.ts +11 -0
  162. package/build/src/semantic/scalars.d.ts.map +1 -1
  163. package/build/src/semantic/scalars.js +16 -1
  164. package/build/src/semantic/stdlib.d.ts +254 -0
  165. package/build/src/semantic/stdlib.d.ts.map +1 -0
  166. package/build/src/semantic/stdlib.js +880 -0
  167. package/build/src/semantic/types.d.ts +2952 -202
  168. package/build/src/semantic/types.d.ts.map +1 -1
  169. package/build/src/semantic/types.js +688 -15
  170. package/build/src/semantic/validate.d.ts +85 -5
  171. package/build/src/semantic/validate.d.ts.map +1 -1
  172. package/build/src/semantic/validate.js +2576 -98
  173. package/build/src/stdlib-facades.d.ts +304 -0
  174. package/build/src/stdlib-facades.d.ts.map +1 -0
  175. package/build/src/stdlib-facades.js +1167 -0
  176. package/build/src/stdlib-negotiation.d.ts +69 -0
  177. package/build/src/stdlib-negotiation.d.ts.map +1 -0
  178. package/build/src/stdlib-negotiation.js +403 -0
  179. package/build/src/stdlib-providers.d.ts +72 -0
  180. package/build/src/stdlib-providers.d.ts.map +1 -0
  181. package/build/src/stdlib-providers.js +339 -0
  182. package/build/src/toolchains.d.ts +55 -1
  183. package/build/src/toolchains.d.ts.map +1 -1
  184. package/build/src/toolchains.js +15 -4
  185. package/docs/architecture.md +45 -13
  186. package/docs/dart.md +60 -0
  187. package/docs/goals.md +3 -3
  188. package/docs/ios.md +121 -0
  189. package/docs/kotlin.md +42 -0
  190. package/docs/language-support.md +231 -26
  191. package/docs/multi-file-modules.md +52 -0
  192. package/docs/parser-qualification.md +121 -8
  193. package/docs/plans/2026-09-05-standard-library-portability.md +10 -10
  194. package/docs/rust.md +88 -0
  195. package/docs/source-maps.md +15 -7
  196. package/docs/standard-library-portability.md +39 -8
  197. package/docs/swift.md +44 -0
  198. package/docs/testing.md +366 -4
  199. package/docs/webassembly.md +52 -0
  200. package/index.js +63 -8
  201. package/node_modules/semantifold-tree-sitter-legacy-internal/README.md +2 -2
  202. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/LICENSE +21 -0
  203. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/README.md +45 -0
  204. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/binding.gyp +30 -0
  205. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/bindings/node/binding.cc +20 -0
  206. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/bindings/node/binding_test.js +9 -0
  207. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/bindings/node/index.d.ts +28 -0
  208. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/bindings/node/index.js +11 -0
  209. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/grammar.js +1630 -0
  210. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/package.json +64 -0
  211. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/prebuilds/darwin-arm64/tree-sitter-rust.node +0 -0
  212. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/prebuilds/darwin-x64/tree-sitter-rust.node +0 -0
  213. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/prebuilds/linux-arm64/tree-sitter-rust.node +0 -0
  214. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/prebuilds/linux-x64/tree-sitter-rust.node +0 -0
  215. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/prebuilds/win32-arm64/tree-sitter-rust.node +0 -0
  216. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/prebuilds/win32-x64/tree-sitter-rust.node +0 -0
  217. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/queries/highlights.scm +159 -0
  218. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/queries/injections.scm +9 -0
  219. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/queries/tags.scm +60 -0
  220. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/grammar.json +9405 -0
  221. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/node-types.json +5399 -0
  222. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/parser.c +192569 -0
  223. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/scanner.c +393 -0
  224. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/tree_sitter/alloc.h +54 -0
  225. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/tree_sitter/array.h +290 -0
  226. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/src/tree_sitter/parser.h +266 -0
  227. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/tree-sitter-rust.wasm +0 -0
  228. package/node_modules/semantifold-tree-sitter-legacy-internal/node_modules/tree-sitter-rust/tree-sitter.json +53 -0
  229. package/node_modules/semantifold-tree-sitter-legacy-internal/package.json +3 -2
  230. package/node_modules/semantifold-tree-sitter-legacy-internal/src/c.js +5 -4
  231. package/package.json +5 -2
  232. package/src/artifact-path.js +47 -2
  233. package/src/artifacts.js +67 -0
  234. package/src/backends/c-validation.js +6 -1
  235. package/src/backends/cpp-validation.js +6 -1
  236. package/src/backends/csharp.js +3 -0
  237. package/src/backends/dart-runtime.js +41 -0
  238. package/src/backends/dart.js +326 -0
  239. package/src/backends/effects.js +705 -0
  240. package/src/backends/go.js +14 -2
  241. package/src/backends/identifiers.js +160 -9
  242. package/src/backends/index.js +27 -2
  243. package/src/backends/ios.js +1612 -0
  244. package/src/backends/java.js +454 -36
  245. package/src/backends/javascript.js +389 -23
  246. package/src/backends/kotlin-runtime.js +29 -0
  247. package/src/backends/kotlin.js +141 -0
  248. package/src/backends/native-validation.js +1 -1
  249. package/src/backends/ordered-expressions.js +40 -6
  250. package/src/backends/php-stdlib-support.js +239 -0
  251. package/src/backends/php.js +469 -32
  252. package/src/backends/program.js +1407 -0
  253. package/src/backends/python.js +3 -0
  254. package/src/backends/ruby.js +326 -23
  255. package/src/backends/rust-runtime.js +34 -0
  256. package/src/backends/rust-validation.js +75 -0
  257. package/src/backends/rust.js +335 -0
  258. package/src/backends/scalars.js +141 -16
  259. package/src/backends/shared.js +2304 -124
  260. package/src/backends/stdlib-support.js +234 -0
  261. package/src/backends/swift-runtime.js +14 -0
  262. package/src/backends/swift.js +132 -0
  263. package/src/backends/typescript.js +349 -23
  264. package/src/backends/wasm.js +2208 -0
  265. package/src/backends/writer.js +520 -2
  266. package/src/diagnostic.js +4 -2
  267. package/src/frontends/c.js +4 -2
  268. package/src/frontends/cpp.js +4 -2
  269. package/src/frontends/csharp.js +4 -2
  270. package/src/frontends/dart.js +963 -0
  271. package/src/frontends/index.js +14 -4
  272. package/src/frontends/java.js +1977 -69
  273. package/src/frontends/javascript-typescript.js +2046 -102
  274. package/src/frontends/kotlin.js +713 -0
  275. package/src/frontends/php.js +1725 -79
  276. package/src/frontends/program.js +1062 -0
  277. package/src/frontends/ruby.js +1624 -98
  278. package/src/frontends/rust-parser.js +18 -0
  279. package/src/frontends/rust.js +714 -0
  280. package/src/frontends/scalars.js +31 -1
  281. package/src/frontends/swift.js +893 -0
  282. package/src/frontends/types.js +750 -0
  283. package/src/language-registry.js +172 -12
  284. package/src/mapping.js +33 -9
  285. package/src/semantic/capabilities.js +671 -0
  286. package/src/semantic/effects.js +737 -0
  287. package/src/semantic/generics.js +58 -0
  288. package/src/semantic/lifetime.js +517 -0
  289. package/src/semantic/provenance.js +412 -19
  290. package/src/semantic/scalars.js +17 -0
  291. package/src/semantic/stdlib.js +921 -0
  292. package/src/semantic/types.js +765 -14
  293. package/src/semantic/validate.js +2934 -209
  294. package/src/stdlib-facades.js +1211 -0
  295. package/src/stdlib-negotiation.js +446 -0
  296. package/src/stdlib-providers.js +377 -0
  297. package/src/toolchains.js +16 -3
@@ -98,7 +98,12 @@ function validateLocalReads(module) {
98
98
  declarations.push(statement)
99
99
  collectIdentifierReads(statement.initializer, reads)
100
100
  } else if (statement.kind == "IfStatement") collectIdentifierReads(statement.condition, reads)
101
- else collectIdentifierReads(statement.expression, reads)
101
+ else if (statement.kind == "AssignmentStatement" || statement.kind == "ExpressionStatement" ||
102
+ statement.kind == "PrintStatement" || statement.kind == "ReturnStatement") {
103
+ const expression = statement.expression
104
+
105
+ if (expression) collectIdentifierReads(expression, reads)
106
+ }
102
107
  })
103
108
  for (const declaration of declarations) {
104
109
  if (!reads.has(declaration.name)) {
@@ -243,16 +248,23 @@ function emitStatement(writer, statement, indent, path) {
243
248
  return emitLocal(writer, statement, indent, path)
244
249
  }
245
250
  if (statement.kind == "IfStatement") return emitIf(writer, statement, indent, path, true)
251
+ if (statement.kind == "ExpressionStatement") throw new TypeError("Go Task 005 expression statement reached emission.")
252
+ if (statement.kind == "BreakStatement" || statement.kind == "ContinueStatement" || statement.kind == "ForEachStatement") {
253
+ throw new TypeError("Unsupported Go statement reached emission.")
254
+ }
246
255
  writer.synthetic(indent, "indentation", [statement], [path])
247
256
  if (statement.kind == "ReturnStatement") {
257
+ if (!statement.expression) throw new TypeError("Go bare return reached emission.")
248
258
  writer.mapped("return", {mappingKind: "anchor", node: statement, path})
249
259
  writer.synthetic(" ", "return spacing", [statement], [path])
250
260
  emitExpression(writer, statement.expression, path + "/expression", "go", identity)
251
- } else {
261
+ } else if (statement.kind == "PrintStatement") {
252
262
  writer.mapped("fmt.Println", {mappingKind: "anchor", node: statement, path})
253
263
  writer.mapped("(", {mappingKind: "anchor", node: statement, path})
254
264
  emitExpression(writer, statement.expression, path + "/expression", "go", identity)
255
265
  writer.mapped(")", {mappingKind: "anchor", node: statement, path})
266
+ } else {
267
+ throw new TypeError("Unsupported Go statement reached emission after preflight.")
256
268
  }
257
269
  writer.synthetic("\n", "line break", [statement], [path])
258
270
  }
@@ -2,8 +2,12 @@
2
2
 
3
3
  import {unsupportedCapability} from "../diagnostic.js"
4
4
 
5
- /** @type {Record<import("../semantic/types.js").SemanticLanguage, RegExp>} */
5
+ /** @type {Record<Exclude<import("../semantic/types.js").BackendLanguage, "ios">, RegExp>} */
6
6
  const identifierPatterns = {
7
+ dart: /^(?:_|\p{L})(?:_|\p{L}|\p{Nd})*$/u,
8
+ kotlin: /^(?:_|\p{L})(?:_|\p{L}|\p{Nd})*$/u,
9
+ swift: /^(?:_|\p{XID_Start})(?:_|\p{XID_Continue})*$/u,
10
+ rust: /^[A-Za-z_][A-Za-z0-9_]*$/u,
7
11
  cpp: /^[A-Za-z][A-Za-z0-9_]*$/u,
8
12
  c: /^[A-Za-z][A-Za-z0-9_]*$/u,
9
13
  csharp: /^[A-Za-z_][A-Za-z0-9_]*$/u,
@@ -13,11 +17,43 @@ const identifierPatterns = {
13
17
  php: /^[A-Za-z_][A-Za-z0-9_]*$/u,
14
18
  python: /^(?:_|\p{XID_Start})(?:_|\p{XID_Continue})*$/u,
15
19
  ruby: /^[a-z_][A-Za-z0-9_]*$/u,
16
- typescript: /^[A-Za-z_$][A-Za-z0-9_$]*$/u
20
+ typescript: /^[A-Za-z_$][A-Za-z0-9_$]*$/u,
21
+ wasm: /^(?:[$_]|\p{XID_Start})(?:[$_]|\p{XID_Continue})*$/u
17
22
  }
18
23
 
19
- /** @type {Record<import("../semantic/types.js").SemanticLanguage, Set<string>>} */
24
+ /** @type {Record<Exclude<import("../semantic/types.js").BackendLanguage, "ios">, Set<string>>} */
20
25
  const reservedWords = {
26
+ dart: new Set([
27
+ "Function", "Never", "Object", "RangeError", "String", "abstract", "as", "assert", "async", "await", "base",
28
+ "bool", "break", "case", "catch", "class", "const", "continue", "covariant", "default", "deferred", "do",
29
+ "double", "dynamic", "else", "enum", "export", "extends", "extension", "external", "factory", "false", "final",
30
+ "finally", "for", "get", "hide", "if", "implements", "import", "in", "int", "interface", "is", "late", "library",
31
+ "main", "mixin", "native", "new", "null", "num", "of", "on", "operator", "part", "print", "required", "rethrow",
32
+ "return", "sealed", "set", "show", "static", "super", "switch", "sync", "this", "throw", "true", "try", "typedef",
33
+ "var", "void", "when", "while", "with", "yield", "BigInt", "_"
34
+ ]),
35
+ kotlin: new Set([
36
+ "as", "break", "class", "continue", "do", "else", "false", "for", "fun", "if", "in", "interface", "is", "null",
37
+ "object", "package", "return", "super", "this", "throw", "true", "try", "typealias", "typeof", "val", "var", "when",
38
+ "while", "_", "main", "println", "Long", "Boolean", "String", "Math", "ArithmeticException"
39
+ ]),
40
+ swift: new Set([
41
+ "Any", "Self", "Type", "Protocol", "actor", "any", "as", "associatedtype", "associativity", "async", "await", "borrowing",
42
+ "break", "case", "catch", "class", "consume", "consuming", "continue", "convenience", "copy", "default", "defer", "deinit",
43
+ "didSet", "distributed", "do", "dynamic", "else", "enum", "extension", "fallthrough", "false", "fileprivate", "final", "for",
44
+ "func", "get", "guard", "if", "import", "in", "indirect", "infix", "init", "inout", "internal", "is", "isolated", "lazy",
45
+ "let", "macro", "mutating", "nil", "nonisolated", "nonmutating", "open", "operator", "optional", "override", "package",
46
+ "postfix", "precedence", "precedencegroup", "prefix", "private", "protocol", "public", "repeat", "required", "rethrows", "return",
47
+ "safe", "self", "sending", "set", "some", "static", "struct", "subscript", "super", "switch", "throws", "true", "try",
48
+ "typealias", "unowned", "unsafe", "var", "weak", "where", "while", "willSet", "yield", "_", "Bool", "Int", "Int64", "String",
49
+ "Swift", "main", "print"
50
+ ]),
51
+ rust: new Set([
52
+ "as", "async", "await", "break", "const", "continue", "crate", "dyn", "else", "enum", "extern", "false", "fn", "for", "if", "impl", "in",
53
+ "let", "loop", "match", "mod", "move", "mut", "pub", "ref", "return", "self", "Self", "static", "struct", "super", "trait", "true", "type",
54
+ "unsafe", "use", "where", "while", "abstract", "become", "box", "do", "final", "macro", "override", "priv", "typeof", "unsized", "virtual",
55
+ "yield", "try", "union", "_", "main", "String", "std", "i64", "bool"
56
+ ]),
21
57
  cpp: new Set([
22
58
  "alignas", "alignof", "and", "and_eq", "asm", "auto", "bitand", "bitor", "bool", "break", "case", "catch", "char", "char8_t", "char16_t", "char32_t", "class", "compl", "concept", "const", "consteval", "constexpr", "constinit", "const_cast", "continue", "co_await", "co_return", "co_yield", "decltype", "default", "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "float", "for", "friend", "goto", "if", "inline", "int", "long", "mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", "private", "protected", "public", "register", "reinterpret_cast", "requires", "return", "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq", "std", "string", "numeric_limits",
23
59
  // The qualified libstdc++ <string> include chain also exposes these global names.
@@ -108,7 +144,8 @@ const reservedWords = {
108
144
  "override", "package", "private", "protected", "public", "readonly", "require", "return", "satisfies", "set",
109
145
  "static", "string", "super", "switch", "symbol", "this", "throw", "true", "try", "type", "typeof", "undefined",
110
146
  "unique", "unknown", "using", "var", "void", "while", "with", "yield"
111
- ])
147
+ ]),
148
+ wasm: new Set()
112
149
  }
113
150
 
114
151
  const phpInvalidParameterBindings = new Set([
@@ -116,9 +153,61 @@ const phpInvalidParameterBindings = new Set([
116
153
  ])
117
154
  const phpInvalidAssignedBindings = new Set(["GLOBALS", "this"])
118
155
 
156
+ /** @type {Readonly<Partial<Record<import("../semantic/types.js").BackendLanguage, Set<string>>>>} */
157
+ const reservedTypeNames = Object.freeze({
158
+ java: new Set(["Boolean", "Integer", "Main", "Math", "Object", "String", "System"]),
159
+ javascript: new Set(["Array", "Boolean", "Map", "Math", "Number", "Object", "Reflect", "String"]),
160
+ php: new Set([
161
+ "addressinfo", "allowdynamicproperties", "appenditerator", "argumentcounterror", "arithmeticerror", "arrayaccess",
162
+ "arrayiterator", "arrayobject", "assertionerror", "attribute", "backedenum", "badfunctioncallexception",
163
+ "badmethodcallexception", "cachingiterator",
164
+ "callbackfilteriterator", "closedgeneratorexception", "closure", "compileerror", "countable", "dateerror", "dateexception",
165
+ "dateinterval", "dateinvalidoperationexception", "dateinvalidtimezoneexception", "datemalformedintervalstringexception",
166
+ "datemalformedperiodstringexception", "datemalformedstringexception", "dateobjecterror", "dateperiod", "daterangeerror",
167
+ "datetime", "datetimeimmutable", "datetimeinterface", "datetimezone", "deflatecontext", "delayedtargetvalidation",
168
+ "deprecated", "directory", "directoryiterator", "divisionbyzeroerror", "domainexception", "emptyiterator", "error",
169
+ "errorexception", "exception", "ffi", "fiber", "fibererror", "filesystemiterator", "filteriterator", "finfo", "generator",
170
+ "globiterator", "hashcontext", "infiniteiterator", "inflatecontext", "internaliterator", "invalidargumentexception",
171
+ "iterator", "iteratoraggregate", "iteratoriterator", "jsonexception", "jsonserializable", "lengthexception",
172
+ "libxmlerror", "limititerator", "logicexception", "multipleiterator", "nodiscard", "norewinditerator",
173
+ "opensslasymmetrickey", "opensslcertificate", "opensslcertificatesigningrequest",
174
+ "outofboundsexception", "outofrangeexception", "outeriterator", "overflowexception", "override", "parentiterator",
175
+ "parseerror", "pdo", "pdoexception", "pdorow", "pdostatement", "phar", "phardata", "pharexception", "pharfileinfo",
176
+ "php_user_filter", "phptoken", "propertyhooktype", "rangeexception", "recursivearrayiterator", "recursivecachingiterator",
177
+ "recursivecallbackfilteriterator",
178
+ "recursivedirectoryiterator", "recursivefilteriterator", "recursiveiterator", "recursiveiteratoriterator",
179
+ "recursiveregexiterator", "recursivetreeiterator", "reflection", "reflectionattribute", "reflectionclass",
180
+ "reflectionclassconstant", "reflectionconstant", "reflectionenum", "reflectionenumbackedcase", "reflectionenumunitcase",
181
+ "reflectionexception", "reflectionextension", "reflectionfiber", "reflectionfunction", "reflectionfunctionabstract",
182
+ "reflectiongenerator", "reflectionintersectiontype", "reflectionmethod", "reflectionnamedtype", "reflectionobject",
183
+ "reflectionparameter", "reflectionproperty", "reflectionreference", "reflectiontype", "reflectionuniontype",
184
+ "reflectionzendextension", "reflector", "regexiterator", "requestparsebodyexception", "returntypewillchange",
185
+ "roundingmode", "runtimeexception", "seekableiterator", "sensitiveparameter", "sensitiveparametervalue", "serializable",
186
+ "sessionhandler", "sessionhandlerinterface", "sessionidinterface", "sessionupdatetimestamphandlerinterface", "shmop",
187
+ "socket", "sodiumexception", "spldoublylinkedlist", "splfileinfo",
188
+ "splfileobject", "splfixedarray", "splheap", "splmaxheap", "splminheap", "splobjectstorage", "splobserver",
189
+ "splpriorityqueue", "splqueue", "splstack", "splsubject", "spltempfileobject", "stdclass", "streambucket", "stringable",
190
+ "sysvmessagequeue", "sysvsemaphore", "sysvsharedmemory", "throwable", "traversable", "typeerror", "underflowexception",
191
+ "unexpectedvalueexception", "unhandledmatcherror", "unitenum", "valueerror", "weakmap", "weakreference"
192
+ ]),
193
+ ruby: new Set([
194
+ "ArgumentError", "Array", "BasicObject", "Binding", "Class", "ClosedQueueError", "Comparable", "Complex", "Data", "Dir",
195
+ "Encoding", "EncodingError", "Enumerable", "Enumerator", "EOFError", "Errno", "Exception", "FalseClass", "Fiber",
196
+ "FiberError", "File", "FileTest", "Float", "FrozenError", "GC", "Hash", "IO", "IOError", "IndexError", "Integer",
197
+ "Interrupt", "Kernel", "KeyError", "LoadError", "LocalJumpError", "Marshal", "MatchData", "Math", "Method", "Module",
198
+ "Mutex", "NameError", "NilClass", "NoMemoryError", "NoMethodError", "NotImplementedError", "Numeric", "Object",
199
+ "ObjectSpace", "Proc", "Process", "Queue", "Ractor", "Random", "Range", "Rational", "Regexp", "RegexpError", "RubyVM",
200
+ "RuntimeError", "ScriptError", "SecurityError", "Signal", "SignalException", "SizedQueue", "StandardError", "StopIteration",
201
+ "String", "Struct", "Symbol", "SyntaxError", "SystemCallError", "SystemExit", "SystemStackError", "Thread", "ThreadError",
202
+ "ThreadGroup", "Time", "TracePoint", "TrueClass", "TypeError", "UnboundMethod", "UncaughtThrowError", "Warning",
203
+ "ZeroDivisionError"
204
+ ]),
205
+ typescript: new Set(["Array", "Boolean", "Map", "Math", "Number", "Object", "ReadonlyArray", "ReadonlyMap", "Reflect", "String"])
206
+ })
207
+
119
208
  /**
120
209
  * Validates an identifier against the target backend's deliberately narrow lexical contract.
121
- * @param {import("../semantic/types.js").SemanticLanguage} language - Target language.
210
+ * @param {import("../semantic/types.js").BackendLanguage} language - Target language.
122
211
  * @param {unknown} name - Candidate semantic identifier.
123
212
  * @param {string} role - Identifier role for diagnostics.
124
213
  * @param {import("../semantic/types.js").SourceLocation | undefined} location - Originating location.
@@ -128,11 +217,16 @@ export function validateTargetIdentifier(language, name, role, location) {
128
217
  if (typeof name != "string") unsupportedCapability(language, `${role} identifier`, location)
129
218
 
130
219
  const reservedName = language == "php" ? name.toLowerCase() : name
220
+ const syntaxLanguage = language == "ios" ? "swift" : language
131
221
 
132
- if (!identifierPatterns[language].test(name) || reservedWords[language].has(reservedName) ||
222
+ if (!identifierPatterns[syntaxLanguage].test(name) || reservedWords[syntaxLanguage].has(reservedName) ||
133
223
  language == "python" && name.normalize("NFKC") != name ||
134
224
  language == "c" && !isCIdentifier(name) ||
135
- language == "cpp" && !isCppIdentifier(name)) {
225
+ language == "rust" && !isRustIdentifier(name) ||
226
+ language == "cpp" && !isCppIdentifier(name) ||
227
+ language == "dart" && !isDartIdentifier(name) ||
228
+ language == "swift" && (!isSwiftIdentifier(name) || name.normalize("NFC") != name) ||
229
+ language == "kotlin" && (!isKotlinIdentifier(name) || name.normalize("NFC") != name)) {
136
230
  unsupportedCapability(language, `${role} identifier '${name}'`, location)
137
231
  }
138
232
  }
@@ -150,7 +244,7 @@ export function isCIdentifier(name) {
150
244
 
151
245
  /**
152
246
  * Validates a binding identifier against target restrictions beyond general identifier syntax.
153
- * @param {import("../semantic/types.js").SemanticLanguage} language - Target language.
247
+ * @param {import("../semantic/types.js").BackendLanguage} language - Target language.
154
248
  * @param {unknown} name - Candidate semantic identifier.
155
249
  * @param {string} role - Binding role for diagnostics.
156
250
  * @param {import("../semantic/types.js").SourceLocation | undefined} location - Originating location.
@@ -162,7 +256,7 @@ export function validateTargetBindingIdentifier(language, name, role, location)
162
256
  const invalidTypeScriptBinding = language == "typescript" && (name == "arguments" || name == "eval")
163
257
  const invalidPhpVariable = language == "php" && typeof name == "string" &&
164
258
  ((role == "parameter" && phpInvalidParameterBindings.has(name)) ||
165
- ((role == "local" || role == "assignment target") && phpInvalidAssignedBindings.has(name)))
259
+ ((role == "local" || role == "assignment target" || role == "catch binding") && phpInvalidAssignedBindings.has(name)))
166
260
  const invalidRubyBinding = language == "ruby" && typeof name == "string" && /^_[1-9]$/u.test(name)
167
261
 
168
262
  if (invalidTypeScriptBinding || invalidPhpVariable || invalidRubyBinding) {
@@ -170,6 +264,25 @@ export function validateTargetBindingIdentifier(language, name, role, location)
170
264
  }
171
265
  }
172
266
 
267
+ /**
268
+ * Validates a nominal record/type declaration name for the original-five targets.
269
+ * @param {import("../semantic/types.js").BackendLanguage} language - Backend language.
270
+ * @param {unknown} name - Candidate type name.
271
+ * @param {import("../semantic/types.js").SourceLocation | undefined} location - Declaration location.
272
+ * @returns {void}
273
+ */
274
+ export function validateTargetTypeIdentifier(language, name, location) {
275
+ if (typeof name != "string" || !/^[A-Z][A-Za-z0-9_]*$/u.test(name)) {
276
+ unsupportedCapability(language, `record type identifier '${String(name)}'`, location)
277
+ }
278
+ const reservedName = language == "php" ? name.toLowerCase() : name
279
+ const syntaxLanguage = language == "ios" ? "swift" : language
280
+
281
+ if (reservedWords[syntaxLanguage].has(reservedName) || reservedTypeNames[language]?.has(reservedName)) {
282
+ unsupportedCapability(language, `record type identifier '${name}'`, location)
283
+ }
284
+ }
285
+
173
286
  /**
174
287
  * Protects C++ keywords, the actual included C library names/macros and the scaffold namespace.
175
288
  * @param {string} name - Caller scalar binding or function name.
@@ -178,3 +291,41 @@ export function validateTargetBindingIdentifier(language, name, role, location)
178
291
  export function isCppIdentifier(name) {
179
292
  return isCIdentifier(name) && !name.includes("__") && !reservedWords.cpp.has(name)
180
293
  }
294
+
295
+ /**
296
+ * Protects the edition-2021 scalar, entry and exact helper environment in both directions.
297
+ * @param {string} name - Caller-owned function or binding name.
298
+ * @returns {boolean} Whether ordinary Rust syntax can represent the name safely.
299
+ */
300
+ export function isRustIdentifier(name) {
301
+ return identifierPatterns.rust.test(name) && !reservedWords.rust.has(name) && !name.startsWith("semantifold_")
302
+ }
303
+
304
+ /**
305
+ * Protects Swift keywords, scalar names, entry plumbing, and target-only helper names.
306
+ * @param {string} name - Caller-owned function or binding name.
307
+ * @returns {boolean} Whether ordinary unescaped Swift syntax can preserve the name.
308
+ */
309
+ export function isSwiftIdentifier(name) {
310
+ return identifierPatterns.swift.test(name) && !reservedWords.swift.has(name) && !name.startsWith("semantifold_")
311
+ }
312
+
313
+ /**
314
+ * Protects Kotlin keywords, JVM scalar/scaffold names, and target-only helper names.
315
+ * @param {string} name - Caller-owned function or binding name.
316
+ * @returns {boolean} Whether ordinary unescaped Kotlin syntax can preserve the name.
317
+ */
318
+ export function isKotlinIdentifier(name) {
319
+ return identifierPatterns.kotlin.test(name) && !reservedWords.kotlin.has(name) && !name.startsWith("semantifold_") &&
320
+ !name.startsWith("SEMANTIFOLD_")
321
+ }
322
+
323
+ /**
324
+ * Protects Dart keywords, VM scalar/scaffold names, and compiler-owned helpers.
325
+ * @param {string} name - Caller-owned function or binding name.
326
+ * @returns {boolean} Whether ordinary Dart syntax can preserve the name.
327
+ */
328
+ export function isDartIdentifier(name) {
329
+ return identifierPatterns.dart.test(name) && !reservedWords.dart.has(name) &&
330
+ !name.startsWith("_semantifold") && name.normalize("NFC") == name
331
+ }
@@ -7,6 +7,7 @@ import {validateNativeGraph} from "./native-validation.js"
7
7
  import {validateBackendModule} from "./shared.js"
8
8
  import {SourceWriter} from "./writer.js"
9
9
  import {finalizeMapping, toSourceMapV3} from "../mapping.js"
10
+ import {preflightEffectCapabilities} from "./effects.js"
10
11
  const syntheticArtifactBase = Object.freeze(["__semantifold_artifacts__"])
11
12
 
12
13
  /**
@@ -38,12 +39,30 @@ export function generateArtifactSource({language, filename, mapDirective = "none
38
39
  if (record.artifactMultiplicity != "single") unsupportedRole(language, "single-text backend", module?.location)
39
40
  if (filename === undefined) filename = record.defaultFilename
40
41
  if (sourceMapFilename === undefined) sourceMapFilename = `${filename}.map`
41
- if (language == "cpp") validateNativeGraph(module, "cpp")
42
- validateBackendModule(module, language)
42
+ const genericDeclaration = [...module?.records ?? [], ...module?.functions ?? []]
43
+ .find((declaration) => (declaration?.typeParameters?.length ?? 0) > 0)
44
+
45
+ if (genericDeclaration && !record.features.typeParametersAndGenerics) {
46
+ unsupportedCapability(/** @type {import("../semantic/types.js").BackendLanguage} */ (language),
47
+ "Task 012 type parameters and generics", genericDeclaration.location ?? module.location)
48
+ }
49
+ if (Array.isArray(module?.records) && module.records.length > 0 && !record.features.closedRecords) {
50
+ unsupportedCapability(/** @type {import("../semantic/types.js").BackendLanguage} */ (language),
51
+ "Task 009 closed records", module.records[0].location ?? module.location)
52
+ }
53
+ preflightEffectCapabilities(module, /** @type {import("../semantic/types.js").BackendLanguage} */ (language))
54
+ if (language == "cpp" || language == "kotlin" || language == "swift") validateNativeGraph(module, language)
55
+ validateBackendModule(module, /** @type {import("../semantic/types.js").BackendLanguage} */ (language))
43
56
 
44
57
  if (language == "cpp" && (mapDirective != "none" || sourceMapFilename != "program.cpp.map")) {
45
58
  unsupportedCapability(language, "CPP map directive or alternate source-map filename", module.location)
46
59
  }
60
+ if (language == "swift" && (mapDirective != "none" || sourceMapFilename != "program.swift.map")) {
61
+ unsupportedCapability(language, "Swift map directive or alternate source-map filename", module.location)
62
+ }
63
+ if (language == "kotlin" && (mapDirective != "none" || sourceMapFilename != "Program.kt.map")) {
64
+ unsupportedCapability(language, "Kotlin map directive or alternate source-map filename", module.location)
65
+ }
47
66
 
48
67
  if (!isValidFilenameMetadata(filename)) {
49
68
  throw new TypeError("Generated filename must be a non-empty single-line string.")
@@ -52,6 +71,8 @@ export function generateArtifactSource({language, filename, mapDirective = "none
52
71
  throw new TypeError("Source map filename must be a non-empty single-line string.")
53
72
  }
54
73
  if (language == "cpp" && filename != "program.cpp") unsupportedCapability(language, "artifact filename other than program.cpp", module.location)
74
+ if (language == "swift" && filename != "program.swift") unsupportedCapability(language, "artifact filename other than program.swift", module.location)
75
+ if (language == "kotlin" && filename != "Program.kt") unsupportedCapability(language, "artifact filename other than Program.kt", module.location)
55
76
  if (language == "java" && filename.split(/[\\/]/u).at(-1) != "Main.java") {
56
77
  unsupportedCapability(language, "artifact filename basename other than Main.java", module.location)
57
78
  }
@@ -81,6 +102,10 @@ export function generateArtifactSource({language, filename, mapDirective = "none
81
102
 
82
103
  const mapping = finalizeMapping(writer.finish())
83
104
 
105
+ if (language == "swift" || language == "kotlin") {
106
+ languageRegistry.resolve(language, "frontend", module.location)({filename, source: mapping.generated.content})
107
+ }
108
+
84
109
  return {
85
110
  code: mapping.generated.content,
86
111
  filename,