Skip to content

Declaration checker cleanups #15408

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 12 commits into from
Mar 22, 2018

Conversation

slavapestov
Copy link
Contributor

@slavapestov slavapestov commented Mar 21, 2018

Inspired by a forum post by @davezarzycki: https://forums.swift.org/t/is-decl-semantic-checking-two-or-three-pass/11231:

  • typeCheckDecl() no longer has IsSecondPass
  • validateDecl() no longer calls typeCheckDecl()
  • Re-declaration checking is now only done for declarations in the primary file(s)

Removing IsFirstPass is a bit trickier.

@@ -480,6 +480,7 @@ class StmtChecker : public StmtVisitor<StmtChecker, Stmt*> {
}

Stmt *visitDeferStmt(DeferStmt *DS) {
TC.typeCheckDecl(DS->getTempDecl(), /*isFirstPass*/true);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think these are deliberately not doing two passes because they are local, as you said.

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'm hoping to get rid of the two passes altogether, but even then if we make two passes over local declarations it shouldn't make much of a difference since it's doing the same amount of work in the end.

@slavapestov slavapestov force-pushed the decl-checker-cleanup branch from 1e6844c to ddee48e Compare March 22, 2018 00:44
…e init

The importer would only synthesize its own memberwise init if the
declaration had a zero initializer, which supresses Sema's automatic
synthesis. Trouble is we cannot rely on Sema synthesizing the
memberwise init in case we deserialize declarations after type
checking.

Some other changes caught this with an assert, so fix the importer
to do the right thing here.
This avoids emitting a diagnostic twice with a subsequent change.
The DeclChecker had three possible states:

- IsFirstPass true, IsSecondPass false. This is the 'first pass' for
  declarations that appear at the top-level, or are nested inside
  top-level types.

- IsFirstPass false, IsSecondPass true. This is the 'second pass' for
  declarations that appear at the top-level, or are nested inside
  top-level types.

- IsFirstPass false, IsSecondPass false. This was used for (some)
  local declarations.

This is unnecessarily confusing. We can eliminate the third state
by calling typeCheckDecl() twice in a few places. This allows
IsSecondPass to be removed entirely since it's now always equal to
!IsFirstPass.
We're going to visit it later after we type check it anyway.
@slavapestov slavapestov force-pushed the decl-checker-cleanup branch from ddee48e to 6caa7b3 Compare March 22, 2018 04:42
@slavapestov slavapestov force-pushed the decl-checker-cleanup branch from 6caa7b3 to a6ff282 Compare March 22, 2018 06:57
@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test

@slavapestov
Copy link
Contributor Author

@swift-ci Please test source compatibility

@slavapestov
Copy link
Contributor Author

@swift-ci Please smoke test compiler performance

@swift-ci
Copy link
Contributor

Build comment file:

Summary for master smoketest

No regressions above thresholds

Debug

debug 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) (2)
name old new delta delta_pct
LLVM.NumLLVMBytesOutput 47,006,426 47,004,893 -1,533 -0.0%
time.swift-driver.wall 79.0s 78.8s -199.2ms -0.25%

debug detailed

Regressed (0)
name old new delta delta_pct
Improved (1)
name old new delta delta_pct
Sema.NumDeclsValidated 184,366 162,677 -21,689 -11.76% ✅
Unchanged (delta < 1.0% or delta < 100.0ms) (22)
name old new delta delta_pct
AST.NumImportedExternalDefinitions 113,826 113,826 0 0.0%
AST.NumLoadedModules 16,158 16,158 0 0.0%
AST.NumTotalClangImportedEntities 333,024 333,024 0 0.0%
AST.NumUsedConformances 9,439 9,439 0 0.0%
IRModule.NumIRBasicBlocks 135,839 135,839 0 0.0%
IRModule.NumIRFunctions 80,197 80,197 0 0.0%
IRModule.NumIRGlobals 74,909 74,909 0 0.0%
IRModule.NumIRInsts 1,493,619 1,493,619 0 0.0%
IRModule.NumIRValueSymbols 138,281 138,281 0 0.0%
LLVM.NumLLVMBytesOutput 47,006,426 47,004,893 -1,533 -0.0%
SILModule.NumSILGenFunctions 51,279 51,279 0 0.0%
SILModule.NumSILOptFunctions 92,132 92,132 0 0.0%
Sema.NumConformancesDeserialized 462,810 462,810 0 0.0%
Sema.NumConstraintScopes 1,018,426 1,018,426 0 0.0%
Sema.NumDeclsDeserialized 3,053,209 3,053,209 0 0.0%
Sema.NumFunctionsTypechecked 64,396 64,396 0 0.0%
Sema.NumGenericSignatureBuilders 85,474 85,444 -30 -0.04%
Sema.NumLazyGenericEnvironments 605,876 605,918 42 0.01%
Sema.NumLazyGenericEnvironmentsLoaded 50,031 50,001 -30 -0.06%
Sema.NumLazyIterableDeclContexts 439,149 439,149 0 0.0%
Sema.NumTypesDeserialized 3,279,656 3,279,656 0 0.0%
Sema.NumTypesValidated 273,154 272,638 -516 -0.19%

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) (2)
name old new delta delta_pct
LLVM.NumLLVMBytesOutput 38,487,585 38,487,582 -3 -0.0%
time.swift-driver.wall 175.5s 175.6s 80.5ms 0.05%

release detailed

Regressed (0)
name old new delta delta_pct
Improved (1)
name old new delta delta_pct
Sema.NumDeclsValidated 37,251 31,065 -6,186 -16.61% ✅
Unchanged (delta < 1.0% or delta < 100.0ms) (22)
name old new delta delta_pct
AST.NumImportedExternalDefinitions 11,354 11,354 0 0.0%
AST.NumLoadedModules 462 462 0 0.0%
AST.NumTotalClangImportedEntities 31,515 31,515 0 0.0%
AST.NumUsedConformances 9,444 9,444 0 0.0%
IRModule.NumIRBasicBlocks 177,477 177,477 0 0.0%
IRModule.NumIRFunctions 61,660 61,660 0 0.0%
IRModule.NumIRGlobals 60,791 60,791 0 0.0%
IRModule.NumIRInsts 1,479,334 1,479,334 0 0.0%
IRModule.NumIRValueSymbols 110,755 110,755 0 0.0%
LLVM.NumLLVMBytesOutput 38,487,585 38,487,582 -3 -0.0%
SILModule.NumSILGenFunctions 26,022 26,022 0 0.0%
SILModule.NumSILOptFunctions 42,654 42,654 0 0.0%
Sema.NumConformancesDeserialized 156,378 156,378 0 0.0%
Sema.NumConstraintScopes 876,815 876,815 0 0.0%
Sema.NumDeclsDeserialized 258,435 258,435 0 0.0%
Sema.NumFunctionsTypechecked 12,616 12,616 0 0.0%
Sema.NumGenericSignatureBuilders 7,664 7,664 0 0.0%
Sema.NumLazyGenericEnvironments 39,785 39,785 0 0.0%
Sema.NumLazyGenericEnvironmentsLoaded 5,035 5,035 0 0.0%
Sema.NumLazyIterableDeclContexts 24,625 24,625 0 0.0%
Sema.NumTypesDeserialized 315,069 315,069 0 0.0%
Sema.NumTypesValidated 44,130 44,130 0 0.0%

@slavapestov slavapestov merged commit 31aa280 into swiftlang:master Mar 22, 2018
aschwaighofer added a commit to aschwaighofer/swift that referenced this pull request Mar 22, 2018
It started failing after swiftlang#15408.

SR-7255
rdar://38751453
@aschwaighofer
Copy link
Contributor

This causes a failure on some bots and PR testing https://ci.swift.org/job/oss-swift-pr-test/1659/

I am disabling the test until you get a chance to look at it: #15421

@jrose-apple
Copy link
Contributor

The test run you linked doesn't show that test failing. Can you find one where it does?

(The test you named has very little to do with this change.)

@aschwaighofer
Copy link
Contributor

@aschwaighofer
Copy link
Contributor

I will revert the disabling commit again since it only failed once on one bot: #15426

@jrose-apple
Copy link
Contributor

Yeah, that's definitely weird but it's very unlikely to be this change's fault.

@slavapestov
Copy link
Contributor Author

That yet has been flaky in the past. It’s not related to these changes

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