Commit Graph

1267 Commits

Author SHA1 Message Date
swift_jenkins
8be3f2244f Merge remote-tracking branch 'origin/master' into master-next 2019-11-20 23:40:29 -08:00
Slava Pestov
53bfc767a3 SIL: Track target formal type for casts
SIL type lowering erases DynamicSelfType, so we generate
incorrect code when casting to DynamicSelfType. Fixing this
requires a fair amount of plumbing, but most of the
changes are mechanical.

Note that the textual SIL syntax for casts has changed
slightly; the target type is now a formal type without a '$',
not a SIL type.

Also, the unconditional_checked_cast_value and
checked_cast_value_br instructions now take the _source_
formal type as well, just like the *_addr forms they are
intended to replace.
2019-11-20 21:30:28 -05:00
swift_jenkins
be06b455b9 Merge remote-tracking branch 'origin/master' into master-next 2019-11-18 14:39:34 -08:00
Slava Pestov
86f6570662 Stop using SharedTimer except to implement FrontendStatsTracer
Name binding can trigger swiftinterface compilation, which creates
a new ASTContext and runs a compilation job. If the compiler was
run with -stats-output-dir, this could trigger an assertion because
SharedTimer is not re-entrant.

Fix this by replacing all direct uses of SharedTimer in the frontend
with FrontendStatsTracer. SharedTimer is still used to _implement_
FrontendStatsTracer, however we can collapse some of the layers in
the implementation later. Many of the usages should also become
redundant over time once more code is converted over to requests.
2019-11-18 12:05:49 -05:00
swift_jenkins
d5ca3542c3 Merge remote-tracking branch 'origin/master' into master-next 2019-11-16 18:40:34 -08:00
swift-ci
9a1d482bde Merge pull request #28307 from dan-zheng/autodiff-cleanup 2019-11-16 18:30:27 -08:00
Dan Zheng
2d2a5ded9d [AutoDiff upstream] Minor cleanup for @differentiable attribute.
Add TODO comments referencing JIRA issues.

Add disabled `@differentiable` attribute serialization test.
TF-836 tracks enabling the test.
Blocked by TF-828: `@differentiable` attribute type-checking.
2019-11-16 15:12:47 -08:00
Marc Rasi
6e559ab8fa rename nondiff => noDerivative 2019-11-15 16:36:26 -08:00
Marc Rasi
f5677cbe42 add @nondiff to AnyFunctionType params 2019-11-14 16:49:22 -08:00
Alex Lorenz
2f78afa4a2 Merge pull request #28214 from francisvm/bitstream-changes/master
Cherry-pick LLVM Bitstream changes
2019-11-14 10:14:29 -08:00
swift-ci
9b98492953 Merge remote-tracking branch 'origin/master' into master-next 2019-11-12 17:30:10 -08:00
Marc Rasi
6413f4341a [AutoDiff upstream] AST bits for @differentiable fn ty 2019-11-12 15:19:03 -08:00
Francis Visoiu Mistrih
47c6ce2af7 [Bitcode] Update includes: llvm/Bitcode -> llvm/Bitstream
The Bitstream part of Bitcode moved to llvm/Bitstream in LLVM. This
updates the uses in swift.

See r365091 [Bitcode] Move Bitstream to a separate library.

(cherry picked from commit 1cd8e19357)
2019-11-12 10:46:07 -08:00
swift-ci
c10a5f7cb1 Merge remote-tracking branch 'origin/master' into master-next 2019-11-11 14:10:53 -08:00
Gogul Balakrishnan
5accda22b2 [AutoDiff upstream] Introduce @differentiable attribute to mark functions as differentiable. (#27506)
This PR introduces `@differentiable` attribute to mark functions as differentiable. This PR only contains changes related to parsing the attribute. Type checking and other changes will be added in subsequent patches.

See https://github.com/apple/swift/pull/27506/files#diff-f3216f4188fd5ed34e1007e5a9c2490f for examples and tests for the new attribute.
2019-11-11 13:58:34 -08:00
swift-ci
5f9e32b974 Merge remote-tracking branch 'origin/master' into master-next 2019-11-04 17:30:26 -08:00
Hamish Knight
92c42ec791 [AST] Add @_nonEphemeral parameter attribute
This non-user-facing attribute is used to denote pointer parameters
which do not accept pointers produced from temporary pointer conversions
such as array-to-pointer, string-to-pointer, and in some cases
inout-to-pointer.
2019-11-03 08:40:59 -08:00
swift-ci
0b41d02a4d Merge remote-tracking branch 'origin/master' into master-next 2019-10-31 20:49:50 -07:00
Brent Royal-Gordon
17169fc1fe Merge pull request #27950 from brentdax/dumpster-fire
[NFC] Standardize dump() methods in frontend
2019-10-31 20:36:26 -07:00
Brent Royal-Gordon
99faa033fc [NFC] Standardize dump() methods in frontend
By convention, most structs and classes in the Swift compiler include a `dump()` method which prints debugging information. This method is meant to be called only from the debugger, but this means they’re often unused and may be eliminated from optimized binaries. On the other hand, some parts of the compiler call `dump()` methods directly despite them being intended as a pure debugging aid. clang supports attributes which can be used to avoid these problems, but they’re used very inconsistently across the compiler.

This commit adds `SWIFT_DEBUG_DUMP` and `SWIFT_DEBUG_DUMPER(<name>(<params>))` macros to declare `dump()` methods with the appropriate set of attributes and adopts this macro throughout the frontend. It does not pervasively adopt this macro in SILGen, SILOptimizer, or IRGen; these components use `dump()` methods in a different way where they’re frequently called from debugging code. Nor does it adopt it in runtime components like swiftRuntime and swiftReflection, because I’m a bit worried about size.

Despite the large number of files and lines affected, this change is NFC.
2019-10-31 18:37:42 -07:00
swift-ci
2689ff9343 Merge remote-tracking branch 'origin/master' into master-next 2019-10-30 07:49:45 -07:00
Robert Widmann
b849e51768 Use operator bool to claw back some readability 2019-10-29 16:56:21 -07:00
Robert Widmann
37e82a6133 [NFC] getWitnessMethodConformanceOrNone -> getWitnessMethodConformanceOrInvalid 2019-10-29 16:56:20 -07:00
Robert Widmann
3e1a61f425 [NFC] Fold The Tri-State In Optional<ProtocolConformanceRef>
ProtocolConformanceRef already has an invalid state.  Drop all of the
uses of Optional<ProtocolConformanceRef> and just use
ProtocolConformanceRef::forInvalid() to represent it.  Mechanically
translate all of the callers and callsites to use this new
representation.
2019-10-29 16:55:56 -07:00
Xi Ge
64c0680686 Merge remote-tracking branch 'apple/master' into master-next 2019-10-28 10:19:36 -07:00
Joe Groff
dc0f770364 remove todo warnings, oops 2019-10-26 10:49:47 -07:00
Joe Groff
03c7919b4a SIL: Add fields to SILFunctionType for substituted function types.
https://forums.swift.org/t/improving-the-representation-of-polymorphic-interfaces-in-sil-with-substituted-function-types/29711

This prepares SIL to be able to more accurately preserve the calling convention of
polymorphic generic interfaces by letting the type system represent "substituted function types".
We add a couple of fields to SILFunctionType to support this:

- A substitution map, accessed by `getSubstitutions()`, which maps the generic signature
  of the function to its concrete implementation. This will allow, for instance, a protocol
  witness for a requirement of type `<Self: P> (Self, ...) -> ...` for a concrete conforming
  type `Foo` to express its type as `<Self: P> (Self, ...) -> ... for <Foo>`, preserving the relation
  to the protocol interface without relying on the pile of hacks that is the `witness_method`
  protocol.

- A bool for whether the generic signature of the function is "implied" by the substitutions.
  If true, the generic signature isn't really part of the calling convention of the function.
  This will allow closure types to distinguish a closure being passed to a generic function, like
  `<T, U> in (*T, *U) -> T for <Int, String>`, from the concrete type `(*Int, *String) -> Int`,
  which will make it easier for us to differentiate the representation of those as types, for
  instance by giving them different pointer authentication discriminators to harden arm64e
  code.

This patch is currently NFC, it just introduces the new APIs and takes a first pass at updating
code to use them. Much more work will need to be done once we start exercising these new
fields.

This does bifurcate some existing APIs:

- SILFunctionType now has two accessors to get its generic signature.
  `getSubstGenericSignature` gets the generic signature that is used to apply its
  substitution map, if any. `getInvocationGenericSignature` gets the generic signature
  used to invoke the function at apply sites. These differ if the generic signature is
  implied.
- SILParameterInfo and SILResultInfo values carry the unsubstituted types of the parameters
  and results of the function. They now have two APIs to get that type. `getInterfaceType`
  returns the unsubstituted type of the generic interface, and
  `getArgumentType`/`getReturnValueType` produce the substituted type that is used at
  apply sites.
2019-10-25 13:38:51 -07:00
Jordan Rose
a52fac4470 [Serialization] Store whether an override depends on its base for ABI (#27784)
In some circumstances, a Swift declaration in module A will depend on
another declaration (usually from Objective-C) that can't be loaded,
for whatever reason. If the Swift declaration is *overriding* the
missing declaration, this can present a problem, because the way
methods are dispatched in Swift can depend on knowing the original
class that introduced the method. However, if the compiler can prove
that the override can still be safely invoked/used in all cases, it
doesn't need to worry about the overridden declaration being missing.

This is especially relevant for property accessors, because there's
currently no logic to recover from a property being successfully
deserialized and then finding out that an accessor couldn't be.

The decision of whether or not an override can be safely invoked
without knowledge of the base method is something to be cautious
about---a mistaken analysis would effectively be a miscompile. So up
until now, this was limited to one case: when a method is known to be
`@objc dynamic`, i.e. always dispatched through objc_msgSend. (Even
this may become questionable if we have first-class method references,
like we do for key paths.) This worked particularly well because the
compiler infers 'dynamic' for any overload of an imported Objective-C
method or accessor, in case it imports differently in a different
-swift-version and a client ends up subclassing it.

However...that inference does not apply if the class is final, because
then there are no subclasses to worry about.

This commit changes the test to be more careful: if the /missing/
declaration was `@objc dynamic`, we know that it can't affect ABI,
because either the override is properly `@objc dynamic` as well, or
the override has introduced its own calling ABI (in practice, a direct
call for final methods) that doesn't depend on the superclass. Again,
this isn't 100% correct in the presence of first-class methods, but it
does fix the issue in practice where a property accessor in a parent
class goes missing. And since Objective-C allows adding property
setters separately from the original property declaration, that's
something that can happen even under normal circumstances. Sadly.

This approach could probably be extended to constructors as well. I'm
a little more cautious about throwing vars and subscripts into the mix
because of the presence of key paths, which do allow identity-based
comparison of overrides and bases.

rdar://problem/56388950
2019-10-21 15:53:25 -07:00
Robert Widmann
3b829943af Uniformly iterate over the pattern binding entry indices
Clarify a bunch of C-style for loops and remove a ton of references to getPatternList().
2019-10-17 13:39:07 -07:00
Robert Widmann
56b6e53dae Remove raw references to PatternBindingEntry APIs
Switch most callers to explicit indices.  The exceptions lie in things that needs to manipulate the parsed output directly including the Parser and components of the ASTScope.  These are included as friend class exceptions.
2019-10-17 13:31:14 -07:00
swift-ci
4950d131b2 Merge remote-tracking branch 'origin/master' into master-next 2019-10-10 17:29:58 -07:00
Jordan Rose
171ff440fc Remove swift::reversed in favor of llvm::reverse (#27610)
The former predates the latter, but we don't need it anymore! The
latter has more features anyway.

No functionality change.
2019-10-10 17:16:09 -07:00
swift-ci
97f8ee294c Merge remote-tracking branch 'origin/master' into master-next 2019-10-10 17:09:54 -07:00
Slava Pestov
3dbdc09a4e Sema: Move ParamDecl interface type computation to validateDecl()
This eliminates typeCheckParameterList() altogether.
2019-10-10 15:28:14 -04:00
swift-ci
cd91226313 Merge remote-tracking branch 'origin/master' into master-next 2019-10-08 18:29:14 -07:00
Slava Pestov
a6b5824dac AST: Correctly set parent DeclContext of ParamDecls in EnumElementDecls
When an EnumElementDecl is parsed, we create the parameter list before
creating the EnumElementDecl itself, so we have to re-parent those
ParamDecls just like we do for functions and subscripts.
2019-10-08 18:39:00 -04:00
swift-ci
82f5b72f7f Merge remote-tracking branch 'origin/master' into master-next 2019-10-02 18:49:28 -07:00
Robert Widmann
2fe3ce8af8 Requestify the Raw Value Accessor
Make getRawValueExpr() return a checked value.

This entails a strange kind of request that effectively acts like
a cache warmer.  In order to properly check the raw value expression for
a single case, we actually need all the other cases for the
autoincrementing synthesis logic.  The strategy is therefore to have the
request act at the level of the parent EnumDecl and check all the values
at once.  We also cache at the level of the EnumDecl so the cache
"warms" for all enum elements simultaneously.

The request also abuses TypeResolutionStage to act as an indicator for
how much information to compute.  In the minimal case, we will return
a complete accounting of (auto-incremented) raw values.  In the maximal
case we will also check and record types and emit diagnostics.  The
minimal case is uncached to support repeated evaluation.

Note that computing the interface type of an @objc enum decl *must*
force this request.  The enum's raw values are part of the ABI, and we
should not get all the way to IRGen before discovering that we cannot
possibly lay out the enum.  In the future, we might want to consider
moving this check earlier or have IRGen tolerate broken cases but for
now we will maintain the status quo and not have IRGen emit
diagnostics.
2019-10-02 16:09:25 -07:00
swift-ci
5e50242b5e Merge remote-tracking branch 'origin/master' into master-next 2019-09-30 16:09:53 -07:00
Robert Widmann
5a8d0744c3 [NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic
signatures by separating the interface into GenericSignature and the
implementation into GenericSignatureBase.  In particular, this allows
the comparison operators to be deleted which forces callers to
canonicalize the signature or ask to compare pointers explicitly.
2019-09-30 14:04:36 -07:00
swift-ci
7fd05165cd Merge remote-tracking branch 'origin/master' into master-next 2019-09-26 12:50:17 -07:00
Harlan Haskins
b904133c42 [Modules] Add flag to skip non-inlinable function bodies
This flag, currently staged in as `-experimental-skip-non-inlinable-function-bodies`, will cause the typechecker to skip typechecking bodies of functions that will not be serialized in the resulting `.swiftmodule`. This patch also includes a SIL verifier that ensures that we don’t accidentally include a body that we should have skipped.

There is still some work left to make sure the emitted .swiftmodule is exactly the same as what’s emitted without the flag, which is what’s causing the benchmark noise above. I’ll be committing follow-up patches to address those, but for now I’m going to land the implementation behind a flag.
2019-09-26 10:40:11 -07:00
Alex Langford
4a95258316 Fix errant use of llvm::make_unique
This looks to be a mismerge from master. master-next uses std::make_unique
instead of the now defunct llvm::make_unique
2019-09-25 13:48:53 -07:00
swift-ci
76e7b1d2eb Merge remote-tracking branch 'origin/master' into master-next 2019-09-24 20:50:21 -07:00
Xi Ge
3103b5cec1 Frontend: set up output file .swiftsourceinfo
This patch will focus on teaching driver and frontend to emit this file.
The actual content and de-serialization parts will come later.

More details: https://forums.swift.org/t/proposal-emitting-source-information-file-during-compilation/28794
2019-09-24 13:52:17 -07:00
swift-ci
388697b23c Merge remote-tracking branch 'origin/master' into master-next 2019-09-23 22:50:12 -07:00
Robert Widmann
f053f9c480 Port getInterfaceType() patterns in libSema 2019-09-23 16:49:29 -07:00
swift-ci
7a21185ac1 Merge remote-tracking branch 'origin/master' into master-next 2019-09-21 08:11:08 -07:00
Robert Widmann
b135928125 Drop CheckingWithValidSignature from the validation state machine
Now that the generic signature is computable on demand, this predicate is doubly useless.  All of the callers intended to ask "hasInterfaceType" anyways.
2019-09-20 22:22:49 -07:00
swift-ci
8ce5b01307 Merge remote-tracking branch 'origin/master' into master-next 2019-09-18 15:09:47 -07:00