Skip to content

Commit

Permalink
Merge branch 'main' into simon/240605-adopt_hermes_runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
rFlex authored Aug 8, 2024
2 parents 665ece5 + 8d23268 commit d814074
Show file tree
Hide file tree
Showing 47 changed files with 870 additions and 1,341 deletions.
79 changes: 39 additions & 40 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -491,64 +491,63 @@ jobs:
cmake -S hermes -B build -G 'Visual Studio 16 2019'
cmake --build build --target check-hermes -- -m /p:UseMultiToolTask=true -m /p:EnforceProcessCountAcrossBuilds=true
test-e2e:
runs-on: ubuntu-20.04
container:
image: reactnativecommunity/react-native-android:latest
env:
TERM: "dumb"
GRADLE_OPTS: '-Dorg.gradle.daemon=false'
# By default we only build ARM64 to save time/resources. For release/nightlies/prealpha, we override this value to build all archs.
ORG_GRADLE_PROJECT_reactNativeArchitectures: "arm64-v8a"
REACT_NATIVE_OVERRIDE_HERMES_DIR: /__w/hermes/hermes/hermes/
runs-on: ubuntu-22.04
env:
ANDROID_NDK: /usr/local/lib/android/sdk/ndk/26.1.10909125
HERMES_WS_DIR: /home/runner/work/hermes
REACT_NATIVE_OVERRIDE_HERMES_DIR: /home/runner/work/hermes/hermes
steps:
- uses: actions/[email protected]
- name: Setup dependencies
run: |-
(yes | sdkmanager "cmake;3.22.1" --verbose) || true
sudo apt update && sudo apt install -y openjdk-11-jdk
- uses: actions/[email protected]
- name: Install Node
uses: actions/[email protected]
- name: Install JDK
uses: actions/setup-java@v3
with:
path: hermes
- name: Prepare RNTester
distribution: "temurin"
java-version: "17"
- name: Checkout Hermes
uses: actions/[email protected]
- name: Checkout React Native
run: |-
cd "$HERMES_WS_DIR"
git clone --depth=1 https://github.com/facebook/react-native
cd react-native
yarn install
echo "console.log('Using Hermes: ' + (global.HermesInternal != null));" >> packages/rn-tester/js/RNTesterApp.android.js
- name: Run android tests
working-directory: react-native
run: |
./gradlew -PreactNativeArchitectures=x86 :packages:rn-tester:android:app:installHermesRelease
&& adb shell am start com.facebook.react.uiapp/.RNTesterActivity
&& timeout 30s adb logcat -e "Using Hermes: true" -m 1
- name: Run RNTester
uses: ReactiveCircus/[email protected]
with:
api-level: 29
ndk: 26.1.10909125
cmake: 3.22.1
script: |
cd ../react-native && ./gradlew -PreactNativeArchitectures=x86 :packages:rn-tester:android:app:installHermesRelease
adb shell am start com.facebook.react.uiapp/.RNTesterActivity
timeout 30s adb logcat -e "Using Hermes: true" -m 1
test-e2e-intl:
runs-on: ubuntu-20.04
container:
image: reactnativecommunity/react-native-android:latest
env:
TERM: "dumb"
GRADLE_OPTS: '-Dorg.gradle.daemon=false'
# By default we only build ARM64 to save time/resources. For release/nightlies/prealpha, we override this value to build all archs.
ORG_GRADLE_PROJECT_reactNativeArchitectures: "arm64-v8a"
HERMES_WS_DIR: /__w/hermes/hermes/
runs-on: ubuntu-22.04
env:
HERMES_WS_DIR: /home/runner/work/hermes
ANDROID_NDK: /usr/local/lib/android/sdk/ndk/26.1.10909125
steps:
- uses: actions/[email protected]
with:
path: hermes
- name: Setup dependencies
- name: Checkout Hermes
uses: actions/[email protected]
- name: Checkout Test262
run: |-
(yes | sdkmanager "cmake;3.22.1" --verbose) || true
# Check out test262 at a pinned revision to reduce flakiness
cd "$HERMES_WS_DIR"
git clone https://github.com/tc39/test262
cd test262
git checkout 19da3ca0757248f7595ee09d532bb83dd438f2b5
- name: Build Hermes Compiler
run: |-
cd "$HERMES_WS_DIR"
cmake -S hermes -B ./build -DCMAKE_BUILD_TYPE=Release
cmake --build ./build -j 4 --target hermesc
- name: Run android tests
working-directory: hermes/android
run: ./gradlew :intltest:prepareTests && ./gradlew -Pabis=x86 :intltest:connectedAndroidTest
uses: ReactiveCircus/[email protected]
with:
api-level: 29
emulator-options: -timezone Europe/Paris -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
script: cd android && ./gradlew :intltest:prepareTests && ./gradlew -Pabis=x86 :intltest:connectedAndroidTest
test-macos-test262:
runs-on: macos-latest
steps:
Expand Down
4 changes: 2 additions & 2 deletions API/hermes/cdp/RemoteObjectConverters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ static m::runtime::ObjectPreview generateArrayPreview(
try {
desc = generatePropertyPreview(
runtime, indexString, obj.getValueAtIndex(runtime, i));
} catch (const jsi::JSError &err) {
} catch (const jsi::JSError &) {
desc.name = indexString;
desc.type = "string";
desc.value = "<Exception>";
Expand Down Expand Up @@ -120,7 +120,7 @@ static m::runtime::ObjectPreview generateObjectPreview(
// Chrome instead detects getters and makes you click to invoke.
desc = generatePropertyPreview(
runtime, propName.utf8(runtime), obj.getProperty(runtime, propName));
} catch (const jsi::JSError &err) {
} catch (const jsi::JSError &) {
desc.name = propName.utf8(runtime);
desc.type = "string";
desc.value = "<Exception>";
Expand Down
4 changes: 2 additions & 2 deletions API/hermes/cdp/RuntimeDomainAgent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ void RuntimeDomainAgent::callFunctionOn(
evalResult = runtime_.evaluateJavaScript(
std::unique_ptr<jsi::StringBuffer>(new jsi::StringBuffer(expression)),
kEvaluatedCodeUrl);
} catch (const jsi::JSIException &error) {
} catch (const jsi::JSIException &) {
sendResponseToClient(m::makeErrorResponse(
req.id,
m::ErrorCode::InternalError,
Expand Down Expand Up @@ -883,7 +883,7 @@ RuntimeDomainAgent::makePropsFromValue(
desc.wasThrown = true;
desc.value = m::runtime::makeRemoteObjectForError(
runtime, err.value(), *objTable_, objectGroup);
} catch (const jsi::JSIException &err) {
} catch (const jsi::JSIException &) {
desc.wasThrown = true;
desc.value = m::runtime::makeRemoteObject(
runtime,
Expand Down
2 changes: 1 addition & 1 deletion API/hermes/inspector/chrome/CDPHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1711,7 +1711,7 @@ std::vector<m::runtime::PropertyDescriptor> CDPHandlerImpl::makePropsFromValue(
jsi::Value propValue = obj.getProperty(runtime, propName);
desc.value = m::runtime::makeRemoteObject(
runtime, propValue, objTable_, objectGroup, false, generatePreview);
} catch (const jsi::JSError &err) {
} catch (const jsi::JSError &) {
// We fetched a property with a getter that threw. Show a placeholder.
// We could have added additional info, but the UI quickly gets messy.
desc.value = m::runtime::makeRemoteObject(
Expand Down
4 changes: 2 additions & 2 deletions API/hermes/inspector/chrome/RemoteObjectConverters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ static m::runtime::ObjectPreview generateArrayPreview(
try {
desc = generatePropertyPreview(
runtime, indexString, obj.getValueAtIndex(runtime, i));
} catch (const jsi::JSError &err) {
} catch (const jsi::JSError &) {
desc.name = indexString;
desc.type = "string";
desc.value = "<Exception>";
Expand Down Expand Up @@ -121,7 +121,7 @@ static m::runtime::ObjectPreview generateObjectPreview(
// Chrome instead detects getters and makes you click to invoke.
desc = generatePropertyPreview(
runtime, propName.utf8(runtime), obj.getProperty(runtime, propName));
} catch (const jsi::JSError &err) {
} catch (const jsi::JSError &) {
desc.name = propName.utf8(runtime);
desc.type = "string";
desc.value = "<Exception>";
Expand Down
2 changes: 1 addition & 1 deletion API/hermes/inspector/chrome/tests/ConnectionTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2793,7 +2793,7 @@ TEST_F(ConnectionTests, testConsoleBuffer) {
EXPECT_EQ(note.type, "log");
EXPECT_EQ(note.args.size(), 1);
received[nthLog % kExpectedMaxBufferSize] = true;
} catch (const std::exception &e) {
} catch (const std::exception &) {
EXPECT_EQ(note.type, "warning");
EXPECT_EQ(note.args.size(), 1);
EXPECT_NE((*note.args[0].value).find("discarded"), std::string::npos);
Expand Down
6 changes: 3 additions & 3 deletions include/hermes/BCGen/RegAlloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,9 @@ class RegisterAllocator {
/// predecessor blocks.
void lowerPhis(ArrayRef<BasicBlock *> order);

/// Allocate the registers for the instructions in the function. The order of
/// the block needs to match the order which we'll use for instruction
/// selection.
/// Allocate the registers for the instructions in the function. The blocks
/// must be in reverse-post-order, and must match the order which we'll use
/// for instruction selection.
void allocate(ArrayRef<BasicBlock *> order);

/// Reserves consecutive registers that will be manually managed by the user.
Expand Down
16 changes: 14 additions & 2 deletions include/hermes/VM/GCBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -971,12 +971,24 @@ class GCBase {
/// \return An error code on failure, else an empty error code.
std::error_code createSnapshotToFile(const std::string &fileName);

/// An edges counter array for each root section. The counter is uninitialized
/// if a root section is not visited yet.
using SavedNumRootEdges = std::array<
llvh::Optional<HeapSizeType>,
static_cast<unsigned>(RootSectionAcceptor::Section::NumSections)>;

/// Creates a snapshot of the heap, which includes information about what
/// objects exist, their sizes, and what they point to.
virtual void createSnapshot(llvh::raw_ostream &os) = 0;
void createSnapshot(GC &gc, llvh::raw_ostream &os);
/// Actual implementation of writing the snapshot.
void createSnapshotImpl(GC &gc, HeapSnapshot &snap);
/// Actual implementation of writing the snapshot. If \p numRootEdges is
// uninitialized, it will be populated with the edge counts for each root
// section. Otherwise, it will be used to pad the output with additional edges
// if necessary so they match the recorded count.
void createSnapshotImpl(
GC &gc,
HeapSnapshot &snap,
SavedNumRootEdges &numRootEdges);

/// Subclasses can override and add more specific native memory usage.
virtual void snapshotAddGCNativeNodes(HeapSnapshot &snap);
Expand Down
4 changes: 4 additions & 0 deletions include/hermes/VM/HeapSnapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ class HeapSnapshot {
EdgeIndex getEdgeCount() const {
return edgeCount_;
}
/// Get the number of edges for the current node.
HeapSizeType getCurEdgeCount() const {
return currEdgeCount_;
}
/// Get the trace function count for stackTracesTree_.
size_t getTraceFunctionCount() const {
return traceFunctionCount_;
Expand Down
89 changes: 60 additions & 29 deletions lib/BCGen/RegAlloc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -535,19 +535,6 @@ void RegisterAllocator::coalesce(
}
}

namespace {
/// Determines whether the Instruction is ever used outside its BasicBlock.
bool isBlockLocal(Instruction *inst) {
BasicBlock *parent = inst->getParent();
for (auto user : inst->getUsers()) {
if (parent != user->getParent()) {
return false;
}
}
return true;
}
} // namespace

void RegisterAllocator::allocateFastPass(ArrayRef<BasicBlock *> order) {
// Make sure Phis and related Movs get the same register
for (auto *bb : order) {
Expand All @@ -563,26 +550,70 @@ void RegisterAllocator::allocateFastPass(ArrayRef<BasicBlock *> order) {
}
}

llvh::SmallVector<Register, 16> blockLocals;
// Bit vector indicating whether a register with a given index is being used
// as a block local register.
llvh::BitVector blockLocals;

// List of free block local registers. We have to maintain this outside the
// file because we cannot determine interference between local and global
// registers. So we have to ensure that the local registers are only reused
// for other block-local instructions.
llvh::SmallVector<Register, 8> freeBlockLocals;

// A dummy register used for all instructions that have no users.
Register deadReg = file.allocateRegister();

// Iterate in reverse, so we can cheaply determine whether an instruction
// is local, and assign it a register accordingly.
for (auto *bb : llvh::reverse(order)) {
for (auto &inst : llvh::reverse(*bb)) {
if (isAllocated(&inst)) {
// If this is using a local register, we know the register is free after
// we visit the definition.
auto reg = getRegister(&inst);
auto idx = reg.getIndex();
if (idx < blockLocals.size() && blockLocals.test(idx))
freeBlockLocals.push_back(reg);
} else {
// Unallocated instruction means the result is dead, because all users
// are visited first. Allocate a temporary register.
// Note that we cannot assert that the instruction has no users, because
// there may be users in dead blocks.
updateRegister(&inst, deadReg);
}

// Then just allocate the rest sequentially, while optimizing the case
// where an inst is only ever used in its own block.
for (auto *bb : order) {
for (auto &inst : *bb) {
if (!isAllocated(&inst)) {
Register R = file.allocateRegister();
updateRegister(&inst, R);
if (inst.getNumUsers() == 0) {
file.killRegister(R);
} else if (isBlockLocal(&inst)) {
blockLocals.push_back(R);
// Allocate a register to unallocated operands.
for (size_t i = 0, e = inst.getNumOperands(); i < e; ++i) {
auto *op = llvh::dyn_cast<Instruction>(inst.getOperand(i));

// Skip if op is not an instruction or already has a register.
if (!op || isAllocated(op))
continue;

if (op->getParent() != bb) {
// Live across blocks, allocate a global regigster.
updateRegister(op, file.allocateRegister());
continue;
}

// We know this operand is local because:
// 1. The operand is in the same block as this one.
// 2. All blocks dominated by this block have been visited.
// 3. All users must be dominated by their def, since Phis are
// allocated beforehand.
if (!freeBlockLocals.empty()) {
updateRegister(op, freeBlockLocals.pop_back_val());
continue;
}

// No free local register, allocate another one.
Register reg = file.allocateRegister();
if (blockLocals.size() <= reg.getIndex())
blockLocals.resize(reg.getIndex() + 1);
blockLocals.set(reg.getIndex());
updateRegister(op, reg);
}
}
for (auto &reg : blockLocals) {
file.killRegister(reg);
}
blockLocals.clear();
}
}

Expand Down
3 changes: 3 additions & 0 deletions lib/Parser/rust-api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -608,14 +608,17 @@ hermes_parser_parse(ParserFlags flags, const char *source, size_t len) {
break;
case ParserDialect::Flow:
parserCtx->context_.setParseFlow(hermes::ParseFlowSetting::ALL);
parserCtx->context_.setParseFlowComponentSyntax(true);
break;
case ParserDialect::FlowUnambiguous:
parserCtx->context_.setParseFlow(hermes::ParseFlowSetting::UNAMBIGUOUS);
parserCtx->context_.setParseFlowComponentSyntax(true);
break;
case ParserDialect::FlowDetect:
parserCtx->context_.setParseFlow(
parser::hasFlowPragma(comments) ? ParseFlowSetting::ALL
: ParseFlowSetting::UNAMBIGUOUS);
parserCtx->context_.setParseFlowComponentSyntax(true);
break;
case ParserDialect::TypeScript:
parserCtx->context_.setParseTS(true);
Expand Down
Loading

0 comments on commit d814074

Please sign in to comment.