Skip to content

[flang] Don't emit needless symbols to hermetic module files #144765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions flang/include/flang/Semantics/symbol-dependence.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//===-- include/flang/Semantics/symbol-dependence.h -------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef FORTRAN_SEMANTICS_SYMBOL_DEPENDENCE_H_
#define FORTRAN_SEMANTICS_SYMBOL_DEPENDENCE_H_

#include "flang/Semantics/symbol.h"

namespace Fortran::semantics {

// For a set or scope of symbols, computes the transitive closure of their
// dependences due to their types, bounds, specific procedures, interfaces,
// initialization, storage association, &c. Includes the original symbol
// or members of the original set. Does not include dependences from
// subprogram definitions, only their interfaces.
enum DependenceCollectionFlags {
NoDependenceCollectionFlags = 0,
IncludeOriginalSymbols = 1 << 0,
FollowUseAssociations = 1 << 1,
IncludeSpecificsOfGenerics = 1 << 2,
IncludeUsesOfGenerics = 1 << 3,
NotJustForOneModule = 1 << 4,
};

SymbolVector CollectAllDependences(const SymbolVector &,
int = NoDependenceCollectionFlags, const Scope * = nullptr);
SymbolVector CollectAllDependences(
const Scope &, int = NoDependenceCollectionFlags);

} // namespace Fortran::semantics
#endif // FORTRAN_SEMANTICS_SYMBOL_DEPENDENCE_H_
2 changes: 1 addition & 1 deletion flang/include/flang/Semantics/tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Scope &GetProgramUnitOrBlockConstructContaining(const Symbol &);

const Scope *FindModuleContaining(const Scope &);
const Scope *FindModuleOrSubmoduleContaining(const Scope &);
const Scope *FindModuleFileContaining(const Scope &);
bool IsInModuleFile(const Scope &);
const Scope *FindPureProcedureContaining(const Scope &);
const Scope *FindOpenACCConstructContaining(const Scope *);

Expand Down
1 change: 1 addition & 0 deletions flang/lib/Semantics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ add_flang_library(FortranSemantics
runtime-type-info.cpp
scope.cpp
semantics.cpp
symbol-dependence.cpp
symbol.cpp
tools.cpp
type.cpp
Expand Down
12 changes: 4 additions & 8 deletions flang/lib/Semantics/check-declarations.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,7 @@ class CheckHelper {
}
return msg;
}
bool InModuleFile() const {
return FindModuleFileContaining(context_.FindScope(messages_.at())) !=
nullptr;
}
bool InModuleFile() const { return context_.IsInModuleFile(messages_.at()); }
template <typename FeatureOrUsageWarning, typename... A>
parser::Message *Warn(FeatureOrUsageWarning warning, A &&...x) {
if (!context_.ShouldWarn(warning) || InModuleFile()) {
Expand All @@ -139,8 +136,7 @@ class CheckHelper {
template <typename FeatureOrUsageWarning, typename... A>
parser::Message *Warn(
FeatureOrUsageWarning warning, parser::CharBlock source, A &&...x) {
if (!context_.ShouldWarn(warning) ||
FindModuleFileContaining(context_.FindScope(source))) {
if (!context_.ShouldWarn(warning) || context_.IsInModuleFile(source)) {
return nullptr;
} else {
return messages_.Say(warning, source, std::forward<A>(x)...);
Expand Down Expand Up @@ -4050,7 +4046,7 @@ void DistinguishabilityHelper::Add(const Symbol &generic, GenericKind kind,
}

void DistinguishabilityHelper::Check(const Scope &scope) {
if (FindModuleFileContaining(scope)) {
if (IsInModuleFile(scope)) {
// Distinguishability was checked when the module was created;
// don't let optional warnings then become errors now.
return;
Expand Down Expand Up @@ -4109,7 +4105,7 @@ void DistinguishabilityHelper::SayNotDistinguishable(const Scope &scope,
if (isWarning &&
(!context_.ShouldWarn(
common::LanguageFeature::IndistinguishableSpecifics) ||
FindModuleFileContaining(scope))) {
IsInModuleFile(scope))) {
return;
}
std::string name1{proc1.name().ToString()};
Expand Down
3 changes: 1 addition & 2 deletions flang/lib/Semantics/expression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1852,8 +1852,7 @@ void ArrayConstructorContext::Push(MaybeExpr &&x) {
} else {
if (!(messageDisplayedSet_ & 2)) {
exprAnalyzer_.Say(
"Values in array constructor must have the same declared type "
"when no explicit type appears"_err_en_US); // C7110
"Values in array constructor must have the same declared type when no explicit type appears"_err_en_US); // C7110
messageDisplayedSet_ |= 2;
}
}
Expand Down
Loading
Loading