已关闭
feat: add tests #2031
duan创建于 8月17日关闭于 9月9日
feat: add tests #2031
已关闭
共 27 个文件变更+785-2
| @@ -1,4 +1,4 @@ | |||
| 1 | -// Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. | 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. |
| 2 | // This source file is part of the Cangjie project, licensed under Apache-2.0 | 2 | // This source file is part of the Cangjie project, licensed under Apache-2.0 |
| 3 | // with Runtime Library Exception. | 3 | // with Runtime Library Exception. |
| 4 | // | 4 | // |
| @@ -1,4 +1,4 @@ | |||
| 1 | -// Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved. | 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. |
| 2 | // This source file is part of the Cangjie project, licensed under Apache-2.0 | 2 | // This source file is part of the Cangjie project, licensed under Apache-2.0 |
| 3 | // with Runtime Library Exception. | 3 | // with Runtime Library Exception. |
| 4 | // | 4 | // |
| @@ -0,0 +1,42 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +// Shared enum import libs are compiled once, normally (they carry full reflection | ||
| 8 | +// metadata). --disable-reflection goes on the main link only, so the backend | ||
| 9 | +// pass cuts the imported-lib reflection at post-link. | ||
| 10 | +// (Linux and CJNATIVE) DEPENDENCE: ../pkgs ../pkga | ||
| 11 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkgs/pkgs.cj --lto=full --output-type=staticlib | ||
| 12 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkga/pkga.cj --lto=full --output-type=staticlib | ||
| 13 | + | ||
| 14 | +// Flagged link -> %output; control link (no flag) -> main_reflect.out. | ||
| 15 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %f -o %output --lto=full --disable-reflection libpkgs.bc libpkga.bc | ||
| 16 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %f -o main_reflect.out --lto=full libpkgs.bc libpkga.bc | ||
| 17 | + | ||
| 18 | +// The flagged binary must still run correctly. | ||
| 19 | +// (Linux and CJNATIVE) RUN-EXEC: %run %run_opt %output %run_args | ||
| 20 | + | ||
| 21 | +// Symbol guard on the flagged binary: enum ctor info kept, the reflect global is | ||
| 22 | +// downgraded to .dbg, and method reflection must be gone. NOTE: scan is | ||
| 23 | +// substring matching, NOT regex — no escaping/anchors. | ||
| 24 | +// (Linux and CJNATIVE) EXEC-PIPE: $CANGJIE_HOME/third_party/llvm/bin/llvm-objdump -t %output 2>&1 | compare %f | ||
| 25 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:E.ti.enumctors | ||
| 26 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:E.ti.reflect.dbg | ||
| 27 | +// (Linux and CJNATIVE) ASSERT: scan-not pkgs:E.ti.method0 | ||
| 28 | + | ||
| 29 | +// Final stage: size comparison (all links already done). | ||
| 30 | +// (Linux and CJNATIVE) EXEC: test $(stat -c %s %output) -lt $(stat -c %s main_reflect.out) | ||
| 31 | + | ||
| 32 | +import pkgs | ||
| 33 | +import pkga | ||
| 34 | + | ||
| 35 | +main(): Int64 { | ||
| 36 | + let e1 = pkgs.E.A | ||
| 37 | + let e2 = pkga.E.A(3) | ||
| 38 | + if (e1.tag() != 1 || e2.tag() != 3) { | ||
| 39 | + return 1 | ||
| 40 | + } | ||
| 41 | + return 0 | ||
| 42 | +} | ||
| @@ -0,0 +1,56 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +// Shared enum import libs are compiled once, normally (they carry full reflection | ||
| 8 | +// metadata). --disable-reflection goes on the main link only, so the backend | ||
| 9 | +// pass cuts the imported-lib reflection at post-link. %enableO2 exercises the | ||
| 10 | +// -O2 path: the LTO post-link pipeline runs at --lto-O2. | ||
| 11 | +// (Linux and CJNATIVE) DEPENDENCE: ../pkgs ../pkga | ||
| 12 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkgs/pkgs.cj --lto=full --output-type=staticlib | ||
| 13 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkga/pkga.cj --lto=full --output-type=staticlib | ||
| 14 | + | ||
| 15 | +// Flagged link -> %output; control link (no flag) -> main_reflect.out. | ||
| 16 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %enableO2 %f -o %output --lto=full --disable-reflection libpkgs.bc libpkga.bc | ||
| 17 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %enableO2 %f -o main_reflect.out --lto=full libpkgs.bc libpkga.bc | ||
| 18 | + | ||
| 19 | +// The flagged binary must still run correctly. | ||
| 20 | +// (Linux and CJNATIVE) RUN-EXEC: %run %run_opt %output %run_args | ||
| 21 | + | ||
| 22 | +// Special full-LTO final-binary guard: imported enum sub-symbols are folded away, | ||
| 23 | +// so use the Option wrapper that carries pkga.E through the program and assert the | ||
| 24 | +// final binary still keeps stable std.core:Option metadata after reflection is cut. | ||
| 25 | +// NOTE: scan is substring matching, NOT regex — no escaping/anchors. | ||
| 26 | +// (Linux and CJNATIVE) EXEC-PIPE: $CANGJIE_HOME/third_party/llvm/bin/llvm-objdump -t %output 2>&1 | compare %f | ||
| 27 | +// (Linux and CJNATIVE) ASSERT: scan std.core:Option.tt.enumctors | ||
| 28 | +// (Linux and CJNATIVE) ASSERT: scan std.core:Option.tt.reflect.dbg | ||
| 29 | +// (Linux and CJNATIVE) ASSERT: scan-not std.core:Option.tt.method0 | ||
| 30 | + | ||
| 31 | +// Final stage: size comparison (all links already done). | ||
| 32 | +// (Linux and CJNATIVE) EXEC: test $(stat -c %s %output) -lt $(stat -c %s main_reflect.out) | ||
| 33 | + | ||
| 34 | +import pkgs | ||
| 35 | +import pkga | ||
| 36 | + | ||
| 37 | +main(): Int64 { | ||
| 38 | + let e = keepEnum(pkga.E.A(3)) | ||
| 39 | + let opt = wrapEnum(e) | ||
| 40 | + let unwrapped = match (opt) { | ||
| 41 | + case Some(v) => v | ||
| 42 | + case None => return 2 | ||
| 43 | + } | ||
| 44 | + if (pkgs.E.A.tag() != 1 || unwrapped.tag() != 3) { | ||
| 45 | + return 1 | ||
| 46 | + } | ||
| 47 | + return 0 | ||
| 48 | +} | ||
| 49 | + | ||
| 50 | +public func keepEnum(e: pkga.E): pkga.E { | ||
| 51 | + return e | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +public func wrapEnum(e: pkga.E): Option<pkga.E> { | ||
| 55 | + return Some(e) | ||
| 56 | +} | ||
| @@ -0,0 +1,19 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package pkga | ||
| 8 | + | ||
| 9 | +public enum E { | ||
| 10 | + | A(Int32) | ||
| 11 | + | B | ||
| 12 | + | ||
| 13 | + public func tag(): Int32 { | ||
| 14 | + match (this) { | ||
| 15 | + case A(v) => return v | ||
| 16 | + case B => return 0 | ||
| 17 | + } | ||
| 18 | + } | ||
| 19 | +} | ||
| @@ -0,0 +1,19 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package pkgs | ||
| 8 | + | ||
| 9 | +public enum E { | ||
| 10 | + | A | ||
| 11 | + | B | ||
| 12 | + | ||
| 13 | + public func tag(): Int32 { | ||
| 14 | + match (this) { | ||
| 15 | + case A => return 1 | ||
| 16 | + case B => return 2 | ||
| 17 | + } | ||
| 18 | + } | ||
| 19 | +} | ||
| @@ -0,0 +1,47 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +// Shared enum import libs are compiled once, normally (they carry full reflection | ||
| 8 | +// metadata). --disable-reflection goes on the main link only, so the backend | ||
| 9 | +// pass cuts the imported-lib reflection at post-link. | ||
| 10 | +// (Linux and CJNATIVE) DEPENDENCE: ../pkgs ../pkga | ||
| 11 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkgs/pkgs.cj --lto=full --output-type=staticlib | ||
| 12 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkga/pkga.cj --lto=full --output-type=staticlib | ||
| 13 | + | ||
| 14 | +// ThinLTO caches per-module objects in the output dir (the dir of -o), and the | ||
| 15 | +// cache key omits the --mllvm flags, so the control link would silently reuse | ||
| 16 | +// the flagged link's cached objects. Clear llvmcache-* between the two thin | ||
| 17 | +// links so the control is really compiled without the pass. | ||
| 18 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %f -o %output --lto=thin --disable-reflection libpkgs.bc libpkga.bc | ||
| 19 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %f -o %output --lto=thin --disable-reflection libpkgs.bc libpkga.bc | ||
| 20 | +// (Linux and CJNATIVE) EXEC: rm -rf llvmcache-* | ||
| 21 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %f -o main_reflect.out --lto=thin libpkgs.bc libpkga.bc | ||
| 22 | + | ||
| 23 | +// The flagged binary must still run correctly. | ||
| 24 | +// (Linux and CJNATIVE) RUN-EXEC: %run %run_opt %output %run_args | ||
| 25 | + | ||
| 26 | +// Symbol guard on the flagged binary: enum ctor info kept, the reflect global is | ||
| 27 | +// downgraded to .dbg, and method reflection must be gone. NOTE: scan is | ||
| 28 | +// substring matching, NOT regex — no escaping/anchors. | ||
| 29 | +// (Linux and CJNATIVE) EXEC-PIPE: $CANGJIE_HOME/third_party/llvm/bin/llvm-objdump -t %output 2>&1 | compare %f | ||
| 30 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:E.ti.enumctors | ||
| 31 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:E.ti.reflect.dbg | ||
| 32 | +// (Linux and CJNATIVE) ASSERT: scan-not pkgs:E.ti.method0 | ||
| 33 | + | ||
| 34 | +// Final stage: size comparison (all links already done). | ||
| 35 | +// (Linux and CJNATIVE) EXEC: test $(stat -c %s %output) -lt $(stat -c %s main_reflect.out) | ||
| 36 | + | ||
| 37 | +import pkgs | ||
| 38 | +import pkga | ||
| 39 | + | ||
| 40 | +main(): Int64 { | ||
| 41 | + let e1 = pkgs.E.A | ||
| 42 | + let e2 = pkga.E.A(3) | ||
| 43 | + if (e1.tag() != 1 || e2.tag() != 3) { | ||
| 44 | + return 1 | ||
| 45 | + } | ||
| 46 | + return 0 | ||
| 47 | +} | ||
| @@ -0,0 +1,50 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +// Shared enum import libs are compiled once, normally (they carry full reflection | ||
| 8 | +// metadata). --disable-reflection goes on the main link only, so the backend | ||
| 9 | +// pass cuts the imported-lib reflection at post-link. %enableO2 exercises the | ||
| 10 | +// -O2 path: the LTO post-link pipeline runs at --lto-O2. | ||
| 11 | +// (Linux and CJNATIVE) DEPENDENCE: ../pkgs ../pkga | ||
| 12 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkgs/pkgs.cj --lto=full --output-type=staticlib | ||
| 13 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkga/pkga.cj --lto=full --output-type=staticlib | ||
| 14 | + | ||
| 15 | +// ThinLTO caches per-module objects in the output dir (the dir of -o), and the | ||
| 16 | +// cache key omits the --mllvm flags, so the control link would silently reuse | ||
| 17 | +// the flagged link's cached objects. Clear llvmcache-* between the two thin | ||
| 18 | +// links so the control is really compiled without the pass. | ||
| 19 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %enableO2 %f -o %output --lto=thin --disable-reflection libpkgs.bc libpkga.bc | ||
| 20 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %enableO2 %f -o %output --lto=thin --disable-reflection libpkgs.bc libpkga.bc | ||
| 21 | +// (Linux and CJNATIVE) EXEC: rm -rf llvmcache-* | ||
| 22 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %enableO2 %f -o main_reflect.out --lto=thin libpkgs.bc libpkga.bc | ||
| 23 | + | ||
| 24 | +// The flagged binary must still run correctly. | ||
| 25 | +// (Linux and CJNATIVE) RUN-EXEC: %run %run_opt %output %run_args | ||
| 26 | + | ||
| 27 | +// Symbol guard on the flagged binary: enum ctor info kept, the reflect global is | ||
| 28 | +// downgraded to .dbg, and method reflection must be gone. NOTE: scan is | ||
| 29 | +// substring matching, NOT regex — no escaping/anchors. | ||
| 30 | +// (Linux and CJNATIVE) EXEC-PIPE: $CANGJIE_HOME/third_party/llvm/bin/llvm-objdump -t %output 2>&1 | compare %f | ||
| 31 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:E.ti.enumctors | ||
| 32 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:E.ti.reflect.dbg | ||
| 33 | +// (Linux and CJNATIVE) ASSERT: scan-not pkgs:E.ti.method0 | ||
| 34 | + | ||
| 35 | +// Final stage: size comparison (all links already done). | ||
| 36 | +// O2 ThinLTO may fold enum reflection sub-symbols away, so only the size win and | ||
| 37 | +// runtime behavior are stable oracles here. | ||
| 38 | +// (Linux and CJNATIVE) EXEC: test $(stat -c %s %output) -lt $(stat -c %s main_reflect.out) | ||
| 39 | + | ||
| 40 | +import pkgs | ||
| 41 | +import pkga | ||
| 42 | + | ||
| 43 | +main(): Int64 { | ||
| 44 | + let e1 = pkgs.E.A | ||
| 45 | + let e2 = pkga.E.A(3) | ||
| 46 | + if (e1.tag() != 1 || e2.tag() != 3) { | ||
| 47 | + return 1 | ||
| 48 | + } | ||
| 49 | + return 0 | ||
| 50 | +} | ||
| @@ -0,0 +1,50 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +// Shared import libs are compiled once, normally (they carry full reflection | ||
| 8 | +// metadata). --disable-reflection goes on the main link only, so the backend | ||
| 9 | +// pass cuts the imported-lib reflection at post-link. | ||
| 10 | +// (Linux and CJNATIVE) DEPENDENCE: ../pkgs ../pkga | ||
| 11 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkgs/pkgs.cj --lto=full --output-type=staticlib | ||
| 12 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkga/pkga.cj --lto=full --output-type=staticlib | ||
| 13 | + | ||
| 14 | +// Flagged link -> %output; control link (no flag) -> main_reflect.out. | ||
| 15 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %f -o %output --lto=full --disable-reflection libpkgs.bc libpkga.bc | ||
| 16 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %f -o main_reflect.out --lto=full libpkgs.bc libpkga.bc | ||
| 17 | + | ||
| 18 | +// The flagged binary must still run correctly. | ||
| 19 | +// (Linux and CJNATIVE) RUN-EXEC: %run %run_opt %output %run_args | ||
| 20 | + | ||
| 21 | +// Symbol guard on the flagged binary: fieldnames kept, the reflect global is | ||
| 22 | +// downgraded to .dbg, and method reflection must be gone. NOTE: scan is | ||
| 23 | +// substring matching, NOT regex — no escaping/anchors. | ||
| 24 | +// (Linux and CJNATIVE) EXEC-PIPE: $CANGJIE_HOME/third_party/llvm/bin/llvm-objdump -t %output 2>&1 | compare %f | ||
| 25 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:Data.tt.fieldnames | ||
| 26 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:Data.tt.reflect.dbg | ||
| 27 | +// (Linux and CJNATIVE) ASSERT: scan-not pkgs:Data.tt.method0 | ||
| 28 | + | ||
| 29 | +// Final stage: size comparison (all links already done). | ||
| 30 | +// (Linux and CJNATIVE) EXEC: test $(stat -c %s %output) -lt $(stat -c %s main_reflect.out) | ||
| 31 | + | ||
| 32 | +import pkgs | ||
| 33 | +import pkga | ||
| 34 | + | ||
| 35 | +main(): Int64 { | ||
| 36 | + return run() | ||
| 37 | +} | ||
| 38 | + | ||
| 39 | +func run(): Int64 { | ||
| 40 | + var a: Int32 = 3 | ||
| 41 | + var b: Int32 = 4 | ||
| 42 | + let data1: pkgs.Data<Int32> = pkgs.Data<Int32>(a, b) | ||
| 43 | + let data2: pkga.Data<Int32> = pkga.Data<Int32>(b, a) | ||
| 44 | + var res1: Int32 = data1.area() | ||
| 45 | + var res2: Int32 = data2.area() | ||
| 46 | + if (res1 == 3 && res2 == 4) { | ||
| 47 | + return 0 | ||
| 48 | + } | ||
| 49 | + return 1 | ||
| 50 | +} | ||
| @@ -0,0 +1,51 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +// Shared import libs are compiled once, normally (they carry full reflection | ||
| 8 | +// metadata). --disable-reflection goes on the main link only, so the backend | ||
| 9 | +// pass cuts the imported-lib reflection at post-link. %enableO2 exercises the | ||
| 10 | +// -O2 path: the LTO post-link pipeline runs at --lto-O2. | ||
| 11 | +// (Linux and CJNATIVE) DEPENDENCE: ../pkgs ../pkga | ||
| 12 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkgs/pkgs.cj --lto=full --output-type=staticlib | ||
| 13 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkga/pkga.cj --lto=full --output-type=staticlib | ||
| 14 | + | ||
| 15 | +// Flagged link -> %output; control link (no flag) -> main_reflect.out. | ||
| 16 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %enableO2 %f -o %output --lto=full --disable-reflection libpkgs.bc libpkga.bc | ||
| 17 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %enableO2 %f -o main_reflect.out --lto=full libpkgs.bc libpkga.bc | ||
| 18 | + | ||
| 19 | +// The flagged binary must still run correctly. | ||
| 20 | +// (Linux and CJNATIVE) RUN-EXEC: %run %run_opt %output %run_args | ||
| 21 | + | ||
| 22 | +// Symbol guard on the flagged binary: fieldnames kept, the reflect global is | ||
| 23 | +// downgraded to .dbg, and method reflection must be gone. NOTE: scan is | ||
| 24 | +// substring matching, NOT regex — no escaping/anchors. | ||
| 25 | +// (Linux and CJNATIVE) EXEC-PIPE: $CANGJIE_HOME/third_party/llvm/bin/llvm-objdump -t %output 2>&1 | compare %f | ||
| 26 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:Data.tt.fieldnames | ||
| 27 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:Data.tt.reflect.dbg | ||
| 28 | +// (Linux and CJNATIVE) ASSERT: scan-not pkgs:Data.tt.method0 | ||
| 29 | + | ||
| 30 | +// Final stage: size comparison (all links already done). | ||
| 31 | +// (Linux and CJNATIVE) EXEC: test $(stat -c %s %output) -lt $(stat -c %s main_reflect.out) | ||
| 32 | + | ||
| 33 | +import pkgs | ||
| 34 | +import pkga | ||
| 35 | + | ||
| 36 | +main(): Int64 { | ||
| 37 | + return run() | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +func run(): Int64 { | ||
| 41 | + var a: Int32 = 3 | ||
| 42 | + var b: Int32 = 4 | ||
| 43 | + let data1: pkgs.Data<Int32> = pkgs.Data<Int32>(a, b) | ||
| 44 | + let data2: pkga.Data<Int32> = pkga.Data<Int32>(b, a) | ||
| 45 | + var res1: Int32 = data1.area() | ||
| 46 | + var res2: Int32 = data2.area() | ||
| 47 | + if (res1 == 3 && res2 == 4) { | ||
| 48 | + return 0 | ||
| 49 | + } | ||
| 50 | + return 1 | ||
| 51 | +} | ||
| @@ -0,0 +1,19 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package pkga | ||
| 8 | + | ||
| 9 | +public struct Data<T> { | ||
| 10 | + public let width: T | ||
| 11 | + public let length: T | ||
| 12 | + public init(width1: T, length1: T) { | ||
| 13 | + width = width1 | ||
| 14 | + length = length1 | ||
| 15 | + } | ||
| 16 | + public func area(): T { | ||
| 17 | + return width | ||
| 18 | + } | ||
| 19 | +} | ||
| @@ -0,0 +1,19 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package pkgs | ||
| 8 | + | ||
| 9 | +public struct Data<T> { | ||
| 10 | + public let width: T | ||
| 11 | + public let length: T | ||
| 12 | + public init(width1: T, length1: T) { | ||
| 13 | + width = width1 | ||
| 14 | + length = length1 | ||
| 15 | + } | ||
| 16 | + public func area(): T { | ||
| 17 | + return width | ||
| 18 | + } | ||
| 19 | +} | ||
| @@ -0,0 +1,54 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +// Shared import libs are compiled once, normally (they carry full reflection | ||
| 8 | +// metadata). --disable-reflection goes on the main link only, so the backend | ||
| 9 | +// pass cuts the imported-lib reflection at post-link. | ||
| 10 | +// (Linux and CJNATIVE) DEPENDENCE: ../pkgs ../pkga | ||
| 11 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkgs/pkgs.cj --lto=full --output-type=staticlib | ||
| 12 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkga/pkga.cj --lto=full --output-type=staticlib | ||
| 13 | + | ||
| 14 | +// ThinLTO caches per-module objects in the output dir (the dir of -o), and the | ||
| 15 | +// cache key omits the --mllvm flags, so the control link would silently reuse | ||
| 16 | +// the flagged link's cached objects. Clear llvmcache-* between the two thin | ||
| 17 | +// links so the control is really compiled without the pass. | ||
| 18 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %f -o %output --lto=thin --disable-reflection libpkgs.bc libpkga.bc | ||
| 19 | +// (Linux and CJNATIVE) EXEC: rm -rf llvmcache-* | ||
| 20 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %f -o main_reflect.out --lto=thin libpkgs.bc libpkga.bc | ||
| 21 | + | ||
| 22 | +// The flagged binary must still run correctly. | ||
| 23 | +// (Linux and CJNATIVE) RUN-EXEC: %run %run_opt %output %run_args | ||
| 24 | + | ||
| 25 | +// Symbol guard on the flagged binary: fieldnames kept, the reflect global is | ||
| 26 | +// downgraded to .dbg, and method reflection must be gone. NOTE: scan is | ||
| 27 | +// substring matching, NOT regex — no escaping/anchors. | ||
| 28 | +// (Linux and CJNATIVE) EXEC-PIPE: $CANGJIE_HOME/third_party/llvm/bin/llvm-objdump -t %output 2>&1 | compare %f | ||
| 29 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:Data.tt.fieldnames | ||
| 30 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:Data.tt.reflect.dbg | ||
| 31 | +// (Linux and CJNATIVE) ASSERT: scan-not pkgs:Data.tt.method0 | ||
| 32 | + | ||
| 33 | +// Final stage: size comparison (all links already done). | ||
| 34 | +// (Linux and CJNATIVE) EXEC: test $(stat -c %s %output) -lt $(stat -c %s main_reflect.out) | ||
| 35 | + | ||
| 36 | +import pkgs | ||
| 37 | +import pkga | ||
| 38 | + | ||
| 39 | +main(): Int64 { | ||
| 40 | + return run() | ||
| 41 | +} | ||
| 42 | + | ||
| 43 | +func run(): Int64 { | ||
| 44 | + var a: Int32 = 3 | ||
| 45 | + var b: Int32 = 4 | ||
| 46 | + let data1: pkgs.Data<Int32> = pkgs.Data<Int32>(a, b) | ||
| 47 | + let data2: pkga.Data<Int32> = pkga.Data<Int32>(b, a) | ||
| 48 | + var res1: Int32 = data1.area() | ||
| 49 | + var res2: Int32 = data2.area() | ||
| 50 | + if (res1 == 3 && res2 == 4) { | ||
| 51 | + return 0 | ||
| 52 | + } | ||
| 53 | + return 1 | ||
| 54 | +} | ||
| @@ -0,0 +1,55 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +// Shared import libs are compiled once, normally (they carry full reflection | ||
| 8 | +// metadata). --disable-reflection goes on the main link only, so the backend | ||
| 9 | +// pass cuts the imported-lib reflection at post-link. %enableO2 exercises the | ||
| 10 | +// -O2 path: the LTO post-link pipeline runs at --lto-O2. | ||
| 11 | +// (Linux and CJNATIVE) DEPENDENCE: ../pkgs ../pkga | ||
| 12 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkgs/pkgs.cj --lto=full --output-type=staticlib | ||
| 13 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkga/pkga.cj --lto=full --output-type=staticlib | ||
| 14 | + | ||
| 15 | +// ThinLTO caches per-module objects in the output dir (the dir of -o), and the | ||
| 16 | +// cache key omits the --mllvm flags, so the control link would silently reuse | ||
| 17 | +// the flagged link's cached objects. Clear llvmcache-* between the two thin | ||
| 18 | +// links so the control is really compiled without the pass. | ||
| 19 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %enableO2 %f -o %output --lto=thin --disable-reflection libpkgs.bc libpkga.bc | ||
| 20 | +// (Linux and CJNATIVE) EXEC: rm -rf llvmcache-* | ||
| 21 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %enableO2 %f -o main_reflect.out --lto=thin libpkgs.bc libpkga.bc | ||
| 22 | + | ||
| 23 | +// The flagged binary must still run correctly. | ||
| 24 | +// (Linux and CJNATIVE) RUN-EXEC: %run %run_opt %output %run_args | ||
| 25 | + | ||
| 26 | +// Symbol guard on the flagged binary: fieldnames kept, the reflect global is | ||
| 27 | +// downgraded to .dbg, and method reflection must be gone. NOTE: scan is | ||
| 28 | +// substring matching, NOT regex — no escaping/anchors. | ||
| 29 | +// (Linux and CJNATIVE) EXEC-PIPE: $CANGJIE_HOME/third_party/llvm/bin/llvm-objdump -t %output 2>&1 | compare %f | ||
| 30 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:Data.tt.fieldnames | ||
| 31 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:Data.tt.reflect.dbg | ||
| 32 | +// (Linux and CJNATIVE) ASSERT: scan-not pkgs:Data.tt.method0 | ||
| 33 | + | ||
| 34 | +// Final stage: size comparison (all links already done). | ||
| 35 | +// (Linux and CJNATIVE) EXEC: test $(stat -c %s %output) -lt $(stat -c %s main_reflect.out) | ||
| 36 | + | ||
| 37 | +import pkgs | ||
| 38 | +import pkga | ||
| 39 | + | ||
| 40 | +main(): Int64 { | ||
| 41 | + return run() | ||
| 42 | +} | ||
| 43 | + | ||
| 44 | +func run(): Int64 { | ||
| 45 | + var a: Int32 = 3 | ||
| 46 | + var b: Int32 = 4 | ||
| 47 | + let data1: pkgs.Data<Int32> = pkgs.Data<Int32>(a, b) | ||
| 48 | + let data2: pkga.Data<Int32> = pkga.Data<Int32>(b, a) | ||
| 49 | + var res1: Int32 = data1.area() | ||
| 50 | + var res2: Int32 = data2.area() | ||
| 51 | + if (res1 == 3 && res2 == 4) { | ||
| 52 | + return 0 | ||
| 53 | + } | ||
| 54 | + return 1 | ||
| 55 | +} | ||
| @@ -0,0 +1,40 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +// Control side of the LTO reflection cut: linking WITHOUT --disable-reflection | ||
| 8 | +// must NOT run CJDisableImportLibReflection, so the final binary keeps full | ||
| 9 | +// imported-lib reflection (method0 present, reflect global NOT downgraded to | ||
| 10 | +// .dbg). Existing tests only size-compare main_reflect.out; this pins the | ||
| 11 | +// control's symbol state. O0 keeps every symbol stable. | ||
| 12 | +// (Linux and CJNATIVE) DEPENDENCE: pkgs pkga | ||
| 13 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkgs/pkgs.cj --lto=full --output-type=staticlib | ||
| 14 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt pkga/pkga.cj --lto=full --output-type=staticlib | ||
| 15 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %f -o %output --lto=full libpkgs.bc libpkga.bc | ||
| 16 | +// (Linux and CJNATIVE) RUN-EXEC: %run %run_opt %output %run_args | ||
| 17 | +// (Linux and CJNATIVE) EXEC-PIPE: $CANGJIE_HOME/third_party/llvm/bin/llvm-objdump -t %output 2>&1 | compare %f | ||
| 18 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:Data.tt.method0 | ||
| 19 | +// (Linux and CJNATIVE) ASSERT: scan pkgs:Data.tt.fieldnames | ||
| 20 | +// (Linux and CJNATIVE) ASSERT: scan-not pkgs:Data.tt.reflect.dbg | ||
| 21 | + | ||
| 22 | +import pkgs | ||
| 23 | +import pkga | ||
| 24 | + | ||
| 25 | +main(): Int64 { | ||
| 26 | + return run() | ||
| 27 | +} | ||
| 28 | + | ||
| 29 | +func run(): Int64 { | ||
| 30 | + var a: Int32 = 3 | ||
| 31 | + var b: Int32 = 4 | ||
| 32 | + let data1: pkgs.Data<Int32> = pkgs.Data<Int32>(a, b) | ||
| 33 | + let data2: pkga.Data<Int32> = pkga.Data<Int32>(b, a) | ||
| 34 | + var res1: Int32 = data1.area() | ||
| 35 | + var res2: Int32 = data2.area() | ||
| 36 | + if (res1 == 3 && res2 == 4) { | ||
| 37 | + return 0 | ||
| 38 | + } | ||
| 39 | + return 1 | ||
| 40 | +} | ||
| @@ -0,0 +1,19 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package pkga | ||
| 8 | + | ||
| 9 | +public struct Data<T> { | ||
| 10 | + public let width: T | ||
| 11 | + public let length: T | ||
| 12 | + public init(width1: T, length1: T) { | ||
| 13 | + width = width1 | ||
| 14 | + length = length1 | ||
| 15 | + } | ||
| 16 | + public func area(): T { | ||
| 17 | + return width | ||
| 18 | + } | ||
| 19 | +} | ||
| @@ -0,0 +1,19 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package pkgs | ||
| 8 | + | ||
| 9 | +public struct Data<T> { | ||
| 10 | + public let width: T | ||
| 11 | + public let length: T | ||
| 12 | + public init(width1: T, length1: T) { | ||
| 13 | + width = width1 | ||
| 14 | + length = length1 | ||
| 15 | + } | ||
| 16 | + public func area(): T { | ||
| 17 | + return width | ||
| 18 | + } | ||
| 19 | +} | ||
| @@ -0,0 +1,25 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +// (Linux and CJNATIVE) DEPENDENCE: pkgs pkga | ||
| 8 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %compile_lib_opt --lto=full pkgs/pkgs.cj -o libpkgs.bc | ||
| 9 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %compile_lib_opt --lto=full pkga/pkga.cj -o libpkga.bc | ||
| 10 | +// (Linux and CJNATIVE) EXEC-PIPE: %compiler %cmp_opt %verbose_opt --lto=full --disable-reflection %f libpkgs.bc libpkga.bc -o %output 2>&1 | compare %f | ||
| 11 | +// (Linux and CJNATIVE) ASSERT: regex (llvm-link|llvm-lto|opt|lld) | ||
| 12 | +// (Linux and CJNATIVE) ASSERT: scan-not --cj-disable-lto-reflection | ||
| 13 | +// (Linux and CJNATIVE) RUN-EXEC: %run %run_opt %output %run_args | ||
| 14 | + | ||
| 15 | +import pkgs | ||
| 16 | +import pkga | ||
| 17 | + | ||
| 18 | +main(): Int64 { | ||
| 19 | + let name1 = pkgs.reflectName() | ||
| 20 | + let name2 = pkga.reflectName() | ||
| 21 | + if (name1.isEmpty() || name2.isEmpty()) { | ||
| 22 | + return 1 | ||
| 23 | + } | ||
| 24 | + return 0 | ||
| 25 | +} | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package pkga | ||
| 8 | + | ||
| 9 | +import std.reflect.* | ||
| 10 | + | ||
| 11 | +public struct Data<T> { | ||
| 12 | + public let width: T | ||
| 13 | + public let length: T | ||
| 14 | + public init(width1: T, length1: T) { | ||
| 15 | + width = width1 | ||
| 16 | + length = length1 | ||
| 17 | + } | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +public func reflectName(): String { | ||
| 21 | + return TypeInfo.of<Data<Int32>>().toString() | ||
| 22 | +} | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package pkgs | ||
| 8 | + | ||
| 9 | +import std.reflect.* | ||
| 10 | + | ||
| 11 | +public struct Data<T> { | ||
| 12 | + public let width: T | ||
| 13 | + public let length: T | ||
| 14 | + public init(width1: T, length1: T) { | ||
| 15 | + width = width1 | ||
| 16 | + length = length1 | ||
| 17 | + } | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +public func reflectName(): String { | ||
| 21 | + return TypeInfo.of<Data<Int32>>().toString() | ||
| 22 | +} | ||
| @@ -0,0 +1,29 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +// ThinLTO variant of reflect_link_input: the program links std.reflect, so | ||
| 8 | +// --lto=thin + --disable-reflection must NOT forward --cj-disable-lto-reflection | ||
| 9 | +// (the LinksStdReflect exemption goes through the same SetOptions branch for | ||
| 10 | +// Full and Thin LTO). | ||
| 11 | +// (Linux and CJNATIVE) DEPENDENCE: pkgs pkga | ||
| 12 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %compile_lib_opt --lto=full pkgs/pkgs.cj -o libpkgs.bc | ||
| 13 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %compile_lib_opt --lto=full pkga/pkga.cj -o libpkga.bc | ||
| 14 | +// (Linux and CJNATIVE) EXEC-PIPE: %compiler %cmp_opt %verbose_opt --lto=thin --disable-reflection %f libpkgs.bc libpkga.bc -o %output 2>&1 | compare %f | ||
| 15 | +// (Linux and CJNATIVE) ASSERT: regex (llvm-link|llvm-lto|opt|lld) | ||
| 16 | +// (Linux and CJNATIVE) ASSERT: scan-not --cj-disable-lto-reflection | ||
| 17 | +// (Linux and CJNATIVE) RUN-EXEC: %run %run_opt %output %run_args | ||
| 18 | + | ||
| 19 | +import pkgs | ||
| 20 | +import pkga | ||
| 21 | + | ||
| 22 | +main(): Int64 { | ||
| 23 | + let name1 = pkgs.reflectName() | ||
| 24 | + let name2 = pkga.reflectName() | ||
| 25 | + if (name1.isEmpty() || name2.isEmpty()) { | ||
| 26 | + return 1 | ||
| 27 | + } | ||
| 28 | + return 0 | ||
| 29 | +} | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package pkga | ||
| 8 | + | ||
| 9 | +import std.reflect.* | ||
| 10 | + | ||
| 11 | +public struct Data<T> { | ||
| 12 | + public let width: T | ||
| 13 | + public let length: T | ||
| 14 | + public init(width1: T, length1: T) { | ||
| 15 | + width = width1 | ||
| 16 | + length = length1 | ||
| 17 | + } | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +public func reflectName(): String { | ||
| 21 | + return TypeInfo.of<Data<Int32>>().toString() | ||
| 22 | +} | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package pkgs | ||
| 8 | + | ||
| 9 | +import std.reflect.* | ||
| 10 | + | ||
| 11 | +public struct Data<T> { | ||
| 12 | + public let width: T | ||
| 13 | + public let length: T | ||
| 14 | + public init(width1: T, length1: T) { | ||
| 15 | + width = width1 | ||
| 16 | + length = length1 | ||
| 17 | + } | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +public func reflectName(): String { | ||
| 21 | + return TypeInfo.of<Data<Int32>>().toString() | ||
| 22 | +} | ||
| @@ -0,0 +1,34 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +// std.reflect exemption through a TRANSITIVE dependency: neither pkgs nor pkga | ||
| 8 | +// imports std.reflect directly; only the middle package does. LinksStdReflect() | ||
| 9 | +// scans direct+indirect builtin deps for std.reflect.cjo, so the driver must | ||
| 10 | +// still skip forwarding --cj-disable-lto-reflection for --lto=full | ||
| 11 | +// --disable-reflection. | ||
| 12 | +// Separate-compilation flow: middle is compiled first (middle.cjo lands in the | ||
| 13 | +// run dir), then pkgs/pkga resolve `import middle` through that cjo; all three | ||
| 14 | +// .bc libs are link inputs of the main link. | ||
| 15 | +// (Linux and CJNATIVE) DEPENDENCE: pkgs pkga middle | ||
| 16 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %compile_lib_opt --lto=full middle/middle.cj -o libmiddle.bc | ||
| 17 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %compile_lib_opt --lto=full pkgs/pkgs.cj -o libpkgs.bc | ||
| 18 | +// (Linux and CJNATIVE) EXEC: %compiler %cmp_opt %compile_lib_opt --lto=full pkga/pkga.cj -o libpkga.bc | ||
| 19 | +// (Linux and CJNATIVE) EXEC-PIPE: %compiler %cmp_opt %verbose_opt --lto=full --disable-reflection %f libpkgs.bc libpkga.bc libmiddle.bc -o %output 2>&1 | compare %f | ||
| 20 | +// (Linux and CJNATIVE) ASSERT: regex (llvm-link|llvm-lto|opt|lld) | ||
| 21 | +// (Linux and CJNATIVE) ASSERT: scan-not --cj-disable-lto-reflection | ||
| 22 | +// (Linux and CJNATIVE) RUN-EXEC: %run %run_opt %output %run_args | ||
| 23 | + | ||
| 24 | +import pkgs | ||
| 25 | +import pkga | ||
| 26 | + | ||
| 27 | +main(): Int64 { | ||
| 28 | + let name1 = pkgs.reflectName() | ||
| 29 | + let name2 = pkga.reflectName() | ||
| 30 | + if (name1.isEmpty() || name2.isEmpty()) { | ||
| 31 | + return 1 | ||
| 32 | + } | ||
| 33 | + return 0 | ||
| 34 | +} | ||
| @@ -0,0 +1,22 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package middle | ||
| 8 | + | ||
| 9 | +import std.reflect.* | ||
| 10 | + | ||
| 11 | +public struct Data<T> { | ||
| 12 | + public let width: T | ||
| 13 | + public let length: T | ||
| 14 | + public init(width1: T, length1: T) { | ||
| 15 | + width = width1 | ||
| 16 | + length = length1 | ||
| 17 | + } | ||
| 18 | +} | ||
| 19 | + | ||
| 20 | +public func reflectName(): String { | ||
| 21 | + return TypeInfo.of<Data<Int32>>().toString() | ||
| 22 | +} | ||
| @@ -0,0 +1,13 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package pkga | ||
| 8 | + | ||
| 9 | +import middle | ||
| 10 | + | ||
| 11 | +public func reflectName(): String { | ||
| 12 | + return middle.reflectName() | ||
| 13 | +} | ||
| @@ -0,0 +1,13 @@ | |||
| 1 | +// Copyright (c) Huawei Technologies Co., Ltd. 2026. All rights reserved. | ||
| 2 | +// This source file is part of the Cangjie project, licensed under Apache-2.0 | ||
| 3 | +// with Runtime Library Exception. | ||
| 4 | +// | ||
| 5 | +// See https://cangjie-lang.cn/pages/LICENSE for license information. | ||
| 6 | + | ||
| 7 | +package pkgs | ||
| 8 | + | ||
| 9 | +import middle | ||
| 10 | + | ||
| 11 | +public func reflectName(): String { | ||
| 12 | + return middle.reflectName() | ||
| 13 | +} | ||