Skip to content

[CodeCompletion] Give up fast-completion if dependent files are modified #31388

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

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Apr 29, 2020

Check if dependencies are modified since the last checking.
Dependencies:

  • Other source files in the current module
  • Dependent files collected by the dependency tracker

When:

  • If the last dependency check was over N (defaults to 5) seconds ago

Invalidate if:

  • The dependency file is missing
  • The modification time of the dependecy is greater than the last check
  • If the modification time is zero, compare the contents using the file system from the previous completion and the current completion (in-memory filesystem)

rdar://problem/62336432

@rintaro
Copy link
Member Author

rintaro commented Apr 29, 2020

@swift-ci Please build toolchain macOS

@swift-ci
Copy link
Contributor

macOS Toolchain
Download Toolchain
Git Sha - 8c8849b4916e5531493849f78d9d19d13c76808b

Install command
tar -zxf swift-PR-31388-505-osx.tar.gz --directory ~/

@rintaro
Copy link
Member Author

rintaro commented Apr 29, 2020

@swift-ci Please build toolchain macOS

@rintaro rintaro force-pushed the ide-completion-fastcheckdep-rdar62336432 branch from e0354c9 to 09c4f2c Compare April 29, 2020 05:43
@rintaro
Copy link
Member Author

rintaro commented Apr 29, 2020

@swift-ci Please build toolchain macOS

@rintaro rintaro force-pushed the ide-completion-fastcheckdep-rdar62336432 branch from 09c4f2c to 38c26cf Compare April 30, 2020 00:03
@rintaro
Copy link
Member Author

rintaro commented Apr 30, 2020

@swift-ci Please build toolchain macOS

@rintaro
Copy link
Member Author

rintaro commented May 1, 2020

@swift-ci Please smoke test

@rintaro rintaro force-pushed the ide-completion-fastcheckdep-rdar62336432 branch from 9d4946e to 95528a4 Compare May 1, 2020 17:02
@rintaro
Copy link
Member Author

rintaro commented May 1, 2020

@swift-ci Please test

@rintaro rintaro marked this pull request as ready for review May 1, 2020 17:04
@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2020

Build failed
Swift Test Linux Platform
Git Sha - 8c8849b4916e5531493849f78d9d19d13c76808b

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2020

Build failed
Swift Test OS X Platform
Git Sha - 8c8849b4916e5531493849f78d9d19d13c76808b

@rintaro rintaro force-pushed the ide-completion-fastcheckdep-rdar62336432 branch from 95528a4 to 0f66247 Compare May 1, 2020 17:20
@rintaro
Copy link
Member Author

rintaro commented May 1, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2020

Build failed
Swift Test Linux Platform
Git Sha - 95528a433c64742ab80725936b4308ea0229a94a

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2020

Build failed
Swift Test OS X Platform
Git Sha - 95528a433c64742ab80725936b4308ea0229a94a

@rintaro rintaro requested review from benlangmuir and akyrtzi May 1, 2020 17:27
// If the last modification time is zero, this file is probably from a
// virtual file system. We need to check the content.
if (lastModTime == llvm::sys::TimePoint<>()) {
if (&CI.getFileSystem() == &FS)
Copy link
Contributor

Choose a reason for hiding this comment

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

A couple of questions:

  • Are these ever going to be equal, or in practice we'll always get a new VFS object?
  • Even if the pointers are equal, is it correct to assume the contents did not change? The VFS object could be mutable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Are these ever going to be equal, or in practice we'll always get a new VFS object?

I don't think so. I believe this is unreachable.

Even if the pointers are equal, is it correct to assume the contents did not change? The VFS object could be mutable.

You are right. We perhaps should retain all buffers of the VFS dependencies. But I think it's good enough for now because the VFS objects should be always different.

Copy link
Contributor

Choose a reason for hiding this comment

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

I would say keep a hash not the whole buffer.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK. I updated the PR to keep hashes of the dependencies.

/*HERE*/
}

// FIXME: Windows CI doesn't support bash array syntax i.e. 'ARRY=( .... )'
Copy link
Contributor

Choose a reason for hiding this comment

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

The tests probably need

// REQUIRES: shell

Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't know shell. Thank you!

@rintaro rintaro force-pushed the ide-completion-fastcheckdep-rdar62336432 branch from 0f66247 to 4b2ad40 Compare May 1, 2020 18:51
@rintaro
Copy link
Member Author

rintaro commented May 1, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2020

Build failed
Swift Test Linux Platform
Git Sha - 0f66247db4c5215f4dc63da70028332aacf3451b

@swift-ci
Copy link
Contributor

swift-ci commented May 1, 2020

Build failed
Swift Test OS X Platform
Git Sha - 0f66247db4c5215f4dc63da70028332aacf3451b

// If the last modification time is zero, this file is probably from a
// virtual file system. We need to check the content.
if (lastModTime == llvm::sys::TimePoint<>()) {
if (&CI.getFileSystem() == &FS)
Copy link
Contributor

Choose a reason for hiding this comment

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

I would say keep a hash not the whole buffer.


// Ignore the current file and synthesized files.
if (filename.empty() || filename.front() == '<' ||
filename.equals(currentFileName))
Copy link
Contributor

Choose a reason for hiding this comment

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

Comparing filename seems potentially brittle - shouldn't we know which file is the completion buffer directly without looking at the name?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated the PR.

@rintaro rintaro force-pushed the ide-completion-fastcheckdep-rdar62336432 branch from 4b2ad40 to be91880 Compare May 1, 2020 21:01
@rintaro
Copy link
Member Author

rintaro commented May 2, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented May 2, 2020

Build failed
Swift Test Linux Platform
Git Sha - 4b2ad40d9e4b50a57d65b12c4a43e1d2e9c32217

@swift-ci
Copy link
Contributor

swift-ci commented May 2, 2020

Build failed
Swift Test OS X Platform
Git Sha - 4b2ad40d9e4b50a57d65b12c4a43e1d2e9c32217

// Stop processing if the modification time is not zero. Probably this
// is not a virtual file system.
if (stat->getLastModificationTime() != llvm::sys::TimePoint<>())
return true;
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 I'm not understanding something: why do we want to stop as soon as we see the first "normal file"? Why can't we have virtual mixed in with regular?

Copy link
Member Author

Choose a reason for hiding this comment

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

I just want to save the stat time if the filesystem is not in-memory.
AFAIU, in reality, we don't mix in-memory file with normal file.

Copy link
Contributor

Choose a reason for hiding this comment

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

The filesystem you get from our builtin FileSystemProvider in sourcekitd is an overlay, so if a call is not handled by the InMemoryFilesystem, it will fall through to the RealFilesystem.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, thank you for notifying! Updated to just ignore the non-zero modification time here.

/// For each dependency files in CI, run \p callback until the callback returns
/// \c true. Returns \c true if any callback call returns \c true, \c false
/// otherwise.
bool forEachDependenciesUntilTrue(
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be singular dependency in the name: forEachDependencyUntilTrue

rintaro added 3 commits May 4, 2020 13:02
Check if dependencies are modified since the last checking.
Dependencies:

 - Other source files in the current module
 - Dependent files collected by the dependency tracker

When:

 - If the last dependency check was over N (defaults to 5) seconds ago

Invalidate if:

 - The dependency file is missing
 - The modification time of the dependecy is greater than the last check
 - If the modification time is zero, compare the content using the file
   system from the previous completion and the current completion

rdar://problem/62336432
These test cases use shell variables etc.
@rintaro rintaro force-pushed the ide-completion-fastcheckdep-rdar62336432 branch 2 times, most recently from 6210634 to 40ed3a4 Compare May 4, 2020 20:18
// RUN: %empty-directory(%t/Frameworks)
// RUN: %empty-directory(%t/MyProject)

// RUN: COMPILER_ARGS=( \
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure how supported it is to assume you can set shell variables and have them persist across run lines. This may work in practice, but are we sure lit will never run commands in a fresh environment?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not 100% certain this is officially supported. But several test cases rely on the behavior e.g. https://github.com/apple/swift/blob/master/test/ModuleInterface/ModuleCache/module-cache-deployment-target-irrelevant.swift.

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, maybe we can follow up with people who know lit well, but no need to block this PR.

@rintaro
Copy link
Member Author

rintaro commented May 4, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented May 4, 2020

Build failed
Swift Test OS X Platform
Git Sha - 42f79c195ae4caf862a06873428c6d291c4d1446

@swift-ci
Copy link
Contributor

swift-ci commented May 4, 2020

Build failed
Swift Test Linux Platform
Git Sha - 42f79c195ae4caf862a06873428c6d291c4d1446

- Detect same file with bufferID instead of the file name
- Compare virtual in-memory filesystem content with hash value
@rintaro rintaro force-pushed the ide-completion-fastcheckdep-rdar62336432 branch from 40ed3a4 to af5daed Compare May 4, 2020 23:36
@rintaro
Copy link
Member Author

rintaro commented May 4, 2020

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented May 4, 2020

Build failed
Swift Test Linux Platform
Git Sha - 40ed3a436c542327795036559a4c6725e856b94e

@swift-ci
Copy link
Contributor

swift-ci commented May 5, 2020

Build failed
Swift Test OS X Platform
Git Sha - 40ed3a436c542327795036559a4c6725e856b94e

@rintaro rintaro merged commit 1f6c3be into swiftlang:master May 5, 2020
@rintaro rintaro deleted the ide-completion-fastcheckdep-rdar62336432 branch May 5, 2020 03:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants