Repository navigation
fix(codegen,modules,json): local shadowing, transitive collisions, runtime pruning, stringify escapes; add Url #798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+1,023
−64
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
902d3c5
feat(stdlib): JSON object keys and Url; fix stringify escapes and loc…
claude ad46652
fix(modules): reject transitive public name collisions when flattening
claude 04a5c1a
fix(modules): one declaration reached by two paths is not a collision
claude 7ca7731
fix(codegen): emit only the runtime helpers a Bun-ESM module reaches
claude 11ee9ad
fix(codegen,json): address review of #798
claude ce22b22
refactor(json): move object-key enumeration to its own PR
claude 50b7b96
fix(codegen): end block-local bindings with their block
claude 2ed6e76
feat(json): enumerate JSON object members (hpm_json_object_len/_key) …
hyperpolymath ff5c3ba
fix(codegen,json): preserve integer scope and call typing and clarify…
coderabbitai[bot] 7ae4d52
Merge origin/main into claude/gifted-lamport-k0mc5l
HoTT-stuff 7c2f8b1
fix(codegen-bun): Int typing of local callables and block assignments…
HoTT-stuff File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| // SPDX-License-Identifier: MPL-2.0 | ||
| // SPDX-FileCopyrightText: 2026 hyperpolymath | ||
| // | ||
| // Url.affine — URL parsing and reference resolution. | ||
| // | ||
| // Semantics are the WHATWG URL Standard's, because the hosts these programs | ||
| // run in (browsers, extensions, Bun, Deno) resolve URLs that way, and code | ||
| // that compares or rewrites URLs must agree with them. WHATWG differs from | ||
| // RFC 3986 in places (backslashes, default ports, host normalisation), so a | ||
| // hand-rolled RFC 3986 resolver would silently disagree with the host. | ||
| // | ||
| // Portability: both externs are lowered by the ESM backend | ||
| // (lib/codegen_deno.ml) to the host's `URL` constructor. There is no native | ||
| // lowering yet; a native backend must supply a WHATWG-conformant parser | ||
| // before these can be used there. | ||
|
|
||
| module Url; | ||
|
|
||
| use prelude::{Option, Some, None}; | ||
|
|
||
| /// The components of a parsed absolute URL, as WHATWG's URL API reports | ||
| /// them: `protocol` keeps its trailing ":", `search` its leading "?" and | ||
| /// `hash` its leading "#"; absent parts are "". | ||
| pub type UrlParts = { | ||
| href: String, | ||
| protocol: String, | ||
| username: String, | ||
| password: String, | ||
| host: String, | ||
| hostname: String, | ||
| port: String, | ||
| pathname: String, | ||
| search: String, | ||
| hash: String | ||
| } | ||
|
|
||
| /// Resolve `href` against `base`. `base` "" means no base, so `href` must | ||
| /// itself be absolute. `None` when the result is not a valid URL. | ||
| pub extern fn url_resolve(href: String, base: String) -> Option<String>; | ||
|
|
||
| /// Parse an absolute URL. `None` when `s` is not one. | ||
| pub extern fn url_parse(s: String) -> Option<UrlParts>; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| (* SPDX-License-Identifier: MPL-2.0 *) | ||
| open Affinescript | ||
|
|
||
| (* Exercise emission directly: the frontend currently rejects nested | ||
| statement bindings that shadow an enclosing binding with another type. *) | ||
| let count_truncs src = | ||
| let prog = Parse_driver.parse_string ~file:"<int_scope>" src in | ||
| let loader = Module_loader.create (Module_loader.default_config ()) in | ||
| let ctx = match Resolve.resolve_program_with_loader prog loader with | ||
| | Ok (ctx, _) -> ctx | ||
| | Error (e, _) -> Alcotest.fail (Resolve.show_resolve_error e) | ||
| in | ||
| match Codegen_deno.codegen_bun prog ctx.symbols with | ||
| | Error e -> Alcotest.fail e | ||
| | Ok js -> Test_int_div_js.count_occurrences ~needle:"Math.trunc(" js | ||
|
|
||
| let expect_truncs what n src = | ||
| Alcotest.(check int) what n (count_truncs src) | ||
|
|
||
| let check_divisions = expect_truncs "only the Int division truncates" 1 | ||
|
|
||
| let tests = [ | ||
| Alcotest.test_case "inner Int preserves outer Float" `Quick (fun () -> | ||
| check_divisions {|pub fn f() -> Float { | ||
| let x = 7.0; let y = 2.0; | ||
| { let x = 9; let y = 2; x / y; }; | ||
| x / y | ||
| }|}); | ||
| Alcotest.test_case "inner Float preserves outer Int" `Quick (fun () -> | ||
| check_divisions {|pub fn f() -> Int { | ||
| let x = 7; | ||
| { let x = 9.0; x / 2.0; }; | ||
| x / 2 | ||
| }|}); | ||
| (* An assignment in a nested block changes the enclosing variable, so the | ||
| Int it records outlives the block. *) | ||
| Alcotest.test_case "Int assigned in a block to an enclosing var" `Quick (fun () -> | ||
| expect_truncs "the division after the block truncates" 1 | ||
| {|pub fn f(flag: Bool) -> Int { | ||
| let mut n = match flag { true => 5, false => 7 }; | ||
| { n = 5; }; | ||
| n / 2 | ||
| }|}); | ||
| (* ... but not when the block declared its own binding of that name. *) | ||
| Alcotest.test_case "Int assigned to a block's own binding" `Quick (fun () -> | ||
| expect_truncs "the outer Float division does not truncate" 0 | ||
| {|pub fn f() -> Float { | ||
| let mut n = 7.0; | ||
| { let mut n = 0.0; n = 5; }; | ||
| n / 2.0 | ||
| }|}); | ||
| (* A lambda parameter is scoped to the lambda: an Int assigned to it does | ||
| not classify a same-named outer Float. *) | ||
| Alcotest.test_case "Int assigned to a lambda parameter" `Quick (fun () -> | ||
| expect_truncs "the outer Float division does not truncate" 0 | ||
| {|pub fn f() -> Float { | ||
| let k = 7.0; | ||
| let g = |k| { k = 4; 0 }; | ||
| k / 2.0 | ||
| }|}); | ||
| (* A callable local is classified by its own declared return type. *) | ||
| Alcotest.test_case "Int-returning callable parameter" `Quick (fun () -> | ||
| expect_truncs "len(s) / 2 truncates" 1 | ||
| {|pub fn f(len: fn(String) -> Int) -> Int { len("abcde") / 2 }|}); | ||
| Alcotest.test_case "Float-returning callable shadows intrinsic" `Quick (fun () -> | ||
| expect_truncs "len(s) / 2.0 does not truncate" 0 | ||
| {|pub fn f(len: fn(String) -> Float) -> Float { len("abcde") / 2.0 }|}); | ||
| Alcotest.test_case "Int-returning callable let" `Quick (fun () -> | ||
| expect_truncs "w(s) / 2 truncates" 1 | ||
| {|pub fn f() -> Int { | ||
| let w: fn(String) -> Int = |s| 5; | ||
| w("abcde") / 2 | ||
| }|}); | ||
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.