Skip to content

Commit

Permalink
Merge commit '5cae9f72975cf0e5a62b27fdd8b01f103e198708' into rnw/canary
Browse files Browse the repository at this point in the history
  • Loading branch information
TatianaKapos committed Feb 3, 2023
2 parents 8327483 + 5cae9f7 commit c3d4ed2
Show file tree
Hide file tree
Showing 30 changed files with 446 additions and 64 deletions.
8 changes: 4 additions & 4 deletions external/llvh/lib/Support/SourceMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ std::pair<StringRef, unsigned> SourceMgr::SrcBuffer::getLineNumber(
EOL != Offsets->end() ? BufStart + *EOL + 1 : Buffer->getBufferEnd();

// Lines count from 1, so add 1 to the distance from the 0th line.
return {StringRef(LineStart, LineEnd - LineStart), (1 + (EOL - Offsets->begin()))};
return {StringRef(LineStart, LineEnd - LineStart), static_cast<unsigned>((1 + (EOL - Offsets->begin())))};
}

template<typename T>
Expand Down Expand Up @@ -219,7 +219,7 @@ std::pair<unsigned, unsigned>
SourceMgr::getLineAndColumn(SMLoc Loc, unsigned BufferID) const {
auto LineRefAndNo = FindLine(Loc, BufferID);
return std::make_pair(LineRefAndNo.second,
Loc.getPointer() - LineRefAndNo.first.data() + 1);
static_cast<unsigned>(Loc.getPointer() - LineRefAndNo.first.data() + 1));
}

void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const {
Expand Down Expand Up @@ -285,8 +285,8 @@ SMDiagnostic SourceMgr::GetMessage(SMLoc Loc, SourceMgr::DiagKind Kind,

// Translate from SMLoc ranges to column ranges.
// FIXME: Handle multibyte characters.
ColRanges.push_back(std::make_pair(R.Start.getPointer()-LineStart,
R.End.getPointer()-LineStart));
ColRanges.push_back(std::make_pair(static_cast<unsigned>(R.Start.getPointer()-LineStart),
static_cast<unsigned>(R.End.getPointer()-LineStart)));
}

LineAndCol = getLineAndColumn(Loc, CurBuf);
Expand Down
32 changes: 32 additions & 0 deletions external/llvh/patches/SourceMgr-msvc-warnings.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
diff --git a/xplat/hermes/external/llvh/lib/Support/SourceMgr.cpp b/xplat/hermes/external/llvh/lib/Support/SourceMgr.cpp
--- a/xplat/hermes/external/llvh/lib/Support/SourceMgr.cpp
+++ b/xplat/hermes/external/llvh/lib/Support/SourceMgr.cpp
@@ -126,7 +126,7 @@
EOL != Offsets->end() ? BufStart + *EOL + 1 : Buffer->getBufferEnd();

// Lines count from 1, so add 1 to the distance from the 0th line.
- return {StringRef(LineStart, LineEnd - LineStart), (1 + (EOL - Offsets->begin()))};
+ return {StringRef(LineStart, LineEnd - LineStart), static_cast<unsigned>((1 + (EOL - Offsets->begin())))};
}

template<typename T>
@@ -219,7 +219,7 @@
SourceMgr::getLineAndColumn(SMLoc Loc, unsigned BufferID) const {
auto LineRefAndNo = FindLine(Loc, BufferID);
return std::make_pair(LineRefAndNo.second,
- Loc.getPointer() - LineRefAndNo.first.data() + 1);
+ static_cast<unsigned>(Loc.getPointer() - LineRefAndNo.first.data() + 1));
}

void SourceMgr::PrintIncludeStack(SMLoc IncludeLoc, raw_ostream &OS) const {
@@ -285,8 +285,8 @@

// Translate from SMLoc ranges to column ranges.
// FIXME: Handle multibyte characters.
- ColRanges.push_back(std::make_pair(R.Start.getPointer()-LineStart,
- R.End.getPointer()-LineStart));
+ ColRanges.push_back(std::make_pair(static_cast<unsigned>(R.Start.getPointer()-LineStart),
+ static_cast<unsigned>(R.End.getPointer()-LineStart)));
}

LineAndCol = getLineAndColumn(Loc, CurBuf);
2 changes: 1 addition & 1 deletion external/zip/src/zip.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ extern int zip_entries_total(struct zip_t *zip);
* @return the number of deleted entries, or negative number (< 0) on error.
*/
extern int zip_entries_delete(struct zip_t *zip, char *const entries[],
size_t len);
const size_t len);

/**
* Extracts a zip archive stream into directory.
Expand Down
10 changes: 5 additions & 5 deletions include/hermes/BCGen/HBC/BytecodeProviderFromSrc.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ class BCProviderLazy final : public BCProviderBase {

/// No debug information will be available without compiling it.
void createDebugInfo() override {
llvm_unreachable("Accessing debug info from a lazy module");
hermes_fatal("Accessing debug info from a lazy module");
}

public:
Expand All @@ -234,20 +234,20 @@ class BCProviderLazy final : public BCProviderBase {
}

StringTableEntry getStringTableEntry(uint32_t index) const override {
llvm_unreachable("Accessing string table from a lazy module");
hermes_fatal("Accessing string table from a lazy module");
}

const uint8_t *getBytecode(uint32_t) const override {
llvm_unreachable("Accessing bytecode from a lazy module");
hermes_fatal("Accessing bytecode from a lazy module");
}

llvh::ArrayRef<hbc::HBCExceptionHandlerInfo> getExceptionTable(
uint32_t) const override {
llvm_unreachable("Accessing exception info from a lazy module");
hermes_fatal("Accessing exception info from a lazy module");
}

const hbc::DebugOffsets *getDebugOffsets(uint32_t) const override {
llvm_unreachable("Accessing debug offsets from a lazy module");
hermes_fatal("Accessing debug offsets from a lazy module");
}

bool isFunctionLazy(uint32_t) const override {
Expand Down
56 changes: 53 additions & 3 deletions include/hermes/Support/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,50 @@
#ifndef HERMES_SUPPORT_JSON_H
#define HERMES_SUPPORT_JSON_H

#include "hermes/Platform/Unicode/CharacterProperties.h"

namespace hermes {

template <typename Output>
void appendUTF16Escaped(Output &output, char16_t cp) {
auto toLowerHex = [](uint8_t u) {
assert(u <= 0xF);
return u"0123456789abcdef"[u];
};
output.append({u'\\', u'u'});
output.push_back(toLowerHex(cp >> 12));
output.push_back(toLowerHex((cp >> 8) & 0xF));
output.push_back(toLowerHex((cp >> 4) & 0xF));
output.push_back(toLowerHex(cp & 0xF));
}

// If there is a valid surrogate pair at position \p i in \p view, then write
// both the high and low surrogate into \p output. Otherwise, write an escaped
// UTF16 value into \p output. \return true if a pair was found.
template <typename Output, typename StringView>
bool handleSurrogate(Output &output, StringView view, size_t i) {
char16_t ch = view[i];
assert(
ch >= UNICODE_SURROGATE_FIRST && ch <= UNICODE_SURROGATE_LAST &&
"charcter should be a surrogate character");
// Handle well-formed-ness here: Represent unpaired surrogate code points as
// JSON escape sequences.
if (isHighSurrogate(ch) && i + 1 < view.length()) {
char16_t next = view[i + 1];
if (isLowSurrogate(next)) {
// We found a surrogate pair. Simply write both of them unescaped to the
// output.
output.push_back(ch);
output.push_back(next);
return true;
}
}
// We did not find a valid pair, so the current surrogate character must be
// written as an escaped JSON sequence.
appendUTF16Escaped(output, ch);
return false;
}

/// Quotes a string given by \p view and puts the quoted version into \p output.
/// \p view should be utf16-encoded, and \p output will be as well.
/// \post output is a container that has a sequential list of utf16 characters
Expand All @@ -19,7 +61,8 @@ void quoteStringForJSON(Output &output, StringView view) {
// Quote.1.
output.push_back(u'"');
// Quote.2.
for (char16_t ch : view) {
for (size_t i = 0; i < view.length(); i++) {
char16_t ch = view[i];
#define ESCAPE(ch, replace) \
case ch: \
output.push_back(u'\\'); \
Expand Down Expand Up @@ -47,8 +90,15 @@ void quoteStringForJSON(Output &output, StringView view) {
output.push_back(u'a' + (ch % 16 - 10));
}
} else {
// Quote.2.d.
output.push_back(ch);
if (ch >= UNICODE_SURROGATE_FIRST && ch <= UNICODE_SURROGATE_LAST) {
if (handleSurrogate(output, view, i)) {
// Found a valid surrogate pair, so skip over the next character.
i++;
}
} else {
// Quote.2.d.
output.push_back(ch);
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions include/hermes/VM/SmallHermesValue-inline.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,14 @@
namespace hermes {
namespace vm {

#ifndef HERMESVM_ALLOW_COMPRESSED_POINTERS

void SmallHermesValueAdaptor::setInGC(SmallHermesValueAdaptor hv, GC &gc) {
HermesValue::setInGC(hv, gc);
}

#else // #ifndef HERMESVM_ALLOW_COMPRESSED_POINTERS

void HermesValue32::setInGC(HermesValue32 hv, GC &gc) {
setNoBarrier(hv);
assert(gc.calledByGC());
Expand Down Expand Up @@ -148,6 +152,9 @@ double HermesValue32::getNumber(PointerBase &pb) const {
"Strings must use encodeStringValue; BigInts, encodeBigIntValue");
return encodePointerImpl(ptr, Tag::Object, pb);
}

#endif // #ifndef HERMESVM_ALLOW_COMPRESSED_POINTERS

} // namespace vm
} // namespace hermes
#pragma GCC diagnostic pop
Expand Down
28 changes: 12 additions & 16 deletions include/hermes/VM/SmallHermesValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
#include <cassert>
#include <cmath>
#include <cstdint>
#pragma GCC diagnostic push

#ifdef HERMES_COMPILER_SUPPORTS_WSHORTEN_64_TO_32
#pragma GCC diagnostic ignored "-Wshorten-64-to-32"
#endif
namespace hermes {
namespace vm {

Expand All @@ -32,6 +28,13 @@ class StringPrimitive;
class GCCell;
class Runtime;

/// If compressed pointers are allowed, then we should also compress
/// HermesValues. This means that when compressed pointers are allowed,
/// SmallHermesValue will almost always be 32 bits, except with MallocGC, which
/// does not support compressed pointers. Depending on the compressed pointers
/// flag, SmallHermesValue will alias SmallHermesValueAdaptor or HermesValue32.

#ifndef HERMESVM_ALLOW_COMPRESSED_POINTERS
/// An adaptor class that provides the API of a SmallHermesValue is internally
/// just a HermesValue.
class SmallHermesValueAdaptor : protected HermesValue {
Expand Down Expand Up @@ -168,6 +171,9 @@ class SmallHermesValueAdaptor : protected HermesValue {
return SmallHermesValueAdaptor{HermesValue::encodeEmptyValue()};
}
};
using SmallHermesValue = SmallHermesValueAdaptor;

#else // #ifndef HERMESVM_ALLOW_COMPRESSED_POINTERS

/// A compressed HermesValue that is always equal to the size of a
/// CompressedPointer. It uses the least significant bits (guaranteed to be zero
Expand Down Expand Up @@ -476,18 +482,9 @@ class HermesValue32 {
raw_ = other.raw_;
}
};
using SmallHermesValue = HermesValue32;

/// If compressed pointers are allowed, then we should also compress
/// HermesValues. This means that when compressed pointers are allowed,
/// SmallHermesValue will almost always be 32 bits, except with MallocGC, which
/// does not support compressed pointers.
using SmallHermesValue =
#ifdef HERMESVM_ALLOW_COMPRESSED_POINTERS
HermesValue32
#else
SmallHermesValueAdaptor
#endif
;
#endif // #ifndef HERMESVM_ALLOW_COMPRESSED_POINTERS

static_assert(
std::is_trivial<SmallHermesValue>::value,
Expand All @@ -498,5 +495,4 @@ using GCSmallHermesValue = GCHermesValueBase<SmallHermesValue>;
} // end namespace vm
} // end namespace hermes

#pragma GCC diagnostic pop
#endif // HERMES_VM_HERMESVALUE_H
3 changes: 2 additions & 1 deletion lib/BCGen/HBC/BytecodeStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,8 @@ void BytecodeSerializer::serializeFunctionsBytecode(BytecodeModule &BM) {
if (isLayout_) {
// Deduplicate the bytecode during layout phase.
DedupKey key = entry->getOpcodeArray();
auto pair = bcMap.insert(std::make_pair(key, loc_));
auto pair =
bcMap.insert(std::make_pair(key, static_cast<uint32_t>(loc_)));
if (!pair.second) {
reuse = true;
entry->setOffset(pair.first->second);
Expand Down
4 changes: 2 additions & 2 deletions lib/IR/IR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void Value::removeUse(Use U) {
// If we've changed the location of a use in the use list then we need to
// update the operand in the user.
if (U.second != Users.size()) {
Use oldUse = {this, Users.size()};
Use oldUse = {this, static_cast<unsigned>(Users.size())};
auto &operands = Users[U.second]->Operands;
for (int i = 0, e = operands.size(); i < e; i++) {
if (operands[i] == oldUse) {
Expand All @@ -116,7 +116,7 @@ void Value::removeUse(Use U) {

Value::Use Value::addUser(Instruction *Inst) {
Users.push_back(Inst);
return {this, Users.size() - 1};
return {this, static_cast<unsigned>(Users.size() - 1)};
}

void Value::replaceAllUsesWith(Value *Other) {
Expand Down
6 changes: 4 additions & 2 deletions lib/Support/BigIntSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2015,7 +2015,8 @@ static std::tuple<uint32_t, bool> getShiftAmountAndSign(
// shiftAmnt is outside of the
// [MinNegativeShiftAmountInBits, MaxPositiveShiftAmountInBits]; thus return
// a really large shift amount.
return std::make_tuple(reallyLargeShiftAmount, shiftAmntIsNeg);
return std::make_tuple(
static_cast<uint32_t>(reallyLargeShiftAmount), shiftAmntIsNeg);
}

const SignedBigIntDigitType sa = (shiftAmnt.numDigits == 0)
Expand All @@ -2026,7 +2027,8 @@ static std::tuple<uint32_t, bool> getShiftAmountAndSign(
shiftAmnt.digits[0] != std::numeric_limits<BigIntDigitType>::min()) &&
"shiftAmnt is MIN_INT, hence -signedShiftAmnt is MIN_INT");
// Always return a positive result -- thus negate sa if shiftAmnt is negative.
return std::make_tuple(shiftAmntIsNeg ? -sa : sa, shiftAmntIsNeg);
return std::make_tuple(
static_cast<uint32_t>(shiftAmntIsNeg ? -sa : sa), shiftAmntIsNeg);
}

} // namespace
Expand Down
2 changes: 2 additions & 0 deletions lib/Support/OSCompatWindows.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
// Include windows.h first because other includes from windows API need it.
// The blank line after the include is necessary to avoid lint error.
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
#define NOMINMAX // do not define min/max macros
#endif
#include <windows.h>

#include <intrin.h>
Expand Down
2 changes: 2 additions & 0 deletions lib/VM/Instrumentation/ProcessStats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
// Include windows.h first because other includes from windows API need it.
// The blank line after the include is necessary to avoid lint error.
#define WIN32_LEAN_AND_MEAN
#ifndef NOMINMAX
#define NOMINMAX // do not define min/max macros
#endif
#include <windows.h>

#include <psapi.h>
Expand Down
39 changes: 31 additions & 8 deletions lib/VM/JSLib/HermesInternal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,14 +574,18 @@ static CallResult<HermesValue> getCodeBlockFileName(
const CodeBlock *codeBlock,
OptValue<hbc::DebugSourceLocation> location) {
RuntimeModule *runtimeModule = codeBlock->getRuntimeModule();
if (location) {
auto debugInfo = runtimeModule->getBytecode()->getDebugInfo();
return StringPrimitive::createEfficient(
runtime, debugInfo->getFilenameByID(location->filenameId));
} else {
llvh::StringRef sourceURL = runtimeModule->getSourceURL();
if (!sourceURL.empty()) {
return StringPrimitive::createEfficient(runtime, sourceURL);
if (!runtimeModule->getBytecode()->isLazy()) {
// Lazy code blocks do not have debug information (and will hermes_fatal if
// you try to access it), so only touch it for non-lazy blocks.
if (location) {
auto debugInfo = runtimeModule->getBytecode()->getDebugInfo();
return StringPrimitive::createEfficient(
runtime, debugInfo->getFilenameByID(location->filenameId));
} else {
llvh::StringRef sourceURL = runtimeModule->getSourceURL();
if (!sourceURL.empty()) {
return StringPrimitive::createEfficient(runtime, sourceURL);
}
}
}
return HermesValue::encodeUndefinedValue();
Expand Down Expand Up @@ -803,6 +807,24 @@ hermesInternalFuzzilli(void *, Runtime &runtime, NativeArgs args) {
}
#endif // HERMES_ENABLE_FUZZILLI

static CallResult<HermesValue>
hermesInternalIsLazy(void *, Runtime &runtime, NativeArgs args) {
auto callable = args.dyncastArg<Callable>(0);
if (!callable) {
return HermesValue::encodeBoolValue(false);
}

auto codeBlock = getLeafCodeBlock(callable, runtime);
if (!codeBlock) {
// Native function is never lazy.
return HermesValue::encodeBoolValue(false);
}

RuntimeModule *runtimeModule = codeBlock->getRuntimeModule();
return HermesValue::encodeBoolValue(
runtimeModule && runtimeModule->getBytecode()->isLazy());
}

Handle<JSObject> createHermesInternalObject(
Runtime &runtime,
const JSLibFlags &flags) {
Expand Down Expand Up @@ -912,6 +934,7 @@ Handle<JSObject> createHermesInternalObject(
defineInternMethod(
P::copyDataProperties, hermesBuiltinCopyDataProperties, 3);
defineInternMethodAndSymbol("isProxy", hermesInternalIsProxy);
defineInternMethodAndSymbol("isLazy", hermesInternalIsLazy);
defineInternMethod(P::drainJobs, hermesInternalDrainJobs);
}

Expand Down
Loading

0 comments on commit c3d4ed2

Please sign in to comment.