Commit Graph

418 Commits

Author SHA1 Message Date
Joe Groff
e4e0f35aed IRGen: Implement an @_alignment attribute.
This is an internal-only affordance for the numerics team to be able to work on SIMD-compatible types. For now, it can only increase alignment of fixed-layout structs and enums; dynamic layout, classes, and other obvious extensions are left to another day when we can design a proper layout control design.

Swift SVN r27323
2015-04-15 17:23:30 +00:00
Doug Gregor
061795d2bf Revert "(De-)serialization for foreign error conventions."
This reverts commit face8b23dc1b7132039e8b20b96e9fabe4634649.

Swift SVN r27295
2015-04-14 23:37:18 +00:00
Doug Gregor
759346e5b8 (De-)serialization for foreign error conventions.
Currently untestable (due to SILGen's inability to handle throwing
@objc methods), but testing will become trivial once that's in place.

Swift SVN r27294
2015-04-14 22:57:44 +00:00
Chris Willmore
2d985c0a5d Revert "(De-)serialization for foreign error conventions."
This reverts commit r27290 due to several test failures in SourceKit.

Swift SVN r27291
2015-04-14 21:40:13 +00:00
Doug Gregor
f1d4293210 (De-)serialization for foreign error conventions.
Currently untestable (due to SILGen's inability to handle throwing
@objc methods), but testing will become trivial once that's in place.

Swift SVN r27290
2015-04-14 21:11:28 +00:00
Joe Groff
ad0d20c07a Fold "AbstractCC" into SILFunctionType::Representation.
These aren't really orthogonal concerns--you'll never have a @thick @cc(objc_method), or an @objc_block @cc(witness_method)--and we have gross decision trees all over the codebase that try to hopscotch between the subset of combinations that make sense. Stop the madness by eliminating AbstractCC and folding its states into SILFunctionTypeRepresentation. This cleans up a ton of code across the compiler.

I couldn't quite eliminate AbstractCC's information from AST function types, since SIL type lowering transiently created AnyFunctionTypes with AbstractCCs set, even though these never occur at the source level. To accommodate type lowering, allow AnyFunctionType::ExtInfo to carry a SILFunctionTypeRepresentation, and arrange for the overlapping representations to share raw values.

In order to avoid disturbing test output, AST and SILFunctionTypes are still printed and parsed using the existing @thin/@thick/@objc_block and @cc() attributes, which is kind of gross, but lets me stage in the real source-breaking change separately.

Swift SVN r27095
2015-04-07 21:59:39 +00:00
Joe Pamer
9781bda6a0 Introduce support for serializing and deserializing throwing function types.
Swift SVN r27026
2015-04-05 19:33:03 +00:00
Joe Groff
56de5fb95e SIL: Drop unnecessary bits from SILFunctionType::ExtInfo.
"Autoclosure" is uninteresting to SIL. "noescape" isn't currently used by SIL and we shouldn't have it until it has a meaningful effect on SIL. "throws" should be adequately represented by a SIL function type having an error result.

Swift SVN r27023
2015-04-05 17:35:28 +00:00
Chris Willmore
690daa539a Back out changes for in-place methods/operators from Xcode 7.
This reverts commits r26508, r26545, and r26576.

Swift SVN r26900
2015-04-02 21:14:28 +00:00
Chris Lattner
b02da0ae31 Add tuple element label information to TuplePatterns. Before we had no way
to represent them, and just dropped them on the ground. Now we parse them,
persist them in the AST, and "resolve" them from the expr grammar, but still
drop them on the ground.  This is progress towards fixing: rdar://20135489


Swift SVN r26828
2015-04-01 22:11:32 +00:00
Roman Levenstein
332af2a892 Introduce a base class for ApplyInst and PartialApplyInst.
The new base class ApplyInstBase contains APIs that are common for ApplyInst and PartialApplyInst. It allows such optimization passes like generic specializer to treat both instructions in the same way whenever it is possible. Before this change, one had to duplicate and adjust a lot of implementation code in such passes, because ApplyInst and PartialApplyInst were not related to each other in any form.

The existing clients of both classes can continue using the usual APIs. No changes are required. Only new clients, which want to treat ApplyInst and PartialApplyInst in a uniform way, may do so. One of such new clients is the generic specializer, whose adjusted implementation will be submitted in the following commit.

Swift SVN r26581
2015-03-26 06:41:28 +00:00
John McCall
35b7db3ae1 Parsing support for error results from SILFunctionType.
Swift SVN r26566
2015-03-26 00:01:32 +00:00
Mark Lacey
1f23ff27bb Remove the transparent bit from apply instructions.
We no longer need or use it since we can always refer to the same bit on
the applied function when deciding whether to inline during mandatory
inlining.

Resolves rdar://problem/19478366.

Swift SVN r26534
2015-03-25 08:36:34 +00:00
Chris Willmore
1ee6f7e67c Implement syntax changes for in-place methods.
Rename 'assignment' attribute of infix operators to 'mutating'. Add
'has_assignment' attribute, which results in an implicit declaration of
the assignment version of the same operator. Parse "func =foo"
declaration and "foo.=bar" expression. Validate some basic properties of
in-place methods.

Not yet implemented: automatic generation of wrapper for =foo() if foo()
is implemented, or vice versa; likewise for operators.

Swift SVN r26508
2015-03-25 00:22:41 +00:00
Doug Gregor
8b97f911c6 Reimplement (de-)serialization of protocol conformances.
Primarily, unique normal protocol conformances and reference them via
a conformance ID. This eliminates the use of trailing records for
normal protocol conformances and (more importantly) the cases were we
would write incomplete conformances. The latter could cause problems
if we ever ended up deserializing an incomplete conformance without
also deserializing a complete record for that same conformance.

Secondarily, simplify the way we write conformances. They are now
always trailing records, and we separate out the derived conformance
kinds (specialized/inherited) from either a reference to a normal
conformance in the current module file (via a normal conformance ID)
or via a cross-reference to a conformance in another module file
(currently always a normal conformance, but this need not always be
the case). As part of this, make each conformance record
self-sustaining, so we don't have to push information down to the
reading routines (e.g., the conforming type) to actually produce a
proper conformance. This simplifies deserialization logic further.

Swift SVN r26482
2015-03-24 06:48:23 +00:00
Doug Gregor
2fae11d62d Serialize generic requirements of extensions.
Swift SVN r26415
2015-03-22 12:35:25 +00:00
Doug Gregor
c0d783fe40 Start serializing the reference components of extension declarations.
Specifically, start serializing the generic parameter list, even
though we basically throw it away during deserialization.

Swift SVN r26318
2015-03-19 22:09:59 +00:00
Doug Gregor
dc27688eca Generalize the importer-only RawOptionSet attribute to a SynthesizedProtocol attribute.
This lets us tag imported declarations with arbitrary synthesized
protocols. Use it to handle imported raw option sets as well as the
RawRepresentable conformances of enums that come in as structs.

Swift SVN r26298
2015-03-19 06:35:25 +00:00
Jordan Rose
c6739b6b6c Add the -enable-testing flag, and serialize it.
This flag indicates that internal APIs within the module should be made
available to client code for testing purposes. Currently does nothing.

Not ready for developer consumption yet, ergo a hidden frontend-only flag.

Part of testability (rdar://problem/17732115)

Swift SVN r26292
2015-03-19 02:20:38 +00:00
Chris Lattner
59c22383fb Rework PatternBindingDecl to maintain a list of pattern/initexpr pairs inside of it.
Previously, a multi-pattern var/let decl like:
  var x = 4, y = 17

would produce two pattern binding decls (one for x=4 one for y=17).  This is convenient
in some ways, but is bad for source reproducibility from the ASTs (see, e.g. the improvements
in test/IDE/structure.swift and test/decl/inherit/initializer.swift).

The hardest part of this change was to get parseDeclVar to set up the AST in a way
compatible with our existing assumptions. I ended up with an approach that forms PBDs in 
more erroneous cases than before.  One downside of this is that we now produce a spurious
  "type annotation missing in pattern"
diagnostic in some cases.  I'll take care of that in a follow-on patch.





Swift SVN r26224
2015-03-17 16:14:18 +00:00
Michael Gottesman
3c2216b115 [+0 self] Add the deallocating parameter convention.
The deallocating parameter convention is a new convention put on a
non-trivial parameter if the caller function guarantees to the callee
that the parameter has the deallocating bit set in its object header.

This means that retains and releases do not need to be emitted on these
parameters even though they are non-trivial. This helps to solve a bug
in +0 self and makes it trivial for the optimizer to perform
optimizations based on this property.

It is not emitted yet by SILGen and will only be put on the self
argument of Deallocator functions.

Swift SVN r26179
2015-03-16 07:51:11 +00:00
Chris Lattner
9ac6c23c1d rename IsaPattern -> IsPattern to follow source syntax, NFC.
Swift SVN r25951
2015-03-10 20:09:02 +00:00
Joe Groff
1cc7f59751 Add a KnownProtocol kind for ErrorType.
Swift SVN r25934
2015-03-10 17:31:34 +00:00
Chris Lattner
db187f2183 Enhance VarPattern to capture a bit indicating whether the pattern was a var or let.
Previously we only used this information in the parser, but Sema needs to know as well.

NFC except in -dump-ast.



Swift SVN r25914
2015-03-10 06:07:56 +00:00
Luqman Aden
34b74cfa1c [driver] Add -emit-sib primary action.
Swift SVN r25783
2015-03-05 19:15:07 +00:00
Chris Lattner
99aa4352b2 remove upgrading support for the old @class_protocol attribute.
Swift SVN r25526
2015-02-25 02:04:06 +00:00
Doug Gregor
96a2659223 Serialize initializer stub implementations.
Fixes the cross-module initializer inheritance issues implied by
rdar://problem/19794036.

Swift SVN r25336
2015-02-17 00:38:21 +00:00
Jordan Rose
d7a90abcbc [Serialization] Add missing bump to VersionMinor.
Also update the comments for NormalProtocolConformanceLayout.

Swift SVN r25293
2015-02-14 02:17:08 +00:00
Doug Gregor
954b4e4d83 Implement @autoclosure(escaping).
Addresses rdar://problem/19499207.

Swift SVN r25249
2015-02-12 21:09:47 +00:00
Jordan Rose
de8a05b293 [Serialization] Serialize the SDK path and -Xcc arguments for an app.
...so that the debugger has the best possible chance of being able to load
the app properly.

We don't do this for frameworks today because we don't want to leak this
information into the public module; once we have a distinction between
"the module that ships with the framework" and "the module that goes into
the debug info" we can do this for frameworks as well.

Part of rdar://problem/17670778

Swift SVN r25204
2015-02-11 23:07:48 +00:00
Erik Eckstein
9dfd349faf Add a new Thunk-flag in SILFunction which specifies that a function is a thunk.
This will have an effect on inlining into thunks.
Currently this flag is set for witness thunks and thunks from function signature optimization.
No change in code generation, yet.



Swift SVN r24998
2015-02-05 16:45:05 +00:00
Jordan Rose
478fdcf3ab [serialization] Stop recording the full paths to input source files.
There were no clients and it leaks information about the developer's system.
After this commit, there should be no full paths present in framework modules.
(App modules may contain search paths for debugging reasons, as well as a
full or relative path to the bridging header.)

Swift SVN r24851
2015-01-30 19:22:34 +00:00
David Farler
51f8070abe Serialize local types
Local type declarations are saved in the source file during parsing,
now serialized as decls. Some of these may be defined in DeclContexts
which aren't Decls and previously weren't serialized. Create four new
record kinds:

* PatternBindingInitializer
* DefaultArgumentInitializer
* AbstractClosureExpr
* TopLevelCodeDecl

These new records are used to only preserve enough information for
remangling in the debugger, and parental context relationships.

Finally, provide a lookup API in the module to search by mangled name.
With the new remangling API, the debugging lifecycle for local types
should be complete.

The extra LOCAL_CONTEXT record will compressed back down in a
subsequent patch.

Swift SVN r24739
2015-01-27 01:49:54 +00:00
Jordan Rose
8ee17a4d0d Serialize search paths when building an app, for a better debugging experience.
There's also a testing option, -serialize-debugging-options, to force this
extra info to be serialized even for library targets. In the long run we'll
probably write out this information for all targets, but strip it out of
the "public module" when a framework is built. (That way it ends up in the
debug info's copy of the module.)

Incidentally, this commit includes the ability to add search paths to the
Clang importer on the fly, which is most of rdar://problem/16347147.
Unfortunately there's no centralized way to add search paths to both Clang
/and/ Swift at the moment.

Part of rdar://problem/17670778

Swift SVN r24545
2015-01-20 03:02:54 +00:00
Jordan Rose
6de91151e2 Record whether a file contains a main entry point in the serialized module.
This isn't being used for much yet, but it will allow us to tell whether
something is an app target even at the module-merging stage, which is a
better way to tell if something is an app than whether it has a bridging
header.

We'll also need this if we ever take advantage of reusing "partial modules"
(serialized ASTs for other parts of the module that aren't affected by the
current source file) for compiling source files in incremental builds;
unfortunately that's unlikely given our dependency model.

Swift SVN r24531
2015-01-19 23:08:57 +00:00
Jordan Rose
6b4dc17038 [Serialization] Serialize and check the target a module was compiled with.
Refuse to load a module if it was compiled for a different architecture or
OS, or if its minimum deployment target is newer than the current target.
Additionally, provide the target triple as part of pre-loading validation
for clients who care (like LLDB).

Part of rdar://problem/17670778

Swift SVN r24469
2015-01-16 02:48:59 +00:00
David Farler
cad9f99929 Revert "Serialize local types and provide a lookup API"
Changing the design of this to maintain more local context
information and changing the lookup API.

This reverts commit 4f2ff1819064dc61c20e31c7c308ae6b3e6615d0.

Swift SVN r24432
2015-01-15 00:33:10 +00:00
David Farler
fab3d491d9 Serialize local types and provide a lookup API
rdar://problem/18295292

Locally scoped type declarations were previously not serialized into the
module, which meant that the debugger couldn't reason about the
structure of instances of those types.

Introduce a new mangling for local types:
[file basename MD5][counter][identifier]
This allows the demangle node's data to be used directly for lookup
without having to backtrack in the debugger.

Local decls are now serialized into a LOCAL_TYPE_DECLS table in the
module, which acts as the backing hash table for looking up
[file basename MD5][counter][identifier] -> DeclID mappings.

New tests:
* swift-ide-test mode for testing the demangle/lookup/mangle lifecycle
of a module that contains local decls
* mangling
* module merging with local decls

Swift SVN r24426
2015-01-14 22:08:47 +00:00
John McCall
cae0f6e3db Add the ability for a owning addressor to return
a non-native owner.  This is required by Slice, which
will use an ObjC immutable array object as the owner
as long as all the elements are contiguous.

As part of this, I decided it was best to encode the
native requirement in the accessor names.  This makes
some of these accessors really long; we can revisit this
if we productize this feature.

Note that pinning addressors still require a native
owner, since pinning as a feature is specific to swift
refcounting.

Swift SVN r24420
2015-01-14 19:14:20 +00:00
John McCall
dc4431ebff Split addressors into unsafe, owning, and pinning variants.
Change all the existing addressors to the unsafe variant.

Update the addressor mangling to include the variant.

The addressor and mutable-addressor may be any of the
variants, independent of the choice for the other.

SILGen and code synthesis for the new variants is still
untested.

Swift SVN r24387
2015-01-13 03:09:16 +00:00
Chris Lattner
3564ce6429 [de]serialize the noescape bit in SILFunctionType's as well. Tests coming in a bit.
Swift SVN r24138
2014-12-24 00:48:44 +00:00
Chris Lattner
21a7a6c89a Doug twisted my arm and convinced me that noescape was a better match for the semantics we’ll have here. NoCapture would be confusable with "this closure doesn’t have any captures, thus should be compatible with thin function types"
The attribute itself remains __'ized.



Swift SVN r24113
2014-12-23 17:52:10 +00:00
Chris Lattner
e349ee3a60 Start the implementation of a "nocapture" attribute, which is only valid on paramdecls.
This is part of rdar://16323038.  Because this hasn't been fully design reviewed and
implemented, I'm naming it as __nocapture for now.  It is blocking finishing off the
"improved let model" work.




Swift SVN r24079
2014-12-22 21:34:30 +00:00
Chris Lattner
11a84793ec Add a new bit to VarDecl to track cases where a vardecl gets an
initializer but has no "parent" PatternBindingDecl or Pattern (i.e.
paramdecls).  This is currently set on decls in the pattern of 
foreach loops and case patterns, but I'll add it to other places I
find as well.

NFC since this bit is only set and not read, just more yak shaving.


Swift SVN r23910
2014-12-13 06:25:14 +00:00
Chris Lattner
5d8613c7c9 Introduce a new "Indirect_In_Guaranteed" SIL parameter convention. This
isn't used yet, but will be for modeling the self argument passed to an 
address-only witness implementation.   NFC since all this code is dead :-)



Swift SVN r23857
2014-12-11 01:41:29 +00: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
Arnold Schwaighofer
c322b3592d Add a data dependence between opened existential values and method_inst that 'use' them.
Before this patch there was no dependence visible to the optimizer between a
open_existential and the witness_method allowing the optimizer to reorder the
two instruction. The dependence was implicit in the opened archetype but this
is not a concept model by the SIL optimizer.

  %2 = open_existential %0 : $*FooProto to $*@opened("...") FooProto
  %3 = witness_method $@opened("...") FooProto,
                      #FooProto.bar!1 : $@cc(...)
  %4 = apply %3<...>(%2)

This patch changes the SIL representation such that witness_methods on opened
archetypes take the open_existential (or the producer of the opened existential)
as an operand preventing the optimizer from reordering them.

  %2 = open_existential %0 : $*FooProto to $*@opened("...") FooProto
  %3 = witness_method $@opened("...") FooProto,
                      #FooProto.bar!1,
                      %2 : $*@opened("...") FooProto : $@cc(...)
  %4 = apply %3<...>(%2)

rdar://18984526

Swift SVN r23438
2014-11-19 17:22:22 +00:00
Joe Groff
dc2ad382a2 Serialization: Serialize the raw values of @objc enums.
This is necessary for @objc enums because, for C compatibility, the representations of the cases must match their raw values. We might want to do this for sufficiently fragile Swift enums in the future too, but that can wait. This lets us successfully print the raw values as ObjC.

Swift SVN r23423
2014-11-19 04:03:06 +00:00
Doug Gregor
b27e88b70b Record Objective-C method lookup tables in Swift modules.
Include a mapping from Objective-C selectors to the @objc methods that
produce Objective-c methods with those selectors. Use this to lazily
populate the Objective-C method lookup tables in each class. This makes
@objc override checking work across Swift modules, which is part of
rdar://problem/18391046.

Note that we use a single, unified selector table, both because it is
simpler and because it makes global queries ("is there any method with
the given selector?") easier.

Swift SVN r23214
2014-11-11 00:19:03 +00:00