Skip to content

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Aug 2, 2019

We now have three methods on AbstractStorageDecl that will eventually replace getAccessor():

  • getParsedAccessor() -- returns an accessor explicitly written in source; otherwise always returns nullptr.
  • getOpaqueAccessor() -- if the accessor kind is part of the ABI of the storage, or if it was parsed, returns the accessor. Returns nullptr if the accessor was not parsed and is not part of the opaque ABI set. The accessor is synthesized if necessary. It's possible for an accessor to be parsed, but not part of the ABI; an example is AccessorKind::WillSet or AccessorKind::DidSet. For convenience this method returns an accessor in this case also. An example of an accessor that is neither parsed or part of the ABI is AccessorKind::Read on a computed property that only has a getter. In this case, this method will return nullptr.
  • getSynthesizedAccessor() -- returns an accessor, always synthesizing one if necessary. This should only be used when, eg, emitting protocol witnesses, which can sometimes require accessors not part of the storage's ABI (for example, an @objc dynamic property does not usually have an AccessorKind::Modify, but if it witnesses a mutable protocol requirement, we synthesize one). Note that if getSynthesizedAccessor() returns an accessor not part of the opaque ABI accessor set, the generated accessor will be emitted with shared linkage.

Using the above three operations, we can now trigger lazy accessor synthesis from various stages of the pipeline, eliminating some logic found in Sema's finalizeDecl() for forcing accessor synthesis for declarations in secondary files.

We still force synthesis of accessors in primary files, and in a couple of other random places. These need a little bit more refactoring to eliminate, because we still call getAccessor(), getAllAccessors() and hasAnyAccessors() on declarations in primary files.

As for finalizeDecl(), it's still used to add some implicit members to ClassDecls, and not much else. The TypeChecker::DeclsToFinalize list now only ever contains ClassDecls. This is also going away soon, in favor of a request to get the "vtable members" of a class.

@slavapestov
Copy link
Contributor Author

@swift-ci Please test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@swift-ci Please test compiler performance

@swift-ci
Copy link
Contributor

swift-ci commented Aug 2, 2019

Build failed
Swift Test OS X Platform
Git Sha - 63f04827870baa2712d6076497abe6790ade0faa

@swift-ci
Copy link
Contributor

swift-ci commented Aug 2, 2019

Build failed
Swift Test Linux Platform
Git Sha - 63f04827870baa2712d6076497abe6790ade0faa

Copy link
Contributor

Choose a reason for hiding this comment

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

"Return an accessor that's known to be part of the set..."

Technically, it's possible to distinguish between opaque accessors, which are guaranteed-to-exist ABI-stable implementations of the core access operations, and accessors that might be part of the (non-stable or frozen) ABI. For example, we might want to do funny things with didSet in the future. Not sure if this is worth spelling out in the comment.

Copy link
Contributor

Choose a reason for hiding this comment

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

These changes don't seem right. The AST verifier is unlike most clients in that it should be doing verification of accessors if they exist for any reason, and I don't think we want to be embedding assumptions in it about whether specific accessors only exist if they're parsed.

Presumably we visit all the accessors that exist as part of the walk? (That seems right for the AST verifier even if it's not normally a good operation to provide.) Maybe these checks can be moved to when we visit the accessor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can change this back. I was planning on keeping something like getAccessor() around specifically for the verifier (and maybe even friend the verifier so people don’t use it on accident).

@swift-ci
Copy link
Contributor

swift-ci commented Aug 2, 2019

Summary for master full

Unexpected test results, excluded stats for RxCocoa, SwifterSwift

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 46,326,644,776,303 46,336,393,633,688 9,748,857,385 0.02%
LLVM.NumLLVMBytesOutput 1,739,397,282 1,739,216,450 -180,832 -0.01%
time.swift-driver.wall 5002.4s 4983.9s -18.5s -0.37%

debug-batch detailed

Regressed (3)
name old new delta delta_pct
Sema.AttachedPropertyWrappersRequest 2,287,823 2,565,840 278,017 12.15% ⛔
Sema.RequiresOpaqueAccessorsRequest 630,211 1,297,544 667,333 105.89% ⛔
Sema.StorageImplInfoRequest 925,098 1,222,488 297,390 32.15% ⛔
Improved (25)
name old new delta delta_pct
AST.NumTotalClangImportedEntities 6,521,806 6,424,077 -97,729 -1.5% ✅
Sema.DefaultDefinitionTypeRequest 8,150 7,969 -181 -2.22% ✅
Sema.DefaultTypeRequest 500,405 493,919 -6,486 -1.3% ✅
Sema.EnumRawTypeRequest 25,380 24,837 -543 -2.14% ✅
Sema.InitKindRequest 122,575 121,090 -1,485 -1.21% ✅
Sema.IsGetterMutatingRequest 489,976 438,402 -51,574 -10.53% ✅
Sema.IsObjCRequest 1,663,265 1,631,552 -31,713 -1.91% ✅
Sema.IsSetterMutatingRequest 371,636 342,860 -28,776 -7.74% ✅
Sema.LazyStoragePropertyRequest 3,210 2,603 -607 -18.91% ✅
Sema.NamedLazyMemberLoadFailureCount 33,314 32,683 -631 -1.89% ✅
Sema.NamedLazyMemberLoadSuccessCount 30,406,715 29,993,854 -412,861 -1.36% ✅
Sema.NominalTypeLookupDirectCount 37,117,591 36,691,166 -426,425 -1.15% ✅
Sema.NumAccessorsSynthesized 400,741 289,453 -111,288 -27.77% ✅
Sema.NumDeclsFinalized 709,592 0 -709,592 -100.0% ✅
Sema.NumDeclsValidated 2,751,869 2,635,302 -116,567 -4.24% ✅
Sema.NumTypesValidated 2,405,805 2,325,563 -80,242 -3.34% ✅
Sema.NumUnloadedLazyIterableDeclContexts 6,215,884 6,147,060 -68,824 -1.11% ✅
Sema.OpaqueReadOwnershipRequest 386,051 277,540 -108,511 -28.11% ✅
Sema.PropertyWrapperMutabilityRequest 664,246 610,783 -53,463 -8.05% ✅
Sema.RequiresOpaqueModifyCoroutineRequest 459,667 264,720 -194,947 -42.41% ✅
Sema.SelfAccessKindRequest 6,392,663 6,292,187 -100,476 -1.57% ✅
Sema.StoredPropertiesRequest 399,947 346,666 -53,281 -13.32% ✅
Sema.SuperclassDeclRequest 506,285 498,325 -7,960 -1.57% ✅
Sema.SuperclassTypeRequest 62,264 61,371 -893 -1.43% ✅
Sema.SynthesizeAccessorRequest 400,741 289,453 -111,288 -27.77% ✅
Unchanged (delta < 1.0% or delta < 100.0ms) (113)
name old new delta delta_pct
AST.NumASTBytesAllocated 66,933,701,962 66,749,374,172 -184,327,790 -0.28%
AST.NumDecls 136,738 136,726 -12 -0.01%
AST.NumDependencies 310,129 310,117 -12 -0.0%
AST.NumInfixOperators 52,921 52,921 0 0.0%
AST.NumLinkLibraries 0 0 0 0.0%
AST.NumLoadedModules 390,117 390,117 0 0.0%
AST.NumLocalTypeDecls 241 241 0 0.0%
AST.NumObjCMethods 24,471 24,471 0 0.0%
AST.NumPostfixOperators 23 23 0 0.0%
AST.NumPrecedenceGroups 24,973 24,973 0 0.0%
AST.NumPrefixOperators 99 99 0 0.0%
AST.NumReferencedDynamicNames 189 189 0 0.0%
AST.NumReferencedMemberNames 6,213,647 6,213,337 -310 -0.0%
AST.NumReferencedTopLevelNames 466,137 466,121 -16 -0.0%
AST.NumSourceBuffers 549,666 549,666 0 0.0%
AST.NumSourceLines 4,600,323 4,599,901 -422 -0.01%
AST.NumSourceLinesPerSecond 3,305,847 3,306,649 802 0.02%
Driver.ChildrenMaxRSS 236,046,876,672 235,383,449,600 -663,427,072 -0.28%
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 27,113 27,113 0 0.0%
Driver.NumDriverJobsSkipped 0 0 0 0.0%
Driver.NumDriverPipePolls 72,354 72,018 -336 -0.46%
Driver.NumDriverPipeReads 62,325 62,092 -233 -0.37%
Driver.NumProcessFailures 0 0 0 0.0%
Frontend.MaxMallocUsage 1,313,405,233,016 1,312,798,841,896 -606,391,120 -0.05%
Frontend.NumInstructionsExecuted 46,326,644,776,303 46,336,393,633,688 9,748,857,385 0.02%
Frontend.NumProcessFailures 0 0 0 0.0%
IRModule.NumIRAliases 193,566 193,541 -25 -0.01%
IRModule.NumIRBasicBlocks 6,954,547 6,953,630 -917 -0.01%
IRModule.NumIRComdatSymbols 0 0 0 0.0%
IRModule.NumIRFunctions 3,254,545 3,254,200 -345 -0.01%
IRModule.NumIRGlobals 3,314,053 3,313,770 -283 -0.01%
IRModule.NumIRIFuncs 0 0 0 0.0%
IRModule.NumIRInsts 85,119,563 85,112,952 -6,611 -0.01%
IRModule.NumIRNamedMetaData 130,380 130,380 0 0.0%
IRModule.NumIRValueSymbols 5,934,066 5,933,488 -578 -0.01%
LLVM.NumLLVMBytesOutput 1,739,397,282 1,739,216,450 -180,832 -0.01%
Parse.NumFunctionsParsed 262,365 262,362 -3 -0.0%
Parse.NumIterableDeclContextParsed 1,796,696 1,796,477 -219 -0.01%
SILModule.NumSILGenDefaultWitnessTables 0 0 0 0.0%
SILModule.NumSILGenFunctions 1,677,114 1,676,966 -148 -0.01%
SILModule.NumSILGenGlobalVariables 53,716 53,710 -6 -0.01%
SILModule.NumSILGenVtables 17,510 17,510 0 0.0%
SILModule.NumSILGenWitnessTables 70,974 70,956 -18 -0.03%
SILModule.NumSILOptDefaultWitnessTables 0 0 0 0.0%
SILModule.NumSILOptFunctions 2,348,651 2,348,461 -190 -0.01%
SILModule.NumSILOptGlobalVariables 55,331 55,325 -6 -0.01%
SILModule.NumSILOptVtables 29,880 29,880 0 0.0%
SILModule.NumSILOptWitnessTables 155,613 155,583 -30 -0.02%
Sema.AccessLevelRequest 11,999,373 12,037,714 38,341 0.32%
Sema.AttachedFunctionBuilderRequest 7 7 0 0.0%
Sema.AttachedPropertyWrapperTypeRequest 502,975 502,605 -370 -0.07%
Sema.CollectOverriddenDeclsRequest 7,368,806 7,439,736 70,930 0.96%
Sema.CursorInfoRequest 0 0 0 0.0%
Sema.CustomAttrNominalRequest 17 17 0 0.0%
Sema.DefaultAndMaxAccessLevelRequest 94,369 93,967 -402 -0.43%
Sema.ExistentialConformsToSelfRequest 23,128 23,114 -14 -0.06%
Sema.ExistentialTypeSupportedRequest 17,276 17,276 0 0.0%
Sema.ExtendedNominalRequest 5,403,739 5,373,419 -30,320 -0.56%
Sema.FunctionBuilderTypeRequest 7 7 0 0.0%
Sema.HasDynamicMemberLookupAttributeRequest 0 0 0 0.0%
Sema.InheritedDeclsReferencedRequest 6,218,754 6,176,072 -42,682 -0.69%
Sema.InheritedTypeRequest 333,101 331,391 -1,710 -0.51%
Sema.IsAccessorTransparentRequest 312,985 312,947 -38 -0.01%
Sema.IsDeclApplicableRequest 0 0 0 0.0%
Sema.IsDynamicRequest 1,633,608 1,632,694 -914 -0.06%
Sema.IsFinalRequest 4,500,996 4,502,855 1,859 0.04%
Sema.MangleLocalTypeDeclRequest 482 482 0 0.0%
Sema.NumAccessorBodiesSynthesized 183,651 183,629 -22 -0.01%
Sema.NumConformancesDeserialized 9,776,531 9,748,264 -28,267 -0.29%
Sema.NumConstraintScopes 24,704,622 24,670,829 -33,793 -0.14%
Sema.NumConstraintsConsideredForEdgeContraction 74,480,510 74,451,607 -28,903 -0.04%
Sema.NumDeclsDeserialized 74,587,701 74,595,067 7,366 0.01%
Sema.NumDeclsTypechecked 1,369,626 1,369,439 -187 -0.01%
Sema.NumFunctionsTypechecked 513,556 513,503 -53 -0.01%
Sema.NumGenericSignatureBuilders 1,494,962 1,484,859 -10,103 -0.68%
Sema.NumLazyGenericEnvironments 13,563,086 13,501,875 -61,211 -0.45%
Sema.NumLazyGenericEnvironmentsLoaded 314,407 312,011 -2,396 -0.76%
Sema.NumLazyIterableDeclContexts 9,637,040 9,574,328 -62,712 -0.65%
Sema.NumLazyRequirementSignatures 1,014,544 1,011,496 -3,048 -0.3%
Sema.NumLazyRequirementSignaturesLoaded 656,700 650,767 -5,933 -0.9%
Sema.NumLeafScopes 15,968,750 15,947,740 -21,010 -0.13%
Sema.NumTypesDeserialized 22,113,648 22,048,369 -65,279 -0.3%
Sema.OverriddenDeclsRequest 2,455,862 2,434,489 -21,373 -0.87%
Sema.PropertyWrapperBackingPropertyInfoRequest 497,636 497,318 -318 -0.06%
Sema.PropertyWrapperBackingPropertyTypeRequest 502,975 502,605 -370 -0.07%
Sema.PropertyWrapperTypeInfoRequest 5 5 0 0.0%
Sema.ProtocolRequiresClassRequest 91,916 91,295 -621 -0.68%
Sema.ProvideDefaultImplForRequest 7,368,806 7,439,736 70,930 0.96%
Sema.RangeInfoRequest 0 0 0 0.0%
Sema.RequirementRequest 109,644 109,440 -204 -0.19%
Sema.RequirementSignatureRequest 757,765 751,208 -6,557 -0.87%
Sema.ResolveProtocolNameRequest 0 0 0 0.0%
Sema.RootAndResultTypeOfKeypathDynamicMemberRequest 0 0 0 0.0%
Sema.RootTypeOfKeypathDynamicMemberRequest 0 0 0 0.0%
Sema.SelfBoundsFromWhereClauseRequest 8,102,488 8,045,415 -57,073 -0.7%
Sema.SetterAccessLevelRequest 149,629 148,867 -762 -0.51%
Sema.StoredPropertiesAndMissingMembersRequest 32,019 32,019 0 0.0%
Sema.StructuralTypeRequest 0 0 0 0.0%
Sema.TypeCheckFunctionBodyUntilRequest 513,556 513,503 -53 -0.01%
Sema.TypeDeclsFromWhereClauseRequest 50,160 50,047 -113 -0.23%
Sema.TypeRelationCheckRequest 0 0 0 0.0%
Sema.USRGenerationRequest 8,574,131 8,647,497 73,366 0.86%
Sema.UnderlyingTypeDeclsReferencedRequest 275,306 273,377 -1,929 -0.7%

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 46,056,003,869,231 46,070,568,856,931 14,564,987,700 0.03%
LLVM.NumLLVMBytesOutput 1,526,234,196 1,526,241,192 6,996 0.0%
time.swift-driver.wall 8197.4s 8203.4s 6.0s 0.07%

release detailed

Regressed (0)
name old new delta delta_pct
Improved (1)
name old new delta delta_pct
Sema.NumDeclsValidated 1,819,542 1,790,555 -28,987 -1.59% ✅
Unchanged (delta < 1.0% or delta < 100.0ms) (20)
name old new delta delta_pct
AST.NumLoadedModules 29,573 29,573 0 0.0%
AST.NumTotalClangImportedEntities 1,211,995 1,211,995 0 0.0%
IRModule.NumIRBasicBlocks 6,289,118 6,289,118 0 0.0%
IRModule.NumIRFunctions 2,760,567 2,760,567 0 0.0%
IRModule.NumIRGlobals 2,931,157 2,931,169 12 0.0%
IRModule.NumIRInsts 55,373,498 55,373,498 0 0.0%
IRModule.NumIRValueSymbols 5,342,895 5,342,907 12 0.0%
LLVM.NumLLVMBytesOutput 1,526,234,196 1,526,241,192 6,996 0.0%
SILModule.NumSILGenFunctions 1,171,270 1,171,270 0 0.0%
SILModule.NumSILOptFunctions 1,563,873 1,563,873 0 0.0%
Sema.NumConformancesDeserialized 3,663,340 3,663,340 0 0.0%
Sema.NumConstraintScopes 24,203,938 24,203,938 0 0.0%
Sema.NumDeclsDeserialized 10,164,570 10,164,538 -32 -0.0%
Sema.NumFunctionsTypechecked 517,372 517,320 -52 -0.01%
Sema.NumGenericSignatureBuilders 299,534 299,535 1 0.0%
Sema.NumLazyGenericEnvironments 1,994,760 1,995,132 372 0.02%
Sema.NumLazyGenericEnvironmentsLoaded 35,000 35,000 0 0.0%
Sema.NumLazyIterableDeclContexts 1,296,805 1,296,805 0 0.0%
Sema.NumTypesDeserialized 5,172,826 5,172,826 0 0.0%
Sema.NumTypesValidated 1,105,968 1,105,968 0 0.0%

Also, change visitOpaqueAccessors() to call getOpaqueAccessor() instead of
asserting if the expected accessor does not exist.
When checking availability of referenced accessors, we may not have
synthesized the accessors yet. This meant that we didn't diagnose
references to internal(set) properties from inlinable contexts if
the property was defined in another file.
Make sure we test checkObjCWitnessSelector() in the multi-file
case.

I made some changes that regressed a source compatibility project
but the regression was not caught by our test suite, so make sure
we have a test for this now.
We can lazily synthesize accessor witnesses from SILGen now.
Previously we would synthesize accessors for any referenced
storage, as well as any storage members of classes and protocols.

Now that synthesis is sufficiently lazy this is no longer needed.
The only remaining work done in finalizeDecl() is adding certain
implicit members to ClassDecls; no other declaration kind ends up
in DeclsToFinalize anymore.
This is a false positive, since the '_read' accessor is synthesized
on demand and emitted with shared linkage. See <rdar://problem/53776566>.
@slavapestov slavapestov force-pushed the lazy-accessor-synthesis-part-1 branch from 63f0482 to 24b20a3 Compare August 2, 2019 23:35
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

1 similar comment
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test Linux

@slavapestov slavapestov merged commit 7a37830 into swiftlang:master Aug 3, 2019
@DougGregor
Copy link
Member

Lots of counters dropped; very nice

@rjmccall
Copy link
Contributor

rjmccall commented Aug 6, 2019

Also, I don't fully appreciate what "non-primary file" means. Why is it okay to omit diagnostics is such files?

When the compiler is asked to produce code for 1 file out of N in the project, but it's blocked by an error in a different file, it still needs to print a diagnostic; it's unreasonable for it to just fail silently.

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.

5 participants