Skip to content

[IRGen] Replace duplicate code with new method #13720

New issue

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

By clicking “No 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? No Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

dtweston
Copy link

@dtweston dtweston commented Jan 4, 2018

This pull request removes duplicated code from GlobalPropertyOpt::isVisibleExternally(), FunctionLivenessComputation::isVisibleExternally() and the static function isAssignableExternally() in LetPropertiesOpts.cpp.

Resolves SR-6264.

lib/AST/Decl.cpp Outdated
AccessLevel access = getEffectiveAccess();
SILLinkage linkage;
switch (access) {
case AccessLevel::Private:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Formatting nit: ‘case’ should have the same level of indenting as ‘switch’ per standard LLVM/Swift project style.

lib/AST/Decl.cpp Outdated
@@ -46,6 +46,7 @@
#include "swift/Basic/Range.h"
#include "swift/Basic/StringExtras.h"
#include "swift/Basic/Statistic.h"
#include "swift/SIL/SILLinkage.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AST should not depend on SIL. Instead, make this a global function in lib/SIL/SIL.cpp.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, that makes sense. I'll rework this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I force updated this change and moved the implementation to lib/SIL/SIL.cpp. include/SIL/SILModule.h seemed to be the best place for this declaration to live, but would it make sense for this to be a member function on SILModule directly?

lib/AST/Decl.cpp Outdated
switch (access) {
case AccessLevel::Private:
case AccessLevel::FilePrivate:
linkage = SILLinkage::Private;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can just fold to 'return false'

lib/AST/Decl.cpp Outdated
linkage = SILLinkage::Private;
break;
case AccessLevel::Internal:
linkage = SILLinkage::Hidden;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is where you return false if isWholeModule, otherwise true

lib/AST/Decl.cpp Outdated
break;
case AccessLevel::Public:
case AccessLevel::Open:
linkage = SILLinkage::Public;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just true

@dtweston
Copy link
Author

@slavapestov, what do you think of the latest version?

return false;
case AccessLevel::Public:
Copy link
Author

@dtweston dtweston Jan 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says we should only consider private members, but it treats public members the same as internal members, which makes me think I'm possibly misunderstanding this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably just an oversight.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok. I think something in this later change broke a SILOptimizer test (global_property_opt.sil), but I wasn't yet able to figure out what it meant.

Here's a gist with the difference: https://gist.github.com/dtweston/1ce13a14a0cadbfe2088aa647ee7a891

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test breakage has gone away, so I think everything's fine now.

case AccessLevel::Private:
break;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The above code also appeared on lines 174 to 185, so it seems redundant to duplicate them here.

@slavapestov
Copy link
Contributor

@dtweston Thank you!

@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@slavapestov slavapestov self-assigned this Jan 12, 2018
lib/SIL/SIL.cpp Outdated
@@ -115,3 +115,18 @@ swift::getLinkageForProtocolConformance(const NormalProtocolConformance *C,
return (definition ? SILLinkage::Public : SILLinkage::PublicExternal);
}
}

bool isDeclVisibleExternally(const ValueDecl *decl, const SILModule *module) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you to qualify the definition here, like bool swift::isDeclVisibleExternally(). CI failed to compile this PR with this error:

Undefined symbols for architecture x86_64:
  "swift::isDeclVisibleExternally(swift::ValueDecl const*, swift::SILModule const*)", referenced from:
      (anonymous namespace)::SILGlobalOpt::run() in libswiftSILOptimizer.a(GlobalOpt.cpp.o)
      (anonymous namespace)::LetPropertiesOptPass::run() in libswiftSILOptimizer.a(LetPropertiesOpts.cpp.o)
      (anonymous namespace)::LetPropertiesOpt::isConstantLetProperty(swift::VarDecl*) in libswiftSILOptimizer.a(LetPropertiesOpts.cpp.o)
      (anonymous namespace)::GlobalPropertyOpt::getFieldEntry(swift::VarDecl*) in libswiftSILOptimizer.a(GlobalPropertyOpt.cpp.o)
      (anonymous namespace)::DeadFunctionElimination::findAnchorsInTables() in libswiftSILOptimizer.a(DeadFunctionElimination.cpp.o)
      isDefaultCaseKnown(swift::ClassHierarchyAnalysis*, swift::FullApplySite, swift::ClassDecl*, llvm::SmallVector<swift::ClassDecl*, 8u>&) in libswiftSILOptimizer.a(SpeculativeDevirtualizer.cpp.o)
      isKnownFinalClass(swift::ClassDecl*, swift::SILModule&, swift::ClassHierarchyAnalysis*) in libswiftSILOptimizer.a(Devirtualize.cpp.o)
      ...
ld: symbol(s) not found for architecture x86_64

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking into this.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed and rebased.

@dtweston
Copy link
Author

@swift-ci Please smoke test

1 similar comment
@slavapestov
Copy link
Contributor

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor

Hi @dtweston, it looks like the devirt-speculate test failure was real -- do you mind investigating?

@jrose-apple
Copy link
Contributor

Closing due to age, but someone else can pick it up.

No Sign up for free to join this conversation on GitHub. Already have an account? No Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants