infer/aot: allow C++-keyword function names via AOT name-mangling#2655
Merged
Conversation
`def float(...)`, `def int(...)`, `def double(...)`, `def do(...)` were rejected with error[30163] "invalid function name" — surprising next to `def string(...)` and `def float2(...)`, which compiled fine. The parser accepts all of them (function_name → das_type_name); a post-parse lint guard was the gate, rejecting any name in a hardcoded C++-keyword set. The asymmetry was just that set: `float` / `int` / `double` are C++ keywords, but `float2` / `string` / `int2` aren't. Drop the function-name guard and have the AOT emitter mangle keyword names the same way it already mangles operator overloads. - daslib/aot_cpp.das: aotSuffixNameEx now seeds prefix = is_cpp_keyword, so `def float` AOTs to `_Funcfloat_<hash>` (valid C++) instead of literal `float`. - src/ast/ast_lint.cpp: remove isValidFunctionName + its callsite. The other 5 isCppKeyword guards (module/enum/enum-value/struct/field) stay — those embed 1:1 into C++ and need the guard. - tests/language/failed_reserved_names.das: drop the `def do` case and 30163 from the expect line. - tests/aot/test_cpp_keyword_names.das: positive test exercising `def float`/`def int`/`def double`/`def do` via interpreter, AOT, and JIT. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
Removes the post-parse lint guard that rejected daslang function names matching C++ keywords (float, int, double, do, …) and instead reuses the existing AOT name-mangler (aotSuffixNameEx) so those names emit as valid C++ identifiers (e.g. _Funcfloat_<hash>). Other identifier classes (module/enum/struct/field) that still embed 1:1 into C++ keep their guard.
Changes:
- Seed
aotSuffixNameEx'sprefixflag withis_cpp_keyword(funcName)so keyword names get the_Funcprefix already used for operator overloads. - Drop
isValidFunctionNameand its invocation fromast_lint.cpp. - Update
failed_reserved_names.das(removedef docase and30163fromexpect) and add a positive AOT/JIT/interpreter testtest_cpp_keyword_names.das.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| daslib/aot_cpp.das | Seed mangler's prefix flag with is_cpp_keyword so keyword names get _Func prefix in AOT C++ output. |
| src/ast/ast_lint.cpp | Remove obsolete function-name C++-keyword lint guard now that AOT mangling handles it. |
| tests/language/failed_reserved_names.das | Drop the def do failing-case and 30163 from the expected error list. |
| tests/aot/test_cpp_keyword_names.das | New positive test exercising def float/int/double/do for interpreter + AOT + JIT. |
| mouse-data/docs/*.md | Three personal Q&A notes documenting the parser-vs-lint asymmetry, the AOT mangler, and the failed_* test convention; no behavior impact. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Inspiration
Summary
def float(...),def int(...),def double(...),def do(...)were rejected witherror[30163] invalid function name— a surprising asymmetry next todef string(...)anddef float2(...), which always compiled fine. The parser accepts all of them (function_name → das_type_nameinsrc/parser/ds2_parser.ypp:1316-1408); a post-parse lint guard atsrc/ast/ast_lint.cpp:867-884was the actual gate, rejecting any function name in a hardcoded C++-keyword set. The asymmetry was just that set:float/int/double/doare C++ keywords, butfloat2/string/int2are daslang-specific identifiers that happen not to clash.The lint guard existed because the AOT C++ emitter would otherwise generate a literal
float(...)C++ function, which is invalid. But the emitter already has a name-rewriting helper (aotSuffixNameEx) used for operator overloads — it just didn't kick in for plain alphanumeric names. This PR has it kick in for C++-keyword names too, and drops the now-redundant function-name lint guard.daslib/aot_cpp.das—aotSuffixNameExseedsprefix = is_cpp_keyword(funcName)so C++-keyword names get the_Funcprefix already used for operator overloads (def +→_FuncAdd_<hash>). After this,def floatemits as_Funcfloat_<hash>.src/ast/ast_lint.cpp— dropisValidFunctionNameand its callsite. The other 5isCppKeywordcallsites (module / enum / enum-value / struct / struct-field names) stay — those embed 1:1 into C++ and need the guard.tests/language/failed_reserved_names.das— drop thedef docase and30163from theexpectline.tests/aot/test_cpp_keyword_names.das(new) — positive test exercisingdef float/def int/def double/def dovia interpreter + AOT + JIT round-trip.Scope is function names only; struct/enum/module/etc. names still 1:1 into C++ identifiers and are correctly out of scope.
Generated C++ for the new test (excerpt) confirms the mangling fires:
Includes three
mouse-data/docs/*.mdblind-mouse cards capturing the diagnosis (parser vs lint asymmetry, AOT name mangler details,failed_*test-prefix convention) — personal Q&A cache, no behavior impact.Test plan
examples/wip.das(the originally failing case from the report) now compiles cleantests/language/failed_reserved_names.dasstill PASSes (matches newexpectline — codes 30106:3, 30146, 30148, 30152, 30240, 30282)tests/aot/test_cpp_keyword_names.das— interpreter: 5/5 PASStests/aot/test_cpp_keyword_names.das— AOT round-trip viatest_aot dastest/dastest.das -use-aot -- --use-aot --run …: 5/5 PASStests/aot/test_cpp_keyword_names.das— JIT viadaslang dastest/dastest.das -jit -- --run …: 5/5 PASS_Funcfloat_<hash>/_Funcint_<hash>/_Funcdouble_<hash>/_Funcdo_<hash>present at def + call + wrapper sitestests/language/regression: 927/927 PASStests/aot/regression: 69/69 PASStests/interpreter regression: 8016/8022 PASS (6 environment-conditional skips, 0 failed, 0 errors)mcp__daslang__linton changed.dasfiles: 0 issuesmcp__daslang__format_fileon changed.dasfiles: already formatted🤖 Generated with Claude Code