[flang-commits] [flang] a94083b - [flang] Break shared library cyclic dependence

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Fri Mar 10 11:29:08 PST 2023


Author: Peter Klausler
Date: 2023-03-10T11:28:58-08:00
New Revision: a94083b511eea13826bde466ffee2c4fcbcec3ea

URL: https://github.com/llvm/llvm-project/commit/a94083b511eea13826bde466ffee2c4fcbcec3ea
DIFF: https://github.com/llvm/llvm-project/commit/a94083b511eea13826bde466ffee2c4fcbcec3ea.diff

LOG: [flang] Break shared library cyclic dependence

I inadvertently introduced a cycle of dependences between the Evaluate
and Semantics libraries; this patch breaks that cycle and reenables
the flang build bots that rely on shared library builds.

Added: 
    

Modified: 
    flang/lib/Evaluate/type.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Evaluate/type.cpp b/flang/lib/Evaluate/type.cpp
index acedf59328c2..4cc1cb173f22 100644
--- a/flang/lib/Evaluate/type.cpp
+++ b/flang/lib/Evaluate/type.cpp
@@ -262,6 +262,71 @@ static bool AreSameComponent(const semantics::Symbol &x,
       y.has<semantics::ObjectEntityDetails>();
 }
 
+// TODO: These utilities were cloned out of Semantics to avoid a cyclic
+// dependency and should be repackaged into then "namespace semantics"
+// part of Evaluate/tools.cpp.
+
+static const semantics::Symbol *GetParentComponent(
+    const semantics::DerivedTypeDetails &details,
+    const semantics::Scope &scope) {
+  if (auto extends{details.GetParentComponentName()}) {
+    if (auto iter{scope.find(*extends)}; iter != scope.cend()) {
+      if (const Symbol & symbol{*iter->second};
+          symbol.test(semantics::Symbol::Flag::ParentComp)) {
+        return &symbol;
+      }
+    }
+  }
+  return nullptr;
+}
+
+static const semantics::Symbol *GetParentComponent(
+    const semantics::Symbol *symbol, const semantics::Scope &scope) {
+  if (symbol) {
+    if (const auto *dtDetails{
+            symbol->detailsIf<semantics::DerivedTypeDetails>()}) {
+      return GetParentComponent(*dtDetails, scope);
+    }
+  }
+  return nullptr;
+}
+
+static const semantics::DerivedTypeSpec *GetParentTypeSpec(
+    const semantics::Symbol *symbol, const semantics::Scope &scope) {
+  if (const Symbol * parentComponent{GetParentComponent(symbol, scope)}) {
+    return &parentComponent->get<semantics::ObjectEntityDetails>()
+                .type()
+                ->derivedTypeSpec();
+  } else {
+    return nullptr;
+  }
+}
+
+static const semantics::Scope *GetDerivedTypeParent(
+    const semantics::Scope *scope) {
+  if (scope) {
+    CHECK(scope->IsDerivedType());
+    if (const auto *parent{GetParentTypeSpec(scope->GetSymbol(), *scope)}) {
+      return parent->scope();
+    }
+  }
+  return nullptr;
+}
+
+static const semantics::Symbol *FindComponent(
+    const semantics::Scope *scope, parser::CharBlock name) {
+  if (!scope) {
+    return nullptr;
+  }
+  CHECK(scope->IsDerivedType());
+  auto found{scope->find(name)};
+  if (found != scope->end()) {
+    return &*found->second;
+  } else {
+    return FindComponent(GetDerivedTypeParent(scope), name);
+  }
+}
+
 static bool AreTypeParamCompatible(const semantics::DerivedTypeSpec &x,
     const semantics::DerivedTypeSpec &y, bool ignoreLenParameters) {
   const auto *xScope{x.typeSymbol().scope()};
@@ -271,8 +336,8 @@ static bool AreTypeParamCompatible(const semantics::DerivedTypeSpec &x,
     if (!yValue) {
       return false;
     }
-    const auto *xParm{xScope ? xScope->FindComponent(paramName) : nullptr};
-    const auto *yParm{yScope ? yScope->FindComponent(paramName) : nullptr};
+    const auto *xParm{FindComponent(xScope, paramName)};
+    const auto *yParm{FindComponent(yScope, paramName)};
     if (xParm && yParm) {
       const auto *xTPD{xParm->detailsIf<semantics::TypeParamDetails>()};
       const auto *yTPD{yParm->detailsIf<semantics::TypeParamDetails>()};


        


More information about the flang-commits mailing list