Commit Graph

185 Commits

Author SHA1 Message Date
Slava Pestov
9f8760b942 AST: Remove unused 'resolver' parameter from ModuleDecl::lookupConformance()
... as well as a bunch of downstream plumbing that is no
longer necessary.
2017-09-07 03:36:17 -07:00
Slava Pestov
5973a2722c SILOptimizer: Fix some unused variable warnings 2017-09-01 02:04:22 -07:00
Joe Shajrawi
8b0eac5cbc Fixes a bug in eraseUsesOfInstruction's iterator 2017-08-29 17:43:25 -07:00
Jordan Rose
449cd98997 Excise "Accessibility" from the compiler (3/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

Rename AccessibilityAttr to AccessControlAttr and
SetterAccessibilityAttr to SetterAccessAttr, then track down the last
few uses of "accessibility" that don't have to do with
NSAccessibility. (I left the SourceKit XPC API alone because that's
supposed to be more stable.)
2017-08-28 13:27:59 -07:00
Jordan Rose
1c651973c3 Excise "Accessibility" from the compiler (2/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the 'Accessibility' enum to be named 'AccessLevel'.
2017-08-28 11:34:44 -07:00
Jordan Rose
5f30eac288 Excise "Accessibility" from the compiler (1/3)
"Accessibility" has a different meaning for app developers, so we've
already deliberately excised it from our diagnostics in favor of terms
like "access control" and "access level". Do the same in the compiler
now that we aren't constantly pulling things into the release branch.

This commit changes the names of methods, fields, a few local
variables, and even a swift-ide-test flag. The full list is below.

accessibilityForDiagnostics -> accessLevelForDiagnostics
checkAccessibility -> checkAccess
checkGenericParamAccessibility -> checkGenericParamAccess
checkTypeAccessibility -> checkTypeAccess
checkWitnessAccessibility -> checkWitnessAccessibility
computeAccessibility -> computeAccessLevel
computeDefaultAccessibility -> computeDefaultAccessLevel
fixItAccessibility -> fixItAccess
getAccessibilityString -> getAccessLevelString
getAccessibilityStrictly -> getAccessLevelStrictly
getAccessibilityUID -> getAccessLevelUID
getActualAccessibility -> getActualAccessLevel
getDefaultAccessibility -> getDefaultAccessLevel
getMaxAccessibility -> getMaxAccessLevel
getOverridableAccessibility -> getOverridableAccessLevel
getRawStableAccessibility -> getRawStableAccessLevel
getSetterAccessibility -> getSetterFormalAccess
hasAccessibility -> hasAccess
hasDefaultAccessibility -> hasDefaultAccessLevel
inferAccessibility -> inferAccessLevel
inferDefaultAccessibility -> inferDefaultAccessLevel
inferSetterAccessibility -> inferSetterAccessLevel
overwriteAccessibility -> overwriteAccess
overwriteSetterAccessibility -> overwriteSetterAccess
printAccessibility -> printAccess
requiredAccessibilityForDiagnostics -> requiredAccessForDiagnostics
resolveAccessibility -> resolveAccessControl
setAccessibility -> setAccess
setSetterAccessibility -> setSetterAccess
setDefaultAndMaxAccessibility -> setDefaultAndMaxAccess
validateAccessibility -> validateAccessControl

Accessibility -> AccessLevel
AccessibilityFilter -> AccessFilter
IgnoreAccessibility -> IgnoreAccessControl
NL_IgnoreAccessibility -> NL_IgnoreAccessControl
PrintAccessibility -> PrintAccess
PrintInternalAccessibilityKeyword -> PrintInternalAccessKeyword
SetterAccessibility -> SetterAccessLevel

setterAccessibility -> setterAccess
storedPropertyAccessibility -> storedPropertyAccess

-print-accessibility -> -print-access
2017-08-28 11:11:57 -07:00
Joe Shajrawi
8911d9a0fd Merge pull request #11520 from shajrawi/reduce_explosion
Reduce expansion of large types in the optimizer
2017-08-25 14:19:16 -07:00
Joe Shajrawi
570a82aea5 Reduce expansion of large types in the optimizer 2017-08-25 13:56:26 -07:00
Andrew Trick
5aac427ee0 SIL Ownership: Remove consumptionKind from SIL unconditional cast and related logic.
Remove the cast consumption kind from all unconditional casts. It
doesn't make sense for unconditional casts, complicates SIL ownership,
and wasn't fully supported for all variants. Copies should be
explicit.
2017-08-18 20:44:54 -07:00
Andrew Trick
6124ae69c4 Fix simplifyCheckedCastAddrBranchInst to properly destroy the value.
Fixes a change from earlier today that popped up on ASAN.
The fix also uses a more idiomatic approach to destroying values.
2017-07-31 23:53:26 -07:00
Andrew Trick
98be5f1a55 Fix SIL checked_cast_br optimization to obey the consumptionKind.
This is a theoretically SIL optimizer bug that won't be reached in
practice. Nevertheless the code is wrong as written.
2017-07-31 14:41:57 -07:00
Michael Gottesman
81914b9234 When creating destroys for addresses passed into a partial apply, first move the values into a stack location with a live range that is guaranteed to be larger than the partial apply's live range.
Otherwise, we may insert destroy_addrs on alloc_stack whose lifetimes have
ended.

rdar://33502257
2017-07-27 20:48:47 -07:00
Erik Eckstein
6377cc095a SIL: Replace TransitivelyUnreachableBlocks with DeadEndBlocks
We had both utilities doing the same thing.
NFC
2017-07-24 09:50:42 -07:00
Erik Eckstein
a0e6082d25 SILOptimizer: change the way how ValueLifetimeAnalysis handles dead-end (unreachable) CFG paths.
In dead-array elimination we assume that the array allocation is post-dominated by all its final releases.
The only exception are branches to dead-end ("unreachable") blocks. So we just ignored all paths which didn't end up in a final release.
Now we explicitly pass the set of dead-end blocks and just ignore those blocks.
This is safer and it's also needed in the upcoming re-write of StackPromotion.
2017-07-21 10:46:03 -07:00
Erik Eckstein
3b54966ff2 SILOptimizer: Add a utility to find dead-end blocks. 2017-07-21 10:37:54 -07:00
Michael Gottesman
5a2556eeca [sil-combine] When deleting a dead partial_apply, insert a destroy for all non-trivial captured values.
partial_apply is a confusing instruction since it:

1. Is printed with a function signature.
2. Takes in some arguments of the same type as the underlying types of the given function signatures.
3. Always takes in those arguments at +1 regardless of the convention printed on the partial apply.

Eventually we will split the partial apply representation so that the box is
represnted explicitly separately from the function signature, eliminating this
confusion.

The problem that we ran into here is that we were not treating @in values from
an alloc_stack or @in_guaranteed at all correctly. The reason why the tests did
not catch this is that a seperate sil_combine optimization that eliminates
trivially dead live ranges was eliminting the alloc_stack of the @in value in
our test. In contrast, the @in_guaranteed case was actually never tested at all.

I added tests for all of these conventions and in addition added a special mode
to SILCombine that stops the alloc_stack eliminating during testing.

rdar://32887993
2017-07-06 17:01:43 -07:00
Roman Levenstein
cae00b96c7 [cast-optimizer] Add a new peephole for casting types to protocols they statically conform to
This peephole is to avoid runtime calls:
unconditional_checked_cast_addr T in %0 : $*T to P in %1 : $*P
->
%addr = init_existential_addr %1 : $*P, T
copy_addr %0 to %addr

where T is a type statically known to conform to non-class existential P.

In caase P is a class existential type, it generates:
%val = load %0 : $*T
%existential = init_existential_ref %val : $T, $T, P
store %existential to %1 : $*P
2017-05-25 08:17:59 -07:00
Roman Levenstein
98f14360a8 [cast-optimizer] Assert and clarify in comments that bridged casts are not possible in certain cases yet 2017-05-22 13:51:01 -07:00
Roman Levenstein
28a7236a4e [cast-optimizer] Use a more correct check for isConditional flag 2017-05-22 13:51:01 -07:00
Roman Levenstein
4ef29e57af [cast-optimizer] Properly handle conditional bridged casts in optimizeBridgedSwiftToObjCCast
If there is a conditional bridged cast from a swift type to an objc type and this cast happens in two stages, where:
-  in the firs stage the Swift type is casted to its bridged ObjC class (e.g. String to NSString) and
-  in the second stage there is a downcast to a subclass of a bridged ObjC class (e.g. NSString to MyString)

then the second stage should use a conditional cast.

rdar://32319580
2017-05-22 13:51:01 -07:00
Roman Levenstein
62e1944d7b [cast-optimizer] Bail out on a conditional downcast to a subclass of a bridged ObjC class
This is very conservative fix for rdar://problem/32316838.
A more aggressive fix would introduce a conditional cast.
2017-05-21 22:51:28 -07:00
Joe Groff
4e9851b032 Don't classify bridging casts as WillSucceed if the object-to-value cast can fail.
When casting from an object type to a bridged Swift value type, classifyDynamicCast would use the cast classification for the target type's bridged object type, which would be trivially WillSucceed for thinks like NSNumber-to-Int or NSError-to-SomeError, even though the bridging itself could fail. Fixing this fixes SR-2920|rdar://problem/31404281.
2017-05-12 10:39:39 -07:00
Roman Levenstein
ecf1c09eca [cast-optimizer] Fix a small bug related to opened existentials tracking
Fixes rdar://32124747
2017-05-11 11:53:40 -07:00
Roman Levenstein
40231ef18f [cast-optimizer] Fix a bug in a peephole for existential metatypes
If the concrete type is an existential or a generic type, we should not perform the optimization, because we don’t know enough information about it.

Fixes rdar://31372306
2017-05-11 11:53:40 -07:00
Roman Levenstein
aa2c88ebcc [cast-optimizer] Fix comments 2017-05-11 11:46:41 -07:00
Roman Levenstein
f909858f53 Remove dead code that became obsolete after re-factoring 2017-05-10 08:04:28 -07:00
Roman Levenstein
45c2c4af0e Re-factoring: Get rid of useless arguments in "create*Apply" functions
Till now createApply, createTryApply, createPartialApply were taking some arguments like SubstCalleeType or ResultType. But these arguments are redundant and can be easily derived from other arguments of these functions. There is no need to put the burden of their computation on the clients of these APIs.

The removal of these redundant parameters simplifies the APIs and reduces the possibility of providing mismatched types by clients, which often happened in the past.
2017-05-10 08:03:37 -07:00
practicalswift
492f5cd35a [gardening] Remove redundant repetition of type names (DRY): RepeatedTypeName foo = dyn_cast<RepeatedTypeName>(bar)
Replace `NameOfType foo = dyn_cast<NameOfType>(bar)` with DRY version `auto foo = dyn_cast<NameOfType>(bar)`.

The DRY auto version is by far the dominant form already used in the repo, so this PR merely brings the exceptional cases (redundant repetition form) in line with the dominant form (auto form).

See the [C++ Core Guidelines](https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#es11-use-auto-to-avoid-redundant-repetition-of-type-names) for a general discussion on why to use `auto` to avoid redundant repetition of type names.
2017-05-05 09:45:53 +02:00
Joe Shajrawi
d17258cac7 @in_constant calling convention - part of passing large loadable types by address 2017-04-30 10:13:02 -07:00
Roman Levenstein
30a50f9ef0 [sil-cast-optimizer] Fix a silly bug related to canonical types
This bug occurs in real projects, when type aliases are involved.
The test-case is a bit hard to provide. I’ll try to provide it later, if I managed to reduce the original project to a small test-case.
But the fix is very obvious.

Fixes rdar://31768258
2017-04-26 09:49:14 -07:00
Doug Gregor
f7e05fd951 [Bridging cast optimization] Unchecked casts can perform a class downcast.
Handle a class downcast following a bridging cast. Fixes
rdar://problem/31791421.
2017-04-25 13:43:06 -07:00
Slava Pestov
f4b91cd118 AST: Remove unused 'resolver' argument from TypeBase::getSuperclass() 2017-04-20 00:37:38 -07:00
Erik Eckstein
805960b0ac ValueLifetimeAnalysis: fix the lifetime computation in case the value definition is in a single-block loop.
This caused DeadObjectElimination to generate a memory leak in case a dead array is in a single-block loop.
rdar://problem/31420889
2017-04-04 10:43:53 -07:00
Michael Gottesman
bd225f9fc4 [capture-promotion] Update capture-promotion for semantic-sil.
rdar://29870610
2017-04-02 11:44:14 -07:00
Slava Pestov
289428ca55 SILOptimizer: Always use Shared linkage for specializations of serialized things
With -sil-serialize-all, we might deserialize and specialize
a private function from multiple TUs which are then linked
together.

Since private symbols have unique mangling, this is fine.

It's hard to make a test for this since it only happens with
-sil-serialize-all, which I'd like to kill soon anyway.
2017-03-31 20:26:26 -07:00
Slava Pestov
8fe8b89b0f SIL: Terminology change: [fragile] => [serialized]
Also, add a third [serializable] state for functions whose bodies we
*can* serialize, but only do so if they're referenced from another
serialized function.

This will be used for bodies synthesized for imported definitions,
such as init(rawValue:), etc, and various thunks, but for now this
change is NFC.
2017-03-29 16:47:28 -07:00
Roman Levenstein
8082e820c9 [sil-optimizer] Make compile time concatenation of constant strings work again
This guaranteed optimization got lost when a + operator for Strings was made a static method on type String.

Fixes SR-4348
2017-03-24 15:55:50 -07:00
Hugh Bellamy
d1849d7c28 Fix top of tree Clang compilation errors 2017-03-21 19:16:39 +07:00
practicalswift
83526fe224 [gardening] Use .is<T>() instead of .getAs<T>() if the result is not needed 2017-03-20 22:54:01 +01:00
Joe Shajrawi
e20653ad04 Merge pull request #8090 from shajrawi/ConsumptionKind_UnconditionalCheckedCastValue
Add consumption kind to UnconditionalCheckedCastValueInst
2017-03-14 15:30:26 -07:00
Joe Shajrawi
ea4ba25b8a Add consumption kind to UnconditionalCheckedCastValueInst 2017-03-14 13:53:05 -07:00
John McCall
3c5de5fa0a Preserve type canonicality better in several places and
idiomatize some uses of SILType::getSwiftRValueType().
2017-03-14 14:59:43 -04:00
John McCall
897f5ab7c5 Restore CanType-based micro-optimizations.
This reverts commit 5036806e5a.
However, it preserves a pair of changes to the SIL optimizer
relating to walking through optional types.
2017-03-14 11:38:11 -04:00
Slava Pestov
5036806e5a AST: Remove some unnecessary getCanonicalType() calls 2017-03-13 02:24:36 -07:00
Slava Pestov
76eb5dd66d SILGen: Clean up ad-hoc SubstitutionList construction when calling intrinsics
Change emitApplyOfLibraryIntrinsic() to take a SubstitutionMap,
and use the correct abstractions to build the map.

This gets rid of the last remaining uses of gatherAllSubstitutions()
in SIL.
2017-03-08 13:54:29 -08:00
Slava Pestov
5465c8ca8f SIL: Remove most usages of TypeBase::gatherAllSubstitutions() 2017-03-08 13:54:28 -08:00
Joe Shajrawi
33b0cf653f Rename unconditional_checked_cast_opaque to unconditional_checked_cast_value 2017-03-07 18:53:52 -08:00
Joe Shajrawi
1f626304f1 Add support for conditional checked cast instruction for opaque value types + SILGen support for it 2017-03-06 16:35:27 -08:00
Slava Pestov
0611d663b8 SIL: Remove SILType::getSwiftType() 2017-02-27 20:01:35 -08:00
Roman Levenstein
6c1eec81c4 Merge pull request #7557 from mtake/enhance-assume-single-threaded
Enhance -assume-single-threaded option (SR-3945)
2017-02-27 13:07:46 -08:00