Skip to content

Conversation

slavapestov
Copy link
Contributor

Building checked AST has certain advantages:

  • It is faster, avoiding the need to create and solve ConstraintSystems
    or performing various diagnostic and semantic walks over the AST.

  • It allows us to postpone delayed body synthesis until needed in SILGen,
    instead of having to walk a list of "external declarations" in Sema.

It also unblocks lazier conformance checking. Now that SILGen can
trigger conformance checking on its own, we need to be able to
synthesize bodies of accessors that witness protocol requirements.
This will allow us to eventually remove Sema's "used conformances"
list.

Note that for now, various utility functions in CodeSynthesis.cpp are
used for both checked and unchecked function bodies, so they take a
'typeChecked' boolean parameter that complicates some logic more than
necessary. Once the remaining body synthesizers are refactored to
build type-checked AST, the 'typeChecked' flag will go away.

@slavapestov slavapestov force-pushed the fully-checked-trivial-accessors branch from 51d0778 to 3cf8c2a Compare May 10, 2019 02:39
@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

@slavapestov slavapestov requested a review from xymus May 10, 2019 02:42
@swift-ci
Copy link
Contributor

Summary for master full

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

No regressions above thresholds

Debug-batch

debug-batch brief

Regressed (0)
name old new delta delta_pct
Improved (1)
name old new delta delta_pct
time.swift-driver.wall 2862.3s 2833.5s -28.8s -1.01% ✅
Unchanged (delta < 1.0% or delta < 100.0ms) (2)
name old new delta delta_pct
Frontend.NumInstructionsExecuted 30,606,461,120,804 30,372,863,531,297 -233,597,589,507 -0.76%
LLVM.NumLLVMBytesOutput 1,168,039,008 1,168,043,644 4,636 0.0%

debug-batch detailed

Regressed (0)
name old new delta delta_pct
Improved (7)
name old new delta delta_pct
Driver.NumDriverPipePolls 201,003 183,337 -17,666 -8.79% ✅
Driver.NumDriverPipeReads 223,181 200,713 -22,468 -10.07% ✅
Sema.DefaultTypeRequest 383,514 345,097 -38,417 -10.02% ✅
Sema.NumDeclsValidated 2,437,988 2,410,046 -27,942 -1.15% ✅
Sema.NumFunctionsTypechecked 1,076,612 954,539 -122,073 -11.34% ✅
Sema.OverriddenDeclsRequest 8,117,876 8,002,199 -115,677 -1.42% ✅
Sema.USRGenerationRequest 13,002,844 12,757,092 -245,752 -1.89% ✅
Unchanged (delta < 1.0% or delta < 100.0ms) (99)
name old new delta delta_pct
AST.NumASTBytesAllocated 72,491,180,656 71,977,546,173 -513,634,483 -0.71%
AST.NumDecls 94,750 94,750 0 0.0%
AST.NumDependencies 213,725 213,723 -2 -0.0%
AST.NumImportedExternalDefinitions 1,213,161 1,212,812 -349 -0.03%
AST.NumInfixOperators 35,705 35,705 0 0.0%
AST.NumLinkLibraries 0 0 0 0.0%
AST.NumLoadedModules 255,366 255,366 0 0.0%
AST.NumLocalTypeDecls 123 123 0 0.0%
AST.NumObjCMethods 15,429 15,429 0 0.0%
AST.NumPostfixOperators 18 18 0 0.0%
AST.NumPrecedenceGroups 17,488 17,488 0 0.0%
AST.NumPrefixOperators 90 90 0 0.0%
AST.NumReferencedDynamicNames 122 122 0 0.0%
AST.NumReferencedMemberNames 4,163,187 4,149,543 -13,644 -0.33%
AST.NumReferencedTopLevelNames 323,183 323,183 0 0.0%
AST.NumSourceBuffers 406,343 406,343 0 0.0%
AST.NumSourceLines 3,165,267 3,165,267 0 0.0%
AST.NumSourceLinesPerSecond 2,358,917 2,368,253 9,336 0.4%
AST.NumTotalClangImportedEntities 4,628,547 4,610,977 -17,570 -0.38%
Driver.ChildrenMaxRSS 111,975,247,872 112,294,797,312 319,549,440 0.29%
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,330 19,330 0 0.0%
Driver.NumDriverJobsSkipped 0 0 0 0.0%
Driver.NumProcessFailures 0 0 0 0.0%
Frontend.MaxMallocUsage 741,416,535,016 738,209,505,424 -3,207,029,592 -0.43%
Frontend.NumInstructionsExecuted 30,606,461,120,804 30,372,863,531,297 -233,597,589,507 -0.76%
Frontend.NumProcessFailures 0 0 0 0.0%
IRModule.NumIRAliases 121,579 121,579 0 0.0%
IRModule.NumIRBasicBlocks 4,518,751 4,518,754 3 0.0%
IRModule.NumIRComdatSymbols 0 0 0 0.0%
IRModule.NumIRFunctions 2,138,233 2,138,240 7 0.0%
IRModule.NumIRGlobals 2,238,521 2,238,529 8 0.0%
IRModule.NumIRIFuncs 0 0 0 0.0%
IRModule.NumIRInsts 61,372,032 61,372,096 64 0.0%
IRModule.NumIRNamedMetaData 93,930 93,930 0 0.0%
IRModule.NumIRValueSymbols 3,907,095 3,907,110 15 0.0%
LLVM.NumLLVMBytesOutput 1,168,039,008 1,168,043,644 4,636 0.0%
Parse.NumFunctionsParsed 174,293 174,293 0 0.0%
Parse.NumIterableDeclContextParsed 1,188,598 1,188,598 0 0.0%
SILModule.NumSILGenDefaultWitnessTables 0 0 0 0.0%
SILModule.NumSILGenFunctions 1,101,363 1,100,148 -1,215 -0.11%
SILModule.NumSILGenGlobalVariables 41,604 41,604 0 0.0%
SILModule.NumSILGenVtables 12,415 12,415 0 0.0%
SILModule.NumSILGenWitnessTables 46,811 46,421 -390 -0.83%
SILModule.NumSILOptDefaultWitnessTables 0 0 0 0.0%
SILModule.NumSILOptFunctions 1,566,803 1,565,310 -1,493 -0.1%
SILModule.NumSILOptGlobalVariables 42,499 42,499 0 0.0%
SILModule.NumSILOptVtables 20,589 20,589 0 0.0%
SILModule.NumSILOptWitnessTables 102,467 101,981 -486 -0.47%
Sema.AccessLevelRequest 2,849,946 2,845,845 -4,101 -0.14%
Sema.AttachedPropertyDelegateRequest 1,456,288 1,454,701 -1,587 -0.11%
Sema.AttachedPropertyDelegateTypeRequest 279,543 279,161 -382 -0.14%
Sema.CustomAttrNominalRequest 0 0 0 0.0%
Sema.DefaultAndMaxAccessLevelRequest 63,685 63,694 9 0.01%
Sema.EnumRawTypeRequest 18,268 18,246 -22 -0.12%
Sema.ExtendedNominalRequest 4,102,235 4,091,954 -10,281 -0.25%
Sema.InheritedDeclsReferencedRequest 4,599,722 4,570,056 -29,666 -0.64%
Sema.InheritedTypeRequest 648,763 648,066 -697 -0.11%
Sema.IsDynamicRequest 2,220,945 2,218,591 -2,354 -0.11%
Sema.IsFinalRequest 4,014,953 3,991,781 -23,172 -0.58%
Sema.IsObjCRequest 1,948,247 1,945,105 -3,142 -0.16%
Sema.MangleLocalTypeDeclRequest 246 246 0 0.0%
Sema.NamedLazyMemberLoadFailureCount 23,473 23,397 -76 -0.32%
Sema.NamedLazyMemberLoadSuccessCount 20,551,301 20,530,728 -20,573 -0.1%
Sema.NominalTypeLookupDirectCount 34,405,060 34,287,466 -117,594 -0.34%
Sema.NumConformancesDeserialized 6,888,076 6,836,074 -52,002 -0.75%
Sema.NumConstraintScopes 19,770,750 19,636,063 -134,687 -0.68%
Sema.NumConstraintsConsideredForEdgeContraction 52,019,322 52,010,413 -8,909 -0.02%
Sema.NumDeclsDeserialized 52,080,243 51,688,945 -391,298 -0.75%
Sema.NumDeclsFinalized 2,012,905 2,010,940 -1,965 -0.1%
Sema.NumDeclsTypechecked 1,040,157 1,040,154 -3 -0.0%
Sema.NumGenericSignatureBuilders 1,301,056 1,296,583 -4,473 -0.34%
Sema.NumLazyGenericEnvironments 10,517,637 10,482,593 -35,044 -0.33%
Sema.NumLazyGenericEnvironmentsLoaded 224,368 224,092 -276 -0.12%
Sema.NumLazyIterableDeclContexts 7,311,217 7,294,824 -16,393 -0.22%
Sema.NumLeafScopes 13,104,892 12,975,633 -129,259 -0.99%
Sema.NumTypesDeserialized 17,712,202 17,638,265 -73,937 -0.42%
Sema.NumTypesValidated 1,827,336 1,826,537 -799 -0.04%
Sema.NumUnloadedLazyIterableDeclContexts 4,820,350 4,821,405 1,055 0.02%
Sema.PropertyDelegateBackingPropertyInfoRequest 277,026 276,644 -382 -0.14%
Sema.PropertyDelegateBackingPropertyTypeRequest 279,543 279,161 -382 -0.14%
Sema.PropertyDelegateTypeInfoRequest 0 0 0 0.0%
Sema.RequirementRequest 71,175 71,173 -2 -0.0%
Sema.SelfBoundsFromWhereClauseRequest 6,652,488 6,609,590 -42,898 -0.64%
Sema.SetterAccessLevelRequest 159,441 159,221 -220 -0.14%
Sema.StructuralTypeRequest 0 0 0 0.0%
Sema.SuperclassDeclRequest 88,837 88,580 -257 -0.29%
Sema.SuperclassTypeRequest 38,570 38,525 -45 -0.12%
Sema.TypeDeclsFromWhereClauseRequest 33,150 33,161 11 0.03%
Sema.UnderlyingTypeDeclsReferencedRequest 180,392 179,631 -761 -0.42%

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 31,137,643,145,115 31,110,164,319,120 -27,478,825,995 -0.09%
LLVM.NumLLVMBytesOutput 994,396,686 994,396,530 -156 -0.0%
time.swift-driver.wall 5430.9s 5413.8s -17.1s -0.31%

release detailed

Regressed (0)
name old new delta delta_pct
Improved (2)
name old new delta delta_pct
Sema.NumDeclsValidated 1,244,363 1,218,107 -26,256 -2.11% ✅
Sema.NumFunctionsTypechecked 489,129 367,910 -121,219 -24.78% ✅
Unchanged (delta < 1.0% or delta < 100.0ms) (20)
name old new delta delta_pct
AST.NumImportedExternalDefinitions 233,224 233,224 0 0.0%
AST.NumLoadedModules 16,875 16,875 0 0.0%
AST.NumTotalClangImportedEntities 803,549 803,187 -362 -0.05%
IRModule.NumIRBasicBlocks 3,956,632 3,956,616 -16 -0.0%
IRModule.NumIRFunctions 1,793,281 1,793,281 0 0.0%
IRModule.NumIRGlobals 1,971,426 1,971,433 7 0.0%
IRModule.NumIRInsts 36,349,572 36,349,475 -97 -0.0%
IRModule.NumIRValueSymbols 3,496,248 3,496,255 7 0.0%
LLVM.NumLLVMBytesOutput 994,396,686 994,396,530 -156 -0.0%
SILModule.NumSILGenFunctions 762,829 762,566 -263 -0.03%
SILModule.NumSILOptFunctions 1,020,342 1,020,117 -225 -0.02%
Sema.NumConformancesDeserialized 2,358,078 2,357,798 -280 -0.01%
Sema.NumConstraintScopes 17,909,448 17,783,280 -126,168 -0.7%
Sema.NumDeclsDeserialized 6,349,469 6,348,954 -515 -0.01%
Sema.NumGenericSignatureBuilders 211,537 211,495 -42 -0.02%
Sema.NumLazyGenericEnvironments 1,301,804 1,301,602 -202 -0.02%
Sema.NumLazyGenericEnvironmentsLoaded 22,517 22,496 -21 -0.09%
Sema.NumLazyIterableDeclContexts 809,618 809,569 -49 -0.01%
Sema.NumTypesDeserialized 3,364,571 3,364,031 -540 -0.02%
Sema.NumTypesValidated 751,167 751,167 0 0.0%

When applying a solution to a nil literal of Optional type, we would
build a direct reference to Optional<T>.none instead of leaving the
NilLiteralExpr in place, because this would generate more efficient
SIL that avoided the call to the Optional(nilLiteral: ()) witness.

However, a few places in the type checker build type-checked AST, and
they build NilLiteralExpr directly. Moving the peephole to SILGen's
lowering of NilLiteralExpr allows us to simplify generated SIL even
further by eliding an unnecessary metatype value. Furthermore, it
allows SILGen to accept NilLiteralExprs that do not have a
ConcreteDeclRef set, which makes type-checked AST easier to build.
This includes all synthesized accessors except for lazy getters
and observer setters.

Building checked AST has certain advantages:

- It is faster, avoiding the need to create and solve ConstraintSystems
  or performing various diagnostic and semantic walks over the AST.

- It allows us to postpone delayed body synthesis until needed in SILGen,
  instead of having to walk a list of "external declarations" in Sema.

It also unblocks lazier conformance checking. Now that SILGen can
trigger conformance checking on its own, we need to be able to
synthesize bodies of accessors that witness protocol requirements.
This will allow us to eventually remove Sema's "used conformances"
list.

Note that for now, various utility functions in CodeSynthesis.cpp are
used for both checked and unchecked function bodies, so they take a
'typeChecked' boolean parameter that complicates some logic more than
necessary. Once the remaining body synthesizers are refactored to
build type-checked AST, the 'typeChecked' flag will go away.
Similarly to trivial accessors, the body of a synthesized
designated initializer override is simple enough that we can
build it directly without involving the constraint solver.
@slavapestov slavapestov force-pushed the fully-checked-trivial-accessors branch from 3cf8c2a to a18c32a Compare May 13, 2019 21:40
@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

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.

3 participants