Skip to content

[ConstraintSystem] Add a type variable merging heuristic to addJoinConstraint #33296

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 7 commits into from
Aug 7, 2020

Conversation

hborla
Copy link
Member

@hborla hborla commented Aug 4, 2020

  • Add a heuristic to addJoinConstraint that merges type variables for "atomic" literal expressions of the same kind. This is valid because such type variables will have the same set of constraints on them, and must be bound to the same type.
  • Add an overload of addJoinConstraint to take in an iterator range and a callback to get the input types/locators. This allows callers to lazily compute the inputs-to-join rather than construct an array beforehand. The old addJoinConstraint is now a wrapper around this new overload.
  • Use addJoinConstraint to join array element types.

Resolves: rdar://problem/66176314
Resolves: rdar://problem/30596744

…nstraint.

This heuristic merges type variables for literal expressions of the same
kind. This is valid because such type variables will have the same
set of constraints on them, and must be bound to the same type.
@hborla hborla requested review from xedin and DougGregor August 4, 2020 21:42
@hborla
Copy link
Member Author

hborla commented Aug 4, 2020

Still need to update the test and also use addJoinConstraint for arrays without a contextual type, but I'd love feedback on the changes to addJoinConstraint

@hborla hborla force-pushed the merge-joined-literal-typevars branch from da40585 to 5e7d7a9 Compare August 4, 2020 22:01
@hborla
Copy link
Member Author

hborla commented Aug 4, 2020

@swift-ci please smoke test compiler performance

@swift-ci
Copy link
Contributor

swift-ci commented Aug 5, 2020

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) (3)
name old new delta delta_pct
Frontend.NumInstructionsExecuted 2,245,161,926,056 2,250,062,060,505 4,900,134,449 0.22%
LLVM.NumLLVMBytesOutput 24,267,516 24,267,780 264 0.0%
time.swift-driver.wall 121.8s 121.8s 35.0ms 0.03%

debug detailed

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (16)
name old new delta delta_pct
AST.NumLoadedModules 4,715 4,715 0 0.0%
AST.NumTotalClangImportedEntities 35,693 35,693 0 0.0%
IRModule.NumIRBasicBlocks 87,267 87,267 0 0.0%
IRModule.NumIRFunctions 43,207 43,207 0 0.0%
IRModule.NumIRGlobals 48,853 48,853 0 0.0%
IRModule.NumIRInsts 1,133,647 1,133,647 0 0.0%
IRModule.NumIRValueSymbols 86,088 86,088 0 0.0%
LLVM.NumLLVMBytesOutput 24,267,516 24,267,780 264 0.0%
SILModule.NumSILGenFunctions 24,503 24,503 0 0.0%
SILModule.NumSILOptFunctions 29,205 29,205 0 0.0%
Sema.NumConformancesDeserialized 65,387 65,387 0 0.0%
Sema.NumConstraintScopes 140,968 140,852 -116 -0.08%
Sema.NumDeclsDeserialized 688,702 688,702 0 0.0%
Sema.NumGenericSignatureBuilders 11,756 11,756 0 0.0%
Sema.NumLazyIterableDeclContexts 121,932 121,932 0 0.0%
Sema.NumTypesDeserialized 253,039 253,039 0 0.0%

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 1,038,847,263,070 1,039,062,805,857 215,542,787 0.02%
LLVM.NumLLVMBytesOutput 29,839,564 29,839,380 -184 -0.0%
time.swift-driver.wall 190.3s 190.6s 370.2ms 0.19%

release detailed

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (16)
name old new delta delta_pct
AST.NumLoadedModules 266 266 0 0.0%
AST.NumTotalClangImportedEntities 10,500 10,500 0 0.0%
IRModule.NumIRBasicBlocks 77,960 77,960 0 0.0%
IRModule.NumIRFunctions 41,888 41,888 0 0.0%
IRModule.NumIRGlobals 53,269 53,269 0 0.0%
IRModule.NumIRInsts 777,946 777,946 0 0.0%
IRModule.NumIRValueSymbols 92,877 92,877 0 0.0%
LLVM.NumLLVMBytesOutput 29,839,564 29,839,380 -184 -0.0%
SILModule.NumSILGenFunctions 17,880 17,880 0 0.0%
SILModule.NumSILOptFunctions 14,561 14,561 0 0.0%
Sema.NumConformancesDeserialized 44,287 44,287 0 0.0%
Sema.NumConstraintScopes 164,028 163,908 -120 -0.07%
Sema.NumDeclsDeserialized 117,241 117,241 0 0.0%
Sema.NumGenericSignatureBuilders 3,271 3,271 0 0.0%
Sema.NumLazyIterableDeclContexts 15,122 15,122 0 0.0%
Sema.NumTypesDeserialized 63,135 63,135 0 0.0%

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

I feel like finding a representative (and equivalence class) for expressions and forming a join are two separate operations. Maybe this could be split into addJoinConstraint which takes expressions and another overload of it which takes an iterator over type variables so one call call another when needed.

@hborla
Copy link
Member Author

hborla commented Aug 5, 2020

I feel like finding a representative (and equivalence class) for expressions and forming a join are two separate operations. Maybe this could be split into addJoinConstraint which takes expressions and another overload of it which takes an iterator over type variables so one call call another when needed.

@xedin I don't think that, for this particular heuristic, joining types and merging representative type variables are two independent operations. Doing this in addJoinConstraint is crucial to the heuristic because we only know it's okay to merge the type variables if they're intended to be joined. I also think this is always valid to do when joining types so I don't think there should be a variant of addJoinConstraint that doesn't do the merging

@hborla hborla force-pushed the merge-joined-literal-typevars branch from 5e7d7a9 to ad77613 Compare August 5, 2020 21:12
@xedin
Copy link
Contributor

xedin commented Aug 5, 2020

@hborla Consider it from this perspective - join operator is responsive for establishing a particular relationship between a given set of type variables, its correctness is unrelated of properties of the type variables themselves. We are integrating heuristic into this method which is based on logic unrelated to the join operation itself - that all of the type variables of the same kind for an equivalence class - that by itself is true is certain situations e.g. if all of them are elements of a collection, arguments to a homogeneous call. I'm not sure if that's safe to do or does it just make it so any future use of addJoinConstraint has to be carefully considered based on the side-effect of merging it would introduce and could it possibly be.

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

LGTM!

@hborla
Copy link
Member Author

hborla commented Aug 6, 2020

@swift-ci please test source compatibility

@hborla
Copy link
Member Author

hborla commented Aug 6, 2020

@swift-ci please smoke test compiler performance

@swift-ci
Copy link
Contributor

swift-ci commented Aug 6, 2020

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) (3)
name old new delta delta_pct
Frontend.NumInstructionsExecuted 1,624,178,880,858 1,620,491,063,124 -3,687,817,734 -0.23%
LLVM.NumLLVMBytesOutput 24,267,972 24,267,632 -340 -0.0%
time.swift-driver.wall 109.7s 109.5s -155.2ms -0.14%

debug detailed

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (16)
name old new delta delta_pct
AST.NumLoadedModules 3,334 3,334 0 0.0%
AST.NumTotalClangImportedEntities 31,374 31,374 0 0.0%
IRModule.NumIRBasicBlocks 87,267 87,267 0 0.0%
IRModule.NumIRFunctions 43,207 43,207 0 0.0%
IRModule.NumIRGlobals 48,853 48,853 0 0.0%
IRModule.NumIRInsts 1,133,647 1,133,647 0 0.0%
IRModule.NumIRValueSymbols 86,088 86,088 0 0.0%
LLVM.NumLLVMBytesOutput 24,267,972 24,267,632 -340 -0.0%
SILModule.NumSILGenFunctions 24,503 24,503 0 0.0%
SILModule.NumSILOptFunctions 29,205 29,205 0 0.0%
Sema.NumConformancesDeserialized 59,344 59,344 0 0.0%
Sema.NumConstraintScopes 140,791 140,565 -226 -0.16%
Sema.NumDeclsDeserialized 606,292 606,292 0 0.0%
Sema.NumGenericSignatureBuilders 10,691 10,691 0 0.0%
Sema.NumLazyIterableDeclContexts 101,882 101,882 0 0.0%
Sema.NumTypesDeserialized 224,107 224,107 0 0.0%

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 1,037,782,031,643 1,037,844,553,282 62,521,639 0.01%
LLVM.NumLLVMBytesOutput 29,839,060 29,839,536 476 0.0%
time.swift-driver.wall 168.9s 169.1s 215.5ms 0.13%

release detailed

Regressed (0)
name old new delta delta_pct
Improved (0)
name old new delta delta_pct
Unchanged (delta < 1.0% or delta < 100.0ms) (16)
name old new delta delta_pct
AST.NumLoadedModules 266 266 0 0.0%
AST.NumTotalClangImportedEntities 10,500 10,500 0 0.0%
IRModule.NumIRBasicBlocks 77,960 77,960 0 0.0%
IRModule.NumIRFunctions 41,888 41,888 0 0.0%
IRModule.NumIRGlobals 53,269 53,269 0 0.0%
IRModule.NumIRInsts 777,946 777,946 0 0.0%
IRModule.NumIRValueSymbols 92,877 92,877 0 0.0%
LLVM.NumLLVMBytesOutput 29,839,060 29,839,536 476 0.0%
SILModule.NumSILGenFunctions 17,880 17,880 0 0.0%
SILModule.NumSILOptFunctions 14,561 14,561 0 0.0%
Sema.NumConformancesDeserialized 44,287 44,287 0 0.0%
Sema.NumConstraintScopes 164,028 163,744 -284 -0.17%
Sema.NumDeclsDeserialized 117,241 117,241 0 0.0%
Sema.NumGenericSignatureBuilders 3,271 3,271 0 0.0%
Sema.NumLazyIterableDeclContexts 15,122 15,122 0 0.0%
Sema.NumTypesDeserialized 63,135 63,135 0 0.0%

hborla added 3 commits August 6, 2020 07:36
an iterator range and a callback to get the type.

This allows callers to lazily compute the input types to join rather
than constructing an array first. The old addJoinConstraint is now
a wrapper for this new overload.
@hborla hborla force-pushed the merge-joined-literal-typevars branch from af01773 to cd44ca8 Compare August 6, 2020 14:37
@hborla
Copy link
Member Author

hborla commented Aug 6, 2020

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Aug 6, 2020

Build failed
Swift Test OS X Platform
Git Sha - da405858d6571923d0e2650357e79b09cc4a83cd

@swift-ci
Copy link
Contributor

swift-ci commented Aug 6, 2020

Build failed
Swift Test Linux Platform
Git Sha - da405858d6571923d0e2650357e79b09cc4a83cd

@hborla hborla marked this pull request as ready for review August 6, 2020 20:46
@hborla
Copy link
Member Author

hborla commented Aug 6, 2020

@swift-ci please smoke test

…ssage

for each element whose type variable was merged in addJoinConstraint
@hborla
Copy link
Member Author

hborla commented Aug 7, 2020

@swift-ci please smoke test

@hborla hborla merged commit 9e81823 into swiftlang:master Aug 7, 2020
@hborla hborla deleted the merge-joined-literal-typevars branch August 7, 2020 16:07
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