Skip to content

Add a request to lazily parse function bodies. #26972

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 31, 2019

Conversation

DougGregor
Copy link
Member

Rework the lazy function body parsing mechanism to use the
request-evaluator, so that asking for the body of a function will
initiate parsing. Clean up a number of callers to
AbstractFunctionDecl::getBody() that don't actually need the body, so
we don't perform unnecessary parsing.

This change does not delay parsing of function bodies in the general
case; rather, it sets up the infrastructure to always delay parsing of
function bodies.

Rework the lazy function body parsing mechanism to use the
request-evaluator, so that asking for the body of a function will
initiate parsing. Clean up a number of callers to
AbstractFunctionDecl::getBody() that don't actually need the body, so
we don't perform unnecessary parsing.

This change does not delay parsing of function bodies in the general
case; rather, it sets up the infrastructure to always delay parsing of
function bodies.
@DougGregor DougGregor requested review from nkcsgexi and xedin August 30, 2019 23:51
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please test source compatibility

@davidungar
Copy link
Contributor

The recent lazy parsing of IterableTypeContexts PR turned out to break lazy ASTScopes because the MemberCount is zero, until getMembers has been called. I've worked around it. Let me know if I need to do something similar for this PR. I.e. if getBody() will return null until some other call is made, I'll need to adjust ASTScopes.

@DougGregor
Copy link
Member Author

@davidungar with this pull request, getBody() will go ahead and parse the statement even if it has been delayed, so getBody() should be more reliable than before. Previously, if it had BodyKind::Unparsed, getBody() would return NULL until delayed parsing kicked in later.

@DougGregor DougGregor merged commit 7ce3553 into swiftlang:master Aug 31, 2019
@DougGregor DougGregor deleted the request-function-body-parse branch August 31, 2019 04:57
@davezarzycki
Copy link
Contributor

Hi @DougGregor – How is this supposed to build? Are the "stable" branches of llvm and clang no longer the right branches to use with swift's "master" branch?

~/s/u 0 $ git -C llvm pull --ff-only
Already up to date.
~/s/u 0 $ git -C clang pull --ff-only
Already up to date.
~/s/u 130 $ ninja -C ~/b/u/t swift
ninja: Entering directory `/home/dave/b/u/t'
[21+1] Building CXX object tools/swift/lib/AST/CMakeFiles/swiftAST.dir/Decl.cpp.o
FAILED: tools/swift/lib/AST/CMakeFiles/swiftAST.dir/Decl.cpp.o 
/p/llvm/bin/clang++  -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/swift/lib/AST -I/home/dave/s/u/swift/lib/AST -Itools/swift/include -I/home/dave/s/u/swift/include -I/usr/include/libxml2 -Iinclude -I/home/dave/s/u/llvm/include -Itools/clang/include -I/home/dave/s/u/llvm/../clang/include -I/home/dave/s/u/cmark/src -Itools/cmark/src -Wno-c11-extensions -Wno-c99-extensions -Wno-c++17-extensions -Wno-dollar-in-identifier-extension -Wno-empty-translation-unit -Wno-format-pedantic -Wno-nullability-extension -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -std=c++11 -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-nested-anon-types -Werror=switch -Wdocumentation -Wimplicit-fallthrough -Wunreachable-code -Woverloaded-virtual -DOBJC_OLD_DISPATCH_PROTOTYPES=0 -O2    -UNDEBUG  -march=skylake -fno-omit-frame-pointer -fno-vectorize -fno-slp-vectorize -mno-omit-leaf-frame-pointer -fno-exceptions -fno-rtti -target x86_64-unknown-linux-gnu -O2 -g0 -UNDEBUG -MD -MT tools/swift/lib/AST/CMakeFiles/swiftAST.dir/Decl.cpp.o -MF tools/swift/lib/AST/CMakeFiles/swiftAST.dir/Decl.cpp.o.d -o tools/swift/lib/AST/CMakeFiles/swiftAST.dir/Decl.cpp.o -c /home/dave/s/u/swift/lib/AST/Decl.cpp
/home/dave/s/u/swift/lib/AST/Decl.cpp:6321:21: error: no member named 'rangeContainsCodeCompletionLoc' in 'swift::SourceManager'
      ctx.SourceMgr.rangeContainsCodeCompletionLoc(getBodySourceRange())) {
      ~~~~~~~~~~~~~ ^
1 error generated.
ninja: build stopped: subcommand failed.

@eeckstein
Copy link
Contributor

I reverted this PR because we are seeing this compiler error on all CI bots.
I'm wondering how this could have passed PR testing.

@davezarzycki
Copy link
Contributor

If you click on the list of commits, you’ll see a red X which means that the status checks didn’t all pass. I’d wager that Doug didn’t notice and merged it anyway

@DougGregor
Copy link
Member Author

DougGregor commented Aug 31, 2019

The Linux failure was not related to that. What happened here is that I ran the tests earlier in the day, and they passed (as they should). https://github.com/apple/swift/pull/26888/files#diff-363ae01084185dad84858de454e6bc95 got merged after my tests ran, but before my merge, and removed the API in question (SourceManager::rangeContainsCodeCompletionLoc()). I tried to bring the API back (via #26976), but that hit another unrelated issue and didn't merge before the revert. I'll try again.

@DougGregor
Copy link
Member Author

#26981 is the redo

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