[torque] Make return types required

Currently, it is possible to declare macros, builtins, etc., without
specifying a return type, in which case the return type is treated as
void. This is confusing; the code is more clear if we require the return
type to be specified.

Aside from src/torque, this change is almost entirely just adding
`: void` until the compiler is happy. However, two intrinsics in
src/builtins/torque-internal.tq have been corrected to declare an
appropriate return type. Those two intrinsics were only used in code
generated within the compiler after the type-checking phase, so we never
noticed that their return types were declared incorrectly.

Bug: v8:7793
Change-Id: Ib7df88678c25393a9e3eba389a6a1c4d9233dcbb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3176502
Commit-Queue: Seth Brenith <seth.brenith@microsoft.com>
Reviewed-by: Jakob Gruber <jgruber@chromium.org>
Reviewed-by: Nico Hartmann <nicohartmann@chromium.org>
Cr-Commit-Position: refs/heads/main@{#77178}
This commit is contained in:
Seth Brenith 2021-09-30 08:12:46 -07:00 committed by V8 LUCI CQ
parent c9f69db900
commit 25f0e32915
37 changed files with 286 additions and 259 deletions

View File

@ -97,7 +97,7 @@ transitioning builtin ArrayFilterLoopContinuation(implicit context: Context)(
transitioning macro FastArrayFilter(implicit context: Context)(
fastO: FastJSArray, len: Smi, callbackfn: Callable, thisArg: JSAny,
output: FastJSArray) labels
output: FastJSArray): void labels
Bailout(Number, Number) {
let k: Smi = 0;
let to: Smi = 0;

View File

@ -147,7 +147,7 @@ macro StoreAndGrowFixedArray<T: type>(
// Buffer.AddSeparators().
struct Buffer {
macro Add(implicit context: Context)(
str: String, nofSeparators: intptr, separatorLength: intptr) {
str: String, nofSeparators: intptr, separatorLength: intptr): void {
// Add separators if necessary (at the beginning or more than one)
const writeSeparators: bool = this.index == 0 | nofSeparators > 1;
this.AddSeparators(nofSeparators, separatorLength, writeSeparators);
@ -161,7 +161,7 @@ struct Buffer {
}
macro AddSeparators(implicit context: Context)(
nofSeparators: intptr, separatorLength: intptr, write: bool) {
nofSeparators: intptr, separatorLength: intptr, write: bool): void {
if (nofSeparators == 0 || separatorLength == 0) return;
const nofSeparatorsInt: intptr = nofSeparators;
@ -504,7 +504,8 @@ builtin JoinStackPop(implicit context: Context)(
}
// Fast path the common non-nested calls.
macro JoinStackPopInline(implicit context: Context)(receiver: JSReceiver) {
macro JoinStackPopInline(implicit context: Context)(receiver: JSReceiver):
void {
const stack: FixedArray = LoadJoinStack()
otherwise unreachable;
const len: intptr = stack.length_intptr;

View File

@ -97,7 +97,7 @@ transitioning builtin ArrayMapLoopContinuation(implicit context: Context)(
}
struct Vector {
macro ReportSkippedElement() {
macro ReportSkippedElement(): void {
this.skippedElements = true;
}
@ -153,7 +153,8 @@ struct Vector {
return a;
}
macro StoreResult(implicit context: Context)(index: Smi, result: JSAny) {
macro StoreResult(implicit context: Context)(
index: Smi, result: JSAny): void {
typeswitch (result) {
case (s: Smi): {
this.fixedArray.objects[index] = s;

View File

@ -27,23 +27,24 @@ LoadElement<array::FastPackedDoubleElements, float64>(
}
macro StoreElement<ElementsAccessor : type extends ElementsKind, T: type>(
implicit context: Context)(elements: FixedArrayBase, index: Smi, value: T);
implicit context: Context)(
elements: FixedArrayBase, index: Smi, value: T): void;
StoreElement<array::FastPackedSmiElements, Smi>(implicit context: Context)(
elements: FixedArrayBase, index: Smi, value: Smi) {
elements: FixedArrayBase, index: Smi, value: Smi): void {
const elems: FixedArray = UnsafeCast<FixedArray>(elements);
StoreFixedArrayElement(elems, index, value);
}
StoreElement<array::FastPackedObjectElements, JSAny>(implicit context: Context)(
elements: FixedArrayBase, index: Smi, value: JSAny) {
elements: FixedArrayBase, index: Smi, value: JSAny): void {
const elements: FixedArray = UnsafeCast<FixedArray>(elements);
elements.objects[index] = value;
}
StoreElement<array::FastPackedDoubleElements, float64>(
implicit context: Context)(
elements: FixedArrayBase, index: Smi, value: float64) {
elements: FixedArrayBase, index: Smi, value: float64): void {
const elems: FixedDoubleArray = UnsafeCast<FixedDoubleArray>(elements);
StoreFixedDoubleArrayElement(elems, index, value);
}
@ -52,7 +53,7 @@ StoreElement<array::FastPackedDoubleElements, float64>(
// whether a property is present, so we can simply swap them using fast
// FixedArray loads/stores.
macro FastPackedArrayReverse<Accessor: type, T: type>(
implicit context: Context)(elements: FixedArrayBase, length: Smi) {
implicit context: Context)(elements: FixedArrayBase, length: Smi): void {
let lower: Smi = 0;
let upper: Smi = length - 1;
@ -138,8 +139,8 @@ transitioning macro GenericArrayReverse(
return object;
}
macro TryFastPackedArrayReverse(implicit context: Context)(receiver: JSAny)
labels Slow {
macro TryFastPackedArrayReverse(implicit context: Context)(receiver: JSAny):
void labels Slow {
const array: FastJSArray = Cast<FastJSArray>(receiver) otherwise Slow;
const kind: ElementsKind = array.map.elements_kind;

View File

@ -16,7 +16,8 @@ type FastSmiOrObjectElements extends ElementsKind;
type FastDoubleElements extends ElementsKind;
type DictionaryElements extends ElementsKind;
macro EnsureWriteableFastElements(implicit context: Context)(array: JSArray) {
macro EnsureWriteableFastElements(implicit context: Context)(array: JSArray):
void {
dcheck(IsFastElementsKind(array.map.elements_kind));
const elements: FixedArrayBase = array.elements;
@ -51,7 +52,7 @@ macro StoreArrayHole(elements: FixedArray, k: Smi): void {
elements.objects[k] = TheHole;
}
extern macro SetPropertyLength(implicit context: Context)(JSAny, Number);
extern macro SetPropertyLength(implicit context: Context)(JSAny, Number): void;
const kLengthDescriptorIndex:
constexpr int31 generates 'JSArray::kLengthDescriptorIndex';

View File

@ -576,11 +576,11 @@ extern macro Is64(): constexpr bool;
extern macro SelectBooleanConstant(bool): Boolean;
extern macro Print(constexpr string);
extern macro Print(constexpr string, Object);
extern macro Comment(constexpr string);
extern macro Print(Object);
extern macro DebugBreak();
extern macro Print(constexpr string): void;
extern macro Print(constexpr string, Object): void;
extern macro Comment(constexpr string): void;
extern macro Print(Object): void;
extern macro DebugBreak(): void;
// ES6 7.1.4 ToInteger ( argument )
transitioning macro ToIntegerImpl(implicit context: Context)(input: JSAny):
@ -739,9 +739,9 @@ transitioning macro ToPrimitiveDefault(implicit context: Context)(v: JSAny):
}
}
extern transitioning runtime NormalizeElements(Context, JSObject);
extern transitioning runtime NormalizeElements(Context, JSObject): void;
extern transitioning runtime TransitionElementsKindWithKind(
Context, JSObject, Smi);
Context, JSObject, Smi): void;
extern macro LoadBufferObject(RawPtr, constexpr int32): Object;
extern macro LoadBufferPointer(RawPtr, constexpr int32): RawPtr;
@ -1226,7 +1226,7 @@ extern operator '.elements_kind' macro LoadElementsKind(JSTypedArray):
extern operator '.length' macro LoadFastJSArrayLength(FastJSArray): Smi;
operator '.length=' macro StoreFastJSArrayLength(
array: FastJSArray, length: Smi) {
array: FastJSArray, length: Smi): void {
const array: JSArray = array;
array.length = length;
}
@ -1360,7 +1360,7 @@ macro NumberIsNaN(number: Number): bool {
}
}
extern macro GotoIfForceSlowPath() labels Taken;
extern macro GotoIfForceSlowPath(): void labels Taken;
macro IsForceSlowPath(): bool {
GotoIfForceSlowPath() otherwise return true;
return false;
@ -1392,7 +1392,7 @@ macro SameValue(a: JSAny, b: JSAny): bool {
// Does "if (index1 + index2 > limit) goto IfOverflow" in an uintptr overflow
// friendly way where index1 and index2 are in [0, kMaxSafeInteger] range.
macro CheckIntegerIndexAdditionOverflow(
index1: uintptr, index2: uintptr, limit: uintptr) labels IfOverflow {
index1: uintptr, index2: uintptr, limit: uintptr): void labels IfOverflow {
if constexpr (Is64()) {
dcheck(index1 <= kMaxSafeIntegerUint64);
dcheck(index2 <= kMaxSafeIntegerUint64);
@ -1711,10 +1711,10 @@ macro IsFastJSArrayForReadWithNoCustomIteration(context: Context, o: Object):
}
extern transitioning runtime
CreateDataProperty(implicit context: Context)(JSReceiver, JSAny, JSAny);
CreateDataProperty(implicit context: Context)(JSReceiver, JSAny, JSAny): void;
extern transitioning runtime SetOwnPropertyIgnoreAttributes(
implicit context: Context)(JSObject, String, JSAny, Smi);
implicit context: Context)(JSObject, String, JSAny, Smi): void;
namespace runtime {
extern runtime

View File

@ -514,13 +514,14 @@ extern macro TruncateFloat64ToWord32(float64): uint32;
extern macro DataViewBuiltinsAssembler::StoreWord8(
RawPtr, uintptr, uint32): void;
macro StoreDataView8(buffer: JSArrayBuffer, offset: uintptr, value: uint32) {
macro StoreDataView8(
buffer: JSArrayBuffer, offset: uintptr, value: uint32): void {
StoreWord8(buffer.backing_store_ptr, offset, value & 0xFF);
}
macro StoreDataView16(
buffer: JSArrayBuffer, offset: uintptr, value: uint32,
requestedLittleEndian: bool) {
requestedLittleEndian: bool): void {
const dataPointer: RawPtr = buffer.backing_store_ptr;
const b0: uint32 = value & 0xFF;
@ -537,7 +538,7 @@ macro StoreDataView16(
macro StoreDataView32(
buffer: JSArrayBuffer, offset: uintptr, value: uint32,
requestedLittleEndian: bool) {
requestedLittleEndian: bool): void {
const dataPointer: RawPtr = buffer.backing_store_ptr;
const b0: uint32 = value & 0xFF;
@ -560,7 +561,7 @@ macro StoreDataView32(
macro StoreDataView64(
buffer: JSArrayBuffer, offset: uintptr, lowWord: uint32, highWord: uint32,
requestedLittleEndian: bool) {
requestedLittleEndian: bool): void {
const dataPointer: RawPtr = buffer.backing_store_ptr;
const b0: uint32 = lowWord & 0xFF;
@ -604,7 +605,7 @@ extern macro DataViewBuiltinsAssembler::DataViewDecodeBigIntSign(BigIntBase):
// on 64-bit platforms, and the 2 lowest BigInt digits on 32-bit ones.
macro StoreDataViewBigInt(
buffer: JSArrayBuffer, offset: uintptr, bigIntValue: BigInt,
requestedLittleEndian: bool) {
requestedLittleEndian: bool): void {
const length: uint32 = DataViewDecodeBigIntLength(bigIntValue);
const sign: uint32 = DataViewDecodeBigIntSign(bigIntValue);

View File

@ -55,7 +55,7 @@ PopClearedCell(finalizationRegistry: JSFinalizationRegistry): WeakCell|
}
transitioning macro PushCell(
finalizationRegistry: JSFinalizationRegistry, cell: WeakCell) {
finalizationRegistry: JSFinalizationRegistry, cell: WeakCell): void {
cell.next = finalizationRegistry.active_cells;
typeswitch (finalizationRegistry.active_cells) {
case (Undefined): {
@ -69,7 +69,7 @@ transitioning macro PushCell(
transitioning macro
FinalizationRegistryCleanupLoop(implicit context: Context)(
finalizationRegistry: JSFinalizationRegistry, callback: Callable) {
finalizationRegistry: JSFinalizationRegistry, callback: Callable): void {
while (true) {
const weakCellHead = PopClearedCell(finalizationRegistry);
typeswitch (weakCellHead) {

View File

@ -24,7 +24,8 @@ const kMinDescriptorsForFastBind:
constexpr int31 generates 'JSFunction::kMinDescriptorsForFastBind';
macro CheckAccessor(implicit context: Context)(
array: DescriptorArray, index: constexpr int32, name: Name) labels Slow {
array: DescriptorArray, index: constexpr int32,
name: Name): void labels Slow {
const descriptor: DescriptorEntry = array.descriptors[index];
const key: Name|Undefined = descriptor.key;
if (!TaggedEqual(key, name)) goto Slow;

View File

@ -5,7 +5,7 @@
namespace growable_fixed_array {
// TODO(pwong): Support FixedTypedArrays.
struct GrowableFixedArray {
macro Push(obj: Object) {
macro Push(obj: Object): void {
this.EnsureCapacity();
this.array.objects[this.length++] = obj;
}
@ -16,7 +16,7 @@ struct GrowableFixedArray {
const first: intptr = 0;
return ExtractFixedArray(this.array, first, this.length, newCapacity);
}
macro EnsureCapacity() {
macro EnsureCapacity(): void {
dcheck(this.length <= this.capacity);
if (this.capacity == this.length) {
// Growth rate is analog to JSObject::NewElementsCapacity:

View File

@ -62,7 +62,8 @@ extern macro StoreFeedbackVectorSlot(
constexpr int32): void;
extern macro StoreWeakReferenceInFeedbackVector(
FeedbackVector, uintptr, HeapObject): MaybeObject;
extern macro ReportFeedbackUpdate(FeedbackVector, uintptr, constexpr string);
extern macro ReportFeedbackUpdate(
FeedbackVector, uintptr, constexpr string): void;
extern operator '.length_intptr' macro LoadFeedbackVectorLength(FeedbackVector):
intptr;

View File

@ -17,7 +17,7 @@ macro GetCoverageInfo(implicit context: Context)(function: JSFunction):
}
macro IncrementBlockCount(implicit context: Context)(
coverageInfo: CoverageInfo, slot: Smi) {
coverageInfo: CoverageInfo, slot: Smi): void {
dcheck(Convert<int32>(slot) < coverageInfo.slot_count);
++coverageInfo.slots[slot].block_count;
}

View File

@ -52,7 +52,7 @@ extern transitioning builtin ForInFilter(implicit context: Context)(
extern enum ForInFeedback extends uint31 { kAny, ...}
extern macro UpdateFeedback(
SmiTagged<ForInFeedback>, Undefined | FeedbackVector, uintptr,
constexpr UpdateFeedbackMode);
constexpr UpdateFeedbackMode): void;
@export
transitioning macro ForInNextSlow(

View File

@ -117,7 +117,7 @@ transitioning builtin CallIteratorWithFeedback(
// https://tc39.es/ecma262/#sec-iteratorclose
@export
transitioning macro IteratorCloseOnException(implicit context: Context)(
iterator: IteratorRecord) {
iterator: IteratorRecord): void {
try {
// 4. Let innerResult be GetMethod(iterator, "return").
const method = GetProperty(iterator.object, kReturnString);

View File

@ -103,7 +103,7 @@ macro NewPromiseRejectReactionJobTask(implicit context: Context)(
@export
transitioning macro RunContextPromiseHookInit(implicit context: Context)(
promise: JSPromise, parent: Object) {
promise: JSPromise, parent: Object): void {
const maybeHook = *NativeContextSlot(
ContextSlot::PROMISE_HOOK_INIT_FUNCTION_INDEX);
const hook = Cast<Callable>(maybeHook) otherwise return;
@ -119,7 +119,7 @@ transitioning macro RunContextPromiseHookInit(implicit context: Context)(
@export
transitioning macro RunContextPromiseHookResolve(implicit context: Context)(
promise: JSPromise) {
promise: JSPromise): void {
RunContextPromiseHook(
ContextSlot::PROMISE_HOOK_RESOLVE_FUNCTION_INDEX, promise,
PromiseHookFlags());
@ -127,14 +127,14 @@ transitioning macro RunContextPromiseHookResolve(implicit context: Context)(
@export
transitioning macro RunContextPromiseHookResolve(implicit context: Context)(
promise: JSPromise, flags: uint32) {
promise: JSPromise, flags: uint32): void {
RunContextPromiseHook(
ContextSlot::PROMISE_HOOK_RESOLVE_FUNCTION_INDEX, promise, flags);
}
@export
transitioning macro RunContextPromiseHookBefore(implicit context: Context)(
promiseOrCapability: JSPromise|PromiseCapability|Undefined) {
promiseOrCapability: JSPromise|PromiseCapability|Undefined): void {
RunContextPromiseHook(
ContextSlot::PROMISE_HOOK_BEFORE_FUNCTION_INDEX, promiseOrCapability,
PromiseHookFlags());
@ -142,7 +142,8 @@ transitioning macro RunContextPromiseHookBefore(implicit context: Context)(
@export
transitioning macro RunContextPromiseHookBefore(implicit context: Context)(
promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32) {
promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32):
void {
RunContextPromiseHook(
ContextSlot::PROMISE_HOOK_BEFORE_FUNCTION_INDEX, promiseOrCapability,
flags);
@ -150,7 +151,7 @@ transitioning macro RunContextPromiseHookBefore(implicit context: Context)(
@export
transitioning macro RunContextPromiseHookAfter(implicit context: Context)(
promiseOrCapability: JSPromise|PromiseCapability|Undefined) {
promiseOrCapability: JSPromise|PromiseCapability|Undefined): void {
RunContextPromiseHook(
ContextSlot::PROMISE_HOOK_AFTER_FUNCTION_INDEX, promiseOrCapability,
PromiseHookFlags());
@ -158,7 +159,8 @@ transitioning macro RunContextPromiseHookAfter(implicit context: Context)(
@export
transitioning macro RunContextPromiseHookAfter(implicit context: Context)(
promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32) {
promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32):
void {
RunContextPromiseHook(
ContextSlot::PROMISE_HOOK_AFTER_FUNCTION_INDEX, promiseOrCapability,
flags);
@ -166,7 +168,8 @@ transitioning macro RunContextPromiseHookAfter(implicit context: Context)(
transitioning macro RunContextPromiseHook(implicit context: Context)(
slot: Slot<NativeContext, Undefined|Callable>,
promiseOrCapability: JSPromise|PromiseCapability|Undefined, flags: uint32) {
promiseOrCapability: JSPromise|PromiseCapability|Undefined,
flags: uint32): void {
if (!IsContextPromiseHookEnabled(flags)) return;
const maybeHook = *NativeContextSlot(slot);
const hook = Cast<Callable>(maybeHook) otherwise return;
@ -192,7 +195,7 @@ transitioning macro RunContextPromiseHook(implicit context: Context)(
}
transitioning macro RunAnyPromiseHookInit(implicit context: Context)(
promise: JSPromise, parent: Object) {
promise: JSPromise, parent: Object): void {
const promiseHookFlags = PromiseHookFlags();
// Fast return if no hooks are set.
if (promiseHookFlags == 0) return;

View File

@ -11,7 +11,7 @@ SetPropertyWithReceiver(implicit context: Context)(
Object, Name, Object, Object): void;
transitioning macro CallThrowTypeErrorIfStrict(implicit context: Context)(
message: constexpr MessageTemplate) {
message: constexpr MessageTemplate): void {
ThrowTypeErrorIfStrict(SmiConstant(message), Null, Null);
}

View File

@ -11,13 +11,13 @@ extern macro ProxiesCodeStubAssembler::AllocateProxy(implicit context: Context)(
extern transitioning macro ProxiesCodeStubAssembler::CheckGetSetTrapResult(
implicit context: Context)(
JSReceiver, JSProxy, Name, Object, constexpr int31);
JSReceiver, JSProxy, Name, Object, constexpr int31): void;
extern transitioning macro ProxiesCodeStubAssembler::CheckDeleteTrapResult(
implicit context: Context)(JSReceiver, JSProxy, Name);
implicit context: Context)(JSReceiver, JSProxy, Name): void;
extern transitioning macro ProxiesCodeStubAssembler::CheckHasTrapResult(
implicit context: Context)(JSReceiver, JSProxy, Name);
implicit context: Context)(JSReceiver, JSProxy, Name): void;
const kProxyGet: constexpr int31
generates 'JSProxy::AccessKind::kGet';

View File

@ -22,7 +22,7 @@ StringReplaceNonGlobalRegExpWithFunction(implicit context: Context)(
transitioning macro RegExpReplaceCallableNoExplicitCaptures(
implicit context: Context)(
matchesElements: FixedArray, matchesLength: intptr, string: String,
replaceFn: Callable) {
replaceFn: Callable): void {
let matchStart: Smi = 0;
for (let i: intptr = 0; i < matchesLength; i++) {
typeswitch (matchesElements.objects[i]) {
@ -63,7 +63,8 @@ transitioning macro RegExpReplaceCallableNoExplicitCaptures(
transitioning macro
RegExpReplaceCallableWithExplicitCaptures(implicit context: Context)(
matchesElements: FixedArray, matchesLength: intptr, replaceFn: Callable) {
matchesElements: FixedArray, matchesLength: intptr,
replaceFn: Callable): void {
for (let i: intptr = 0; i < matchesLength; i++) {
const elArray =
Cast<JSArray>(matchesElements.objects[i]) otherwise continue;

View File

@ -243,7 +243,7 @@ macro AllocateFromNew(
}
macro InitializeFieldsFromIterator<T: type, Iterator: type>(
target: MutableSlice<T>, originIterator: Iterator) {
target: MutableSlice<T>, originIterator: Iterator): void {
let targetIterator = target.Iterator();
let originIterator = originIterator;
while (true) {
@ -253,12 +253,14 @@ macro InitializeFieldsFromIterator<T: type, Iterator: type>(
}
// Dummy implementations: do not initialize for UninitializedIterator.
InitializeFieldsFromIterator<char8, UninitializedIterator>(
_target: MutableSlice<char8>, _originIterator: UninitializedIterator) {}
_target: MutableSlice<char8>,
_originIterator: UninitializedIterator): void {}
InitializeFieldsFromIterator<char16, UninitializedIterator>(
_target: MutableSlice<char16>, _originIterator: UninitializedIterator) {}
_target: MutableSlice<char16>,
_originIterator: UninitializedIterator): void {}
extern macro IsDoubleHole(HeapObject, intptr): bool;
extern macro StoreDoubleHole(HeapObject, intptr);
extern macro StoreDoubleHole(HeapObject, intptr): void;
macro LoadFloat64OrHole(r:&float64_or_hole): float64_or_hole {
return float64_or_hole{
@ -267,7 +269,7 @@ macro LoadFloat64OrHole(r:&float64_or_hole): float64_or_hole {
value: *unsafe::NewReference<float64>(r.object, r.offset)
};
}
macro StoreFloat64OrHole(r:&float64_or_hole, value: float64_or_hole) {
macro StoreFloat64OrHole(r:&float64_or_hole, value: float64_or_hole): void {
if (value.is_hole) {
StoreDoubleHole(
%RawDownCast<HeapObject>(r.object), r.offset - kHeapObjectTag);
@ -297,12 +299,12 @@ macro DownCastForTorqueClass<T : type extends HeapObject>(o: HeapObject):
return %RawDownCast<T>(o);
}
extern macro StaticAssert(bool, constexpr string);
extern macro StaticAssert(bool, constexpr string): void;
// This is for the implementation of the dot operator. In any context where the
// dot operator is available, the correct way to get the length of an indexed
// field x from object o is `(&o.x).length`.
intrinsic %IndexedFieldLength<T: type>(o: T, f: constexpr string);
intrinsic %IndexedFieldLength<T: type>(o: T, f: constexpr string): intptr;
// If field x is defined as optional, then &o.x returns a reference to the field
// or crashes the program (unreachable) if the field is not present. Usually
@ -311,7 +313,8 @@ intrinsic %IndexedFieldLength<T: type>(o: T, f: constexpr string);
// optional field, which is either length zero or one depending on whether the
// field is present. This intrinsic provides Slices for both indexed fields
// (equivalent to &o.x) and optional fields.
intrinsic %FieldSlice<T: type>(o: T, f: constexpr string);
intrinsic %FieldSlice<T: type, TSlice: type>(
o: T, f: constexpr string): TSlice;
} // namespace torque_internal

View File

@ -12,7 +12,7 @@ extern macro TypedArrayBuiltinsAssembler::CallCCopyTypedArrayElementsSlice(
macro FastCopy(
src: typed_array::AttachedJSTypedArray, dest: JSTypedArray, k: uintptr,
count: uintptr) labels IfSlow {
count: uintptr): void labels IfSlow {
if (IsForceSlowPath()) goto IfSlow;
const srcKind: ElementsKind = src.elements_kind;
@ -48,7 +48,7 @@ macro FastCopy(
}
macro SlowCopy(implicit context: Context)(
src: JSTypedArray, dest: JSTypedArray, k: uintptr, final: uintptr) {
src: JSTypedArray, dest: JSTypedArray, k: uintptr, final: uintptr): void {
if (typed_array::IsBigInt64ElementsKind(src.elements_kind) !=
typed_array::IsBigInt64ElementsKind(dest.elements_kind))
deferred {

View File

@ -33,7 +33,7 @@ transitioning macro
TypedArrayMerge(
implicit context: Context, array: JSTypedArray, comparefn: Callable)(
source: FixedArray, from: uintptr, middle: uintptr, to: uintptr,
target: FixedArray) {
target: FixedArray): void {
let left: uintptr = from;
let right: uintptr = middle;

View File

@ -82,10 +82,10 @@ extern macro TypedArrayBuiltinsAssembler::IsBigInt64ElementsKind(ElementsKind):
extern macro LoadFixedTypedArrayElementAsTagged(
RawPtr, uintptr, constexpr ElementsKind): Numeric;
extern macro TypedArrayBuiltinsAssembler::StoreJSTypedArrayElementFromNumeric(
Context, JSTypedArray, uintptr, Numeric, constexpr ElementsKind);
Context, JSTypedArray, uintptr, Numeric, constexpr ElementsKind): void;
extern macro TypedArrayBuiltinsAssembler::StoreJSTypedArrayElementFromTagged(
Context, JSTypedArray, uintptr, JSAny, constexpr ElementsKind)
labels IfDetached;
Context, JSTypedArray, uintptr, JSAny,
constexpr ElementsKind): void labels IfDetached;
extern macro LoadJSTypedArrayLengthAndCheckDetached(JSTypedArray): uintptr
labels IfDetached;
@ -105,15 +105,16 @@ struct TypedArrayAccessor {
}
macro StoreNumeric(
context: Context, array: JSTypedArray, index: uintptr, value: Numeric) {
context: Context, array: JSTypedArray, index: uintptr,
value: Numeric): void {
const storefn: StoreNumericFn = this.storeNumericFn;
const result = storefn(context, array, index, value);
dcheck(result == kStoreSucceded);
}
macro StoreJSAny(
context: Context, array: JSTypedArray, index: uintptr, value: JSAny)
labels IfDetached {
context: Context, array: JSTypedArray, index: uintptr,
value: JSAny): void labels IfDetached {
const storefn: StoreJSAnyFn = this.storeJSAnyFn;
const result = storefn(context, array, index, value);
if (result == kStoreFailureArrayDetached) {
@ -194,7 +195,7 @@ struct AttachedJSTypedArrayWitness {
return this.stable;
}
macro Recheck() labels Detached {
macro Recheck(): void labels Detached {
if (IsDetachedBuffer(this.stable.buffer)) goto Detached;
this.unstable = %RawDownCast<AttachedJSTypedArray>(this.stable);
}

View File

@ -372,7 +372,7 @@ builtin WasmArrayCopyWithChecks(
// Redeclaration with different typing (value is an Object, not JSAny).
extern transitioning runtime
CreateDataProperty(implicit context: Context)(JSReceiver, JSAny, Object);
CreateDataProperty(implicit context: Context)(JSReceiver, JSAny, Object): void;
transitioning builtin WasmAllocateObjectWrapper(implicit context: Context)(
obj: Object): JSObject {

View File

@ -4,7 +4,8 @@
namespace runtime {
extern runtime JSWeakRefAddToKeptObjects(implicit context: Context)(JSReceiver);
extern runtime JSWeakRefAddToKeptObjects(implicit context: Context)(JSReceiver):
void;
} // namespace runtime

View File

@ -61,7 +61,8 @@ type Slot<Container : type extends Context, T : type extends Object> extends
// slot has the right type already.
macro InitContextSlot<
ArgumentContext: type, AnnotatedContext: type, T: type, U: type>(
context: ArgumentContext, index: Slot<AnnotatedContext, T>, value: U) {
context: ArgumentContext, index: Slot<AnnotatedContext, T>,
value: U): void {
// Make sure the arguments have the right type.
const context: AnnotatedContext = context;
const value: T = value;
@ -179,17 +180,17 @@ macro LoadContextElement(c: Context, i: constexpr int32): Object {
}
@export
macro StoreContextElement(c: Context, i: intptr, o: Object) {
macro StoreContextElement(c: Context, i: intptr, o: Object): void {
c.elements[i] = o;
}
@export
macro StoreContextElement(c: Context, i: Smi, o: Object) {
macro StoreContextElement(c: Context, i: Smi, o: Object): void {
c.elements[i] = o;
}
@export
macro StoreContextElement(c: Context, i: constexpr int32, o: Object) {
macro StoreContextElement(c: Context, i: constexpr int32, o: Object): void {
c.elements[i] = o;
}

View File

@ -86,10 +86,11 @@ extern operator '.floats[]=' macro StoreFixedDoubleArrayElement(
extern operator '.floats[]' macro LoadFixedDoubleArrayElement(
FixedDoubleArray, intptr): float64;
operator '[]=' macro StoreFixedDoubleArrayDirect(
a: FixedDoubleArray, i: Smi, v: Number) {
a: FixedDoubleArray, i: Smi, v: Number): void {
a.floats[i] = Convert<float64_or_hole>(Convert<float64>(v));
}
operator '[]=' macro StoreFixedArrayDirect(a: FixedArray, i: Smi, v: Object) {
operator '[]=' macro StoreFixedArrayDirect(
a: FixedArray, i: Smi, v: Object): void {
a.objects[i] = v;
}

View File

@ -187,7 +187,7 @@ struct FastJSArrayWitness {
return this.unstable;
}
macro Recheck() labels CastError {
macro Recheck(): void labels CastError {
if (this.stable.map != this.map) goto CastError;
// We don't need to check elements kind or whether the prototype
// has changed away from the default JSArray prototype, because
@ -210,7 +210,7 @@ struct FastJSArrayWitness {
}
}
macro StoreHole(k: Smi) {
macro StoreHole(k: Smi): void {
if (this.hasDoubles) {
const elements = Cast<FixedDoubleArray>(this.unstable.elements)
otherwise unreachable;
@ -230,18 +230,18 @@ struct FastJSArrayWitness {
}
}
macro EnsureArrayPushable(implicit context: Context)() labels Failed {
macro EnsureArrayPushable(implicit context: Context)(): void labels Failed {
EnsureArrayPushable(this.map) otherwise Failed;
array::EnsureWriteableFastElements(this.unstable);
this.arrayIsPushable = true;
}
macro ChangeLength(newLength: Smi) {
macro ChangeLength(newLength: Smi): void {
dcheck(this.arrayIsPushable);
this.unstable.length = newLength;
}
macro Push(value: JSAny) labels Failed {
macro Push(value: JSAny): void labels Failed {
dcheck(this.arrayIsPushable);
if (this.hasDoubles) {
BuildAppendJSArray(
@ -259,7 +259,7 @@ struct FastJSArrayWitness {
}
}
macro MoveElements(dst: intptr, src: intptr, length: intptr) {
macro MoveElements(dst: intptr, src: intptr, length: intptr): void {
dcheck(this.arrayIsPushable);
if (this.hasDoubles) {
const elements: FixedDoubleArray =
@ -303,7 +303,7 @@ struct FastJSArrayForReadWitness {
return this.unstable;
}
macro Recheck() labels CastError {
macro Recheck(): void labels CastError {
if (this.stable.map != this.map) goto CastError;
// We don't need to check elements kind or whether the prototype
// has changed away from the default JSArray prototype, because

View File

@ -177,8 +177,10 @@ macro AllocateSeqTwoByteString(length: uint32): SeqTwoByteString|EmptyString {
return AllocateSeqTwoByteString(length, UninitializedIterator{});
}
extern macro StringWriteToFlatOneByte(String, RawPtr<char8>, int32, int32);
extern macro StringWriteToFlatTwoByte(String, RawPtr<char16>, int32, int32);
extern macro StringWriteToFlatOneByte(
String, RawPtr<char8>, int32, int32): void;
extern macro StringWriteToFlatTwoByte(
String, RawPtr<char16>, int32, int32): void;
// Corresponds to String::SlowFlatten in the C++ runtime.
builtin StringSlowFlatten(cons: ConsString): String {

View File

@ -31,7 +31,7 @@ extern macro LoadSwissNameDictionaryCtrlTableGroup(intptr): uint64;
// Counterpart to swiss_table::ProbeSequence in C++ implementation.
struct ProbeSequence {
macro Next() {
macro Next(): void {
this.index = this.index + Unsigned(FromConstexpr<int32>(kGroupWidth));
this.offset = (this.offset + this.index) & this.mask;
}
@ -64,7 +64,7 @@ struct ByteMask {
}
// Counterpart to operator++() in C++ version.
macro ClearLowestSetBit() {
macro ClearLowestSetBit(): void {
this.mask = ClearLowestSetBit<uint64>(this.mask);
}
@ -83,7 +83,7 @@ struct BitMask {
}
// Counterpart to operator++() in C++ version.
macro ClearLowestSetBit() {
macro ClearLowestSetBit(): void {
this.mask = ClearLowestSetBit<uint32>(this.mask);
}

View File

@ -31,13 +31,13 @@ const kNotFoundSentinel:
extern macro LoadSwissNameDictionaryKey(SwissNameDictionary, intptr): Name;
extern macro StoreSwissNameDictionaryKeyAndValue(
SwissNameDictionary, intptr, Object, Object);
SwissNameDictionary, intptr, Object, Object): void;
extern macro SwissNameDictionarySetCtrl(
SwissNameDictionary, intptr, intptr, uint8);
SwissNameDictionary, intptr, intptr, uint8): void;
extern macro StoreSwissNameDictionaryPropertyDetails(
SwissNameDictionary, intptr, intptr, uint8);
SwissNameDictionary, intptr, intptr, uint8): void;
extern macro
SwissNameDictionaryIncreaseElementCountOrBailout(
@ -45,7 +45,7 @@ SwissNameDictionaryIncreaseElementCountOrBailout(
extern macro
StoreSwissNameDictionaryEnumToEntryMapping(
SwissNameDictionary, intptr, intptr, int32);
SwissNameDictionary, intptr, intptr, int32): void;
extern macro
SwissNameDictionaryUpdateCountsForDeletion(ByteArray, intptr): uint32;
@ -214,8 +214,7 @@ macro FindFirstEmpty<GroupLoader: type>(
macro Add<GroupLoader: type>(
table: SwissNameDictionary, key: Name, value: Object,
propertyDetails: uint8)
labels Bailout {
propertyDetails: uint8): void labels Bailout {
const capacity: intptr = Convert<intptr>(table.capacity);
const maxUsable: uint32 =
Unsigned(Convert<int32>(SwissNameDictionaryMaxUsableCapacity(capacity)));
@ -249,9 +248,8 @@ macro Add<GroupLoader: type>(
}
@export
macro SwissNameDictionaryDelete(table: SwissNameDictionary, entry: intptr)
labels
Shrunk(SwissNameDictionary) {
macro SwissNameDictionaryDelete(table: SwissNameDictionary, entry: intptr):
void labels Shrunk(SwissNameDictionary) {
const capacity = Convert<intptr>(table.capacity);
// Update present and deleted element counts at once, without needing to do
@ -304,7 +302,7 @@ Found(intptr),
@export
macro SwissNameDictionaryAddSIMD(
table: SwissNameDictionary, key: Name, value: Object,
propertyDetails: uint8) labels Bailout {
propertyDetails: uint8): void labels Bailout {
Add<GroupSse2Loader>(table, key, value, propertyDetails)
otherwise Bailout;
}
@ -312,7 +310,7 @@ macro SwissNameDictionaryAddSIMD(
@export
macro SwissNameDictionaryAddPortable(
table: SwissNameDictionary, key: Name, value: Object,
propertyDetails: uint8) labels Bailout {
propertyDetails: uint8): void labels Bailout {
Add<GroupPortableLoader>(table, key, value, propertyDetails)
otherwise Bailout;
}

View File

@ -3107,10 +3107,20 @@ VisitResult ImplementationVisitor::GenerateCall(
const Type* type = specialization_types[0];
const ClassType* class_type = ClassType::DynamicCast(type);
if (!class_type) {
ReportError("%FieldSlice must take a class type parameter");
ReportError("The first type parameter to %FieldSlice must be a class");
}
const Field& field =
class_type->LookupField(StringLiteralUnquote(constexpr_arguments[0]));
const Type* expected_slice_type =
field.const_qualified
? TypeOracle::GetConstSliceType(field.name_and_type.type)
: TypeOracle::GetMutableSliceType(field.name_and_type.type);
const Type* declared_slice_type = specialization_types[1];
if (expected_slice_type != declared_slice_type) {
Error(
"The second type parameter to %FieldSlice must be the precise "
"slice type for the named field");
}
LocationReference ref = GenerateFieldReference(
VisitResult(type, argument_range), field, class_type,
/*treat_optional_as_indexed=*/true);

View File

@ -523,13 +523,6 @@ base::Optional<ParseResult> MakeDebugStatement(
return ParseResult{result};
}
base::Optional<ParseResult> MakeVoidType(ParseResultIterator* child_results) {
TypeExpression* result = MakeNode<BasicTypeExpression>(
std::vector<std::string>{}, MakeNode<Identifier>("void"),
std::vector<TypeExpression*>{});
return ParseResult{result};
}
base::Optional<ParseResult> MakeExternalMacro(
ParseResultIterator* child_results) {
auto transitioning = child_results->NextAs<bool>();
@ -2269,10 +2262,6 @@ struct TorqueGrammar : Grammar {
TryOrDefault<TypeList>(Sequence({Token("("), typeList, Token(")")}))},
MakeLabelAndTypes)};
// Result: TypeExpression*
Symbol optionalReturnType = {Rule({Token(":"), &type}),
Rule({}, MakeVoidType)};
// Result: LabelAndTypesVector
Symbol* optionalLabelList{TryOrDefault<LabelAndTypesVector>(
Sequence({Token("labels"),
@ -2580,7 +2569,7 @@ struct TorqueGrammar : Grammar {
Symbol method = {Rule(
{CheckIf(Token("transitioning")),
Optional<std::string>(Sequence({Token("operator"), &externalString})),
Token("macro"), &name, &parameterListNoVararg, &optionalReturnType,
Token("macro"), &name, &parameterListNoVararg, Token(":"), &type,
optionalLabelList, &block},
MakeMethodDeclaration)};
@ -2627,7 +2616,7 @@ struct TorqueGrammar : Grammar {
AsSingletonVector<Declaration*, MakeTypeAliasDeclaration>()),
Rule({Token("intrinsic"), &intrinsicName,
TryOrDefault<GenericParameters>(&genericParameters),
&parameterListNoVararg, &optionalReturnType, &optionalBody},
&parameterListNoVararg, Token(":"), &type, &optionalBody},
AsSingletonVector<Declaration*, MakeIntrinsicDeclaration>()),
Rule({Token("extern"), CheckIf(Token("transitioning")),
Optional<std::string>(
@ -2635,33 +2624,33 @@ struct TorqueGrammar : Grammar {
Token("macro"),
Optional<std::string>(Sequence({&identifier, Token("::")})), &name,
TryOrDefault<GenericParameters>(&genericParameters),
&typeListMaybeVarArgs, &optionalReturnType, optionalLabelList,
&typeListMaybeVarArgs, Token(":"), &type, optionalLabelList,
Token(";")},
AsSingletonVector<Declaration*, MakeExternalMacro>()),
Rule({Token("extern"), CheckIf(Token("transitioning")),
CheckIf(Token("javascript")), Token("builtin"), &name,
TryOrDefault<GenericParameters>(&genericParameters),
&typeListMaybeVarArgs, &optionalReturnType, Token(";")},
&typeListMaybeVarArgs, Token(":"), &type, Token(";")},
AsSingletonVector<Declaration*, MakeExternalBuiltin>()),
Rule({Token("extern"), CheckIf(Token("transitioning")), Token("runtime"),
&name, &typeListMaybeVarArgs, &optionalReturnType, Token(";")},
&name, &typeListMaybeVarArgs, Token(":"), &type, Token(";")},
AsSingletonVector<Declaration*, MakeExternalRuntime>()),
Rule({annotations, CheckIf(Token("transitioning")),
Optional<std::string>(
Sequence({Token("operator"), &externalString})),
Token("macro"), &name,
TryOrDefault<GenericParameters>(&genericParameters),
&parameterListNoVararg, &optionalReturnType, optionalLabelList,
&parameterListNoVararg, Token(":"), &type, optionalLabelList,
&optionalBody},
AsSingletonVector<Declaration*, MakeTorqueMacroDeclaration>()),
Rule({CheckIf(Token("transitioning")), CheckIf(Token("javascript")),
Token("builtin"), &name,
TryOrDefault<GenericParameters>(&genericParameters),
&parameterListAllowVararg, &optionalReturnType, &optionalBody},
&parameterListAllowVararg, Token(":"), &type, &optionalBody},
AsSingletonVector<Declaration*, MakeTorqueBuiltinDeclaration>()),
Rule({CheckIf(Token("transitioning")), &name,
&genericSpecializationTypeList, &parameterListAllowVararg,
&optionalReturnType, optionalLabelList, &block},
Token(":"), &type, optionalLabelList, &block},
AsSingletonVector<Declaration*, MakeSpecializationDeclaration>()),
Rule({Token("#include"), &externalString},
AsSingletonVector<Declaration*, MakeCppIncludeDeclaration>()),

View File

@ -818,10 +818,10 @@ void ClassType::GenerateSliceAccessor(size_t field_index) {
// );
// }
//
// If the field has an unknown offset, and the previous field is named p, and
// an item in the previous field has size 4:
// If the field has an unknown offset, and the previous field is named p, is
// not const, and is of type PType with size 4:
// FieldSliceClassNameFieldName(o: ClassName) {
// const previous = %FieldSlice<ClassName>(o, "p");
// const previous = %FieldSlice<ClassName, MutableSlice<PType>>(o, "p");
// return torque_internal::unsafe::New{Const,Mutable}Slice<FieldType>(
// /*object:*/ o,
// /*offset:*/ previous.offset + 4 * previous.length,
@ -853,14 +853,21 @@ void ClassType::GenerateSliceAccessor(size_t field_index) {
const Field* previous = GetFieldPreceding(field_index);
DCHECK_NOT_NULL(previous);
// %FieldSlice<ClassName>(o, "p")
const Type* previous_slice_type =
previous->const_qualified
? TypeOracle::GetConstSliceType(previous->name_and_type.type)
: TypeOracle::GetMutableSliceType(previous->name_and_type.type);
// %FieldSlice<ClassName, MutableSlice<PType>>(o, "p")
Expression* previous_expression = MakeCallExpression(
MakeIdentifierExpression({"torque_internal"}, "%FieldSlice",
{MakeNode<PrecomputedTypeExpression>(this)}),
MakeIdentifierExpression(
{"torque_internal"}, "%FieldSlice",
{MakeNode<PrecomputedTypeExpression>(this),
MakeNode<PrecomputedTypeExpression>(previous_slice_type)}),
{parameter, MakeNode<StringLiteralExpression>(
StringLiteralQuote(previous->name_and_type.name))});
// const previous = %FieldSlice<ClassName>(o, "p");
// const previous = %FieldSlice<ClassName, MutableSlice<PType>>(o, "p");
Statement* define_previous =
MakeConstDeclarationStatement("previous", previous_expression);
statements.push_back(define_previous);

View File

@ -40,20 +40,20 @@ macro LabelTestHelper3(): never
}
@export
macro TestConstexpr1() {
macro TestConstexpr1(): void {
check(FromConstexpr<bool>(
IsFastElementsKind(ElementsKind::PACKED_SMI_ELEMENTS)));
}
@export
macro TestConstexprIf() {
macro TestConstexprIf(): void {
check(ElementsKindTestHelper1(ElementsKind::UINT8_ELEMENTS));
check(ElementsKindTestHelper1(ElementsKind::UINT16_ELEMENTS));
check(!ElementsKindTestHelper1(ElementsKind::UINT32_ELEMENTS));
}
@export
macro TestConstexprReturn() {
macro TestConstexprReturn(): void {
check(FromConstexpr<bool>(
ElementsKindTestHelper2(ElementsKind::UINT8_ELEMENTS)));
check(FromConstexpr<bool>(
@ -103,7 +103,7 @@ GenericBuiltinTest<JSAny>(param: JSAny): JSAny {
}
@export
macro TestBuiltinSpecialization() {
macro TestBuiltinSpecialization(): void {
check(GenericBuiltinTest<Smi>(0) == Null);
check(GenericBuiltinTest<Smi>(1) == Null);
check(GenericBuiltinTest<JSAny>(Undefined) == Undefined);
@ -160,7 +160,7 @@ GenericMacroTestWithLabels<Object>(param2: Object): Object
}
@export
macro TestMacroSpecialization() {
macro TestMacroSpecialization(): void {
try {
const _smi0: Smi = 0;
check(GenericMacroTest<Smi>(0) == Undefined);
@ -208,7 +208,7 @@ macro TestTernaryOperator(x: Smi): Smi {
}
@export
macro TestFunctionPointerToGeneric() {
macro TestFunctionPointerToGeneric(): void {
const fptr1: builtin(Smi) => JSAny = GenericBuiltinTest<Smi>;
const fptr2: builtin(JSAny) => JSAny = GenericBuiltinTest<JSAny>;
@ -236,19 +236,19 @@ macro TestUnsafeCast(implicit context: Context)(n: Number): Boolean {
}
@export
macro TestHexLiteral() {
macro TestHexLiteral(): void {
check(Convert<intptr>(0xffff) + 1 == 0x10000);
check(Convert<intptr>(-0xffff) == -65535);
}
@export
macro TestLargeIntegerLiterals(implicit c: Context)() {
macro TestLargeIntegerLiterals(implicit c: Context)(): void {
let _x: int32 = 0x40000000;
let _y: int32 = 0x7fffffff;
}
@export
macro TestMultilineAssert() {
macro TestMultilineAssert(): void {
const someVeryLongVariableNameThatWillCauseLineBreaks: Smi = 5;
check(
someVeryLongVariableNameThatWillCauseLineBreaks > 0 &&
@ -256,7 +256,7 @@ macro TestMultilineAssert() {
}
@export
macro TestNewlineInString() {
macro TestNewlineInString(): void {
Print('Hello, World!\n');
}
@ -265,14 +265,14 @@ const kIntptrConst: intptr = 4;
const kSmiConst: Smi = 3;
@export
macro TestModuleConstBindings() {
macro TestModuleConstBindings(): void {
check(kConstexprConst == Int32Constant(5));
check(kIntptrConst == 4);
check(kSmiConst == 3);
}
@export
macro TestLocalConstBindings() {
macro TestLocalConstBindings(): void {
const x: constexpr int31 = 3;
const xSmi: Smi = x;
{
@ -347,7 +347,7 @@ Foo(TestStructA) {
goto Foo(TestStruct2());
}
@export // Silence unused warning.
macro CallTestStructInLabel(implicit context: Context)() {
macro CallTestStructInLabel(implicit context: Context)(): void {
try {
TestStructInLabel() otherwise Foo;
} label Foo(_s: TestStructA) {}
@ -356,7 +356,7 @@ macro CallTestStructInLabel(implicit context: Context)() {
// This macro tests different versions of the for-loop where some parts
// are (not) present.
@export
macro TestForLoop() {
macro TestForLoop(): void {
let sum: Smi = 0;
for (let i: Smi = 0; i < 5; ++i) sum += i;
check(sum == 10);
@ -455,7 +455,7 @@ macro TestForLoop() {
}
@export
macro TestSubtyping(x: Smi) {
macro TestSubtyping(x: Smi): void {
const _foo: JSAny = x;
}
@ -501,7 +501,7 @@ macro TypeswitchExample(implicit context: Context)(x: NumberOrFixedArray):
}
@export
macro TestTypeswitch(implicit context: Context)() {
macro TestTypeswitch(implicit context: Context)(): void {
check(TypeswitchExample(FromConstexpr<Smi>(5)) == 26);
const a: FixedArray = AllocateZeroedFixedArray(3);
check(TypeswitchExample(a) == 13);
@ -509,7 +509,8 @@ macro TestTypeswitch(implicit context: Context)() {
}
@export
macro TestTypeswitchAsanLsanFailure(implicit context: Context)(obj: Object) {
macro TestTypeswitchAsanLsanFailure(implicit context: Context)(obj: Object):
void {
typeswitch (obj) {
case (_o: Smi): {
}
@ -530,7 +531,7 @@ macro ExampleGenericOverload<A: type>(o: Smi): A {
}
@export
macro TestGenericOverload(implicit context: Context)() {
macro TestGenericOverload(implicit context: Context)(): void {
const xSmi: Smi = 5;
const xObject: Object = xSmi;
check(ExampleGenericOverload<Smi>(xSmi) == 6);
@ -538,7 +539,7 @@ macro TestGenericOverload(implicit context: Context)() {
}
@export
macro TestEquality(implicit context: Context)() {
macro TestEquality(implicit context: Context)(): void {
const notEqual: bool =
AllocateHeapNumberWithValue(0.5) != AllocateHeapNumberWithValue(0.5);
check(!notEqual);
@ -558,7 +559,7 @@ macro TestAndOr(x: bool, y: bool, z: bool): bool {
}
@export
macro TestLogicalOperators() {
macro TestLogicalOperators(): void {
check(TestAndOr(true, true, true));
check(TestAndOr(true, true, false));
check(TestAndOr(true, false, true));
@ -584,7 +585,7 @@ macro TestCall(i: Smi): Smi labels A {
}
@export
macro TestOtherwiseWithCode1() {
macro TestOtherwiseWithCode1(): void {
let v: Smi = 0;
let s: Smi = 1;
try {
@ -596,7 +597,7 @@ macro TestOtherwiseWithCode1() {
}
@export
macro TestOtherwiseWithCode2() {
macro TestOtherwiseWithCode2(): void {
let s: Smi = 0;
for (let i: Smi = 0; i < 10; ++i) {
TestCall(i) otherwise break;
@ -606,7 +607,7 @@ macro TestOtherwiseWithCode2() {
}
@export
macro TestOtherwiseWithCode3() {
macro TestOtherwiseWithCode3(): void {
let s: Smi = 0;
for (let i: Smi = 0; i < 10; ++i) {
s += TestCall(i) otherwise break;
@ -615,7 +616,7 @@ macro TestOtherwiseWithCode3() {
}
@export
macro TestForwardLabel() {
macro TestForwardLabel(): void {
try {
goto A;
} label A {
@ -626,7 +627,7 @@ macro TestForwardLabel() {
}
@export
macro TestQualifiedAccess(implicit context: Context)() {
macro TestQualifiedAccess(implicit context: Context)(): void {
const s: Smi = 0;
check(!Is<JSArray>(s));
}
@ -683,7 +684,7 @@ macro TestCatch3(implicit context: Context)(): Smi {
// iterator.tq.
@export
transitioning macro TestIterator(implicit context: Context)(
o: JSReceiver, map: Map) {
o: JSReceiver, map: Map): void {
try {
const t1: JSAny = iterator::GetIteratorMethod(o);
const t2: iterator::IteratorRecord = iterator::GetIterator(o);
@ -701,7 +702,7 @@ transitioning macro TestIterator(implicit context: Context)(
}
@export
macro TestFrame1(implicit context: Context)() {
macro TestFrame1(implicit context: Context)(): void {
const f: Frame = LoadFramePointer();
const frameType: FrameType =
Cast<FrameType>(f.context_or_frame_type) otherwise unreachable;
@ -717,14 +718,14 @@ macro TestFrame1(implicit context: Context)() {
}
@export
macro TestNew(implicit context: Context)() {
macro TestNew(implicit context: Context)(): void {
const f: JSArray = NewJSArray();
check(f.IsEmpty());
f.length = 0;
}
struct TestInner {
macro SetX(newValue: int32) {
macro SetX(newValue: int32): void {
this.x = newValue;
}
macro GetX(): int32 {
@ -741,7 +742,7 @@ struct TestOuter {
}
@export
macro TestStructConstructor(implicit context: Context)() {
macro TestStructConstructor(implicit context: Context)(): void {
// Test default constructor
let a: TestOuter = TestOuter{a: 5, b: TestInner{x: 6, y: 7}, c: 8};
check(a.a == 5);
@ -756,7 +757,7 @@ macro TestStructConstructor(implicit context: Context)() {
}
class InternalClass extends HeapObject {
macro Flip() labels NotASmi {
macro Flip(): void labels NotASmi {
const tmp = Cast<Smi>(this.b) otherwise NotASmi;
this.b = this.a;
this.a = tmp;
@ -770,7 +771,7 @@ macro NewInternalClass(x: Smi): InternalClass {
}
@export
macro TestInternalClass(implicit context: Context)() {
macro TestInternalClass(implicit context: Context)(): void {
const o = NewInternalClass(5);
o.Flip() otherwise unreachable;
check(o.a == 6);
@ -789,7 +790,7 @@ struct StructWithConst {
}
@export
macro TestConstInStructs() {
macro TestConstInStructs(): void {
const x = StructWithConst{a: Null, b: 1};
let y = StructWithConst{a: Null, b: 1};
y.a = Undefined;
@ -800,7 +801,7 @@ macro TestConstInStructs() {
}
@export
macro TestParentFrameArguments(implicit context: Context)() {
macro TestParentFrameArguments(implicit context: Context)(): void {
const parentFrame = LoadParentFramePointer();
const castFrame = Cast<StandardFrame>(parentFrame) otherwise unreachable;
const arguments = GetFrameArguments(castFrame, 1);
@ -829,14 +830,14 @@ class SmiPair extends HeapObject {
b: Smi;
}
macro Swap<T: type>(a:&T, b:&T) {
macro Swap<T: type>(a:&T, b:&T): void {
const tmp = *a;
*a = *b;
*b = tmp;
}
@export
macro TestReferences() {
macro TestReferences(): void {
const array = new SmiPair{a: 7, b: 2};
const ref:&Smi = &array.a;
*ref = 3 + *ref;
@ -847,7 +848,7 @@ macro TestReferences() {
}
@export
macro TestSlices() {
macro TestSlices(): void {
const it = TestIterator{count: 3};
const a = new FixedArray{map: kFixedArrayMap, length: 3, objects: ...it};
check(a.length == 3);
@ -904,7 +905,7 @@ macro TestSliceEnumeration(implicit context: Context)(): Undefined {
}
@export
macro TestStaticAssert() {
macro TestStaticAssert(): void {
static_assert(1 + 2 == 3);
static_assert(Convert<uintptr>(5) < Convert<uintptr>(6));
@ -932,7 +933,7 @@ builtin NewSmiBox(implicit context: Context)(value: Smi): SmiBox {
}
@export
macro TestLoadEliminationFixed(implicit context: Context)() {
macro TestLoadEliminationFixed(implicit context: Context)(): void {
const box = NewSmiBox(123);
const v1 = box.value;
box.unrelated = 999;
@ -946,7 +947,7 @@ macro TestLoadEliminationFixed(implicit context: Context)() {
}
@export
macro TestLoadEliminationVariable(implicit context: Context)() {
macro TestLoadEliminationVariable(implicit context: Context)(): void {
const a = UnsafeCast<FixedArray>(kEmptyFixedArray);
const box = NewSmiBox(1);
const v1 = a.objects[box.value];
@ -1035,7 +1036,8 @@ macro BranchAndWriteResult(x: Smi, box: SmiBox): bool {
}
@export
macro TestBranchOnBoolOptimization(implicit context: Context)(input: Smi) {
macro TestBranchOnBoolOptimization(implicit context: Context)(input: Smi):
void {
const box = NewSmiBox(1);
// If the two branches get combined into one, we should be able to determine
// the value of {box} statically.
@ -1056,7 +1058,7 @@ bitfield struct TestBitFieldStruct extends uint8 {
@export
macro TestBitFieldLoad(
val: TestBitFieldStruct, expectedA: bool, expectedB: uint16,
expectedC: uint32, expectedD: bool) {
expectedC: uint32, expectedD: bool): void {
check(val.a == expectedA);
check(val.b == expectedB);
check(val.c == expectedC);
@ -1064,7 +1066,7 @@ macro TestBitFieldLoad(
}
@export
macro TestBitFieldStore(val: TestBitFieldStruct) {
macro TestBitFieldStore(val: TestBitFieldStruct): void {
let val: TestBitFieldStruct = val; // Get a mutable local copy.
const a: bool = val.a;
const b: uint16 = val.b;
@ -1083,7 +1085,7 @@ macro TestBitFieldStore(val: TestBitFieldStruct) {
}
@export
macro TestBitFieldInit(a: bool, b: uint16, c: uint32, d: bool) {
macro TestBitFieldInit(a: bool, b: uint16, c: uint32, d: bool): void {
const val: TestBitFieldStruct = TestBitFieldStruct{a: a, b: b, c: c, d: d};
TestBitFieldLoad(val, a, b, c, d);
}
@ -1102,7 +1104,7 @@ bitfield struct TestBitFieldStruct3 extends uintptr {
@export
macro TestBitFieldUintptrOps(
val2: TestBitFieldStruct2, val3: TestBitFieldStruct3) {
val2: TestBitFieldStruct2, val3: TestBitFieldStruct3): void {
let val2: TestBitFieldStruct2 = val2; // Get a mutable local copy.
let val3: TestBitFieldStruct3 = val3; // Get a mutable local copy.
@ -1142,7 +1144,7 @@ bitfield struct TestBitFieldStruct5 extends uint31 {
}
@export
macro TestBitFieldMultipleFlags(a: bool, b: int32, c: bool) {
macro TestBitFieldMultipleFlags(a: bool, b: int32, c: bool): void {
const f = TestBitFieldStruct4{a: a, b: b, c: c};
let simpleExpression = f.a & f.b == 3 & !f.c;
let expectedReduction = (Signed(f) & 0x1f) == Convert<int32>(1 | 3 << 1);
@ -1222,7 +1224,7 @@ struct InternalClassStructElementGeneratorIterator {
}
@export
macro TestFullyGeneratedClassWithElements() {
macro TestFullyGeneratedClassWithElements(): void {
// Test creation, initialization and access of a fully generated class with
// simple (Smi) elements
const length: Smi = Convert<Smi>(3);
@ -1285,7 +1287,7 @@ class ExportedSubClass2 extends ExportedSubClassBase {
}
@export
macro TestGeneratedCastOperators(implicit context: Context)() {
macro TestGeneratedCastOperators(implicit context: Context)(): void {
const a = new
ExportedSubClass{a: Null, b: Null, c_field: 3, d_field: 4, e_field: 5};
const b = new ExportedSubClassBase{a: Undefined, b: Null};
@ -1319,14 +1321,14 @@ extern runtime InYoungGeneration(implicit context: Context)(HeapObject):
Boolean;
@export
macro TestNewPretenured(implicit context: Context)() {
macro TestNewPretenured(implicit context: Context)(): void {
const obj = new (Pretenured) ExportedSubClassBase{a: Undefined, b: Null};
dcheck(Is<ExportedSubClassBase>(obj));
dcheck(InYoungGeneration(obj) == False);
}
@export
macro TestWord8Phi() {
macro TestWord8Phi(): void {
for (let i: intptr = -5; i < 5; ++i) {
let x: int8;
if (i == -1) {
@ -1339,7 +1341,7 @@ macro TestWord8Phi() {
}
@export
macro TestOffHeapSlice(ptr: RawPtr<char8>, length: intptr) {
macro TestOffHeapSlice(ptr: RawPtr<char8>, length: intptr): void {
const string = UnsafeCast<SeqOneByteString>(Convert<String>('Hello World!'));
check(*torque_internal::unsafe::NewOffHeapReference(ptr) == string.chars[0]);
@ -1362,7 +1364,7 @@ builtin ReturnTwoValues(implicit context: Context)(
}
@export
macro TestCallMultiReturnBuiltin(implicit context: Context)() {
macro TestCallMultiReturnBuiltin(implicit context: Context)(): void {
const result = ReturnTwoValues(444, FromConstexpr<String>('hi'));
check(result.a == 445);
check(result.b == FromConstexpr<String>('hi').map);
@ -1388,7 +1390,7 @@ macro AddSmiAndConstexprValues(a: Smi, b: constexpr int31): Smi {
}
@export
macro TestCreateLazyNodeFromTorque() {
macro TestCreateLazyNodeFromTorque(): void {
const lazy = %MakeLazy<Smi>('GetLazySmi');
const result = TestRunLazyTwice(lazy);
check(result == 6);

View File

@ -100,7 +100,7 @@ TEST(LanguageServer, GotoLabelDefinitionInSignature) {
"macro Foo(): never labels Fail {\n"
" goto Fail;\n"
"}\n"
"macro Bar() labels Bailout {\n"
"macro Bar(): void labels Bailout {\n"
" Foo() otherwise Bailout;\n"
"}\n";
@ -113,8 +113,8 @@ TEST(LanguageServer, GotoLabelDefinitionInSignature) {
id, LineAndColumn::WithUnknownOffset(6, 18));
ASSERT_TRUE(maybe_position.has_value());
EXPECT_EQ(*maybe_position,
(SourcePosition{id, LineAndColumn::WithUnknownOffset(5, 19),
LineAndColumn::WithUnknownOffset(5, 26)}));
(SourcePosition{id, LineAndColumn::WithUnknownOffset(5, 25),
LineAndColumn::WithUnknownOffset(5, 32)}));
}
#endif
@ -125,7 +125,7 @@ TEST(LanguageServer, GotoLabelDefinitionInTryBlock) {
"macro Foo(): never labels Fail {\n"
" goto Fail;\n"
"}\n"
"macro Bar() {\n"
"macro Bar(): void {\n"
" try { Foo() otherwise Bailout; }\n"
" label Bailout {}\n"
"}\n";
@ -193,7 +193,7 @@ TEST(LanguageServer, GotoLabelDefinitionInTryBlockGoto) {
const std::string source =
"type void;\n"
"type never;\n"
"macro Bar() {\n"
"macro Bar(): void {\n"
" try { goto Bailout; }\n"
" label Bailout {}\n"
"}\n";
@ -218,7 +218,7 @@ TEST(LanguageServer, GotoLabelDefinitionGotoInOtherwise) {
"macro Foo(): never labels Fail {\n"
" goto Fail;\n"
"}\n"
"macro Bar() {\n"
"macro Bar(): void {\n"
" try { Foo() otherwise goto Bailout; }\n"
" label Bailout {}\n"
"}\n";

View File

@ -276,7 +276,7 @@ TEST(Torque, ClassDefinition) {
@export
macro TestClassWithAllTypesLoadsAndStores(
t: TestClassWithAllTypes, r: RawPtr, v1: int8, v2: uint8, v3: int16,
v4: uint16, v5: int32, v6: uint32, v7: intptr, v8: uintptr) {
v4: uint16, v5: int32, v6: uint32, v7: intptr, v8: uintptr): void {
t.a = v1;
t.b = v2;
t.c = v3;
@ -355,7 +355,7 @@ TEST(Torque, ConditionalFields) {
TEST(Torque, ConstexprLetBindingDoesNotCrash) {
ExpectFailingCompilation(
R"(@export macro FooBar() { let foo = 0; check(foo >= 0); })",
R"(@export macro FooBar(): void { let foo = 0; check(foo >= 0); })",
HasSubstr("Use 'const' instead of 'let' for variable 'foo'"));
}
@ -366,10 +366,10 @@ TEST(Torque, FailedImplicitCastFromConstexprDoesNotCrash) {
kValue,
...
}
macro Foo() {
macro Foo(): void {
Bar(SomeEnum::kValue);
}
macro Bar<T: type>(value: T) {}
macro Bar<T: type>(value: T): void {}
)",
HasSubstr(
"Cannot find non-constexpr type corresponding to constexpr kValue"));
@ -377,7 +377,7 @@ TEST(Torque, FailedImplicitCastFromConstexprDoesNotCrash) {
TEST(Torque, DoubleUnderScorePrefixIllegalForIdentifiers) {
ExpectFailingCompilation(R"(
@export macro Foo() {
@export macro Foo(): void {
let __x;
}
)",
@ -387,7 +387,7 @@ TEST(Torque, DoubleUnderScorePrefixIllegalForIdentifiers) {
TEST(Torque, UnusedLetBindingLintError) {
ExpectFailingCompilation(R"(
@export macro Foo(y: Smi) {
@export macro Foo(y: Smi): void {
let x: Smi = y;
}
)",
@ -396,7 +396,7 @@ TEST(Torque, UnusedLetBindingLintError) {
TEST(Torque, UnderscorePrefixSilencesUnusedWarning) {
ExpectSuccessfulCompilation(R"(
@export macro Foo(y: Smi) {
@export macro Foo(y: Smi): void {
let _x: Smi = y;
}
)");
@ -408,7 +408,7 @@ TEST(Torque, UnderscorePrefixSilencesUnusedWarning) {
#if !defined(V8_TARGET_OS_FUCHSIA)
TEST(Torque, UsingUnderscorePrefixedIdentifierError) {
ExpectFailingCompilation(R"(
@export macro Foo(y: Smi) {
@export macro Foo(y: Smi): void {
let _x: Smi = y;
check(_x == y);
}
@ -419,39 +419,39 @@ TEST(Torque, UsingUnderscorePrefixedIdentifierError) {
TEST(Torque, UnusedArgumentLintError) {
ExpectFailingCompilation(R"(
@export macro Foo(x: Smi) {}
@export macro Foo(x: Smi): void {}
)",
HasSubstr("Variable 'x' is never used."));
}
TEST(Torque, UsingUnderscorePrefixedArgumentSilencesWarning) {
ExpectSuccessfulCompilation(R"(
@export macro Foo(_y: Smi) {}
@export macro Foo(_y: Smi): void {}
)");
}
TEST(Torque, UnusedLabelLintError) {
ExpectFailingCompilation(R"(
@export macro Foo() labels Bar {}
@export macro Foo(): void labels Bar {}
)",
HasSubstr("Label 'Bar' is never used."));
}
TEST(Torque, UsingUnderScorePrefixLabelSilencesWarning) {
ExpectSuccessfulCompilation(R"(
@export macro Foo() labels _Bar {}
@export macro Foo(): void labels _Bar {}
)");
}
TEST(Torque, NoUnusedWarningForImplicitArguments) {
ExpectSuccessfulCompilation(R"(
@export macro Foo(implicit c: Context, r: JSReceiver)() {}
@export macro Foo(implicit c: Context, r: JSReceiver)(): void {}
)");
}
TEST(Torque, NoUnusedWarningForVariablesOnlyUsedInDchecks) {
ExpectSuccessfulCompilation(R"(
@export macro Foo(x: bool) {
@export macro Foo(x: bool): void {
dcheck(x);
}
)");
@ -493,12 +493,12 @@ TEST(Torque, LetShouldBeConstIsSkippedForStructs) {
TEST(Torque, GenericAbstractType) {
ExpectSuccessfulCompilation(R"(
type Foo<T: type> extends HeapObject;
extern macro F1(HeapObject);
macro F2<T: type>(x: Foo<T>) {
extern macro F1(HeapObject): void;
macro F2<T: type>(x: Foo<T>): void {
F1(x);
}
@export
macro F3(a: Foo<Smi>, b: Foo<HeapObject>){
macro F3(a: Foo<Smi>, b: Foo<HeapObject>): void {
F2(a);
F2(b);
}
@ -506,18 +506,18 @@ TEST(Torque, GenericAbstractType) {
ExpectFailingCompilation(R"(
type Foo<T: type> extends HeapObject;
macro F1<T: type>(x: Foo<T>) {}
macro F1<T: type>(x: Foo<T>): void {}
@export
macro F2(a: Foo<Smi>) {
macro F2(a: Foo<Smi>): void {
F1<HeapObject>(a);
})",
HasSubstr("cannot find suitable callable"));
ExpectFailingCompilation(R"(
type Foo<T: type> extends HeapObject;
extern macro F1(Foo<HeapObject>);
extern macro F1(Foo<HeapObject>): void;
@export
macro F2(a: Foo<Smi>) {
macro F2(a: Foo<Smi>): void {
F1(a);
})",
HasSubstr("cannot find suitable callable"));
@ -526,14 +526,14 @@ TEST(Torque, GenericAbstractType) {
TEST(Torque, SpecializationRequesters) {
ExpectFailingCompilation(
R"(
macro A<T: type extends HeapObject>() {}
macro B<T: type>() {
macro A<T: type extends HeapObject>(): void {}
macro B<T: type>(): void {
A<T>();
}
macro C<T: type>() {
macro C<T: type>(): void {
B<T>();
}
macro D() {
macro D(): void {
C<Smi>();
}
)",
@ -586,16 +586,16 @@ TEST(Torque, SpecializationRequesters) {
ExpectFailingCompilation(
R"(
macro A<T: type extends HeapObject>() {}
macro B<T: type>() {
macro A<T: type extends HeapObject>(): void {}
macro B<T: type>(): void {
A<T>();
}
struct C<T: type> {
macro Method() {
macro Method(): void {
B<T>();
}
}
macro D(_b: C<Smi>) {}
macro D(_b: C<Smi>): void {}
)",
SubstrVector{
SubstrTester("cannot find suitable callable", 4, 7),
@ -691,7 +691,7 @@ TEST(Torque, EnumTypeAnnotations) {
kValue2: Type2,
kValue3
}
@export macro Foo() {
@export macro Foo(): void {
const _a: Type1 = MyEnum::kValue1;
const _b: Type2 = MyEnum::kValue2;
const _c: intptr = MyEnum::kValue3;
@ -707,7 +707,7 @@ TEST(Torque, ConstClassFields) {
}
@export
macro Test(implicit context: Context)(o: Foo, n: int32) {
macro Test(implicit context: Context)(o: Foo, n: int32): void {
const _x: int32 = o.x;
o.y = n;
}
@ -719,7 +719,7 @@ TEST(Torque, ConstClassFields) {
}
@export
macro Test(implicit context: Context)(o: Foo, n: int32) {
macro Test(implicit context: Context)(o: Foo, n: int32): void {
o.x = n;
}
)",
@ -735,7 +735,7 @@ TEST(Torque, ConstClassFields) {
}
@export
macro Test(implicit context: Context)(o: Foo, n: int32) {
macro Test(implicit context: Context)(o: Foo, n: int32): void {
const _x: int32 = o.s.x;
// Assigning a struct as a value is OK, even when the struct contains
// const fields.
@ -754,7 +754,7 @@ TEST(Torque, ConstClassFields) {
}
@export
macro Test(implicit context: Context)(o: Foo, n: int32) {
macro Test(implicit context: Context)(o: Foo, n: int32): void {
o.s.y = n;
}
)",
@ -770,7 +770,7 @@ TEST(Torque, ConstClassFields) {
}
@export
macro Test(implicit context: Context)(o: Foo, n: int32) {
macro Test(implicit context: Context)(o: Foo, n: int32): void {
o.s.x = n;
}
)",
@ -785,7 +785,7 @@ TEST(Torque, References) {
}
@export
macro Test(implicit context: Context)(o: Foo, n: int32) {
macro Test(implicit context: Context)(o: Foo, n: int32): void {
const constRefX: const &int32 = &o.x;
const refY: &int32 = &o.y;
const constRefY: const &int32 = refY;
@ -805,7 +805,7 @@ TEST(Torque, References) {
}
@export
macro Test(implicit context: Context)(o: Foo) {
macro Test(implicit context: Context)(o: Foo): void {
const _refX: &int32 = &o.x;
}
)",
@ -819,7 +819,7 @@ TEST(Torque, References) {
}
@export
macro Test(implicit context: Context)(o: Foo, n: int32) {
macro Test(implicit context: Context)(o: Foo, n: int32): void {
const constRefX: const &int32 = &o.x;
*constRefX = n;
}
@ -831,7 +831,7 @@ TEST(Torque, CatchFirstHandler) {
ExpectFailingCompilation(
R"(
@export
macro Test() {
macro Test(): void {
try {
} label Foo {
} catch (e) {}
@ -876,14 +876,14 @@ TEST(Torque, UnusedImplicit) {
@export
macro Test1(implicit c: Smi)(a: Object): Object { return a; }
@export
macro Test2(b: Object) { Test1(b); }
macro Test2(b: Object): void { Test1(b); }
)");
ExpectFailingCompilation(
R"(
macro Test1(implicit c: Smi)(_a: Object): Smi { return c; }
@export
macro Test2(b: Smi) { Test1(b); }
macro Test2(b: Smi): void { Test1(b); }
)",
HasSubstr("undefined expression of type Smi: the implicit "
"parameter 'c' is not defined when invoking Test1 at"));
@ -892,7 +892,7 @@ TEST(Torque, UnusedImplicit) {
R"(
extern macro Test3(implicit c: Smi)(Object): Smi;
@export
macro Test4(b: Smi) { Test3(b); }
macro Test4(b: Smi): void { Test3(b); }
)",
HasSubstr("unititialized implicit parameters can only be passed to "
"Torque-defined macros: the implicit parameter 'c' is not "
@ -902,7 +902,7 @@ TEST(Torque, UnusedImplicit) {
macro Test7<T: type>(implicit c: Smi)(o: T): Smi;
Test7<Smi>(implicit c: Smi)(o: Smi): Smi { return o; }
@export
macro Test8(b: Smi) { Test7(b); }
macro Test8(b: Smi): void { Test7(b); }
)");
ExpectFailingCompilation(
@ -914,7 +914,7 @@ TEST(Torque, UnusedImplicit) {
macro Test7<T: type>(o: T): Smi;
Test7<Smi>(o: Smi): Smi { return Test6<Smi>(o); }
@export
macro Test8(b: Smi) { Test7(b); }
macro Test8(b: Smi): void { Test7(b); }
)",
HasSubstr("\nambiguous callable : \n Test6(Smi)\ncandidates are:\n "
"Test6(Smi): Smi\n Test6(implicit Smi)(Smi): Smi"));
@ -922,27 +922,27 @@ TEST(Torque, UnusedImplicit) {
TEST(Torque, ImplicitTemplateParameterInference) {
ExpectSuccessfulCompilation(R"(
macro Foo(_x: Map) {}
macro Foo(_x: Smi) {}
macro GenericMacro<T: type>(implicit x: T)() {
macro Foo(_x: Map): void {}
macro Foo(_x: Smi): void {}
macro GenericMacro<T: type>(implicit x: T)(): void {
Foo(x);
}
@export
macro Test1(implicit x: Smi)() { GenericMacro(); }
macro Test1(implicit x: Smi)(): void { GenericMacro(); }
@export
macro Test2(implicit x: Map)() { GenericMacro(); }
macro Test2(implicit x: Map)(): void { GenericMacro(); }
)");
ExpectFailingCompilation(
R"(
// Wrap in namespace to avoid redeclaration error.
namespace foo {
macro Foo(implicit x: Map)() {}
macro Foo(implicit x: Map)(): void {}
}
macro Foo(implicit x: Smi)() {}
macro Foo(implicit x: Smi)(): void {}
namespace foo{
@export
macro Test(implicit x: Smi)() { Foo(); }
macro Test(implicit x: Smi)(): void { Foo(); }
}
)",
HasSubstr("ambiguous callable"));
@ -951,12 +951,12 @@ TEST(Torque, ImplicitTemplateParameterInference) {
R"(
// Wrap in namespace to avoid redeclaration error.
namespace foo {
macro Foo(implicit x: Map)() {}
macro Foo(implicit x: Map)(): void {}
}
macro Foo(implicit x: Smi)() {}
macro Foo(implicit x: Smi)(): void {}
namespace foo{
@export
macro Test(implicit x: Map)() { Foo(); }
macro Test(implicit x: Map)(): void { Foo(); }
}
)",
HasSubstr("ambiguous callable"));

View File

@ -20,7 +20,7 @@ class SortState extends HeapObject {
return sortCompare(context, this.userCmpFn, x, y);
}
macro CheckAccessor(implicit context: Context)() labels Bailout {
macro CheckAccessor(implicit context: Context)(): void labels Bailout {
if (!IsFastJSArray(this.receiver, context)) goto Bailout;
const canUseSameAccessorFn: CanUseSameAccessorFn =
@ -33,7 +33,7 @@ class SortState extends HeapObject {
}
}
macro ResetToGenericAccessor() {
macro ResetToGenericAccessor(): void {
this.loadFn = Load<GenericElementsAccessor>;
this.storeFn = Store<GenericElementsAccessor>;
this.deleteFn = Delete<GenericElementsAccessor>;
@ -410,7 +410,7 @@ macro GetPendingRunBase(implicit context: Context)(
return UnsafeCast<Smi>(pendingRuns.objects[run << 1]);
}
macro SetPendingRunBase(pendingRuns: FixedArray, run: Smi, value: Smi) {
macro SetPendingRunBase(pendingRuns: FixedArray, run: Smi, value: Smi): void {
pendingRuns.objects[run << 1] = value;
}
@ -419,12 +419,12 @@ macro GetPendingRunLength(implicit context: Context)(
return UnsafeCast<Smi>(pendingRuns.objects[(run << 1) + 1]);
}
macro SetPendingRunLength(pendingRuns: FixedArray, run: Smi, value: Smi) {
macro SetPendingRunLength(pendingRuns: FixedArray, run: Smi, value: Smi): void {
pendingRuns.objects[(run << 1) + 1] = value;
}
macro PushRun(implicit context: Context)(
sortState: SortState, base: Smi, length: Smi) {
sortState: SortState, base: Smi, length: Smi): void {
dcheck(GetPendingRunsSize(sortState) < kMaxMergePending);
const stackSize: Smi = GetPendingRunsSize(sortState);
@ -498,7 +498,7 @@ Copy(implicit context: Context)(
// On entry, must have low <= start <= high, and that [low, start) is
// already sorted. Pass start == low if you do not know!.
macro BinaryInsertionSort(implicit context: Context, sortState: SortState)(
low: Smi, startArg: Smi, high: Smi) {
low: Smi, startArg: Smi, high: Smi): void {
dcheck(low <= startArg && startArg <= high);
const workArray = sortState.workArray;
@ -604,7 +604,7 @@ macro CountAndMakeRun(implicit context: Context, sortState: SortState)(
return runLength;
}
macro ReverseRange(array: FixedArray, from: Smi, to: Smi) {
macro ReverseRange(array: FixedArray, from: Smi, to: Smi): void {
let low: Smi = from;
let high: Smi = to - 1;
@ -890,7 +890,7 @@ builtin GallopRight(implicit context: Context, sortState: SortState)(
// that array[baseA + lengthA - 1] belongs at the end of the merge,
// and should have lengthA <= lengthB.
transitioning macro MergeLow(implicit context: Context, sortState: SortState)(
baseA: Smi, lengthAArg: Smi, baseB: Smi, lengthBArg: Smi) {
baseA: Smi, lengthAArg: Smi, baseB: Smi, lengthBArg: Smi): void {
dcheck(0 < lengthAArg && 0 < lengthBArg);
dcheck(0 <= baseA && 0 < baseB);
dcheck(baseA + lengthAArg == baseB);
@ -1020,7 +1020,7 @@ transitioning macro MergeLow(implicit context: Context, sortState: SortState)(
// be > 0. Must also have that array[baseA + lengthA - 1] belongs at the
// end of the merge and should have lengthA >= lengthB.
transitioning macro MergeHigh(implicit context: Context, sortState: SortState)(
baseA: Smi, lengthAArg: Smi, baseB: Smi, lengthBArg: Smi) {
baseA: Smi, lengthAArg: Smi, baseB: Smi, lengthBArg: Smi): void {
dcheck(0 < lengthAArg && 0 < lengthBArg);
dcheck(0 <= baseA && 0 < baseB);
dcheck(baseA + lengthAArg == baseB);
@ -1198,7 +1198,8 @@ macro RunInvariantEstablished(implicit context: Context)(
// TODO(szuend): Remove unnecessary loads. This macro was refactored to
// improve readability, introducing unnecessary loads in the
// process. Determine if all these extra loads are ok.
transitioning macro MergeCollapse(context: Context, sortState: SortState) {
transitioning macro MergeCollapse(
context: Context, sortState: SortState): void {
const pendingRuns: FixedArray = sortState.pendingRuns;
// Reload the stack size because MergeAt might change it.
@ -1226,7 +1227,7 @@ transitioning macro MergeCollapse(context: Context, sortState: SortState) {
// Regardless of invariants, merge all runs on the stack until only one
// remains. This is used at the end of the mergesort.
transitioning macro
MergeForceCollapse(context: Context, sortState: SortState) {
MergeForceCollapse(context: Context, sortState: SortState): void {
const pendingRuns: FixedArray = sortState.pendingRuns;
// Reload the stack size becuase MergeAt might change it.
@ -1243,7 +1244,7 @@ MergeForceCollapse(context: Context, sortState: SortState) {
}
transitioning macro
ArrayTimSortImpl(context: Context, sortState: SortState, length: Smi) {
ArrayTimSortImpl(context: Context, sortState: SortState, length: Smi): void {
if (length < 2) return;
let remaining: Smi = length;
@ -1322,7 +1323,7 @@ CompactReceiverElementsIntoWorkArray(
transitioning macro
CopyWorkArrayToReceiver(implicit context: Context, sortState: SortState)(
numberOfNonUndefined: Smi) {
numberOfNonUndefined: Smi): void {
const storeFn = sortState.storeFn;
const workArray = sortState.workArray;