-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[clangd] [Modules] Fix to correctly handle module dependencies #142828
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| # A smoke test to check that a simple dependency chain for modules can work. | ||
| # | ||
| # FIXME: This fails on the Windows ARM64 build server. Not entirely sure why as it has been tested on | ||
| # an ARM64 Windows VM and appears to work there. | ||
| # UNSUPPORTED: host=aarch64-pc-windows-msvc | ||
| # | ||
| # RUN: rm -fr %t | ||
| # RUN: mkdir -p %t | ||
| # RUN: split-file %s %t | ||
| # | ||
| # RUN: sed -e "s|DIR|%/t|g" %t/compile_commands.json.tmpl > %t/compile_commands.json.tmp | ||
| # RUN: sed -e "s|CLANG_CC|%clang|g" %t/compile_commands.json.tmp > %t/compile_commands.json | ||
| # RUN: sed -e "s|DIR|%/t|g" %t/definition.jsonrpc.tmpl > %t/definition.jsonrpc.tmp | ||
| # | ||
| # On Windows, we need the URI in didOpen to look like "uri":"file:///C:/..." | ||
| # (with the extra slash in the front), so we add it here. | ||
| # RUN: sed -E -e 's|"file://([A-Z]):/|"file:///\1:/|g' %/t/definition.jsonrpc.tmp > %/t/definition.jsonrpc | ||
| # | ||
| # RUN: clangd -experimental-modules-support -lit-test < %t/definition.jsonrpc \ | ||
| # RUN: | FileCheck -strict-whitespace %t/definition.jsonrpc | ||
|
|
||
| #--- A-frag.cppm | ||
| export module A:frag; | ||
| export void printA() {} | ||
|
|
||
| #--- A.cppm | ||
| export module A; | ||
| export import :frag; | ||
|
|
||
| #--- Use.cpp | ||
| import A; | ||
| void foo() { | ||
| } | ||
|
|
||
| #--- compile_commands.json.tmpl | ||
| [ | ||
| { | ||
| "directory": "DIR", | ||
| "command": "CLANG_CC -fprebuilt-module-path=DIR -std=c++20 -o DIR/main.cpp.o -c DIR/Use.cpp", | ||
| "file": "DIR/Use.cpp" | ||
| }, | ||
| { | ||
| "directory": "DIR", | ||
| "command": "CLANG_CC -std=c++20 DIR/A.cppm --precompile -o DIR/A.pcm", | ||
| "file": "DIR/A.cppm" | ||
| }, | ||
| { | ||
| "directory": "DIR", | ||
| "command": "CLANG_CC -std=c++20 DIR/A-frag.cppm --precompile -o DIR/A-frag.pcm", | ||
| "file": "DIR/A-frag.cppm" | ||
| } | ||
| ] | ||
|
|
||
| #--- definition.jsonrpc.tmpl | ||
| { | ||
| "jsonrpc": "2.0", | ||
| "id": 0, | ||
| "method": "initialize", | ||
| "params": { | ||
| "processId": 123, | ||
| "rootPath": "clangd", | ||
| "capabilities": { | ||
| "textDocument": { | ||
| "completion": { | ||
| "completionItem": { | ||
| "snippetSupport": true | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| "trace": "off" | ||
| } | ||
| } | ||
| --- | ||
| { | ||
| "jsonrpc": "2.0", | ||
| "method": "textDocument/didOpen", | ||
| "params": { | ||
| "textDocument": { | ||
| "uri": "file://DIR/Use.cpp", | ||
| "languageId": "cpp", | ||
| "version": 1, | ||
| "text": "import A;\nvoid foo() {\n print\n}\n" | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # CHECK: "message"{{.*}}printA{{.*}}(fix available) | ||
|
|
||
| --- | ||
| {"jsonrpc":"2.0","id":1,"method":"textDocument/completion","params":{"textDocument":{"uri":"file://DIR/Use.cpp"},"context":{"triggerKind":1},"position":{"line":2,"character":6}}} | ||
| --- | ||
| {"jsonrpc":"2.0","id":2,"method":"shutdown"} | ||
| --- | ||
| {"jsonrpc":"2.0","method":"exit"} | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using
sedfor paths like this isn't portable, and I'm seeing failures on some internal windows bots because of it. TheUNSUPPORTEDhere doesn't seem sufficient.Notably, since on windows paths will include backslashes, a number of paths will be interpreted as having escape sequences, so we end up with either an error from the sed command saying we can't use that escape sequence there, or some kind of garbage in the replacement text.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fleeting-xx
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bogner in case @fleeting-xx doesn't respond in time, would you like to fix these failures in windows by updating the
UNSUPPORTEDclause properly? I hope we can get this in 20.x. Thanks in ahead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're seeing failures on Windows too: https://crbug.com/423658620
I've disabled the test in http://github.com/llvm/llvm-project/commit/5471d933af193eb2be4992428271cdcc7013599b
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fleeting-xx I suspect the right medium to long term solution here would be to convert these tests to unit tests, as @ChuanqiXu9 suggested. This would avoid having to mess around with the config file using
sedsince all of that set up could be done programatically.Thanks @zmodem for the short term fix!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry I missed this. I'll see about getting these moved to unit tests.