Commit Graph

2777 Commits

Author SHA1 Message Date
Michael Gottesman
430f865f73 [inliner] Extract out checking if we can inline from inlineFunction into canInlineFunction. NFC.
The reason to do this is:

1. The check in SILInliner if we can inline can be done without triggering
side-effects.

2. This enables us to know if inlining will succeed before attempting to inline.
This enables for arguments to be adjusted with new SILInstructions and the like
before inlining occurs. I use this in a forthcoming patch that updates mandatory
inlining for ownership.

rdar://31521023
2017-09-08 18:25:57 -07:00
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
Jordan Rose
f8b7db4e76 Excise the terms "blacklist" and "whitelist" from Swift source. (#11687)
The etymology of these terms isn't about race, but "black" = "blocked"
and "white" = "allowed" isn't really a good look these days. In most
cases we weren't using these terms particularly precisely anyway, so
the rephrasing is actually an improvement.
2017-08-30 09:28:00 -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
Erik Eckstein
9c6fe76927 SIL, IRGen: add instructions "object" and "global_value” to support statically initialized objects.
This commit contains:
-) adding the new instructions + infrastructure, like parsing, printing, etc.
-) support in IRGen to generate global object-variables (i.e. "heap" objects) which are statically initialized in the data section.
-) IRGen for global_value which lazily initializes the object header and returns a reference to the object.

For details see the documentation of the new instructions in SIL.rst.
2017-08-23 09:15:49 -07:00
Roman Levenstein
038dc3bd6a metatype_inst with a concrete, non-generic type can be considered a constant for the purposes of the pure invocations checks 2017-08-22 15:16:19 -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
Slava Pestov
cc5a3b0a9a SILOptimizer: Simplify getTargetClassMethod() 2017-08-14 23:56:17 -04:00
Roman Levenstein
661c8964c6 Collect statistics about prevented generic specializations
Count how many generic specializations were prevented due to the possibility of creating an infinite generic specialization loop and due to the complexity of their generic type parameters.
2017-08-07 08:23:46 -07:00
Roman Levenstein
ffa927a2dc Support even more complex cases of generic substitution loops
Allow for cases, where the old substitution type `T1` is partially contained in the new substitution type `T2`. Partially contained means that if you drop the common structural "prefix" of `T1` and `T2` and get `T1'` and `T2'` then `T1'` is strictly contained in `T2'`. E.g.  `Outer<Start>` is partially contained in `Outer<Step<Start>>` if you drop the common prefix `Outer`, then `Start` is contained in `Step<Start>`
2017-08-07 08:23:46 -07:00
Roman Levenstein
a920e32e54 Allocate GenericSpecializationInformation using SILModule's memory allocator. 2017-08-06 23:04:46 -07:00
Roman Levenstein
8503daee0d Implement a more robust way to avoid infinite generic specialization loops
The existing simple mechanism for avoiding infinite generic specialization loops is based on checking the structural depth and width of types passed as generic type parameters. If the depth or the width of a type is above a certain threshold, the type is considered too complex for generic specialization and no specialization is produced. While this approach prevents the possibility of producing an infinite number of generic specializations for ever-growing generic type parameters, it catches the issue too late in some cases, leading to excessive CPU and memory usage.

Therefore, the new method tries to solve the problem at its root. An infinite generic specialization loop can be triggered by specializing a given generic call-site if and only if:
-  Doing so would result in a loop inside the specialization graph represented by the `GenericSpecializationInformations`, i.e. it would produce direct or indirect recursion involving a generic call
-  The substitutions used by the current generic call-site are structurally more complex than the substitutions used by the same call-site in the previous iteration inside specialization graph. More complex in this context means that the new generic type parameter structurally contains the generic type parameter from a previous iteration inside the specialization graph and has greater structural depth, e.g. `Array<Int>` is more complex than `Int`.

The generic specializer now records all the required information about specializations it produces and uses it later to detect and prevent any generic specializations which would result in an infinite specialization loop. It detects them as early as possible and thus reduces compile times, memory consumption and potentially also reduces the code-size by not generating useless specializations.
2017-08-06 12:51:49 -07:00
Roman Levenstein
786c7a7513 [sil-devirtualizer] Code clean-up. Simplify the previous patch.
Since the return type of the callee is not changed and the old apply instruction is not removed by devirtualizeClassMethod, there is no need to insert an "unreachable" instruction, because by construction rules of SIL it should be already there right after the old apply.
2017-08-02 16:39:30 -07:00
Roman Levenstein
b83faa0109 [sil-devirtualizer] Fix a bug in devirtualization of methods that never return
This bug was caught by the SIL verifier. Any invocation of a NoReturn function should be followed by an `unreachable` instruction.

Fixes rdar://problem/33591235
2017-08-02 15:14:03 -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
Slava Pestov
74822250a5 SILOptimizer: Add a couple of FIXMEs for later 2017-07-24 22:38:33 -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
Andrew Trick
4db2a46cff Add SIL instruction: open_existential_box_value.
This has the same semantics as open_existential_box, but returns an object value
instead of an address.

This is used in SIL opaque values mode. Attempting to reuse open_existential_box
in this mode causes SIL type inconsistencies that are too difficult to work
around. Adding this instruction allows for consistent handling of opaque values.

The original versions of several of these currently redundant instructions will
be removed once the SIL representation stabilizes.
2017-07-17 23:46:41 -07:00
Andrew Trick
f657ad2d3a Rename *ExistentialOpaque instructions to *ExistentialValue.
These instructions have the same semantics as the *ExistentialAddr instructions
but operate directly on the existential value, not its address.

This is in preparation for adding ExistentialBoxValue instructions.
The previous name would cause impossible confusion with "opaque existentials"
and "opaque existential boxes".
2017-07-17 23:46:41 -07:00
Arnold Schwaighofer
a440302088 Inliner: Add @_semantics("inline_late")
@_semantics(inline_late) for inlining only outside the standard library in the
late performance inliner.

It can be beneficial to run the inliner only outside the standard library when
code size has been reduced far enough that inlining can take place based on the
inliner's heuristics.

rdar://33099675
SR-5360
2017-07-11 15:21:05 -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
abdee7fb43 [sil-inliner] Do not perform early performance inlining for functions with certain @_semantics attributes
Specifically, do not perform the early inlining for functions annotated with @_semantics("pair_no_escaping_closure") and @_semantics("self_no_escaping_closure")

Add new tests and cleanup some tests.

It recovers from the performance regression that was recently introduced.

Fixes rdar://32555803
2017-06-05 11:59:37 -07:00
Roman Levenstein
00d663d172 [sil-generic-specializer] Add @_semantics("optimize.sil.specialize.generic.partial.never") to disable partial specialization on functions
This new @_semantics is used to annotate some very big functions in the standard library. It reduced the code size of the stdlib by 2%.
2017-06-01 16:33:18 -07:00
Roman Levenstein
ef41353877 [sil-inliner] Skip only array @_semantics during early inlining
The inliner was skipping even non-array related @_semantics by mistake.
2017-06-01 14:09:22 -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
Erik Eckstein
6a478caf7d demangling: Drop the support of "unmangled suffix"
Either the demangling completely succeeds or it fails. Don't demangle to something like: [...] with unmangled suffix "..."

This avoids getting really stupid demangled names for symbols which are actually not swift symbols.
2017-05-24 17:00:20 -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
Roman Levenstein
341b5c506d [sil-inliner] Respect the @inline(__always) and @_transparent even if inlining of generics is disabled
If some functions are explicitly annotated by developers as @inline(__always) or @_transparent, they should always be a subject for the inlining of generics, even if this kind of inlining is not enabled currently for all functions.
2017-05-19 15:08:18 -07:00
Roman Levenstein
5b4691d901 Revert "[sil-inliner] Respect the @inline(__always) and @_transparent even if inlining of generics is disabled" 2017-05-19 08:20:55 -07:00
Roman Levenstein
3fcd6f40c8 [sil-inliner] Respect the @inline(__always) and @_transparent even if inlining of generics is disabled
If some functions are explicitly annotated by developers as @inline(__always) or @_transparent, they should always be a subject for the inlining of generics, even if this kind of inlining is not enabled currently for all functions.
2017-05-18 21:54:45 -07:00
Erik Eckstein
74fa0bcc87 Disable generic inlining and partial specialization, except in libswiftCore
This avoids code size regressions in programs while still getting the performance improvements in generic code in the stdlib.

rdar://problem/32277313
2017-05-18 15:38:54 -07:00
practicalswift
fbad9fc6b8 [gardening] Remove unused variable 2017-05-16 23:23:41 +02:00
Doug Gregor
fef69478f6 [GSB] Introduce computeGenericSignature() for generic signature creation.
The GenericSignatureBuilder requires `finalize()` to be called before a
generic signature can be retrieved with `getGenericSignature()`. Most of the former isn’t strictly needed unless you want a generic signature, and the 
latter is potentially expensive. `computeGenericSignature()` combines the two
operations together, since they are conceptually related. Update most of the
callers to the former two functions to use `computeGenericSignature()`.
2017-05-15 17:16:50 -07:00
Roman Levenstein
dd93027a0e Always inline pure functions with constant arguments
A function is pure if it has no side-effects.
If there is a call of a pure function with constant arguments, it always makes sense to inline it, because we know that the whole computation will be constant folded.
2017-05-15 11:52:36 -07:00
Roman Levenstein
d66924b01e [sil-inliner] Move some functionality from PerformanceInliner into PerformanceInlinerUtils. NFC.
It does not change any functionality. The only purpose it to make some functions reusable by other passes.
2017-05-15 09:03:53 -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