Skip to content

Commit a96c794

Browse files
committed
Add an option to ignore unchecked() expressions
This new option, --ignoreUnchecked, can be useful for debugging whether out-of-bounds reads/writes are taking place in code that normally should not bounds-check for performance reasons.
1 parent 8ae086d commit a96c794

File tree

5 files changed

+15
-1
lines changed

5 files changed

+15
-1
lines changed

cli/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ export async function main(argv, options) {
320320
assemblyscript.setMemoryBase(compilerOptions, opts.memoryBase >>> 0);
321321
assemblyscript.setTableBase(compilerOptions, opts.tableBase >>> 0);
322322
assemblyscript.setSourceMap(compilerOptions, opts.sourceMap != null);
323+
assemblyscript.setIgnoreUnchecked(compilerOptions, opts.ignoreUnchecked);
323324
assemblyscript.setNoUnsafe(compilerOptions, opts.noUnsafe);
324325
assemblyscript.setPedantic(compilerOptions, opts.pedantic);
325326
assemblyscript.setLowMemoryLimit(compilerOptions, opts.lowMemoryLimit >>> 0);

cli/options.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@
9898
],
9999
"type": "s"
100100
},
101+
"ignoreUnchecked": {
102+
"category": "Debugging",
103+
"description": "Ignores unchecked() expressions.",
104+
"type": "b",
105+
"default": false
106+
},
101107
"debug": {
102108
"category": "Debugging",
103109
"description": "Enables debug information in emitted binaries.",

src/builtins.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3588,7 +3588,7 @@ function builtin_unchecked(ctx: BuiltinContext): ExpressionRef {
35883588
) return module.unreachable();
35893589
let flow = compiler.currentFlow;
35903590
let alreadyUnchecked = flow.is(FlowFlags.UncheckedContext);
3591-
flow.set(FlowFlags.UncheckedContext);
3591+
if (!compiler.options.ignoreUnchecked) flow.set(FlowFlags.UncheckedContext);
35923592
// eliminate unnecessary tees by preferring contextualType(=void)
35933593
let expr = compiler.compileExpression(ctx.operands[0], ctx.contextualType);
35943594
if (!alreadyUnchecked) flow.unset(FlowFlags.UncheckedContext);

src/compiler.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,8 @@ export class Options {
246246
exportTable: bool = false;
247247
/** If true, generates information necessary for source maps. */
248248
sourceMap: bool = false;
249+
/** If true, unchecked() expressions are ignored. */
250+
ignoreUnchecked: bool = false;
249251
/** If given, exports the start function instead of calling it implicitly. */
250252
exportStart: string | null = null;
251253
/** Static memory start offset. */

src/index-wasm.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,11 @@ export function setSourceMap(options: Options, sourceMap: bool): void {
102102
options.sourceMap = sourceMap;
103103
}
104104

105+
/** Sets the `ignoreUnchecked` option. */
106+
export function setIgnoreUnchecked(options: Options, ignoreUnchecked: bool): void {
107+
options.ignoreUnchecked = ignoreUnchecked;
108+
}
109+
105110
/** Sets the `memoryBase` option. */
106111
export function setMemoryBase(options: Options, memoryBase: u32): void {
107112
options.memoryBase = memoryBase;

0 commit comments

Comments
 (0)