René's URL Explorer Experiment


Title: Add `if (var x = expr)` and `map[k].field op= rhs` by congwang-mk · Pull Request #19 · multikernel/kernelscript · GitHub

Open Graph Title: Add `if (var x = expr)` and `map[k].field op= rhs` by congwang-mk · Pull Request #19 · multikernel/kernelscript

X Title: Add `if (var x = expr)` and `map[k].field op= rhs` by congwang-mk · Pull Request #19 · multikernel/kernelscript

Description: Summary Two new statement forms for ergonomic map access, plus the doc and test work pinning them down. if (var x = expr) { ... } else { ... } — declaration-as-condition. Binds x only inside the truthy branch; the branch is taken iff expr produces a present value (map hit, non-null pointer return). Lowers to a single bpf_map_lookup_elem plus a null check; for struct-valued maps the body's field operations mutate the entry in place via the underlying lookup pointer (no manual write-back). m[k].field op= rhs — compound assignment on a struct-field of a map value. Lowers to a presence-checked if (p) { p->field = p->field op rhs; } against the same single lookup. Absent entries are a no-op (no creation), distinguishing it from the existing scalar m[k] op= rhs which creates on first use. Bundled deliverables: examples/maps_demo.ks and examples/map_operations_demo.ks: rewrite the read-modify-write blocks to use the new idiom (drops 13 LoC, removes redundant write-backs). README.md: replace the misleading lookup_or_create snippet with paired examples; add an "Ergonomic map idioms" bullet to the solution checklist. SPEC.md: new §6.2.5 (compound assignment with map indexing — scalar and struct-field forms with full semantics: LHS shape, type rules, presence/creation semantics, lowering shape), new §7.5.1.2 (declaration-as-condition with single-evaluation, scoping, and lowering); assignment_statement and if_statement EBNF productions expanded from the prior shorthand into the seven forms the parser actually implements. Also fixes the §6.2.3 example, which used stats.field += 1 on a value-bound stats — a shape the parser has never accepted. tests/test_iflet.ml (new): 10 tests across parse, type-check, and codegen-string layers — covers struct/scalar bindings, else, else if (var ...) chains, binding-leak rejections (then-branch only), and the in-place-mutation codegen shape. tests/test_compound_index_assignment.ml: extend the Phase 2 test with a codegen-string check pinning the synthetic-pointer-binding path that the codegen-fix in this PR repaired (verified by temporarily reverting the fix — test flips red on "synthetic binding does NOT use deref-load init"). 84 alcotest suites pass (was 83); the new test_iflet suite is the +1. Test plan eval \$(opam env) && dune build && dune runtest --force — 84 suites green cd /tmp && cp .ks . && kernelscript compile .ks -o out && cd out && make — example end-to-end build for maps_demo.ks (clean) and a minimal m[k].field += 1 source (clean) Skim the eBPF C output for a Phase 2 source — confirms bpf_map_lookup_elem happens once, presence is checked against NULL, and the mutation is ptr->field = ... Spot-check generated C for a struct-map IfLet — confirms the dead value-typed local declaration plus the in-place-mutation through the lookup pointer (this is the existing user-written-IfLet shape, locked in by tests/test_iflet.ml::codegen_struct_value_binding_shape) 🤖 Generated with Claude Code

Open Graph Description: Summary Two new statement forms for ergonomic map access, plus the doc and test work pinning them down. if (var x = expr) { ... } else { ... } — declaration-as-condition. Binds x only inside the t...

X Description: Summary Two new statement forms for ergonomic map access, plus the doc and test work pinning them down. if (var x = expr) { ... } else { ... } — declaration-as-condition. Binds x only inside the t...

Opengraph URL: https://github.com/multikernel/kernelscript/pull/19

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:70ffffd3-a893-8bf3-beec-b08c93a02569
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-id831A:76DE3:F8718A:16534D5:6A622A3F
html-safe-nonceb84dd0dd0ab6dc261e855539e0861aaf89715eeeaee36cd83242b9aad8ad93d8
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MzFBOjc2REUzOkY4NzE4QToxNjUzNEQ1OjZBNjIyQTNGIiwidmlzaXRvcl9pZCI6IjIwNTA5MTc2NTM4MDA5NTQ0MzEiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacb66d79f67e64444c903fe58409f22c02c53d1080e08a2426dd519bcfef0bfd82
hovercard-subject-tagpull_request:3633076677
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/multikernel/kernelscript/pull/19/files
twitter:imagehttps://avatars.githubusercontent.com/u/227915880?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/227915880?s=400&v=4
og:image:altSummary Two new statement forms for ergonomic map access, plus the doc and test work pinning them down. if (var x = expr) { ... } else { ... } — declaration-as-condition. Binds x only inside the t...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None0e882415c7b47986d65f899389c870b31642bb1c6f36516eb042618596c60e62
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/multikernel/kernelscript git https://github.com/multikernel/kernelscript.git
octolytics-dimension-user_id202362072
octolytics-dimension-user_loginmultikernel
octolytics-dimension-repository_id1019261571
octolytics-dimension-repository_nwomultikernel/kernelscript
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id1019261571
octolytics-dimension-repository_network_root_nwomultikernel/kernelscript
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release230e2af5fc0870303dd4569d72d2bb393ed52c52
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/multikernel/kernelscript/pull/19/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmultikernel%2Fkernelscript%2Fpull%2F19%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
Code QualityEnforce quality at mergehttps://github.com/features/code-quality
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmultikernel%2Fkernelscript%2Fpull%2F19%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=multikernel%2Fkernelscript
Reloadhttps://github.com/multikernel/kernelscript/pull/19/files
Reloadhttps://github.com/multikernel/kernelscript/pull/19/files
Reloadhttps://github.com/multikernel/kernelscript/pull/19/files
Please reload this pagehttps://github.com/multikernel/kernelscript/pull/19/files
multikernel https://github.com/multikernel
kernelscripthttps://github.com/multikernel/kernelscript
Notifications https://github.com/login?return_to=%2Fmultikernel%2Fkernelscript
Fork 23 https://github.com/login?return_to=%2Fmultikernel%2Fkernelscript
Star 501 https://github.com/login?return_to=%2Fmultikernel%2Fkernelscript
Code https://github.com/multikernel/kernelscript
Issues 2 https://github.com/multikernel/kernelscript/issues
Pull requests 0 https://github.com/multikernel/kernelscript/pulls
Actions https://github.com/multikernel/kernelscript/actions
Projects https://github.com/multikernel/kernelscript/projects
Security and quality 0 https://github.com/multikernel/kernelscript/security
Insights https://github.com/multikernel/kernelscript/pulse
Code https://github.com/multikernel/kernelscript
Issues https://github.com/multikernel/kernelscript/issues
Pull requests https://github.com/multikernel/kernelscript/pulls
Actions https://github.com/multikernel/kernelscript/actions
Projects https://github.com/multikernel/kernelscript/projects
Security and quality https://github.com/multikernel/kernelscript/security
Insights https://github.com/multikernel/kernelscript/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fmultikernel%2Fkernelscript%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fmultikernel%2Fkernelscript%2Fissues%2Fnew%2Fchoose
congwang-mkhttps://github.com/congwang-mk
mainhttps://github.com/multikernel/kernelscript/tree/main
iflet-and-map-field-compoundhttps://github.com/multikernel/kernelscript/tree/iflet-and-map-field-compound
Conversation 1 https://github.com/multikernel/kernelscript/pull/19
Commits 9 https://github.com/multikernel/kernelscript/pull/19/commits
Checks 1 https://github.com/multikernel/kernelscript/pull/19/checks
Files changed https://github.com/multikernel/kernelscript/pull/19/files
Please reload this pagehttps://github.com/multikernel/kernelscript/pull/19/files
Add if (var x = expr) and map[k].field op= rhs https://github.com/multikernel/kernelscript/pull/19/files#top
Show all changes 9 commits https://github.com/multikernel/kernelscript/pull/19/files
e4f979c feat: add `if (var x = expr)` declaration-as-condition congwang-mk Apr 26, 2026 https://github.com/multikernel/kernelscript/pull/19/commits/e4f979c7bff205cbb38a7d77eaea2d4e01478137
62b1cc7 feat: add `map[key].field op= rhs` compound assignment congwang-mk May 5, 2026 https://github.com/multikernel/kernelscript/pull/19/commits/62b1cc7feb2ef44e0d2ae0582e1453d4ec55ca79
ca701a7 docs(examples): adopt elegant `if (var x = m[k])` idiom in map demos congwang-mk May 5, 2026 https://github.com/multikernel/kernelscript/pull/19/commits/ca701a754615a9ad50d25e5ab9cb8dfb6fde0a19
7044637 docs: document `if (var x = expr)` and `m[k].field op= rhs` in README… congwang-mk May 5, 2026 https://github.com/multikernel/kernelscript/pull/19/commits/7044637bc4598134fbef9f4455c9332e07d494b9
814e336 test: lock in Phase 1 IfLet and Phase 2 codegen behaviour congwang-mk May 5, 2026 https://github.com/multikernel/kernelscript/pull/19/commits/814e33652e997d53fe8ce85e63d4ba4777d3cbc9
e0ddcd9 feat: drop `none` literal in favour of `null` congwang-mk May 5, 2026 https://github.com/multikernel/kernelscript/pull/19/commits/e0ddcd98565edb417944785c099b2eb4a36ec7b1
d5f25c1 docs(examples,README,SPEC): adopt `if (var x = expr)` for remaining p… congwang-mk May 5, 2026 https://github.com/multikernel/kernelscript/pull/19/commits/d5f25c18f02f795faa7bf2573b85cff6999be8c2
ccd2324 fix(ir-gen): scope IfLet binding to its then-branch via alias table congwang-mk May 6, 2026 https://github.com/multikernel/kernelscript/pull/19/commits/ccd232455f409b17649d8d355cfb7aa9276fb862
198fe92 fix(type-checker): restrict `if (var x = expr)` RHS to presence-produ… congwang-mk May 6, 2026 https://github.com/multikernel/kernelscript/pull/19/commits/198fe92d7e5b0c12a70ce05ef9418f3bdca7ebd7
Clear filters https://github.com/multikernel/kernelscript/pull/19/files
Please reload this pagehttps://github.com/multikernel/kernelscript/pull/19/files
Please reload this pagehttps://github.com/multikernel/kernelscript/pull/19/files
README.md https://github.com/multikernel/kernelscript/pull/19/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5
SPEC.md https://github.com/multikernel/kernelscript/pull/19/files#diff-7426c9e3a694ca6015df5f98637912975f2edea23270203ee89a8bdeed246ee0
map_operations_demo.ks https://github.com/multikernel/kernelscript/pull/19/files#diff-fbf70b8dc2ac26554cdd9e71cfc019d7e59607f2d98b0b3f4ec4a13f33799202
maps_demo.ks https://github.com/multikernel/kernelscript/pull/19/files#diff-975370e04a27a52c5cdedc7aebccd48ba21446d91854cf5dca77bfd4b44ee9b3
object_allocation.ks https://github.com/multikernel/kernelscript/pull/19/files#diff-4d6cd566010741561ae0c55a864ecff20eb47273649e36a2127fef80739a7ca3
rate_limiter.ks https://github.com/multikernel/kernelscript/pull/19/files#diff-371e357454780176e5f7df08392a995b09b6ab5c29f36511b7ed4931aa8a59c5
ringbuf_demo.ks https://github.com/multikernel/kernelscript/pull/19/files#diff-96d6aeba03cfcb95957aca6f70112b1c0d3bca27b5b4ec1b4907eae1d35f2848
safety_demo.ks https://github.com/multikernel/kernelscript/pull/19/files#diff-3ec1c36d0c1195cce5c197f55f08dfce585006b53fa3929c79f85597dbde825c
test_error_handling.ks https://github.com/multikernel/kernelscript/pull/19/files#diff-519b9d96cb2f1b4e5db9c612a1ae965dcc2fe352e3355d4d81acf0cd511c2026
type_checking.ks https://github.com/multikernel/kernelscript/pull/19/files#diff-4536e053897e942b68238eff313592b90e999dbe3cb6f72d600b648a1da2d420
types_demo.ks https://github.com/multikernel/kernelscript/pull/19/files#diff-b2865d6a4fe295b8f139d0d95a0715ac29f7cc1cb83345c133a5f46794869116
ast.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-b5e3d83ee8061a39f9c69482481a1759d85c7d7f6c1cfee7598c5987156b3e9d
ebpf_c_codegen.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-087a8faac5edce9a796f07749864a234f146bca085c99e2bc5761e20f2018b6c
evaluator.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-6b4d2b7d18f3a07a61bb05ea537a20f3be8c44346a5b7338c1598e3a90ef6af0
ir.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-2b848748d43816bd815a34efc941358ca8f66627a72d289483be0541be7b640a
ir_generator.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-7b7b3d36c6a326e1a022a7eaf0e67082de1abe843a789dc49e3580493ba9ffdf
lexer.mll https://github.com/multikernel/kernelscript/pull/19/files#diff-94fdc9b91b11bcb3aba75e939a9f04a375201fbd137e063b0bf67ad7725d38cc
multi_program_analyzer.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-7704336b4cd1a1a1cdd840c524d4cee0430b6a09b86e7dce01a7f9bd7faff74e
parse.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-039309ed6fde77ae928fe309b8c5427cfedb4b56ec44fd19575be76bc3732fb4
parser.mly https://github.com/multikernel/kernelscript/pull/19/files#diff-d7182de4d0ae1030d2c3d76c08002c83f89bb79e6084e9248ff5771dce3beb2c
safety_checker.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-9c4c3cf81b6413c159ebf7c15d0facb48cb1a73a5a83fe5c9de0223032bcb8bf
symbol_table.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-b07dac5bb58209d8a98c507df5f1fe65a299d28b4de33ac0a06738decca31a91
type_checker.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-19547f3bd84789512c822f230e0efa538e8dcef3e62b677be000400b908496fa
userspace_codegen.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-1864935d68899925ab1485ad4f91071ac537e818db74b2dfc6c5979902c7efbf
dune https://github.com/multikernel/kernelscript/pull/19/files#diff-f00bc4a85dc91983057a45088c3b4e6ac0d794731907dabd54d0293b71b22ed8
test_compound_index_assignment.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-321d683b2c74d57781fc104fb08491ae37ee9aaa079f021a382f0c0fec1f6252
test_enum.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-3f149e4d8eacd74a6c58ff9827f6120386b9cf552e2f840ccd1617faaac76602
test_iflet.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-83fa049b871654ecac033bfbd6359bf2e423c69b5965cce8ed4cbe3636b27f59
test_map_integration.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-79dde04e27252cc89683b07d0bf4a8b76cf19e240ac3a92c43c733b3250510e7
test_map_operations.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-6f64dacd55088ae64aad5519efff86532aa5d9732c271a8fdf9a85c657c59f00
test_truthy_falsy.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-26390d1da42f537877faaf0fc882ad9cb4b32bceb782941ff329d90888215c0a
test_type_checker.ml https://github.com/multikernel/kernelscript/pull/19/files#diff-a39bb6b1fc120412284ded2b375cd1061b1566d12a242d49fdead1b9f96a9753
README.mdhttps://github.com/multikernel/kernelscript/pull/19/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5
View file https://github.com/multikernel/kernelscript/blob/198fe92d7e5b0c12a70ce05ef9418f3bdca7ebd7/README.md
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/multikernel/kernelscript/pull/19/{{ revealButtonHref }}
https://github.com/multikernel/kernelscript/pull/19/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5
https://github.com/multikernel/kernelscript/pull/19/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5
https://github.com/multikernel/kernelscript/pull/19/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5
https://github.com/multikernel/kernelscript/pull/19/files#diff-b335630551682c19a781afebcf4d07bf978fb1f8ac04c6bf87428ed5106870f5
Please reload this pagehttps://github.com/multikernel/kernelscript/pull/19/files
Please reload this pagehttps://github.com/multikernel/kernelscript/pull/19/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.