Skip to content

[Frontend] Generate an interface hash for emit-module-separately jobs #38939

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

Merged
merged 1 commit into from
Aug 19, 2021
Merged
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
9 changes: 5 additions & 4 deletions lib/Frontend/Frontend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1156,10 +1156,10 @@ CompilerInstance::getSourceFileParsingOptions(bool forPrimary) const {
opts |= SourceFile::ParsingFlags::DisableDelayedBodies;
}

auto typeOpts = getASTContext().TypeCheckerOpts;
if (forPrimary || isWholeModuleCompilation()) {
// Disable delayed body parsing for primaries and in WMO, unless
// forcefully skipping function bodies
auto typeOpts = getASTContext().TypeCheckerOpts;
if (typeOpts.SkipFunctionBodies == FunctionBodySkipping::None)
opts |= SourceFile::ParsingFlags::DisableDelayedBodies;
} else {
Expand All @@ -1168,9 +1168,10 @@ CompilerInstance::getSourceFileParsingOptions(bool forPrimary) const {
opts |= SourceFile::ParsingFlags::SuppressWarnings;
}

// Enable interface hash computation for primaries, but not in WMO, as it's
// only currently needed for incremental mode.
if (forPrimary) {
// Enable interface hash computation for primaries or emit-module-separately,
// but not in WMO, as it's only currently needed for incremental mode.
if (forPrimary ||
typeOpts.SkipFunctionBodies == FunctionBodySkipping::NonInlinableWithoutTypes) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we use FrontOptions::ActionType::EmitModuleOnly here instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can if we don't mind turning on interface hashing in some non-incremental builds. EmitModuleOnly is used when we skip compilation, it's already pretty common before the emit-module-separately work afaict. It looks like the stdlib is built this way via CMake and a lot of tests just do an -emit-module without an -emit-library, so they are considered EmitModuleOnly.

What do you think? Can we turn on interface hashing in more cases or should we keep limiting it only to emit-module-separately builds with the check on -experimental-skip-non-inlinable-function-bodies-without-types or some new flag?

opts |= SourceFile::ParsingFlags::EnableInterfaceHash;
}
return opts;
Expand Down
5 changes: 5 additions & 0 deletions test/InterfaceHash/added_function.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@
// RUN: %target-swift-frontend -dump-interface-hash -primary-file %t/b.swift 2> %t/b.hash
// RUN: not cmp %t/a.hash %t/b.hash

/// We should generate an interface hash for emit-module-separately jobs even
/// with no primaries.
// RUN: %target-swift-frontend -dump-interface-hash %t/b.swift -experimental-skip-non-inlinable-function-bodies-without-types 2> %t/b-emit-module.hash
// RUN: cmp %t/b.hash %t/b-emit-module.hash

// BEGIN a.swift
func f() {}

Expand Down