Skip to content

Improve lazy synthesis of function bodies #26102

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

Closed
wants to merge 7 commits into from

Conversation

DougGregor
Copy link
Member

Start improving lazy synthesis of function bodies:

  • Don't ask for a complete function body when we only need the source range
  • Don't have lazy body synthesizers mutate the function; return the synthesized body along with a flag indicating whether it is already type checked
  • Switch a few Clang importer-synthesized bodies over to lazy synthesizers

Introduce a stub request for type checking a function body. It’s currently
not triggered lazily, but we’ll start migrating the synthesis and
type-checking logic here.
A number of callers to AbstractFunctionDecl::getBody() were only
extracting the source range of the body... which can be retrieved more
efficiently with getBodySourceRange().
Instead of requiring that function body synthesizers will always call
setBody(), which is annoyingly stateful, have function body synthesizers
always return the synthesized brace statement along with a bit that
indicates whether the body was already type-checked. This takes us a
step closer to centralizing the mutation of the body of a function.
@DougGregor
Copy link
Member Author

@swift-ci please smoke test

@DougGregor
Copy link
Member Author

@swift-ci please test compiler performance

@DougGregor
Copy link
Member Author

This will be superseded by #26105

@swift-ci
Copy link
Contributor

Summary for master full

Unexpected test results, excluded stats for ProcedureKit, Tagged, Wordy, SwifterSwift, Deferred

Regressions found (see below)

Debug-batch

debug-batch brief

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (3)
name old new delta delta_pct
Frontend.NumInstructionsExecuted 27,629,775,356,369 27,745,642,554,598 115,867,198,229 0.42%
LLVM.NumLLVMBytesOutput 1,159,768,608 1,159,767,982 -626 -0.0%
time.swift-driver.wall 2597.8s 2578.5s -19.3s -0.74%

debug-batch detailed

Regressed (4)
name old new delta delta_pct
Driver.NumDriverPipePolls 90,293 92,926 2,633 2.92% ⛔
Driver.NumDriverPipeReads 88,671 91,446 2,775 3.13% ⛔
Sema.AccessLevelRequest 7,372,911 7,493,215 120,304 1.63% ⛔
Sema.USRGenerationRequest 4,723,006 4,794,955 71,949 1.52% ⛔
Improved (1)
name old new delta delta_pct
Sema.NumGenericSignatureBuilders 1,085,728 997,028 -88,700 -8.17% ✅
Unchanged (delta < 1.0% or delta < 100.0ms) (113)
name old new delta delta_pct
AST.NumASTBytesAllocated 41,631,162,711 41,585,450,237 -45,712,474 -0.11%
AST.NumDecls 93,543 93,543 0 0.0%
AST.NumDependencies 216,527 216,532 5 0.0%
AST.NumInfixOperators 34,812 34,812 0 0.0%
AST.NumLinkLibraries 0 0 0 0.0%
AST.NumLoadedModules 262,351 262,351 0 0.0%
AST.NumLocalTypeDecls 123 123 0 0.0%
AST.NumObjCMethods 15,290 15,290 0 0.0%
AST.NumPostfixOperators 18 18 0 0.0%
AST.NumPrecedenceGroups 17,193 17,193 0 0.0%
AST.NumPrefixOperators 60 60 0 0.0%
AST.NumReferencedDynamicNames 122 122 0 0.0%
AST.NumReferencedMemberNames 4,071,175 4,071,175 0 0.0%
AST.NumReferencedTopLevelNames 315,682 315,682 0 0.0%
AST.NumSourceBuffers 399,348 399,348 0 0.0%
AST.NumSourceLines 3,118,982 3,118,982 0 0.0%
AST.NumSourceLinesPerSecond 2,548,494 2,545,681 -2,813 -0.11%
AST.NumStoredPropertiesQueries 9,230,668 9,230,904 236 0.0%
AST.NumTotalClangImportedEntities 4,360,570 4,361,781 1,211 0.03%
Driver.ChildrenMaxRSS 131,823,665,152 132,081,723,392 258,058,240 0.2%
Driver.DriverDepCascadingDynamic 0 0 0 0.0%
Driver.DriverDepCascadingExternal 0 0 0 0.0%
Driver.DriverDepCascadingMember 0 0 0 0.0%
Driver.DriverDepCascadingNominal 0 0 0 0.0%
Driver.DriverDepCascadingTopLevel 0 0 0 0.0%
Driver.DriverDepDynamic 0 0 0 0.0%
Driver.DriverDepExternal 0 0 0 0.0%
Driver.DriverDepMember 0 0 0 0.0%
Driver.DriverDepNominal 0 0 0 0.0%
Driver.DriverDepTopLevel 0 0 0 0.0%
Driver.NumDriverJobsRun 19,038 19,038 0 0.0%
Driver.NumDriverJobsSkipped 0 0 0 0.0%
Driver.NumProcessFailures 0 0 0 0.0%
Frontend.MaxMallocUsage 815,378,653,544 816,298,967,952 920,314,408 0.11%
Frontend.NumInstructionsExecuted 27,629,775,356,369 27,745,642,554,598 115,867,198,229 0.42%
Frontend.NumProcessFailures 0 0 0 0.0%
IRModule.NumIRAliases 120,775 120,775 0 0.0%
IRModule.NumIRBasicBlocks 4,609,887 4,609,887 0 0.0%
IRModule.NumIRComdatSymbols 0 0 0 0.0%
IRModule.NumIRFunctions 2,144,147 2,144,147 0 0.0%
IRModule.NumIRGlobals 2,243,377 2,243,377 0 0.0%
IRModule.NumIRIFuncs 0 0 0 0.0%
IRModule.NumIRInsts 60,935,359 60,935,359 0 0.0%
IRModule.NumIRNamedMetaData 92,490 92,490 0 0.0%
IRModule.NumIRValueSymbols 3,922,904 3,922,904 0 0.0%
LLVM.NumLLVMBytesOutput 1,159,768,608 1,159,767,982 -626 -0.0%
Parse.NumFunctionsParsed 171,430 171,430 0 0.0%
Parse.NumIterableDeclContextParsed 1,174,574 1,174,574 0 0.0%
SILModule.NumSILGenDefaultWitnessTables 0 0 0 0.0%
SILModule.NumSILGenFunctions 1,081,632 1,081,632 0 0.0%
SILModule.NumSILGenGlobalVariables 36,840 36,840 0 0.0%
SILModule.NumSILGenVtables 12,417 12,417 0 0.0%
SILModule.NumSILGenWitnessTables 46,027 46,027 0 0.0%
SILModule.NumSILOptDefaultWitnessTables 0 0 0 0.0%
SILModule.NumSILOptFunctions 1,535,399 1,535,399 0 0.0%
SILModule.NumSILOptGlobalVariables 37,716 37,716 0 0.0%
SILModule.NumSILOptVtables 20,593 20,593 0 0.0%
SILModule.NumSILOptWitnessTables 101,019 101,019 0 0.0%
Sema.AttachedFunctionBuilderRequest 0 0 0 0.0%
Sema.AttachedPropertyWrapperTypeRequest 325,238 325,238 0 0.0%
Sema.AttachedPropertyWrappersRequest 1,370,101 1,370,101 0 0.0%
Sema.CustomAttrNominalRequest 0 0 0 0.0%
Sema.DefaultAndMaxAccessLevelRequest 58,815 58,818 3 0.01%
Sema.DefaultDefinitionTypeRequest 5,457 5,457 0 0.0%
Sema.DefaultTypeRequest 323,597 323,597 0 0.0%
Sema.EnumRawTypeRequest 17,342 17,342 0 0.0%
Sema.ExtendedNominalRequest 3,384,265 3,389,098 4,833 0.14%
Sema.FunctionBuilderTypeRequest 0 0 0 0.0%
Sema.InheritedDeclsReferencedRequest 3,878,677 3,878,217 -460 -0.01%
Sema.InheritedTypeRequest 235,070 235,213 143 0.06%
Sema.IsDynamicRequest 1,979,553 1,979,553 0 0.0%
Sema.IsFinalRequest 3,087,875 3,098,343 10,468 0.34%
Sema.IsGetterMutatingRequest 401,071 401,071 0 0.0%
Sema.IsObjCRequest 1,784,683 1,786,388 1,705 0.1%
Sema.IsSetterMutatingRequest 279,242 279,242 0 0.0%
Sema.LazyStoragePropertyRequest 2,418 2,418 0 0.0%
Sema.MangleLocalTypeDeclRequest 246 246 0 0.0%
Sema.NamedLazyMemberLoadFailureCount 22,229 22,172 -57 -0.26%
Sema.NamedLazyMemberLoadSuccessCount 19,712,376 19,708,846 -3,530 -0.02%
Sema.NominalTypeLookupDirectCount 24,690,782 24,733,439 42,657 0.17%
Sema.NumConformancesDeserialized 5,897,218 5,932,074 34,856 0.59%
Sema.NumConstraintScopes 17,898,047 17,903,833 5,786 0.03%
Sema.NumConstraintsConsideredForEdgeContraction 52,842,621 52,842,944 323 0.0%
Sema.NumDeclsDeserialized 45,318,454 45,567,456 249,002 0.55%
Sema.NumDeclsFinalized 1,732,245 1,732,245 0 0.0%
Sema.NumDeclsTypechecked 887,843 887,843 0 0.0%
Sema.NumDeclsValidated 2,307,360 2,307,371 11 0.0%
Sema.NumFunctionsTypechecked 198,299 198,299 0 0.0%
Sema.NumLazyGenericEnvironments 8,224,334 8,283,342 59,008 0.72%
Sema.NumLazyGenericEnvironmentsLoaded 216,834 217,010 176 0.08%
Sema.NumLazyIterableDeclContexts 6,138,934 6,144,059 5,125 0.08%
Sema.NumLazyRequirementSignatures 662,277 662,630 353 0.05%
Sema.NumLazyRequirementSignaturesLoaded 421,976 422,108 132 0.03%
Sema.NumLeafScopes 11,507,718 11,512,700 4,982 0.04%
Sema.NumTypesDeserialized 13,857,544 13,909,267 51,723 0.37%
Sema.NumTypesValidated 1,727,612 1,727,623 11 0.0%
Sema.NumUnloadedLazyIterableDeclContexts 4,110,273 4,098,258 -12,015 -0.29%
Sema.OpaqueReadOwnershipRequest 423,179 423,179 0 0.0%
Sema.OverriddenDeclsRequest 2,233,466 2,247,576 14,110 0.63%
Sema.PropertyWrapperBackingPropertyInfoRequest 322,765 322,765 0 0.0%
Sema.PropertyWrapperBackingPropertyTypeRequest 325,238 325,238 0 0.0%
Sema.PropertyWrapperTypeInfoRequest 0 0 0 0.0%
Sema.RequirementRequest 67,170 67,172 2 0.0%
Sema.RequirementSignatureRequest 492,187 492,433 246 0.05%
Sema.SelfAccessKindRequest 4,378,547 4,369,160 -9,387 -0.21%
Sema.SelfBoundsFromWhereClauseRequest 4,988,904 4,992,331 3,427 0.07%
Sema.SetterAccessLevelRequest 156,459 156,459 0 0.0%
Sema.StructuralTypeRequest 0 0 0 0.0%
Sema.SuperclassDeclRequest 330,208 330,598 390 0.12%
Sema.SuperclassTypeRequest 39,898 39,898 0 0.0%
Sema.TypeCheckFunctionBodyRequest 318,297 318,297 0 0.0%
Sema.TypeDeclsFromWhereClauseRequest 31,546 31,549 3 0.01%
Sema.UnderlyingTypeDeclsReferencedRequest 172,575 172,912 337 0.2%

Release

release brief

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (3)
name old new delta delta_pct
Frontend.NumInstructionsExecuted 30,681,488,477,346 30,670,416,778,593 -11,071,698,753 -0.04%
LLVM.NumLLVMBytesOutput 993,094,998 993,095,866 868 0.0%
time.swift-driver.wall 5172.4s 5172.4s 27.1ms 0.0%

release detailed

Regressed (0)
name old new delta delta_pct
Improved (1)
name old new delta delta_pct
Sema.NumGenericSignatureBuilders 207,868 192,607 -15,261 -7.34% ✅
Unchanged (delta < 1.0% or delta < 100.0ms) (20)
name old new delta delta_pct
AST.NumLoadedModules 17,619 17,619 0 0.0%
AST.NumTotalClangImportedEntities 778,391 778,391 0 0.0%
IRModule.NumIRBasicBlocks 3,931,136 3,931,136 0 0.0%
IRModule.NumIRFunctions 1,811,885 1,811,885 0 0.0%
IRModule.NumIRGlobals 1,989,946 1,989,946 0 0.0%
IRModule.NumIRInsts 36,194,966 36,194,966 0 0.0%
IRModule.NumIRValueSymbols 3,533,288 3,533,288 0 0.0%
LLVM.NumLLVMBytesOutput 993,094,998 993,095,866 868 0.0%
SILModule.NumSILGenFunctions 748,037 748,037 0 0.0%
SILModule.NumSILOptFunctions 1,001,547 1,001,547 0 0.0%
Sema.NumConformancesDeserialized 2,288,921 2,288,921 0 0.0%
Sema.NumConstraintScopes 17,599,082 17,599,082 0 0.0%
Sema.NumDeclsDeserialized 6,154,292 6,154,292 0 0.0%
Sema.NumDeclsValidated 1,197,884 1,197,884 0 0.0%
Sema.NumFunctionsTypechecked 201,866 201,866 0 0.0%
Sema.NumLazyGenericEnvironments 1,197,652 1,197,652 0 0.0%
Sema.NumLazyGenericEnvironmentsLoaded 22,075 22,075 0 0.0%
Sema.NumLazyIterableDeclContexts 762,403 762,403 0 0.0%
Sema.NumTypesDeserialized 3,168,577 3,168,577 0 0.0%
Sema.NumTypesValidated 741,424 741,424 0 0.0%

@DougGregor DougGregor closed this Jul 12, 2019
@DougGregor DougGregor deleted the lazy-body-synthesis branch July 12, 2019 17:08
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.

2 participants