Repository navigation
feat: include closure 跨ぎの型/関数共有と generation dist 導入 #120
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
base: wiki-stage1a-serving
Are you sure you want to change the base?
Changes from all commits
1c9a477
773cecb
97688e6
ae84f92
75d1169
5a9e161
5ba0cf7
3f89404
3100de3
e3edbfe
aca3671
a29364d
780de69
b724586
006fe8d
3260257
7a9516f
dcadd8b
41314c0
dbcc13e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| # SPDX-License-Identifier: MIT | ||
| @include "dsl/util.awk" | ||
| @include "dsl/lex.awk" | ||
| @include "dsl/rpn.awk" | ||
| @include "dsl/parse.awk" | ||
| @include "dsl/check.awk" | ||
|
|
||
| function q(s) { | ||
| gsub(/\\/, "\\\\", s) | ||
| gsub(/"/, "\\\"", s) | ||
| return "\"" s "\"" | ||
| } | ||
|
|
||
| function emit_shared(out, k, p, n, v) { | ||
| print "BEGIN {" > out | ||
| for (k in V2_RECORD_TYPE) | ||
| printf " V2_SHARED_RECORD_TYPE[%s] = 1\n", q(k) > out | ||
| for (k in V2_RECORD_FIELDS) { | ||
| split(k, p, SUBSEP) | ||
| printf " V2_SHARED_RECORD_FIELDS[%s, %s] = %s\n", q(p[1]), q(p[2]), q(V2_RECORD_FIELDS[k]) > out | ||
| } | ||
| for (k in ALIAS) | ||
| printf " V2_SHARED_ALIAS[%s] = %s\n", q(k), q(ALIAS[k]) > out | ||
| for (k in SIG) { | ||
| split(k, p, SUBSEP) | ||
| printf " V2_SHARED_SIG[%s, %s] = %s\n", q(p[1]), q(p[2]), q(SIG[k]) > out | ||
| } | ||
| for (k in V2_RAW_FUNC) | ||
| printf " V2_SHARED_RAW_FUNC[%s] = 1\n", q(k) > out | ||
| print "}" > out | ||
| } | ||
|
|
||
| BEGIN { | ||
| if (V2_INDEX_LIST == "") exit 1 | ||
| V2_INDEX_MODE = 1 | ||
| n = split(V2_INDEX_LIST, files, SUBSEP) | ||
| for (i = 1; i <= n; i++) { | ||
| if (files[i] == "") continue | ||
| delete V2_INDEX_RUN_FIELDS | ||
| delete V2_INDEX_RUN_RECORDS | ||
| delete V2_INDEX_OLD_FIELDS | ||
| for (k in V2_INDEX_RECORD_FIELDS) V2_INDEX_OLD_FIELDS[k] = V2_INDEX_RECORD_FIELDS[k] | ||
| delete V2_INDEX_OLD_RECORDS | ||
| for (k in V2_INDEX_RECORD_NAMES) V2_INDEX_OLD_RECORDS[k] = 1 | ||
| v2_lex(files[i]) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This loop indexes every file in a single gawk process, but Useful? React with 👍 / 👎.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in 780de69.
回帰テスト |
||
| v2_rpn() | ||
| for (k in V2_RECORD_FIELDS) { | ||
| if ((k in V2_INDEX_RECORD_FIELDS) && V2_INDEX_RECORD_FIELDS[k] != V2_RECORD_FIELDS[k]) { | ||
| print "[hawk-libs] index failed: conflicting record field definition" > "/dev/stderr" | ||
| exit 1 | ||
| } | ||
| V2_INDEX_RECORD_FIELDS[k] = V2_RECORD_FIELDS[k] | ||
| } | ||
| for (k in V2_INDEX_OLD_FIELDS) { | ||
| split(k, p, SUBSEP) | ||
| if ((p[1] in V2_INDEX_RUN_RECORDS) && !(k in V2_INDEX_RUN_FIELDS)) { | ||
| print "[hawk-libs] index failed: conflicting record field definition" > "/dev/stderr" | ||
| exit 1 | ||
| } | ||
| } | ||
| for (k in V2_INDEX_RUN_FIELDS) { | ||
| split(k, p, SUBSEP) | ||
| if ((p[1] in V2_INDEX_OLD_RECORDS) && !(k in V2_INDEX_OLD_FIELDS)) { | ||
| print "[hawk-libs] index failed: conflicting record field definition" > "/dev/stderr" | ||
| exit 1 | ||
| } | ||
| } | ||
| for (k in V2_INDEX_RUN_RECORDS) { | ||
| if (k in V2_INDEX_ALIAS) { | ||
| print "[hawk-libs] index failed: type name is both record and alias: " k > "/dev/stderr" | ||
| exit 1 | ||
| } | ||
| V2_INDEX_RECORD_NAMES[k] = 1 | ||
| } | ||
| v2_parse() | ||
| v2_collect(1) | ||
| v2_collect_raw_funcs() | ||
| for (k in ALIAS) { | ||
| if (k in V2_INDEX_RECORD_NAMES) { | ||
| print "[hawk-libs] index failed: type name is both record and alias: " k > "/dev/stderr" | ||
| exit 1 | ||
| } | ||
| if ((k in V2_INDEX_ALIAS) && V2_INDEX_ALIAS[k] != ALIAS[k]) { | ||
| print "[hawk-libs] index failed: conflicting type alias definition: " k > "/dev/stderr" | ||
| exit 1 | ||
| } | ||
| V2_INDEX_ALIAS[k] = ALIAS[k] | ||
|
Comment on lines
+78
to
+87
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
When one file in the include closure defines Useful? React with 👍 / 👎.
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 対応しました。record 登録時に同名が既存 alias にあれば拒否、alias 登録時に同名が既存/現在の record にあれば拒否と、両方向の衝突を index 時点で fail closed にしています。テスト |
||
| } | ||
| for (k in SIG) { | ||
| if ((k in V2_INDEX_SIG) && V2_INDEX_SIG[k] != SIG[k]) { | ||
| print "[hawk-libs] index failed: conflicting function signature: " k > "/dev/stderr" | ||
| exit 1 | ||
| } | ||
| V2_INDEX_SIG[k] = SIG[k] | ||
| } | ||
| } | ||
| emit_shared(V2_INDEX_OUT) | ||
| exit 0 | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When an included file provides a typed function and the entry calls it from an otherwise raw AWK function, this merge point is too late:
v2_lexhas already built the function-call detector without the shared signatures, so the call line stays RAWLINE and skipsv2_check_calls. For example, withlib.awkdefiningfunction normalize(x: Str) -> Strandmain.awkcontainingfunction caller() { return normalize(1) },hawk-libs desugarexits 0, whereas the same declarations in one file correctly report theStr/Intmismatch.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
対応しました。
v2_merge_shared_pre_rpn()の呼び出しをv2_lex()の前に移し、マージ対象をV2_SHARED_SIG/V2_SHARED_ALIAS/V2_SHARED_RAW_FUNCにも拡張しています(従来は record 型/フィールドのみで、しかも lex の後というタイミングも誤っていました)。テストshared_signature_checks_raw_caller(include 先のnormalize(x: Str) -> Strを raw AWK の caller がnormalize(123)で呼ぶ型不一致が検出されること)を追加しています。