Skip to content

Commit

Permalink
Simplify Probes evaluation
Browse files Browse the repository at this point in the history
Change-Id: I7e7b8b44483febe4e1911026a0b18deb772c3fca
  • Loading branch information
ABBAPOH committed Jan 5, 2025
1 parent 95f859c commit d89995d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
5 changes: 0 additions & 5 deletions src/lib/corelib/language/evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -525,10 +525,6 @@ static void convertToPropertyType(
ConversionType conversionType,
JSValue &v)
{
if (value->type() == Value::VariantValueType && JS_IsUndefined(v) && !decl.isScalar()) {
v = engine->newArray(0, JsValueOwner::ScriptEngine); // QTBUG-51237
return;
}
convertToPropertyType_impl(
engine,
engine->evaluator()->pathPropertiesBaseDir(),
Expand Down Expand Up @@ -1013,7 +1009,6 @@ static EvalResult getEvalProperty(
*itemOfProperty,
itemOfProperty->propertyDeclaration(name))
.eval();

if (debugProperties)
qDebug() << "[SC] cache miss " << name << ": "
<< resultToString(engine.context(), result);
Expand Down
13 changes: 11 additions & 2 deletions src/lib/corelib/language/language.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,22 @@ bool Probe::needsReconfigure(const FileTime &referenceTime) const
return Internal::any_of(m_importedFilesUsed, criterion);
}

void Probe::restoreValues()
void Probe::restoreValues(const QVariantMap& properties)
{
for (auto it = m_properties.begin(), end = m_properties.end(); it != end; ++it) {
for (auto it = properties.begin(), end = properties.end(); it != end; ++it) {
m_values[it.key()] = VariantValue::createStored(it.value());
}
}

QVariantMap Probe::storeValues() const
{
QVariantMap result;
for (auto it = m_values.begin(), end = m_values.end(); it != end; ++it) {
result[it.key()] = it.value()->value();
}
return result;
}

/*!
* \class SourceArtifact
* \brief The \c SourceArtifact class represents a source file.
Expand Down
17 changes: 8 additions & 9 deletions src/lib/corelib/language/language.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,31 +116,32 @@ class Probe
const CodeLocation &location,
bool condition,
const QString &configureScript,
const QVariantMap &properties,
const QVariantMap &initialProperties,
const QMap<QString, VariantValuePtr> &values,
const std::vector<QString> &importedFilesUsed)
{
return ProbeConstPtr(new Probe(globalId, location, condition, configureScript, properties,
return ProbeConstPtr(new Probe(globalId, location, condition, configureScript,
initialProperties, values, importedFilesUsed));
}

const QString &globalId() const { return m_globalId; }
bool condition() const { return m_condition; }
const CodeLocation &location() const { return m_location; }
const QString &configureScript() const { return m_configureScript; }
const QVariantMap &properties() const { return m_properties; }
const QVariantMap &initialProperties() const { return m_initialProperties; }
const QMap<QString, VariantValuePtr> &values() const { return m_values; }
const std::vector<QString> &importedFilesUsed() const { return m_importedFilesUsed; }
bool needsReconfigure(const FileTime &referenceTime) const;

template<PersistentPool::OpType opType> void completeSerializationOp(PersistentPool &pool)
{
QVariantMap properties;
if constexpr (opType == PersistentPool::OpType::Store)
properties = storeValues();
pool.serializationOp<opType>(m_globalId, m_location, m_condition, m_configureScript,
m_properties, m_initialProperties, m_importedFilesUsed);
properties, m_initialProperties, m_importedFilesUsed);
if constexpr (opType == PersistentPool::OpType::Load)
restoreValues();
restoreValues(properties);
}

private:
Expand All @@ -149,27 +150,25 @@ class Probe
const CodeLocation &location,
bool condition,
QString configureScript,
QVariantMap properties,
QVariantMap initialProperties,
QMap<QString, VariantValuePtr> values,
std::vector<QString> importedFilesUsed)
: m_globalId(std::move(globalId))
, m_location(location)
, m_configureScript(std::move(configureScript))
, m_properties(std::move(properties))
, m_initialProperties(std::move(initialProperties))
, m_values(std::move(values))
, m_importedFilesUsed(std::move(importedFilesUsed))
, m_condition(condition)
{
}

void restoreValues();
void restoreValues(const QVariantMap& properties);
QVariantMap storeValues() const;

QString m_globalId;
CodeLocation m_location;
QString m_configureScript;
QVariantMap m_properties;
QVariantMap m_initialProperties;
QMap<QString, VariantValuePtr> m_values;
std::vector<QString> m_importedFilesUsed;
Expand Down
24 changes: 11 additions & 13 deletions src/lib/corelib/loader/probesresolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,13 +175,16 @@ void ProbesResolver::resolveProbe(ProductContext &productContext, Item *parent,
} else {
importedFilesUsedInConfigure = resolvedProbe->importedFilesUsed();
}
QVariantMap properties;
VariantValuePtr storedValue;
QMap<QString, VariantValuePtr> storedValues;
for (const ProbeProperty &b : probeBindings) {
if (b.first == StringConstants::conditionProperty()
|| b.first == StringConstants::configureProperty())
continue;

QVariant newValue;
if (resolvedProbe) {
newValue = resolvedProbe->properties().value(b.first);
storedValue = resolvedProbe->values().value(b.first);
} else {
if (condition) {
JSValue v = getJsProperty(ctx, configureScope, b.first);
Expand Down Expand Up @@ -216,23 +219,18 @@ void ProbesResolver::resolveProbe(ProductContext &productContext, Item *parent,
} else {
newValue = initialProperties.value(b.first);
}
storedValue = VariantValue::createStored(newValue);
}
if (!qVariantsEqual(newValue, getJsVariant(ctx, b.second))) {
if (!resolvedProbe)
storedValue = VariantValue::createStored(newValue);
else
storedValue = resolvedProbe->values().value(b.first);

if (storedValue) {
probe->setProperty(b.first, storedValue);
}
if (!resolvedProbe) {
properties.insert(b.first, newValue);
storedValues[b.first] = storedValue;
if (!resolvedProbe) {
storedValues[b.first] = storedValue;
}
}
}
if (!resolvedProbe) {
resolvedProbe = Probe::create(probeId, probe->location(), condition,
sourceCode, properties, initialProperties, storedValues,
sourceCode, initialProperties, storedValues,
importedFilesUsedInConfigure);
m_loaderState.topLevelProject().addNewlyResolvedProbe(resolvedProbe);
}
Expand Down

0 comments on commit d89995d

Please sign in to comment.