Skip to content

Commit

Permalink
Version 3.5.0-203.0.dev
Browse files Browse the repository at this point in the history
Merge 698bf08 into dev
  • Loading branch information
Dart CI committed May 29, 2024
2 parents c50505c + 698bf08 commit ef405fb
Show file tree
Hide file tree
Showing 30 changed files with 92 additions and 111 deletions.
3 changes: 1 addition & 2 deletions pkg/dart2wasm/lib/target.dart
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,7 @@ class WasmTarget extends Target {
logger?.call("Transformed ffi annotations");
}

wasmTrans.transformLibraries(
libraries, coreTypes, hierarchy, diagnosticReporter);
wasmTrans.transformLibraries(libraries, coreTypes, hierarchy);

awaitTrans.transformLibraries(libraries, hierarchy, coreTypes);
}
Expand Down
14 changes: 5 additions & 9 deletions pkg/dart2wasm/lib/transformers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,27 @@
import 'package:kernel/ast.dart';
import 'package:kernel/class_hierarchy.dart';
import 'package:kernel/core_types.dart';
import 'package:kernel/target/targets.dart';
import 'package:kernel/type_algebra.dart';
import 'package:kernel/type_environment.dart';
import 'package:vm/modular/transformations/type_casts_optimizer.dart'
as typeCastsOptimizer show transformAsExpression;

import 'list_factory_specializer.dart';

void transformLibraries(List<Library> libraries, CoreTypes coreTypes,
ClassHierarchy hierarchy, DiagnosticReporter diagnosticReporter) {
final transformer =
_WasmTransformer(coreTypes, hierarchy, diagnosticReporter);
void transformLibraries(
List<Library> libraries, CoreTypes coreTypes, ClassHierarchy hierarchy) {
final transformer = _WasmTransformer(coreTypes, hierarchy);
libraries.forEach(transformer.visitLibrary);
}

void transformProcedure(
Procedure procedure, CoreTypes coreTypes, ClassHierarchy hierarchy) {
final transformer = _WasmTransformer(coreTypes, hierarchy, null);
final transformer = _WasmTransformer(coreTypes, hierarchy);
procedure.accept(transformer);
}

class _WasmTransformer extends Transformer {
final TypeEnvironment env;
final DiagnosticReporter? diagnosticReporter;

Member? _currentMember;
StaticTypeContext? _cachedTypeContext;
Expand Down Expand Up @@ -67,8 +64,7 @@ class _WasmTransformer extends Transformer {

CoreTypes get coreTypes => env.coreTypes;

_WasmTransformer(
CoreTypes coreTypes, ClassHierarchy hierarchy, this.diagnosticReporter)
_WasmTransformer(CoreTypes coreTypes, ClassHierarchy hierarchy)
: env = TypeEnvironment(coreTypes, hierarchy),
_nonNullableTypeType = coreTypes.index
.getClass('dart:core', '_Type')
Expand Down
11 changes: 5 additions & 6 deletions runtime/bin/dartdev_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,30 +79,29 @@ bool DartDevIsolate::ShouldParseCommand(const char* script_uri) {
(strncmp(script_uri, "google3://", 10) != 0)));
}

Utils::CStringUniquePtr DartDevIsolate::TryResolveArtifactPath(
const char* filename) {
CStringUniquePtr DartDevIsolate::TryResolveArtifactPath(const char* filename) {
// |dir_prefix| includes the last path separator.
auto dir_prefix = EXEUtils::GetDirectoryPrefixFromExeName();

// First assume we're in dart-sdk/bin.
char* snapshot_path =
Utils::SCreate("%ssnapshots/%s", dir_prefix.get(), filename);
if (File::Exists(nullptr, snapshot_path)) {
return Utils::CreateCStringUniquePtr(snapshot_path);
return CStringUniquePtr(snapshot_path);
}
free(snapshot_path);

// If we're not in dart-sdk/bin, we might be in one of the $SDK/out/*
// directories. Try to use a snapshot from a previously built SDK.
snapshot_path = Utils::SCreate("%s%s", dir_prefix.get(), filename);
if (File::Exists(nullptr, snapshot_path)) {
return Utils::CreateCStringUniquePtr(snapshot_path);
return CStringUniquePtr(snapshot_path);
}
free(snapshot_path);
return Utils::CreateCStringUniquePtr(nullptr);
return CStringUniquePtr(nullptr);
}

Utils::CStringUniquePtr DartDevIsolate::TryResolveDartDevSnapshotPath() {
CStringUniquePtr DartDevIsolate::TryResolveDartDevSnapshotPath() {
return TryResolveArtifactPath("dartdev.dart.snapshot");
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/bin/dartdev_isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class DartDevIsolate {
static bool should_run_dart_dev() { return should_run_dart_dev_; }

// Attempts to find the path of the DartDev snapshot.
static Utils::CStringUniquePtr TryResolveDartDevSnapshotPath();
static CStringUniquePtr TryResolveDartDevSnapshotPath();

// Starts a DartDev instance in a new isolate and runs it to completion.
//
Expand Down Expand Up @@ -93,7 +93,7 @@ class DartDevIsolate {
};

private:
static Utils::CStringUniquePtr TryResolveArtifactPath(const char* filename);
static CStringUniquePtr TryResolveArtifactPath(const char* filename);

static DartDevRunner runner_;
static bool should_run_dart_dev_;
Expand Down
4 changes: 2 additions & 2 deletions runtime/bin/dfe.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,13 +178,13 @@ class KernelBlob {
public:
// Takes ownership over [uri] and [buffer].
KernelBlob(char* uri, uint8_t* buffer, intptr_t size)
: uri_(uri, std::free), buffer_(buffer, std::free), size_(size) {}
: uri_(uri), buffer_(buffer, std::free), size_(size) {}

std::shared_ptr<uint8_t> buffer() { return buffer_; }
intptr_t size() const { return size_; }

private:
Utils::CStringUniquePtr uri_;
CStringUniquePtr uri_;
std::shared_ptr<uint8_t> buffer_;
const intptr_t size_;

Expand Down
10 changes: 4 additions & 6 deletions runtime/bin/exe_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ static const char* GetFileNameFromPath(const char* path) {
return path;
}

Utils::CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
const char* name = nullptr;
const int kTargetSize = PATH_MAX;
char target[kTargetSize];
Expand All @@ -87,8 +87,7 @@ Utils::CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
// cwd is currently wherever we launched from, so set the cwd to the
// directory of the symlink while we try and resolve it. If we don't
// do this, we won't be able to properly resolve relative paths.
auto initial_dir_path =
Utils::CreateCStringUniquePtr(Directory::CurrentNoScope());
CStringUniquePtr initial_dir_path(Directory::CurrentNoScope());
// We might run into symlinks of symlinks, so make sure we follow the
// links all the way. See https://github.com/dart-lang/sdk/issues/41057 for
// an example where this happens with brew on MacOS.
Expand All @@ -98,7 +97,7 @@ Utils::CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
name = File::LinkTarget(namespc, GetFileNameFromPath(name), target,
kTargetSize);
if (name == nullptr) {
return Utils::CreateCStringUniquePtr(Utils::StrDup(""));
return CStringUniquePtr(Utils::StrDup(""));
}
} while (File::GetType(namespc, name, false) == File::kIsLink);
target_size = strlen(name);
Expand All @@ -117,8 +116,7 @@ Utils::CStringUniquePtr EXEUtils::GetDirectoryPrefixFromExeName() {
result = GetDirectoryFromPath(target, nullptr);
}
namespc->Release();
return Utils::CreateCStringUniquePtr(result == nullptr ? Utils::StrDup("")
: result);
return CStringUniquePtr(result == nullptr ? Utils::StrDup("") : result);
}

#if !defined(DART_HOST_OS_WINDOWS)
Expand Down
2 changes: 1 addition & 1 deletion runtime/bin/exe_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace bin {
class EXEUtils {
public:
// Returns the path to the directory the current executable resides in.
static Utils::CStringUniquePtr GetDirectoryPrefixFromExeName();
static CStringUniquePtr GetDirectoryPrefixFromExeName();

#if !defined(DART_HOST_OS_WINDOWS)
// Loads a compact symbolization table from "$exepath.sym" that is used by the
Expand Down
2 changes: 1 addition & 1 deletion runtime/bin/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ class File : public ReferenceCounted<File> {
static File* OpenUri(Namespace* namespc, const char* uri, FileOpenMode mode);

// Attempts to convert the given [uri] to a file path.
static Utils::CStringUniquePtr UriToPath(const char* uri);
static CStringUniquePtr UriToPath(const char* uri);

// Create a file object for the specified stdio file descriptor
// (stdin, stout or stderr).
Expand Down
6 changes: 3 additions & 3 deletions runtime/bin/file_fuchsia.cc
Original file line number Diff line number Diff line change
Expand Up @@ -253,15 +253,15 @@ File* File::Open(Namespace* namespc, const char* name, FileOpenMode mode) {
return OpenFD(fd);
}

Utils::CStringUniquePtr File::UriToPath(const char* uri) {
CStringUniquePtr File::UriToPath(const char* uri) {
const char* path =
(strlen(uri) >= 8 && strncmp(uri, "file:///", 8) == 0) ? uri + 7 : uri;
UriDecoder uri_decoder(path);
if (uri_decoder.decoded() == nullptr) {
errno = EINVAL;
return Utils::CreateCStringUniquePtr(nullptr);
return CStringUniquePtr(nullptr);
}
return Utils::CreateCStringUniquePtr(strdup(uri_decoder.decoded()));
return CStringUniquePtr(strdup(uri_decoder.decoded()));
}

File* File::OpenUri(Namespace* namespc, const char* uri, FileOpenMode mode) {
Expand Down
6 changes: 3 additions & 3 deletions runtime/bin/file_linux.cc
Original file line number Diff line number Diff line change
Expand Up @@ -265,15 +265,15 @@ File* File::Open(Namespace* namespc, const char* name, FileOpenMode mode) {
return OpenFD(fd);
}

Utils::CStringUniquePtr File::UriToPath(const char* uri) {
CStringUniquePtr File::UriToPath(const char* uri) {
const char* path =
(strlen(uri) >= 8 && strncmp(uri, "file:///", 8) == 0) ? uri + 7 : uri;
UriDecoder uri_decoder(path);
if (uri_decoder.decoded() == nullptr) {
errno = EINVAL;
return Utils::CreateCStringUniquePtr(nullptr);
return CStringUniquePtr(nullptr);
}
return Utils::CreateCStringUniquePtr(strdup(uri_decoder.decoded()));
return CStringUniquePtr(strdup(uri_decoder.decoded()));
}

File* File::OpenUri(Namespace* namespc, const char* uri, FileOpenMode mode) {
Expand Down
6 changes: 3 additions & 3 deletions runtime/bin/file_macos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,15 @@ File* File::Open(Namespace* namespc, const char* name, FileOpenMode mode) {
return new File(new FileHandle(fd));
}

Utils::CStringUniquePtr File::UriToPath(const char* uri) {
CStringUniquePtr File::UriToPath(const char* uri) {
const char* path =
(strlen(uri) >= 8 && strncmp(uri, "file:///", 8) == 0) ? uri + 7 : uri;
UriDecoder uri_decoder(path);
if (uri_decoder.decoded() == nullptr) {
errno = EINVAL;
return Utils::CreateCStringUniquePtr(nullptr);
return CStringUniquePtr(nullptr);
}
return Utils::CreateCStringUniquePtr(strdup(uri_decoder.decoded()));
return CStringUniquePtr(strdup(uri_decoder.decoded()));
}

File* File::OpenUri(Namespace* namespc, const char* uri, FileOpenMode mode) {
Expand Down
8 changes: 4 additions & 4 deletions runtime/bin/file_win.cc
Original file line number Diff line number Diff line change
Expand Up @@ -447,23 +447,23 @@ File* File::Open(Namespace* namespc, const char* name, FileOpenMode mode) {
return file;
}

Utils::CStringUniquePtr File::UriToPath(const char* uri) {
CStringUniquePtr File::UriToPath(const char* uri) {
UriDecoder uri_decoder(uri);
if (uri_decoder.decoded() == nullptr) {
SetLastError(ERROR_INVALID_NAME);
return Utils::CreateCStringUniquePtr(nullptr);
return CStringUniquePtr(nullptr);
}

const auto uri_w = Utf8ToWideChar(uri_decoder.decoded());
if (!UrlIsFileUrlW(uri_w.get())) {
return Utils::CreateCStringUniquePtr(Utils::StrDup(uri_decoder.decoded()));
return CStringUniquePtr(Utils::StrDup(uri_decoder.decoded()));
}
wchar_t filename_w[MAX_PATH];
DWORD filename_len = MAX_PATH;
HRESULT result = PathCreateFromUrlW(uri_w.get(), filename_w, &filename_len,
/* dwFlags= */ 0);
if (result != S_OK) {
return Utils::CreateCStringUniquePtr(nullptr);
return CStringUniquePtr(nullptr);
}

WideToUtf8Scope utf8_path(filename_w);
Expand Down
5 changes: 2 additions & 3 deletions runtime/bin/snapshot_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ bool Snapshot::IsPEFormattedBinary(const char* filename) {
AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_uri,
bool force_load_elf_from_memory,
bool decode_uri) {
Utils::CStringUniquePtr decoded_path(nullptr, std::free);
CStringUniquePtr decoded_path(nullptr);
const char* script_name = nullptr;
if (decode_uri) {
decoded_path = File::UriToPath(script_uri);
Expand Down Expand Up @@ -636,8 +636,7 @@ AppSnapshot* Snapshot::TryReadAppSnapshot(const char* script_uri,
#if defined(DART_TARGET_OS_LINUX) || defined(DART_TARGET_OS_MACOS)
// On Linux and OSX, resolve the script path before passing into dlopen()
// since dlopen will not search the filesystem for paths like 'libtest.so'.
std::unique_ptr<char, decltype(std::free)*> absolute_path{
realpath(script_name, nullptr), std::free};
CStringUniquePtr absolute_path(realpath(script_name, nullptr));
script_name = absolute_path.get();
#endif

Expand Down
8 changes: 4 additions & 4 deletions runtime/bin/utils_win.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,24 @@ class StringUtilsWin {
class WideToUtf8Scope {
public:
explicit WideToUtf8Scope(const wchar_t* wide)
: utf8_(Utils::CreateCStringUniquePtr(nullptr)) {
: utf8_(CStringUniquePtr(nullptr)) {
intptr_t utf8_len =
WideCharToMultiByte(CP_UTF8, 0, wide, -1, nullptr, 0, nullptr, nullptr);
char* utf8 = reinterpret_cast<char*>(malloc(utf8_len));
WideCharToMultiByte(CP_UTF8, 0, wide, -1, utf8, utf8_len, nullptr, nullptr);
length_ = utf8_len;
utf8_ = Utils::CreateCStringUniquePtr(utf8);
utf8_.reset(utf8);
}

char* utf8() const { return utf8_.get(); }
intptr_t length() const { return length_; }

// Release the ownership of the converted string and return it.
Utils::CStringUniquePtr release() { return std::move(utf8_); }
CStringUniquePtr release() { return std::move(utf8_); }

private:
intptr_t length_;
Utils::CStringUniquePtr utf8_;
CStringUniquePtr utf8_;

DISALLOW_ALLOCATION();
DISALLOW_IMPLICIT_CONSTRUCTORS(WideToUtf8Scope);
Expand Down
4 changes: 0 additions & 4 deletions runtime/platform/utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,6 @@ char* Utils::VSCreate(const char* format, va_list args) {
return buffer;
}

Utils::CStringUniquePtr Utils::CreateCStringUniquePtr(char* str) {
return std::unique_ptr<char, decltype(std::free)*>{str, std::free};
}

static void GetLastErrorAsString(char** error) {
if (error == nullptr) return; // Nothing to do.

Expand Down
16 changes: 11 additions & 5 deletions runtime/platform/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@

namespace dart {

template <typename T>
class CAllocUniquePtr : public std::unique_ptr<T, decltype(std::free)*> {
public:
CAllocUniquePtr()
: std::unique_ptr<T, decltype(std::free)*>(nullptr, std::free) {}
explicit CAllocUniquePtr(T* value)
: std::unique_ptr<T, decltype(std::free)*>(value, std::free) {}
};

using CStringUniquePtr = CAllocUniquePtr<char>;

class Utils {
public:
template <typename T>
Expand Down Expand Up @@ -641,11 +652,6 @@ class Utils {
static char* SCreate(const char* format, ...) PRINTF_ATTRIBUTE(1, 2);
static char* VSCreate(const char* format, va_list args);

typedef std::unique_ptr<char, decltype(std::free)*> CStringUniquePtr;

// Returns str in a unique_ptr with free used as its deleter.
static CStringUniquePtr CreateCStringUniquePtr(char* str);

// Load dynamic library from the given |library_path| and return the
// library handle. |library_path| can be |nullptr| in which case
// library handle representing the executable is returned.
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/compiler/backend/il_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -764,7 +764,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_LoadThread) {
#if !defined(TARGET_ARCH_IA32)
ISOLATE_UNIT_TEST_CASE(IRTest_CachableIdempotentCall) {
// clang-format off
auto kScript = Utils::CStringUniquePtr(OS::SCreate(nullptr, R"(
CStringUniquePtr kScript(OS::SCreate(nullptr, R"(
int globalCounter = 0;

int increment() => ++globalCounter;
Expand All @@ -785,7 +785,7 @@ ISOLATE_UNIT_TEST_CASE(IRTest_CachableIdempotentCall) {
}
return returnValue;
}
)"), std::free);
)"));
// clang-format on

const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/compiler/backend/memory_copy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ static void RunMemoryCopyInstrTest(intptr_t src_start,
OS::Print("&ptr %p &ptr2 %p\n", ptr, ptr2);

// clang-format off
auto kScript = Utils::CStringUniquePtr(OS::SCreate(nullptr, R"(
CStringUniquePtr kScript(OS::SCreate(nullptr, R"(
import 'dart:ffi';
void copyConst() {
Expand Down Expand Up @@ -182,7 +182,7 @@ static void RunMemoryCopyInstrTest(intptr_t src_start,
int length) {}
)", pointer_prefix, ptr, pointer_prefix, ptr2,
pointer_prefix, ptr, pointer_prefix, ptr2,
src_start, dest_start, length), std::free);
src_start, dest_start, length));
// clang-format on

const auto& root_library = Library::Handle(LoadTestScript(kScript.get()));
Expand Down
Loading

0 comments on commit ef405fb

Please sign in to comment.