Commit Graph

190 Commits

Author SHA1 Message Date
Huon Wilson
cb60dbeee2 [IDE] Teach type checker about conditional conformance extensions.
Before conditional conformances, the archetypes in conformance
extensions (i.e. extension Foo: SomeProtocol) were equivalent to those
in the type decl, with the same protocol bounds and so on. The code for
printing "synthesized" members relied on this fact. This commit teaches
that code to deal with archetypes in the conditional conformance
extension when required.

Fixes rdar://problem/36553066 and SR-6930.
2018-02-13 17:37:15 +11:00
Harlan
b9f468e79a [NFC] Remove Syntax's dependency on Sema (#10984)
* Move LegacyASTTransformer and SyntaxASTMapping to AST

* Fix import in swift-syntax-format

* Update swift-syntax-test
2017-07-18 16:58:18 -07:00
Xi Ge
0bba7d900b ASTPrinter: Remove ASTPrinter's dependency on Sema. (#10985) 2017-07-14 20:02:25 -07:00
Harlan
70089a7bcc [Syntax] Represent TokenSyntax as a Syntax node (#10606)
Previously, users of TokenSyntax would always deal with RC<TokenSyntax>
which is a subclass of RawSyntax. Instead, provide TokenSyntax as a
fully-realized Syntax node, that will always exist as a leaf in the
Syntax tree.

This hides the implementation detail of RawSyntax and SyntaxData
completely from clients of libSyntax, and paves the way for future
generation of Syntax nodes.
2017-06-27 11:08:10 -07:00
Nathan Hawes
4ff254de97 Move canDeclProvideDefaultImplementationFor() from libIDE into libIndex 2017-04-27 23:23:45 -07:00
Joe Groff
595e0e4ede Merge branch 'master' into keypaths 2017-04-19 18:38:24 -07:00
practicalswift
7eb7d5b109 [gardening] Fix 100 typos. 2017-04-18 17:01:42 +02:00
David Farler
303a3e5824 Start the Migrator library
The Swift 4 Migrator is invoked through either the driver and frontend
with the -update-code flag.

The basic pipeline in the frontend is:

- Perform some list of syntactic fixes (there are currently none).
- Perform N rounds of sema fix-its on the primary input file, currently
  set to 7 based on prior migrator seasons.  Right now, this is just set
  to take any fix-it suggested by the compiler.
- Emit a replacement map file, a JSON file describing replacements to a
  file that Xcode knows how to understand.

Currently, the Migrator maintains a history of migration states along
the way for debugging purposes.

- Add -emit-remap frontend option
  This will indicate the EmitRemap frontend action.
- Don't fork to a separte swift-update binary.
  This is going to be a mode of the compiler, invoked by the same flags.
- Add -disable-migrator-fixits option
  Useful for debugging, this skips the phase in the Migrator that
  automatically applies fix-its suggested by the compiler.
- Add -emit-migrated-file-path option
  This is used for testing/debugging scenarios. This takes the final
  migration state's output text and writes it to the file specified
  by this option.
- Add -dump-migration-states-dir

  This dumps all of the migration states encountered during a migration
  run for a file to the given directory. For example, the compiler
  fix-it migration pass dumps the input file, the output file, and the
  remap file between the two.

  State output has the following naming convention:
  ${Index}-${MigrationPassName}-${What}.${extension}, such as:
  1-FixitMigrationState-Input.swift

rdar://problem/30926261
2017-04-17 16:25:02 -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
Xi Ge
0ccbfdb933 Index: Record override-of relationship between a decl in protocol extension and the protocol requirements it can provide default implementations for. (#8418) 2017-03-29 19:39:39 -07:00
Xi Ge
3ad7df273f [SourceKit] DocSupport: constraint extensions provide default implementation too. rdar://25692947 (#8398) 2017-03-28 15:55:39 -07:00
Xi Ge
fb842c789a IDE: Hide the implementation detail of ResolvedMemberResult. NFC (#8385) 2017-03-27 20:47:20 -07:00
Xi Ge
5663f6799f IDE: Simplify/Refactor some code that collects the default implementations in protocol extensions. NFC (#8381) 2017-03-27 18:14:45 -07:00
practicalswift
246cfa6c16 [gardening] Use consistent headers 2017-02-24 09:37:37 +01:00
David Farler
7ee42994c8 Start the Syntax library and optional full token lexing
Add an option to the lexer to go back and get a list of "full"
tokens, which include their leading and trailing trivia, which
we can index into from SourceLocs in the current AST.

This starts the Syntax sublibrary, which will support structured
editing APIs. Some skeleton support and basic implementations are
in place for types and generics in the grammar. Yes, it's slightly
redundant with what we have right now. lib/AST conflates syntax
and semantics in the same place(s); this is a first step in changing
that to separate the two concepts for clarity and also to get closer
to incremental parsing and type-checking. The goal is to eventually
extract all of the syntactic information from lib/AST and change that
to be more of a semantic/symbolic model.

Stub out a Semantics manager. This ought to eventually be used as a hub
for encapsulating lazily computed semantic information for syntax nodes.
For the time being, it can serve as a temporary place for mapping from
Syntax nodes to semantically full lib/AST nodes.

This is still in a molten state - don't get too close, wear appropriate
proximity suits, etc.
2017-02-17 12:57:04 -08:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00
Robert Widmann
dfa41d625b Optimize Condition Resolution (#6279)
* Pack the bits for IfConfigDecls into Decl

* Don't open symbols into a module when evaluating canImport statements

The module loaders now have API to check whether a given module can be
imported without importing the referenced module.  This provides a
significant speed boost to condition resolution and no longer
introduces symbols from the referenced module into the current context
without the user explicitly requesting it.

The definition of ‘canImport’ does not necessarily mean that a full
import without error is possible, merely that the path to the import is
visible to the compiler and the module is loadable in some form or
another.

Note that this means this check is insufficient to guarantee that you
are on one platform or another.  For those kinds of checks, use
‘os(OSNAME)’.
2017-01-05 12:08:54 -07:00
Hugh Bellamy
48109f2a64 Fix errors and warnings building libSwiftSema on Windows using MSVC 2016-11-29 11:24:13 +00:00
practicalswift
797b80765f [gardening] Use the correct base URL (https://swift.org) in references to the Swift website
Remove all references to the old non-TLS enabled base URL (http://swift.org)
2016-11-20 17:36:03 +01:00
Slava Pestov
cfe9e6a3de IDE: Use GenericSignatures and interface types (mostly)
There was a ton of complicated logic here to work around
two problems:

- Same-type constraints were not represented properly in
  RequirementReprs, requiring us to store them in strong form
  and parse them out when printing type interfaces.

- The TypeBase::getAllGenericArgs() method did not do the
  right thing for members of protocols and protocol extensions,
  and so instead of simple calls to Type::subst(), we had
  an elaborate 'ArchetypeTransformer' abstraction repeated
  in two places.

Rewrite this code to use GenericSignatures and
GenericFunctionType instead of old-school GenericParamLists
and PolymorphicFunctionType.

This changes the code completion and AST printer output
slightly. A few of the changes are actually fixes for cases
where the old code didn't handle substitutions properly.
A few others are subjective, for example a generic parameter
list of the form <T : Proto> now prints as <T where T : Proto>.

We can add heuristics to make the output whatever we want
here; the important thing is that now we're using modern
abstractions.
2016-10-02 23:49:15 -04:00
Doug Gregor
e2632c1cfa [Code completion] Teach code completion to use declarations for postfix completions.
Code completion had the ability to use declarations to provide better
code completion results for postfix completions, e.g., calls to
functions/methods, but it wasn't trying to get these declarations from
anywhere. Now, get these declarations from the solution to the
constraint system.

The impetus for this is to use default-argument information from the
declaration rather than the type, but plumbing this information
through also means that we get proper "rethrows" annotations, covered
by <rdar://problem/21010193>, and more specific completions in a
number of other places.

Fixes <rdar://problem/21010193>.
2016-06-16 11:44:42 -07:00
Doug Gregor
814a08a5da [IDE] Code completion for Objective-C #keyPath expressions.
Implement code completion support for Objective-C #keyPath
expressions, using semantic analysis of the partially-typed keypath
argument to provide an appropriate set of results (i.e., just
properties and types).

This implements all of the necessary parts of SE-0062 / SR-1237 /
rdar://problem/25710611, although at some point I'd like to follow it
up with some warnings to help migrate existing string literals to
2016-05-21 22:28:51 -07:00
Xi Ge
b313668ca2 IDETypeChecking: Add a function to collect protocol members who have default implementations in protocol extensions. Need for rdar://25032869 2016-03-29 18:01:53 -07:00
Xi Ge
b4d0cb4ffe ModulePrinting: Avoid printing duplicated members in synthesized extensions. 2016-03-23 15:19:16 -07:00
Xi Ge
8bde763ba2 IDETypeChecking: make parameter consistently pass reference. NFC 2016-03-03 18:02:13 -08:00
Xi Ge
326514e397 ModulePrinting: when printing synthesized extensions, avoid printing requirements that are known to be true. 2016-03-03 17:42:35 -08:00
Xi Ge
2f41702dd9 IDETypeChecking: Add two utilities canPossiblyConvertTo() and canPossiblyEqual(). 2016-03-02 12:28:02 -08:00
Xi Ge
4e8c8ffe07 IDETypeChecking: Add two utilities to IDETypeChecking.h which are isEqual() and LookUpTypeInContext(). NFC 2016-03-01 15:44:41 -08:00
Andrew Trick
ff02652108 Move enums into AttrKind.h.
This reorganization allows adding attributes that refer to types.
I need this for a @_specialize attribute with a type list.

PrintOptions.h and other headers depend on these enums. But Attr.h
defines a lot of classes that almost never need to be included.
2016-02-26 21:10:22 -08:00
practicalswift
50f0d0a7bd [gardening] Fix header consistency in recently introduced files 2016-02-05 17:05:35 +01:00
Xi Ge
77b7180f1a Rename CodeCompletionTypeChecking.h to IDETypeChecking.h since it's used by more clients now. NFC 2016-02-04 11:09:21 -08:00
Slava Pestov
81267ce1db AST: Serialize -enable-resilience flag on the ModuleDecl
Since resilience is a property of the module being compiled,
not decls being accessed, we need to record which types are
resilient as part of the module.

Previously we would only ever look at the @_fixed_layout
attribute on a type. If the flag was not specified, Sema
would slap this attribute on every type that gets validated.

This is wasteful for non-resilient builds, because there
all types get the attribute. It was also apparently wrong,
and I don't fully understand when Sema decides to validate
which decls.

It is much cleaner conceptually to just serialize this flag
with the module, and check for its presence if the
attribute was not found on a type.
2016-01-16 02:23:27 -08:00
practicalswift
ca92efc8e6 Use consistent formatting of header comments.
Correct format:
```
//===--- Name of file - Description ----------------------------*- Lang -*-===//
```

Notes:
* Comment line should be exactly 80 chars.
* Padding: Pad with dashes after "Description" to reach 80 chars.
* "Name of file", "Description" and "Lang" are all optional.
* In case of missing "Lang": drop the "-*-" markers.
* In case of missing space: drop one, two or three dashes before "Name of file".
2016-01-04 23:00:53 +01:00
practicalswift
1339b5403b Consistent use of header comment format.
Correct format:
//===--- Name of file - Description ----------------------------*- Lang -*-===//
2016-01-04 13:26:31 +01:00
practicalswift
199c4eae2e Consistent use of programming language indicator in top of file comment. 2016-01-04 09:20:19 +01:00
Zach Panzarino
e3a4147ac9 Update copyright date 2015-12-31 23:28:40 +00:00
Dmitri Gribenko
7778955dc8 Merge pull request #601 from dcci/copycons
[Sema] Provide copy constructor/assignment operator for TypeCheckRequ…
2015-12-19 19:27:08 -08:00
practicalswift
8ab8847684 Fix typos. 2015-12-16 22:09:32 +01:00
Davide Italiano
be210fcd91 [Sema] Provide copy constructor/assignment operator for TypeCheckRequest.
One of the member variant of the union has a non-trivial copy
constructor, therefore the copy cosntructor is implicitly deleted
(in C++11). Provide the constructor and the copy assignment operator
explictly in order to avoid build errors.
2015-12-16 19:12:34 +00:00
Xi Ge
dd113d0f6c Reapply "[InterfacePrint] When printing a type interface, omit the extensions that are not applicable."
After fixing a dangling pointer.

Swift SVN r32672
2015-10-13 22:08:08 +00:00
Xi Ge
ad3c03243f Revert "[InterfacePrint] When printing a type interface, omit the extensions that are not applicable."
For unhappy bots

Swift SVN r32666
2015-10-13 20:36:06 +00:00
Xi Ge
59c4ca96e8 [InterfacePrint] When printing a type interface, omit the extensions that are not applicable.
Swift SVN r32663
2015-10-13 20:00:03 +00:00
Doug Gregor
278fe4f63b Split the type check request payloads out into a separate .def file. NFC
Swift SVN r32575
2015-10-09 17:27:47 +00:00
Doug Gregor
2d324cac45 Minor cleanups in the iterative type checker. NFC
Only use the existing type checker (via "TC") in the iterative type
checker when we're actually making use of its functionality. The
intent is to drive this usage down to zero as we port code over to the
iterative type checker, so unprincipled uses get in the way.

Swift SVN r32573
2015-10-09 17:18:50 +00:00
Doug Gregor
8c9be9be12 Iterative type checker: simple circular reference detection.
Put in some rudimentary logic for finding circular references within
the iterative type checker and diagnosing those cycles. The
"rudimentary" part is because we're performing linear searches within
a stack rather than keeping a proper dependency graph, which is
inefficient and could display longer cycles than are actually
present. Additionally, the diagnostic is not specialized to the actual
query, so we get a generic "circular reference" diagnostic. OTOH, we
show all of the declarations involved in the cycle, which at least
lets the user figure out where the cycle occurred.

Enable the iterative type checker for resolving the type of a global
typealiases.

Swift SVN r32572
2015-10-09 17:18:49 +00:00
Doug Gregor
c560c377cd Iterative type checker: stub out "structural" type resolution requests.
Introduce a request kind for resolving a TypeRepr, and teach type
resolution the start of performing "structural" resolution of a
TypeRepr that gets the basic structure (e.g., we're pointing at
something that is a nominal type, etc.) without checking its
semantics, dealing with generic arguments, etc.

None of this is active yet.

Swift SVN r32569
2015-10-09 17:18:46 +00:00
Doug Gregor
bbf335e596 Iterative type checker: make request construction more convenient.
Add free functions request##Request(PayloadType), rather than having
to directly construct TypeCheckRequest objects.

Swift SVN r32568
2015-10-09 17:18:45 +00:00
Doug Gregor
d245734773 Iterative type checker: thread an UnsatisfiedDependency through type resolution.
Start threading an (optional) UnsatisfiedDependency callback through type resolution, poke it when we're going to perform name lookup on a particular name.

As part of this, teach type resolution to distinguish between "early return due to unsatisfied dependencies" and "early return due to error", and not to mark type representations as invalid while failing.

This is all inactive code.

Swift SVN r32567
2015-10-09 17:18:44 +00:00
Doug Gregor
bef46010b7 Iterative type checker: add requests for name lookup.
These requests are, thus far, unused.

Swift SVN r32566
2015-10-09 17:18:44 +00:00
Doug Gregor
1ee99dd184 Iterative type checker: make checking dependencies more direct. NFC
Swift SVN r32565
2015-10-09 17:18:43 +00:00