Skip to content

Commit 256a6b0

Browse files
authored
Add warnings if entry contains imported / exported function or global with v128 type (#2429)
1 parent bdfe551 commit 256a6b0

File tree

8 files changed

+108
-18
lines changed

8 files changed

+108
-18
lines changed

cli/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -858,7 +858,7 @@ export async function main(argv, options) {
858858
if (!opts.noEmit) {
859859
if (opts.binaryFile) {
860860
// We catched lagacy field for binary output (before 0.20)
861-
return prepareResult(Error("`binaryFile` doesn't support. Please use `outFile` instead."));
861+
return prepareResult(Error("Usage of the --binaryFile compiler option is no longer supported. Use --outFile instead."));
862862
}
863863
let bindings = opts.bindings || [];
864864
let hasStdout = false;

src/bindings/js.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1369,6 +1369,8 @@ function indentText(text: string, indentLevel: i32, sb: string[], butFirst: bool
13691369
}
13701370

13711371
export function liftRequiresExportRuntime(type: Type): bool {
1372+
// TODO: enable v128 in signatures in future
1373+
// if (type.isVectorValue) return true;
13721374
if (!type.isInternalReference) return false;
13731375
let clazz = type.classReference;
13741376
if (!clazz) {
@@ -1398,6 +1400,8 @@ export function liftRequiresExportRuntime(type: Type): bool {
13981400
}
13991401

14001402
export function lowerRequiresExportRuntime(type: Type): bool {
1403+
// TODO: enable v128 in signatures in future
1404+
// if (type.isVectorValue) return true;
14011405
if (!type.isInternalReference) return false;
14021406
let clazz = type.classReference;
14031407
if (!clazz) {

src/compiler.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -915,6 +915,15 @@ export class Compiler extends DiagnosticEmitter {
915915
}
916916
}
917917
}
918+
if (global.type == Type.v128) {
919+
this.warning(
920+
DiagnosticCode.Exchange_of_0_values_is_not_supported_by_all_embeddings,
921+
global.typeNode
922+
? assert(global.typeNode).range
923+
: global.identifierNode.range,
924+
"v128"
925+
);
926+
}
918927
return;
919928
}
920929
break;
@@ -1517,6 +1526,25 @@ export class Compiler extends DiagnosticEmitter {
15171526
instance.set(CommonFlags.ERRORED);
15181527
}
15191528

1529+
if (instance.is(CommonFlags.AMBIENT) || instance.is(CommonFlags.EXPORT)) {
1530+
// Verify and print warn if signature has v128 type for imported or exported functions
1531+
let hasVectorValueOperands = signature.hasVectorValueOperands;
1532+
if (hasVectorValueOperands) {
1533+
let range: Range;
1534+
let fnTypeNode = instance.prototype.functionTypeNode;
1535+
if (signature.returnType == Type.v128) {
1536+
range = fnTypeNode.returnType.range;
1537+
} else {
1538+
let firstIndex = signature.getVectorValueOperandIndices()[0];
1539+
range = fnTypeNode.parameters[firstIndex].range;
1540+
}
1541+
this.warning(
1542+
DiagnosticCode.Exchange_of_0_values_is_not_supported_by_all_embeddings,
1543+
range, "v128"
1544+
);
1545+
}
1546+
}
1547+
15201548
instance.finalize(module, funcRef);
15211549
this.currentType = previousType;
15221550
pendingElements.delete(instance);

src/diagnosticMessages.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"Transform '{0}': {1}": 109,
1212
"Start function name '{0}' is invalid or conflicts with another export.": 110,
1313
"Element '{0}' not found.": 111,
14+
"Exchange of '{0}' values is not supported by all embeddings": 112,
1415

1516
"Conversion from type '{0}' to '{1}' requires an explicit cast.": 200,
1617
"Conversion from type '{0}' to '{1}' will require an explicit cast when switching between 32/64-bit.": 201,

src/types.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,38 @@ export class Signature {
930930
return indices;
931931
}
932932

933+
/** Tests if this signature has at least one v128 operand. */
934+
get hasVectorValueOperands(): bool {
935+
var thisType = this.thisType;
936+
if (thisType && thisType.isVectorValue) {
937+
return true;
938+
}
939+
var parameterTypes = this.parameterTypes;
940+
for (let i = 0, k = parameterTypes.length; i < k; ++i) {
941+
if (unchecked(parameterTypes[i]).isVectorValue) return true;
942+
}
943+
return false;
944+
}
945+
946+
/** Gets the indices of all v128 operands. */
947+
getVectorValueOperandIndices(): i32[] {
948+
var indices = new Array<i32>();
949+
var index = 0;
950+
var thisType = this.thisType;
951+
if (thisType) {
952+
if (thisType.isVectorValue) indices.push(index);
953+
++index;
954+
}
955+
var parameterTypes = this.parameterTypes;
956+
for (let i = 0, k = parameterTypes.length; i < k; ++i) {
957+
if (unchecked(parameterTypes[i]).isVectorValue) {
958+
indices.push(index);
959+
}
960+
++index;
961+
}
962+
return indices;
963+
}
964+
933965
/** Converts this signature to a string. */
934966
toString(validWat: bool = false): string {
935967
var sb = new Array<string>();

tests/compiler/simd.debug.wat

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
(type $none_=>_i32 (func (result i32)))
1212
(type $i32_i32_=>_v128 (func (param i32 i32) (result v128)))
1313
(type $none_=>_v128 (func (result v128)))
14+
(type $v128_=>_v128 (func (param v128) (result v128)))
1415
(type $i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_=>_v128 (func (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result v128)))
1516
(type $i32_i32_i32_i32_i32_i32_i32_i32_=>_v128 (func (param i32 i32 i32 i32 i32 i32 i32 i32) (result v128)))
1617
(type $i32_i32_i32_i32_=>_v128 (func (param i32 i32 i32 i32) (result v128)))
@@ -36,7 +37,7 @@
3637
(global $~lib/rt/itcms/fromSpace (mut i32) (i32.const 0))
3738
(global $~lib/rt/tlsf/ROOT (mut i32) (i32.const 0))
3839
(global $~lib/native/ASC_LOW_MEMORY_LIMIT i32 (i32.const 0))
39-
(global $~lib/native/ASC_FEATURE_SIMD i32 (i32.const 1))
40+
(global $simd/vec (mut v128) (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000))
4041
(global $~lib/builtins/u8.MAX_VALUE i32 (i32.const 255))
4142
(global $~lib/builtins/u16.MAX_VALUE i32 (i32.const 65535))
4243
(global $~lib/builtins/i16.MAX_VALUE i32 (i32.const 32767))
@@ -63,6 +64,7 @@
6364
(data (i32.const 560) "\05\00\00\00 \00\00\00\00\00\00\00 \00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\02\04\00\00\00\00\00\00\02\t\00\00\00\00\00\00")
6465
(table $0 1 1 funcref)
6566
(elem $0 (i32.const 1))
67+
(export "reexport" (func $simd/reexport))
6668
(export "test_vars_i8x16_partial" (func $simd/test_vars_i8x16_partial))
6769
(export "test_vars_i8x16_full" (func $simd/test_vars_i8x16_full))
6870
(export "test_vars_i16x8_partial" (func $simd/test_vars_i16x8_partial))
@@ -75,6 +77,7 @@
7577
(export "test_vars_f32x4_full" (func $simd/test_vars_f32x4_full))
7678
(export "test_vars_f64x2_partial" (func $simd/test_vars_f64x2_partial))
7779
(export "test_vars_f64x2_full" (func $simd/test_vars_f64x2_full))
80+
(export "vec" (global $simd/vec))
7881
(export "memory" (memory $0))
7982
(start $~start)
8083
(func $~lib/rt/itcms/Object#set:nextWithColor (param $0 i32) (param $1 i32)
@@ -6500,7 +6503,8 @@
65006503
unreachable
65016504
end
65026505
i32.const 1
6503-
drop
6506+
i32x4.splat
6507+
global.set $simd/vec
65046508
i32.const 1
65056509
drop
65066510
i32.const 0
@@ -6525,6 +6529,11 @@
65256529
i32.add
65266530
global.set $~lib/memory/__stack_pointer
65276531
)
6532+
(func $simd/reexport (param $0 v128) (result v128)
6533+
local.get $0
6534+
local.get $0
6535+
i32x4.mul
6536+
)
65286537
(func $simd/test_vars_i8x16_partial (param $0 i32) (param $1 i32) (param $2 i32) (result v128)
65296538
v128.const i32x4 0x03000100 0x07000504 0x0b0a0908 0x000e0d0c
65306539
local.get $0

tests/compiler/simd.release.wat

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
(type $i32_i32_i32_=>_none (func (param i32 i32 i32)))
99
(type $none_=>_i32 (func (result i32)))
1010
(type $i32_=>_i32 (func (param i32) (result i32)))
11+
(type $v128_=>_v128 (func (param v128) (result v128)))
1112
(type $i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_i32_=>_v128 (func (param i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32 i32) (result v128)))
1213
(type $i32_i32_i32_i32_i32_i32_i32_i32_=>_v128 (func (param i32 i32 i32 i32 i32 i32 i32 i32) (result v128)))
1314
(type $i32_i32_i32_i32_=>_v128 (func (param i32 i32 i32 i32) (result v128)))
@@ -28,6 +29,7 @@
2829
(global $~lib/rt/itcms/white (mut i32) (i32.const 0))
2930
(global $~lib/rt/itcms/fromSpace (mut i32) (i32.const 0))
3031
(global $~lib/rt/tlsf/ROOT (mut i32) (i32.const 0))
32+
(global $simd/vec (mut v128) (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000))
3133
(global $~lib/memory/__stack_pointer (mut i32) (i32.const 18012))
3234
(memory $0 1)
3335
(data (i32.const 1036) ",")
@@ -48,6 +50,7 @@
4850
(data (i32.const 1544) "\01\00\00\00\0e\00\00\00s\00i\00m\00d\00.\00t\00s")
4951
(data (i32.const 1584) "\05\00\00\00 \00\00\00\00\00\00\00 ")
5052
(data (i32.const 1612) "\02\04\00\00\00\00\00\00\02\t")
53+
(export "reexport" (func $simd/reexport))
5154
(export "test_vars_i8x16_partial" (func $simd/test_vars_i8x16_partial))
5255
(export "test_vars_i8x16_full" (func $simd/test_vars_i8x16_full))
5356
(export "test_vars_i16x8_partial" (func $simd/test_vars_i16x8_partial))
@@ -60,6 +63,7 @@
6063
(export "test_vars_f32x4_full" (func $simd/test_vars_f32x4_full))
6164
(export "test_vars_f64x2_partial" (func $simd/test_vars_f64x2_partial))
6265
(export "test_vars_f64x2_full" (func $simd/test_vars_f64x2_full))
66+
(export "vec" (global $simd/vec))
6367
(export "memory" (memory $0))
6468
(start $~start)
6569
(func $~lib/rt/itcms/visitRoots
@@ -2009,6 +2013,8 @@
20092013
call $~lib/builtins/abort
20102014
unreachable
20112015
end
2016+
v128.const i32x4 0x00000001 0x00000001 0x00000001 0x00000001
2017+
global.set $simd/vec
20122018
call $simd/test_v128
20132019
global.get $~lib/rt/tlsf/ROOT
20142020
i32.eqz
@@ -2185,6 +2191,11 @@
21852191
call $~lib/builtins/abort
21862192
unreachable
21872193
)
2194+
(func $simd/reexport (param $0 v128) (result v128)
2195+
local.get $0
2196+
local.get $0
2197+
i32x4.mul
2198+
)
21882199
(func $simd/test_vars_i8x16_partial (param $0 i32) (param $1 i32) (param $2 i32) (result v128)
21892200
v128.const i32x4 0x03000100 0x07000504 0x0b0a0908 0x000e0d0c
21902201
local.get $0

tests/compiler/simd.ts

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,6 +1086,10 @@ function test_const(): v128 {
10861086
return one; // should not inline
10871087
}
10881088

1089+
export function reexport(a: v128): v128 {
1090+
return i32x4.mul(a, a);
1091+
}
1092+
10891093
export function test_vars_i8x16_partial(a: i8, b: i8, c: i8): v128 {
10901094
return i8x16(0, 1, a, 3, 4, 5, b, 7, 8, 9, 10, 11, 12, 13, 14, c);
10911095
}
@@ -1142,20 +1146,21 @@ export function test_vars_f64x2_full(a: f64, b: f64): v128 {
11421146
return f64x2(a, b);
11431147
}
11441148

1145-
if (ASC_FEATURE_SIMD) {
1146-
// test builtins
1147-
assert(isVector<v128>());
1148-
assert(!isVector<i32>());
1149+
// test exported var
1150+
export let vec: v128 = i32x4.splat(1);
11491151

1150-
assert(isVector(i32x4.splat(0)));
1151-
assert(!isVector(0));
1152+
// test builtins
1153+
assert(isVector<v128>());
1154+
assert(!isVector<i32>());
11521155

1153-
test_v128();
1154-
test_i8x16();
1155-
test_i16x8();
1156-
test_i32x4();
1157-
test_i64x2();
1158-
test_f32x4();
1159-
test_f64x2();
1160-
test_const();
1161-
}
1156+
assert(isVector(i32x4.splat(0)));
1157+
assert(!isVector(0));
1158+
1159+
test_v128();
1160+
test_i8x16();
1161+
test_i16x8();
1162+
test_i32x4();
1163+
test_i64x2();
1164+
test_f32x4();
1165+
test_f64x2();
1166+
test_const();

0 commit comments

Comments
 (0)