Commit Graph

577 Commits

Author SHA1 Message Date
Holly Borla
24826e01bd Merge pull request #29775 from hborla/parse-type-eraser-attribute
[Parse] Add an attribute for typeEraser.
2020-02-12 09:58:14 -08:00
Holly Borla
ffba71b889 [Parse] Add an attribute for typeEraser.
This will be used for compiler-driven type erasure for dynamic
replacement of functions with an opaque return type. For now, just
parse the attribute and ignore it.
2020-02-11 17:30:21 -08:00
Michael Gottesman
67e57f3083 [master-rebranch] Running into some weird module version issues on master-rebranch. Bumping the module version just in case. 2020-02-09 19:11:35 -08:00
Robert Widmann
f56fee839b [ModuleInterface] Pass Through Flags for Nested Types Tables
When a swift module is generated from a swift interface file, we must
remember to setup the nested types tables. Plumb the flag down from the
frontend options.

In the future, we must remove the ability to turn this off. There's
literally zero reason to have this be a configuration option anymore.

Resolves rdar://59202687 and its many, many dupes.
2020-02-07 14:37:03 -08:00
Dan Zheng
7b064a6500 [AutoDiff upstream] Add SIL differentiability witness serialization. (#29642)
SIL differentiability witnesses are a new top-level SIL construct mapping
an "original" SIL function and derivative configuration to derivative SIL
functions.

This patch adds `SILDifferentiabilityWitness` serialization/deserialization.

Resolves TF-1136.
2020-02-07 09:35:16 -08:00
John McCall
faee21b626 Implement Swift serialization and deserialization of Clang types.
As part of this, we have to change the type export rules to
prevent `@convention(c)` function types from being used in
exported interfaces if they aren't serializable.  This is a
more conservative version of the original rule I had, which
was to import such function-pointer types as opaque pointers.
That rule would've completely prevented importing function-pointer
types defined in bridging headers and so simply doesn't work,
so we're left trying to catch the unsupportable cases
retroactively.  This has the unfortunate consequence that we
can't necessarily serialize the internal state of the compiler,
but that was already true due to normal type uses of aggregate
types from bridging headers; if we can teach the compiler to
reliably serialize such types, we should be able to use the
same mechanisms for function types.

This PR doesn't flip the switch to use Clang function types
by default, so many of the clang-function-type-serialization
FIXMEs are still in place.
2020-02-06 22:09:00 -05:00
Doug Gregor
950c73f471 [Serialization] Bump module format version.
The change to introduce a "top-level" bit for VarDecls requires a
module format version bump, per https://github.com/apple/swift/pull/29024.
Fixes rdar://problem/59078925
2020-01-31 16:19:42 -08:00
Adrian Prantl
4bd1ffc67f Serialize whether a VarDecl is a top-level global.
The current way that VarDecl::isLazilyInitializedGlobal() is implemented does
not work in the debugger, since the DeclContext of all VarDecls are deserialized
Swift modules. By adding a bit to the VarDecl we can recover the fact that a
VarDecl was in fact a global even in the debugger.

<rdar://problem/58939370>
2020-01-29 09:21:02 -08:00
Dan Zheng
ac48febfd4 Add @noDerivative flag to SILParameterInfo.
The `@noDerivative` attribute marks the non-differentiability parameters of a
`@differentiable` function type. All parameters except those marked with
`@noDerivative` are differentiability parameters.

For example, `@differentiable (Float, @noDerivative Float) -> Float` is only
differentiable with respect to its first parameter.

The `@noDerivative` attribute is represented as a
`SILParameterDifferentiability` bit on `SILParameterInfo`.

Add round-trip serialization tests.

Resolves TF-872.
2020-01-23 15:29:14 -08:00
Brent Royal-Gordon
0c478b6be6 Revert "Merge pull request #28665 from CodaFi/the-phantom-menace"
This reverts commit 43a3ab7e35, reversing
changes made to 4f39d9c749.

# Conflicts:
#	include/swift/AST/Attr.def
#	lib/AST/Attr.cpp
#	lib/Serialization/Deserialization.cpp
#	lib/Serialization/ModuleFormat.h
#	lib/Serialization/Serialization.cpp
2020-01-15 15:28:42 -08:00
Harlan Haskins
8e45f44da4 [Serialization] Serialize hasMissingDesignatedInitializers
Since this is going to be something modules tell clients, rather than something clients discover about modules, serialize it.
2020-01-06 10:15:07 -08:00
Marc Rasi
72194c547b Merge branch 'master' into ast-nondiff 2019-12-18 17:25:09 -08:00
Dan Zheng
c842fee0a4 [AutoDiff upstream] Add @transpose(of:) attribute.
The `@transpose(of:)` attribute registers a function as a transpose of another
function. This patch adds the `@transpose(of:)` attribute definition, syntax,
parsing, and printing.

Resolves TF-827.

Todos:
- Type-checking (TF-830, TF-1060).
- Enable serialization (TF-838).
- Use module-qualified names instead of custom qualified name syntax/parsing
  (TF-1066).
2019-12-16 12:23:08 -08:00
Robert Widmann
06d27f08fd Define @_implicitly_synthesizes_nested_requirement
State the previously unstated nested type requirement that CodingKeys adds to the witness requirements of a given type. The goal is to make this member cheap to synthesize, and independent of the expensive protocol conformance checks required to append it to the member list.

Further, this makes a clean conceptual separation between what I'm calling "nested type requirements" and actual type and value requirements.

With luck, we'll never have to use this attribute anywhere else.
2019-12-10 16:28:50 -08:00
Joe Groff
4742968454 Serialization support for SIL substituted function types 2019-12-10 12:09:06 -08:00
Dan Zheng
0585eb0e90 [AutoDiff upstream] Add @derivative(of:) attribute. (#28321)
The `@derivative(of:)` attribute registers a function as a derivative of another
function. This patch adds the `@derivative(of:)` attribute definition, syntax,
parsing, and printing.

Resolves TF-826.

Todos:
- Type-checking (TF-829).
- Serialization (TF-837).
2019-12-10 09:29:43 -08:00
Brent Royal-Gordon
e1e7a3fe75 Merge pull request #25656 from brentdax/file-name-basis
Shorten #file and add #filePath (behind an experimental flag)
2019-12-06 21:34:58 -08:00
Brent Royal-Gordon
63ec1cf5af Introduce a separate #filePath, remove -pound-file
This makes the path behavior more first-class. The feature is now hidden behind an experimental flag, -enable-experimental-concise-pound-file.
2019-12-04 16:35:13 -08:00
Adrian Prantl
bdc1eec983 Use the same alignment for writing and readin .swift_ast section contents.
This fixes a bug that made it impossible to read any subsequent Swift modules
out of a .swift_ast section a previous section had a size divisible by 4.

rdar://problem/57110020
2019-12-04 14:39:12 -08:00
Robert Widmann
72e80c21f1 Bump the module format version
We've changed *what* is serialized by changing the way
@_dynamicReplacement is type checked, but not *how* it's
serialized.  Bump the format so there aren't strange incompatibilities
because of this.
2019-12-03 15:30:05 -08:00
Xi Ge
5a862e49bd Merge pull request #28369 from nkcsgexi/originally-defined-in-attribute
AST: introduce a new attribute @_originallyDefinedIn to the AST
2019-11-21 20:26:29 -08:00
Xi Ge
7f8c04e0b7 AST: introduce a new attribute @_originallDefinedIn to the AST
We need this attribute to teach compiler to use a different name from the current
module name when generating runtime symbol names for a declaration. This is to serve
the workflow of refactoring a symbol from one library to another without breaking the existing
ABI.

This patch focuses on parsing and serializing the attribute, so @_originallyDefinedIn
will show up in AST, swiftinterface files and swiftmodule files.

rdar://55268186
2019-11-21 14:25:57 -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
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
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
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
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
Michael Gottesman
7ee5ad7318 [sil] Rename {,Strong}Copy{Unowned,Unmanaged}. 2019-10-26 17:03:47 -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
Xi Ge
014f863546 SerializeLoc: address more comments from Jordan. NFC 2019-10-09 15:29:52 -07:00
Xi Ge
e9dfdea6fd SerializeLoc: serialize basic decl source location information to .swiftsourceinfo file
After setting up the .swiftsourceinfo file, this patch starts to actually serialize
and de-serialize source locations for declaration. The binary format of .swiftsourceinfo
currently contains these three records:

BasicDeclLocs: a hash table mapping from a USR ID to a list of basic source locations. The USR id
could be retrieved from the following DeclUSRs record using an actual decl USR. The basic source locations
include a file ID and the results from Decl::getLoc(), ValueDecl::getNameLoc(), Decl::getStartLoc() and Decl::getEndLoc().
The file ID could be used to retrieve the actual file name from the following SourceFilePaths record.
Each location is encoded as a line:column pair.

DeclUSRS: a hash table mapping from USR to a USR ID used by location records.

SourceFilePaths: a hash table mapping from a file ID to actual file name.

BasicDeclLocs should be sufficient for most diagnostic cases. If additional source locations
are needed, we could always add new source location records without breaking the backward compatibility.
When de-serializing the source location from a module-imported decl, we calculate its USR, retrieve the USR ID
from the DeclUSRS record, and use the USR ID to look up the basic location list in the BasicDeclLocs record.

For more details about .swiftsourceinfo file: https://forums.swift.org/t/proposal-emitting-source-information-file-during-compilation
2019-10-09 15:29:51 -07:00
Harlan Haskins
c82c9b8210 [ModuleInterfaces] Remove references to 'parseable' interfaces everywhere
Now that we've settled on Module Interface as the name, let's remove the
vestiges of "Parseable Interfaces"
2019-09-13 14:55:48 -07:00
Slava Pestov
3a59e7c53a SIL: Serialize availability with the SIL function, not just a weak imported flag
The weak imported flag is now only set if the attribute is unconditionally
weak linked, which is the case when it or one of its parent contexts has a
@_weakLinked attribute.

To correctly handle weak linking based availability with serialized SIL
functions, we need to serialize the actual version tuple when the SIL function
was introduced. This is because the deployment target of the client app can
be older than the deployment target that the original module was built with.

Fixes <rdar://problem/52783668>.
2019-09-06 20:08:40 -04:00
Varun Gandhi
0dcb936531 Serialize extended nominal separately when serializing an extension.
Instead of computing it from the extended type after deserialization --
which is tricky to do, due to potential presence of protocol
compositions -- we obtain the extended nominal directly.

Fixes SR-11227 and linked rdar://problem/53712389.
2019-09-05 15:33:02 -07:00
Jordan Rose
3c2d709996 [Serialization] Move a bunch of internal headers to lib/ (#27012)
This will discourage their use outside of Serialization, which is a
good thing for encapsulation.
2019-09-04 08:58:06 -07:00
John McCall
2e60c2947d Revert "Summon the eldritch horror "EagerDeserializationDecls" from the bowels of history."
This reverts commit dc98e17d84b991b6be8b8feb5e0d05aad24f52a4.

I believe this commit was causing test failures on:
  IRGen/c_layout.sil
  IRGen/existentials.sil
It also recreates the file lib/Serialization/ModuleFormat.h,
which really can't have been intended.

Swift SVN r23732
2014-12-05 06:53:27 +00:00
Joe Groff
df53d4bd80 Summon the eldritch horror "EagerDeserializationDecls" from the bowels of history.
Adding explicit constructors to Clang-imported structs in the previous commits exposes a latent phase ordering issue between the Clang importer and SIL deserialization. Deserializing the standard library SIL ends up pulling in additional Clang decls which never get type-checked before we attempt to emit their code. Work around this by bringing back the "EagerDeserializedDecls" block in the serialization format, and adding any cross-referenced decls that get referenced in SILSerializeAll mode to it, so that we ensure they're available before SILGen. We also have to type-check external decls after doing so, since when only importing a module, we wouldn't do any type-checking at all otherwise.

Swift SVN r23728
2014-12-05 05:31:25 +00:00
Michael Gottesman
9311672c33 Move ModuleFile.h, ModuleFormat.h, and DeclTypeRecordNodes.def to include/swift/Serialization.
This allows for a secondary tool to access the deserialized Module inside the SerializedASTFile's ModuleFile.

Swift SVN r14173
2014-02-20 22:03:55 +00:00
Joe Groff
0bafd1f084 Bump module format version.
Swift SVN r14110
2014-02-19 22:53:54 +00:00
Doug Gregor
a1673d7c8f Add an Objective-C metatype representation spelled with @objc_metatype.
This representation is just a placeholder at the moment.


Swift SVN r14076
2014-02-19 07:21:38 +00:00
Doug Gregor
c54f98fbc9 Convert thick/thin metatype bool to an enumeration. NFC
Swift SVN r14075
2014-02-19 06:05:48 +00:00
Doug Gregor
8bc87bbe1e fromRaw() witnesses can only be synthesized when the raw type is Equatable.
Swift SVN r14067
2014-02-19 01:09:43 +00:00
Chris Lattner
28903887e7 Rename the internal compiler lexicon from let -> val.
Swift SVN r13992
2014-02-17 16:48:21 +00:00
Dmitri Hrybenko
571c9b3c5e Split 'type' keyword into 'static' and 'class'
rdar://15911697


Swift SVN r13908
2014-02-14 14:50:32 +00:00
Doug Gregor
1fa4612eb8 Implement (de-)serialization for open_existential[_ref].
Swift SVN r13898
2014-02-14 05:01:18 +00:00
Dave Abrahams
5063c33cbb Rename "Stream" protocol back to "Generator"
The name Stream didn't seem to be working out as intended; we kept
gravitating back to calling it Generator, which is precedented in other
languages.  Also, Stream seems to beg for qualification as Input or
Output.  I think we'd like to reserve Stream for things that are more
bulk-character-API-ish.

Swift SVN r13893
2014-02-14 01:48:52 +00:00
Chris Lattner
a6640a1b12 Rework has .sil files handle computed vardecls and subscripts.
Previously, we would just parse vars and subscripts with no definitions,
then let getters and setters be referenced arbitrarily later.  This was
problematic for a number of reasons, not least of which, the .sil file
might be invalid.

Instead, change sil to require that a protocol style definition indicate
whether a vardecl/subscript is computed or not, and whether it is both 
get-able and set-able, e.g. like "var x : Int { get }".  Change the 
sil printer to print decls in this form, and change the SILParser to 
make SILDeclRef::Func values instead of ::Getter/Setter values.

One thing that this exposed is that we weren't correctly serializing the
accessor state in modules, so accessors would get detatched from their
AbstractStorageDecls when deserialized (and in fact, their ASD never got
deserialized at all in some cases).  Fix this in the serialization of
the accessors.

NFC, other than the SIL printer and parser.



Swift SVN r13884
2014-02-14 00:57:04 +00:00