Improve inlining where locals can be aliased; Add a crude mechanism for explicit unchecked array accesses

The `unchecked` builtin should be handled with ultimate care and it would be a lot better if there'd be a mechanism doing this automatically.
This commit is contained in:
dcodeIO
2018-04-25 05:04:35 +02:00
parent 391db28fe2
commit 6d6d1dddcf
47 changed files with 5374 additions and 15672 deletions

View File

@ -43,7 +43,8 @@ import {
FunctionPrototype,
Class,
Field,
OperatorKind
OperatorKind,
FlowFlags
} from "./program";
/** Compiles a call to a built-in function. */
@ -2057,6 +2058,26 @@ export function compileCall(
}
return ret;
}
case "unchecked": {
if (typeArguments) {
compiler.error(
DiagnosticCode.Type_0_is_not_generic,
reportNode.range, prototype.internalName
);
}
if (operands.length != 1) {
compiler.error(
DiagnosticCode.Expected_0_arguments_but_got_1,
reportNode.range, "1", operands.length.toString(10)
);
return module.createUnreachable();
}
let flow = compiler.currentFunction.flow;
flow.set(FlowFlags.UNCHECKED_CONTEXT);
ret = compiler.compileExpressionRetainType(operands[0], contextualType, false);
flow.unset(FlowFlags.UNCHECKED_CONTEXT);
return ret;
}
// conversions