Commit 73aaa19f authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] cleanup CastHeapObject

Since the improvement of overload resolution (https://crrev.com/c/1304294),
overload resolution of generics doesn't take into account existing
specializations anymore. This means that the issue of infinite recursion
when an overload of Cast for HeapObject is missing doesn't exist anymore.
Thus we can get rid of the CastHeapObject workaround.

Bug: v8:7793
Change-Id: I8442cfb81b78aaa8234bcee673647261c25f9a63
Reviewed-on: https://chromium-review.googlesource.com/c/1448324Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59263}
parent 80d7ce6e
...@@ -661,103 +661,124 @@ extern macro HeapObjectToSloppyArgumentsElements(HeapObject): ...@@ -661,103 +661,124 @@ extern macro HeapObjectToSloppyArgumentsElements(HeapObject):
extern macro TaggedToNumber(Object): Number extern macro TaggedToNumber(Object): Number
labels CastError; labels CastError;
macro CastHeapObject<A: type>(o: HeapObject): A macro Cast<A: type>(implicit context: Context)(o: Object): A
labels CastError {
return Cast<A>(TaggedToHeapObject(o) otherwise CastError)
otherwise CastError;
}
Cast<Smi>(o: Object): Smi
labels CastError {
return TaggedToSmi(o) otherwise CastError;
}
Cast<PositiveSmi>(o: Object): PositiveSmi
labels CastError {
return TaggedToPositiveSmi(o) otherwise CastError;
}
Cast<Number>(o: Object): Number
labels CastError {
return TaggedToNumber(o) otherwise CastError;
}
macro Cast<A: type>(o: HeapObject): A
labels CastError; labels CastError;
CastHeapObject<HeapObject>(o: HeapObject): HeapObject Cast<HeapObject>(o: HeapObject): HeapObject
labels CastError { labels CastError {
return o; return o;
} }
CastHeapObject<FixedArray>(o: HeapObject): FixedArray Cast<FixedArray>(o: HeapObject): FixedArray
labels CastError { labels CastError {
return HeapObjectToFixedArray(o) otherwise CastError; return HeapObjectToFixedArray(o) otherwise CastError;
} }
CastHeapObject<FixedDoubleArray>(o: HeapObject): FixedDoubleArray Cast<FixedDoubleArray>(o: HeapObject): FixedDoubleArray
labels CastError { labels CastError {
return HeapObjectToFixedDoubleArray(o) otherwise CastError; return HeapObjectToFixedDoubleArray(o) otherwise CastError;
} }
CastHeapObject<SloppyArgumentsElements>(o: HeapObject): SloppyArgumentsElements Cast<SloppyArgumentsElements>(o: HeapObject): SloppyArgumentsElements
labels CastError { labels CastError {
return HeapObjectToSloppyArgumentsElements(o) otherwise CastError; return HeapObjectToSloppyArgumentsElements(o) otherwise CastError;
} }
CastHeapObject<JSDataView>(o: HeapObject): JSDataView Cast<JSDataView>(o: HeapObject): JSDataView
labels CastError { labels CastError {
return HeapObjectToJSDataView(o) otherwise CastError; return HeapObjectToJSDataView(o) otherwise CastError;
} }
CastHeapObject<JSTypedArray>(o: HeapObject): JSTypedArray Cast<JSTypedArray>(o: HeapObject): JSTypedArray
labels CastError { labels CastError {
if (IsJSTypedArray(o)) return %RawDownCast<JSTypedArray>(o); if (IsJSTypedArray(o)) return %RawDownCast<JSTypedArray>(o);
goto CastError; goto CastError;
} }
CastHeapObject<Callable>(o: HeapObject): Callable Cast<Callable>(o: HeapObject): Callable
labels CastError { labels CastError {
return HeapObjectToCallable(o) otherwise CastError; return HeapObjectToCallable(o) otherwise CastError;
} }
CastHeapObject<JSArray>(o: HeapObject): JSArray Cast<JSArray>(o: HeapObject): JSArray
labels CastError { labels CastError {
return HeapObjectToJSArray(o) otherwise CastError; return HeapObjectToJSArray(o) otherwise CastError;
} }
CastHeapObject<JSArrayBuffer>(o: HeapObject): JSArrayBuffer Cast<JSArrayBuffer>(o: HeapObject): JSArrayBuffer
labels CastError { labels CastError {
return HeapObjectToJSArrayBuffer(o) otherwise CastError; return HeapObjectToJSArrayBuffer(o) otherwise CastError;
} }
CastHeapObject<Context>(o: HeapObject): Context Cast<Context>(o: HeapObject): Context
labels CastError { labels CastError {
if (IsContext(o)) return %RawDownCast<Context>(o); if (IsContext(o)) return %RawDownCast<Context>(o);
goto CastError; goto CastError;
} }
CastHeapObject<JSObject>(o: HeapObject): JSObject Cast<JSObject>(o: HeapObject): JSObject
labels CastError { labels CastError {
if (IsJSObject(o)) return %RawDownCast<JSObject>(o); if (IsJSObject(o)) return %RawDownCast<JSObject>(o);
goto CastError; goto CastError;
} }
CastHeapObject<NumberDictionary>(o: HeapObject): NumberDictionary Cast<NumberDictionary>(o: HeapObject): NumberDictionary
labels CastError { labels CastError {
if (IsNumberDictionary(o)) return %RawDownCast<NumberDictionary>(o); if (IsNumberDictionary(o)) return %RawDownCast<NumberDictionary>(o);
goto CastError; goto CastError;
} }
CastHeapObject<FixedTypedArrayBase>(o: HeapObject): FixedTypedArrayBase Cast<FixedTypedArrayBase>(o: HeapObject): FixedTypedArrayBase
labels CastError { labels CastError {
if (IsFixedTypedArray(o)) return %RawDownCast<FixedTypedArrayBase>(o); if (IsFixedTypedArray(o)) return %RawDownCast<FixedTypedArrayBase>(o);
goto CastError; goto CastError;
} }
CastHeapObject<String>(o: HeapObject): String Cast<String>(o: HeapObject): String
labels CastError { labels CastError {
return HeapObjectToString(o) otherwise CastError; return HeapObjectToString(o) otherwise CastError;
} }
CastHeapObject<Constructor>(o: HeapObject): Constructor Cast<Constructor>(o: HeapObject): Constructor
labels CastError { labels CastError {
return HeapObjectToConstructor(o) otherwise CastError; return HeapObjectToConstructor(o) otherwise CastError;
} }
CastHeapObject<HeapNumber>(o: HeapObject): HeapNumber Cast<HeapNumber>(o: HeapObject): HeapNumber
labels CastError { labels CastError {
if (IsHeapNumber(o)) return %RawDownCast<HeapNumber>(o); if (IsHeapNumber(o)) return %RawDownCast<HeapNumber>(o);
goto CastError; goto CastError;
} }
CastHeapObject<Map>(implicit context: Context)(o: HeapObject): Map Cast<Map>(implicit context: Context)(o: HeapObject): Map
labels CastError { labels CastError {
if (IsMap(o)) return %RawDownCast<Map>(o); if (IsMap(o)) return %RawDownCast<Map>(o);
goto CastError; goto CastError;
} }
CastHeapObject<JSArgumentsObjectWithLength>(implicit context: Context)( Cast<JSArgumentsObjectWithLength>(implicit context: Context)(o: HeapObject):
o: HeapObject): JSArgumentsObjectWithLength JSArgumentsObjectWithLength
labels CastError { labels CastError {
const map: Map = o.map; const map: Map = o.map;
try { try {
...@@ -772,8 +793,7 @@ CastHeapObject<JSArgumentsObjectWithLength>(implicit context: Context)( ...@@ -772,8 +793,7 @@ CastHeapObject<JSArgumentsObjectWithLength>(implicit context: Context)(
} }
} }
CastHeapObject<FastJSArray>(implicit context: Context)(o: HeapObject): Cast<FastJSArray>(implicit context: Context)(o: HeapObject): FastJSArray
FastJSArray
labels CastError { labels CastError {
const map: Map = o.map; const map: Map = o.map;
if (!IsJSArrayMap(map)) goto CastError; if (!IsJSArrayMap(map)) goto CastError;
...@@ -816,7 +836,7 @@ struct FastJSArrayWitness { ...@@ -816,7 +836,7 @@ struct FastJSArrayWitness {
map: Map; map: Map;
} }
CastHeapObject<FastJSArrayForCopy>(implicit context: Context)(o: HeapObject): Cast<FastJSArrayForCopy>(implicit context: Context)(o: HeapObject):
FastJSArrayForCopy FastJSArrayForCopy
labels CastError { labels CastError {
if (IsArraySpeciesProtectorCellInvalid()) goto CastError; if (IsArraySpeciesProtectorCellInvalid()) goto CastError;
...@@ -824,7 +844,7 @@ CastHeapObject<FastJSArrayForCopy>(implicit context: Context)(o: HeapObject): ...@@ -824,7 +844,7 @@ CastHeapObject<FastJSArrayForCopy>(implicit context: Context)(o: HeapObject):
return %RawDownCast<FastJSArrayForCopy>(o); return %RawDownCast<FastJSArrayForCopy>(o);
} }
CastHeapObject<FastJSArrayWithNoCustomIteration>(implicit context: Context)( Cast<FastJSArrayWithNoCustomIteration>(implicit context: Context)(
o: HeapObject): FastJSArrayWithNoCustomIteration o: HeapObject): FastJSArrayWithNoCustomIteration
labels CastError { labels CastError {
if (IsArrayIteratorProtectorCellInvalid()) goto CastError; if (IsArrayIteratorProtectorCellInvalid()) goto CastError;
...@@ -832,46 +852,18 @@ CastHeapObject<FastJSArrayWithNoCustomIteration>(implicit context: Context)( ...@@ -832,46 +852,18 @@ CastHeapObject<FastJSArrayWithNoCustomIteration>(implicit context: Context)(
return %RawDownCast<FastJSArrayWithNoCustomIteration>(o); return %RawDownCast<FastJSArrayWithNoCustomIteration>(o);
} }
CastHeapObject<JSReceiver>(implicit context: Context)(o: HeapObject): JSReceiver Cast<JSReceiver>(implicit context: Context)(o: HeapObject): JSReceiver
labels CastError { labels CastError {
if (IsJSReceiver(o)) return %RawDownCast<JSReceiver>(o); if (IsJSReceiver(o)) return %RawDownCast<JSReceiver>(o);
goto CastError; goto CastError;
} }
CastHeapObject<JSFunction>(implicit context: Context)(o: HeapObject): JSFunction Cast<JSFunction>(implicit context: Context)(o: HeapObject): JSFunction
labels CastError { labels CastError {
if (IsJSFunction(o)) return %RawDownCast<JSFunction>(o); if (IsJSFunction(o)) return %RawDownCast<JSFunction>(o);
goto CastError; goto CastError;
} }
macro Cast<A: type>(implicit context: Context)(o: HeapObject): A
labels CastError {
return CastHeapObject<A>(o) otherwise CastError;
}
// CastHeapObject allows this default-implementation to be non-recursive.
// Otherwise the generated CSA code might run into infinite recursion.
macro Cast<A: type>(implicit context: Context)(o: Object): A
labels CastError {
return CastHeapObject<A>(TaggedToHeapObject(o) otherwise CastError)
otherwise CastError;
}
Cast<Smi>(o: Object): Smi
labels CastError {
return TaggedToSmi(o) otherwise CastError;
}
Cast<PositiveSmi>(o: Object): PositiveSmi
labels CastError {
return TaggedToPositiveSmi(o) otherwise CastError;
}
Cast<Number>(o: Object): Number
labels CastError {
return TaggedToNumber(o) otherwise CastError;
}
extern macro AllocateHeapNumberWithValue(float64): HeapNumber; extern macro AllocateHeapNumberWithValue(float64): HeapNumber;
extern macro ChangeInt32ToTagged(int32): Number; extern macro ChangeInt32ToTagged(int32): Number;
extern macro ChangeUint32ToTagged(uint32): Number; extern macro ChangeUint32ToTagged(uint32): Number;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment