Skip to content
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

☣️[Sema] Transform initializers into coercions for conforming numeric literals #15311

Closed

Conversation

xedin
Copy link
Member

@xedin xedin commented Mar 16, 2018

To speed up type-checking for numeric literal types let's try to implicitly
convert expressions like UInt32(42) into 42 as UInt32 but only
if requested type conforms to the correct literal protocol.

The desired outcome is that we can properly type-check expressions
like UInt64(0xffff_ffff_ffff_ffff) and speed up solving of more
complex expressions by avoiding checking all of the initializer
overloads since most of them are likely unrelated.

@xedin xedin force-pushed the transform-constructors-into-coercions branch from 4a1da85 to 7d9c2b8 Compare March 16, 2018 22:57
@xedin
Copy link
Member Author

xedin commented Mar 16, 2018

@swift-ci please test source compatibility

@xedin
Copy link
Member Author

xedin commented Mar 16, 2018

🤞

@xwu
Copy link
Collaborator

xwu commented Mar 17, 2018

This is a potentially source-breaking change, although it's likely users would have wanted the new behavior all along. Previously, the possibility of warning the user in these cases was discussed.

However, surely, it can't be sound to have silently custom type inference rules specifically for these initializers and not other uses of literals as arguments.

Have you considered formally adopting the rule you're using above for all literal arguments (and, ideally, extending them to operators too)? That'd fix the heterogeneous-comparison-over-homogeneous-comparison-in-generic-code issue too!

…iterals

To speed up type-checking for numeric literal types let's try to
implicitly convert expressions like `UInt32(42)` into `42 as UInt32`
but only if requested type conforms to the correct literal protocol.

The desired outcome is that we can properly type-check expressions
like `UInt64(0xffff_ffff_ffff_ffff)` and speed up solving of more
complex expressions by avoiding checking all of the initializer
overloads since most of them are likely unrelated.
@xedin xedin force-pushed the transform-constructors-into-coercions branch from 7d9c2b8 to 4039e0f Compare March 17, 2018 01:16
@xedin
Copy link
Member Author

xedin commented Mar 17, 2018

@xwu The idea is to verify that this is going to help type-checker and other things, and if so then go through formal evolution process.

@xedin xedin changed the title ☣️[Sema] Transform initializers into coercions for conforming literals ☣️[Sema] Transform initializers into coercions for conforming numeric literals Mar 17, 2018
@xedin
Copy link
Member Author

xedin commented Mar 17, 2018

@swift-ci please test source compatibility

@xedin
Copy link
Member Author

xedin commented Mar 17, 2018

Only one project failed with an error I haven't see before:

/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/build/compat_macos/install/toolchain/usr/bin/swift -frontend -c /Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/Source/SiestaUI/Ω_UI_Deprecations.swift /Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/Source/SiestaUI/SiestaUI-ObjC.swift /Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/Source/SiestaUI/ResourceStatusOverlay.swift /Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/Source/Siesta/Support/Collection+Siesta.swift /Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/Source/SiestaUI/NetworkActivityIndicator.swift /Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/Source/SiestaUI/RemoteImageView.swift -supplementary-output-file-map /var/folders/_8/79jmzf2142z2xydc_01btlx00000gn/T/supplementaryOutputs-494e68 -target arm64-apple-ios8.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS11.3.sdk -I /Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Release-iphoneos -F /Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Release-iphoneos -F /Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/Carthage/Build/iOS -g -import-underlying-module -swift-version 3 -O -serialize-debugging-options -Xcc "-I/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/swift-overrides.hmap" -Xcc -iquote -Xcc "/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/SiestaUI-generated-files.hmap" -Xcc "-I/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/SiestaUI-own-target-headers.hmap" -Xcc "-I/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/SiestaUI-all-non-framework-target-headers.hmap" -Xcc -ivfsoverlay -Xcc /Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/all-product-headers.yaml -Xcc -iquote -Xcc "/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/SiestaUI-project-headers.hmap" -Xcc -I/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Release-iphoneos/include -Xcc "-I/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/DerivedSources/arm64" -Xcc "-I/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/DerivedSources" -Xcc -ivfsoverlay -Xcc "/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/unextended-module-overlay.yaml" -Xcc -working-directory/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta -module-name SiestaUI -num-threads 4 -o "/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/Objects-normal/arm64/Ω_UI_Deprecations.o" -o "/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/Objects-normal/arm64/SiestaUI-ObjC.o" -o "/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/Objects-normal/arm64/ResourceStatusOverlay.o" -o "/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/Objects-normal/arm64/Collection+Siesta.o" -o "/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/Objects-normal/arm64/NetworkActivityIndicator.o" -o "/Users/buildnode/jenkins/workspace-private/swift-PR-source-compat-suite/project_cache/siesta/build/Siesta.build/Release-iphoneos/SiestaUI iOS.build/Objects-normal/arm64/RemoteImageView.o"
/var/folders/_8/79jmzf2142z2xydc_01btlx00000gn/T/supplementaryOutputs-494e68:5:16: error: Unrecognized escape code!

@xedin
Copy link
Member Author

xedin commented Mar 17, 2018

@swift-ci please smoke benchmark compiler performance

@xedin
Copy link
Member Author

xedin commented Mar 17, 2018

@graydon @shahmishal Any idea why compiler performance CI isn't triggering?

@xedin
Copy link
Member Author

xedin commented Mar 17, 2018

Ok, it's just me being stupid...

@xedin
Copy link
Member Author

xedin commented Mar 17, 2018

@swift-ci Please smoke test compiler performance

@swift-ci
Copy link
Collaborator

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 46,771,280 46,769,908 -1,372 -0.0%
time.swift-driver.wall 79.3s 79.5s 156.0ms 0.2%

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) (23)
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 331,937 331,925 -12 -0.0%
AST.NumUsedConformances 9,439 9,433 -6 -0.06%
IRModule.NumIRBasicBlocks 137,575 137,575 0 0.0%
IRModule.NumIRFunctions 80,629 80,627 -2 -0.0%
IRModule.NumIRGlobals 73,185 73,175 -10 -0.01%
IRModule.NumIRInsts 1,505,762 1,505,694 -68 -0.0%
IRModule.NumIRValueSymbols 138,258 138,246 -12 -0.01%
LLVM.NumLLVMBytesOutput 46,771,280 46,769,908 -1,372 -0.0%
SILModule.NumSILGenFunctions 51,485 51,483 -2 -0.0%
SILModule.NumSILOptFunctions 92,172 92,172 0 0.0%
Sema.NumConformancesDeserialized 464,261 463,747 -514 -0.11%
Sema.NumConstraintScopes 1,040,697 1,040,415 -282 -0.03%
Sema.NumDeclsDeserialized 3,044,586 3,044,280 -306 -0.01%
Sema.NumDeclsValidated 184,368 184,368 0 0.0%
Sema.NumFunctionsTypechecked 64,396 64,396 0 0.0%
Sema.NumGenericSignatureBuilders 85,488 85,488 0 0.0%
Sema.NumLazyGenericEnvironments 604,261 604,247 -14 -0.0%
Sema.NumLazyGenericEnvironmentsLoaded 50,785 50,777 -8 -0.02%
Sema.NumLazyIterableDeclContexts 438,280 438,206 -74 -0.02%
Sema.NumTypesDeserialized 3,272,402 3,272,204 -198 -0.01%
Sema.NumTypesValidated 273,522 273,526 4 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) (2)
name old new delta delta_pct
LLVM.NumLLVMBytesOutput 38,973,476 38,973,468 -8 -0.0%
time.swift-driver.wall 178.5s 178.8s 244.8ms 0.14%

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) (23)
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,403 31,391 -12 -0.04%
AST.NumUsedConformances 9,444 9,438 -6 -0.06%
IRModule.NumIRBasicBlocks 176,935 176,935 0 0.0%
IRModule.NumIRFunctions 62,275 62,275 0 0.0%
IRModule.NumIRGlobals 59,146 59,146 0 0.0%
IRModule.NumIRInsts 1,446,857 1,446,857 0 0.0%
IRModule.NumIRValueSymbols 109,794 109,794 0 0.0%
LLVM.NumLLVMBytesOutput 38,973,476 38,973,468 -8 -0.0%
SILModule.NumSILGenFunctions 26,029 26,027 -2 -0.01%
SILModule.NumSILOptFunctions 43,693 43,638 -55 -0.13%
Sema.NumConformancesDeserialized 157,113 156,989 -124 -0.08%
Sema.NumConstraintScopes 897,405 897,123 -282 -0.03%
Sema.NumDeclsDeserialized 256,964 256,712 -252 -0.1%
Sema.NumDeclsValidated 37,253 37,253 0 0.0%
Sema.NumFunctionsTypechecked 12,616 12,616 0 0.0%
Sema.NumGenericSignatureBuilders 7,666 7,666 0 0.0%
Sema.NumLazyGenericEnvironments 39,635 39,629 -6 -0.02%
Sema.NumLazyGenericEnvironmentsLoaded 5,113 5,111 -2 -0.04%
Sema.NumLazyIterableDeclContexts 24,580 24,508 -72 -0.29%
Sema.NumTypesDeserialized 313,886 313,734 -152 -0.05%
Sema.NumTypesValidated 44,453 44,457 4 0.01%

@xedin
Copy link
Member Author

xedin commented Mar 17, 2018

@swift-ci please test compiler performance

1 similar comment
@xedin
Copy link
Member Author

xedin commented Mar 17, 2018

@swift-ci please test compiler performance

@swift-ci
Copy link
Collaborator

Build comment file:

Summary for master full

Unexpected test results, excluded stats for ChattoAdditions, CoreStore, SourceKittenFramework, StencilSwiftKit, AMScrollingNavbar, ProcedureKit, GRDB, JSQDataSourcesKit, AsyncNinja, ReactiveCocoa, IBAnimatable, ObjectMapper

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 833,886,169 834,161,060 274,891 0.03%
time.swift-driver.wall 1540.0s 1536.6s -3.4s -0.22%

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) (23)
name old new delta delta_pct
AST.NumImportedExternalDefinitions 1,043,525 1,043,525 0 0.0%
AST.NumLoadedModules 253,150 253,150 0 0.0%
AST.NumTotalClangImportedEntities 3,324,772 3,324,328 -444 -0.01%
AST.NumUsedConformances 116,342 116,174 -168 -0.14%
IRModule.NumIRBasicBlocks 2,376,858 2,376,535 -323 -0.01%
IRModule.NumIRFunctions 1,242,149 1,242,093 -56 -0.0%
IRModule.NumIRGlobals 1,213,349 1,213,080 -269 -0.02%
IRModule.NumIRInsts 27,452,549 27,519,327 66,778 0.24%
IRModule.NumIRValueSymbols 2,178,774 2,178,449 -325 -0.01%
LLVM.NumLLVMBytesOutput 833,886,169 834,161,060 274,891 0.03%
SILModule.NumSILGenFunctions 788,717 788,646 -71 -0.01%
SILModule.NumSILOptFunctions 1,178,758 1,178,734 -24 -0.0%
Sema.NumConformancesDeserialized 4,804,498 4,789,084 -15,414 -0.32%
Sema.NumConstraintScopes 9,189,965 9,176,034 -13,931 -0.15%
Sema.NumDeclsDeserialized 37,844,682 37,830,429 -14,253 -0.04%
Sema.NumDeclsValidated 1,487,818 1,487,807 -11 -0.0%
Sema.NumFunctionsTypechecked 651,265 651,265 0 0.0%
Sema.NumGenericSignatureBuilders 1,134,197 1,134,144 -53 -0.0%
Sema.NumLazyGenericEnvironments 7,508,230 7,506,956 -1,274 -0.02%
Sema.NumLazyGenericEnvironmentsLoaded 662,298 662,046 -252 -0.04%
Sema.NumLazyIterableDeclContexts 5,797,516 5,794,637 -2,879 -0.05%
Sema.NumTypesDeserialized 39,636,666 39,628,120 -8,546 -0.02%
Sema.NumTypesValidated 3,780,128 3,780,287 159 0.0%

Debug-opt

debug-opt 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 824,546,412 824,760,436 214,024 0.03%
time.swift-driver.wall 2717.5s 2708.0s -9.5s -0.35%

debug-opt 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) (23)
name old new delta delta_pct
AST.NumImportedExternalDefinitions 1,043,525 1,043,525 0 0.0%
AST.NumLoadedModules 243,185 243,185 0 0.0%
AST.NumTotalClangImportedEntities 3,407,797 3,407,353 -444 -0.01%
AST.NumUsedConformances 116,342 116,174 -168 -0.14%
IRModule.NumIRBasicBlocks 2,767,426 2,767,263 -163 -0.01%
IRModule.NumIRFunctions 1,030,186 1,030,230 44 0.0%
IRModule.NumIRGlobals 997,754 997,750 -4 -0.0%
IRModule.NumIRInsts 23,568,373 23,632,729 64,356 0.27%
IRModule.NumIRValueSymbols 1,851,637 1,851,677 40 0.0%
LLVM.NumLLVMBytesOutput 824,546,412 824,760,436 214,024 0.03%
SILModule.NumSILGenFunctions 787,534 787,463 -71 -0.01%
SILModule.NumSILOptFunctions 1,646,913 1,640,589 -6,324 -0.38%
Sema.NumConformancesDeserialized 10,204,292 10,163,004 -41,288 -0.4%
Sema.NumConstraintScopes 9,189,965 9,176,034 -13,931 -0.15%
Sema.NumDeclsDeserialized 43,561,533 43,541,772 -19,761 -0.05%
Sema.NumDeclsValidated 1,487,818 1,487,807 -11 -0.0%
Sema.NumFunctionsTypechecked 651,265 651,265 0 0.0%
Sema.NumGenericSignatureBuilders 1,178,101 1,177,827 -274 -0.02%
Sema.NumLazyGenericEnvironments 8,417,366 8,415,751 -1,615 -0.02%
Sema.NumLazyGenericEnvironmentsLoaded 678,944 678,690 -254 -0.04%
Sema.NumLazyIterableDeclContexts 6,137,156 6,134,040 -3,116 -0.05%
Sema.NumTypesDeserialized 46,864,802 46,846,131 -18,671 -0.04%
Sema.NumTypesValidated 3,780,128 3,780,287 159 0.0%

Wmo-onone

wmo-onone 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 761,279,352 761,582,732 303,380 0.04%
time.swift-driver.wall 1416.8s 1411.1s -5.8s -0.41%

wmo-onone 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) (23)
name old new delta delta_pct
AST.NumImportedExternalDefinitions 158,407 158,407 0 0.0%
AST.NumLoadedModules 11,082 11,082 0 0.0%
AST.NumTotalClangImportedEntities 503,673 503,307 -366 -0.07%
AST.NumUsedConformances 120,159 119,995 -164 -0.14%
IRModule.NumIRBasicBlocks 2,046,319 2,045,980 -339 -0.02%
IRModule.NumIRFunctions 1,167,305 1,167,248 -57 -0.0%
IRModule.NumIRGlobals 1,091,702 1,091,426 -276 -0.03%
IRModule.NumIRInsts 25,627,230 25,698,390 71,160 0.28%
IRModule.NumIRValueSymbols 2,027,831 2,027,498 -333 -0.02%
LLVM.NumLLVMBytesOutput 761,279,352 761,582,732 303,380 0.04%
SILModule.NumSILGenFunctions 470,427 470,379 -48 -0.01%
SILModule.NumSILOptFunctions 548,475 548,458 -17 -0.0%
Sema.NumConformancesDeserialized 1,370,150 1,363,381 -6,769 -0.49%
Sema.NumConstraintScopes 8,908,830 8,894,860 -13,970 -0.16%
Sema.NumDeclsDeserialized 4,650,376 4,642,190 -8,186 -0.18%
Sema.NumDeclsValidated 786,855 786,855 0 0.0%
Sema.NumFunctionsTypechecked 244,726 244,726 0 0.0%
Sema.NumGenericSignatureBuilders 151,388 151,382 -6 -0.0%
Sema.NumLazyGenericEnvironments 799,156 798,671 -485 -0.06%
Sema.NumLazyGenericEnvironmentsLoaded 95,246 95,159 -87 -0.09%
Sema.NumLazyIterableDeclContexts 498,292 496,651 -1,641 -0.33%
Sema.NumTypesDeserialized 4,803,365 4,798,181 -5,184 -0.11%
Sema.NumTypesValidated 1,154,383 1,154,564 181 0.02%

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 817,844,502 818,098,888 254,386 0.03%
time.swift-driver.wall 3190.3s 3182.9s -7.4s -0.23%

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) (23)
name old new delta delta_pct
AST.NumImportedExternalDefinitions 277,253 277,253 0 0.0%
AST.NumLoadedModules 38,602 38,602 0 0.0%
AST.NumTotalClangImportedEntities 866,347 865,981 -366 -0.04%
AST.NumUsedConformances 123,363 123,195 -168 -0.14%
IRModule.NumIRBasicBlocks 2,443,041 2,442,904 -137 -0.01%
IRModule.NumIRFunctions 1,077,012 1,077,060 48 0.0%
IRModule.NumIRGlobals 1,083,708 1,083,702 -6 -0.0%
IRModule.NumIRInsts 22,409,463 22,479,538 70,075 0.31%
IRModule.NumIRValueSymbols 1,966,846 1,966,888 42 0.0%
LLVM.NumLLVMBytesOutput 817,844,502 818,098,888 254,386 0.03%
SILModule.NumSILGenFunctions 489,552 489,504 -48 -0.01%
SILModule.NumSILOptFunctions 820,288 818,310 -1,978 -0.24%
Sema.NumConformancesDeserialized 3,290,547 3,286,430 -4,117 -0.13%
Sema.NumConstraintScopes 9,120,350 9,106,350 -14,000 -0.15%
Sema.NumDeclsDeserialized 8,673,851 8,666,451 -7,400 -0.09%
Sema.NumDeclsValidated 840,505 840,505 0 0.0%
Sema.NumFunctionsTypechecked 300,162 300,162 0 0.0%
Sema.NumGenericSignatureBuilders 278,996 278,973 -23 -0.01%
Sema.NumLazyGenericEnvironments 1,533,451 1,533,041 -410 -0.03%
Sema.NumLazyGenericEnvironmentsLoaded 153,195 153,108 -87 -0.06%
Sema.NumLazyIterableDeclContexts 1,098,575 1,096,947 -1,628 -0.15%
Sema.NumTypesDeserialized 9,660,702 9,656,119 -4,583 -0.05%
Sema.NumTypesValidated 1,433,969 1,434,152 183 0.01%

@xedin
Copy link
Member Author

xedin commented Mar 19, 2018

I'll try another way where instead of converting to coercion I'm just going to favor overloads which satisfy protocol requirement related to literals, that should work for every literal protocol and be less intrusive (but would still require swift-evolution proposal).

@xedin xedin closed this Mar 19, 2018
@xedin
Copy link
Member Author

xedin commented Mar 22, 2018

@xwu I've created a pitch for these changes - https://forums.swift.org/t/pitch-literal-initialization-via-coercion/11251 (going to open separate PR if everything goes fine).

@lattner
Copy link
Collaborator

lattner commented Apr 1, 2018

Instead of rewriting this in the precheck pass, have you considered just generating different constraints in CSApply? That would keep the AST aligned with what the user wrote. I realize that that would make it a trickier patch, I'm just wondering if you considered the tradeoffs and discussed it with @rudkx ?

@xedin
Copy link
Member Author

xedin commented Apr 1, 2018

@lattner Yes, we've discussed it with @rudkx and @DougGregor and came to the conclusion that preCheckExpression is the best place for this transformation.

@rudkx
Copy link
Member

rudkx commented Apr 2, 2018

@lattner I'm curious if you have specific benefits in mind to implementing this completely in the constraint system rather than doing this as a sort of desugaring during preCheckExpression?

@lattner
Copy link
Collaborator

lattner commented Apr 2, 2018

I don't have specific goals, other than keeping the ASTs more closely aligned to source code. This tends to matter for refactoring and source transformation'y things, and is an (academically) more pure way to go.

@xedin
Copy link
Member Author

xedin commented Apr 2, 2018

For what it's worth I can look into how to do the same thing when we generate overload sets for constructors, so the overload for the literal protocol requirement is favored in this situation, which should produce exactly the same results.

@rudkx
Copy link
Member

rudkx commented Apr 2, 2018

@lattner I assumed you might be thinking of one or more of those concerns but didn't want to be a mind-reader so I thought I would ask.

@xedin I wonder if we could just bind the appropriate overload and effectively treat T(literal) like T(literal as T) and eliminate both the type variable for the literal and the one for the disjunction, all during constraint generation (without changing the AST)? If we need to use the favoring mechanism that's fine, but I'm hoping long term we can just eliminate that.

return nullptr;

auto *argExpr = call->getArg()->getSemanticsProvidingExpr();
auto *number = dyn_cast<NumberLiteralExpr>(argExpr);
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this apply to all literal kinds? For example, Set([1, 2, 3])?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, I just tried with NumberLiteralExpr because I ran into problem with failable initializer in swiftpm clashing with ExpressibleByStringLiteral but still wanted to get some performance numbers, and NumberLiteralExpr since to be the biggest pain point for stdlib folks anyway.

auto result = TC.conformsToProtocol(type, protocol, DC, options);
if (result) {
auto *expr =
new (TC.Context) CoerceExpr(argExpr, {}, typeExpr->getTypeRepr());
Copy link
Member

Choose a reason for hiding this comment

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

We're losing a bunch of the source information in doing this. Should we try to make this a constraint-system change and have CSApply fix up the result, rather than turning it into a CoerceExpr?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's on my agenda to do next.

@xedin xedin closed this Jul 10, 2018
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.

None yet

6 participants