Skip to content

Commit

Permalink
fix inferring and add some comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mkornaukhov03 committed Nov 7, 2024
1 parent ab0342d commit edc386e
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
2 changes: 1 addition & 1 deletion compiler/code-gen/vertex-compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,7 @@ void compile_func_call(VertexAdaptor<op_func_call> root, CodeGenerator &W, func_
if (auto index = root->args()[0].try_as<op_index>()) {
if (tinf::get_type(index->array())->get_real_ptype() == tp_mixed) {
W << "(" << index->array() << ")";
W << ".empty_on(" << index->key() << ")";
W << ".empty_on(" << index->key() << ")"; // TODO implement optimization with precomputed hash (can_use_precomputed_hash_indexing_array)
return;
}
}
Expand Down
29 changes: 14 additions & 15 deletions compiler/inferring/type-data.cpp
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
// Compiler for PHP (aka KPHP)
// Copyright (c) 2020 LLC «V Kontakte»
// Copyright (c) 2024 LLC «V Kontakte»
// Distributed under the GPL v3 License, see LICENSE.notice.txt

#include "compiler/inferring/type-data.h"

#include "compiler/inferring/primitive-type.h"
#include "compiler/kphp_assert.h"

#include <string>
#include <vector>

#include "common/algorithms/compare.h"
#include "common/algorithms/contains.h"
#include "common/php-functions.h"
#include "common/termformat/termformat.h"

#include "common/php-functions.h"
#include "compiler/compiler-core.h"
#include "compiler/code-gen/common.h"
#include "compiler/compiler-core.h"
#include "compiler/data/class-data.h"
#include "compiler/data/ffi-data.h"
#include "compiler/inferring/primitive-type.h"
#include "compiler/kphp_assert.h"
#include "compiler/pipes/collect-main-edges.h"
#include "compiler/stage.h"
#include "compiler/threading/hash-table.h"
#include "compiler/utils/string-utils.h"


static std::vector<const TypeData *> primitive_types;
static std::vector<const TypeData *> array_types;

Expand Down Expand Up @@ -354,19 +354,14 @@ const TypeData *TypeData::const_read_at(const Key &key) const {
return get_type(tp_string);
}
if (ptype() == tp_Class) {
// TODO any race conditions?
if (!class_type_.empty()) {
auto klass = class_type();

if (auto klass = class_type(); klass) {
ClassPtr aa = G->get_class("ArrayAccess");
assert(aa && "Cannot find ArrayAccess");
kphp_assert_msg(aa, "Internal error: cannot find ArrayAccess interface");

if (aa->is_parent_of(klass)) {
return get_type(tp_mixed);
}
kphp_error(false, fmt_format("Class {} that does not implement \\ArrayAccess", klass->name));
} else {
kphp_fail_msg("class types is empty! =(");
}
}
if (!structured()) {
Expand Down Expand Up @@ -438,8 +433,9 @@ void TypeData::set_lca(const TypeData *rhs, bool save_or_false, bool save_or_nul
PrimitiveType new_ptype = type_lca(lhs->ptype(), rhs->ptype());
if (lhs->ptype_ == tp_array && rhs->ptype_ == tp_Class) {
if (lhs->get_write_flag()) {
// It means that lhs(==this) is something like that "$a[.] = "
new_ptype = tp_Class; // for array access
// `ArrayAccess::offsetSet()` case
// It means that lhs is something like that `$a[*] = foo()`
new_ptype = tp_Class;
}
}
if (new_ptype == tp_mixed) {
Expand Down Expand Up @@ -555,6 +551,9 @@ void TypeData::set_lca_at(const MultiKey &multi_key, const TypeData *rhs, bool s
}

if (cur->get_write_flag()) {
// Access using `multi_key` is storing, not loading
// So, we need to save this info in this node to correctly handle `ArrayAccess::offsetSet()`
// But `cur` is not always pointing to `this`, `write_at()` method in previous loop may reallocate node
this->set_write_flag();
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/inferring/type-inferer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void TypeInferer::recalc_node(Node *node) {
}

void TypeInferer::add_node(Node *node) {
// fprintf (stderr, "tinf::add_node %d %p %s\n", get_thread_id(), node, node->get_description().c_str());
//fprintf (stderr, "tinf::add_node %d %p %s\n", get_thread_id(), node, node->get_description().c_str());
if (!node->was_recalc_started_at_least_once()) {
recalc_node(node);
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/make/make.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ static std::string get_light_runtime_compiler_options() {
for (vk::string_view option : options) {
for (vk::string_view prohibit_substr : black_list_substrings) {
if (vk::contains(option, prohibit_substr)) continue;
s tion << " ";
s << option << " ";
}
}
s << "-std=c++20 ";
Expand Down

0 comments on commit edc386e

Please sign in to comment.