rcompiler 2.1.0 → 2.2.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.
@@ -0,0 +1,416 @@
1
+ // rCompiler 本机能力扩展 — process 进程
2
+ // 接口参考:Alia 语言标准库 process(https://alia.0832.ink/docs/stdlib/process)
3
+ // 编译期生成零外部依赖 Rust(std::process / std::env):
4
+ // - exec 经 shell 执行(失败不中断,错误写入 stderr 结果);
5
+ // - spawn 不经 shell 直接执行(无注入风险),支持 捕获输出/直通终端/丢弃 三种流模式;
6
+ // - exec/spawn 结果存于 last_exec 字段,配套报告器读取(stdout/stderr/code/pid);
7
+ // - 进程信息按目标平台编译期常量(platform/arch),RSS/PPID 仅 Linux(/proc);
8
+ // - 不含 kill(std 无法向任意 PID 发信号,可用 exec 'kill ...' 替代)。
9
+ // 注意:exec/spawn 为同步阻塞调用,多任务(tokio)项目中会阻塞协作线程直至完成。
10
+ (function (util) {
11
+ const ArgumentType = util.ArgumentType ? util.ArgumentType : { STRING: 'r', NUMBER: 'r', BOOLEAN: 'b' };
12
+ const isC = () => !!util.isCompiler;
13
+
14
+ const stuOf = (x) => (x && typeof x.Stu === 'function') ? x.Stu() : ((typeof x === 'string' && x) ? x : '""');
15
+ const numOf = (x) => (x && typeof x.Num === 'function') ? x.Num() : '0.0';
16
+
17
+ // 菜单/字段值读取:fields 优先,inputs 影子兜底(两种 VM 存储形态)
18
+ const gf = (args, name) => {
19
+ const b = args.scope.block;
20
+ if (b.fields && b.fields[name] != null) return String(b.fields[name][0]);
21
+ const inp = b.inputs && b.inputs[name];
22
+ if (Array.isArray(inp)) {
23
+ const sid = (typeof inp[2] === 'string') ? inp[2] : (inp[0] === 1 && typeof inp[1] === 'string' ? inp[1] : null);
24
+ if (sid != null) {
25
+ const sh = args.scope.target.blocks[sid];
26
+ if (sh && sh.fields && sh.fields[name] != null) return String(sh.fields[name][0]);
27
+ }
28
+ }
29
+ return null;
30
+ };
31
+
32
+ // last_exec 字段:exec/spawn 共用(Mutex 跨任务安全;克隆 Mutex 无法复制,
33
+ // 克隆实例的 last_exec 初始为默认值——子进程结果与"发起执行的脚本"同实例语义一致)
34
+ const storeField = () => util.Tools.setstruct([
35
+ ['last_exec', 'std::sync::Mutex<RcompilerProcResult>', 'std::sync::Mutex::new(RcompilerProcResult::empty())']
36
+ ]);
37
+
38
+ // ---- 运行时(std::process / std::env / /proc,零外部依赖)----
39
+ const RT_PROC = [
40
+ // 注意:生成代码的主结构体名为 Default(遮蔽 std 的 Default trait),
41
+ // 不能为 RcompilerProcResult 实现 Default trait——用关联函数 empty()
42
+ '#[derive(Clone)]',
43
+ 'pub struct RcompilerProcResult { pub stdout: String, pub stderr: String, pub code: i32, pub pid: u32 }',
44
+ 'impl RcompilerProcResult {',
45
+ 'pub fn empty() -> Self { Self { stdout: String::new(), stderr: String::new(), code: -1, pid: 0 } }',
46
+ '}',
47
+ 'fn rcompiler_proc_split_args(s: &str) -> Vec<String> {',
48
+ 'let mut out: Vec<String> = Vec::new();',
49
+ 'let mut cur = String::new();',
50
+ 'let mut in_q = false;',
51
+ 'for c in s.chars() {',
52
+ 'if in_q { if c == \'"\' { in_q = false; } else { cur.push(c); } }',
53
+ 'else if c == \'"\' { in_q = true; }',
54
+ 'else if c.is_whitespace() { if !cur.is_empty() { out.push(std::mem::take(&mut cur)); } }',
55
+ 'else { cur.push(c); }',
56
+ '}',
57
+ 'if !cur.is_empty() { out.push(cur); }',
58
+ 'out',
59
+ '}',
60
+ 'pub fn rcompiler_proc_cwd() -> String {',
61
+ 'std::env::current_dir().map(|d| d.to_string_lossy().into_owned()).unwrap_or_default()',
62
+ '}',
63
+ 'pub fn rcompiler_proc_uptime() -> f64 {',
64
+ 'static T0: std::sync::OnceLock<std::time::Instant> = std::sync::OnceLock::new();',
65
+ 'T0.get_or_init(std::time::Instant::now).elapsed().as_secs_f64()',
66
+ '}',
67
+ 'pub fn rcompiler_proc_platform() -> &\'static str {',
68
+ 'if cfg!(target_os = "linux") { "linux" }',
69
+ 'else if cfg!(target_os = "macos") { "darwin" }',
70
+ 'else if cfg!(windows) { "win32" }',
71
+ 'else { "other" }',
72
+ '}',
73
+ 'pub fn rcompiler_proc_arch() -> &\'static str {',
74
+ 'if cfg!(target_arch = "x86_64") { "x64" }',
75
+ 'else if cfg!(target_arch = "aarch64") { "arm64" }',
76
+ 'else if cfg!(target_arch = "x86") { "ia32" }',
77
+ 'else { "other" }',
78
+ '}',
79
+ 'pub fn rcompiler_proc_mem_rss() -> f64 {',
80
+ '#[cfg(target_os = "linux")]',
81
+ '{',
82
+ 'if let Ok(s) = std::fs::read_to_string("/proc/self/statm") {',
83
+ 'if let Some(rss) = s.split_whitespace().nth(1) {',
84
+ 'if let Ok(pages) = rss.parse::<f64>() { return pages * 4096.0; }',
85
+ '}',
86
+ '}',
87
+ '}',
88
+ '0.0',
89
+ '}',
90
+ 'pub fn rcompiler_proc_ppid() -> f64 {',
91
+ '#[cfg(target_os = "linux")]',
92
+ '{',
93
+ 'if let Ok(s) = std::fs::read_to_string("/proc/self/status") {',
94
+ 'for line in s.lines() {',
95
+ 'if let Some(v) = line.strip_prefix("PPid:") { return v.trim().parse::<f64>().unwrap_or(0.0); }',
96
+ '}',
97
+ '}',
98
+ '}',
99
+ '0.0',
100
+ '}',
101
+ 'pub fn rcompiler_proc_env_get(key: &str) -> String {',
102
+ 'std::env::var(key).unwrap_or_default()',
103
+ '}',
104
+ 'pub fn rcompiler_proc_env_has(key: &str) -> bool {',
105
+ 'std::env::var(key).is_ok()',
106
+ '}',
107
+ 'pub fn rcompiler_proc_env_all() -> String {',
108
+ 'let mut rows: Vec<String> = std::env::vars().map(|(k, v)| format!("{}={}", k, v)).collect();',
109
+ 'rows.sort();',
110
+ 'rows.join("\\n")',
111
+ '}'
112
+ ].join('\n');
113
+ const rt = () => util.Tools.setruntime([RT_PROC]);
114
+
115
+ // exec/spawn 结果落盘到 last_exec 的公共生成
116
+ const spawnCode = [
117
+ '{',
118
+ 'let __prog = (__PROG__);',
119
+ 'let __argv = rcompiler_proc_split_args(__ARGLIST__);',
120
+ 'let mut __c = std::process::Command::new(&__prog);',
121
+ 'for __a in &__argv { __c.arg(__a); }',
122
+ '__STDIO__',
123
+ 'let __res = match __c.spawn() {',
124
+ 'Ok(mut __ch) => {',
125
+ 'let __pid = __ch.id();',
126
+ 'match __ch.wait_with_output() {',
127
+ 'Ok(__o) => RcompilerProcResult { stdout: String::from_utf8_lossy(&__o.stdout).into_owned(), stderr: String::from_utf8_lossy(&__o.stderr).into_owned(), code: __o.status.code().unwrap_or(-1), pid: __pid },',
128
+ 'Err(__e) => RcompilerProcResult { stdout: String::new(), stderr: format!("{}", __e), code: -1, pid: __pid },',
129
+ '}',
130
+ '},',
131
+ 'Err(__e) => RcompilerProcResult { stdout: String::new(), stderr: format!("{}", __e), code: -1, pid: 0 },',
132
+ '};',
133
+ '*self.last_exec.lock().unwrap() = __res;',
134
+ '}'
135
+ ];
136
+
137
+ class processExt {
138
+ id = 'process';
139
+ blocks = [
140
+ // ---- 进程控制 ----
141
+ {
142
+ opcode: 'exit',
143
+ blockType: util.BlockType.COMMAND,
144
+ text: '退出进程,状态码 [code]',
145
+ arguments: { code: { type: ArgumentType.NUMBER, defaultValue: '0' } }
146
+ },
147
+ {
148
+ opcode: 'chdir',
149
+ blockType: util.BlockType.COMMAND,
150
+ text: '切换工作目录 [path]',
151
+ arguments: { path: { type: ArgumentType.STRING, defaultValue: '/tmp' } }
152
+ },
153
+ // ---- 环境变量 ----
154
+ {
155
+ opcode: 'env_set',
156
+ blockType: util.BlockType.COMMAND,
157
+ text: '设置环境变量 [key] 为 [value]',
158
+ arguments: {
159
+ key: { type: ArgumentType.STRING, defaultValue: 'MY_VAR' },
160
+ value: { type: ArgumentType.STRING, defaultValue: 'hello' }
161
+ }
162
+ },
163
+ {
164
+ opcode: 'env_delete',
165
+ blockType: util.BlockType.COMMAND,
166
+ text: '删除环境变量 [key]',
167
+ arguments: { key: { type: ArgumentType.STRING, defaultValue: 'MY_VAR' } }
168
+ },
169
+ // ---- 命令执行 ----
170
+ {
171
+ opcode: 'exec',
172
+ blockType: util.BlockType.COMMAND,
173
+ text: '执行命令 [cmd](shell)工作目录 [cwd] 留空为当前',
174
+ arguments: {
175
+ cmd: { type: ArgumentType.STRING, defaultValue: 'echo hello' },
176
+ cwd: { type: ArgumentType.STRING, defaultValue: '' }
177
+ }
178
+ },
179
+ {
180
+ opcode: 'spawn',
181
+ blockType: util.BlockType.COMMAND,
182
+ text: '运行程序 [program] 参数 [arglist] 输出 [mode]',
183
+ usefield: ['2'],
184
+ arguments: {
185
+ program: { type: ArgumentType.STRING, defaultValue: 'ls' },
186
+ arglist: { type: ArgumentType.STRING, defaultValue: '-la /tmp' },
187
+ mode: {
188
+ type: ArgumentType.STRING,
189
+ menu: 'spawnModes',
190
+ defaultValue: 'capture'
191
+ }
192
+ }
193
+ },
194
+ // ---- 结果报告器(上次 exec/spawn)----
195
+ {
196
+ opcode: 'last_stdout',
197
+ blockType: util.BlockType.REPORTER,
198
+ text: '上次执行的标准输出'
199
+ },
200
+ {
201
+ opcode: 'last_stderr',
202
+ blockType: util.BlockType.REPORTER,
203
+ text: '上次执行的标准错误'
204
+ },
205
+ {
206
+ opcode: 'last_code',
207
+ blockType: util.BlockType.REPORTER,
208
+ text: '上次执行的退出码'
209
+ },
210
+ {
211
+ opcode: 'last_pid',
212
+ blockType: util.BlockType.REPORTER,
213
+ text: '上次运行的子进程 PID'
214
+ },
215
+ // ---- 进程信息 ----
216
+ {
217
+ opcode: 'pid',
218
+ blockType: util.BlockType.REPORTER,
219
+ text: '进程 PID'
220
+ },
221
+ {
222
+ opcode: 'ppid',
223
+ blockType: util.BlockType.REPORTER,
224
+ text: '父进程 PID'
225
+ },
226
+ {
227
+ opcode: 'platform',
228
+ blockType: util.BlockType.REPORTER,
229
+ text: '平台'
230
+ },
231
+ {
232
+ opcode: 'arch',
233
+ blockType: util.BlockType.REPORTER,
234
+ text: 'CPU 架构'
235
+ },
236
+ {
237
+ opcode: 'cwd',
238
+ blockType: util.BlockType.REPORTER,
239
+ text: '当前工作目录'
240
+ },
241
+ {
242
+ opcode: 'uptime',
243
+ blockType: util.BlockType.REPORTER,
244
+ text: '已运行秒数'
245
+ },
246
+ {
247
+ opcode: 'mem_rss',
248
+ blockType: util.BlockType.REPORTER,
249
+ text: '内存 RSS(字节)'
250
+ },
251
+ // ---- 环境变量报告器 ----
252
+ {
253
+ opcode: 'env_get',
254
+ blockType: util.BlockType.REPORTER,
255
+ text: '环境变量 [key]',
256
+ arguments: { key: { type: ArgumentType.STRING, defaultValue: 'HOME' } }
257
+ },
258
+ {
259
+ opcode: 'env_has',
260
+ blockType: util.BlockType.BOOLEAN,
261
+ text: '存在环境变量 [key]?',
262
+ arguments: { key: { type: ArgumentType.STRING, defaultValue: 'PATH' } }
263
+ },
264
+ {
265
+ opcode: 'env_all',
266
+ blockType: util.BlockType.REPORTER,
267
+ text: '全部环境变量(KEY=VALUE 换行分隔)'
268
+ }
269
+ ];
270
+ getInfo() {
271
+ return {
272
+ id: this.id,
273
+ name: '进程',
274
+ color1: '#3d7ac9',
275
+ color2: '#5c96e0',
276
+ blocks: this.blocks,
277
+ menus: {
278
+ spawnModes: [
279
+ { text: '捕获', value: 'capture' },
280
+ { text: '直通终端', value: 'inherit' },
281
+ { text: '丢弃', value: 'ignore' }
282
+ ]
283
+ }
284
+ };
285
+ }
286
+ // ---- VM 端不实现,仅编译期生成 Rust ----
287
+ exit(args) {
288
+ if (!isC()) return;
289
+ args.compiler += `std::process::exit(((${numOf(args.code)})) as i32);\n`;
290
+ return args.compiler;
291
+ }
292
+ chdir(args) {
293
+ if (!isC()) return;
294
+ args.compiler += `if let Err(__e) = std::env::set_current_dir(${stuOf(args.path)}) { eprintln!("process: 切换目录失败: {}", __e); }\n`;
295
+ return args.compiler;
296
+ }
297
+ env_set(args) {
298
+ if (!isC()) return;
299
+ args.compiler += `std::env::set_var(${stuOf(args.key)}, ${stuOf(args.value)});\n`;
300
+ return args.compiler;
301
+ }
302
+ env_delete(args) {
303
+ if (!isC()) return;
304
+ args.compiler += `std::env::remove_var(${stuOf(args.key)});\n`;
305
+ return args.compiler;
306
+ }
307
+ exec(args) {
308
+ if (!isC()) return;
309
+ rt(); storeField();
310
+ args.compiler += [
311
+ '{',
312
+ `let __cwd = (${stuOf(args.cwd)});`,
313
+ `let __cmd = (${stuOf(args.cmd)});`,
314
+ 'let __sh = if cfg!(windows) { ("cmd", "/C") } else { ("sh", "-c") };',
315
+ 'let mut __c = std::process::Command::new(__sh.0);',
316
+ '__c.arg(__sh.1).arg(&__cmd);',
317
+ 'if !__cwd.is_empty() { __c.current_dir(&__cwd); }',
318
+ 'let __res = match __c.output() {',
319
+ 'Ok(__o) => RcompilerProcResult { stdout: String::from_utf8_lossy(&__o.stdout).into_owned(), stderr: String::from_utf8_lossy(&__o.stderr).into_owned(), code: __o.status.code().unwrap_or(-1), pid: 0 },',
320
+ 'Err(__e) => RcompilerProcResult { stdout: String::new(), stderr: format!("{}", __e), code: -1, pid: 0 },',
321
+ '};',
322
+ '*self.last_exec.lock().unwrap() = __res;',
323
+ '}'
324
+ ].join('\n') + '\n';
325
+ return args.compiler;
326
+ }
327
+ spawn(args) {
328
+ if (!isC()) return;
329
+ rt(); storeField();
330
+ const mode = gf(args, 'mode') || 'capture';
331
+ const stdio = mode === 'inherit'
332
+ ? '__c.stdin(std::process::Stdio::inherit()).stdout(std::process::Stdio::inherit()).stderr(std::process::Stdio::inherit());'
333
+ : (mode === 'ignore'
334
+ ? '__c.stdin(std::process::Stdio::null()).stdout(std::process::Stdio::null()).stderr(std::process::Stdio::null());'
335
+ : '__c.stdin(std::process::Stdio::piped());');
336
+ const code = spawnCode
337
+ .join('\n')
338
+ .replace('__PROG__', stuOf(args.program))
339
+ .replace('__ARGLIST__', stuOf(args.arglist))
340
+ .replace('__STDIO__', stdio);
341
+ args.compiler += code + '\n';
342
+ return args.compiler;
343
+ }
344
+ last_stdout(args) {
345
+ if (!isC()) return '';
346
+ rt(); storeField();
347
+ return new util.TypeInput.Stri('self.last_exec.lock().unwrap().stdout.clone()');
348
+ }
349
+ last_stderr(args) {
350
+ if (!isC()) return '';
351
+ rt(); storeField();
352
+ return new util.TypeInput.Stri('self.last_exec.lock().unwrap().stderr.clone()');
353
+ }
354
+ last_code(args) {
355
+ if (!isC()) return -1;
356
+ rt(); storeField();
357
+ return new util.TypeInput.Num('(self.last_exec.lock().unwrap().code) as f64');
358
+ }
359
+ last_pid(args) {
360
+ if (!isC()) return 0;
361
+ rt(); storeField();
362
+ return new util.TypeInput.Num('(self.last_exec.lock().unwrap().pid) as f64');
363
+ }
364
+ pid(args) {
365
+ if (!isC()) return 0;
366
+ rt();
367
+ return new util.TypeInput.Num('std::process::id() as f64');
368
+ }
369
+ ppid(args) {
370
+ if (!isC()) return 0;
371
+ rt();
372
+ return new util.TypeInput.Num('rcompiler_proc_ppid()');
373
+ }
374
+ platform(args) {
375
+ if (!isC()) return '';
376
+ rt();
377
+ return new util.TypeInput.Str('rcompiler_proc_platform()');
378
+ }
379
+ arch(args) {
380
+ if (!isC()) return '';
381
+ rt();
382
+ return new util.TypeInput.Str('rcompiler_proc_arch()');
383
+ }
384
+ cwd(args) {
385
+ if (!isC()) return '';
386
+ rt();
387
+ return new util.TypeInput.Stri('rcompiler_proc_cwd()');
388
+ }
389
+ uptime(args) {
390
+ if (!isC()) return 0;
391
+ rt();
392
+ return new util.TypeInput.Num('rcompiler_proc_uptime()');
393
+ }
394
+ mem_rss(args) {
395
+ if (!isC()) return 0;
396
+ rt();
397
+ return new util.TypeInput.Num('rcompiler_proc_mem_rss()');
398
+ }
399
+ env_get(args) {
400
+ if (!isC()) return '';
401
+ rt();
402
+ return new util.TypeInput.Stri(`rcompiler_proc_env_get(${stuOf(args.key)})`);
403
+ }
404
+ env_has(args) {
405
+ if (!isC()) return false;
406
+ rt();
407
+ return new util.TypeInput.Bool(`rcompiler_proc_env_has(${stuOf(args.key)})`);
408
+ }
409
+ env_all(args) {
410
+ if (!isC()) return '';
411
+ rt();
412
+ return new util.TypeInput.Stri('rcompiler_proc_env_all()');
413
+ }
414
+ }
415
+ util.extensions.register(new processExt());
416
+ })(this.isCompiler ? this : Scratch);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rcompiler",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "description": "Scratch/TurboWarp (and rCodenow) .sb3 to Rust compiler",
5
5
  "main": "src/rcompiler.js",
6
6
  "bin": {
package/src/analysis.js CHANGED
@@ -542,6 +542,14 @@ function analyze(projectJson, opts = {}) {
542
542
  exitKey: ['escape', 'ctrlq'].includes(exitKeyRaw) ? exitKeyRaw : 'none',
543
543
  quitOnStop: pickTri('QuitOnStop', APP_DEFAULTS.QuitOnStop),
544
544
  cloneLimit,
545
+ // 围栏(对照 TurboWarp runtimeOptions.fencing,默认开):模拟器/测量类项目需关闭
546
+ fencing: (() => {
547
+ const raw = has(appStored, 'fencing') ? appStored.fencing : (has(appCli, 'fencing') ? appCli.fencing : undefined);
548
+ if (raw === undefined) return true;
549
+ if (typeof raw === 'boolean') return raw;
550
+ const v = tri(raw);
551
+ return v === 'default' ? true : v === 'on';
552
+ })(),
545
553
  bg: parseHexColor(pickStr('Bg', APP_DEFAULTS.Bg), APP_DEFAULTS.Bg),
546
554
  stageWidth: appNum('StageWidth'),
547
555
  stageHeight: appNum('StageHeight')
package/src/assets.js CHANGED
@@ -238,7 +238,7 @@ async function buildAssetConsts(profile, emit, opts) {
238
238
  profile.soundMeta = [];
239
239
 
240
240
  if (profile.hasStage) {
241
- const lines = ['// ---- 舞台造型常量 ----'];
241
+ const lines = [];
242
242
  const items = [];
243
243
  for (const c of profile.assets.costumes) {
244
244
  const info = extracted.costumeFiles.get(`${c.target}:${c.index}`);
@@ -316,7 +316,7 @@ async function buildAssetConsts(profile, emit, opts) {
316
316
  }
317
317
 
318
318
  if (profile.hasSound) {
319
- const lines = ['// ---- 声音常量 ----'];
319
+ const lines = [];
320
320
  const items = [];
321
321
  for (const s of profile.assets.sounds) {
322
322
  const info = extracted.soundFiles.get(`${s.target}:${s.index}`);
package/src/cli.js CHANGED
@@ -56,6 +56,7 @@ function appOptions(argv) {
56
56
  if (argv.exitKey !== undefined) app.ExitKey = String(argv.exitKey);
57
57
  if (argv.quitOnStop !== undefined) app.QuitOnStop = argv.quitOnStop ? 'on' : 'off';
58
58
  if (argv.cloneLimit !== undefined) app.CloneLimit = Number(argv.cloneLimit);
59
+ if (argv.fencing !== undefined) app.fencing = argv.fencing;
59
60
  if (argv.bg !== undefined) app.Bg = String(argv.bg);
60
61
  if (argv.stageWidth !== undefined) app.StageWidth = Number(argv.stageWidth);
61
62
  if (argv.stageHeight !== undefined) app.StageHeight = Number(argv.stageHeight);
@@ -283,6 +284,7 @@ if (require.main === module) {
283
284
  .option('decorations', { type: 'boolean', describe: '窗口边框(--no-decorations 隐藏)' })
284
285
  .option('hide-cursor', { type: 'boolean', describe: '隐藏鼠标指针' })
285
286
  .option('controls', { type: 'boolean', describe: '顶栏绿旗/暂停/停止' })
287
+ .option('fencing', { type: 'boolean', describe: '围栏(默认开,对照 TurboWarp fencing);--no-fencing 关闭坐标/尺寸钳制——模拟器与"走到边缘测量"类项目需要' })
286
288
  .option('autoplay', { type: 'boolean', describe: '启动即运行绿旗(--no-autoplay 关闭)' })
287
289
  .option('exit-key', { type: 'string', describe: '退出快捷键:none | escape | ctrlq' })
288
290
  .option('quit-on-stop', { type: 'boolean', describe: '停止全部脚本后退出' })
package/src/emit.js CHANGED
@@ -65,7 +65,6 @@ class Emit {
65
65
  if (web) {
66
66
  lines.push(
67
67
  '',
68
- '# WASM:wasm-bindgen 从 cdylib 生成 JS 胶水;输出 web/ 宿主所需的 wasm 模块',
69
68
  '[lib]',
70
69
  'crate-type = ["cdylib"]',
71
70
  'path = "src/lib.rs"'
@@ -73,7 +72,6 @@ class Emit {
73
72
  }
74
73
  lines.push(
75
74
  '',
76
- '# 大型单文件项目下 rustc 的增量编译与调试信息内存开销极大,dev 档关闭',
77
75
  '[profile.dev]',
78
76
  'debug = 0',
79
77
  'incremental = false'
@@ -135,7 +133,9 @@ class Emit {
135
133
  const stage = p.hasStage;
136
134
  const out = [];
137
135
  out.push(`// By rCompiler`);
138
- out.push(`// profile: stage=${stage} sound=${p.hasSound} concurrency=${p.concurrency}`);
136
+ // 生成代码的防御性括号/约定性 mut 会产生数千条 lint 诊断,拖慢 rustc 且淹没有用警告;
137
+ // crate 级豁免这两类纯风格 lint(真实问题类警告如 unused_variables 仍保留)
138
+ out.push(`#![allow(unused_parens, unused_mut)]`);
139
139
 
140
140
  // 1. use 语句
141
141
  const uses = [...this.uses].sort();