Commit Graph

787 Commits

Author SHA1 Message Date
Jordan Rose
82930033d2 Add VTablePlaceholderDecl (but don't hook it up to anything yet). 2017-05-10 11:55:54 -06:00
Slava Pestov
dad864af6b AST: Don't print satisfied protocol requirements when dumping Decls
This can trigger recursive conformance checking, which can change
how associated type inference behaves due to ordering issues, as
well as cause crashes.

Dumping should be idempotent.
2017-05-09 14:53:20 -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
Doug Gregor
bafa99cd6e Add the @_staticInitializeObjCMetadata attribute.
Currently inactive, this attribute indicates that a static initializer should be emitted to register the Objective-C metadata when the image is loaded, rather than on first use of the Objective-C metadata. Infer this attribute for NSCoding classes that won’t have static Objective-C metadata or have an @NSKeyedArchiveLegacy attributed.
2017-05-02 23:30:27 -07:00
Huon Wilson
07c5ab8fb2 Implement \ syntax for Swift key paths.
This introduces a few unfortunate things because the syntax is awkward.
In particular, the period and following token in \.[a], \.? and \.! are
token sequences that don't appear anywhere else in Swift, and so need
special handling. This is somewhat compounded by \foo.bar.baz possibly
being \(foo).bar.baz or \(foo.bar).baz (parens around the type), and,
furthermore, needing to distinguish \Foo?.bar from \Foo.?bar.

rdar://problem/31724243
2017-05-01 16:06:15 -07:00
John McCall
e6d52d8808 LValueToPointerExpr is dead code. RIP LValueToPointerExpr. 2017-04-25 03:01:16 -04:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
Slava Pestov
d49f8fb6d9 AST: Introduce primitive AnyObject type
Add a 'hasExplicitAnyObject()' bit to ProtocolCompositionType
to represent canonical composition types containing '& AnyObject'.

Serialize this bit and take it into account when building
ExistentialLayouts.

Rename ProtocolCompositionType::getProtocols() to getMembers()
since it can contain classes now, and update a few usages that
need further attention with FIXMEs or asserts.

For now, nothing actually constructs these types, and they will
trigger arounds asserts. Upcoming patches will introduce support
for this.
2017-04-13 21:17:05 -07:00
Arnold Schwaighofer
4d60ec333b AST/SILGen support for constant string literals
rdar://30545013
2017-04-11 11:41:43 -07:00
Joe Groff
964dc0e174 Sema: (wip) Overload resolution for keypath subscripts.
TODO: Some diagnostic regressions:
test-macosx-x86_64/Compatibility/tuple_arguments.swift
test-macosx-x86_64/Constraints/diagnostics.swift
test-macosx-x86_64/Constraints/tuple_arguments.swift
test-macosx-x86_64/expr/unary/keypath/keypath.swift
test-macosx-x86_64/expr/unary/selector/selector.swift
2017-04-09 16:38:02 -07:00
Joe Groff
fc23781906 Sema: First pass at type-checking Swift key paths.
TODO:

- Select the KeyPath subclass corresponding to the write capability of the key path components
- Figure out an issue with unresolved solutions being chosen with contextually-typed keypaths
- Diagnostic QoI
2017-04-04 11:31:15 -07:00
Joe Groff
e3046d6f75 Parsing for native keypaths.
Use `#keyPath2` as a stand-in for the final syntax.
2017-04-04 11:31:15 -07:00
Joe Groff
a5ca6ccd61 Restructure KeyPathExpr to allow more kinds of components.
Expand the representation in anticipation of more kinds of components. NFC intended yet.
2017-04-04 11:31:15 -07:00
Joe Groff
eb5d006e40 Rename ObjCKeyPathExpr -> KeyPathExpr.
We can use the same general shape of expression for native key paths.
2017-04-04 11:31:15 -07:00
Rintaro Ishizaki
b56ab17fa5 [Parse] Separate compilation condition validation and evaluation
Fixes:
https://bugs.swift.org/browse/SR-3455
https://bugs.swift.org/browse/SR-3663
https://bugs.swift.org/browse/SR-4032
https://bugs.swift.org/browse/SR-4031

Now, compilation conditions are validated at first, then evaluated. Also,
in non-Swift3 mode, '&&' now has higher precedence than '||'.
'A || B && C || D' are evaluated as 'A || (B && C) || D'.

Swift3 source breaking changes:

* [SR-3663] This used to be accepted and evaluate to 'true' because of short
  circuit without any validation.

  #if true || true * 12 = try Anything is OK?
  print("foo")
  #endif

  In this change, remaining expressions are properly validated and
  diagnosed if it's invalid.

* [SR-4031] Compound name references are now diagnosed as errors.
  e.g. `#if os(foo:bar:)(macOS)` or `#if FLAG(x:y:)`

Swift3 compatibility:

* [SR-3663] The precedence of '||' and '&&' are still the same and the
  following code evaluates to 'true'.

  #if false || true && false
  print("foo")
  #endif
2017-03-23 01:25:29 +09:00
Huon Wilson
ca3a398b4a Merge pull request #8021 from huonw/protocol-where-clause
Parse/typecheck/print where clauses on protocols
2017-03-15 11:00:46 -07:00
Huon Wilson
e4fb40ce9b [AST] Print where clauses on protocols and associated types.
In the general case, this is done by reverse engineering the "best"
places for requirements to go from the requirement signature.

Conformance/superclass requirements like Self: Foo and Self.T: Bar defer
to the inheritance clause if they appear there, or are attached to the
protocol where clause or T (respectively) if not. A conformance
requirement like Self.T.U: Baz will go on T (if T is declared in the
protocol being printed).

Same-type requirements always go in where clauses, and specifically a
where clause of an associated type that is mentioned in them, so
something simple like Self.T.U == Int goes on the T associated type
definition, and similarly Self.T.U == Self.V will go on V (it's kinda
nonsense, but also more directly connected to V). There's a left-bias
for cases without an "obvious" choice, meaning something more
complicated like Self.T.U == Foo<Self.V> will end up on T.

Requirements that don't fit elsewhere will go on the
protocol (e.g. Self.AssocTypeFromSuperProtocol == Int).
2017-03-14 14:22:07 -07:00
John McCall
2077abaca3 Fix a couple of dump() methods to add newlines. 2017-03-14 03:21:50 -04:00
Slava Pestov
162b2d252e AST: Include gardening to minimize dependencies on Expr.h
A lot of files transitively include Expr.h, because it was
included from SILInstruction.h, SILLocation.h and SILDeclRef.h.

However in reality most of these files don't do anything
with Exprs, especially not anything in IRGen or the SILOptimizer.

Now we're down to 171 files in the frontend which depend on
Expr.h, which is still a lot but much better than before.
2017-03-12 22:26:56 -07:00
Huon Wilson
a9299802bb Factor out first = true; ... if (first) first = false; else ....
There's an `interleave` function for this: let's use it.
2017-03-10 15:44:12 -08:00
Hugh Bellamy
33f5f89912 Update unreachable control path annotations 2017-03-03 20:21:49 +07:00
Slava Pestov
0f4a7d246f AST: Remove GenericSignature::getAllDependentTypes()
This was a remnant of the old generics implementation, where
all nested types were expanded into an AllArchetypes list.

For quite some time, this method no longer returned *all*
dependent types, only those with generic requirements on
them, and all if its remaining uses were a bit convoluted.

- In the generic specialization code, we used this to mangle
  substitutions for generic parameters that are not subject
  to a concrete same-type constraint.

  A new GenericSignature::getSubstitutableParams()
  function handles this use-case instead. It is similar
  to getGenericParams(), but only returns generic parameters
  which require substitution.

  In the future, SubstitutionLists will only store replacement
  types for these generic parameters, instead of the list of
  types that we used to produce from getAllDependentTypes().

- In specialization mangling and speculative devirtualization,
  we relied on SubstitutionLists having the same size and
  order as getAllDependentTypes(). It's better to turn the
  SubstitutionList into a SubstitutionMap instead, and do lookups
  into the map.

- In the SIL parser, we were making a pass over the generic
  requirements before looking at getAllDependentTypes();
  enumeratePairedRequirements() gives the correct information
  upfront.

- In SIL box serialization, we don't serialize the size of the
  substitution list, since it's available from the generic
  signature. Add a GenericSignature::getSubstitutionListSize()
  method, but that will go away soon once SubstitionList
  serialization only serializes replacement types for generic
  parameters.

- A few remaining uses now call enumeratePairedRequirements()
  directly.
2017-03-02 22:57:52 -08:00
Doug Gregor
348c6b8001 Protocol conformance: store conformances needed for the requirement signature.
The protocol conformance checker verifies that all of the requirements
in the protocol's requirement signature are fulfilled. Save the
conformances from that check into the NormalProtocolConformance,
because this is the record of how that concrete type satisfies the
protocol requirements.

Compute, deserialize, and verify this information, but don't use it
for anything just yet. We'll use this to eliminate the "inherited
protocol map" and possibility some redundant type-witness
information.
2017-03-01 15:32:50 -08:00
swift-ci
af53cb9778 Merge pull request #7733 from rintaro/parse-ifconfig-refactoring 2017-02-28 19:10:59 -08:00
Jordan Rose
845017cc81 Improve how DeclContext chains are printed in AST dumps. (#7786) 2017-02-28 10:37:21 -08:00
Rintaro Ishizaki
136651e191 [AST] Merge IfConfigDeclClause and IfConfigStmtClause
into IfConfigClause<ElemTy>.
2017-02-24 11:07:27 +09:00
Brian King
5f734c2f15 Clean up enum to string transformations 2017-02-21 00:20:03 -05:00
Slava Pestov
3519e0cd25 AST: Introduce new SubstitutionList type to replace ArrayRef<Substitution>
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.

For now, it's just a typedef for ArrayRef<Substitution>.
2017-02-06 21:36:33 -08:00
Rintaro Ishizaki
571804b02e [ASTDumper] print 'trailing_semi' for Expr, Stmt, and Decl if they have valid 'TrailingSemiLoc' 2017-01-23 13:45:41 +09:00
Slava Pestov
c86b5ae427 AST: Header file gardening - include what you use 2017-01-19 20:07:06 -08:00
Roman Levenstein
29180ca1a0 Add support for layout requirements with layout constraints.
This commit introduces new kind of requirements: layout requirements.

This kind of requirements allows to expose that a type should satisfy certain layout properties, e.g. it should be a trivial type, have a given size and alignment, etc.
2017-01-11 19:21:45 -08:00
Slava Pestov
5eb16e6b34 Include-what-you-use: Initializer.h should not be pulled in from AST.h 2017-01-09 16:46:31 -08:00
Brian Gesiak
663b92ece9 [AST] Completely replace Module with ModuleDecl
The typedef `swift::Module` was a temporary solution that allowed
`swift::Module` to be renamed to `swift::ModuleDecl` without requiring
every single callsite to be modified.

Modify all the callsites, and get rid of the typedef.
2017-01-08 00:36:08 -05:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
swift-ci
8581e84d74 Merge pull request #6494 from modocache/ast-print-generic-params 2017-01-04 13:18:38 -08:00
Brian Gesiak
ff7f01c7e5 [AST] Missing space when printing generic params
Using `-dump-parse` on `func foo<T>(bar: T) {}` results in:

```
(source_file
  (func_decl "foo(bar:)"<T>
    (parameter_list
      (parameter "bar" apiName=bar))
    (brace_stmt)))
```

Notice there is no space between "foo(bar:)" and <T>.

Add a space to correct the formatting error.
2017-01-04 15:58:02 -05:00
Slava Pestov
e4abdfc2bd AST: Model protocols nested inside other types
We might allow protocols inside non-generic class/struct/enum
declarations eventually; there's no conceptual difficulty, just
some IRGen and Serialization work that has to happen first.

Also, this fixes a crasher :-)
2017-01-04 00:10:29 -08:00
Slava Pestov
54752d4999 Merge pull request #6495 from modocache/ast-dump-colors
[ASTDumper] Improve colorization of parse and AST dumps
2017-01-03 20:59:52 -08:00
Brian Gesiak
71a9292d0e [ASTDumper] Use color when printing protocols
Print protocols using color, when available. Also, color many more
parentheses.
2016-12-26 16:08:19 -05:00
Brian Gesiak
8459212ce6 [ASTDumper] Use color when printing TypeRepr
Print TypeRepr using color, when available.
2016-12-26 16:08:19 -05:00
Brian Gesiak
11a46ff4ac [ASTDumper] Use color when printing identifiers
Print identifiers using color, when available.
2016-12-26 16:08:19 -05:00
Brian Gesiak
02738a5e66 [ASTDumper] Use color when printing Stmt
Print Stmt using color, when available.
2016-12-26 16:08:18 -05:00
Brian Gesiak
755c0a6ac7 [ASTDumper] Use color when printing parameters
Print parameters using color, when available.
2016-12-26 16:08:18 -05:00
Brian Gesiak
e58648a1b0 [ASTDumper] Use color when printing AST nodes
Print AST nodes using color, when available.
2016-12-26 16:08:18 -05:00
Brian Gesiak
31855711f1 [ASTDumper] Use color when printing Decl
Print Decl using color, when available.
2016-12-26 16:08:17 -05:00
Brian Gesiak
611600127d [ASTDumper] Use color when printing patterns
Print patterns using color, when available.
2016-12-26 16:08:11 -05:00
Brian Gesiak
9d62225392 [ASTDumper] Print colors for Expr
Begin using colors when printing Expr. Also, move AccessSemantics
overload from the output stream `<<` operator to the PrintWithColorRAII
operator.
2016-12-26 16:01:01 -05:00
Brian Gesiak
b02568f476 [ASTDumper] More colors, compat with print methods
* The Clang AST dumper uses a wide variety of colors, including bold
  fonts. Use a similar scheme in the Swift AST dumper, by introducing a
  `TerminalColor` struct that encompasses both a color and whether it
  is bold.
* Currently the only color Swift's ASTDumper uses is red, for patterns.
  Add a wider variety of colors, for various purposes. If maintainers
  decide to change the color scheme of the output AST, they need only
  to modify the color macros.
* Many AST methods take an output stream as an argument. When using
  PrintWithColorRAII, these methods could not be used. Add a `getOS()`
  method to PrintWithColorRAII, in order to support these methods.
2016-12-26 16:00:58 -05:00
Joe Groff
0c9297862f Sema: Handle type-checking for withoutActuallyEscaping.
withoutActuallyEscaping has a signature like `<T..., U, V, W> (@nonescaping (T...) throws<U> -> V, (@escaping (T...) throws<U> -> V) -> W) -> W, but our type system for functions unfortunately isn't quite that expressive yet, so we need to special-case it. Set up the necessary type system when resolving an overload set to reference withoutActuallyEscaping, and if a type check succeeds, build a MakeTemporarilyEscapableExpr to represent it in the type-checked AST.
2016-12-22 17:51:26 -08:00
Slava Pestov
12326013e3 ASTDumper: Better printing of TupleShuffleExpr 2016-12-22 14:33:00 -05:00